Eeems-Org / remarkable-gameboy

Gameboy emulator for the reMarkable tablet
MIT License
5 stars 1 forks source link

Optimization passes on libqboy #6

Open Eeems opened 10 months ago

Eeems commented 10 months ago

The CPU utilization for running this is near 100% on a rM1, so it may be worth looking to see if there is any low-hanging fruit for quick optimizations in libqboy. Maybe @calc84maniac would have some insight, since he's written several gameboy emulators on much more limited platforms.

Eeems commented 10 months ago

The first thing that stands out is the following: https://github.com/Eeems-Org/remarkable-gameboy/blob/89aff2dc1ec4b595e10ad0cbe50ab908ae5245e1/src/vendor/libqboy/z80register.cpp#L42-L51 https://github.com/Eeems-Org/remarkable-gameboy/blob/89aff2dc1ec4b595e10ad0cbe50ab908ae5245e1/src/vendor/libqboy/z80register.cpp#L61-L69

These should really be macros.

calc84maniac commented 10 months ago

Frankly there's a lot that stands out, I mean I could help optimize it but I'm going to hate every bit of code I look at here 😅

Eeems commented 10 months ago

https://github.com/Eeems-Org/remarkable-gameboy/blob/89aff2dc1ec4b595e10ad0cbe50ab908ae5245e1/src/vendor/libqboy/gbgpu.cpp#L155 This should be an array instead of a vector

Eeems commented 10 months ago

image i.e. gbgpu::preprocessram() and gbgpu::postprocessram() should be replaced by interfaces to the memory mapped registers that just keep themselves up to date as part of the main cpu cycle.

Eeems commented 10 months ago

https://github.com/Eeems-Org/remarkable-gameboy/blob/89aff2dc1ec4b595e10ad0cbe50ab908ae5245e1/src/vendor/libqboy/z80.cpp#L63-L73 ~If (interrupt_occured & interrupt_enabled & 0x1F) == 0 exit loop early.~

EDIT: This is resolved


for all the places there are things like mmu->readbyte(0xFF0F), it might be good to expose a function on the mmu object that accesses directly instead of going down through the two-layer switch statement just to figure out that value is in the 0xFFxx range

calc84maniac commented 10 months ago

If (interrupt_occured & interrupt_enabled & 0x1F) == 0 exit loop early.

Or actually, exit the function before the loop even starts