linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND Patch 0/2] trivial cleanup for get_count_order[_long]
@ 2020-08-07  8:58 Wei Yang
  2020-08-07  8:58 ` [RESEND Patch 1/2] bitops: simplify get_count_order_long() Wei Yang
  2020-08-07  8:58 ` [RESEND Patch 2/2] bitops: use the same mechanism for get_count_order[_long] Wei Yang
  0 siblings, 2 replies; 3+ messages in thread
From: Wei Yang @ 2020-08-07  8:58 UTC (permalink / raw)
  To: akpm, christian.brauner, andriy.shevchenko; +Cc: linux-kernel, Wei Yang

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)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RESEND Patch 1/2] bitops: simplify get_count_order_long()
  2020-08-07  8:58 [RESEND Patch 0/2] trivial cleanup for get_count_order[_long] Wei Yang
@ 2020-08-07  8:58 ` Wei Yang
  2020-08-07  8:58 ` [RESEND Patch 2/2] bitops: use the same mechanism for get_count_order[_long] Wei Yang
  1 sibling, 0 replies; 3+ messages in thread
From: Wei Yang @ 2020-08-07  8:58 UTC (permalink / raw)
  To: akpm, christian.brauner, andriy.shevchenko; +Cc: linux-kernel, Wei Yang

These two cases could be unified into one.

Signed-off-by: Wei Yang <richard.weiyang@linux.alibaba.com>
---
 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)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [RESEND Patch 2/2] bitops: use the same mechanism for get_count_order[_long]
  2020-08-07  8:58 [RESEND Patch 0/2] trivial cleanup for get_count_order[_long] Wei Yang
  2020-08-07  8:58 ` [RESEND Patch 1/2] bitops: simplify get_count_order_long() Wei Yang
@ 2020-08-07  8:58 ` Wei Yang
  1 sibling, 0 replies; 3+ messages in thread
From: Wei Yang @ 2020-08-07  8:58 UTC (permalink / raw)
  To: akpm, christian.brauner, andriy.shevchenko; +Cc: linux-kernel, Wei Yang

These two functions share the same logic.

Signed-off-by: Wei Yang <richard.weiyang@linux.alibaba.com>
---
 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)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-07  8:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07  8:58 [RESEND Patch 0/2] trivial cleanup for get_count_order[_long] Wei Yang
2020-08-07  8:58 ` [RESEND Patch 1/2] bitops: simplify get_count_order_long() Wei Yang
2020-08-07  8:58 ` [RESEND Patch 2/2] bitops: use the same mechanism for get_count_order[_long] Wei Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).