2 ms·
I think this call for something similar to "__builtin_expect" or linux' likely()/unlikely(). Not very clean, but better than inserting obscure optimisations in
by anthonj 3mo ago
I think this call for something similar to "__builtin_expect" or linux' likely()/unlikely().
Not very clean, but better than inserting obscure optimisations in the source.
- gblargg 3mo agoAssuming compilers are smart enough to insert an unnecessary branch to break the dependency.
- vitally3643 3mo agoThat's what the hints are for. Expect/likely/unlikely are the programmer informing the compiler what it should expect and how it should optimize
- purplesyringa 3mo agoThat would be great, if only it worked as intended! From the perspective of an optimizing compiler, `a == b ? a : b` is worse than `b` regardless of the probability you assign to `a == b`. ETA: someone on Lobsters (https://lobste.rs/s/1an425/quadrupling_code_performance_with#c_4clhdw https://lobste.rs/s/1an425/quadrupling_code_performance_with...) noticed that `[[unlikely]]` actually works on LLVM (not on GCC, and with worse codegen on LLVM, but it's still good to know) -- updated the post.
- MaxBarraclough 3mo agoI was wondering the same thing. Also, could profile-guided optimisation help here?