mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 07:17:45 -04:00
32x: drc: first implementation finished, no more interpreter dep
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@832 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
4b315c210a
commit
f0d7b1faa1
11 changed files with 397 additions and 161 deletions
|
@ -189,8 +189,11 @@
|
|||
|
||||
#define EOP_BX(rm) EOP_C_BX(A_COND_AL,rm)
|
||||
|
||||
#define EOP_C_B_PTR(ptr,cond,l,signed_immed_24) \
|
||||
EMIT_PTR(ptr, ((cond)<<28) | 0x0a000000 | ((l)<<24) | (signed_immed_24))
|
||||
|
||||
#define EOP_C_B(cond,l,signed_immed_24) \
|
||||
EMIT(((cond)<<28) | 0x0a000000 | ((l)<<24) | (signed_immed_24))
|
||||
EOP_C_B_PTR(tcache_ptr,cond,l,signed_immed_24)
|
||||
|
||||
#define EOP_B( signed_immed_24) EOP_C_B(A_COND_AL,0,signed_immed_24)
|
||||
#define EOP_BL(signed_immed_24) EOP_C_B(A_COND_AL,1,signed_immed_24)
|
||||
|
@ -205,6 +208,9 @@
|
|||
#define EOP_C_SMULL(cond,s,rdhi,rdlo,rs,rm) \
|
||||
EMIT(((cond)<<28) | 0x00c00000 | ((s)<<20) | ((rdhi)<<16) | ((rdlo)<<12) | ((rs)<<8) | 0x90 | (rm))
|
||||
|
||||
#define EOP_C_SMLAL(cond,s,rdhi,rdlo,rs,rm) \
|
||||
EMIT(((cond)<<28) | 0x00e00000 | ((s)<<20) | ((rdhi)<<16) | ((rdlo)<<12) | ((rs)<<8) | 0x90 | (rm))
|
||||
|
||||
#define EOP_MUL(rd,rm,rs) EOP_C_MUL(A_COND_AL,0,rd,rs,rm) // note: rd != rm
|
||||
|
||||
#define EOP_C_MRS(cond,rd) \
|
||||
|
@ -308,6 +314,15 @@ static int emith_xbranch(int cond, void *target, int is_call)
|
|||
#define emith_eor_r_r_r_lsl(d, s1, s2, lslimm) \
|
||||
EOP_EOR_REG(A_COND_AL,0,d,s1,s2,A_AM1_LSL,lslimm)
|
||||
|
||||
#define emith_eor_r_r_r_lsr(d, s1, s2, lsrimm) \
|
||||
EOP_EOR_REG(A_COND_AL,0,d,s1,s2,A_AM1_LSR,lsrimm)
|
||||
|
||||
#define emith_or_r_r_lsl(d, s, lslimm) \
|
||||
emith_or_r_r_r_lsl(d, d, s, lslimm)
|
||||
|
||||
#define emith_eor_r_r_lsr(d, s, lsrimm) \
|
||||
emith_eor_r_r_r_lsr(d, d, s, lsrimm)
|
||||
|
||||
#define emith_or_r_r_r(d, s1, s2) \
|
||||
emith_or_r_r_r_lsl(d, s1, s2, 0)
|
||||
|
||||
|
@ -390,6 +405,9 @@ static int emith_xbranch(int cond, void *target, int is_call)
|
|||
#define emith_or_r_imm_c(cond, r, imm) \
|
||||
emith_op_imm(cond, 0, A_OP_ORR, r, imm)
|
||||
|
||||
#define emith_eor_r_imm_c(cond, r, imm) \
|
||||
emith_op_imm(cond, 0, A_OP_EOR, r, imm)
|
||||
|
||||
#define emith_bic_r_imm_c(cond, r, imm) \
|
||||
emith_op_imm(cond, 0, A_OP_BIC, r, imm)
|
||||
|
||||
|
@ -459,6 +477,9 @@ static int emith_xbranch(int cond, void *target, int is_call)
|
|||
#define emith_mul_s64(dlo, dhi, s1, s2) \
|
||||
EOP_C_SMULL(A_COND_AL,0,dhi,dlo,s1,s2)
|
||||
|
||||
#define emith_mula_s64(dlo, dhi, s1, s2) \
|
||||
EOP_C_SMLAL(A_COND_AL,0,dhi,dlo,s1,s2)
|
||||
|
||||
// misc
|
||||
#define emith_ctx_read(r, offs) \
|
||||
EOP_LDR_IMM(r, CONTEXT_REG, offs)
|
||||
|
@ -466,27 +487,42 @@ static int emith_xbranch(int cond, void *target, int is_call)
|
|||
#define emith_ctx_write(r, offs) \
|
||||
EOP_STR_IMM(r, CONTEXT_REG, offs)
|
||||
|
||||
#define emith_clear_msb(d, s, count) { \
|
||||
#define emith_clear_msb_c(cond, d, s, count) { \
|
||||
u32 t; \
|
||||
if ((count) <= 8) { \
|
||||
t = (count) - 8; \
|
||||
t = (0xff << t) & 0xff; \
|
||||
EOP_BIC_IMM(d,s,8/2,t); \
|
||||
EOP_C_DOP_IMM(cond,A_OP_BIC,0,s,d,8/2,t); \
|
||||
} else if ((count) >= 24) { \
|
||||
t = (count) - 24; \
|
||||
t = 0xff >> t; \
|
||||
EOP_AND_IMM(d,s,0,t); \
|
||||
EOP_C_DOP_IMM(cond,A_OP_AND,0,s,d,0,t); \
|
||||
} else { \
|
||||
EOP_MOV_REG_LSL(d,s,count); \
|
||||
EOP_MOV_REG_LSR(d,d,count); \
|
||||
EOP_MOV_REG(cond,0,d,s,A_AM1_LSL,count); \
|
||||
EOP_MOV_REG(cond,0,d,d,A_AM1_LSR,count); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define emith_clear_msb(d, s, count) \
|
||||
emith_clear_msb_c(A_COND_AL, d, s, count)
|
||||
|
||||
#define emith_sext(d, s, bits) { \
|
||||
EOP_MOV_REG_LSL(d,s,32 - (bits)); \
|
||||
EOP_MOV_REG_ASR(d,d,32 - (bits)); \
|
||||
}
|
||||
|
||||
#define JMP_POS(ptr) \
|
||||
ptr = tcache_ptr; \
|
||||
tcache_ptr += sizeof(u32)
|
||||
|
||||
#define JMP_EMIT(cond, ptr) { \
|
||||
int val = (u32 *)tcache_ptr - (u32 *)(ptr) - 2; \
|
||||
EOP_C_B_PTR(ptr, cond, 0, val & 0xffffff); \
|
||||
}
|
||||
|
||||
// _r_r
|
||||
// put bit0 of r0 to carry
|
||||
#define emith_set_carry(r0) \
|
||||
EOP_TST_REG(A_COND_AL,r0,r0,A_AM1_LSR,1) /* shift out to carry */ \
|
||||
|
@ -564,3 +600,24 @@ static int emith_xbranch(int cond, void *target, int is_call)
|
|||
emith_bic_r_imm_c(A_COND_CC, srr, 1); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* if Q
|
||||
* t = carry(Rn += Rm)
|
||||
* else
|
||||
* t = carry(Rn -= Rm)
|
||||
* T ^= t
|
||||
*/
|
||||
#define emith_sh2_div1_step(rn, rm, sr) { \
|
||||
void *jmp0, *jmp1; \
|
||||
emith_tst_r_imm(sr, Q); /* if (Q ^ M) */ \
|
||||
JMP_POS(jmp0); /* beq do_sub */ \
|
||||
emith_addf_r_r(rn, rm); \
|
||||
emith_eor_r_imm_c(A_COND_CS, sr, T); \
|
||||
JMP_POS(jmp1); /* b done */ \
|
||||
JMP_EMIT(A_COND_EQ, jmp0); /* do_sub: */ \
|
||||
emith_subf_r_r(rn, rm); \
|
||||
emith_eor_r_imm_c(A_COND_CC, sr, T); \
|
||||
JMP_EMIT(A_COND_AL, jmp1); /* done: */ \
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* note about silly things like emith_or_r_r_r_lsl:
|
||||
* note about silly things like emith_eor_r_r_r:
|
||||
* these are here because the compiler was designed
|
||||
* for ARM as it's primary target.
|
||||
*/
|
||||
|
@ -9,6 +9,7 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
|
|||
|
||||
#define CONTEXT_REG xBP
|
||||
|
||||
#define IOP_JMP 0xeb
|
||||
#define IOP_JO 0x70
|
||||
#define IOP_JNO 0x71
|
||||
#define IOP_JB 0x72
|
||||
|
@ -56,6 +57,9 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
|
|||
#define EMIT_MODRM(mod,r,rm) \
|
||||
EMIT(((mod)<<6) | ((r)<<3) | (rm), u8)
|
||||
|
||||
#define EMIT_SIB(scale,index,base) \
|
||||
EMIT(((scale)<<6) | ((index)<<3) | (base), u8)
|
||||
|
||||
#define EMIT_OP_MODRM(op,mod,r,rm) { \
|
||||
EMIT_OP(op); \
|
||||
EMIT_MODRM(mod, r, rm); \
|
||||
|
@ -139,14 +143,22 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
|
|||
} \
|
||||
}
|
||||
|
||||
#define emith_or_r_r_r_lsl(d, s1, s2, lslimm) { \
|
||||
// _r_r_shift
|
||||
#define emith_or_r_r_lsl(d, s, lslimm) { \
|
||||
int tmp_ = rcache_get_tmp(); \
|
||||
emith_lsl(tmp_, s2, lslimm); \
|
||||
emith_or_r_r(tmp_, s1); \
|
||||
emith_move_r_r(d, tmp_); \
|
||||
emith_lsl(tmp_, s, lslimm); \
|
||||
emith_or_r_r(d, tmp_); \
|
||||
rcache_free_tmp(tmp_); \
|
||||
}
|
||||
|
||||
// d != s
|
||||
#define emith_eor_r_r_lsr(d, s, lsrimm) { \
|
||||
emith_push(s); \
|
||||
emith_lsr(s, s, lsrimm); \
|
||||
emith_eor_r_r(d, s); \
|
||||
emith_pop(s); \
|
||||
}
|
||||
|
||||
// _r_imm
|
||||
#define emith_move_r_imm(r, imm) { \
|
||||
EMIT_OP(0xb8 + (r)); \
|
||||
|
@ -200,6 +212,11 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
|
|||
emith_or_r_imm(r, imm); \
|
||||
}
|
||||
|
||||
#define emith_eor_r_imm_c(cond, r, imm) { \
|
||||
(void)(cond); \
|
||||
emith_eor_r_imm(r, imm); \
|
||||
}
|
||||
|
||||
#define emith_sub_r_imm_c(cond, r, imm) { \
|
||||
(void)(cond); \
|
||||
emith_sub_r_imm(r, imm); \
|
||||
|
@ -264,11 +281,22 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
|
|||
emith_and_r_imm(d, t); \
|
||||
}
|
||||
|
||||
#define emith_clear_msb_c(cond, d, s, count) { \
|
||||
(void)(cond); \
|
||||
emith_clear_msb(d, s, count); \
|
||||
}
|
||||
|
||||
#define emith_sext(d, s, bits) { \
|
||||
emith_lsl(d, s, 32 - (bits)); \
|
||||
emith_asr(d, d, 32 - (bits)); \
|
||||
}
|
||||
|
||||
#define emith_setc(r) { \
|
||||
EMIT_OP(0x0f); \
|
||||
EMIT(0x92, u8); \
|
||||
EMIT_MODRM(3, 0, r); /* SETC r */ \
|
||||
}
|
||||
|
||||
// put bit0 of r0 to carry
|
||||
#define emith_set_carry(r0) { \
|
||||
emith_tst_r_imm(r0, 1); /* clears C */ \
|
||||
|
@ -318,6 +346,19 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
|
|||
#define emith_mul(d, s1, s2) \
|
||||
emith_mul_(4, d, -1, s1, s2)
|
||||
|
||||
// (dlo,dhi) += signed(s1) * signed(s2)
|
||||
#define emith_mula_s64(dlo, dhi, s1, s2) { \
|
||||
emith_push(dhi); \
|
||||
emith_push(dlo); \
|
||||
emith_mul_(5, dlo, dhi, s1, s2); \
|
||||
EMIT_OP_MODRM(0x03, 0, dlo, 4); \
|
||||
EMIT_SIB(0, 4, 4); /* add dlo, [esp] */ \
|
||||
EMIT_OP_MODRM(0x13, 1, dhi, 4); \
|
||||
EMIT_SIB(0, 4, 4); \
|
||||
EMIT(4, u8); /* adc dhi, [esp+4] */ \
|
||||
emith_add_r_imm(xSP, 4*2); \
|
||||
}
|
||||
|
||||
// "flag" instructions are the same
|
||||
#define emith_subf_r_imm emith_sub_r_imm
|
||||
#define emith_addf_r_r emith_add_r_r
|
||||
|
@ -357,6 +398,9 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
|
|||
EMIT(disp, u32); \
|
||||
}
|
||||
|
||||
#define emith_call_cond(cond, ptr) \
|
||||
emith_call(ptr)
|
||||
|
||||
// "simple" or "short" jump
|
||||
#define EMITH_SJMP_START(cond) { \
|
||||
u8 *cond_ptr; \
|
||||
|
@ -429,11 +473,31 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI };
|
|||
|
||||
#define emith_carry_to_t(srr, is_sub) { \
|
||||
int tmp_ = rcache_get_tmp(); \
|
||||
EMIT_OP(0x0f); \
|
||||
EMIT(0x92, u8); \
|
||||
EMIT_MODRM(3, 0, tmp_); /* SETC */ \
|
||||
emith_setc(tmp_); \
|
||||
emith_bic_r_imm(srr, 1); \
|
||||
EMIT_OP_MODRM(0x08, 3, tmp_, srr); /* OR srrl, tmpl */ \
|
||||
rcache_free_tmp(tmp_); \
|
||||
}
|
||||
|
||||
/*
|
||||
* if Q
|
||||
* t = carry(Rn += Rm)
|
||||
* else
|
||||
* t = carry(Rn -= Rm)
|
||||
* T ^= t
|
||||
*/
|
||||
#define emith_sh2_div1_step(rn, rm, sr) { \
|
||||
u8 *jmp0, *jmp1; \
|
||||
int tmp_ = rcache_get_tmp(); \
|
||||
emith_tst_r_imm(sr, Q); /* if (Q ^ M) */ \
|
||||
JMP8_POS(jmp0); /* je do_sub */ \
|
||||
emith_add_r_r(rn, rm); \
|
||||
JMP8_POS(jmp1); /* jmp done */ \
|
||||
JMP8_EMIT(IOP_JE, jmp0); /* do_sub: */ \
|
||||
emith_sub_r_r(rn, rm); \
|
||||
JMP8_EMIT(IOP_JMP, jmp1);/* done: */ \
|
||||
emith_setc(tmp_); \
|
||||
EMIT_OP_MODRM(0x30, 3, tmp_, sr); /* T = Q1 ^ Q2 (byte) */ \
|
||||
rcache_free_tmp(tmp_); \
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue