nukeykt / Nuked-MD

Cycle accurate Mega Drive emulator
GNU General Public License v2.0
146 stars 6 forks source link

Further optimize fm.c. #15

Closed ghost closed 1 year ago

ghost commented 1 year ago

Branching has been reduced in this commit. This commit deals mostly with branching optimizations.

Im pretty sure this cover all the routines that are called upon most frequent, if not let me know and i can optimize other routines within fm.c if this isn't the case.

nukeykt commented 1 year ago

idk. this one seems to hurt code readability too much for a little speed gain

ghost commented 1 year ago

Yes that is a problem with some of these optimizations. Depending on which parts seem too much; i could cherry pick them. Tried to keep somethings within inline routines at an attempt to try and keep it readable. Though i'm pretty sure these are most called routines within the fm chip.

ogamespec commented 1 year ago

You've gone through the whole module. And most of the edits are things that the compiler is already able to do itself. To understand where the slowdowns are, you can use a profiler, and then do spot optimization. Such PR is very difficult to do a review and there is little confidence that nothing will break.

ogamespec commented 1 year ago

@nukeykt I looked at the PR, except for useless refactoring, I didn't see anything of value. @movrsi Can you point out places where optimization was really done, not just reworked for (as you think) optimization by throwing out local variables (which the compiler already knows how to do on its own)?

ogamespec commented 1 year ago

Does it make sense to optimize FM at all? I have shown that FM takes about 2% of performance.

image

nukeykt commented 1 year ago

I redid most important optimization with less code redundancy in this commit def65d7bbfa1edc4712c963b5353a632c4e4c8de. Thank you for the idea for this one. Other optimizations seems are not as important, so I'm closing PR

ghost commented 1 year ago

Understandable, some of the code provided was to clean up things up a bit. next time ill do pr's in batches to prevent such a mess. ill get into the habit of attempting to use macros to prevent redundant code where possible.