]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
xen/config.h: Move BITS_PER_* definitions from asm/config.h to xen/config.h
authorOleksii Kurochko <oleksii.kurochko@gmail.com>
Tue, 15 Apr 2025 11:23:39 +0000 (13:23 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 15 Apr 2025 11:23:39 +0000 (13:23 +0200)
BITS_PER_* values can be defined in a common way using compiler-provided macros.
Thus, these definitions are moved to xen/config.h to reduce duplication across
architectures.

Additionally, *_BYTEORDER macros are removed, as BITS_PER_* values now come
directly from the compiler environment.

The arch_fls() implementation for Arm and PPC is updated to use BITS_PER_INT
instead of a hardcoded value of 32.

Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
xen/arch/arm/include/asm/bitops.h
xen/arch/arm/include/asm/config.h
xen/arch/ppc/include/asm/bitops.h
xen/arch/ppc/include/asm/config.h
xen/arch/riscv/include/asm/config.h
xen/arch/x86/include/asm/config.h
xen/include/xen/config.h

index f163d9bb4578a912281d5ee4548ca22fa0c7e583..60686a3a55030fd5add01ff1e267809a567a0d4f 100644 (file)
@@ -22,8 +22,6 @@
 #define __set_bit(n,p)            set_bit(n,p)
 #define __clear_bit(n,p)          clear_bit(n,p)
 
-#define BITS_PER_BYTE           8
-
 #define ADDR (*(volatile int *) addr)
 #define CONST_ADDR (*(const volatile int *) addr)
 
@@ -75,7 +73,7 @@ bool clear_mask16_timeout(uint16_t mask, volatile void *p,
 
 #define arch_ffs(x)  ((x) ? 1 + __builtin_ctz(x) : 0)
 #define arch_ffsl(x) ((x) ? 1 + __builtin_ctzl(x) : 0)
-#define arch_fls(x)  ((x) ? 32 - __builtin_clz(x) : 0)
+#define arch_fls(x)  ((x) ? BITS_PER_INT - __builtin_clz(x) : 0)
 #define arch_flsl(x) ((x) ? BITS_PER_LONG - __builtin_clzl(x) : 0)
 
 #endif /* _ARM_BITOPS_H */
index 799bc2a8ac46e461495d8a9e0230fd635b6f8719..272e4565e592f2dd14cf29905bf1b6f7f54a7753 100644 (file)
@@ -8,19 +8,11 @@
 #define __ARM_CONFIG_H__
 
 #if defined(CONFIG_ARM_64)
-# define LONG_BYTEORDER 3
 # define ELFSIZE 64
 #else
-# define LONG_BYTEORDER 2
 # define ELFSIZE 32
 #endif
 
-#define BYTES_PER_LONG (1 << LONG_BYTEORDER)
-#define BITS_PER_LONG (BYTES_PER_LONG << 3)
-#define POINTER_ALIGN BYTES_PER_LONG
-
-#define BITS_PER_LLONG 64
-
 /* xen_ulong_t is always 64 bits */
 #define BITS_PER_XEN_ULONG 64
 
index c942e9432e20594171c0f445d0949af6bbdf453a..e72942cca0969a4d623c884a17c0a769831dc375 100644 (file)
@@ -15,8 +15,6 @@
 #define __set_bit(n, p)         set_bit(n, p)
 #define __clear_bit(n, p)       clear_bit(n, p)
 
-#define BITS_PER_BYTE           8
-
 /* PPC bit number conversion */
 #define PPC_BITLSHIFT(be)    (BITS_PER_LONG - 1 - (be))
 #define PPC_BIT(bit)         (1UL << PPC_BITLSHIFT(bit))
@@ -121,7 +119,7 @@ static inline int test_and_set_bit(unsigned int nr, volatile void *addr)
 
 #define arch_ffs(x)  ((x) ? 1 + __builtin_ctz(x) : 0)
 #define arch_ffsl(x) ((x) ? 1 + __builtin_ctzl(x) : 0)
-#define arch_fls(x)  ((x) ? 32 - __builtin_clz(x) : 0)
+#define arch_fls(x)  ((x) ? BITS_PER_INT - __builtin_clz(x) : 0)
 #define arch_flsl(x) ((x) ? BITS_PER_LONG - __builtin_clzl(x) : 0)
 
 #define arch_hweightl(x) __builtin_popcountl(x)
index 148fb3074d83c177f9439f160ed66e3f7482d1e7..8e32edd5a52a8e643f329c26d68df14d5826462c 100644 (file)
@@ -6,19 +6,12 @@
 #include <xen/page-size.h>
 
 #if defined(CONFIG_PPC64)
-#define LONG_BYTEORDER 3
 #define ELFSIZE        64
 #define MAX_VIRT_CPUS  1024u
 #else
 #error "Unsupported PowerPC variant"
 #endif
 
-#define BYTES_PER_LONG (1 << LONG_BYTEORDER)
-#define BITS_PER_LONG  (BYTES_PER_LONG << 3)
-#define POINTER_ALIGN  BYTES_PER_LONG
-
-#define BITS_PER_LLONG 64
-
 /* xen_ulong_t is always 64 bits */
 #define BITS_PER_XEN_ULONG 64
 
index 7141bd9e46d2fa8b5cc833cdb3dc73db8866fb1f..314c97c20aa5832308b5176679a0d4970f51b93b 100644 (file)
 #define HYPERVISOR_VIRT_START XEN_VIRT_START
 
 #if defined(CONFIG_RISCV_64)
-# define INT_BYTEORDER 2
-# define LONG_BYTEORDER 3
 # define ELFSIZE 64
 # define MAX_VIRT_CPUS 128u
 #else
 # error "Unsupported RISCV variant"
 #endif
 
-#define BYTES_PER_INT  (1 << INT_BYTEORDER)
-#define BITS_PER_INT  (BYTES_PER_INT << 3)
-
-#define BYTES_PER_LONG (1 << LONG_BYTEORDER)
-#define BITS_PER_LONG  (BYTES_PER_LONG << 3)
-#define POINTER_ALIGN  BYTES_PER_LONG
-
-#define BITS_PER_LLONG 64
-
-#define BITS_PER_BYTE 8
-
 /* xen_ulong_t is always 64 bits */
 #define BITS_PER_XEN_ULONG 64
 
index 19746f956ec3b895eb3597996645a4620ad1070b..f0123a7de9837b8b4e1f1b6de7059fc393c652bd 100644 (file)
@@ -7,16 +7,8 @@
 #ifndef __X86_CONFIG_H__
 #define __X86_CONFIG_H__
 
-#define LONG_BYTEORDER 3
 #define CONFIG_PAGING_LEVELS 4
 
-#define BYTES_PER_LONG (1 << LONG_BYTEORDER)
-#define BITS_PER_LONG (BYTES_PER_LONG << 3)
-#define BITS_PER_BYTE 8
-#define POINTER_ALIGN BYTES_PER_LONG
-
-#define BITS_PER_LLONG 64
-
 #define BITS_PER_XEN_ULONG BITS_PER_LONG
 
 #define CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 1
index d888b2314dafcb629c4d053c5b557b9755020b9c..7d43159efb5629487840dafa0d13c357cc4282ca 100644 (file)
 #define ZERO_BLOCK_PTR ((void *)-1L)
 #endif
 
+#define BYTES_PER_LONG  __SIZEOF_LONG__
+
+#define BITS_PER_BYTE   __CHAR_BIT__
+#define BITS_PER_INT    (BITS_PER_BYTE * __SIZEOF_INT__)
+#define BITS_PER_LONG   (BITS_PER_BYTE * BYTES_PER_LONG)
+#define BITS_PER_LLONG  (BITS_PER_BYTE * __SIZEOF_LONG_LONG__)
+
+/* It is assumed that sizeof(void *) == __alignof(void *) */
+#define POINTER_ALIGN   __SIZEOF_POINTER__
+
 #endif /* __XEN_CONFIG_H__ */