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/>.
28 #include "translate.h"
29 #include "qemu/host-utils.h"
31 #include "exec/gen-icount.h"
37 static TCGv_i64 cpu_X
[32];
38 static TCGv_i64 cpu_pc
;
39 static TCGv_i32 cpu_NF
, cpu_ZF
, cpu_CF
, cpu_VF
;
41 /* Load/store exclusive handling */
42 static TCGv_i64 cpu_exclusive_addr
;
43 static TCGv_i64 cpu_exclusive_val
;
44 static TCGv_i64 cpu_exclusive_high
;
45 #ifdef CONFIG_USER_ONLY
46 static TCGv_i64 cpu_exclusive_test
;
47 static TCGv_i32 cpu_exclusive_info
;
50 static const char *regnames
[] = {
51 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
52 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
53 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
54 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
58 A64_SHIFT_TYPE_LSL
= 0,
59 A64_SHIFT_TYPE_LSR
= 1,
60 A64_SHIFT_TYPE_ASR
= 2,
61 A64_SHIFT_TYPE_ROR
= 3
64 /* Table based decoder typedefs - used when the relevant bits for decode
65 * are too awkwardly scattered across the instruction (eg SIMD).
67 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
69 typedef struct AArch64DecodeTable
{
72 AArch64DecodeFn
*disas_fn
;
75 /* Function prototype for gen_ functions for calling Neon helpers */
76 typedef void NeonGenOneOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
);
77 typedef void NeonGenTwoOpFn(TCGv_i32
, TCGv_i32
, TCGv_i32
);
78 typedef void NeonGenTwoOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
, TCGv_i32
);
79 typedef void NeonGenTwo64OpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
);
80 typedef void NeonGenTwo64OpEnvFn(TCGv_i64
, TCGv_ptr
, TCGv_i64
, TCGv_i64
);
81 typedef void NeonGenNarrowFn(TCGv_i32
, TCGv_i64
);
82 typedef void NeonGenNarrowEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i64
);
83 typedef void NeonGenWidenFn(TCGv_i64
, TCGv_i32
);
84 typedef void NeonGenTwoSingleOPFn(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
85 typedef void NeonGenTwoDoubleOPFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGv_ptr
);
86 typedef void NeonGenOneOpFn(TCGv_i64
, TCGv_i64
);
88 /* initialize TCG globals. */
89 void a64_translate_init(void)
93 cpu_pc
= tcg_global_mem_new_i64(TCG_AREG0
,
94 offsetof(CPUARMState
, pc
),
96 for (i
= 0; i
< 32; i
++) {
97 cpu_X
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
98 offsetof(CPUARMState
, xregs
[i
]),
102 cpu_NF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, NF
), "NF");
103 cpu_ZF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, ZF
), "ZF");
104 cpu_CF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, CF
), "CF");
105 cpu_VF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, VF
), "VF");
107 cpu_exclusive_addr
= tcg_global_mem_new_i64(TCG_AREG0
,
108 offsetof(CPUARMState
, exclusive_addr
), "exclusive_addr");
109 cpu_exclusive_val
= tcg_global_mem_new_i64(TCG_AREG0
,
110 offsetof(CPUARMState
, exclusive_val
), "exclusive_val");
111 cpu_exclusive_high
= tcg_global_mem_new_i64(TCG_AREG0
,
112 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
113 #ifdef CONFIG_USER_ONLY
114 cpu_exclusive_test
= tcg_global_mem_new_i64(TCG_AREG0
,
115 offsetof(CPUARMState
, exclusive_test
), "exclusive_test");
116 cpu_exclusive_info
= tcg_global_mem_new_i32(TCG_AREG0
,
117 offsetof(CPUARMState
, exclusive_info
), "exclusive_info");
121 void aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
122 fprintf_function cpu_fprintf
, int flags
)
124 ARMCPU
*cpu
= ARM_CPU(cs
);
125 CPUARMState
*env
= &cpu
->env
;
126 uint32_t psr
= pstate_read(env
);
129 cpu_fprintf(f
, "PC=%016"PRIx64
" SP=%016"PRIx64
"\n",
130 env
->pc
, env
->xregs
[31]);
131 for (i
= 0; i
< 31; i
++) {
132 cpu_fprintf(f
, "X%02d=%016"PRIx64
, i
, env
->xregs
[i
]);
134 cpu_fprintf(f
, "\n");
139 cpu_fprintf(f
, "PSTATE=%08x (flags %c%c%c%c)\n",
141 psr
& PSTATE_N
? 'N' : '-',
142 psr
& PSTATE_Z
? 'Z' : '-',
143 psr
& PSTATE_C
? 'C' : '-',
144 psr
& PSTATE_V
? 'V' : '-');
145 cpu_fprintf(f
, "\n");
147 if (flags
& CPU_DUMP_FPU
) {
149 for (i
= 0; i
< numvfpregs
; i
+= 2) {
150 uint64_t vlo
= float64_val(env
->vfp
.regs
[i
* 2]);
151 uint64_t vhi
= float64_val(env
->vfp
.regs
[(i
* 2) + 1]);
152 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
" ",
154 vlo
= float64_val(env
->vfp
.regs
[(i
+ 1) * 2]);
155 vhi
= float64_val(env
->vfp
.regs
[((i
+ 1) * 2) + 1]);
156 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
"\n",
159 cpu_fprintf(f
, "FPCR: %08x FPSR: %08x\n",
160 vfp_get_fpcr(env
), vfp_get_fpsr(env
));
164 static int get_mem_index(DisasContext
*s
)
166 #ifdef CONFIG_USER_ONLY
173 void gen_a64_set_pc_im(uint64_t val
)
175 tcg_gen_movi_i64(cpu_pc
, val
);
178 static void gen_exception(int excp
)
180 TCGv_i32 tmp
= tcg_temp_new_i32();
181 tcg_gen_movi_i32(tmp
, excp
);
182 gen_helper_exception(cpu_env
, tmp
);
183 tcg_temp_free_i32(tmp
);
186 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
)
188 gen_a64_set_pc_im(s
->pc
- offset
);
190 s
->is_jmp
= DISAS_EXC
;
193 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
195 /* No direct tb linking with singlestep or deterministic io */
196 if (s
->singlestep_enabled
|| (s
->tb
->cflags
& CF_LAST_IO
)) {
200 /* Only link tbs from inside the same guest page */
201 if ((s
->tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
208 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
210 TranslationBlock
*tb
;
213 if (use_goto_tb(s
, n
, dest
)) {
215 gen_a64_set_pc_im(dest
);
216 tcg_gen_exit_tb((intptr_t)tb
+ n
);
217 s
->is_jmp
= DISAS_TB_JUMP
;
219 gen_a64_set_pc_im(dest
);
220 if (s
->singlestep_enabled
) {
221 gen_exception(EXCP_DEBUG
);
224 s
->is_jmp
= DISAS_JUMP
;
228 static void unallocated_encoding(DisasContext
*s
)
230 gen_exception_insn(s
, 4, EXCP_UDEF
);
233 #define unsupported_encoding(s, insn) \
235 qemu_log_mask(LOG_UNIMP, \
236 "%s:%d: unsupported instruction encoding 0x%08x " \
237 "at pc=%016" PRIx64 "\n", \
238 __FILE__, __LINE__, insn, s->pc - 4); \
239 unallocated_encoding(s); \
242 static void init_tmp_a64_array(DisasContext
*s
)
244 #ifdef CONFIG_DEBUG_TCG
246 for (i
= 0; i
< ARRAY_SIZE(s
->tmp_a64
); i
++) {
247 TCGV_UNUSED_I64(s
->tmp_a64
[i
]);
250 s
->tmp_a64_count
= 0;
253 static void free_tmp_a64(DisasContext
*s
)
256 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
257 tcg_temp_free_i64(s
->tmp_a64
[i
]);
259 init_tmp_a64_array(s
);
262 static TCGv_i64
new_tmp_a64(DisasContext
*s
)
264 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
265 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
268 static TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
270 TCGv_i64 t
= new_tmp_a64(s
);
271 tcg_gen_movi_i64(t
, 0);
276 * Register access functions
278 * These functions are used for directly accessing a register in where
279 * changes to the final register value are likely to be made. If you
280 * need to use a register for temporary calculation (e.g. index type
281 * operations) use the read_* form.
283 * B1.2.1 Register mappings
285 * In instruction register encoding 31 can refer to ZR (zero register) or
286 * the SP (stack pointer) depending on context. In QEMU's case we map SP
287 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
288 * This is the point of the _sp forms.
290 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
293 return new_tmp_a64_zero(s
);
299 /* register access for when 31 == SP */
300 static TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
305 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
306 * representing the register contents. This TCGv is an auto-freed
307 * temporary so it need not be explicitly freed, and may be modified.
309 static TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
311 TCGv_i64 v
= new_tmp_a64(s
);
314 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
316 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
319 tcg_gen_movi_i64(v
, 0);
324 static TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
326 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
]);
335 /* Return the offset into CPUARMState of an element of specified
336 * size, 'element' places in from the least significant end of
337 * the FP/vector register Qn.
339 static inline int vec_reg_offset(int regno
, int element
, TCGMemOp size
)
341 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
342 #ifdef HOST_WORDS_BIGENDIAN
343 /* This is complicated slightly because vfp.regs[2n] is
344 * still the low half and vfp.regs[2n+1] the high half
345 * of the 128 bit vector, even on big endian systems.
346 * Calculate the offset assuming a fully bigendian 128 bits,
347 * then XOR to account for the order of the two 64 bit halves.
349 offs
+= (16 - ((element
+ 1) * (1 << size
)));
352 offs
+= element
* (1 << size
);
357 /* Return the offset into CPUARMState of a slice (from
358 * the least significant end) of FP register Qn (ie
360 * (Note that this is not the same mapping as for A32; see cpu.h)
362 static inline int fp_reg_offset(int regno
, TCGMemOp size
)
364 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
365 #ifdef HOST_WORDS_BIGENDIAN
366 offs
+= (8 - (1 << size
));
371 /* Offset of the high half of the 128 bit vector Qn */
372 static inline int fp_reg_hi_offset(int regno
)
374 return offsetof(CPUARMState
, vfp
.regs
[regno
* 2 + 1]);
377 /* Convenience accessors for reading and writing single and double
378 * FP registers. Writing clears the upper parts of the associated
379 * 128 bit vector register, as required by the architecture.
380 * Note that unlike the GP register accessors, the values returned
381 * by the read functions must be manually freed.
383 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
385 TCGv_i64 v
= tcg_temp_new_i64();
387 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(reg
, MO_64
));
391 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
393 TCGv_i32 v
= tcg_temp_new_i32();
395 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(reg
, MO_32
));
399 static void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
401 TCGv_i64 tcg_zero
= tcg_const_i64(0);
403 tcg_gen_st_i64(v
, cpu_env
, fp_reg_offset(reg
, MO_64
));
404 tcg_gen_st_i64(tcg_zero
, cpu_env
, fp_reg_hi_offset(reg
));
405 tcg_temp_free_i64(tcg_zero
);
408 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
410 TCGv_i64 tmp
= tcg_temp_new_i64();
412 tcg_gen_extu_i32_i64(tmp
, v
);
413 write_fp_dreg(s
, reg
, tmp
);
414 tcg_temp_free_i64(tmp
);
417 static TCGv_ptr
get_fpstatus_ptr(void)
419 TCGv_ptr statusptr
= tcg_temp_new_ptr();
422 /* In A64 all instructions (both FP and Neon) use the FPCR;
423 * there is no equivalent of the A32 Neon "standard FPSCR value"
424 * and all operations use vfp.fp_status.
426 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
427 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
431 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
432 * than the 32 bit equivalent.
434 static inline void gen_set_NZ64(TCGv_i64 result
)
436 TCGv_i64 flag
= tcg_temp_new_i64();
438 tcg_gen_setcondi_i64(TCG_COND_NE
, flag
, result
, 0);
439 tcg_gen_trunc_i64_i32(cpu_ZF
, flag
);
440 tcg_gen_shri_i64(flag
, result
, 32);
441 tcg_gen_trunc_i64_i32(cpu_NF
, flag
);
442 tcg_temp_free_i64(flag
);
445 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
446 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
449 gen_set_NZ64(result
);
451 tcg_gen_trunc_i64_i32(cpu_ZF
, result
);
452 tcg_gen_trunc_i64_i32(cpu_NF
, result
);
454 tcg_gen_movi_i32(cpu_CF
, 0);
455 tcg_gen_movi_i32(cpu_VF
, 0);
458 /* dest = T0 + T1; compute C, N, V and Z flags */
459 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
462 TCGv_i64 result
, flag
, tmp
;
463 result
= tcg_temp_new_i64();
464 flag
= tcg_temp_new_i64();
465 tmp
= tcg_temp_new_i64();
467 tcg_gen_movi_i64(tmp
, 0);
468 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
470 tcg_gen_trunc_i64_i32(cpu_CF
, flag
);
472 gen_set_NZ64(result
);
474 tcg_gen_xor_i64(flag
, result
, t0
);
475 tcg_gen_xor_i64(tmp
, t0
, t1
);
476 tcg_gen_andc_i64(flag
, flag
, tmp
);
477 tcg_temp_free_i64(tmp
);
478 tcg_gen_shri_i64(flag
, flag
, 32);
479 tcg_gen_trunc_i64_i32(cpu_VF
, flag
);
481 tcg_gen_mov_i64(dest
, result
);
482 tcg_temp_free_i64(result
);
483 tcg_temp_free_i64(flag
);
485 /* 32 bit arithmetic */
486 TCGv_i32 t0_32
= tcg_temp_new_i32();
487 TCGv_i32 t1_32
= tcg_temp_new_i32();
488 TCGv_i32 tmp
= tcg_temp_new_i32();
490 tcg_gen_movi_i32(tmp
, 0);
491 tcg_gen_trunc_i64_i32(t0_32
, t0
);
492 tcg_gen_trunc_i64_i32(t1_32
, t1
);
493 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
494 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
495 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
496 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
497 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
498 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
500 tcg_temp_free_i32(tmp
);
501 tcg_temp_free_i32(t0_32
);
502 tcg_temp_free_i32(t1_32
);
506 /* dest = T0 - T1; compute C, N, V and Z flags */
507 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
510 /* 64 bit arithmetic */
511 TCGv_i64 result
, flag
, tmp
;
513 result
= tcg_temp_new_i64();
514 flag
= tcg_temp_new_i64();
515 tcg_gen_sub_i64(result
, t0
, t1
);
517 gen_set_NZ64(result
);
519 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
520 tcg_gen_trunc_i64_i32(cpu_CF
, flag
);
522 tcg_gen_xor_i64(flag
, result
, t0
);
523 tmp
= tcg_temp_new_i64();
524 tcg_gen_xor_i64(tmp
, t0
, t1
);
525 tcg_gen_and_i64(flag
, flag
, tmp
);
526 tcg_temp_free_i64(tmp
);
527 tcg_gen_shri_i64(flag
, flag
, 32);
528 tcg_gen_trunc_i64_i32(cpu_VF
, flag
);
529 tcg_gen_mov_i64(dest
, result
);
530 tcg_temp_free_i64(flag
);
531 tcg_temp_free_i64(result
);
533 /* 32 bit arithmetic */
534 TCGv_i32 t0_32
= tcg_temp_new_i32();
535 TCGv_i32 t1_32
= tcg_temp_new_i32();
538 tcg_gen_trunc_i64_i32(t0_32
, t0
);
539 tcg_gen_trunc_i64_i32(t1_32
, t1
);
540 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
541 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
542 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
543 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
544 tmp
= tcg_temp_new_i32();
545 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
546 tcg_temp_free_i32(t0_32
);
547 tcg_temp_free_i32(t1_32
);
548 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
549 tcg_temp_free_i32(tmp
);
550 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
554 /* dest = T0 + T1 + CF; do not compute flags. */
555 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
557 TCGv_i64 flag
= tcg_temp_new_i64();
558 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
559 tcg_gen_add_i64(dest
, t0
, t1
);
560 tcg_gen_add_i64(dest
, dest
, flag
);
561 tcg_temp_free_i64(flag
);
564 tcg_gen_ext32u_i64(dest
, dest
);
568 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
569 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
572 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
573 result
= tcg_temp_new_i64();
574 cf_64
= tcg_temp_new_i64();
575 vf_64
= tcg_temp_new_i64();
576 tmp
= tcg_const_i64(0);
578 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
579 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
580 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
581 tcg_gen_trunc_i64_i32(cpu_CF
, cf_64
);
582 gen_set_NZ64(result
);
584 tcg_gen_xor_i64(vf_64
, result
, t0
);
585 tcg_gen_xor_i64(tmp
, t0
, t1
);
586 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
587 tcg_gen_shri_i64(vf_64
, vf_64
, 32);
588 tcg_gen_trunc_i64_i32(cpu_VF
, vf_64
);
590 tcg_gen_mov_i64(dest
, result
);
592 tcg_temp_free_i64(tmp
);
593 tcg_temp_free_i64(vf_64
);
594 tcg_temp_free_i64(cf_64
);
595 tcg_temp_free_i64(result
);
597 TCGv_i32 t0_32
, t1_32
, tmp
;
598 t0_32
= tcg_temp_new_i32();
599 t1_32
= tcg_temp_new_i32();
600 tmp
= tcg_const_i32(0);
602 tcg_gen_trunc_i64_i32(t0_32
, t0
);
603 tcg_gen_trunc_i64_i32(t1_32
, t1
);
604 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
605 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
607 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
608 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
609 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
610 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
611 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
613 tcg_temp_free_i32(tmp
);
614 tcg_temp_free_i32(t1_32
);
615 tcg_temp_free_i32(t0_32
);
620 * Load/Store generators
624 * Store from GPR register to memory.
626 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
627 TCGv_i64 tcg_addr
, int size
, int memidx
)
630 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, MO_TE
+ size
);
633 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
634 TCGv_i64 tcg_addr
, int size
)
636 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
));
640 * Load from memory to GPR register
642 static void do_gpr_ld_memidx(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
643 int size
, bool is_signed
, bool extend
, int memidx
)
645 TCGMemOp memop
= MO_TE
+ size
;
653 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
655 if (extend
&& is_signed
) {
657 tcg_gen_ext32u_i64(dest
, dest
);
661 static void do_gpr_ld(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
662 int size
, bool is_signed
, bool extend
)
664 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
669 * Store from FP register to memory
671 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
673 /* This writes the bottom N bits of a 128 bit wide vector to memory */
674 TCGv_i64 tmp
= tcg_temp_new_i64();
675 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(srcidx
, MO_64
));
677 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TE
+ size
);
679 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
680 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
681 tcg_gen_qemu_st64(tmp
, tcg_addr
, get_mem_index(s
));
682 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(srcidx
));
683 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
684 tcg_gen_qemu_st_i64(tmp
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
685 tcg_temp_free_i64(tcg_hiaddr
);
688 tcg_temp_free_i64(tmp
);
692 * Load from memory to FP register
694 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
696 /* This always zero-extends and writes to a full 128 bit wide vector */
697 TCGv_i64 tmplo
= tcg_temp_new_i64();
701 TCGMemOp memop
= MO_TE
+ size
;
702 tmphi
= tcg_const_i64(0);
703 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
706 tmphi
= tcg_temp_new_i64();
707 tcg_hiaddr
= tcg_temp_new_i64();
709 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
710 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
711 tcg_gen_qemu_ld_i64(tmphi
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
712 tcg_temp_free_i64(tcg_hiaddr
);
715 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(destidx
, MO_64
));
716 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(destidx
));
718 tcg_temp_free_i64(tmplo
);
719 tcg_temp_free_i64(tmphi
);
723 * Vector load/store helpers.
725 * The principal difference between this and a FP load is that we don't
726 * zero extend as we are filling a partial chunk of the vector register.
727 * These functions don't support 128 bit loads/stores, which would be
728 * normal load/store operations.
730 * The _i32 versions are useful when operating on 32 bit quantities
731 * (eg for floating point single or using Neon helper functions).
734 /* Get value of an element within a vector register */
735 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
736 int element
, TCGMemOp memop
)
738 int vect_off
= vec_reg_offset(srcidx
, element
, memop
& MO_SIZE
);
741 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
744 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
747 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
750 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
753 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
756 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
760 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
763 g_assert_not_reached();
767 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
768 int element
, TCGMemOp memop
)
770 int vect_off
= vec_reg_offset(srcidx
, element
, memop
& MO_SIZE
);
773 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
776 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
779 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
782 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
786 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
789 g_assert_not_reached();
793 /* Set value of an element within a vector register */
794 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
795 int element
, TCGMemOp memop
)
797 int vect_off
= vec_reg_offset(destidx
, element
, memop
& MO_SIZE
);
800 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
803 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
806 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
809 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
812 g_assert_not_reached();
816 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
817 int destidx
, int element
, TCGMemOp memop
)
819 int vect_off
= vec_reg_offset(destidx
, element
, memop
& MO_SIZE
);
822 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
825 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
828 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
831 g_assert_not_reached();
835 /* Clear the high 64 bits of a 128 bit vector (in general non-quad
836 * vector ops all need to do this).
838 static void clear_vec_high(DisasContext
*s
, int rd
)
840 TCGv_i64 tcg_zero
= tcg_const_i64(0);
842 write_vec_element(s
, tcg_zero
, rd
, 1, MO_64
);
843 tcg_temp_free_i64(tcg_zero
);
846 /* Store from vector register to memory */
847 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
848 TCGv_i64 tcg_addr
, int size
)
850 TCGMemOp memop
= MO_TE
+ size
;
851 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
853 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
854 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
856 tcg_temp_free_i64(tcg_tmp
);
859 /* Load from memory to vector register */
860 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
861 TCGv_i64 tcg_addr
, int size
)
863 TCGMemOp memop
= MO_TE
+ size
;
864 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
866 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
867 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
869 tcg_temp_free_i64(tcg_tmp
);
873 * This utility function is for doing register extension with an
874 * optional shift. You will likely want to pass a temporary for the
875 * destination register. See DecodeRegExtend() in the ARM ARM.
877 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
878 int option
, unsigned int shift
)
880 int extsize
= extract32(option
, 0, 2);
881 bool is_signed
= extract32(option
, 2, 1);
886 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
889 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
892 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
895 tcg_gen_mov_i64(tcg_out
, tcg_in
);
901 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
904 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
907 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
910 tcg_gen_mov_i64(tcg_out
, tcg_in
);
916 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
920 static inline void gen_check_sp_alignment(DisasContext
*s
)
922 /* The AArch64 architecture mandates that (if enabled via PSTATE
923 * or SCTLR bits) there is a check that SP is 16-aligned on every
924 * SP-relative load or store (with an exception generated if it is not).
925 * In line with general QEMU practice regarding misaligned accesses,
926 * we omit these checks for the sake of guest program performance.
927 * This function is provided as a hook so we can more easily add these
928 * checks in future (possibly as a "favour catching guest program bugs
929 * over speed" user selectable option).
934 * This provides a simple table based table lookup decoder. It is
935 * intended to be used when the relevant bits for decode are too
936 * awkwardly placed and switch/if based logic would be confusing and
937 * deeply nested. Since it's a linear search through the table, tables
938 * should be kept small.
940 * It returns the first handler where insn & mask == pattern, or
941 * NULL if there is no match.
942 * The table is terminated by an empty mask (i.e. 0)
944 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
947 const AArch64DecodeTable
*tptr
= table
;
950 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
951 return tptr
->disas_fn
;
959 * the instruction disassembly implemented here matches
960 * the instruction encoding classifications in chapter 3 (C3)
961 * of the ARM Architecture Reference Manual (DDI0487A_a)
964 /* C3.2.7 Unconditional branch (immediate)
966 * +----+-----------+-------------------------------------+
967 * | op | 0 0 1 0 1 | imm26 |
968 * +----+-----------+-------------------------------------+
970 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
972 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
974 if (insn
& (1 << 31)) {
975 /* C5.6.26 BL Branch with link */
976 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
979 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
980 gen_goto_tb(s
, 0, addr
);
983 /* C3.2.1 Compare & branch (immediate)
984 * 31 30 25 24 23 5 4 0
985 * +----+-------------+----+---------------------+--------+
986 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
987 * +----+-------------+----+---------------------+--------+
989 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
991 unsigned int sf
, op
, rt
;
996 sf
= extract32(insn
, 31, 1);
997 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
998 rt
= extract32(insn
, 0, 5);
999 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1001 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1002 label_match
= gen_new_label();
1004 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1005 tcg_cmp
, 0, label_match
);
1007 gen_goto_tb(s
, 0, s
->pc
);
1008 gen_set_label(label_match
);
1009 gen_goto_tb(s
, 1, addr
);
1012 /* C3.2.5 Test & branch (immediate)
1013 * 31 30 25 24 23 19 18 5 4 0
1014 * +----+-------------+----+-------+-------------+------+
1015 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1016 * +----+-------------+----+-------+-------------+------+
1018 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1020 unsigned int bit_pos
, op
, rt
;
1025 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1026 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1027 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1028 rt
= extract32(insn
, 0, 5);
1030 tcg_cmp
= tcg_temp_new_i64();
1031 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1032 label_match
= gen_new_label();
1033 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1034 tcg_cmp
, 0, label_match
);
1035 tcg_temp_free_i64(tcg_cmp
);
1036 gen_goto_tb(s
, 0, s
->pc
);
1037 gen_set_label(label_match
);
1038 gen_goto_tb(s
, 1, addr
);
1041 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
1042 * 31 25 24 23 5 4 3 0
1043 * +---------------+----+---------------------+----+------+
1044 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1045 * +---------------+----+---------------------+----+------+
1047 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1052 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1053 unallocated_encoding(s
);
1056 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1057 cond
= extract32(insn
, 0, 4);
1060 /* genuinely conditional branches */
1061 int label_match
= gen_new_label();
1062 arm_gen_test_cc(cond
, label_match
);
1063 gen_goto_tb(s
, 0, s
->pc
);
1064 gen_set_label(label_match
);
1065 gen_goto_tb(s
, 1, addr
);
1067 /* 0xe and 0xf are both "always" conditions */
1068 gen_goto_tb(s
, 0, addr
);
1073 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1074 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1076 unsigned int selector
= crm
<< 3 | op2
;
1079 unallocated_encoding(s
);
1087 s
->is_jmp
= DISAS_WFI
;
1093 /* we treat all as NOP at least for now */
1096 /* default specified as NOP equivalent */
1101 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1103 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1106 /* CLREX, DSB, DMB, ISB */
1107 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1108 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1111 unallocated_encoding(s
);
1122 /* We don't emulate caches so barriers are no-ops */
1125 unallocated_encoding(s
);
1130 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
1131 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1132 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1134 int op
= op1
<< 3 | op2
;
1136 case 0x05: /* SPSel */
1137 if (s
->current_pl
== 0) {
1138 unallocated_encoding(s
);
1142 case 0x1e: /* DAIFSet */
1143 case 0x1f: /* DAIFClear */
1145 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1146 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1147 gen_a64_set_pc_im(s
->pc
- 4);
1148 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1149 tcg_temp_free_i32(tcg_imm
);
1150 tcg_temp_free_i32(tcg_op
);
1151 s
->is_jmp
= DISAS_UPDATE
;
1155 unallocated_encoding(s
);
1160 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1162 TCGv_i32 tmp
= tcg_temp_new_i32();
1163 TCGv_i32 nzcv
= tcg_temp_new_i32();
1165 /* build bit 31, N */
1166 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1 << 31));
1167 /* build bit 30, Z */
1168 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1169 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1170 /* build bit 29, C */
1171 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1172 /* build bit 28, V */
1173 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1174 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1175 /* generate result */
1176 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1178 tcg_temp_free_i32(nzcv
);
1179 tcg_temp_free_i32(tmp
);
1182 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1185 TCGv_i32 nzcv
= tcg_temp_new_i32();
1187 /* take NZCV from R[t] */
1188 tcg_gen_trunc_i64_i32(nzcv
, tcg_rt
);
1191 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1 << 31));
1193 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1194 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1196 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1197 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1199 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1200 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1201 tcg_temp_free_i32(nzcv
);
1204 /* C5.6.129 MRS - move from system register
1205 * C5.6.131 MSR (register) - move to system register
1208 * These are all essentially the same insn in 'read' and 'write'
1209 * versions, with varying op0 fields.
1211 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1212 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1213 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1215 const ARMCPRegInfo
*ri
;
1218 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1219 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1220 crn
, crm
, op0
, op1
, op2
));
1223 /* Unknown register; this might be a guest error or a QEMU
1224 * unimplemented feature.
1226 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1227 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1228 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1229 unallocated_encoding(s
);
1233 /* Check access permissions */
1234 if (!cp_access_ok(s
->current_pl
, ri
, isread
)) {
1235 unallocated_encoding(s
);
1240 /* Emit code to perform further access permissions checks at
1241 * runtime; this may result in an exception.
1244 gen_a64_set_pc_im(s
->pc
- 4);
1245 tmpptr
= tcg_const_ptr(ri
);
1246 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
);
1247 tcg_temp_free_ptr(tmpptr
);
1250 /* Handle special cases first */
1251 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1255 tcg_rt
= cpu_reg(s
, rt
);
1257 gen_get_nzcv(tcg_rt
);
1259 gen_set_nzcv(tcg_rt
);
1262 case ARM_CP_CURRENTEL
:
1263 /* Reads as current EL value from pstate, which is
1264 * guaranteed to be constant by the tb flags.
1266 tcg_rt
= cpu_reg(s
, rt
);
1267 tcg_gen_movi_i64(tcg_rt
, s
->current_pl
<< 2);
1273 if (use_icount
&& (ri
->type
& ARM_CP_IO
)) {
1277 tcg_rt
= cpu_reg(s
, rt
);
1280 if (ri
->type
& ARM_CP_CONST
) {
1281 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1282 } else if (ri
->readfn
) {
1284 tmpptr
= tcg_const_ptr(ri
);
1285 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1286 tcg_temp_free_ptr(tmpptr
);
1288 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1291 if (ri
->type
& ARM_CP_CONST
) {
1292 /* If not forbidden by access permissions, treat as WI */
1294 } else if (ri
->writefn
) {
1296 tmpptr
= tcg_const_ptr(ri
);
1297 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1298 tcg_temp_free_ptr(tmpptr
);
1300 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1304 if (use_icount
&& (ri
->type
& ARM_CP_IO
)) {
1305 /* I/O operations must end the TB here (whether read or write) */
1307 s
->is_jmp
= DISAS_UPDATE
;
1308 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1309 /* We default to ending the TB on a coprocessor register write,
1310 * but allow this to be suppressed by the register definition
1311 * (usually only necessary to work around guest bugs).
1313 s
->is_jmp
= DISAS_UPDATE
;
1318 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1319 * +---------------------+---+-----+-----+-------+-------+-----+------+
1320 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1321 * +---------------------+---+-----+-----+-------+-------+-----+------+
1323 static void disas_system(DisasContext
*s
, uint32_t insn
)
1325 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1326 l
= extract32(insn
, 21, 1);
1327 op0
= extract32(insn
, 19, 2);
1328 op1
= extract32(insn
, 16, 3);
1329 crn
= extract32(insn
, 12, 4);
1330 crm
= extract32(insn
, 8, 4);
1331 op2
= extract32(insn
, 5, 3);
1332 rt
= extract32(insn
, 0, 5);
1335 if (l
|| rt
!= 31) {
1336 unallocated_encoding(s
);
1340 case 2: /* C5.6.68 HINT */
1341 handle_hint(s
, insn
, op1
, op2
, crm
);
1343 case 3: /* CLREX, DSB, DMB, ISB */
1344 handle_sync(s
, insn
, op1
, op2
, crm
);
1346 case 4: /* C5.6.130 MSR (immediate) */
1347 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1350 unallocated_encoding(s
);
1355 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1358 /* C3.2.3 Exception generation
1360 * 31 24 23 21 20 5 4 2 1 0
1361 * +-----------------+-----+------------------------+-----+----+
1362 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1363 * +-----------------------+------------------------+----------+
1365 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1367 int opc
= extract32(insn
, 21, 3);
1368 int op2_ll
= extract32(insn
, 0, 5);
1372 /* SVC, HVC, SMC; since we don't support the Virtualization
1373 * or TrustZone extensions these all UNDEF except SVC.
1376 unallocated_encoding(s
);
1379 gen_exception_insn(s
, 0, EXCP_SWI
);
1383 unallocated_encoding(s
);
1387 gen_exception_insn(s
, 0, EXCP_BKPT
);
1391 unallocated_encoding(s
);
1395 unsupported_encoding(s
, insn
);
1398 if (op2_ll
< 1 || op2_ll
> 3) {
1399 unallocated_encoding(s
);
1402 /* DCPS1, DCPS2, DCPS3 */
1403 unsupported_encoding(s
, insn
);
1406 unallocated_encoding(s
);
1411 /* C3.2.7 Unconditional branch (register)
1412 * 31 25 24 21 20 16 15 10 9 5 4 0
1413 * +---------------+-------+-------+-------+------+-------+
1414 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1415 * +---------------+-------+-------+-------+------+-------+
1417 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1419 unsigned int opc
, op2
, op3
, rn
, op4
;
1421 opc
= extract32(insn
, 21, 4);
1422 op2
= extract32(insn
, 16, 5);
1423 op3
= extract32(insn
, 10, 6);
1424 rn
= extract32(insn
, 5, 5);
1425 op4
= extract32(insn
, 0, 5);
1427 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1428 unallocated_encoding(s
);
1437 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1442 unallocated_encoding(s
);
1444 unsupported_encoding(s
, insn
);
1448 unallocated_encoding(s
);
1452 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1453 s
->is_jmp
= DISAS_JUMP
;
1456 /* C3.2 Branches, exception generating and system instructions */
1457 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1459 switch (extract32(insn
, 25, 7)) {
1460 case 0x0a: case 0x0b:
1461 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1462 disas_uncond_b_imm(s
, insn
);
1464 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1465 disas_comp_b_imm(s
, insn
);
1467 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1468 disas_test_b_imm(s
, insn
);
1470 case 0x2a: /* Conditional branch (immediate) */
1471 disas_cond_b_imm(s
, insn
);
1473 case 0x6a: /* Exception generation / System */
1474 if (insn
& (1 << 24)) {
1475 disas_system(s
, insn
);
1480 case 0x6b: /* Unconditional branch (register) */
1481 disas_uncond_b_reg(s
, insn
);
1484 unallocated_encoding(s
);
1490 * Load/Store exclusive instructions are implemented by remembering
1491 * the value/address loaded, and seeing if these are the same
1492 * when the store is performed. This is not actually the architecturally
1493 * mandated semantics, but it works for typical guest code sequences
1494 * and avoids having to monitor regular stores.
1496 * In system emulation mode only one CPU will be running at once, so
1497 * this sequence is effectively atomic. In user emulation mode we
1498 * throw an exception and handle the atomic operation elsewhere.
1500 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1501 TCGv_i64 addr
, int size
, bool is_pair
)
1503 TCGv_i64 tmp
= tcg_temp_new_i64();
1504 TCGMemOp memop
= MO_TE
+ size
;
1506 g_assert(size
<= 3);
1507 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), memop
);
1510 TCGv_i64 addr2
= tcg_temp_new_i64();
1511 TCGv_i64 hitmp
= tcg_temp_new_i64();
1513 g_assert(size
>= 2);
1514 tcg_gen_addi_i64(addr2
, addr
, 1 << size
);
1515 tcg_gen_qemu_ld_i64(hitmp
, addr2
, get_mem_index(s
), memop
);
1516 tcg_temp_free_i64(addr2
);
1517 tcg_gen_mov_i64(cpu_exclusive_high
, hitmp
);
1518 tcg_gen_mov_i64(cpu_reg(s
, rt2
), hitmp
);
1519 tcg_temp_free_i64(hitmp
);
1522 tcg_gen_mov_i64(cpu_exclusive_val
, tmp
);
1523 tcg_gen_mov_i64(cpu_reg(s
, rt
), tmp
);
1525 tcg_temp_free_i64(tmp
);
1526 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1529 #ifdef CONFIG_USER_ONLY
1530 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1531 TCGv_i64 addr
, int size
, int is_pair
)
1533 tcg_gen_mov_i64(cpu_exclusive_test
, addr
);
1534 tcg_gen_movi_i32(cpu_exclusive_info
,
1535 size
| is_pair
<< 2 | (rd
<< 4) | (rt
<< 9) | (rt2
<< 14));
1536 gen_exception_insn(s
, 4, EXCP_STREX
);
1539 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1540 TCGv_i64 inaddr
, int size
, int is_pair
)
1542 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1543 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1546 * [addr + datasize] = {Rt2};
1552 * env->exclusive_addr = -1;
1554 int fail_label
= gen_new_label();
1555 int done_label
= gen_new_label();
1556 TCGv_i64 addr
= tcg_temp_local_new_i64();
1559 /* Copy input into a local temp so it is not trashed when the
1560 * basic block ends at the branch insn.
1562 tcg_gen_mov_i64(addr
, inaddr
);
1563 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
1565 tmp
= tcg_temp_new_i64();
1566 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), MO_TE
+ size
);
1567 tcg_gen_brcond_i64(TCG_COND_NE
, tmp
, cpu_exclusive_val
, fail_label
);
1568 tcg_temp_free_i64(tmp
);
1571 TCGv_i64 addrhi
= tcg_temp_new_i64();
1572 TCGv_i64 tmphi
= tcg_temp_new_i64();
1574 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1575 tcg_gen_qemu_ld_i64(tmphi
, addrhi
, get_mem_index(s
), MO_TE
+ size
);
1576 tcg_gen_brcond_i64(TCG_COND_NE
, tmphi
, cpu_exclusive_high
, fail_label
);
1578 tcg_temp_free_i64(tmphi
);
1579 tcg_temp_free_i64(addrhi
);
1582 /* We seem to still have the exclusive monitor, so do the store */
1583 tcg_gen_qemu_st_i64(cpu_reg(s
, rt
), addr
, get_mem_index(s
), MO_TE
+ size
);
1585 TCGv_i64 addrhi
= tcg_temp_new_i64();
1587 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1588 tcg_gen_qemu_st_i64(cpu_reg(s
, rt2
), addrhi
,
1589 get_mem_index(s
), MO_TE
+ size
);
1590 tcg_temp_free_i64(addrhi
);
1593 tcg_temp_free_i64(addr
);
1595 tcg_gen_movi_i64(cpu_reg(s
, rd
), 0);
1596 tcg_gen_br(done_label
);
1597 gen_set_label(fail_label
);
1598 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
1599 gen_set_label(done_label
);
1600 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1605 /* C3.3.6 Load/store exclusive
1607 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
1608 * +-----+-------------+----+---+----+------+----+-------+------+------+
1609 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
1610 * +-----+-------------+----+---+----+------+----+-------+------+------+
1612 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
1613 * L: 0 -> store, 1 -> load
1614 * o2: 0 -> exclusive, 1 -> not
1615 * o1: 0 -> single register, 1 -> register pair
1616 * o0: 1 -> load-acquire/store-release, 0 -> not
1618 * o0 == 0 AND o2 == 1 is un-allocated
1619 * o1 == 1 is un-allocated except for 32 and 64 bit sizes
1621 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
1623 int rt
= extract32(insn
, 0, 5);
1624 int rn
= extract32(insn
, 5, 5);
1625 int rt2
= extract32(insn
, 10, 5);
1626 int is_lasr
= extract32(insn
, 15, 1);
1627 int rs
= extract32(insn
, 16, 5);
1628 int is_pair
= extract32(insn
, 21, 1);
1629 int is_store
= !extract32(insn
, 22, 1);
1630 int is_excl
= !extract32(insn
, 23, 1);
1631 int size
= extract32(insn
, 30, 2);
1634 if ((!is_excl
&& !is_lasr
) ||
1635 (is_pair
&& size
< 2)) {
1636 unallocated_encoding(s
);
1641 gen_check_sp_alignment(s
);
1643 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1645 /* Note that since TCG is single threaded load-acquire/store-release
1646 * semantics require no extra if (is_lasr) { ... } handling.
1651 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1653 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1656 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1658 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1660 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, false, false);
1663 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt
);
1664 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1666 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
1668 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, false, false);
1675 * C3.3.5 Load register (literal)
1677 * 31 30 29 27 26 25 24 23 5 4 0
1678 * +-----+-------+---+-----+-------------------+-------+
1679 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
1680 * +-----+-------+---+-----+-------------------+-------+
1682 * V: 1 -> vector (simd/fp)
1683 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
1684 * 10-> 32 bit signed, 11 -> prefetch
1685 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
1687 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
1689 int rt
= extract32(insn
, 0, 5);
1690 int64_t imm
= sextract32(insn
, 5, 19) << 2;
1691 bool is_vector
= extract32(insn
, 26, 1);
1692 int opc
= extract32(insn
, 30, 2);
1693 bool is_signed
= false;
1695 TCGv_i64 tcg_rt
, tcg_addr
;
1699 unallocated_encoding(s
);
1705 /* PRFM (literal) : prefetch */
1708 size
= 2 + extract32(opc
, 0, 1);
1709 is_signed
= extract32(opc
, 1, 1);
1712 tcg_rt
= cpu_reg(s
, rt
);
1714 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
1716 do_fp_ld(s
, rt
, tcg_addr
, size
);
1718 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
1720 tcg_temp_free_i64(tcg_addr
);
1724 * C5.6.80 LDNP (Load Pair - non-temporal hint)
1725 * C5.6.81 LDP (Load Pair - non vector)
1726 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
1727 * C5.6.176 STNP (Store Pair - non-temporal hint)
1728 * C5.6.177 STP (Store Pair - non vector)
1729 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
1730 * C6.3.165 LDP (Load Pair of SIMD&FP)
1731 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
1732 * C6.3.284 STP (Store Pair of SIMD&FP)
1734 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
1735 * +-----+-------+---+---+-------+---+-----------------------------+
1736 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
1737 * +-----+-------+---+---+-------+---+-------+-------+------+------+
1739 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
1741 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
1742 * V: 0 -> GPR, 1 -> Vector
1743 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
1744 * 10 -> signed offset, 11 -> pre-index
1745 * L: 0 -> Store 1 -> Load
1747 * Rt, Rt2 = GPR or SIMD registers to be stored
1748 * Rn = general purpose register containing address
1749 * imm7 = signed offset (multiple of 4 or 8 depending on size)
1751 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
1753 int rt
= extract32(insn
, 0, 5);
1754 int rn
= extract32(insn
, 5, 5);
1755 int rt2
= extract32(insn
, 10, 5);
1756 int64_t offset
= sextract32(insn
, 15, 7);
1757 int index
= extract32(insn
, 23, 2);
1758 bool is_vector
= extract32(insn
, 26, 1);
1759 bool is_load
= extract32(insn
, 22, 1);
1760 int opc
= extract32(insn
, 30, 2);
1762 bool is_signed
= false;
1763 bool postindex
= false;
1766 TCGv_i64 tcg_addr
; /* calculated address */
1770 unallocated_encoding(s
);
1777 size
= 2 + extract32(opc
, 1, 1);
1778 is_signed
= extract32(opc
, 0, 1);
1779 if (!is_load
&& is_signed
) {
1780 unallocated_encoding(s
);
1786 case 1: /* post-index */
1791 /* signed offset with "non-temporal" hint. Since we don't emulate
1792 * caches we don't care about hints to the cache system about
1793 * data access patterns, and handle this identically to plain
1797 /* There is no non-temporal-hint version of LDPSW */
1798 unallocated_encoding(s
);
1803 case 2: /* signed offset, rn not updated */
1806 case 3: /* pre-index */
1815 gen_check_sp_alignment(s
);
1818 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1821 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
1826 do_fp_ld(s
, rt
, tcg_addr
, size
);
1828 do_fp_st(s
, rt
, tcg_addr
, size
);
1831 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1833 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
1835 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1838 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1841 do_fp_ld(s
, rt2
, tcg_addr
, size
);
1843 do_fp_st(s
, rt2
, tcg_addr
, size
);
1846 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
1848 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false);
1850 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
1856 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
1858 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1860 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
1865 * C3.3.8 Load/store (immediate post-indexed)
1866 * C3.3.9 Load/store (immediate pre-indexed)
1867 * C3.3.12 Load/store (unscaled immediate)
1869 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
1870 * +----+-------+---+-----+-----+---+--------+-----+------+------+
1871 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
1872 * +----+-------+---+-----+-----+---+--------+-----+------+------+
1874 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
1876 * V = 0 -> non-vector
1877 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
1878 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
1880 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
)
1882 int rt
= extract32(insn
, 0, 5);
1883 int rn
= extract32(insn
, 5, 5);
1884 int imm9
= sextract32(insn
, 12, 9);
1885 int opc
= extract32(insn
, 22, 2);
1886 int size
= extract32(insn
, 30, 2);
1887 int idx
= extract32(insn
, 10, 2);
1888 bool is_signed
= false;
1889 bool is_store
= false;
1890 bool is_extended
= false;
1891 bool is_unpriv
= (idx
== 2);
1892 bool is_vector
= extract32(insn
, 26, 1);
1899 size
|= (opc
& 2) << 1;
1900 if (size
> 4 || is_unpriv
) {
1901 unallocated_encoding(s
);
1904 is_store
= ((opc
& 1) == 0);
1906 if (size
== 3 && opc
== 2) {
1907 /* PRFM - prefetch */
1909 unallocated_encoding(s
);
1914 if (opc
== 3 && size
> 1) {
1915 unallocated_encoding(s
);
1918 is_store
= (opc
== 0);
1919 is_signed
= opc
& (1<<1);
1920 is_extended
= (size
< 3) && (opc
& 1);
1940 gen_check_sp_alignment(s
);
1942 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1945 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
1950 do_fp_st(s
, rt
, tcg_addr
, size
);
1952 do_fp_ld(s
, rt
, tcg_addr
, size
);
1955 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1956 int memidx
= is_unpriv
? 1 : get_mem_index(s
);
1959 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
);
1961 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
1962 is_signed
, is_extended
, memidx
);
1967 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
1969 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
1971 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
1976 * C3.3.10 Load/store (register offset)
1978 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
1979 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
1980 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
1981 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
1984 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
1985 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
1987 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
1988 * opc<0>: 0 -> store, 1 -> load
1989 * V: 1 -> vector/simd
1990 * opt: extend encoding (see DecodeRegExtend)
1991 * S: if S=1 then scale (essentially index by sizeof(size))
1992 * Rt: register to transfer into/out of
1993 * Rn: address register or SP for base
1994 * Rm: offset register or ZR for offset
1996 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
)
1998 int rt
= extract32(insn
, 0, 5);
1999 int rn
= extract32(insn
, 5, 5);
2000 int shift
= extract32(insn
, 12, 1);
2001 int rm
= extract32(insn
, 16, 5);
2002 int opc
= extract32(insn
, 22, 2);
2003 int opt
= extract32(insn
, 13, 3);
2004 int size
= extract32(insn
, 30, 2);
2005 bool is_signed
= false;
2006 bool is_store
= false;
2007 bool is_extended
= false;
2008 bool is_vector
= extract32(insn
, 26, 1);
2013 if (extract32(opt
, 1, 1) == 0) {
2014 unallocated_encoding(s
);
2019 size
|= (opc
& 2) << 1;
2021 unallocated_encoding(s
);
2024 is_store
= !extract32(opc
, 0, 1);
2026 if (size
== 3 && opc
== 2) {
2027 /* PRFM - prefetch */
2030 if (opc
== 3 && size
> 1) {
2031 unallocated_encoding(s
);
2034 is_store
= (opc
== 0);
2035 is_signed
= extract32(opc
, 1, 1);
2036 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2040 gen_check_sp_alignment(s
);
2042 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2044 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2045 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2047 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2051 do_fp_st(s
, rt
, tcg_addr
, size
);
2053 do_fp_ld(s
, rt
, tcg_addr
, size
);
2056 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2058 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2060 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2066 * C3.3.13 Load/store (unsigned immediate)
2068 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2069 * +----+-------+---+-----+-----+------------+-------+------+
2070 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2071 * +----+-------+---+-----+-----+------------+-------+------+
2074 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2075 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2077 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2078 * opc<0>: 0 -> store, 1 -> load
2079 * Rn: base address register (inc SP)
2080 * Rt: target register
2082 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
)
2084 int rt
= extract32(insn
, 0, 5);
2085 int rn
= extract32(insn
, 5, 5);
2086 unsigned int imm12
= extract32(insn
, 10, 12);
2087 bool is_vector
= extract32(insn
, 26, 1);
2088 int size
= extract32(insn
, 30, 2);
2089 int opc
= extract32(insn
, 22, 2);
2090 unsigned int offset
;
2095 bool is_signed
= false;
2096 bool is_extended
= false;
2099 size
|= (opc
& 2) << 1;
2101 unallocated_encoding(s
);
2104 is_store
= !extract32(opc
, 0, 1);
2106 if (size
== 3 && opc
== 2) {
2107 /* PRFM - prefetch */
2110 if (opc
== 3 && size
> 1) {
2111 unallocated_encoding(s
);
2114 is_store
= (opc
== 0);
2115 is_signed
= extract32(opc
, 1, 1);
2116 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2120 gen_check_sp_alignment(s
);
2122 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2123 offset
= imm12
<< size
;
2124 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2128 do_fp_st(s
, rt
, tcg_addr
, size
);
2130 do_fp_ld(s
, rt
, tcg_addr
, size
);
2133 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2135 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2137 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2142 /* Load/store register (all forms) */
2143 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2145 switch (extract32(insn
, 24, 2)) {
2147 if (extract32(insn
, 21, 1) == 1 && extract32(insn
, 10, 2) == 2) {
2148 disas_ldst_reg_roffset(s
, insn
);
2150 /* Load/store register (unscaled immediate)
2151 * Load/store immediate pre/post-indexed
2152 * Load/store register unprivileged
2154 disas_ldst_reg_imm9(s
, insn
);
2158 disas_ldst_reg_unsigned_imm(s
, insn
);
2161 unallocated_encoding(s
);
2166 /* C3.3.1 AdvSIMD load/store multiple structures
2168 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2169 * +---+---+---------------+---+-------------+--------+------+------+------+
2170 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2171 * +---+---+---------------+---+-------------+--------+------+------+------+
2173 * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
2175 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2176 * +---+---+---------------+---+---+---------+--------+------+------+------+
2177 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2178 * +---+---+---------------+---+---+---------+--------+------+------+------+
2180 * Rt: first (or only) SIMD&FP register to be transferred
2181 * Rn: base address or SP
2182 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2184 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2186 int rt
= extract32(insn
, 0, 5);
2187 int rn
= extract32(insn
, 5, 5);
2188 int size
= extract32(insn
, 10, 2);
2189 int opcode
= extract32(insn
, 12, 4);
2190 bool is_store
= !extract32(insn
, 22, 1);
2191 bool is_postidx
= extract32(insn
, 23, 1);
2192 bool is_q
= extract32(insn
, 30, 1);
2193 TCGv_i64 tcg_addr
, tcg_rn
;
2195 int ebytes
= 1 << size
;
2196 int elements
= (is_q
? 128 : 64) / (8 << size
);
2197 int rpt
; /* num iterations */
2198 int selem
; /* structure elements */
2201 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2202 unallocated_encoding(s
);
2206 /* From the shared decode logic */
2237 unallocated_encoding(s
);
2241 if (size
== 3 && !is_q
&& selem
!= 1) {
2243 unallocated_encoding(s
);
2248 gen_check_sp_alignment(s
);
2251 tcg_rn
= cpu_reg_sp(s
, rn
);
2252 tcg_addr
= tcg_temp_new_i64();
2253 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2255 for (r
= 0; r
< rpt
; r
++) {
2257 for (e
= 0; e
< elements
; e
++) {
2258 int tt
= (rt
+ r
) % 32;
2260 for (xs
= 0; xs
< selem
; xs
++) {
2262 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
2264 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
2266 /* For non-quad operations, setting a slice of the low
2267 * 64 bits of the register clears the high 64 bits (in
2268 * the ARM ARM pseudocode this is implicit in the fact
2269 * that 'rval' is a 64 bit wide variable). We optimize
2270 * by noticing that we only need to do this the first
2271 * time we touch a register.
2273 if (!is_q
&& e
== 0 && (r
== 0 || xs
== selem
- 1)) {
2274 clear_vec_high(s
, tt
);
2277 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2284 int rm
= extract32(insn
, 16, 5);
2286 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2288 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2291 tcg_temp_free_i64(tcg_addr
);
2294 /* C3.3.3 AdvSIMD load/store single structure
2296 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2297 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2298 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
2299 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2301 * C3.3.4 AdvSIMD load/store single structure (post-indexed)
2303 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2304 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2305 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
2306 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2308 * Rt: first (or only) SIMD&FP register to be transferred
2309 * Rn: base address or SP
2310 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2311 * index = encoded in Q:S:size dependent on size
2313 * lane_size = encoded in R, opc
2314 * transfer width = encoded in opc, S, size
2316 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
2318 int rt
= extract32(insn
, 0, 5);
2319 int rn
= extract32(insn
, 5, 5);
2320 int size
= extract32(insn
, 10, 2);
2321 int S
= extract32(insn
, 12, 1);
2322 int opc
= extract32(insn
, 13, 3);
2323 int R
= extract32(insn
, 21, 1);
2324 int is_load
= extract32(insn
, 22, 1);
2325 int is_postidx
= extract32(insn
, 23, 1);
2326 int is_q
= extract32(insn
, 30, 1);
2328 int scale
= extract32(opc
, 1, 2);
2329 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
2330 bool replicate
= false;
2331 int index
= is_q
<< 3 | S
<< 2 | size
;
2333 TCGv_i64 tcg_addr
, tcg_rn
;
2337 if (!is_load
|| S
) {
2338 unallocated_encoding(s
);
2347 if (extract32(size
, 0, 1)) {
2348 unallocated_encoding(s
);
2354 if (extract32(size
, 1, 1)) {
2355 unallocated_encoding(s
);
2358 if (!extract32(size
, 0, 1)) {
2362 unallocated_encoding(s
);
2370 g_assert_not_reached();
2373 ebytes
= 1 << scale
;
2376 gen_check_sp_alignment(s
);
2379 tcg_rn
= cpu_reg_sp(s
, rn
);
2380 tcg_addr
= tcg_temp_new_i64();
2381 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2383 for (xs
= 0; xs
< selem
; xs
++) {
2385 /* Load and replicate to all elements */
2387 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
2389 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
2390 get_mem_index(s
), MO_TE
+ scale
);
2393 mulconst
= 0x0101010101010101ULL
;
2396 mulconst
= 0x0001000100010001ULL
;
2399 mulconst
= 0x0000000100000001ULL
;
2405 g_assert_not_reached();
2408 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
2410 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
2412 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
2414 clear_vec_high(s
, rt
);
2416 tcg_temp_free_i64(tcg_tmp
);
2418 /* Load/store one element per register */
2420 do_vec_ld(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2422 do_vec_st(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2425 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2430 int rm
= extract32(insn
, 16, 5);
2432 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2434 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2437 tcg_temp_free_i64(tcg_addr
);
2440 /* C3.3 Loads and stores */
2441 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
2443 switch (extract32(insn
, 24, 6)) {
2444 case 0x08: /* Load/store exclusive */
2445 disas_ldst_excl(s
, insn
);
2447 case 0x18: case 0x1c: /* Load register (literal) */
2448 disas_ld_lit(s
, insn
);
2450 case 0x28: case 0x29:
2451 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
2452 disas_ldst_pair(s
, insn
);
2454 case 0x38: case 0x39:
2455 case 0x3c: case 0x3d: /* Load/store register (all forms) */
2456 disas_ldst_reg(s
, insn
);
2458 case 0x0c: /* AdvSIMD load/store multiple structures */
2459 disas_ldst_multiple_struct(s
, insn
);
2461 case 0x0d: /* AdvSIMD load/store single structure */
2462 disas_ldst_single_struct(s
, insn
);
2465 unallocated_encoding(s
);
2470 /* C3.4.6 PC-rel. addressing
2471 * 31 30 29 28 24 23 5 4 0
2472 * +----+-------+-----------+-------------------+------+
2473 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
2474 * +----+-------+-----------+-------------------+------+
2476 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
2478 unsigned int page
, rd
;
2482 page
= extract32(insn
, 31, 1);
2483 /* SignExtend(immhi:immlo) -> offset */
2484 offset
= ((int64_t)sextract32(insn
, 5, 19) << 2) | extract32(insn
, 29, 2);
2485 rd
= extract32(insn
, 0, 5);
2489 /* ADRP (page based) */
2494 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
2498 * C3.4.1 Add/subtract (immediate)
2500 * 31 30 29 28 24 23 22 21 10 9 5 4 0
2501 * +--+--+--+-----------+-----+-------------+-----+-----+
2502 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
2503 * +--+--+--+-----------+-----+-------------+-----+-----+
2505 * sf: 0 -> 32bit, 1 -> 64bit
2506 * op: 0 -> add , 1 -> sub
2508 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
2510 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
2512 int rd
= extract32(insn
, 0, 5);
2513 int rn
= extract32(insn
, 5, 5);
2514 uint64_t imm
= extract32(insn
, 10, 12);
2515 int shift
= extract32(insn
, 22, 2);
2516 bool setflags
= extract32(insn
, 29, 1);
2517 bool sub_op
= extract32(insn
, 30, 1);
2518 bool is_64bit
= extract32(insn
, 31, 1);
2520 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2521 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
2522 TCGv_i64 tcg_result
;
2531 unallocated_encoding(s
);
2535 tcg_result
= tcg_temp_new_i64();
2538 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
2540 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
2543 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
2545 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2547 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2549 tcg_temp_free_i64(tcg_imm
);
2553 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
2555 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
2558 tcg_temp_free_i64(tcg_result
);
2561 /* The input should be a value in the bottom e bits (with higher
2562 * bits zero); returns that value replicated into every element
2563 * of size e in a 64 bit integer.
2565 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
2575 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
2576 static inline uint64_t bitmask64(unsigned int length
)
2578 assert(length
> 0 && length
<= 64);
2579 return ~0ULL >> (64 - length
);
2582 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
2583 * only require the wmask. Returns false if the imms/immr/immn are a reserved
2584 * value (ie should cause a guest UNDEF exception), and true if they are
2585 * valid, in which case the decoded bit pattern is written to result.
2587 static bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
2588 unsigned int imms
, unsigned int immr
)
2591 unsigned e
, levels
, s
, r
;
2594 assert(immn
< 2 && imms
< 64 && immr
< 64);
2596 /* The bit patterns we create here are 64 bit patterns which
2597 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
2598 * 64 bits each. Each element contains the same value: a run
2599 * of between 1 and e-1 non-zero bits, rotated within the
2600 * element by between 0 and e-1 bits.
2602 * The element size and run length are encoded into immn (1 bit)
2603 * and imms (6 bits) as follows:
2604 * 64 bit elements: immn = 1, imms = <length of run - 1>
2605 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
2606 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
2607 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
2608 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
2609 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
2610 * Notice that immn = 0, imms = 11111x is the only combination
2611 * not covered by one of the above options; this is reserved.
2612 * Further, <length of run - 1> all-ones is a reserved pattern.
2614 * In all cases the rotation is by immr % e (and immr is 6 bits).
2617 /* First determine the element size */
2618 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
2620 /* This is the immn == 0, imms == 0x11111x case */
2630 /* <length of run - 1> mustn't be all-ones. */
2634 /* Create the value of one element: s+1 set bits rotated
2635 * by r within the element (which is e bits wide)...
2637 mask
= bitmask64(s
+ 1);
2638 mask
= (mask
>> r
) | (mask
<< (e
- r
));
2639 /* ...then replicate the element over the whole 64 bit value */
2640 mask
= bitfield_replicate(mask
, e
);
2645 /* C3.4.4 Logical (immediate)
2646 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2647 * +----+-----+-------------+---+------+------+------+------+
2648 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
2649 * +----+-----+-------------+---+------+------+------+------+
2651 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
2653 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
2654 TCGv_i64 tcg_rd
, tcg_rn
;
2656 bool is_and
= false;
2658 sf
= extract32(insn
, 31, 1);
2659 opc
= extract32(insn
, 29, 2);
2660 is_n
= extract32(insn
, 22, 1);
2661 immr
= extract32(insn
, 16, 6);
2662 imms
= extract32(insn
, 10, 6);
2663 rn
= extract32(insn
, 5, 5);
2664 rd
= extract32(insn
, 0, 5);
2667 unallocated_encoding(s
);
2671 if (opc
== 0x3) { /* ANDS */
2672 tcg_rd
= cpu_reg(s
, rd
);
2674 tcg_rd
= cpu_reg_sp(s
, rd
);
2676 tcg_rn
= cpu_reg(s
, rn
);
2678 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
2679 /* some immediate field values are reserved */
2680 unallocated_encoding(s
);
2685 wmask
&= 0xffffffff;
2689 case 0x3: /* ANDS */
2691 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
2695 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
2698 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
2701 assert(FALSE
); /* must handle all above */
2705 if (!sf
&& !is_and
) {
2706 /* zero extend final result; we know we can skip this for AND
2707 * since the immediate had the high 32 bits clear.
2709 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2712 if (opc
== 3) { /* ANDS */
2713 gen_logic_CC(sf
, tcg_rd
);
2718 * C3.4.5 Move wide (immediate)
2720 * 31 30 29 28 23 22 21 20 5 4 0
2721 * +--+-----+-------------+-----+----------------+------+
2722 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
2723 * +--+-----+-------------+-----+----------------+------+
2725 * sf: 0 -> 32 bit, 1 -> 64 bit
2726 * opc: 00 -> N, 10 -> Z, 11 -> K
2727 * hw: shift/16 (0,16, and sf only 32, 48)
2729 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
2731 int rd
= extract32(insn
, 0, 5);
2732 uint64_t imm
= extract32(insn
, 5, 16);
2733 int sf
= extract32(insn
, 31, 1);
2734 int opc
= extract32(insn
, 29, 2);
2735 int pos
= extract32(insn
, 21, 2) << 4;
2736 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
2739 if (!sf
&& (pos
>= 32)) {
2740 unallocated_encoding(s
);
2754 tcg_gen_movi_i64(tcg_rd
, imm
);
2757 tcg_imm
= tcg_const_i64(imm
);
2758 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
2759 tcg_temp_free_i64(tcg_imm
);
2761 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2765 unallocated_encoding(s
);
2771 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2772 * +----+-----+-------------+---+------+------+------+------+
2773 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
2774 * +----+-----+-------------+---+------+------+------+------+
2776 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
2778 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
2779 TCGv_i64 tcg_rd
, tcg_tmp
;
2781 sf
= extract32(insn
, 31, 1);
2782 opc
= extract32(insn
, 29, 2);
2783 n
= extract32(insn
, 22, 1);
2784 ri
= extract32(insn
, 16, 6);
2785 si
= extract32(insn
, 10, 6);
2786 rn
= extract32(insn
, 5, 5);
2787 rd
= extract32(insn
, 0, 5);
2788 bitsize
= sf
? 64 : 32;
2790 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
2791 unallocated_encoding(s
);
2795 tcg_rd
= cpu_reg(s
, rd
);
2796 tcg_tmp
= read_cpu_reg(s
, rn
, sf
);
2798 /* OPTME: probably worth recognizing common cases of ext{8,16,32}{u,s} */
2800 if (opc
!= 1) { /* SBFM or UBFM */
2801 tcg_gen_movi_i64(tcg_rd
, 0);
2804 /* do the bit move operation */
2806 /* Wd<s-r:0> = Wn<s:r> */
2807 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
2809 len
= (si
- ri
) + 1;
2811 /* Wd<32+s-r,32-r> = Wn<s:0> */
2816 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
2818 if (opc
== 0) { /* SBFM - sign extend the destination field */
2819 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
2820 tcg_gen_sari_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
2823 if (!sf
) { /* zero extend final result */
2824 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2829 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
2830 * +----+------+-------------+---+----+------+--------+------+------+
2831 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
2832 * +----+------+-------------+---+----+------+--------+------+------+
2834 static void disas_extract(DisasContext
*s
, uint32_t insn
)
2836 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
2838 sf
= extract32(insn
, 31, 1);
2839 n
= extract32(insn
, 22, 1);
2840 rm
= extract32(insn
, 16, 5);
2841 imm
= extract32(insn
, 10, 6);
2842 rn
= extract32(insn
, 5, 5);
2843 rd
= extract32(insn
, 0, 5);
2844 op21
= extract32(insn
, 29, 2);
2845 op0
= extract32(insn
, 21, 1);
2846 bitsize
= sf
? 64 : 32;
2848 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
2849 unallocated_encoding(s
);
2851 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
2853 tcg_rd
= cpu_reg(s
, rd
);
2856 /* OPTME: we can special case rm==rn as a rotate */
2857 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
2858 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
2859 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
2860 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
2861 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
2863 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2866 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
2867 * so an extract from bit 0 is a special case.
2870 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
2872 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
2879 /* C3.4 Data processing - immediate */
2880 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
2882 switch (extract32(insn
, 23, 6)) {
2883 case 0x20: case 0x21: /* PC-rel. addressing */
2884 disas_pc_rel_adr(s
, insn
);
2886 case 0x22: case 0x23: /* Add/subtract (immediate) */
2887 disas_add_sub_imm(s
, insn
);
2889 case 0x24: /* Logical (immediate) */
2890 disas_logic_imm(s
, insn
);
2892 case 0x25: /* Move wide (immediate) */
2893 disas_movw_imm(s
, insn
);
2895 case 0x26: /* Bitfield */
2896 disas_bitfield(s
, insn
);
2898 case 0x27: /* Extract */
2899 disas_extract(s
, insn
);
2902 unallocated_encoding(s
);
2907 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
2908 * Note that it is the caller's responsibility to ensure that the
2909 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
2910 * mandated semantics for out of range shifts.
2912 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
2913 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
2915 switch (shift_type
) {
2916 case A64_SHIFT_TYPE_LSL
:
2917 tcg_gen_shl_i64(dst
, src
, shift_amount
);
2919 case A64_SHIFT_TYPE_LSR
:
2920 tcg_gen_shr_i64(dst
, src
, shift_amount
);
2922 case A64_SHIFT_TYPE_ASR
:
2924 tcg_gen_ext32s_i64(dst
, src
);
2926 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
2928 case A64_SHIFT_TYPE_ROR
:
2930 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
2933 t0
= tcg_temp_new_i32();
2934 t1
= tcg_temp_new_i32();
2935 tcg_gen_trunc_i64_i32(t0
, src
);
2936 tcg_gen_trunc_i64_i32(t1
, shift_amount
);
2937 tcg_gen_rotr_i32(t0
, t0
, t1
);
2938 tcg_gen_extu_i32_i64(dst
, t0
);
2939 tcg_temp_free_i32(t0
);
2940 tcg_temp_free_i32(t1
);
2944 assert(FALSE
); /* all shift types should be handled */
2948 if (!sf
) { /* zero extend final result */
2949 tcg_gen_ext32u_i64(dst
, dst
);
2953 /* Shift a TCGv src by immediate, put result in dst.
2954 * The shift amount must be in range (this should always be true as the
2955 * relevant instructions will UNDEF on bad shift immediates).
2957 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
2958 enum a64_shift_type shift_type
, unsigned int shift_i
)
2960 assert(shift_i
< (sf
? 64 : 32));
2963 tcg_gen_mov_i64(dst
, src
);
2965 TCGv_i64 shift_const
;
2967 shift_const
= tcg_const_i64(shift_i
);
2968 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
2969 tcg_temp_free_i64(shift_const
);
2973 /* C3.5.10 Logical (shifted register)
2974 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
2975 * +----+-----+-----------+-------+---+------+--------+------+------+
2976 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
2977 * +----+-----+-----------+-------+---+------+--------+------+------+
2979 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
2981 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
2982 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
2984 sf
= extract32(insn
, 31, 1);
2985 opc
= extract32(insn
, 29, 2);
2986 shift_type
= extract32(insn
, 22, 2);
2987 invert
= extract32(insn
, 21, 1);
2988 rm
= extract32(insn
, 16, 5);
2989 shift_amount
= extract32(insn
, 10, 6);
2990 rn
= extract32(insn
, 5, 5);
2991 rd
= extract32(insn
, 0, 5);
2993 if (!sf
&& (shift_amount
& (1 << 5))) {
2994 unallocated_encoding(s
);
2998 tcg_rd
= cpu_reg(s
, rd
);
3000 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3001 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3002 * register-register MOV and MVN, so it is worth special casing.
3004 tcg_rm
= cpu_reg(s
, rm
);
3006 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3008 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3012 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3014 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3020 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3023 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3026 tcg_rn
= cpu_reg(s
, rn
);
3028 switch (opc
| (invert
<< 2)) {
3031 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3034 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3037 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3041 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3044 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3047 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3055 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3059 gen_logic_CC(sf
, tcg_rd
);
3064 * C3.5.1 Add/subtract (extended register)
3066 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3067 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3068 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3069 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3071 * sf: 0 -> 32bit, 1 -> 64bit
3072 * op: 0 -> add , 1 -> sub
3075 * option: extension type (see DecodeRegExtend)
3076 * imm3: optional shift to Rm
3078 * Rd = Rn + LSL(extend(Rm), amount)
3080 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3082 int rd
= extract32(insn
, 0, 5);
3083 int rn
= extract32(insn
, 5, 5);
3084 int imm3
= extract32(insn
, 10, 3);
3085 int option
= extract32(insn
, 13, 3);
3086 int rm
= extract32(insn
, 16, 5);
3087 bool setflags
= extract32(insn
, 29, 1);
3088 bool sub_op
= extract32(insn
, 30, 1);
3089 bool sf
= extract32(insn
, 31, 1);
3091 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3093 TCGv_i64 tcg_result
;
3096 unallocated_encoding(s
);
3100 /* non-flag setting ops may use SP */
3102 tcg_rd
= cpu_reg_sp(s
, rd
);
3104 tcg_rd
= cpu_reg(s
, rd
);
3106 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3108 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3109 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3111 tcg_result
= tcg_temp_new_i64();
3115 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3117 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3121 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3123 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3128 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3130 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3133 tcg_temp_free_i64(tcg_result
);
3137 * C3.5.2 Add/subtract (shifted register)
3139 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3140 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3141 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3142 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3144 * sf: 0 -> 32bit, 1 -> 64bit
3145 * op: 0 -> add , 1 -> sub
3147 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3148 * imm6: Shift amount to apply to Rm before the add/sub
3150 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3152 int rd
= extract32(insn
, 0, 5);
3153 int rn
= extract32(insn
, 5, 5);
3154 int imm6
= extract32(insn
, 10, 6);
3155 int rm
= extract32(insn
, 16, 5);
3156 int shift_type
= extract32(insn
, 22, 2);
3157 bool setflags
= extract32(insn
, 29, 1);
3158 bool sub_op
= extract32(insn
, 30, 1);
3159 bool sf
= extract32(insn
, 31, 1);
3161 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3162 TCGv_i64 tcg_rn
, tcg_rm
;
3163 TCGv_i64 tcg_result
;
3165 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3166 unallocated_encoding(s
);
3170 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3171 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3173 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3175 tcg_result
= tcg_temp_new_i64();
3179 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3181 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3185 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3187 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3192 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3194 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3197 tcg_temp_free_i64(tcg_result
);
3200 /* C3.5.9 Data-processing (3 source)
3202 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3203 +--+------+-----------+------+------+----+------+------+------+
3204 |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3205 +--+------+-----------+------+------+----+------+------+------+
3208 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
3210 int rd
= extract32(insn
, 0, 5);
3211 int rn
= extract32(insn
, 5, 5);
3212 int ra
= extract32(insn
, 10, 5);
3213 int rm
= extract32(insn
, 16, 5);
3214 int op_id
= (extract32(insn
, 29, 3) << 4) |
3215 (extract32(insn
, 21, 3) << 1) |
3216 extract32(insn
, 15, 1);
3217 bool sf
= extract32(insn
, 31, 1);
3218 bool is_sub
= extract32(op_id
, 0, 1);
3219 bool is_high
= extract32(op_id
, 2, 1);
3220 bool is_signed
= false;
3225 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
3227 case 0x42: /* SMADDL */
3228 case 0x43: /* SMSUBL */
3229 case 0x44: /* SMULH */
3232 case 0x0: /* MADD (32bit) */
3233 case 0x1: /* MSUB (32bit) */
3234 case 0x40: /* MADD (64bit) */
3235 case 0x41: /* MSUB (64bit) */
3236 case 0x4a: /* UMADDL */
3237 case 0x4b: /* UMSUBL */
3238 case 0x4c: /* UMULH */
3241 unallocated_encoding(s
);
3246 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
3247 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3248 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
3249 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
3252 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3254 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3257 tcg_temp_free_i64(low_bits
);
3261 tcg_op1
= tcg_temp_new_i64();
3262 tcg_op2
= tcg_temp_new_i64();
3263 tcg_tmp
= tcg_temp_new_i64();
3266 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
3267 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
3270 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
3271 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
3273 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
3274 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
3278 if (ra
== 31 && !is_sub
) {
3279 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
3280 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
3282 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
3284 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3286 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3291 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
3294 tcg_temp_free_i64(tcg_op1
);
3295 tcg_temp_free_i64(tcg_op2
);
3296 tcg_temp_free_i64(tcg_tmp
);
3299 /* C3.5.3 - Add/subtract (with carry)
3300 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
3301 * +--+--+--+------------------------+------+---------+------+-----+
3302 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
3303 * +--+--+--+------------------------+------+---------+------+-----+
3307 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
3309 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
3310 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
3312 if (extract32(insn
, 10, 6) != 0) {
3313 unallocated_encoding(s
);
3317 sf
= extract32(insn
, 31, 1);
3318 op
= extract32(insn
, 30, 1);
3319 setflags
= extract32(insn
, 29, 1);
3320 rm
= extract32(insn
, 16, 5);
3321 rn
= extract32(insn
, 5, 5);
3322 rd
= extract32(insn
, 0, 5);
3324 tcg_rd
= cpu_reg(s
, rd
);
3325 tcg_rn
= cpu_reg(s
, rn
);
3328 tcg_y
= new_tmp_a64(s
);
3329 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
3331 tcg_y
= cpu_reg(s
, rm
);
3335 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3337 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3341 /* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
3342 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3343 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3344 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
3345 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3348 static void disas_cc(DisasContext
*s
, uint32_t insn
)
3350 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
3351 int label_continue
= -1;
3352 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
3354 if (!extract32(insn
, 29, 1)) {
3355 unallocated_encoding(s
);
3358 if (insn
& (1 << 10 | 1 << 4)) {
3359 unallocated_encoding(s
);
3362 sf
= extract32(insn
, 31, 1);
3363 op
= extract32(insn
, 30, 1);
3364 is_imm
= extract32(insn
, 11, 1);
3365 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
3366 cond
= extract32(insn
, 12, 4);
3367 rn
= extract32(insn
, 5, 5);
3368 nzcv
= extract32(insn
, 0, 4);
3370 if (cond
< 0x0e) { /* not always */
3371 int label_match
= gen_new_label();
3372 label_continue
= gen_new_label();
3373 arm_gen_test_cc(cond
, label_match
);
3375 tcg_tmp
= tcg_temp_new_i64();
3376 tcg_gen_movi_i64(tcg_tmp
, nzcv
<< 28);
3377 gen_set_nzcv(tcg_tmp
);
3378 tcg_temp_free_i64(tcg_tmp
);
3379 tcg_gen_br(label_continue
);
3380 gen_set_label(label_match
);
3382 /* match, or condition is always */
3384 tcg_y
= new_tmp_a64(s
);
3385 tcg_gen_movi_i64(tcg_y
, y
);
3387 tcg_y
= cpu_reg(s
, y
);
3389 tcg_rn
= cpu_reg(s
, rn
);
3391 tcg_tmp
= tcg_temp_new_i64();
3393 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3395 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3397 tcg_temp_free_i64(tcg_tmp
);
3399 if (cond
< 0x0e) { /* continue */
3400 gen_set_label(label_continue
);
3404 /* C3.5.6 Conditional select
3405 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
3406 * +----+----+---+-----------------+------+------+-----+------+------+
3407 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
3408 * +----+----+---+-----------------+------+------+-----+------+------+
3410 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
3412 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
3413 TCGv_i64 tcg_rd
, tcg_src
;
3415 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
3416 /* S == 1 or op2<1> == 1 */
3417 unallocated_encoding(s
);
3420 sf
= extract32(insn
, 31, 1);
3421 else_inv
= extract32(insn
, 30, 1);
3422 rm
= extract32(insn
, 16, 5);
3423 cond
= extract32(insn
, 12, 4);
3424 else_inc
= extract32(insn
, 10, 1);
3425 rn
= extract32(insn
, 5, 5);
3426 rd
= extract32(insn
, 0, 5);
3429 /* silly no-op write; until we use movcond we must special-case
3430 * this to avoid a dead temporary across basic blocks.
3435 tcg_rd
= cpu_reg(s
, rd
);
3437 if (cond
>= 0x0e) { /* condition "always" */
3438 tcg_src
= read_cpu_reg(s
, rn
, sf
);
3439 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3441 /* OPTME: we could use movcond here, at the cost of duplicating
3442 * a lot of the arm_gen_test_cc() logic.
3444 int label_match
= gen_new_label();
3445 int label_continue
= gen_new_label();
3447 arm_gen_test_cc(cond
, label_match
);
3449 tcg_src
= cpu_reg(s
, rm
);
3451 if (else_inv
&& else_inc
) {
3452 tcg_gen_neg_i64(tcg_rd
, tcg_src
);
3453 } else if (else_inv
) {
3454 tcg_gen_not_i64(tcg_rd
, tcg_src
);
3455 } else if (else_inc
) {
3456 tcg_gen_addi_i64(tcg_rd
, tcg_src
, 1);
3458 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3461 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3463 tcg_gen_br(label_continue
);
3465 gen_set_label(label_match
);
3466 tcg_src
= read_cpu_reg(s
, rn
, sf
);
3467 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3469 gen_set_label(label_continue
);
3473 static void handle_clz(DisasContext
*s
, unsigned int sf
,
3474 unsigned int rn
, unsigned int rd
)
3476 TCGv_i64 tcg_rd
, tcg_rn
;
3477 tcg_rd
= cpu_reg(s
, rd
);
3478 tcg_rn
= cpu_reg(s
, rn
);
3481 gen_helper_clz64(tcg_rd
, tcg_rn
);
3483 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3484 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3485 gen_helper_clz(tcg_tmp32
, tcg_tmp32
);
3486 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3487 tcg_temp_free_i32(tcg_tmp32
);
3491 static void handle_cls(DisasContext
*s
, unsigned int sf
,
3492 unsigned int rn
, unsigned int rd
)
3494 TCGv_i64 tcg_rd
, tcg_rn
;
3495 tcg_rd
= cpu_reg(s
, rd
);
3496 tcg_rn
= cpu_reg(s
, rn
);
3499 gen_helper_cls64(tcg_rd
, tcg_rn
);
3501 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3502 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3503 gen_helper_cls32(tcg_tmp32
, tcg_tmp32
);
3504 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3505 tcg_temp_free_i32(tcg_tmp32
);
3509 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
3510 unsigned int rn
, unsigned int rd
)
3512 TCGv_i64 tcg_rd
, tcg_rn
;
3513 tcg_rd
= cpu_reg(s
, rd
);
3514 tcg_rn
= cpu_reg(s
, rn
);
3517 gen_helper_rbit64(tcg_rd
, tcg_rn
);
3519 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3520 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3521 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
3522 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3523 tcg_temp_free_i32(tcg_tmp32
);
3527 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
3528 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
3529 unsigned int rn
, unsigned int rd
)
3532 unallocated_encoding(s
);
3535 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
3538 /* C5.6.149 REV with sf==0, opcode==2
3539 * C5.6.151 REV32 (sf==1, opcode==2)
3541 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
3542 unsigned int rn
, unsigned int rd
)
3544 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3547 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3548 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3550 /* bswap32_i64 requires zero high word */
3551 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
3552 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
3553 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3554 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
3555 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
3557 tcg_temp_free_i64(tcg_tmp
);
3559 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
3560 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
3564 /* C5.6.150 REV16 (opcode==1) */
3565 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
3566 unsigned int rn
, unsigned int rd
)
3568 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3569 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3570 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3572 tcg_gen_andi_i64(tcg_tmp
, tcg_rn
, 0xffff);
3573 tcg_gen_bswap16_i64(tcg_rd
, tcg_tmp
);
3575 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 16);
3576 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3577 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3578 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 16, 16);
3581 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3582 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3583 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3584 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 32, 16);
3586 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 48);
3587 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3588 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 48, 16);
3591 tcg_temp_free_i64(tcg_tmp
);
3594 /* C3.5.7 Data-processing (1 source)
3595 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3596 * +----+---+---+-----------------+---------+--------+------+------+
3597 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
3598 * +----+---+---+-----------------+---------+--------+------+------+
3600 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
3602 unsigned int sf
, opcode
, rn
, rd
;
3604 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
3605 unallocated_encoding(s
);
3609 sf
= extract32(insn
, 31, 1);
3610 opcode
= extract32(insn
, 10, 6);
3611 rn
= extract32(insn
, 5, 5);
3612 rd
= extract32(insn
, 0, 5);
3616 handle_rbit(s
, sf
, rn
, rd
);
3619 handle_rev16(s
, sf
, rn
, rd
);
3622 handle_rev32(s
, sf
, rn
, rd
);
3625 handle_rev64(s
, sf
, rn
, rd
);
3628 handle_clz(s
, sf
, rn
, rd
);
3631 handle_cls(s
, sf
, rn
, rd
);
3636 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
3637 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3639 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
3640 tcg_rd
= cpu_reg(s
, rd
);
3642 if (!sf
&& is_signed
) {
3643 tcg_n
= new_tmp_a64(s
);
3644 tcg_m
= new_tmp_a64(s
);
3645 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
3646 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
3648 tcg_n
= read_cpu_reg(s
, rn
, sf
);
3649 tcg_m
= read_cpu_reg(s
, rm
, sf
);
3653 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
3655 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
3658 if (!sf
) { /* zero extend final result */
3659 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3663 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
3664 static void handle_shift_reg(DisasContext
*s
,
3665 enum a64_shift_type shift_type
, unsigned int sf
,
3666 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3668 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
3669 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3670 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3672 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
3673 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
3674 tcg_temp_free_i64(tcg_shift
);
3677 /* C3.5.8 Data-processing (2 source)
3678 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3679 * +----+---+---+-----------------+------+--------+------+------+
3680 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
3681 * +----+---+---+-----------------+------+--------+------+------+
3683 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
3685 unsigned int sf
, rm
, opcode
, rn
, rd
;
3686 sf
= extract32(insn
, 31, 1);
3687 rm
= extract32(insn
, 16, 5);
3688 opcode
= extract32(insn
, 10, 6);
3689 rn
= extract32(insn
, 5, 5);
3690 rd
= extract32(insn
, 0, 5);
3692 if (extract32(insn
, 29, 1)) {
3693 unallocated_encoding(s
);
3699 handle_div(s
, false, sf
, rm
, rn
, rd
);
3702 handle_div(s
, true, sf
, rm
, rn
, rd
);
3705 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
3708 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
3711 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
3714 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
3723 case 23: /* CRC32 */
3724 unsupported_encoding(s
, insn
);
3727 unallocated_encoding(s
);
3732 /* C3.5 Data processing - register */
3733 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
3735 switch (extract32(insn
, 24, 5)) {
3736 case 0x0a: /* Logical (shifted register) */
3737 disas_logic_reg(s
, insn
);
3739 case 0x0b: /* Add/subtract */
3740 if (insn
& (1 << 21)) { /* (extended register) */
3741 disas_add_sub_ext_reg(s
, insn
);
3743 disas_add_sub_reg(s
, insn
);
3746 case 0x1b: /* Data-processing (3 source) */
3747 disas_data_proc_3src(s
, insn
);
3750 switch (extract32(insn
, 21, 3)) {
3751 case 0x0: /* Add/subtract (with carry) */
3752 disas_adc_sbc(s
, insn
);
3754 case 0x2: /* Conditional compare */
3755 disas_cc(s
, insn
); /* both imm and reg forms */
3757 case 0x4: /* Conditional select */
3758 disas_cond_select(s
, insn
);
3760 case 0x6: /* Data-processing */
3761 if (insn
& (1 << 30)) { /* (1 source) */
3762 disas_data_proc_1src(s
, insn
);
3763 } else { /* (2 source) */
3764 disas_data_proc_2src(s
, insn
);
3768 unallocated_encoding(s
);
3773 unallocated_encoding(s
);
3778 static void handle_fp_compare(DisasContext
*s
, bool is_double
,
3779 unsigned int rn
, unsigned int rm
,
3780 bool cmp_with_zero
, bool signal_all_nans
)
3782 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
3783 TCGv_ptr fpst
= get_fpstatus_ptr();
3786 TCGv_i64 tcg_vn
, tcg_vm
;
3788 tcg_vn
= read_fp_dreg(s
, rn
);
3789 if (cmp_with_zero
) {
3790 tcg_vm
= tcg_const_i64(0);
3792 tcg_vm
= read_fp_dreg(s
, rm
);
3794 if (signal_all_nans
) {
3795 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
3797 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
3799 tcg_temp_free_i64(tcg_vn
);
3800 tcg_temp_free_i64(tcg_vm
);
3802 TCGv_i32 tcg_vn
, tcg_vm
;
3804 tcg_vn
= read_fp_sreg(s
, rn
);
3805 if (cmp_with_zero
) {
3806 tcg_vm
= tcg_const_i32(0);
3808 tcg_vm
= read_fp_sreg(s
, rm
);
3810 if (signal_all_nans
) {
3811 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
3813 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
3815 tcg_temp_free_i32(tcg_vn
);
3816 tcg_temp_free_i32(tcg_vm
);
3819 tcg_temp_free_ptr(fpst
);
3821 gen_set_nzcv(tcg_flags
);
3823 tcg_temp_free_i64(tcg_flags
);
3826 /* C3.6.22 Floating point compare
3827 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
3828 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
3829 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
3830 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
3832 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
3834 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
3836 mos
= extract32(insn
, 29, 3);
3837 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
3838 rm
= extract32(insn
, 16, 5);
3839 op
= extract32(insn
, 14, 2);
3840 rn
= extract32(insn
, 5, 5);
3841 opc
= extract32(insn
, 3, 2);
3842 op2r
= extract32(insn
, 0, 3);
3844 if (mos
|| op
|| op2r
|| type
> 1) {
3845 unallocated_encoding(s
);
3849 handle_fp_compare(s
, type
, rn
, rm
, opc
& 1, opc
& 2);
3852 /* C3.6.23 Floating point conditional compare
3853 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3854 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
3855 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
3856 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
3858 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
3860 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
3862 int label_continue
= -1;
3864 mos
= extract32(insn
, 29, 3);
3865 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
3866 rm
= extract32(insn
, 16, 5);
3867 cond
= extract32(insn
, 12, 4);
3868 rn
= extract32(insn
, 5, 5);
3869 op
= extract32(insn
, 4, 1);
3870 nzcv
= extract32(insn
, 0, 4);
3872 if (mos
|| type
> 1) {
3873 unallocated_encoding(s
);
3877 if (cond
< 0x0e) { /* not always */
3878 int label_match
= gen_new_label();
3879 label_continue
= gen_new_label();
3880 arm_gen_test_cc(cond
, label_match
);
3882 tcg_flags
= tcg_const_i64(nzcv
<< 28);
3883 gen_set_nzcv(tcg_flags
);
3884 tcg_temp_free_i64(tcg_flags
);
3885 tcg_gen_br(label_continue
);
3886 gen_set_label(label_match
);
3889 handle_fp_compare(s
, type
, rn
, rm
, false, op
);
3892 gen_set_label(label_continue
);
3896 /* copy src FP register to dst FP register; type specifies single or double */
3897 static void gen_mov_fp2fp(DisasContext
*s
, int type
, int dst
, int src
)
3900 TCGv_i64 v
= read_fp_dreg(s
, src
);
3901 write_fp_dreg(s
, dst
, v
);
3902 tcg_temp_free_i64(v
);
3904 TCGv_i32 v
= read_fp_sreg(s
, src
);
3905 write_fp_sreg(s
, dst
, v
);
3906 tcg_temp_free_i32(v
);
3910 /* C3.6.24 Floating point conditional select
3911 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
3912 * +---+---+---+-----------+------+---+------+------+-----+------+------+
3913 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
3914 * +---+---+---+-----------+------+---+------+------+-----+------+------+
3916 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
3918 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
3919 int label_continue
= -1;
3921 mos
= extract32(insn
, 29, 3);
3922 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
3923 rm
= extract32(insn
, 16, 5);
3924 cond
= extract32(insn
, 12, 4);
3925 rn
= extract32(insn
, 5, 5);
3926 rd
= extract32(insn
, 0, 5);
3928 if (mos
|| type
> 1) {
3929 unallocated_encoding(s
);
3933 if (cond
< 0x0e) { /* not always */
3934 int label_match
= gen_new_label();
3935 label_continue
= gen_new_label();
3936 arm_gen_test_cc(cond
, label_match
);
3938 gen_mov_fp2fp(s
, type
, rd
, rm
);
3939 tcg_gen_br(label_continue
);
3940 gen_set_label(label_match
);
3943 gen_mov_fp2fp(s
, type
, rd
, rn
);
3945 if (cond
< 0x0e) { /* continue */
3946 gen_set_label(label_continue
);
3950 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
3951 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
3957 fpst
= get_fpstatus_ptr();
3958 tcg_op
= read_fp_sreg(s
, rn
);
3959 tcg_res
= tcg_temp_new_i32();
3962 case 0x0: /* FMOV */
3963 tcg_gen_mov_i32(tcg_res
, tcg_op
);
3965 case 0x1: /* FABS */
3966 gen_helper_vfp_abss(tcg_res
, tcg_op
);
3968 case 0x2: /* FNEG */
3969 gen_helper_vfp_negs(tcg_res
, tcg_op
);
3971 case 0x3: /* FSQRT */
3972 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
3974 case 0x8: /* FRINTN */
3975 case 0x9: /* FRINTP */
3976 case 0xa: /* FRINTM */
3977 case 0xb: /* FRINTZ */
3978 case 0xc: /* FRINTA */
3980 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
3982 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
3983 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
3985 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
3986 tcg_temp_free_i32(tcg_rmode
);
3989 case 0xe: /* FRINTX */
3990 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
3992 case 0xf: /* FRINTI */
3993 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
3999 write_fp_sreg(s
, rd
, tcg_res
);
4001 tcg_temp_free_ptr(fpst
);
4002 tcg_temp_free_i32(tcg_op
);
4003 tcg_temp_free_i32(tcg_res
);
4006 /* C3.6.25 Floating-point data-processing (1 source) - double precision */
4007 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
4013 fpst
= get_fpstatus_ptr();
4014 tcg_op
= read_fp_dreg(s
, rn
);
4015 tcg_res
= tcg_temp_new_i64();
4018 case 0x0: /* FMOV */
4019 tcg_gen_mov_i64(tcg_res
, tcg_op
);
4021 case 0x1: /* FABS */
4022 gen_helper_vfp_absd(tcg_res
, tcg_op
);
4024 case 0x2: /* FNEG */
4025 gen_helper_vfp_negd(tcg_res
, tcg_op
);
4027 case 0x3: /* FSQRT */
4028 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
4030 case 0x8: /* FRINTN */
4031 case 0x9: /* FRINTP */
4032 case 0xa: /* FRINTM */
4033 case 0xb: /* FRINTZ */
4034 case 0xc: /* FRINTA */
4036 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4038 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4039 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4041 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4042 tcg_temp_free_i32(tcg_rmode
);
4045 case 0xe: /* FRINTX */
4046 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
4048 case 0xf: /* FRINTI */
4049 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4055 write_fp_dreg(s
, rd
, tcg_res
);
4057 tcg_temp_free_ptr(fpst
);
4058 tcg_temp_free_i64(tcg_op
);
4059 tcg_temp_free_i64(tcg_res
);
4062 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
4063 int rd
, int rn
, int dtype
, int ntype
)
4068 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4070 /* Single to double */
4071 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4072 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
4073 write_fp_dreg(s
, rd
, tcg_rd
);
4074 tcg_temp_free_i64(tcg_rd
);
4076 /* Single to half */
4077 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4078 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4079 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4080 write_fp_sreg(s
, rd
, tcg_rd
);
4081 tcg_temp_free_i32(tcg_rd
);
4083 tcg_temp_free_i32(tcg_rn
);
4088 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
4089 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4091 /* Double to single */
4092 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
4094 /* Double to half */
4095 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4096 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4098 write_fp_sreg(s
, rd
, tcg_rd
);
4099 tcg_temp_free_i32(tcg_rd
);
4100 tcg_temp_free_i64(tcg_rn
);
4105 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4106 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
4108 /* Half to single */
4109 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4110 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, cpu_env
);
4111 write_fp_sreg(s
, rd
, tcg_rd
);
4112 tcg_temp_free_i32(tcg_rd
);
4114 /* Half to double */
4115 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4116 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, cpu_env
);
4117 write_fp_dreg(s
, rd
, tcg_rd
);
4118 tcg_temp_free_i64(tcg_rd
);
4120 tcg_temp_free_i32(tcg_rn
);
4128 /* C3.6.25 Floating point data-processing (1 source)
4129 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
4130 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4131 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
4132 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4134 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
4136 int type
= extract32(insn
, 22, 2);
4137 int opcode
= extract32(insn
, 15, 6);
4138 int rn
= extract32(insn
, 5, 5);
4139 int rd
= extract32(insn
, 0, 5);
4142 case 0x4: case 0x5: case 0x7:
4144 /* FCVT between half, single and double precision */
4145 int dtype
= extract32(opcode
, 0, 2);
4146 if (type
== 2 || dtype
== type
) {
4147 unallocated_encoding(s
);
4150 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
4156 /* 32-to-32 and 64-to-64 ops */
4159 handle_fp_1src_single(s
, opcode
, rd
, rn
);
4162 handle_fp_1src_double(s
, opcode
, rd
, rn
);
4165 unallocated_encoding(s
);
4169 unallocated_encoding(s
);
4174 /* C3.6.26 Floating-point data-processing (2 source) - single precision */
4175 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
4176 int rd
, int rn
, int rm
)
4183 tcg_res
= tcg_temp_new_i32();
4184 fpst
= get_fpstatus_ptr();
4185 tcg_op1
= read_fp_sreg(s
, rn
);
4186 tcg_op2
= read_fp_sreg(s
, rm
);
4189 case 0x0: /* FMUL */
4190 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4192 case 0x1: /* FDIV */
4193 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4195 case 0x2: /* FADD */
4196 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4198 case 0x3: /* FSUB */
4199 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4201 case 0x4: /* FMAX */
4202 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4204 case 0x5: /* FMIN */
4205 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4207 case 0x6: /* FMAXNM */
4208 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4210 case 0x7: /* FMINNM */
4211 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4213 case 0x8: /* FNMUL */
4214 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4215 gen_helper_vfp_negs(tcg_res
, tcg_res
);
4219 write_fp_sreg(s
, rd
, tcg_res
);
4221 tcg_temp_free_ptr(fpst
);
4222 tcg_temp_free_i32(tcg_op1
);
4223 tcg_temp_free_i32(tcg_op2
);
4224 tcg_temp_free_i32(tcg_res
);
4227 /* C3.6.26 Floating-point data-processing (2 source) - double precision */
4228 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
4229 int rd
, int rn
, int rm
)
4236 tcg_res
= tcg_temp_new_i64();
4237 fpst
= get_fpstatus_ptr();
4238 tcg_op1
= read_fp_dreg(s
, rn
);
4239 tcg_op2
= read_fp_dreg(s
, rm
);
4242 case 0x0: /* FMUL */
4243 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4245 case 0x1: /* FDIV */
4246 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4248 case 0x2: /* FADD */
4249 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4251 case 0x3: /* FSUB */
4252 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4254 case 0x4: /* FMAX */
4255 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4257 case 0x5: /* FMIN */
4258 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4260 case 0x6: /* FMAXNM */
4261 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4263 case 0x7: /* FMINNM */
4264 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4266 case 0x8: /* FNMUL */
4267 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4268 gen_helper_vfp_negd(tcg_res
, tcg_res
);
4272 write_fp_dreg(s
, rd
, tcg_res
);
4274 tcg_temp_free_ptr(fpst
);
4275 tcg_temp_free_i64(tcg_op1
);
4276 tcg_temp_free_i64(tcg_op2
);
4277 tcg_temp_free_i64(tcg_res
);
4280 /* C3.6.26 Floating point data-processing (2 source)
4281 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4282 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4283 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
4284 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4286 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
4288 int type
= extract32(insn
, 22, 2);
4289 int rd
= extract32(insn
, 0, 5);
4290 int rn
= extract32(insn
, 5, 5);
4291 int rm
= extract32(insn
, 16, 5);
4292 int opcode
= extract32(insn
, 12, 4);
4295 unallocated_encoding(s
);
4301 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
4304 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
4307 unallocated_encoding(s
);
4311 /* C3.6.27 Floating-point data-processing (3 source) - single precision */
4312 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
4313 int rd
, int rn
, int rm
, int ra
)
4315 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
4316 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4317 TCGv_ptr fpst
= get_fpstatus_ptr();
4319 tcg_op1
= read_fp_sreg(s
, rn
);
4320 tcg_op2
= read_fp_sreg(s
, rm
);
4321 tcg_op3
= read_fp_sreg(s
, ra
);
4323 /* These are fused multiply-add, and must be done as one
4324 * floating point operation with no rounding between the
4325 * multiplication and addition steps.
4326 * NB that doing the negations here as separate steps is
4327 * correct : an input NaN should come out with its sign bit
4328 * flipped if it is a negated-input.
4331 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
4335 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
4338 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4340 write_fp_sreg(s
, rd
, tcg_res
);
4342 tcg_temp_free_ptr(fpst
);
4343 tcg_temp_free_i32(tcg_op1
);
4344 tcg_temp_free_i32(tcg_op2
);
4345 tcg_temp_free_i32(tcg_op3
);
4346 tcg_temp_free_i32(tcg_res
);
4349 /* C3.6.27 Floating-point data-processing (3 source) - double precision */
4350 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
4351 int rd
, int rn
, int rm
, int ra
)
4353 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
4354 TCGv_i64 tcg_res
= tcg_temp_new_i64();
4355 TCGv_ptr fpst
= get_fpstatus_ptr();
4357 tcg_op1
= read_fp_dreg(s
, rn
);
4358 tcg_op2
= read_fp_dreg(s
, rm
);
4359 tcg_op3
= read_fp_dreg(s
, ra
);
4361 /* These are fused multiply-add, and must be done as one
4362 * floating point operation with no rounding between the
4363 * multiplication and addition steps.
4364 * NB that doing the negations here as separate steps is
4365 * correct : an input NaN should come out with its sign bit
4366 * flipped if it is a negated-input.
4369 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
4373 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
4376 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4378 write_fp_dreg(s
, rd
, tcg_res
);
4380 tcg_temp_free_ptr(fpst
);
4381 tcg_temp_free_i64(tcg_op1
);
4382 tcg_temp_free_i64(tcg_op2
);
4383 tcg_temp_free_i64(tcg_op3
);
4384 tcg_temp_free_i64(tcg_res
);
4387 /* C3.6.27 Floating point data-processing (3 source)
4388 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
4389 * +---+---+---+-----------+------+----+------+----+------+------+------+
4390 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
4391 * +---+---+---+-----------+------+----+------+----+------+------+------+
4393 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
4395 int type
= extract32(insn
, 22, 2);
4396 int rd
= extract32(insn
, 0, 5);
4397 int rn
= extract32(insn
, 5, 5);
4398 int ra
= extract32(insn
, 10, 5);
4399 int rm
= extract32(insn
, 16, 5);
4400 bool o0
= extract32(insn
, 15, 1);
4401 bool o1
= extract32(insn
, 21, 1);
4405 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4408 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4411 unallocated_encoding(s
);
4415 /* C3.6.28 Floating point immediate
4416 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
4417 * +---+---+---+-----------+------+---+------------+-------+------+------+
4418 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
4419 * +---+---+---+-----------+------+---+------------+-------+------+------+
4421 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
4423 int rd
= extract32(insn
, 0, 5);
4424 int imm8
= extract32(insn
, 13, 8);
4425 int is_double
= extract32(insn
, 22, 2);
4429 if (is_double
> 1) {
4430 unallocated_encoding(s
);
4434 /* The imm8 encodes the sign bit, enough bits to represent
4435 * an exponent in the range 01....1xx to 10....0xx,
4436 * and the most significant 4 bits of the mantissa; see
4437 * VFPExpandImm() in the v8 ARM ARM.
4440 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4441 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
4442 extract32(imm8
, 0, 6);
4445 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4446 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
4447 (extract32(imm8
, 0, 6) << 3);
4451 tcg_res
= tcg_const_i64(imm
);
4452 write_fp_dreg(s
, rd
, tcg_res
);
4453 tcg_temp_free_i64(tcg_res
);
4456 /* Handle floating point <=> fixed point conversions. Note that we can
4457 * also deal with fp <=> integer conversions as a special case (scale == 64)
4458 * OPTME: consider handling that special case specially or at least skipping
4459 * the call to scalbn in the helpers for zero shifts.
4461 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
4462 bool itof
, int rmode
, int scale
, int sf
, int type
)
4464 bool is_signed
= !(opcode
& 1);
4465 bool is_double
= type
;
4466 TCGv_ptr tcg_fpstatus
;
4469 tcg_fpstatus
= get_fpstatus_ptr();
4471 tcg_shift
= tcg_const_i32(64 - scale
);
4474 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
4476 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
4479 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
4481 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
4484 tcg_int
= tcg_extend
;
4488 TCGv_i64 tcg_double
= tcg_temp_new_i64();
4490 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
4491 tcg_shift
, tcg_fpstatus
);
4493 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
4494 tcg_shift
, tcg_fpstatus
);
4496 write_fp_dreg(s
, rd
, tcg_double
);
4497 tcg_temp_free_i64(tcg_double
);
4499 TCGv_i32 tcg_single
= tcg_temp_new_i32();
4501 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
4502 tcg_shift
, tcg_fpstatus
);
4504 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
4505 tcg_shift
, tcg_fpstatus
);
4507 write_fp_sreg(s
, rd
, tcg_single
);
4508 tcg_temp_free_i32(tcg_single
);
4511 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
4514 if (extract32(opcode
, 2, 1)) {
4515 /* There are too many rounding modes to all fit into rmode,
4516 * so FCVTA[US] is a special case.
4518 rmode
= FPROUNDING_TIEAWAY
;
4521 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
4523 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4526 TCGv_i64 tcg_double
= read_fp_dreg(s
, rn
);
4529 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
4530 tcg_shift
, tcg_fpstatus
);
4532 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
4533 tcg_shift
, tcg_fpstatus
);
4537 gen_helper_vfp_tould(tcg_int
, tcg_double
,
4538 tcg_shift
, tcg_fpstatus
);
4540 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
4541 tcg_shift
, tcg_fpstatus
);
4544 tcg_temp_free_i64(tcg_double
);
4546 TCGv_i32 tcg_single
= read_fp_sreg(s
, rn
);
4549 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
4550 tcg_shift
, tcg_fpstatus
);
4552 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
4553 tcg_shift
, tcg_fpstatus
);
4556 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
4558 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
4559 tcg_shift
, tcg_fpstatus
);
4561 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
4562 tcg_shift
, tcg_fpstatus
);
4564 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
4565 tcg_temp_free_i32(tcg_dest
);
4567 tcg_temp_free_i32(tcg_single
);
4570 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4571 tcg_temp_free_i32(tcg_rmode
);
4574 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
4578 tcg_temp_free_ptr(tcg_fpstatus
);
4579 tcg_temp_free_i32(tcg_shift
);
4582 /* C3.6.29 Floating point <-> fixed point conversions
4583 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4584 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4585 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
4586 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4588 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
4590 int rd
= extract32(insn
, 0, 5);
4591 int rn
= extract32(insn
, 5, 5);
4592 int scale
= extract32(insn
, 10, 6);
4593 int opcode
= extract32(insn
, 16, 3);
4594 int rmode
= extract32(insn
, 19, 2);
4595 int type
= extract32(insn
, 22, 2);
4596 bool sbit
= extract32(insn
, 29, 1);
4597 bool sf
= extract32(insn
, 31, 1);
4600 if (sbit
|| (type
> 1)
4601 || (!sf
&& scale
< 32)) {
4602 unallocated_encoding(s
);
4606 switch ((rmode
<< 3) | opcode
) {
4607 case 0x2: /* SCVTF */
4608 case 0x3: /* UCVTF */
4611 case 0x18: /* FCVTZS */
4612 case 0x19: /* FCVTZU */
4616 unallocated_encoding(s
);
4620 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
4623 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
4625 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
4626 * without conversion.
4630 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4636 TCGv_i64 tmp
= tcg_temp_new_i64();
4637 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
4638 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_offset(rd
, MO_64
));
4639 tcg_gen_movi_i64(tmp
, 0);
4640 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(rd
));
4641 tcg_temp_free_i64(tmp
);
4647 TCGv_i64 tmp
= tcg_const_i64(0);
4648 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_offset(rd
, MO_64
));
4649 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(rd
));
4650 tcg_temp_free_i64(tmp
);
4654 /* 64 bit to top half. */
4655 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(rd
));
4659 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4664 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(rn
, MO_32
));
4668 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(rn
, MO_64
));
4671 /* 64 bits from top half */
4672 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(rn
));
4678 /* C3.6.30 Floating point <-> integer conversions
4679 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4680 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4681 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
4682 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4684 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
4686 int rd
= extract32(insn
, 0, 5);
4687 int rn
= extract32(insn
, 5, 5);
4688 int opcode
= extract32(insn
, 16, 3);
4689 int rmode
= extract32(insn
, 19, 2);
4690 int type
= extract32(insn
, 22, 2);
4691 bool sbit
= extract32(insn
, 29, 1);
4692 bool sf
= extract32(insn
, 31, 1);
4695 unallocated_encoding(s
);
4701 bool itof
= opcode
& 1;
4704 unallocated_encoding(s
);
4708 switch (sf
<< 3 | type
<< 1 | rmode
) {
4709 case 0x0: /* 32 bit */
4710 case 0xa: /* 64 bit */
4711 case 0xd: /* 64 bit to top half of quad */
4714 /* all other sf/type/rmode combinations are invalid */
4715 unallocated_encoding(s
);
4719 handle_fmov(s
, rd
, rn
, type
, itof
);
4721 /* actual FP conversions */
4722 bool itof
= extract32(opcode
, 1, 1);
4724 if (type
> 1 || (rmode
!= 0 && opcode
> 1)) {
4725 unallocated_encoding(s
);
4729 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
4733 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
4734 * 31 30 29 28 25 24 0
4735 * +---+---+---+---------+-----------------------------+
4736 * | | 0 | | 1 1 1 1 | |
4737 * +---+---+---+---------+-----------------------------+
4739 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
4741 if (extract32(insn
, 24, 1)) {
4742 /* Floating point data-processing (3 source) */
4743 disas_fp_3src(s
, insn
);
4744 } else if (extract32(insn
, 21, 1) == 0) {
4745 /* Floating point to fixed point conversions */
4746 disas_fp_fixed_conv(s
, insn
);
4748 switch (extract32(insn
, 10, 2)) {
4750 /* Floating point conditional compare */
4751 disas_fp_ccomp(s
, insn
);
4754 /* Floating point data-processing (2 source) */
4755 disas_fp_2src(s
, insn
);
4758 /* Floating point conditional select */
4759 disas_fp_csel(s
, insn
);
4762 switch (ctz32(extract32(insn
, 12, 4))) {
4763 case 0: /* [15:12] == xxx1 */
4764 /* Floating point immediate */
4765 disas_fp_imm(s
, insn
);
4767 case 1: /* [15:12] == xx10 */
4768 /* Floating point compare */
4769 disas_fp_compare(s
, insn
);
4771 case 2: /* [15:12] == x100 */
4772 /* Floating point data-processing (1 source) */
4773 disas_fp_1src(s
, insn
);
4775 case 3: /* [15:12] == 1000 */
4776 unallocated_encoding(s
);
4778 default: /* [15:12] == 0000 */
4779 /* Floating point <-> integer conversions */
4780 disas_fp_int_conv(s
, insn
);
4788 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
4791 /* Extract 64 bits from the middle of two concatenated 64 bit
4792 * vector register slices left:right. The extracted bits start
4793 * at 'pos' bits into the right (least significant) side.
4794 * We return the result in tcg_right, and guarantee not to
4797 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4798 assert(pos
> 0 && pos
< 64);
4800 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
4801 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
4802 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
4804 tcg_temp_free_i64(tcg_tmp
);
4808 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
4809 * +---+---+-------------+-----+---+------+---+------+---+------+------+
4810 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
4811 * +---+---+-------------+-----+---+------+---+------+---+------+------+
4813 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
4815 int is_q
= extract32(insn
, 30, 1);
4816 int op2
= extract32(insn
, 22, 2);
4817 int imm4
= extract32(insn
, 11, 4);
4818 int rm
= extract32(insn
, 16, 5);
4819 int rn
= extract32(insn
, 5, 5);
4820 int rd
= extract32(insn
, 0, 5);
4821 int pos
= imm4
<< 3;
4822 TCGv_i64 tcg_resl
, tcg_resh
;
4824 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
4825 unallocated_encoding(s
);
4829 tcg_resh
= tcg_temp_new_i64();
4830 tcg_resl
= tcg_temp_new_i64();
4832 /* Vd gets bits starting at pos bits into Vm:Vn. This is
4833 * either extracting 128 bits from a 128:128 concatenation, or
4834 * extracting 64 bits from a 64:64 concatenation.
4837 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
4839 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
4840 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
4842 tcg_gen_movi_i64(tcg_resh
, 0);
4849 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
4850 EltPosns
*elt
= eltposns
;
4857 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
4859 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
4862 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
4863 tcg_hh
= tcg_temp_new_i64();
4864 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
4865 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
4866 tcg_temp_free_i64(tcg_hh
);
4870 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
4871 tcg_temp_free_i64(tcg_resl
);
4872 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
4873 tcg_temp_free_i64(tcg_resh
);
4877 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
4878 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
4879 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
4880 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
4882 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
4884 int op2
= extract32(insn
, 22, 2);
4885 int is_q
= extract32(insn
, 30, 1);
4886 int rm
= extract32(insn
, 16, 5);
4887 int rn
= extract32(insn
, 5, 5);
4888 int rd
= extract32(insn
, 0, 5);
4889 int is_tblx
= extract32(insn
, 12, 1);
4890 int len
= extract32(insn
, 13, 2);
4891 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
4892 TCGv_i32 tcg_regno
, tcg_numregs
;
4895 unallocated_encoding(s
);
4899 /* This does a table lookup: for every byte element in the input
4900 * we index into a table formed from up to four vector registers,
4901 * and then the output is the result of the lookups. Our helper
4902 * function does the lookup operation for a single 64 bit part of
4905 tcg_resl
= tcg_temp_new_i64();
4906 tcg_resh
= tcg_temp_new_i64();
4909 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
4911 tcg_gen_movi_i64(tcg_resl
, 0);
4913 if (is_tblx
&& is_q
) {
4914 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
4916 tcg_gen_movi_i64(tcg_resh
, 0);
4919 tcg_idx
= tcg_temp_new_i64();
4920 tcg_regno
= tcg_const_i32(rn
);
4921 tcg_numregs
= tcg_const_i32(len
+ 1);
4922 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
4923 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
4924 tcg_regno
, tcg_numregs
);
4926 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
4927 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
4928 tcg_regno
, tcg_numregs
);
4930 tcg_temp_free_i64(tcg_idx
);
4931 tcg_temp_free_i32(tcg_regno
);
4932 tcg_temp_free_i32(tcg_numregs
);
4934 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
4935 tcg_temp_free_i64(tcg_resl
);
4936 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
4937 tcg_temp_free_i64(tcg_resh
);
4940 /* C3.6.3 ZIP/UZP/TRN
4941 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
4942 * +---+---+-------------+------+---+------+---+------------------+------+
4943 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
4944 * +---+---+-------------+------+---+------+---+------------------+------+
4946 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
4948 int rd
= extract32(insn
, 0, 5);
4949 int rn
= extract32(insn
, 5, 5);
4950 int rm
= extract32(insn
, 16, 5);
4951 int size
= extract32(insn
, 22, 2);
4952 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
4953 * bit 2 indicates 1 vs 2 variant of the insn.
4955 int opcode
= extract32(insn
, 12, 2);
4956 bool part
= extract32(insn
, 14, 1);
4957 bool is_q
= extract32(insn
, 30, 1);
4958 int esize
= 8 << size
;
4960 int datasize
= is_q
? 128 : 64;
4961 int elements
= datasize
/ esize
;
4962 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
4964 if (opcode
== 0 || (size
== 3 && !is_q
)) {
4965 unallocated_encoding(s
);
4969 tcg_resl
= tcg_const_i64(0);
4970 tcg_resh
= tcg_const_i64(0);
4971 tcg_res
= tcg_temp_new_i64();
4973 for (i
= 0; i
< elements
; i
++) {
4975 case 1: /* UZP1/2 */
4977 int midpoint
= elements
/ 2;
4979 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
4981 read_vec_element(s
, tcg_res
, rm
,
4982 2 * (i
- midpoint
) + part
, size
);
4986 case 2: /* TRN1/2 */
4988 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
4990 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
4993 case 3: /* ZIP1/2 */
4995 int base
= part
* elements
/ 2;
4997 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
4999 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
5004 g_assert_not_reached();
5009 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
5010 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
5012 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
5013 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
5017 tcg_temp_free_i64(tcg_res
);
5019 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5020 tcg_temp_free_i64(tcg_resl
);
5021 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5022 tcg_temp_free_i64(tcg_resh
);
5025 static void do_minmaxop(DisasContext
*s
, TCGv_i32 tcg_elt1
, TCGv_i32 tcg_elt2
,
5026 int opc
, bool is_min
, TCGv_ptr fpst
)
5028 /* Helper function for disas_simd_across_lanes: do a single precision
5029 * min/max operation on the specified two inputs,
5030 * and return the result in tcg_elt1.
5034 gen_helper_vfp_minnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5036 gen_helper_vfp_maxnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5041 gen_helper_vfp_mins(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5043 gen_helper_vfp_maxs(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5048 /* C3.6.4 AdvSIMD across lanes
5049 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5050 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5051 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5052 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5054 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
5056 int rd
= extract32(insn
, 0, 5);
5057 int rn
= extract32(insn
, 5, 5);
5058 int size
= extract32(insn
, 22, 2);
5059 int opcode
= extract32(insn
, 12, 5);
5060 bool is_q
= extract32(insn
, 30, 1);
5061 bool is_u
= extract32(insn
, 29, 1);
5063 bool is_min
= false;
5067 TCGv_i64 tcg_res
, tcg_elt
;
5070 case 0x1b: /* ADDV */
5072 unallocated_encoding(s
);
5076 case 0x3: /* SADDLV, UADDLV */
5077 case 0xa: /* SMAXV, UMAXV */
5078 case 0x1a: /* SMINV, UMINV */
5079 if (size
== 3 || (size
== 2 && !is_q
)) {
5080 unallocated_encoding(s
);
5084 case 0xc: /* FMAXNMV, FMINNMV */
5085 case 0xf: /* FMAXV, FMINV */
5086 if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
5087 unallocated_encoding(s
);
5090 /* Bit 1 of size field encodes min vs max, and actual size is always
5091 * 32 bits: adjust the size variable so following code can rely on it
5093 is_min
= extract32(size
, 1, 1);
5098 unallocated_encoding(s
);
5103 elements
= (is_q
? 128 : 64) / esize
;
5105 tcg_res
= tcg_temp_new_i64();
5106 tcg_elt
= tcg_temp_new_i64();
5108 /* These instructions operate across all lanes of a vector
5109 * to produce a single result. We can guarantee that a 64
5110 * bit intermediate is sufficient:
5111 * + for [US]ADDLV the maximum element size is 32 bits, and
5112 * the result type is 64 bits
5113 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
5114 * same as the element size, which is 32 bits at most
5115 * For the integer operations we can choose to work at 64
5116 * or 32 bits and truncate at the end; for simplicity
5117 * we use 64 bits always. The floating point
5118 * ops do require 32 bit intermediates, though.
5121 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
5123 for (i
= 1; i
< elements
; i
++) {
5124 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
5127 case 0x03: /* SADDLV / UADDLV */
5128 case 0x1b: /* ADDV */
5129 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
5131 case 0x0a: /* SMAXV / UMAXV */
5132 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
5134 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5136 case 0x1a: /* SMINV / UMINV */
5137 tcg_gen_movcond_i64(is_u
? TCG_COND_LEU
: TCG_COND_LE
,
5139 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5143 g_assert_not_reached();
5148 /* Floating point ops which work on 32 bit (single) intermediates.
5149 * Note that correct NaN propagation requires that we do these
5150 * operations in exactly the order specified by the pseudocode.
5152 TCGv_i32 tcg_elt1
= tcg_temp_new_i32();
5153 TCGv_i32 tcg_elt2
= tcg_temp_new_i32();
5154 TCGv_i32 tcg_elt3
= tcg_temp_new_i32();
5155 TCGv_ptr fpst
= get_fpstatus_ptr();
5157 assert(esize
== 32);
5158 assert(elements
== 4);
5160 read_vec_element(s
, tcg_elt
, rn
, 0, MO_32
);
5161 tcg_gen_trunc_i64_i32(tcg_elt1
, tcg_elt
);
5162 read_vec_element(s
, tcg_elt
, rn
, 1, MO_32
);
5163 tcg_gen_trunc_i64_i32(tcg_elt2
, tcg_elt
);
5165 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5167 read_vec_element(s
, tcg_elt
, rn
, 2, MO_32
);
5168 tcg_gen_trunc_i64_i32(tcg_elt2
, tcg_elt
);
5169 read_vec_element(s
, tcg_elt
, rn
, 3, MO_32
);
5170 tcg_gen_trunc_i64_i32(tcg_elt3
, tcg_elt
);
5172 do_minmaxop(s
, tcg_elt2
, tcg_elt3
, opcode
, is_min
, fpst
);
5174 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5176 tcg_gen_extu_i32_i64(tcg_res
, tcg_elt1
);
5177 tcg_temp_free_i32(tcg_elt1
);
5178 tcg_temp_free_i32(tcg_elt2
);
5179 tcg_temp_free_i32(tcg_elt3
);
5180 tcg_temp_free_ptr(fpst
);
5183 tcg_temp_free_i64(tcg_elt
);
5185 /* Now truncate the result to the width required for the final output */
5186 if (opcode
== 0x03) {
5187 /* SADDLV, UADDLV: result is 2*esize */
5193 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
5196 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
5199 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
5204 g_assert_not_reached();
5207 write_fp_dreg(s
, rd
, tcg_res
);
5208 tcg_temp_free_i64(tcg_res
);
5211 /* C6.3.31 DUP (Element, Vector)
5213 * 31 30 29 21 20 16 15 10 9 5 4 0
5214 * +---+---+-------------------+--------+-------------+------+------+
5215 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5216 * +---+---+-------------------+--------+-------------+------+------+
5218 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5220 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
5223 int size
= ctz32(imm5
);
5224 int esize
= 8 << size
;
5225 int elements
= (is_q
? 128 : 64) / esize
;
5229 if (size
> 3 || (size
== 3 && !is_q
)) {
5230 unallocated_encoding(s
);
5234 index
= imm5
>> (size
+ 1);
5236 tmp
= tcg_temp_new_i64();
5237 read_vec_element(s
, tmp
, rn
, index
, size
);
5239 for (i
= 0; i
< elements
; i
++) {
5240 write_vec_element(s
, tmp
, rd
, i
, size
);
5244 clear_vec_high(s
, rd
);
5247 tcg_temp_free_i64(tmp
);
5250 /* C6.3.31 DUP (element, scalar)
5251 * 31 21 20 16 15 10 9 5 4 0
5252 * +-----------------------+--------+-------------+------+------+
5253 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5254 * +-----------------------+--------+-------------+------+------+
5256 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
5259 int size
= ctz32(imm5
);
5264 unallocated_encoding(s
);
5268 index
= imm5
>> (size
+ 1);
5270 /* This instruction just extracts the specified element and
5271 * zero-extends it into the bottom of the destination register.
5273 tmp
= tcg_temp_new_i64();
5274 read_vec_element(s
, tmp
, rn
, index
, size
);
5275 write_fp_dreg(s
, rd
, tmp
);
5276 tcg_temp_free_i64(tmp
);
5279 /* C6.3.32 DUP (General)
5281 * 31 30 29 21 20 16 15 10 9 5 4 0
5282 * +---+---+-------------------+--------+-------------+------+------+
5283 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
5284 * +---+---+-------------------+--------+-------------+------+------+
5286 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5288 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
5291 int size
= ctz32(imm5
);
5292 int esize
= 8 << size
;
5293 int elements
= (is_q
? 128 : 64)/esize
;
5296 if (size
> 3 || ((size
== 3) && !is_q
)) {
5297 unallocated_encoding(s
);
5300 for (i
= 0; i
< elements
; i
++) {
5301 write_vec_element(s
, cpu_reg(s
, rn
), rd
, i
, size
);
5304 clear_vec_high(s
, rd
);
5308 /* C6.3.150 INS (Element)
5310 * 31 21 20 16 15 14 11 10 9 5 4 0
5311 * +-----------------------+--------+------------+---+------+------+
5312 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5313 * +-----------------------+--------+------------+---+------+------+
5315 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5316 * index: encoded in imm5<4:size+1>
5318 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
5321 int size
= ctz32(imm5
);
5322 int src_index
, dst_index
;
5326 unallocated_encoding(s
);
5329 dst_index
= extract32(imm5
, 1+size
, 5);
5330 src_index
= extract32(imm4
, size
, 4);
5332 tmp
= tcg_temp_new_i64();
5334 read_vec_element(s
, tmp
, rn
, src_index
, size
);
5335 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
5337 tcg_temp_free_i64(tmp
);
5341 /* C6.3.151 INS (General)
5343 * 31 21 20 16 15 10 9 5 4 0
5344 * +-----------------------+--------+-------------+------+------+
5345 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
5346 * +-----------------------+--------+-------------+------+------+
5348 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5349 * index: encoded in imm5<4:size+1>
5351 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
5353 int size
= ctz32(imm5
);
5357 unallocated_encoding(s
);
5361 idx
= extract32(imm5
, 1 + size
, 4 - size
);
5362 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
5366 * C6.3.321 UMOV (General)
5367 * C6.3.237 SMOV (General)
5369 * 31 30 29 21 20 16 15 12 10 9 5 4 0
5370 * +---+---+-------------------+--------+-------------+------+------+
5371 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
5372 * +---+---+-------------------+--------+-------------+------+------+
5374 * U: unsigned when set
5375 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5377 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
5378 int rn
, int rd
, int imm5
)
5380 int size
= ctz32(imm5
);
5384 /* Check for UnallocatedEncodings */
5386 if (size
> 2 || (size
== 2 && !is_q
)) {
5387 unallocated_encoding(s
);
5392 || (size
< 3 && is_q
)
5393 || (size
== 3 && !is_q
)) {
5394 unallocated_encoding(s
);
5398 element
= extract32(imm5
, 1+size
, 4);
5400 tcg_rd
= cpu_reg(s
, rd
);
5401 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
5402 if (is_signed
&& !is_q
) {
5403 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5407 /* C3.6.5 AdvSIMD copy
5408 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5409 * +---+---+----+-----------------+------+---+------+---+------+------+
5410 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5411 * +---+---+----+-----------------+------+---+------+---+------+------+
5413 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
5415 int rd
= extract32(insn
, 0, 5);
5416 int rn
= extract32(insn
, 5, 5);
5417 int imm4
= extract32(insn
, 11, 4);
5418 int op
= extract32(insn
, 29, 1);
5419 int is_q
= extract32(insn
, 30, 1);
5420 int imm5
= extract32(insn
, 16, 5);
5425 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
5427 unallocated_encoding(s
);
5432 /* DUP (element - vector) */
5433 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
5437 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
5442 handle_simd_insg(s
, rd
, rn
, imm5
);
5444 unallocated_encoding(s
);
5449 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
5450 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
5453 unallocated_encoding(s
);
5459 /* C3.6.6 AdvSIMD modified immediate
5460 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
5461 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5462 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
5463 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5465 * There are a number of operations that can be carried out here:
5466 * MOVI - move (shifted) imm into register
5467 * MVNI - move inverted (shifted) imm into register
5468 * ORR - bitwise OR of (shifted) imm with register
5469 * BIC - bitwise clear of (shifted) imm with register
5471 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
5473 int rd
= extract32(insn
, 0, 5);
5474 int cmode
= extract32(insn
, 12, 4);
5475 int cmode_3_1
= extract32(cmode
, 1, 3);
5476 int cmode_0
= extract32(cmode
, 0, 1);
5477 int o2
= extract32(insn
, 11, 1);
5478 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
5479 bool is_neg
= extract32(insn
, 29, 1);
5480 bool is_q
= extract32(insn
, 30, 1);
5482 TCGv_i64 tcg_rd
, tcg_imm
;
5485 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
5486 unallocated_encoding(s
);
5490 /* See AdvSIMDExpandImm() in ARM ARM */
5491 switch (cmode_3_1
) {
5492 case 0: /* Replicate(Zeros(24):imm8, 2) */
5493 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
5494 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
5495 case 3: /* Replicate(imm8:Zeros(24), 2) */
5497 int shift
= cmode_3_1
* 8;
5498 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
5501 case 4: /* Replicate(Zeros(8):imm8, 4) */
5502 case 5: /* Replicate(imm8:Zeros(8), 4) */
5504 int shift
= (cmode_3_1
& 0x1) * 8;
5505 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
5510 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
5511 imm
= (abcdefgh
<< 16) | 0xffff;
5513 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
5514 imm
= (abcdefgh
<< 8) | 0xff;
5516 imm
= bitfield_replicate(imm
, 32);
5519 if (!cmode_0
&& !is_neg
) {
5520 imm
= bitfield_replicate(abcdefgh
, 8);
5521 } else if (!cmode_0
&& is_neg
) {
5524 for (i
= 0; i
< 8; i
++) {
5525 if ((abcdefgh
) & (1 << i
)) {
5526 imm
|= 0xffULL
<< (i
* 8);
5529 } else if (cmode_0
) {
5531 imm
= (abcdefgh
& 0x3f) << 48;
5532 if (abcdefgh
& 0x80) {
5533 imm
|= 0x8000000000000000ULL
;
5535 if (abcdefgh
& 0x40) {
5536 imm
|= 0x3fc0000000000000ULL
;
5538 imm
|= 0x4000000000000000ULL
;
5541 imm
= (abcdefgh
& 0x3f) << 19;
5542 if (abcdefgh
& 0x80) {
5545 if (abcdefgh
& 0x40) {
5556 if (cmode_3_1
!= 7 && is_neg
) {
5560 tcg_imm
= tcg_const_i64(imm
);
5561 tcg_rd
= new_tmp_a64(s
);
5563 for (i
= 0; i
< 2; i
++) {
5564 int foffs
= i
? fp_reg_hi_offset(rd
) : fp_reg_offset(rd
, MO_64
);
5566 if (i
== 1 && !is_q
) {
5567 /* non-quad ops clear high half of vector */
5568 tcg_gen_movi_i64(tcg_rd
, 0);
5569 } else if ((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9) {
5570 tcg_gen_ld_i64(tcg_rd
, cpu_env
, foffs
);
5573 tcg_gen_and_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5576 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5580 tcg_gen_mov_i64(tcg_rd
, tcg_imm
);
5582 tcg_gen_st_i64(tcg_rd
, cpu_env
, foffs
);
5585 tcg_temp_free_i64(tcg_imm
);
5588 /* C3.6.7 AdvSIMD scalar copy
5589 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5590 * +-----+----+-----------------+------+---+------+---+------+------+
5591 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5592 * +-----+----+-----------------+------+---+------+---+------+------+
5594 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
5596 int rd
= extract32(insn
, 0, 5);
5597 int rn
= extract32(insn
, 5, 5);
5598 int imm4
= extract32(insn
, 11, 4);
5599 int imm5
= extract32(insn
, 16, 5);
5600 int op
= extract32(insn
, 29, 1);
5602 if (op
!= 0 || imm4
!= 0) {
5603 unallocated_encoding(s
);
5607 /* DUP (element, scalar) */
5608 handle_simd_dupes(s
, rd
, rn
, imm5
);
5611 /* C3.6.8 AdvSIMD scalar pairwise
5612 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5613 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5614 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5615 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5617 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
5619 int u
= extract32(insn
, 29, 1);
5620 int size
= extract32(insn
, 22, 2);
5621 int opcode
= extract32(insn
, 12, 5);
5622 int rn
= extract32(insn
, 5, 5);
5623 int rd
= extract32(insn
, 0, 5);
5626 /* For some ops (the FP ones), size[1] is part of the encoding.
5627 * For ADDP strictly it is not but size[1] is always 1 for valid
5630 opcode
|= (extract32(size
, 1, 1) << 5);
5633 case 0x3b: /* ADDP */
5634 if (u
|| size
!= 3) {
5635 unallocated_encoding(s
);
5638 TCGV_UNUSED_PTR(fpst
);
5640 case 0xc: /* FMAXNMP */
5641 case 0xd: /* FADDP */
5642 case 0xf: /* FMAXP */
5643 case 0x2c: /* FMINNMP */
5644 case 0x2f: /* FMINP */
5645 /* FP op, size[0] is 32 or 64 bit */
5647 unallocated_encoding(s
);
5650 size
= extract32(size
, 0, 1) ? 3 : 2;
5651 fpst
= get_fpstatus_ptr();
5654 unallocated_encoding(s
);
5659 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
5660 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
5661 TCGv_i64 tcg_res
= tcg_temp_new_i64();
5663 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
5664 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
5667 case 0x3b: /* ADDP */
5668 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
5670 case 0xc: /* FMAXNMP */
5671 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5673 case 0xd: /* FADDP */
5674 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5676 case 0xf: /* FMAXP */
5677 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5679 case 0x2c: /* FMINNMP */
5680 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5682 case 0x2f: /* FMINP */
5683 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5686 g_assert_not_reached();
5689 write_fp_dreg(s
, rd
, tcg_res
);
5691 tcg_temp_free_i64(tcg_op1
);
5692 tcg_temp_free_i64(tcg_op2
);
5693 tcg_temp_free_i64(tcg_res
);
5695 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
5696 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
5697 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5699 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_32
);
5700 read_vec_element_i32(s
, tcg_op2
, rn
, 1, MO_32
);
5703 case 0xc: /* FMAXNMP */
5704 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5706 case 0xd: /* FADDP */
5707 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5709 case 0xf: /* FMAXP */
5710 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5712 case 0x2c: /* FMINNMP */
5713 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5715 case 0x2f: /* FMINP */
5716 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5719 g_assert_not_reached();
5722 write_fp_sreg(s
, rd
, tcg_res
);
5724 tcg_temp_free_i32(tcg_op1
);
5725 tcg_temp_free_i32(tcg_op2
);
5726 tcg_temp_free_i32(tcg_res
);
5729 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
5730 tcg_temp_free_ptr(fpst
);
5735 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
5737 * This code is handles the common shifting code and is used by both
5738 * the vector and scalar code.
5740 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
5741 TCGv_i64 tcg_rnd
, bool accumulate
,
5742 bool is_u
, int size
, int shift
)
5744 bool extended_result
= false;
5745 bool round
= !TCGV_IS_UNUSED_I64(tcg_rnd
);
5747 TCGv_i64 tcg_src_hi
;
5749 if (round
&& size
== 3) {
5750 extended_result
= true;
5751 ext_lshift
= 64 - shift
;
5752 tcg_src_hi
= tcg_temp_new_i64();
5753 } else if (shift
== 64) {
5754 if (!accumulate
&& is_u
) {
5755 /* result is zero */
5756 tcg_gen_movi_i64(tcg_res
, 0);
5761 /* Deal with the rounding step */
5763 if (extended_result
) {
5764 TCGv_i64 tcg_zero
= tcg_const_i64(0);
5766 /* take care of sign extending tcg_res */
5767 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
5768 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
5769 tcg_src
, tcg_src_hi
,
5772 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
5776 tcg_temp_free_i64(tcg_zero
);
5778 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
5782 /* Now do the shift right */
5783 if (round
&& extended_result
) {
5784 /* extended case, >64 bit precision required */
5785 if (ext_lshift
== 0) {
5786 /* special case, only high bits matter */
5787 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
5789 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
5790 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
5791 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
5796 /* essentially shifting in 64 zeros */
5797 tcg_gen_movi_i64(tcg_src
, 0);
5799 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
5803 /* effectively extending the sign-bit */
5804 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
5806 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
5812 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
5814 tcg_gen_mov_i64(tcg_res
, tcg_src
);
5817 if (extended_result
) {
5818 tcg_temp_free_i64(tcg_src_hi
);
5822 /* Common SHL/SLI - Shift left with an optional insert */
5823 static void handle_shli_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
5824 bool insert
, int shift
)
5826 if (insert
) { /* SLI */
5827 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, shift
, 64 - shift
);
5829 tcg_gen_shli_i64(tcg_res
, tcg_src
, shift
);
5833 /* SRI: shift right with insert */
5834 static void handle_shri_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
5835 int size
, int shift
)
5837 int esize
= 8 << size
;
5839 /* shift count same as element size is valid but does nothing;
5840 * special case to avoid potential shift by 64.
5842 if (shift
!= esize
) {
5843 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
5844 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, 0, esize
- shift
);
5848 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
5849 static void handle_scalar_simd_shri(DisasContext
*s
,
5850 bool is_u
, int immh
, int immb
,
5851 int opcode
, int rn
, int rd
)
5854 int immhb
= immh
<< 3 | immb
;
5855 int shift
= 2 * (8 << size
) - immhb
;
5856 bool accumulate
= false;
5858 bool insert
= false;
5863 if (!extract32(immh
, 3, 1)) {
5864 unallocated_encoding(s
);
5869 case 0x02: /* SSRA / USRA (accumulate) */
5872 case 0x04: /* SRSHR / URSHR (rounding) */
5875 case 0x06: /* SRSRA / URSRA (accum + rounding) */
5876 accumulate
= round
= true;
5878 case 0x08: /* SRI */
5884 uint64_t round_const
= 1ULL << (shift
- 1);
5885 tcg_round
= tcg_const_i64(round_const
);
5887 TCGV_UNUSED_I64(tcg_round
);
5890 tcg_rn
= read_fp_dreg(s
, rn
);
5891 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
5894 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
5896 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
5897 accumulate
, is_u
, size
, shift
);
5900 write_fp_dreg(s
, rd
, tcg_rd
);
5902 tcg_temp_free_i64(tcg_rn
);
5903 tcg_temp_free_i64(tcg_rd
);
5905 tcg_temp_free_i64(tcg_round
);
5909 /* SHL/SLI - Scalar shift left */
5910 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
5911 int immh
, int immb
, int opcode
,
5914 int size
= 32 - clz32(immh
) - 1;
5915 int immhb
= immh
<< 3 | immb
;
5916 int shift
= immhb
- (8 << size
);
5917 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
5918 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
5920 if (!extract32(immh
, 3, 1)) {
5921 unallocated_encoding(s
);
5925 tcg_rn
= read_fp_dreg(s
, rn
);
5926 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
5928 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
5930 write_fp_dreg(s
, rd
, tcg_rd
);
5932 tcg_temp_free_i64(tcg_rn
);
5933 tcg_temp_free_i64(tcg_rd
);
5936 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
5937 * (signed/unsigned) narrowing */
5938 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
5939 bool is_u_shift
, bool is_u_narrow
,
5940 int immh
, int immb
, int opcode
,
5943 int immhb
= immh
<< 3 | immb
;
5944 int size
= 32 - clz32(immh
) - 1;
5945 int esize
= 8 << size
;
5946 int shift
= (2 * esize
) - immhb
;
5947 int elements
= is_scalar
? 1 : (64 / esize
);
5948 bool round
= extract32(opcode
, 0, 1);
5949 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
5950 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
5951 TCGv_i32 tcg_rd_narrowed
;
5954 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
5955 { gen_helper_neon_narrow_sat_s8
,
5956 gen_helper_neon_unarrow_sat8
},
5957 { gen_helper_neon_narrow_sat_s16
,
5958 gen_helper_neon_unarrow_sat16
},
5959 { gen_helper_neon_narrow_sat_s32
,
5960 gen_helper_neon_unarrow_sat32
},
5963 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
5964 gen_helper_neon_narrow_sat_u8
,
5965 gen_helper_neon_narrow_sat_u16
,
5966 gen_helper_neon_narrow_sat_u32
,
5969 NeonGenNarrowEnvFn
*narrowfn
;
5975 if (extract32(immh
, 3, 1)) {
5976 unallocated_encoding(s
);
5981 narrowfn
= unsigned_narrow_fns
[size
];
5983 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
5986 tcg_rn
= tcg_temp_new_i64();
5987 tcg_rd
= tcg_temp_new_i64();
5988 tcg_rd_narrowed
= tcg_temp_new_i32();
5989 tcg_final
= tcg_const_i64(0);
5992 uint64_t round_const
= 1ULL << (shift
- 1);
5993 tcg_round
= tcg_const_i64(round_const
);
5995 TCGV_UNUSED_I64(tcg_round
);
5998 for (i
= 0; i
< elements
; i
++) {
5999 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
6000 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6001 false, is_u_shift
, size
+1, shift
);
6002 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
6003 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
6004 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
6008 clear_vec_high(s
, rd
);
6009 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
6011 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
6015 tcg_temp_free_i64(tcg_round
);
6017 tcg_temp_free_i64(tcg_rn
);
6018 tcg_temp_free_i64(tcg_rd
);
6019 tcg_temp_free_i32(tcg_rd_narrowed
);
6020 tcg_temp_free_i64(tcg_final
);
6024 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
6025 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
6026 bool src_unsigned
, bool dst_unsigned
,
6027 int immh
, int immb
, int rn
, int rd
)
6029 int immhb
= immh
<< 3 | immb
;
6030 int size
= 32 - clz32(immh
) - 1;
6031 int shift
= immhb
- (8 << size
);
6035 assert(!(scalar
&& is_q
));
6038 if (!is_q
&& extract32(immh
, 3, 1)) {
6039 unallocated_encoding(s
);
6043 /* Since we use the variable-shift helpers we must
6044 * replicate the shift count into each element of
6045 * the tcg_shift value.
6049 shift
|= shift
<< 8;
6052 shift
|= shift
<< 16;
6058 g_assert_not_reached();
6063 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
6064 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
6065 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
6066 { NULL
, gen_helper_neon_qshl_u64
},
6068 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
6069 int maxpass
= is_q
? 2 : 1;
6071 for (pass
= 0; pass
< maxpass
; pass
++) {
6072 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6074 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6075 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6076 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6078 tcg_temp_free_i64(tcg_op
);
6080 tcg_temp_free_i64(tcg_shift
);
6083 clear_vec_high(s
, rd
);
6086 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
6087 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
6089 { gen_helper_neon_qshl_s8
,
6090 gen_helper_neon_qshl_s16
,
6091 gen_helper_neon_qshl_s32
},
6092 { gen_helper_neon_qshlu_s8
,
6093 gen_helper_neon_qshlu_s16
,
6094 gen_helper_neon_qshlu_s32
}
6096 { NULL
, NULL
, NULL
},
6097 { gen_helper_neon_qshl_u8
,
6098 gen_helper_neon_qshl_u16
,
6099 gen_helper_neon_qshl_u32
}
6102 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
6103 TCGMemOp memop
= scalar
? size
: MO_32
;
6104 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
6106 for (pass
= 0; pass
< maxpass
; pass
++) {
6107 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6109 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
6110 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6114 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
6117 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
6122 g_assert_not_reached();
6124 write_fp_sreg(s
, rd
, tcg_op
);
6126 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6129 tcg_temp_free_i32(tcg_op
);
6131 tcg_temp_free_i32(tcg_shift
);
6133 if (!is_q
&& !scalar
) {
6134 clear_vec_high(s
, rd
);
6139 /* Common vector code for handling integer to FP conversion */
6140 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
6141 int elements
, int is_signed
,
6142 int fracbits
, int size
)
6144 bool is_double
= size
== 3 ? true : false;
6145 TCGv_ptr tcg_fpst
= get_fpstatus_ptr();
6146 TCGv_i32 tcg_shift
= tcg_const_i32(fracbits
);
6147 TCGv_i64 tcg_int
= tcg_temp_new_i64();
6148 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
6151 for (pass
= 0; pass
< elements
; pass
++) {
6152 read_vec_element(s
, tcg_int
, rn
, pass
, mop
);
6155 TCGv_i64 tcg_double
= tcg_temp_new_i64();
6157 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6158 tcg_shift
, tcg_fpst
);
6160 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6161 tcg_shift
, tcg_fpst
);
6163 if (elements
== 1) {
6164 write_fp_dreg(s
, rd
, tcg_double
);
6166 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
6168 tcg_temp_free_i64(tcg_double
);
6170 TCGv_i32 tcg_single
= tcg_temp_new_i32();
6172 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6173 tcg_shift
, tcg_fpst
);
6175 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6176 tcg_shift
, tcg_fpst
);
6178 if (elements
== 1) {
6179 write_fp_sreg(s
, rd
, tcg_single
);
6181 write_vec_element_i32(s
, tcg_single
, rd
, pass
, MO_32
);
6183 tcg_temp_free_i32(tcg_single
);
6187 if (!is_double
&& elements
== 2) {
6188 clear_vec_high(s
, rd
);
6191 tcg_temp_free_i64(tcg_int
);
6192 tcg_temp_free_ptr(tcg_fpst
);
6193 tcg_temp_free_i32(tcg_shift
);
6196 /* UCVTF/SCVTF - Integer to FP conversion */
6197 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
6198 bool is_q
, bool is_u
,
6199 int immh
, int immb
, int opcode
,
6202 bool is_double
= extract32(immh
, 3, 1);
6203 int size
= is_double
? MO_64
: MO_32
;
6205 int immhb
= immh
<< 3 | immb
;
6206 int fracbits
= (is_double
? 128 : 64) - immhb
;
6208 if (!extract32(immh
, 2, 2)) {
6209 unallocated_encoding(s
);
6216 elements
= is_double
? 2 : is_q
? 4 : 2;
6217 if (is_double
&& !is_q
) {
6218 unallocated_encoding(s
);
6222 /* immh == 0 would be a failure of the decode logic */
6225 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
6228 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
6229 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
6230 bool is_q
, bool is_u
,
6231 int immh
, int immb
, int rn
, int rd
)
6233 bool is_double
= extract32(immh
, 3, 1);
6234 int immhb
= immh
<< 3 | immb
;
6235 int fracbits
= (is_double
? 128 : 64) - immhb
;
6237 TCGv_ptr tcg_fpstatus
;
6238 TCGv_i32 tcg_rmode
, tcg_shift
;
6240 if (!extract32(immh
, 2, 2)) {
6241 unallocated_encoding(s
);
6245 if (!is_scalar
&& !is_q
&& is_double
) {
6246 unallocated_encoding(s
);
6250 assert(!(is_scalar
&& is_q
));
6252 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
6253 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6254 tcg_fpstatus
= get_fpstatus_ptr();
6255 tcg_shift
= tcg_const_i32(fracbits
);
6258 int maxpass
= is_scalar
? 1 : is_q
? 2 : 1;
6260 for (pass
= 0; pass
< maxpass
; pass
++) {
6261 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6263 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6265 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6267 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6269 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6270 tcg_temp_free_i64(tcg_op
);
6273 clear_vec_high(s
, rd
);
6276 int maxpass
= is_scalar
? 1 : is_q
? 4 : 2;
6277 for (pass
= 0; pass
< maxpass
; pass
++) {
6278 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6280 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
6282 gen_helper_vfp_touls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6284 gen_helper_vfp_tosls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6287 write_fp_sreg(s
, rd
, tcg_op
);
6289 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6291 tcg_temp_free_i32(tcg_op
);
6293 if (!is_q
&& !is_scalar
) {
6294 clear_vec_high(s
, rd
);
6298 tcg_temp_free_ptr(tcg_fpstatus
);
6299 tcg_temp_free_i32(tcg_shift
);
6300 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6301 tcg_temp_free_i32(tcg_rmode
);
6304 /* C3.6.9 AdvSIMD scalar shift by immediate
6305 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
6306 * +-----+---+-------------+------+------+--------+---+------+------+
6307 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
6308 * +-----+---+-------------+------+------+--------+---+------+------+
6310 * This is the scalar version so it works on a fixed sized registers
6312 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
6314 int rd
= extract32(insn
, 0, 5);
6315 int rn
= extract32(insn
, 5, 5);
6316 int opcode
= extract32(insn
, 11, 5);
6317 int immb
= extract32(insn
, 16, 3);
6318 int immh
= extract32(insn
, 19, 4);
6319 bool is_u
= extract32(insn
, 29, 1);
6322 unallocated_encoding(s
);
6327 case 0x08: /* SRI */
6329 unallocated_encoding(s
);
6333 case 0x00: /* SSHR / USHR */
6334 case 0x02: /* SSRA / USRA */
6335 case 0x04: /* SRSHR / URSHR */
6336 case 0x06: /* SRSRA / URSRA */
6337 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6339 case 0x0a: /* SHL / SLI */
6340 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6342 case 0x1c: /* SCVTF, UCVTF */
6343 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
6346 case 0x10: /* SQSHRUN, SQSHRUN2 */
6347 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
6349 unallocated_encoding(s
);
6352 handle_vec_simd_sqshrn(s
, true, false, false, true,
6353 immh
, immb
, opcode
, rn
, rd
);
6355 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
6356 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
6357 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
6358 immh
, immb
, opcode
, rn
, rd
);
6360 case 0xc: /* SQSHLU */
6362 unallocated_encoding(s
);
6365 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
6367 case 0xe: /* SQSHL, UQSHL */
6368 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
6370 case 0x1f: /* FCVTZS, FCVTZU */
6371 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
6374 unallocated_encoding(s
);
6379 /* C3.6.10 AdvSIMD scalar three different
6380 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6381 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6382 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
6383 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6385 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
6387 bool is_u
= extract32(insn
, 29, 1);
6388 int size
= extract32(insn
, 22, 2);
6389 int opcode
= extract32(insn
, 12, 4);
6390 int rm
= extract32(insn
, 16, 5);
6391 int rn
= extract32(insn
, 5, 5);
6392 int rd
= extract32(insn
, 0, 5);
6395 unallocated_encoding(s
);
6400 case 0x9: /* SQDMLAL, SQDMLAL2 */
6401 case 0xb: /* SQDMLSL, SQDMLSL2 */
6402 case 0xd: /* SQDMULL, SQDMULL2 */
6403 if (size
== 0 || size
== 3) {
6404 unallocated_encoding(s
);
6409 unallocated_encoding(s
);
6414 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6415 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6416 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6418 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
6419 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
6421 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
6422 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6425 case 0xd: /* SQDMULL, SQDMULL2 */
6427 case 0xb: /* SQDMLSL, SQDMLSL2 */
6428 tcg_gen_neg_i64(tcg_res
, tcg_res
);
6430 case 0x9: /* SQDMLAL, SQDMLAL2 */
6431 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
6432 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
6436 g_assert_not_reached();
6439 write_fp_dreg(s
, rd
, tcg_res
);
6441 tcg_temp_free_i64(tcg_op1
);
6442 tcg_temp_free_i64(tcg_op2
);
6443 tcg_temp_free_i64(tcg_res
);
6445 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6446 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6447 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6449 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_16
);
6450 read_vec_element_i32(s
, tcg_op2
, rm
, 0, MO_16
);
6452 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
6453 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6456 case 0xd: /* SQDMULL, SQDMULL2 */
6458 case 0xb: /* SQDMLSL, SQDMLSL2 */
6459 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
6461 case 0x9: /* SQDMLAL, SQDMLAL2 */
6463 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
6464 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
6465 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
6467 tcg_temp_free_i64(tcg_op3
);
6471 g_assert_not_reached();
6474 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
6475 write_fp_dreg(s
, rd
, tcg_res
);
6477 tcg_temp_free_i32(tcg_op1
);
6478 tcg_temp_free_i32(tcg_op2
);
6479 tcg_temp_free_i64(tcg_res
);
6483 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
6484 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
6486 /* Handle 64x64->64 opcodes which are shared between the scalar
6487 * and vector 3-same groups. We cover every opcode where size == 3
6488 * is valid in either the three-reg-same (integer, not pairwise)
6489 * or scalar-three-reg-same groups. (Some opcodes are not yet
6495 case 0x1: /* SQADD */
6497 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6499 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6502 case 0x5: /* SQSUB */
6504 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6506 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6509 case 0x6: /* CMGT, CMHI */
6510 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
6511 * We implement this using setcond (test) and then negating.
6513 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
6515 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
6516 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6518 case 0x7: /* CMGE, CMHS */
6519 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
6521 case 0x11: /* CMTST, CMEQ */
6526 /* CMTST : test is "if (X & Y != 0)". */
6527 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6528 tcg_gen_setcondi_i64(TCG_COND_NE
, tcg_rd
, tcg_rd
, 0);
6529 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6531 case 0x8: /* SSHL, USHL */
6533 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6535 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6538 case 0x9: /* SQSHL, UQSHL */
6540 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6542 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6545 case 0xa: /* SRSHL, URSHL */
6547 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6549 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6552 case 0xb: /* SQRSHL, UQRSHL */
6554 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6556 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6559 case 0x10: /* ADD, SUB */
6561 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6563 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6567 g_assert_not_reached();
6571 /* Handle the 3-same-operands float operations; shared by the scalar
6572 * and vector encodings. The caller must filter out any encodings
6573 * not allocated for the encoding it is dealing with.
6575 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
6576 int fpopcode
, int rd
, int rn
, int rm
)
6579 TCGv_ptr fpst
= get_fpstatus_ptr();
6581 for (pass
= 0; pass
< elements
; pass
++) {
6584 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6585 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6586 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6588 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
6589 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
6592 case 0x39: /* FMLS */
6593 /* As usual for ARM, separate negation for fused multiply-add */
6594 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6596 case 0x19: /* FMLA */
6597 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
6598 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
6601 case 0x18: /* FMAXNM */
6602 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6604 case 0x1a: /* FADD */
6605 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6607 case 0x1b: /* FMULX */
6608 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6610 case 0x1c: /* FCMEQ */
6611 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6613 case 0x1e: /* FMAX */
6614 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6616 case 0x1f: /* FRECPS */
6617 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6619 case 0x38: /* FMINNM */
6620 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6622 case 0x3a: /* FSUB */
6623 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6625 case 0x3e: /* FMIN */
6626 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6628 case 0x3f: /* FRSQRTS */
6629 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6631 case 0x5b: /* FMUL */
6632 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6634 case 0x5c: /* FCMGE */
6635 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6637 case 0x5d: /* FACGE */
6638 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6640 case 0x5f: /* FDIV */
6641 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6643 case 0x7a: /* FABD */
6644 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6645 gen_helper_vfp_absd(tcg_res
, tcg_res
);
6647 case 0x7c: /* FCMGT */
6648 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6650 case 0x7d: /* FACGT */
6651 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6654 g_assert_not_reached();
6657 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
6659 tcg_temp_free_i64(tcg_res
);
6660 tcg_temp_free_i64(tcg_op1
);
6661 tcg_temp_free_i64(tcg_op2
);
6664 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6665 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6666 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6668 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
6669 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
6672 case 0x39: /* FMLS */
6673 /* As usual for ARM, separate negation for fused multiply-add */
6674 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
6676 case 0x19: /* FMLA */
6677 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
6678 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
6681 case 0x1a: /* FADD */
6682 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6684 case 0x1b: /* FMULX */
6685 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6687 case 0x1c: /* FCMEQ */
6688 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6690 case 0x1e: /* FMAX */
6691 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6693 case 0x1f: /* FRECPS */
6694 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6696 case 0x18: /* FMAXNM */
6697 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6699 case 0x38: /* FMINNM */
6700 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6702 case 0x3a: /* FSUB */
6703 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6705 case 0x3e: /* FMIN */
6706 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6708 case 0x3f: /* FRSQRTS */
6709 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6711 case 0x5b: /* FMUL */
6712 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6714 case 0x5c: /* FCMGE */
6715 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6717 case 0x5d: /* FACGE */
6718 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6720 case 0x5f: /* FDIV */
6721 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6723 case 0x7a: /* FABD */
6724 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6725 gen_helper_vfp_abss(tcg_res
, tcg_res
);
6727 case 0x7c: /* FCMGT */
6728 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6730 case 0x7d: /* FACGT */
6731 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6734 g_assert_not_reached();
6737 if (elements
== 1) {
6738 /* scalar single so clear high part */
6739 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
6741 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
6742 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
6743 tcg_temp_free_i64(tcg_tmp
);
6745 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
6748 tcg_temp_free_i32(tcg_res
);
6749 tcg_temp_free_i32(tcg_op1
);
6750 tcg_temp_free_i32(tcg_op2
);
6754 tcg_temp_free_ptr(fpst
);
6756 if ((elements
<< size
) < 4) {
6757 /* scalar, or non-quad vector op */
6758 clear_vec_high(s
, rd
);
6762 /* C3.6.11 AdvSIMD scalar three same
6763 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
6764 * +-----+---+-----------+------+---+------+--------+---+------+------+
6765 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
6766 * +-----+---+-----------+------+---+------+--------+---+------+------+
6768 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
6770 int rd
= extract32(insn
, 0, 5);
6771 int rn
= extract32(insn
, 5, 5);
6772 int opcode
= extract32(insn
, 11, 5);
6773 int rm
= extract32(insn
, 16, 5);
6774 int size
= extract32(insn
, 22, 2);
6775 bool u
= extract32(insn
, 29, 1);
6778 if (opcode
>= 0x18) {
6779 /* Floating point: U, size[1] and opcode indicate operation */
6780 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
6782 case 0x1b: /* FMULX */
6783 case 0x1f: /* FRECPS */
6784 case 0x3f: /* FRSQRTS */
6785 case 0x5d: /* FACGE */
6786 case 0x7d: /* FACGT */
6787 case 0x1c: /* FCMEQ */
6788 case 0x5c: /* FCMGE */
6789 case 0x7c: /* FCMGT */
6790 case 0x7a: /* FABD */
6793 unallocated_encoding(s
);
6797 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
6802 case 0x1: /* SQADD, UQADD */
6803 case 0x5: /* SQSUB, UQSUB */
6804 case 0x9: /* SQSHL, UQSHL */
6805 case 0xb: /* SQRSHL, UQRSHL */
6807 case 0x8: /* SSHL, USHL */
6808 case 0xa: /* SRSHL, URSHL */
6809 case 0x6: /* CMGT, CMHI */
6810 case 0x7: /* CMGE, CMHS */
6811 case 0x11: /* CMTST, CMEQ */
6812 case 0x10: /* ADD, SUB (vector) */
6814 unallocated_encoding(s
);
6818 case 0x16: /* SQDMULH, SQRDMULH (vector) */
6819 if (size
!= 1 && size
!= 2) {
6820 unallocated_encoding(s
);
6825 unallocated_encoding(s
);
6829 tcg_rd
= tcg_temp_new_i64();
6832 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
6833 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
6835 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
6836 tcg_temp_free_i64(tcg_rn
);
6837 tcg_temp_free_i64(tcg_rm
);
6839 /* Do a single operation on the lowest element in the vector.
6840 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
6841 * no side effects for all these operations.
6842 * OPTME: special-purpose helpers would avoid doing some
6843 * unnecessary work in the helper for the 8 and 16 bit cases.
6845 NeonGenTwoOpEnvFn
*genenvfn
;
6846 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
6847 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
6848 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
6850 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
6851 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
6854 case 0x1: /* SQADD, UQADD */
6856 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
6857 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
6858 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
6859 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
6861 genenvfn
= fns
[size
][u
];
6864 case 0x5: /* SQSUB, UQSUB */
6866 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
6867 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
6868 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
6869 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
6871 genenvfn
= fns
[size
][u
];
6874 case 0x9: /* SQSHL, UQSHL */
6876 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
6877 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
6878 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
6879 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
6881 genenvfn
= fns
[size
][u
];
6884 case 0xb: /* SQRSHL, UQRSHL */
6886 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
6887 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
6888 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
6889 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
6891 genenvfn
= fns
[size
][u
];
6894 case 0x16: /* SQDMULH, SQRDMULH */
6896 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
6897 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
6898 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
6900 assert(size
== 1 || size
== 2);
6901 genenvfn
= fns
[size
- 1][u
];
6905 g_assert_not_reached();
6908 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
6909 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
6910 tcg_temp_free_i32(tcg_rd32
);
6911 tcg_temp_free_i32(tcg_rn
);
6912 tcg_temp_free_i32(tcg_rm
);
6915 write_fp_dreg(s
, rd
, tcg_rd
);
6917 tcg_temp_free_i64(tcg_rd
);
6920 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
6921 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
6922 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
6924 /* Handle 64->64 opcodes which are shared between the scalar and
6925 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
6926 * is valid in either group and also the double-precision fp ops.
6927 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
6933 case 0x4: /* CLS, CLZ */
6935 gen_helper_clz64(tcg_rd
, tcg_rn
);
6937 gen_helper_cls64(tcg_rd
, tcg_rn
);
6941 /* This opcode is shared with CNT and RBIT but we have earlier
6942 * enforced that size == 3 if and only if this is the NOT insn.
6944 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
6946 case 0x7: /* SQABS, SQNEG */
6948 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
6950 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
6953 case 0xa: /* CMLT */
6954 /* 64 bit integer comparison against zero, result is
6955 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
6960 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
6961 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6963 case 0x8: /* CMGT, CMGE */
6964 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
6966 case 0x9: /* CMEQ, CMLE */
6967 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
6969 case 0xb: /* ABS, NEG */
6971 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
6973 TCGv_i64 tcg_zero
= tcg_const_i64(0);
6974 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
6975 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
6977 tcg_temp_free_i64(tcg_zero
);
6980 case 0x2f: /* FABS */
6981 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
6983 case 0x6f: /* FNEG */
6984 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
6986 case 0x7f: /* FSQRT */
6987 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
6989 case 0x1a: /* FCVTNS */
6990 case 0x1b: /* FCVTMS */
6991 case 0x1c: /* FCVTAS */
6992 case 0x3a: /* FCVTPS */
6993 case 0x3b: /* FCVTZS */
6995 TCGv_i32 tcg_shift
= tcg_const_i32(0);
6996 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
6997 tcg_temp_free_i32(tcg_shift
);
7000 case 0x5a: /* FCVTNU */
7001 case 0x5b: /* FCVTMU */
7002 case 0x5c: /* FCVTAU */
7003 case 0x7a: /* FCVTPU */
7004 case 0x7b: /* FCVTZU */
7006 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7007 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7008 tcg_temp_free_i32(tcg_shift
);
7011 case 0x18: /* FRINTN */
7012 case 0x19: /* FRINTM */
7013 case 0x38: /* FRINTP */
7014 case 0x39: /* FRINTZ */
7015 case 0x58: /* FRINTA */
7016 case 0x79: /* FRINTI */
7017 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7019 case 0x59: /* FRINTX */
7020 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7023 g_assert_not_reached();
7027 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
7028 bool is_scalar
, bool is_u
, bool is_q
,
7029 int size
, int rn
, int rd
)
7031 bool is_double
= (size
== 3);
7032 TCGv_ptr fpst
= get_fpstatus_ptr();
7035 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7036 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7037 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7038 NeonGenTwoDoubleOPFn
*genfn
;
7043 case 0x2e: /* FCMLT (zero) */
7046 case 0x2c: /* FCMGT (zero) */
7047 genfn
= gen_helper_neon_cgt_f64
;
7049 case 0x2d: /* FCMEQ (zero) */
7050 genfn
= gen_helper_neon_ceq_f64
;
7052 case 0x6d: /* FCMLE (zero) */
7055 case 0x6c: /* FCMGE (zero) */
7056 genfn
= gen_helper_neon_cge_f64
;
7059 g_assert_not_reached();
7062 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7063 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7065 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7067 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7069 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7072 clear_vec_high(s
, rd
);
7075 tcg_temp_free_i64(tcg_res
);
7076 tcg_temp_free_i64(tcg_zero
);
7077 tcg_temp_free_i64(tcg_op
);
7079 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7080 TCGv_i32 tcg_zero
= tcg_const_i32(0);
7081 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7082 NeonGenTwoSingleOPFn
*genfn
;
7084 int pass
, maxpasses
;
7087 case 0x2e: /* FCMLT (zero) */
7090 case 0x2c: /* FCMGT (zero) */
7091 genfn
= gen_helper_neon_cgt_f32
;
7093 case 0x2d: /* FCMEQ (zero) */
7094 genfn
= gen_helper_neon_ceq_f32
;
7096 case 0x6d: /* FCMLE (zero) */
7099 case 0x6c: /* FCMGE (zero) */
7100 genfn
= gen_helper_neon_cge_f32
;
7103 g_assert_not_reached();
7109 maxpasses
= is_q
? 4 : 2;
7112 for (pass
= 0; pass
< maxpasses
; pass
++) {
7113 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7115 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7117 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7120 write_fp_sreg(s
, rd
, tcg_res
);
7122 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7125 tcg_temp_free_i32(tcg_res
);
7126 tcg_temp_free_i32(tcg_zero
);
7127 tcg_temp_free_i32(tcg_op
);
7128 if (!is_q
&& !is_scalar
) {
7129 clear_vec_high(s
, rd
);
7133 tcg_temp_free_ptr(fpst
);
7136 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
7137 bool is_scalar
, bool is_u
, bool is_q
,
7138 int size
, int rn
, int rd
)
7140 bool is_double
= (size
== 3);
7141 TCGv_ptr fpst
= get_fpstatus_ptr();
7144 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7145 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7148 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7149 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7151 case 0x3d: /* FRECPE */
7152 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
7154 case 0x3f: /* FRECPX */
7155 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
7157 case 0x7d: /* FRSQRTE */
7158 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
7161 g_assert_not_reached();
7163 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7166 clear_vec_high(s
, rd
);
7169 tcg_temp_free_i64(tcg_res
);
7170 tcg_temp_free_i64(tcg_op
);
7172 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7173 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7174 int pass
, maxpasses
;
7179 maxpasses
= is_q
? 4 : 2;
7182 for (pass
= 0; pass
< maxpasses
; pass
++) {
7183 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7186 case 0x3c: /* URECPE */
7187 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
7189 case 0x3d: /* FRECPE */
7190 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
7192 case 0x3f: /* FRECPX */
7193 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
7195 case 0x7d: /* FRSQRTE */
7196 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
7199 g_assert_not_reached();
7203 write_fp_sreg(s
, rd
, tcg_res
);
7205 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7208 tcg_temp_free_i32(tcg_res
);
7209 tcg_temp_free_i32(tcg_op
);
7210 if (!is_q
&& !is_scalar
) {
7211 clear_vec_high(s
, rd
);
7214 tcg_temp_free_ptr(fpst
);
7217 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
7218 int opcode
, bool u
, bool is_q
,
7219 int size
, int rn
, int rd
)
7221 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
7222 * in the source becomes a size element in the destination).
7225 TCGv_i32 tcg_res
[2];
7226 int destelt
= is_q
? 2 : 0;
7227 int passes
= scalar
? 1 : 2;
7230 tcg_res
[1] = tcg_const_i32(0);
7233 for (pass
= 0; pass
< passes
; pass
++) {
7234 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7235 NeonGenNarrowFn
*genfn
= NULL
;
7236 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
7239 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
7241 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7243 tcg_res
[pass
] = tcg_temp_new_i32();
7246 case 0x12: /* XTN, SQXTUN */
7248 static NeonGenNarrowFn
* const xtnfns
[3] = {
7249 gen_helper_neon_narrow_u8
,
7250 gen_helper_neon_narrow_u16
,
7251 tcg_gen_trunc_i64_i32
,
7253 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
7254 gen_helper_neon_unarrow_sat8
,
7255 gen_helper_neon_unarrow_sat16
,
7256 gen_helper_neon_unarrow_sat32
,
7259 genenvfn
= sqxtunfns
[size
];
7261 genfn
= xtnfns
[size
];
7265 case 0x14: /* SQXTN, UQXTN */
7267 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
7268 { gen_helper_neon_narrow_sat_s8
,
7269 gen_helper_neon_narrow_sat_u8
},
7270 { gen_helper_neon_narrow_sat_s16
,
7271 gen_helper_neon_narrow_sat_u16
},
7272 { gen_helper_neon_narrow_sat_s32
,
7273 gen_helper_neon_narrow_sat_u32
},
7275 genenvfn
= fns
[size
][u
];
7278 case 0x16: /* FCVTN, FCVTN2 */
7279 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
7281 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
7283 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
7284 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
7285 tcg_gen_trunc_i64_i32(tcg_lo
, tcg_op
);
7286 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, cpu_env
);
7287 tcg_gen_shri_i64(tcg_op
, tcg_op
, 32);
7288 tcg_gen_trunc_i64_i32(tcg_hi
, tcg_op
);
7289 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, cpu_env
);
7290 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
7291 tcg_temp_free_i32(tcg_lo
);
7292 tcg_temp_free_i32(tcg_hi
);
7295 case 0x56: /* FCVTXN, FCVTXN2 */
7296 /* 64 bit to 32 bit float conversion
7297 * with von Neumann rounding (round to odd)
7300 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
7303 g_assert_not_reached();
7307 genfn(tcg_res
[pass
], tcg_op
);
7308 } else if (genenvfn
) {
7309 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
7312 tcg_temp_free_i64(tcg_op
);
7315 for (pass
= 0; pass
< 2; pass
++) {
7316 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
7317 tcg_temp_free_i32(tcg_res
[pass
]);
7320 clear_vec_high(s
, rd
);
7324 /* Remaining saturating accumulating ops */
7325 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
7326 bool is_q
, int size
, int rn
, int rd
)
7328 bool is_double
= (size
== 3);
7331 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
7332 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7335 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7336 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
7337 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7339 if (is_u
) { /* USQADD */
7340 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7341 } else { /* SUQADD */
7342 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7344 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7347 clear_vec_high(s
, rd
);
7350 tcg_temp_free_i64(tcg_rd
);
7351 tcg_temp_free_i64(tcg_rn
);
7353 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7354 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7355 int pass
, maxpasses
;
7360 maxpasses
= is_q
? 4 : 2;
7363 for (pass
= 0; pass
< maxpasses
; pass
++) {
7365 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
7366 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
7368 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
7369 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7372 if (is_u
) { /* USQADD */
7375 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7378 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7381 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7384 g_assert_not_reached();
7386 } else { /* SUQADD */
7389 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7392 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7395 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7398 g_assert_not_reached();
7403 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7404 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
7405 tcg_temp_free_i64(tcg_zero
);
7407 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7411 clear_vec_high(s
, rd
);
7414 tcg_temp_free_i32(tcg_rd
);
7415 tcg_temp_free_i32(tcg_rn
);
7419 /* C3.6.12 AdvSIMD scalar two reg misc
7420 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7421 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7422 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
7423 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7425 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
7427 int rd
= extract32(insn
, 0, 5);
7428 int rn
= extract32(insn
, 5, 5);
7429 int opcode
= extract32(insn
, 12, 5);
7430 int size
= extract32(insn
, 22, 2);
7431 bool u
= extract32(insn
, 29, 1);
7432 bool is_fcvt
= false;
7435 TCGv_ptr tcg_fpstatus
;
7438 case 0x3: /* USQADD / SUQADD*/
7439 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
7441 case 0x7: /* SQABS / SQNEG */
7443 case 0xa: /* CMLT */
7445 unallocated_encoding(s
);
7449 case 0x8: /* CMGT, CMGE */
7450 case 0x9: /* CMEQ, CMLE */
7451 case 0xb: /* ABS, NEG */
7453 unallocated_encoding(s
);
7457 case 0x12: /* SQXTUN */
7459 unallocated_encoding(s
);
7463 case 0x14: /* SQXTN, UQXTN */
7465 unallocated_encoding(s
);
7468 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
7473 /* Floating point: U, size[1] and opcode indicate operation;
7474 * size[0] indicates single or double precision.
7476 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
7477 size
= extract32(size
, 0, 1) ? 3 : 2;
7479 case 0x2c: /* FCMGT (zero) */
7480 case 0x2d: /* FCMEQ (zero) */
7481 case 0x2e: /* FCMLT (zero) */
7482 case 0x6c: /* FCMGE (zero) */
7483 case 0x6d: /* FCMLE (zero) */
7484 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
7486 case 0x1d: /* SCVTF */
7487 case 0x5d: /* UCVTF */
7489 bool is_signed
= (opcode
== 0x1d);
7490 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
7493 case 0x3d: /* FRECPE */
7494 case 0x3f: /* FRECPX */
7495 case 0x7d: /* FRSQRTE */
7496 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
7498 case 0x1a: /* FCVTNS */
7499 case 0x1b: /* FCVTMS */
7500 case 0x3a: /* FCVTPS */
7501 case 0x3b: /* FCVTZS */
7502 case 0x5a: /* FCVTNU */
7503 case 0x5b: /* FCVTMU */
7504 case 0x7a: /* FCVTPU */
7505 case 0x7b: /* FCVTZU */
7507 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
7509 case 0x1c: /* FCVTAS */
7510 case 0x5c: /* FCVTAU */
7511 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
7513 rmode
= FPROUNDING_TIEAWAY
;
7515 case 0x56: /* FCVTXN, FCVTXN2 */
7517 unallocated_encoding(s
);
7520 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
7523 unallocated_encoding(s
);
7528 unallocated_encoding(s
);
7533 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
7534 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
7535 tcg_fpstatus
= get_fpstatus_ptr();
7537 TCGV_UNUSED_I32(tcg_rmode
);
7538 TCGV_UNUSED_PTR(tcg_fpstatus
);
7542 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7543 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7545 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
7546 write_fp_dreg(s
, rd
, tcg_rd
);
7547 tcg_temp_free_i64(tcg_rd
);
7548 tcg_temp_free_i64(tcg_rn
);
7550 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7551 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7553 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7556 case 0x7: /* SQABS, SQNEG */
7558 NeonGenOneOpEnvFn
*genfn
;
7559 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
7560 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
7561 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
7562 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
7564 genfn
= fns
[size
][u
];
7565 genfn(tcg_rd
, cpu_env
, tcg_rn
);
7568 case 0x1a: /* FCVTNS */
7569 case 0x1b: /* FCVTMS */
7570 case 0x1c: /* FCVTAS */
7571 case 0x3a: /* FCVTPS */
7572 case 0x3b: /* FCVTZS */
7574 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7575 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7576 tcg_temp_free_i32(tcg_shift
);
7579 case 0x5a: /* FCVTNU */
7580 case 0x5b: /* FCVTMU */
7581 case 0x5c: /* FCVTAU */
7582 case 0x7a: /* FCVTPU */
7583 case 0x7b: /* FCVTZU */
7585 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7586 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7587 tcg_temp_free_i32(tcg_shift
);
7591 g_assert_not_reached();
7594 write_fp_sreg(s
, rd
, tcg_rd
);
7595 tcg_temp_free_i32(tcg_rd
);
7596 tcg_temp_free_i32(tcg_rn
);
7600 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
7601 tcg_temp_free_i32(tcg_rmode
);
7602 tcg_temp_free_ptr(tcg_fpstatus
);
7606 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
7607 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
7608 int immh
, int immb
, int opcode
, int rn
, int rd
)
7610 int size
= 32 - clz32(immh
) - 1;
7611 int immhb
= immh
<< 3 | immb
;
7612 int shift
= 2 * (8 << size
) - immhb
;
7613 bool accumulate
= false;
7615 bool insert
= false;
7616 int dsize
= is_q
? 128 : 64;
7617 int esize
= 8 << size
;
7618 int elements
= dsize
/esize
;
7619 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
7620 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
7621 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
7625 if (extract32(immh
, 3, 1) && !is_q
) {
7626 unallocated_encoding(s
);
7630 if (size
> 3 && !is_q
) {
7631 unallocated_encoding(s
);
7636 case 0x02: /* SSRA / USRA (accumulate) */
7639 case 0x04: /* SRSHR / URSHR (rounding) */
7642 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7643 accumulate
= round
= true;
7645 case 0x08: /* SRI */
7651 uint64_t round_const
= 1ULL << (shift
- 1);
7652 tcg_round
= tcg_const_i64(round_const
);
7654 TCGV_UNUSED_I64(tcg_round
);
7657 for (i
= 0; i
< elements
; i
++) {
7658 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
7659 if (accumulate
|| insert
) {
7660 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
7664 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
7666 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7667 accumulate
, is_u
, size
, shift
);
7670 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
7674 clear_vec_high(s
, rd
);
7678 tcg_temp_free_i64(tcg_round
);
7682 /* SHL/SLI - Vector shift left */
7683 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
7684 int immh
, int immb
, int opcode
, int rn
, int rd
)
7686 int size
= 32 - clz32(immh
) - 1;
7687 int immhb
= immh
<< 3 | immb
;
7688 int shift
= immhb
- (8 << size
);
7689 int dsize
= is_q
? 128 : 64;
7690 int esize
= 8 << size
;
7691 int elements
= dsize
/esize
;
7692 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
7693 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
7696 if (extract32(immh
, 3, 1) && !is_q
) {
7697 unallocated_encoding(s
);
7701 if (size
> 3 && !is_q
) {
7702 unallocated_encoding(s
);
7706 for (i
= 0; i
< elements
; i
++) {
7707 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
7709 read_vec_element(s
, tcg_rd
, rd
, i
, size
);
7712 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
7714 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
7718 clear_vec_high(s
, rd
);
7722 /* USHLL/SHLL - Vector shift left with widening */
7723 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
7724 int immh
, int immb
, int opcode
, int rn
, int rd
)
7726 int size
= 32 - clz32(immh
) - 1;
7727 int immhb
= immh
<< 3 | immb
;
7728 int shift
= immhb
- (8 << size
);
7730 int esize
= 8 << size
;
7731 int elements
= dsize
/esize
;
7732 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
7733 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
7737 unallocated_encoding(s
);
7741 /* For the LL variants the store is larger than the load,
7742 * so if rd == rn we would overwrite parts of our input.
7743 * So load everything right now and use shifts in the main loop.
7745 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
7747 for (i
= 0; i
< elements
; i
++) {
7748 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
7749 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
7750 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
7751 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
7755 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
7756 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
7757 int immh
, int immb
, int opcode
, int rn
, int rd
)
7759 int immhb
= immh
<< 3 | immb
;
7760 int size
= 32 - clz32(immh
) - 1;
7762 int esize
= 8 << size
;
7763 int elements
= dsize
/esize
;
7764 int shift
= (2 * esize
) - immhb
;
7765 bool round
= extract32(opcode
, 0, 1);
7766 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
7770 if (extract32(immh
, 3, 1)) {
7771 unallocated_encoding(s
);
7775 tcg_rn
= tcg_temp_new_i64();
7776 tcg_rd
= tcg_temp_new_i64();
7777 tcg_final
= tcg_temp_new_i64();
7778 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
7781 uint64_t round_const
= 1ULL << (shift
- 1);
7782 tcg_round
= tcg_const_i64(round_const
);
7784 TCGV_UNUSED_I64(tcg_round
);
7787 for (i
= 0; i
< elements
; i
++) {
7788 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
7789 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7790 false, true, size
+1, shift
);
7792 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
7796 clear_vec_high(s
, rd
);
7797 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
7799 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
7803 tcg_temp_free_i64(tcg_round
);
7805 tcg_temp_free_i64(tcg_rn
);
7806 tcg_temp_free_i64(tcg_rd
);
7807 tcg_temp_free_i64(tcg_final
);
7812 /* C3.6.14 AdvSIMD shift by immediate
7813 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
7814 * +---+---+---+-------------+------+------+--------+---+------+------+
7815 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
7816 * +---+---+---+-------------+------+------+--------+---+------+------+
7818 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
7820 int rd
= extract32(insn
, 0, 5);
7821 int rn
= extract32(insn
, 5, 5);
7822 int opcode
= extract32(insn
, 11, 5);
7823 int immb
= extract32(insn
, 16, 3);
7824 int immh
= extract32(insn
, 19, 4);
7825 bool is_u
= extract32(insn
, 29, 1);
7826 bool is_q
= extract32(insn
, 30, 1);
7829 case 0x08: /* SRI */
7831 unallocated_encoding(s
);
7835 case 0x00: /* SSHR / USHR */
7836 case 0x02: /* SSRA / USRA (accumulate) */
7837 case 0x04: /* SRSHR / URSHR (rounding) */
7838 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7839 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
7841 case 0x0a: /* SHL / SLI */
7842 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
7844 case 0x10: /* SHRN */
7845 case 0x11: /* RSHRN / SQRSHRUN */
7847 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
7850 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
7853 case 0x12: /* SQSHRN / UQSHRN */
7854 case 0x13: /* SQRSHRN / UQRSHRN */
7855 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
7858 case 0x14: /* SSHLL / USHLL */
7859 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
7861 case 0x1c: /* SCVTF / UCVTF */
7862 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
7865 case 0xc: /* SQSHLU */
7867 unallocated_encoding(s
);
7870 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
7872 case 0xe: /* SQSHL, UQSHL */
7873 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
7875 case 0x1f: /* FCVTZS/ FCVTZU */
7876 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
7879 unallocated_encoding(s
);
7884 /* Generate code to do a "long" addition or subtraction, ie one done in
7885 * TCGv_i64 on vector lanes twice the width specified by size.
7887 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
7888 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
7890 static NeonGenTwo64OpFn
* const fns
[3][2] = {
7891 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
7892 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
7893 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
7895 NeonGenTwo64OpFn
*genfn
;
7898 genfn
= fns
[size
][is_sub
];
7899 genfn(tcg_res
, tcg_op1
, tcg_op2
);
7902 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
7903 int opcode
, int rd
, int rn
, int rm
)
7905 /* 3-reg-different widening insns: 64 x 64 -> 128 */
7906 TCGv_i64 tcg_res
[2];
7909 tcg_res
[0] = tcg_temp_new_i64();
7910 tcg_res
[1] = tcg_temp_new_i64();
7912 /* Does this op do an adding accumulate, a subtracting accumulate,
7913 * or no accumulate at all?
7931 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
7932 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
7935 /* size == 2 means two 32x32->64 operations; this is worth special
7936 * casing because we can generally handle it inline.
7939 for (pass
= 0; pass
< 2; pass
++) {
7940 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7941 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7942 TCGv_i64 tcg_passres
;
7943 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
7945 int elt
= pass
+ is_q
* 2;
7947 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
7948 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
7951 tcg_passres
= tcg_res
[pass
];
7953 tcg_passres
= tcg_temp_new_i64();
7957 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
7958 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
7960 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
7961 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
7963 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
7964 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
7966 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
7967 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
7969 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
7970 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
7971 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
7973 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
7974 tcg_temp_free_i64(tcg_tmp1
);
7975 tcg_temp_free_i64(tcg_tmp2
);
7978 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
7979 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
7980 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
7981 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
7983 case 9: /* SQDMLAL, SQDMLAL2 */
7984 case 11: /* SQDMLSL, SQDMLSL2 */
7985 case 13: /* SQDMULL, SQDMULL2 */
7986 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
7987 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
7988 tcg_passres
, tcg_passres
);
7991 g_assert_not_reached();
7994 if (opcode
== 9 || opcode
== 11) {
7995 /* saturating accumulate ops */
7997 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
7999 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
8000 tcg_res
[pass
], tcg_passres
);
8001 } else if (accop
> 0) {
8002 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8003 } else if (accop
< 0) {
8004 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8008 tcg_temp_free_i64(tcg_passres
);
8011 tcg_temp_free_i64(tcg_op1
);
8012 tcg_temp_free_i64(tcg_op2
);
8015 /* size 0 or 1, generally helper functions */
8016 for (pass
= 0; pass
< 2; pass
++) {
8017 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8018 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8019 TCGv_i64 tcg_passres
;
8020 int elt
= pass
+ is_q
* 2;
8022 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
8023 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
8026 tcg_passres
= tcg_res
[pass
];
8028 tcg_passres
= tcg_temp_new_i64();
8032 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8033 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8035 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
8036 static NeonGenWidenFn
* const widenfns
[2][2] = {
8037 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8038 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8040 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8042 widenfn(tcg_op2_64
, tcg_op2
);
8043 widenfn(tcg_passres
, tcg_op1
);
8044 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
8045 tcg_passres
, tcg_op2_64
);
8046 tcg_temp_free_i64(tcg_op2_64
);
8049 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8050 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8053 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8055 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8059 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
8061 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
8065 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8066 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8067 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8070 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
8072 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
8076 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8078 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8082 case 9: /* SQDMLAL, SQDMLAL2 */
8083 case 11: /* SQDMLSL, SQDMLSL2 */
8084 case 13: /* SQDMULL, SQDMULL2 */
8086 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8087 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
8088 tcg_passres
, tcg_passres
);
8090 case 14: /* PMULL */
8092 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
8095 g_assert_not_reached();
8097 tcg_temp_free_i32(tcg_op1
);
8098 tcg_temp_free_i32(tcg_op2
);
8101 if (opcode
== 9 || opcode
== 11) {
8102 /* saturating accumulate ops */
8104 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
8106 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
8110 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
8111 tcg_res
[pass
], tcg_passres
);
8113 tcg_temp_free_i64(tcg_passres
);
8118 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8119 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8120 tcg_temp_free_i64(tcg_res
[0]);
8121 tcg_temp_free_i64(tcg_res
[1]);
8124 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
8125 int opcode
, int rd
, int rn
, int rm
)
8127 TCGv_i64 tcg_res
[2];
8128 int part
= is_q
? 2 : 0;
8131 for (pass
= 0; pass
< 2; pass
++) {
8132 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8133 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8134 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
8135 static NeonGenWidenFn
* const widenfns
[3][2] = {
8136 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8137 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8138 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
8140 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8142 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8143 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
8144 widenfn(tcg_op2_wide
, tcg_op2
);
8145 tcg_temp_free_i32(tcg_op2
);
8146 tcg_res
[pass
] = tcg_temp_new_i64();
8147 gen_neon_addl(size
, (opcode
== 3),
8148 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
8149 tcg_temp_free_i64(tcg_op1
);
8150 tcg_temp_free_i64(tcg_op2_wide
);
8153 for (pass
= 0; pass
< 2; pass
++) {
8154 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8155 tcg_temp_free_i64(tcg_res
[pass
]);
8159 static void do_narrow_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8161 tcg_gen_shri_i64(in
, in
, 32);
8162 tcg_gen_trunc_i64_i32(res
, in
);
8165 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8167 tcg_gen_addi_i64(in
, in
, 1U << 31);
8168 do_narrow_high_u32(res
, in
);
8171 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
8172 int opcode
, int rd
, int rn
, int rm
)
8174 TCGv_i32 tcg_res
[2];
8175 int part
= is_q
? 2 : 0;
8178 for (pass
= 0; pass
< 2; pass
++) {
8179 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8180 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8181 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
8182 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
8183 { gen_helper_neon_narrow_high_u8
,
8184 gen_helper_neon_narrow_round_high_u8
},
8185 { gen_helper_neon_narrow_high_u16
,
8186 gen_helper_neon_narrow_round_high_u16
},
8187 { do_narrow_high_u32
, do_narrow_round_high_u32
},
8189 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
8191 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8192 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8194 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
8196 tcg_temp_free_i64(tcg_op1
);
8197 tcg_temp_free_i64(tcg_op2
);
8199 tcg_res
[pass
] = tcg_temp_new_i32();
8200 gennarrow(tcg_res
[pass
], tcg_wideres
);
8201 tcg_temp_free_i64(tcg_wideres
);
8204 for (pass
= 0; pass
< 2; pass
++) {
8205 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
8206 tcg_temp_free_i32(tcg_res
[pass
]);
8209 clear_vec_high(s
, rd
);
8213 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
8215 /* PMULL of 64 x 64 -> 128 is an odd special case because it
8216 * is the only three-reg-diff instruction which produces a
8217 * 128-bit wide result from a single operation. However since
8218 * it's possible to calculate the two halves more or less
8219 * separately we just use two helper calls.
8221 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8222 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8223 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8225 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
8226 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
8227 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
8228 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
8229 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
8230 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
8232 tcg_temp_free_i64(tcg_op1
);
8233 tcg_temp_free_i64(tcg_op2
);
8234 tcg_temp_free_i64(tcg_res
);
8237 /* C3.6.15 AdvSIMD three different
8238 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8239 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8240 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8241 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8243 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8245 /* Instructions in this group fall into three basic classes
8246 * (in each case with the operation working on each element in
8247 * the input vectors):
8248 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
8250 * (2) wide 64 x 128 -> 128
8251 * (3) narrowing 128 x 128 -> 64
8252 * Here we do initial decode, catch unallocated cases and
8253 * dispatch to separate functions for each class.
8255 int is_q
= extract32(insn
, 30, 1);
8256 int is_u
= extract32(insn
, 29, 1);
8257 int size
= extract32(insn
, 22, 2);
8258 int opcode
= extract32(insn
, 12, 4);
8259 int rm
= extract32(insn
, 16, 5);
8260 int rn
= extract32(insn
, 5, 5);
8261 int rd
= extract32(insn
, 0, 5);
8264 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
8265 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
8266 /* 64 x 128 -> 128 */
8268 unallocated_encoding(s
);
8271 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8273 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
8274 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
8275 /* 128 x 128 -> 64 */
8277 unallocated_encoding(s
);
8280 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8282 case 14: /* PMULL, PMULL2 */
8283 if (is_u
|| size
== 1 || size
== 2) {
8284 unallocated_encoding(s
);
8288 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)) {
8289 unallocated_encoding(s
);
8292 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
8296 case 9: /* SQDMLAL, SQDMLAL2 */
8297 case 11: /* SQDMLSL, SQDMLSL2 */
8298 case 13: /* SQDMULL, SQDMULL2 */
8299 if (is_u
|| size
== 0) {
8300 unallocated_encoding(s
);
8304 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8305 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8306 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8307 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8308 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8309 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8310 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
8311 /* 64 x 64 -> 128 */
8313 unallocated_encoding(s
);
8317 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8320 /* opcode 15 not allocated */
8321 unallocated_encoding(s
);
8326 /* Logic op (opcode == 3) subgroup of C3.6.16. */
8327 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
8329 int rd
= extract32(insn
, 0, 5);
8330 int rn
= extract32(insn
, 5, 5);
8331 int rm
= extract32(insn
, 16, 5);
8332 int size
= extract32(insn
, 22, 2);
8333 bool is_u
= extract32(insn
, 29, 1);
8334 bool is_q
= extract32(insn
, 30, 1);
8335 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8336 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8337 TCGv_i64 tcg_res
[2];
8340 tcg_res
[0] = tcg_temp_new_i64();
8341 tcg_res
[1] = tcg_temp_new_i64();
8343 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
8344 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8345 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8350 tcg_gen_and_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8353 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8356 tcg_gen_or_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8359 tcg_gen_orc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8364 /* B* ops need res loaded to operate on */
8365 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8370 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8372 case 1: /* BSL bitwise select */
8373 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8374 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8375 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op1
);
8377 case 2: /* BIT, bitwise insert if true */
8378 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8379 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8380 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8382 case 3: /* BIF, bitwise insert if false */
8383 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8384 tcg_gen_andc_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8385 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8391 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8393 tcg_gen_movi_i64(tcg_res
[1], 0);
8395 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8397 tcg_temp_free_i64(tcg_op1
);
8398 tcg_temp_free_i64(tcg_op2
);
8399 tcg_temp_free_i64(tcg_res
[0]);
8400 tcg_temp_free_i64(tcg_res
[1]);
8403 /* Helper functions for 32 bit comparisons */
8404 static void gen_max_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8406 tcg_gen_movcond_i32(TCG_COND_GE
, res
, op1
, op2
, op1
, op2
);
8409 static void gen_max_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8411 tcg_gen_movcond_i32(TCG_COND_GEU
, res
, op1
, op2
, op1
, op2
);
8414 static void gen_min_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8416 tcg_gen_movcond_i32(TCG_COND_LE
, res
, op1
, op2
, op1
, op2
);
8419 static void gen_min_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8421 tcg_gen_movcond_i32(TCG_COND_LEU
, res
, op1
, op2
, op1
, op2
);
8424 /* Pairwise op subgroup of C3.6.16.
8426 * This is called directly or via the handle_3same_float for float pairwise
8427 * operations where the opcode and size are calculated differently.
8429 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
8430 int size
, int rn
, int rm
, int rd
)
8435 /* Floating point operations need fpst */
8436 if (opcode
>= 0x58) {
8437 fpst
= get_fpstatus_ptr();
8439 TCGV_UNUSED_PTR(fpst
);
8442 /* These operations work on the concatenated rm:rn, with each pair of
8443 * adjacent elements being operated on to produce an element in the result.
8446 TCGv_i64 tcg_res
[2];
8448 for (pass
= 0; pass
< 2; pass
++) {
8449 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8450 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8451 int passreg
= (pass
== 0) ? rn
: rm
;
8453 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
8454 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
8455 tcg_res
[pass
] = tcg_temp_new_i64();
8458 case 0x17: /* ADDP */
8459 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8461 case 0x58: /* FMAXNMP */
8462 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8464 case 0x5a: /* FADDP */
8465 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8467 case 0x5e: /* FMAXP */
8468 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8470 case 0x78: /* FMINNMP */
8471 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8473 case 0x7e: /* FMINP */
8474 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8477 g_assert_not_reached();
8480 tcg_temp_free_i64(tcg_op1
);
8481 tcg_temp_free_i64(tcg_op2
);
8484 for (pass
= 0; pass
< 2; pass
++) {
8485 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8486 tcg_temp_free_i64(tcg_res
[pass
]);
8489 int maxpass
= is_q
? 4 : 2;
8490 TCGv_i32 tcg_res
[4];
8492 for (pass
= 0; pass
< maxpass
; pass
++) {
8493 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8494 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8495 NeonGenTwoOpFn
*genfn
= NULL
;
8496 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
8497 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
8499 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
8500 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
8501 tcg_res
[pass
] = tcg_temp_new_i32();
8504 case 0x17: /* ADDP */
8506 static NeonGenTwoOpFn
* const fns
[3] = {
8507 gen_helper_neon_padd_u8
,
8508 gen_helper_neon_padd_u16
,
8514 case 0x14: /* SMAXP, UMAXP */
8516 static NeonGenTwoOpFn
* const fns
[3][2] = {
8517 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
8518 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
8519 { gen_max_s32
, gen_max_u32
},
8521 genfn
= fns
[size
][u
];
8524 case 0x15: /* SMINP, UMINP */
8526 static NeonGenTwoOpFn
* const fns
[3][2] = {
8527 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
8528 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
8529 { gen_min_s32
, gen_min_u32
},
8531 genfn
= fns
[size
][u
];
8534 /* The FP operations are all on single floats (32 bit) */
8535 case 0x58: /* FMAXNMP */
8536 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8538 case 0x5a: /* FADDP */
8539 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8541 case 0x5e: /* FMAXP */
8542 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8544 case 0x78: /* FMINNMP */
8545 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8547 case 0x7e: /* FMINP */
8548 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8551 g_assert_not_reached();
8554 /* FP ops called directly, otherwise call now */
8556 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8559 tcg_temp_free_i32(tcg_op1
);
8560 tcg_temp_free_i32(tcg_op2
);
8563 for (pass
= 0; pass
< maxpass
; pass
++) {
8564 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
8565 tcg_temp_free_i32(tcg_res
[pass
]);
8568 clear_vec_high(s
, rd
);
8572 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
8573 tcg_temp_free_ptr(fpst
);
8577 /* Floating point op subgroup of C3.6.16. */
8578 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
8580 /* For floating point ops, the U, size[1] and opcode bits
8581 * together indicate the operation. size[0] indicates single
8584 int fpopcode
= extract32(insn
, 11, 5)
8585 | (extract32(insn
, 23, 1) << 5)
8586 | (extract32(insn
, 29, 1) << 6);
8587 int is_q
= extract32(insn
, 30, 1);
8588 int size
= extract32(insn
, 22, 1);
8589 int rm
= extract32(insn
, 16, 5);
8590 int rn
= extract32(insn
, 5, 5);
8591 int rd
= extract32(insn
, 0, 5);
8593 int datasize
= is_q
? 128 : 64;
8594 int esize
= 32 << size
;
8595 int elements
= datasize
/ esize
;
8597 if (size
== 1 && !is_q
) {
8598 unallocated_encoding(s
);
8603 case 0x58: /* FMAXNMP */
8604 case 0x5a: /* FADDP */
8605 case 0x5e: /* FMAXP */
8606 case 0x78: /* FMINNMP */
8607 case 0x7e: /* FMINP */
8608 if (size
&& !is_q
) {
8609 unallocated_encoding(s
);
8612 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
8615 case 0x1b: /* FMULX */
8616 case 0x1f: /* FRECPS */
8617 case 0x3f: /* FRSQRTS */
8618 case 0x5d: /* FACGE */
8619 case 0x7d: /* FACGT */
8620 case 0x19: /* FMLA */
8621 case 0x39: /* FMLS */
8622 case 0x18: /* FMAXNM */
8623 case 0x1a: /* FADD */
8624 case 0x1c: /* FCMEQ */
8625 case 0x1e: /* FMAX */
8626 case 0x38: /* FMINNM */
8627 case 0x3a: /* FSUB */
8628 case 0x3e: /* FMIN */
8629 case 0x5b: /* FMUL */
8630 case 0x5c: /* FCMGE */
8631 case 0x5f: /* FDIV */
8632 case 0x7a: /* FABD */
8633 case 0x7c: /* FCMGT */
8634 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
8637 unallocated_encoding(s
);
8642 /* Integer op subgroup of C3.6.16. */
8643 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
8645 int is_q
= extract32(insn
, 30, 1);
8646 int u
= extract32(insn
, 29, 1);
8647 int size
= extract32(insn
, 22, 2);
8648 int opcode
= extract32(insn
, 11, 5);
8649 int rm
= extract32(insn
, 16, 5);
8650 int rn
= extract32(insn
, 5, 5);
8651 int rd
= extract32(insn
, 0, 5);
8655 case 0x13: /* MUL, PMUL */
8656 if (u
&& size
!= 0) {
8657 unallocated_encoding(s
);
8661 case 0x0: /* SHADD, UHADD */
8662 case 0x2: /* SRHADD, URHADD */
8663 case 0x4: /* SHSUB, UHSUB */
8664 case 0xc: /* SMAX, UMAX */
8665 case 0xd: /* SMIN, UMIN */
8666 case 0xe: /* SABD, UABD */
8667 case 0xf: /* SABA, UABA */
8668 case 0x12: /* MLA, MLS */
8670 unallocated_encoding(s
);
8674 case 0x16: /* SQDMULH, SQRDMULH */
8675 if (size
== 0 || size
== 3) {
8676 unallocated_encoding(s
);
8681 if (size
== 3 && !is_q
) {
8682 unallocated_encoding(s
);
8689 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
8690 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8691 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8692 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8694 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8695 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8697 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
8699 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8701 tcg_temp_free_i64(tcg_res
);
8702 tcg_temp_free_i64(tcg_op1
);
8703 tcg_temp_free_i64(tcg_op2
);
8706 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
8707 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8708 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8709 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8710 NeonGenTwoOpFn
*genfn
= NULL
;
8711 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
8713 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
8714 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
8717 case 0x0: /* SHADD, UHADD */
8719 static NeonGenTwoOpFn
* const fns
[3][2] = {
8720 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
8721 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
8722 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
8724 genfn
= fns
[size
][u
];
8727 case 0x1: /* SQADD, UQADD */
8729 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8730 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
8731 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
8732 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
8734 genenvfn
= fns
[size
][u
];
8737 case 0x2: /* SRHADD, URHADD */
8739 static NeonGenTwoOpFn
* const fns
[3][2] = {
8740 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
8741 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
8742 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
8744 genfn
= fns
[size
][u
];
8747 case 0x4: /* SHSUB, UHSUB */
8749 static NeonGenTwoOpFn
* const fns
[3][2] = {
8750 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
8751 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
8752 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
8754 genfn
= fns
[size
][u
];
8757 case 0x5: /* SQSUB, UQSUB */
8759 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8760 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
8761 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
8762 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
8764 genenvfn
= fns
[size
][u
];
8767 case 0x6: /* CMGT, CMHI */
8769 static NeonGenTwoOpFn
* const fns
[3][2] = {
8770 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_u8
},
8771 { gen_helper_neon_cgt_s16
, gen_helper_neon_cgt_u16
},
8772 { gen_helper_neon_cgt_s32
, gen_helper_neon_cgt_u32
},
8774 genfn
= fns
[size
][u
];
8777 case 0x7: /* CMGE, CMHS */
8779 static NeonGenTwoOpFn
* const fns
[3][2] = {
8780 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_u8
},
8781 { gen_helper_neon_cge_s16
, gen_helper_neon_cge_u16
},
8782 { gen_helper_neon_cge_s32
, gen_helper_neon_cge_u32
},
8784 genfn
= fns
[size
][u
];
8787 case 0x8: /* SSHL, USHL */
8789 static NeonGenTwoOpFn
* const fns
[3][2] = {
8790 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
8791 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
8792 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
8794 genfn
= fns
[size
][u
];
8797 case 0x9: /* SQSHL, UQSHL */
8799 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8800 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
8801 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
8802 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
8804 genenvfn
= fns
[size
][u
];
8807 case 0xa: /* SRSHL, URSHL */
8809 static NeonGenTwoOpFn
* const fns
[3][2] = {
8810 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
8811 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
8812 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
8814 genfn
= fns
[size
][u
];
8817 case 0xb: /* SQRSHL, UQRSHL */
8819 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8820 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
8821 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
8822 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
8824 genenvfn
= fns
[size
][u
];
8827 case 0xc: /* SMAX, UMAX */
8829 static NeonGenTwoOpFn
* const fns
[3][2] = {
8830 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
8831 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
8832 { gen_max_s32
, gen_max_u32
},
8834 genfn
= fns
[size
][u
];
8838 case 0xd: /* SMIN, UMIN */
8840 static NeonGenTwoOpFn
* const fns
[3][2] = {
8841 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
8842 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
8843 { gen_min_s32
, gen_min_u32
},
8845 genfn
= fns
[size
][u
];
8848 case 0xe: /* SABD, UABD */
8849 case 0xf: /* SABA, UABA */
8851 static NeonGenTwoOpFn
* const fns
[3][2] = {
8852 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
8853 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
8854 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
8856 genfn
= fns
[size
][u
];
8859 case 0x10: /* ADD, SUB */
8861 static NeonGenTwoOpFn
* const fns
[3][2] = {
8862 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
8863 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
8864 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
8866 genfn
= fns
[size
][u
];
8869 case 0x11: /* CMTST, CMEQ */
8871 static NeonGenTwoOpFn
* const fns
[3][2] = {
8872 { gen_helper_neon_tst_u8
, gen_helper_neon_ceq_u8
},
8873 { gen_helper_neon_tst_u16
, gen_helper_neon_ceq_u16
},
8874 { gen_helper_neon_tst_u32
, gen_helper_neon_ceq_u32
},
8876 genfn
= fns
[size
][u
];
8879 case 0x13: /* MUL, PMUL */
8883 genfn
= gen_helper_neon_mul_p8
;
8886 /* fall through : MUL */
8887 case 0x12: /* MLA, MLS */
8889 static NeonGenTwoOpFn
* const fns
[3] = {
8890 gen_helper_neon_mul_u8
,
8891 gen_helper_neon_mul_u16
,
8897 case 0x16: /* SQDMULH, SQRDMULH */
8899 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
8900 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
8901 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
8903 assert(size
== 1 || size
== 2);
8904 genenvfn
= fns
[size
- 1][u
];
8908 g_assert_not_reached();
8912 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
8914 genfn(tcg_res
, tcg_op1
, tcg_op2
);
8917 if (opcode
== 0xf || opcode
== 0x12) {
8918 /* SABA, UABA, MLA, MLS: accumulating ops */
8919 static NeonGenTwoOpFn
* const fns
[3][2] = {
8920 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
8921 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
8922 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
8924 bool is_sub
= (opcode
== 0x12 && u
); /* MLS */
8926 genfn
= fns
[size
][is_sub
];
8927 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
8928 genfn(tcg_res
, tcg_op1
, tcg_res
);
8931 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8933 tcg_temp_free_i32(tcg_res
);
8934 tcg_temp_free_i32(tcg_op1
);
8935 tcg_temp_free_i32(tcg_op2
);
8940 clear_vec_high(s
, rd
);
8944 /* C3.6.16 AdvSIMD three same
8945 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8946 * +---+---+---+-----------+------+---+------+--------+---+------+------+
8947 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8948 * +---+---+---+-----------+------+---+------+--------+---+------+------+
8950 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
8952 int opcode
= extract32(insn
, 11, 5);
8955 case 0x3: /* logic ops */
8956 disas_simd_3same_logic(s
, insn
);
8958 case 0x17: /* ADDP */
8959 case 0x14: /* SMAXP, UMAXP */
8960 case 0x15: /* SMINP, UMINP */
8962 /* Pairwise operations */
8963 int is_q
= extract32(insn
, 30, 1);
8964 int u
= extract32(insn
, 29, 1);
8965 int size
= extract32(insn
, 22, 2);
8966 int rm
= extract32(insn
, 16, 5);
8967 int rn
= extract32(insn
, 5, 5);
8968 int rd
= extract32(insn
, 0, 5);
8969 if (opcode
== 0x17) {
8970 if (u
|| (size
== 3 && !is_q
)) {
8971 unallocated_encoding(s
);
8976 unallocated_encoding(s
);
8980 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
8984 /* floating point ops, sz[1] and U are part of opcode */
8985 disas_simd_3same_float(s
, insn
);
8988 disas_simd_3same_int(s
, insn
);
8993 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
8994 int size
, int rn
, int rd
)
8996 /* Handle 2-reg-misc ops which are widening (so each size element
8997 * in the source becomes a 2*size element in the destination.
8998 * The only instruction like this is FCVTL.
9003 /* 32 -> 64 bit fp conversion */
9004 TCGv_i64 tcg_res
[2];
9005 int srcelt
= is_q
? 2 : 0;
9007 for (pass
= 0; pass
< 2; pass
++) {
9008 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9009 tcg_res
[pass
] = tcg_temp_new_i64();
9011 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
9012 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
9013 tcg_temp_free_i32(tcg_op
);
9015 for (pass
= 0; pass
< 2; pass
++) {
9016 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9017 tcg_temp_free_i64(tcg_res
[pass
]);
9020 /* 16 -> 32 bit fp conversion */
9021 int srcelt
= is_q
? 4 : 0;
9022 TCGv_i32 tcg_res
[4];
9024 for (pass
= 0; pass
< 4; pass
++) {
9025 tcg_res
[pass
] = tcg_temp_new_i32();
9027 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
9028 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
9031 for (pass
= 0; pass
< 4; pass
++) {
9032 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9033 tcg_temp_free_i32(tcg_res
[pass
]);
9038 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
9039 bool is_q
, int size
, int rn
, int rd
)
9041 int op
= (opcode
<< 1) | u
;
9042 int opsz
= op
+ size
;
9043 int grp_size
= 3 - opsz
;
9044 int dsize
= is_q
? 128 : 64;
9048 unallocated_encoding(s
);
9053 /* Special case bytes, use bswap op on each group of elements */
9054 int groups
= dsize
/ (8 << grp_size
);
9056 for (i
= 0; i
< groups
; i
++) {
9057 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9059 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
9062 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
9065 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
9068 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
9071 g_assert_not_reached();
9073 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
9074 tcg_temp_free_i64(tcg_tmp
);
9077 clear_vec_high(s
, rd
);
9080 int revmask
= (1 << grp_size
) - 1;
9081 int esize
= 8 << size
;
9082 int elements
= dsize
/ esize
;
9083 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9084 TCGv_i64 tcg_rd
= tcg_const_i64(0);
9085 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
9087 for (i
= 0; i
< elements
; i
++) {
9088 int e_rev
= (i
& 0xf) ^ revmask
;
9089 int off
= e_rev
* esize
;
9090 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
9092 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
9093 tcg_rn
, off
- 64, esize
);
9095 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
9098 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
9099 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
9101 tcg_temp_free_i64(tcg_rd_hi
);
9102 tcg_temp_free_i64(tcg_rd
);
9103 tcg_temp_free_i64(tcg_rn
);
9107 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
9108 bool is_q
, int size
, int rn
, int rd
)
9110 /* Implement the pairwise operations from 2-misc:
9111 * SADDLP, UADDLP, SADALP, UADALP.
9112 * These all add pairs of elements in the input to produce a
9113 * double-width result element in the output (possibly accumulating).
9115 bool accum
= (opcode
== 0x6);
9116 int maxpass
= is_q
? 2 : 1;
9118 TCGv_i64 tcg_res
[2];
9121 /* 32 + 32 -> 64 op */
9122 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
9124 for (pass
= 0; pass
< maxpass
; pass
++) {
9125 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9126 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9128 tcg_res
[pass
] = tcg_temp_new_i64();
9130 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
9131 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
9132 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9134 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
9135 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9138 tcg_temp_free_i64(tcg_op1
);
9139 tcg_temp_free_i64(tcg_op2
);
9142 for (pass
= 0; pass
< maxpass
; pass
++) {
9143 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9144 NeonGenOneOpFn
*genfn
;
9145 static NeonGenOneOpFn
* const fns
[2][2] = {
9146 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
9147 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
9150 genfn
= fns
[size
][u
];
9152 tcg_res
[pass
] = tcg_temp_new_i64();
9154 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9155 genfn(tcg_res
[pass
], tcg_op
);
9158 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9160 gen_helper_neon_addl_u16(tcg_res
[pass
],
9161 tcg_res
[pass
], tcg_op
);
9163 gen_helper_neon_addl_u32(tcg_res
[pass
],
9164 tcg_res
[pass
], tcg_op
);
9167 tcg_temp_free_i64(tcg_op
);
9171 tcg_res
[1] = tcg_const_i64(0);
9173 for (pass
= 0; pass
< 2; pass
++) {
9174 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9175 tcg_temp_free_i64(tcg_res
[pass
]);
9179 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
9181 /* Implement SHLL and SHLL2 */
9183 int part
= is_q
? 2 : 0;
9184 TCGv_i64 tcg_res
[2];
9186 for (pass
= 0; pass
< 2; pass
++) {
9187 static NeonGenWidenFn
* const widenfns
[3] = {
9188 gen_helper_neon_widen_u8
,
9189 gen_helper_neon_widen_u16
,
9190 tcg_gen_extu_i32_i64
,
9192 NeonGenWidenFn
*widenfn
= widenfns
[size
];
9193 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9195 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
9196 tcg_res
[pass
] = tcg_temp_new_i64();
9197 widenfn(tcg_res
[pass
], tcg_op
);
9198 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
9200 tcg_temp_free_i32(tcg_op
);
9203 for (pass
= 0; pass
< 2; pass
++) {
9204 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9205 tcg_temp_free_i64(tcg_res
[pass
]);
9209 /* C3.6.17 AdvSIMD two reg misc
9210 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9211 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9212 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9213 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9215 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9217 int size
= extract32(insn
, 22, 2);
9218 int opcode
= extract32(insn
, 12, 5);
9219 bool u
= extract32(insn
, 29, 1);
9220 bool is_q
= extract32(insn
, 30, 1);
9221 int rn
= extract32(insn
, 5, 5);
9222 int rd
= extract32(insn
, 0, 5);
9223 bool need_fpstatus
= false;
9224 bool need_rmode
= false;
9227 TCGv_ptr tcg_fpstatus
;
9230 case 0x0: /* REV64, REV32 */
9231 case 0x1: /* REV16 */
9232 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9234 case 0x5: /* CNT, NOT, RBIT */
9235 if (u
&& size
== 0) {
9236 /* NOT: adjust size so we can use the 64-bits-at-a-time loop. */
9239 } else if (u
&& size
== 1) {
9242 } else if (!u
&& size
== 0) {
9246 unallocated_encoding(s
);
9248 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
9249 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
9251 unallocated_encoding(s
);
9254 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
9256 case 0x4: /* CLS, CLZ */
9258 unallocated_encoding(s
);
9262 case 0x2: /* SADDLP, UADDLP */
9263 case 0x6: /* SADALP, UADALP */
9265 unallocated_encoding(s
);
9268 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9270 case 0x13: /* SHLL, SHLL2 */
9271 if (u
== 0 || size
== 3) {
9272 unallocated_encoding(s
);
9275 handle_shll(s
, is_q
, size
, rn
, rd
);
9277 case 0xa: /* CMLT */
9279 unallocated_encoding(s
);
9283 case 0x8: /* CMGT, CMGE */
9284 case 0x9: /* CMEQ, CMLE */
9285 case 0xb: /* ABS, NEG */
9286 if (size
== 3 && !is_q
) {
9287 unallocated_encoding(s
);
9291 case 0x3: /* SUQADD, USQADD */
9292 if (size
== 3 && !is_q
) {
9293 unallocated_encoding(s
);
9296 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
9298 case 0x7: /* SQABS, SQNEG */
9299 if (size
== 3 && !is_q
) {
9300 unallocated_encoding(s
);
9308 /* Floating point: U, size[1] and opcode indicate operation;
9309 * size[0] indicates single or double precision.
9311 int is_double
= extract32(size
, 0, 1);
9312 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9313 size
= is_double
? 3 : 2;
9315 case 0x2f: /* FABS */
9316 case 0x6f: /* FNEG */
9317 if (size
== 3 && !is_q
) {
9318 unallocated_encoding(s
);
9322 case 0x1d: /* SCVTF */
9323 case 0x5d: /* UCVTF */
9325 bool is_signed
= (opcode
== 0x1d) ? true : false;
9326 int elements
= is_double
? 2 : is_q
? 4 : 2;
9327 if (is_double
&& !is_q
) {
9328 unallocated_encoding(s
);
9331 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
9334 case 0x2c: /* FCMGT (zero) */
9335 case 0x2d: /* FCMEQ (zero) */
9336 case 0x2e: /* FCMLT (zero) */
9337 case 0x6c: /* FCMGE (zero) */
9338 case 0x6d: /* FCMLE (zero) */
9339 if (size
== 3 && !is_q
) {
9340 unallocated_encoding(s
);
9343 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9345 case 0x7f: /* FSQRT */
9346 if (size
== 3 && !is_q
) {
9347 unallocated_encoding(s
);
9351 case 0x1a: /* FCVTNS */
9352 case 0x1b: /* FCVTMS */
9353 case 0x3a: /* FCVTPS */
9354 case 0x3b: /* FCVTZS */
9355 case 0x5a: /* FCVTNU */
9356 case 0x5b: /* FCVTMU */
9357 case 0x7a: /* FCVTPU */
9358 case 0x7b: /* FCVTZU */
9359 need_fpstatus
= true;
9361 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9362 if (size
== 3 && !is_q
) {
9363 unallocated_encoding(s
);
9367 case 0x5c: /* FCVTAU */
9368 case 0x1c: /* FCVTAS */
9369 need_fpstatus
= true;
9371 rmode
= FPROUNDING_TIEAWAY
;
9372 if (size
== 3 && !is_q
) {
9373 unallocated_encoding(s
);
9377 case 0x3c: /* URECPE */
9379 unallocated_encoding(s
);
9383 case 0x3d: /* FRECPE */
9384 case 0x7d: /* FRSQRTE */
9385 if (size
== 3 && !is_q
) {
9386 unallocated_encoding(s
);
9389 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9391 case 0x56: /* FCVTXN, FCVTXN2 */
9393 unallocated_encoding(s
);
9397 case 0x16: /* FCVTN, FCVTN2 */
9398 /* handle_2misc_narrow does a 2*size -> size operation, but these
9399 * instructions encode the source size rather than dest size.
9401 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
9403 case 0x17: /* FCVTL, FCVTL2 */
9404 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
9406 case 0x18: /* FRINTN */
9407 case 0x19: /* FRINTM */
9408 case 0x38: /* FRINTP */
9409 case 0x39: /* FRINTZ */
9411 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9413 case 0x59: /* FRINTX */
9414 case 0x79: /* FRINTI */
9415 need_fpstatus
= true;
9416 if (size
== 3 && !is_q
) {
9417 unallocated_encoding(s
);
9421 case 0x58: /* FRINTA */
9423 rmode
= FPROUNDING_TIEAWAY
;
9424 need_fpstatus
= true;
9425 if (size
== 3 && !is_q
) {
9426 unallocated_encoding(s
);
9430 case 0x7c: /* URSQRTE */
9432 unallocated_encoding(s
);
9435 need_fpstatus
= true;
9438 unallocated_encoding(s
);
9444 unallocated_encoding(s
);
9448 if (need_fpstatus
) {
9449 tcg_fpstatus
= get_fpstatus_ptr();
9451 TCGV_UNUSED_PTR(tcg_fpstatus
);
9454 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9455 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
9457 TCGV_UNUSED_I32(tcg_rmode
);
9461 /* All 64-bit element operations can be shared with scalar 2misc */
9464 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
9465 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9466 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9468 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9470 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
9471 tcg_rmode
, tcg_fpstatus
);
9473 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9475 tcg_temp_free_i64(tcg_res
);
9476 tcg_temp_free_i64(tcg_op
);
9481 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9482 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9483 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9486 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
9489 /* Special cases for 32 bit elements */
9491 case 0xa: /* CMLT */
9492 /* 32 bit integer comparison against zero, result is
9493 * test ? (2^32 - 1) : 0. We implement via setcond(test)
9498 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
9499 tcg_gen_neg_i32(tcg_res
, tcg_res
);
9501 case 0x8: /* CMGT, CMGE */
9502 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
9504 case 0x9: /* CMEQ, CMLE */
9505 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
9509 gen_helper_clz32(tcg_res
, tcg_op
);
9511 gen_helper_cls32(tcg_res
, tcg_op
);
9514 case 0x7: /* SQABS, SQNEG */
9516 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
9518 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
9521 case 0xb: /* ABS, NEG */
9523 tcg_gen_neg_i32(tcg_res
, tcg_op
);
9525 TCGv_i32 tcg_zero
= tcg_const_i32(0);
9526 tcg_gen_neg_i32(tcg_res
, tcg_op
);
9527 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
9528 tcg_zero
, tcg_op
, tcg_res
);
9529 tcg_temp_free_i32(tcg_zero
);
9532 case 0x2f: /* FABS */
9533 gen_helper_vfp_abss(tcg_res
, tcg_op
);
9535 case 0x6f: /* FNEG */
9536 gen_helper_vfp_negs(tcg_res
, tcg_op
);
9538 case 0x7f: /* FSQRT */
9539 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
9541 case 0x1a: /* FCVTNS */
9542 case 0x1b: /* FCVTMS */
9543 case 0x1c: /* FCVTAS */
9544 case 0x3a: /* FCVTPS */
9545 case 0x3b: /* FCVTZS */
9547 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9548 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
9549 tcg_shift
, tcg_fpstatus
);
9550 tcg_temp_free_i32(tcg_shift
);
9553 case 0x5a: /* FCVTNU */
9554 case 0x5b: /* FCVTMU */
9555 case 0x5c: /* FCVTAU */
9556 case 0x7a: /* FCVTPU */
9557 case 0x7b: /* FCVTZU */
9559 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9560 gen_helper_vfp_touls(tcg_res
, tcg_op
,
9561 tcg_shift
, tcg_fpstatus
);
9562 tcg_temp_free_i32(tcg_shift
);
9565 case 0x18: /* FRINTN */
9566 case 0x19: /* FRINTM */
9567 case 0x38: /* FRINTP */
9568 case 0x39: /* FRINTZ */
9569 case 0x58: /* FRINTA */
9570 case 0x79: /* FRINTI */
9571 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
9573 case 0x59: /* FRINTX */
9574 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
9576 case 0x7c: /* URSQRTE */
9577 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
9580 g_assert_not_reached();
9583 /* Use helpers for 8 and 16 bit elements */
9585 case 0x5: /* CNT, RBIT */
9586 /* For these two insns size is part of the opcode specifier
9587 * (handled earlier); they always operate on byte elements.
9590 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
9592 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
9595 case 0x7: /* SQABS, SQNEG */
9597 NeonGenOneOpEnvFn
*genfn
;
9598 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
9599 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
9600 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
9602 genfn
= fns
[size
][u
];
9603 genfn(tcg_res
, cpu_env
, tcg_op
);
9606 case 0x8: /* CMGT, CMGE */
9607 case 0x9: /* CMEQ, CMLE */
9608 case 0xa: /* CMLT */
9610 static NeonGenTwoOpFn
* const fns
[3][2] = {
9611 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
9612 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
9613 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
9615 NeonGenTwoOpFn
*genfn
;
9618 TCGv_i32 tcg_zero
= tcg_const_i32(0);
9620 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
9621 comp
= (opcode
- 0x8) * 2 + u
;
9622 /* ...but LE, LT are implemented as reverse GE, GT */
9623 reverse
= (comp
> 2);
9627 genfn
= fns
[comp
][size
];
9629 genfn(tcg_res
, tcg_zero
, tcg_op
);
9631 genfn(tcg_res
, tcg_op
, tcg_zero
);
9633 tcg_temp_free_i32(tcg_zero
);
9636 case 0xb: /* ABS, NEG */
9638 TCGv_i32 tcg_zero
= tcg_const_i32(0);
9640 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
9642 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
9644 tcg_temp_free_i32(tcg_zero
);
9647 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
9649 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
9653 case 0x4: /* CLS, CLZ */
9656 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
9658 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
9662 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
9664 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
9669 g_assert_not_reached();
9673 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9675 tcg_temp_free_i32(tcg_res
);
9676 tcg_temp_free_i32(tcg_op
);
9680 clear_vec_high(s
, rd
);
9684 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
9685 tcg_temp_free_i32(tcg_rmode
);
9687 if (need_fpstatus
) {
9688 tcg_temp_free_ptr(tcg_fpstatus
);
9692 /* C3.6.13 AdvSIMD scalar x indexed element
9693 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
9694 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
9695 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
9696 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
9697 * C3.6.18 AdvSIMD vector x indexed element
9698 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
9699 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
9700 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
9701 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
9703 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
9705 /* This encoding has two kinds of instruction:
9706 * normal, where we perform elt x idxelt => elt for each
9707 * element in the vector
9708 * long, where we perform elt x idxelt and generate a result of
9709 * double the width of the input element
9710 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
9712 bool is_scalar
= extract32(insn
, 28, 1);
9713 bool is_q
= extract32(insn
, 30, 1);
9714 bool u
= extract32(insn
, 29, 1);
9715 int size
= extract32(insn
, 22, 2);
9716 int l
= extract32(insn
, 21, 1);
9717 int m
= extract32(insn
, 20, 1);
9718 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
9719 int rm
= extract32(insn
, 16, 4);
9720 int opcode
= extract32(insn
, 12, 4);
9721 int h
= extract32(insn
, 11, 1);
9722 int rn
= extract32(insn
, 5, 5);
9723 int rd
= extract32(insn
, 0, 5);
9724 bool is_long
= false;
9732 if (!u
|| is_scalar
) {
9733 unallocated_encoding(s
);
9737 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
9738 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
9739 case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
9741 unallocated_encoding(s
);
9746 case 0x3: /* SQDMLAL, SQDMLAL2 */
9747 case 0x7: /* SQDMLSL, SQDMLSL2 */
9748 case 0xb: /* SQDMULL, SQDMULL2 */
9751 case 0xc: /* SQDMULH */
9752 case 0xd: /* SQRDMULH */
9754 unallocated_encoding(s
);
9759 if (u
|| is_scalar
) {
9760 unallocated_encoding(s
);
9764 case 0x1: /* FMLA */
9765 case 0x5: /* FMLS */
9767 unallocated_encoding(s
);
9771 case 0x9: /* FMUL, FMULX */
9772 if (!extract32(size
, 1, 1)) {
9773 unallocated_encoding(s
);
9779 unallocated_encoding(s
);
9784 /* low bit of size indicates single/double */
9785 size
= extract32(size
, 0, 1) ? 3 : 2;
9790 unallocated_encoding(s
);
9799 index
= h
<< 2 | l
<< 1 | m
;
9806 unallocated_encoding(s
);
9812 fpst
= get_fpstatus_ptr();
9814 TCGV_UNUSED_PTR(fpst
);
9818 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
9821 assert(is_fp
&& is_q
&& !is_long
);
9823 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
9825 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9826 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9827 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9829 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9832 case 0x5: /* FMLS */
9833 /* As usual for ARM, separate negation for fused multiply-add */
9834 gen_helper_vfp_negd(tcg_op
, tcg_op
);
9836 case 0x1: /* FMLA */
9837 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9838 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
9840 case 0x9: /* FMUL, FMULX */
9842 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
9844 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
9848 g_assert_not_reached();
9851 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9852 tcg_temp_free_i64(tcg_op
);
9853 tcg_temp_free_i64(tcg_res
);
9857 clear_vec_high(s
, rd
);
9860 tcg_temp_free_i64(tcg_idx
);
9861 } else if (!is_long
) {
9862 /* 32 bit floating point, or 16 or 32 bit integer.
9863 * For the 16 bit scalar case we use the usual Neon helpers and
9864 * rely on the fact that 0 op 0 == 0 with no side effects.
9866 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
9867 int pass
, maxpasses
;
9872 maxpasses
= is_q
? 4 : 2;
9875 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
9877 if (size
== 1 && !is_scalar
) {
9878 /* The simplest way to handle the 16x16 indexed ops is to duplicate
9879 * the index into both halves of the 32 bit tcg_idx and then use
9880 * the usual Neon helpers.
9882 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
9885 for (pass
= 0; pass
< maxpasses
; pass
++) {
9886 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9887 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9889 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
9896 static NeonGenTwoOpFn
* const fns
[2][2] = {
9897 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9898 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9900 NeonGenTwoOpFn
*genfn
;
9901 bool is_sub
= opcode
== 0x4;
9904 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
9906 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
9908 if (opcode
== 0x8) {
9911 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
9912 genfn
= fns
[size
- 1][is_sub
];
9913 genfn(tcg_res
, tcg_op
, tcg_res
);
9916 case 0x5: /* FMLS */
9917 /* As usual for ARM, separate negation for fused multiply-add */
9918 gen_helper_vfp_negs(tcg_op
, tcg_op
);
9920 case 0x1: /* FMLA */
9921 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9922 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
9924 case 0x9: /* FMUL, FMULX */
9926 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
9928 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
9931 case 0xc: /* SQDMULH */
9933 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
9936 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
9940 case 0xd: /* SQRDMULH */
9942 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
9945 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
9950 g_assert_not_reached();
9954 write_fp_sreg(s
, rd
, tcg_res
);
9956 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9959 tcg_temp_free_i32(tcg_op
);
9960 tcg_temp_free_i32(tcg_res
);
9963 tcg_temp_free_i32(tcg_idx
);
9966 clear_vec_high(s
, rd
);
9969 /* long ops: 16x16->32 or 32x32->64 */
9970 TCGv_i64 tcg_res
[2];
9972 bool satop
= extract32(opcode
, 0, 1);
9973 TCGMemOp memop
= MO_32
;
9980 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
9982 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
9984 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9985 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9986 TCGv_i64 tcg_passres
;
9992 passelt
= pass
+ (is_q
* 2);
9995 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
9997 tcg_res
[pass
] = tcg_temp_new_i64();
9999 if (opcode
== 0xa || opcode
== 0xb) {
10000 /* Non-accumulating ops */
10001 tcg_passres
= tcg_res
[pass
];
10003 tcg_passres
= tcg_temp_new_i64();
10006 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
10007 tcg_temp_free_i64(tcg_op
);
10010 /* saturating, doubling */
10011 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10012 tcg_passres
, tcg_passres
);
10015 if (opcode
== 0xa || opcode
== 0xb) {
10019 /* Accumulating op: handle accumulate step */
10020 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10023 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10024 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10026 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10027 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10029 case 0x7: /* SQDMLSL, SQDMLSL2 */
10030 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10032 case 0x3: /* SQDMLAL, SQDMLAL2 */
10033 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10038 g_assert_not_reached();
10040 tcg_temp_free_i64(tcg_passres
);
10042 tcg_temp_free_i64(tcg_idx
);
10045 clear_vec_high(s
, rd
);
10048 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10051 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10054 /* The simplest way to handle the 16x16 indexed ops is to
10055 * duplicate the index into both halves of the 32 bit tcg_idx
10056 * and then use the usual Neon helpers.
10058 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10061 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10062 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10063 TCGv_i64 tcg_passres
;
10066 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10068 read_vec_element_i32(s
, tcg_op
, rn
,
10069 pass
+ (is_q
* 2), MO_32
);
10072 tcg_res
[pass
] = tcg_temp_new_i64();
10074 if (opcode
== 0xa || opcode
== 0xb) {
10075 /* Non-accumulating ops */
10076 tcg_passres
= tcg_res
[pass
];
10078 tcg_passres
= tcg_temp_new_i64();
10081 if (memop
& MO_SIGN
) {
10082 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
10084 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
10087 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10088 tcg_passres
, tcg_passres
);
10090 tcg_temp_free_i32(tcg_op
);
10092 if (opcode
== 0xa || opcode
== 0xb) {
10096 /* Accumulating op: handle accumulate step */
10097 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10100 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10101 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
10104 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10105 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
10108 case 0x7: /* SQDMLSL, SQDMLSL2 */
10109 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10111 case 0x3: /* SQDMLAL, SQDMLAL2 */
10112 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10117 g_assert_not_reached();
10119 tcg_temp_free_i64(tcg_passres
);
10121 tcg_temp_free_i32(tcg_idx
);
10124 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
10129 tcg_res
[1] = tcg_const_i64(0);
10132 for (pass
= 0; pass
< 2; pass
++) {
10133 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10134 tcg_temp_free_i64(tcg_res
[pass
]);
10138 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
10139 tcg_temp_free_ptr(fpst
);
10143 /* C3.6.19 Crypto AES
10144 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10145 * +-----------------+------+-----------+--------+-----+------+------+
10146 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10147 * +-----------------+------+-----------+--------+-----+------+------+
10149 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
10151 unsupported_encoding(s
, insn
);
10154 /* C3.6.20 Crypto three-reg SHA
10155 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
10156 * +-----------------+------+---+------+---+--------+-----+------+------+
10157 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
10158 * +-----------------+------+---+------+---+--------+-----+------+------+
10160 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
10162 unsupported_encoding(s
, insn
);
10165 /* C3.6.21 Crypto two-reg SHA
10166 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10167 * +-----------------+------+-----------+--------+-----+------+------+
10168 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10169 * +-----------------+------+-----------+--------+-----+------+------+
10171 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
10173 unsupported_encoding(s
, insn
);
10176 /* C3.6 Data processing - SIMD, inc Crypto
10178 * As the decode gets a little complex we are using a table based
10179 * approach for this part of the decode.
10181 static const AArch64DecodeTable data_proc_simd
[] = {
10182 /* pattern , mask , fn */
10183 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
10184 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
10185 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
10186 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
10187 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
10188 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
10189 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
10190 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
10191 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
10192 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
10193 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
10194 { 0x2e000000, 0xbf208400, disas_simd_ext
},
10195 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
10196 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
10197 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
10198 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
10199 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
10200 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
10201 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
10202 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
10203 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
10204 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
10205 { 0x00000000, 0x00000000, NULL
}
10208 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
10210 /* Note that this is called with all non-FP cases from
10211 * table C3-6 so it must UNDEF for entries not specifically
10212 * allocated to instructions in that table.
10214 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
10218 unallocated_encoding(s
);
10222 /* C3.6 Data processing - SIMD and floating point */
10223 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
10225 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
10226 disas_data_proc_fp(s
, insn
);
10228 /* SIMD, including crypto */
10229 disas_data_proc_simd(s
, insn
);
10233 /* C3.1 A64 instruction index by encoding */
10234 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
10238 insn
= arm_ldl_code(env
, s
->pc
, s
->bswap_code
);
10242 switch (extract32(insn
, 25, 4)) {
10243 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
10244 unallocated_encoding(s
);
10246 case 0x8: case 0x9: /* Data processing - immediate */
10247 disas_data_proc_imm(s
, insn
);
10249 case 0xa: case 0xb: /* Branch, exception generation and system insns */
10250 disas_b_exc_sys(s
, insn
);
10255 case 0xe: /* Loads and stores */
10256 disas_ldst(s
, insn
);
10259 case 0xd: /* Data processing - register */
10260 disas_data_proc_reg(s
, insn
);
10263 case 0xf: /* Data processing - SIMD and floating point */
10264 disas_data_proc_simd_fp(s
, insn
);
10267 assert(FALSE
); /* all 15 cases should be handled above */
10271 /* if we allocated any temporaries, free them here */
10275 void gen_intermediate_code_internal_a64(ARMCPU
*cpu
,
10276 TranslationBlock
*tb
,
10279 CPUState
*cs
= CPU(cpu
);
10280 CPUARMState
*env
= &cpu
->env
;
10281 DisasContext dc1
, *dc
= &dc1
;
10283 uint16_t *gen_opc_end
;
10285 target_ulong pc_start
;
10286 target_ulong next_page_start
;
10294 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
10296 dc
->is_jmp
= DISAS_NEXT
;
10298 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
10303 dc
->bswap_code
= 0;
10304 dc
->condexec_mask
= 0;
10305 dc
->condexec_cond
= 0;
10306 #if !defined(CONFIG_USER_ONLY)
10307 dc
->user
= (ARM_TBFLAG_AA64_EL(tb
->flags
) == 0);
10309 dc
->vfp_enabled
= 0;
10311 dc
->vec_stride
= 0;
10312 dc
->cp_regs
= cpu
->cp_regs
;
10313 dc
->current_pl
= arm_current_pl(env
);
10314 dc
->features
= env
->features
;
10316 init_tmp_a64_array(dc
);
10318 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
10321 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
10322 if (max_insns
== 0) {
10323 max_insns
= CF_COUNT_MASK
;
10328 tcg_clear_temp_count();
10331 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
10332 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
10333 if (bp
->pc
== dc
->pc
) {
10334 gen_exception_insn(dc
, 0, EXCP_DEBUG
);
10335 /* Advance PC so that clearing the breakpoint will
10336 invalidate this TB. */
10338 goto done_generating
;
10344 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
10348 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
10351 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
10352 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
10353 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
10356 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
10360 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
10361 tcg_gen_debug_insn_start(dc
->pc
);
10364 disas_a64_insn(env
, dc
);
10366 if (tcg_check_temp_count()) {
10367 fprintf(stderr
, "TCG temporary leak before "TARGET_FMT_lx
"\n",
10371 /* Translation stops when a conditional branch is encountered.
10372 * Otherwise the subsequent code could get translated several times.
10373 * Also stop translation when a page boundary is reached. This
10374 * ensures prefetch aborts occur at the right place.
10377 } while (!dc
->is_jmp
&& tcg_ctx
.gen_opc_ptr
< gen_opc_end
&&
10378 !cs
->singlestep_enabled
&&
10380 dc
->pc
< next_page_start
&&
10381 num_insns
< max_insns
);
10383 if (tb
->cflags
& CF_LAST_IO
) {
10387 if (unlikely(cs
->singlestep_enabled
) && dc
->is_jmp
!= DISAS_EXC
) {
10388 /* Note that this means single stepping WFI doesn't halt the CPU.
10389 * For conditional branch insns this is harmless unreachable code as
10390 * gen_goto_tb() has already handled emitting the debug exception
10391 * (and thus a tb-jump is not possible when singlestepping).
10393 assert(dc
->is_jmp
!= DISAS_TB_JUMP
);
10394 if (dc
->is_jmp
!= DISAS_JUMP
) {
10395 gen_a64_set_pc_im(dc
->pc
);
10397 gen_exception(EXCP_DEBUG
);
10399 switch (dc
->is_jmp
) {
10401 gen_goto_tb(dc
, 1, dc
->pc
);
10405 gen_a64_set_pc_im(dc
->pc
);
10408 /* indicate that the hash table must be used to find the next TB */
10409 tcg_gen_exit_tb(0);
10411 case DISAS_TB_JUMP
:
10416 /* This is a special case because we don't want to just halt the CPU
10417 * if trying to debug across a WFI.
10419 gen_a64_set_pc_im(dc
->pc
);
10420 gen_helper_wfi(cpu_env
);
10426 gen_tb_end(tb
, num_insns
);
10427 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
10430 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
10431 qemu_log("----------------\n");
10432 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
10433 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
,
10434 4 | (dc
->bswap_code
<< 1));
10439 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
10442 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
10445 tb
->size
= dc
->pc
- pc_start
;
10446 tb
->icount
= num_insns
;