3 ms·
Unfortunately these hacks are very compiler-dependent and can become ineffective with a compiler update. Clang in particular is very stubborn about not emitting
by ot 5y ago
Unfortunately these hacks are very compiler-dependent and can become ineffective with a compiler update. Clang in particular is very stubborn about not emitting cmovs (see https://bugs.llvm.org/show_bug.cgi?id=40027 https://bugs.llvm.org/show_bug.cgi?id=40027 for example).
In that thread the annotation __builtin_unpredictable() is discussed, which would be a good solution, but it does not support this case yet.
In my code the only reliable alternative I found was inline ASM. Luckily with enough templating you can hide it away.