diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-28 10:58:14 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-28 10:58:14 +0100 |
| commit | 3bc348f6eea9b74fa93e72ea77e70b05a29b97eb (patch) | |
| tree | e547a945fd6e6a59645ac542829b5f285e1e7cc5 /bits.h | |
| parent | f50c482ebabe3572cdd8a97d8b51ca94e44aba3a (diff) | |
| parent | cafabc769e77f14e47ab44866b304e51af42c44c (diff) | |
| download | sparse-dev-3bc348f6eea9b74fa93e72ea77e70b05a29b97eb.tar.gz | |
Merge branch 'bit-trans' into next
* factorize (x OP1 z) OP2 (y OP1 z) into (x OP2 y) OP1 z
* factorize SHIFT(x, s) OP SHIFT(y, s) into SHIFT((x OP y), s)
* factorize SEL(x, OP(y,z), y) into OP(SEL(x, z, 0), y)
* convert SEL(x & BIT1, BIT2, 0) into SHIFT(x & BIT1, S)
Diffstat (limited to 'bits.h')
| -rw-r--r-- | bits.h | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -58,4 +58,16 @@ static inline long long bits_extend(long long val, unsigned size, int is_signed) return val; } +static inline int is_power_of_2(long long val) +{ + return val && !(val & (val - 1)); +} + +/// +// log base 2 of an exact power-of-2 +static inline int log2_exact(unsigned long long val) +{ + return 8 * sizeof(val) - __builtin_clzl(val) - 1; +} + #endif |
