aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-02-19 21:27:03 -0800
committerGuy Harris <guy@alum.mit.edu>2018-02-20 05:27:38 +0000
commitdc6b9dfcd635a1ca97a218bcdaf16a2ee5f7b693 (patch)
tree49ce29aca0c5cce7f14b06b7bd89d7a1a35614b4 /wsutil
parente4787a9190c82dadae7e57c0847e2529bb2a9bbf (diff)
Define macros to calculate (2^N)^M, and use them in more places.
Change-Id: I4df1b35d8d2233c301f0ba9e119d012aebe9cd17 Reviewed-on: https://code.wireshark.org/review/25913 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/CMakeLists.txt1
-rw-r--r--wsutil/Makefile.am1
-rw-r--r--wsutil/pow2.h29
3 files changed, 31 insertions, 0 deletions
diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt
index bb75fd4dfd..c8e685e2da 100644
--- a/wsutil/CMakeLists.txt
+++ b/wsutil/CMakeLists.txt
@@ -61,6 +61,7 @@ set(WSUTIL_PUBLIC_HEADERS
os_version_info.h
pint.h
plugins.h
+ pow2.h
privileges.h
processes.h
report_message.h
diff --git a/wsutil/Makefile.am b/wsutil/Makefile.am
index 008a50110d..0ce957f4ce 100644
--- a/wsutil/Makefile.am
+++ b/wsutil/Makefile.am
@@ -68,6 +68,7 @@ WSUTIL_PUBLIC_INCLUDES = \
os_version_info.h \
pint.h \
plugins.h \
+ pow2.h \
privileges.h \
processes.h \
report_message.h \
diff --git a/wsutil/pow2.h b/wsutil/pow2.h
new file mode 100644
index 0000000000..f72b09133e
--- /dev/null
+++ b/wsutil/pow2.h
@@ -0,0 +1,29 @@
+/* ws_pow2.h
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef __WS_POW2_H__
+#define __WS_POW2_H__
+
+/*
+ * Macros to calculate pow2^M, for various power-of-2 values and positive
+ * integer values of M. That's (2^N)^M, i.e. 2^(N*M).
+ *
+ * The first argument is the type of the desired result; the second
+ * argument is M.
+ */
+#define pow2(type, m) (((type)1U) << (m))
+#define pow4(type, m) (((type)1U) << (2*(m)))
+#define pow8(type, m) (((type)1U) << (3*(m)))
+#define pow16(type, m) (((type)1U) << (4*(m)))
+#define pow32(type, m) (((type)1U) << (5*(m)))
+#define pow64(type, m) (((type)1U) << (6*(m)))
+#define pow128(type, m) (((type)1U) << (7*(m)))
+#define pow256(type, m) (((type)1U) << (8*(m)))
+
+#endif /* __WS_POW2_H__ */