summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2015-05-10 20:35:15 +0200
committerMarek Olšák <[email protected]>2015-06-14 20:17:29 +0200
commitb0a2280e45e5abc56e5301f84f33226469000d6c (patch)
tree3a35deffae3d70711ca4c0d6fb305802ff224f38 /src/gallium/auxiliary/util
parent2489054f663baa69e659e0878cb39f4e7197ee0b (diff)
gallium/util: add util_last_bit64
This will be needed by radeonsi. Reviewed-by: Ilia Mirkin <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_math.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 58070a9dafa..3b4040f0ee2 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -425,6 +425,25 @@ util_last_bit(unsigned u)
}
/**
+ * Find last bit set in a word. The least significant bit is 1.
+ * Return 0 if no bits are set.
+ */
+static INLINE unsigned
+util_last_bit64(uint64_t u)
+{
+#if defined(HAVE___BUILTIN_CLZLL)
+ return u == 0 ? 0 : 64 - __builtin_clzll(u);
+#else
+ unsigned r = 0;
+ while (u) {
+ r++;
+ u >>= 1;
+ }
+ return r;
+#endif
+}
+
+/**
* Find last bit in a word that does not match the sign bit. The least
* significant bit is 1.
* Return 0 if no bits are set.