Skip to contentSkip to conversation

trivial cleanup for get_count_order[_long]

PATCH RESEND Applied Wei Yang 1 participant 3 messages Aug 7, 2020 Bitops API

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

cover 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(-)
Signature · 1 line
2.20.1 (Apple Git-117)
author
#1 lore raw

PATCH RESEND 1/2 bitops: simplify get_count_order_long()

These two cases could be unified into one.

---
 include/linux/bitops.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
include/linux/bitops.h +1 -4
index 99f2ac30b1d9..030a98f0c452 100644
@@ -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);
 }
 
 /**
Signature · 1 line
2.20.1 (Apple Git-117)
author
#2 lore raw

PATCH RESEND 2/2 bitops: use the same mechanism for get_count_order[_long]

In reply to Wei Yang

These two functions share the same logic.

---
 include/linux/bitops.h | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
include/linux/bitops.h +3 -5
index 030a98f0c452..5b74bdf159d6 100644
@@ -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);
 }
 
 /**
Signature · 1 line
2.20.1 (Apple Git-117)