2020-08-07 08:59:55

by Wei Yang

[permalink] [raw]
Subject: [RESEND Patch 0/2] trivial cleanup for get_count_order[_long]

The following two patches cleanup get_count_order[_long] a little.

The lib/test_bitops pass with these two patches.

Wei Yang (2):
bitops: simplify get_count_order_long()
bitops: use the same mechanism for get_count_order[_long]

include/linux/bitops.h | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

--
2.20.1 (Apple Git-117)


2020-08-07 09:00:46

by Wei Yang

[permalink] [raw]
Subject: [RESEND Patch 1/2] bitops: simplify get_count_order_long()

These two cases could be unified into one.

Signed-off-by: Wei Yang <[email protected]>
---
include/linux/bitops.h | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 99f2ac30b1d9..030a98f0c452 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -206,10 +206,7 @@ static inline int get_count_order_long(unsigned long l)
{
if (l == 0UL)
return -1;
- else if (l & (l - 1UL))
- return (int)fls_long(l);
- else
- return (int)fls_long(l) - 1;
+ return (int)fls_long(--l);
}

/**
--
2.20.1 (Apple Git-117)

2020-08-07 09:02:03

by Wei Yang

[permalink] [raw]
Subject: [RESEND Patch 2/2] bitops: use the same mechanism for get_count_order[_long]

These two functions share the same logic.

Signed-off-by: Wei Yang <[email protected]>
---
include/linux/bitops.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 030a98f0c452..5b74bdf159d6 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -188,12 +188,10 @@ static inline unsigned fls_long(unsigned long l)

static inline int get_count_order(unsigned int count)
{
- int order;
+ if (count == 0)
+ return -1;

- order = fls(count) - 1;
- if (count & (count - 1))
- order++;
- return order;
+ return fls(--count);
}

/**
--
2.20.1 (Apple Git-117)