git: b7cbf741d554 - main - libkern: avoid local var in order_base_2()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 27 Sep 2024 23:45:39 UTC
The branch main has been updated by dougm:
URL: https://cgit.FreeBSD.org/src/commit/?id=b7cbf741d55468ba34305a14ac3acc1c286af034
commit b7cbf741d55468ba34305a14ac3acc1c286af034
Author: Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2024-09-27 23:43:07 +0000
Commit: Doug Moore <dougm@FreeBSD.org>
CommitDate: 2024-09-27 23:43:07 +0000
libkern: avoid local var in order_base_2()
order_base_2(n) is implemented with a variable, which keeps it from
being used at file scope. Implement it instead as ilog2(2*n-1), which
produces a different result when 2*n overflows, which appears unlikely
in practice.
Reviewed by: bz
Differential Revision: https://reviews.freebsd.org/D46826
---
sys/sys/libkern.h | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h
index 64744f57b5c3..ad64d0fb0a57 100644
--- a/sys/sys/libkern.h
+++ b/sys/sys/libkern.h
@@ -227,10 +227,7 @@ ilog2_long_long(long long n)
#define ilog2(n) (__builtin_constant_p(n) ? ilog2_const(n) : ilog2_var(n))
#define rounddown_pow_of_two(n) ((__typeof(n))1 << ilog2(n))
-#define order_base_2(n) ({ \
- __typeof(n) _n = (n); \
- _n == 1 ? 0 : 1 + ilog2(_n - 1); \
-})
+#define order_base_2(n) ilog2(2*(n)-1)
#define roundup_pow_of_two(n) ((__typeof(n))1 << order_base_2(n))
#define bitcount64(x) __bitcount64((uint64_t)(x))