mirror of https://github.com/mgba-emu/mgba.git
GBA Memory: Optimize stalling behavior
This commit is contained in:
parent
2ed7d51376
commit
5b740518cf
1
CHANGES
1
CHANGES
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue