2 * Tiny Code Generator for QEMU
4 * Copyright (c) 2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #define TCG_CT_CONST_S16 0x100
26 #define TCG_CT_CONST_U16 0x200
27 #define TCG_CT_CONST_S32 0x400
28 #define TCG_CT_CONST_U32 0x800
29 #define TCG_CT_CONST_ZERO 0x1000
30 #define TCG_CT_CONST_MONE 0x2000
32 static uint8_t *tb_ret_addr
;
36 #if TARGET_LONG_BITS == 32
48 #ifdef CONFIG_GETAUXVAL
50 static bool have_isa_2_06
;
51 #define HAVE_ISA_2_06 have_isa_2_06
52 #define HAVE_ISEL have_isa_2_06
54 #define HAVE_ISA_2_06 0
58 #ifdef CONFIG_USE_GUEST_BASE
59 #define TCG_GUEST_BASE_REG 30
61 #define TCG_GUEST_BASE_REG 0
65 static const char * const tcg_target_reg_names
[TCG_TARGET_NB_REGS
] = {
101 static const int tcg_target_reg_alloc_order
[] = {
137 static const int tcg_target_call_iarg_regs
[] = {
148 static const int tcg_target_call_oarg_regs
[] = {
152 static const int tcg_target_callee_save_regs
[] = {
169 TCG_REG_R27
, /* currently used for the global env */
176 static uint32_t reloc_pc24_val (void *pc
, tcg_target_long target
)
178 tcg_target_long disp
;
180 disp
= target
- (tcg_target_long
) pc
;
181 if ((disp
<< 38) >> 38 != disp
)
184 return disp
& 0x3fffffc;
187 static void reloc_pc24 (void *pc
, tcg_target_long target
)
189 *(uint32_t *) pc
= (*(uint32_t *) pc
& ~0x3fffffc)
190 | reloc_pc24_val (pc
, target
);
193 static uint16_t reloc_pc14_val (void *pc
, tcg_target_long target
)
195 tcg_target_long disp
;
197 disp
= target
- (tcg_target_long
) pc
;
198 if (disp
!= (int16_t) disp
)
201 return disp
& 0xfffc;
204 static void reloc_pc14 (void *pc
, tcg_target_long target
)
206 *(uint32_t *) pc
= (*(uint32_t *) pc
& ~0xfffc)
207 | reloc_pc14_val (pc
, target
);
210 static void patch_reloc (uint8_t *code_ptr
, int type
,
211 intptr_t value
, intptr_t addend
)
216 reloc_pc14 (code_ptr
, value
);
219 reloc_pc24 (code_ptr
, value
);
226 /* parse target specific constraints */
227 static int target_parse_constraint (TCGArgConstraint
*ct
, const char **pct_str
)
233 case 'A': case 'B': case 'C': case 'D':
234 ct
->ct
|= TCG_CT_REG
;
235 tcg_regset_set_reg (ct
->u
.regs
, 3 + ct_str
[0] - 'A');
238 ct
->ct
|= TCG_CT_REG
;
239 tcg_regset_set32 (ct
->u
.regs
, 0, 0xffffffff);
241 case 'L': /* qemu_ld constraint */
242 ct
->ct
|= TCG_CT_REG
;
243 tcg_regset_set32 (ct
->u
.regs
, 0, 0xffffffff);
244 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R3
);
245 #ifdef CONFIG_SOFTMMU
246 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R4
);
247 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R5
);
250 case 'S': /* qemu_st constraint */
251 ct
->ct
|= TCG_CT_REG
;
252 tcg_regset_set32 (ct
->u
.regs
, 0, 0xffffffff);
253 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R3
);
254 #ifdef CONFIG_SOFTMMU
255 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R4
);
256 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R5
);
257 tcg_regset_reset_reg (ct
->u
.regs
, TCG_REG_R6
);
261 ct
->ct
|= TCG_CT_CONST_S16
;
264 ct
->ct
|= TCG_CT_CONST_U16
;
267 ct
->ct
|= TCG_CT_CONST_MONE
;
270 ct
->ct
|= TCG_CT_CONST_S32
;
273 ct
->ct
|= TCG_CT_CONST_U32
;
276 ct
->ct
|= TCG_CT_CONST_ZERO
;
286 /* test if a constant matches the constraint */
287 static int tcg_target_const_match (tcg_target_long val
,
288 const TCGArgConstraint
*arg_ct
)
291 if (ct
& TCG_CT_CONST
) {
293 } else if ((ct
& TCG_CT_CONST_S16
) && val
== (int16_t)val
) {
295 } else if ((ct
& TCG_CT_CONST_U16
) && val
== (uint16_t)val
) {
297 } else if ((ct
& TCG_CT_CONST_S32
) && val
== (int32_t)val
) {
299 } else if ((ct
& TCG_CT_CONST_U32
) && val
== (uint32_t)val
) {
301 } else if ((ct
& TCG_CT_CONST_ZERO
) && val
== 0) {
303 } else if ((ct
& TCG_CT_CONST_MONE
) && val
== -1) {
309 #define OPCD(opc) ((opc)<<26)
310 #define XO19(opc) (OPCD(19)|((opc)<<1))
311 #define MD30(opc) (OPCD(30)|((opc)<<2))
312 #define MDS30(opc) (OPCD(30)|((opc)<<1))
313 #define XO31(opc) (OPCD(31)|((opc)<<1))
314 #define XO58(opc) (OPCD(58)|(opc))
315 #define XO62(opc) (OPCD(62)|(opc))
319 #define LBZ OPCD( 34)
320 #define LHZ OPCD( 40)
321 #define LHA OPCD( 42)
322 #define LWZ OPCD( 32)
323 #define STB OPCD( 38)
324 #define STH OPCD( 44)
325 #define STW OPCD( 36)
328 #define STDU XO62( 1)
329 #define STDX XO31(149)
332 #define LDX XO31( 21)
335 #define LWAX XO31(341)
337 #define ADDIC OPCD( 12)
338 #define ADDI OPCD( 14)
339 #define ADDIS OPCD( 15)
340 #define ORI OPCD( 24)
341 #define ORIS OPCD( 25)
342 #define XORI OPCD( 26)
343 #define XORIS OPCD( 27)
344 #define ANDI OPCD( 28)
345 #define ANDIS OPCD( 29)
346 #define MULLI OPCD( 7)
347 #define CMPLI OPCD( 10)
348 #define CMPI OPCD( 11)
349 #define SUBFIC OPCD( 8)
351 #define LWZU OPCD( 33)
352 #define STWU OPCD( 37)
354 #define RLWIMI OPCD( 20)
355 #define RLWINM OPCD( 21)
356 #define RLWNM OPCD( 23)
358 #define RLDICL MD30( 0)
359 #define RLDICR MD30( 1)
360 #define RLDIMI MD30( 3)
361 #define RLDCL MDS30( 8)
363 #define BCLR XO19( 16)
364 #define BCCTR XO19(528)
365 #define CRAND XO19(257)
366 #define CRANDC XO19(129)
367 #define CRNAND XO19(225)
368 #define CROR XO19(449)
369 #define CRNOR XO19( 33)
371 #define EXTSB XO31(954)
372 #define EXTSH XO31(922)
373 #define EXTSW XO31(986)
374 #define ADD XO31(266)
375 #define ADDE XO31(138)
376 #define ADDME XO31(234)
377 #define ADDZE XO31(202)
378 #define ADDC XO31( 10)
379 #define AND XO31( 28)
380 #define SUBF XO31( 40)
381 #define SUBFC XO31( 8)
382 #define SUBFE XO31(136)
383 #define SUBFME XO31(232)
384 #define SUBFZE XO31(200)
386 #define XOR XO31(316)
387 #define MULLW XO31(235)
388 #define MULHWU XO31( 11)
389 #define DIVW XO31(491)
390 #define DIVWU XO31(459)
392 #define CMPL XO31( 32)
393 #define LHBRX XO31(790)
394 #define LWBRX XO31(534)
395 #define LDBRX XO31(532)
396 #define STHBRX XO31(918)
397 #define STWBRX XO31(662)
398 #define STDBRX XO31(660)
399 #define MFSPR XO31(339)
400 #define MTSPR XO31(467)
401 #define SRAWI XO31(824)
402 #define NEG XO31(104)
403 #define MFCR XO31( 19)
404 #define MFOCRF (MFCR | (1u << 20))
405 #define NOR XO31(124)
406 #define CNTLZW XO31( 26)
407 #define CNTLZD XO31( 58)
408 #define ANDC XO31( 60)
409 #define ORC XO31(412)
410 #define EQV XO31(284)
411 #define NAND XO31(476)
412 #define ISEL XO31( 15)
414 #define MULLD XO31(233)
415 #define MULHD XO31( 73)
416 #define MULHDU XO31( 9)
417 #define DIVD XO31(489)
418 #define DIVDU XO31(457)
420 #define LBZX XO31( 87)
421 #define LHZX XO31(279)
422 #define LHAX XO31(343)
423 #define LWZX XO31( 23)
424 #define STBX XO31(215)
425 #define STHX XO31(407)
426 #define STWX XO31(151)
428 #define SPR(a,b) ((((a)<<5)|(b))<<11)
430 #define CTR SPR(9, 0)
432 #define SLW XO31( 24)
433 #define SRW XO31(536)
434 #define SRAW XO31(792)
436 #define SLD XO31( 27)
437 #define SRD XO31(539)
438 #define SRAD XO31(794)
439 #define SRADI XO31(413<<1)
442 #define TRAP (TW | TO (31))
444 #define RT(r) ((r)<<21)
445 #define RS(r) ((r)<<21)
446 #define RA(r) ((r)<<16)
447 #define RB(r) ((r)<<11)
448 #define TO(t) ((t)<<21)
449 #define SH(s) ((s)<<11)
450 #define MB(b) ((b)<<6)
451 #define ME(e) ((e)<<1)
452 #define BO(o) ((o)<<21)
453 #define MB64(b) ((b)<<5)
454 #define FXM(b) (1 << (19 - (b)))
458 #define TAB(t, a, b) (RT(t) | RA(a) | RB(b))
459 #define SAB(s, a, b) (RS(s) | RA(a) | RB(b))
460 #define TAI(s, a, i) (RT(s) | RA(a) | ((i) & 0xffff))
461 #define SAI(s, a, i) (RS(s) | RA(a) | ((i) & 0xffff))
463 #define BF(n) ((n)<<23)
464 #define BI(n, c) (((c)+((n)*4))<<16)
465 #define BT(n, c) (((c)+((n)*4))<<21)
466 #define BA(n, c) (((c)+((n)*4))<<16)
467 #define BB(n, c) (((c)+((n)*4))<<11)
468 #define BC_(n, c) (((c)+((n)*4))<<6)
470 #define BO_COND_TRUE BO (12)
471 #define BO_COND_FALSE BO ( 4)
472 #define BO_ALWAYS BO (20)
481 static const uint32_t tcg_to_bc
[] = {
482 [TCG_COND_EQ
] = BC
| BI (7, CR_EQ
) | BO_COND_TRUE
,
483 [TCG_COND_NE
] = BC
| BI (7, CR_EQ
) | BO_COND_FALSE
,
484 [TCG_COND_LT
] = BC
| BI (7, CR_LT
) | BO_COND_TRUE
,
485 [TCG_COND_GE
] = BC
| BI (7, CR_LT
) | BO_COND_FALSE
,
486 [TCG_COND_LE
] = BC
| BI (7, CR_GT
) | BO_COND_FALSE
,
487 [TCG_COND_GT
] = BC
| BI (7, CR_GT
) | BO_COND_TRUE
,
488 [TCG_COND_LTU
] = BC
| BI (7, CR_LT
) | BO_COND_TRUE
,
489 [TCG_COND_GEU
] = BC
| BI (7, CR_LT
) | BO_COND_FALSE
,
490 [TCG_COND_LEU
] = BC
| BI (7, CR_GT
) | BO_COND_FALSE
,
491 [TCG_COND_GTU
] = BC
| BI (7, CR_GT
) | BO_COND_TRUE
,
494 /* The low bit here is set if the RA and RB fields must be inverted. */
495 static const uint32_t tcg_to_isel
[] = {
496 [TCG_COND_EQ
] = ISEL
| BC_(7, CR_EQ
),
497 [TCG_COND_NE
] = ISEL
| BC_(7, CR_EQ
) | 1,
498 [TCG_COND_LT
] = ISEL
| BC_(7, CR_LT
),
499 [TCG_COND_GE
] = ISEL
| BC_(7, CR_LT
) | 1,
500 [TCG_COND_LE
] = ISEL
| BC_(7, CR_GT
) | 1,
501 [TCG_COND_GT
] = ISEL
| BC_(7, CR_GT
),
502 [TCG_COND_LTU
] = ISEL
| BC_(7, CR_LT
),
503 [TCG_COND_GEU
] = ISEL
| BC_(7, CR_LT
) | 1,
504 [TCG_COND_LEU
] = ISEL
| BC_(7, CR_GT
) | 1,
505 [TCG_COND_GTU
] = ISEL
| BC_(7, CR_GT
),
508 static inline void tcg_out_mov(TCGContext
*s
, TCGType type
,
509 TCGReg ret
, TCGReg arg
)
511 tcg_out32 (s
, OR
| SAB (arg
, ret
, arg
));
514 static inline void tcg_out_rld(TCGContext
*s
, int op
, TCGReg ra
, TCGReg rs
,
517 sh
= SH (sh
& 0x1f) | (((sh
>> 5) & 1) << 1);
518 mb
= MB64 ((mb
>> 5) | ((mb
<< 1) & 0x3f));
519 tcg_out32 (s
, op
| RA (ra
) | RS (rs
) | sh
| mb
);
522 static inline void tcg_out_rlw(TCGContext
*s
, int op
, TCGReg ra
, TCGReg rs
,
523 int sh
, int mb
, int me
)
525 tcg_out32(s
, op
| RA(ra
) | RS(rs
) | SH(sh
) | MB(mb
) | ME(me
));
528 static inline void tcg_out_ext32u(TCGContext
*s
, TCGReg dst
, TCGReg src
)
530 tcg_out_rld(s
, RLDICL
, dst
, src
, 0, 32);
533 static inline void tcg_out_shli64(TCGContext
*s
, TCGReg dst
, TCGReg src
, int c
)
535 tcg_out_rld(s
, RLDICR
, dst
, src
, c
, 63 - c
);
538 static inline void tcg_out_shri64(TCGContext
*s
, TCGReg dst
, TCGReg src
, int c
)
540 tcg_out_rld(s
, RLDICL
, dst
, src
, 64 - c
, c
);
543 static void tcg_out_movi32(TCGContext
*s
, TCGReg ret
, int32_t arg
)
545 if (arg
== (int16_t) arg
) {
546 tcg_out32(s
, ADDI
| TAI(ret
, 0, arg
));
548 tcg_out32(s
, ADDIS
| TAI(ret
, 0, arg
>> 16));
550 tcg_out32(s
, ORI
| SAI(ret
, ret
, arg
));
555 static void tcg_out_movi(TCGContext
*s
, TCGType type
, TCGReg ret
,
558 if (type
== TCG_TYPE_I32
|| arg
== (int32_t)arg
) {
559 tcg_out_movi32(s
, ret
, arg
);
560 } else if (arg
== (uint32_t)arg
&& !(arg
& 0x8000)) {
561 tcg_out32(s
, ADDI
| TAI(ret
, 0, arg
));
562 tcg_out32(s
, ORIS
| SAI(ret
, ret
, arg
>> 16));
564 int32_t high
= arg
>> 32;
565 tcg_out_movi32(s
, ret
, high
);
567 tcg_out_shli64(s
, ret
, ret
, 32);
569 if (arg
& 0xffff0000) {
570 tcg_out32(s
, ORIS
| SAI(ret
, ret
, arg
>> 16));
573 tcg_out32(s
, ORI
| SAI(ret
, ret
, arg
));
578 static bool mask_operand(uint32_t c
, int *mb
, int *me
)
582 /* Accept a bit pattern like:
586 Keep track of the transitions. */
587 if (c
== 0 || c
== -1) {
593 if (test
& (test
- 1)) {
598 *mb
= test
? clz32(test
& -test
) + 1 : 0;
602 static bool mask64_operand(uint64_t c
, int *mb
, int *me
)
611 /* Accept 1..10..0. */
617 /* Accept 0..01..1. */
618 if (lsb
== 1 && (c
& (c
+ 1)) == 0) {
619 *mb
= clz64(c
+ 1) + 1;
626 static void tcg_out_andi32(TCGContext
*s
, TCGReg dst
, TCGReg src
, uint32_t c
)
630 if ((c
& 0xffff) == c
) {
631 tcg_out32(s
, ANDI
| SAI(src
, dst
, c
));
633 } else if ((c
& 0xffff0000) == c
) {
634 tcg_out32(s
, ANDIS
| SAI(src
, dst
, c
>> 16));
636 } else if (mask_operand(c
, &mb
, &me
)) {
637 tcg_out_rlw(s
, RLWINM
, dst
, src
, 0, mb
, me
);
639 tcg_out_movi(s
, TCG_TYPE_I32
, 0, c
);
640 tcg_out32(s
, AND
| SAB(src
, dst
, 0));
644 static void tcg_out_andi64(TCGContext
*s
, TCGReg dst
, TCGReg src
, uint64_t c
)
648 if ((c
& 0xffff) == c
) {
649 tcg_out32(s
, ANDI
| SAI(src
, dst
, c
));
651 } else if ((c
& 0xffff0000) == c
) {
652 tcg_out32(s
, ANDIS
| SAI(src
, dst
, c
>> 16));
654 } else if (mask64_operand(c
, &mb
, &me
)) {
656 tcg_out_rld(s
, RLDICR
, dst
, src
, 0, me
);
658 tcg_out_rld(s
, RLDICL
, dst
, src
, 0, mb
);
661 tcg_out_movi(s
, TCG_TYPE_I64
, 0, c
);
662 tcg_out32(s
, AND
| SAB(src
, dst
, 0));
666 static void tcg_out_zori32(TCGContext
*s
, TCGReg dst
, TCGReg src
, uint32_t c
,
667 int op_lo
, int op_hi
)
670 tcg_out32(s
, op_hi
| SAI(src
, dst
, c
>> 16));
674 tcg_out32(s
, op_lo
| SAI(src
, dst
, c
));
679 static void tcg_out_ori32(TCGContext
*s
, TCGReg dst
, TCGReg src
, uint32_t c
)
681 tcg_out_zori32(s
, dst
, src
, c
, ORI
, ORIS
);
684 static void tcg_out_xori32(TCGContext
*s
, TCGReg dst
, TCGReg src
, uint32_t c
)
686 tcg_out_zori32(s
, dst
, src
, c
, XORI
, XORIS
);
689 static void tcg_out_b (TCGContext
*s
, int mask
, tcg_target_long target
)
691 tcg_target_long disp
;
693 disp
= target
- (tcg_target_long
) s
->code_ptr
;
694 if ((disp
<< 38) >> 38 == disp
)
695 tcg_out32 (s
, B
| (disp
& 0x3fffffc) | mask
);
697 tcg_out_movi (s
, TCG_TYPE_I64
, 0, (tcg_target_long
) target
);
698 tcg_out32 (s
, MTSPR
| RS (0) | CTR
);
699 tcg_out32 (s
, BCCTR
| BO_ALWAYS
| mask
);
703 static void tcg_out_call (TCGContext
*s
, tcg_target_long arg
, int const_arg
)
707 tcg_out_b (s
, LK
, arg
);
710 tcg_out32 (s
, MTSPR
| RS (arg
) | LR
);
711 tcg_out32 (s
, BCLR
| BO_ALWAYS
| LK
);
718 tcg_out_movi (s
, TCG_TYPE_I64
, reg
, arg
);
722 tcg_out32 (s
, LD
| RT (0) | RA (reg
));
723 tcg_out32 (s
, MTSPR
| RA (0) | CTR
);
724 tcg_out32 (s
, LD
| RT (11) | RA (reg
) | 16);
725 tcg_out32 (s
, LD
| RT (2) | RA (reg
) | 8);
726 tcg_out32 (s
, BCCTR
| BO_ALWAYS
| LK
);
730 static void tcg_out_ldst(TCGContext
*s
, TCGReg ret
, TCGReg addr
,
731 int offset
, int op1
, int op2
)
733 if (offset
== (int16_t) offset
) {
734 tcg_out32(s
, op1
| TAI(ret
, addr
, offset
));
736 tcg_out_movi(s
, TCG_TYPE_I64
, 0, offset
);
737 tcg_out32(s
, op2
| TAB(ret
, addr
, 0));
741 static void tcg_out_ldsta(TCGContext
*s
, TCGReg ret
, TCGReg addr
,
742 int offset
, int op1
, int op2
)
744 if (offset
== (int16_t) (offset
& ~3)) {
745 tcg_out32(s
, op1
| TAI(ret
, addr
, offset
));
747 tcg_out_movi(s
, TCG_TYPE_I64
, 0, offset
);
748 tcg_out32(s
, op2
| TAB(ret
, addr
, 0));
752 #if defined (CONFIG_SOFTMMU)
753 /* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr,
755 static const void * const qemu_ld_helpers
[4] = {
762 /* helper signature: helper_st_mmu(CPUState *env, target_ulong addr,
763 uintxx_t val, int mmu_idx) */
764 static const void * const qemu_st_helpers
[4] = {
771 static void tcg_out_tlb_read(TCGContext
*s
, TCGReg r0
, TCGReg r1
, TCGReg r2
,
772 TCGReg addr_reg
, int s_bits
, int offset
)
774 #if TARGET_LONG_BITS == 32
775 tcg_out_ext32u(s
, addr_reg
, addr_reg
);
777 tcg_out_rlw(s
, RLWINM
, r0
, addr_reg
,
778 32 - (TARGET_PAGE_BITS
- CPU_TLB_ENTRY_BITS
),
779 32 - (CPU_TLB_BITS
+ CPU_TLB_ENTRY_BITS
),
780 31 - CPU_TLB_ENTRY_BITS
);
781 tcg_out32(s
, ADD
| TAB(r0
, r0
, TCG_AREG0
));
782 tcg_out32(s
, LWZU
| TAI(r1
, r0
, offset
));
783 tcg_out_rlw(s
, RLWINM
, r2
, addr_reg
, 0,
784 (32 - s_bits
) & 31, 31 - TARGET_PAGE_BITS
);
786 tcg_out_rld (s
, RLDICL
, r0
, addr_reg
,
787 64 - TARGET_PAGE_BITS
,
789 tcg_out_shli64(s
, r0
, r0
, CPU_TLB_ENTRY_BITS
);
791 tcg_out32(s
, ADD
| TAB(r0
, r0
, TCG_AREG0
));
792 tcg_out32(s
, LD_ADDR
| TAI(r1
, r0
, offset
));
795 tcg_out_rld (s
, RLDICR
, r2
, addr_reg
, 0, 63 - TARGET_PAGE_BITS
);
798 tcg_out_rld (s
, RLDICL
, r2
, addr_reg
,
799 64 - TARGET_PAGE_BITS
,
800 TARGET_PAGE_BITS
- s_bits
);
801 tcg_out_rld (s
, RLDICL
, r2
, r2
, TARGET_PAGE_BITS
, 0);
807 static const uint32_t qemu_ldx_opc
[8] = {
808 #ifdef TARGET_WORDS_BIGENDIAN
809 LBZX
, LHZX
, LWZX
, LDX
,
812 LBZX
, LHBRX
, LWBRX
, LDBRX
,
817 static const uint32_t qemu_stx_opc
[4] = {
818 #ifdef TARGET_WORDS_BIGENDIAN
819 STBX
, STHX
, STWX
, STDX
821 STBX
, STHBRX
, STWBRX
, STDBRX
,
825 static const uint32_t qemu_exts_opc
[4] = {
826 EXTSB
, EXTSH
, EXTSW
, 0
829 static void tcg_out_qemu_ld (TCGContext
*s
, const TCGArg
*args
, int opc
)
831 TCGReg addr_reg
, data_reg
, r0
, r1
, rbase
;
832 uint32_t insn
, s_bits
;
833 #ifdef CONFIG_SOFTMMU
836 void *label1_ptr
, *label2_ptr
;
843 #ifdef CONFIG_SOFTMMU
851 tcg_out_tlb_read (s
, r0
, r1
, r2
, addr_reg
, s_bits
,
852 offsetof (CPUArchState
, tlb_table
[mem_index
][0].addr_read
));
854 tcg_out32 (s
, CMP
| BF (7) | RA (r2
) | RB (r1
) | CMP_L
);
856 label1_ptr
= s
->code_ptr
;
858 tcg_out32 (s
, BC
| BI (7, CR_EQ
) | BO_COND_TRUE
);
863 tcg_out_mov (s
, TCG_TYPE_I64
, ir
++, TCG_AREG0
);
864 tcg_out_mov (s
, TCG_TYPE_I64
, ir
++, addr_reg
);
865 tcg_out_movi (s
, TCG_TYPE_I64
, ir
++, mem_index
);
867 tcg_out_call (s
, (tcg_target_long
) qemu_ld_helpers
[s_bits
], 1);
870 insn
= qemu_exts_opc
[s_bits
];
871 tcg_out32(s
, insn
| RA(data_reg
) | RS(3));
872 } else if (data_reg
!= 3) {
873 tcg_out_mov(s
, TCG_TYPE_I64
, data_reg
, 3);
875 label2_ptr
= s
->code_ptr
;
878 /* label1: fast path */
880 reloc_pc14 (label1_ptr
, (tcg_target_long
) s
->code_ptr
);
883 /* r0 now contains &env->tlb_table[mem_index][index].addr_read */
884 tcg_out32(s
, LD
| TAI(r0
, r0
,
885 offsetof(CPUTLBEntry
, addend
)
886 - offsetof(CPUTLBEntry
, addr_read
)));
887 /* r0 = env->tlb_table[mem_index][index].addend */
888 tcg_out32(s
, ADD
| TAB(r0
, r0
, addr_reg
));
889 /* r0 = env->tlb_table[mem_index][index].addend + addr */
891 #else /* !CONFIG_SOFTMMU */
892 #if TARGET_LONG_BITS == 32
893 tcg_out_ext32u(s
, addr_reg
, addr_reg
);
897 rbase
= GUEST_BASE
? TCG_GUEST_BASE_REG
: 0;
900 insn
= qemu_ldx_opc
[opc
];
901 if (!HAVE_ISA_2_06
&& insn
== LDBRX
) {
902 tcg_out32(s
, ADDI
| TAI(r1
, r0
, 4));
903 tcg_out32(s
, LWBRX
| TAB(data_reg
, rbase
, r0
));
904 tcg_out32(s
, LWBRX
| TAB( r1
, rbase
, r1
));
905 tcg_out_rld(s
, RLDIMI
, data_reg
, r1
, 32, 0);
907 tcg_out32(s
, insn
| TAB(data_reg
, rbase
, r0
));
909 insn
= qemu_ldx_opc
[s_bits
];
910 tcg_out32(s
, insn
| TAB(data_reg
, rbase
, r0
));
911 insn
= qemu_exts_opc
[s_bits
];
912 tcg_out32 (s
, insn
| RA(data_reg
) | RS(data_reg
));
915 #ifdef CONFIG_SOFTMMU
916 reloc_pc24 (label2_ptr
, (tcg_target_long
) s
->code_ptr
);
920 static void tcg_out_qemu_st (TCGContext
*s
, const TCGArg
*args
, int opc
)
922 TCGReg addr_reg
, r0
, r1
, rbase
, data_reg
;
924 #ifdef CONFIG_SOFTMMU
927 void *label1_ptr
, *label2_ptr
;
933 #ifdef CONFIG_SOFTMMU
941 tcg_out_tlb_read (s
, r0
, r1
, r2
, addr_reg
, opc
,
942 offsetof (CPUArchState
, tlb_table
[mem_index
][0].addr_write
));
944 tcg_out32 (s
, CMP
| BF (7) | RA (r2
) | RB (r1
) | CMP_L
);
946 label1_ptr
= s
->code_ptr
;
948 tcg_out32 (s
, BC
| BI (7, CR_EQ
) | BO_COND_TRUE
);
953 tcg_out_mov (s
, TCG_TYPE_I64
, ir
++, TCG_AREG0
);
954 tcg_out_mov (s
, TCG_TYPE_I64
, ir
++, addr_reg
);
955 tcg_out_rld (s
, RLDICL
, ir
++, data_reg
, 0, 64 - (1 << (3 + opc
)));
956 tcg_out_movi (s
, TCG_TYPE_I64
, ir
++, mem_index
);
958 tcg_out_call (s
, (tcg_target_long
) qemu_st_helpers
[opc
], 1);
960 label2_ptr
= s
->code_ptr
;
963 /* label1: fast path */
965 reloc_pc14 (label1_ptr
, (tcg_target_long
) s
->code_ptr
);
971 | (offsetof (CPUTLBEntry
, addend
)
972 - offsetof (CPUTLBEntry
, addr_write
))
974 /* r0 = env->tlb_table[mem_index][index].addend */
975 tcg_out32(s
, ADD
| TAB(r0
, r0
, addr_reg
));
976 /* r0 = env->tlb_table[mem_index][index].addend + addr */
978 #else /* !CONFIG_SOFTMMU */
979 #if TARGET_LONG_BITS == 32
980 tcg_out_ext32u(s
, addr_reg
, addr_reg
);
984 rbase
= GUEST_BASE
? TCG_GUEST_BASE_REG
: 0;
987 insn
= qemu_stx_opc
[opc
];
988 if (!HAVE_ISA_2_06
&& insn
== STDBRX
) {
989 tcg_out32(s
, STWBRX
| SAB(data_reg
, rbase
, r0
));
990 tcg_out32(s
, ADDI
| TAI(r1
, r0
, 4));
991 tcg_out_shri64(s
, 0, data_reg
, 32);
992 tcg_out32(s
, STWBRX
| SAB(0, rbase
, r1
));
994 tcg_out32(s
, insn
| SAB(data_reg
, rbase
, r0
));
997 #ifdef CONFIG_SOFTMMU
998 reloc_pc24 (label2_ptr
, (tcg_target_long
) s
->code_ptr
);
1002 static void tcg_target_qemu_prologue (TCGContext
*s
)
1010 + 8 /* back chain */
1013 + 8 /* compiler doubleword */
1014 + 8 /* link editor doubleword */
1015 + 8 /* TOC save area */
1016 + TCG_STATIC_CALL_ARGS_SIZE
1017 + ARRAY_SIZE (tcg_target_callee_save_regs
) * 8
1018 + CPU_TEMP_BUF_NLONGS
* sizeof(long)
1020 frame_size
= (frame_size
+ 15) & ~15;
1022 tcg_set_frame (s
, TCG_REG_CALL_STACK
, frame_size
1023 - CPU_TEMP_BUF_NLONGS
* sizeof (long),
1024 CPU_TEMP_BUF_NLONGS
* sizeof (long));
1027 /* First emit adhoc function descriptor */
1028 addr
= (uint64_t) s
->code_ptr
+ 24;
1029 tcg_out32 (s
, addr
>> 32); tcg_out32 (s
, addr
); /* entry point */
1030 s
->code_ptr
+= 16; /* skip TOC and environment pointer */
1034 tcg_out32 (s
, MFSPR
| RT (0) | LR
);
1035 tcg_out32 (s
, STDU
| RS (1) | RA (1) | (-frame_size
& 0xffff));
1036 for (i
= 0; i
< ARRAY_SIZE (tcg_target_callee_save_regs
); ++i
)
1038 | RS (tcg_target_callee_save_regs
[i
])
1040 | (i
* 8 + 48 + TCG_STATIC_CALL_ARGS_SIZE
)
1043 tcg_out32 (s
, STD
| RS (0) | RA (1) | (frame_size
+ 16));
1045 #ifdef CONFIG_USE_GUEST_BASE
1047 tcg_out_movi (s
, TCG_TYPE_I64
, TCG_GUEST_BASE_REG
, GUEST_BASE
);
1048 tcg_regset_set_reg (s
->reserved_regs
, TCG_GUEST_BASE_REG
);
1052 tcg_out_mov (s
, TCG_TYPE_PTR
, TCG_AREG0
, tcg_target_call_iarg_regs
[0]);
1053 tcg_out32 (s
, MTSPR
| RS (tcg_target_call_iarg_regs
[1]) | CTR
);
1054 tcg_out32 (s
, BCCTR
| BO_ALWAYS
);
1057 tb_ret_addr
= s
->code_ptr
;
1059 for (i
= 0; i
< ARRAY_SIZE (tcg_target_callee_save_regs
); ++i
)
1061 | RT (tcg_target_callee_save_regs
[i
])
1063 | (i
* 8 + 48 + TCG_STATIC_CALL_ARGS_SIZE
)
1066 tcg_out32(s
, LD
| TAI(0, 1, frame_size
+ 16));
1067 tcg_out32(s
, MTSPR
| RS(0) | LR
);
1068 tcg_out32(s
, ADDI
| TAI(1, 1, frame_size
));
1069 tcg_out32(s
, BCLR
| BO_ALWAYS
);
1072 static void tcg_out_ld(TCGContext
*s
, TCGType type
, TCGReg ret
, TCGReg arg1
,
1075 if (type
== TCG_TYPE_I32
)
1076 tcg_out_ldst (s
, ret
, arg1
, arg2
, LWZ
, LWZX
);
1078 tcg_out_ldsta (s
, ret
, arg1
, arg2
, LD
, LDX
);
1081 static void tcg_out_st(TCGContext
*s
, TCGType type
, TCGReg arg
, TCGReg arg1
,
1084 if (type
== TCG_TYPE_I32
)
1085 tcg_out_ldst (s
, arg
, arg1
, arg2
, STW
, STWX
);
1087 tcg_out_ldsta (s
, arg
, arg1
, arg2
, STD
, STDX
);
1090 static void tcg_out_cmp(TCGContext
*s
, int cond
, TCGArg arg1
, TCGArg arg2
,
1091 int const_arg2
, int cr
, TCGType type
)
1096 /* Simplify the comparisons below wrt CMPI. */
1097 if (type
== TCG_TYPE_I32
) {
1098 arg2
= (int32_t)arg2
;
1105 if ((int16_t) arg2
== arg2
) {
1110 else if ((uint16_t) arg2
== arg2
) {
1125 if ((int16_t) arg2
== arg2
) {
1140 if ((uint16_t) arg2
== arg2
) {
1153 op
|= BF(cr
) | ((type
== TCG_TYPE_I64
) << 21);
1156 tcg_out32(s
, op
| RA(arg1
) | (arg2
& 0xffff));
1159 tcg_out_movi(s
, type
, 0, arg2
);
1162 tcg_out32(s
, op
| RA(arg1
) | RB(arg2
));
1166 static void tcg_out_setcond_eq0(TCGContext
*s
, TCGType type
,
1167 TCGReg dst
, TCGReg src
)
1169 tcg_out32(s
, (type
== TCG_TYPE_I64
? CNTLZD
: CNTLZW
) | RS(src
) | RA(dst
));
1170 tcg_out_shri64(s
, dst
, dst
, type
== TCG_TYPE_I64
? 6 : 5);
1173 static void tcg_out_setcond_ne0(TCGContext
*s
, TCGReg dst
, TCGReg src
)
1175 /* X != 0 implies X + -1 generates a carry. Extra addition
1176 trickery means: R = X-1 + ~X + C = X-1 + (-X+1) + C = C. */
1178 tcg_out32(s
, ADDIC
| TAI(dst
, src
, -1));
1179 tcg_out32(s
, SUBFE
| TAB(dst
, dst
, src
));
1181 tcg_out32(s
, ADDIC
| TAI(0, src
, -1));
1182 tcg_out32(s
, SUBFE
| TAB(dst
, 0, src
));
1186 static TCGReg
tcg_gen_setcond_xor(TCGContext
*s
, TCGReg arg1
, TCGArg arg2
,
1190 if ((uint32_t)arg2
== arg2
) {
1191 tcg_out_xori32(s
, TCG_REG_R0
, arg1
, arg2
);
1193 tcg_out_movi(s
, TCG_TYPE_I64
, TCG_REG_R0
, arg2
);
1194 tcg_out32(s
, XOR
| SAB(arg1
, TCG_REG_R0
, TCG_REG_R0
));
1197 tcg_out32(s
, XOR
| SAB(arg1
, TCG_REG_R0
, arg2
));
1202 static void tcg_out_setcond(TCGContext
*s
, TCGType type
, TCGCond cond
,
1203 TCGArg arg0
, TCGArg arg1
, TCGArg arg2
,
1208 /* Ignore high bits of a potential constant arg2. */
1209 if (type
== TCG_TYPE_I32
) {
1210 arg2
= (uint32_t)arg2
;
1213 /* Handle common and trivial cases before handling anything else. */
1217 tcg_out_setcond_eq0(s
, type
, arg0
, arg1
);
1220 if (type
== TCG_TYPE_I32
) {
1221 tcg_out_ext32u(s
, TCG_REG_R0
, arg1
);
1224 tcg_out_setcond_ne0(s
, arg0
, arg1
);
1227 tcg_out32(s
, NOR
| SAB(arg1
, arg0
, arg1
));
1231 /* Extract the sign bit. */
1232 tcg_out_rld(s
, RLDICL
, arg0
, arg1
,
1233 type
== TCG_TYPE_I64
? 1 : 33, 63);
1240 /* If we have ISEL, we can implement everything with 3 or 4 insns.
1241 All other cases below are also at least 3 insns, so speed up the
1242 code generator by not considering them and always using ISEL. */
1246 tcg_out_cmp(s
, cond
, arg1
, arg2
, const_arg2
, 7, type
);
1248 isel
= tcg_to_isel
[cond
];
1250 tcg_out_movi(s
, type
, arg0
, 1);
1252 /* arg0 = (bc ? 0 : 1) */
1253 tab
= TAB(arg0
, 0, arg0
);
1256 /* arg0 = (bc ? 1 : 0) */
1257 tcg_out_movi(s
, type
, TCG_REG_R0
, 0);
1258 tab
= TAB(arg0
, arg0
, TCG_REG_R0
);
1260 tcg_out32(s
, isel
| tab
);
1266 arg1
= tcg_gen_setcond_xor(s
, arg1
, arg2
, const_arg2
);
1267 tcg_out_setcond_eq0(s
, type
, arg0
, arg1
);
1271 arg1
= tcg_gen_setcond_xor(s
, arg1
, arg2
, const_arg2
);
1272 /* Discard the high bits only once, rather than both inputs. */
1273 if (type
== TCG_TYPE_I32
) {
1274 tcg_out_ext32u(s
, TCG_REG_R0
, arg1
);
1277 tcg_out_setcond_ne0(s
, arg0
, arg1
);
1295 crop
= CRNOR
| BT (7, CR_EQ
) | BA (7, CR_LT
) | BB (7, CR_LT
);
1301 crop
= CRNOR
| BT (7, CR_EQ
) | BA (7, CR_GT
) | BB (7, CR_GT
);
1303 tcg_out_cmp(s
, cond
, arg1
, arg2
, const_arg2
, 7, type
);
1307 tcg_out32(s
, MFOCRF
| RT(TCG_REG_R0
) | FXM(7));
1308 tcg_out_rlw(s
, RLWINM
, arg0
, TCG_REG_R0
, sh
, 31, 31);
1316 static void tcg_out_bc (TCGContext
*s
, int bc
, int label_index
)
1318 TCGLabel
*l
= &s
->labels
[label_index
];
1321 tcg_out32 (s
, bc
| reloc_pc14_val (s
->code_ptr
, l
->u
.value
));
1323 uint16_t val
= *(uint16_t *) &s
->code_ptr
[2];
1325 /* Thanks to Andrzej Zaborowski */
1326 tcg_out32 (s
, bc
| (val
& 0xfffc));
1327 tcg_out_reloc (s
, s
->code_ptr
- 4, R_PPC_REL14
, label_index
, 0);
1331 static void tcg_out_brcond(TCGContext
*s
, TCGCond cond
,
1332 TCGArg arg1
, TCGArg arg2
, int const_arg2
,
1333 int label_index
, TCGType type
)
1335 tcg_out_cmp(s
, cond
, arg1
, arg2
, const_arg2
, 7, type
);
1336 tcg_out_bc(s
, tcg_to_bc
[cond
], label_index
);
1339 static void tcg_out_movcond(TCGContext
*s
, TCGType type
, TCGCond cond
,
1340 TCGArg dest
, TCGArg c1
, TCGArg c2
, TCGArg v1
,
1341 TCGArg v2
, bool const_c2
)
1343 /* If for some reason both inputs are zero, don't produce bad code. */
1344 if (v1
== 0 && v2
== 0) {
1345 tcg_out_movi(s
, type
, dest
, 0);
1349 tcg_out_cmp(s
, cond
, c1
, c2
, const_c2
, 7, type
);
1352 int isel
= tcg_to_isel
[cond
];
1354 /* Swap the V operands if the operation indicates inversion. */
1361 /* V1 == 0 is handled by isel; V2 == 0 must be handled by hand. */
1363 tcg_out_movi(s
, type
, 0, 0);
1365 tcg_out32(s
, isel
| TAB(dest
, v1
, v2
));
1368 cond
= tcg_invert_cond(cond
);
1370 } else if (dest
!= v1
) {
1372 tcg_out_movi(s
, type
, dest
, 0);
1374 tcg_out_mov(s
, type
, dest
, v1
);
1377 /* Branch forward over one insn */
1378 tcg_out32(s
, tcg_to_bc
[cond
] | 8);
1380 tcg_out_movi(s
, type
, dest
, 0);
1382 tcg_out_mov(s
, type
, dest
, v2
);
1387 void ppc_tb_set_jmp_target (unsigned long jmp_addr
, unsigned long addr
)
1390 unsigned long patch_size
;
1392 s
.code_ptr
= (uint8_t *) jmp_addr
;
1393 tcg_out_b (&s
, 0, addr
);
1394 patch_size
= s
.code_ptr
- (uint8_t *) jmp_addr
;
1395 flush_icache_range (jmp_addr
, jmp_addr
+ patch_size
);
1398 static void tcg_out_op (TCGContext
*s
, TCGOpcode opc
, const TCGArg
*args
,
1399 const int *const_args
)
1405 case INDEX_op_exit_tb
:
1406 tcg_out_movi (s
, TCG_TYPE_I64
, TCG_REG_R3
, args
[0]);
1407 tcg_out_b (s
, 0, (tcg_target_long
) tb_ret_addr
);
1409 case INDEX_op_goto_tb
:
1410 if (s
->tb_jmp_offset
) {
1411 /* direct jump method */
1413 s
->tb_jmp_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
1419 s
->tb_next_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
1423 TCGLabel
*l
= &s
->labels
[args
[0]];
1426 tcg_out_b (s
, 0, l
->u
.value
);
1429 uint32_t val
= *(uint32_t *) s
->code_ptr
;
1431 /* Thanks to Andrzej Zaborowski */
1432 tcg_out32 (s
, B
| (val
& 0x3fffffc));
1433 tcg_out_reloc (s
, s
->code_ptr
- 4, R_PPC_REL24
, args
[0], 0);
1438 tcg_out_call (s
, args
[0], const_args
[0]);
1440 case INDEX_op_movi_i32
:
1441 tcg_out_movi (s
, TCG_TYPE_I32
, args
[0], args
[1]);
1443 case INDEX_op_movi_i64
:
1444 tcg_out_movi (s
, TCG_TYPE_I64
, args
[0], args
[1]);
1446 case INDEX_op_ld8u_i32
:
1447 case INDEX_op_ld8u_i64
:
1448 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LBZ
, LBZX
);
1450 case INDEX_op_ld8s_i32
:
1451 case INDEX_op_ld8s_i64
:
1452 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LBZ
, LBZX
);
1453 tcg_out32 (s
, EXTSB
| RS (args
[0]) | RA (args
[0]));
1455 case INDEX_op_ld16u_i32
:
1456 case INDEX_op_ld16u_i64
:
1457 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LHZ
, LHZX
);
1459 case INDEX_op_ld16s_i32
:
1460 case INDEX_op_ld16s_i64
:
1461 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LHA
, LHAX
);
1463 case INDEX_op_ld_i32
:
1464 case INDEX_op_ld32u_i64
:
1465 tcg_out_ldst (s
, args
[0], args
[1], args
[2], LWZ
, LWZX
);
1467 case INDEX_op_ld32s_i64
:
1468 tcg_out_ldsta (s
, args
[0], args
[1], args
[2], LWA
, LWAX
);
1470 case INDEX_op_ld_i64
:
1471 tcg_out_ldsta (s
, args
[0], args
[1], args
[2], LD
, LDX
);
1473 case INDEX_op_st8_i32
:
1474 case INDEX_op_st8_i64
:
1475 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STB
, STBX
);
1477 case INDEX_op_st16_i32
:
1478 case INDEX_op_st16_i64
:
1479 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STH
, STHX
);
1481 case INDEX_op_st_i32
:
1482 case INDEX_op_st32_i64
:
1483 tcg_out_ldst (s
, args
[0], args
[1], args
[2], STW
, STWX
);
1485 case INDEX_op_st_i64
:
1486 tcg_out_ldsta (s
, args
[0], args
[1], args
[2], STD
, STDX
);
1489 case INDEX_op_add_i32
:
1490 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1491 if (const_args
[2]) {
1497 tcg_out32(s
, ADDIS
| TAI(a0
, a1
, h
>> 16));
1500 if (l
|| a0
!= a1
) {
1501 tcg_out32(s
, ADDI
| TAI(a0
, a1
, l
));
1504 tcg_out32(s
, ADD
| TAB(a0
, a1
, a2
));
1507 case INDEX_op_sub_i32
:
1508 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1509 if (const_args
[1]) {
1510 if (const_args
[2]) {
1511 tcg_out_movi(s
, TCG_TYPE_I32
, a0
, a1
- a2
);
1513 tcg_out32(s
, SUBFIC
| TAI(a0
, a2
, a1
));
1515 } else if (const_args
[2]) {
1519 tcg_out32(s
, SUBF
| TAB(a0
, a2
, a1
));
1523 case INDEX_op_and_i32
:
1524 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1525 if (const_args
[2]) {
1526 tcg_out_andi32(s
, a0
, a1
, a2
);
1528 tcg_out32(s
, AND
| SAB(a1
, a0
, a2
));
1531 case INDEX_op_and_i64
:
1532 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1533 if (const_args
[2]) {
1534 tcg_out_andi64(s
, a0
, a1
, a2
);
1536 tcg_out32(s
, AND
| SAB(a1
, a0
, a2
));
1539 case INDEX_op_or_i64
:
1540 case INDEX_op_or_i32
:
1541 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1542 if (const_args
[2]) {
1543 tcg_out_ori32(s
, a0
, a1
, a2
);
1545 tcg_out32(s
, OR
| SAB(a1
, a0
, a2
));
1548 case INDEX_op_xor_i64
:
1549 case INDEX_op_xor_i32
:
1550 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1551 if (const_args
[2]) {
1552 tcg_out_xori32(s
, a0
, a1
, a2
);
1554 tcg_out32(s
, XOR
| SAB(a1
, a0
, a2
));
1557 case INDEX_op_andc_i32
:
1558 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1559 if (const_args
[2]) {
1560 tcg_out_andi32(s
, a0
, a1
, ~a2
);
1562 tcg_out32(s
, ANDC
| SAB(a1
, a0
, a2
));
1565 case INDEX_op_andc_i64
:
1566 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1567 if (const_args
[2]) {
1568 tcg_out_andi64(s
, a0
, a1
, ~a2
);
1570 tcg_out32(s
, ANDC
| SAB(a1
, a0
, a2
));
1573 case INDEX_op_orc_i32
:
1574 if (const_args
[2]) {
1575 tcg_out_ori32(s
, args
[0], args
[1], ~args
[2]);
1579 case INDEX_op_orc_i64
:
1580 tcg_out32(s
, ORC
| SAB(args
[1], args
[0], args
[2]));
1582 case INDEX_op_eqv_i32
:
1583 if (const_args
[2]) {
1584 tcg_out_xori32(s
, args
[0], args
[1], ~args
[2]);
1588 case INDEX_op_eqv_i64
:
1589 tcg_out32(s
, EQV
| SAB(args
[1], args
[0], args
[2]));
1591 case INDEX_op_nand_i32
:
1592 case INDEX_op_nand_i64
:
1593 tcg_out32(s
, NAND
| SAB(args
[1], args
[0], args
[2]));
1595 case INDEX_op_nor_i32
:
1596 case INDEX_op_nor_i64
:
1597 tcg_out32(s
, NOR
| SAB(args
[1], args
[0], args
[2]));
1600 case INDEX_op_mul_i32
:
1601 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1602 if (const_args
[2]) {
1603 tcg_out32(s
, MULLI
| TAI(a0
, a1
, a2
));
1605 tcg_out32(s
, MULLW
| TAB(a0
, a1
, a2
));
1609 case INDEX_op_div_i32
:
1610 tcg_out32 (s
, DIVW
| TAB (args
[0], args
[1], args
[2]));
1613 case INDEX_op_divu_i32
:
1614 tcg_out32 (s
, DIVWU
| TAB (args
[0], args
[1], args
[2]));
1617 case INDEX_op_shl_i32
:
1618 if (const_args
[2]) {
1619 tcg_out_rlw(s
, RLWINM
, args
[0], args
[1], args
[2], 0, 31 - args
[2]);
1621 tcg_out32 (s
, SLW
| SAB (args
[1], args
[0], args
[2]));
1624 case INDEX_op_shr_i32
:
1625 if (const_args
[2]) {
1626 tcg_out_rlw(s
, RLWINM
, args
[0], args
[1], 32 - args
[2], args
[2], 31);
1628 tcg_out32 (s
, SRW
| SAB (args
[1], args
[0], args
[2]));
1631 case INDEX_op_sar_i32
:
1633 tcg_out32 (s
, SRAWI
| RS (args
[1]) | RA (args
[0]) | SH (args
[2]));
1635 tcg_out32 (s
, SRAW
| SAB (args
[1], args
[0], args
[2]));
1637 case INDEX_op_rotl_i32
:
1638 if (const_args
[2]) {
1639 tcg_out_rlw(s
, RLWINM
, args
[0], args
[1], args
[2], 0, 31);
1641 tcg_out32(s
, RLWNM
| SAB(args
[1], args
[0], args
[2])
1645 case INDEX_op_rotr_i32
:
1646 if (const_args
[2]) {
1647 tcg_out_rlw(s
, RLWINM
, args
[0], args
[1], 32 - args
[2], 0, 31);
1649 tcg_out32(s
, SUBFIC
| TAI(0, args
[2], 32));
1650 tcg_out32(s
, RLWNM
| SAB(args
[1], args
[0], 0)
1655 case INDEX_op_brcond_i32
:
1656 tcg_out_brcond(s
, args
[2], args
[0], args
[1], const_args
[1],
1657 args
[3], TCG_TYPE_I32
);
1660 case INDEX_op_brcond_i64
:
1661 tcg_out_brcond(s
, args
[2], args
[0], args
[1], const_args
[1],
1662 args
[3], TCG_TYPE_I64
);
1665 case INDEX_op_neg_i32
:
1666 case INDEX_op_neg_i64
:
1667 tcg_out32 (s
, NEG
| RT (args
[0]) | RA (args
[1]));
1670 case INDEX_op_not_i32
:
1671 case INDEX_op_not_i64
:
1672 tcg_out32 (s
, NOR
| SAB (args
[1], args
[0], args
[1]));
1675 case INDEX_op_add_i64
:
1676 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1677 if (const_args
[2]) {
1680 /* We can always split any 32-bit signed constant into 3 pieces.
1681 Note the positive 0x80000000 coming from the sub_i64 path,
1682 handled with the same code we need for eg 0x7fff8000. */
1683 assert(a2
== (int32_t)a2
|| a2
== 0x80000000);
1687 if (h1
< 0 && (int64_t)a2
> 0) {
1691 assert((TCGArg
)h2
+ h1
+ l0
== a2
);
1694 tcg_out32(s
, ADDIS
| TAI(a0
, a1
, h2
>> 16));
1698 tcg_out32(s
, ADDIS
| TAI(a0
, a1
, h1
>> 16));
1701 if (l0
|| a0
!= a1
) {
1702 tcg_out32(s
, ADDI
| TAI(a0
, a1
, l0
));
1705 tcg_out32(s
, ADD
| TAB(a0
, a1
, a2
));
1708 case INDEX_op_sub_i64
:
1709 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1710 if (const_args
[1]) {
1711 if (const_args
[2]) {
1712 tcg_out_movi(s
, TCG_TYPE_I64
, a0
, a1
- a2
);
1714 tcg_out32(s
, SUBFIC
| TAI(a0
, a2
, a1
));
1716 } else if (const_args
[2]) {
1720 tcg_out32(s
, SUBF
| TAB(a0
, a2
, a1
));
1724 case INDEX_op_shl_i64
:
1726 tcg_out_shli64(s
, args
[0], args
[1], args
[2]);
1728 tcg_out32 (s
, SLD
| SAB (args
[1], args
[0], args
[2]));
1730 case INDEX_op_shr_i64
:
1732 tcg_out_shri64(s
, args
[0], args
[1], args
[2]);
1734 tcg_out32 (s
, SRD
| SAB (args
[1], args
[0], args
[2]));
1736 case INDEX_op_sar_i64
:
1737 if (const_args
[2]) {
1738 int sh
= SH (args
[2] & 0x1f) | (((args
[2] >> 5) & 1) << 1);
1739 tcg_out32 (s
, SRADI
| RA (args
[0]) | RS (args
[1]) | sh
);
1742 tcg_out32 (s
, SRAD
| SAB (args
[1], args
[0], args
[2]));
1744 case INDEX_op_rotl_i64
:
1745 if (const_args
[2]) {
1746 tcg_out_rld(s
, RLDICL
, args
[0], args
[1], args
[2], 0);
1748 tcg_out32(s
, RLDCL
| SAB(args
[1], args
[0], args
[2]) | MB64(0));
1751 case INDEX_op_rotr_i64
:
1752 if (const_args
[2]) {
1753 tcg_out_rld(s
, RLDICL
, args
[0], args
[1], 64 - args
[2], 0);
1755 tcg_out32(s
, SUBFIC
| TAI(0, args
[2], 64));
1756 tcg_out32(s
, RLDCL
| SAB(args
[1], args
[0], 0) | MB64(0));
1760 case INDEX_op_mul_i64
:
1761 a0
= args
[0], a1
= args
[1], a2
= args
[2];
1762 if (const_args
[2]) {
1763 tcg_out32(s
, MULLI
| TAI(a0
, a1
, a2
));
1765 tcg_out32(s
, MULLD
| TAB(a0
, a1
, a2
));
1768 case INDEX_op_div_i64
:
1769 tcg_out32 (s
, DIVD
| TAB (args
[0], args
[1], args
[2]));
1771 case INDEX_op_divu_i64
:
1772 tcg_out32 (s
, DIVDU
| TAB (args
[0], args
[1], args
[2]));
1775 case INDEX_op_qemu_ld8u
:
1776 tcg_out_qemu_ld (s
, args
, 0);
1778 case INDEX_op_qemu_ld8s
:
1779 tcg_out_qemu_ld (s
, args
, 0 | 4);
1781 case INDEX_op_qemu_ld16u
:
1782 tcg_out_qemu_ld (s
, args
, 1);
1784 case INDEX_op_qemu_ld16s
:
1785 tcg_out_qemu_ld (s
, args
, 1 | 4);
1787 case INDEX_op_qemu_ld32
:
1788 case INDEX_op_qemu_ld32u
:
1789 tcg_out_qemu_ld (s
, args
, 2);
1791 case INDEX_op_qemu_ld32s
:
1792 tcg_out_qemu_ld (s
, args
, 2 | 4);
1794 case INDEX_op_qemu_ld64
:
1795 tcg_out_qemu_ld (s
, args
, 3);
1797 case INDEX_op_qemu_st8
:
1798 tcg_out_qemu_st (s
, args
, 0);
1800 case INDEX_op_qemu_st16
:
1801 tcg_out_qemu_st (s
, args
, 1);
1803 case INDEX_op_qemu_st32
:
1804 tcg_out_qemu_st (s
, args
, 2);
1806 case INDEX_op_qemu_st64
:
1807 tcg_out_qemu_st (s
, args
, 3);
1810 case INDEX_op_ext8s_i32
:
1811 case INDEX_op_ext8s_i64
:
1814 case INDEX_op_ext16s_i32
:
1815 case INDEX_op_ext16s_i64
:
1818 case INDEX_op_ext32s_i64
:
1822 tcg_out32 (s
, c
| RS (args
[1]) | RA (args
[0]));
1825 case INDEX_op_setcond_i32
:
1826 tcg_out_setcond (s
, TCG_TYPE_I32
, args
[3], args
[0], args
[1], args
[2],
1829 case INDEX_op_setcond_i64
:
1830 tcg_out_setcond (s
, TCG_TYPE_I64
, args
[3], args
[0], args
[1], args
[2],
1834 case INDEX_op_bswap16_i32
:
1835 case INDEX_op_bswap16_i64
:
1836 a0
= args
[0], a1
= args
[1];
1839 /* a0 = (a1 r<< 24) & 0xff # 000c */
1840 tcg_out_rlw(s
, RLWINM
, a0
, a1
, 24, 24, 31);
1841 /* a0 = (a0 & ~0xff00) | (a1 r<< 8) & 0xff00 # 00dc */
1842 tcg_out_rlw(s
, RLWIMI
, a0
, a1
, 8, 16, 23);
1844 /* r0 = (a1 r<< 8) & 0xff00 # 00d0 */
1845 tcg_out_rlw(s
, RLWINM
, TCG_REG_R0
, a1
, 8, 16, 23);
1846 /* a0 = (a1 r<< 24) & 0xff # 000c */
1847 tcg_out_rlw(s
, RLWINM
, a0
, a1
, 24, 24, 31);
1848 /* a0 = a0 | r0 # 00dc */
1849 tcg_out32(s
, OR
| SAB(TCG_REG_R0
, a0
, a0
));
1853 case INDEX_op_bswap32_i32
:
1854 case INDEX_op_bswap32_i64
:
1855 /* Stolen from gcc's builtin_bswap32 */
1857 a0
= args
[0] == a1
? TCG_REG_R0
: args
[0];
1859 /* a1 = args[1] # abcd */
1860 /* a0 = rotate_left (a1, 8) # bcda */
1861 tcg_out_rlw(s
, RLWINM
, a0
, a1
, 8, 0, 31);
1862 /* a0 = (a0 & ~0xff000000) | ((a1 r<< 24) & 0xff000000) # dcda */
1863 tcg_out_rlw(s
, RLWIMI
, a0
, a1
, 24, 0, 7);
1864 /* a0 = (a0 & ~0x0000ff00) | ((a1 r<< 24) & 0x0000ff00) # dcba */
1865 tcg_out_rlw(s
, RLWIMI
, a0
, a1
, 24, 16, 23);
1867 if (a0
== TCG_REG_R0
) {
1868 tcg_out_mov(s
, TCG_TYPE_I64
, args
[0], a0
);
1872 case INDEX_op_bswap64_i64
:
1873 a0
= args
[0], a1
= args
[1], a2
= 0;
1879 /* a1 = # abcd efgh */
1880 /* a0 = rl32(a1, 8) # 0000 fghe */
1881 tcg_out_rlw(s
, RLWINM
, a0
, a1
, 8, 0, 31);
1882 /* a0 = dep(a0, rl32(a1, 24), 0xff000000) # 0000 hghe */
1883 tcg_out_rlw(s
, RLWIMI
, a0
, a1
, 24, 0, 7);
1884 /* a0 = dep(a0, rl32(a1, 24), 0x0000ff00) # 0000 hgfe */
1885 tcg_out_rlw(s
, RLWIMI
, a0
, a1
, 24, 16, 23);
1887 /* a0 = rl64(a0, 32) # hgfe 0000 */
1888 /* a2 = rl64(a1, 32) # efgh abcd */
1889 tcg_out_rld(s
, RLDICL
, a0
, a0
, 32, 0);
1890 tcg_out_rld(s
, RLDICL
, a2
, a1
, 32, 0);
1892 /* a0 = dep(a0, rl32(a2, 8), 0xffffffff) # hgfe bcda */
1893 tcg_out_rlw(s
, RLWIMI
, a0
, a2
, 8, 0, 31);
1894 /* a0 = dep(a0, rl32(a2, 24), 0xff000000) # hgfe dcda */
1895 tcg_out_rlw(s
, RLWIMI
, a0
, a2
, 24, 0, 7);
1896 /* a0 = dep(a0, rl32(a2, 24), 0x0000ff00) # hgfe dcba */
1897 tcg_out_rlw(s
, RLWIMI
, a0
, a2
, 24, 16, 23);
1900 tcg_out_mov(s
, TCG_TYPE_I64
, args
[0], a0
);
1904 case INDEX_op_deposit_i32
:
1905 if (const_args
[2]) {
1906 uint32_t mask
= ((2u << (args
[4] - 1)) - 1) << args
[3];
1907 tcg_out_andi32(s
, args
[0], args
[0], ~mask
);
1909 tcg_out_rlw(s
, RLWIMI
, args
[0], args
[2], args
[3],
1910 32 - args
[3] - args
[4], 31 - args
[3]);
1913 case INDEX_op_deposit_i64
:
1914 if (const_args
[2]) {
1915 uint64_t mask
= ((2ull << (args
[4] - 1)) - 1) << args
[3];
1916 tcg_out_andi64(s
, args
[0], args
[0], ~mask
);
1918 tcg_out_rld(s
, RLDIMI
, args
[0], args
[2], args
[3],
1919 64 - args
[3] - args
[4]);
1923 case INDEX_op_movcond_i32
:
1924 tcg_out_movcond(s
, TCG_TYPE_I32
, args
[5], args
[0], args
[1], args
[2],
1925 args
[3], args
[4], const_args
[2]);
1927 case INDEX_op_movcond_i64
:
1928 tcg_out_movcond(s
, TCG_TYPE_I64
, args
[5], args
[0], args
[1], args
[2],
1929 args
[3], args
[4], const_args
[2]);
1932 case INDEX_op_add2_i64
:
1933 /* Note that the CA bit is defined based on the word size of the
1934 environment. So in 64-bit mode it's always carry-out of bit 63.
1935 The fallback code using deposit works just as well for 32-bit. */
1936 a0
= args
[0], a1
= args
[1];
1937 if (a0
== args
[3] || (!const_args
[5] && a0
== args
[5])) {
1940 if (const_args
[4]) {
1941 tcg_out32(s
, ADDIC
| TAI(a0
, args
[2], args
[4]));
1943 tcg_out32(s
, ADDC
| TAB(a0
, args
[2], args
[4]));
1945 if (const_args
[5]) {
1946 tcg_out32(s
, (args
[5] ? ADDME
: ADDZE
) | RT(a1
) | RA(args
[3]));
1948 tcg_out32(s
, ADDE
| TAB(a1
, args
[3], args
[5]));
1950 if (a0
!= args
[0]) {
1951 tcg_out_mov(s
, TCG_TYPE_I64
, args
[0], a0
);
1955 case INDEX_op_sub2_i64
:
1956 a0
= args
[0], a1
= args
[1];
1957 if (a0
== args
[5] || (!const_args
[4] && a0
== args
[4])) {
1960 if (const_args
[2]) {
1961 tcg_out32(s
, SUBFIC
| TAI(a0
, args
[3], args
[2]));
1963 tcg_out32(s
, SUBFC
| TAB(a0
, args
[3], args
[2]));
1965 if (const_args
[4]) {
1966 tcg_out32(s
, (args
[4] ? SUBFME
: SUBFZE
) | RT(a1
) | RA(args
[5]));
1968 tcg_out32(s
, SUBFE
| TAB(a1
, args
[5], args
[4]));
1970 if (a0
!= args
[0]) {
1971 tcg_out_mov(s
, TCG_TYPE_I64
, args
[0], a0
);
1975 case INDEX_op_muluh_i64
:
1976 tcg_out32(s
, MULHDU
| TAB(args
[0], args
[1], args
[2]));
1978 case INDEX_op_mulsh_i64
:
1979 tcg_out32(s
, MULHD
| TAB(args
[0], args
[1], args
[2]));
1988 static const TCGTargetOpDef ppc_op_defs
[] = {
1989 { INDEX_op_exit_tb
, { } },
1990 { INDEX_op_goto_tb
, { } },
1991 { INDEX_op_call
, { "ri" } },
1992 { INDEX_op_br
, { } },
1994 { INDEX_op_mov_i32
, { "r", "r" } },
1995 { INDEX_op_mov_i64
, { "r", "r" } },
1996 { INDEX_op_movi_i32
, { "r" } },
1997 { INDEX_op_movi_i64
, { "r" } },
1999 { INDEX_op_ld8u_i32
, { "r", "r" } },
2000 { INDEX_op_ld8s_i32
, { "r", "r" } },
2001 { INDEX_op_ld16u_i32
, { "r", "r" } },
2002 { INDEX_op_ld16s_i32
, { "r", "r" } },
2003 { INDEX_op_ld_i32
, { "r", "r" } },
2004 { INDEX_op_ld_i64
, { "r", "r" } },
2005 { INDEX_op_st8_i32
, { "r", "r" } },
2006 { INDEX_op_st8_i64
, { "r", "r" } },
2007 { INDEX_op_st16_i32
, { "r", "r" } },
2008 { INDEX_op_st16_i64
, { "r", "r" } },
2009 { INDEX_op_st_i32
, { "r", "r" } },
2010 { INDEX_op_st_i64
, { "r", "r" } },
2011 { INDEX_op_st32_i64
, { "r", "r" } },
2013 { INDEX_op_ld8u_i64
, { "r", "r" } },
2014 { INDEX_op_ld8s_i64
, { "r", "r" } },
2015 { INDEX_op_ld16u_i64
, { "r", "r" } },
2016 { INDEX_op_ld16s_i64
, { "r", "r" } },
2017 { INDEX_op_ld32u_i64
, { "r", "r" } },
2018 { INDEX_op_ld32s_i64
, { "r", "r" } },
2020 { INDEX_op_add_i32
, { "r", "r", "ri" } },
2021 { INDEX_op_mul_i32
, { "r", "r", "rI" } },
2022 { INDEX_op_div_i32
, { "r", "r", "r" } },
2023 { INDEX_op_divu_i32
, { "r", "r", "r" } },
2024 { INDEX_op_sub_i32
, { "r", "rI", "ri" } },
2025 { INDEX_op_and_i32
, { "r", "r", "ri" } },
2026 { INDEX_op_or_i32
, { "r", "r", "ri" } },
2027 { INDEX_op_xor_i32
, { "r", "r", "ri" } },
2028 { INDEX_op_andc_i32
, { "r", "r", "ri" } },
2029 { INDEX_op_orc_i32
, { "r", "r", "ri" } },
2030 { INDEX_op_eqv_i32
, { "r", "r", "ri" } },
2031 { INDEX_op_nand_i32
, { "r", "r", "r" } },
2032 { INDEX_op_nor_i32
, { "r", "r", "r" } },
2034 { INDEX_op_shl_i32
, { "r", "r", "ri" } },
2035 { INDEX_op_shr_i32
, { "r", "r", "ri" } },
2036 { INDEX_op_sar_i32
, { "r", "r", "ri" } },
2037 { INDEX_op_rotl_i32
, { "r", "r", "ri" } },
2038 { INDEX_op_rotr_i32
, { "r", "r", "ri" } },
2040 { INDEX_op_brcond_i32
, { "r", "ri" } },
2041 { INDEX_op_brcond_i64
, { "r", "ri" } },
2043 { INDEX_op_neg_i32
, { "r", "r" } },
2044 { INDEX_op_not_i32
, { "r", "r" } },
2046 { INDEX_op_add_i64
, { "r", "r", "rT" } },
2047 { INDEX_op_sub_i64
, { "r", "rI", "rT" } },
2048 { INDEX_op_and_i64
, { "r", "r", "ri" } },
2049 { INDEX_op_or_i64
, { "r", "r", "rU" } },
2050 { INDEX_op_xor_i64
, { "r", "r", "rU" } },
2051 { INDEX_op_andc_i64
, { "r", "r", "ri" } },
2052 { INDEX_op_orc_i64
, { "r", "r", "r" } },
2053 { INDEX_op_eqv_i64
, { "r", "r", "r" } },
2054 { INDEX_op_nand_i64
, { "r", "r", "r" } },
2055 { INDEX_op_nor_i64
, { "r", "r", "r" } },
2057 { INDEX_op_shl_i64
, { "r", "r", "ri" } },
2058 { INDEX_op_shr_i64
, { "r", "r", "ri" } },
2059 { INDEX_op_sar_i64
, { "r", "r", "ri" } },
2060 { INDEX_op_rotl_i64
, { "r", "r", "ri" } },
2061 { INDEX_op_rotr_i64
, { "r", "r", "ri" } },
2063 { INDEX_op_mul_i64
, { "r", "r", "rI" } },
2064 { INDEX_op_div_i64
, { "r", "r", "r" } },
2065 { INDEX_op_divu_i64
, { "r", "r", "r" } },
2067 { INDEX_op_neg_i64
, { "r", "r" } },
2068 { INDEX_op_not_i64
, { "r", "r" } },
2070 { INDEX_op_qemu_ld8u
, { "r", "L" } },
2071 { INDEX_op_qemu_ld8s
, { "r", "L" } },
2072 { INDEX_op_qemu_ld16u
, { "r", "L" } },
2073 { INDEX_op_qemu_ld16s
, { "r", "L" } },
2074 { INDEX_op_qemu_ld32
, { "r", "L" } },
2075 { INDEX_op_qemu_ld32u
, { "r", "L" } },
2076 { INDEX_op_qemu_ld32s
, { "r", "L" } },
2077 { INDEX_op_qemu_ld64
, { "r", "L" } },
2079 { INDEX_op_qemu_st8
, { "S", "S" } },
2080 { INDEX_op_qemu_st16
, { "S", "S" } },
2081 { INDEX_op_qemu_st32
, { "S", "S" } },
2082 { INDEX_op_qemu_st64
, { "S", "S" } },
2084 { INDEX_op_ext8s_i32
, { "r", "r" } },
2085 { INDEX_op_ext16s_i32
, { "r", "r" } },
2086 { INDEX_op_ext8s_i64
, { "r", "r" } },
2087 { INDEX_op_ext16s_i64
, { "r", "r" } },
2088 { INDEX_op_ext32s_i64
, { "r", "r" } },
2090 { INDEX_op_setcond_i32
, { "r", "r", "ri" } },
2091 { INDEX_op_setcond_i64
, { "r", "r", "ri" } },
2092 { INDEX_op_movcond_i32
, { "r", "r", "ri", "rZ", "rZ" } },
2093 { INDEX_op_movcond_i64
, { "r", "r", "ri", "rZ", "rZ" } },
2095 { INDEX_op_bswap16_i32
, { "r", "r" } },
2096 { INDEX_op_bswap16_i64
, { "r", "r" } },
2097 { INDEX_op_bswap32_i32
, { "r", "r" } },
2098 { INDEX_op_bswap32_i64
, { "r", "r" } },
2099 { INDEX_op_bswap64_i64
, { "r", "r" } },
2101 { INDEX_op_deposit_i32
, { "r", "0", "rZ" } },
2102 { INDEX_op_deposit_i64
, { "r", "0", "rZ" } },
2104 { INDEX_op_add2_i64
, { "r", "r", "r", "r", "rI", "rZM" } },
2105 { INDEX_op_sub2_i64
, { "r", "r", "rI", "r", "rZM", "r" } },
2106 { INDEX_op_mulsh_i64
, { "r", "r", "r" } },
2107 { INDEX_op_muluh_i64
, { "r", "r", "r" } },
2112 static void tcg_target_init (TCGContext
*s
)
2114 #ifdef CONFIG_GETAUXVAL
2115 unsigned long hwcap
= getauxval(AT_HWCAP
);
2116 if (hwcap
& PPC_FEATURE_ARCH_2_06
) {
2117 have_isa_2_06
= true;
2121 tcg_regset_set32 (tcg_target_available_regs
[TCG_TYPE_I32
], 0, 0xffffffff);
2122 tcg_regset_set32 (tcg_target_available_regs
[TCG_TYPE_I64
], 0, 0xffffffff);
2123 tcg_regset_set32 (tcg_target_call_clobber_regs
, 0,
2135 (1 << TCG_REG_R10
) |
2136 (1 << TCG_REG_R11
) |
2140 tcg_regset_clear (s
->reserved_regs
);
2141 tcg_regset_set_reg (s
->reserved_regs
, TCG_REG_R0
);
2142 tcg_regset_set_reg (s
->reserved_regs
, TCG_REG_R1
);
2144 tcg_regset_set_reg (s
->reserved_regs
, TCG_REG_R2
);
2146 tcg_regset_set_reg (s
->reserved_regs
, TCG_REG_R13
);
2148 tcg_add_target_add_op_defs (ppc_op_defs
);