mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
sh2, optimizations to innermost run loop
This commit is contained in:
parent
9a02334f3a
commit
2eb213314a
3 changed files with 21 additions and 18 deletions
|
@ -75,6 +75,7 @@ typedef struct SH2_
|
||||||
unsigned int cycles_timeslice;
|
unsigned int cycles_timeslice;
|
||||||
|
|
||||||
struct SH2_ *other_sh2;
|
struct SH2_ *other_sh2;
|
||||||
|
int (*run)(struct SH2_ *, int);
|
||||||
|
|
||||||
// we use 68k reference cycles for easier sync
|
// we use 68k reference cycles for easier sync
|
||||||
unsigned int m68krcycles_done;
|
unsigned int m68krcycles_done;
|
||||||
|
@ -82,7 +83,7 @@ typedef struct SH2_
|
||||||
unsigned int mult_sh2_to_m68k;
|
unsigned int mult_sh2_to_m68k;
|
||||||
|
|
||||||
uint8_t data_array[0x1000]; // cache (can be used as RAM)
|
uint8_t data_array[0x1000]; // cache (can be used as RAM)
|
||||||
uint32_t peri_regs[0x200/4]; // periphereal regs
|
uint32_t peri_regs[0x200/4]; // peripheral regs
|
||||||
} SH2;
|
} SH2;
|
||||||
|
|
||||||
#define CYCLE_MULT_SHIFT 10
|
#define CYCLE_MULT_SHIFT 10
|
||||||
|
@ -103,17 +104,17 @@ void sh2_unpack(SH2 *sh2, const unsigned char *buff);
|
||||||
int sh2_execute_drc(SH2 *sh2c, int cycles);
|
int sh2_execute_drc(SH2 *sh2c, int cycles);
|
||||||
int sh2_execute_interpreter(SH2 *sh2c, int cycles);
|
int sh2_execute_interpreter(SH2 *sh2c, int cycles);
|
||||||
|
|
||||||
static __inline int sh2_execute(SH2 *sh2, int cycles, int use_drc)
|
static __inline void sh2_execute_prepare(SH2 *sh2, int use_drc)
|
||||||
|
{
|
||||||
|
sh2->run = use_drc ? sh2_execute_drc : sh2_execute_interpreter;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline int sh2_execute(SH2 *sh2, int cycles)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
sh2->cycles_timeslice = cycles;
|
sh2->cycles_timeslice = cycles;
|
||||||
#ifdef DRC_SH2
|
ret = sh2->run(sh2, cycles);
|
||||||
if (use_drc)
|
|
||||||
ret = sh2_execute_drc(sh2, cycles);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
ret = sh2_execute_interpreter(sh2, cycles);
|
|
||||||
|
|
||||||
return sh2->cycles_timeslice - ret;
|
return sh2->cycles_timeslice - ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,7 +383,7 @@ static void run_sh2(SH2 *sh2, unsigned int m68k_cycles)
|
||||||
elprintf_sh2(sh2, EL_32X, "+run %u %d @%08x",
|
elprintf_sh2(sh2, EL_32X, "+run %u %d @%08x",
|
||||||
sh2->m68krcycles_done, cycles, sh2->pc);
|
sh2->m68krcycles_done, cycles, sh2->pc);
|
||||||
|
|
||||||
done = sh2_execute(sh2, cycles, PicoIn.opt & POPT_EN_DRC);
|
done = sh2_execute(sh2, cycles);
|
||||||
|
|
||||||
sh2->m68krcycles_done += C_SH2_TO_M68K(sh2, done);
|
sh2->m68krcycles_done += C_SH2_TO_M68K(sh2, done);
|
||||||
sh2->state &= ~SH2_STATE_RUN;
|
sh2->state &= ~SH2_STATE_RUN;
|
||||||
|
@ -499,12 +499,12 @@ void sync_sh2s_normal(unsigned int m68k_target)
|
||||||
pprof_end(msh2);
|
pprof_end(msh2);
|
||||||
|
|
||||||
now = next;
|
now = next;
|
||||||
if (!(msh2.state & SH2_IDLE_STATES)) {
|
if (CYCLES_GT(now, msh2.m68krcycles_done)) {
|
||||||
if (CYCLES_GT(now, msh2.m68krcycles_done))
|
if (!(msh2.state & SH2_IDLE_STATES))
|
||||||
now = msh2.m68krcycles_done;
|
now = msh2.m68krcycles_done;
|
||||||
}
|
}
|
||||||
if (!(ssh2.state & SH2_IDLE_STATES)) {
|
if (CYCLES_GT(now, ssh2.m68krcycles_done)) {
|
||||||
if (CYCLES_GT(now, ssh2.m68krcycles_done))
|
if (!(ssh2.state & SH2_IDLE_STATES))
|
||||||
now = ssh2.m68krcycles_done;
|
now = ssh2.m68krcycles_done;
|
||||||
}
|
}
|
||||||
if (CYCLES_GT(now, timer_cycles+STEP_N)) {
|
if (CYCLES_GT(now, timer_cycles+STEP_N)) {
|
||||||
|
@ -571,6 +571,9 @@ void sync_sh2s_lockstep(unsigned int m68k_target)
|
||||||
|
|
||||||
void PicoFrame32x(void)
|
void PicoFrame32x(void)
|
||||||
{
|
{
|
||||||
|
sh2_execute_prepare(&msh2, PicoIn.opt & POPT_EN_DRC);
|
||||||
|
sh2_execute_prepare(&ssh2, PicoIn.opt & POPT_EN_DRC);
|
||||||
|
|
||||||
Pico.m.scanline = 0;
|
Pico.m.scanline = 0;
|
||||||
|
|
||||||
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_VBLK; // get out of vblank
|
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_VBLK; // get out of vblank
|
||||||
|
|
|
@ -235,11 +235,10 @@ extern SH2 sh2s[2];
|
||||||
# define sh2_pc(sh2) (sh2)->ppc
|
# define sh2_pc(sh2) (sh2)->ppc
|
||||||
#else
|
#else
|
||||||
# define sh2_end_run(sh2, after_) do { \
|
# define sh2_end_run(sh2, after_) do { \
|
||||||
int left_ = (signed int)(sh2)->sr >> 12; \
|
int left_ = ((signed int)(sh2)->sr >> 12) - (after_); \
|
||||||
if (left_ > (after_)) { \
|
if (left_ > 0) { \
|
||||||
(sh2)->cycles_timeslice -= left_ - (after_); \
|
(sh2)->cycles_timeslice -= left_; \
|
||||||
(sh2)->sr &= 0xfff; \
|
(sh2)->sr -= (left_ << 12); \
|
||||||
(sh2)->sr |= (after_) << 12; \
|
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
# define sh2_cycles_left(sh2) ((signed int)(sh2)->sr >> 12)
|
# define sh2_cycles_left(sh2) ((signed int)(sh2)->sr >> 12)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue