Thanks Bob! I understand about the compiler not knowing about the limits of a case statement. There is an attribute (i think that is what it is called) but I can't remember and I can't find it in my notes or online. It is something like this:bob wrote: ↑Mon Apr 13, 2020 4:26 am Here's the simple answer from a compiler guy. Small functions are just fine. If they SHOULD be inlined, the compiler will do it during the compilation process. If it won't help, it won't. Not inlining can improve cache efficiency if the function is executed infrequently. Better to have the natural instruction stream sequential rather than broken up into blocks with interspaced dead code.
With today's optimizers, you can do pretty well to just write readable code you can understand and work on. Let the compiler do its thing.
For exampleMight be compiled as is. Or if the condition is mostly false, the compiler might turn that into this:Code: Select all
if (condition) { do some stuff }
I used to have to write code like the latter in the early FORTRAN days, the optimizers were not very good. Today the compilers can do this so that your code looks readable, and then gets reorganized when converting from source to object code, leaving the source easy to read.Code: Select all
if (! condition) go to xx); getback: Somewhere else in memory: xx: do some stuff go to getback;
Yes, there are places you might do better. In particular if you have information the compiler doesn't have. IE you know that ALL the cases in your switch statement are covered explicitly. The compiler still has to check for the rest and skip all the way to the closing "}". You don't. That can eliminate instructions.
default:
_unreachable;
That is supposed to give the compiler more information.
Also, in this function board[t][fs] and board[t][ts] is referenced so many times that I was about to create a pointer s32* boardptr = board[t]; and replace board references with boardptr[sq]. Is that a good idea or simply not necessary? Thanks again