2 * Tiny Code Generator for QEMU
4 * Copyright (c) 2009-2010 Aurelien Jarno <aurelien@aurel32.net>
5 * Based on i386/tcg-target.c - Copyright (c) 2008 Fabrice Bellard
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * Register definitions
31 static const char * const tcg_target_reg_names
[TCG_TARGET_NB_REGS
] = {
32 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
33 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
34 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
35 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
36 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
37 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
38 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
39 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63",
43 #ifndef CONFIG_SOFTMMU
44 #define TCG_GUEST_BASE_REG TCG_REG_R55
47 /* Branch registers */
59 /* Floating point registers */
79 /* Predicate registers */
99 /* Application registers */
104 static const int tcg_target_reg_alloc_order
[] = {
158 static const int tcg_target_call_iarg_regs
[8] = {
169 static const int tcg_target_call_oarg_regs
[] = {
177 /* bundle templates: stops (double bar in the IA64 manual) are marked with
178 an uppercase letter. */
207 OPC_ADD_A1
= 0x10000000000ull
,
208 OPC_AND_A1
= 0x10060000000ull
,
209 OPC_AND_A3
= 0x10160000000ull
,
210 OPC_ANDCM_A1
= 0x10068000000ull
,
211 OPC_ANDCM_A3
= 0x10168000000ull
,
212 OPC_ADDS_A4
= 0x10800000000ull
,
213 OPC_ADDL_A5
= 0x12000000000ull
,
214 OPC_ALLOC_M34
= 0x02c00000000ull
,
215 OPC_BR_DPTK_FEW_B1
= 0x08400000000ull
,
216 OPC_BR_SPTK_MANY_B1
= 0x08000001000ull
,
217 OPC_BR_CALL_SPNT_FEW_B3
= 0x0a200000000ull
,
218 OPC_BR_SPTK_MANY_B4
= 0x00100001000ull
,
219 OPC_BR_CALL_SPTK_MANY_B5
= 0x02100001000ull
,
220 OPC_BR_RET_SPTK_MANY_B4
= 0x00108001100ull
,
221 OPC_BRL_SPTK_MANY_X3
= 0x18000001000ull
,
222 OPC_BRL_CALL_SPNT_MANY_X4
= 0x1a200001000ull
,
223 OPC_BRL_CALL_SPTK_MANY_X4
= 0x1a000001000ull
,
224 OPC_CMP_LT_A6
= 0x18000000000ull
,
225 OPC_CMP_LTU_A6
= 0x1a000000000ull
,
226 OPC_CMP_EQ_A6
= 0x1c000000000ull
,
227 OPC_CMP4_LT_A6
= 0x18400000000ull
,
228 OPC_CMP4_LTU_A6
= 0x1a400000000ull
,
229 OPC_CMP4_EQ_A6
= 0x1c400000000ull
,
230 OPC_DEP_I14
= 0x0ae00000000ull
,
231 OPC_DEP_I15
= 0x08000000000ull
,
232 OPC_DEP_Z_I12
= 0x0a600000000ull
,
233 OPC_EXTR_I11
= 0x0a400002000ull
,
234 OPC_EXTR_U_I11
= 0x0a400000000ull
,
235 OPC_FCVT_FX_TRUNC_S1_F10
= 0x004d0000000ull
,
236 OPC_FCVT_FXU_TRUNC_S1_F10
= 0x004d8000000ull
,
237 OPC_FCVT_XF_F11
= 0x000e0000000ull
,
238 OPC_FMA_S1_F1
= 0x10400000000ull
,
239 OPC_FNMA_S1_F1
= 0x18400000000ull
,
240 OPC_FRCPA_S1_F6
= 0x00600000000ull
,
241 OPC_GETF_SIG_M19
= 0x08708000000ull
,
242 OPC_LD1_M1
= 0x08000000000ull
,
243 OPC_LD1_M3
= 0x0a000000000ull
,
244 OPC_LD2_M1
= 0x08040000000ull
,
245 OPC_LD2_M3
= 0x0a040000000ull
,
246 OPC_LD4_M1
= 0x08080000000ull
,
247 OPC_LD4_M3
= 0x0a080000000ull
,
248 OPC_LD8_M1
= 0x080c0000000ull
,
249 OPC_LD8_M3
= 0x0a0c0000000ull
,
250 OPC_MUX1_I3
= 0x0eca0000000ull
,
251 OPC_NOP_B9
= 0x04008000000ull
,
252 OPC_NOP_F16
= 0x00008000000ull
,
253 OPC_NOP_I18
= 0x00008000000ull
,
254 OPC_NOP_M48
= 0x00008000000ull
,
255 OPC_MOV_I21
= 0x00e00100000ull
,
256 OPC_MOV_RET_I21
= 0x00e00500000ull
,
257 OPC_MOV_I22
= 0x00188000000ull
,
258 OPC_MOV_I_I26
= 0x00150000000ull
,
259 OPC_MOVL_X2
= 0x0c000000000ull
,
260 OPC_OR_A1
= 0x10070000000ull
,
261 OPC_OR_A3
= 0x10170000000ull
,
262 OPC_SETF_EXP_M18
= 0x0c748000000ull
,
263 OPC_SETF_SIG_M18
= 0x0c708000000ull
,
264 OPC_SHL_I7
= 0x0f240000000ull
,
265 OPC_SHR_I5
= 0x0f220000000ull
,
266 OPC_SHR_U_I5
= 0x0f200000000ull
,
267 OPC_SHRP_I10
= 0x0ac00000000ull
,
268 OPC_SXT1_I29
= 0x000a0000000ull
,
269 OPC_SXT2_I29
= 0x000a8000000ull
,
270 OPC_SXT4_I29
= 0x000b0000000ull
,
271 OPC_ST1_M4
= 0x08c00000000ull
,
272 OPC_ST2_M4
= 0x08c40000000ull
,
273 OPC_ST4_M4
= 0x08c80000000ull
,
274 OPC_ST8_M4
= 0x08cc0000000ull
,
275 OPC_SUB_A1
= 0x10028000000ull
,
276 OPC_SUB_A3
= 0x10128000000ull
,
277 OPC_UNPACK4_L_I2
= 0x0f860000000ull
,
278 OPC_XMA_L_F2
= 0x1d000000000ull
,
279 OPC_XOR_A1
= 0x10078000000ull
,
280 OPC_XOR_A3
= 0x10178000000ull
,
281 OPC_ZXT1_I29
= 0x00080000000ull
,
282 OPC_ZXT2_I29
= 0x00088000000ull
,
283 OPC_ZXT4_I29
= 0x00090000000ull
,
285 INSN_NOP_M
= OPC_NOP_M48
, /* nop.m 0 */
286 INSN_NOP_I
= OPC_NOP_I18
, /* nop.i 0 */
289 static inline uint64_t tcg_opc_a1(int qp
, uint64_t opc
, int r1
,
293 | ((r3
& 0x7f) << 20)
294 | ((r2
& 0x7f) << 13)
299 static inline uint64_t tcg_opc_a3(int qp
, uint64_t opc
, int r1
,
300 uint64_t imm
, int r3
)
303 | ((imm
& 0x80) << 29) /* s */
304 | ((imm
& 0x7f) << 13) /* imm7b */
305 | ((r3
& 0x7f) << 20)
310 static inline uint64_t tcg_opc_a4(int qp
, uint64_t opc
, int r1
,
311 uint64_t imm
, int r3
)
314 | ((imm
& 0x2000) << 23) /* s */
315 | ((imm
& 0x1f80) << 20) /* imm6d */
316 | ((imm
& 0x007f) << 13) /* imm7b */
317 | ((r3
& 0x7f) << 20)
322 static inline uint64_t tcg_opc_a5(int qp
, uint64_t opc
, int r1
,
323 uint64_t imm
, int r3
)
326 | ((imm
& 0x200000) << 15) /* s */
327 | ((imm
& 0x1f0000) << 6) /* imm5c */
328 | ((imm
& 0x00ff80) << 20) /* imm9d */
329 | ((imm
& 0x00007f) << 13) /* imm7b */
330 | ((r3
& 0x03) << 20)
335 static inline uint64_t tcg_opc_a6(int qp
, uint64_t opc
, int p1
,
336 int p2
, int r2
, int r3
)
339 | ((p2
& 0x3f) << 27)
340 | ((r3
& 0x7f) << 20)
341 | ((r2
& 0x7f) << 13)
346 static inline uint64_t tcg_opc_b1(int qp
, uint64_t opc
, uint64_t imm
)
349 | ((imm
& 0x100000) << 16) /* s */
350 | ((imm
& 0x0fffff) << 13) /* imm20b */
354 static inline uint64_t tcg_opc_b3(int qp
, uint64_t opc
, int b1
, uint64_t imm
)
357 | ((imm
& 0x100000) << 16) /* s */
358 | ((imm
& 0x0fffff) << 13) /* imm20b */
363 static inline uint64_t tcg_opc_b4(int qp
, uint64_t opc
, int b2
)
370 static inline uint64_t tcg_opc_b5(int qp
, uint64_t opc
, int b1
, int b2
)
379 static inline uint64_t tcg_opc_b9(int qp
, uint64_t opc
, uint64_t imm
)
382 | ((imm
& 0x100000) << 16) /* i */
383 | ((imm
& 0x0fffff) << 6) /* imm20a */
387 static inline uint64_t tcg_opc_f1(int qp
, uint64_t opc
, int f1
,
388 int f3
, int f4
, int f2
)
391 | ((f4
& 0x7f) << 27)
392 | ((f3
& 0x7f) << 20)
393 | ((f2
& 0x7f) << 13)
398 static inline uint64_t tcg_opc_f2(int qp
, uint64_t opc
, int f1
,
399 int f3
, int f4
, int f2
)
402 | ((f4
& 0x7f) << 27)
403 | ((f3
& 0x7f) << 20)
404 | ((f2
& 0x7f) << 13)
409 static inline uint64_t tcg_opc_f6(int qp
, uint64_t opc
, int f1
,
410 int p2
, int f2
, int f3
)
413 | ((p2
& 0x3f) << 27)
414 | ((f3
& 0x7f) << 20)
415 | ((f2
& 0x7f) << 13)
420 static inline uint64_t tcg_opc_f10(int qp
, uint64_t opc
, int f1
, int f2
)
423 | ((f2
& 0x7f) << 13)
428 static inline uint64_t tcg_opc_f11(int qp
, uint64_t opc
, int f1
, int f2
)
431 | ((f2
& 0x7f) << 13)
436 static inline uint64_t tcg_opc_f16(int qp
, uint64_t opc
, uint64_t imm
)
439 | ((imm
& 0x100000) << 16) /* i */
440 | ((imm
& 0x0fffff) << 6) /* imm20a */
444 static inline uint64_t tcg_opc_i2(int qp
, uint64_t opc
, int r1
,
448 | ((r3
& 0x7f) << 20)
449 | ((r2
& 0x7f) << 13)
454 static inline uint64_t tcg_opc_i3(int qp
, uint64_t opc
, int r1
,
458 | ((mbtype
& 0x0f) << 20)
459 | ((r2
& 0x7f) << 13)
464 static inline uint64_t tcg_opc_i5(int qp
, uint64_t opc
, int r1
,
468 | ((r3
& 0x7f) << 20)
469 | ((r2
& 0x7f) << 13)
474 static inline uint64_t tcg_opc_i7(int qp
, uint64_t opc
, int r1
,
478 | ((r3
& 0x7f) << 20)
479 | ((r2
& 0x7f) << 13)
484 static inline uint64_t tcg_opc_i10(int qp
, uint64_t opc
, int r1
,
485 int r2
, int r3
, uint64_t count
)
488 | ((count
& 0x3f) << 27)
489 | ((r3
& 0x7f) << 20)
490 | ((r2
& 0x7f) << 13)
495 static inline uint64_t tcg_opc_i11(int qp
, uint64_t opc
, int r1
,
496 int r3
, uint64_t pos
, uint64_t len
)
499 | ((len
& 0x3f) << 27)
500 | ((r3
& 0x7f) << 20)
501 | ((pos
& 0x3f) << 14)
506 static inline uint64_t tcg_opc_i12(int qp
, uint64_t opc
, int r1
,
507 int r2
, uint64_t pos
, uint64_t len
)
510 | ((len
& 0x3f) << 27)
511 | ((pos
& 0x3f) << 20)
512 | ((r2
& 0x7f) << 13)
517 static inline uint64_t tcg_opc_i14(int qp
, uint64_t opc
, int r1
, uint64_t imm
,
518 int r3
, uint64_t pos
, uint64_t len
)
521 | ((imm
& 0x01) << 36)
522 | ((len
& 0x3f) << 27)
523 | ((r3
& 0x7f) << 20)
524 | ((pos
& 0x3f) << 14)
529 static inline uint64_t tcg_opc_i15(int qp
, uint64_t opc
, int r1
, int r2
,
530 int r3
, uint64_t pos
, uint64_t len
)
533 | ((pos
& 0x3f) << 31)
534 | ((len
& 0x0f) << 27)
535 | ((r3
& 0x7f) << 20)
536 | ((r2
& 0x7f) << 13)
541 static inline uint64_t tcg_opc_i18(int qp
, uint64_t opc
, uint64_t imm
)
544 | ((imm
& 0x100000) << 16) /* i */
545 | ((imm
& 0x0fffff) << 6) /* imm20a */
549 static inline uint64_t tcg_opc_i21(int qp
, uint64_t opc
, int b1
,
550 int r2
, uint64_t imm
)
553 | ((imm
& 0x1ff) << 24)
554 | ((r2
& 0x7f) << 13)
559 static inline uint64_t tcg_opc_i22(int qp
, uint64_t opc
, int r1
, int b2
)
567 static inline uint64_t tcg_opc_i26(int qp
, uint64_t opc
, int ar3
, int r2
)
570 | ((ar3
& 0x7f) << 20)
571 | ((r2
& 0x7f) << 13)
575 static inline uint64_t tcg_opc_i29(int qp
, uint64_t opc
, int r1
, int r3
)
578 | ((r3
& 0x7f) << 20)
583 static inline uint64_t tcg_opc_l2(uint64_t imm
)
585 return (imm
& 0x7fffffffffc00000ull
) >> 22;
588 static inline uint64_t tcg_opc_l3(uint64_t imm
)
590 return (imm
& 0x07fffffffff00000ull
) >> 18;
593 #define tcg_opc_l4 tcg_opc_l3
595 static inline uint64_t tcg_opc_m1(int qp
, uint64_t opc
, int r1
, int r3
)
598 | ((r3
& 0x7f) << 20)
603 static inline uint64_t tcg_opc_m3(int qp
, uint64_t opc
, int r1
,
604 int r3
, uint64_t imm
)
607 | ((imm
& 0x100) << 28) /* s */
608 | ((imm
& 0x080) << 20) /* i */
609 | ((imm
& 0x07f) << 13) /* imm7b */
610 | ((r3
& 0x7f) << 20)
615 static inline uint64_t tcg_opc_m4(int qp
, uint64_t opc
, int r2
, int r3
)
618 | ((r3
& 0x7f) << 20)
619 | ((r2
& 0x7f) << 13)
623 static inline uint64_t tcg_opc_m18(int qp
, uint64_t opc
, int f1
, int r2
)
626 | ((r2
& 0x7f) << 13)
631 static inline uint64_t tcg_opc_m19(int qp
, uint64_t opc
, int r1
, int f2
)
634 | ((f2
& 0x7f) << 13)
639 static inline uint64_t tcg_opc_m34(int qp
, uint64_t opc
, int r1
,
640 int sof
, int sol
, int sor
)
643 | ((sor
& 0x0f) << 27)
644 | ((sol
& 0x7f) << 20)
645 | ((sof
& 0x7f) << 13)
650 static inline uint64_t tcg_opc_m48(int qp
, uint64_t opc
, uint64_t imm
)
653 | ((imm
& 0x100000) << 16) /* i */
654 | ((imm
& 0x0fffff) << 6) /* imm20a */
658 static inline uint64_t tcg_opc_x2(int qp
, uint64_t opc
,
659 int r1
, uint64_t imm
)
662 | ((imm
& 0x8000000000000000ull
) >> 27) /* i */
663 | (imm
& 0x0000000000200000ull
) /* ic */
664 | ((imm
& 0x00000000001f0000ull
) << 6) /* imm5c */
665 | ((imm
& 0x000000000000ff80ull
) << 20) /* imm9d */
666 | ((imm
& 0x000000000000007full
) << 13) /* imm7b */
671 static inline uint64_t tcg_opc_x3(int qp
, uint64_t opc
, uint64_t imm
)
674 | ((imm
& 0x0800000000000000ull
) >> 23) /* i */
675 | ((imm
& 0x00000000000fffffull
) << 13) /* imm20b */
679 static inline uint64_t tcg_opc_x4(int qp
, uint64_t opc
, int b1
, uint64_t imm
)
682 | ((imm
& 0x0800000000000000ull
) >> 23) /* i */
683 | ((imm
& 0x00000000000fffffull
) << 13) /* imm20b */
690 * Relocations - Note that we never encode branches elsewhere than slot 2.
693 static void reloc_pcrel21b_slot2(tcg_insn_unit
*pc
, tcg_insn_unit
*target
)
695 uint64_t imm
= target
- pc
;
697 pc
->hi
= (pc
->hi
& 0xf700000fffffffffull
)
698 | ((imm
& 0x100000) << 39) /* s */
699 | ((imm
& 0x0fffff) << 36); /* imm20b */
702 static uint64_t get_reloc_pcrel21b_slot2(tcg_insn_unit
*pc
)
704 int64_t high
= pc
->hi
;
706 return ((high
>> 39) & 0x100000) + /* s */
707 ((high
>> 36) & 0x0fffff); /* imm20b */
710 static void patch_reloc(tcg_insn_unit
*code_ptr
, int type
,
711 intptr_t value
, intptr_t addend
)
714 assert(type
== R_IA64_PCREL21B
);
715 reloc_pcrel21b_slot2(code_ptr
, (tcg_insn_unit
*)value
);
722 /* parse target specific constraints */
723 static int target_parse_constraint(TCGArgConstraint
*ct
, const char **pct_str
)
730 ct
->ct
|= TCG_CT_REG
;
731 tcg_regset_set(ct
->u
.regs
, 0xffffffffffffffffull
);
734 ct
->ct
|= TCG_CT_CONST_S22
;
737 ct
->ct
|= TCG_CT_REG
;
738 tcg_regset_set(ct
->u
.regs
, 0xffffffffffffffffull
);
739 #if defined(CONFIG_SOFTMMU)
740 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R56
);
741 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R57
);
742 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R58
);
746 /* We are cheating a bit here, using the fact that the register
747 r0 is also the register number 0. Hence there is no need
748 to check for const_args in each instruction. */
749 ct
->ct
|= TCG_CT_CONST_ZERO
;
759 /* test if a constant matches the constraint */
760 static inline int tcg_target_const_match(tcg_target_long val
, TCGType type
,
761 const TCGArgConstraint
*arg_ct
)
765 if (ct
& TCG_CT_CONST
)
767 else if ((ct
& TCG_CT_CONST_ZERO
) && val
== 0)
769 else if ((ct
& TCG_CT_CONST_S22
) && val
== ((int32_t)val
<< 10) >> 10)
779 static tcg_insn_unit
*tb_ret_addr
;
781 static inline void tcg_out_bundle(TCGContext
*s
, int template,
782 uint64_t slot0
, uint64_t slot1
,
785 template &= 0x1f; /* 5 bits */
786 slot0
&= 0x1ffffffffffull
; /* 41 bits */
787 slot1
&= 0x1ffffffffffull
; /* 41 bits */
788 slot2
&= 0x1ffffffffffull
; /* 41 bits */
790 *s
->code_ptr
++ = (tcg_insn_unit
){
791 (slot1
<< 46) | (slot0
<< 5) | template,
792 (slot2
<< 23) | (slot1
>> 18)
796 static inline uint64_t tcg_opc_mov_a(int qp
, TCGReg dst
, TCGReg src
)
798 return tcg_opc_a4(qp
, OPC_ADDS_A4
, dst
, 0, src
);
801 static inline void tcg_out_mov(TCGContext
*s
, TCGType type
,
802 TCGReg ret
, TCGReg arg
)
804 tcg_out_bundle(s
, mmI
,
807 tcg_opc_mov_a(TCG_REG_P0
, ret
, arg
));
810 static inline uint64_t tcg_opc_movi_a(int qp
, TCGReg dst
, int64_t src
)
812 assert(src
== sextract64(src
, 0, 22));
813 return tcg_opc_a5(qp
, OPC_ADDL_A5
, dst
, src
, TCG_REG_R0
);
816 static inline void tcg_out_movi(TCGContext
*s
, TCGType type
,
817 TCGReg reg
, tcg_target_long arg
)
819 tcg_out_bundle(s
, mLX
,
822 tcg_opc_x2 (TCG_REG_P0
, OPC_MOVL_X2
, reg
, arg
));
825 static void tcg_out_br(TCGContext
*s
, TCGLabel
*l
)
829 /* We pay attention here to not modify the branch target by reading
830 the existing value and using it again. This ensure that caches and
831 memory are kept coherent during retranslation. */
833 imm
= l
->u
.value_ptr
- s
->code_ptr
;
835 imm
= get_reloc_pcrel21b_slot2(s
->code_ptr
);
836 tcg_out_reloc(s
, s
->code_ptr
, R_IA64_PCREL21B
, l
, 0);
839 tcg_out_bundle(s
, mmB
,
842 tcg_opc_b1(TCG_REG_P0
, OPC_BR_SPTK_MANY_B1
, imm
));
845 static inline void tcg_out_call(TCGContext
*s
, tcg_insn_unit
*desc
)
847 uintptr_t func
= desc
->lo
, gp
= desc
->hi
, disp
;
849 /* Look through the function descriptor. */
850 tcg_out_bundle(s
, mlx
,
853 tcg_opc_x2 (TCG_REG_P0
, OPC_MOVL_X2
, TCG_REG_R1
, gp
));
854 disp
= (tcg_insn_unit
*)func
- s
->code_ptr
;
855 tcg_out_bundle(s
, mLX
,
858 tcg_opc_x4 (TCG_REG_P0
, OPC_BRL_CALL_SPTK_MANY_X4
,
862 static void tcg_out_exit_tb(TCGContext
*s
, tcg_target_long arg
)
866 /* At least arg == 0 is a common operation. */
867 if (arg
== sextract64(arg
, 0, 22)) {
868 opc1
= tcg_opc_movi_a(TCG_REG_P0
, TCG_REG_R8
, arg
);
870 tcg_out_movi(s
, TCG_TYPE_PTR
, TCG_REG_R8
, arg
);
874 imm
= tb_ret_addr
- s
->code_ptr
;
876 tcg_out_bundle(s
, mLX
,
879 tcg_opc_x3 (TCG_REG_P0
, OPC_BRL_SPTK_MANY_X3
, imm
));
882 static inline void tcg_out_goto_tb(TCGContext
*s
, TCGArg arg
)
884 if (s
->tb_jmp_offset
) {
885 /* direct jump method */
888 /* indirect jump method */
889 tcg_out_movi(s
, TCG_TYPE_PTR
, TCG_REG_R2
,
890 (tcg_target_long
)(s
->tb_next
+ arg
));
891 tcg_out_bundle(s
, MmI
,
892 tcg_opc_m1 (TCG_REG_P0
, OPC_LD8_M1
,
893 TCG_REG_R2
, TCG_REG_R2
),
895 tcg_opc_i21(TCG_REG_P0
, OPC_MOV_I21
, TCG_REG_B6
,
897 tcg_out_bundle(s
, mmB
,
900 tcg_opc_b4 (TCG_REG_P0
, OPC_BR_SPTK_MANY_B4
,
903 s
->tb_next_offset
[arg
] = tcg_current_code_size(s
);
906 static inline void tcg_out_jmp(TCGContext
*s
, TCGArg addr
)
908 tcg_out_bundle(s
, mmI
,
911 tcg_opc_i21(TCG_REG_P0
, OPC_MOV_I21
, TCG_REG_B6
, addr
, 0));
912 tcg_out_bundle(s
, mmB
,
915 tcg_opc_b4(TCG_REG_P0
, OPC_BR_SPTK_MANY_B4
, TCG_REG_B6
));
918 static inline void tcg_out_ld_rel(TCGContext
*s
, uint64_t opc_m4
, TCGArg arg
,
919 TCGArg arg1
, tcg_target_long arg2
)
921 if (arg2
== ((int16_t)arg2
>> 2) << 2) {
922 tcg_out_bundle(s
, MmI
,
923 tcg_opc_a4(TCG_REG_P0
, OPC_ADDS_A4
,
924 TCG_REG_R2
, arg2
, arg1
),
925 tcg_opc_m1 (TCG_REG_P0
, opc_m4
, arg
, TCG_REG_R2
),
928 tcg_out_movi(s
, TCG_TYPE_PTR
, TCG_REG_R2
, arg2
);
929 tcg_out_bundle(s
, MmI
,
930 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
,
931 TCG_REG_R2
, TCG_REG_R2
, arg1
),
932 tcg_opc_m1 (TCG_REG_P0
, opc_m4
, arg
, TCG_REG_R2
),
937 static inline void tcg_out_st_rel(TCGContext
*s
, uint64_t opc_m4
, TCGArg arg
,
938 TCGArg arg1
, tcg_target_long arg2
)
940 if (arg2
== ((int16_t)arg2
>> 2) << 2) {
941 tcg_out_bundle(s
, MmI
,
942 tcg_opc_a4(TCG_REG_P0
, OPC_ADDS_A4
,
943 TCG_REG_R2
, arg2
, arg1
),
944 tcg_opc_m4 (TCG_REG_P0
, opc_m4
, arg
, TCG_REG_R2
),
947 tcg_out_movi(s
, TCG_TYPE_PTR
, TCG_REG_R2
, arg2
);
948 tcg_out_bundle(s
, MmI
,
949 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
,
950 TCG_REG_R2
, TCG_REG_R2
, arg1
),
951 tcg_opc_m4 (TCG_REG_P0
, opc_m4
, arg
, TCG_REG_R2
),
956 static inline void tcg_out_ld(TCGContext
*s
, TCGType type
, TCGReg arg
,
957 TCGReg arg1
, intptr_t arg2
)
959 if (type
== TCG_TYPE_I32
) {
960 tcg_out_ld_rel(s
, OPC_LD4_M1
, arg
, arg1
, arg2
);
962 tcg_out_ld_rel(s
, OPC_LD8_M1
, arg
, arg1
, arg2
);
966 static inline void tcg_out_st(TCGContext
*s
, TCGType type
, TCGReg arg
,
967 TCGReg arg1
, intptr_t arg2
)
969 if (type
== TCG_TYPE_I32
) {
970 tcg_out_st_rel(s
, OPC_ST4_M4
, arg
, arg1
, arg2
);
972 tcg_out_st_rel(s
, OPC_ST8_M4
, arg
, arg1
, arg2
);
976 static inline void tcg_out_alu(TCGContext
*s
, uint64_t opc_a1
, uint64_t opc_a3
,
977 TCGReg ret
, TCGArg arg1
, int const_arg1
,
978 TCGArg arg2
, int const_arg2
)
980 uint64_t opc1
= 0, opc2
= 0, opc3
= 0;
982 if (const_arg2
&& arg2
!= 0) {
983 opc2
= tcg_opc_movi_a(TCG_REG_P0
, TCG_REG_R3
, arg2
);
986 if (const_arg1
&& arg1
!= 0) {
987 if (opc_a3
&& arg1
== (int8_t)arg1
) {
988 opc3
= tcg_opc_a3(TCG_REG_P0
, opc_a3
, ret
, arg1
, arg2
);
990 opc1
= tcg_opc_movi_a(TCG_REG_P0
, TCG_REG_R2
, arg1
);
995 opc3
= tcg_opc_a1(TCG_REG_P0
, opc_a1
, ret
, arg1
, arg2
);
998 tcg_out_bundle(s
, (opc1
|| opc2
? mII
: miI
),
999 opc1
? opc1
: INSN_NOP_M
,
1000 opc2
? opc2
: INSN_NOP_I
,
1004 static inline void tcg_out_add(TCGContext
*s
, TCGReg ret
, TCGReg arg1
,
1005 TCGArg arg2
, int const_arg2
)
1007 if (const_arg2
&& arg2
== sextract64(arg2
, 0, 14)) {
1008 tcg_out_bundle(s
, mmI
,
1011 tcg_opc_a4(TCG_REG_P0
, OPC_ADDS_A4
, ret
, arg2
, arg1
));
1013 tcg_out_alu(s
, OPC_ADD_A1
, 0, ret
, arg1
, 0, arg2
, const_arg2
);
1017 static inline void tcg_out_sub(TCGContext
*s
, TCGReg ret
, TCGArg arg1
,
1018 int const_arg1
, TCGArg arg2
, int const_arg2
)
1020 if (!const_arg1
&& const_arg2
&& -arg2
== sextract64(-arg2
, 0, 14)) {
1021 tcg_out_bundle(s
, mmI
,
1024 tcg_opc_a4(TCG_REG_P0
, OPC_ADDS_A4
, ret
, -arg2
, arg1
));
1026 tcg_out_alu(s
, OPC_SUB_A1
, OPC_SUB_A3
, ret
,
1027 arg1
, const_arg1
, arg2
, const_arg2
);
1031 static inline void tcg_out_eqv(TCGContext
*s
, TCGArg ret
,
1032 TCGArg arg1
, int const_arg1
,
1033 TCGArg arg2
, int const_arg2
)
1035 tcg_out_bundle(s
, mII
,
1037 tcg_opc_a1 (TCG_REG_P0
, OPC_XOR_A1
, ret
, arg1
, arg2
),
1038 tcg_opc_a3 (TCG_REG_P0
, OPC_ANDCM_A3
, ret
, -1, ret
));
1041 static inline void tcg_out_nand(TCGContext
*s
, TCGArg ret
,
1042 TCGArg arg1
, int const_arg1
,
1043 TCGArg arg2
, int const_arg2
)
1045 tcg_out_bundle(s
, mII
,
1047 tcg_opc_a1 (TCG_REG_P0
, OPC_AND_A1
, ret
, arg1
, arg2
),
1048 tcg_opc_a3 (TCG_REG_P0
, OPC_ANDCM_A3
, ret
, -1, ret
));
1051 static inline void tcg_out_nor(TCGContext
*s
, TCGArg ret
,
1052 TCGArg arg1
, int const_arg1
,
1053 TCGArg arg2
, int const_arg2
)
1055 tcg_out_bundle(s
, mII
,
1057 tcg_opc_a1 (TCG_REG_P0
, OPC_OR_A1
, ret
, arg1
, arg2
),
1058 tcg_opc_a3 (TCG_REG_P0
, OPC_ANDCM_A3
, ret
, -1, ret
));
1061 static inline void tcg_out_orc(TCGContext
*s
, TCGArg ret
,
1062 TCGArg arg1
, int const_arg1
,
1063 TCGArg arg2
, int const_arg2
)
1065 tcg_out_bundle(s
, mII
,
1067 tcg_opc_a3 (TCG_REG_P0
, OPC_ANDCM_A3
, TCG_REG_R2
, -1, arg2
),
1068 tcg_opc_a1 (TCG_REG_P0
, OPC_OR_A1
, ret
, arg1
, TCG_REG_R2
));
1071 static inline void tcg_out_mul(TCGContext
*s
, TCGArg ret
,
1072 TCGArg arg1
, TCGArg arg2
)
1074 tcg_out_bundle(s
, mmI
,
1075 tcg_opc_m18(TCG_REG_P0
, OPC_SETF_SIG_M18
, TCG_REG_F6
, arg1
),
1076 tcg_opc_m18(TCG_REG_P0
, OPC_SETF_SIG_M18
, TCG_REG_F7
, arg2
),
1078 tcg_out_bundle(s
, mmF
,
1081 tcg_opc_f2 (TCG_REG_P0
, OPC_XMA_L_F2
, TCG_REG_F6
, TCG_REG_F6
,
1082 TCG_REG_F7
, TCG_REG_F0
));
1083 tcg_out_bundle(s
, miI
,
1084 tcg_opc_m19(TCG_REG_P0
, OPC_GETF_SIG_M19
, ret
, TCG_REG_F6
),
1089 static inline void tcg_out_sar_i32(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1090 TCGArg arg2
, int const_arg2
)
1093 tcg_out_bundle(s
, miI
,
1096 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_I11
,
1097 ret
, arg1
, arg2
, 31 - arg2
));
1099 tcg_out_bundle(s
, mII
,
1100 tcg_opc_a3 (TCG_REG_P0
, OPC_AND_A3
,
1101 TCG_REG_R3
, 0x1f, arg2
),
1102 tcg_opc_i29(TCG_REG_P0
, OPC_SXT4_I29
, TCG_REG_R2
, arg1
),
1103 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_I5
, ret
,
1104 TCG_REG_R2
, TCG_REG_R3
));
1108 static inline void tcg_out_sar_i64(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1109 TCGArg arg2
, int const_arg2
)
1112 tcg_out_bundle(s
, miI
,
1115 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_I11
,
1116 ret
, arg1
, arg2
, 63 - arg2
));
1118 tcg_out_bundle(s
, miI
,
1121 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_I5
, ret
, arg1
, arg2
));
1125 static inline void tcg_out_shl_i32(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1126 TCGArg arg2
, int const_arg2
)
1129 tcg_out_bundle(s
, miI
,
1132 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
, ret
,
1133 arg1
, 63 - arg2
, 31 - arg2
));
1135 tcg_out_bundle(s
, mII
,
1137 tcg_opc_a3 (TCG_REG_P0
, OPC_AND_A3
, TCG_REG_R2
,
1139 tcg_opc_i7 (TCG_REG_P0
, OPC_SHL_I7
, ret
,
1144 static inline void tcg_out_shl_i64(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1145 TCGArg arg2
, int const_arg2
)
1148 tcg_out_bundle(s
, miI
,
1151 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
, ret
,
1152 arg1
, 63 - arg2
, 63 - arg2
));
1154 tcg_out_bundle(s
, miI
,
1157 tcg_opc_i7 (TCG_REG_P0
, OPC_SHL_I7
, ret
,
1162 static inline void tcg_out_shr_i32(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1163 TCGArg arg2
, int const_arg2
)
1166 tcg_out_bundle(s
, miI
,
1169 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
, ret
,
1170 arg1
, arg2
, 31 - arg2
));
1172 tcg_out_bundle(s
, mII
,
1173 tcg_opc_a3 (TCG_REG_P0
, OPC_AND_A3
, TCG_REG_R3
,
1175 tcg_opc_i29(TCG_REG_P0
, OPC_ZXT4_I29
, TCG_REG_R2
, arg1
),
1176 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, ret
,
1177 TCG_REG_R2
, TCG_REG_R3
));
1181 static inline void tcg_out_shr_i64(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1182 TCGArg arg2
, int const_arg2
)
1185 tcg_out_bundle(s
, miI
,
1188 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
, ret
,
1189 arg1
, arg2
, 63 - arg2
));
1191 tcg_out_bundle(s
, miI
,
1194 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, ret
,
1199 static inline void tcg_out_rotl_i32(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1200 TCGArg arg2
, int const_arg2
)
1203 tcg_out_bundle(s
, mII
,
1205 tcg_opc_i2 (TCG_REG_P0
, OPC_UNPACK4_L_I2
,
1206 TCG_REG_R2
, arg1
, arg1
),
1207 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
, ret
,
1208 TCG_REG_R2
, 32 - arg2
, 31));
1210 tcg_out_bundle(s
, miI
,
1212 tcg_opc_i2 (TCG_REG_P0
, OPC_UNPACK4_L_I2
,
1213 TCG_REG_R2
, arg1
, arg1
),
1214 tcg_opc_a3 (TCG_REG_P0
, OPC_AND_A3
, TCG_REG_R3
,
1216 tcg_out_bundle(s
, mII
,
1218 tcg_opc_a3 (TCG_REG_P0
, OPC_SUB_A3
, TCG_REG_R3
,
1220 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, ret
,
1221 TCG_REG_R2
, TCG_REG_R3
));
1225 static inline void tcg_out_rotl_i64(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1226 TCGArg arg2
, int const_arg2
)
1229 tcg_out_bundle(s
, miI
,
1232 tcg_opc_i10(TCG_REG_P0
, OPC_SHRP_I10
, ret
, arg1
,
1233 arg1
, 0x40 - arg2
));
1235 tcg_out_bundle(s
, mII
,
1236 tcg_opc_a3 (TCG_REG_P0
, OPC_SUB_A3
, TCG_REG_R2
,
1238 tcg_opc_i7 (TCG_REG_P0
, OPC_SHL_I7
, TCG_REG_R3
,
1240 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, TCG_REG_R2
,
1242 tcg_out_bundle(s
, miI
,
1245 tcg_opc_a1 (TCG_REG_P0
, OPC_OR_A1
, ret
,
1246 TCG_REG_R2
, TCG_REG_R3
));
1250 static inline void tcg_out_rotr_i32(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1251 TCGArg arg2
, int const_arg2
)
1254 tcg_out_bundle(s
, mII
,
1256 tcg_opc_i2 (TCG_REG_P0
, OPC_UNPACK4_L_I2
,
1257 TCG_REG_R2
, arg1
, arg1
),
1258 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
, ret
,
1259 TCG_REG_R2
, arg2
, 31));
1261 tcg_out_bundle(s
, mII
,
1262 tcg_opc_a3 (TCG_REG_P0
, OPC_AND_A3
, TCG_REG_R3
,
1264 tcg_opc_i2 (TCG_REG_P0
, OPC_UNPACK4_L_I2
,
1265 TCG_REG_R2
, arg1
, arg1
),
1266 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, ret
,
1267 TCG_REG_R2
, TCG_REG_R3
));
1271 static inline void tcg_out_rotr_i64(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1272 TCGArg arg2
, int const_arg2
)
1275 tcg_out_bundle(s
, miI
,
1278 tcg_opc_i10(TCG_REG_P0
, OPC_SHRP_I10
, ret
, arg1
,
1281 tcg_out_bundle(s
, mII
,
1282 tcg_opc_a3 (TCG_REG_P0
, OPC_SUB_A3
, TCG_REG_R2
,
1284 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, TCG_REG_R3
,
1286 tcg_opc_i7 (TCG_REG_P0
, OPC_SHL_I7
, TCG_REG_R2
,
1288 tcg_out_bundle(s
, miI
,
1291 tcg_opc_a1 (TCG_REG_P0
, OPC_OR_A1
, ret
,
1292 TCG_REG_R2
, TCG_REG_R3
));
1296 static const uint64_t opc_ext_i29
[8] = {
1297 OPC_ZXT1_I29
, OPC_ZXT2_I29
, OPC_ZXT4_I29
, 0,
1298 OPC_SXT1_I29
, OPC_SXT2_I29
, OPC_SXT4_I29
, 0
1301 static inline uint64_t tcg_opc_ext_i(int qp
, TCGMemOp opc
, TCGReg d
, TCGReg s
)
1303 if ((opc
& MO_SIZE
) == MO_64
) {
1304 return tcg_opc_mov_a(qp
, d
, s
);
1306 return tcg_opc_i29(qp
, opc_ext_i29
[opc
& MO_SSIZE
], d
, s
);
1310 static inline void tcg_out_ext(TCGContext
*s
, uint64_t opc_i29
,
1311 TCGArg ret
, TCGArg arg
)
1313 tcg_out_bundle(s
, miI
,
1316 tcg_opc_i29(TCG_REG_P0
, opc_i29
, ret
, arg
));
1319 static inline uint64_t tcg_opc_bswap64_i(int qp
, TCGReg d
, TCGReg s
)
1321 return tcg_opc_i3(qp
, OPC_MUX1_I3
, d
, s
, 0xb);
1324 static inline void tcg_out_bswap16(TCGContext
*s
, TCGArg ret
, TCGArg arg
)
1326 tcg_out_bundle(s
, mII
,
1328 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
, ret
, arg
, 15, 15),
1329 tcg_opc_bswap64_i(TCG_REG_P0
, ret
, ret
));
1332 static inline void tcg_out_bswap32(TCGContext
*s
, TCGArg ret
, TCGArg arg
)
1334 tcg_out_bundle(s
, mII
,
1336 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
, ret
, arg
, 31, 31),
1337 tcg_opc_bswap64_i(TCG_REG_P0
, ret
, ret
));
1340 static inline void tcg_out_bswap64(TCGContext
*s
, TCGArg ret
, TCGArg arg
)
1342 tcg_out_bundle(s
, miI
,
1345 tcg_opc_bswap64_i(TCG_REG_P0
, ret
, arg
));
1348 static inline void tcg_out_deposit(TCGContext
*s
, TCGArg ret
, TCGArg a1
,
1349 TCGArg a2
, int const_a2
, int pos
, int len
)
1351 uint64_t i1
= 0, i2
= 0;
1352 int cpos
= 63 - pos
, lm1
= len
- 1;
1355 /* Truncate the value of a constant a2 to the width of the field. */
1356 int mask
= (1u << len
) - 1;
1359 if (a2
== 0 || a2
== mask
) {
1360 /* 1-bit signed constant inserted into register. */
1361 i2
= tcg_opc_i14(TCG_REG_P0
, OPC_DEP_I14
, ret
, a2
, a1
, cpos
, lm1
);
1363 /* Otherwise, load any constant into a temporary. Do this into
1364 the first I slot to help out with cross-unit delays. */
1365 i1
= tcg_opc_movi_a(TCG_REG_P0
, TCG_REG_R2
, a2
);
1370 i2
= tcg_opc_i15(TCG_REG_P0
, OPC_DEP_I15
, ret
, a2
, a1
, cpos
, lm1
);
1372 tcg_out_bundle(s
, (i1
? mII
: miI
),
1374 i1
? i1
: INSN_NOP_I
,
1378 static inline uint64_t tcg_opc_cmp_a(int qp
, TCGCond cond
, TCGArg arg1
,
1379 TCGArg arg2
, int cmp4
)
1381 uint64_t opc_eq_a6
, opc_lt_a6
, opc_ltu_a6
;
1384 opc_eq_a6
= OPC_CMP4_EQ_A6
;
1385 opc_lt_a6
= OPC_CMP4_LT_A6
;
1386 opc_ltu_a6
= OPC_CMP4_LTU_A6
;
1388 opc_eq_a6
= OPC_CMP_EQ_A6
;
1389 opc_lt_a6
= OPC_CMP_LT_A6
;
1390 opc_ltu_a6
= OPC_CMP_LTU_A6
;
1395 return tcg_opc_a6 (qp
, opc_eq_a6
, TCG_REG_P6
, TCG_REG_P7
, arg1
, arg2
);
1397 return tcg_opc_a6 (qp
, opc_eq_a6
, TCG_REG_P7
, TCG_REG_P6
, arg1
, arg2
);
1399 return tcg_opc_a6 (qp
, opc_lt_a6
, TCG_REG_P6
, TCG_REG_P7
, arg1
, arg2
);
1401 return tcg_opc_a6 (qp
, opc_ltu_a6
, TCG_REG_P6
, TCG_REG_P7
, arg1
, arg2
);
1403 return tcg_opc_a6 (qp
, opc_lt_a6
, TCG_REG_P7
, TCG_REG_P6
, arg1
, arg2
);
1405 return tcg_opc_a6 (qp
, opc_ltu_a6
, TCG_REG_P7
, TCG_REG_P6
, arg1
, arg2
);
1407 return tcg_opc_a6 (qp
, opc_lt_a6
, TCG_REG_P7
, TCG_REG_P6
, arg2
, arg1
);
1409 return tcg_opc_a6 (qp
, opc_ltu_a6
, TCG_REG_P7
, TCG_REG_P6
, arg2
, arg1
);
1411 return tcg_opc_a6 (qp
, opc_lt_a6
, TCG_REG_P6
, TCG_REG_P7
, arg2
, arg1
);
1413 return tcg_opc_a6 (qp
, opc_ltu_a6
, TCG_REG_P6
, TCG_REG_P7
, arg2
, arg1
);
1420 static inline void tcg_out_brcond(TCGContext
*s
, TCGCond cond
, TCGReg arg1
,
1421 TCGReg arg2
, TCGLabel
*l
, int cmp4
)
1425 /* We pay attention here to not modify the branch target by reading
1426 the existing value and using it again. This ensure that caches and
1427 memory are kept coherent during retranslation. */
1429 imm
= l
->u
.value_ptr
- s
->code_ptr
;
1431 imm
= get_reloc_pcrel21b_slot2(s
->code_ptr
);
1432 tcg_out_reloc(s
, s
->code_ptr
, R_IA64_PCREL21B
, l
, 0);
1435 tcg_out_bundle(s
, miB
,
1437 tcg_opc_cmp_a(TCG_REG_P0
, cond
, arg1
, arg2
, cmp4
),
1438 tcg_opc_b1(TCG_REG_P6
, OPC_BR_DPTK_FEW_B1
, imm
));
1441 static inline void tcg_out_setcond(TCGContext
*s
, TCGCond cond
, TCGArg ret
,
1442 TCGArg arg1
, TCGArg arg2
, int cmp4
)
1444 tcg_out_bundle(s
, MmI
,
1445 tcg_opc_cmp_a(TCG_REG_P0
, cond
, arg1
, arg2
, cmp4
),
1446 tcg_opc_movi_a(TCG_REG_P6
, ret
, 1),
1447 tcg_opc_movi_a(TCG_REG_P7
, ret
, 0));
1450 static inline void tcg_out_movcond(TCGContext
*s
, TCGCond cond
, TCGArg ret
,
1451 TCGArg c1
, TCGArg c2
,
1452 TCGArg v1
, int const_v1
,
1453 TCGArg v2
, int const_v2
, int cmp4
)
1455 uint64_t opc1
, opc2
;
1458 opc1
= tcg_opc_movi_a(TCG_REG_P6
, ret
, v1
);
1459 } else if (ret
== v1
) {
1462 opc1
= tcg_opc_mov_a(TCG_REG_P6
, ret
, v1
);
1465 opc2
= tcg_opc_movi_a(TCG_REG_P7
, ret
, v2
);
1466 } else if (ret
== v2
) {
1469 opc2
= tcg_opc_mov_a(TCG_REG_P7
, ret
, v2
);
1472 tcg_out_bundle(s
, MmI
,
1473 tcg_opc_cmp_a(TCG_REG_P0
, cond
, c1
, c2
, cmp4
),
1478 #if defined(CONFIG_SOFTMMU)
1479 /* We're expecting to use an signed 22-bit immediate add. */
1480 QEMU_BUILD_BUG_ON(offsetof(CPUArchState
, tlb_table
[NB_MMU_MODES
- 1][1])
1483 /* Load and compare a TLB entry, and return the result in (p6, p7).
1484 R2 is loaded with the addend TLB entry.
1485 R57 is loaded with the address, zero extented on 32-bit targets.
1486 R1, R3 are clobbered, leaving R56 free for...
1487 BSWAP_1, BSWAP_2 and I-slot insns for swapping data for store. */
1488 static inline void tcg_out_qemu_tlb(TCGContext
*s
, TCGReg addr_reg
,
1489 TCGMemOp s_bits
, int off_rw
, int off_add
,
1490 uint64_t bswap1
, uint64_t bswap2
)
1495 extr.u r3 = addr_reg, ... # extract tlb page
1496 zxt4 r57 = addr_reg # or mov for 64-bit guest
1500 shl r3 = r3, cteb # via dep.z
1501 dep r1 = 0, r57, ... # zero page ofs, keep align
1506 ld4 r3 = [r2], off_add-off_rw # or ld8 for 64-bit guest
1511 cmp.eq p6, p7 = r3, r58
1515 tcg_out_bundle(s
, miI
,
1516 tcg_opc_movi_a(TCG_REG_P0
, TCG_REG_R2
, off_rw
),
1517 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
, TCG_REG_R3
,
1518 addr_reg
, TARGET_PAGE_BITS
, CPU_TLB_BITS
- 1),
1519 tcg_opc_ext_i(TCG_REG_P0
,
1520 TARGET_LONG_BITS
== 32 ? MO_UL
: MO_Q
,
1521 TCG_REG_R57
, addr_reg
));
1522 tcg_out_bundle(s
, miI
,
1523 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
, TCG_REG_R2
,
1524 TCG_REG_R2
, TCG_AREG0
),
1525 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
, TCG_REG_R3
,
1526 TCG_REG_R3
, 63 - CPU_TLB_ENTRY_BITS
,
1527 63 - CPU_TLB_ENTRY_BITS
),
1528 tcg_opc_i14(TCG_REG_P0
, OPC_DEP_I14
, TCG_REG_R1
, 0,
1529 TCG_REG_R57
, 63 - s_bits
,
1530 TARGET_PAGE_BITS
- s_bits
- 1));
1531 tcg_out_bundle(s
, MmI
,
1532 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
,
1533 TCG_REG_R2
, TCG_REG_R2
, TCG_REG_R3
),
1534 tcg_opc_m3 (TCG_REG_P0
,
1535 (TARGET_LONG_BITS
== 32
1536 ? OPC_LD4_M3
: OPC_LD8_M3
), TCG_REG_R3
,
1537 TCG_REG_R2
, off_add
- off_rw
),
1539 tcg_out_bundle(s
, mmI
,
1540 tcg_opc_m1 (TCG_REG_P0
, OPC_LD8_M1
, TCG_REG_R2
, TCG_REG_R2
),
1541 tcg_opc_a6 (TCG_REG_P0
, OPC_CMP_EQ_A6
, TCG_REG_P6
,
1542 TCG_REG_P7
, TCG_REG_R1
, TCG_REG_R3
),
1546 typedef struct TCGLabelQemuLdst
{
1549 tcg_insn_unit
*label_ptr
; /* label pointers to be updated */
1550 struct TCGLabelQemuLdst
*next
;
1553 typedef struct TCGBackendData
{
1554 TCGLabelQemuLdst
*labels
;
1557 static inline void tcg_out_tb_init(TCGContext
*s
)
1559 s
->be
->labels
= NULL
;
1562 static void add_qemu_ldst_label(TCGContext
*s
, bool is_ld
, TCGMemOp opc
,
1563 tcg_insn_unit
*label_ptr
)
1565 TCGBackendData
*be
= s
->be
;
1566 TCGLabelQemuLdst
*l
= tcg_malloc(sizeof(*l
));
1569 l
->size
= opc
& MO_SIZE
;
1570 l
->label_ptr
= label_ptr
;
1571 l
->next
= be
->labels
;
1575 static void tcg_out_tb_finalize(TCGContext
*s
)
1577 static const void * const helpers
[8] = {
1582 helper_ret_ldub_mmu
,
1587 tcg_insn_unit
*thunks
[8] = { };
1588 TCGLabelQemuLdst
*l
;
1590 for (l
= s
->be
->labels
; l
!= NULL
; l
= l
->next
) {
1591 long x
= l
->is_ld
* 4 + l
->size
;
1592 tcg_insn_unit
*dest
= thunks
[x
];
1594 /* The out-of-line thunks are all the same; load the return address
1595 from B0, load the GP, and branch to the code. Note that we are
1596 always post-call, so the register window has rolled, so we're
1597 using incoming parameter register numbers, not outgoing. */
1599 uintptr_t *desc
= (uintptr_t *)helpers
[x
];
1600 uintptr_t func
= desc
[0], gp
= desc
[1], disp
;
1602 thunks
[x
] = dest
= s
->code_ptr
;
1604 tcg_out_bundle(s
, mlx
,
1607 tcg_opc_x2 (TCG_REG_P0
, OPC_MOVL_X2
,
1609 tcg_out_bundle(s
, mii
,
1612 tcg_opc_i22(TCG_REG_P0
, OPC_MOV_I22
,
1613 l
->is_ld
? TCG_REG_R35
: TCG_REG_R36
,
1615 disp
= (tcg_insn_unit
*)func
- s
->code_ptr
;
1616 tcg_out_bundle(s
, mLX
,
1619 tcg_opc_x3 (TCG_REG_P0
, OPC_BRL_SPTK_MANY_X3
, disp
));
1622 reloc_pcrel21b_slot2(l
->label_ptr
, dest
);
1626 static inline void tcg_out_qemu_ld(TCGContext
*s
, const TCGArg
*args
)
1628 static const uint64_t opc_ld_m1
[4] = {
1629 OPC_LD1_M1
, OPC_LD2_M1
, OPC_LD4_M1
, OPC_LD8_M1
1631 int addr_reg
, data_reg
, mem_index
;
1633 TCGMemOp opc
, s_bits
;
1634 uint64_t fin1
, fin2
;
1635 tcg_insn_unit
*label_ptr
;
1640 opc
= get_memop(oi
);
1641 mem_index
= get_mmuidx(oi
);
1642 s_bits
= opc
& MO_SIZE
;
1644 /* Read the TLB entry */
1645 tcg_out_qemu_tlb(s
, addr_reg
, s_bits
,
1646 offsetof(CPUArchState
, tlb_table
[mem_index
][0].addr_read
),
1647 offsetof(CPUArchState
, tlb_table
[mem_index
][0].addend
),
1648 INSN_NOP_I
, INSN_NOP_I
);
1650 /* P6 is the fast path, and P7 the slow path */
1653 if (opc
& MO_BSWAP
) {
1654 fin1
= tcg_opc_bswap64_i(TCG_REG_P0
, data_reg
, TCG_REG_R8
);
1655 if (s_bits
< MO_64
) {
1656 int shift
= 64 - (8 << s_bits
);
1657 fin2
= (opc
& MO_SIGN
? OPC_EXTR_I11
: OPC_EXTR_U_I11
);
1658 fin2
= tcg_opc_i11(TCG_REG_P0
, fin2
,
1659 data_reg
, data_reg
, shift
, 63 - shift
);
1662 fin1
= tcg_opc_ext_i(TCG_REG_P0
, opc
, data_reg
, TCG_REG_R8
);
1665 tcg_out_bundle(s
, mmI
,
1666 tcg_opc_mov_a(TCG_REG_P7
, TCG_REG_R56
, TCG_AREG0
),
1667 tcg_opc_a1 (TCG_REG_P6
, OPC_ADD_A1
, TCG_REG_R2
,
1668 TCG_REG_R2
, TCG_REG_R57
),
1669 tcg_opc_movi_a(TCG_REG_P7
, TCG_REG_R58
, oi
));
1670 label_ptr
= s
->code_ptr
;
1671 tcg_out_bundle(s
, miB
,
1672 tcg_opc_m1 (TCG_REG_P6
, opc_ld_m1
[s_bits
],
1673 TCG_REG_R8
, TCG_REG_R2
),
1675 tcg_opc_b3 (TCG_REG_P7
, OPC_BR_CALL_SPNT_FEW_B3
, TCG_REG_B0
,
1676 get_reloc_pcrel21b_slot2(label_ptr
)));
1678 add_qemu_ldst_label(s
, 1, opc
, label_ptr
);
1680 /* Note that we always use LE helper functions, so the bswap insns
1681 here for the fast path also apply to the slow path. */
1682 tcg_out_bundle(s
, (fin2
? mII
: miI
),
1685 fin2
? fin2
: INSN_NOP_I
);
1688 static inline void tcg_out_qemu_st(TCGContext
*s
, const TCGArg
*args
)
1690 static const uint64_t opc_st_m4
[4] = {
1691 OPC_ST1_M4
, OPC_ST2_M4
, OPC_ST4_M4
, OPC_ST8_M4
1693 TCGReg addr_reg
, data_reg
;
1695 uint64_t pre1
, pre2
;
1697 TCGMemOp opc
, s_bits
;
1698 tcg_insn_unit
*label_ptr
;
1703 opc
= get_memop(oi
);
1704 mem_index
= get_mmuidx(oi
);
1705 s_bits
= opc
& MO_SIZE
;
1707 /* Note that we always use LE helper functions, so the bswap insns
1708 that are here for the fast path also apply to the slow path,
1709 and move the data into the argument register. */
1711 if (opc
& MO_BSWAP
) {
1712 pre1
= tcg_opc_bswap64_i(TCG_REG_P0
, TCG_REG_R58
, data_reg
);
1713 if (s_bits
< MO_64
) {
1714 int shift
= 64 - (8 << s_bits
);
1715 pre2
= tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
,
1716 TCG_REG_R58
, TCG_REG_R58
, shift
, 63 - shift
);
1719 /* Just move the data into place for the slow path. */
1720 pre1
= tcg_opc_ext_i(TCG_REG_P0
, opc
, TCG_REG_R58
, data_reg
);
1723 tcg_out_qemu_tlb(s
, addr_reg
, s_bits
,
1724 offsetof(CPUArchState
, tlb_table
[mem_index
][0].addr_write
),
1725 offsetof(CPUArchState
, tlb_table
[mem_index
][0].addend
),
1728 /* P6 is the fast path, and P7 the slow path */
1729 tcg_out_bundle(s
, mmI
,
1730 tcg_opc_mov_a(TCG_REG_P7
, TCG_REG_R56
, TCG_AREG0
),
1731 tcg_opc_a1 (TCG_REG_P6
, OPC_ADD_A1
, TCG_REG_R2
,
1732 TCG_REG_R2
, TCG_REG_R57
),
1733 tcg_opc_movi_a(TCG_REG_P7
, TCG_REG_R59
, oi
));
1734 label_ptr
= s
->code_ptr
;
1735 tcg_out_bundle(s
, miB
,
1736 tcg_opc_m4 (TCG_REG_P6
, opc_st_m4
[s_bits
],
1737 TCG_REG_R58
, TCG_REG_R2
),
1739 tcg_opc_b3 (TCG_REG_P7
, OPC_BR_CALL_SPNT_FEW_B3
, TCG_REG_B0
,
1740 get_reloc_pcrel21b_slot2(label_ptr
)));
1742 add_qemu_ldst_label(s
, 0, opc
, label_ptr
);
1745 #else /* !CONFIG_SOFTMMU */
1746 # include "tcg-be-null.h"
1748 static inline void tcg_out_qemu_ld(TCGContext
*s
, const TCGArg
*args
)
1750 static uint64_t const opc_ld_m1
[4] = {
1751 OPC_LD1_M1
, OPC_LD2_M1
, OPC_LD4_M1
, OPC_LD8_M1
1753 int addr_reg
, data_reg
;
1754 TCGMemOp opc
, s_bits
, bswap
;
1759 s_bits
= opc
& MO_SIZE
;
1760 bswap
= opc
& MO_BSWAP
;
1762 #if TARGET_LONG_BITS == 32
1763 if (guest_base
!= 0) {
1764 tcg_out_bundle(s
, mII
,
1766 tcg_opc_i29(TCG_REG_P0
, OPC_ZXT4_I29
,
1767 TCG_REG_R3
, addr_reg
),
1768 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
, TCG_REG_R2
,
1769 TCG_GUEST_BASE_REG
, TCG_REG_R3
));
1771 tcg_out_bundle(s
, miI
,
1773 tcg_opc_i29(TCG_REG_P0
, OPC_ZXT4_I29
,
1774 TCG_REG_R2
, addr_reg
),
1779 if (!(opc
& MO_SIGN
)) {
1780 tcg_out_bundle(s
, miI
,
1781 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1782 data_reg
, TCG_REG_R2
),
1786 tcg_out_bundle(s
, mII
,
1787 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1788 data_reg
, TCG_REG_R2
),
1790 tcg_opc_ext_i(TCG_REG_P0
, opc
, data_reg
, data_reg
));
1792 } else if (s_bits
== MO_64
) {
1793 tcg_out_bundle(s
, mII
,
1794 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1795 data_reg
, TCG_REG_R2
),
1797 tcg_opc_bswap64_i(TCG_REG_P0
, data_reg
, data_reg
));
1799 if (s_bits
== MO_16
) {
1800 tcg_out_bundle(s
, mII
,
1801 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1802 data_reg
, TCG_REG_R2
),
1804 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1805 data_reg
, data_reg
, 15, 15));
1807 tcg_out_bundle(s
, mII
,
1808 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1809 data_reg
, TCG_REG_R2
),
1811 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1812 data_reg
, data_reg
, 31, 31));
1814 if (!(opc
& MO_SIGN
)) {
1815 tcg_out_bundle(s
, miI
,
1818 tcg_opc_bswap64_i(TCG_REG_P0
, data_reg
, data_reg
));
1820 tcg_out_bundle(s
, mII
,
1822 tcg_opc_bswap64_i(TCG_REG_P0
, data_reg
, data_reg
),
1823 tcg_opc_ext_i(TCG_REG_P0
, opc
, data_reg
, data_reg
));
1827 if (guest_base
!= 0) {
1828 tcg_out_bundle(s
, MmI
,
1829 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
, TCG_REG_R2
,
1830 TCG_GUEST_BASE_REG
, addr_reg
),
1831 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1832 data_reg
, TCG_REG_R2
),
1835 tcg_out_bundle(s
, mmI
,
1837 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1838 data_reg
, addr_reg
),
1842 if (bswap
&& s_bits
== MO_16
) {
1843 tcg_out_bundle(s
, mII
,
1845 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1846 data_reg
, data_reg
, 15, 15),
1847 tcg_opc_bswap64_i(TCG_REG_P0
, data_reg
, data_reg
));
1848 } else if (bswap
&& s_bits
== MO_32
) {
1849 tcg_out_bundle(s
, mII
,
1851 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1852 data_reg
, data_reg
, 31, 31),
1853 tcg_opc_bswap64_i(TCG_REG_P0
, data_reg
, data_reg
));
1854 } else if (bswap
&& s_bits
== MO_64
) {
1855 tcg_out_bundle(s
, miI
,
1858 tcg_opc_bswap64_i(TCG_REG_P0
, data_reg
, data_reg
));
1860 if (opc
& MO_SIGN
) {
1861 tcg_out_bundle(s
, miI
,
1864 tcg_opc_ext_i(TCG_REG_P0
, opc
, data_reg
, data_reg
));
1869 static inline void tcg_out_qemu_st(TCGContext
*s
, const TCGArg
*args
)
1871 static uint64_t const opc_st_m4
[4] = {
1872 OPC_ST1_M4
, OPC_ST2_M4
, OPC_ST4_M4
, OPC_ST8_M4
1874 int addr_reg
, data_reg
;
1875 #if TARGET_LONG_BITS == 64
1876 uint64_t add_guest_base
;
1878 TCGMemOp opc
, s_bits
, bswap
;
1883 s_bits
= opc
& MO_SIZE
;
1884 bswap
= opc
& MO_BSWAP
;
1886 #if TARGET_LONG_BITS == 32
1887 if (guest_base
!= 0) {
1888 tcg_out_bundle(s
, mII
,
1890 tcg_opc_i29(TCG_REG_P0
, OPC_ZXT4_I29
,
1891 TCG_REG_R3
, addr_reg
),
1892 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
, TCG_REG_R2
,
1893 TCG_GUEST_BASE_REG
, TCG_REG_R3
));
1895 tcg_out_bundle(s
, miI
,
1897 tcg_opc_i29(TCG_REG_P0
, OPC_ZXT4_I29
,
1898 TCG_REG_R2
, addr_reg
),
1903 if (s_bits
== MO_16
) {
1904 tcg_out_bundle(s
, mII
,
1906 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1907 TCG_REG_R3
, data_reg
, 15, 15),
1908 tcg_opc_bswap64_i(TCG_REG_P0
,
1909 TCG_REG_R3
, TCG_REG_R3
));
1910 data_reg
= TCG_REG_R3
;
1911 } else if (s_bits
== MO_32
) {
1912 tcg_out_bundle(s
, mII
,
1914 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1915 TCG_REG_R3
, data_reg
, 31, 31),
1916 tcg_opc_bswap64_i(TCG_REG_P0
,
1917 TCG_REG_R3
, TCG_REG_R3
));
1918 data_reg
= TCG_REG_R3
;
1919 } else if (s_bits
== MO_64
) {
1920 tcg_out_bundle(s
, miI
,
1923 tcg_opc_bswap64_i(TCG_REG_P0
, TCG_REG_R3
, data_reg
));
1924 data_reg
= TCG_REG_R3
;
1927 tcg_out_bundle(s
, mmI
,
1928 tcg_opc_m4 (TCG_REG_P0
, opc_st_m4
[s_bits
],
1929 data_reg
, TCG_REG_R2
),
1933 if (guest_base
!= 0) {
1934 add_guest_base
= tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
, TCG_REG_R2
,
1935 TCG_GUEST_BASE_REG
, addr_reg
);
1936 addr_reg
= TCG_REG_R2
;
1938 add_guest_base
= INSN_NOP_M
;
1942 tcg_out_bundle(s
, (guest_base
? MmI
: mmI
),
1944 tcg_opc_m4 (TCG_REG_P0
, opc_st_m4
[s_bits
],
1945 data_reg
, addr_reg
),
1948 if (s_bits
== MO_16
) {
1949 tcg_out_bundle(s
, mII
,
1951 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1952 TCG_REG_R3
, data_reg
, 15, 15),
1953 tcg_opc_bswap64_i(TCG_REG_P0
,
1954 TCG_REG_R3
, TCG_REG_R3
));
1955 data_reg
= TCG_REG_R3
;
1956 } else if (s_bits
== MO_32
) {
1957 tcg_out_bundle(s
, mII
,
1959 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1960 TCG_REG_R3
, data_reg
, 31, 31),
1961 tcg_opc_bswap64_i(TCG_REG_P0
,
1962 TCG_REG_R3
, TCG_REG_R3
));
1963 data_reg
= TCG_REG_R3
;
1964 } else if (s_bits
== MO_64
) {
1965 tcg_out_bundle(s
, miI
,
1968 tcg_opc_bswap64_i(TCG_REG_P0
, TCG_REG_R3
, data_reg
));
1969 data_reg
= TCG_REG_R3
;
1971 tcg_out_bundle(s
, miI
,
1972 tcg_opc_m4 (TCG_REG_P0
, opc_st_m4
[s_bits
],
1973 data_reg
, addr_reg
),
1982 static inline void tcg_out_op(TCGContext
*s
, TCGOpcode opc
,
1983 const TCGArg
*args
, const int *const_args
)
1986 case INDEX_op_exit_tb
:
1987 tcg_out_exit_tb(s
, args
[0]);
1990 tcg_out_br(s
, arg_label(args
[0]));
1992 case INDEX_op_goto_tb
:
1993 tcg_out_goto_tb(s
, args
[0]);
1996 case INDEX_op_ld8u_i32
:
1997 case INDEX_op_ld8u_i64
:
1998 tcg_out_ld_rel(s
, OPC_LD1_M1
, args
[0], args
[1], args
[2]);
2000 case INDEX_op_ld8s_i32
:
2001 case INDEX_op_ld8s_i64
:
2002 tcg_out_ld_rel(s
, OPC_LD1_M1
, args
[0], args
[1], args
[2]);
2003 tcg_out_ext(s
, OPC_SXT1_I29
, args
[0], args
[0]);
2005 case INDEX_op_ld16u_i32
:
2006 case INDEX_op_ld16u_i64
:
2007 tcg_out_ld_rel(s
, OPC_LD2_M1
, args
[0], args
[1], args
[2]);
2009 case INDEX_op_ld16s_i32
:
2010 case INDEX_op_ld16s_i64
:
2011 tcg_out_ld_rel(s
, OPC_LD2_M1
, args
[0], args
[1], args
[2]);
2012 tcg_out_ext(s
, OPC_SXT2_I29
, args
[0], args
[0]);
2014 case INDEX_op_ld_i32
:
2015 case INDEX_op_ld32u_i64
:
2016 tcg_out_ld_rel(s
, OPC_LD4_M1
, args
[0], args
[1], args
[2]);
2018 case INDEX_op_ld32s_i64
:
2019 tcg_out_ld_rel(s
, OPC_LD4_M1
, args
[0], args
[1], args
[2]);
2020 tcg_out_ext(s
, OPC_SXT4_I29
, args
[0], args
[0]);
2022 case INDEX_op_ld_i64
:
2023 tcg_out_ld_rel(s
, OPC_LD8_M1
, args
[0], args
[1], args
[2]);
2025 case INDEX_op_st8_i32
:
2026 case INDEX_op_st8_i64
:
2027 tcg_out_st_rel(s
, OPC_ST1_M4
, args
[0], args
[1], args
[2]);
2029 case INDEX_op_st16_i32
:
2030 case INDEX_op_st16_i64
:
2031 tcg_out_st_rel(s
, OPC_ST2_M4
, args
[0], args
[1], args
[2]);
2033 case INDEX_op_st_i32
:
2034 case INDEX_op_st32_i64
:
2035 tcg_out_st_rel(s
, OPC_ST4_M4
, args
[0], args
[1], args
[2]);
2037 case INDEX_op_st_i64
:
2038 tcg_out_st_rel(s
, OPC_ST8_M4
, args
[0], args
[1], args
[2]);
2041 case INDEX_op_add_i32
:
2042 case INDEX_op_add_i64
:
2043 tcg_out_add(s
, args
[0], args
[1], args
[2], const_args
[2]);
2045 case INDEX_op_sub_i32
:
2046 case INDEX_op_sub_i64
:
2047 tcg_out_sub(s
, args
[0], args
[1], const_args
[1], args
[2], const_args
[2]);
2050 case INDEX_op_and_i32
:
2051 case INDEX_op_and_i64
:
2052 /* TCG expects arg2 constant; A3 expects arg1 constant. Swap. */
2053 tcg_out_alu(s
, OPC_AND_A1
, OPC_AND_A3
, args
[0],
2054 args
[2], const_args
[2], args
[1], const_args
[1]);
2056 case INDEX_op_andc_i32
:
2057 case INDEX_op_andc_i64
:
2058 tcg_out_alu(s
, OPC_ANDCM_A1
, OPC_ANDCM_A3
, args
[0],
2059 args
[1], const_args
[1], args
[2], const_args
[2]);
2061 case INDEX_op_eqv_i32
:
2062 case INDEX_op_eqv_i64
:
2063 tcg_out_eqv(s
, args
[0], args
[1], const_args
[1],
2064 args
[2], const_args
[2]);
2066 case INDEX_op_nand_i32
:
2067 case INDEX_op_nand_i64
:
2068 tcg_out_nand(s
, args
[0], args
[1], const_args
[1],
2069 args
[2], const_args
[2]);
2071 case INDEX_op_nor_i32
:
2072 case INDEX_op_nor_i64
:
2073 tcg_out_nor(s
, args
[0], args
[1], const_args
[1],
2074 args
[2], const_args
[2]);
2076 case INDEX_op_or_i32
:
2077 case INDEX_op_or_i64
:
2078 /* TCG expects arg2 constant; A3 expects arg1 constant. Swap. */
2079 tcg_out_alu(s
, OPC_OR_A1
, OPC_OR_A3
, args
[0],
2080 args
[2], const_args
[2], args
[1], const_args
[1]);
2082 case INDEX_op_orc_i32
:
2083 case INDEX_op_orc_i64
:
2084 tcg_out_orc(s
, args
[0], args
[1], const_args
[1],
2085 args
[2], const_args
[2]);
2087 case INDEX_op_xor_i32
:
2088 case INDEX_op_xor_i64
:
2089 /* TCG expects arg2 constant; A3 expects arg1 constant. Swap. */
2090 tcg_out_alu(s
, OPC_XOR_A1
, OPC_XOR_A3
, args
[0],
2091 args
[2], const_args
[2], args
[1], const_args
[1]);
2094 case INDEX_op_mul_i32
:
2095 case INDEX_op_mul_i64
:
2096 tcg_out_mul(s
, args
[0], args
[1], args
[2]);
2099 case INDEX_op_sar_i32
:
2100 tcg_out_sar_i32(s
, args
[0], args
[1], args
[2], const_args
[2]);
2102 case INDEX_op_sar_i64
:
2103 tcg_out_sar_i64(s
, args
[0], args
[1], args
[2], const_args
[2]);
2105 case INDEX_op_shl_i32
:
2106 tcg_out_shl_i32(s
, args
[0], args
[1], args
[2], const_args
[2]);
2108 case INDEX_op_shl_i64
:
2109 tcg_out_shl_i64(s
, args
[0], args
[1], args
[2], const_args
[2]);
2111 case INDEX_op_shr_i32
:
2112 tcg_out_shr_i32(s
, args
[0], args
[1], args
[2], const_args
[2]);
2114 case INDEX_op_shr_i64
:
2115 tcg_out_shr_i64(s
, args
[0], args
[1], args
[2], const_args
[2]);
2117 case INDEX_op_rotl_i32
:
2118 tcg_out_rotl_i32(s
, args
[0], args
[1], args
[2], const_args
[2]);
2120 case INDEX_op_rotl_i64
:
2121 tcg_out_rotl_i64(s
, args
[0], args
[1], args
[2], const_args
[2]);
2123 case INDEX_op_rotr_i32
:
2124 tcg_out_rotr_i32(s
, args
[0], args
[1], args
[2], const_args
[2]);
2126 case INDEX_op_rotr_i64
:
2127 tcg_out_rotr_i64(s
, args
[0], args
[1], args
[2], const_args
[2]);
2130 case INDEX_op_ext8s_i32
:
2131 case INDEX_op_ext8s_i64
:
2132 tcg_out_ext(s
, OPC_SXT1_I29
, args
[0], args
[1]);
2134 case INDEX_op_ext8u_i32
:
2135 case INDEX_op_ext8u_i64
:
2136 tcg_out_ext(s
, OPC_ZXT1_I29
, args
[0], args
[1]);
2138 case INDEX_op_ext16s_i32
:
2139 case INDEX_op_ext16s_i64
:
2140 tcg_out_ext(s
, OPC_SXT2_I29
, args
[0], args
[1]);
2142 case INDEX_op_ext16u_i32
:
2143 case INDEX_op_ext16u_i64
:
2144 tcg_out_ext(s
, OPC_ZXT2_I29
, args
[0], args
[1]);
2146 case INDEX_op_ext_i32_i64
:
2147 case INDEX_op_ext32s_i64
:
2148 tcg_out_ext(s
, OPC_SXT4_I29
, args
[0], args
[1]);
2150 case INDEX_op_extu_i32_i64
:
2151 case INDEX_op_ext32u_i64
:
2152 tcg_out_ext(s
, OPC_ZXT4_I29
, args
[0], args
[1]);
2155 case INDEX_op_bswap16_i32
:
2156 case INDEX_op_bswap16_i64
:
2157 tcg_out_bswap16(s
, args
[0], args
[1]);
2159 case INDEX_op_bswap32_i32
:
2160 case INDEX_op_bswap32_i64
:
2161 tcg_out_bswap32(s
, args
[0], args
[1]);
2163 case INDEX_op_bswap64_i64
:
2164 tcg_out_bswap64(s
, args
[0], args
[1]);
2167 case INDEX_op_deposit_i32
:
2168 case INDEX_op_deposit_i64
:
2169 tcg_out_deposit(s
, args
[0], args
[1], args
[2], const_args
[2],
2173 case INDEX_op_brcond_i32
:
2174 tcg_out_brcond(s
, args
[2], args
[0], args
[1], arg_label(args
[3]), 1);
2176 case INDEX_op_brcond_i64
:
2177 tcg_out_brcond(s
, args
[2], args
[0], args
[1], arg_label(args
[3]), 0);
2179 case INDEX_op_setcond_i32
:
2180 tcg_out_setcond(s
, args
[3], args
[0], args
[1], args
[2], 1);
2182 case INDEX_op_setcond_i64
:
2183 tcg_out_setcond(s
, args
[3], args
[0], args
[1], args
[2], 0);
2185 case INDEX_op_movcond_i32
:
2186 tcg_out_movcond(s
, args
[5], args
[0], args
[1], args
[2],
2187 args
[3], const_args
[3], args
[4], const_args
[4], 1);
2189 case INDEX_op_movcond_i64
:
2190 tcg_out_movcond(s
, args
[5], args
[0], args
[1], args
[2],
2191 args
[3], const_args
[3], args
[4], const_args
[4], 0);
2194 case INDEX_op_qemu_ld_i32
:
2195 tcg_out_qemu_ld(s
, args
);
2197 case INDEX_op_qemu_ld_i64
:
2198 tcg_out_qemu_ld(s
, args
);
2200 case INDEX_op_qemu_st_i32
:
2201 tcg_out_qemu_st(s
, args
);
2203 case INDEX_op_qemu_st_i64
:
2204 tcg_out_qemu_st(s
, args
);
2207 case INDEX_op_mov_i32
: /* Always emitted via tcg_out_mov. */
2208 case INDEX_op_mov_i64
:
2209 case INDEX_op_movi_i32
: /* Always emitted via tcg_out_movi. */
2210 case INDEX_op_movi_i64
:
2211 case INDEX_op_call
: /* Always emitted via tcg_out_call. */
2217 static const TCGTargetOpDef ia64_op_defs
[] = {
2218 { INDEX_op_br
, { } },
2219 { INDEX_op_exit_tb
, { } },
2220 { INDEX_op_goto_tb
, { } },
2222 { INDEX_op_ld8u_i32
, { "r", "r" } },
2223 { INDEX_op_ld8s_i32
, { "r", "r" } },
2224 { INDEX_op_ld16u_i32
, { "r", "r" } },
2225 { INDEX_op_ld16s_i32
, { "r", "r" } },
2226 { INDEX_op_ld_i32
, { "r", "r" } },
2227 { INDEX_op_st8_i32
, { "rZ", "r" } },
2228 { INDEX_op_st16_i32
, { "rZ", "r" } },
2229 { INDEX_op_st_i32
, { "rZ", "r" } },
2231 { INDEX_op_add_i32
, { "r", "rZ", "rI" } },
2232 { INDEX_op_sub_i32
, { "r", "rI", "rI" } },
2234 { INDEX_op_and_i32
, { "r", "rI", "rI" } },
2235 { INDEX_op_andc_i32
, { "r", "rI", "rI" } },
2236 { INDEX_op_eqv_i32
, { "r", "rZ", "rZ" } },
2237 { INDEX_op_nand_i32
, { "r", "rZ", "rZ" } },
2238 { INDEX_op_nor_i32
, { "r", "rZ", "rZ" } },
2239 { INDEX_op_or_i32
, { "r", "rI", "rI" } },
2240 { INDEX_op_orc_i32
, { "r", "rZ", "rZ" } },
2241 { INDEX_op_xor_i32
, { "r", "rI", "rI" } },
2243 { INDEX_op_mul_i32
, { "r", "rZ", "rZ" } },
2245 { INDEX_op_sar_i32
, { "r", "rZ", "ri" } },
2246 { INDEX_op_shl_i32
, { "r", "rZ", "ri" } },
2247 { INDEX_op_shr_i32
, { "r", "rZ", "ri" } },
2248 { INDEX_op_rotl_i32
, { "r", "rZ", "ri" } },
2249 { INDEX_op_rotr_i32
, { "r", "rZ", "ri" } },
2251 { INDEX_op_ext8s_i32
, { "r", "rZ"} },
2252 { INDEX_op_ext8u_i32
, { "r", "rZ"} },
2253 { INDEX_op_ext16s_i32
, { "r", "rZ"} },
2254 { INDEX_op_ext16u_i32
, { "r", "rZ"} },
2256 { INDEX_op_bswap16_i32
, { "r", "rZ" } },
2257 { INDEX_op_bswap32_i32
, { "r", "rZ" } },
2259 { INDEX_op_brcond_i32
, { "rZ", "rZ" } },
2260 { INDEX_op_setcond_i32
, { "r", "rZ", "rZ" } },
2261 { INDEX_op_movcond_i32
, { "r", "rZ", "rZ", "rI", "rI" } },
2263 { INDEX_op_ld8u_i64
, { "r", "r" } },
2264 { INDEX_op_ld8s_i64
, { "r", "r" } },
2265 { INDEX_op_ld16u_i64
, { "r", "r" } },
2266 { INDEX_op_ld16s_i64
, { "r", "r" } },
2267 { INDEX_op_ld32u_i64
, { "r", "r" } },
2268 { INDEX_op_ld32s_i64
, { "r", "r" } },
2269 { INDEX_op_ld_i64
, { "r", "r" } },
2270 { INDEX_op_st8_i64
, { "rZ", "r" } },
2271 { INDEX_op_st16_i64
, { "rZ", "r" } },
2272 { INDEX_op_st32_i64
, { "rZ", "r" } },
2273 { INDEX_op_st_i64
, { "rZ", "r" } },
2275 { INDEX_op_add_i64
, { "r", "rZ", "rI" } },
2276 { INDEX_op_sub_i64
, { "r", "rI", "rI" } },
2278 { INDEX_op_and_i64
, { "r", "rI", "rI" } },
2279 { INDEX_op_andc_i64
, { "r", "rI", "rI" } },
2280 { INDEX_op_eqv_i64
, { "r", "rZ", "rZ" } },
2281 { INDEX_op_nand_i64
, { "r", "rZ", "rZ" } },
2282 { INDEX_op_nor_i64
, { "r", "rZ", "rZ" } },
2283 { INDEX_op_or_i64
, { "r", "rI", "rI" } },
2284 { INDEX_op_orc_i64
, { "r", "rZ", "rZ" } },
2285 { INDEX_op_xor_i64
, { "r", "rI", "rI" } },
2287 { INDEX_op_mul_i64
, { "r", "rZ", "rZ" } },
2289 { INDEX_op_sar_i64
, { "r", "rZ", "ri" } },
2290 { INDEX_op_shl_i64
, { "r", "rZ", "ri" } },
2291 { INDEX_op_shr_i64
, { "r", "rZ", "ri" } },
2292 { INDEX_op_rotl_i64
, { "r", "rZ", "ri" } },
2293 { INDEX_op_rotr_i64
, { "r", "rZ", "ri" } },
2295 { INDEX_op_ext8s_i64
, { "r", "rZ"} },
2296 { INDEX_op_ext8u_i64
, { "r", "rZ"} },
2297 { INDEX_op_ext16s_i64
, { "r", "rZ"} },
2298 { INDEX_op_ext16u_i64
, { "r", "rZ"} },
2299 { INDEX_op_ext32s_i64
, { "r", "rZ"} },
2300 { INDEX_op_ext32u_i64
, { "r", "rZ"} },
2301 { INDEX_op_ext_i32_i64
, { "r", "rZ" } },
2302 { INDEX_op_extu_i32_i64
, { "r", "rZ" } },
2304 { INDEX_op_bswap16_i64
, { "r", "rZ" } },
2305 { INDEX_op_bswap32_i64
, { "r", "rZ" } },
2306 { INDEX_op_bswap64_i64
, { "r", "rZ" } },
2308 { INDEX_op_brcond_i64
, { "rZ", "rZ" } },
2309 { INDEX_op_setcond_i64
, { "r", "rZ", "rZ" } },
2310 { INDEX_op_movcond_i64
, { "r", "rZ", "rZ", "rI", "rI" } },
2312 { INDEX_op_deposit_i32
, { "r", "rZ", "ri" } },
2313 { INDEX_op_deposit_i64
, { "r", "rZ", "ri" } },
2315 { INDEX_op_qemu_ld_i32
, { "r", "r" } },
2316 { INDEX_op_qemu_ld_i64
, { "r", "r" } },
2317 { INDEX_op_qemu_st_i32
, { "SZ", "r" } },
2318 { INDEX_op_qemu_st_i64
, { "SZ", "r" } },
2323 /* Generate global QEMU prologue and epilogue code */
2324 static void tcg_target_qemu_prologue(TCGContext
*s
)
2328 /* reserve some stack space */
2329 frame_size
= TCG_STATIC_CALL_ARGS_SIZE
+
2330 CPU_TEMP_BUF_NLONGS
* sizeof(long);
2331 frame_size
= (frame_size
+ TCG_TARGET_STACK_ALIGN
- 1) &
2332 ~(TCG_TARGET_STACK_ALIGN
- 1);
2333 tcg_set_frame(s
, TCG_REG_CALL_STACK
, TCG_STATIC_CALL_ARGS_SIZE
,
2334 CPU_TEMP_BUF_NLONGS
* sizeof(long));
2336 /* First emit adhoc function descriptor */
2337 *s
->code_ptr
= (tcg_insn_unit
){
2338 (uint64_t)(s
->code_ptr
+ 1), /* entry point */
2344 tcg_out_bundle(s
, miI
,
2345 tcg_opc_m34(TCG_REG_P0
, OPC_ALLOC_M34
,
2346 TCG_REG_R34
, 32, 24, 0),
2348 tcg_opc_i21(TCG_REG_P0
, OPC_MOV_I21
,
2349 TCG_REG_B6
, TCG_REG_R33
, 0));
2351 /* ??? If guest_base < 0x200000, we could load the register via
2352 an ADDL in the M slot of the next bundle. */
2353 if (guest_base
!= 0) {
2354 tcg_out_bundle(s
, mlx
,
2356 tcg_opc_l2(guest_base
),
2357 tcg_opc_x2 (TCG_REG_P0
, OPC_MOVL_X2
,
2358 TCG_GUEST_BASE_REG
, guest_base
));
2359 tcg_regset_set_reg(s
->reserved_regs
, TCG_GUEST_BASE_REG
);
2362 tcg_out_bundle(s
, miB
,
2363 tcg_opc_a4 (TCG_REG_P0
, OPC_ADDS_A4
,
2364 TCG_REG_R12
, -frame_size
, TCG_REG_R12
),
2365 tcg_opc_i22(TCG_REG_P0
, OPC_MOV_I22
,
2366 TCG_REG_R33
, TCG_REG_B0
),
2367 tcg_opc_b4 (TCG_REG_P0
, OPC_BR_SPTK_MANY_B4
, TCG_REG_B6
));
2370 tb_ret_addr
= s
->code_ptr
;
2371 tcg_out_bundle(s
, miI
,
2373 tcg_opc_i21(TCG_REG_P0
, OPC_MOV_I21
,
2374 TCG_REG_B0
, TCG_REG_R33
, 0),
2375 tcg_opc_a4 (TCG_REG_P0
, OPC_ADDS_A4
,
2376 TCG_REG_R12
, frame_size
, TCG_REG_R12
));
2377 tcg_out_bundle(s
, miB
,
2379 tcg_opc_i26(TCG_REG_P0
, OPC_MOV_I_I26
,
2380 TCG_REG_PFS
, TCG_REG_R34
),
2381 tcg_opc_b4 (TCG_REG_P0
, OPC_BR_RET_SPTK_MANY_B4
,
2385 static void tcg_target_init(TCGContext
*s
)
2387 tcg_regset_set(tcg_target_available_regs
[TCG_TYPE_I32
],
2388 0xffffffffffffffffull
);
2389 tcg_regset_set(tcg_target_available_regs
[TCG_TYPE_I64
],
2390 0xffffffffffffffffull
);
2392 tcg_regset_clear(tcg_target_call_clobber_regs
);
2393 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R8
);
2394 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R9
);
2395 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R10
);
2396 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R11
);
2397 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R14
);
2398 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R15
);
2399 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R16
);
2400 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R17
);
2401 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R18
);
2402 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R19
);
2403 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R20
);
2404 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R21
);
2405 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R22
);
2406 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R23
);
2407 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R24
);
2408 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R25
);
2409 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R26
);
2410 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R27
);
2411 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R28
);
2412 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R29
);
2413 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R30
);
2414 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R31
);
2415 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R56
);
2416 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R57
);
2417 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R58
);
2418 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R59
);
2419 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R60
);
2420 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R61
);
2421 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R62
);
2422 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R63
);
2424 tcg_regset_clear(s
->reserved_regs
);
2425 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R0
); /* zero register */
2426 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R1
); /* global pointer */
2427 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R2
); /* internal use */
2428 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R3
); /* internal use */
2429 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R12
); /* stack pointer */
2430 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R13
); /* thread pointer */
2431 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R33
); /* return address */
2432 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R34
); /* PFS */
2434 /* The following 4 are not in use, are call-saved, but *not* saved
2435 by the prologue. Therefore we cannot use them without modifying
2436 the prologue. There doesn't seem to be any good reason to use
2437 these as opposed to the windowed registers. */
2438 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R4
);
2439 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R5
);
2440 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R6
);
2441 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R7
);
2443 tcg_add_target_add_op_defs(ia64_op_defs
);