I propose a whole refactoring by using bitwise | and & instead of logical || and && for all booleans related conditionals.
This drastically reduces the number of branches, but ultimately has to be benchmarked.
It is something that the compiler can do, but almost never does, because of short circuiting behavior.
In reality, in most real world HPC scenarios, sacrificing short circuiting for a branchless option is almost always better.
This solution works in every architecture.
Example:
if (var1 == true && var2 == false)
Becomes
if ((var1 == true) & (var2 == false))
I argue that it is not harder to read, it just needs an extra parenthesis.
I propose a whole refactoring by using bitwise
|and&instead of logical||and&&for all booleans related conditionals.This drastically reduces the number of branches, but ultimately has to be benchmarked.
It is something that the compiler can do, but almost never does, because of short circuiting behavior.
In reality, in most real world HPC scenarios, sacrificing short circuiting for a branchless option is almost always better.
This solution works in every architecture.
Example:
if (var1 == true && var2 == false)Becomes
if ((var1 == true) & (var2 == false))I argue that it is not harder to read, it just needs an extra parenthesis.