libretro / virtualjaguar-libretro

Hard fork of Virtual Jaguar (abandoned project) to Libretro
31 stars 34 forks source link

[spike] Test ‘register’ keyword #61

Closed JoeMatt closed 1 year ago

JoeMatt commented 2 years ago

C has a register keyword.

There's a few functions/vars that have heavy repeated memory access with small intrinsic types.

Seems like some candidates for optimisation hints.

I actually didn't know about this keyword before so, note to self;

https://www.geeksforgeeks.org/understanding-register-keyword/

There's some controversy if this keyword is useful, but much like const I still think people can outsmart compilers in edge cases. It's worth benchmarking at least, specifically in the register emulation which has some bullshit code already that needs more scrutiny.

FWIW, a recent project to re-compile and optimised Mario64 uses register in some of the replaced OG methods post disassembly.

djipi commented 2 years ago

It can be useful when using the compiler optimization but it depends also on the cpu architecture. The register keyword can provide some hints to the compiler for the registers usage. 'Modern' compiler tends to be good to determine the best course of actions for such usage anyway.

JoeMatt commented 2 years ago

It can be useful when using the compiler optimization but it depends also on the cpu architecture. The register keyword can provide some hints to the compiler for the registers usage. 'Modern' compiler tends to be good to determine the best course of actions for such usage anyway.

Thanks for the info. My interest in this is the fact I got started in virtual jaguar at first because the ARM compiler for iOS was making really poor decisions with bit masks and bit shift operations.

The lack of static, contst etc keywords was one improvement to allow the compiler some room to flex. The fact this core is single threaded I think would benefit from a few vars being forced to register due to their I/O access in critical loops

Doesn't hurt to try, simple enough I just need a good testing/benchmark method to call to be smart with what "optimizations" are actually useful. We use INLINE a lot but technically the compiler can still override use unless we use __inline_always macro.