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 "opcode_tilegx.h"
27 #include "spr_def_64.h"
29 #define FMT64X "%016" PRIx64
31 static TCGv_ptr cpu_env;
33 static TCGv cpu_regs[TILEGX_R_COUNT];
35 static const char * const reg_names[64] = {
36 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
37 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
38 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
39 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
40 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
41 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
42 "r48", "r49", "r50", "r51", "bp", "tp", "sp", "lr",
43 "sn", "idn0", "idn1", "udn0", "udn1", "udn2", "udn2", "zero"
46 /* Modified registers are cached in temporaries until the end of the bundle. */
52 #define MAX_WRITEBACK 4
54 /* This is the state at translation time. */
56 uint64_t pc; /* Current pc */
58 TCGv zero; /* For zero register */
60 DisasContextTemp wb[MAX_WRITEBACK];
67 TCGCond cond; /* branch condition */
68 TCGv dest; /* branch destination */
69 TCGv val1; /* value to be compared against zero, for cond */
70 } jmp; /* Jump object, only once in each TB block */
73 #include "exec/gen-icount.h"
75 /* Differentiate the various pipe encodings. */
81 /* Remerge the base opcode and extension fields for switching.
82 The X opcode fields are 3 bits; Y0/Y1 opcode fields are 4 bits;
83 Y2 opcode field is 2 bits. */
84 #define OE(OP, EXT, XY) (TY_##XY + OP * 4 + EXT * 64)
86 /* Similar, but for Y2 only. */
87 #define OEY2(OP, MODE) (OP + MODE * 4)
89 /* Similar, but make sure opcode names match up. */
90 #define OE_RR_X0(E) OE(RRR_0_OPCODE_X0, E##_UNARY_OPCODE_X0, X0)
91 #define OE_RR_X1(E) OE(RRR_0_OPCODE_X1, E##_UNARY_OPCODE_X1, X1)
92 #define OE_RR_Y0(E) OE(RRR_1_OPCODE_Y0, E##_UNARY_OPCODE_Y0, Y0)
93 #define OE_RR_Y1(E) OE(RRR_1_OPCODE_Y1, E##_UNARY_OPCODE_Y1, Y1)
94 #define OE_RRR(E,N,XY) OE(RRR_##N##_OPCODE_##XY, E##_RRR_##N##_OPCODE_##XY, XY)
95 #define OE_IM(E,XY) OE(IMM8_OPCODE_##XY, E##_IMM8_OPCODE_##XY, XY)
96 #define OE_SH(E,XY) OE(SHIFT_OPCODE_##XY, E##_SHIFT_OPCODE_##XY, XY)
98 #define V1_IMM(X) (((X) & 0xff) * 0x0101010101010101ull)
99 #define V2_IMM(X) (((X) & 0xffff) * 0x0001000100010001ull)
102 static void gen_exception(DisasContext *dc, TileExcp num)
106 tcg_gen_movi_tl(cpu_pc, dc->pc + TILEGX_BUNDLE_SIZE_IN_BYTES);
108 tmp = tcg_const_i32(num);
109 gen_helper_exception(cpu_env, tmp);
110 tcg_temp_free_i32(tmp);
114 static bool check_gr(DisasContext *dc, uint8_t reg)
116 if (likely(reg < TILEGX_R_COUNT)) {
126 gen_exception(dc, TILEGX_EXCP_REG_IDN_ACCESS);
132 gen_exception(dc, TILEGX_EXCP_REG_UDN_ACCESS);
135 g_assert_not_reached();
140 static TCGv load_zero(DisasContext *dc)
142 if (TCGV_IS_UNUSED_I64(dc->zero)) {
143 dc->zero = tcg_const_i64(0);
148 static TCGv load_gr(DisasContext *dc, unsigned reg)
150 if (check_gr(dc, reg)) {
151 return cpu_regs[reg];
153 return load_zero(dc);
156 static TCGv dest_gr(DisasContext *dc, unsigned reg)
160 /* Skip the result, mark the exception if necessary, and continue */
165 return dc->wb[n].val = tcg_temp_new_i64();
168 static void gen_saturate_op(TCGv tdest, TCGv tsrca, TCGv tsrcb,
169 void (*operate)(TCGv, TCGv, TCGv))
171 TCGv t0 = tcg_temp_new();
173 tcg_gen_ext32s_tl(tdest, tsrca);
174 tcg_gen_ext32s_tl(t0, tsrcb);
175 operate(tdest, tdest, t0);
177 tcg_gen_movi_tl(t0, 0x7fffffff);
178 tcg_gen_movcond_tl(TCG_COND_GT, tdest, tdest, t0, t0, tdest);
179 tcg_gen_movi_tl(t0, -0x80000000LL);
180 tcg_gen_movcond_tl(TCG_COND_LT, tdest, tdest, t0, t0, tdest);
185 static void gen_atomic_excp(DisasContext *dc, unsigned dest, TCGv tdest,
186 TCGv tsrca, TCGv tsrcb, TileExcp excp)
188 #ifdef CONFIG_USER_ONLY
191 tcg_gen_st_tl(tsrca, cpu_env, offsetof(CPUTLGState, atomic_srca));
192 tcg_gen_st_tl(tsrcb, cpu_env, offsetof(CPUTLGState, atomic_srcb));
193 t = tcg_const_i32(dest);
194 tcg_gen_st_i32(t, cpu_env, offsetof(CPUTLGState, atomic_dstr));
195 tcg_temp_free_i32(t);
197 /* We're going to write the real result in the exception. But in
198 the meantime we've already created a writeback register, and
199 we don't want that to remain uninitialized. */
200 tcg_gen_movi_tl(tdest, 0);
202 /* Note that we need to delay issuing the exception that implements
203 the atomic operation until after writing back the results of the
204 instruction occupying the X0 pipe. */
205 dc->atomic_excp = excp;
207 gen_exception(dc, TILEGX_EXCP_OPCODE_UNIMPLEMENTED);
211 /* Shift the 128-bit value TSRCA:TSRCD right by the number of bytes
212 specified by the bottom 3 bits of TSRCB, and set TDEST to the
213 low 64 bits of the resulting value. */
214 static void gen_dblalign(TCGv tdest, TCGv tsrcd, TCGv tsrca, TCGv tsrcb)
216 TCGv t0 = tcg_temp_new();
218 tcg_gen_andi_tl(t0, tsrcb, 7);
219 tcg_gen_shli_tl(t0, t0, 3);
220 tcg_gen_shr_tl(tdest, tsrcd, t0);
222 /* We want to do "t0 = tsrca << (64 - t0)". Two's complement
223 arithmetic on a 6-bit field tells us that 64 - t0 is equal
224 to (t0 ^ 63) + 1. So we can do the shift in two parts,
225 neither of which will be an invalid shift by 64. */
226 tcg_gen_xori_tl(t0, t0, 63);
227 tcg_gen_shl_tl(t0, tsrca, t0);
228 tcg_gen_shli_tl(t0, t0, 1);
229 tcg_gen_or_tl(tdest, tdest, t0);
234 /* Similarly, except that the 128-bit value is TSRCA:TSRCB, and the
235 right shift is an immediate. */
236 static void gen_dblaligni(TCGv tdest, TCGv tsrca, TCGv tsrcb, int shr)
238 TCGv t0 = tcg_temp_new();
240 tcg_gen_shri_tl(t0, tsrcb, shr);
241 tcg_gen_shli_tl(tdest, tsrca, 64 - shr);
242 tcg_gen_or_tl(tdest, tdest, t0);
251 static void gen_ext_half(TCGv d, TCGv s, MulHalf h)
255 tcg_gen_ext32u_tl(d, s);
258 tcg_gen_ext32s_tl(d, s);
261 tcg_gen_shri_tl(d, s, 32);
264 tcg_gen_sari_tl(d, s, 32);
269 static void gen_mul_half(TCGv tdest, TCGv tsrca, TCGv tsrcb,
270 MulHalf ha, MulHalf hb)
272 TCGv t = tcg_temp_new();
273 gen_ext_half(t, tsrca, ha);
274 gen_ext_half(tdest, tsrcb, hb);
275 tcg_gen_mul_tl(tdest, tdest, t);
279 static TileExcp gen_st_opcode(DisasContext *dc, unsigned dest, unsigned srca,
280 unsigned srcb, TCGMemOp memop, const char *name)
283 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
286 tcg_gen_qemu_st_tl(load_gr(dc, srcb), load_gr(dc, srca),
289 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s", name,
290 reg_names[srca], reg_names[srcb]);
291 return TILEGX_EXCP_NONE;
294 static TileExcp gen_st_add_opcode(DisasContext *dc, unsigned srca, unsigned srcb,
295 int imm, TCGMemOp memop, const char *name)
297 TCGv tsrca = load_gr(dc, srca);
298 TCGv tsrcb = load_gr(dc, srcb);
300 tcg_gen_qemu_st_tl(tsrcb, tsrca, dc->mmuidx, memop);
301 tcg_gen_addi_tl(dest_gr(dc, srca), tsrca, imm);
303 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s, %d", name,
304 reg_names[srca], reg_names[srcb], imm);
305 return TILEGX_EXCP_NONE;
308 /* Equality comparison with zero can be done quickly and efficiently. */
309 static void gen_v1cmpeq0(TCGv v)
311 TCGv m = tcg_const_tl(V1_IMM(0x7f));
312 TCGv c = tcg_temp_new();
314 /* ~(((v & m) + m) | m | v). Sets the msb for each byte == 0. */
315 tcg_gen_and_tl(c, v, m);
316 tcg_gen_add_tl(c, c, m);
317 tcg_gen_or_tl(c, c, m);
318 tcg_gen_nor_tl(c, c, v);
321 /* Shift the msb down to form the lsb boolean result. */
322 tcg_gen_shri_tl(v, c, 7);
326 static void gen_v1cmpne0(TCGv v)
328 TCGv m = tcg_const_tl(V1_IMM(0x7f));
329 TCGv c = tcg_temp_new();
331 /* (((v & m) + m) | v) & ~m. Sets the msb for each byte != 0. */
332 tcg_gen_and_tl(c, v, m);
333 tcg_gen_add_tl(c, c, m);
334 tcg_gen_or_tl(c, c, v);
335 tcg_gen_andc_tl(c, c, m);
338 /* Shift the msb down to form the lsb boolean result. */
339 tcg_gen_shri_tl(v, c, 7);
343 /* Vector addition can be performed via arithmetic plus masking. It is
344 efficient this way only for 4 or more elements. */
345 static void gen_v12add(TCGv tdest, TCGv tsrca, TCGv tsrcb, uint64_t sign)
347 TCGv tmask = tcg_const_tl(~sign);
348 TCGv t0 = tcg_temp_new();
349 TCGv t1 = tcg_temp_new();
351 /* ((a & ~sign) + (b & ~sign)) ^ ((a ^ b) & sign). */
352 tcg_gen_and_tl(t0, tsrca, tmask);
353 tcg_gen_and_tl(t1, tsrcb, tmask);
354 tcg_gen_add_tl(tdest, t0, t1);
355 tcg_gen_xor_tl(t0, tsrca, tsrcb);
356 tcg_gen_andc_tl(t0, t0, tmask);
357 tcg_gen_xor_tl(tdest, tdest, t0);
361 tcg_temp_free(tmask);
364 /* Similarly for vector subtraction. */
365 static void gen_v12sub(TCGv tdest, TCGv tsrca, TCGv tsrcb, uint64_t sign)
367 TCGv tsign = tcg_const_tl(sign);
368 TCGv t0 = tcg_temp_new();
369 TCGv t1 = tcg_temp_new();
371 /* ((a | sign) - (b & ~sign)) ^ ((a ^ ~b) & sign). */
372 tcg_gen_or_tl(t0, tsrca, tsign);
373 tcg_gen_andc_tl(t1, tsrcb, tsign);
374 tcg_gen_sub_tl(tdest, t0, t1);
375 tcg_gen_eqv_tl(t0, tsrca, tsrcb);
376 tcg_gen_and_tl(t0, t0, tsign);
377 tcg_gen_xor_tl(tdest, tdest, t0);
381 tcg_temp_free(tsign);
384 static void gen_v4sh(TCGv d64, TCGv a64, TCGv b64,
385 void (*generate)(TCGv_i32, TCGv_i32, TCGv_i32))
387 TCGv_i32 al = tcg_temp_new_i32();
388 TCGv_i32 ah = tcg_temp_new_i32();
389 TCGv_i32 bl = tcg_temp_new_i32();
391 tcg_gen_extr_i64_i32(al, ah, a64);
392 tcg_gen_extrl_i64_i32(bl, b64);
393 tcg_gen_andi_i32(bl, bl, 31);
394 generate(al, al, bl);
395 generate(ah, ah, bl);
396 tcg_gen_concat_i32_i64(d64, al, ah);
398 tcg_temp_free_i32(al);
399 tcg_temp_free_i32(ah);
400 tcg_temp_free_i32(bl);
403 static void gen_v4op(TCGv d64, TCGv a64, TCGv b64,
404 void (*generate)(TCGv_i32, TCGv_i32, TCGv_i32))
406 TCGv_i32 al = tcg_temp_new_i32();
407 TCGv_i32 ah = tcg_temp_new_i32();
408 TCGv_i32 bl = tcg_temp_new_i32();
409 TCGv_i32 bh = tcg_temp_new_i32();
411 tcg_gen_extr_i64_i32(al, ah, a64);
412 tcg_gen_extr_i64_i32(bl, bh, b64);
413 generate(al, al, bl);
414 generate(ah, ah, bh);
415 tcg_gen_concat_i32_i64(d64, al, ah);
417 tcg_temp_free_i32(al);
418 tcg_temp_free_i32(ah);
419 tcg_temp_free_i32(bl);
420 tcg_temp_free_i32(bh);
423 static TileExcp gen_rr_opcode(DisasContext *dc, unsigned opext,
424 unsigned dest, unsigned srca)
427 const char *mnemonic;
429 TileExcp ret = TILEGX_EXCP_NONE;
431 /* Eliminate instructions with no output before doing anything else. */
445 case OE_RR_X1(DRAIN):
448 case OE_RR_X1(FLUSHWB):
449 mnemonic = "flushwb";
453 mnemonic = (dest == 0x1c && srca == 0x25 ? "bpt" : "ill");
454 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s", mnemonic);
455 return TILEGX_EXCP_OPCODE_UNKNOWN;
460 /* ??? This should yield, especially in system mode. */
463 case OE_RR_X1(SWINT0):
464 case OE_RR_X1(SWINT2):
465 case OE_RR_X1(SWINT3):
466 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
467 case OE_RR_X1(SWINT1):
468 ret = TILEGX_EXCP_SYSCALL;
472 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
474 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s", mnemonic);
477 case OE_RR_X1(DTLBPR):
478 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
482 case OE_RR_X1(FLUSH):
502 case OE_RR_X1(JALRP):
503 case OE_RR_Y1(JALRP):
510 tcg_gen_movi_tl(dest_gr(dc, TILEGX_R_LR),
511 dc->pc + TILEGX_BUNDLE_SIZE_IN_BYTES);
513 dc->jmp.cond = TCG_COND_ALWAYS;
514 dc->jmp.dest = tcg_temp_new();
515 tcg_gen_andi_tl(dc->jmp.dest, load_gr(dc, srca), ~7);
518 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
520 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s", mnemonic, reg_names[srca]);
524 tdest = dest_gr(dc, dest);
525 tsrca = load_gr(dc, srca);
528 case OE_RR_X0(CNTLZ):
529 case OE_RR_Y0(CNTLZ):
530 gen_helper_cntlz(tdest, tsrca);
533 case OE_RR_X0(CNTTZ):
534 case OE_RR_Y0(CNTTZ):
535 gen_helper_cnttz(tdest, tsrca);
538 case OE_RR_X0(FSINGLE_PACK1):
539 case OE_RR_Y0(FSINGLE_PACK1):
541 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
566 case OE_RR_X1(LDNT1S):
570 case OE_RR_X1(LDNT1U):
574 case OE_RR_X1(LDNT2S):
578 case OE_RR_X1(LDNT2U):
582 case OE_RR_X1(LDNT4S):
586 case OE_RR_X1(LDNT4U):
598 tcg_gen_qemu_ld_tl(tdest, tsrca, dc->mmuidx, memop);
601 tcg_gen_andi_tl(tdest, tsrca, ~7);
602 tcg_gen_qemu_ld_tl(tdest, tdest, dc->mmuidx, MO_TEQ);
608 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
610 tcg_gen_movi_tl(tdest, dc->pc + TILEGX_BUNDLE_SIZE_IN_BYTES);
615 gen_helper_pcnt(tdest, tsrca);
618 case OE_RR_X0(REVBITS):
619 case OE_RR_Y0(REVBITS):
620 gen_helper_revbits(tdest, tsrca);
621 mnemonic = "revbits";
623 case OE_RR_X0(REVBYTES):
624 case OE_RR_Y0(REVBYTES):
625 tcg_gen_bswap64_tl(tdest, tsrca);
626 mnemonic = "revbytes";
628 case OE_RR_X0(TBLIDXB0):
629 case OE_RR_Y0(TBLIDXB0):
630 tcg_gen_deposit_tl(tdest, load_gr(dc, dest), tsrca, 2, 8);
631 mnemonic = "tblidxb0";
633 case OE_RR_X0(TBLIDXB1):
634 case OE_RR_Y0(TBLIDXB1):
635 tcg_gen_shri_tl(tdest, tsrca, 8);
636 tcg_gen_deposit_tl(tdest, load_gr(dc, dest), tdest, 2, 8);
637 mnemonic = "tblidxb1";
639 case OE_RR_X0(TBLIDXB2):
640 case OE_RR_Y0(TBLIDXB2):
641 tcg_gen_shri_tl(tdest, tsrca, 16);
642 tcg_gen_deposit_tl(tdest, load_gr(dc, dest), tdest, 2, 8);
643 mnemonic = "tblidxb2";
645 case OE_RR_X0(TBLIDXB3):
646 case OE_RR_Y0(TBLIDXB3):
647 tcg_gen_shri_tl(tdest, tsrca, 24);
648 tcg_gen_deposit_tl(tdest, load_gr(dc, dest), tdest, 2, 8);
649 mnemonic = "tblidxb3";
652 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
655 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s", mnemonic,
656 reg_names[dest], reg_names[srca]);
660 static TileExcp gen_rrr_opcode(DisasContext *dc, unsigned opext,
661 unsigned dest, unsigned srca, unsigned srcb)
663 TCGv tdest = dest_gr(dc, dest);
664 TCGv tsrca = load_gr(dc, srca);
665 TCGv tsrcb = load_gr(dc, srcb);
667 const char *mnemonic;
670 case OE_RRR(ADDXSC, 0, X0):
671 case OE_RRR(ADDXSC, 0, X1):
672 gen_saturate_op(tdest, tsrca, tsrcb, tcg_gen_add_tl);
675 case OE_RRR(ADDX, 0, X0):
676 case OE_RRR(ADDX, 0, X1):
677 case OE_RRR(ADDX, 0, Y0):
678 case OE_RRR(ADDX, 0, Y1):
679 tcg_gen_add_tl(tdest, tsrca, tsrcb);
680 tcg_gen_ext32s_tl(tdest, tdest);
683 case OE_RRR(ADD, 0, X0):
684 case OE_RRR(ADD, 0, X1):
685 case OE_RRR(ADD, 0, Y0):
686 case OE_RRR(ADD, 0, Y1):
687 tcg_gen_add_tl(tdest, tsrca, tsrcb);
690 case OE_RRR(AND, 0, X0):
691 case OE_RRR(AND, 0, X1):
692 case OE_RRR(AND, 5, Y0):
693 case OE_RRR(AND, 5, Y1):
694 tcg_gen_and_tl(tdest, tsrca, tsrcb);
697 case OE_RRR(CMOVEQZ, 0, X0):
698 case OE_RRR(CMOVEQZ, 4, Y0):
699 tcg_gen_movcond_tl(TCG_COND_EQ, tdest, tsrca, load_zero(dc),
700 tsrcb, load_gr(dc, dest));
701 mnemonic = "cmoveqz";
703 case OE_RRR(CMOVNEZ, 0, X0):
704 case OE_RRR(CMOVNEZ, 4, Y0):
705 tcg_gen_movcond_tl(TCG_COND_NE, tdest, tsrca, load_zero(dc),
706 tsrcb, load_gr(dc, dest));
707 mnemonic = "cmovnez";
709 case OE_RRR(CMPEQ, 0, X0):
710 case OE_RRR(CMPEQ, 0, X1):
711 case OE_RRR(CMPEQ, 3, Y0):
712 case OE_RRR(CMPEQ, 3, Y1):
713 tcg_gen_setcond_tl(TCG_COND_EQ, tdest, tsrca, tsrcb);
716 case OE_RRR(CMPEXCH4, 0, X1):
717 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
718 TILEGX_EXCP_OPCODE_CMPEXCH4);
719 mnemonic = "cmpexch4";
721 case OE_RRR(CMPEXCH, 0, X1):
722 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
723 TILEGX_EXCP_OPCODE_CMPEXCH);
724 mnemonic = "cmpexch";
726 case OE_RRR(CMPLES, 0, X0):
727 case OE_RRR(CMPLES, 0, X1):
728 case OE_RRR(CMPLES, 2, Y0):
729 case OE_RRR(CMPLES, 2, Y1):
730 tcg_gen_setcond_tl(TCG_COND_LE, tdest, tsrca, tsrcb);
733 case OE_RRR(CMPLEU, 0, X0):
734 case OE_RRR(CMPLEU, 0, X1):
735 case OE_RRR(CMPLEU, 2, Y0):
736 case OE_RRR(CMPLEU, 2, Y1):
737 tcg_gen_setcond_tl(TCG_COND_LEU, tdest, tsrca, tsrcb);
740 case OE_RRR(CMPLTS, 0, X0):
741 case OE_RRR(CMPLTS, 0, X1):
742 case OE_RRR(CMPLTS, 2, Y0):
743 case OE_RRR(CMPLTS, 2, Y1):
744 tcg_gen_setcond_tl(TCG_COND_LT, tdest, tsrca, tsrcb);
747 case OE_RRR(CMPLTU, 0, X0):
748 case OE_RRR(CMPLTU, 0, X1):
749 case OE_RRR(CMPLTU, 2, Y0):
750 case OE_RRR(CMPLTU, 2, Y1):
751 tcg_gen_setcond_tl(TCG_COND_LTU, tdest, tsrca, tsrcb);
754 case OE_RRR(CMPNE, 0, X0):
755 case OE_RRR(CMPNE, 0, X1):
756 case OE_RRR(CMPNE, 3, Y0):
757 case OE_RRR(CMPNE, 3, Y1):
758 tcg_gen_setcond_tl(TCG_COND_NE, tdest, tsrca, tsrcb);
761 case OE_RRR(CMULAF, 0, X0):
762 case OE_RRR(CMULA, 0, X0):
763 case OE_RRR(CMULFR, 0, X0):
764 case OE_RRR(CMULF, 0, X0):
765 case OE_RRR(CMULHR, 0, X0):
766 case OE_RRR(CMULH, 0, X0):
767 case OE_RRR(CMUL, 0, X0):
768 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
769 case OE_RRR(CRC32_32, 0, X0):
770 gen_helper_crc32_32(tdest, tsrca, tsrcb);
771 mnemonic = "crc32_32";
773 case OE_RRR(CRC32_8, 0, X0):
774 gen_helper_crc32_8(tdest, tsrca, tsrcb);
775 mnemonic = "crc32_8";
777 case OE_RRR(DBLALIGN2, 0, X0):
778 case OE_RRR(DBLALIGN2, 0, X1):
779 gen_dblaligni(tdest, tsrca, tsrcb, 16);
780 mnemonic = "dblalign2";
782 case OE_RRR(DBLALIGN4, 0, X0):
783 case OE_RRR(DBLALIGN4, 0, X1):
784 gen_dblaligni(tdest, tsrca, tsrcb, 32);
785 mnemonic = "dblalign4";
787 case OE_RRR(DBLALIGN6, 0, X0):
788 case OE_RRR(DBLALIGN6, 0, X1):
789 gen_dblaligni(tdest, tsrca, tsrcb, 48);
790 mnemonic = "dblalign6";
792 case OE_RRR(DBLALIGN, 0, X0):
793 gen_dblalign(tdest, load_gr(dc, dest), tsrca, tsrcb);
794 mnemonic = "dblalign";
796 case OE_RRR(EXCH4, 0, X1):
797 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
798 TILEGX_EXCP_OPCODE_EXCH4);
801 case OE_RRR(EXCH, 0, X1):
802 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
803 TILEGX_EXCP_OPCODE_EXCH);
806 case OE_RRR(FDOUBLE_ADDSUB, 0, X0):
807 case OE_RRR(FDOUBLE_ADD_FLAGS, 0, X0):
808 case OE_RRR(FDOUBLE_MUL_FLAGS, 0, X0):
809 case OE_RRR(FDOUBLE_PACK1, 0, X0):
810 case OE_RRR(FDOUBLE_PACK2, 0, X0):
811 case OE_RRR(FDOUBLE_SUB_FLAGS, 0, X0):
812 case OE_RRR(FDOUBLE_UNPACK_MAX, 0, X0):
813 case OE_RRR(FDOUBLE_UNPACK_MIN, 0, X0):
814 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
815 case OE_RRR(FETCHADD4, 0, X1):
816 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
817 TILEGX_EXCP_OPCODE_FETCHADD4);
818 mnemonic = "fetchadd4";
820 case OE_RRR(FETCHADDGEZ4, 0, X1):
821 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
822 TILEGX_EXCP_OPCODE_FETCHADDGEZ4);
823 mnemonic = "fetchaddgez4";
825 case OE_RRR(FETCHADDGEZ, 0, X1):
826 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
827 TILEGX_EXCP_OPCODE_FETCHADDGEZ);
828 mnemonic = "fetchaddgez";
830 case OE_RRR(FETCHADD, 0, X1):
831 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
832 TILEGX_EXCP_OPCODE_FETCHADD);
833 mnemonic = "fetchadd";
835 case OE_RRR(FETCHAND4, 0, X1):
836 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
837 TILEGX_EXCP_OPCODE_FETCHAND4);
838 mnemonic = "fetchand4";
840 case OE_RRR(FETCHAND, 0, X1):
841 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
842 TILEGX_EXCP_OPCODE_FETCHAND);
843 mnemonic = "fetchand";
845 case OE_RRR(FETCHOR4, 0, X1):
846 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
847 TILEGX_EXCP_OPCODE_FETCHOR4);
848 mnemonic = "fetchor4";
850 case OE_RRR(FETCHOR, 0, X1):
851 gen_atomic_excp(dc, dest, tdest, tsrca, tsrcb,
852 TILEGX_EXCP_OPCODE_FETCHOR);
853 mnemonic = "fetchor";
855 case OE_RRR(FSINGLE_ADD1, 0, X0):
856 case OE_RRR(FSINGLE_ADDSUB2, 0, X0):
857 case OE_RRR(FSINGLE_MUL1, 0, X0):
858 case OE_RRR(FSINGLE_MUL2, 0, X0):
859 case OE_RRR(FSINGLE_PACK2, 0, X0):
860 case OE_RRR(FSINGLE_SUB1, 0, X0):
861 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
862 case OE_RRR(MNZ, 0, X0):
863 case OE_RRR(MNZ, 0, X1):
864 case OE_RRR(MNZ, 4, Y0):
865 case OE_RRR(MNZ, 4, Y1):
867 tcg_gen_movcond_tl(TCG_COND_NE, tdest, tsrca, t0, tsrcb, t0);
870 case OE_RRR(MULAX, 0, X0):
871 case OE_RRR(MULAX, 3, Y0):
872 tcg_gen_mul_tl(tdest, tsrca, tsrcb);
873 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
874 tcg_gen_ext32s_tl(tdest, tdest);
877 case OE_RRR(MULA_HS_HS, 0, X0):
878 case OE_RRR(MULA_HS_HS, 9, Y0):
879 gen_mul_half(tdest, tsrca, tsrcb, HS, HS);
880 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
881 mnemonic = "mula_hs_hs";
883 case OE_RRR(MULA_HS_HU, 0, X0):
884 gen_mul_half(tdest, tsrca, tsrcb, HS, HU);
885 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
886 mnemonic = "mula_hs_hu";
888 case OE_RRR(MULA_HS_LS, 0, X0):
889 gen_mul_half(tdest, tsrca, tsrcb, HS, LS);
890 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
891 mnemonic = "mula_hs_ls";
893 case OE_RRR(MULA_HS_LU, 0, X0):
894 gen_mul_half(tdest, tsrca, tsrcb, HS, LU);
895 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
896 mnemonic = "mula_hs_lu";
898 case OE_RRR(MULA_HU_HU, 0, X0):
899 case OE_RRR(MULA_HU_HU, 9, Y0):
900 gen_mul_half(tdest, tsrca, tsrcb, HU, HU);
901 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
902 mnemonic = "mula_hu_hu";
904 case OE_RRR(MULA_HU_LS, 0, X0):
905 gen_mul_half(tdest, tsrca, tsrcb, HU, LS);
906 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
907 mnemonic = "mula_hu_ls";
909 case OE_RRR(MULA_HU_LU, 0, X0):
910 gen_mul_half(tdest, tsrca, tsrcb, HU, LU);
911 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
912 mnemonic = "mula_hu_lu";
914 case OE_RRR(MULA_LS_LS, 0, X0):
915 case OE_RRR(MULA_LS_LS, 9, Y0):
916 gen_mul_half(tdest, tsrca, tsrcb, LS, LS);
917 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
918 mnemonic = "mula_ls_ls";
920 case OE_RRR(MULA_LS_LU, 0, X0):
921 gen_mul_half(tdest, tsrca, tsrcb, LS, LU);
922 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
923 mnemonic = "mula_ls_lu";
925 case OE_RRR(MULA_LU_LU, 0, X0):
926 case OE_RRR(MULA_LU_LU, 9, Y0):
927 gen_mul_half(tdest, tsrca, tsrcb, LU, LU);
928 tcg_gen_add_tl(tdest, tdest, load_gr(dc, dest));
929 mnemonic = "mula_lu_lu";
931 case OE_RRR(MULX, 0, X0):
932 case OE_RRR(MULX, 3, Y0):
933 tcg_gen_mul_tl(tdest, tsrca, tsrcb);
934 tcg_gen_ext32s_tl(tdest, tdest);
937 case OE_RRR(MUL_HS_HS, 0, X0):
938 case OE_RRR(MUL_HS_HS, 8, Y0):
939 gen_mul_half(tdest, tsrca, tsrcb, HS, HS);
940 mnemonic = "mul_hs_hs";
942 case OE_RRR(MUL_HS_HU, 0, X0):
943 gen_mul_half(tdest, tsrca, tsrcb, HS, HU);
944 mnemonic = "mul_hs_hu";
946 case OE_RRR(MUL_HS_LS, 0, X0):
947 gen_mul_half(tdest, tsrca, tsrcb, HS, LS);
948 mnemonic = "mul_hs_ls";
950 case OE_RRR(MUL_HS_LU, 0, X0):
951 gen_mul_half(tdest, tsrca, tsrcb, HS, LU);
952 mnemonic = "mul_hs_lu";
954 case OE_RRR(MUL_HU_HU, 0, X0):
955 case OE_RRR(MUL_HU_HU, 8, Y0):
956 gen_mul_half(tdest, tsrca, tsrcb, HU, HU);
957 mnemonic = "mul_hu_hu";
959 case OE_RRR(MUL_HU_LS, 0, X0):
960 gen_mul_half(tdest, tsrca, tsrcb, HU, LS);
961 mnemonic = "mul_hu_ls";
963 case OE_RRR(MUL_HU_LU, 0, X0):
964 gen_mul_half(tdest, tsrca, tsrcb, HU, LU);
965 mnemonic = "mul_hu_lu";
967 case OE_RRR(MUL_LS_LS, 0, X0):
968 case OE_RRR(MUL_LS_LS, 8, Y0):
969 gen_mul_half(tdest, tsrca, tsrcb, LS, LS);
970 mnemonic = "mul_ls_ls";
972 case OE_RRR(MUL_LS_LU, 0, X0):
973 gen_mul_half(tdest, tsrca, tsrcb, LS, LU);
974 mnemonic = "mul_ls_lu";
976 case OE_RRR(MUL_LU_LU, 0, X0):
977 case OE_RRR(MUL_LU_LU, 8, Y0):
978 gen_mul_half(tdest, tsrca, tsrcb, LU, LU);
979 mnemonic = "mul_lu_lu";
981 case OE_RRR(MZ, 0, X0):
982 case OE_RRR(MZ, 0, X1):
983 case OE_RRR(MZ, 4, Y0):
984 case OE_RRR(MZ, 4, Y1):
986 tcg_gen_movcond_tl(TCG_COND_EQ, tdest, tsrca, t0, tsrcb, t0);
989 case OE_RRR(NOR, 0, X0):
990 case OE_RRR(NOR, 0, X1):
991 case OE_RRR(NOR, 5, Y0):
992 case OE_RRR(NOR, 5, Y1):
993 tcg_gen_nor_tl(tdest, tsrca, tsrcb);
996 case OE_RRR(OR, 0, X0):
997 case OE_RRR(OR, 0, X1):
998 case OE_RRR(OR, 5, Y0):
999 case OE_RRR(OR, 5, Y1):
1000 tcg_gen_or_tl(tdest, tsrca, tsrcb);
1003 case OE_RRR(ROTL, 0, X0):
1004 case OE_RRR(ROTL, 0, X1):
1005 case OE_RRR(ROTL, 6, Y0):
1006 case OE_RRR(ROTL, 6, Y1):
1007 tcg_gen_andi_tl(tdest, tsrcb, 63);
1008 tcg_gen_rotl_tl(tdest, tsrca, tdest);
1011 case OE_RRR(SHL1ADDX, 0, X0):
1012 case OE_RRR(SHL1ADDX, 0, X1):
1013 case OE_RRR(SHL1ADDX, 7, Y0):
1014 case OE_RRR(SHL1ADDX, 7, Y1):
1015 tcg_gen_shli_tl(tdest, tsrca, 1);
1016 tcg_gen_add_tl(tdest, tdest, tsrcb);
1017 tcg_gen_ext32s_tl(tdest, tdest);
1018 mnemonic = "shl1addx";
1020 case OE_RRR(SHL1ADD, 0, X0):
1021 case OE_RRR(SHL1ADD, 0, X1):
1022 case OE_RRR(SHL1ADD, 1, Y0):
1023 case OE_RRR(SHL1ADD, 1, Y1):
1024 tcg_gen_shli_tl(tdest, tsrca, 1);
1025 tcg_gen_add_tl(tdest, tdest, tsrcb);
1026 mnemonic = "shl1add";
1028 case OE_RRR(SHL2ADDX, 0, X0):
1029 case OE_RRR(SHL2ADDX, 0, X1):
1030 case OE_RRR(SHL2ADDX, 7, Y0):
1031 case OE_RRR(SHL2ADDX, 7, Y1):
1032 tcg_gen_shli_tl(tdest, tsrca, 2);
1033 tcg_gen_add_tl(tdest, tdest, tsrcb);
1034 tcg_gen_ext32s_tl(tdest, tdest);
1035 mnemonic = "shl2addx";
1037 case OE_RRR(SHL2ADD, 0, X0):
1038 case OE_RRR(SHL2ADD, 0, X1):
1039 case OE_RRR(SHL2ADD, 1, Y0):
1040 case OE_RRR(SHL2ADD, 1, Y1):
1041 tcg_gen_shli_tl(tdest, tsrca, 2);
1042 tcg_gen_add_tl(tdest, tdest, tsrcb);
1043 mnemonic = "shl2add";
1045 case OE_RRR(SHL3ADDX, 0, X0):
1046 case OE_RRR(SHL3ADDX, 0, X1):
1047 case OE_RRR(SHL3ADDX, 7, Y0):
1048 case OE_RRR(SHL3ADDX, 7, Y1):
1049 tcg_gen_shli_tl(tdest, tsrca, 3);
1050 tcg_gen_add_tl(tdest, tdest, tsrcb);
1051 tcg_gen_ext32s_tl(tdest, tdest);
1052 mnemonic = "shl3addx";
1054 case OE_RRR(SHL3ADD, 0, X0):
1055 case OE_RRR(SHL3ADD, 0, X1):
1056 case OE_RRR(SHL3ADD, 1, Y0):
1057 case OE_RRR(SHL3ADD, 1, Y1):
1058 tcg_gen_shli_tl(tdest, tsrca, 3);
1059 tcg_gen_add_tl(tdest, tdest, tsrcb);
1060 mnemonic = "shl3add";
1062 case OE_RRR(SHLX, 0, X0):
1063 case OE_RRR(SHLX, 0, X1):
1064 tcg_gen_andi_tl(tdest, tsrcb, 31);
1065 tcg_gen_shl_tl(tdest, tsrca, tdest);
1066 tcg_gen_ext32s_tl(tdest, tdest);
1069 case OE_RRR(SHL, 0, X0):
1070 case OE_RRR(SHL, 0, X1):
1071 case OE_RRR(SHL, 6, Y0):
1072 case OE_RRR(SHL, 6, Y1):
1073 tcg_gen_andi_tl(tdest, tsrcb, 63);
1074 tcg_gen_shl_tl(tdest, tsrca, tdest);
1077 case OE_RRR(SHRS, 0, X0):
1078 case OE_RRR(SHRS, 0, X1):
1079 case OE_RRR(SHRS, 6, Y0):
1080 case OE_RRR(SHRS, 6, Y1):
1081 tcg_gen_andi_tl(tdest, tsrcb, 63);
1082 tcg_gen_sar_tl(tdest, tsrca, tdest);
1085 case OE_RRR(SHRUX, 0, X0):
1086 case OE_RRR(SHRUX, 0, X1):
1087 t0 = tcg_temp_new();
1088 tcg_gen_andi_tl(t0, tsrcb, 31);
1089 tcg_gen_ext32u_tl(tdest, tsrca);
1090 tcg_gen_shr_tl(tdest, tdest, t0);
1091 tcg_gen_ext32s_tl(tdest, tdest);
1095 case OE_RRR(SHRU, 0, X0):
1096 case OE_RRR(SHRU, 0, X1):
1097 case OE_RRR(SHRU, 6, Y0):
1098 case OE_RRR(SHRU, 6, Y1):
1099 tcg_gen_andi_tl(tdest, tsrcb, 63);
1100 tcg_gen_shr_tl(tdest, tsrca, tdest);
1103 case OE_RRR(SHUFFLEBYTES, 0, X0):
1104 gen_helper_shufflebytes(tdest, load_gr(dc, dest), tsrca, tsrca);
1105 mnemonic = "shufflebytes";
1107 case OE_RRR(SUBXSC, 0, X0):
1108 case OE_RRR(SUBXSC, 0, X1):
1109 gen_saturate_op(tdest, tsrca, tsrcb, tcg_gen_sub_tl);
1110 mnemonic = "subxsc";
1112 case OE_RRR(SUBX, 0, X0):
1113 case OE_RRR(SUBX, 0, X1):
1114 case OE_RRR(SUBX, 0, Y0):
1115 case OE_RRR(SUBX, 0, Y1):
1116 tcg_gen_sub_tl(tdest, tsrca, tsrcb);
1117 tcg_gen_ext32s_tl(tdest, tdest);
1120 case OE_RRR(SUB, 0, X0):
1121 case OE_RRR(SUB, 0, X1):
1122 case OE_RRR(SUB, 0, Y0):
1123 case OE_RRR(SUB, 0, Y1):
1124 tcg_gen_sub_tl(tdest, tsrca, tsrcb);
1127 case OE_RRR(V1ADDUC, 0, X0):
1128 case OE_RRR(V1ADDUC, 0, X1):
1129 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1130 case OE_RRR(V1ADD, 0, X0):
1131 case OE_RRR(V1ADD, 0, X1):
1132 gen_v12add(tdest, tsrca, tsrcb, V1_IMM(0x80));
1135 case OE_RRR(V1ADIFFU, 0, X0):
1136 case OE_RRR(V1AVGU, 0, X0):
1137 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1138 case OE_RRR(V1CMPEQ, 0, X0):
1139 case OE_RRR(V1CMPEQ, 0, X1):
1140 tcg_gen_xor_tl(tdest, tsrca, tsrcb);
1141 gen_v1cmpeq0(tdest);
1142 mnemonic = "v1cmpeq";
1144 case OE_RRR(V1CMPLES, 0, X0):
1145 case OE_RRR(V1CMPLES, 0, X1):
1146 case OE_RRR(V1CMPLEU, 0, X0):
1147 case OE_RRR(V1CMPLEU, 0, X1):
1148 case OE_RRR(V1CMPLTS, 0, X0):
1149 case OE_RRR(V1CMPLTS, 0, X1):
1150 case OE_RRR(V1CMPLTU, 0, X0):
1151 case OE_RRR(V1CMPLTU, 0, X1):
1152 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1153 case OE_RRR(V1CMPNE, 0, X0):
1154 case OE_RRR(V1CMPNE, 0, X1):
1155 tcg_gen_xor_tl(tdest, tsrca, tsrcb);
1156 gen_v1cmpne0(tdest);
1157 mnemonic = "v1cmpne";
1159 case OE_RRR(V1DDOTPUA, 0, X0):
1160 case OE_RRR(V1DDOTPUSA, 0, X0):
1161 case OE_RRR(V1DDOTPUS, 0, X0):
1162 case OE_RRR(V1DDOTPU, 0, X0):
1163 case OE_RRR(V1DOTPA, 0, X0):
1164 case OE_RRR(V1DOTPUA, 0, X0):
1165 case OE_RRR(V1DOTPUSA, 0, X0):
1166 case OE_RRR(V1DOTPUS, 0, X0):
1167 case OE_RRR(V1DOTPU, 0, X0):
1168 case OE_RRR(V1DOTP, 0, X0):
1169 case OE_RRR(V1INT_H, 0, X0):
1170 case OE_RRR(V1INT_H, 0, X1):
1171 case OE_RRR(V1INT_L, 0, X0):
1172 case OE_RRR(V1INT_L, 0, X1):
1173 case OE_RRR(V1MAXU, 0, X0):
1174 case OE_RRR(V1MAXU, 0, X1):
1175 case OE_RRR(V1MINU, 0, X0):
1176 case OE_RRR(V1MINU, 0, X1):
1177 case OE_RRR(V1MNZ, 0, X0):
1178 case OE_RRR(V1MNZ, 0, X1):
1179 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1180 case OE_RRR(V1MULTU, 0, X0):
1181 gen_helper_v1multu(tdest, tsrca, tsrcb);
1182 mnemonic = "v1multu";
1184 case OE_RRR(V1MULUS, 0, X0):
1185 case OE_RRR(V1MULU, 0, X0):
1186 case OE_RRR(V1MZ, 0, X0):
1187 case OE_RRR(V1MZ, 0, X1):
1188 case OE_RRR(V1SADAU, 0, X0):
1189 case OE_RRR(V1SADU, 0, X0):
1190 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1191 case OE_RRR(V1SHL, 0, X0):
1192 case OE_RRR(V1SHL, 0, X1):
1193 gen_helper_v1shl(tdest, tsrca, tsrcb);
1196 case OE_RRR(V1SHRS, 0, X0):
1197 case OE_RRR(V1SHRS, 0, X1):
1198 gen_helper_v1shrs(tdest, tsrca, tsrcb);
1199 mnemonic = "v1shrs";
1201 case OE_RRR(V1SHRU, 0, X0):
1202 case OE_RRR(V1SHRU, 0, X1):
1203 gen_helper_v1shru(tdest, tsrca, tsrcb);
1204 mnemonic = "v1shru";
1206 case OE_RRR(V1SUBUC, 0, X0):
1207 case OE_RRR(V1SUBUC, 0, X1):
1208 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1209 case OE_RRR(V1SUB, 0, X0):
1210 case OE_RRR(V1SUB, 0, X1):
1211 gen_v12sub(tdest, tsrca, tsrcb, V1_IMM(0x80));
1214 case OE_RRR(V2ADDSC, 0, X0):
1215 case OE_RRR(V2ADDSC, 0, X1):
1216 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1217 case OE_RRR(V2ADD, 0, X0):
1218 case OE_RRR(V2ADD, 0, X1):
1219 gen_v12add(tdest, tsrca, tsrcb, V2_IMM(0x8000));
1222 case OE_RRR(V2ADIFFS, 0, X0):
1223 case OE_RRR(V2AVGS, 0, X0):
1224 case OE_RRR(V2CMPEQ, 0, X0):
1225 case OE_RRR(V2CMPEQ, 0, X1):
1226 case OE_RRR(V2CMPLES, 0, X0):
1227 case OE_RRR(V2CMPLES, 0, X1):
1228 case OE_RRR(V2CMPLEU, 0, X0):
1229 case OE_RRR(V2CMPLEU, 0, X1):
1230 case OE_RRR(V2CMPLTS, 0, X0):
1231 case OE_RRR(V2CMPLTS, 0, X1):
1232 case OE_RRR(V2CMPLTU, 0, X0):
1233 case OE_RRR(V2CMPLTU, 0, X1):
1234 case OE_RRR(V2CMPNE, 0, X0):
1235 case OE_RRR(V2CMPNE, 0, X1):
1236 case OE_RRR(V2DOTPA, 0, X0):
1237 case OE_RRR(V2DOTP, 0, X0):
1238 case OE_RRR(V2INT_H, 0, X0):
1239 case OE_RRR(V2INT_H, 0, X1):
1240 case OE_RRR(V2INT_L, 0, X0):
1241 case OE_RRR(V2INT_L, 0, X1):
1242 case OE_RRR(V2MAXS, 0, X0):
1243 case OE_RRR(V2MAXS, 0, X1):
1244 case OE_RRR(V2MINS, 0, X0):
1245 case OE_RRR(V2MINS, 0, X1):
1246 case OE_RRR(V2MNZ, 0, X0):
1247 case OE_RRR(V2MNZ, 0, X1):
1248 case OE_RRR(V2MULFSC, 0, X0):
1249 case OE_RRR(V2MULS, 0, X0):
1250 case OE_RRR(V2MULTS, 0, X0):
1251 case OE_RRR(V2MZ, 0, X0):
1252 case OE_RRR(V2MZ, 0, X1):
1253 case OE_RRR(V2PACKH, 0, X0):
1254 case OE_RRR(V2PACKH, 0, X1):
1255 case OE_RRR(V2PACKL, 0, X0):
1256 case OE_RRR(V2PACKL, 0, X1):
1257 case OE_RRR(V2PACKUC, 0, X0):
1258 case OE_RRR(V2PACKUC, 0, X1):
1259 case OE_RRR(V2SADAS, 0, X0):
1260 case OE_RRR(V2SADAU, 0, X0):
1261 case OE_RRR(V2SADS, 0, X0):
1262 case OE_RRR(V2SADU, 0, X0):
1263 case OE_RRR(V2SHLSC, 0, X0):
1264 case OE_RRR(V2SHLSC, 0, X1):
1265 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1266 case OE_RRR(V2SHL, 0, X0):
1267 case OE_RRR(V2SHL, 0, X1):
1268 gen_helper_v2shl(tdest, tsrca, tsrcb);
1271 case OE_RRR(V2SHRS, 0, X0):
1272 case OE_RRR(V2SHRS, 0, X1):
1273 gen_helper_v2shrs(tdest, tsrca, tsrcb);
1274 mnemonic = "v2shrs";
1276 case OE_RRR(V2SHRU, 0, X0):
1277 case OE_RRR(V2SHRU, 0, X1):
1278 gen_helper_v2shru(tdest, tsrca, tsrcb);
1279 mnemonic = "v2shru";
1281 case OE_RRR(V2SUBSC, 0, X0):
1282 case OE_RRR(V2SUBSC, 0, X1):
1283 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1284 case OE_RRR(V2SUB, 0, X0):
1285 case OE_RRR(V2SUB, 0, X1):
1286 gen_v12sub(tdest, tsrca, tsrcb, V2_IMM(0x8000));
1289 case OE_RRR(V4ADDSC, 0, X0):
1290 case OE_RRR(V4ADDSC, 0, X1):
1291 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1292 case OE_RRR(V4ADD, 0, X0):
1293 case OE_RRR(V4ADD, 0, X1):
1294 gen_v4op(tdest, tsrca, tsrcb, tcg_gen_add_i32);
1297 case OE_RRR(V4INT_H, 0, X0):
1298 case OE_RRR(V4INT_H, 0, X1):
1299 tcg_gen_shri_tl(tdest, tsrcb, 32);
1300 tcg_gen_deposit_tl(tdest, tsrca, tdest, 0, 32);
1301 mnemonic = "v4int_h";
1303 case OE_RRR(V4INT_L, 0, X0):
1304 case OE_RRR(V4INT_L, 0, X1):
1305 tcg_gen_deposit_tl(tdest, tsrcb, tsrca, 32, 32);
1306 mnemonic = "v4int_l";
1308 case OE_RRR(V4PACKSC, 0, X0):
1309 case OE_RRR(V4PACKSC, 0, X1):
1310 case OE_RRR(V4SHLSC, 0, X0):
1311 case OE_RRR(V4SHLSC, 0, X1):
1312 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1313 case OE_RRR(V4SHL, 0, X0):
1314 case OE_RRR(V4SHL, 0, X1):
1315 gen_v4sh(tdest, tsrca, tsrcb, tcg_gen_shl_i32);
1318 case OE_RRR(V4SHRS, 0, X0):
1319 case OE_RRR(V4SHRS, 0, X1):
1320 gen_v4sh(tdest, tsrca, tsrcb, tcg_gen_sar_i32);
1321 mnemonic = "v4shrs";
1323 case OE_RRR(V4SHRU, 0, X0):
1324 case OE_RRR(V4SHRU, 0, X1):
1325 gen_v4sh(tdest, tsrca, tsrcb, tcg_gen_shr_i32);
1326 mnemonic = "v4shru";
1328 case OE_RRR(V4SUBSC, 0, X0):
1329 case OE_RRR(V4SUBSC, 0, X1):
1330 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1331 case OE_RRR(V4SUB, 0, X0):
1332 case OE_RRR(V4SUB, 0, X1):
1333 gen_v4op(tdest, tsrca, tsrcb, tcg_gen_sub_i32);
1336 case OE_RRR(XOR, 0, X0):
1337 case OE_RRR(XOR, 0, X1):
1338 case OE_RRR(XOR, 5, Y0):
1339 case OE_RRR(XOR, 5, Y1):
1340 tcg_gen_xor_tl(tdest, tsrca, tsrcb);
1344 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1347 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s, %s", mnemonic,
1348 reg_names[dest], reg_names[srca], reg_names[srcb]);
1349 return TILEGX_EXCP_NONE;
1352 static TileExcp gen_rri_opcode(DisasContext *dc, unsigned opext,
1353 unsigned dest, unsigned srca, int imm)
1355 TCGv tdest = dest_gr(dc, dest);
1356 TCGv tsrca = load_gr(dc, srca);
1357 const char *mnemonic;
1363 case OE(ADDI_OPCODE_Y0, 0, Y0):
1364 case OE(ADDI_OPCODE_Y1, 0, Y1):
1365 case OE_IM(ADDI, X0):
1366 case OE_IM(ADDI, X1):
1367 tcg_gen_addi_tl(tdest, tsrca, imm);
1370 case OE(ADDXI_OPCODE_Y0, 0, Y0):
1371 case OE(ADDXI_OPCODE_Y1, 0, Y1):
1372 case OE_IM(ADDXI, X0):
1373 case OE_IM(ADDXI, X1):
1374 tcg_gen_addi_tl(tdest, tsrca, imm);
1375 tcg_gen_ext32s_tl(tdest, tdest);
1378 case OE(ANDI_OPCODE_Y0, 0, Y0):
1379 case OE(ANDI_OPCODE_Y1, 0, Y1):
1380 case OE_IM(ANDI, X0):
1381 case OE_IM(ANDI, X1):
1382 tcg_gen_andi_tl(tdest, tsrca, imm);
1385 case OE(CMPEQI_OPCODE_Y0, 0, Y0):
1386 case OE(CMPEQI_OPCODE_Y1, 0, Y1):
1387 case OE_IM(CMPEQI, X0):
1388 case OE_IM(CMPEQI, X1):
1389 tcg_gen_setcondi_tl(TCG_COND_EQ, tdest, tsrca, imm);
1390 mnemonic = "cmpeqi";
1392 case OE(CMPLTSI_OPCODE_Y0, 0, Y0):
1393 case OE(CMPLTSI_OPCODE_Y1, 0, Y1):
1394 case OE_IM(CMPLTSI, X0):
1395 case OE_IM(CMPLTSI, X1):
1396 tcg_gen_setcondi_tl(TCG_COND_LT, tdest, tsrca, imm);
1397 mnemonic = "cmpltsi";
1399 case OE_IM(CMPLTUI, X0):
1400 case OE_IM(CMPLTUI, X1):
1401 tcg_gen_setcondi_tl(TCG_COND_LTU, tdest, tsrca, imm);
1402 mnemonic = "cmpltui";
1404 case OE_IM(LD1S_ADD, X1):
1406 mnemonic = "ld1s_add";
1408 case OE_IM(LD1U_ADD, X1):
1410 mnemonic = "ld1u_add";
1412 case OE_IM(LD2S_ADD, X1):
1414 mnemonic = "ld2s_add";
1416 case OE_IM(LD2U_ADD, X1):
1418 mnemonic = "ld2u_add";
1420 case OE_IM(LD4S_ADD, X1):
1422 mnemonic = "ld4s_add";
1424 case OE_IM(LD4U_ADD, X1):
1426 mnemonic = "ld4u_add";
1428 case OE_IM(LDNT1S_ADD, X1):
1430 mnemonic = "ldnt1s_add";
1432 case OE_IM(LDNT1U_ADD, X1):
1434 mnemonic = "ldnt1u_add";
1436 case OE_IM(LDNT2S_ADD, X1):
1438 mnemonic = "ldnt2s_add";
1440 case OE_IM(LDNT2U_ADD, X1):
1442 mnemonic = "ldnt2u_add";
1444 case OE_IM(LDNT4S_ADD, X1):
1446 mnemonic = "ldnt4s_add";
1448 case OE_IM(LDNT4U_ADD, X1):
1450 mnemonic = "ldnt4u_add";
1452 case OE_IM(LDNT_ADD, X1):
1454 mnemonic = "ldnt_add";
1456 case OE_IM(LD_ADD, X1):
1458 mnemonic = "ldnt_add";
1460 tcg_gen_qemu_ld_tl(tdest, tsrca, dc->mmuidx, memop);
1461 tcg_gen_addi_tl(dest_gr(dc, srca), tsrca, imm);
1463 case OE_IM(LDNA_ADD, X1):
1464 tcg_gen_andi_tl(tdest, tsrca, ~7);
1465 tcg_gen_qemu_ld_tl(tdest, tdest, dc->mmuidx, MO_TEQ);
1466 tcg_gen_addi_tl(dest_gr(dc, srca), tsrca, imm);
1467 mnemonic = "ldna_add";
1469 case OE_IM(ORI, X0):
1470 case OE_IM(ORI, X1):
1471 tcg_gen_ori_tl(tdest, tsrca, imm);
1474 case OE_IM(V1ADDI, X0):
1475 case OE_IM(V1ADDI, X1):
1476 t0 = tcg_const_tl(V1_IMM(imm));
1477 gen_v12add(tdest, tsrca, t0, V1_IMM(0x80));
1479 mnemonic = "v1addi";
1481 case OE_IM(V1CMPEQI, X0):
1482 case OE_IM(V1CMPEQI, X1):
1483 tcg_gen_xori_tl(tdest, tsrca, V1_IMM(imm));
1484 gen_v1cmpeq0(tdest);
1485 mnemonic = "v1cmpeqi";
1487 case OE_IM(V1CMPLTSI, X0):
1488 case OE_IM(V1CMPLTSI, X1):
1489 case OE_IM(V1CMPLTUI, X0):
1490 case OE_IM(V1CMPLTUI, X1):
1491 case OE_IM(V1MAXUI, X0):
1492 case OE_IM(V1MAXUI, X1):
1493 case OE_IM(V1MINUI, X0):
1494 case OE_IM(V1MINUI, X1):
1495 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1496 case OE_IM(V2ADDI, X0):
1497 case OE_IM(V2ADDI, X1):
1498 t0 = tcg_const_tl(V2_IMM(imm));
1499 gen_v12add(tdest, tsrca, t0, V2_IMM(0x8000));
1501 mnemonic = "v2addi";
1503 case OE_IM(V2CMPEQI, X0):
1504 case OE_IM(V2CMPEQI, X1):
1505 case OE_IM(V2CMPLTSI, X0):
1506 case OE_IM(V2CMPLTSI, X1):
1507 case OE_IM(V2CMPLTUI, X0):
1508 case OE_IM(V2CMPLTUI, X1):
1509 case OE_IM(V2MAXSI, X0):
1510 case OE_IM(V2MAXSI, X1):
1511 case OE_IM(V2MINSI, X0):
1512 case OE_IM(V2MINSI, X1):
1513 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1514 case OE_IM(XORI, X0):
1515 case OE_IM(XORI, X1):
1516 tcg_gen_xori_tl(tdest, tsrca, imm);
1520 case OE_SH(ROTLI, X0):
1521 case OE_SH(ROTLI, X1):
1522 case OE_SH(ROTLI, Y0):
1523 case OE_SH(ROTLI, Y1):
1524 tcg_gen_rotli_tl(tdest, tsrca, imm);
1527 case OE_SH(SHLI, X0):
1528 case OE_SH(SHLI, X1):
1529 case OE_SH(SHLI, Y0):
1530 case OE_SH(SHLI, Y1):
1531 tcg_gen_shli_tl(tdest, tsrca, imm);
1534 case OE_SH(SHLXI, X0):
1535 case OE_SH(SHLXI, X1):
1536 tcg_gen_shli_tl(tdest, tsrca, imm & 31);
1537 tcg_gen_ext32s_tl(tdest, tdest);
1540 case OE_SH(SHRSI, X0):
1541 case OE_SH(SHRSI, X1):
1542 case OE_SH(SHRSI, Y0):
1543 case OE_SH(SHRSI, Y1):
1544 tcg_gen_sari_tl(tdest, tsrca, imm);
1547 case OE_SH(SHRUI, X0):
1548 case OE_SH(SHRUI, X1):
1549 case OE_SH(SHRUI, Y0):
1550 case OE_SH(SHRUI, Y1):
1551 tcg_gen_shri_tl(tdest, tsrca, imm);
1554 case OE_SH(SHRUXI, X0):
1555 case OE_SH(SHRUXI, X1):
1556 if ((imm & 31) == 0) {
1557 tcg_gen_ext32s_tl(tdest, tsrca);
1559 tcg_gen_ext32u_tl(tdest, tsrca);
1560 tcg_gen_shri_tl(tdest, tdest, imm & 31);
1564 case OE_SH(V1SHLI, X0):
1565 case OE_SH(V1SHLI, X1):
1568 tcg_gen_andi_tl(tdest, tsrca, V1_IMM(i3));
1569 tcg_gen_shli_tl(tdest, tdest, i2);
1570 mnemonic = "v1shli";
1572 case OE_SH(V1SHRSI, X0):
1573 case OE_SH(V1SHRSI, X1):
1574 t0 = tcg_const_tl(imm & 7);
1575 gen_helper_v1shrs(tdest, tsrca, t0);
1577 mnemonic = "v1shrsi";
1579 case OE_SH(V1SHRUI, X0):
1580 case OE_SH(V1SHRUI, X1):
1582 i3 = (0xff << i2) & 0xff;
1583 tcg_gen_andi_tl(tdest, tsrca, V1_IMM(i3));
1584 tcg_gen_shri_tl(tdest, tdest, i2);
1585 mnemonic = "v1shrui";
1587 case OE_SH(V2SHLI, X0):
1588 case OE_SH(V2SHLI, X1):
1589 case OE_SH(V2SHRSI, X0):
1590 case OE_SH(V2SHRSI, X1):
1591 case OE_SH(V2SHRUI, X0):
1592 case OE_SH(V2SHRUI, X1):
1593 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1595 case OE(ADDLI_OPCODE_X0, 0, X0):
1596 case OE(ADDLI_OPCODE_X1, 0, X1):
1597 tcg_gen_addi_tl(tdest, tsrca, imm);
1600 case OE(ADDXLI_OPCODE_X0, 0, X0):
1601 case OE(ADDXLI_OPCODE_X1, 0, X1):
1602 tcg_gen_addi_tl(tdest, tsrca, imm);
1603 tcg_gen_ext32s_tl(tdest, tdest);
1604 mnemonic = "addxli";
1606 case OE(SHL16INSLI_OPCODE_X0, 0, X0):
1607 case OE(SHL16INSLI_OPCODE_X1, 0, X1):
1608 tcg_gen_shli_tl(tdest, tsrca, 16);
1609 tcg_gen_ori_tl(tdest, tdest, imm & 0xffff);
1610 mnemonic = "shl16insli";
1614 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1617 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s, %d", mnemonic,
1618 reg_names[dest], reg_names[srca], imm);
1619 return TILEGX_EXCP_NONE;
1622 static TileExcp gen_bf_opcode_x0(DisasContext *dc, unsigned ext,
1623 unsigned dest, unsigned srca,
1624 unsigned bfs, unsigned bfe)
1626 TCGv tdest = dest_gr(dc, dest);
1627 TCGv tsrca = load_gr(dc, srca);
1630 const char *mnemonic;
1632 /* The bitfield is either between E and S inclusive,
1633 or up from S and down from E inclusive. */
1635 len = bfe - bfs + 1;
1637 len = (64 - bfs) + (bfe + 1);
1641 case BFEXTU_BF_OPCODE_X0:
1642 if (bfs == 0 && bfe == 7) {
1643 tcg_gen_ext8u_tl(tdest, tsrca);
1644 } else if (bfs == 0 && bfe == 15) {
1645 tcg_gen_ext16u_tl(tdest, tsrca);
1646 } else if (bfs == 0 && bfe == 31) {
1647 tcg_gen_ext32u_tl(tdest, tsrca);
1651 tcg_gen_shli_tl(tdest, tsrca, rol);
1653 tcg_gen_rotli_tl(tdest, tsrca, rol);
1655 tcg_gen_shri_tl(tdest, tdest, (bfs + rol) & 63);
1657 mnemonic = "bfextu";
1660 case BFEXTS_BF_OPCODE_X0:
1661 if (bfs == 0 && bfe == 7) {
1662 tcg_gen_ext8s_tl(tdest, tsrca);
1663 } else if (bfs == 0 && bfe == 15) {
1664 tcg_gen_ext16s_tl(tdest, tsrca);
1665 } else if (bfs == 0 && bfe == 31) {
1666 tcg_gen_ext32s_tl(tdest, tsrca);
1670 tcg_gen_shli_tl(tdest, tsrca, rol);
1672 tcg_gen_rotli_tl(tdest, tsrca, rol);
1674 tcg_gen_sari_tl(tdest, tdest, (bfs + rol) & 63);
1676 mnemonic = "bfexts";
1679 case BFINS_BF_OPCODE_X0:
1680 tsrcd = load_gr(dc, dest);
1682 tcg_gen_deposit_tl(tdest, tsrcd, tsrca, bfs, len);
1684 tcg_gen_rotri_tl(tdest, tsrcd, bfs);
1685 tcg_gen_deposit_tl(tdest, tdest, tsrca, 0, len);
1686 tcg_gen_rotli_tl(tdest, tdest, bfs);
1691 case MM_BF_OPCODE_X0:
1692 tsrcd = load_gr(dc, dest);
1694 tcg_gen_deposit_tl(tdest, tsrca, tsrcd, 0, len);
1696 uint64_t mask = len == 64 ? -1 : rol64((1ULL << len) - 1, bfs);
1697 TCGv tmp = tcg_const_tl(mask);
1699 tcg_gen_and_tl(tdest, tsrcd, tmp);
1700 tcg_gen_andc_tl(tmp, tsrca, tmp);
1701 tcg_gen_or_tl(tdest, tdest, tmp);
1708 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1711 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s, %u, %u", mnemonic,
1712 reg_names[dest], reg_names[srca], bfs, bfe);
1713 return TILEGX_EXCP_NONE;
1716 static TileExcp gen_branch_opcode_x1(DisasContext *dc, unsigned ext,
1717 unsigned srca, int off)
1719 target_ulong tgt = dc->pc + off * TILEGX_BUNDLE_SIZE_IN_BYTES;
1720 const char *mnemonic;
1722 dc->jmp.dest = tcg_const_tl(tgt);
1723 dc->jmp.val1 = tcg_temp_new();
1724 tcg_gen_mov_tl(dc->jmp.val1, load_gr(dc, srca));
1726 /* Note that the "predict taken" opcodes have bit 0 clear.
1727 Therefore, fold the two cases together by setting bit 0. */
1729 case BEQZ_BRANCH_OPCODE_X1:
1730 dc->jmp.cond = TCG_COND_EQ;
1733 case BNEZ_BRANCH_OPCODE_X1:
1734 dc->jmp.cond = TCG_COND_NE;
1737 case BGEZ_BRANCH_OPCODE_X1:
1738 dc->jmp.cond = TCG_COND_GE;
1741 case BGTZ_BRANCH_OPCODE_X1:
1742 dc->jmp.cond = TCG_COND_GT;
1745 case BLEZ_BRANCH_OPCODE_X1:
1746 dc->jmp.cond = TCG_COND_LE;
1749 case BLTZ_BRANCH_OPCODE_X1:
1750 dc->jmp.cond = TCG_COND_LT;
1753 case BLBC_BRANCH_OPCODE_X1:
1754 dc->jmp.cond = TCG_COND_EQ;
1755 tcg_gen_andi_tl(dc->jmp.val1, dc->jmp.val1, 1);
1758 case BLBS_BRANCH_OPCODE_X1:
1759 dc->jmp.cond = TCG_COND_NE;
1760 tcg_gen_andi_tl(dc->jmp.val1, dc->jmp.val1, 1);
1764 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1767 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
1768 qemu_log("%s%s %s, " TARGET_FMT_lx " <%s>",
1769 mnemonic, ext & 1 ? "" : "t",
1770 reg_names[srca], tgt, lookup_symbol(tgt));
1772 return TILEGX_EXCP_NONE;
1775 static TileExcp gen_jump_opcode_x1(DisasContext *dc, unsigned ext, int off)
1777 target_ulong tgt = dc->pc + off * TILEGX_BUNDLE_SIZE_IN_BYTES;
1778 const char *mnemonic = "j";
1780 /* The extension field is 1 bit, therefore we only have JAL and J. */
1781 if (ext == JAL_JUMP_OPCODE_X1) {
1782 tcg_gen_movi_tl(dest_gr(dc, TILEGX_R_LR),
1783 dc->pc + TILEGX_BUNDLE_SIZE_IN_BYTES);
1786 dc->jmp.cond = TCG_COND_ALWAYS;
1787 dc->jmp.dest = tcg_const_tl(tgt);
1789 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
1790 qemu_log("%s " TARGET_FMT_lx " <%s>",
1791 mnemonic, tgt, lookup_symbol(tgt));
1793 return TILEGX_EXCP_NONE;
1799 void (*get)(TCGv, TCGv_ptr);
1800 void (*put)(TCGv_ptr, TCGv);
1803 static const TileSPR *find_spr(unsigned spr)
1805 /* Allow the compiler to construct the binary search tree. */
1806 #define D(N, O, G, P) \
1807 case SPR_##N: { static const TileSPR x = { #N, O, G, P }; return &x; }
1811 offsetof(CPUTLGState, spregs[TILEGX_SPR_CMPEXCH]), 0, 0)
1812 D(INTERRUPT_CRITICAL_SECTION,
1813 offsetof(CPUTLGState, spregs[TILEGX_SPR_CRITICAL_SEC]), 0, 0)
1815 offsetof(CPUTLGState, spregs[TILEGX_SPR_SIM_CONTROL]), 0, 0)
1820 qemu_log_mask(LOG_UNIMP, "UNIMP SPR %u\n", spr);
1824 static TileExcp gen_mtspr_x1(DisasContext *dc, unsigned spr, unsigned srca)
1826 const TileSPR *def = find_spr(spr);
1830 qemu_log_mask(CPU_LOG_TB_IN_ASM, "mtspr spr[%u], %s", spr, reg_names[srca]);
1831 return TILEGX_EXCP_OPCODE_UNKNOWN;
1834 tsrca = load_gr(dc, srca);
1836 def->put(cpu_env, tsrca);
1838 tcg_gen_st_tl(tsrca, cpu_env, def->offset);
1840 qemu_log_mask(CPU_LOG_TB_IN_ASM, "mtspr %s, %s", def->name, reg_names[srca]);
1841 return TILEGX_EXCP_NONE;
1844 static TileExcp gen_mfspr_x1(DisasContext *dc, unsigned dest, unsigned spr)
1846 const TileSPR *def = find_spr(spr);
1850 qemu_log_mask(CPU_LOG_TB_IN_ASM, "mtspr %s, spr[%u]", reg_names[dest], spr);
1851 return TILEGX_EXCP_OPCODE_UNKNOWN;
1854 tdest = dest_gr(dc, dest);
1856 def->get(tdest, cpu_env);
1858 tcg_gen_ld_tl(tdest, cpu_env, def->offset);
1860 qemu_log_mask(CPU_LOG_TB_IN_ASM, "mfspr %s, %s", reg_names[dest], def->name);
1861 return TILEGX_EXCP_NONE;
1864 static TileExcp decode_y0(DisasContext *dc, tilegx_bundle_bits bundle)
1866 unsigned opc = get_Opcode_Y0(bundle);
1867 unsigned ext = get_RRROpcodeExtension_Y0(bundle);
1868 unsigned dest = get_Dest_Y0(bundle);
1869 unsigned srca = get_SrcA_Y0(bundle);
1874 case RRR_1_OPCODE_Y0:
1875 if (ext == UNARY_RRR_1_OPCODE_Y0) {
1876 ext = get_UnaryOpcodeExtension_Y0(bundle);
1877 return gen_rr_opcode(dc, OE(opc, ext, Y0), dest, srca);
1880 case RRR_0_OPCODE_Y0:
1881 case RRR_2_OPCODE_Y0:
1882 case RRR_3_OPCODE_Y0:
1883 case RRR_4_OPCODE_Y0:
1884 case RRR_5_OPCODE_Y0:
1885 case RRR_6_OPCODE_Y0:
1886 case RRR_7_OPCODE_Y0:
1887 case RRR_8_OPCODE_Y0:
1888 case RRR_9_OPCODE_Y0:
1889 srcb = get_SrcB_Y0(bundle);
1890 return gen_rrr_opcode(dc, OE(opc, ext, Y0), dest, srca, srcb);
1892 case SHIFT_OPCODE_Y0:
1893 ext = get_ShiftOpcodeExtension_Y0(bundle);
1894 imm = get_ShAmt_Y0(bundle);
1895 return gen_rri_opcode(dc, OE(opc, ext, Y0), dest, srca, imm);
1897 case ADDI_OPCODE_Y0:
1898 case ADDXI_OPCODE_Y0:
1899 case ANDI_OPCODE_Y0:
1900 case CMPEQI_OPCODE_Y0:
1901 case CMPLTSI_OPCODE_Y0:
1902 imm = (int8_t)get_Imm8_Y0(bundle);
1903 return gen_rri_opcode(dc, OE(opc, 0, Y0), dest, srca, imm);
1906 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1910 static TileExcp decode_y1(DisasContext *dc, tilegx_bundle_bits bundle)
1912 unsigned opc = get_Opcode_Y1(bundle);
1913 unsigned ext = get_RRROpcodeExtension_Y1(bundle);
1914 unsigned dest = get_Dest_Y1(bundle);
1915 unsigned srca = get_SrcA_Y1(bundle);
1919 switch (get_Opcode_Y1(bundle)) {
1920 case RRR_1_OPCODE_Y1:
1921 if (ext == UNARY_RRR_1_OPCODE_Y0) {
1922 ext = get_UnaryOpcodeExtension_Y1(bundle);
1923 return gen_rr_opcode(dc, OE(opc, ext, Y1), dest, srca);
1926 case RRR_0_OPCODE_Y1:
1927 case RRR_2_OPCODE_Y1:
1928 case RRR_3_OPCODE_Y1:
1929 case RRR_4_OPCODE_Y1:
1930 case RRR_5_OPCODE_Y1:
1931 case RRR_6_OPCODE_Y1:
1932 case RRR_7_OPCODE_Y1:
1933 srcb = get_SrcB_Y1(bundle);
1934 return gen_rrr_opcode(dc, OE(opc, ext, Y1), dest, srca, srcb);
1936 case SHIFT_OPCODE_Y1:
1937 ext = get_ShiftOpcodeExtension_Y1(bundle);
1938 imm = get_ShAmt_Y1(bundle);
1939 return gen_rri_opcode(dc, OE(opc, ext, Y1), dest, srca, imm);
1941 case ADDI_OPCODE_Y1:
1942 case ADDXI_OPCODE_Y1:
1943 case ANDI_OPCODE_Y1:
1944 case CMPEQI_OPCODE_Y1:
1945 case CMPLTSI_OPCODE_Y1:
1946 imm = (int8_t)get_Imm8_Y1(bundle);
1947 return gen_rri_opcode(dc, OE(opc, 0, Y1), dest, srca, imm);
1950 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
1954 static TileExcp decode_y2(DisasContext *dc, tilegx_bundle_bits bundle)
1956 unsigned mode = get_Mode(bundle);
1957 unsigned opc = get_Opcode_Y2(bundle);
1958 unsigned srca = get_SrcA_Y2(bundle);
1959 unsigned srcbdest = get_SrcBDest_Y2(bundle);
1960 const char *mnemonic;
1963 switch (OEY2(opc, mode)) {
1964 case OEY2(LD1S_OPCODE_Y2, MODE_OPCODE_YA2):
1968 case OEY2(LD1U_OPCODE_Y2, MODE_OPCODE_YA2):
1972 case OEY2(LD2S_OPCODE_Y2, MODE_OPCODE_YA2):
1976 case OEY2(LD2U_OPCODE_Y2, MODE_OPCODE_YA2):
1980 case OEY2(LD4S_OPCODE_Y2, MODE_OPCODE_YB2):
1984 case OEY2(LD4U_OPCODE_Y2, MODE_OPCODE_YB2):
1988 case OEY2(LD_OPCODE_Y2, MODE_OPCODE_YB2):
1992 tcg_gen_qemu_ld_tl(dest_gr(dc, srcbdest), load_gr(dc, srca),
1994 qemu_log_mask(CPU_LOG_TB_IN_ASM, "%s %s, %s", mnemonic,
1995 reg_names[srcbdest], reg_names[srca]);
1996 return TILEGX_EXCP_NONE;
1998 case OEY2(ST1_OPCODE_Y2, MODE_OPCODE_YC2):
1999 return gen_st_opcode(dc, 0, srca, srcbdest, MO_UB, "st1");
2000 case OEY2(ST2_OPCODE_Y2, MODE_OPCODE_YC2):
2001 return gen_st_opcode(dc, 0, srca, srcbdest, MO_TEUW, "st2");
2002 case OEY2(ST4_OPCODE_Y2, MODE_OPCODE_YC2):
2003 return gen_st_opcode(dc, 0, srca, srcbdest, MO_TEUL, "st4");
2004 case OEY2(ST_OPCODE_Y2, MODE_OPCODE_YC2):
2005 return gen_st_opcode(dc, 0, srca, srcbdest, MO_TEQ, "st");
2008 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
2012 static TileExcp decode_x0(DisasContext *dc, tilegx_bundle_bits bundle)
2014 unsigned opc = get_Opcode_X0(bundle);
2015 unsigned dest = get_Dest_X0(bundle);
2016 unsigned srca = get_SrcA_X0(bundle);
2017 unsigned ext, srcb, bfs, bfe;
2021 case RRR_0_OPCODE_X0:
2022 ext = get_RRROpcodeExtension_X0(bundle);
2023 if (ext == UNARY_RRR_0_OPCODE_X0) {
2024 ext = get_UnaryOpcodeExtension_X0(bundle);
2025 return gen_rr_opcode(dc, OE(opc, ext, X0), dest, srca);
2027 srcb = get_SrcB_X0(bundle);
2028 return gen_rrr_opcode(dc, OE(opc, ext, X0), dest, srca, srcb);
2030 case SHIFT_OPCODE_X0:
2031 ext = get_ShiftOpcodeExtension_X0(bundle);
2032 imm = get_ShAmt_X0(bundle);
2033 return gen_rri_opcode(dc, OE(opc, ext, X0), dest, srca, imm);
2035 case IMM8_OPCODE_X0:
2036 ext = get_Imm8OpcodeExtension_X0(bundle);
2037 imm = (int8_t)get_Imm8_X0(bundle);
2038 return gen_rri_opcode(dc, OE(opc, ext, X0), dest, srca, imm);
2041 ext = get_BFOpcodeExtension_X0(bundle);
2042 bfs = get_BFStart_X0(bundle);
2043 bfe = get_BFEnd_X0(bundle);
2044 return gen_bf_opcode_x0(dc, ext, dest, srca, bfs, bfe);
2046 case ADDLI_OPCODE_X0:
2047 case SHL16INSLI_OPCODE_X0:
2048 case ADDXLI_OPCODE_X0:
2049 imm = (int16_t)get_Imm16_X0(bundle);
2050 return gen_rri_opcode(dc, OE(opc, 0, X0), dest, srca, imm);
2053 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
2057 static TileExcp decode_x1(DisasContext *dc, tilegx_bundle_bits bundle)
2059 unsigned opc = get_Opcode_X1(bundle);
2060 unsigned dest = get_Dest_X1(bundle);
2061 unsigned srca = get_SrcA_X1(bundle);
2066 case RRR_0_OPCODE_X1:
2067 ext = get_RRROpcodeExtension_X1(bundle);
2068 srcb = get_SrcB_X1(bundle);
2070 case UNARY_RRR_0_OPCODE_X1:
2071 ext = get_UnaryOpcodeExtension_X1(bundle);
2072 return gen_rr_opcode(dc, OE(opc, ext, X1), dest, srca);
2073 case ST1_RRR_0_OPCODE_X1:
2074 return gen_st_opcode(dc, dest, srca, srcb, MO_UB, "st1");
2075 case ST2_RRR_0_OPCODE_X1:
2076 return gen_st_opcode(dc, dest, srca, srcb, MO_TEUW, "st2");
2077 case ST4_RRR_0_OPCODE_X1:
2078 return gen_st_opcode(dc, dest, srca, srcb, MO_TEUL, "st4");
2079 case STNT1_RRR_0_OPCODE_X1:
2080 return gen_st_opcode(dc, dest, srca, srcb, MO_UB, "stnt1");
2081 case STNT2_RRR_0_OPCODE_X1:
2082 return gen_st_opcode(dc, dest, srca, srcb, MO_TEUW, "stnt2");
2083 case STNT4_RRR_0_OPCODE_X1:
2084 return gen_st_opcode(dc, dest, srca, srcb, MO_TEUL, "stnt4");
2085 case STNT_RRR_0_OPCODE_X1:
2086 return gen_st_opcode(dc, dest, srca, srcb, MO_TEQ, "stnt");
2087 case ST_RRR_0_OPCODE_X1:
2088 return gen_st_opcode(dc, dest, srca, srcb, MO_TEQ, "st");
2090 return gen_rrr_opcode(dc, OE(opc, ext, X1), dest, srca, srcb);
2092 case SHIFT_OPCODE_X1:
2093 ext = get_ShiftOpcodeExtension_X1(bundle);
2094 imm = get_ShAmt_X1(bundle);
2095 return gen_rri_opcode(dc, OE(opc, ext, X1), dest, srca, imm);
2097 case IMM8_OPCODE_X1:
2098 ext = get_Imm8OpcodeExtension_X1(bundle);
2099 imm = (int8_t)get_Dest_Imm8_X1(bundle);
2100 srcb = get_SrcB_X1(bundle);
2102 case ST1_ADD_IMM8_OPCODE_X1:
2103 return gen_st_add_opcode(dc, srca, srcb, imm, MO_UB, "st1_add");
2104 case ST2_ADD_IMM8_OPCODE_X1:
2105 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEUW, "st2_add");
2106 case ST4_ADD_IMM8_OPCODE_X1:
2107 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEUL, "st4_add");
2108 case STNT1_ADD_IMM8_OPCODE_X1:
2109 return gen_st_add_opcode(dc, srca, srcb, imm, MO_UB, "stnt1_add");
2110 case STNT2_ADD_IMM8_OPCODE_X1:
2111 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEUW, "stnt2_add");
2112 case STNT4_ADD_IMM8_OPCODE_X1:
2113 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEUL, "stnt4_add");
2114 case STNT_ADD_IMM8_OPCODE_X1:
2115 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEQ, "stnt_add");
2116 case ST_ADD_IMM8_OPCODE_X1:
2117 return gen_st_add_opcode(dc, srca, srcb, imm, MO_TEQ, "st_add");
2118 case MFSPR_IMM8_OPCODE_X1:
2119 return gen_mfspr_x1(dc, dest, get_MF_Imm14_X1(bundle));
2120 case MTSPR_IMM8_OPCODE_X1:
2121 return gen_mtspr_x1(dc, get_MT_Imm14_X1(bundle), srca);
2123 imm = (int8_t)get_Imm8_X1(bundle);
2124 return gen_rri_opcode(dc, OE(opc, ext, X1), dest, srca, imm);
2126 case BRANCH_OPCODE_X1:
2127 ext = get_BrType_X1(bundle);
2128 imm = sextract32(get_BrOff_X1(bundle), 0, 17);
2129 return gen_branch_opcode_x1(dc, ext, srca, imm);
2131 case JUMP_OPCODE_X1:
2132 ext = get_JumpOpcodeExtension_X1(bundle);
2133 imm = sextract32(get_JumpOff_X1(bundle), 0, 27);
2134 return gen_jump_opcode_x1(dc, ext, imm);
2136 case ADDLI_OPCODE_X1:
2137 case SHL16INSLI_OPCODE_X1:
2138 case ADDXLI_OPCODE_X1:
2139 imm = (int16_t)get_Imm16_X1(bundle);
2140 return gen_rri_opcode(dc, OE(opc, 0, X1), dest, srca, imm);
2143 return TILEGX_EXCP_OPCODE_UNIMPLEMENTED;
2147 static void notice_excp(DisasContext *dc, uint64_t bundle,
2148 const char *type, TileExcp excp)
2150 if (likely(excp == TILEGX_EXCP_NONE)) {
2153 gen_exception(dc, excp);
2154 if (excp == TILEGX_EXCP_OPCODE_UNIMPLEMENTED) {
2155 qemu_log_mask(LOG_UNIMP, "UNIMP %s, [" FMT64X "]\n", type, bundle);
2159 static void translate_one_bundle(DisasContext *dc, uint64_t bundle)
2163 for (i = 0; i < ARRAY_SIZE(dc->wb); i++) {
2164 DisasContextTemp *wb = &dc->wb[i];
2165 wb->reg = TILEGX_R_NOREG;
2166 TCGV_UNUSED_I64(wb->val);
2170 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
2171 tcg_gen_debug_insn_start(dc->pc);
2174 qemu_log_mask(CPU_LOG_TB_IN_ASM, " %" PRIx64 ": { ", dc->pc);
2175 if (get_Mode(bundle)) {
2176 notice_excp(dc, bundle, "y0", decode_y0(dc, bundle));
2177 qemu_log_mask(CPU_LOG_TB_IN_ASM, " ; ");
2178 notice_excp(dc, bundle, "y1", decode_y1(dc, bundle));
2179 qemu_log_mask(CPU_LOG_TB_IN_ASM, " ; ");
2180 notice_excp(dc, bundle, "y2", decode_y2(dc, bundle));
2182 notice_excp(dc, bundle, "x0", decode_x0(dc, bundle));
2183 qemu_log_mask(CPU_LOG_TB_IN_ASM, " ; ");
2184 notice_excp(dc, bundle, "x1", decode_x1(dc, bundle));
2186 qemu_log_mask(CPU_LOG_TB_IN_ASM, " }\n");
2188 for (i = dc->num_wb - 1; i >= 0; --i) {
2189 DisasContextTemp *wb = &dc->wb[i];
2190 if (wb->reg < TILEGX_R_COUNT) {
2191 tcg_gen_mov_i64(cpu_regs[wb->reg], wb->val);
2193 tcg_temp_free_i64(wb->val);
2196 if (dc->jmp.cond != TCG_COND_NEVER) {
2197 if (dc->jmp.cond == TCG_COND_ALWAYS) {
2198 tcg_gen_mov_i64(cpu_pc, dc->jmp.dest);
2200 TCGv next = tcg_const_i64(dc->pc + TILEGX_BUNDLE_SIZE_IN_BYTES);
2201 tcg_gen_movcond_i64(dc->jmp.cond, cpu_pc,
2202 dc->jmp.val1, load_zero(dc),
2203 dc->jmp.dest, next);
2204 tcg_temp_free_i64(dc->jmp.val1);
2205 tcg_temp_free_i64(next);
2207 tcg_temp_free_i64(dc->jmp.dest);
2210 } else if (dc->atomic_excp != TILEGX_EXCP_NONE) {
2211 gen_exception(dc, dc->atomic_excp);
2215 static inline void gen_intermediate_code_internal(TileGXCPU *cpu,
2216 TranslationBlock *tb,
2220 DisasContext *dc = &ctx;
2221 CPUState *cs = CPU(cpu);
2222 CPUTLGState *env = &cpu->env;
2223 uint64_t pc_start = tb->pc;
2224 uint64_t next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
2227 int max_insns = tb->cflags & CF_COUNT_MASK;
2231 dc->exit_tb = false;
2232 dc->atomic_excp = TILEGX_EXCP_NONE;
2233 dc->jmp.cond = TCG_COND_NEVER;
2234 TCGV_UNUSED_I64(dc->jmp.dest);
2235 TCGV_UNUSED_I64(dc->jmp.val1);
2236 TCGV_UNUSED_I64(dc->zero);
2238 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
2239 qemu_log("IN: %s\n", lookup_symbol(pc_start));
2242 max_insns = CF_COUNT_MASK;
2244 if (cs->singlestep_enabled || singlestep) {
2251 j = tcg_op_buf_count();
2255 tcg_ctx.gen_opc_instr_start[lj++] = 0;
2258 tcg_ctx.gen_opc_pc[lj] = dc->pc;
2259 tcg_ctx.gen_opc_instr_start[lj] = 1;
2260 tcg_ctx.gen_opc_icount[lj] = num_insns;
2262 translate_one_bundle(dc, cpu_ldq_data(env, dc->pc));
2265 /* PC updated and EXIT_TB/GOTO_TB/exception emitted. */
2268 dc->pc += TILEGX_BUNDLE_SIZE_IN_BYTES;
2269 if (++num_insns >= max_insns
2270 || dc->pc >= next_page_start
2271 || tcg_op_buf_full()) {
2272 /* Ending the TB due to TB size or page boundary. Set PC. */
2273 tcg_gen_movi_tl(cpu_pc, dc->pc);
2279 gen_tb_end(tb, num_insns);
2281 j = tcg_op_buf_count();
2284 tcg_ctx.gen_opc_instr_start[lj++] = 0;
2287 tb->size = dc->pc - pc_start;
2288 tb->icount = num_insns;
2291 qemu_log_mask(CPU_LOG_TB_IN_ASM, "\n");
2294 void gen_intermediate_code(CPUTLGState *env, struct TranslationBlock *tb)
2296 gen_intermediate_code_internal(tilegx_env_get_cpu(env), tb, false);
2299 void gen_intermediate_code_pc(CPUTLGState *env, struct TranslationBlock *tb)
2301 gen_intermediate_code_internal(tilegx_env_get_cpu(env), tb, true);
2304 void restore_state_to_opc(CPUTLGState *env, TranslationBlock *tb, int pc_pos)
2306 env->pc = tcg_ctx.gen_opc_pc[pc_pos];
2309 void tilegx_tcg_init(void)
2313 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
2314 cpu_pc = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUTLGState, pc), "pc");
2315 for (i = 0; i < TILEGX_R_COUNT; i++) {
2316 cpu_regs[i] = tcg_global_mem_new_i64(TCG_AREG0,
2317 offsetof(CPUTLGState, regs[i]),