diff options
author | Jack Lloyd <[email protected]> | 2018-12-22 08:49:29 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-12-22 08:49:34 -0500 |
commit | e62836000c0883c555cf9da41164f61a287783db (patch) | |
tree | 2e778a785b5963aed524beb213c2b6d695abf5cd /src | |
parent | 480046433becaa5e52ab85dfedf2a1061c78f65b (diff) |
Make high_bit and ctz actually const time
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/utils/bit_ops.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/utils/bit_ops.h b/src/lib/utils/bit_ops.h index 75cefbdfa..bfeebdfb4 100644 --- a/src/lib/utils/bit_ops.h +++ b/src/lib/utils/bit_ops.h @@ -63,7 +63,7 @@ inline size_t high_bit(T n) * it will depend on the compiler and arch. GCC compiles this * function to straight line code on x86-64, Aarch64 and ARM. */ - const size_t z = s * ((n >> s) != 0); + const size_t z = s * ((~ct_is_zero(n >> s)) & 1); hb += z; n >>= z; } @@ -114,12 +114,12 @@ inline size_t ctz(T n) * If n == 0 then this function will compute 8*sizeof(T)-1, so * initialize lb to 1 if n == 0 to produce the expected result. */ - size_t lb = (n == 0); + size_t lb = ct_is_zero(n) & 1; for(size_t s = 8*sizeof(T) / 2; s > 0; s /= 2) { const T mask = (static_cast<T>(1) << s) - 1; - const T n_bits = (n & mask) == 0; + const T n_bits = ct_is_zero(n & mask) & 1; lb += s * n_bits; n >>= s * n_bits; } |