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>
21 #include "qemu/osdep.h"
24 #include "disas/disas.h"
26 #include "exec/cpu_ldst.h"
27 #include "linux-user/syscall_defs.h"
29 #include "opcode_tilegx.h"
30 #include "spr_def_64.h"
32 #define FMT64X "%016" PRIx64
34 static TCGv_ptr cpu_env
;
36 static TCGv cpu_regs
[TILEGX_R_COUNT
];
38 static const char * const reg_names
[64] = {
39 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
40 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
41 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
42 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
43 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
44 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
45 "r48", "r49", "r50", "r51", "bp", "tp", "sp", "lr",
46 "sn", "idn0", "idn1", "udn0", "udn1", "udn2", "udn2", "zero"
49 /* Modified registers are cached in temporaries until the end of the bundle. */
55 #define MAX_WRITEBACK 4
57 /* This is the state at translation time. */
59 uint64_t pc
; /* Current pc */
61 TCGv zero
; /* For zero register */
63 DisasContextTemp wb
[MAX_WRITEBACK
];
70 TCGCond cond
; /* branch condition */
71 TCGv dest
; /* branch destination */
72 TCGv val1
; /* value to be compared against zero, for cond */
73 } jmp
; /* Jump object, only once in each TB block */
76 #include "exec/gen-icount.h"
78 /* Differentiate the various pipe encodings. */
84 /* Remerge the base opcode and extension fields for switching.
85 The X opcode fields are 3 bits; Y0/Y1 opcode fields are 4 bits;
86 Y2 opcode field is 2 bits. */
87 #define OE(OP, EXT, XY) (TY_##XY + OP * 4 + EXT * 64)
89 /* Similar, but for Y2 only. */
90 #define OEY2(OP, MODE) (OP + MODE * 4)
92 /* Similar, but make sure opcode names match up. */
93 #define OE_RR_X0(E) OE(RRR_0_OPCODE_X0, E##_UNARY_OPCODE_X0, X0)
94 #define OE_RR_X1(E) OE(RRR_0_OPCODE_X1, E##_UNARY_OPCODE_X1, X1)
95 #define OE_RR_Y0(E) OE(RRR_1_OPCODE_Y0, E##_UNARY_OPCODE_Y0, Y0)
96 #define OE_RR_Y1(E) OE(RRR_1_OPCODE_Y1, E##_UNARY_OPCODE_Y1, Y1)
97 #define OE_RRR(E,N,XY) OE(RRR_##N##_OPCODE_##XY, E##_RRR_##N##_OPCODE_##XY, XY)
98 #define OE_IM(E,XY) OE(IMM8_OPCODE_##XY, E##_IMM8_OPCODE_##XY, XY)
99 #define OE_SH(E,XY) OE(SHIFT_OPCODE_##XY, E##_SHIFT_OPCODE_##XY, XY)
101 #define V1_IMM(X) (((X) & 0xff) * 0x0101010101010101ull)
102 #define V2_IMM(X) (((X) & 0xffff) * 0x0001000100010001ull)
105 static void gen_exception(DisasContext
*dc
, TileExcp num
)
109 tcg_gen_movi_tl(cpu_pc
, dc
->pc
+ TILEGX_BUNDLE_SIZE_IN_BYTES
);
111 tmp
= tcg_const_i32(num
);
112 gen_helper_exception(cpu_env
, tmp
);
113 tcg_temp_free_i32(tmp
);
117 static bool check_gr(DisasContext
*dc
, uint8_t reg
)
119 if (likely(reg
< TILEGX_R_COUNT
)) {
129 gen_exception(dc
, TILEGX_EXCP_REG_IDN_ACCESS
);
135 gen_exception(dc
, TILEGX_EXCP_REG_UDN_ACCESS
);
138 g_assert_not_reached();
143 static TCGv
load_zero(DisasContext
*dc
)
145 if (TCGV_IS_UNUSED_I64(dc
->zero
)) {
146 dc
->zero
= tcg_const_i64(0);
151 static TCGv
load_gr(DisasContext
*dc
, unsigned reg
)
153 if (check_gr(dc
, reg
)) {
154 return cpu_regs
[reg
];
156 return load_zero(dc
);
159 static TCGv
dest_gr(DisasContext
*dc
, unsigned reg
)
163 /* Skip the result, mark the exception if necessary, and continue */
168 return dc
->wb
[n
].val
= tcg_temp_new_i64();
171 static void gen_saturate_op(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
,
172 void (*operate
)(TCGv
, TCGv
, TCGv
))
174 TCGv t0
= tcg_temp_new();
176 tcg_gen_ext32s_tl(tdest
, tsrca
);
177 tcg_gen_ext32s_tl(t0
, tsrcb
);
178 operate(tdest
, tdest
, t0
);
180 tcg_gen_movi_tl(t0
, 0x7fffffff);
181 tcg_gen_movcond_tl(TCG_COND_GT
, tdest
, tdest
, t0
, t0
, tdest
);
182 tcg_gen_movi_tl(t0
, -0x80000000LL
);
183 tcg_gen_movcond_tl(TCG_COND_LT
, tdest
, tdest
, t0
, t0
, tdest
);
188 static void gen_atomic_excp(DisasContext
*dc
, unsigned dest
, TCGv tdest
,
189 TCGv tsrca
, TCGv tsrcb
, TileExcp excp
)
191 #ifdef CONFIG_USER_ONLY
194 tcg_gen_st_tl(tsrca
, cpu_env
, offsetof(CPUTLGState
, atomic_srca
));
195 tcg_gen_st_tl(tsrcb
, cpu_env
, offsetof(CPUTLGState
, atomic_srcb
));
196 t
= tcg_const_i32(dest
);
197 tcg_gen_st_i32(t
, cpu_env
, offsetof(CPUTLGState
, atomic_dstr
));
198 tcg_temp_free_i32(t
);
200 /* We're going to write the real result in the exception. But in
201 the meantime we've already created a writeback register, and
202 we don't want that to remain uninitialized. */
203 tcg_gen_movi_tl(tdest
, 0);
205 /* Note that we need to delay issuing the exception that implements
206 the atomic operation until after writing back the results of the
207 instruction occupying the X0 pipe. */
208 dc
->atomic_excp
= excp
;
210 gen_exception(dc
, TILEGX_EXCP_OPCODE_UNIMPLEMENTED
);
214 /* Shift the 128-bit value TSRCA:TSRCD right by the number of bytes
215 specified by the bottom 3 bits of TSRCB, and set TDEST to the
216 low 64 bits of the resulting value. */
217 static void gen_dblalign(TCGv tdest
, TCGv tsrcd
, TCGv tsrca
, TCGv tsrcb
)
219 TCGv t0
= tcg_temp_new();
221 tcg_gen_andi_tl(t0
, tsrcb
, 7);
222 tcg_gen_shli_tl(t0
, t0
, 3);
223 tcg_gen_shr_tl(tdest
, tsrcd
, t0
);
225 /* We want to do "t0 = tsrca << (64 - t0)". Two's complement
226 arithmetic on a 6-bit field tells us that 64 - t0 is equal
227 to (t0 ^ 63) + 1. So we can do the shift in two parts,
228 neither of which will be an invalid shift by 64. */
229 tcg_gen_xori_tl(t0
, t0
, 63);
230 tcg_gen_shl_tl(t0
, tsrca
, t0
);
231 tcg_gen_shli_tl(t0
, t0
, 1);
232 tcg_gen_or_tl(tdest
, tdest
, t0
);
237 /* Similarly, except that the 128-bit value is TSRCA:TSRCB, and the
238 right shift is an immediate. */
239 static void gen_dblaligni(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
, int shr
)
241 TCGv t0
= tcg_temp_new();
243 tcg_gen_shri_tl(t0
, tsrcb
, shr
);
244 tcg_gen_shli_tl(tdest
, tsrca
, 64 - shr
);
245 tcg_gen_or_tl(tdest
, tdest
, t0
);
254 static void gen_ext_half(TCGv d
, TCGv s
, MulHalf h
)
258 tcg_gen_ext32u_tl(d
, s
);
261 tcg_gen_ext32s_tl(d
, s
);
264 tcg_gen_shri_tl(d
, s
, 32);
267 tcg_gen_sari_tl(d
, s
, 32);
272 static void gen_mul_half(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
,
273 MulHalf ha
, MulHalf hb
)
275 TCGv t
= tcg_temp_new();
276 gen_ext_half(t
, tsrca
, ha
);
277 gen_ext_half(tdest
, tsrcb
, hb
);
278 tcg_gen_mul_tl(tdest
, tdest
, t
);
282 static void gen_cmul2(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
, int sh
, int rd
)
284 TCGv_i32 tsh
= tcg_const_i32(sh
);
285 TCGv_i32 trd
= tcg_const_i32(rd
);
286 gen_helper_cmul2(tdest
, tsrca
, tsrcb
, tsh
, trd
);
287 tcg_temp_free_i32(tsh
);
288 tcg_temp_free_i32(trd
);
291 static TileExcp
gen_st_opcode(DisasContext
*dc
, unsigned dest
, unsigned srca
,
292 unsigned srcb
, TCGMemOp memop
, const char *name
)
295 return TILEGX_EXCP_OPCODE_UNKNOWN
;
298 tcg_gen_qemu_st_tl(load_gr(dc
, srcb
), load_gr(dc
, srca
),
301 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s", name
,
302 reg_names
[srca
], reg_names
[srcb
]);
303 return TILEGX_EXCP_NONE
;
306 static TileExcp
gen_st_add_opcode(DisasContext
*dc
, unsigned srca
, unsigned srcb
,
307 int imm
, TCGMemOp memop
, const char *name
)
309 TCGv tsrca
= load_gr(dc
, srca
);
310 TCGv tsrcb
= load_gr(dc
, srcb
);
312 tcg_gen_qemu_st_tl(tsrcb
, tsrca
, dc
->mmuidx
, memop
);
313 tcg_gen_addi_tl(dest_gr(dc
, srca
), tsrca
, imm
);
315 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s, %d", name
,
316 reg_names
[srca
], reg_names
[srcb
], imm
);
317 return TILEGX_EXCP_NONE
;
320 /* Equality comparison with zero can be done quickly and efficiently. */
321 static void gen_v1cmpeq0(TCGv v
)
323 TCGv m
= tcg_const_tl(V1_IMM(0x7f));
324 TCGv c
= tcg_temp_new();
326 /* ~(((v & m) + m) | m | v). Sets the msb for each byte == 0. */
327 tcg_gen_and_tl(c
, v
, m
);
328 tcg_gen_add_tl(c
, c
, m
);
329 tcg_gen_or_tl(c
, c
, m
);
330 tcg_gen_nor_tl(c
, c
, v
);
333 /* Shift the msb down to form the lsb boolean result. */
334 tcg_gen_shri_tl(v
, c
, 7);
338 static void gen_v1cmpne0(TCGv v
)
340 TCGv m
= tcg_const_tl(V1_IMM(0x7f));
341 TCGv c
= tcg_temp_new();
343 /* (((v & m) + m) | v) & ~m. Sets the msb for each byte != 0. */
344 tcg_gen_and_tl(c
, v
, m
);
345 tcg_gen_add_tl(c
, c
, m
);
346 tcg_gen_or_tl(c
, c
, v
);
347 tcg_gen_andc_tl(c
, c
, m
);
350 /* Shift the msb down to form the lsb boolean result. */
351 tcg_gen_shri_tl(v
, c
, 7);
355 /* Vector addition can be performed via arithmetic plus masking. It is
356 efficient this way only for 4 or more elements. */
357 static void gen_v12add(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
, uint64_t sign
)
359 TCGv tmask
= tcg_const_tl(~sign
);
360 TCGv t0
= tcg_temp_new();
361 TCGv t1
= tcg_temp_new();
363 /* ((a & ~sign) + (b & ~sign)) ^ ((a ^ b) & sign). */
364 tcg_gen_and_tl(t0
, tsrca
, tmask
);
365 tcg_gen_and_tl(t1
, tsrcb
, tmask
);
366 tcg_gen_add_tl(tdest
, t0
, t1
);
367 tcg_gen_xor_tl(t0
, tsrca
, tsrcb
);
368 tcg_gen_andc_tl(t0
, t0
, tmask
);
369 tcg_gen_xor_tl(tdest
, tdest
, t0
);
373 tcg_temp_free(tmask
);
376 /* Similarly for vector subtraction. */
377 static void gen_v12sub(TCGv tdest
, TCGv tsrca
, TCGv tsrcb
, uint64_t sign
)
379 TCGv tsign
= tcg_const_tl(sign
);
380 TCGv t0
= tcg_temp_new();
381 TCGv t1
= tcg_temp_new();
383 /* ((a | sign) - (b & ~sign)) ^ ((a ^ ~b) & sign). */
384 tcg_gen_or_tl(t0
, tsrca
, tsign
);
385 tcg_gen_andc_tl(t1
, tsrcb
, tsign
);
386 tcg_gen_sub_tl(tdest
, t0
, t1
);
387 tcg_gen_eqv_tl(t0
, tsrca
, tsrcb
);
388 tcg_gen_and_tl(t0
, t0
, tsign
);
389 tcg_gen_xor_tl(tdest
, tdest
, t0
);
393 tcg_temp_free(tsign
);
396 static void gen_v4sh(TCGv d64
, TCGv a64
, TCGv b64
,
397 void (*generate
)(TCGv_i32
, TCGv_i32
, TCGv_i32
))
399 TCGv_i32 al
= tcg_temp_new_i32();
400 TCGv_i32 ah
= tcg_temp_new_i32();
401 TCGv_i32 bl
= tcg_temp_new_i32();
403 tcg_gen_extr_i64_i32(al
, ah
, a64
);
404 tcg_gen_extrl_i64_i32(bl
, b64
);
405 tcg_gen_andi_i32(bl
, bl
, 31);
406 generate(al
, al
, bl
);
407 generate(ah
, ah
, bl
);
408 tcg_gen_concat_i32_i64(d64
, al
, ah
);
410 tcg_temp_free_i32(al
);
411 tcg_temp_free_i32(ah
);
412 tcg_temp_free_i32(bl
);
415 static void gen_v4op(TCGv d64
, TCGv a64
, TCGv b64
,
416 void (*generate
)(TCGv_i32
, TCGv_i32
, TCGv_i32
))
418 TCGv_i32 al
= tcg_temp_new_i32();
419 TCGv_i32 ah
= tcg_temp_new_i32();
420 TCGv_i32 bl
= tcg_temp_new_i32();
421 TCGv_i32 bh
= tcg_temp_new_i32();
423 tcg_gen_extr_i64_i32(al
, ah
, a64
);
424 tcg_gen_extr_i64_i32(bl
, bh
, b64
);
425 generate(al
, al
, bl
);
426 generate(ah
, ah
, bh
);
427 tcg_gen_concat_i32_i64(d64
, al
, ah
);
429 tcg_temp_free_i32(al
);
430 tcg_temp_free_i32(ah
);
431 tcg_temp_free_i32(bl
);
432 tcg_temp_free_i32(bh
);
435 static TileExcp
gen_signal(DisasContext
*dc
, int signo
, int sigcode
,
436 const char *mnemonic
)
438 TCGv_i32 t0
= tcg_const_i32(signo
);
439 TCGv_i32 t1
= tcg_const_i32(sigcode
);
441 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUTLGState
, signo
));
442 tcg_gen_st_i32(t1
, cpu_env
, offsetof(CPUTLGState
, sigcode
));
444 tcg_temp_free_i32(t1
);
445 tcg_temp_free_i32(t0
);
447 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s", mnemonic
);
448 return TILEGX_EXCP_SIGNAL
;
451 static bool parse_from_addli(uint64_t bundle
, int *signo
, int *sigcode
)
455 if ((get_Opcode_X0(bundle
) != ADDLI_OPCODE_X0
)
456 || (get_Dest_X0(bundle
) != TILEGX_R_ZERO
)
457 || (get_SrcA_X0(bundle
) != TILEGX_R_ZERO
)) {
461 imm
= get_Imm16_X0(bundle
);
463 *sigcode
= (imm
>> 6) & 0xf;
465 /* ??? The linux kernel validates both signo and the sigcode vs the
466 known max for each signal. Don't bother here. */
470 static TileExcp
gen_specill(DisasContext
*dc
, unsigned dest
, unsigned srca
,
473 const char *mnemonic
;
477 if (dest
== 0x1c && srca
== 0x25) {
478 signo
= TARGET_SIGTRAP
;
479 sigcode
= TARGET_TRAP_BRKPT
;
481 } else if (dest
== 0x1d && srca
== 0x25
482 && parse_from_addli(bundle
, &signo
, &sigcode
)) {
485 signo
= TARGET_SIGILL
;
486 sigcode
= TARGET_ILL_ILLOPC
;
490 return gen_signal(dc
, signo
, sigcode
, mnemonic
);
493 static TileExcp
gen_rr_opcode(DisasContext
*dc
, unsigned opext
,
494 unsigned dest
, unsigned srca
, uint64_t bundle
)
497 const char *mnemonic
;
499 TileExcp ret
= TILEGX_EXCP_NONE
;
500 bool prefetch_nofault
= false;
502 /* Eliminate instructions with no output before doing anything else. */
516 case OE_RR_X1(DRAIN
):
519 case OE_RR_X1(FLUSHWB
):
520 mnemonic
= "flushwb";
523 return gen_specill(dc
, dest
, srca
, bundle
);
525 return gen_signal(dc
, TARGET_SIGILL
, TARGET_ILL_ILLOPC
, "ill");
530 /* ??? This should yield, especially in system mode. */
534 gen_helper_ext01_ics(cpu_env
);
535 dc
->jmp
.cond
= TCG_COND_ALWAYS
;
536 dc
->jmp
.dest
= tcg_temp_new();
537 tcg_gen_ld_tl(dc
->jmp
.dest
, cpu_env
,
538 offsetof(CPUTLGState
, spregs
[TILEGX_SPR_EX_CONTEXT_0_0
]));
539 tcg_gen_andi_tl(dc
->jmp
.dest
, dc
->jmp
.dest
, ~7);
542 case OE_RR_X1(SWINT0
):
543 case OE_RR_X1(SWINT2
):
544 case OE_RR_X1(SWINT3
):
545 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
546 case OE_RR_X1(SWINT1
):
547 ret
= TILEGX_EXCP_SYSCALL
;
551 return TILEGX_EXCP_OPCODE_UNKNOWN
;
553 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s", mnemonic
);
556 case OE_RR_X1(DTLBPR
):
557 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
561 case OE_RR_X1(FLUSH
):
581 case OE_RR_X1(JALRP
):
582 case OE_RR_Y1(JALRP
):
589 tcg_gen_movi_tl(dest_gr(dc
, TILEGX_R_LR
),
590 dc
->pc
+ TILEGX_BUNDLE_SIZE_IN_BYTES
);
592 dc
->jmp
.cond
= TCG_COND_ALWAYS
;
593 dc
->jmp
.dest
= tcg_temp_new();
594 tcg_gen_andi_tl(dc
->jmp
.dest
, load_gr(dc
, srca
), ~7);
597 return TILEGX_EXCP_OPCODE_UNKNOWN
;
599 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s", mnemonic
, reg_names
[srca
]);
603 tdest
= dest_gr(dc
, dest
);
604 tsrca
= load_gr(dc
, srca
);
607 case OE_RR_X0(CNTLZ
):
608 case OE_RR_Y0(CNTLZ
):
609 gen_helper_cntlz(tdest
, tsrca
);
612 case OE_RR_X0(CNTTZ
):
613 case OE_RR_Y0(CNTTZ
):
614 gen_helper_cnttz(tdest
, tsrca
);
617 case OE_RR_X0(FSINGLE_PACK1
):
618 case OE_RR_Y0(FSINGLE_PACK1
):
619 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
622 mnemonic
= "ld1s"; /* prefetch_l1_fault */
626 mnemonic
= "ld1u"; /* prefetch, prefetch_l1 */
627 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
631 mnemonic
= "ld2s"; /* prefetch_l2_fault */
635 mnemonic
= "ld2u"; /* prefetch_l2 */
636 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
640 mnemonic
= "ld4s"; /* prefetch_l3_fault */
644 mnemonic
= "ld4u"; /* prefetch_l3 */
645 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
647 case OE_RR_X1(LDNT1S
):
651 case OE_RR_X1(LDNT1U
):
655 case OE_RR_X1(LDNT2S
):
659 case OE_RR_X1(LDNT2U
):
663 case OE_RR_X1(LDNT4S
):
667 case OE_RR_X1(LDNT4U
):
679 if (!prefetch_nofault
) {
680 tcg_gen_qemu_ld_tl(tdest
, tsrca
, dc
->mmuidx
, memop
);
684 tcg_gen_andi_tl(tdest
, tsrca
, ~7);
685 tcg_gen_qemu_ld_tl(tdest
, tdest
, dc
->mmuidx
, MO_TEQ
);
691 return TILEGX_EXCP_OPCODE_UNKNOWN
;
693 tcg_gen_movi_tl(tdest
, dc
->pc
+ TILEGX_BUNDLE_SIZE_IN_BYTES
);
698 gen_helper_pcnt(tdest
, tsrca
);
701 case OE_RR_X0(REVBITS
):
702 case OE_RR_Y0(REVBITS
):
703 gen_helper_revbits(tdest
, tsrca
);
704 mnemonic
= "revbits";
706 case OE_RR_X0(REVBYTES
):
707 case OE_RR_Y0(REVBYTES
):
708 tcg_gen_bswap64_tl(tdest
, tsrca
);
709 mnemonic
= "revbytes";
711 case OE_RR_X0(TBLIDXB0
):
712 case OE_RR_Y0(TBLIDXB0
):
713 tcg_gen_deposit_tl(tdest
, load_gr(dc
, dest
), tsrca
, 2, 8);
714 mnemonic
= "tblidxb0";
716 case OE_RR_X0(TBLIDXB1
):
717 case OE_RR_Y0(TBLIDXB1
):
718 tcg_gen_shri_tl(tdest
, tsrca
, 8);
719 tcg_gen_deposit_tl(tdest
, load_gr(dc
, dest
), tdest
, 2, 8);
720 mnemonic
= "tblidxb1";
722 case OE_RR_X0(TBLIDXB2
):
723 case OE_RR_Y0(TBLIDXB2
):
724 tcg_gen_shri_tl(tdest
, tsrca
, 16);
725 tcg_gen_deposit_tl(tdest
, load_gr(dc
, dest
), tdest
, 2, 8);
726 mnemonic
= "tblidxb2";
728 case OE_RR_X0(TBLIDXB3
):
729 case OE_RR_Y0(TBLIDXB3
):
730 tcg_gen_shri_tl(tdest
, tsrca
, 24);
731 tcg_gen_deposit_tl(tdest
, load_gr(dc
, dest
), tdest
, 2, 8);
732 mnemonic
= "tblidxb3";
735 return TILEGX_EXCP_OPCODE_UNKNOWN
;
738 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s", mnemonic
,
739 reg_names
[dest
], reg_names
[srca
]);
743 static TileExcp
gen_rrr_opcode(DisasContext
*dc
, unsigned opext
,
744 unsigned dest
, unsigned srca
, unsigned srcb
)
746 TCGv tdest
= dest_gr(dc
, dest
);
747 TCGv tsrca
= load_gr(dc
, srca
);
748 TCGv tsrcb
= load_gr(dc
, srcb
);
750 const char *mnemonic
;
753 case OE_RRR(ADDXSC
, 0, X0
):
754 case OE_RRR(ADDXSC
, 0, X1
):
755 gen_saturate_op(tdest
, tsrca
, tsrcb
, tcg_gen_add_tl
);
758 case OE_RRR(ADDX
, 0, X0
):
759 case OE_RRR(ADDX
, 0, X1
):
760 case OE_RRR(ADDX
, 0, Y0
):
761 case OE_RRR(ADDX
, 0, Y1
):
762 tcg_gen_add_tl(tdest
, tsrca
, tsrcb
);
763 tcg_gen_ext32s_tl(tdest
, tdest
);
766 case OE_RRR(ADD
, 0, X0
):
767 case OE_RRR(ADD
, 0, X1
):
768 case OE_RRR(ADD
, 0, Y0
):
769 case OE_RRR(ADD
, 0, Y1
):
770 tcg_gen_add_tl(tdest
, tsrca
, tsrcb
);
773 case OE_RRR(AND
, 0, X0
):
774 case OE_RRR(AND
, 0, X1
):
775 case OE_RRR(AND
, 5, Y0
):
776 case OE_RRR(AND
, 5, Y1
):
777 tcg_gen_and_tl(tdest
, tsrca
, tsrcb
);
780 case OE_RRR(CMOVEQZ
, 0, X0
):
781 case OE_RRR(CMOVEQZ
, 4, Y0
):
782 tcg_gen_movcond_tl(TCG_COND_EQ
, tdest
, tsrca
, load_zero(dc
),
783 tsrcb
, load_gr(dc
, dest
));
784 mnemonic
= "cmoveqz";
786 case OE_RRR(CMOVNEZ
, 0, X0
):
787 case OE_RRR(CMOVNEZ
, 4, Y0
):
788 tcg_gen_movcond_tl(TCG_COND_NE
, tdest
, tsrca
, load_zero(dc
),
789 tsrcb
, load_gr(dc
, dest
));
790 mnemonic
= "cmovnez";
792 case OE_RRR(CMPEQ
, 0, X0
):
793 case OE_RRR(CMPEQ
, 0, X1
):
794 case OE_RRR(CMPEQ
, 3, Y0
):
795 case OE_RRR(CMPEQ
, 3, Y1
):
796 tcg_gen_setcond_tl(TCG_COND_EQ
, tdest
, tsrca
, tsrcb
);
799 case OE_RRR(CMPEXCH4
, 0, X1
):
800 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
801 TILEGX_EXCP_OPCODE_CMPEXCH4
);
802 mnemonic
= "cmpexch4";
804 case OE_RRR(CMPEXCH
, 0, X1
):
805 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
806 TILEGX_EXCP_OPCODE_CMPEXCH
);
807 mnemonic
= "cmpexch";
809 case OE_RRR(CMPLES
, 0, X0
):
810 case OE_RRR(CMPLES
, 0, X1
):
811 case OE_RRR(CMPLES
, 2, Y0
):
812 case OE_RRR(CMPLES
, 2, Y1
):
813 tcg_gen_setcond_tl(TCG_COND_LE
, tdest
, tsrca
, tsrcb
);
816 case OE_RRR(CMPLEU
, 0, X0
):
817 case OE_RRR(CMPLEU
, 0, X1
):
818 case OE_RRR(CMPLEU
, 2, Y0
):
819 case OE_RRR(CMPLEU
, 2, Y1
):
820 tcg_gen_setcond_tl(TCG_COND_LEU
, tdest
, tsrca
, tsrcb
);
823 case OE_RRR(CMPLTS
, 0, X0
):
824 case OE_RRR(CMPLTS
, 0, X1
):
825 case OE_RRR(CMPLTS
, 2, Y0
):
826 case OE_RRR(CMPLTS
, 2, Y1
):
827 tcg_gen_setcond_tl(TCG_COND_LT
, tdest
, tsrca
, tsrcb
);
830 case OE_RRR(CMPLTU
, 0, X0
):
831 case OE_RRR(CMPLTU
, 0, X1
):
832 case OE_RRR(CMPLTU
, 2, Y0
):
833 case OE_RRR(CMPLTU
, 2, Y1
):
834 tcg_gen_setcond_tl(TCG_COND_LTU
, tdest
, tsrca
, tsrcb
);
837 case OE_RRR(CMPNE
, 0, X0
):
838 case OE_RRR(CMPNE
, 0, X1
):
839 case OE_RRR(CMPNE
, 3, Y0
):
840 case OE_RRR(CMPNE
, 3, Y1
):
841 tcg_gen_setcond_tl(TCG_COND_NE
, tdest
, tsrca
, tsrcb
);
844 case OE_RRR(CMULAF
, 0, X0
):
845 gen_helper_cmulaf(tdest
, load_gr(dc
, dest
), tsrca
, tsrcb
);
848 case OE_RRR(CMULA
, 0, X0
):
849 gen_helper_cmula(tdest
, load_gr(dc
, dest
), tsrca
, tsrcb
);
852 case OE_RRR(CMULFR
, 0, X0
):
853 gen_cmul2(tdest
, tsrca
, tsrcb
, 15, 1 << 14);
856 case OE_RRR(CMULF
, 0, X0
):
857 gen_cmul2(tdest
, tsrca
, tsrcb
, 15, 0);
860 case OE_RRR(CMULHR
, 0, X0
):
861 gen_cmul2(tdest
, tsrca
, tsrcb
, 16, 1 << 15);
864 case OE_RRR(CMULH
, 0, X0
):
865 gen_cmul2(tdest
, tsrca
, tsrcb
, 16, 0);
868 case OE_RRR(CMUL
, 0, X0
):
869 gen_helper_cmula(tdest
, load_zero(dc
), tsrca
, tsrcb
);
872 case OE_RRR(CRC32_32
, 0, X0
):
873 gen_helper_crc32_32(tdest
, tsrca
, tsrcb
);
874 mnemonic
= "crc32_32";
876 case OE_RRR(CRC32_8
, 0, X0
):
877 gen_helper_crc32_8(tdest
, tsrca
, tsrcb
);
878 mnemonic
= "crc32_8";
880 case OE_RRR(DBLALIGN2
, 0, X0
):
881 case OE_RRR(DBLALIGN2
, 0, X1
):
882 gen_dblaligni(tdest
, tsrca
, tsrcb
, 16);
883 mnemonic
= "dblalign2";
885 case OE_RRR(DBLALIGN4
, 0, X0
):
886 case OE_RRR(DBLALIGN4
, 0, X1
):
887 gen_dblaligni(tdest
, tsrca
, tsrcb
, 32);
888 mnemonic
= "dblalign4";
890 case OE_RRR(DBLALIGN6
, 0, X0
):
891 case OE_RRR(DBLALIGN6
, 0, X1
):
892 gen_dblaligni(tdest
, tsrca
, tsrcb
, 48);
893 mnemonic
= "dblalign6";
895 case OE_RRR(DBLALIGN
, 0, X0
):
896 gen_dblalign(tdest
, load_gr(dc
, dest
), tsrca
, tsrcb
);
897 mnemonic
= "dblalign";
899 case OE_RRR(EXCH4
, 0, X1
):
900 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
901 TILEGX_EXCP_OPCODE_EXCH4
);
904 case OE_RRR(EXCH
, 0, X1
):
905 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
906 TILEGX_EXCP_OPCODE_EXCH
);
909 case OE_RRR(FDOUBLE_ADDSUB
, 0, X0
):
910 case OE_RRR(FDOUBLE_ADD_FLAGS
, 0, X0
):
911 case OE_RRR(FDOUBLE_MUL_FLAGS
, 0, X0
):
912 case OE_RRR(FDOUBLE_PACK1
, 0, X0
):
913 case OE_RRR(FDOUBLE_PACK2
, 0, X0
):
914 case OE_RRR(FDOUBLE_SUB_FLAGS
, 0, X0
):
915 case OE_RRR(FDOUBLE_UNPACK_MAX
, 0, X0
):
916 case OE_RRR(FDOUBLE_UNPACK_MIN
, 0, X0
):
917 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
918 case OE_RRR(FETCHADD4
, 0, X1
):
919 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
920 TILEGX_EXCP_OPCODE_FETCHADD4
);
921 mnemonic
= "fetchadd4";
923 case OE_RRR(FETCHADDGEZ4
, 0, X1
):
924 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
925 TILEGX_EXCP_OPCODE_FETCHADDGEZ4
);
926 mnemonic
= "fetchaddgez4";
928 case OE_RRR(FETCHADDGEZ
, 0, X1
):
929 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
930 TILEGX_EXCP_OPCODE_FETCHADDGEZ
);
931 mnemonic
= "fetchaddgez";
933 case OE_RRR(FETCHADD
, 0, X1
):
934 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
935 TILEGX_EXCP_OPCODE_FETCHADD
);
936 mnemonic
= "fetchadd";
938 case OE_RRR(FETCHAND4
, 0, X1
):
939 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
940 TILEGX_EXCP_OPCODE_FETCHAND4
);
941 mnemonic
= "fetchand4";
943 case OE_RRR(FETCHAND
, 0, X1
):
944 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
945 TILEGX_EXCP_OPCODE_FETCHAND
);
946 mnemonic
= "fetchand";
948 case OE_RRR(FETCHOR4
, 0, X1
):
949 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
950 TILEGX_EXCP_OPCODE_FETCHOR4
);
951 mnemonic
= "fetchor4";
953 case OE_RRR(FETCHOR
, 0, X1
):
954 gen_atomic_excp(dc
, dest
, tdest
, tsrca
, tsrcb
,
955 TILEGX_EXCP_OPCODE_FETCHOR
);
956 mnemonic
= "fetchor";
958 case OE_RRR(FSINGLE_ADD1
, 0, X0
):
959 case OE_RRR(FSINGLE_ADDSUB2
, 0, X0
):
960 case OE_RRR(FSINGLE_MUL1
, 0, X0
):
961 case OE_RRR(FSINGLE_MUL2
, 0, X0
):
962 case OE_RRR(FSINGLE_PACK2
, 0, X0
):
963 case OE_RRR(FSINGLE_SUB1
, 0, X0
):
964 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
965 case OE_RRR(MNZ
, 0, X0
):
966 case OE_RRR(MNZ
, 0, X1
):
967 case OE_RRR(MNZ
, 4, Y0
):
968 case OE_RRR(MNZ
, 4, Y1
):
970 tcg_gen_movcond_tl(TCG_COND_NE
, tdest
, tsrca
, t0
, tsrcb
, t0
);
973 case OE_RRR(MULAX
, 0, X0
):
974 case OE_RRR(MULAX
, 3, Y0
):
975 tcg_gen_mul_tl(tdest
, tsrca
, tsrcb
);
976 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
977 tcg_gen_ext32s_tl(tdest
, tdest
);
980 case OE_RRR(MULA_HS_HS
, 0, X0
):
981 case OE_RRR(MULA_HS_HS
, 9, Y0
):
982 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, HS
);
983 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
984 mnemonic
= "mula_hs_hs";
986 case OE_RRR(MULA_HS_HU
, 0, X0
):
987 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, HU
);
988 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
989 mnemonic
= "mula_hs_hu";
991 case OE_RRR(MULA_HS_LS
, 0, X0
):
992 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, LS
);
993 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
994 mnemonic
= "mula_hs_ls";
996 case OE_RRR(MULA_HS_LU
, 0, X0
):
997 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, LU
);
998 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
999 mnemonic
= "mula_hs_lu";
1001 case OE_RRR(MULA_HU_HU
, 0, X0
):
1002 case OE_RRR(MULA_HU_HU
, 9, Y0
):
1003 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, HU
);
1004 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1005 mnemonic
= "mula_hu_hu";
1007 case OE_RRR(MULA_HU_LS
, 0, X0
):
1008 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, LS
);
1009 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1010 mnemonic
= "mula_hu_ls";
1012 case OE_RRR(MULA_HU_LU
, 0, X0
):
1013 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, LU
);
1014 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1015 mnemonic
= "mula_hu_lu";
1017 case OE_RRR(MULA_LS_LS
, 0, X0
):
1018 case OE_RRR(MULA_LS_LS
, 9, Y0
):
1019 gen_mul_half(tdest
, tsrca
, tsrcb
, LS
, LS
);
1020 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1021 mnemonic
= "mula_ls_ls";
1023 case OE_RRR(MULA_LS_LU
, 0, X0
):
1024 gen_mul_half(tdest
, tsrca
, tsrcb
, LS
, LU
);
1025 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1026 mnemonic
= "mula_ls_lu";
1028 case OE_RRR(MULA_LU_LU
, 0, X0
):
1029 case OE_RRR(MULA_LU_LU
, 9, Y0
):
1030 gen_mul_half(tdest
, tsrca
, tsrcb
, LU
, LU
);
1031 tcg_gen_add_tl(tdest
, tdest
, load_gr(dc
, dest
));
1032 mnemonic
= "mula_lu_lu";
1034 case OE_RRR(MULX
, 0, X0
):
1035 case OE_RRR(MULX
, 3, Y0
):
1036 tcg_gen_mul_tl(tdest
, tsrca
, tsrcb
);
1037 tcg_gen_ext32s_tl(tdest
, tdest
);
1040 case OE_RRR(MUL_HS_HS
, 0, X0
):
1041 case OE_RRR(MUL_HS_HS
, 8, Y0
):
1042 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, HS
);
1043 mnemonic
= "mul_hs_hs";
1045 case OE_RRR(MUL_HS_HU
, 0, X0
):
1046 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, HU
);
1047 mnemonic
= "mul_hs_hu";
1049 case OE_RRR(MUL_HS_LS
, 0, X0
):
1050 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, LS
);
1051 mnemonic
= "mul_hs_ls";
1053 case OE_RRR(MUL_HS_LU
, 0, X0
):
1054 gen_mul_half(tdest
, tsrca
, tsrcb
, HS
, LU
);
1055 mnemonic
= "mul_hs_lu";
1057 case OE_RRR(MUL_HU_HU
, 0, X0
):
1058 case OE_RRR(MUL_HU_HU
, 8, Y0
):
1059 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, HU
);
1060 mnemonic
= "mul_hu_hu";
1062 case OE_RRR(MUL_HU_LS
, 0, X0
):
1063 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, LS
);
1064 mnemonic
= "mul_hu_ls";
1066 case OE_RRR(MUL_HU_LU
, 0, X0
):
1067 gen_mul_half(tdest
, tsrca
, tsrcb
, HU
, LU
);
1068 mnemonic
= "mul_hu_lu";
1070 case OE_RRR(MUL_LS_LS
, 0, X0
):
1071 case OE_RRR(MUL_LS_LS
, 8, Y0
):
1072 gen_mul_half(tdest
, tsrca
, tsrcb
, LS
, LS
);
1073 mnemonic
= "mul_ls_ls";
1075 case OE_RRR(MUL_LS_LU
, 0, X0
):
1076 gen_mul_half(tdest
, tsrca
, tsrcb
, LS
, LU
);
1077 mnemonic
= "mul_ls_lu";
1079 case OE_RRR(MUL_LU_LU
, 0, X0
):
1080 case OE_RRR(MUL_LU_LU
, 8, Y0
):
1081 gen_mul_half(tdest
, tsrca
, tsrcb
, LU
, LU
);
1082 mnemonic
= "mul_lu_lu";
1084 case OE_RRR(MZ
, 0, X0
):
1085 case OE_RRR(MZ
, 0, X1
):
1086 case OE_RRR(MZ
, 4, Y0
):
1087 case OE_RRR(MZ
, 4, Y1
):
1089 tcg_gen_movcond_tl(TCG_COND_EQ
, tdest
, tsrca
, t0
, tsrcb
, t0
);
1092 case OE_RRR(NOR
, 0, X0
):
1093 case OE_RRR(NOR
, 0, X1
):
1094 case OE_RRR(NOR
, 5, Y0
):
1095 case OE_RRR(NOR
, 5, Y1
):
1096 tcg_gen_nor_tl(tdest
, tsrca
, tsrcb
);
1099 case OE_RRR(OR
, 0, X0
):
1100 case OE_RRR(OR
, 0, X1
):
1101 case OE_RRR(OR
, 5, Y0
):
1102 case OE_RRR(OR
, 5, Y1
):
1103 tcg_gen_or_tl(tdest
, tsrca
, tsrcb
);
1106 case OE_RRR(ROTL
, 0, X0
):
1107 case OE_RRR(ROTL
, 0, X1
):
1108 case OE_RRR(ROTL
, 6, Y0
):
1109 case OE_RRR(ROTL
, 6, Y1
):
1110 tcg_gen_andi_tl(tdest
, tsrcb
, 63);
1111 tcg_gen_rotl_tl(tdest
, tsrca
, tdest
);
1114 case OE_RRR(SHL1ADDX
, 0, X0
):
1115 case OE_RRR(SHL1ADDX
, 0, X1
):
1116 case OE_RRR(SHL1ADDX
, 7, Y0
):
1117 case OE_RRR(SHL1ADDX
, 7, Y1
):
1118 tcg_gen_shli_tl(tdest
, tsrca
, 1);
1119 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1120 tcg_gen_ext32s_tl(tdest
, tdest
);
1121 mnemonic
= "shl1addx";
1123 case OE_RRR(SHL1ADD
, 0, X0
):
1124 case OE_RRR(SHL1ADD
, 0, X1
):
1125 case OE_RRR(SHL1ADD
, 1, Y0
):
1126 case OE_RRR(SHL1ADD
, 1, Y1
):
1127 tcg_gen_shli_tl(tdest
, tsrca
, 1);
1128 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1129 mnemonic
= "shl1add";
1131 case OE_RRR(SHL2ADDX
, 0, X0
):
1132 case OE_RRR(SHL2ADDX
, 0, X1
):
1133 case OE_RRR(SHL2ADDX
, 7, Y0
):
1134 case OE_RRR(SHL2ADDX
, 7, Y1
):
1135 tcg_gen_shli_tl(tdest
, tsrca
, 2);
1136 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1137 tcg_gen_ext32s_tl(tdest
, tdest
);
1138 mnemonic
= "shl2addx";
1140 case OE_RRR(SHL2ADD
, 0, X0
):
1141 case OE_RRR(SHL2ADD
, 0, X1
):
1142 case OE_RRR(SHL2ADD
, 1, Y0
):
1143 case OE_RRR(SHL2ADD
, 1, Y1
):
1144 tcg_gen_shli_tl(tdest
, tsrca
, 2);
1145 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1146 mnemonic
= "shl2add";
1148 case OE_RRR(SHL3ADDX
, 0, X0
):
1149 case OE_RRR(SHL3ADDX
, 0, X1
):
1150 case OE_RRR(SHL3ADDX
, 7, Y0
):
1151 case OE_RRR(SHL3ADDX
, 7, Y1
):
1152 tcg_gen_shli_tl(tdest
, tsrca
, 3);
1153 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1154 tcg_gen_ext32s_tl(tdest
, tdest
);
1155 mnemonic
= "shl3addx";
1157 case OE_RRR(SHL3ADD
, 0, X0
):
1158 case OE_RRR(SHL3ADD
, 0, X1
):
1159 case OE_RRR(SHL3ADD
, 1, Y0
):
1160 case OE_RRR(SHL3ADD
, 1, Y1
):
1161 tcg_gen_shli_tl(tdest
, tsrca
, 3);
1162 tcg_gen_add_tl(tdest
, tdest
, tsrcb
);
1163 mnemonic
= "shl3add";
1165 case OE_RRR(SHLX
, 0, X0
):
1166 case OE_RRR(SHLX
, 0, X1
):
1167 tcg_gen_andi_tl(tdest
, tsrcb
, 31);
1168 tcg_gen_shl_tl(tdest
, tsrca
, tdest
);
1169 tcg_gen_ext32s_tl(tdest
, tdest
);
1172 case OE_RRR(SHL
, 0, X0
):
1173 case OE_RRR(SHL
, 0, X1
):
1174 case OE_RRR(SHL
, 6, Y0
):
1175 case OE_RRR(SHL
, 6, Y1
):
1176 tcg_gen_andi_tl(tdest
, tsrcb
, 63);
1177 tcg_gen_shl_tl(tdest
, tsrca
, tdest
);
1180 case OE_RRR(SHRS
, 0, X0
):
1181 case OE_RRR(SHRS
, 0, X1
):
1182 case OE_RRR(SHRS
, 6, Y0
):
1183 case OE_RRR(SHRS
, 6, Y1
):
1184 tcg_gen_andi_tl(tdest
, tsrcb
, 63);
1185 tcg_gen_sar_tl(tdest
, tsrca
, tdest
);
1188 case OE_RRR(SHRUX
, 0, X0
):
1189 case OE_RRR(SHRUX
, 0, X1
):
1190 t0
= tcg_temp_new();
1191 tcg_gen_andi_tl(t0
, tsrcb
, 31);
1192 tcg_gen_ext32u_tl(tdest
, tsrca
);
1193 tcg_gen_shr_tl(tdest
, tdest
, t0
);
1194 tcg_gen_ext32s_tl(tdest
, tdest
);
1198 case OE_RRR(SHRU
, 0, X0
):
1199 case OE_RRR(SHRU
, 0, X1
):
1200 case OE_RRR(SHRU
, 6, Y0
):
1201 case OE_RRR(SHRU
, 6, Y1
):
1202 tcg_gen_andi_tl(tdest
, tsrcb
, 63);
1203 tcg_gen_shr_tl(tdest
, tsrca
, tdest
);
1206 case OE_RRR(SHUFFLEBYTES
, 0, X0
):
1207 gen_helper_shufflebytes(tdest
, load_gr(dc
, dest
), tsrca
, tsrca
);
1208 mnemonic
= "shufflebytes";
1210 case OE_RRR(SUBXSC
, 0, X0
):
1211 case OE_RRR(SUBXSC
, 0, X1
):
1212 gen_saturate_op(tdest
, tsrca
, tsrcb
, tcg_gen_sub_tl
);
1213 mnemonic
= "subxsc";
1215 case OE_RRR(SUBX
, 0, X0
):
1216 case OE_RRR(SUBX
, 0, X1
):
1217 case OE_RRR(SUBX
, 0, Y0
):
1218 case OE_RRR(SUBX
, 0, Y1
):
1219 tcg_gen_sub_tl(tdest
, tsrca
, tsrcb
);
1220 tcg_gen_ext32s_tl(tdest
, tdest
);
1223 case OE_RRR(SUB
, 0, X0
):
1224 case OE_RRR(SUB
, 0, X1
):
1225 case OE_RRR(SUB
, 0, Y0
):
1226 case OE_RRR(SUB
, 0, Y1
):
1227 tcg_gen_sub_tl(tdest
, tsrca
, tsrcb
);
1230 case OE_RRR(V1ADDUC
, 0, X0
):
1231 case OE_RRR(V1ADDUC
, 0, X1
):
1232 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1233 case OE_RRR(V1ADD
, 0, X0
):
1234 case OE_RRR(V1ADD
, 0, X1
):
1235 gen_v12add(tdest
, tsrca
, tsrcb
, V1_IMM(0x80));
1238 case OE_RRR(V1ADIFFU
, 0, X0
):
1239 case OE_RRR(V1AVGU
, 0, X0
):
1240 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1241 case OE_RRR(V1CMPEQ
, 0, X0
):
1242 case OE_RRR(V1CMPEQ
, 0, X1
):
1243 tcg_gen_xor_tl(tdest
, tsrca
, tsrcb
);
1244 gen_v1cmpeq0(tdest
);
1245 mnemonic
= "v1cmpeq";
1247 case OE_RRR(V1CMPLES
, 0, X0
):
1248 case OE_RRR(V1CMPLES
, 0, X1
):
1249 case OE_RRR(V1CMPLEU
, 0, X0
):
1250 case OE_RRR(V1CMPLEU
, 0, X1
):
1251 case OE_RRR(V1CMPLTS
, 0, X0
):
1252 case OE_RRR(V1CMPLTS
, 0, X1
):
1253 case OE_RRR(V1CMPLTU
, 0, X0
):
1254 case OE_RRR(V1CMPLTU
, 0, X1
):
1255 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1256 case OE_RRR(V1CMPNE
, 0, X0
):
1257 case OE_RRR(V1CMPNE
, 0, X1
):
1258 tcg_gen_xor_tl(tdest
, tsrca
, tsrcb
);
1259 gen_v1cmpne0(tdest
);
1260 mnemonic
= "v1cmpne";
1262 case OE_RRR(V1DDOTPUA
, 0, X0
):
1263 case OE_RRR(V1DDOTPUSA
, 0, X0
):
1264 case OE_RRR(V1DDOTPUS
, 0, X0
):
1265 case OE_RRR(V1DDOTPU
, 0, X0
):
1266 case OE_RRR(V1DOTPA
, 0, X0
):
1267 case OE_RRR(V1DOTPUA
, 0, X0
):
1268 case OE_RRR(V1DOTPUSA
, 0, X0
):
1269 case OE_RRR(V1DOTPUS
, 0, X0
):
1270 case OE_RRR(V1DOTPU
, 0, X0
):
1271 case OE_RRR(V1DOTP
, 0, X0
):
1272 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1273 case OE_RRR(V1INT_H
, 0, X0
):
1274 case OE_RRR(V1INT_H
, 0, X1
):
1275 gen_helper_v1int_h(tdest
, tsrca
, tsrcb
);
1276 mnemonic
= "v1int_h";
1278 case OE_RRR(V1INT_L
, 0, X0
):
1279 case OE_RRR(V1INT_L
, 0, X1
):
1280 gen_helper_v1int_l(tdest
, tsrca
, tsrcb
);
1281 mnemonic
= "v1int_l";
1283 case OE_RRR(V1MAXU
, 0, X0
):
1284 case OE_RRR(V1MAXU
, 0, X1
):
1285 case OE_RRR(V1MINU
, 0, X0
):
1286 case OE_RRR(V1MINU
, 0, X1
):
1287 case OE_RRR(V1MNZ
, 0, X0
):
1288 case OE_RRR(V1MNZ
, 0, X1
):
1289 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1290 case OE_RRR(V1MULTU
, 0, X0
):
1291 gen_helper_v1multu(tdest
, tsrca
, tsrcb
);
1292 mnemonic
= "v1multu";
1294 case OE_RRR(V1MULUS
, 0, X0
):
1295 case OE_RRR(V1MULU
, 0, X0
):
1296 case OE_RRR(V1MZ
, 0, X0
):
1297 case OE_RRR(V1MZ
, 0, X1
):
1298 case OE_RRR(V1SADAU
, 0, X0
):
1299 case OE_RRR(V1SADU
, 0, X0
):
1300 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1301 case OE_RRR(V1SHL
, 0, X0
):
1302 case OE_RRR(V1SHL
, 0, X1
):
1303 gen_helper_v1shl(tdest
, tsrca
, tsrcb
);
1306 case OE_RRR(V1SHRS
, 0, X0
):
1307 case OE_RRR(V1SHRS
, 0, X1
):
1308 gen_helper_v1shrs(tdest
, tsrca
, tsrcb
);
1309 mnemonic
= "v1shrs";
1311 case OE_RRR(V1SHRU
, 0, X0
):
1312 case OE_RRR(V1SHRU
, 0, X1
):
1313 gen_helper_v1shru(tdest
, tsrca
, tsrcb
);
1314 mnemonic
= "v1shru";
1316 case OE_RRR(V1SUBUC
, 0, X0
):
1317 case OE_RRR(V1SUBUC
, 0, X1
):
1318 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1319 case OE_RRR(V1SUB
, 0, X0
):
1320 case OE_RRR(V1SUB
, 0, X1
):
1321 gen_v12sub(tdest
, tsrca
, tsrcb
, V1_IMM(0x80));
1324 case OE_RRR(V2ADDSC
, 0, X0
):
1325 case OE_RRR(V2ADDSC
, 0, X1
):
1326 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1327 case OE_RRR(V2ADD
, 0, X0
):
1328 case OE_RRR(V2ADD
, 0, X1
):
1329 gen_v12add(tdest
, tsrca
, tsrcb
, V2_IMM(0x8000));
1332 case OE_RRR(V2ADIFFS
, 0, X0
):
1333 case OE_RRR(V2AVGS
, 0, X0
):
1334 case OE_RRR(V2CMPEQ
, 0, X0
):
1335 case OE_RRR(V2CMPEQ
, 0, X1
):
1336 case OE_RRR(V2CMPLES
, 0, X0
):
1337 case OE_RRR(V2CMPLES
, 0, X1
):
1338 case OE_RRR(V2CMPLEU
, 0, X0
):
1339 case OE_RRR(V2CMPLEU
, 0, X1
):
1340 case OE_RRR(V2CMPLTS
, 0, X0
):
1341 case OE_RRR(V2CMPLTS
, 0, X1
):
1342 case OE_RRR(V2CMPLTU
, 0, X0
):
1343 case OE_RRR(V2CMPLTU
, 0, X1
):
1344 case OE_RRR(V2CMPNE
, 0, X0
):
1345 case OE_RRR(V2CMPNE
, 0, X1
):
1346 case OE_RRR(V2DOTPA
, 0, X0
):
1347 case OE_RRR(V2DOTP
, 0, X0
):
1348 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1349 case OE_RRR(V2INT_H
, 0, X0
):
1350 case OE_RRR(V2INT_H
, 0, X1
):
1351 gen_helper_v2int_h(tdest
, tsrca
, tsrcb
);
1352 mnemonic
= "v2int_h";
1354 case OE_RRR(V2INT_L
, 0, X0
):
1355 case OE_RRR(V2INT_L
, 0, X1
):
1356 gen_helper_v2int_l(tdest
, tsrca
, tsrcb
);
1357 mnemonic
= "v2int_l";
1359 case OE_RRR(V2MAXS
, 0, X0
):
1360 case OE_RRR(V2MAXS
, 0, X1
):
1361 case OE_RRR(V2MINS
, 0, X0
):
1362 case OE_RRR(V2MINS
, 0, X1
):
1363 case OE_RRR(V2MNZ
, 0, X0
):
1364 case OE_RRR(V2MNZ
, 0, X1
):
1365 case OE_RRR(V2MULFSC
, 0, X0
):
1366 case OE_RRR(V2MULS
, 0, X0
):
1367 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1368 case OE_RRR(V2MULTS
, 0, X0
):
1369 gen_helper_v2mults(tdest
, tsrca
, tsrcb
);
1370 mnemonic
= "v2mults";
1372 case OE_RRR(V2MZ
, 0, X0
):
1373 case OE_RRR(V2MZ
, 0, X1
):
1374 case OE_RRR(V2PACKH
, 0, X0
):
1375 case OE_RRR(V2PACKH
, 0, X1
):
1376 case OE_RRR(V2PACKL
, 0, X0
):
1377 case OE_RRR(V2PACKL
, 0, X1
):
1378 case OE_RRR(V2PACKUC
, 0, X0
):
1379 case OE_RRR(V2PACKUC
, 0, X1
):
1380 case OE_RRR(V2SADAS
, 0, X0
):
1381 case OE_RRR(V2SADAU
, 0, X0
):
1382 case OE_RRR(V2SADS
, 0, X0
):
1383 case OE_RRR(V2SADU
, 0, X0
):
1384 case OE_RRR(V2SHLSC
, 0, X0
):
1385 case OE_RRR(V2SHLSC
, 0, X1
):
1386 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1387 case OE_RRR(V2SHL
, 0, X0
):
1388 case OE_RRR(V2SHL
, 0, X1
):
1389 gen_helper_v2shl(tdest
, tsrca
, tsrcb
);
1392 case OE_RRR(V2SHRS
, 0, X0
):
1393 case OE_RRR(V2SHRS
, 0, X1
):
1394 gen_helper_v2shrs(tdest
, tsrca
, tsrcb
);
1395 mnemonic
= "v2shrs";
1397 case OE_RRR(V2SHRU
, 0, X0
):
1398 case OE_RRR(V2SHRU
, 0, X1
):
1399 gen_helper_v2shru(tdest
, tsrca
, tsrcb
);
1400 mnemonic
= "v2shru";
1402 case OE_RRR(V2SUBSC
, 0, X0
):
1403 case OE_RRR(V2SUBSC
, 0, X1
):
1404 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1405 case OE_RRR(V2SUB
, 0, X0
):
1406 case OE_RRR(V2SUB
, 0, X1
):
1407 gen_v12sub(tdest
, tsrca
, tsrcb
, V2_IMM(0x8000));
1410 case OE_RRR(V4ADDSC
, 0, X0
):
1411 case OE_RRR(V4ADDSC
, 0, X1
):
1412 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1413 case OE_RRR(V4ADD
, 0, X0
):
1414 case OE_RRR(V4ADD
, 0, X1
):
1415 gen_v4op(tdest
, tsrca
, tsrcb
, tcg_gen_add_i32
);
1418 case OE_RRR(V4INT_H
, 0, X0
):
1419 case OE_RRR(V4INT_H
, 0, X1
):
1420 tcg_gen_shri_tl(tdest
, tsrcb
, 32);
1421 tcg_gen_deposit_tl(tdest
, tsrca
, tdest
, 0, 32);
1422 mnemonic
= "v4int_h";
1424 case OE_RRR(V4INT_L
, 0, X0
):
1425 case OE_RRR(V4INT_L
, 0, X1
):
1426 tcg_gen_deposit_tl(tdest
, tsrcb
, tsrca
, 32, 32);
1427 mnemonic
= "v4int_l";
1429 case OE_RRR(V4PACKSC
, 0, X0
):
1430 case OE_RRR(V4PACKSC
, 0, X1
):
1431 case OE_RRR(V4SHLSC
, 0, X0
):
1432 case OE_RRR(V4SHLSC
, 0, X1
):
1433 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1434 case OE_RRR(V4SHL
, 0, X0
):
1435 case OE_RRR(V4SHL
, 0, X1
):
1436 gen_v4sh(tdest
, tsrca
, tsrcb
, tcg_gen_shl_i32
);
1439 case OE_RRR(V4SHRS
, 0, X0
):
1440 case OE_RRR(V4SHRS
, 0, X1
):
1441 gen_v4sh(tdest
, tsrca
, tsrcb
, tcg_gen_sar_i32
);
1442 mnemonic
= "v4shrs";
1444 case OE_RRR(V4SHRU
, 0, X0
):
1445 case OE_RRR(V4SHRU
, 0, X1
):
1446 gen_v4sh(tdest
, tsrca
, tsrcb
, tcg_gen_shr_i32
);
1447 mnemonic
= "v4shru";
1449 case OE_RRR(V4SUBSC
, 0, X0
):
1450 case OE_RRR(V4SUBSC
, 0, X1
):
1451 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1452 case OE_RRR(V4SUB
, 0, X0
):
1453 case OE_RRR(V4SUB
, 0, X1
):
1454 gen_v4op(tdest
, tsrca
, tsrcb
, tcg_gen_sub_i32
);
1457 case OE_RRR(XOR
, 0, X0
):
1458 case OE_RRR(XOR
, 0, X1
):
1459 case OE_RRR(XOR
, 5, Y0
):
1460 case OE_RRR(XOR
, 5, Y1
):
1461 tcg_gen_xor_tl(tdest
, tsrca
, tsrcb
);
1465 return TILEGX_EXCP_OPCODE_UNKNOWN
;
1468 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s, %s", mnemonic
,
1469 reg_names
[dest
], reg_names
[srca
], reg_names
[srcb
]);
1470 return TILEGX_EXCP_NONE
;
1473 static TileExcp
gen_rri_opcode(DisasContext
*dc
, unsigned opext
,
1474 unsigned dest
, unsigned srca
, int imm
)
1476 TCGv tdest
= dest_gr(dc
, dest
);
1477 TCGv tsrca
= load_gr(dc
, srca
);
1478 bool prefetch_nofault
= false;
1479 const char *mnemonic
;
1485 case OE(ADDI_OPCODE_Y0
, 0, Y0
):
1486 case OE(ADDI_OPCODE_Y1
, 0, Y1
):
1487 case OE_IM(ADDI
, X0
):
1488 case OE_IM(ADDI
, X1
):
1489 tcg_gen_addi_tl(tdest
, tsrca
, imm
);
1492 case OE(ADDXI_OPCODE_Y0
, 0, Y0
):
1493 case OE(ADDXI_OPCODE_Y1
, 0, Y1
):
1494 case OE_IM(ADDXI
, X0
):
1495 case OE_IM(ADDXI
, X1
):
1496 tcg_gen_addi_tl(tdest
, tsrca
, imm
);
1497 tcg_gen_ext32s_tl(tdest
, tdest
);
1500 case OE(ANDI_OPCODE_Y0
, 0, Y0
):
1501 case OE(ANDI_OPCODE_Y1
, 0, Y1
):
1502 case OE_IM(ANDI
, X0
):
1503 case OE_IM(ANDI
, X1
):
1504 tcg_gen_andi_tl(tdest
, tsrca
, imm
);
1507 case OE(CMPEQI_OPCODE_Y0
, 0, Y0
):
1508 case OE(CMPEQI_OPCODE_Y1
, 0, Y1
):
1509 case OE_IM(CMPEQI
, X0
):
1510 case OE_IM(CMPEQI
, X1
):
1511 tcg_gen_setcondi_tl(TCG_COND_EQ
, tdest
, tsrca
, imm
);
1512 mnemonic
= "cmpeqi";
1514 case OE(CMPLTSI_OPCODE_Y0
, 0, Y0
):
1515 case OE(CMPLTSI_OPCODE_Y1
, 0, Y1
):
1516 case OE_IM(CMPLTSI
, X0
):
1517 case OE_IM(CMPLTSI
, X1
):
1518 tcg_gen_setcondi_tl(TCG_COND_LT
, tdest
, tsrca
, imm
);
1519 mnemonic
= "cmpltsi";
1521 case OE_IM(CMPLTUI
, X0
):
1522 case OE_IM(CMPLTUI
, X1
):
1523 tcg_gen_setcondi_tl(TCG_COND_LTU
, tdest
, tsrca
, imm
);
1524 mnemonic
= "cmpltui";
1526 case OE_IM(LD1S_ADD
, X1
):
1528 mnemonic
= "ld1s_add"; /* prefetch_add_l1_fault */
1530 case OE_IM(LD1U_ADD
, X1
):
1532 mnemonic
= "ld1u_add"; /* prefetch_add_l1 */
1533 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
1535 case OE_IM(LD2S_ADD
, X1
):
1537 mnemonic
= "ld2s_add"; /* prefetch_add_l2_fault */
1539 case OE_IM(LD2U_ADD
, X1
):
1541 mnemonic
= "ld2u_add"; /* prefetch_add_l2 */
1542 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
1544 case OE_IM(LD4S_ADD
, X1
):
1546 mnemonic
= "ld4s_add"; /* prefetch_add_l3_fault */
1548 case OE_IM(LD4U_ADD
, X1
):
1550 mnemonic
= "ld4u_add"; /* prefetch_add_l3 */
1551 prefetch_nofault
= (dest
== TILEGX_R_ZERO
);
1553 case OE_IM(LDNT1S_ADD
, X1
):
1555 mnemonic
= "ldnt1s_add";
1557 case OE_IM(LDNT1U_ADD
, X1
):
1559 mnemonic
= "ldnt1u_add";
1561 case OE_IM(LDNT2S_ADD
, X1
):
1563 mnemonic
= "ldnt2s_add";
1565 case OE_IM(LDNT2U_ADD
, X1
):
1567 mnemonic
= "ldnt2u_add";
1569 case OE_IM(LDNT4S_ADD
, X1
):
1571 mnemonic
= "ldnt4s_add";
1573 case OE_IM(LDNT4U_ADD
, X1
):
1575 mnemonic
= "ldnt4u_add";
1577 case OE_IM(LDNT_ADD
, X1
):
1579 mnemonic
= "ldnt_add";
1581 case OE_IM(LD_ADD
, X1
):
1583 mnemonic
= "ld_add";
1585 if (!prefetch_nofault
) {
1586 tcg_gen_qemu_ld_tl(tdest
, tsrca
, dc
->mmuidx
, memop
);
1588 tcg_gen_addi_tl(dest_gr(dc
, srca
), tsrca
, imm
);
1590 case OE_IM(LDNA_ADD
, X1
):
1591 tcg_gen_andi_tl(tdest
, tsrca
, ~7);
1592 tcg_gen_qemu_ld_tl(tdest
, tdest
, dc
->mmuidx
, MO_TEQ
);
1593 tcg_gen_addi_tl(dest_gr(dc
, srca
), tsrca
, imm
);
1594 mnemonic
= "ldna_add";
1596 case OE_IM(ORI
, X0
):
1597 case OE_IM(ORI
, X1
):
1598 tcg_gen_ori_tl(tdest
, tsrca
, imm
);
1601 case OE_IM(V1ADDI
, X0
):
1602 case OE_IM(V1ADDI
, X1
):
1603 t0
= tcg_const_tl(V1_IMM(imm
));
1604 gen_v12add(tdest
, tsrca
, t0
, V1_IMM(0x80));
1606 mnemonic
= "v1addi";
1608 case OE_IM(V1CMPEQI
, X0
):
1609 case OE_IM(V1CMPEQI
, X1
):
1610 tcg_gen_xori_tl(tdest
, tsrca
, V1_IMM(imm
));
1611 gen_v1cmpeq0(tdest
);
1612 mnemonic
= "v1cmpeqi";
1614 case OE_IM(V1CMPLTSI
, X0
):
1615 case OE_IM(V1CMPLTSI
, X1
):
1616 case OE_IM(V1CMPLTUI
, X0
):
1617 case OE_IM(V1CMPLTUI
, X1
):
1618 case OE_IM(V1MAXUI
, X0
):
1619 case OE_IM(V1MAXUI
, X1
):
1620 case OE_IM(V1MINUI
, X0
):
1621 case OE_IM(V1MINUI
, X1
):
1622 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1623 case OE_IM(V2ADDI
, X0
):
1624 case OE_IM(V2ADDI
, X1
):
1625 t0
= tcg_const_tl(V2_IMM(imm
));
1626 gen_v12add(tdest
, tsrca
, t0
, V2_IMM(0x8000));
1628 mnemonic
= "v2addi";
1630 case OE_IM(V2CMPEQI
, X0
):
1631 case OE_IM(V2CMPEQI
, X1
):
1632 case OE_IM(V2CMPLTSI
, X0
):
1633 case OE_IM(V2CMPLTSI
, X1
):
1634 case OE_IM(V2CMPLTUI
, X0
):
1635 case OE_IM(V2CMPLTUI
, X1
):
1636 case OE_IM(V2MAXSI
, X0
):
1637 case OE_IM(V2MAXSI
, X1
):
1638 case OE_IM(V2MINSI
, X0
):
1639 case OE_IM(V2MINSI
, X1
):
1640 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1641 case OE_IM(XORI
, X0
):
1642 case OE_IM(XORI
, X1
):
1643 tcg_gen_xori_tl(tdest
, tsrca
, imm
);
1647 case OE_SH(ROTLI
, X0
):
1648 case OE_SH(ROTLI
, X1
):
1649 case OE_SH(ROTLI
, Y0
):
1650 case OE_SH(ROTLI
, Y1
):
1651 tcg_gen_rotli_tl(tdest
, tsrca
, imm
);
1654 case OE_SH(SHLI
, X0
):
1655 case OE_SH(SHLI
, X1
):
1656 case OE_SH(SHLI
, Y0
):
1657 case OE_SH(SHLI
, Y1
):
1658 tcg_gen_shli_tl(tdest
, tsrca
, imm
);
1661 case OE_SH(SHLXI
, X0
):
1662 case OE_SH(SHLXI
, X1
):
1663 tcg_gen_shli_tl(tdest
, tsrca
, imm
& 31);
1664 tcg_gen_ext32s_tl(tdest
, tdest
);
1667 case OE_SH(SHRSI
, X0
):
1668 case OE_SH(SHRSI
, X1
):
1669 case OE_SH(SHRSI
, Y0
):
1670 case OE_SH(SHRSI
, Y1
):
1671 tcg_gen_sari_tl(tdest
, tsrca
, imm
);
1674 case OE_SH(SHRUI
, X0
):
1675 case OE_SH(SHRUI
, X1
):
1676 case OE_SH(SHRUI
, Y0
):
1677 case OE_SH(SHRUI
, Y1
):
1678 tcg_gen_shri_tl(tdest
, tsrca
, imm
);
1681 case OE_SH(SHRUXI
, X0
):
1682 case OE_SH(SHRUXI
, X1
):
1683 if ((imm
& 31) == 0) {
1684 tcg_gen_ext32s_tl(tdest
, tsrca
);
1686 tcg_gen_ext32u_tl(tdest
, tsrca
);
1687 tcg_gen_shri_tl(tdest
, tdest
, imm
& 31);
1691 case OE_SH(V1SHLI
, X0
):
1692 case OE_SH(V1SHLI
, X1
):
1695 tcg_gen_andi_tl(tdest
, tsrca
, V1_IMM(i3
));
1696 tcg_gen_shli_tl(tdest
, tdest
, i2
);
1697 mnemonic
= "v1shli";
1699 case OE_SH(V1SHRSI
, X0
):
1700 case OE_SH(V1SHRSI
, X1
):
1701 t0
= tcg_const_tl(imm
& 7);
1702 gen_helper_v1shrs(tdest
, tsrca
, t0
);
1704 mnemonic
= "v1shrsi";
1706 case OE_SH(V1SHRUI
, X0
):
1707 case OE_SH(V1SHRUI
, X1
):
1709 i3
= (0xff << i2
) & 0xff;
1710 tcg_gen_andi_tl(tdest
, tsrca
, V1_IMM(i3
));
1711 tcg_gen_shri_tl(tdest
, tdest
, i2
);
1712 mnemonic
= "v1shrui";
1714 case OE_SH(V2SHLI
, X0
):
1715 case OE_SH(V2SHLI
, X1
):
1718 tcg_gen_andi_tl(tdest
, tsrca
, V2_IMM(i3
));
1719 tcg_gen_shli_tl(tdest
, tdest
, i2
);
1720 mnemonic
= "v2shli";
1722 case OE_SH(V2SHRSI
, X0
):
1723 case OE_SH(V2SHRSI
, X1
):
1724 t0
= tcg_const_tl(imm
& 15);
1725 gen_helper_v2shrs(tdest
, tsrca
, t0
);
1727 mnemonic
= "v2shrsi";
1729 case OE_SH(V2SHRUI
, X0
):
1730 case OE_SH(V2SHRUI
, X1
):
1732 i3
= (0xffff << i2
) & 0xffff;
1733 tcg_gen_andi_tl(tdest
, tsrca
, V2_IMM(i3
));
1734 tcg_gen_shri_tl(tdest
, tdest
, i2
);
1735 mnemonic
= "v2shrui";
1738 case OE(ADDLI_OPCODE_X0
, 0, X0
):
1739 case OE(ADDLI_OPCODE_X1
, 0, X1
):
1740 tcg_gen_addi_tl(tdest
, tsrca
, imm
);
1743 case OE(ADDXLI_OPCODE_X0
, 0, X0
):
1744 case OE(ADDXLI_OPCODE_X1
, 0, X1
):
1745 tcg_gen_addi_tl(tdest
, tsrca
, imm
);
1746 tcg_gen_ext32s_tl(tdest
, tdest
);
1747 mnemonic
= "addxli";
1749 case OE(SHL16INSLI_OPCODE_X0
, 0, X0
):
1750 case OE(SHL16INSLI_OPCODE_X1
, 0, X1
):
1751 tcg_gen_shli_tl(tdest
, tsrca
, 16);
1752 tcg_gen_ori_tl(tdest
, tdest
, imm
& 0xffff);
1753 mnemonic
= "shl16insli";
1757 return TILEGX_EXCP_OPCODE_UNKNOWN
;
1760 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s, %d", mnemonic
,
1761 reg_names
[dest
], reg_names
[srca
], imm
);
1762 return TILEGX_EXCP_NONE
;
1765 static TileExcp
gen_bf_opcode_x0(DisasContext
*dc
, unsigned ext
,
1766 unsigned dest
, unsigned srca
,
1767 unsigned bfs
, unsigned bfe
)
1769 TCGv tdest
= dest_gr(dc
, dest
);
1770 TCGv tsrca
= load_gr(dc
, srca
);
1773 const char *mnemonic
;
1775 /* The bitfield is either between E and S inclusive,
1776 or up from S and down from E inclusive. */
1778 len
= bfe
- bfs
+ 1;
1780 len
= (64 - bfs
) + (bfe
+ 1);
1784 case BFEXTU_BF_OPCODE_X0
:
1785 if (bfs
== 0 && bfe
== 7) {
1786 tcg_gen_ext8u_tl(tdest
, tsrca
);
1787 } else if (bfs
== 0 && bfe
== 15) {
1788 tcg_gen_ext16u_tl(tdest
, tsrca
);
1789 } else if (bfs
== 0 && bfe
== 31) {
1790 tcg_gen_ext32u_tl(tdest
, tsrca
);
1794 tcg_gen_shli_tl(tdest
, tsrca
, rol
);
1796 tcg_gen_rotli_tl(tdest
, tsrca
, rol
);
1798 tcg_gen_shri_tl(tdest
, tdest
, (bfs
+ rol
) & 63);
1800 mnemonic
= "bfextu";
1803 case BFEXTS_BF_OPCODE_X0
:
1804 if (bfs
== 0 && bfe
== 7) {
1805 tcg_gen_ext8s_tl(tdest
, tsrca
);
1806 } else if (bfs
== 0 && bfe
== 15) {
1807 tcg_gen_ext16s_tl(tdest
, tsrca
);
1808 } else if (bfs
== 0 && bfe
== 31) {
1809 tcg_gen_ext32s_tl(tdest
, tsrca
);
1813 tcg_gen_shli_tl(tdest
, tsrca
, rol
);
1815 tcg_gen_rotli_tl(tdest
, tsrca
, rol
);
1817 tcg_gen_sari_tl(tdest
, tdest
, (bfs
+ rol
) & 63);
1819 mnemonic
= "bfexts";
1822 case BFINS_BF_OPCODE_X0
:
1823 tsrcd
= load_gr(dc
, dest
);
1825 tcg_gen_deposit_tl(tdest
, tsrcd
, tsrca
, bfs
, len
);
1827 tcg_gen_rotri_tl(tdest
, tsrcd
, bfs
);
1828 tcg_gen_deposit_tl(tdest
, tdest
, tsrca
, 0, len
);
1829 tcg_gen_rotli_tl(tdest
, tdest
, bfs
);
1834 case MM_BF_OPCODE_X0
:
1835 tsrcd
= load_gr(dc
, dest
);
1837 tcg_gen_deposit_tl(tdest
, tsrca
, tsrcd
, 0, len
);
1839 uint64_t mask
= len
== 64 ? -1 : rol64((1ULL << len
) - 1, bfs
);
1840 TCGv tmp
= tcg_const_tl(mask
);
1842 tcg_gen_and_tl(tdest
, tsrcd
, tmp
);
1843 tcg_gen_andc_tl(tmp
, tsrca
, tmp
);
1844 tcg_gen_or_tl(tdest
, tdest
, tmp
);
1851 return TILEGX_EXCP_OPCODE_UNKNOWN
;
1854 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s, %u, %u", mnemonic
,
1855 reg_names
[dest
], reg_names
[srca
], bfs
, bfe
);
1856 return TILEGX_EXCP_NONE
;
1859 static TileExcp
gen_branch_opcode_x1(DisasContext
*dc
, unsigned ext
,
1860 unsigned srca
, int off
)
1862 target_ulong tgt
= dc
->pc
+ off
* TILEGX_BUNDLE_SIZE_IN_BYTES
;
1863 const char *mnemonic
;
1865 dc
->jmp
.dest
= tcg_const_tl(tgt
);
1866 dc
->jmp
.val1
= tcg_temp_new();
1867 tcg_gen_mov_tl(dc
->jmp
.val1
, load_gr(dc
, srca
));
1869 /* Note that the "predict taken" opcodes have bit 0 clear.
1870 Therefore, fold the two cases together by setting bit 0. */
1872 case BEQZ_BRANCH_OPCODE_X1
:
1873 dc
->jmp
.cond
= TCG_COND_EQ
;
1876 case BNEZ_BRANCH_OPCODE_X1
:
1877 dc
->jmp
.cond
= TCG_COND_NE
;
1880 case BGEZ_BRANCH_OPCODE_X1
:
1881 dc
->jmp
.cond
= TCG_COND_GE
;
1884 case BGTZ_BRANCH_OPCODE_X1
:
1885 dc
->jmp
.cond
= TCG_COND_GT
;
1888 case BLEZ_BRANCH_OPCODE_X1
:
1889 dc
->jmp
.cond
= TCG_COND_LE
;
1892 case BLTZ_BRANCH_OPCODE_X1
:
1893 dc
->jmp
.cond
= TCG_COND_LT
;
1896 case BLBC_BRANCH_OPCODE_X1
:
1897 dc
->jmp
.cond
= TCG_COND_EQ
;
1898 tcg_gen_andi_tl(dc
->jmp
.val1
, dc
->jmp
.val1
, 1);
1901 case BLBS_BRANCH_OPCODE_X1
:
1902 dc
->jmp
.cond
= TCG_COND_NE
;
1903 tcg_gen_andi_tl(dc
->jmp
.val1
, dc
->jmp
.val1
, 1);
1907 return TILEGX_EXCP_OPCODE_UNKNOWN
;
1910 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1911 qemu_log("%s%s %s, " TARGET_FMT_lx
" <%s>",
1912 mnemonic
, ext
& 1 ? "" : "t",
1913 reg_names
[srca
], tgt
, lookup_symbol(tgt
));
1915 return TILEGX_EXCP_NONE
;
1918 static TileExcp
gen_jump_opcode_x1(DisasContext
*dc
, unsigned ext
, int off
)
1920 target_ulong tgt
= dc
->pc
+ off
* TILEGX_BUNDLE_SIZE_IN_BYTES
;
1921 const char *mnemonic
= "j";
1923 /* The extension field is 1 bit, therefore we only have JAL and J. */
1924 if (ext
== JAL_JUMP_OPCODE_X1
) {
1925 tcg_gen_movi_tl(dest_gr(dc
, TILEGX_R_LR
),
1926 dc
->pc
+ TILEGX_BUNDLE_SIZE_IN_BYTES
);
1929 dc
->jmp
.cond
= TCG_COND_ALWAYS
;
1930 dc
->jmp
.dest
= tcg_const_tl(tgt
);
1932 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
1933 qemu_log("%s " TARGET_FMT_lx
" <%s>",
1934 mnemonic
, tgt
, lookup_symbol(tgt
));
1936 return TILEGX_EXCP_NONE
;
1942 void (*get
)(TCGv
, TCGv_ptr
);
1943 void (*put
)(TCGv_ptr
, TCGv
);
1946 static const TileSPR
*find_spr(unsigned spr
)
1948 /* Allow the compiler to construct the binary search tree. */
1949 #define D(N, O, G, P) \
1950 case SPR_##N: { static const TileSPR x = { #N, O, G, P }; return &x; }
1954 offsetof(CPUTLGState
, spregs
[TILEGX_SPR_CMPEXCH
]), 0, 0)
1955 D(INTERRUPT_CRITICAL_SECTION
,
1956 offsetof(CPUTLGState
, spregs
[TILEGX_SPR_CRITICAL_SEC
]), 0, 0)
1958 offsetof(CPUTLGState
, spregs
[TILEGX_SPR_SIM_CONTROL
]), 0, 0)
1960 offsetof(CPUTLGState
, spregs
[TILEGX_SPR_EX_CONTEXT_0_0
]), 0, 0)
1962 offsetof(CPUTLGState
, spregs
[TILEGX_SPR_EX_CONTEXT_0_1
]), 0, 0)
1967 qemu_log_mask(LOG_UNIMP
, "UNIMP SPR %u\n", spr
);
1971 static TileExcp
gen_mtspr_x1(DisasContext
*dc
, unsigned spr
, unsigned srca
)
1973 const TileSPR
*def
= find_spr(spr
);
1977 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "mtspr spr[%u], %s", spr
, reg_names
[srca
]);
1978 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
1981 tsrca
= load_gr(dc
, srca
);
1983 def
->put(cpu_env
, tsrca
);
1985 tcg_gen_st_tl(tsrca
, cpu_env
, def
->offset
);
1987 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "mtspr %s, %s", def
->name
, reg_names
[srca
]);
1988 return TILEGX_EXCP_NONE
;
1991 static TileExcp
gen_mfspr_x1(DisasContext
*dc
, unsigned dest
, unsigned spr
)
1993 const TileSPR
*def
= find_spr(spr
);
1997 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "mtspr %s, spr[%u]", reg_names
[dest
], spr
);
1998 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED
;
2001 tdest
= dest_gr(dc
, dest
);
2003 def
->get(tdest
, cpu_env
);
2005 tcg_gen_ld_tl(tdest
, cpu_env
, def
->offset
);
2007 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "mfspr %s, %s", reg_names
[dest
], def
->name
);
2008 return TILEGX_EXCP_NONE
;
2011 static TileExcp
decode_y0(DisasContext
*dc
, tilegx_bundle_bits bundle
)
2013 unsigned opc
= get_Opcode_Y0(bundle
);
2014 unsigned ext
= get_RRROpcodeExtension_Y0(bundle
);
2015 unsigned dest
= get_Dest_Y0(bundle
);
2016 unsigned srca
= get_SrcA_Y0(bundle
);
2021 case RRR_1_OPCODE_Y0
:
2022 if (ext
== UNARY_RRR_1_OPCODE_Y0
) {
2023 ext
= get_UnaryOpcodeExtension_Y0(bundle
);
2024 return gen_rr_opcode(dc
, OE(opc
, ext
, Y0
), dest
, srca
, bundle
);
2027 case RRR_0_OPCODE_Y0
:
2028 case RRR_2_OPCODE_Y0
:
2029 case RRR_3_OPCODE_Y0
:
2030 case RRR_4_OPCODE_Y0
:
2031 case RRR_5_OPCODE_Y0
:
2032 case RRR_6_OPCODE_Y0
:
2033 case RRR_7_OPCODE_Y0
:
2034 case RRR_8_OPCODE_Y0
:
2035 case RRR_9_OPCODE_Y0
:
2036 srcb
= get_SrcB_Y0(bundle
);
2037 return gen_rrr_opcode(dc
, OE(opc
, ext
, Y0
), dest
, srca
, srcb
);
2039 case SHIFT_OPCODE_Y0
:
2040 ext
= get_ShiftOpcodeExtension_Y0(bundle
);
2041 imm
= get_ShAmt_Y0(bundle
);
2042 return gen_rri_opcode(dc
, OE(opc
, ext
, Y0
), dest
, srca
, imm
);
2044 case ADDI_OPCODE_Y0
:
2045 case ADDXI_OPCODE_Y0
:
2046 case ANDI_OPCODE_Y0
:
2047 case CMPEQI_OPCODE_Y0
:
2048 case CMPLTSI_OPCODE_Y0
:
2049 imm
= (int8_t)get_Imm8_Y0(bundle
);
2050 return gen_rri_opcode(dc
, OE(opc
, 0, Y0
), dest
, srca
, imm
);
2053 return TILEGX_EXCP_OPCODE_UNKNOWN
;
2057 static TileExcp
decode_y1(DisasContext
*dc
, tilegx_bundle_bits bundle
)
2059 unsigned opc
= get_Opcode_Y1(bundle
);
2060 unsigned ext
= get_RRROpcodeExtension_Y1(bundle
);
2061 unsigned dest
= get_Dest_Y1(bundle
);
2062 unsigned srca
= get_SrcA_Y1(bundle
);
2066 switch (get_Opcode_Y1(bundle
)) {
2067 case RRR_1_OPCODE_Y1
:
2068 if (ext
== UNARY_RRR_1_OPCODE_Y0
) {
2069 ext
= get_UnaryOpcodeExtension_Y1(bundle
);
2070 return gen_rr_opcode(dc
, OE(opc
, ext
, Y1
), dest
, srca
, bundle
);
2073 case RRR_0_OPCODE_Y1
:
2074 case RRR_2_OPCODE_Y1
:
2075 case RRR_3_OPCODE_Y1
:
2076 case RRR_4_OPCODE_Y1
:
2077 case RRR_5_OPCODE_Y1
:
2078 case RRR_6_OPCODE_Y1
:
2079 case RRR_7_OPCODE_Y1
:
2080 srcb
= get_SrcB_Y1(bundle
);
2081 return gen_rrr_opcode(dc
, OE(opc
, ext
, Y1
), dest
, srca
, srcb
);
2083 case SHIFT_OPCODE_Y1
:
2084 ext
= get_ShiftOpcodeExtension_Y1(bundle
);
2085 imm
= get_ShAmt_Y1(bundle
);
2086 return gen_rri_opcode(dc
, OE(opc
, ext
, Y1
), dest
, srca
, imm
);
2088 case ADDI_OPCODE_Y1
:
2089 case ADDXI_OPCODE_Y1
:
2090 case ANDI_OPCODE_Y1
:
2091 case CMPEQI_OPCODE_Y1
:
2092 case CMPLTSI_OPCODE_Y1
:
2093 imm
= (int8_t)get_Imm8_Y1(bundle
);
2094 return gen_rri_opcode(dc
, OE(opc
, 0, Y1
), dest
, srca
, imm
);
2097 return TILEGX_EXCP_OPCODE_UNKNOWN
;
2101 static TileExcp
decode_y2(DisasContext
*dc
, tilegx_bundle_bits bundle
)
2103 unsigned mode
= get_Mode(bundle
);
2104 unsigned opc
= get_Opcode_Y2(bundle
);
2105 unsigned srca
= get_SrcA_Y2(bundle
);
2106 unsigned srcbdest
= get_SrcBDest_Y2(bundle
);
2107 const char *mnemonic
;
2109 bool prefetch_nofault
= false;
2111 switch (OEY2(opc
, mode
)) {
2112 case OEY2(LD1S_OPCODE_Y2
, MODE_OPCODE_YA2
):
2114 mnemonic
= "ld1s"; /* prefetch_l1_fault */
2116 case OEY2(LD1U_OPCODE_Y2
, MODE_OPCODE_YA2
):
2118 mnemonic
= "ld1u"; /* prefetch, prefetch_l1 */
2119 prefetch_nofault
= (srcbdest
== TILEGX_R_ZERO
);
2121 case OEY2(LD2S_OPCODE_Y2
, MODE_OPCODE_YA2
):
2123 mnemonic
= "ld2s"; /* prefetch_l2_fault */
2125 case OEY2(LD2U_OPCODE_Y2
, MODE_OPCODE_YA2
):
2127 mnemonic
= "ld2u"; /* prefetch_l2 */
2128 prefetch_nofault
= (srcbdest
== TILEGX_R_ZERO
);
2130 case OEY2(LD4S_OPCODE_Y2
, MODE_OPCODE_YB2
):
2132 mnemonic
= "ld4s"; /* prefetch_l3_fault */
2134 case OEY2(LD4U_OPCODE_Y2
, MODE_OPCODE_YB2
):
2136 mnemonic
= "ld4u"; /* prefetch_l3 */
2137 prefetch_nofault
= (srcbdest
== TILEGX_R_ZERO
);
2139 case OEY2(LD_OPCODE_Y2
, MODE_OPCODE_YB2
):
2143 if (!prefetch_nofault
) {
2144 tcg_gen_qemu_ld_tl(dest_gr(dc
, srcbdest
), load_gr(dc
, srca
),
2147 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "%s %s, %s", mnemonic
,
2148 reg_names
[srcbdest
], reg_names
[srca
]);
2149 return TILEGX_EXCP_NONE
;
2151 case OEY2(ST1_OPCODE_Y2
, MODE_OPCODE_YC2
):
2152 return gen_st_opcode(dc
, 0, srca
, srcbdest
, MO_UB
, "st1");
2153 case OEY2(ST2_OPCODE_Y2
, MODE_OPCODE_YC2
):
2154 return gen_st_opcode(dc
, 0, srca
, srcbdest
, MO_TEUW
, "st2");
2155 case OEY2(ST4_OPCODE_Y2
, MODE_OPCODE_YC2
):
2156 return gen_st_opcode(dc
, 0, srca
, srcbdest
, MO_TEUL
, "st4");
2157 case OEY2(ST_OPCODE_Y2
, MODE_OPCODE_YC2
):
2158 return gen_st_opcode(dc
, 0, srca
, srcbdest
, MO_TEQ
, "st");
2161 return TILEGX_EXCP_OPCODE_UNKNOWN
;
2165 static TileExcp
decode_x0(DisasContext
*dc
, tilegx_bundle_bits bundle
)
2167 unsigned opc
= get_Opcode_X0(bundle
);
2168 unsigned dest
= get_Dest_X0(bundle
);
2169 unsigned srca
= get_SrcA_X0(bundle
);
2170 unsigned ext
, srcb
, bfs
, bfe
;
2174 case RRR_0_OPCODE_X0
:
2175 ext
= get_RRROpcodeExtension_X0(bundle
);
2176 if (ext
== UNARY_RRR_0_OPCODE_X0
) {
2177 ext
= get_UnaryOpcodeExtension_X0(bundle
);
2178 return gen_rr_opcode(dc
, OE(opc
, ext
, X0
), dest
, srca
, bundle
);
2180 srcb
= get_SrcB_X0(bundle
);
2181 return gen_rrr_opcode(dc
, OE(opc
, ext
, X0
), dest
, srca
, srcb
);
2183 case SHIFT_OPCODE_X0
:
2184 ext
= get_ShiftOpcodeExtension_X0(bundle
);
2185 imm
= get_ShAmt_X0(bundle
);
2186 return gen_rri_opcode(dc
, OE(opc
, ext
, X0
), dest
, srca
, imm
);
2188 case IMM8_OPCODE_X0
:
2189 ext
= get_Imm8OpcodeExtension_X0(bundle
);
2190 imm
= (int8_t)get_Imm8_X0(bundle
);
2191 return gen_rri_opcode(dc
, OE(opc
, ext
, X0
), dest
, srca
, imm
);
2194 ext
= get_BFOpcodeExtension_X0(bundle
);
2195 bfs
= get_BFStart_X0(bundle
);
2196 bfe
= get_BFEnd_X0(bundle
);
2197 return gen_bf_opcode_x0(dc
, ext
, dest
, srca
, bfs
, bfe
);
2199 case ADDLI_OPCODE_X0
:
2200 case SHL16INSLI_OPCODE_X0
:
2201 case ADDXLI_OPCODE_X0
:
2202 imm
= (int16_t)get_Imm16_X0(bundle
);
2203 return gen_rri_opcode(dc
, OE(opc
, 0, X0
), dest
, srca
, imm
);
2206 return TILEGX_EXCP_OPCODE_UNKNOWN
;
2210 static TileExcp
decode_x1(DisasContext
*dc
, tilegx_bundle_bits bundle
)
2212 unsigned opc
= get_Opcode_X1(bundle
);
2213 unsigned dest
= get_Dest_X1(bundle
);
2214 unsigned srca
= get_SrcA_X1(bundle
);
2219 case RRR_0_OPCODE_X1
:
2220 ext
= get_RRROpcodeExtension_X1(bundle
);
2221 srcb
= get_SrcB_X1(bundle
);
2223 case UNARY_RRR_0_OPCODE_X1
:
2224 ext
= get_UnaryOpcodeExtension_X1(bundle
);
2225 return gen_rr_opcode(dc
, OE(opc
, ext
, X1
), dest
, srca
, bundle
);
2226 case ST1_RRR_0_OPCODE_X1
:
2227 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_UB
, "st1");
2228 case ST2_RRR_0_OPCODE_X1
:
2229 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEUW
, "st2");
2230 case ST4_RRR_0_OPCODE_X1
:
2231 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEUL
, "st4");
2232 case STNT1_RRR_0_OPCODE_X1
:
2233 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_UB
, "stnt1");
2234 case STNT2_RRR_0_OPCODE_X1
:
2235 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEUW
, "stnt2");
2236 case STNT4_RRR_0_OPCODE_X1
:
2237 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEUL
, "stnt4");
2238 case STNT_RRR_0_OPCODE_X1
:
2239 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEQ
, "stnt");
2240 case ST_RRR_0_OPCODE_X1
:
2241 return gen_st_opcode(dc
, dest
, srca
, srcb
, MO_TEQ
, "st");
2243 return gen_rrr_opcode(dc
, OE(opc
, ext
, X1
), dest
, srca
, srcb
);
2245 case SHIFT_OPCODE_X1
:
2246 ext
= get_ShiftOpcodeExtension_X1(bundle
);
2247 imm
= get_ShAmt_X1(bundle
);
2248 return gen_rri_opcode(dc
, OE(opc
, ext
, X1
), dest
, srca
, imm
);
2250 case IMM8_OPCODE_X1
:
2251 ext
= get_Imm8OpcodeExtension_X1(bundle
);
2252 imm
= (int8_t)get_Dest_Imm8_X1(bundle
);
2253 srcb
= get_SrcB_X1(bundle
);
2255 case ST1_ADD_IMM8_OPCODE_X1
:
2256 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_UB
, "st1_add");
2257 case ST2_ADD_IMM8_OPCODE_X1
:
2258 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEUW
, "st2_add");
2259 case ST4_ADD_IMM8_OPCODE_X1
:
2260 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEUL
, "st4_add");
2261 case STNT1_ADD_IMM8_OPCODE_X1
:
2262 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_UB
, "stnt1_add");
2263 case STNT2_ADD_IMM8_OPCODE_X1
:
2264 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEUW
, "stnt2_add");
2265 case STNT4_ADD_IMM8_OPCODE_X1
:
2266 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEUL
, "stnt4_add");
2267 case STNT_ADD_IMM8_OPCODE_X1
:
2268 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEQ
, "stnt_add");
2269 case ST_ADD_IMM8_OPCODE_X1
:
2270 return gen_st_add_opcode(dc
, srca
, srcb
, imm
, MO_TEQ
, "st_add");
2271 case MFSPR_IMM8_OPCODE_X1
:
2272 return gen_mfspr_x1(dc
, dest
, get_MF_Imm14_X1(bundle
));
2273 case MTSPR_IMM8_OPCODE_X1
:
2274 return gen_mtspr_x1(dc
, get_MT_Imm14_X1(bundle
), srca
);
2276 imm
= (int8_t)get_Imm8_X1(bundle
);
2277 return gen_rri_opcode(dc
, OE(opc
, ext
, X1
), dest
, srca
, imm
);
2279 case BRANCH_OPCODE_X1
:
2280 ext
= get_BrType_X1(bundle
);
2281 imm
= sextract32(get_BrOff_X1(bundle
), 0, 17);
2282 return gen_branch_opcode_x1(dc
, ext
, srca
, imm
);
2284 case JUMP_OPCODE_X1
:
2285 ext
= get_JumpOpcodeExtension_X1(bundle
);
2286 imm
= sextract32(get_JumpOff_X1(bundle
), 0, 27);
2287 return gen_jump_opcode_x1(dc
, ext
, imm
);
2289 case ADDLI_OPCODE_X1
:
2290 case SHL16INSLI_OPCODE_X1
:
2291 case ADDXLI_OPCODE_X1
:
2292 imm
= (int16_t)get_Imm16_X1(bundle
);
2293 return gen_rri_opcode(dc
, OE(opc
, 0, X1
), dest
, srca
, imm
);
2296 return TILEGX_EXCP_OPCODE_UNKNOWN
;
2300 static void notice_excp(DisasContext
*dc
, uint64_t bundle
,
2301 const char *type
, TileExcp excp
)
2303 if (likely(excp
== TILEGX_EXCP_NONE
)) {
2306 gen_exception(dc
, excp
);
2308 case TILEGX_EXCP_OPCODE_UNIMPLEMENTED
:
2309 qemu_log_mask(LOG_UNIMP
, "UNIMP %s, [" FMT64X
"]\n", type
, bundle
);
2311 case TILEGX_EXCP_OPCODE_UNKNOWN
:
2312 qemu_log_mask(LOG_UNIMP
, "UNKNOWN %s, [" FMT64X
"]\n", type
, bundle
);
2319 static void translate_one_bundle(DisasContext
*dc
, uint64_t bundle
)
2323 for (i
= 0; i
< ARRAY_SIZE(dc
->wb
); i
++) {
2324 DisasContextTemp
*wb
= &dc
->wb
[i
];
2325 wb
->reg
= TILEGX_R_NOREG
;
2326 TCGV_UNUSED_I64(wb
->val
);
2330 qemu_log_mask(CPU_LOG_TB_IN_ASM
, " %" PRIx64
": { ", dc
->pc
);
2331 if (get_Mode(bundle
)) {
2332 notice_excp(dc
, bundle
, "y0", decode_y0(dc
, bundle
));
2333 qemu_log_mask(CPU_LOG_TB_IN_ASM
, " ; ");
2334 notice_excp(dc
, bundle
, "y1", decode_y1(dc
, bundle
));
2335 qemu_log_mask(CPU_LOG_TB_IN_ASM
, " ; ");
2336 notice_excp(dc
, bundle
, "y2", decode_y2(dc
, bundle
));
2338 notice_excp(dc
, bundle
, "x0", decode_x0(dc
, bundle
));
2339 qemu_log_mask(CPU_LOG_TB_IN_ASM
, " ; ");
2340 notice_excp(dc
, bundle
, "x1", decode_x1(dc
, bundle
));
2342 qemu_log_mask(CPU_LOG_TB_IN_ASM
, " }\n");
2344 for (i
= dc
->num_wb
- 1; i
>= 0; --i
) {
2345 DisasContextTemp
*wb
= &dc
->wb
[i
];
2346 if (wb
->reg
< TILEGX_R_COUNT
) {
2347 tcg_gen_mov_i64(cpu_regs
[wb
->reg
], wb
->val
);
2349 tcg_temp_free_i64(wb
->val
);
2352 if (dc
->jmp
.cond
!= TCG_COND_NEVER
) {
2353 if (dc
->jmp
.cond
== TCG_COND_ALWAYS
) {
2354 tcg_gen_mov_i64(cpu_pc
, dc
->jmp
.dest
);
2356 TCGv next
= tcg_const_i64(dc
->pc
+ TILEGX_BUNDLE_SIZE_IN_BYTES
);
2357 tcg_gen_movcond_i64(dc
->jmp
.cond
, cpu_pc
,
2358 dc
->jmp
.val1
, load_zero(dc
),
2359 dc
->jmp
.dest
, next
);
2360 tcg_temp_free_i64(dc
->jmp
.val1
);
2361 tcg_temp_free_i64(next
);
2363 tcg_temp_free_i64(dc
->jmp
.dest
);
2366 } else if (dc
->atomic_excp
!= TILEGX_EXCP_NONE
) {
2367 gen_exception(dc
, dc
->atomic_excp
);
2371 void gen_intermediate_code(CPUTLGState
*env
, struct TranslationBlock
*tb
)
2373 TileGXCPU
*cpu
= tilegx_env_get_cpu(env
);
2375 DisasContext
*dc
= &ctx
;
2376 CPUState
*cs
= CPU(cpu
);
2377 uint64_t pc_start
= tb
->pc
;
2378 uint64_t next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2380 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2384 dc
->exit_tb
= false;
2385 dc
->atomic_excp
= TILEGX_EXCP_NONE
;
2386 dc
->jmp
.cond
= TCG_COND_NEVER
;
2387 TCGV_UNUSED_I64(dc
->jmp
.dest
);
2388 TCGV_UNUSED_I64(dc
->jmp
.val1
);
2389 TCGV_UNUSED_I64(dc
->zero
);
2391 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
2392 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
2395 max_insns
= CF_COUNT_MASK
;
2397 if (cs
->singlestep_enabled
|| singlestep
) {
2400 if (max_insns
> TCG_MAX_INSNS
) {
2401 max_insns
= TCG_MAX_INSNS
;
2406 tcg_gen_insn_start(dc
->pc
);
2409 translate_one_bundle(dc
, cpu_ldq_data(env
, dc
->pc
));
2412 /* PC updated and EXIT_TB/GOTO_TB/exception emitted. */
2415 dc
->pc
+= TILEGX_BUNDLE_SIZE_IN_BYTES
;
2416 if (num_insns
>= max_insns
2417 || dc
->pc
>= next_page_start
2418 || tcg_op_buf_full()) {
2419 /* Ending the TB due to TB size or page boundary. Set PC. */
2420 tcg_gen_movi_tl(cpu_pc
, dc
->pc
);
2426 gen_tb_end(tb
, num_insns
);
2427 tb
->size
= dc
->pc
- pc_start
;
2428 tb
->icount
= num_insns
;
2430 qemu_log_mask(CPU_LOG_TB_IN_ASM
, "\n");
2433 void restore_state_to_opc(CPUTLGState
*env
, TranslationBlock
*tb
,
2439 void tilegx_tcg_init(void)
2443 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
2444 cpu_pc
= tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUTLGState
, pc
), "pc");
2445 for (i
= 0; i
< TILEGX_R_COUNT
; i
++) {
2446 cpu_regs
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
2447 offsetof(CPUTLGState
, regs
[i
]),