Sparc code generator update (fix qemu_ld & qemu_st)

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5014 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
blueswir1 2008-08-16 19:54:01 +00:00
parent a245f2e7b8
commit 56fc64dfd0

View File

@ -141,9 +141,6 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
tcg_regset_reset_reg(ct->u.regs, TCG_REG_O0); tcg_regset_reset_reg(ct->u.regs, TCG_REG_O0);
tcg_regset_reset_reg(ct->u.regs, TCG_REG_O1); tcg_regset_reset_reg(ct->u.regs, TCG_REG_O1);
tcg_regset_reset_reg(ct->u.regs, TCG_REG_O2); tcg_regset_reset_reg(ct->u.regs, TCG_REG_O2);
// Internal use
tcg_regset_reset_reg(ct->u.regs, TCG_REG_L0);
tcg_regset_reset_reg(ct->u.regs, TCG_REG_L1);
break; break;
case 'I': case 'I':
ct->ct |= TCG_CT_CONST_S11; ct->ct |= TCG_CT_CONST_S11;
@ -497,8 +494,8 @@ static const void * const qemu_st_helpers[4] = {
static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
int opc) int opc)
{ {
int addr_reg, data_reg, r0, r1, arg0, arg1, mem_index, s_bits; int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits;
int target_ld_op, host_ld_op; int target_ld_op, host_ld_op, sll_op, sra_op;
#if defined(CONFIG_SOFTMMU) #if defined(CONFIG_SOFTMMU)
uint32_t *label1_ptr, *label2_ptr; uint32_t *label1_ptr, *label2_ptr;
#endif #endif
@ -508,10 +505,9 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
mem_index = *args; mem_index = *args;
s_bits = opc & 3; s_bits = opc & 3;
r0 = TCG_REG_L0;
r1 = TCG_REG_L1;
arg0 = TCG_REG_O0; arg0 = TCG_REG_O0;
arg1 = TCG_REG_O1; arg1 = TCG_REG_O1;
arg2 = TCG_REG_O2;
#if TARGET_LONG_BITS == 32 #if TARGET_LONG_BITS == 32
target_ld_op = LDUW; target_ld_op = LDUW;
@ -521,33 +517,39 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
#ifdef __arch64__ #ifdef __arch64__
host_ld_op = LDX; host_ld_op = LDX;
sll_op = SHIFT_SLLX;
sra_op = SHIFT_SRAX;
#else #else
host_ld_op = LDUW; host_ld_op = LDUW;
sll_op = SHIFT_SLL;
sra_op = SHIFT_SRA;
#endif #endif
#if defined(CONFIG_SOFTMMU) #if defined(CONFIG_SOFTMMU)
/* srl addr_reg, x, r1 */ /* srl addr_reg, x, arg1 */
tcg_out_arithi(s, r1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS, tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS,
SHIFT_SRL); SHIFT_SRL);
/* and addr_reg, x, r0 */ /* and addr_reg, x, arg0 */
tcg_out_arithi(s, r0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1), tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1),
ARITH_AND); ARITH_AND);
/* and r1, x, r1 */ /* and arg1, x, arg1 */
tcg_out_andi(s, r1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS); tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
/* add r1, x, r1 */ /* add arg1, x, arg1 */
tcg_out_addi(s, r1, offsetof(CPUState, tlb_table[mem_index][0].addr_read)); tcg_out_addi(s, arg1, offsetof(CPUState,
tlb_table[mem_index][0].addr_read));
/* add env, r1, r1 */ /* add env, arg1, arg1 */
tcg_out_arith(s, r1, TCG_AREG0, r1, ARITH_ADD); tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD);
/* ld [r1], arg1 */ /* ld [arg1], arg2 */
tcg_out32(s, target_ld_op | INSN_RD(arg1) | INSN_RS1(r1) | INSN_RS2(TCG_REG_G0)); tcg_out32(s, target_ld_op | INSN_RD(arg2) | INSN_RS1(arg1) |
INSN_RS2(TCG_REG_G0));
/* subcc r0, arg1, %g0 */ /* subcc arg0, arg2, %g0 */
tcg_out_arith(s, TCG_REG_G0, r0, arg1, ARITH_SUBCC); tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC);
/* will become: /* will become:
be label1 */ be label1 */
@ -569,25 +571,25 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
switch(opc) { switch(opc) {
case 0 | 4: case 0 | 4:
/* sll arg0, 24/56, data_reg */ /* sll arg0, 24/56, data_reg */
tcg_out_arithi(s, data_reg, arg0, sizeof(tcg_target_long) * 8 - 8, tcg_out_arithi(s, data_reg, arg0, (int)sizeof(tcg_target_long) * 8 - 8,
SHIFT_SLL); sll_op);
/* sra data_reg, 24/56, data_reg */ /* sra data_reg, 24/56, data_reg */
tcg_out_arithi(s, data_reg, data_reg, sizeof(tcg_target_long) * 8 - 8, tcg_out_arithi(s, data_reg, data_reg,
SHIFT_SRA); (int)sizeof(tcg_target_long) * 8 - 8, sra_op);
break; break;
case 1 | 4: case 1 | 4:
/* sll arg0, 16/48, data_reg */ /* sll arg0, 16/48, data_reg */
tcg_out_arithi(s, data_reg, arg0, sizeof(tcg_target_long) * 8 - 16, tcg_out_arithi(s, data_reg, arg0,
SHIFT_SLL); (int)sizeof(tcg_target_long) * 8 - 16, sll_op);
/* sra data_reg, 16/48, data_reg */ /* sra data_reg, 16/48, data_reg */
tcg_out_arithi(s, data_reg, data_reg, sizeof(tcg_target_long) * 8 - 16, tcg_out_arithi(s, data_reg, data_reg,
SHIFT_SRA); (int)sizeof(tcg_target_long) * 8 - 16, sra_op);
break; break;
case 2 | 4: case 2 | 4:
/* sll arg0, 32, data_reg */ /* sll arg0, 32, data_reg */
tcg_out_arithi(s, data_reg, arg0, 32, SHIFT_SLL); tcg_out_arithi(s, data_reg, arg0, 32, sll_op);
/* sra data_reg, 32, data_reg */ /* sra data_reg, 32, data_reg */
tcg_out_arithi(s, data_reg, data_reg, 32, SHIFT_SRA); tcg_out_arithi(s, data_reg, data_reg, 32, sra_op);
break; break;
case 0: case 0:
case 1: case 1:
@ -612,67 +614,67 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
INSN_OFF22((unsigned long)s->code_ptr - INSN_OFF22((unsigned long)s->code_ptr -
(unsigned long)label1_ptr)); (unsigned long)label1_ptr));
/* ld [r1 + x], r1 */ /* ld [arg1 + x], arg1 */
tcg_out_ldst(s, r1, r1, offsetof(CPUTLBEntry, addend) - tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) -
offsetof(CPUTLBEntry, addr_read), host_ld_op); offsetof(CPUTLBEntry, addr_read), host_ld_op);
/* add r0, r1, r0 */ /* add addr_reg, arg1, arg0 */
tcg_out_arith(s, r0, r1, r0, ARITH_ADD); tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD);
#else #else
r0 = addr_reg; arg0 = addr_reg;
#endif #endif
switch(opc) { switch(opc) {
case 0: case 0:
/* ldub [r0], data_reg */ /* ldub [arg0], data_reg */
tcg_out_ldst(s, data_reg, r0, 0, LDUB); tcg_out_ldst(s, data_reg, arg0, 0, LDUB);
break; break;
case 0 | 4: case 0 | 4:
/* ldsb [r0], data_reg */ /* ldsb [arg0], data_reg */
tcg_out_ldst(s, data_reg, r0, 0, LDSB); tcg_out_ldst(s, data_reg, arg0, 0, LDSB);
break; break;
case 1: case 1:
#ifdef TARGET_WORDS_BIGENDIAN #ifdef TARGET_WORDS_BIGENDIAN
/* lduh [r0], data_reg */ /* lduh [arg0], data_reg */
tcg_out_ldst(s, data_reg, r0, 0, LDUH); tcg_out_ldst(s, data_reg, arg0, 0, LDUH);
#else #else
/* lduha [r0] ASI_PRIMARY_LITTLE, data_reg */ /* lduha [arg0] ASI_PRIMARY_LITTLE, data_reg */
tcg_out_ldst_asi(s, data_reg, r0, 0, LDUHA, ASI_PRIMARY_LITTLE); tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUHA, ASI_PRIMARY_LITTLE);
#endif #endif
break; break;
case 1 | 4: case 1 | 4:
#ifdef TARGET_WORDS_BIGENDIAN #ifdef TARGET_WORDS_BIGENDIAN
/* ldsh [r0], data_reg */ /* ldsh [arg0], data_reg */
tcg_out_ldst(s, data_reg, r0, 0, LDSH); tcg_out_ldst(s, data_reg, arg0, 0, LDSH);
#else #else
/* ldsha [r0] ASI_PRIMARY_LITTLE, data_reg */ /* ldsha [arg0] ASI_PRIMARY_LITTLE, data_reg */
tcg_out_ldst_asi(s, data_reg, r0, 0, LDSHA, ASI_PRIMARY_LITTLE); tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSHA, ASI_PRIMARY_LITTLE);
#endif #endif
break; break;
case 2: case 2:
#ifdef TARGET_WORDS_BIGENDIAN #ifdef TARGET_WORDS_BIGENDIAN
/* lduw [r0], data_reg */ /* lduw [arg0], data_reg */
tcg_out_ldst(s, data_reg, r0, 0, LDUW); tcg_out_ldst(s, data_reg, arg0, 0, LDUW);
#else #else
/* lduwa [r0] ASI_PRIMARY_LITTLE, data_reg */ /* lduwa [arg0] ASI_PRIMARY_LITTLE, data_reg */
tcg_out_ldst_asi(s, data_reg, r0, 0, LDUWA, ASI_PRIMARY_LITTLE); tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUWA, ASI_PRIMARY_LITTLE);
#endif #endif
break; break;
case 2 | 4: case 2 | 4:
#ifdef TARGET_WORDS_BIGENDIAN #ifdef TARGET_WORDS_BIGENDIAN
/* ldsw [r0], data_reg */ /* ldsw [arg0], data_reg */
tcg_out_ldst(s, data_reg, r0, 0, LDSW); tcg_out_ldst(s, data_reg, arg0, 0, LDSW);
#else #else
/* ldswa [r0] ASI_PRIMARY_LITTLE, data_reg */ /* ldswa [arg0] ASI_PRIMARY_LITTLE, data_reg */
tcg_out_ldst_asi(s, data_reg, r0, 0, LDSWA, ASI_PRIMARY_LITTLE); tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSWA, ASI_PRIMARY_LITTLE);
#endif #endif
break; break;
case 3: case 3:
#ifdef TARGET_WORDS_BIGENDIAN #ifdef TARGET_WORDS_BIGENDIAN
/* ldx [r0], data_reg */ /* ldx [arg0], data_reg */
tcg_out_ldst(s, data_reg, r0, 0, LDX); tcg_out_ldst(s, data_reg, arg0, 0, LDX);
#else #else
/* ldxa [r0] ASI_PRIMARY_LITTLE, data_reg */ /* ldxa [arg0] ASI_PRIMARY_LITTLE, data_reg */
tcg_out_ldst_asi(s, data_reg, r0, 0, LDXA, ASI_PRIMARY_LITTLE); tcg_out_ldst_asi(s, data_reg, arg0, 0, LDXA, ASI_PRIMARY_LITTLE);
#endif #endif
break; break;
default: default:
@ -690,7 +692,7 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
int opc) int opc)
{ {
int addr_reg, data_reg, r0, r1, arg0, arg1, arg2, mem_index, s_bits; int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits;
int target_ld_op, host_ld_op; int target_ld_op, host_ld_op;
#if defined(CONFIG_SOFTMMU) #if defined(CONFIG_SOFTMMU)
uint32_t *label1_ptr, *label2_ptr; uint32_t *label1_ptr, *label2_ptr;
@ -702,8 +704,6 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
s_bits = opc; s_bits = opc;
r0 = TCG_REG_L0;
r1 = TCG_REG_L1;
arg0 = TCG_REG_O0; arg0 = TCG_REG_O0;
arg1 = TCG_REG_O1; arg1 = TCG_REG_O1;
arg2 = TCG_REG_O2; arg2 = TCG_REG_O2;
@ -721,28 +721,30 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
#endif #endif
#if defined(CONFIG_SOFTMMU) #if defined(CONFIG_SOFTMMU)
/* srl addr_reg, x, r1 */ /* srl addr_reg, x, arg1 */
tcg_out_arithi(s, r1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS, tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS,
SHIFT_SRL); SHIFT_SRL);
/* and addr_reg, x, r0 */ /* and addr_reg, x, arg0 */
tcg_out_arithi(s, r0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1), tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1),
ARITH_AND); ARITH_AND);
/* and r1, x, r1 */ /* and arg1, x, arg1 */
tcg_out_andi(s, r1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS); tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
/* add r1, x, r1 */ /* add arg1, x, arg1 */
tcg_out_addi(s, r1, offsetof(CPUState, tlb_table[mem_index][0].addr_write)); tcg_out_addi(s, arg1, offsetof(CPUState,
tlb_table[mem_index][0].addr_write));
/* add env, r1, r1 */ /* add env, arg1, arg1 */
tcg_out_arith(s, r1, TCG_AREG0, r1, ARITH_ADD); tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD);
/* ld [r1], arg1 */ /* ld [arg1], arg2 */
tcg_out32(s, target_ld_op | INSN_RD(arg1) | INSN_RS1(r1) | INSN_RS2(TCG_REG_G0)); tcg_out32(s, target_ld_op | INSN_RD(arg2) | INSN_RS1(arg1) |
INSN_RS2(TCG_REG_G0));
/* subcc r0, arg1, %g0 */ /* subcc arg0, arg2, %g0 */
tcg_out_arith(s, TCG_REG_G0, r0, arg1, ARITH_SUBCC); tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC);
/* will become: /* will become:
be label1 */ be label1 */
@ -752,40 +754,8 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
/* mov (delay slot) */ /* mov (delay slot) */
tcg_out_mov(s, arg0, addr_reg); tcg_out_mov(s, arg0, addr_reg);
/* arg1 = sign_extend(data_reg); */
switch(opc) {
case 0 | 4:
/* sll data_reg, 24/56, arg1 */
tcg_out_arithi(s, arg1, data_reg, sizeof(tcg_target_long) * 8 - 8, SHIFT_SLL);
/* sra arg1, 24/56, arg1 */
tcg_out_arithi(s, arg1, arg1, sizeof(tcg_target_long) * 8 - 8,
SHIFT_SRA);
break;
case 1 | 4:
/* sll data_reg, 16/48, arg1 */
tcg_out_arithi(s, data_reg, arg1, sizeof(tcg_target_long) * 8 - 16, SHIFT_SLL);
/* sra arg1, 16/48, arg1 */
tcg_out_arithi(s, arg1, arg1, sizeof(tcg_target_long) * 8 - 16,
SHIFT_SRA);
break;
case 2 | 4:
/* sll data_reg, 32, arg1 */
tcg_out_arithi(s, data_reg, arg1, 32, SHIFT_SLL);
/* sra arg1, 32, arg1 */
tcg_out_arithi(s, arg1, arg1, 32, SHIFT_SRA);
break;
case 0:
case 1:
case 2:
case 3:
default:
/* mov */
tcg_out_mov(s, arg1, data_reg);
break;
}
/* mov */ /* mov */
tcg_out_mov(s, arg0, addr_reg); tcg_out_mov(s, arg1, data_reg);
/* XXX: move that code at the end of the TB */ /* XXX: move that code at the end of the TB */
/* qemu_st_helper[s_bits](arg0, arg1, arg2) */ /* qemu_st_helper[s_bits](arg0, arg1, arg2) */
@ -808,46 +778,46 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
INSN_OFF22((unsigned long)s->code_ptr - INSN_OFF22((unsigned long)s->code_ptr -
(unsigned long)label1_ptr)); (unsigned long)label1_ptr));
/* ld [r1 + x], r1 */ /* ld [arg1 + x], arg1 */
tcg_out_ldst(s, arg1, r1, offsetof(CPUTLBEntry, addend) - tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) -
offsetof(CPUTLBEntry, addr_write), host_ld_op); offsetof(CPUTLBEntry, addr_write), host_ld_op);
/* add r0, r1, r0 */ /* add addr_reg, arg1, arg0 */
tcg_out_arith(s, r0, arg1, r0, ARITH_ADD); tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD);
#else #else
r0 = addr_reg; arg0 = addr_reg;
#endif #endif
switch(opc) { switch(opc) {
case 0: case 0:
/* stb data_reg, [r0] */ /* stb data_reg, [arg0] */
tcg_out_ldst(s, data_reg, r0, 0, STB); tcg_out_ldst(s, data_reg, arg0, 0, STB);
break; break;
case 1: case 1:
#ifdef TARGET_WORDS_BIGENDIAN #ifdef TARGET_WORDS_BIGENDIAN
/* sth data_reg, [r0] */ /* sth data_reg, [arg0] */
tcg_out_ldst(s, data_reg, r0, 0, STH); tcg_out_ldst(s, data_reg, arg0, 0, STH);
#else #else
/* stha data_reg, [r0] ASI_PRIMARY_LITTLE */ /* stha data_reg, [arg0] ASI_PRIMARY_LITTLE */
tcg_out_ldst_asi(s, data_reg, r0, 0, STHA, ASI_PRIMARY_LITTLE); tcg_out_ldst_asi(s, data_reg, arg0, 0, STHA, ASI_PRIMARY_LITTLE);
#endif #endif
break; break;
case 2: case 2:
#ifdef TARGET_WORDS_BIGENDIAN #ifdef TARGET_WORDS_BIGENDIAN
/* stw data_reg, [r0] */ /* stw data_reg, [arg0] */
tcg_out_ldst(s, data_reg, r0, 0, STW); tcg_out_ldst(s, data_reg, arg0, 0, STW);
#else #else
/* stwa data_reg, [r0] ASI_PRIMARY_LITTLE */ /* stwa data_reg, [arg0] ASI_PRIMARY_LITTLE */
tcg_out_ldst_asi(s, data_reg, r0, 0, STWA, ASI_PRIMARY_LITTLE); tcg_out_ldst_asi(s, data_reg, arg0, 0, STWA, ASI_PRIMARY_LITTLE);
#endif #endif
break; break;
case 3: case 3:
#ifdef TARGET_WORDS_BIGENDIAN #ifdef TARGET_WORDS_BIGENDIAN
/* stx data_reg, [r0] */ /* stx data_reg, [arg0] */
tcg_out_ldst(s, data_reg, r0, 0, STX); tcg_out_ldst(s, data_reg, arg0, 0, STX);
#else #else
/* stxa data_reg, [r0] ASI_PRIMARY_LITTLE */ /* stxa data_reg, [arg0] ASI_PRIMARY_LITTLE */
tcg_out_ldst_asi(s, data_reg, r0, 0, STXA, ASI_PRIMARY_LITTLE); tcg_out_ldst_asi(s, data_reg, arg0, 0, STXA, ASI_PRIMARY_LITTLE);
#endif #endif
break; break;
default: default:
@ -1164,6 +1134,8 @@ static const TCGTargetOpDef sparc_op_defs[] = {
{ INDEX_op_st16_i64, { "r", "r" } }, { INDEX_op_st16_i64, { "r", "r" } },
{ INDEX_op_st32_i64, { "r", "r" } }, { INDEX_op_st32_i64, { "r", "r" } },
{ INDEX_op_st_i64, { "r", "r" } }, { INDEX_op_st_i64, { "r", "r" } },
{ INDEX_op_qemu_ld64, { "L", "L" } },
{ INDEX_op_qemu_st64, { "L", "L" } },
{ INDEX_op_add_i64, { "r", "r", "rJ" } }, { INDEX_op_add_i64, { "r", "r", "rJ" } },
{ INDEX_op_mul_i64, { "r", "r", "rJ" } }, { INDEX_op_mul_i64, { "r", "r", "rJ" } },