all repos — mgba @ ed3a3b2fabac6c9e8b701819762b96f8bb963820

mGBA Game Boy Advance Emulator

Core: A few micro-optimizations
Jeffrey Pfau jeffrey@endrift.com
Mon, 31 Oct 2016 00:08:01 -0700
commit

ed3a3b2fabac6c9e8b701819762b96f8bb963820

parent

2c2a7ca436ed1229a30c07ac45389a0a539e7259

4 files changed, 9 insertions(+), 13 deletions(-)

jump to
M src/core/timing.csrc/core/timing.c

@@ -53,19 +53,19 @@ }

} } -void mTimingTick(struct mTiming* timing, int32_t cycles) { +int32_t mTimingTick(struct mTiming* timing, int32_t cycles) { timing->masterCycles += cycles; uint32_t masterCycles = timing->masterCycles; while (mTimingEventListSize(&timing->events)) { struct mTimingEvent* next = *mTimingEventListGetPointer(&timing->events, 0); int32_t nextWhen = next->when - masterCycles; if (nextWhen > 0) { - *timing->nextEvent = nextWhen; - return; + return nextWhen; } mTimingEventListShift(&timing->events, 0, 1); next->callback(timing, next->context, -nextWhen); } + return *timing->nextEvent; } int32_t mTimingNextEvent(struct mTiming* timing) {
M src/core/timing.hsrc/core/timing.h

@@ -32,7 +32,7 @@ void mTimingDeinit(struct mTiming* timing);

void mTimingClear(struct mTiming* timing); void mTimingSchedule(struct mTiming* timing, struct mTimingEvent*, int32_t when); void mTimingDeschedule(struct mTiming* timing, struct mTimingEvent*); -void mTimingTick(struct mTiming* timing, int32_t cycles); +int32_t mTimingTick(struct mTiming* timing, int32_t cycles); int32_t mTimingNextEvent(struct mTiming* timing); #endif
M src/gb/gb.csrc/gb/gb.c

@@ -546,10 +546,7 @@ nextEvent = gb->eiPending;

} } - mTimingTick(&gb->timing, cycles); - nextEvent = cpu->nextEvent; - - cpu->nextEvent = nextEvent; + cpu->nextEvent = mTimingTick(&gb->timing, cycles); if (cpu->halted) { cpu->cycles = cpu->nextEvent;
M src/gba/gba.csrc/gba/gba.c

@@ -235,8 +235,8 @@ ARMRaiseIRQ(cpu);

gba->springIRQ = 0; } - int32_t nextEvent; - do { + int32_t nextEvent = cpu->nextEvent; + while (cpu->cycles >= nextEvent) { int32_t cycles = cpu->cycles; int32_t testEvent;

@@ -250,8 +250,7 @@ }

#endif nextEvent = cycles; do { - mTimingTick(&gba->timing, nextEvent); - nextEvent = cpu->nextEvent; + nextEvent = mTimingTick(&gba->timing, nextEvent); } while (gba->cpuBlocked); testEvent = GBASIOProcessEvents(&gba->sio, cycles);

@@ -275,7 +274,7 @@ else if (nextEvent < 0) {

mLOG(GBA, FATAL, "Negative cycles will pass: %i", nextEvent); } #endif - } while (cpu->cycles >= nextEvent); + } } void GBAAttachDebugger(struct GBA* gba, struct mDebugger* debugger) {