4 * Copyright (c) 2015 Chen Gang
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.1 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
18 * <http://www.gnu.org/licenses/lgpl-2.1.html>
23 #include "disas/disas.h"
25 #include "exec/cpu_ldst.h"
26 #include "linux-user/syscall_defs.h"
28 #include "opcode_tilegx.h"
29 #include "spr_def_64.h"
31 #define FMT64X "%016" PRIx64
33 static TCGv_ptr cpu_env
;
35 static TCGv cpu_regs
[TILEGX_R_COUNT
];
37 static const char * const reg_names
[64] = {
38 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
39 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
40 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
41 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
42 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
43 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
44 "r48", "r49", "r50", "r51", "bp", "tp", "sp", "lr",
45 "sn", "idn0", "idn1", "udn0", "udn1", "udn2", "udn2", "zero"
48 /* Modified registers are cached in temporaries until the end of the bundle. */
54 #define MAX_WRITEBACK 4
56 /* This is the state at translation time. */
58 uint64_t pc
; /* Current pc */
60 TCGv zero
; /* For zero register */
62 DisasContextTemp wb
[MAX_WRITEBACK
];
69 TCGCond cond
; /* branch condition */
70 TCGv dest
; /* branch destination */
71 TCGv val1
; /* value to be compared against zero, for cond */
72 } jmp
; /* Jump object, only once in each TB block */
75 #include "exec/gen-icount.h"
77 /* Differentiate the various pipe encodings. */
83 /* Remerge the base opcode and extension fields for switching.
84 The X opcode fields are 3 bits; Y0/Y1 opcode fields are 4 bits;
85 Y2 opcode field is 2 bits. */
86 #define OE(OP, EXT, XY) (TY_##XY + OP * 4 + EXT * 64)
88 /* Similar, but for Y2 only. */
89 #define OEY2(OP, MODE) (OP + MODE * 4)
91 /* Similar, but make sure opcode names match up. */
92 #define OE_RR_X0(E) OE(RRR_0_OPCODE_X0, E##_UNARY_OPCODE_X0, X0)
93 #define OE_RR_X1(E) OE(RRR_0_OPCODE_X1, E##_UNARY_OPCODE_X1, X1)
94 #define OE_RR_Y0(E) OE(RRR_1_OPCODE_Y0, E##_UNARY_OPCODE_Y0, Y0)
95 #define OE_RR_Y1(E) OE(RRR_1_OPCODE_Y1, E##_UNARY_OPCODE_Y1, Y1)
96 #define OE_RRR(E,N,XY) OE(RRR_##N##_OPCODE_##XY, E##_RRR_##N##_OPCODE_##XY, XY)
97 #define OE_IM(E,XY) OE(IMM8_OPCODE_##XY, E##_IMM8_OPCODE_##XY, XY)
98 #define OE_SH(E,XY) OE(SHIFT_OPCODE_##XY, E##_SHIFT_OPCODE_##XY, XY)
100 #define V1_IMM(X) (((X) & 0xff) * 0x0101010101010101ull)
101 #define V2_IMM(X) (((X) & 0xffff) * 0x0001000100010001ull)
104 static void gen_exception(DisasContext
*dc
, TileExcp num
)
108 tcg_gen_movi_tl(cpu_pc
, dc
->pc
+ TILEGX_BUNDLE_SIZE_IN_BYTES
);
110 tmp
= tcg_const_i32(num
);
111 gen_helper_exception(cpu_env
, tmp
);
112 tcg_temp_free_i32(tmp
);
116 static bool check_gr(DisasContext
*dc
, uint8_t reg
)
118 if (likely(reg
< TILEGX_R_COUNT
)) {
128 gen_exception(dc
, TILEGX_EXCP_REG_IDN_ACCESS
);
134 gen_exception(dc
, TILEGX_EXCP_REG_UDN_ACCESS
);
137 g_assert_not_reached();
142 static TCGv
load_zero(DisasContext
*dc
)
144 if (TCGV_IS_UNUSED_I64(dc
->zero
)) {
145 dc
->zero
= tcg_const_i64(0);
150 static TCGv
load_gr(DisasContext
*dc
, unsigned reg
)
152 if (check_gr(dc
, reg
)) {
153 return cpu_regs
[reg
];
155 return load_zero(dc
);
158 static TCGv
dest_gr(DisasContext
*dc
, unsigned reg
)
162 /* Skip the result, mark the exception if necessary, and continue */
167 return dc
->wb
[n
].val
= tcg_temp_new_i64();
170 static void gen_saturate_op(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
,
171 void (*operate
)(TCGv
, TCGv
, TCGv
))
173 TCGv t0
= tcg_temp_new();
175 tcg_gen_ext32s_tl(tdest
, tsrca
);
176 tcg_gen_ext32s_tl(t0
, tsrcb
);
177 operate(tdest
, tdest
, t0
);
179 tcg_gen_movi_tl(t0
, 0x7fffffff);
180 tcg_gen_movcond_tl(TCG_COND_GT
, tdest
, tdest
, t0
, t0
, tdest
);
181 tcg_gen_movi_tl(t0
, -0x80000000LL
);
182 tcg_gen_movcond_tl(TCG_COND_LT
, tdest
, tdest
, t0
, t0
, tdest
);
187 static void gen_atomic_excp(DisasContext
*dc
, unsigned dest
, TCGv tdest
,
188 TCGv tsrca
, TCGv tsrcb
, TileExcp excp
)
190 #ifdef CONFIG_USER_ONLY
193 tcg_gen_st_tl(tsrca
, cpu_env
, offsetof(CPUTLGState
, atomic_srca
));
194 tcg_gen_st_tl(tsrcb
, cpu_env
, offsetof(CPUTLGState
, atomic_srcb
));
195 t
= tcg_const_i32(dest
);
196 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUTLGState
, atomic_dstr
));
197 tcg_temp_free_i32(t
);
199 /* We're going to write the real result in the exception. But in
200 the meantime we've already created a writeback register, and
201 we don't want that to remain uninitialized. */
202 tcg_gen_movi_tl(tdest
, 0);
204 /* Note that we need to delay issuing the exception that implements
205 the atomic operation until after writing back the results of the
206 instruction occupying the X0 pipe. */
207 dc
->atomic_excp
= excp
;
209 gen_exception(dc
, TILEGX_EXCP_OPCODE_UNIMPLEMENTED
);
213 /* Shift the 128-bit value TSRCA:TSRCD right by the number of bytes
214 specified by the bottom 3 bits of TSRCB, and set TDEST to the
215 low 64 bits of the resulting value. */
216 static void gen_dblalign(TCGv tdest
, TCGv tsrcd
, TCGv tsrca
, TCGv tsrcb
)
218 TCGv t0
= tcg_temp_new();
220 tcg_gen_andi_tl(t0
, tsrcb
, 7);
221 tcg_gen_shli_tl(t0
, t0
, 3);
222 tcg_gen_shr_tl(tdest
, tsrcd
, t0
);
224 /* We want to do "t0 = tsrca << (64 - t0)". Two's complement
225 arithmetic on a 6-bit field tells us that 64 - t0 is equal
226 to (t0 ^ 63) + 1. So we can do the shift in two parts,
227 neither of which will be an invalid shift by 64. */
228 tcg_gen_xori_tl(t0
, t0
, 63);
229 tcg_gen_shl_tl(t0
, tsrca
, t0
);
230 tcg_gen_shli_tl(t0
, t0
, 1);
231 tcg_gen_or_tl(tdest
, tdest
, t0
);
236 /* Similarly, except that the 128-bit value is TSRCA:TSRCB, and the
237 right shift is an immediate. */
238 static void gen_dblaligni(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
, int shr
)
240 TCGv t0
= tcg_temp_new();
242 tcg_gen_shri_tl(t0
, tsrcb
, shr
);
243 tcg_gen_shli_tl(tdest
, tsrca
, 64 - shr
);
244 tcg_gen_or_tl(tdest
, tdest
, t0
);
253 static void gen_ext_half(TCGv d
, TCGv s
, MulHalf h
)
257 tcg_gen_ext32u_tl(d
, s
);
260 tcg_gen_ext32s_tl(d
, s
);
263 tcg_gen_shri_tl(d
, s
, 32);
266 tcg_gen_sari_tl(d
, s
, 32);
271 static void gen_mul_half(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
,
272 MulHalf ha
, MulHalf hb
)
274 TCGv t
= tcg_temp_new();
275 gen_ext_half(t
, tsrca
, ha
);
276 gen_ext_half(tdest
, tsrcb
, hb
);
277 tcg_gen_mul_tl(tdest
, tdest
, t
);
281 static void gen_cmul2(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
, int sh
, int rd
)
283 TCGv_i32 tsh
= tcg_const_i32(sh
);
284 TCGv_i32 trd
= tcg_const_i32(rd
);
285 gen_helper_cmul2(tdest
, tsrca
, tsrcb
, tsh
, trd
);
286 tcg_temp_free_i32(tsh
);
287 tcg_temp_free_i32(trd
);
290 static TileExcp
gen_st_opcode(DisasContext
*dc
, unsigned dest
, unsigned srca
,
291 unsigned srcb
, TCGMemOp memop
, const char *name
)
294 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
297 tcg_gen_qemu_st_tl(load_gr(dc
, srcb
), load_gr(dc
, srca
),
300 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s", name
,
301 reg_names
[srca
], reg_names
[srcb
]);
302 return TILEGX_EXCP_NONE
;
305 static TileExcp
gen_st_add_opcode(DisasContext
*dc
, unsigned srca
, unsigned srcb
,
306 int imm
, TCGMemOp memop
, const char *name
)
308 TCGv tsrca
= load_gr(dc
, srca
);
309 TCGv tsrcb
= load_gr(dc
, srcb
);
311 tcg_gen_qemu_st_tl(tsrcb
, tsrca
, dc
->mmuidx
, memop
);
312 tcg_gen_addi_tl(dest_gr(dc
, srca
), tsrca
, imm
);
314 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s, %d", name
,
315 reg_names
[srca
], reg_names
[srcb
], imm
);
316 return TILEGX_EXCP_NONE
;
319 /* Equality comparison with zero can be done quickly and efficiently. */
320 static void gen_v1cmpeq0(TCGv v
)
322 TCGv m
= tcg_const_tl(V1_IMM(0x7f));
323 TCGv c
= tcg_temp_new();
325 /* ~(((v & m) + m) | m | v). Sets the msb for each byte == 0. */
326 tcg_gen_and_tl(c
, v
, m
);
327 tcg_gen_add_tl(c
, c
, m
);
328 tcg_gen_or_tl(c
, c
, m
);
329 tcg_gen_nor_tl(c
, c
, v
);
332 /* Shift the msb down to form the lsb boolean result. */
333 tcg_gen_shri_tl(v
, c
, 7);
337 static void gen_v1cmpne0(TCGv v
)
339 TCGv m
= tcg_const_tl(V1_IMM(0x7f));
340 TCGv c
= tcg_temp_new();
342 /* (((v & m) + m) | v) & ~m. Sets the msb for each byte != 0. */
343 tcg_gen_and_tl(c
, v
, m
);
344 tcg_gen_add_tl(c
, c
, m
);
345 tcg_gen_or_tl(c
, c
, v
);
346 tcg_gen_andc_tl(c
, c
, m
);
349 /* Shift the msb down to form the lsb boolean result. */
350 tcg_gen_shri_tl(v
, c
, 7);
354 /* Vector addition can be performed via arithmetic plus masking. It is
355 efficient this way only for 4 or more elements. */
356 static void gen_v12add(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
, uint64_t sign
)
358 TCGv tmask
= tcg_const_tl(~sign
);
359 TCGv t0
= tcg_temp_new();
360 TCGv t1
= tcg_temp_new();
362 /* ((a & ~sign) + (b & ~sign)) ^ ((a ^ b) & sign). */
363 tcg_gen_and_tl(t0
, tsrca
, tmask
);
364 tcg_gen_and_tl(t1
, tsrcb
, tmask
);
365 tcg_gen_add_tl(tdest
, t0
, t1
);
366 tcg_gen_xor_tl(t0
, tsrca
, tsrcb
);
367 tcg_gen_andc_tl(t0
, t0
, tmask
);
368 tcg_gen_xor_tl(tdest
, tdest
, t0
);
372 tcg_temp_free(tmask
);
375 /* Similarly for vector subtraction. */
376 static void gen_v12sub(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
, uint64_t sign
)
378 TCGv tsign
= tcg_const_tl(sign
);
379 TCGv t0
= tcg_temp_new();
380 TCGv t1
= tcg_temp_new();
382 /* ((a | sign) - (b & ~sign)) ^ ((a ^ ~b) & sign). */
383 tcg_gen_or_tl(t0
, tsrca
, tsign
);
384 tcg_gen_andc_tl(t1
, tsrcb
, tsign
);
385 tcg_gen_sub_tl(tdest
, t0
, t1
);
386 tcg_gen_eqv_tl(t0
, tsrca
, tsrcb
);
387 tcg_gen_and_tl(t0
, t0
, tsign
);
388 tcg_gen_xor_tl(tdest
, tdest
, t0
);
392 tcg_temp_free(tsign
);
395 static void gen_v4sh(TCGv d64
, TCGv a64
, TCGv b64
,
396 void (*generate
)(TCGv_i32
, TCGv_i32
, TCGv_i32
))
398 TCGv_i32 al
= tcg_temp_new_i32();
399 TCGv_i32 ah
= tcg_temp_new_i32();
400 TCGv_i32 bl
= tcg_temp_new_i32();
402 tcg_gen_extr_i64_i32(al
, ah
, a64
);
403 tcg_gen_extrl_i64_i32(bl
, b64
);
404 tcg_gen_andi_i32(bl
, bl
, 31);
405 generate(al
, al
, bl
);
406 generate(ah
, ah
, bl
);
407 tcg_gen_concat_i32_i64(d64
, al
, ah
);
409 tcg_temp_free_i32(al
);
410 tcg_temp_free_i32(ah
);
411 tcg_temp_free_i32(bl
);
414 static void gen_v4op(TCGv d64
, TCGv a64
, TCGv b64
,
415 void (*generate
)(TCGv_i32
, TCGv_i32
, TCGv_i32
))
417 TCGv_i32 al
= tcg_temp_new_i32();
418 TCGv_i32 ah
= tcg_temp_new_i32();
419 TCGv_i32 bl
= tcg_temp_new_i32();
420 TCGv_i32 bh
= tcg_temp_new_i32();
422 tcg_gen_extr_i64_i32(al
, ah
, a64
);
423 tcg_gen_extr_i64_i32(bl
, bh
, b64
);
424 generate(al
, al
, bl
);
425 generate(ah
, ah
, bh
);
426 tcg_gen_concat_i32_i64(d64
, al
, ah
);
428 tcg_temp_free_i32(al
);
429 tcg_temp_free_i32(ah
);
430 tcg_temp_free_i32(bl
);
431 tcg_temp_free_i32(bh
);
434 static TileExcp
gen_signal(DisasContext
*dc
, int signo
, int sigcode
,
435 const char *mnemonic
)
437 TCGv_i32 t0
= tcg_const_i32(signo
);
438 TCGv_i32 t1
= tcg_const_i32(sigcode
);
440 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUTLGState
, signo
));
441 tcg_gen_st_i32(t1
, cpu_env
, offsetof(CPUTLGState
, sigcode
));
443 tcg_temp_free_i32(t1
);
444 tcg_temp_free_i32(t0
);
446 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s", mnemonic
);
447 return TILEGX_EXCP_SIGNAL
;
450 static bool parse_from_addli(uint64_t bundle
, int *signo
, int *sigcode
)
454 if ((get_Opcode_X0(bundle
) != ADDLI_OPCODE_X0
)
455 || (get_Dest_X0(bundle
) != TILEGX_R_ZERO
)
456 || (get_SrcA_X0(bundle
) != TILEGX_R_ZERO
)) {
460 imm
= get_Imm16_X0(bundle
);
462 *sigcode
= (imm
>> 6) & 0xf;
464 /* ??? The linux kernel validates both signo and the sigcode vs the
465 known max for each signal. Don't bother here. */
469 static TileExcp
gen_specill(DisasContext
*dc
, unsigned dest
, unsigned srca
,
472 const char *mnemonic
;
476 if (dest
== 0x1c && srca
== 0x25) {
477 signo
= TARGET_SIGTRAP
;
478 sigcode
= TARGET_TRAP_BRKPT
;
480 } else if (dest
== 0x1d && srca
== 0x25
481 && parse_from_addli(bundle
, &signo
, &sigcode
)) {
484 signo
= TARGET_SIGILL
;
485 sigcode
= TARGET_ILL_ILLOPC
;
489 return gen_signal(dc
, signo
, sigcode
, mnemonic
);
492 static TileExcp
gen_rr_opcode(DisasContext
*dc
, unsigned opext
,
493 unsigned dest
, unsigned srca
, uint64_t bundle
)
496 const char *mnemonic
;
498 TileExcp ret
= TILEGX_EXCP_NONE
;
499 bool prefetch_nofault
= false;
501 /* Eliminate instructions with no output before doing anything else. */
515 case OE_RR_X1(DRAIN
):
518 case OE_RR_X1(FLUSHWB
):
519 mnemonic
= "flushwb";
522 return gen_specill(dc
, dest
, srca
, bundle
);
524 return gen_signal(dc
, TARGET_SIGILL
, TARGET_ILL_ILLOPC
, "ill");
529 /* ??? This should yield, especially in system mode. */
532 case OE_RR_X1(SWINT0
):
533 case OE_RR_X1(SWINT2
):
534 case OE_RR_X1(SWINT3
):
535 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
536 case OE_RR_X1(SWINT1
):
537 ret
= TILEGX_EXCP_SYSCALL
;
541 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
543 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s", mnemonic
);
546 case OE_RR_X1(DTLBPR
):
547 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
551 case OE_RR_X1(FLUSH
):
571 case OE_RR_X1(JALRP
):
572 case OE_RR_Y1(JALRP
):
579 tcg_gen_movi_tl(dest_gr(dc
, TILEGX_R_LR
),
580 dc
->pc
+ TILEGX_BUNDLE_SIZE_IN_BYTES
);
582 dc
->jmp
.cond
= TCG_COND_ALWAYS
;
583 dc
->jmp
.dest
= tcg_temp_new();
584 tcg_gen_andi_tl(dc
->jmp
.dest
, load_gr(dc
, srca
), ~7);
587 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
589 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s", mnemonic
, reg_names
[srca
]);
593 tdest
= dest_gr(dc
, dest
);
594 tsrca
= load_gr(dc
, srca
);
597 case OE_RR_X0(CNTLZ
):
598 case OE_RR_Y0(CNTLZ
):
599 gen_helper_cntlz(tdest
, tsrca
);
602 case OE_RR_X0(CNTTZ
):
603 case OE_RR_Y0(CNTTZ
):
604 gen_helper_cnttz(tdest
, tsrca
);
607 case OE_RR_X0(FSINGLE_PACK1
):
608 case OE_RR_Y0(FSINGLE_PACK1
):
610 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
613 mnemonic
= "ld1s"; /* prefetch_l1_fault */
617 mnemonic
= "ld1u"; /* prefetch, prefetch_l1 */
618 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
622 mnemonic
= "ld2s"; /* prefetch_l2_fault */
626 mnemonic
= "ld2u"; /* prefetch_l2 */
627 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
631 mnemonic
= "ld4s"; /* prefetch_l3_fault */
635 mnemonic
= "ld4u"; /* prefetch_l3 */
636 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
638 case OE_RR_X1(LDNT1S
):
642 case OE_RR_X1(LDNT1U
):
646 case OE_RR_X1(LDNT2S
):
650 case OE_RR_X1(LDNT2U
):
654 case OE_RR_X1(LDNT4S
):
658 case OE_RR_X1(LDNT4U
):
670 if (!prefetch_nofault
) {
671 tcg_gen_qemu_ld_tl(tdest
, tsrca
, dc
->mmuidx
, memop
);
675 tcg_gen_andi_tl(tdest
, tsrca
, ~7);
676 tcg_gen_qemu_ld_tl(tdest
, tdest
, dc
->mmuidx
, MO_TEQ
);
682 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
684 tcg_gen_movi_tl(tdest
, dc
->pc
+ TILEGX_BUNDLE_SIZE_IN_BYTES
);
689 gen_helper_pcnt(tdest
, tsrca
);
692 case OE_RR_X0(REVBITS
):
693 case OE_RR_Y0(REVBITS
):
694 gen_helper_revbits(tdest
, tsrca
);
695 mnemonic
= "revbits";
697 case OE_RR_X0(REVBYTES
):
698 case OE_RR_Y0(REVBYTES
):
699 tcg_gen_bswap64_tl(tdest
, tsrca
);
700 mnemonic
= "revbytes";
702 case OE_RR_X0(TBLIDXB0
):
703 case OE_RR_Y0(TBLIDXB0
):
704 tcg_gen_deposit_tl(tdest
, load_gr(dc
, dest
), tsrca
, 2, 8);
705 mnemonic
= "tblidxb0";
707 case OE_RR_X0(TBLIDXB1
):
708 case OE_RR_Y0(TBLIDXB1
):
709 tcg_gen_shri_tl(tdest
, tsrca
, 8);
710 tcg_gen_deposit_tl(tdest
, load_gr(dc
, dest
), tdest
, 2, 8);
711 mnemonic
= "tblidxb1";
713 case OE_RR_X0(TBLIDXB2
):
714 case OE_RR_Y0(TBLIDXB2
):
715 tcg_gen_shri_tl(tdest
, tsrca
, 16);
716 tcg_gen_deposit_tl(tdest
, load_gr(dc
, dest
), tdest
, 2, 8);
717 mnemonic
= "tblidxb2";
719 case OE_RR_X0(TBLIDXB3
):
720 case OE_RR_Y0(TBLIDXB3
):
721 tcg_gen_shri_tl(tdest
, tsrca
, 24);
722 tcg_gen_deposit_tl(tdest
, load_gr(dc
, dest
), tdest
, 2, 8);
723 mnemonic
= "tblidxb3";
726 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
729 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s", mnemonic
,
730 reg_names
[dest
], reg_names
[srca
]);
734 static TileExcp
gen_rrr_opcode(DisasContext
*dc
, unsigned opext
,
735 unsigned dest
, unsigned srca
, unsigned srcb
)
737 TCGv tdest
= dest_gr(dc
, dest
);
738 TCGv tsrca
= load_gr(dc
, srca
);
739 TCGv tsrcb
= load_gr(dc
, srcb
);
741 const char *mnemonic
;
744 case OE_RRR(ADDXSC
, 0, X0
):
745 case OE_RRR(ADDXSC
, 0, X1
):
746 gen_saturate_op(tdest
, tsrca
, tsrcb
, tcg_gen_add_tl
);
749 case OE_RRR(ADDX
, 0, X0
):
750 case OE_RRR(ADDX
, 0, X1
):
751 case OE_RRR(ADDX
, 0, Y0
):
752 case OE_RRR(ADDX
, 0, Y1
):
753 tcg_gen_add_tl(tdest
, tsrca
, tsrcb
);
754 tcg_gen_ext32s_tl(tdest
, tdest
);
757 case OE_RRR(ADD
, 0, X0
):
758 case OE_RRR(ADD
, 0, X1
):
759 case OE_RRR(ADD
, 0, Y0
):
760 case OE_RRR(ADD
, 0, Y1
):
761 tcg_gen_add_tl(tdest
, tsrca
, tsrcb
);
764 case OE_RRR(AND
, 0, X0
):
765 case OE_RRR(AND
, 0, X1
):
766 case OE_RRR(AND
, 5, Y0
):
767 case OE_RRR(AND
, 5, Y1
):
768 tcg_gen_and_tl(tdest
, tsrca
, tsrcb
);
771 case OE_RRR(CMOVEQZ
, 0, X0
):
772 case OE_RRR(CMOVEQZ
, 4, Y0
):
773 tcg_gen_movcond_tl(TCG_COND_EQ
, tdest
, tsrca
, load_zero(dc
),
774 tsrcb
, load_gr(dc
, dest
));
775 mnemonic
= "cmoveqz";
777 case OE_RRR(CMOVNEZ
, 0, X0
):
778 case OE_RRR(CMOVNEZ
, 4, Y0
):
779 tcg_gen_movcond_tl(TCG_COND_NE
, tdest
, tsrca
, load_zero(dc
),
780 tsrcb
, load_gr(dc
, dest
));
781 mnemonic
= "cmovnez";
783 case OE_RRR(CMPEQ
, 0, X0
):
784 case OE_RRR(CMPEQ
, 0, X1
):
785 case OE_RRR(CMPEQ
, 3, Y0
):
786 case OE_RRR(CMPEQ
, 3, Y1
):
787 tcg_gen_setcond_tl(TCG_COND_EQ
, tdest
, tsrca
, tsrcb
);
790 case OE_RRR(CMPEXCH4
, 0, X1
):
791 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
792 TILEGX_EXCP_OPCODE_CMPEXCH4
);
793 mnemonic
= "cmpexch4";
795 case OE_RRR(CMPEXCH
, 0, X1
):
796 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
797 TILEGX_EXCP_OPCODE_CMPEXCH
);
798 mnemonic
= "cmpexch";
800 case OE_RRR(CMPLES
, 0, X0
):
801 case OE_RRR(CMPLES
, 0, X1
):
802 case OE_RRR(CMPLES
, 2, Y0
):
803 case OE_RRR(CMPLES
, 2, Y1
):
804 tcg_gen_setcond_tl(TCG_COND_LE
, tdest
, tsrca
, tsrcb
);
807 case OE_RRR(CMPLEU
, 0, X0
):
808 case OE_RRR(CMPLEU
, 0, X1
):
809 case OE_RRR(CMPLEU
, 2, Y0
):
810 case OE_RRR(CMPLEU
, 2, Y1
):
811 tcg_gen_setcond_tl(TCG_COND_LEU
, tdest
, tsrca
, tsrcb
);
814 case OE_RRR(CMPLTS
, 0, X0
):
815 case OE_RRR(CMPLTS
, 0, X1
):
816 case OE_RRR(CMPLTS
, 2, Y0
):
817 case OE_RRR(CMPLTS
, 2, Y1
):
818 tcg_gen_setcond_tl(TCG_COND_LT
, tdest
, tsrca
, tsrcb
);
821 case OE_RRR(CMPLTU
, 0, X0
):
822 case OE_RRR(CMPLTU
, 0, X1
):
823 case OE_RRR(CMPLTU
, 2, Y0
):
824 case OE_RRR(CMPLTU
, 2, Y1
):
825 tcg_gen_setcond_tl(TCG_COND_LTU
, tdest
, tsrca
, tsrcb
);
828 case OE_RRR(CMPNE
, 0, X0
):
829 case OE_RRR(CMPNE
, 0, X1
):
830 case OE_RRR(CMPNE
, 3, Y0
):
831 case OE_RRR(CMPNE
, 3, Y1
):
832 tcg_gen_setcond_tl(TCG_COND_NE
, tdest
, tsrca
, tsrcb
);
835 case OE_RRR(CMULAF
, 0, X0
):
836 gen_helper_cmulaf(tdest
, load_gr(dc
, dest
), tsrca
, tsrcb
);
839 case OE_RRR(CMULA
, 0, X0
):
840 gen_helper_cmula(tdest
, load_gr(dc
, dest
), tsrca
, tsrcb
);
843 case OE_RRR(CMULFR
, 0, X0
):
844 gen_cmul2(tdest
, tsrca
, tsrcb
, 15, 1 << 14);
847 case OE_RRR(CMULF
, 0, X0
):
848 gen_cmul2(tdest
, tsrca
, tsrcb
, 15, 0);
851 case OE_RRR(CMULHR
, 0, X0
):
852 gen_cmul2(tdest
, tsrca
, tsrcb
, 16, 1 << 15);
855 case OE_RRR(CMULH
, 0, X0
):
856 gen_cmul2(tdest
, tsrca
, tsrcb
, 16, 0);
859 case OE_RRR(CMUL
, 0, X0
):
860 gen_helper_cmula(tdest
, load_zero(dc
), tsrca
, tsrcb
);
863 case OE_RRR(CRC32_32
, 0, X0
):
864 gen_helper_crc32_32(tdest
, tsrca
, tsrcb
);
865 mnemonic
= "crc32_32";
867 case OE_RRR(CRC32_8
, 0, X0
):
868 gen_helper_crc32_8(tdest
, tsrca
, tsrcb
);
869 mnemonic
= "crc32_8";
871 case OE_RRR(DBLALIGN2
, 0, X0
):
872 case OE_RRR(DBLALIGN2
, 0, X1
):
873 gen_dblaligni(tdest
, tsrca
, tsrcb
, 16);
874 mnemonic
= "dblalign2";
876 case OE_RRR(DBLALIGN4
, 0, X0
):
877 case OE_RRR(DBLALIGN4
, 0, X1
):
878 gen_dblaligni(tdest
, tsrca
, tsrcb
, 32);
879 mnemonic
= "dblalign4";
881 case OE_RRR(DBLALIGN6
, 0, X0
):
882 case OE_RRR(DBLALIGN6
, 0, X1
):
883 gen_dblaligni(tdest
, tsrca
, tsrcb
, 48);
884 mnemonic
= "dblalign6";
886 case OE_RRR(DBLALIGN
, 0, X0
):
887 gen_dblalign(tdest
, load_gr(dc
, dest
), tsrca
, tsrcb
);
888 mnemonic
= "dblalign";
890 case OE_RRR(EXCH4
, 0, X1
):
891 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
892 TILEGX_EXCP_OPCODE_EXCH4
);
895 case OE_RRR(EXCH
, 0, X1
):
896 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
897 TILEGX_EXCP_OPCODE_EXCH
);
900 case OE_RRR(FDOUBLE_ADDSUB
, 0, X0
):
901 case OE_RRR(FDOUBLE_ADD_FLAGS
, 0, X0
):
902 case OE_RRR(FDOUBLE_MUL_FLAGS
, 0, X0
):
903 case OE_RRR(FDOUBLE_PACK1
, 0, X0
):
904 case OE_RRR(FDOUBLE_PACK2
, 0, X0
):
905 case OE_RRR(FDOUBLE_SUB_FLAGS
, 0, X0
):
906 case OE_RRR(FDOUBLE_UNPACK_MAX
, 0, X0
):
907 case OE_RRR(FDOUBLE_UNPACK_MIN
, 0, X0
):
908 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
909 case OE_RRR(FETCHADD4
, 0, X1
):
910 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
911 TILEGX_EXCP_OPCODE_FETCHADD4
);
912 mnemonic
= "fetchadd4";
914 case OE_RRR(FETCHADDGEZ4
, 0, X1
):
915 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
916 TILEGX_EXCP_OPCODE_FETCHADDGEZ4
);
917 mnemonic
= "fetchaddgez4";
919 case OE_RRR(FETCHADDGEZ
, 0, X1
):
920 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
921 TILEGX_EXCP_OPCODE_FETCHADDGEZ
);
922 mnemonic
= "fetchaddgez";
924 case OE_RRR(FETCHADD
, 0, X1
):
925 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
926 TILEGX_EXCP_OPCODE_FETCHADD
);
927 mnemonic
= "fetchadd";
929 case OE_RRR(FETCHAND4
, 0, X1
):
930 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
931 TILEGX_EXCP_OPCODE_FETCHAND4
);
932 mnemonic
= "fetchand4";
934 case OE_RRR(FETCHAND
, 0, X1
):
935 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
936 TILEGX_EXCP_OPCODE_FETCHAND
);
937 mnemonic
= "fetchand";
939 case OE_RRR(FETCHOR4
, 0, X1
):
940 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
941 TILEGX_EXCP_OPCODE_FETCHOR4
);
942 mnemonic
= "fetchor4";
944 case OE_RRR(FETCHOR
, 0, X1
):
945 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
946 TILEGX_EXCP_OPCODE_FETCHOR
);
947 mnemonic
= "fetchor";
949 case OE_RRR(FSINGLE_ADD1
, 0, X0
):
950 case OE_RRR(FSINGLE_ADDSUB2
, 0, X0
):
951 case OE_RRR(FSINGLE_MUL1
, 0, X0
):
952 case OE_RRR(FSINGLE_MUL2
, 0, X0
):
953 case OE_RRR(FSINGLE_PACK2
, 0, X0
):
954 case OE_RRR(FSINGLE_SUB1
, 0, X0
):
955 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
956 case OE_RRR(MNZ
, 0, X0
):
957 case OE_RRR(MNZ
, 0, X1
):
958 case OE_RRR(MNZ
, 4, Y0
):
959 case OE_RRR(MNZ
, 4, Y1
):
961 tcg_gen_movcond_tl(TCG_COND_NE
, tdest
, tsrca
, t0
, tsrcb
, t0
);
964 case OE_RRR(MULAX
, 0, X0
):
965 case OE_RRR(MULAX
, 3, Y0
):
966 tcg_gen_mul_tl(tdest
, tsrca
, tsrcb
);
967 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
968 tcg_gen_ext32s_tl(tdest
, tdest
);
971 case OE_RRR(MULA_HS_HS
, 0, X0
):
972 case OE_RRR(MULA_HS_HS
, 9, Y0
):
973 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, HS
);
974 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
975 mnemonic
= "mula_hs_hs";
977 case OE_RRR(MULA_HS_HU
, 0, X0
):
978 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, HU
);
979 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
980 mnemonic
= "mula_hs_hu";
982 case OE_RRR(MULA_HS_LS
, 0, X0
):
983 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, LS
);
984 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
985 mnemonic
= "mula_hs_ls";
987 case OE_RRR(MULA_HS_LU
, 0, X0
):
988 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, LU
);
989 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
990 mnemonic
= "mula_hs_lu";
992 case OE_RRR(MULA_HU_HU
, 0, X0
):
993 case OE_RRR(MULA_HU_HU
, 9, Y0
):
994 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, HU
);
995 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
996 mnemonic
= "mula_hu_hu";
998 case OE_RRR(MULA_HU_LS
, 0, X0
):
999 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, LS
);
1000 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1001 mnemonic
= "mula_hu_ls";
1003 case OE_RRR(MULA_HU_LU
, 0, X0
):
1004 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, LU
);
1005 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1006 mnemonic
= "mula_hu_lu";
1008 case OE_RRR(MULA_LS_LS
, 0, X0
):
1009 case OE_RRR(MULA_LS_LS
, 9, Y0
):
1010 gen_mul_half(tdest
, tsrca
, tsrcb
, LS
, LS
);
1011 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1012 mnemonic
= "mula_ls_ls";
1014 case OE_RRR(MULA_LS_LU
, 0, X0
):
1015 gen_mul_half(tdest
, tsrca
, tsrcb
, LS
, LU
);
1016 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1017 mnemonic
= "mula_ls_lu";
1019 case OE_RRR(MULA_LU_LU
, 0, X0
):
1020 case OE_RRR(MULA_LU_LU
, 9, Y0
):
1021 gen_mul_half(tdest
, tsrca
, tsrcb
, LU
, LU
);
1022 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1023 mnemonic
= "mula_lu_lu";
1025 case OE_RRR(MULX
, 0, X0
):
1026 case OE_RRR(MULX
, 3, Y0
):
1027 tcg_gen_mul_tl(tdest
, tsrca
, tsrcb
);
1028 tcg_gen_ext32s_tl(tdest
, tdest
);
1031 case OE_RRR(MUL_HS_HS
, 0, X0
):
1032 case OE_RRR(MUL_HS_HS
, 8, Y0
):
1033 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, HS
);
1034 mnemonic
= "mul_hs_hs";
1036 case OE_RRR(MUL_HS_HU
, 0, X0
):
1037 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, HU
);
1038 mnemonic
= "mul_hs_hu";
1040 case OE_RRR(MUL_HS_LS
, 0, X0
):
1041 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, LS
);
1042 mnemonic
= "mul_hs_ls";
1044 case OE_RRR(MUL_HS_LU
, 0, X0
):
1045 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, LU
);
1046 mnemonic
= "mul_hs_lu";
1048 case OE_RRR(MUL_HU_HU
, 0, X0
):
1049 case OE_RRR(MUL_HU_HU
, 8, Y0
):
1050 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, HU
);
1051 mnemonic
= "mul_hu_hu";
1053 case OE_RRR(MUL_HU_LS
, 0, X0
):
1054 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, LS
);
1055 mnemonic
= "mul_hu_ls";
1057 case OE_RRR(MUL_HU_LU
, 0, X0
):
1058 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, LU
);
1059 mnemonic
= "mul_hu_lu";
1061 case OE_RRR(MUL_LS_LS
, 0, X0
):
1062 case OE_RRR(MUL_LS_LS
, 8, Y0
):
1063 gen_mul_half(tdest
, tsrca
, tsrcb
, LS
, LS
);
1064 mnemonic
= "mul_ls_ls";
1066 case OE_RRR(MUL_LS_LU
, 0, X0
):
1067 gen_mul_half(tdest
, tsrca
, tsrcb
, LS
, LU
);
1068 mnemonic
= "mul_ls_lu";
1070 case OE_RRR(MUL_LU_LU
, 0, X0
):
1071 case OE_RRR(MUL_LU_LU
, 8, Y0
):
1072 gen_mul_half(tdest
, tsrca
, tsrcb
, LU
, LU
);
1073 mnemonic
= "mul_lu_lu";
1075 case OE_RRR(MZ
, 0, X0
):
1076 case OE_RRR(MZ
, 0, X1
):
1077 case OE_RRR(MZ
, 4, Y0
):
1078 case OE_RRR(MZ
, 4, Y1
):
1080 tcg_gen_movcond_tl(TCG_COND_EQ
, tdest
, tsrca
, t0
, tsrcb
, t0
);
1083 case OE_RRR(NOR
, 0, X0
):
1084 case OE_RRR(NOR
, 0, X1
):
1085 case OE_RRR(NOR
, 5, Y0
):
1086 case OE_RRR(NOR
, 5, Y1
):
1087 tcg_gen_nor_tl(tdest
, tsrca
, tsrcb
);
1090 case OE_RRR(OR
, 0, X0
):
1091 case OE_RRR(OR
, 0, X1
):
1092 case OE_RRR(OR
, 5, Y0
):
1093 case OE_RRR(OR
, 5, Y1
):
1094 tcg_gen_or_tl(tdest
, tsrca
, tsrcb
);
1097 case OE_RRR(ROTL
, 0, X0
):
1098 case OE_RRR(ROTL
, 0, X1
):
1099 case OE_RRR(ROTL
, 6, Y0
):
1100 case OE_RRR(ROTL
, 6, Y1
):
1101 tcg_gen_andi_tl(tdest
, tsrcb
, 63);
1102 tcg_gen_rotl_tl(tdest
, tsrca
, tdest
);
1105 case OE_RRR(SHL1ADDX
, 0, X0
):
1106 case OE_RRR(SHL1ADDX
, 0, X1
):
1107 case OE_RRR(SHL1ADDX
, 7, Y0
):
1108 case OE_RRR(SHL1ADDX
, 7, Y1
):
1109 tcg_gen_shli_tl(tdest
, tsrca
, 1);
1110 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1111 tcg_gen_ext32s_tl(tdest
, tdest
);
1112 mnemonic
= "shl1addx";
1114 case OE_RRR(SHL1ADD
, 0, X0
):
1115 case OE_RRR(SHL1ADD
, 0, X1
):
1116 case OE_RRR(SHL1ADD
, 1, Y0
):
1117 case OE_RRR(SHL1ADD
, 1, Y1
):
1118 tcg_gen_shli_tl(tdest
, tsrca
, 1);
1119 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1120 mnemonic
= "shl1add";
1122 case OE_RRR(SHL2ADDX
, 0, X0
):
1123 case OE_RRR(SHL2ADDX
, 0, X1
):
1124 case OE_RRR(SHL2ADDX
, 7, Y0
):
1125 case OE_RRR(SHL2ADDX
, 7, Y1
):
1126 tcg_gen_shli_tl(tdest
, tsrca
, 2);
1127 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1128 tcg_gen_ext32s_tl(tdest
, tdest
);
1129 mnemonic
= "shl2addx";
1131 case OE_RRR(SHL2ADD
, 0, X0
):
1132 case OE_RRR(SHL2ADD
, 0, X1
):
1133 case OE_RRR(SHL2ADD
, 1, Y0
):
1134 case OE_RRR(SHL2ADD
, 1, Y1
):
1135 tcg_gen_shli_tl(tdest
, tsrca
, 2);
1136 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1137 mnemonic
= "shl2add";
1139 case OE_RRR(SHL3ADDX
, 0, X0
):
1140 case OE_RRR(SHL3ADDX
, 0, X1
):
1141 case OE_RRR(SHL3ADDX
, 7, Y0
):
1142 case OE_RRR(SHL3ADDX
, 7, Y1
):
1143 tcg_gen_shli_tl(tdest
, tsrca
, 3);
1144 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1145 tcg_gen_ext32s_tl(tdest
, tdest
);
1146 mnemonic
= "shl3addx";
1148 case OE_RRR(SHL3ADD
, 0, X0
):
1149 case OE_RRR(SHL3ADD
, 0, X1
):
1150 case OE_RRR(SHL3ADD
, 1, Y0
):
1151 case OE_RRR(SHL3ADD
, 1, Y1
):
1152 tcg_gen_shli_tl(tdest
, tsrca
, 3);
1153 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1154 mnemonic
= "shl3add";
1156 case OE_RRR(SHLX
, 0, X0
):
1157 case OE_RRR(SHLX
, 0, X1
):
1158 tcg_gen_andi_tl(tdest
, tsrcb
, 31);
1159 tcg_gen_shl_tl(tdest
, tsrca
, tdest
);
1160 tcg_gen_ext32s_tl(tdest
, tdest
);
1163 case OE_RRR(SHL
, 0, X0
):
1164 case OE_RRR(SHL
, 0, X1
):
1165 case OE_RRR(SHL
, 6, Y0
):
1166 case OE_RRR(SHL
, 6, Y1
):
1167 tcg_gen_andi_tl(tdest
, tsrcb
, 63);
1168 tcg_gen_shl_tl(tdest
, tsrca
, tdest
);
1171 case OE_RRR(SHRS
, 0, X0
):
1172 case OE_RRR(SHRS
, 0, X1
):
1173 case OE_RRR(SHRS
, 6, Y0
):
1174 case OE_RRR(SHRS
, 6, Y1
):
1175 tcg_gen_andi_tl(tdest
, tsrcb
, 63);
1176 tcg_gen_sar_tl(tdest
, tsrca
, tdest
);
1179 case OE_RRR(SHRUX
, 0, X0
):
1180 case OE_RRR(SHRUX
, 0, X1
):
1181 t0
= tcg_temp_new();
1182 tcg_gen_andi_tl(t0
, tsrcb
, 31);
1183 tcg_gen_ext32u_tl(tdest
, tsrca
);
1184 tcg_gen_shr_tl(tdest
, tdest
, t0
);
1185 tcg_gen_ext32s_tl(tdest
, tdest
);
1189 case OE_RRR(SHRU
, 0, X0
):
1190 case OE_RRR(SHRU
, 0, X1
):
1191 case OE_RRR(SHRU
, 6, Y0
):
1192 case OE_RRR(SHRU
, 6, Y1
):
1193 tcg_gen_andi_tl(tdest
, tsrcb
, 63);
1194 tcg_gen_shr_tl(tdest
, tsrca
, tdest
);
1197 case OE_RRR(SHUFFLEBYTES
, 0, X0
):
1198 gen_helper_shufflebytes(tdest
, load_gr(dc
, dest
), tsrca
, tsrca
);
1199 mnemonic
= "shufflebytes";
1201 case OE_RRR(SUBXSC
, 0, X0
):
1202 case OE_RRR(SUBXSC
, 0, X1
):
1203 gen_saturate_op(tdest
, tsrca
, tsrcb
, tcg_gen_sub_tl
);
1204 mnemonic
= "subxsc";
1206 case OE_RRR(SUBX
, 0, X0
):
1207 case OE_RRR(SUBX
, 0, X1
):
1208 case OE_RRR(SUBX
, 0, Y0
):
1209 case OE_RRR(SUBX
, 0, Y1
):
1210 tcg_gen_sub_tl(tdest
, tsrca
, tsrcb
);
1211 tcg_gen_ext32s_tl(tdest
, tdest
);
1214 case OE_RRR(SUB
, 0, X0
):
1215 case OE_RRR(SUB
, 0, X1
):
1216 case OE_RRR(SUB
, 0, Y0
):
1217 case OE_RRR(SUB
, 0, Y1
):
1218 tcg_gen_sub_tl(tdest
, tsrca
, tsrcb
);
1221 case OE_RRR(V1ADDUC
, 0, X0
):
1222 case OE_RRR(V1ADDUC
, 0, X1
):
1223 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1224 case OE_RRR(V1ADD
, 0, X0
):
1225 case OE_RRR(V1ADD
, 0, X1
):
1226 gen_v12add(tdest
, tsrca
, tsrcb
, V1_IMM(0x80));
1229 case OE_RRR(V1ADIFFU
, 0, X0
):
1230 case OE_RRR(V1AVGU
, 0, X0
):
1231 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1232 case OE_RRR(V1CMPEQ
, 0, X0
):
1233 case OE_RRR(V1CMPEQ
, 0, X1
):
1234 tcg_gen_xor_tl(tdest
, tsrca
, tsrcb
);
1235 gen_v1cmpeq0(tdest
);
1236 mnemonic
= "v1cmpeq";
1238 case OE_RRR(V1CMPLES
, 0, X0
):
1239 case OE_RRR(V1CMPLES
, 0, X1
):
1240 case OE_RRR(V1CMPLEU
, 0, X0
):
1241 case OE_RRR(V1CMPLEU
, 0, X1
):
1242 case OE_RRR(V1CMPLTS
, 0, X0
):
1243 case OE_RRR(V1CMPLTS
, 0, X1
):
1244 case OE_RRR(V1CMPLTU
, 0, X0
):
1245 case OE_RRR(V1CMPLTU
, 0, X1
):
1246 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1247 case OE_RRR(V1CMPNE
, 0, X0
):
1248 case OE_RRR(V1CMPNE
, 0, X1
):
1249 tcg_gen_xor_tl(tdest
, tsrca
, tsrcb
);
1250 gen_v1cmpne0(tdest
);
1251 mnemonic
= "v1cmpne";
1253 case OE_RRR(V1DDOTPUA
, 0, X0
):
1254 case OE_RRR(V1DDOTPUSA
, 0, X0
):
1255 case OE_RRR(V1DDOTPUS
, 0, X0
):
1256 case OE_RRR(V1DDOTPU
, 0, X0
):
1257 case OE_RRR(V1DOTPA
, 0, X0
):
1258 case OE_RRR(V1DOTPUA
, 0, X0
):
1259 case OE_RRR(V1DOTPUSA
, 0, X0
):
1260 case OE_RRR(V1DOTPUS
, 0, X0
):
1261 case OE_RRR(V1DOTPU
, 0, X0
):
1262 case OE_RRR(V1DOTP
, 0, X0
):
1263 case OE_RRR(V1INT_H
, 0, X0
):
1264 case OE_RRR(V1INT_H
, 0, X1
):
1265 case OE_RRR(V1INT_L
, 0, X0
):
1266 case OE_RRR(V1INT_L
, 0, X1
):
1267 case OE_RRR(V1MAXU
, 0, X0
):
1268 case OE_RRR(V1MAXU
, 0, X1
):
1269 case OE_RRR(V1MINU
, 0, X0
):
1270 case OE_RRR(V1MINU
, 0, X1
):
1271 case OE_RRR(V1MNZ
, 0, X0
):
1272 case OE_RRR(V1MNZ
, 0, X1
):
1273 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1274 case OE_RRR(V1MULTU
, 0, X0
):
1275 gen_helper_v1multu(tdest
, tsrca
, tsrcb
);
1276 mnemonic
= "v1multu";
1278 case OE_RRR(V1MULUS
, 0, X0
):
1279 case OE_RRR(V1MULU
, 0, X0
):
1280 case OE_RRR(V1MZ
, 0, X0
):
1281 case OE_RRR(V1MZ
, 0, X1
):
1282 case OE_RRR(V1SADAU
, 0, X0
):
1283 case OE_RRR(V1SADU
, 0, X0
):
1284 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1285 case OE_RRR(V1SHL
, 0, X0
):
1286 case OE_RRR(V1SHL
, 0, X1
):
1287 gen_helper_v1shl(tdest
, tsrca
, tsrcb
);
1290 case OE_RRR(V1SHRS
, 0, X0
):
1291 case OE_RRR(V1SHRS
, 0, X1
):
1292 gen_helper_v1shrs(tdest
, tsrca
, tsrcb
);
1293 mnemonic
= "v1shrs";
1295 case OE_RRR(V1SHRU
, 0, X0
):
1296 case OE_RRR(V1SHRU
, 0, X1
):
1297 gen_helper_v1shru(tdest
, tsrca
, tsrcb
);
1298 mnemonic
= "v1shru";
1300 case OE_RRR(V1SUBUC
, 0, X0
):
1301 case OE_RRR(V1SUBUC
, 0, X1
):
1302 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1303 case OE_RRR(V1SUB
, 0, X0
):
1304 case OE_RRR(V1SUB
, 0, X1
):
1305 gen_v12sub(tdest
, tsrca
, tsrcb
, V1_IMM(0x80));
1308 case OE_RRR(V2ADDSC
, 0, X0
):
1309 case OE_RRR(V2ADDSC
, 0, X1
):
1310 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1311 case OE_RRR(V2ADD
, 0, X0
):
1312 case OE_RRR(V2ADD
, 0, X1
):
1313 gen_v12add(tdest
, tsrca
, tsrcb
, V2_IMM(0x8000));
1316 case OE_RRR(V2ADIFFS
, 0, X0
):
1317 case OE_RRR(V2AVGS
, 0, X0
):
1318 case OE_RRR(V2CMPEQ
, 0, X0
):
1319 case OE_RRR(V2CMPEQ
, 0, X1
):
1320 case OE_RRR(V2CMPLES
, 0, X0
):
1321 case OE_RRR(V2CMPLES
, 0, X1
):
1322 case OE_RRR(V2CMPLEU
, 0, X0
):
1323 case OE_RRR(V2CMPLEU
, 0, X1
):
1324 case OE_RRR(V2CMPLTS
, 0, X0
):
1325 case OE_RRR(V2CMPLTS
, 0, X1
):
1326 case OE_RRR(V2CMPLTU
, 0, X0
):
1327 case OE_RRR(V2CMPLTU
, 0, X1
):
1328 case OE_RRR(V2CMPNE
, 0, X0
):
1329 case OE_RRR(V2CMPNE
, 0, X1
):
1330 case OE_RRR(V2DOTPA
, 0, X0
):
1331 case OE_RRR(V2DOTP
, 0, X0
):
1332 case OE_RRR(V2INT_H
, 0, X0
):
1333 case OE_RRR(V2INT_H
, 0, X1
):
1334 case OE_RRR(V2INT_L
, 0, X0
):
1335 case OE_RRR(V2INT_L
, 0, X1
):
1336 case OE_RRR(V2MAXS
, 0, X0
):
1337 case OE_RRR(V2MAXS
, 0, X1
):
1338 case OE_RRR(V2MINS
, 0, X0
):
1339 case OE_RRR(V2MINS
, 0, X1
):
1340 case OE_RRR(V2MNZ
, 0, X0
):
1341 case OE_RRR(V2MNZ
, 0, X1
):
1342 case OE_RRR(V2MULFSC
, 0, X0
):
1343 case OE_RRR(V2MULS
, 0, X0
):
1344 case OE_RRR(V2MULTS
, 0, X0
):
1345 case OE_RRR(V2MZ
, 0, X0
):
1346 case OE_RRR(V2MZ
, 0, X1
):
1347 case OE_RRR(V2PACKH
, 0, X0
):
1348 case OE_RRR(V2PACKH
, 0, X1
):
1349 case OE_RRR(V2PACKL
, 0, X0
):
1350 case OE_RRR(V2PACKL
, 0, X1
):
1351 case OE_RRR(V2PACKUC
, 0, X0
):
1352 case OE_RRR(V2PACKUC
, 0, X1
):
1353 case OE_RRR(V2SADAS
, 0, X0
):
1354 case OE_RRR(V2SADAU
, 0, X0
):
1355 case OE_RRR(V2SADS
, 0, X0
):
1356 case OE_RRR(V2SADU
, 0, X0
):
1357 case OE_RRR(V2SHLSC
, 0, X0
):
1358 case OE_RRR(V2SHLSC
, 0, X1
):
1359 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1360 case OE_RRR(V2SHL
, 0, X0
):
1361 case OE_RRR(V2SHL
, 0, X1
):
1362 gen_helper_v2shl(tdest
, tsrca
, tsrcb
);
1365 case OE_RRR(V2SHRS
, 0, X0
):
1366 case OE_RRR(V2SHRS
, 0, X1
):
1367 gen_helper_v2shrs(tdest
, tsrca
, tsrcb
);
1368 mnemonic
= "v2shrs";
1370 case OE_RRR(V2SHRU
, 0, X0
):
1371 case OE_RRR(V2SHRU
, 0, X1
):
1372 gen_helper_v2shru(tdest
, tsrca
, tsrcb
);
1373 mnemonic
= "v2shru";
1375 case OE_RRR(V2SUBSC
, 0, X0
):
1376 case OE_RRR(V2SUBSC
, 0, X1
):
1377 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1378 case OE_RRR(V2SUB
, 0, X0
):
1379 case OE_RRR(V2SUB
, 0, X1
):
1380 gen_v12sub(tdest
, tsrca
, tsrcb
, V2_IMM(0x8000));
1383 case OE_RRR(V4ADDSC
, 0, X0
):
1384 case OE_RRR(V4ADDSC
, 0, X1
):
1385 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1386 case OE_RRR(V4ADD
, 0, X0
):
1387 case OE_RRR(V4ADD
, 0, X1
):
1388 gen_v4op(tdest
, tsrca
, tsrcb
, tcg_gen_add_i32
);
1391 case OE_RRR(V4INT_H
, 0, X0
):
1392 case OE_RRR(V4INT_H
, 0, X1
):
1393 tcg_gen_shri_tl(tdest
, tsrcb
, 32);
1394 tcg_gen_deposit_tl(tdest
, tsrca
, tdest
, 0, 32);
1395 mnemonic
= "v4int_h";
1397 case OE_RRR(V4INT_L
, 0, X0
):
1398 case OE_RRR(V4INT_L
, 0, X1
):
1399 tcg_gen_deposit_tl(tdest
, tsrcb
, tsrca
, 32, 32);
1400 mnemonic
= "v4int_l";
1402 case OE_RRR(V4PACKSC
, 0, X0
):
1403 case OE_RRR(V4PACKSC
, 0, X1
):
1404 case OE_RRR(V4SHLSC
, 0, X0
):
1405 case OE_RRR(V4SHLSC
, 0, X1
):
1406 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1407 case OE_RRR(V4SHL
, 0, X0
):
1408 case OE_RRR(V4SHL
, 0, X1
):
1409 gen_v4sh(tdest
, tsrca
, tsrcb
, tcg_gen_shl_i32
);
1412 case OE_RRR(V4SHRS
, 0, X0
):
1413 case OE_RRR(V4SHRS
, 0, X1
):
1414 gen_v4sh(tdest
, tsrca
, tsrcb
, tcg_gen_sar_i32
);
1415 mnemonic
= "v4shrs";
1417 case OE_RRR(V4SHRU
, 0, X0
):
1418 case OE_RRR(V4SHRU
, 0, X1
):
1419 gen_v4sh(tdest
, tsrca
, tsrcb
, tcg_gen_shr_i32
);
1420 mnemonic
= "v4shru";
1422 case OE_RRR(V4SUBSC
, 0, X0
):
1423 case OE_RRR(V4SUBSC
, 0, X1
):
1424 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1425 case OE_RRR(V4SUB
, 0, X0
):
1426 case OE_RRR(V4SUB
, 0, X1
):
1427 gen_v4op(tdest
, tsrca
, tsrcb
, tcg_gen_sub_i32
);
1430 case OE_RRR(XOR
, 0, X0
):
1431 case OE_RRR(XOR
, 0, X1
):
1432 case OE_RRR(XOR
, 5, Y0
):
1433 case OE_RRR(XOR
, 5, Y1
):
1434 tcg_gen_xor_tl(tdest
, tsrca
, tsrcb
);
1438 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1441 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s, %s", mnemonic
,
1442 reg_names
[dest
], reg_names
[srca
], reg_names
[srcb
]);
1443 return TILEGX_EXCP_NONE
;
1446 static TileExcp
gen_rri_opcode(DisasContext
*dc
, unsigned opext
,
1447 unsigned dest
, unsigned srca
, int imm
)
1449 TCGv tdest
= dest_gr(dc
, dest
);
1450 TCGv tsrca
= load_gr(dc
, srca
);
1451 bool prefetch_nofault
= false;
1452 const char *mnemonic
;
1458 case OE(ADDI_OPCODE_Y0
, 0, Y0
):
1459 case OE(ADDI_OPCODE_Y1
, 0, Y1
):
1460 case OE_IM(ADDI
, X0
):
1461 case OE_IM(ADDI
, X1
):
1462 tcg_gen_addi_tl(tdest
, tsrca
, imm
);
1465 case OE(ADDXI_OPCODE_Y0
, 0, Y0
):
1466 case OE(ADDXI_OPCODE_Y1
, 0, Y1
):
1467 case OE_IM(ADDXI
, X0
):
1468 case OE_IM(ADDXI
, X1
):
1469 tcg_gen_addi_tl(tdest
, tsrca
, imm
);
1470 tcg_gen_ext32s_tl(tdest
, tdest
);
1473 case OE(ANDI_OPCODE_Y0
, 0, Y0
):
1474 case OE(ANDI_OPCODE_Y1
, 0, Y1
):
1475 case OE_IM(ANDI
, X0
):
1476 case OE_IM(ANDI
, X1
):
1477 tcg_gen_andi_tl(tdest
, tsrca
, imm
);
1480 case OE(CMPEQI_OPCODE_Y0
, 0, Y0
):
1481 case OE(CMPEQI_OPCODE_Y1
, 0, Y1
):
1482 case OE_IM(CMPEQI
, X0
):
1483 case OE_IM(CMPEQI
, X1
):
1484 tcg_gen_setcondi_tl(TCG_COND_EQ
, tdest
, tsrca
, imm
);
1485 mnemonic
= "cmpeqi";
1487 case OE(CMPLTSI_OPCODE_Y0
, 0, Y0
):
1488 case OE(CMPLTSI_OPCODE_Y1
, 0, Y1
):
1489 case OE_IM(CMPLTSI
, X0
):
1490 case OE_IM(CMPLTSI
, X1
):
1491 tcg_gen_setcondi_tl(TCG_COND_LT
, tdest
, tsrca
, imm
);
1492 mnemonic
= "cmpltsi";
1494 case OE_IM(CMPLTUI
, X0
):
1495 case OE_IM(CMPLTUI
, X1
):
1496 tcg_gen_setcondi_tl(TCG_COND_LTU
, tdest
, tsrca
, imm
);
1497 mnemonic
= "cmpltui";
1499 case OE_IM(LD1S_ADD
, X1
):
1501 mnemonic
= "ld1s_add"; /* prefetch_add_l1_fault */
1503 case OE_IM(LD1U_ADD
, X1
):
1505 mnemonic
= "ld1u_add"; /* prefetch_add_l1 */
1506 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
1508 case OE_IM(LD2S_ADD
, X1
):
1510 mnemonic
= "ld2s_add"; /* prefetch_add_l2_fault */
1512 case OE_IM(LD2U_ADD
, X1
):
1514 mnemonic
= "ld2u_add"; /* prefetch_add_l2 */
1515 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
1517 case OE_IM(LD4S_ADD
, X1
):
1519 mnemonic
= "ld4s_add"; /* prefetch_add_l3_fault */
1521 case OE_IM(LD4U_ADD
, X1
):
1523 mnemonic
= "ld4u_add"; /* prefetch_add_l3 */
1524 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
1526 case OE_IM(LDNT1S_ADD
, X1
):
1528 mnemonic
= "ldnt1s_add";
1530 case OE_IM(LDNT1U_ADD
, X1
):
1532 mnemonic
= "ldnt1u_add";
1534 case OE_IM(LDNT2S_ADD
, X1
):
1536 mnemonic
= "ldnt2s_add";
1538 case OE_IM(LDNT2U_ADD
, X1
):
1540 mnemonic
= "ldnt2u_add";
1542 case OE_IM(LDNT4S_ADD
, X1
):
1544 mnemonic
= "ldnt4s_add";
1546 case OE_IM(LDNT4U_ADD
, X1
):
1548 mnemonic
= "ldnt4u_add";
1550 case OE_IM(LDNT_ADD
, X1
):
1552 mnemonic
= "ldnt_add";
1554 case OE_IM(LD_ADD
, X1
):
1556 mnemonic
= "ld_add";
1558 if (!prefetch_nofault
) {
1559 tcg_gen_qemu_ld_tl(tdest
, tsrca
, dc
->mmuidx
, memop
);
1561 tcg_gen_addi_tl(dest_gr(dc
, srca
), tsrca
, imm
);
1563 case OE_IM(LDNA_ADD
, X1
):
1564 tcg_gen_andi_tl(tdest
, tsrca
, ~7);
1565 tcg_gen_qemu_ld_tl(tdest
, tdest
, dc
->mmuidx
, MO_TEQ
);
1566 tcg_gen_addi_tl(dest_gr(dc
, srca
), tsrca
, imm
);
1567 mnemonic
= "ldna_add";
1569 case OE_IM(ORI
, X0
):
1570 case OE_IM(ORI
, X1
):
1571 tcg_gen_ori_tl(tdest
, tsrca
, imm
);
1574 case OE_IM(V1ADDI
, X0
):
1575 case OE_IM(V1ADDI
, X1
):
1576 t0
= tcg_const_tl(V1_IMM(imm
));
1577 gen_v12add(tdest
, tsrca
, t0
, V1_IMM(0x80));
1579 mnemonic
= "v1addi";
1581 case OE_IM(V1CMPEQI
, X0
):
1582 case OE_IM(V1CMPEQI
, X1
):
1583 tcg_gen_xori_tl(tdest
, tsrca
, V1_IMM(imm
));
1584 gen_v1cmpeq0(tdest
);
1585 mnemonic
= "v1cmpeqi";
1587 case OE_IM(V1CMPLTSI
, X0
):
1588 case OE_IM(V1CMPLTSI
, X1
):
1589 case OE_IM(V1CMPLTUI
, X0
):
1590 case OE_IM(V1CMPLTUI
, X1
):
1591 case OE_IM(V1MAXUI
, X0
):
1592 case OE_IM(V1MAXUI
, X1
):
1593 case OE_IM(V1MINUI
, X0
):
1594 case OE_IM(V1MINUI
, X1
):
1595 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1596 case OE_IM(V2ADDI
, X0
):
1597 case OE_IM(V2ADDI
, X1
):
1598 t0
= tcg_const_tl(V2_IMM(imm
));
1599 gen_v12add(tdest
, tsrca
, t0
, V2_IMM(0x8000));
1601 mnemonic
= "v2addi";
1603 case OE_IM(V2CMPEQI
, X0
):
1604 case OE_IM(V2CMPEQI
, X1
):
1605 case OE_IM(V2CMPLTSI
, X0
):
1606 case OE_IM(V2CMPLTSI
, X1
):
1607 case OE_IM(V2CMPLTUI
, X0
):
1608 case OE_IM(V2CMPLTUI
, X1
):
1609 case OE_IM(V2MAXSI
, X0
):
1610 case OE_IM(V2MAXSI
, X1
):
1611 case OE_IM(V2MINSI
, X0
):
1612 case OE_IM(V2MINSI
, X1
):
1613 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1614 case OE_IM(XORI
, X0
):
1615 case OE_IM(XORI
, X1
):
1616 tcg_gen_xori_tl(tdest
, tsrca
, imm
);
1620 case OE_SH(ROTLI
, X0
):
1621 case OE_SH(ROTLI
, X1
):
1622 case OE_SH(ROTLI
, Y0
):
1623 case OE_SH(ROTLI
, Y1
):
1624 tcg_gen_rotli_tl(tdest
, tsrca
, imm
);
1627 case OE_SH(SHLI
, X0
):
1628 case OE_SH(SHLI
, X1
):
1629 case OE_SH(SHLI
, Y0
):
1630 case OE_SH(SHLI
, Y1
):
1631 tcg_gen_shli_tl(tdest
, tsrca
, imm
);
1634 case OE_SH(SHLXI
, X0
):
1635 case OE_SH(SHLXI
, X1
):
1636 tcg_gen_shli_tl(tdest
, tsrca
, imm
& 31);
1637 tcg_gen_ext32s_tl(tdest
, tdest
);
1640 case OE_SH(SHRSI
, X0
):
1641 case OE_SH(SHRSI
, X1
):
1642 case OE_SH(SHRSI
, Y0
):
1643 case OE_SH(SHRSI
, Y1
):
1644 tcg_gen_sari_tl(tdest
, tsrca
, imm
);
1647 case OE_SH(SHRUI
, X0
):
1648 case OE_SH(SHRUI
, X1
):
1649 case OE_SH(SHRUI
, Y0
):
1650 case OE_SH(SHRUI
, Y1
):
1651 tcg_gen_shri_tl(tdest
, tsrca
, imm
);
1654 case OE_SH(SHRUXI
, X0
):
1655 case OE_SH(SHRUXI
, X1
):
1656 if ((imm
& 31) == 0) {
1657 tcg_gen_ext32s_tl(tdest
, tsrca
);
1659 tcg_gen_ext32u_tl(tdest
, tsrca
);
1660 tcg_gen_shri_tl(tdest
, tdest
, imm
& 31);
1664 case OE_SH(V1SHLI
, X0
):
1665 case OE_SH(V1SHLI
, X1
):
1668 tcg_gen_andi_tl(tdest
, tsrca
, V1_IMM(i3
));
1669 tcg_gen_shli_tl(tdest
, tdest
, i2
);
1670 mnemonic
= "v1shli";
1672 case OE_SH(V1SHRSI
, X0
):
1673 case OE_SH(V1SHRSI
, X1
):
1674 t0
= tcg_const_tl(imm
& 7);
1675 gen_helper_v1shrs(tdest
, tsrca
, t0
);
1677 mnemonic
= "v1shrsi";
1679 case OE_SH(V1SHRUI
, X0
):
1680 case OE_SH(V1SHRUI
, X1
):
1682 i3
= (0xff << i2
) & 0xff;
1683 tcg_gen_andi_tl(tdest
, tsrca
, V1_IMM(i3
));
1684 tcg_gen_shri_tl(tdest
, tdest
, i2
);
1685 mnemonic
= "v1shrui";
1687 case OE_SH(V2SHLI
, X0
):
1688 case OE_SH(V2SHLI
, X1
):
1689 case OE_SH(V2SHRSI
, X0
):
1690 case OE_SH(V2SHRSI
, X1
):
1691 case OE_SH(V2SHRUI
, X0
):
1692 case OE_SH(V2SHRUI
, X1
):
1693 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1695 case OE(ADDLI_OPCODE_X0
, 0, X0
):
1696 case OE(ADDLI_OPCODE_X1
, 0, X1
):
1697 tcg_gen_addi_tl(tdest
, tsrca
, imm
);
1700 case OE(ADDXLI_OPCODE_X0
, 0, X0
):
1701 case OE(ADDXLI_OPCODE_X1
, 0, X1
):
1702 tcg_gen_addi_tl(tdest
, tsrca
, imm
);
1703 tcg_gen_ext32s_tl(tdest
, tdest
);
1704 mnemonic
= "addxli";
1706 case OE(SHL16INSLI_OPCODE_X0
, 0, X0
):
1707 case OE(SHL16INSLI_OPCODE_X1
, 0, X1
):
1708 tcg_gen_shli_tl(tdest
, tsrca
, 16);
1709 tcg_gen_ori_tl(tdest
, tdest
, imm
& 0xffff);
1710 mnemonic
= "shl16insli";
1714 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1717 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s, %d", mnemonic
,
1718 reg_names
[dest
], reg_names
[srca
], imm
);
1719 return TILEGX_EXCP_NONE
;
1722 static TileExcp
gen_bf_opcode_x0(DisasContext
*dc
, unsigned ext
,
1723 unsigned dest
, unsigned srca
,
1724 unsigned bfs
, unsigned bfe
)
1726 TCGv tdest
= dest_gr(dc
, dest
);
1727 TCGv tsrca
= load_gr(dc
, srca
);
1730 const char *mnemonic
;
1732 /* The bitfield is either between E and S inclusive,
1733 or up from S and down from E inclusive. */
1735 len
= bfe
- bfs
+ 1;
1737 len
= (64 - bfs
) + (bfe
+ 1);
1741 case BFEXTU_BF_OPCODE_X0
:
1742 if (bfs
== 0 && bfe
== 7) {
1743 tcg_gen_ext8u_tl(tdest
, tsrca
);
1744 } else if (bfs
== 0 && bfe
== 15) {
1745 tcg_gen_ext16u_tl(tdest
, tsrca
);
1746 } else if (bfs
== 0 && bfe
== 31) {
1747 tcg_gen_ext32u_tl(tdest
, tsrca
);
1751 tcg_gen_shli_tl(tdest
, tsrca
, rol
);
1753 tcg_gen_rotli_tl(tdest
, tsrca
, rol
);
1755 tcg_gen_shri_tl(tdest
, tdest
, (bfs
+ rol
) & 63);
1757 mnemonic
= "bfextu";
1760 case BFEXTS_BF_OPCODE_X0
:
1761 if (bfs
== 0 && bfe
== 7) {
1762 tcg_gen_ext8s_tl(tdest
, tsrca
);
1763 } else if (bfs
== 0 && bfe
== 15) {
1764 tcg_gen_ext16s_tl(tdest
, tsrca
);
1765 } else if (bfs
== 0 && bfe
== 31) {
1766 tcg_gen_ext32s_tl(tdest
, tsrca
);
1770 tcg_gen_shli_tl(tdest
, tsrca
, rol
);
1772 tcg_gen_rotli_tl(tdest
, tsrca
, rol
);
1774 tcg_gen_sari_tl(tdest
, tdest
, (bfs
+ rol
) & 63);
1776 mnemonic
= "bfexts";
1779 case BFINS_BF_OPCODE_X0
:
1780 tsrcd
= load_gr(dc
, dest
);
1782 tcg_gen_deposit_tl(tdest
, tsrcd
, tsrca
, bfs
, len
);
1784 tcg_gen_rotri_tl(tdest
, tsrcd
, bfs
);
1785 tcg_gen_deposit_tl(tdest
, tdest
, tsrca
, 0, len
);
1786 tcg_gen_rotli_tl(tdest
, tdest
, bfs
);
1791 case MM_BF_OPCODE_X0
:
1792 tsrcd
= load_gr(dc
, dest
);
1794 tcg_gen_deposit_tl(tdest
, tsrca
, tsrcd
, 0, len
);
1796 uint64_t mask
= len
== 64 ? -1 : rol64((1ULL << len
) - 1, bfs
);
1797 TCGv tmp
= tcg_const_tl(mask
);
1799 tcg_gen_and_tl(tdest
, tsrcd
, tmp
);
1800 tcg_gen_andc_tl(tmp
, tsrca
, tmp
);
1801 tcg_gen_or_tl(tdest
, tdest
, tmp
);
1808 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1811 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s, %u, %u", mnemonic
,
1812 reg_names
[dest
], reg_names
[srca
], bfs
, bfe
);
1813 return TILEGX_EXCP_NONE
;
1816 static TileExcp
gen_branch_opcode_x1(DisasContext
*dc
, unsigned ext
,
1817 unsigned srca
, int off
)
1819 target_ulong tgt
= dc
->pc
+ off
* TILEGX_BUNDLE_SIZE_IN_BYTES
;
1820 const char *mnemonic
;
1822 dc
->jmp
.dest
= tcg_const_tl(tgt
);
1823 dc
->jmp
.val1
= tcg_temp_new();
1824 tcg_gen_mov_tl(dc
->jmp
.val1
, load_gr(dc
, srca
));
1826 /* Note that the "predict taken" opcodes have bit 0 clear.
1827 Therefore, fold the two cases together by setting bit 0. */
1829 case BEQZ_BRANCH_OPCODE_X1
:
1830 dc
->jmp
.cond
= TCG_COND_EQ
;
1833 case BNEZ_BRANCH_OPCODE_X1
:
1834 dc
->jmp
.cond
= TCG_COND_NE
;
1837 case BGEZ_BRANCH_OPCODE_X1
:
1838 dc
->jmp
.cond
= TCG_COND_GE
;
1841 case BGTZ_BRANCH_OPCODE_X1
:
1842 dc
->jmp
.cond
= TCG_COND_GT
;
1845 case BLEZ_BRANCH_OPCODE_X1
:
1846 dc
->jmp
.cond
= TCG_COND_LE
;
1849 case BLTZ_BRANCH_OPCODE_X1
:
1850 dc
->jmp
.cond
= TCG_COND_LT
;
1853 case BLBC_BRANCH_OPCODE_X1
:
1854 dc
->jmp
.cond
= TCG_COND_EQ
;
1855 tcg_gen_andi_tl(dc
->jmp
.val1
, dc
->jmp
.val1
, 1);
1858 case BLBS_BRANCH_OPCODE_X1
:
1859 dc
->jmp
.cond
= TCG_COND_NE
;
1860 tcg_gen_andi_tl(dc
->jmp
.val1
, dc
->jmp
.val1
, 1);
1864 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1867 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1868 qemu_log("%s%s %s, " TARGET_FMT_lx
" <%s>",
1869 mnemonic
, ext
& 1 ? "" : "t",
1870 reg_names
[srca
], tgt
, lookup_symbol(tgt
));
1872 return TILEGX_EXCP_NONE
;
1875 static TileExcp
gen_jump_opcode_x1(DisasContext
*dc
, unsigned ext
, int off
)
1877 target_ulong tgt
= dc
->pc
+ off
* TILEGX_BUNDLE_SIZE_IN_BYTES
;
1878 const char *mnemonic
= "j";
1880 /* The extension field is 1 bit, therefore we only have JAL and J. */
1881 if (ext
== JAL_JUMP_OPCODE_X1
) {
1882 tcg_gen_movi_tl(dest_gr(dc
, TILEGX_R_LR
),
1883 dc
->pc
+ TILEGX_BUNDLE_SIZE_IN_BYTES
);
1886 dc
->jmp
.cond
= TCG_COND_ALWAYS
;
1887 dc
->jmp
.dest
= tcg_const_tl(tgt
);
1889 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1890 qemu_log("%s " TARGET_FMT_lx
" <%s>",
1891 mnemonic
, tgt
, lookup_symbol(tgt
));
1893 return TILEGX_EXCP_NONE
;
1899 void (*get
)(TCGv
, TCGv_ptr
);
1900 void (*put
)(TCGv_ptr
, TCGv
);
1903 static const TileSPR
*find_spr(unsigned spr
)
1905 /* Allow the compiler to construct the binary search tree. */
1906 #define D(N, O, G, P) \
1907 case SPR_##N: { static const TileSPR x = { #N, O, G, P }; return &x; }
1911 offsetof(CPUTLGState
, spregs
[TILEGX_SPR_CMPEXCH
]), 0, 0)
1912 D(INTERRUPT_CRITICAL_SECTION
,
1913 offsetof(CPUTLGState
, spregs
[TILEGX_SPR_CRITICAL_SEC
]), 0, 0)
1915 offsetof(CPUTLGState
, spregs
[TILEGX_SPR_SIM_CONTROL
]), 0, 0)
1920 qemu_log_mask(LOG_UNIMP
, "UNIMP SPR %u\n", spr
);
1924 static TileExcp
gen_mtspr_x1(DisasContext
*dc
, unsigned spr
, unsigned srca
)
1926 const TileSPR
*def
= find_spr(spr
);
1930 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "mtspr spr[%u], %s", spr
, reg_names
[srca
]);
1931 return TILEGX_EXCP_OPCODE_UNKNOWN
;
1934 tsrca
= load_gr(dc
, srca
);
1936 def
->put(cpu_env
, tsrca
);
1938 tcg_gen_st_tl(tsrca
, cpu_env
, def
->offset
);
1940 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "mtspr %s, %s", def
->name
, reg_names
[srca
]);
1941 return TILEGX_EXCP_NONE
;
1944 static TileExcp
gen_mfspr_x1(DisasContext
*dc
, unsigned dest
, unsigned spr
)
1946 const TileSPR
*def
= find_spr(spr
);
1950 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "mtspr %s, spr[%u]", reg_names
[dest
], spr
);
1951 return TILEGX_EXCP_OPCODE_UNKNOWN
;
1954 tdest
= dest_gr(dc
, dest
);
1956 def
->get(tdest
, cpu_env
);
1958 tcg_gen_ld_tl(tdest
, cpu_env
, def
->offset
);
1960 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "mfspr %s, %s", reg_names
[dest
], def
->name
);
1961 return TILEGX_EXCP_NONE
;
1964 static TileExcp
decode_y0(DisasContext
*dc
, tilegx_bundle_bits bundle
)
1966 unsigned opc
= get_Opcode_Y0(bundle
);
1967 unsigned ext
= get_RRROpcodeExtension_Y0(bundle
);
1968 unsigned dest
= get_Dest_Y0(bundle
);
1969 unsigned srca
= get_SrcA_Y0(bundle
);
1974 case RRR_1_OPCODE_Y0
:
1975 if (ext
== UNARY_RRR_1_OPCODE_Y0
) {
1976 ext
= get_UnaryOpcodeExtension_Y0(bundle
);
1977 return gen_rr_opcode(dc
, OE(opc
, ext
, Y0
), dest
, srca
, bundle
);
1980 case RRR_0_OPCODE_Y0
:
1981 case RRR_2_OPCODE_Y0
:
1982 case RRR_3_OPCODE_Y0
:
1983 case RRR_4_OPCODE_Y0
:
1984 case RRR_5_OPCODE_Y0
:
1985 case RRR_6_OPCODE_Y0
:
1986 case RRR_7_OPCODE_Y0
:
1987 case RRR_8_OPCODE_Y0
:
1988 case RRR_9_OPCODE_Y0
:
1989 srcb
= get_SrcB_Y0(bundle
);
1990 return gen_rrr_opcode(dc
, OE(opc
, ext
, Y0
), dest
, srca
, srcb
);
1992 case SHIFT_OPCODE_Y0
:
1993 ext
= get_ShiftOpcodeExtension_Y0(bundle
);
1994 imm
= get_ShAmt_Y0(bundle
);
1995 return gen_rri_opcode(dc
, OE(opc
, ext
, Y0
), dest
, srca
, imm
);
1997 case ADDI_OPCODE_Y0
:
1998 case ADDXI_OPCODE_Y0
:
1999 case ANDI_OPCODE_Y0
:
2000 case CMPEQI_OPCODE_Y0
:
2001 case CMPLTSI_OPCODE_Y0
:
2002 imm
= (int8_t)get_Imm8_Y0(bundle
);
2003 return gen_rri_opcode(dc
, OE(opc
, 0, Y0
), dest
, srca
, imm
);
2006 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
2010 static TileExcp
decode_y1(DisasContext
*dc
, tilegx_bundle_bits bundle
)
2012 unsigned opc
= get_Opcode_Y1(bundle
);
2013 unsigned ext
= get_RRROpcodeExtension_Y1(bundle
);
2014 unsigned dest
= get_Dest_Y1(bundle
);
2015 unsigned srca
= get_SrcA_Y1(bundle
);
2019 switch (get_Opcode_Y1(bundle
)) {
2020 case RRR_1_OPCODE_Y1
:
2021 if (ext
== UNARY_RRR_1_OPCODE_Y0
) {
2022 ext
= get_UnaryOpcodeExtension_Y1(bundle
);
2023 return gen_rr_opcode(dc
, OE(opc
, ext
, Y1
), dest
, srca
, bundle
);
2026 case RRR_0_OPCODE_Y1
:
2027 case RRR_2_OPCODE_Y1
:
2028 case RRR_3_OPCODE_Y1
:
2029 case RRR_4_OPCODE_Y1
:
2030 case RRR_5_OPCODE_Y1
:
2031 case RRR_6_OPCODE_Y1
:
2032 case RRR_7_OPCODE_Y1
:
2033 srcb
= get_SrcB_Y1(bundle
);
2034 return gen_rrr_opcode(dc
, OE(opc
, ext
, Y1
), dest
, srca
, srcb
);
2036 case SHIFT_OPCODE_Y1
:
2037 ext
= get_ShiftOpcodeExtension_Y1(bundle
);
2038 imm
= get_ShAmt_Y1(bundle
);
2039 return gen_rri_opcode(dc
, OE(opc
, ext
, Y1
), dest
, srca
, imm
);
2041 case ADDI_OPCODE_Y1
:
2042 case ADDXI_OPCODE_Y1
:
2043 case ANDI_OPCODE_Y1
:
2044 case CMPEQI_OPCODE_Y1
:
2045 case CMPLTSI_OPCODE_Y1
:
2046 imm
= (int8_t)get_Imm8_Y1(bundle
);
2047 return gen_rri_opcode(dc
, OE(opc
, 0, Y1
), dest
, srca
, imm
);
2050 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
2054 static TileExcp
decode_y2(DisasContext
*dc
, tilegx_bundle_bits bundle
)
2056 unsigned mode
= get_Mode(bundle
);
2057 unsigned opc
= get_Opcode_Y2(bundle
);
2058 unsigned srca
= get_SrcA_Y2(bundle
);
2059 unsigned srcbdest
= get_SrcBDest_Y2(bundle
);
2060 const char *mnemonic
;
2063 switch (OEY2(opc
, mode
)) {
2064 case OEY2(LD1S_OPCODE_Y2
, MODE_OPCODE_YA2
):
2068 case OEY2(LD1U_OPCODE_Y2
, MODE_OPCODE_YA2
):
2072 case OEY2(LD2S_OPCODE_Y2
, MODE_OPCODE_YA2
):
2076 case OEY2(LD2U_OPCODE_Y2
, MODE_OPCODE_YA2
):
2080 case OEY2(LD4S_OPCODE_Y2
, MODE_OPCODE_YB2
):
2084 case OEY2(LD4U_OPCODE_Y2
, MODE_OPCODE_YB2
):
2088 case OEY2(LD_OPCODE_Y2
, MODE_OPCODE_YB2
):
2092 tcg_gen_qemu_ld_tl(dest_gr(dc
, srcbdest
), load_gr(dc
, srca
),
2094 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s", mnemonic
,
2095 reg_names
[srcbdest
], reg_names
[srca
]);
2096 return TILEGX_EXCP_NONE
;
2098 case OEY2(ST1_OPCODE_Y2
, MODE_OPCODE_YC2
):
2099 return gen_st_opcode(dc
, 0, srca
, srcbdest
, MO_UB
, "st1");
2100 case OEY2(ST2_OPCODE_Y2
, MODE_OPCODE_YC2
):
2101 return gen_st_opcode(dc
, 0, srca
, srcbdest
, MO_TEUW
, "st2");
2102 case OEY2(ST4_OPCODE_Y2
, MODE_OPCODE_YC2
):
2103 return gen_st_opcode(dc
, 0, srca
, srcbdest
, MO_TEUL
, "st4");
2104 case OEY2(ST_OPCODE_Y2
, MODE_OPCODE_YC2
):
2105 return gen_st_opcode(dc
, 0, srca
, srcbdest
, MO_TEQ
, "st");
2108 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
2112 static TileExcp
decode_x0(DisasContext
*dc
, tilegx_bundle_bits bundle
)
2114 unsigned opc
= get_Opcode_X0(bundle
);
2115 unsigned dest
= get_Dest_X0(bundle
);
2116 unsigned srca
= get_SrcA_X0(bundle
);
2117 unsigned ext
, srcb
, bfs
, bfe
;
2121 case RRR_0_OPCODE_X0
:
2122 ext
= get_RRROpcodeExtension_X0(bundle
);
2123 if (ext
== UNARY_RRR_0_OPCODE_X0
) {
2124 ext
= get_UnaryOpcodeExtension_X0(bundle
);
2125 return gen_rr_opcode(dc
, OE(opc
, ext
, X0
), dest
, srca
, bundle
);
2127 srcb
= get_SrcB_X0(bundle
);
2128 return gen_rrr_opcode(dc
, OE(opc
, ext
, X0
), dest
, srca
, srcb
);
2130 case SHIFT_OPCODE_X0
:
2131 ext
= get_ShiftOpcodeExtension_X0(bundle
);
2132 imm
= get_ShAmt_X0(bundle
);
2133 return gen_rri_opcode(dc
, OE(opc
, ext
, X0
), dest
, srca
, imm
);
2135 case IMM8_OPCODE_X0
:
2136 ext
= get_Imm8OpcodeExtension_X0(bundle
);
2137 imm
= (int8_t)get_Imm8_X0(bundle
);
2138 return gen_rri_opcode(dc
, OE(opc
, ext
, X0
), dest
, srca
, imm
);
2141 ext
= get_BFOpcodeExtension_X0(bundle
);
2142 bfs
= get_BFStart_X0(bundle
);
2143 bfe
= get_BFEnd_X0(bundle
);
2144 return gen_bf_opcode_x0(dc
, ext
, dest
, srca
, bfs
, bfe
);
2146 case ADDLI_OPCODE_X0
:
2147 case SHL16INSLI_OPCODE_X0
:
2148 case ADDXLI_OPCODE_X0
:
2149 imm
= (int16_t)get_Imm16_X0(bundle
);
2150 return gen_rri_opcode(dc
, OE(opc
, 0, X0
), dest
, srca
, imm
);
2153 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
2157 static TileExcp
decode_x1(DisasContext
*dc
, tilegx_bundle_bits bundle
)
2159 unsigned opc
= get_Opcode_X1(bundle
);
2160 unsigned dest
= get_Dest_X1(bundle
);
2161 unsigned srca
= get_SrcA_X1(bundle
);
2166 case RRR_0_OPCODE_X1
:
2167 ext
= get_RRROpcodeExtension_X1(bundle
);
2168 srcb
= get_SrcB_X1(bundle
);
2170 case UNARY_RRR_0_OPCODE_X1
:
2171 ext
= get_UnaryOpcodeExtension_X1(bundle
);
2172 return gen_rr_opcode(dc
, OE(opc
, ext
, X1
), dest
, srca
, bundle
);
2173 case ST1_RRR_0_OPCODE_X1
:
2174 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_UB
, "st1");
2175 case ST2_RRR_0_OPCODE_X1
:
2176 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEUW
, "st2");
2177 case ST4_RRR_0_OPCODE_X1
:
2178 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEUL
, "st4");
2179 case STNT1_RRR_0_OPCODE_X1
:
2180 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_UB
, "stnt1");
2181 case STNT2_RRR_0_OPCODE_X1
:
2182 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEUW
, "stnt2");
2183 case STNT4_RRR_0_OPCODE_X1
:
2184 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEUL
, "stnt4");
2185 case STNT_RRR_0_OPCODE_X1
:
2186 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEQ
, "stnt");
2187 case ST_RRR_0_OPCODE_X1
:
2188 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEQ
, "st");
2190 return gen_rrr_opcode(dc
, OE(opc
, ext
, X1
), dest
, srca
, srcb
);
2192 case SHIFT_OPCODE_X1
:
2193 ext
= get_ShiftOpcodeExtension_X1(bundle
);
2194 imm
= get_ShAmt_X1(bundle
);
2195 return gen_rri_opcode(dc
, OE(opc
, ext
, X1
), dest
, srca
, imm
);
2197 case IMM8_OPCODE_X1
:
2198 ext
= get_Imm8OpcodeExtension_X1(bundle
);
2199 imm
= (int8_t)get_Dest_Imm8_X1(bundle
);
2200 srcb
= get_SrcB_X1(bundle
);
2202 case ST1_ADD_IMM8_OPCODE_X1
:
2203 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_UB
, "st1_add");
2204 case ST2_ADD_IMM8_OPCODE_X1
:
2205 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEUW
, "st2_add");
2206 case ST4_ADD_IMM8_OPCODE_X1
:
2207 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEUL
, "st4_add");
2208 case STNT1_ADD_IMM8_OPCODE_X1
:
2209 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_UB
, "stnt1_add");
2210 case STNT2_ADD_IMM8_OPCODE_X1
:
2211 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEUW
, "stnt2_add");
2212 case STNT4_ADD_IMM8_OPCODE_X1
:
2213 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEUL
, "stnt4_add");
2214 case STNT_ADD_IMM8_OPCODE_X1
:
2215 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEQ
, "stnt_add");
2216 case ST_ADD_IMM8_OPCODE_X1
:
2217 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEQ
, "st_add");
2218 case MFSPR_IMM8_OPCODE_X1
:
2219 return gen_mfspr_x1(dc
, dest
, get_MF_Imm14_X1(bundle
));
2220 case MTSPR_IMM8_OPCODE_X1
:
2221 return gen_mtspr_x1(dc
, get_MT_Imm14_X1(bundle
), srca
);
2223 imm
= (int8_t)get_Imm8_X1(bundle
);
2224 return gen_rri_opcode(dc
, OE(opc
, ext
, X1
), dest
, srca
, imm
);
2226 case BRANCH_OPCODE_X1
:
2227 ext
= get_BrType_X1(bundle
);
2228 imm
= sextract32(get_BrOff_X1(bundle
), 0, 17);
2229 return gen_branch_opcode_x1(dc
, ext
, srca
, imm
);
2231 case JUMP_OPCODE_X1
:
2232 ext
= get_JumpOpcodeExtension_X1(bundle
);
2233 imm
= sextract32(get_JumpOff_X1(bundle
), 0, 27);
2234 return gen_jump_opcode_x1(dc
, ext
, imm
);
2236 case ADDLI_OPCODE_X1
:
2237 case SHL16INSLI_OPCODE_X1
:
2238 case ADDXLI_OPCODE_X1
:
2239 imm
= (int16_t)get_Imm16_X1(bundle
);
2240 return gen_rri_opcode(dc
, OE(opc
, 0, X1
), dest
, srca
, imm
);
2243 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
2247 static void notice_excp(DisasContext
*dc
, uint64_t bundle
,
2248 const char *type
, TileExcp excp
)
2250 if (likely(excp
== TILEGX_EXCP_NONE
)) {
2253 gen_exception(dc
, excp
);
2254 if (excp
== TILEGX_EXCP_OPCODE_UNIMPLEMENTED
) {
2255 qemu_log_mask(LOG_UNIMP
, "UNIMP %s, [" FMT64X
"]\n", type
, bundle
);
2259 static void translate_one_bundle(DisasContext
*dc
, uint64_t bundle
)
2263 for (i
= 0; i
< ARRAY_SIZE(dc
->wb
); i
++) {
2264 DisasContextTemp
*wb
= &dc
->wb
[i
];
2265 wb
->reg
= TILEGX_R_NOREG
;
2266 TCGV_UNUSED_I64(wb
->val
);
2270 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
2271 tcg_gen_debug_insn_start(dc
->pc
);
2274 qemu_log_mask(CPU_LOG_TB_IN_ASM
, " %" PRIx64
": { ", dc
->pc
);
2275 if (get_Mode(bundle
)) {
2276 notice_excp(dc
, bundle
, "y0", decode_y0(dc
, bundle
));
2277 qemu_log_mask(CPU_LOG_TB_IN_ASM
, " ; ");
2278 notice_excp(dc
, bundle
, "y1", decode_y1(dc
, bundle
));
2279 qemu_log_mask(CPU_LOG_TB_IN_ASM
, " ; ");
2280 notice_excp(dc
, bundle
, "y2", decode_y2(dc
, bundle
));
2282 notice_excp(dc
, bundle
, "x0", decode_x0(dc
, bundle
));
2283 qemu_log_mask(CPU_LOG_TB_IN_ASM
, " ; ");
2284 notice_excp(dc
, bundle
, "x1", decode_x1(dc
, bundle
));
2286 qemu_log_mask(CPU_LOG_TB_IN_ASM
, " }\n");
2288 for (i
= dc
->num_wb
- 1; i
>= 0; --i
) {
2289 DisasContextTemp
*wb
= &dc
->wb
[i
];
2290 if (wb
->reg
< TILEGX_R_COUNT
) {
2291 tcg_gen_mov_i64(cpu_regs
[wb
->reg
], wb
->val
);
2293 tcg_temp_free_i64(wb
->val
);
2296 if (dc
->jmp
.cond
!= TCG_COND_NEVER
) {
2297 if (dc
->jmp
.cond
== TCG_COND_ALWAYS
) {
2298 tcg_gen_mov_i64(cpu_pc
, dc
->jmp
.dest
);
2300 TCGv next
= tcg_const_i64(dc
->pc
+ TILEGX_BUNDLE_SIZE_IN_BYTES
);
2301 tcg_gen_movcond_i64(dc
->jmp
.cond
, cpu_pc
,
2302 dc
->jmp
.val1
, load_zero(dc
),
2303 dc
->jmp
.dest
, next
);
2304 tcg_temp_free_i64(dc
->jmp
.val1
);
2305 tcg_temp_free_i64(next
);
2307 tcg_temp_free_i64(dc
->jmp
.dest
);
2310 } else if (dc
->atomic_excp
!= TILEGX_EXCP_NONE
) {
2311 gen_exception(dc
, dc
->atomic_excp
);
2315 static inline void gen_intermediate_code_internal(TileGXCPU
*cpu
,
2316 TranslationBlock
*tb
,
2320 DisasContext
*dc
= &ctx
;
2321 CPUState
*cs
= CPU(cpu
);
2322 CPUTLGState
*env
= &cpu
->env
;
2323 uint64_t pc_start
= tb
->pc
;
2324 uint64_t next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2327 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2331 dc
->exit_tb
= false;
2332 dc
->atomic_excp
= TILEGX_EXCP_NONE
;
2333 dc
->jmp
.cond
= TCG_COND_NEVER
;
2334 TCGV_UNUSED_I64(dc
->jmp
.dest
);
2335 TCGV_UNUSED_I64(dc
->jmp
.val1
);
2336 TCGV_UNUSED_I64(dc
->zero
);
2338 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
2339 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
2342 max_insns
= CF_COUNT_MASK
;
2344 if (cs
->singlestep_enabled
|| singlestep
) {
2351 j
= tcg_op_buf_count();
2355 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2358 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
2359 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
2360 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
2362 translate_one_bundle(dc
, cpu_ldq_data(env
, dc
->pc
));
2365 /* PC updated and EXIT_TB/GOTO_TB/exception emitted. */
2368 dc
->pc
+= TILEGX_BUNDLE_SIZE_IN_BYTES
;
2369 if (++num_insns
>= max_insns
2370 || dc
->pc
>= next_page_start
2371 || tcg_op_buf_full()) {
2372 /* Ending the TB due to TB size or page boundary. Set PC. */
2373 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
2379 gen_tb_end(tb
, num_insns
);
2381 j
= tcg_op_buf_count();
2384 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2387 tb
->size
= dc
->pc
- pc_start
;
2388 tb
->icount
= num_insns
;
2391 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "\n");
2394 void gen_intermediate_code(CPUTLGState
*env
, struct TranslationBlock
*tb
)
2396 gen_intermediate_code_internal(tilegx_env_get_cpu(env
), tb
, false);
2399 void gen_intermediate_code_pc(CPUTLGState
*env
, struct TranslationBlock
*tb
)
2401 gen_intermediate_code_internal(tilegx_env_get_cpu(env
), tb
, true);
2404 void restore_state_to_opc(CPUTLGState
*env
, TranslationBlock
*tb
, int pc_pos
)
2406 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];
2409 void tilegx_tcg_init(void)
2413 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
2414 cpu_pc
= tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUTLGState
, pc
), "pc");
2415 for (i
= 0; i
< TILEGX_R_COUNT
; i
++) {
2416 cpu_regs
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
2417 offsetof(CPUTLGState
, regs
[i
]),