all repos — mgba @ 5b740518cfd941cfaf4b528c1cf6e158d809df60

mGBA Game Boy Advance Emulator

GBA Memory: Optimize stalling behavior
Jeffrey Pfau jeffrey@endrift.com
Mon, 01 Aug 2016 02:13:02 -0700
commit

5b740518cfd941cfaf4b528c1cf6e158d809df60

parent

2ed7d513762b380fb00abdff521f579ce71b68c8

2 files changed, 18 insertions(+), 15 deletions(-)

jump to
M CHANGESCHANGES

@@ -32,6 +32,7 @@ - 3DS: Use system font for menus

- 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:
M src/gba/memory.csrc/gba/memory.c

@@ -1748,30 +1748,32 @@ // The wait is the stall

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;