Mesa (master): gallium/util: add util_last_bit64
Marek Olšák
mareko at kemper.freedesktop.org
Sun Jun 14 18:19:51 UTC 2015
Module: Mesa
Branch: master
Commit: b0a2280e45e5abc56e5301f84f33226469000d6c
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b0a2280e45e5abc56e5301f84f33226469000d6c
Author: Marek Olšák <marek.olsak at amd.com>
Date: Sun May 10 20:35:15 2015 +0200
gallium/util: add util_last_bit64
This will be needed by radeonsi.
Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
src/gallium/auxiliary/util/u_math.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 58070a9..3b4040f 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.
More information about the mesa-commit
mailing list