]> xenbits.xensource.com Git - people/aperard/xen-unstable.git/commitdiff
common: Move a few more standalone macros from xen/lib.h to xen/macros.h
authorShawn Anastasio <sanastasio@raptorengineering.com>
Mon, 24 Jul 2023 12:13:08 +0000 (14:13 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 24 Jul 2023 12:13:08 +0000 (14:13 +0200)
Move a few more macros which have no dependencies on other headers from
xen/lib.h to xen/macros.h. Notably, this includes BUILD_BUG_ON* and
ARRAY_SIZE.

Signed-off-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/include/xen/lib.h
xen/include/xen/macros.h

index dae2a1f08523432b019dde9e3eca99cacd4d09bb..359cfdc7849b66686268dc0bdbbbc7a22ea1ee88 100644 (file)
     unlikely(ret_warn_on_);             \
 })
 
-/* All clang versions supported by Xen have _Static_assert. */
-#if defined(__clang__) || \
-    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
-/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
-
-/* Force a compilation error if condition is true, but also produce a
-   result (of value 0 and type size_t), so the expression can be used
-   e.g. in a structure initializer (or where-ever else comma expressions
-   aren't permitted). */
-#define BUILD_BUG_ON_ZERO(cond) \
-    (sizeof(struct { char c; _Static_assert(!(cond), "!(" #cond ")"); }) & 0)
-#else
-#define BUILD_BUG_ON_ZERO(cond) \
-    (sizeof(struct { unsigned u : !(cond); }) & 0)
-#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond))
-#endif
-
 #ifndef NDEBUG
 #define ASSERT(p) \
     do { if ( unlikely(!(p)) ) assert_failed(#p); } while (0)
 #define ASSERT_UNREACHABLE() do { } while (0)
 #endif
 
-#define ABS(_x) ({                              \
-    typeof(_x) __x = (_x);                      \
-    (__x < 0) ? -__x : __x;                     \
-})
-
-#define SWAP(_a, _b) \
-   do { typeof(_a) _t = (_a); (_a) = (_b); (_b) = _t; } while ( 0 )
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
-
 #define __ACCESS_ONCE(x) ({                             \
             (void)(typeof(x))0; /* Scalar typecheck. */ \
             (volatile typeof(x) *)&(x); })
index 7b92d345044dd601a1bf00ceaabe03d4c3ca47b3..d0caae7db298c8565dfe82b438460b72e80b0965 100644 (file)
 #define __STR(...) #__VA_ARGS__
 #define STR(...) __STR(__VA_ARGS__)
 
+#ifndef __ASSEMBLY__
+
+/* All clang versions supported by Xen have _Static_assert. */
+#if defined(__clang__) || \
+    (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+/* Force a compilation error if condition is true */
+#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
+
+/*
+ * Force a compilation error if condition is true, but also produce a
+ * result (of value 0 and type size_t), so the expression can be used
+ * e.g. in a structure initializer (or where-ever else comma expressions
+ * aren't permitted).
+ */
+#define BUILD_BUG_ON_ZERO(cond) \
+    (sizeof(struct { char c; _Static_assert(!(cond), "!(" #cond ")"); }) & 0)
+#else
+#define BUILD_BUG_ON_ZERO(cond) \
+    (sizeof(struct { unsigned u : !(cond); }) & 0)
+#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond))
+#endif
+
+#define ABS(x) ({                              \
+    typeof(x) x_ = (x);                        \
+    (x_ < 0) ? -x_ : x_;                       \
+})
+
+#define SWAP(a, b) \
+   do { typeof(a) t_ = (a); (a) = (b); (b) = t_; } while ( 0 )
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
+
+#endif /* __ASSEMBLY__ */
+
 #endif /* __MACROS_H__ */
 
 /*