summaryrefslogtreecommitdiffstats
path: root/src/H5Vprivate.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Vprivate.h')
-rw-r--r--src/H5Vprivate.h33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/H5Vprivate.h b/src/H5Vprivate.h
index 52f9d6b..55047cb 100644
--- a/src/H5Vprivate.h
+++ b/src/H5Vprivate.h
@@ -300,4 +300,35 @@ H5V_vector_inc(int n, hsize_t *v1, const hsize_t *v2)
while (n--) *v1++ += *v2++;
}
-#endif
+
+/*-------------------------------------------------------------------------
+ * Function: H5V_power_of_two
+ *
+ * Purpose: Determines the log base two of a number (i.e. log2(n)).
+ *
+ * Note: N must be a power of two and is limited to 32-bit quantities.
+
+ * This is from the "Bit Twiddling Hacks" at:
+ * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
+ *
+ * Return: log2(n) (always - no failure condition)
+ *
+ * Programmer: Quincey Koziol
+ * Monday, Febraury 27, 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+static H5_inline unsigned
+H5V_log2(unsigned n)
+{
+ static const unsigned MultiplyDeBruijnBitPosition[32] =
+ {
+ 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
+ 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
+ };
+
+ return(MultiplyDeBruijnBitPosition[(n * 0x077CB531UL) >> 27]);
+} /* H5V_log2() */
+
+#endif /* H5Vprivate_H */
+