deltabeard / Peanut-GB

A Game Boy (DMG) emulator single header library written in C99. Performance is prioritised over accuracy.
https://projects.deltabeard.com/peanutgb/
283 stars 40 forks source link

Add likely/unlikely macros for improved performance #23

Open deltabeard opened 5 years ago

deltabeard commented 5 years ago

Some checks, like the following NULL check, will either always be true or false depending on if the user application is implemented correctly. When using peanut-gb with LCD enabled, this NULL check should never be true, so it's a bit of a waste. https://github.com/deltabeard/Peanut-GB/blob/dad797741c5a100bc7e753ef6baf7eb8ca18ddc4/peanut_gb.h#L1113

The least we can do is use an unlikely(x) macro here, or we could wrap it in an assert.

Peanut-GB should be profiled, and unlikely/likely macros should be used throughout where there is likely to be significant performance gains.

deltabeard commented 1 year ago

Removed the milestone because requires a lot of profiling. It would be nice to have a script that plays a few games in order to generate a profile, and then provide suggestions as to where such macros would be most appropriate.