Changeset: 45912f01a150 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=45912f01a150
Modified Files:
gdk/gdk_select.c
Branch: Oct2020
Log Message:
Inline ilog2 and use intrinsics if available.
diffs (45 lines):
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -801,9 +801,32 @@ scanselect(BAT *b, struct canditer *rest
/* calculate the integer 2 logarithm (i.e. position of highest set
* bit) of the argument (with a slight twist: 0 gives 0, 1 gives 1,
* 0x8 to 0xF give 4, etc.) */
-static unsigned
+static inline unsigned
ilog2(BUN x)
{
+#if defined(__GNUC__)
+ if (x == 0)
+ return 0;
+#if SIZEOF_BUN == 8
+ return (unsigned) (64 - __builtin_clzll((unsigned long long) x));
+#else
+ return (unsigned) (32 - __builtin_clz((unsigned) x));
+#endif
+#elif defined(_MSC_VER)
+ if (x == 0)
+ return 0;
+ unsigned long n;
+ if (
+#if SIZEOF_BUN == 8
+ _BitScanReverse64(&n, (unsigned __int64) x)
+#else
+ _BitScanReverse(&n, (unsigned long) x)
+#endif
+ )
+ return (unsigned) n + 1;
+ else
+ return 0;
+#else
unsigned n = 0;
BUN y;
@@ -835,6 +858,7 @@ ilog2(BUN x)
n += 1;
}
return n + (x != 0);
+#endif
}
/* Normalize the variables li, hi, lval, hval, possibly changing anti
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list