From: Andrew Cooper Date: Tue, 17 Aug 2021 20:55:01 +0000 (+0100) Subject: common: Move {BITS,BYTES}_PER_LONG into limits.h X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=fc32c40a97069d4696fb7aa9cb76e3ae09aa18dd;p=xtf.git common: Move {BITS,BYTES}_PER_LONG into limits.h 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 --- diff --git a/common/setup.c b/common/setup.c index 932fc09..ed2ae59 100644 --- a/common/setup.c +++ b/common/setup.c @@ -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 diff --git a/include/limits.h b/include/limits.h index ae8b2d5..9822d2c 100644 --- a/include/limits.h +++ b/include/limits.h @@ -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 */ /* diff --git a/include/xtf/lib.h b/include/xtf/lib.h index 3348464..9ced1e7 100644 --- a/include/xtf/lib.h +++ b/include/xtf/lib.h @@ -5,17 +5,6 @@ #include #include -#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))