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
26 #include "tcg-be-null.h"
29 * Register definitions
33 static const char * const tcg_target_reg_names
[TCG_TARGET_NB_REGS
] = {
34 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
35 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
36 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
37 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
38 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
39 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
40 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
41 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63",
45 #ifdef CONFIG_USE_GUEST_BASE
46 #define TCG_GUEST_BASE_REG TCG_REG_R55
48 #define TCG_GUEST_BASE_REG TCG_REG_R0
54 /* Branch registers */
66 /* Floating point registers */
86 /* Predicate registers */
106 /* Application registers */
111 static const int tcg_target_reg_alloc_order
[] = {
166 static const int tcg_target_call_iarg_regs
[8] = {
177 static const int tcg_target_call_oarg_regs
[] = {
185 /* bundle templates: stops (double bar in the IA64 manual) are marked with
186 an uppercase letter. */
215 OPC_ADD_A1
= 0x10000000000ull
,
216 OPC_AND_A1
= 0x10060000000ull
,
217 OPC_AND_A3
= 0x10160000000ull
,
218 OPC_ANDCM_A1
= 0x10068000000ull
,
219 OPC_ANDCM_A3
= 0x10168000000ull
,
220 OPC_ADDS_A4
= 0x10800000000ull
,
221 OPC_ADDL_A5
= 0x12000000000ull
,
222 OPC_ALLOC_M34
= 0x02c00000000ull
,
223 OPC_BR_DPTK_FEW_B1
= 0x08400000000ull
,
224 OPC_BR_SPTK_MANY_B1
= 0x08000001000ull
,
225 OPC_BR_SPTK_MANY_B4
= 0x00100001000ull
,
226 OPC_BR_CALL_SPTK_MANY_B5
= 0x02100001000ull
,
227 OPC_BR_RET_SPTK_MANY_B4
= 0x00108001100ull
,
228 OPC_BRL_SPTK_MANY_X3
= 0x18000001000ull
,
229 OPC_CMP_LT_A6
= 0x18000000000ull
,
230 OPC_CMP_LTU_A6
= 0x1a000000000ull
,
231 OPC_CMP_EQ_A6
= 0x1c000000000ull
,
232 OPC_CMP4_LT_A6
= 0x18400000000ull
,
233 OPC_CMP4_LTU_A6
= 0x1a400000000ull
,
234 OPC_CMP4_EQ_A6
= 0x1c400000000ull
,
235 OPC_DEP_I14
= 0x0ae00000000ull
,
236 OPC_DEP_I15
= 0x08000000000ull
,
237 OPC_DEP_Z_I12
= 0x0a600000000ull
,
238 OPC_EXTR_I11
= 0x0a400002000ull
,
239 OPC_EXTR_U_I11
= 0x0a400000000ull
,
240 OPC_FCVT_FX_TRUNC_S1_F10
= 0x004d0000000ull
,
241 OPC_FCVT_FXU_TRUNC_S1_F10
= 0x004d8000000ull
,
242 OPC_FCVT_XF_F11
= 0x000e0000000ull
,
243 OPC_FMA_S1_F1
= 0x10400000000ull
,
244 OPC_FNMA_S1_F1
= 0x18400000000ull
,
245 OPC_FRCPA_S1_F6
= 0x00600000000ull
,
246 OPC_GETF_SIG_M19
= 0x08708000000ull
,
247 OPC_LD1_M1
= 0x08000000000ull
,
248 OPC_LD1_M3
= 0x0a000000000ull
,
249 OPC_LD2_M1
= 0x08040000000ull
,
250 OPC_LD2_M3
= 0x0a040000000ull
,
251 OPC_LD4_M1
= 0x08080000000ull
,
252 OPC_LD4_M3
= 0x0a080000000ull
,
253 OPC_LD8_M1
= 0x080c0000000ull
,
254 OPC_LD8_M3
= 0x0a0c0000000ull
,
255 OPC_MUX1_I3
= 0x0eca0000000ull
,
256 OPC_NOP_B9
= 0x04008000000ull
,
257 OPC_NOP_F16
= 0x00008000000ull
,
258 OPC_NOP_I18
= 0x00008000000ull
,
259 OPC_NOP_M48
= 0x00008000000ull
,
260 OPC_MOV_I21
= 0x00e00100000ull
,
261 OPC_MOV_RET_I21
= 0x00e00500000ull
,
262 OPC_MOV_I22
= 0x00188000000ull
,
263 OPC_MOV_I_I26
= 0x00150000000ull
,
264 OPC_MOVL_X2
= 0x0c000000000ull
,
265 OPC_OR_A1
= 0x10070000000ull
,
266 OPC_SETF_EXP_M18
= 0x0c748000000ull
,
267 OPC_SETF_SIG_M18
= 0x0c708000000ull
,
268 OPC_SHL_I7
= 0x0f240000000ull
,
269 OPC_SHR_I5
= 0x0f220000000ull
,
270 OPC_SHR_U_I5
= 0x0f200000000ull
,
271 OPC_SHRP_I10
= 0x0ac00000000ull
,
272 OPC_SXT1_I29
= 0x000a0000000ull
,
273 OPC_SXT2_I29
= 0x000a8000000ull
,
274 OPC_SXT4_I29
= 0x000b0000000ull
,
275 OPC_ST1_M4
= 0x08c00000000ull
,
276 OPC_ST2_M4
= 0x08c40000000ull
,
277 OPC_ST4_M4
= 0x08c80000000ull
,
278 OPC_ST8_M4
= 0x08cc0000000ull
,
279 OPC_SUB_A1
= 0x10028000000ull
,
280 OPC_SUB_A3
= 0x10128000000ull
,
281 OPC_UNPACK4_L_I2
= 0x0f860000000ull
,
282 OPC_XMA_L_F2
= 0x1d000000000ull
,
283 OPC_XOR_A1
= 0x10078000000ull
,
284 OPC_ZXT1_I29
= 0x00080000000ull
,
285 OPC_ZXT2_I29
= 0x00088000000ull
,
286 OPC_ZXT4_I29
= 0x00090000000ull
,
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_b4(int qp
, uint64_t opc
, int b2
)
361 static inline uint64_t tcg_opc_b5(int qp
, uint64_t opc
, int b1
, int b2
)
370 static inline uint64_t tcg_opc_b9(int qp
, uint64_t opc
, uint64_t imm
)
373 | ((imm
& 0x100000) << 16) /* i */
374 | ((imm
& 0x0fffff) << 6) /* imm20a */
378 static inline uint64_t tcg_opc_f1(int qp
, uint64_t opc
, int f1
,
379 int f3
, int f4
, int f2
)
382 | ((f4
& 0x7f) << 27)
383 | ((f3
& 0x7f) << 20)
384 | ((f2
& 0x7f) << 13)
389 static inline uint64_t tcg_opc_f2(int qp
, uint64_t opc
, int f1
,
390 int f3
, int f4
, int f2
)
393 | ((f4
& 0x7f) << 27)
394 | ((f3
& 0x7f) << 20)
395 | ((f2
& 0x7f) << 13)
400 static inline uint64_t tcg_opc_f6(int qp
, uint64_t opc
, int f1
,
401 int p2
, int f2
, int f3
)
404 | ((p2
& 0x3f) << 27)
405 | ((f3
& 0x7f) << 20)
406 | ((f2
& 0x7f) << 13)
411 static inline uint64_t tcg_opc_f10(int qp
, uint64_t opc
, int f1
, int f2
)
414 | ((f2
& 0x7f) << 13)
419 static inline uint64_t tcg_opc_f11(int qp
, uint64_t opc
, int f1
, int f2
)
422 | ((f2
& 0x7f) << 13)
427 static inline uint64_t tcg_opc_f16(int qp
, uint64_t opc
, uint64_t imm
)
430 | ((imm
& 0x100000) << 16) /* i */
431 | ((imm
& 0x0fffff) << 6) /* imm20a */
435 static inline uint64_t tcg_opc_i2(int qp
, uint64_t opc
, int r1
,
439 | ((r3
& 0x7f) << 20)
440 | ((r2
& 0x7f) << 13)
445 static inline uint64_t tcg_opc_i3(int qp
, uint64_t opc
, int r1
,
449 | ((mbtype
& 0x0f) << 20)
450 | ((r2
& 0x7f) << 13)
455 static inline uint64_t tcg_opc_i5(int qp
, uint64_t opc
, int r1
,
459 | ((r3
& 0x7f) << 20)
460 | ((r2
& 0x7f) << 13)
465 static inline uint64_t tcg_opc_i7(int qp
, uint64_t opc
, int r1
,
469 | ((r3
& 0x7f) << 20)
470 | ((r2
& 0x7f) << 13)
475 static inline uint64_t tcg_opc_i10(int qp
, uint64_t opc
, int r1
,
476 int r2
, int r3
, uint64_t count
)
479 | ((count
& 0x3f) << 27)
480 | ((r3
& 0x7f) << 20)
481 | ((r2
& 0x7f) << 13)
486 static inline uint64_t tcg_opc_i11(int qp
, uint64_t opc
, int r1
,
487 int r3
, uint64_t pos
, uint64_t len
)
490 | ((len
& 0x3f) << 27)
491 | ((r3
& 0x7f) << 20)
492 | ((pos
& 0x3f) << 14)
497 static inline uint64_t tcg_opc_i12(int qp
, uint64_t opc
, int r1
,
498 int r2
, uint64_t pos
, uint64_t len
)
501 | ((len
& 0x3f) << 27)
502 | ((pos
& 0x3f) << 20)
503 | ((r2
& 0x7f) << 13)
508 static inline uint64_t tcg_opc_i14(int qp
, uint64_t opc
, int r1
, uint64_t imm
,
509 int r3
, uint64_t pos
, uint64_t len
)
512 | ((imm
& 0x01) << 36)
513 | ((len
& 0x3f) << 27)
514 | ((r3
& 0x7f) << 20)
515 | ((pos
& 0x3f) << 14)
520 static inline uint64_t tcg_opc_i15(int qp
, uint64_t opc
, int r1
, int r2
,
521 int r3
, uint64_t pos
, uint64_t len
)
524 | ((pos
& 0x3f) << 31)
525 | ((len
& 0x0f) << 27)
526 | ((r3
& 0x7f) << 20)
527 | ((r2
& 0x7f) << 13)
532 static inline uint64_t tcg_opc_i18(int qp
, uint64_t opc
, uint64_t imm
)
535 | ((imm
& 0x100000) << 16) /* i */
536 | ((imm
& 0x0fffff) << 6) /* imm20a */
540 static inline uint64_t tcg_opc_i21(int qp
, uint64_t opc
, int b1
,
541 int r2
, uint64_t imm
)
544 | ((imm
& 0x1ff) << 24)
545 | ((r2
& 0x7f) << 13)
550 static inline uint64_t tcg_opc_i22(int qp
, uint64_t opc
, int r1
, int b2
)
558 static inline uint64_t tcg_opc_i26(int qp
, uint64_t opc
, int ar3
, int r2
)
561 | ((ar3
& 0x7f) << 20)
562 | ((r2
& 0x7f) << 13)
566 static inline uint64_t tcg_opc_i29(int qp
, uint64_t opc
, int r1
, int r3
)
569 | ((r3
& 0x7f) << 20)
574 static inline uint64_t tcg_opc_l2(uint64_t imm
)
576 return (imm
& 0x7fffffffffc00000ull
) >> 22;
579 static inline uint64_t tcg_opc_l3(uint64_t imm
)
581 return (imm
& 0x07fffffffff00000ull
) >> 18;
584 static inline uint64_t tcg_opc_m1(int qp
, uint64_t opc
, int r1
, int r3
)
587 | ((r3
& 0x7f) << 20)
592 static inline uint64_t tcg_opc_m3(int qp
, uint64_t opc
, int r1
,
593 int r3
, uint64_t imm
)
596 | ((imm
& 0x100) << 28) /* s */
597 | ((imm
& 0x080) << 20) /* i */
598 | ((imm
& 0x07f) << 13) /* imm7b */
599 | ((r3
& 0x7f) << 20)
604 static inline uint64_t tcg_opc_m4(int qp
, uint64_t opc
, int r2
, int r3
)
607 | ((r3
& 0x7f) << 20)
608 | ((r2
& 0x7f) << 13)
612 static inline uint64_t tcg_opc_m18(int qp
, uint64_t opc
, int f1
, int r2
)
615 | ((r2
& 0x7f) << 13)
620 static inline uint64_t tcg_opc_m19(int qp
, uint64_t opc
, int r1
, int f2
)
623 | ((f2
& 0x7f) << 13)
628 static inline uint64_t tcg_opc_m34(int qp
, uint64_t opc
, int r1
,
629 int sof
, int sol
, int sor
)
632 | ((sor
& 0x0f) << 27)
633 | ((sol
& 0x7f) << 20)
634 | ((sof
& 0x7f) << 13)
639 static inline uint64_t tcg_opc_m48(int qp
, uint64_t opc
, uint64_t imm
)
642 | ((imm
& 0x100000) << 16) /* i */
643 | ((imm
& 0x0fffff) << 6) /* imm20a */
647 static inline uint64_t tcg_opc_x2(int qp
, uint64_t opc
,
648 int r1
, uint64_t imm
)
651 | ((imm
& 0x8000000000000000ull
) >> 27) /* i */
652 | (imm
& 0x0000000000200000ull
) /* ic */
653 | ((imm
& 0x00000000001f0000ull
) << 6) /* imm5c */
654 | ((imm
& 0x000000000000ff80ull
) << 20) /* imm9d */
655 | ((imm
& 0x000000000000007full
) << 13) /* imm7b */
660 static inline uint64_t tcg_opc_x3(int qp
, uint64_t opc
, uint64_t imm
)
663 | ((imm
& 0x0800000000000000ull
) >> 23) /* i */
664 | ((imm
& 0x00000000000fffffull
) << 13) /* imm20b */
673 static inline void reloc_pcrel21b(void *pc
, intptr_t target
)
679 slot
= (intptr_t)pc
& 3;
680 pc
= (void *)((intptr_t)pc
& ~3);
682 disp
= target
- (intptr_t)pc
;
683 imm
= (uint64_t) disp
>> 4;
687 *(uint64_t *)(pc
+ 0) = (*(uint64_t *)(pc
+ 8) & 0xfffffdc00003ffffull
)
688 | ((imm
& 0x100000) << 21) /* s */
689 | ((imm
& 0x0fffff) << 18); /* imm20b */
692 *(uint64_t *)(pc
+ 8) = (*(uint64_t *)(pc
+ 8) & 0xfffffffffffb8000ull
)
693 | ((imm
& 0x100000) >> 2) /* s */
694 | ((imm
& 0x0fffe0) >> 5); /* imm20b */
695 *(uint64_t *)(pc
+ 0) = (*(uint64_t *)(pc
+ 0) & 0x07ffffffffffffffull
)
696 | ((imm
& 0x00001f) << 59); /* imm20b */
699 *(uint64_t *)(pc
+ 8) = (*(uint64_t *)(pc
+ 8) & 0xf700000fffffffffull
)
700 | ((imm
& 0x100000) << 39) /* s */
701 | ((imm
& 0x0fffff) << 36); /* imm20b */
706 static inline uint64_t get_reloc_pcrel21b (void *pc
)
711 slot
= (tcg_target_long
) pc
& 3;
712 pc
= (void *)((tcg_target_long
) pc
& ~3);
714 low
= (*(uint64_t *)(pc
+ 0));
715 high
= (*(uint64_t *)(pc
+ 8));
719 return ((low
>> 21) & 0x100000) + /* s */
720 ((low
>> 18) & 0x0fffff); /* imm20b */
722 return ((high
<< 2) & 0x100000) + /* s */
723 ((high
<< 5) & 0x0fffe0) + /* imm20b */
724 ((low
>> 59) & 0x00001f); /* imm20b */
726 return ((high
>> 39) & 0x100000) + /* s */
727 ((high
>> 36) & 0x0fffff); /* imm20b */
733 static inline void reloc_pcrel60b(void *pc
, intptr_t target
)
738 disp
= target
- (intptr_t)pc
;
739 imm
= (uint64_t) disp
>> 4;
741 *(uint64_t *)(pc
+ 8) = (*(uint64_t *)(pc
+ 8) & 0xf700000fff800000ull
)
742 | (imm
& 0x0800000000000000ull
) /* s */
743 | ((imm
& 0x07fffff000000000ull
) >> 36) /* imm39 */
744 | ((imm
& 0x00000000000fffffull
) << 36); /* imm20b */
745 *(uint64_t *)(pc
+ 0) = (*(uint64_t *)(pc
+ 0) & 0x00003fffffffffffull
)
746 | ((imm
& 0x0000000ffff00000ull
) << 28); /* imm39 */
749 static inline uint64_t get_reloc_pcrel60b (void *pc
)
753 low
= (*(uint64_t *)(pc
+ 0));
754 high
= (*(uint64_t *)(pc
+ 8));
756 return ((high
) & 0x0800000000000000ull
) + /* s */
757 ((high
>> 36) & 0x00000000000fffffull
) + /* imm20b */
758 ((high
<< 36) & 0x07fffff000000000ull
) + /* imm39 */
759 ((low
>> 28) & 0x0000000ffff00000ull
); /* imm39 */
763 static void patch_reloc(uint8_t *code_ptr
, int type
,
764 intptr_t value
, intptr_t addend
)
768 case R_IA64_PCREL21B
:
769 reloc_pcrel21b(code_ptr
, value
);
771 case R_IA64_PCREL60B
:
772 reloc_pcrel60b(code_ptr
, value
);
782 /* parse target specific constraints */
783 static int target_parse_constraint(TCGArgConstraint
*ct
, const char **pct_str
)
790 ct
->ct
|= TCG_CT_REG
;
791 tcg_regset_set(ct
->u
.regs
, 0xffffffffffffffffull
);
794 ct
->ct
|= TCG_CT_CONST_S22
;
797 ct
->ct
|= TCG_CT_REG
;
798 tcg_regset_set(ct
->u
.regs
, 0xffffffffffffffffull
);
799 #if defined(CONFIG_SOFTMMU)
800 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R56
);
801 tcg_regset_reset_reg(ct
->u
.regs
, TCG_REG_R57
);
805 /* We are cheating a bit here, using the fact that the register
806 r0 is also the register number 0. Hence there is no need
807 to check for const_args in each instruction. */
808 ct
->ct
|= TCG_CT_CONST_ZERO
;
818 /* test if a constant matches the constraint */
819 static inline int tcg_target_const_match(tcg_target_long val
,
820 const TCGArgConstraint
*arg_ct
)
824 if (ct
& TCG_CT_CONST
)
826 else if ((ct
& TCG_CT_CONST_ZERO
) && val
== 0)
828 else if ((ct
& TCG_CT_CONST_S22
) && val
== ((int32_t)val
<< 10) >> 10)
838 static uint8_t *tb_ret_addr
;
840 static inline void tcg_out_bundle(TCGContext
*s
, int template,
841 uint64_t slot0
, uint64_t slot1
,
844 template &= 0x1f; /* 5 bits */
845 slot0
&= 0x1ffffffffffull
; /* 41 bits */
846 slot1
&= 0x1ffffffffffull
; /* 41 bits */
847 slot2
&= 0x1ffffffffffull
; /* 41 bits */
849 *(uint64_t *)(s
->code_ptr
+ 0) = (slot1
<< 46) | (slot0
<< 5) | template;
850 *(uint64_t *)(s
->code_ptr
+ 8) = (slot2
<< 23) | (slot1
>> 18);
854 static inline void tcg_out_mov(TCGContext
*s
, TCGType type
,
855 TCGReg ret
, TCGReg arg
)
857 tcg_out_bundle(s
, mmI
,
858 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
859 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
860 tcg_opc_a4(TCG_REG_P0
, OPC_ADDS_A4
, ret
, 0, arg
));
863 static inline void tcg_out_movi(TCGContext
*s
, TCGType type
,
864 TCGReg reg
, tcg_target_long arg
)
866 tcg_out_bundle(s
, mLX
,
867 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
869 tcg_opc_x2 (TCG_REG_P0
, OPC_MOVL_X2
, reg
, arg
));
872 static void tcg_out_br(TCGContext
*s
, int label_index
)
874 TCGLabel
*l
= &s
->labels
[label_index
];
876 /* We pay attention here to not modify the branch target by reading
877 the existing value and using it again. This ensure that caches and
878 memory are kept coherent during retranslation. */
879 tcg_out_bundle(s
, mmB
,
880 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
881 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
882 tcg_opc_b1 (TCG_REG_P0
, OPC_BR_SPTK_MANY_B1
,
883 get_reloc_pcrel21b(s
->code_ptr
+ 2)));
886 reloc_pcrel21b((s
->code_ptr
- 16) + 2, l
->u
.value
);
888 tcg_out_reloc(s
, (s
->code_ptr
- 16) + 2,
889 R_IA64_PCREL21B
, label_index
, 0);
893 static inline void tcg_out_call(TCGContext
*s
, TCGArg addr
)
895 tcg_out_bundle(s
, MmI
,
896 tcg_opc_m1 (TCG_REG_P0
, OPC_LD8_M1
, TCG_REG_R2
, addr
),
897 tcg_opc_a4 (TCG_REG_P0
, OPC_ADDS_A4
, TCG_REG_R3
, 8, addr
),
898 tcg_opc_i21(TCG_REG_P0
, OPC_MOV_I21
,
899 TCG_REG_B6
, TCG_REG_R2
, 0));
900 tcg_out_bundle(s
, mmB
,
901 tcg_opc_m1 (TCG_REG_P0
, OPC_LD8_M1
, TCG_REG_R1
, TCG_REG_R3
),
902 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
903 tcg_opc_b5 (TCG_REG_P0
, OPC_BR_CALL_SPTK_MANY_B5
,
904 TCG_REG_B0
, TCG_REG_B6
));
907 static void tcg_out_exit_tb(TCGContext
*s
, tcg_target_long arg
)
912 tcg_out_movi(s
, TCG_TYPE_PTR
, TCG_REG_R8
, arg
);
914 disp
= tb_ret_addr
- s
->code_ptr
;
915 imm
= (uint64_t)disp
>> 4;
917 tcg_out_bundle(s
, mLX
,
918 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
920 tcg_opc_x3 (TCG_REG_P0
, OPC_BRL_SPTK_MANY_X3
, imm
));
923 static inline void tcg_out_goto_tb(TCGContext
*s
, TCGArg arg
)
925 if (s
->tb_jmp_offset
) {
926 /* direct jump method */
929 /* indirect jump method */
930 tcg_out_movi(s
, TCG_TYPE_PTR
, TCG_REG_R2
,
931 (tcg_target_long
)(s
->tb_next
+ arg
));
932 tcg_out_bundle(s
, MmI
,
933 tcg_opc_m1 (TCG_REG_P0
, OPC_LD8_M1
,
934 TCG_REG_R2
, TCG_REG_R2
),
935 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
936 tcg_opc_i21(TCG_REG_P0
, OPC_MOV_I21
, TCG_REG_B6
,
938 tcg_out_bundle(s
, mmB
,
939 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
940 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
941 tcg_opc_b4 (TCG_REG_P0
, OPC_BR_SPTK_MANY_B4
,
944 s
->tb_next_offset
[arg
] = s
->code_ptr
- s
->code_buf
;
947 static inline void tcg_out_jmp(TCGContext
*s
, TCGArg addr
)
949 tcg_out_bundle(s
, mmI
,
950 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
951 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
952 tcg_opc_i21(TCG_REG_P0
, OPC_MOV_I21
, TCG_REG_B6
, addr
, 0));
953 tcg_out_bundle(s
, mmB
,
954 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
955 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
956 tcg_opc_b4(TCG_REG_P0
, OPC_BR_SPTK_MANY_B4
, TCG_REG_B6
));
959 static inline void tcg_out_ld_rel(TCGContext
*s
, uint64_t opc_m4
, TCGArg arg
,
960 TCGArg arg1
, tcg_target_long arg2
)
962 if (arg2
== ((int16_t)arg2
>> 2) << 2) {
963 tcg_out_bundle(s
, MmI
,
964 tcg_opc_a4(TCG_REG_P0
, OPC_ADDS_A4
,
965 TCG_REG_R2
, arg2
, arg1
),
966 tcg_opc_m1 (TCG_REG_P0
, opc_m4
, arg
, TCG_REG_R2
),
967 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
969 tcg_out_movi(s
, TCG_TYPE_PTR
, TCG_REG_R2
, arg2
);
970 tcg_out_bundle(s
, MmI
,
971 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
,
972 TCG_REG_R2
, TCG_REG_R2
, arg1
),
973 tcg_opc_m1 (TCG_REG_P0
, opc_m4
, arg
, TCG_REG_R2
),
974 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
978 static inline void tcg_out_st_rel(TCGContext
*s
, uint64_t opc_m4
, TCGArg arg
,
979 TCGArg arg1
, tcg_target_long arg2
)
981 if (arg2
== ((int16_t)arg2
>> 2) << 2) {
982 tcg_out_bundle(s
, MmI
,
983 tcg_opc_a4(TCG_REG_P0
, OPC_ADDS_A4
,
984 TCG_REG_R2
, arg2
, arg1
),
985 tcg_opc_m4 (TCG_REG_P0
, opc_m4
, arg
, TCG_REG_R2
),
986 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
988 tcg_out_movi(s
, TCG_TYPE_PTR
, TCG_REG_R2
, arg2
);
989 tcg_out_bundle(s
, MmI
,
990 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
,
991 TCG_REG_R2
, TCG_REG_R2
, arg1
),
992 tcg_opc_m4 (TCG_REG_P0
, opc_m4
, arg
, TCG_REG_R2
),
993 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
997 static inline void tcg_out_ld(TCGContext
*s
, TCGType type
, TCGReg arg
,
998 TCGReg arg1
, intptr_t arg2
)
1000 if (type
== TCG_TYPE_I32
) {
1001 tcg_out_ld_rel(s
, OPC_LD4_M1
, arg
, arg1
, arg2
);
1003 tcg_out_ld_rel(s
, OPC_LD8_M1
, arg
, arg1
, arg2
);
1007 static inline void tcg_out_st(TCGContext
*s
, TCGType type
, TCGReg arg
,
1008 TCGReg arg1
, intptr_t arg2
)
1010 if (type
== TCG_TYPE_I32
) {
1011 tcg_out_st_rel(s
, OPC_ST4_M4
, arg
, arg1
, arg2
);
1013 tcg_out_st_rel(s
, OPC_ST8_M4
, arg
, arg1
, arg2
);
1017 static inline void tcg_out_alu(TCGContext
*s
, uint64_t opc_a1
, TCGArg ret
,
1018 TCGArg arg1
, int const_arg1
,
1019 TCGArg arg2
, int const_arg2
)
1021 uint64_t opc1
, opc2
;
1023 if (const_arg1
&& arg1
!= 0) {
1024 opc1
= tcg_opc_a5(TCG_REG_P0
, OPC_ADDL_A5
,
1025 TCG_REG_R2
, arg1
, TCG_REG_R0
);
1028 opc1
= tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0);
1031 if (const_arg2
&& arg2
!= 0) {
1032 opc2
= tcg_opc_a5(TCG_REG_P0
, OPC_ADDL_A5
,
1033 TCG_REG_R3
, arg2
, TCG_REG_R0
);
1036 opc2
= tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0);
1039 tcg_out_bundle(s
, mII
,
1042 tcg_opc_a1(TCG_REG_P0
, opc_a1
, ret
, arg1
, arg2
));
1045 static inline void tcg_out_eqv(TCGContext
*s
, TCGArg ret
,
1046 TCGArg arg1
, int const_arg1
,
1047 TCGArg arg2
, int const_arg2
)
1049 tcg_out_bundle(s
, mII
,
1050 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1051 tcg_opc_a1 (TCG_REG_P0
, OPC_XOR_A1
, ret
, arg1
, arg2
),
1052 tcg_opc_a3 (TCG_REG_P0
, OPC_ANDCM_A3
, ret
, -1, ret
));
1055 static inline void tcg_out_nand(TCGContext
*s
, TCGArg ret
,
1056 TCGArg arg1
, int const_arg1
,
1057 TCGArg arg2
, int const_arg2
)
1059 tcg_out_bundle(s
, mII
,
1060 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1061 tcg_opc_a1 (TCG_REG_P0
, OPC_AND_A1
, ret
, arg1
, arg2
),
1062 tcg_opc_a3 (TCG_REG_P0
, OPC_ANDCM_A3
, ret
, -1, ret
));
1065 static inline void tcg_out_nor(TCGContext
*s
, TCGArg ret
,
1066 TCGArg arg1
, int const_arg1
,
1067 TCGArg arg2
, int const_arg2
)
1069 tcg_out_bundle(s
, mII
,
1070 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1071 tcg_opc_a1 (TCG_REG_P0
, OPC_OR_A1
, ret
, arg1
, arg2
),
1072 tcg_opc_a3 (TCG_REG_P0
, OPC_ANDCM_A3
, ret
, -1, ret
));
1075 static inline void tcg_out_orc(TCGContext
*s
, TCGArg ret
,
1076 TCGArg arg1
, int const_arg1
,
1077 TCGArg arg2
, int const_arg2
)
1079 tcg_out_bundle(s
, mII
,
1080 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1081 tcg_opc_a3 (TCG_REG_P0
, OPC_ANDCM_A3
, TCG_REG_R2
, -1, arg2
),
1082 tcg_opc_a1 (TCG_REG_P0
, OPC_OR_A1
, ret
, arg1
, TCG_REG_R2
));
1085 static inline void tcg_out_mul(TCGContext
*s
, TCGArg ret
,
1086 TCGArg arg1
, TCGArg arg2
)
1088 tcg_out_bundle(s
, mmI
,
1089 tcg_opc_m18(TCG_REG_P0
, OPC_SETF_SIG_M18
, TCG_REG_F6
, arg1
),
1090 tcg_opc_m18(TCG_REG_P0
, OPC_SETF_SIG_M18
, TCG_REG_F7
, arg2
),
1091 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1092 tcg_out_bundle(s
, mmF
,
1093 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1094 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1095 tcg_opc_f2 (TCG_REG_P0
, OPC_XMA_L_F2
, TCG_REG_F6
, TCG_REG_F6
,
1096 TCG_REG_F7
, TCG_REG_F0
));
1097 tcg_out_bundle(s
, miI
,
1098 tcg_opc_m19(TCG_REG_P0
, OPC_GETF_SIG_M19
, ret
, TCG_REG_F6
),
1099 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1100 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1103 static inline void tcg_out_sar_i32(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1104 TCGArg arg2
, int const_arg2
)
1107 tcg_out_bundle(s
, miI
,
1108 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1109 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1110 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_I11
,
1111 ret
, arg1
, arg2
, 31 - arg2
));
1113 tcg_out_bundle(s
, mII
,
1114 tcg_opc_a3 (TCG_REG_P0
, OPC_AND_A3
,
1115 TCG_REG_R3
, 0x1f, arg2
),
1116 tcg_opc_i29(TCG_REG_P0
, OPC_SXT4_I29
, TCG_REG_R2
, arg1
),
1117 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_I5
, ret
,
1118 TCG_REG_R2
, TCG_REG_R3
));
1122 static inline void tcg_out_sar_i64(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1123 TCGArg arg2
, int const_arg2
)
1126 tcg_out_bundle(s
, miI
,
1127 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1128 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1129 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_I11
,
1130 ret
, arg1
, arg2
, 63 - arg2
));
1132 tcg_out_bundle(s
, miI
,
1133 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1134 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1135 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_I5
, ret
, arg1
, arg2
));
1139 static inline void tcg_out_shl_i32(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1140 TCGArg arg2
, int const_arg2
)
1143 tcg_out_bundle(s
, miI
,
1144 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1145 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1146 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
, ret
,
1147 arg1
, 63 - arg2
, 31 - arg2
));
1149 tcg_out_bundle(s
, mII
,
1150 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1151 tcg_opc_a3 (TCG_REG_P0
, OPC_AND_A3
, TCG_REG_R2
,
1153 tcg_opc_i7 (TCG_REG_P0
, OPC_SHL_I7
, ret
,
1158 static inline void tcg_out_shl_i64(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1159 TCGArg arg2
, int const_arg2
)
1162 tcg_out_bundle(s
, miI
,
1163 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1164 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1165 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
, ret
,
1166 arg1
, 63 - arg2
, 63 - arg2
));
1168 tcg_out_bundle(s
, miI
,
1169 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1170 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1171 tcg_opc_i7 (TCG_REG_P0
, OPC_SHL_I7
, ret
,
1176 static inline void tcg_out_shr_i32(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1177 TCGArg arg2
, int const_arg2
)
1180 tcg_out_bundle(s
, miI
,
1181 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1182 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1183 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
, ret
,
1184 arg1
, arg2
, 31 - arg2
));
1186 tcg_out_bundle(s
, mII
,
1187 tcg_opc_a3 (TCG_REG_P0
, OPC_AND_A3
, TCG_REG_R3
,
1189 tcg_opc_i29(TCG_REG_P0
, OPC_ZXT4_I29
, TCG_REG_R2
, arg1
),
1190 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, ret
,
1191 TCG_REG_R2
, TCG_REG_R3
));
1195 static inline void tcg_out_shr_i64(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1196 TCGArg arg2
, int const_arg2
)
1199 tcg_out_bundle(s
, miI
,
1200 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1201 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1202 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
, ret
,
1203 arg1
, arg2
, 63 - arg2
));
1205 tcg_out_bundle(s
, miI
,
1206 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1207 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1208 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, ret
,
1213 static inline void tcg_out_rotl_i32(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1214 TCGArg arg2
, int const_arg2
)
1217 tcg_out_bundle(s
, mII
,
1218 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1219 tcg_opc_i2 (TCG_REG_P0
, OPC_UNPACK4_L_I2
,
1220 TCG_REG_R2
, arg1
, arg1
),
1221 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
, ret
,
1222 TCG_REG_R2
, 32 - arg2
, 31));
1224 tcg_out_bundle(s
, miI
,
1225 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1226 tcg_opc_i2 (TCG_REG_P0
, OPC_UNPACK4_L_I2
,
1227 TCG_REG_R2
, arg1
, arg1
),
1228 tcg_opc_a3 (TCG_REG_P0
, OPC_AND_A3
, TCG_REG_R3
,
1230 tcg_out_bundle(s
, mII
,
1231 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1232 tcg_opc_a3 (TCG_REG_P0
, OPC_SUB_A3
, TCG_REG_R3
,
1234 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, ret
,
1235 TCG_REG_R2
, TCG_REG_R3
));
1239 static inline void tcg_out_rotl_i64(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1240 TCGArg arg2
, int const_arg2
)
1243 tcg_out_bundle(s
, miI
,
1244 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1245 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1246 tcg_opc_i10(TCG_REG_P0
, OPC_SHRP_I10
, ret
, arg1
,
1247 arg1
, 0x40 - arg2
));
1249 tcg_out_bundle(s
, mII
,
1250 tcg_opc_a3 (TCG_REG_P0
, OPC_SUB_A3
, TCG_REG_R2
,
1252 tcg_opc_i7 (TCG_REG_P0
, OPC_SHL_I7
, TCG_REG_R3
,
1254 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, TCG_REG_R2
,
1256 tcg_out_bundle(s
, miI
,
1257 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1258 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1259 tcg_opc_a1 (TCG_REG_P0
, OPC_OR_A1
, ret
,
1260 TCG_REG_R2
, TCG_REG_R3
));
1264 static inline void tcg_out_rotr_i32(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1265 TCGArg arg2
, int const_arg2
)
1268 tcg_out_bundle(s
, mII
,
1269 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1270 tcg_opc_i2 (TCG_REG_P0
, OPC_UNPACK4_L_I2
,
1271 TCG_REG_R2
, arg1
, arg1
),
1272 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
, ret
,
1273 TCG_REG_R2
, arg2
, 31));
1275 tcg_out_bundle(s
, mII
,
1276 tcg_opc_a3 (TCG_REG_P0
, OPC_AND_A3
, TCG_REG_R3
,
1278 tcg_opc_i2 (TCG_REG_P0
, OPC_UNPACK4_L_I2
,
1279 TCG_REG_R2
, arg1
, arg1
),
1280 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, ret
,
1281 TCG_REG_R2
, TCG_REG_R3
));
1285 static inline void tcg_out_rotr_i64(TCGContext
*s
, TCGArg ret
, TCGArg arg1
,
1286 TCGArg arg2
, int const_arg2
)
1289 tcg_out_bundle(s
, miI
,
1290 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1291 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1292 tcg_opc_i10(TCG_REG_P0
, OPC_SHRP_I10
, ret
, arg1
,
1295 tcg_out_bundle(s
, mII
,
1296 tcg_opc_a3 (TCG_REG_P0
, OPC_SUB_A3
, TCG_REG_R2
,
1298 tcg_opc_i5 (TCG_REG_P0
, OPC_SHR_U_I5
, TCG_REG_R3
,
1300 tcg_opc_i7 (TCG_REG_P0
, OPC_SHL_I7
, TCG_REG_R2
,
1302 tcg_out_bundle(s
, miI
,
1303 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1304 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1305 tcg_opc_a1 (TCG_REG_P0
, OPC_OR_A1
, ret
,
1306 TCG_REG_R2
, TCG_REG_R3
));
1310 static inline void tcg_out_ext(TCGContext
*s
, uint64_t opc_i29
,
1311 TCGArg ret
, TCGArg arg
)
1313 tcg_out_bundle(s
, miI
,
1314 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1315 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1316 tcg_opc_i29(TCG_REG_P0
, opc_i29
, ret
, arg
));
1319 static inline void tcg_out_bswap16(TCGContext
*s
, TCGArg ret
, TCGArg arg
)
1321 tcg_out_bundle(s
, mII
,
1322 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1323 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
, ret
, arg
, 15, 15),
1324 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
, ret
, ret
, 0xb));
1327 static inline void tcg_out_bswap32(TCGContext
*s
, TCGArg ret
, TCGArg arg
)
1329 tcg_out_bundle(s
, mII
,
1330 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1331 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
, ret
, arg
, 31, 31),
1332 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
, ret
, ret
, 0xb));
1335 static inline void tcg_out_bswap64(TCGContext
*s
, TCGArg ret
, TCGArg arg
)
1337 tcg_out_bundle(s
, miI
,
1338 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1339 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1340 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
, ret
, arg
, 0xb));
1343 static inline void tcg_out_deposit(TCGContext
*s
, TCGArg ret
, TCGArg a1
,
1344 TCGArg a2
, int const_a2
, int pos
, int len
)
1346 uint64_t i1
= 0, i2
= 0;
1347 int cpos
= 63 - pos
, lm1
= len
- 1;
1350 /* Truncate the value of a constant a2 to the width of the field. */
1351 int mask
= (1u << len
) - 1;
1354 if (a2
== 0 || a2
== mask
) {
1355 /* 1-bit signed constant inserted into register. */
1356 i2
= tcg_opc_i14(TCG_REG_P0
, OPC_DEP_I14
, ret
, a2
, a1
, cpos
, lm1
);
1358 /* Otherwise, load any constant into a temporary. Do this into
1359 the first I slot to help out with cross-unit delays. */
1360 i1
= tcg_opc_a5(TCG_REG_P0
, OPC_ADDL_A5
,
1361 TCG_REG_R2
, a2
, TCG_REG_R0
);
1366 i2
= tcg_opc_i15(TCG_REG_P0
, OPC_DEP_I15
, ret
, a2
, a1
, cpos
, lm1
);
1368 tcg_out_bundle(s
, (i1
? mII
: miI
),
1369 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1370 i1
? i1
: tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1374 static inline uint64_t tcg_opc_cmp_a(int qp
, TCGCond cond
, TCGArg arg1
,
1375 TCGArg arg2
, int cmp4
)
1377 uint64_t opc_eq_a6
, opc_lt_a6
, opc_ltu_a6
;
1380 opc_eq_a6
= OPC_CMP4_EQ_A6
;
1381 opc_lt_a6
= OPC_CMP4_LT_A6
;
1382 opc_ltu_a6
= OPC_CMP4_LTU_A6
;
1384 opc_eq_a6
= OPC_CMP_EQ_A6
;
1385 opc_lt_a6
= OPC_CMP_LT_A6
;
1386 opc_ltu_a6
= OPC_CMP_LTU_A6
;
1391 return tcg_opc_a6 (qp
, opc_eq_a6
, TCG_REG_P6
, TCG_REG_P7
, arg1
, arg2
);
1393 return tcg_opc_a6 (qp
, opc_eq_a6
, TCG_REG_P7
, TCG_REG_P6
, arg1
, arg2
);
1395 return tcg_opc_a6 (qp
, opc_lt_a6
, TCG_REG_P6
, TCG_REG_P7
, arg1
, arg2
);
1397 return tcg_opc_a6 (qp
, opc_ltu_a6
, TCG_REG_P6
, TCG_REG_P7
, arg1
, arg2
);
1399 return tcg_opc_a6 (qp
, opc_lt_a6
, TCG_REG_P7
, TCG_REG_P6
, arg1
, arg2
);
1401 return tcg_opc_a6 (qp
, opc_ltu_a6
, TCG_REG_P7
, TCG_REG_P6
, arg1
, arg2
);
1403 return tcg_opc_a6 (qp
, opc_lt_a6
, TCG_REG_P7
, TCG_REG_P6
, arg2
, arg1
);
1405 return tcg_opc_a6 (qp
, opc_ltu_a6
, TCG_REG_P7
, TCG_REG_P6
, arg2
, arg1
);
1407 return tcg_opc_a6 (qp
, opc_lt_a6
, TCG_REG_P6
, TCG_REG_P7
, arg2
, arg1
);
1409 return tcg_opc_a6 (qp
, opc_ltu_a6
, TCG_REG_P6
, TCG_REG_P7
, arg2
, arg1
);
1416 static inline void tcg_out_brcond(TCGContext
*s
, TCGCond cond
, TCGArg arg1
,
1417 int const_arg1
, TCGArg arg2
, int const_arg2
,
1418 int label_index
, int cmp4
)
1420 TCGLabel
*l
= &s
->labels
[label_index
];
1421 uint64_t opc1
, opc2
;
1423 if (const_arg1
&& arg1
!= 0) {
1424 opc1
= tcg_opc_a5(TCG_REG_P0
, OPC_ADDL_A5
, TCG_REG_R2
,
1428 opc1
= tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0);
1431 if (const_arg2
&& arg2
!= 0) {
1432 opc2
= tcg_opc_a5(TCG_REG_P0
, OPC_ADDL_A5
, TCG_REG_R3
,
1436 opc2
= tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0);
1439 tcg_out_bundle(s
, mII
,
1442 tcg_opc_cmp_a(TCG_REG_P0
, cond
, arg1
, arg2
, cmp4
));
1443 tcg_out_bundle(s
, mmB
,
1444 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1445 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1446 tcg_opc_b1 (TCG_REG_P6
, OPC_BR_DPTK_FEW_B1
,
1447 get_reloc_pcrel21b(s
->code_ptr
+ 2)));
1450 reloc_pcrel21b((s
->code_ptr
- 16) + 2, l
->u
.value
);
1452 tcg_out_reloc(s
, (s
->code_ptr
- 16) + 2,
1453 R_IA64_PCREL21B
, label_index
, 0);
1457 static inline void tcg_out_setcond(TCGContext
*s
, TCGCond cond
, TCGArg ret
,
1458 TCGArg arg1
, TCGArg arg2
, int cmp4
)
1460 tcg_out_bundle(s
, MmI
,
1461 tcg_opc_cmp_a(TCG_REG_P0
, cond
, arg1
, arg2
, cmp4
),
1462 tcg_opc_a5(TCG_REG_P6
, OPC_ADDL_A5
, ret
, 1, TCG_REG_R0
),
1463 tcg_opc_a5(TCG_REG_P7
, OPC_ADDL_A5
, ret
, 0, TCG_REG_R0
));
1466 static inline void tcg_out_movcond(TCGContext
*s
, TCGCond cond
, TCGArg ret
,
1467 TCGArg c1
, TCGArg c2
,
1468 TCGArg v1
, int const_v1
,
1469 TCGArg v2
, int const_v2
, int cmp4
)
1471 uint64_t opc1
, opc2
;
1474 opc1
= tcg_opc_a5(TCG_REG_P6
, OPC_ADDL_A5
, ret
, v1
, TCG_REG_R0
);
1475 } else if (ret
== v1
) {
1476 opc1
= tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0);
1478 opc1
= tcg_opc_a4(TCG_REG_P6
, OPC_ADDS_A4
, ret
, 0, v1
);
1481 opc2
= tcg_opc_a5(TCG_REG_P7
, OPC_ADDL_A5
, ret
, v2
, TCG_REG_R0
);
1482 } else if (ret
== v2
) {
1483 opc2
= tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0);
1485 opc2
= tcg_opc_a4(TCG_REG_P7
, OPC_ADDS_A4
, ret
, 0, v2
);
1488 tcg_out_bundle(s
, MmI
,
1489 tcg_opc_cmp_a(TCG_REG_P0
, cond
, c1
, c2
, cmp4
),
1494 #if defined(CONFIG_SOFTMMU)
1495 /* Load and compare a TLB entry, and return the result in (p6, p7).
1496 R2 is loaded with the address of the addend TLB entry.
1497 R57 is loaded with the address, zero extented on 32-bit targets. */
1498 static inline void tcg_out_qemu_tlb(TCGContext
*s
, TCGArg addr_reg
,
1499 TCGMemOp s_bits
, uint64_t offset_rw
,
1500 uint64_t offset_addend
)
1502 tcg_out_bundle(s
, mII
,
1503 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1504 tcg_opc_i11(TCG_REG_P0
, OPC_EXTR_U_I11
, TCG_REG_R2
,
1505 addr_reg
, TARGET_PAGE_BITS
, CPU_TLB_BITS
- 1),
1506 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
, TCG_REG_R2
,
1507 TCG_REG_R2
, 63 - CPU_TLB_ENTRY_BITS
,
1508 63 - CPU_TLB_ENTRY_BITS
));
1509 tcg_out_bundle(s
, mII
,
1510 tcg_opc_a5 (TCG_REG_P0
, OPC_ADDL_A5
, TCG_REG_R2
,
1511 offset_rw
, TCG_REG_R2
),
1512 #if TARGET_LONG_BITS == 32
1513 tcg_opc_i29(TCG_REG_P0
, OPC_ZXT4_I29
, TCG_REG_R57
, addr_reg
),
1515 tcg_opc_a4(TCG_REG_P0
, OPC_ADDS_A4
, TCG_REG_R57
,
1518 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
, TCG_REG_R2
,
1519 TCG_REG_R2
, TCG_AREG0
));
1520 tcg_out_bundle(s
, mII
,
1521 tcg_opc_m3 (TCG_REG_P0
,
1522 (TARGET_LONG_BITS
== 32
1523 ? OPC_LD4_M3
: OPC_LD8_M3
), TCG_REG_R56
,
1524 TCG_REG_R2
, offset_addend
- offset_rw
),
1525 tcg_opc_i14(TCG_REG_P0
, OPC_DEP_I14
, TCG_REG_R3
, 0,
1526 TCG_REG_R57
, 63 - s_bits
,
1527 TARGET_PAGE_BITS
- s_bits
- 1),
1528 tcg_opc_a6 (TCG_REG_P0
, OPC_CMP_EQ_A6
, TCG_REG_P6
,
1529 TCG_REG_P7
, TCG_REG_R3
, TCG_REG_R56
));
1532 /* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr,
1534 static const void * const qemu_ld_helpers
[4] = {
1541 static inline void tcg_out_qemu_ld(TCGContext
*s
, const TCGArg
*args
,
1544 static const uint64_t opc_ld_m1
[4] = {
1545 OPC_LD1_M1
, OPC_LD2_M1
, OPC_LD4_M1
, OPC_LD8_M1
1547 static const uint64_t opc_ext_i29
[8] = {
1548 OPC_ZXT1_I29
, OPC_ZXT2_I29
, OPC_ZXT4_I29
, 0,
1549 OPC_SXT1_I29
, OPC_SXT2_I29
, OPC_SXT4_I29
, 0
1551 int addr_reg
, data_reg
, mem_index
;
1552 TCGMemOp s_bits
, bswap
;
1557 s_bits
= opc
& MO_SIZE
;
1558 bswap
= opc
& MO_BSWAP
;
1560 /* Read the TLB entry */
1561 tcg_out_qemu_tlb(s
, addr_reg
, s_bits
,
1562 offsetof(CPUArchState
, tlb_table
[mem_index
][0].addr_read
),
1563 offsetof(CPUArchState
, tlb_table
[mem_index
][0].addend
));
1565 /* P6 is the fast path, and P7 the slow path */
1566 tcg_out_bundle(s
, mLX
,
1567 tcg_opc_a4 (TCG_REG_P7
, OPC_ADDS_A4
,
1568 TCG_REG_R56
, 0, TCG_AREG0
),
1569 tcg_opc_l2 ((tcg_target_long
) qemu_ld_helpers
[s_bits
]),
1570 tcg_opc_x2 (TCG_REG_P7
, OPC_MOVL_X2
, TCG_REG_R2
,
1571 (tcg_target_long
) qemu_ld_helpers
[s_bits
]));
1572 tcg_out_bundle(s
, MmI
,
1573 tcg_opc_m3 (TCG_REG_P0
, OPC_LD8_M3
, TCG_REG_R3
,
1575 tcg_opc_a1 (TCG_REG_P6
, OPC_ADD_A1
, TCG_REG_R3
,
1576 TCG_REG_R3
, TCG_REG_R57
),
1577 tcg_opc_i21(TCG_REG_P7
, OPC_MOV_I21
, TCG_REG_B6
,
1579 if (bswap
&& s_bits
== MO_16
) {
1580 tcg_out_bundle(s
, MmI
,
1581 tcg_opc_m1 (TCG_REG_P6
, opc_ld_m1
[s_bits
],
1582 TCG_REG_R8
, TCG_REG_R3
),
1583 tcg_opc_m1 (TCG_REG_P7
, OPC_LD8_M1
, TCG_REG_R1
, TCG_REG_R2
),
1584 tcg_opc_i12(TCG_REG_P6
, OPC_DEP_Z_I12
,
1585 TCG_REG_R8
, TCG_REG_R8
, 15, 15));
1586 } else if (bswap
&& s_bits
== MO_32
) {
1587 tcg_out_bundle(s
, MmI
,
1588 tcg_opc_m1 (TCG_REG_P6
, opc_ld_m1
[s_bits
],
1589 TCG_REG_R8
, TCG_REG_R3
),
1590 tcg_opc_m1 (TCG_REG_P7
, OPC_LD8_M1
, TCG_REG_R1
, TCG_REG_R2
),
1591 tcg_opc_i12(TCG_REG_P6
, OPC_DEP_Z_I12
,
1592 TCG_REG_R8
, TCG_REG_R8
, 31, 31));
1594 tcg_out_bundle(s
, mmI
,
1595 tcg_opc_m1 (TCG_REG_P6
, opc_ld_m1
[s_bits
],
1596 TCG_REG_R8
, TCG_REG_R3
),
1597 tcg_opc_m1 (TCG_REG_P7
, OPC_LD8_M1
, TCG_REG_R1
, TCG_REG_R2
),
1598 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1601 tcg_out_bundle(s
, miB
,
1602 tcg_opc_a5 (TCG_REG_P7
, OPC_ADDL_A5
, TCG_REG_R58
,
1603 mem_index
, TCG_REG_R0
),
1604 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1605 tcg_opc_b5 (TCG_REG_P7
, OPC_BR_CALL_SPTK_MANY_B5
,
1606 TCG_REG_B0
, TCG_REG_B6
));
1608 tcg_out_bundle(s
, miB
,
1609 tcg_opc_a5 (TCG_REG_P7
, OPC_ADDL_A5
, TCG_REG_R58
,
1610 mem_index
, TCG_REG_R0
),
1611 tcg_opc_i3 (TCG_REG_P6
, OPC_MUX1_I3
,
1612 TCG_REG_R8
, TCG_REG_R8
, 0xb),
1613 tcg_opc_b5 (TCG_REG_P7
, OPC_BR_CALL_SPTK_MANY_B5
,
1614 TCG_REG_B0
, TCG_REG_B6
));
1617 if (s_bits
== MO_64
) {
1618 tcg_out_bundle(s
, miI
,
1619 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1620 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1621 tcg_opc_a4 (TCG_REG_P0
, OPC_ADDS_A4
,
1622 data_reg
, 0, TCG_REG_R8
));
1624 tcg_out_bundle(s
, miI
,
1625 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1626 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1627 tcg_opc_i29(TCG_REG_P0
, opc_ext_i29
[opc
& MO_SSIZE
],
1628 data_reg
, TCG_REG_R8
));
1632 /* helper signature: helper_st_mmu(CPUState *env, target_ulong addr,
1633 uintxx_t val, int mmu_idx) */
1634 static const void * const qemu_st_helpers
[4] = {
1641 static inline void tcg_out_qemu_st(TCGContext
*s
, const TCGArg
*args
,
1644 static const uint64_t opc_st_m4
[4] = {
1645 OPC_ST1_M4
, OPC_ST2_M4
, OPC_ST4_M4
, OPC_ST8_M4
1647 int addr_reg
, data_reg
, mem_index
;
1653 s_bits
= opc
& MO_SIZE
;
1655 tcg_out_qemu_tlb(s
, addr_reg
, s_bits
,
1656 offsetof(CPUArchState
, tlb_table
[mem_index
][0].addr_write
),
1657 offsetof(CPUArchState
, tlb_table
[mem_index
][0].addend
));
1659 /* P6 is the fast path, and P7 the slow path */
1660 tcg_out_bundle(s
, mLX
,
1661 tcg_opc_a4 (TCG_REG_P7
, OPC_ADDS_A4
,
1662 TCG_REG_R56
, 0, TCG_AREG0
),
1663 tcg_opc_l2 ((tcg_target_long
) qemu_st_helpers
[s_bits
]),
1664 tcg_opc_x2 (TCG_REG_P7
, OPC_MOVL_X2
, TCG_REG_R2
,
1665 (tcg_target_long
) qemu_st_helpers
[s_bits
]));
1666 tcg_out_bundle(s
, MmI
,
1667 tcg_opc_m3 (TCG_REG_P0
, OPC_LD8_M3
, TCG_REG_R3
,
1669 tcg_opc_a1 (TCG_REG_P6
, OPC_ADD_A1
, TCG_REG_R3
,
1670 TCG_REG_R3
, TCG_REG_R57
),
1671 tcg_opc_i21(TCG_REG_P7
, OPC_MOV_I21
, TCG_REG_B6
,
1679 tcg_out_bundle(s
, mii
,
1680 tcg_opc_m1 (TCG_REG_P7
, OPC_LD8_M1
,
1681 TCG_REG_R1
, TCG_REG_R2
),
1682 tcg_opc_a4 (TCG_REG_P7
, OPC_ADDS_A4
, TCG_REG_R58
,
1684 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1687 case MO_16
| MO_BSWAP
:
1688 tcg_out_bundle(s
, miI
,
1689 tcg_opc_m1 (TCG_REG_P7
, OPC_LD8_M1
,
1690 TCG_REG_R1
, TCG_REG_R2
),
1691 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1692 tcg_opc_i12(TCG_REG_P6
, OPC_DEP_Z_I12
,
1693 TCG_REG_R2
, data_reg
, 15, 15));
1694 tcg_out_bundle(s
, miI
,
1695 tcg_opc_a4 (TCG_REG_P7
, OPC_ADDS_A4
, TCG_REG_R58
,
1697 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1698 tcg_opc_i3 (TCG_REG_P6
, OPC_MUX1_I3
,
1699 TCG_REG_R2
, TCG_REG_R2
, 0xb));
1700 data_reg
= TCG_REG_R2
;
1703 case MO_32
| MO_BSWAP
:
1704 tcg_out_bundle(s
, miI
,
1705 tcg_opc_m1 (TCG_REG_P7
, OPC_LD8_M1
,
1706 TCG_REG_R1
, TCG_REG_R2
),
1707 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1708 tcg_opc_i12(TCG_REG_P6
, OPC_DEP_Z_I12
,
1709 TCG_REG_R2
, data_reg
, 31, 31));
1710 tcg_out_bundle(s
, miI
,
1711 tcg_opc_a4 (TCG_REG_P7
, OPC_ADDS_A4
, TCG_REG_R58
,
1713 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1714 tcg_opc_i3 (TCG_REG_P6
, OPC_MUX1_I3
,
1715 TCG_REG_R2
, TCG_REG_R2
, 0xb));
1716 data_reg
= TCG_REG_R2
;
1719 case MO_64
| MO_BSWAP
:
1720 tcg_out_bundle(s
, miI
,
1721 tcg_opc_m1 (TCG_REG_P7
, OPC_LD8_M1
,
1722 TCG_REG_R1
, TCG_REG_R2
),
1723 tcg_opc_a4 (TCG_REG_P7
, OPC_ADDS_A4
, TCG_REG_R58
,
1725 tcg_opc_i3 (TCG_REG_P6
, OPC_MUX1_I3
,
1726 TCG_REG_R2
, data_reg
, 0xb));
1727 data_reg
= TCG_REG_R2
;
1734 tcg_out_bundle(s
, miB
,
1735 tcg_opc_m4 (TCG_REG_P6
, opc_st_m4
[s_bits
],
1736 data_reg
, TCG_REG_R3
),
1737 tcg_opc_a5 (TCG_REG_P7
, OPC_ADDL_A5
, TCG_REG_R59
,
1738 mem_index
, TCG_REG_R0
),
1739 tcg_opc_b5 (TCG_REG_P7
, OPC_BR_CALL_SPTK_MANY_B5
,
1740 TCG_REG_B0
, TCG_REG_B6
));
1743 #else /* !CONFIG_SOFTMMU */
1745 static inline void tcg_out_qemu_ld(TCGContext
*s
, const TCGArg
*args
,
1748 static uint64_t const opc_ld_m1
[4] = {
1749 OPC_LD1_M1
, OPC_LD2_M1
, OPC_LD4_M1
, OPC_LD8_M1
1751 static uint64_t const opc_sxt_i29
[4] = {
1752 OPC_SXT1_I29
, OPC_SXT2_I29
, OPC_SXT4_I29
, 0
1754 int addr_reg
, data_reg
;
1755 TCGMemOp 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
,
1765 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
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
,
1772 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1773 tcg_opc_i29(TCG_REG_P0
, OPC_ZXT4_I29
,
1774 TCG_REG_R2
, addr_reg
),
1775 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
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
),
1783 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1784 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1786 tcg_out_bundle(s
, mII
,
1787 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1788 data_reg
, TCG_REG_R2
),
1789 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1790 tcg_opc_i29(TCG_REG_P0
, opc_sxt_i29
[s_bits
],
1791 data_reg
, data_reg
));
1793 } else if (s_bits
== MO_64
) {
1794 tcg_out_bundle(s
, mII
,
1795 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1796 data_reg
, TCG_REG_R2
),
1797 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1798 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1799 data_reg
, data_reg
, 0xb));
1801 if (s_bits
== MO_16
) {
1802 tcg_out_bundle(s
, mII
,
1803 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1804 data_reg
, TCG_REG_R2
),
1805 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1806 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1807 data_reg
, data_reg
, 15, 15));
1809 tcg_out_bundle(s
, mII
,
1810 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1811 data_reg
, TCG_REG_R2
),
1812 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1813 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1814 data_reg
, data_reg
, 31, 31));
1816 if (!(opc
& MO_SIGN
)) {
1817 tcg_out_bundle(s
, miI
,
1818 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1819 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1820 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1821 data_reg
, data_reg
, 0xb));
1823 tcg_out_bundle(s
, mII
,
1824 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1825 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1826 data_reg
, data_reg
, 0xb),
1827 tcg_opc_i29(TCG_REG_P0
, opc_sxt_i29
[s_bits
],
1828 data_reg
, data_reg
));
1832 if (GUEST_BASE
!= 0) {
1833 tcg_out_bundle(s
, MmI
,
1834 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
, TCG_REG_R2
,
1835 TCG_GUEST_BASE_REG
, addr_reg
),
1836 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1837 data_reg
, TCG_REG_R2
),
1838 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1840 tcg_out_bundle(s
, mmI
,
1841 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1842 tcg_opc_m1 (TCG_REG_P0
, opc_ld_m1
[s_bits
],
1843 data_reg
, addr_reg
),
1844 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1847 if (bswap
&& s_bits
== MO_16
) {
1848 tcg_out_bundle(s
, mII
,
1849 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1850 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1851 data_reg
, data_reg
, 15, 15),
1852 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1853 data_reg
, data_reg
, 0xb));
1854 } else if (bswap
&& s_bits
== MO_32
) {
1855 tcg_out_bundle(s
, mII
,
1856 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1857 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1858 data_reg
, data_reg
, 31, 31),
1859 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1860 data_reg
, data_reg
, 0xb));
1861 } else if (bswap
&& s_bits
== MO_64
) {
1862 tcg_out_bundle(s
, miI
,
1863 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1864 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1865 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1866 data_reg
, data_reg
, 0xb));
1868 if (opc
& MO_SIGN
) {
1869 tcg_out_bundle(s
, miI
,
1870 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1871 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1872 tcg_opc_i29(TCG_REG_P0
, opc_sxt_i29
[s_bits
],
1873 data_reg
, data_reg
));
1878 static inline void tcg_out_qemu_st(TCGContext
*s
, const TCGArg
*args
,
1881 static uint64_t const opc_st_m4
[4] = {
1882 OPC_ST1_M4
, OPC_ST2_M4
, OPC_ST4_M4
, OPC_ST8_M4
1884 int addr_reg
, data_reg
;
1885 #if TARGET_LONG_BITS == 64
1886 uint64_t add_guest_base
;
1888 TCGMemOp s_bits
, bswap
;
1892 s_bits
= opc
& MO_SIZE
;
1893 bswap
= opc
& MO_BSWAP
;
1895 #if TARGET_LONG_BITS == 32
1896 if (GUEST_BASE
!= 0) {
1897 tcg_out_bundle(s
, mII
,
1898 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1899 tcg_opc_i29(TCG_REG_P0
, OPC_ZXT4_I29
,
1900 TCG_REG_R3
, addr_reg
),
1901 tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
, TCG_REG_R2
,
1902 TCG_GUEST_BASE_REG
, TCG_REG_R3
));
1904 tcg_out_bundle(s
, miI
,
1905 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1906 tcg_opc_i29(TCG_REG_P0
, OPC_ZXT4_I29
,
1907 TCG_REG_R2
, addr_reg
),
1908 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1912 if (s_bits
== MO_16
) {
1913 tcg_out_bundle(s
, mII
,
1914 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1915 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1916 TCG_REG_R3
, data_reg
, 15, 15),
1917 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1918 TCG_REG_R3
, TCG_REG_R3
, 0xb));
1919 data_reg
= TCG_REG_R3
;
1920 } else if (s_bits
== MO_32
) {
1921 tcg_out_bundle(s
, mII
,
1922 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1923 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1924 TCG_REG_R3
, data_reg
, 31, 31),
1925 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1926 TCG_REG_R3
, TCG_REG_R3
, 0xb));
1927 data_reg
= TCG_REG_R3
;
1928 } else if (s_bits
== MO_64
) {
1929 tcg_out_bundle(s
, miI
,
1930 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1931 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1932 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1933 TCG_REG_R3
, data_reg
, 0xb));
1934 data_reg
= TCG_REG_R3
;
1937 tcg_out_bundle(s
, mmI
,
1938 tcg_opc_m4 (TCG_REG_P0
, opc_st_m4
[s_bits
],
1939 data_reg
, TCG_REG_R2
),
1940 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
1941 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1943 if (GUEST_BASE
!= 0) {
1944 add_guest_base
= tcg_opc_a1 (TCG_REG_P0
, OPC_ADD_A1
, TCG_REG_R2
,
1945 TCG_GUEST_BASE_REG
, addr_reg
);
1946 addr_reg
= TCG_REG_R2
;
1948 add_guest_base
= tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0);
1952 tcg_out_bundle(s
, (GUEST_BASE
? MmI
: mmI
),
1954 tcg_opc_m4 (TCG_REG_P0
, opc_st_m4
[s_bits
],
1955 data_reg
, addr_reg
),
1956 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1958 if (s_bits
== MO_16
) {
1959 tcg_out_bundle(s
, mII
,
1961 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1962 TCG_REG_R3
, data_reg
, 15, 15),
1963 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1964 TCG_REG_R3
, TCG_REG_R3
, 0xb));
1965 data_reg
= TCG_REG_R3
;
1966 } else if (s_bits
== MO_32
) {
1967 tcg_out_bundle(s
, mII
,
1969 tcg_opc_i12(TCG_REG_P0
, OPC_DEP_Z_I12
,
1970 TCG_REG_R3
, data_reg
, 31, 31),
1971 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1972 TCG_REG_R3
, TCG_REG_R3
, 0xb));
1973 data_reg
= TCG_REG_R3
;
1974 } else if (s_bits
== MO_64
) {
1975 tcg_out_bundle(s
, miI
,
1977 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1978 tcg_opc_i3 (TCG_REG_P0
, OPC_MUX1_I3
,
1979 TCG_REG_R3
, data_reg
, 0xb));
1980 data_reg
= TCG_REG_R3
;
1982 tcg_out_bundle(s
, miI
,
1983 tcg_opc_m4 (TCG_REG_P0
, opc_st_m4
[s_bits
],
1984 data_reg
, addr_reg
),
1985 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0),
1986 tcg_opc_i18(TCG_REG_P0
, OPC_NOP_I18
, 0));
1993 static inline void tcg_out_op(TCGContext
*s
, TCGOpcode opc
,
1994 const TCGArg
*args
, const int *const_args
)
1997 case INDEX_op_exit_tb
:
1998 tcg_out_exit_tb(s
, args
[0]);
2001 tcg_out_br(s
, args
[0]);
2004 tcg_out_call(s
, args
[0]);
2006 case INDEX_op_goto_tb
:
2007 tcg_out_goto_tb(s
, args
[0]);
2010 case INDEX_op_movi_i32
:
2011 tcg_out_movi(s
, TCG_TYPE_I32
, args
[0], args
[1]);
2013 case INDEX_op_movi_i64
:
2014 tcg_out_movi(s
, TCG_TYPE_I64
, args
[0], args
[1]);
2017 case INDEX_op_ld8u_i32
:
2018 case INDEX_op_ld8u_i64
:
2019 tcg_out_ld_rel(s
, OPC_LD1_M1
, args
[0], args
[1], args
[2]);
2021 case INDEX_op_ld8s_i32
:
2022 case INDEX_op_ld8s_i64
:
2023 tcg_out_ld_rel(s
, OPC_LD1_M1
, args
[0], args
[1], args
[2]);
2024 tcg_out_ext(s
, OPC_SXT1_I29
, args
[0], args
[0]);
2026 case INDEX_op_ld16u_i32
:
2027 case INDEX_op_ld16u_i64
:
2028 tcg_out_ld_rel(s
, OPC_LD2_M1
, args
[0], args
[1], args
[2]);
2030 case INDEX_op_ld16s_i32
:
2031 case INDEX_op_ld16s_i64
:
2032 tcg_out_ld_rel(s
, OPC_LD2_M1
, args
[0], args
[1], args
[2]);
2033 tcg_out_ext(s
, OPC_SXT2_I29
, args
[0], args
[0]);
2035 case INDEX_op_ld_i32
:
2036 case INDEX_op_ld32u_i64
:
2037 tcg_out_ld_rel(s
, OPC_LD4_M1
, args
[0], args
[1], args
[2]);
2039 case INDEX_op_ld32s_i64
:
2040 tcg_out_ld_rel(s
, OPC_LD4_M1
, args
[0], args
[1], args
[2]);
2041 tcg_out_ext(s
, OPC_SXT4_I29
, args
[0], args
[0]);
2043 case INDEX_op_ld_i64
:
2044 tcg_out_ld_rel(s
, OPC_LD8_M1
, args
[0], args
[1], args
[2]);
2046 case INDEX_op_st8_i32
:
2047 case INDEX_op_st8_i64
:
2048 tcg_out_st_rel(s
, OPC_ST1_M4
, args
[0], args
[1], args
[2]);
2050 case INDEX_op_st16_i32
:
2051 case INDEX_op_st16_i64
:
2052 tcg_out_st_rel(s
, OPC_ST2_M4
, args
[0], args
[1], args
[2]);
2054 case INDEX_op_st_i32
:
2055 case INDEX_op_st32_i64
:
2056 tcg_out_st_rel(s
, OPC_ST4_M4
, args
[0], args
[1], args
[2]);
2058 case INDEX_op_st_i64
:
2059 tcg_out_st_rel(s
, OPC_ST8_M4
, args
[0], args
[1], args
[2]);
2062 case INDEX_op_add_i32
:
2063 case INDEX_op_add_i64
:
2064 tcg_out_alu(s
, OPC_ADD_A1
, args
[0], args
[1], const_args
[1],
2065 args
[2], const_args
[2]);
2067 case INDEX_op_sub_i32
:
2068 case INDEX_op_sub_i64
:
2069 tcg_out_alu(s
, OPC_SUB_A1
, args
[0], args
[1], const_args
[1],
2070 args
[2], const_args
[2]);
2073 case INDEX_op_and_i32
:
2074 case INDEX_op_and_i64
:
2075 tcg_out_alu(s
, OPC_AND_A1
, args
[0], args
[1], const_args
[1],
2076 args
[2], const_args
[2]);
2078 case INDEX_op_andc_i32
:
2079 case INDEX_op_andc_i64
:
2080 tcg_out_alu(s
, OPC_ANDCM_A1
, args
[0], args
[1], const_args
[1],
2081 args
[2], const_args
[2]);
2083 case INDEX_op_eqv_i32
:
2084 case INDEX_op_eqv_i64
:
2085 tcg_out_eqv(s
, args
[0], args
[1], const_args
[1],
2086 args
[2], const_args
[2]);
2088 case INDEX_op_nand_i32
:
2089 case INDEX_op_nand_i64
:
2090 tcg_out_nand(s
, args
[0], args
[1], const_args
[1],
2091 args
[2], const_args
[2]);
2093 case INDEX_op_nor_i32
:
2094 case INDEX_op_nor_i64
:
2095 tcg_out_nor(s
, args
[0], args
[1], const_args
[1],
2096 args
[2], const_args
[2]);
2098 case INDEX_op_or_i32
:
2099 case INDEX_op_or_i64
:
2100 tcg_out_alu(s
, OPC_OR_A1
, args
[0], args
[1], const_args
[1],
2101 args
[2], const_args
[2]);
2103 case INDEX_op_orc_i32
:
2104 case INDEX_op_orc_i64
:
2105 tcg_out_orc(s
, args
[0], args
[1], const_args
[1],
2106 args
[2], const_args
[2]);
2108 case INDEX_op_xor_i32
:
2109 case INDEX_op_xor_i64
:
2110 tcg_out_alu(s
, OPC_XOR_A1
, args
[0], args
[1], const_args
[1],
2111 args
[2], const_args
[2]);
2114 case INDEX_op_mul_i32
:
2115 case INDEX_op_mul_i64
:
2116 tcg_out_mul(s
, args
[0], args
[1], args
[2]);
2119 case INDEX_op_sar_i32
:
2120 tcg_out_sar_i32(s
, args
[0], args
[1], args
[2], const_args
[2]);
2122 case INDEX_op_sar_i64
:
2123 tcg_out_sar_i64(s
, args
[0], args
[1], args
[2], const_args
[2]);
2125 case INDEX_op_shl_i32
:
2126 tcg_out_shl_i32(s
, args
[0], args
[1], args
[2], const_args
[2]);
2128 case INDEX_op_shl_i64
:
2129 tcg_out_shl_i64(s
, args
[0], args
[1], args
[2], const_args
[2]);
2131 case INDEX_op_shr_i32
:
2132 tcg_out_shr_i32(s
, args
[0], args
[1], args
[2], const_args
[2]);
2134 case INDEX_op_shr_i64
:
2135 tcg_out_shr_i64(s
, args
[0], args
[1], args
[2], const_args
[2]);
2137 case INDEX_op_rotl_i32
:
2138 tcg_out_rotl_i32(s
, args
[0], args
[1], args
[2], const_args
[2]);
2140 case INDEX_op_rotl_i64
:
2141 tcg_out_rotl_i64(s
, args
[0], args
[1], args
[2], const_args
[2]);
2143 case INDEX_op_rotr_i32
:
2144 tcg_out_rotr_i32(s
, args
[0], args
[1], args
[2], const_args
[2]);
2146 case INDEX_op_rotr_i64
:
2147 tcg_out_rotr_i64(s
, args
[0], args
[1], args
[2], const_args
[2]);
2150 case INDEX_op_ext8s_i32
:
2151 case INDEX_op_ext8s_i64
:
2152 tcg_out_ext(s
, OPC_SXT1_I29
, args
[0], args
[1]);
2154 case INDEX_op_ext8u_i32
:
2155 case INDEX_op_ext8u_i64
:
2156 tcg_out_ext(s
, OPC_ZXT1_I29
, args
[0], args
[1]);
2158 case INDEX_op_ext16s_i32
:
2159 case INDEX_op_ext16s_i64
:
2160 tcg_out_ext(s
, OPC_SXT2_I29
, args
[0], args
[1]);
2162 case INDEX_op_ext16u_i32
:
2163 case INDEX_op_ext16u_i64
:
2164 tcg_out_ext(s
, OPC_ZXT2_I29
, args
[0], args
[1]);
2166 case INDEX_op_ext32s_i64
:
2167 tcg_out_ext(s
, OPC_SXT4_I29
, args
[0], args
[1]);
2169 case INDEX_op_ext32u_i64
:
2170 tcg_out_ext(s
, OPC_ZXT4_I29
, args
[0], args
[1]);
2173 case INDEX_op_bswap16_i32
:
2174 case INDEX_op_bswap16_i64
:
2175 tcg_out_bswap16(s
, args
[0], args
[1]);
2177 case INDEX_op_bswap32_i32
:
2178 case INDEX_op_bswap32_i64
:
2179 tcg_out_bswap32(s
, args
[0], args
[1]);
2181 case INDEX_op_bswap64_i64
:
2182 tcg_out_bswap64(s
, args
[0], args
[1]);
2185 case INDEX_op_deposit_i32
:
2186 case INDEX_op_deposit_i64
:
2187 tcg_out_deposit(s
, args
[0], args
[1], args
[2], const_args
[2],
2191 case INDEX_op_brcond_i32
:
2192 tcg_out_brcond(s
, args
[2], args
[0], const_args
[0],
2193 args
[1], const_args
[1], args
[3], 1);
2195 case INDEX_op_brcond_i64
:
2196 tcg_out_brcond(s
, args
[2], args
[0], const_args
[0],
2197 args
[1], const_args
[1], args
[3], 0);
2199 case INDEX_op_setcond_i32
:
2200 tcg_out_setcond(s
, args
[3], args
[0], args
[1], args
[2], 1);
2202 case INDEX_op_setcond_i64
:
2203 tcg_out_setcond(s
, args
[3], args
[0], args
[1], args
[2], 0);
2205 case INDEX_op_movcond_i32
:
2206 tcg_out_movcond(s
, args
[5], args
[0], args
[1], args
[2],
2207 args
[3], const_args
[3], args
[4], const_args
[4], 1);
2209 case INDEX_op_movcond_i64
:
2210 tcg_out_movcond(s
, args
[5], args
[0], args
[1], args
[2],
2211 args
[3], const_args
[3], args
[4], const_args
[4], 0);
2214 case INDEX_op_qemu_ld8u
:
2215 tcg_out_qemu_ld(s
, args
, MO_UB
);
2217 case INDEX_op_qemu_ld8s
:
2218 tcg_out_qemu_ld(s
, args
, MO_SB
);
2220 case INDEX_op_qemu_ld16u
:
2221 tcg_out_qemu_ld(s
, args
, MO_TEUW
);
2223 case INDEX_op_qemu_ld16s
:
2224 tcg_out_qemu_ld(s
, args
, MO_TESW
);
2226 case INDEX_op_qemu_ld32
:
2227 case INDEX_op_qemu_ld32u
:
2228 tcg_out_qemu_ld(s
, args
, MO_TEUL
);
2230 case INDEX_op_qemu_ld32s
:
2231 tcg_out_qemu_ld(s
, args
, MO_TESL
);
2233 case INDEX_op_qemu_ld64
:
2234 tcg_out_qemu_ld(s
, args
, MO_TEQ
);
2237 case INDEX_op_qemu_st8
:
2238 tcg_out_qemu_st(s
, args
, MO_UB
);
2240 case INDEX_op_qemu_st16
:
2241 tcg_out_qemu_st(s
, args
, MO_TEUW
);
2243 case INDEX_op_qemu_st32
:
2244 tcg_out_qemu_st(s
, args
, MO_TEUL
);
2246 case INDEX_op_qemu_st64
:
2247 tcg_out_qemu_st(s
, args
, MO_TEQ
);
2255 static const TCGTargetOpDef ia64_op_defs
[] = {
2256 { INDEX_op_br
, { } },
2257 { INDEX_op_call
, { "r" } },
2258 { INDEX_op_exit_tb
, { } },
2259 { INDEX_op_goto_tb
, { } },
2261 { INDEX_op_mov_i32
, { "r", "r" } },
2262 { INDEX_op_movi_i32
, { "r" } },
2264 { INDEX_op_ld8u_i32
, { "r", "r" } },
2265 { INDEX_op_ld8s_i32
, { "r", "r" } },
2266 { INDEX_op_ld16u_i32
, { "r", "r" } },
2267 { INDEX_op_ld16s_i32
, { "r", "r" } },
2268 { INDEX_op_ld_i32
, { "r", "r" } },
2269 { INDEX_op_st8_i32
, { "rZ", "r" } },
2270 { INDEX_op_st16_i32
, { "rZ", "r" } },
2271 { INDEX_op_st_i32
, { "rZ", "r" } },
2273 { INDEX_op_add_i32
, { "r", "rI", "rI" } },
2274 { INDEX_op_sub_i32
, { "r", "rI", "rI" } },
2276 { INDEX_op_and_i32
, { "r", "rI", "rI" } },
2277 { INDEX_op_andc_i32
, { "r", "rI", "rI" } },
2278 { INDEX_op_eqv_i32
, { "r", "rZ", "rZ" } },
2279 { INDEX_op_nand_i32
, { "r", "rZ", "rZ" } },
2280 { INDEX_op_nor_i32
, { "r", "rZ", "rZ" } },
2281 { INDEX_op_or_i32
, { "r", "rI", "rI" } },
2282 { INDEX_op_orc_i32
, { "r", "rZ", "rZ" } },
2283 { INDEX_op_xor_i32
, { "r", "rI", "rI" } },
2285 { INDEX_op_mul_i32
, { "r", "rZ", "rZ" } },
2287 { INDEX_op_sar_i32
, { "r", "rZ", "ri" } },
2288 { INDEX_op_shl_i32
, { "r", "rZ", "ri" } },
2289 { INDEX_op_shr_i32
, { "r", "rZ", "ri" } },
2290 { INDEX_op_rotl_i32
, { "r", "rZ", "ri" } },
2291 { INDEX_op_rotr_i32
, { "r", "rZ", "ri" } },
2293 { INDEX_op_ext8s_i32
, { "r", "rZ"} },
2294 { INDEX_op_ext8u_i32
, { "r", "rZ"} },
2295 { INDEX_op_ext16s_i32
, { "r", "rZ"} },
2296 { INDEX_op_ext16u_i32
, { "r", "rZ"} },
2298 { INDEX_op_bswap16_i32
, { "r", "rZ" } },
2299 { INDEX_op_bswap32_i32
, { "r", "rZ" } },
2301 { INDEX_op_brcond_i32
, { "rI", "rI" } },
2302 { INDEX_op_setcond_i32
, { "r", "rZ", "rZ" } },
2303 { INDEX_op_movcond_i32
, { "r", "rZ", "rZ", "rI", "rI" } },
2305 { INDEX_op_mov_i64
, { "r", "r" } },
2306 { INDEX_op_movi_i64
, { "r" } },
2308 { INDEX_op_ld8u_i64
, { "r", "r" } },
2309 { INDEX_op_ld8s_i64
, { "r", "r" } },
2310 { INDEX_op_ld16u_i64
, { "r", "r" } },
2311 { INDEX_op_ld16s_i64
, { "r", "r" } },
2312 { INDEX_op_ld32u_i64
, { "r", "r" } },
2313 { INDEX_op_ld32s_i64
, { "r", "r" } },
2314 { INDEX_op_ld_i64
, { "r", "r" } },
2315 { INDEX_op_st8_i64
, { "rZ", "r" } },
2316 { INDEX_op_st16_i64
, { "rZ", "r" } },
2317 { INDEX_op_st32_i64
, { "rZ", "r" } },
2318 { INDEX_op_st_i64
, { "rZ", "r" } },
2320 { INDEX_op_add_i64
, { "r", "rI", "rI" } },
2321 { INDEX_op_sub_i64
, { "r", "rI", "rI" } },
2323 { INDEX_op_and_i64
, { "r", "rI", "rI" } },
2324 { INDEX_op_andc_i64
, { "r", "rI", "rI" } },
2325 { INDEX_op_eqv_i64
, { "r", "rZ", "rZ" } },
2326 { INDEX_op_nand_i64
, { "r", "rZ", "rZ" } },
2327 { INDEX_op_nor_i64
, { "r", "rZ", "rZ" } },
2328 { INDEX_op_or_i64
, { "r", "rI", "rI" } },
2329 { INDEX_op_orc_i64
, { "r", "rZ", "rZ" } },
2330 { INDEX_op_xor_i64
, { "r", "rI", "rI" } },
2332 { INDEX_op_mul_i64
, { "r", "rZ", "rZ" } },
2334 { INDEX_op_sar_i64
, { "r", "rZ", "ri" } },
2335 { INDEX_op_shl_i64
, { "r", "rZ", "ri" } },
2336 { INDEX_op_shr_i64
, { "r", "rZ", "ri" } },
2337 { INDEX_op_rotl_i64
, { "r", "rZ", "ri" } },
2338 { INDEX_op_rotr_i64
, { "r", "rZ", "ri" } },
2340 { INDEX_op_ext8s_i64
, { "r", "rZ"} },
2341 { INDEX_op_ext8u_i64
, { "r", "rZ"} },
2342 { INDEX_op_ext16s_i64
, { "r", "rZ"} },
2343 { INDEX_op_ext16u_i64
, { "r", "rZ"} },
2344 { INDEX_op_ext32s_i64
, { "r", "rZ"} },
2345 { INDEX_op_ext32u_i64
, { "r", "rZ"} },
2347 { INDEX_op_bswap16_i64
, { "r", "rZ" } },
2348 { INDEX_op_bswap32_i64
, { "r", "rZ" } },
2349 { INDEX_op_bswap64_i64
, { "r", "rZ" } },
2351 { INDEX_op_brcond_i64
, { "rI", "rI" } },
2352 { INDEX_op_setcond_i64
, { "r", "rZ", "rZ" } },
2353 { INDEX_op_movcond_i64
, { "r", "rZ", "rZ", "rI", "rI" } },
2355 { INDEX_op_deposit_i32
, { "r", "rZ", "ri" } },
2356 { INDEX_op_deposit_i64
, { "r", "rZ", "ri" } },
2358 { INDEX_op_qemu_ld8u
, { "r", "r" } },
2359 { INDEX_op_qemu_ld8s
, { "r", "r" } },
2360 { INDEX_op_qemu_ld16u
, { "r", "r" } },
2361 { INDEX_op_qemu_ld16s
, { "r", "r" } },
2362 { INDEX_op_qemu_ld32
, { "r", "r" } },
2363 { INDEX_op_qemu_ld32u
, { "r", "r" } },
2364 { INDEX_op_qemu_ld32s
, { "r", "r" } },
2365 { INDEX_op_qemu_ld64
, { "r", "r" } },
2367 { INDEX_op_qemu_st8
, { "SZ", "r" } },
2368 { INDEX_op_qemu_st16
, { "SZ", "r" } },
2369 { INDEX_op_qemu_st32
, { "SZ", "r" } },
2370 { INDEX_op_qemu_st64
, { "SZ", "r" } },
2375 /* Generate global QEMU prologue and epilogue code */
2376 static void tcg_target_qemu_prologue(TCGContext
*s
)
2380 /* reserve some stack space */
2381 frame_size
= TCG_STATIC_CALL_ARGS_SIZE
+
2382 CPU_TEMP_BUF_NLONGS
* sizeof(long);
2383 frame_size
= (frame_size
+ TCG_TARGET_STACK_ALIGN
- 1) &
2384 ~(TCG_TARGET_STACK_ALIGN
- 1);
2385 tcg_set_frame(s
, TCG_REG_CALL_STACK
, TCG_STATIC_CALL_ARGS_SIZE
,
2386 CPU_TEMP_BUF_NLONGS
* sizeof(long));
2388 /* First emit adhoc function descriptor */
2389 *(uint64_t *)(s
->code_ptr
) = (uint64_t)s
->code_ptr
+ 16; /* entry point */
2390 s
->code_ptr
+= 16; /* skip GP */
2393 tcg_out_bundle(s
, miI
,
2394 tcg_opc_m34(TCG_REG_P0
, OPC_ALLOC_M34
,
2395 TCG_REG_R34
, 32, 24, 0),
2396 tcg_opc_a4 (TCG_REG_P0
, OPC_ADDS_A4
,
2397 TCG_AREG0
, 0, TCG_REG_R32
),
2398 tcg_opc_i21(TCG_REG_P0
, OPC_MOV_I21
,
2399 TCG_REG_B6
, TCG_REG_R33
, 0));
2401 /* ??? If GUEST_BASE < 0x200000, we could load the register via
2402 an ADDL in the M slot of the next bundle. */
2403 if (GUEST_BASE
!= 0) {
2404 tcg_out_bundle(s
, mlx
,
2405 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
2406 tcg_opc_l2 (GUEST_BASE
),
2407 tcg_opc_x2 (TCG_REG_P0
, OPC_MOVL_X2
,
2408 TCG_GUEST_BASE_REG
, GUEST_BASE
));
2409 tcg_regset_set_reg(s
->reserved_regs
, TCG_GUEST_BASE_REG
);
2412 tcg_out_bundle(s
, miB
,
2413 tcg_opc_a4 (TCG_REG_P0
, OPC_ADDS_A4
,
2414 TCG_REG_R12
, -frame_size
, TCG_REG_R12
),
2415 tcg_opc_i22(TCG_REG_P0
, OPC_MOV_I22
,
2416 TCG_REG_R32
, TCG_REG_B0
),
2417 tcg_opc_b4 (TCG_REG_P0
, OPC_BR_SPTK_MANY_B4
, TCG_REG_B6
));
2420 tb_ret_addr
= s
->code_ptr
;
2421 tcg_out_bundle(s
, miI
,
2422 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
2423 tcg_opc_i21(TCG_REG_P0
, OPC_MOV_I21
,
2424 TCG_REG_B0
, TCG_REG_R32
, 0),
2425 tcg_opc_a4 (TCG_REG_P0
, OPC_ADDS_A4
,
2426 TCG_REG_R12
, frame_size
, TCG_REG_R12
));
2427 tcg_out_bundle(s
, miB
,
2428 tcg_opc_m48(TCG_REG_P0
, OPC_NOP_M48
, 0),
2429 tcg_opc_i26(TCG_REG_P0
, OPC_MOV_I_I26
,
2430 TCG_REG_PFS
, TCG_REG_R34
),
2431 tcg_opc_b4 (TCG_REG_P0
, OPC_BR_RET_SPTK_MANY_B4
,
2435 static void tcg_target_init(TCGContext
*s
)
2437 tcg_regset_set(tcg_target_available_regs
[TCG_TYPE_I32
],
2438 0xffffffffffffffffull
);
2439 tcg_regset_set(tcg_target_available_regs
[TCG_TYPE_I64
],
2440 0xffffffffffffffffull
);
2442 tcg_regset_clear(tcg_target_call_clobber_regs
);
2443 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R8
);
2444 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R9
);
2445 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R10
);
2446 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R11
);
2447 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R14
);
2448 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R15
);
2449 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R16
);
2450 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R17
);
2451 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R18
);
2452 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R19
);
2453 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R20
);
2454 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R21
);
2455 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R22
);
2456 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R23
);
2457 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R24
);
2458 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R25
);
2459 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R26
);
2460 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R27
);
2461 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R28
);
2462 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R29
);
2463 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R30
);
2464 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R31
);
2465 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R56
);
2466 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R57
);
2467 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R58
);
2468 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R59
);
2469 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R60
);
2470 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R61
);
2471 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R62
);
2472 tcg_regset_set_reg(tcg_target_call_clobber_regs
, TCG_REG_R63
);
2474 tcg_regset_clear(s
->reserved_regs
);
2475 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R0
); /* zero register */
2476 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R1
); /* global pointer */
2477 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R2
); /* internal use */
2478 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R3
); /* internal use */
2479 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R12
); /* stack pointer */
2480 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R13
); /* thread pointer */
2481 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R32
); /* return address */
2482 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R34
); /* PFS */
2484 /* The following 3 are not in use, are call-saved, but *not* saved
2485 by the prologue. Therefore we cannot use them without modifying
2486 the prologue. There doesn't seem to be any good reason to use
2487 these as opposed to the windowed registers. */
2488 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R4
);
2489 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R5
);
2490 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_R6
);
2492 tcg_add_target_add_op_defs(ia64_op_defs
);