summaryrefslogtreecommitdiff
path: root/wsutil/bits_ctz.h
diff options
context:
space:
mode:
authorDaniel Mack <daniel@zonque.org>2014-09-17 18:39:22 +0200
committerMichael Mann <mmann78@netscape.net>2014-10-12 14:15:12 +0000
commited0b19b94bf07056b5e0cfe64d4d05c3ebae801a (patch)
tree4c4dd80aa856bf0a4c55704c88761a2d2ab2199a /wsutil/bits_ctz.h
parent29afac24a579b01c029b2b5404bda7a102fe2232 (diff)
downloadwireshark-ed0b19b94bf07056b5e0cfe64d4d05c3ebae801a.tar.gz
Make boolean bitmask type 64-bit wide
There are protocols out there that have 64-bit wide bit mask fields, so make the internal representation and bitfield decoders 64-bit aware. For this, the ws_ctz() fallback and bits_count_ones() have to be tweaked slightly. Change-Id: I19237b954a69c9e6c55864f281993c1e8731a233 Reviewed-on: https://code.wireshark.org/review/4158 Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'wsutil/bits_ctz.h')
-rw-r--r--wsutil/bits_ctz.h26
1 files changed, 20 insertions, 6 deletions
diff --git a/wsutil/bits_ctz.h b/wsutil/bits_ctz.h
index 9b05882bfa..dfdf24bf93 100644
--- a/wsutil/bits_ctz.h
+++ b/wsutil/bits_ctz.h
@@ -25,14 +25,16 @@
#include <glib.h>
+#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
static inline int
-ws_ctz(guint32 x)
+ws_ctz(guint64 x)
{
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
- g_assert(x != 0);
-
- return __builtin_ctz(x);
+ return __builtin_ctzll(x);
+}
#else
+static inline int
+__ws_ctz32(guint32 x)
+{
/* From http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
static const int table[32] = {
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
@@ -40,7 +42,19 @@ ws_ctz(guint32 x)
};
return table[((guint32)((x & -(gint32)x) * 0x077CB531U)) >> 27];
-#endif
}
+static inline int
+ws_ctz(guint64 x)
+{
+ guint32 hi = x >> 32;
+ guint32 lo = (guint32) x;
+
+ if (lo == 0)
+ return 32 + __ws_ctz32(hi);
+ else
+ return __ws_ctz32(lo);
+}
+#endif
+
#endif /* __WSUTIL_BITS_CTZ_H__ */