summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/openvswitch/compiler.h3
-rw-r--r--include/openvswitch/util.h50
-rw-r--r--lib/util.h51
3 files changed, 52 insertions, 52 deletions
diff --git a/include/openvswitch/compiler.h b/include/openvswitch/compiler.h
index cef641f1b..42c864f31 100644
--- a/include/openvswitch/compiler.h
+++ b/include/openvswitch/compiler.h
@@ -17,6 +17,9 @@
#ifndef OPENVSWITCH_COMPILER_H
#define OPENVSWITCH_COMPILER_H 1
+#include <stddef.h>
+#include <stdbool.h>
+
#ifndef __has_feature
#define __has_feature(x) 0
#endif
diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
index 63c8a4532..cfafc3612 100644
--- a/include/openvswitch/util.h
+++ b/include/openvswitch/util.h
@@ -17,8 +17,9 @@
#ifndef OPENVSWITCH_UTIL_H
#define OPENVSWITCH_UTIL_H 1
-#include <openvswitch/version.h>
#include <openvswitch/compiler.h>
+#include <openvswitch/version.h>
+#include <openvswitch/types.h>
#ifdef __cplusplus
extern "C" {
@@ -147,6 +148,53 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
#define INIT_CONTAINER(OBJECT, POINTER, MEMBER) \
((OBJECT) = NULL, ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER))
+/* Returns the number of elements in ARRAY. */
+#define ARRAY_SIZE(ARRAY) __ARRAY_SIZE(ARRAY)
+
+/* Returns X / Y, rounding up. X must be nonnegative to round correctly. */
+#define DIV_ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y))
+
+/* Returns X rounded up to the nearest multiple of Y. */
+#define ROUND_UP(X, Y) (DIV_ROUND_UP(X, Y) * (Y))
+
+/* Returns the least number that, when added to X, yields a multiple of Y. */
+#define PAD_SIZE(X, Y) (ROUND_UP(X, Y) - (X))
+
+/* Returns X rounded down to the nearest multiple of Y. */
+#define ROUND_DOWN(X, Y) ((X) / (Y) * (Y))
+
+/* Returns true if X is a power of 2, otherwise false. */
+#define IS_POW2(X) ((X) && !((X) & ((X) - 1)))
+
+static inline bool
+is_pow2(uintmax_t x)
+{
+ return IS_POW2(x);
+}
+
+/* Returns X rounded up to a power of 2. X must be a constant expression. */
+#define ROUND_UP_POW2(X) RUP2__(X)
+#define RUP2__(X) (RUP2_1(X) + 1)
+#define RUP2_1(X) (RUP2_2(X) | (RUP2_2(X) >> 16))
+#define RUP2_2(X) (RUP2_3(X) | (RUP2_3(X) >> 8))
+#define RUP2_3(X) (RUP2_4(X) | (RUP2_4(X) >> 4))
+#define RUP2_4(X) (RUP2_5(X) | (RUP2_5(X) >> 2))
+#define RUP2_5(X) (RUP2_6(X) | (RUP2_6(X) >> 1))
+#define RUP2_6(X) ((X) - 1)
+
+/* Returns X rounded down to a power of 2. X must be a constant expression. */
+#define ROUND_DOWN_POW2(X) RDP2__(X)
+#define RDP2__(X) (RDP2_1(X) - (RDP2_1(X) >> 1))
+#define RDP2_1(X) (RDP2_2(X) | (RDP2_2(X) >> 16))
+#define RDP2_2(X) (RDP2_3(X) | (RDP2_3(X) >> 8))
+#define RDP2_3(X) (RDP2_4(X) | (RDP2_4(X) >> 4))
+#define RDP2_4(X) (RDP2_5(X) | (RDP2_5(X) >> 2))
+#define RDP2_5(X) ( (X) | ( (X) >> 1))
+
+/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
+ * (void *). This is to suppress the alignment warning issued by clang. */
+#define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/util.h b/lib/util.h
index 5a429d7a5..55e2c6722 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -20,15 +20,10 @@
#include <arpa/inet.h>
#include <inttypes.h>
#include <limits.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "compiler.h"
-#include "openvswitch/types.h"
#include "openvswitch/util.h"
extern char *program_name;
@@ -48,48 +43,6 @@ extern char *program_name;
#define __ARRAY_SIZE(ARRAY) __ARRAY_SIZE_NOCHECK(ARRAY)
#endif
-/* Returns the number of elements in ARRAY. */
-#define ARRAY_SIZE(ARRAY) __ARRAY_SIZE(ARRAY)
-
-/* Returns X / Y, rounding up. X must be nonnegative to round correctly. */
-#define DIV_ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y))
-
-/* Returns X rounded up to the nearest multiple of Y. */
-#define ROUND_UP(X, Y) (DIV_ROUND_UP(X, Y) * (Y))
-
-/* Returns the least number that, when added to X, yields a multiple of Y. */
-#define PAD_SIZE(X, Y) (ROUND_UP(X, Y) - (X))
-
-/* Returns X rounded down to the nearest multiple of Y. */
-#define ROUND_DOWN(X, Y) ((X) / (Y) * (Y))
-
-/* Returns true if X is a power of 2, otherwise false. */
-#define IS_POW2(X) ((X) && !((X) & ((X) - 1)))
-
-static inline bool
-is_pow2(uintmax_t x)
-{
- return IS_POW2(x);
-}
-
-/* Returns X rounded up to a power of 2. X must be a constant expression. */
-#define ROUND_UP_POW2(X) RUP2__(X)
-#define RUP2__(X) (RUP2_1(X) + 1)
-#define RUP2_1(X) (RUP2_2(X) | (RUP2_2(X) >> 16))
-#define RUP2_2(X) (RUP2_3(X) | (RUP2_3(X) >> 8))
-#define RUP2_3(X) (RUP2_4(X) | (RUP2_4(X) >> 4))
-#define RUP2_4(X) (RUP2_5(X) | (RUP2_5(X) >> 2))
-#define RUP2_5(X) (RUP2_6(X) | (RUP2_6(X) >> 1))
-#define RUP2_6(X) ((X) - 1)
-
-/* Returns X rounded down to a power of 2. X must be a constant expression. */
-#define ROUND_DOWN_POW2(X) RDP2__(X)
-#define RDP2__(X) (RDP2_1(X) - (RDP2_1(X) >> 1))
-#define RDP2_1(X) (RDP2_2(X) | (RDP2_2(X) >> 16))
-#define RDP2_2(X) (RDP2_3(X) | (RDP2_3(X) >> 8))
-#define RDP2_3(X) (RDP2_4(X) | (RDP2_4(X) >> 4))
-#define RDP2_4(X) (RDP2_5(X) | (RDP2_5(X) >> 2))
-#define RDP2_5(X) ( (X) | ( (X) >> 1))
/* This system's cache line size, in bytes.
* Being wrong hurts performance but not correctness. */
@@ -117,10 +70,6 @@ ovs_prefetch_range(const void *start, size_t size)
#define OVS_NOT_REACHED() abort()
-/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
- * (void *). This is to suppress the alignment warning issued by clang. */
-#define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
-
/* Use "%"PRIuSIZE to format size_t with printf(). */
#ifdef _WIN32
#define PRIdSIZE "Id"