aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/bits.h
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-28 10:58:14 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-28 10:58:14 +0100
commit3bc348f6eea9b74fa93e72ea77e70b05a29b97eb (patch)
treee547a945fd6e6a59645ac542829b5f285e1e7cc5 /bits.h
parentf50c482ebabe3572cdd8a97d8b51ca94e44aba3a (diff)
parentcafabc769e77f14e47ab44866b304e51af42c44c (diff)
downloadsparse-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.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/bits.h b/bits.h
index c0dc952e..9908190d 100644
--- a/bits.h
+++ b/bits.h
@@ -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