GBA Memory: Optimize stall code

This commit is contained in:
Jeffrey Pfau 2015-06-28 22:39:52 -07:00
parent 9bee2f4cd3
commit 0772fc4967
1 changed files with 10 additions and 5 deletions

View File

@ -1529,7 +1529,7 @@ int32_t GBAMemoryStall(struct ARMCore* cpu, int32_t wait) {
struct GBA* gba = (struct GBA*) cpu->master; struct GBA* gba = (struct GBA*) cpu->master;
struct GBAMemory* memory = &gba->memory; struct GBAMemory* memory = &gba->memory;
if (!memory->prefetch || memory->activeRegion < REGION_CART0) { if (memory->activeRegion < REGION_CART0 || !memory->prefetch) {
// The wait is the stall // The wait is the stall
return wait; return wait;
} }
@ -1543,14 +1543,19 @@ int32_t GBAMemoryStall(struct ARMCore* cpu, int32_t wait) {
int32_t previousLoads = 0; int32_t previousLoads = 0;
// Don't prefetch too much if we're overlapping with a previous prefetch // Don't prefetch too much if we're overlapping with a previous prefetch
if (UNLIKELY((memory->lastPrefetchedPc - cpu->gprs[ARM_PC]) < memory->lastPrefetchedLoads * WORD_SIZE_THUMB)) { uint32_t dist = (memory->lastPrefetchedPc - cpu->gprs[ARM_PC]) >> 1;
previousLoads = (memory->lastPrefetchedPc - cpu->gprs[ARM_PC]) >> 1; if (dist < memory->lastPrefetchedLoads) {
previousLoads = dist;
} }
while (stall < wait && LIKELY(loads + previousLoads < 8)) { while (stall < wait) {
stall += s; stall += s;
++loads; ++loads;
} }
if (stall > wait && loads == 1) { if (loads + previousLoads > 8) {
int diff = (loads + previousLoads) - 8;
loads -= diff;
stall -= s * diff;
} else if (stall > wait && loads == 1) {
// We might need to stall a bit extra if we haven't finished the first S cycle // We might need to stall a bit extra if we haven't finished the first S cycle
wait = stall; wait = stall;
} }