GBA Memory: Optimize stalling behavior
Jeffrey Pfau jeffrey@endrift.com
Mon, 01 Aug 2016 02:13:02 -0700
2 files changed,
18 insertions(+),
15 deletions(-)
M
src/gba/memory.c
→
src/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;