util: added ffsll() function
authorBrian Paul <brianp@vmware.com>
Tue, 1 Sep 2015 22:29:17 +0000 (16:29 -0600)
committerBrian Paul <brianp@vmware.com>
Tue, 1 Sep 2015 22:29:17 +0000 (16:29 -0600)
v2: fix errant _GNU_SOURCE test, per Matt Turner.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
src/gallium/auxiliary/util/u_math.h

index 7175d1d4ee8c08ba63a89c0f13c193719b7b516e..e92f83a8109a5d04331499b8253cf9f50c37120c 100644 (file)
@@ -389,6 +389,26 @@ unsigned ffs( unsigned u )
 #define ffs __builtin_ffs
 #endif
 
+#ifdef HAVE___BUILTIN_FFSLL
+#define ffsll __builtin_ffsll
+#else
+static inline int
+ffsll(long long int val)
+{
+   int bit;
+
+   bit = ffs((unsigned) (val & 0xffffffff));
+   if (bit != 0)
+      return bit;
+
+   bit = ffs((unsigned) (val >> 32));
+   if (bit != 0)
+      return 32 + bit;
+
+   return 0;
+}
+#endif
+
 #endif /* FFS_DEFINED */
 
 /**