GBA Memory: Optimize stalling behavior

This commit is contained in:
Jeffrey Pfau 2016-08-01 02:13:02 -07:00
parent 2ed7d51376
commit 5b740518cf
2 changed files with 18 additions and 15 deletions

View File

@ -32,6 +32,7 @@ Misc:
- PSP2: Use system font for menus
- All: Faster memory read/write
- Qt: Make audio channel/video layer options shortcut mappable
- GBA Memory: Optimize stalling behavior
0.4.1: (2016-07-11)
Bugfixes:

View File

@ -1748,30 +1748,32 @@ int32_t GBAMemoryStall(struct ARMCore* cpu, int32_t wait) {
return wait;
}
int32_t previousLoads = 0;
// Don't prefetch too much if we're overlapping with a previous prefetch
uint32_t dist = (memory->lastPrefetchedPc - cpu->gprs[ARM_PC]) >> 1;
if (dist < 8) {
previousLoads = dist;
}
int32_t s = cpu->memory.activeSeqCycles16 + 1;
int32_t n2s = cpu->memory.activeNonseqCycles16 - cpu->memory.activeSeqCycles16 + 1;
// Figure out how many sequential loads we can jam in
int32_t stall = s;
int32_t loads = 1;
int32_t previousLoads = 0;
// Don't prefetch too much if we're overlapping with a previous prefetch
uint32_t dist = (memory->lastPrefetchedPc - cpu->gprs[ARM_PC]) >> 1;
if (dist < memory->lastPrefetchedLoads) {
previousLoads = dist;
}
while (stall < wait) {
stall += s;
++loads;
}
if (loads + previousLoads > 8) {
int diff = (loads + previousLoads) - 8;
loads -= diff;
stall -= s * diff;
} else if (stall > wait && loads == 1) {
if (stall > wait && !previousLoads) {
// We might need to stall a bit extra if we haven't finished the first S cycle
wait = stall;
} else {
while (stall < wait) {
stall += s;
++loads;
}
if (loads + previousLoads > 8) {
loads = 8 - previousLoads;
}
}
// This instruction used to have an N, convert it to an S.
wait -= n2s;