3 comments

[ 1.8 ms ] story [ 17.1 ms ] thread
> However, I’ve found that some compilers, e.g. GCC on x86-64 will refuse to make this variant branchless. I hate how fickle compilers can be sometimes, and I wish compilers exposed not just the likely/unlikely attributes, but also an attribute that allows you to mark something as unpredictable to nudge the compiler towards using branchless techniques like CMOV’s.

Clang has `__builtin_unpredictable`[^1]. Both of the have `__builtin_expect_with_probability` [^2], which could help. But these builtins are fickle/make no guarantees as far as I can tell.

[^1] https://clang.llvm.org/docs/LanguageExtensions.html#builtin-... [^2] https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index...

I wasn't aware of __builtin_unpredictable until yesterday. I was aware of __builtin_expect_with_probability. Unfortunately I've found both of them to be essentially useless with today's compilers.