summaryrefslogtreecommitdiff
path: root/include/sbi
diff options
context:
space:
mode:
authorPetro Karashchenko <petro.karashchenko@gmail.com>2022-01-28 10:13:23 +0300
committerAnup Patel <anup@brainfault.org>2022-02-04 08:34:19 +0300
commit6ad8917b7e27e5e80fb9268492b9111b17ed2024 (patch)
treed8af3fafb149bdcc42b7d8905940b846b135fdfc /include/sbi
parent5d53b55aa77ffeefd4012445dfa6ad3535e1ff2c (diff)
downloadopensbi-6ad8917b7e27e5e80fb9268492b9111b17ed2024.tar.xz
lib: fix compilation when strings.h is included
In a systems that provide strings.h and it is included together with sbi_bitops.h the compilation error appears. The ffs() and fls() are provided by strings.h Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'include/sbi')
-rw-r--r--include/sbi/sbi_bitops.h82
1 files changed, 6 insertions, 76 deletions
diff --git a/include/sbi/sbi_bitops.h b/include/sbi/sbi_bitops.h
index 879430d..251e4d8 100644
--- a/include/sbi/sbi_bitops.h
+++ b/include/sbi/sbi_bitops.h
@@ -37,47 +37,12 @@
(((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
/**
- * ffs - Find first bit set
- * @x: the word to search
- *
- * This is defined the same way as
- * the libc and compiler builtin ffs routines, therefore
- * differs in spirit from the above ffz (man ffs).
- */
-static inline int ffs(int x)
-{
- int r = 1;
-
- if (!x)
- return 0;
- if (!(x & 0xffff)) {
- x >>= 16;
- r += 16;
- }
- if (!(x & 0xff)) {
- x >>= 8;
- r += 8;
- }
- if (!(x & 0xf)) {
- x >>= 4;
- r += 4;
- }
- if (!(x & 3)) {
- x >>= 2;
- r += 2;
- }
- if (!(x & 1))
- r += 1;
- return r;
-}
-
-/**
- * __ffs - find first bit in word.
+ * sbi_ffs - find first (less-significant) set bit in a long word.
* @word: The word to search
*
* Undefined if no bit exists, so code should check against 0 first.
*/
-static inline int __ffs(unsigned long word)
+static inline int sbi_ffs(unsigned long word)
{
int num = 0;
@@ -109,55 +74,20 @@ static inline int __ffs(unsigned long word)
}
/*
- * ffz - find first zero in word.
+ * sbi_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))
-
-/**
- * fls - find last (most-significant) bit set
- * @x: the word to search
- *
- * This is defined the same way as ffs.
- * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
- */
-
-static inline int fls(int x)
-{
- int r = 32;
-
- if (!x)
- return 0;
- if (!(x & 0xffff0000u)) {
- x <<= 16;
- r -= 16;
- }
- if (!(x & 0xff000000u)) {
- x <<= 8;
- r -= 8;
- }
- if (!(x & 0xf0000000u)) {
- x <<= 4;
- r -= 4;
- }
- if (!(x & 0xc0000000u)) {
- x <<= 2;
- r -= 2;
- }
- if (!(x & 0x80000000u))
- r -= 1;
- return r;
-}
+#define sbi_ffz(x) sbi_ffs(~(x))
/**
- * __fls - find last (most-significant) set bit in a long word
+ * sbi_fls - find last (most-significant) set bit in a long word
* @word: the word to search
*
* Undefined if no set bit exists, so code should check against 0 first.
*/
-static inline unsigned long __fls(unsigned long word)
+static inline unsigned long sbi_fls(unsigned long word)
{
int num = BITS_PER_LONG - 1;