Improve usage of sf_assume

Make the sf_assume also have an effect with clang and help the compiler
proof it's side effect free by comparing against a variable.

https://tests.stockfishchess.org/tests/view/6979d14fa2c75f923be1e681
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 63488 W: 16530 L: 16188 D: 30770
Ptnml(0-2): 167, 6904, 17277, 7212, 184

closes https://github.com/official-stockfish/Stockfish/pull/6573

No functional change
This commit is contained in:
disservin
2026-02-04 17:46:47 +01:00
committed by Joost VandeVondele
parent 542c30c292
commit 9f968446cb
2 changed files with 39 additions and 21 deletions
+9 -1
View File
@@ -444,7 +444,9 @@ void move_to_front(std::vector<T>& vec, Predicate pred) {
#define sf_always_inline
#endif
#if defined(__GNUC__) && !defined(__clang__)
#if defined(__clang__)
#define sf_assume(cond) __builtin_assume(cond)
#elif defined(__GNUC__)
#if __GNUC__ >= 13
#define sf_assume(cond) __attribute__((assume(cond)))
#else
@@ -460,6 +462,12 @@ void move_to_front(std::vector<T>& vec, Predicate pred) {
#define sf_assume(cond)
#endif
#ifdef __GNUC__
#define sf_unreachable() __builtin_unreachable()
#else
#define sf_unreachable()
#endif
} // namespace Stockfish
template<std::size_t N>