]> xenbits.xensource.com Git - people/tklengyel/xen.git/commitdiff
xen/bitops: put __ffs() into linux compatible header
authorOleksii Kurochko <oleksii.kurochko@gmail.com>
Thu, 16 May 2024 08:08:37 +0000 (10:08 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 16 May 2024 08:08:37 +0000 (10:08 +0200)
The mentioned macros exist only because of Linux compatible purpose.

The patch defines __ffs() in terms of Xen bitops and it is safe
to define in this way ( as __ffs() - 1 ) as considering that __ffs()
was defined as __builtin_ctzl(x), which has undefined behavior when x=0,
so it is assumed that such cases are not encountered in the current code.

To not include <xen/linux-compat.h> to Xen library files __ffs() and __ffz()
were defined locally in find-next-bit.c.

Except __ffs() usage in find-next-bit.c only one usage of __ffs() leave
in smmu-v3.c. It seems that it __ffs can be changed to ffsl(x)-1 in
this file, but to keep smmu-v3.c looks close to linux it was deciced just
to define __ffs() in xen/linux-compat.h and include it in smmu-v3.c

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Shawn Anastasio <sanastasio@raptorengineering.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Rahul Singh <rahul.singh@arm.com>
xen/arch/arm/include/asm/arm64/bitops.h
xen/arch/ppc/include/asm/bitops.h
xen/drivers/passthrough/arm/smmu-v3.c
xen/include/xen/linux-compat.h
xen/lib/find-next-bit.c

index 0efde290684a369683e0ed68b70d1c1b0004f775..906d84e5f295cefd68a700fb688785d2aac34b59 100644 (file)
@@ -1,27 +1,6 @@
 #ifndef _ARM_ARM64_BITOPS_H
 #define _ARM_ARM64_BITOPS_H
 
-/* Based on linux/include/asm-generic/bitops/builtin-__ffs.h */
-/**
- * __ffs - find first bit in word.
- * @word: The word to search
- *
- * Undefined if no bit exists, so code should check against 0 first.
- */
-static /*__*/always_inline unsigned long __ffs(unsigned long word)
-{
-        return __builtin_ctzl(word);
-}
-
-/* Based on linux/include/asm-generic/bitops/ffz.h */
-/*
- * ffz - find first zero in word.
- * @word: The word to search
- *
- * Undefined if no zero exists, so code should check against ~0UL first.
- */
-#define ffz(x)  __ffs(~(x))
-
 static inline int flsl(unsigned long x)
 {
         uint64_t ret;
index 5820b9ce7bb50e8f1af8b8181a46cd1da4880093..bea655796d64d9d4dfd88c0ef0e5370931163947 100644 (file)
@@ -176,15 +176,6 @@ static inline int __test_and_clear_bit(int nr, volatile void *addr)
 #define ffs(x) ({ unsigned int t_ = (x); fls(t_ & -t_); })
 #define ffsl(x) ({ unsigned long t_ = (x); flsl(t_ & -t_); })
 
-/* Based on linux/include/asm-generic/bitops/ffz.h */
-/*
- * ffz - find first zero in word.
- * @word: The word to search
- *
- * Undefined if no zero exists, so code should check against ~0UL first.
- */
-#define ffz(x) __ffs(~(x))
-
 /**
  * hweightN - returns the hamming weight of a N-bit word
  * @x: the word to weigh
@@ -196,18 +187,6 @@ static inline int __test_and_clear_bit(int nr, volatile void *addr)
 #define hweight16(x) __builtin_popcount((uint16_t)(x))
 #define hweight8(x)  __builtin_popcount((uint8_t)(x))
 
-/* Based on linux/include/asm-generic/bitops/builtin-__ffs.h */
-/**
- * __ffs - find first bit in word.
- * @word: The word to search
- *
- * Undefined if no bit exists, so code should check against 0 first.
- */
-static always_inline unsigned long __ffs(unsigned long word)
-{
-    return __builtin_ctzl(word);
-}
-
 /**
  * find_first_set_bit - find the first set bit in @word
  * @word: the word to search
index b1c40c2c0ae7f8ab87e5d312b7b1a6b54853c3b5..69049624670e82747ef92cd981644c75f4c6c462 100644 (file)
  */
 
 #include <xen/acpi.h>
+#include <xen/bitops.h>
 #include <xen/config.h>
 #include <xen/delay.h>
 #include <xen/errno.h>
 #include <xen/err.h>
 #include <xen/irq.h>
 #include <xen/lib.h>
+#include <xen/linux-compat.h>
 #include <xen/list.h>
 #include <xen/mm.h>
 #include <xen/rbtree.h>
index 62ba71485cdeaa1b918b3d2c2716f11c9e6e5eaf..b289dfd8948ac2c422bcaa722eecdfc0a3bdfd75 100644 (file)
@@ -19,4 +19,6 @@ typedef int64_t __s64;
 
 typedef paddr_t phys_addr_t;
 
+#define __ffs(x) (ffsl(x) - 1UL)
+
 #endif /* __XEN_LINUX_COMPAT_H__ */
index ca6f82277e7700d02ccbb8f200187d96d0dbdd21..761b02739841bb90b114feb41cbbb089695ae76a 100644 (file)
@@ -12,6 +12,9 @@
 
 #include <asm/byteorder.h>
 
+#define __ffs(x) (ffsl(x) - 1)
+#define ffz(x) __ffs(~(x))
+
 #ifndef find_next_bit
 /*
  * Find the next set bit in a memory region.