]> xenbits.xensource.com Git - people/aperard/xtf.git/commitdiff
common: Move {BITS,BYTES}_PER_LONG into limits.h
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 17 Aug 2021 20:55:01 +0000 (21:55 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 17 Aug 2021 21:01:32 +0000 (22:01 +0100)
We're already using compiler-provided __*_TYPE__ macros, so instead of basing
BYTES_PER_LONG on __i386__ or __x86_64__, just use __SIZEOF_LONG__ directly.

This form doesn't require editing to add different architectures.

Add some build assertions that we have a half-way sane compile environment.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
common/setup.c
include/limits.h
include/xtf/lib.h

index 932fc09168da981773d6aa4e38004a2e6d93846a..ed2ae59018ef0188953c2ef7acd91dd231fc1e9a 100644 (file)
@@ -36,6 +36,15 @@ void __noreturn xtf_main(void)
     xtf_exit();
 }
 
+/**
+ * Some basic assertions about the compile environment.
+ */
+static void __maybe_unused build_assertions(void)
+{
+    BUILD_BUG_ON(BITS_PER_LONG != 32 &&
+                 BITS_PER_LONG != 64);
+}
+
 /*
  * Local variables:
  * mode: C
index ae8b2d59ff102c3d69c26e7357346f13921742fb..9822d2cd0ef466c4aa927e76b9bf02f661bc9de7 100644 (file)
@@ -8,6 +8,9 @@
 
 #define CHAR_BIT __CHAR_BIT__
 
+#define BYTES_PER_LONG __SIZEOF_LONG__
+#define BITS_PER_LONG (BYTES_PER_LONG * CHAR_BIT)
+
 #endif /* LIMITS_H */
 
 /*
index 3348464b7069894687dba701bf59a4b1877b920b..9ced1e795258c3dba92f359488f757a910ac2dce 100644 (file)
@@ -5,17 +5,6 @@
 #include <xtf/console.h>
 #include <xtf/types.h>
 
-#if defined(__i386__)
-# define BYTES_PER_LONG 4
-#elif defined(__x86_64__)
-# define BYTES_PER_LONG 8
-#else
-# errror Bad width
-#endif
-
-#define BITS_PER_LONG (BYTES_PER_LONG * 8)
-
-
 #define ARRAY_SIZE(a)    (sizeof(a) / sizeof(*a))
 
 #define ACCESS_ONCE(x)   (*(volatile typeof(x) *)&(x))