[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v2 7/9] uk/include: use ukarch_ffs func family in bitopts.h



From: Costin Lupu <costin.lupu@xxxxxxxxx>

ukarch_ffs functions are returning 0-based result. Meaning the least
significant bit is in position 0 (unlike the ffs function from gcc).
So we do not need __ffs wrappers from the original FreeBSD code.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 include/uk/bitops.h | 52 ++++++++++++---------------------------------
 1 file changed, 14 insertions(+), 38 deletions(-)

diff --git a/include/uk/bitops.h b/include/uk/bitops.h
index cfe7f6a..9f0de25 100644
--- a/include/uk/bitops.h
+++ b/include/uk/bitops.h
@@ -64,30 +64,6 @@
 #define        hweight64(x)    bitcount64(x)
 #define        hweight_long(x) bitcountl(x)
 
-static inline int
-__ffs(int mask)
-{
-       return (ffs(mask) - 1);
-}
-
-static inline int
-__fls(int mask)
-{
-       return (fls(mask) - 1);
-}
-
-static inline int
-__ffsl(long mask)
-{
-       return (ffsl(mask) - 1);
-}
-
-static inline int
-__flsl(long mask)
-{
-       return (flsl(mask) - 1);
-}
-
 static inline int
 fls64(uint64_t mask)
 {
@@ -100,13 +76,13 @@ ror32(uint32_t word, unsigned int shift)
        return ((word >> shift) | (word << (32 - shift)));
 }
 
-#define        ffz(mask)       __ffs(~(mask))
+#define        ffz(mask)       ukarch_ffs(~(mask))
 
 static inline int get_count_order(unsigned int count)
 {
        int order;
 
-       order = fls(count) - 1;
+       order = ukarch_fls(count);
        if (count & (count - 1))
                order++;
        return order;
@@ -122,12 +98,12 @@ find_first_bit(const unsigned long *addr, unsigned long 
size)
                size -= BITS_PER_LONG, bit += BITS_PER_LONG, addr++) {
                if (*addr == 0)
                        continue;
-               return (bit + __ffsl(*addr));
+               return (bit + ukarch_ffsl(*addr));
        }
        if (size) {
                mask = (*addr) & BITMAP_LAST_WORD_MASK(size);
                if (mask)
-                       bit += __ffsl(mask);
+                       bit += ukarch_ffsl(mask);
                else
                        bit += size;
        }
@@ -144,12 +120,12 @@ find_first_zero_bit(const unsigned long *addr, unsigned 
long size)
                size -= BITS_PER_LONG, bit += BITS_PER_LONG, addr++) {
                if (~(*addr) == 0)
                        continue;
-               return (bit + __ffsl(~(*addr)));
+               return (bit + ukarch_ffsl(~(*addr)));
        }
        if (size) {
                mask = ~(*addr) & BITMAP_LAST_WORD_MASK(size);
                if (mask)
-                       bit += __ffsl(mask);
+                       bit += ukarch_ffsl(mask);
                else
                        bit += size;
        }
@@ -171,13 +147,13 @@ find_last_bit(const unsigned long *addr, unsigned long 
size)
        if (offs) {
                mask = (*addr) & BITMAP_LAST_WORD_MASK(offs);
                if (mask)
-                       return (bit + __flsl(mask));
+                       return (bit + ukarch_flsl(mask));
        }
        while (pos--) {
                addr--;
                bit -= BITS_PER_LONG;
                if (*addr)
-                       return (bit + __flsl(*addr));
+                       return (bit + ukarch_flsl(*addr));
        }
        return (size);
 }
@@ -200,7 +176,7 @@ find_next_bit(const unsigned long *addr, unsigned long size,
        if (offs) {
                mask = (*addr) & ~BITMAP_LAST_WORD_MASK(offs);
                if (mask)
-                       return (bit + __ffsl(mask));
+                       return (bit + ukarch_ffsl(mask));
                if (size - bit <= BITS_PER_LONG)
                        return (size);
                bit += BITS_PER_LONG;
@@ -210,12 +186,12 @@ find_next_bit(const unsigned long *addr, unsigned long 
size,
                size -= BITS_PER_LONG, bit += BITS_PER_LONG, addr++) {
                if (*addr == 0)
                        continue;
-               return (bit + __ffsl(*addr));
+               return (bit + ukarch_ffsl(*addr));
        }
        if (size) {
                mask = (*addr) & BITMAP_LAST_WORD_MASK(size);
                if (mask)
-                       bit += __ffsl(mask);
+                       bit += ukarch_ffsl(mask);
                else
                        bit += size;
        }
@@ -240,7 +216,7 @@ find_next_zero_bit(const unsigned long *addr, unsigned long 
size,
        if (offs) {
                mask = ~(*addr) & ~BITMAP_LAST_WORD_MASK(offs);
                if (mask)
-                       return (bit + __ffsl(mask));
+                       return (bit + ukarch_ffsl(mask));
                if (size - bit <= BITS_PER_LONG)
                        return (size);
                bit += BITS_PER_LONG;
@@ -250,12 +226,12 @@ find_next_zero_bit(const unsigned long *addr, unsigned 
long size,
                size -= BITS_PER_LONG, bit += BITS_PER_LONG, addr++) {
                if (~(*addr) == 0)
                        continue;
-               return (bit + __ffsl(~(*addr)));
+               return (bit + ukarch_ffsl(~(*addr)));
        }
        if (size) {
                mask = ~(*addr) & BITMAP_LAST_WORD_MASK(size);
                if (mask)
-                       bit += __ffsl(mask);
+                       bit += ukarch_ffsl(mask);
                else
                        bit += size;
        }
-- 
2.18.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.