Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément <clement@Clements-MacBook-Pro.local>2020-09-05 15:04:00 +0300
committerClément <clement@Clements-MacBook-Pro.local>2020-09-05 15:04:00 +0300
commit5265ed7be263f46e1ff7a5ffaeeb0ac6e1ce3015 (patch)
tree528495f4343975284d0ea0eeccf4cb7f57a4edba
parent5b314f884d8ac82cf8a46fd50b650931f431830f (diff)
Math Utils: Add bitscan 64bit version
-rw-r--r--source/blender/blenlib/BLI_math_bits.h2
-rw-r--r--source/blender/blenlib/intern/math_bits_inline.c24
2 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_bits.h b/source/blender/blenlib/BLI_math_bits.h
index b602900bedc..b007dd7cfed 100644
--- a/source/blender/blenlib/BLI_math_bits.h
+++ b/source/blender/blenlib/BLI_math_bits.h
@@ -31,6 +31,7 @@ extern "C" {
/* Search the value from LSB to MSB for a set bit. Returns index of this bit. */
MINLINE int bitscan_forward_i(int a);
MINLINE unsigned int bitscan_forward_uint(unsigned int a);
+MINLINE unsigned int bitscan_forward_uint64(unsigned long long a);
/* Similar to above, but also clears the bit. */
MINLINE int bitscan_forward_clear_i(int *a);
@@ -39,6 +40,7 @@ MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a);
/* Search the value from MSB to LSB for a set bit. Returns index of this bit. */
MINLINE int bitscan_reverse_i(int a);
MINLINE unsigned int bitscan_reverse_uint(unsigned int a);
+MINLINE unsigned int bitscan_reverse_uint64(unsigned long long a);
/* Similar to above, but also clears the bit. */
MINLINE int bitscan_reverse_clear_i(int *a);
diff --git a/source/blender/blenlib/intern/math_bits_inline.c b/source/blender/blenlib/intern/math_bits_inline.c
index e7a7b17e1e4..3a0cea182ba 100644
--- a/source/blender/blenlib/intern/math_bits_inline.c
+++ b/source/blender/blenlib/intern/math_bits_inline.c
@@ -40,6 +40,18 @@ MINLINE unsigned int bitscan_forward_uint(unsigned int a)
#endif
}
+MINLINE unsigned int bitscan_forward_uint64(unsigned long long a)
+{
+ BLI_assert(a != 0);
+#ifdef _MSC_VER
+ unsigned long ctz;
+ _BitScanForward64(&ctz, a);
+ return ctz;
+#else
+ return (unsigned int)__builtin_ctz(a);
+#endif
+}
+
MINLINE int bitscan_forward_i(int a)
{
return (int)bitscan_forward_uint((unsigned int)a);
@@ -69,6 +81,18 @@ MINLINE unsigned int bitscan_reverse_uint(unsigned int a)
#endif
}
+MINLINE unsigned int bitscan_reverse_uint64(unsigned long long a)
+{
+ BLI_assert(a != 0);
+#ifdef _MSC_VER
+ unsigned long clz;
+ _BitScanReverse64(&clz, a);
+ return 31 - clz;
+#else
+ return (unsigned int)__builtin_clzll(a);
+#endif
+}
+
MINLINE int bitscan_reverse_i(int a)
{
return (int)bitscan_reverse_uint((unsigned int)a);