Re:Beautiful branchless binary search
by berkut on Friday April 28, 2023 @03:12AM
(#35738413)
Yeah, it's mildly annoying there's no (at least to my knowledge?) compiler hint like the '__builtin_expect' ones to tell compilers that the values are very unlikely going to be predictable with enough accuracy to allow the branch predictors to be useful in general, and to use a cmov instead of the traditional branching instructions because of this.
[ Parent
| on HN ]
clang has __builtin_unpredictable [0]
[0] https://clang.llvm.org/docs/LanguageExtensions.html#builtin-...
Oooooh :)
Thanks!
It does, but unfortunately it doesn't always work. For example (note the -march=broadwell option):