mirror of https://github.com/mgba-emu/mgba.git
GBA Memory: Minor prefetch fixes
This commit is contained in:
parent
262cbf046c
commit
2346c2355a
|
@ -452,8 +452,8 @@ void GBATimerUpdateRegister(struct GBA* gba, int timer) {
|
|||
struct GBATimer* currentTimer = &gba->timers[timer];
|
||||
if (currentTimer->enable && !currentTimer->countUp) {
|
||||
int32_t prefetchSkew = 0;
|
||||
if ((gba->memory.lastPrefetchedPc - gba->cpu->gprs[ARM_PC]) < gba->memory.lastPrefetchedLoads * WORD_SIZE_THUMB) {
|
||||
prefetchSkew = (gba->memory.lastPrefetchedPc - gba->cpu->gprs[ARM_PC]) / gba->cpu->memory.activeSeqCycles16;
|
||||
if (gba->memory.lastPrefetchedPc - gba->memory.lastPrefetchedLoads * WORD_SIZE_THUMB >= (uint32_t) gba->cpu->gprs[ARM_PC]) {
|
||||
prefetchSkew = (gba->memory.lastPrefetchedPc - gba->cpu->gprs[ARM_PC]) * (gba->cpu->memory.activeSeqCycles16 + 1) / WORD_SIZE_THUMB;
|
||||
}
|
||||
// Reading this takes two cycles (1N+1I), so let's remove them preemptively
|
||||
gba->memory.io[(REG_TM0CNT_LO + (timer << 2)) >> 1] = currentTimer->oldReload + ((gba->cpu->cycles - currentTimer->lastEvent - 2 + prefetchSkew) >> currentTimer->prescaleBits);
|
||||
|
|
|
@ -235,6 +235,8 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) {
|
|||
}
|
||||
|
||||
gba->lastJump = address;
|
||||
memory->lastPrefetchedPc = 0;
|
||||
memory->lastPrefetchedLoads = 0;
|
||||
if (newRegion == memory->activeRegion && (newRegion < REGION_CART0 || (address & (SIZE_CART0 - 1)) < memory->romSize)) {
|
||||
return;
|
||||
}
|
||||
|
@ -1541,10 +1543,10 @@ int32_t GBAMemoryStall(struct ARMCore* cpu, int32_t wait) {
|
|||
int32_t previousLoads = 0;
|
||||
|
||||
// Don't prefetch too much if we're overlapping with a previous prefetch
|
||||
if ((memory->lastPrefetchedPc - cpu->gprs[ARM_PC]) < memory->lastPrefetchedLoads * WORD_SIZE_THUMB) {
|
||||
if (UNLIKELY((memory->lastPrefetchedPc - cpu->gprs[ARM_PC]) < memory->lastPrefetchedLoads * WORD_SIZE_THUMB)) {
|
||||
previousLoads = (memory->lastPrefetchedPc - cpu->gprs[ARM_PC]) >> 1;
|
||||
}
|
||||
while (stall < wait && loads + previousLoads < 8) {
|
||||
while (stall < wait && LIKELY(loads + previousLoads < 8)) {
|
||||
stall += s;
|
||||
++loads;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue