3 ms·
Something like X = flag ? X : 0; X = test ? X : 0; Vs X |= flag; X |= test; The latter is more obviously branch less. How exactly the two pe
by tedunangst 9y ago
Something like
X = flag ? X : 0;
X = test ? X : 0;
Vs
X |= flag;
X |= test;
The latter is more obviously branch less. How exactly the two perform probably requires some testing.
And somewhat more general point, since we're writing C and not asm, depends how much you want to depend on the compiler to use the right instructions. To backtrack on my point a bit, whether CMOV gets used is an important consideration.
> There's a chance that when inlined into the benchmark Clang uses a CMOV
And a chance it won't. :)