sh2 drc, make B/W read functions signed (reduces generated code size)

This commit is contained in:
kub 2019-04-26 18:53:21 +02:00
parent ed7e915078
commit aa4c4cb951
7 changed files with 85 additions and 60 deletions

View file

@ -2354,17 +2354,15 @@ static int emit_memhandler_read_rr(SH2 *sh2, sh2_reg_e rd, sh2_reg_e rs, u32 off
hr2 = hr;
else
#if REMAP_REGISTER
hr2 = rcache_map_reg(rd, hr, size != 2 ? RC_GR_RMW : RC_GR_WRITE);
hr2 = rcache_map_reg(rd, hr, RC_GR_WRITE);
#else
hr2 = rcache_get_reg(rd, RC_GR_WRITE, NULL);
#endif
if (rd != SHR_TMP && size != 2) { // 16, 8
emith_sext(hr2, hr, size ? 16 : 8);
} else if (hr != hr2) // 32
if (hr != hr2) {
emith_move_r_r(hr2, hr);
if (hr != hr2)
rcache_free_tmp(hr);
}
return hr2;
}
@ -2422,21 +2420,19 @@ static int emit_indirect_indexed_read(SH2 *sh2, sh2_reg_e rd, sh2_reg_e rx, sh2_
hr = emit_memhandler_read(size);
size &= MF_SIZEMASK;
if (rd != SHR_TMP)
if (rd == SHR_TMP)
hr2 = hr;
else
#if REMAP_REGISTER
hr2 = rcache_map_reg(rd, hr, size != 2 ? RC_GR_RMW : RC_GR_WRITE);
hr2 = rcache_map_reg(rd, hr, RC_GR_WRITE);
#else
hr2 = rcache_get_reg(rd, RC_GR_WRITE, NULL);
#endif
else
hr2 = hr;
if (rd != SHR_TMP && size != 2) { // 16, 8
emith_sext(hr2, hr, size ? 16 : 8);
} else if (hr != hr2) // 32
if (hr != hr2) {
emith_move_r_r(hr2, hr);
if (hr != hr2)
rcache_free_tmp(hr);
}
return hr2;
}
@ -2991,16 +2987,14 @@ static void REGPARM(2) *sh2_translate(SH2 *sh2, int tcache_id)
}
tmp2 = emit_memhandler_read(opd->size);
#if REMAP_REGISTER
tmp3 = rcache_map_reg(GET_Rn(), tmp2, opd->size != 2 ? RC_GR_RMW : RC_GR_WRITE);
tmp3 = rcache_map_reg(GET_Rn(), tmp2, RC_GR_WRITE);
#else
tmp3 = rcache_get_reg(GET_Rn(), RC_GR_WRITE, NULL);
#endif
if (opd->size != 2) {
emith_sext(tmp3, tmp2, 16);
} else if (tmp3 != tmp2)
if (tmp3 != tmp2) {
emith_move_r_r(tmp3, tmp2);
if (tmp3 != tmp2)
rcache_free_tmp(tmp2);
}
}
goto end_op;
@ -4025,7 +4019,7 @@ static void sh2_generate_utils(void)
EMITH_SJMP_START(DCOND_CS);
emith_and_r_r_c(DCOND_CC, arg0, arg3);
emith_eor_r_imm_c(DCOND_CC, arg0, 1);
emith_read8_r_r_r_c(DCOND_CC, RET_REG, arg0, arg2);
emith_read8s_r_r_r_c(DCOND_CC, RET_REG, arg0, arg2);
emith_ret_c(DCOND_CC);
EMITH_SJMP_END(DCOND_CS);
emith_move_r_r_ptr(arg1, CONTEXT_REG);
@ -4037,7 +4031,7 @@ static void sh2_generate_utils(void)
emith_sh2_rcall(arg0, arg1, arg2, arg3);
EMITH_SJMP_START(DCOND_CS);
emith_and_r_r_c(DCOND_CC, arg0, arg3);
emith_read16_r_r_r_c(DCOND_CC, RET_REG, arg0, arg2);
emith_read16s_r_r_r_c(DCOND_CC, RET_REG, arg0, arg2);
emith_ret_c(DCOND_CC);
EMITH_SJMP_END(DCOND_CS);
emith_move_r_r_ptr(arg1, CONTEXT_REG);

View file

@ -44,10 +44,10 @@ unsigned short scan_block(unsigned int base_pc, int is_slave,
#define _DRC_DECLARE_SR(SR) __DRC_DECLARE_SR(SR)
#define DRC_DECLARE_SR _DRC_DECLARE_SR(DRC_SR_REG)
#define DRC_SAVE_SR(sh2) \
if ((sh2->state & (SH2_STATE_RUN)) == SH2_STATE_RUN) \
if ((sh2->state & (SH2_STATE_RUN|SH2_STATE_SLEEP)) == SH2_STATE_RUN) \
sh2->sr = sh2_sr;
#define DRC_RESTORE_SR(sh2) \
if ((sh2->state & (SH2_STATE_RUN)) == SH2_STATE_RUN) \
if ((sh2->state & (SH2_STATE_RUN|SH2_STATE_SLEEP)) == SH2_STATE_RUN) \
sh2_sr = sh2->sr;
#else
#define DRC_DECLARE_SR

View file

@ -372,7 +372,7 @@ INLINE void BRA(sh2_state *sh2, UINT32 d)
#if BUSY_LOOP_HACKS
if (disp == -2)
{
UINT32 next_opcode = RW( sh2, sh2->ppc & AM );
UINT32 next_opcode = (UINT32)(UINT16)RW( sh2, sh2->ppc & AM );
/* BRA $
* NOP
*/
@ -802,7 +802,7 @@ INLINE void DT(sh2_state *sh2, UINT32 n)
sh2->sr &= ~T;
#if BUSY_LOOP_HACKS
{
UINT32 next_opcode = RW( sh2, sh2->ppc & AM );
UINT32 next_opcode = (UINT32)(UINT16)RW( sh2, sh2->ppc & AM );
/* DT Rn
* BF $-2
*/
@ -1049,12 +1049,12 @@ INLINE void MAC_W(sh2_state *sh2, UINT32 m, UINT32 n)
INT32 tempm, tempn, dest, src, ans;
UINT32 templ;
tempn = (INT32) RW( sh2, sh2->r[n] );
tempn = (INT32)(INT16) RW( sh2, sh2->r[n] );
sh2->r[n] += 2;
tempm = (INT32) RW( sh2, sh2->r[m] );
tempm = (INT32)(INT16) RW( sh2, sh2->r[m] );
sh2->r[m] += 2;
templ = sh2->macl;
tempm = ((INT32) (short) tempn * (INT32) (short) tempm);
tempm = (tempn * tempm);
if ((INT32) sh2->macl >= 0)
dest = 0;
else

View file

@ -121,7 +121,7 @@ int sh2_execute_interpreter(SH2 *sh2, int cycles)
if (sh2->delay)
{
sh2->ppc = sh2->delay;
opcode = RW(sh2, sh2->delay);
opcode = (UINT32)(UINT16)RW(sh2, sh2->delay);
// TODO: more branch types
if ((opcode >> 13) == 5) { // BRA/BSR
@ -139,7 +139,7 @@ int sh2_execute_interpreter(SH2 *sh2, int cycles)
else
{
sh2->ppc = sh2->pc;
opcode = RW(sh2, sh2->pc);
opcode = (UINT32)(UINT16)RW(sh2, sh2->pc);
}
sh2->delay = 0;
@ -232,13 +232,13 @@ int sh2_execute_interpreter(SH2 *sh2, int cycles)
if (sh2->delay)
{
sh2->ppc = sh2->delay;
opcode = RW(sh2, sh2->delay);
opcode = (UINT32)(UINT16)RW(sh2, sh2->delay);
sh2->pc -= 2;
}
else
{
sh2->ppc = sh2->pc;
opcode = RW(sh2, sh2->pc);
opcode = (UINT32)(UINT16)RW(sh2, sh2->pc);
}
sh2->delay = 0;