summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util
diff options
context:
space:
mode:
authorMathias Fröhlich <[email protected]>2016-06-09 06:35:34 +0200
committerMathias Fröhlich <[email protected]>2016-06-14 05:19:10 +0200
commitc3b66566760dd44eaeed9e4df13687dc3ee69bd9 (patch)
treebf72312b4b8cf9e9c5b31909c5a866b8a3c08343 /src/gallium/auxiliary/util
parentfafe026dbe0680c971bf3ba2452954eea84287f2 (diff)
mesa/gallium: Move u_bit_scan{,64} from gallium to util.
The functions are also useful for mesa. Introduce src/util/bitscan.{h,c}. Move ffs function implementations from src/mesa/main/imports.{h,c}. Move bit scan related functions from src/gallium/auxiliary/util/u_math.h. Merge platform handling with what is available from within mesa. v2: Try to fix MSVC compile. Reviewed-by: Brian Paul <[email protected]> Tested-by: Brian Paul <[email protected]> Signed-off-by: Mathias Fröhlich <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r--src/gallium/auxiliary/util/u_math.h149
1 files changed, 1 insertions, 148 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index ecb1d636fcc..c94967e8a42 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -46,14 +46,7 @@
#include <float.h>
#include <stdarg.h>
-#ifdef PIPE_OS_UNIX
-#include <strings.h> /* for ffs */
-#endif
-
-#if defined(_MSC_VER)
-#include <intrin.h>
-#endif
-
+#include "util/bitscan.h"
#ifdef __cplusplus
extern "C" {
@@ -354,80 +347,6 @@ util_half_inf_sign(int16_t x)
/**
- * Find first bit set in word. Least significant bit is 1.
- * Return 0 if no bits set.
- */
-#ifndef FFS_DEFINED
-#define FFS_DEFINED 1
-
-#if defined(_MSC_VER) && (_M_IX86 || _M_AMD64 || _M_IA64)
-static inline
-unsigned long ffs( unsigned long u )
-{
- unsigned long i;
- if (_BitScanForward(&i, u))
- return i + 1;
- else
- return 0;
-}
-#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
-static inline
-unsigned ffs( unsigned u )
-{
- unsigned i;
-
- if (u == 0) {
- return 0;
- }
-
- __asm bsf eax, [u]
- __asm inc eax
- __asm mov [i], eax
-
- return i;
-}
-#elif defined(__MINGW32__) || defined(PIPE_OS_ANDROID) || \
- defined(HAVE___BUILTIN_FFS)
-#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 */
-
-/**
- * Find first bit set in long long. Least significant bit is 1.
- * Return 0 if no bits set.
- */
-#ifndef FFSLL_DEFINED
-#define FFSLL_DEFINED 1
-
-#if defined(__MINGW32__) || defined(PIPE_OS_ANDROID) || \
- defined(HAVE___BUILTIN_FFSLL)
-#define ffsll __builtin_ffsll
-#endif
-
-#endif /* FFSLL_DEFINED */
-
-/**
* Find last bit set in a word. The least significant bit is 1.
* Return 0 if no bits are set.
*/
@@ -479,72 +398,6 @@ util_last_bit_signed(int i)
return util_last_bit(~(unsigned)i);
}
-/* Destructively loop over all of the bits in a mask as in:
- *
- * while (mymask) {
- * int i = u_bit_scan(&mymask);
- * ... process element i
- * }
- *
- */
-static inline int
-u_bit_scan(unsigned *mask)
-{
- int i = ffs(*mask) - 1;
- *mask &= ~(1u << i);
- return i;
-}
-
-#ifndef _MSC_VER
-static inline int
-u_bit_scan64(uint64_t *mask)
-{
- int i = ffsll(*mask) - 1;
- *mask &= ~(1llu << i);
- return i;
-}
-#endif
-
-/* For looping over a bitmask when you want to loop over consecutive bits
- * manually, for example:
- *
- * while (mask) {
- * int start, count, i;
- *
- * u_bit_scan_consecutive_range(&mask, &start, &count);
- *
- * for (i = 0; i < count; i++)
- * ... process element (start+i)
- * }
- */
-static inline void
-u_bit_scan_consecutive_range(unsigned *mask, int *start, int *count)
-{
- if (*mask == 0xffffffff) {
- *start = 0;
- *count = 32;
- *mask = 0;
- return;
- }
- *start = ffs(*mask) - 1;
- *count = ffs(~(*mask >> *start)) - 1;
- *mask &= ~(((1u << *count) - 1) << *start);
-}
-
-static inline void
-u_bit_scan_consecutive_range64(uint64_t *mask, int *start, int *count)
-{
- if (*mask == ~0llu) {
- *start = 0;
- *count = 64;
- *mask = 0;
- return;
- }
- *start = ffsll(*mask) - 1;
- *count = ffsll(~(*mask >> *start)) - 1;
- *mask &= ~(((1llu << *count) - 1) << *start);
-}
-
/* Returns a bitfield in which the first count bits starting at start are
* set.
*/