diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-11-13 15:13:27 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-11-13 15:13:27 -0500 |
commit | cc7d66416b91e0972c1022d0a835804a63ab7ab1 (patch) | |
tree | 3e5d75ee69c13173b9d0cff315cdc3fbc6de8772 /src/bit.h | |
parent | 32daab769e4c0902255d9e55843eb94c66d7cb33 (diff) | |
download | bfs-cc7d66416b91e0972c1022d0a835804a63ab7ab1.tar.xz |
bit: Implement a branchless has_single_bit()
Diffstat (limited to 'src/bit.h')
-rw-r--r-- | src/bit.h | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -350,7 +350,8 @@ UINT_OVERLOADS(FIRST_TRAILING_ONE) #define HAS_SINGLE_BIT(type, suffix, width) \ static inline bool has_single_bit##suffix(type n) { \ - return n && !(n & (n - 1)); \ + /** Branchless n && !(n & (n - 1)) */ \ + return n - 1 < (n ^ (n - 1)); \ } UINT_OVERLOADS(ROTATE_LEFT) |