Comments by "Jeffrey Phipps" (@jeffreyphipps1507) on "Branchless Programming: Why "If" is Sloowww... and what we can do about it!" video.
-
As a CS professor at Uni, I am not pleased with either your initial explanation or you first example. Your initial explanation assumes older processor logic or the use of a non-multicore or multi-threading OS. With the proper OS, it is not necessary to discard a section of code because ALL possible predicted code can be loaded into different threading and/or cores.
As for the example, one should NEVER use multiple return statements. Structured Programming dictates that all structures including functions should be written such that there is only one-entry/one-exit to guarantee no mistakes are made by the compiler (and I've seen students have problems have problems based on this even as late as the last year). Not all compilers properly resolve this issue. This is a common and sloppy thing that I always have to break students of when teaching recursion. The problem is that returning static variables can work, however the returning of dynamic variable might fail and damage the stack.
Switching between upper and lower case without context can be done by logical masking (as you know), but if I am programming in a mid-high level language (and not using the built-in libraries), I don't want to switch to AL just for minimal things.
Simply put, if you're willing to shift to processing that your processor is faster doing to optimize for some reason, that's great - but there needs to be a reason. Also, you didn't mention the one way to massively increase mathematical/logical calculations - GPUs are specifically designed for this. Lastly, swapping branching for multiplication may or may not be efficient. Multiplication takes multiple cycles on some processors.
Having said that, some optimization is worthwhile.
2