diff mbox series

[01/12] useful: Add utility to find the next power of two

Message ID 20240722190443.43196-1-denkenz@gmail.com (mailing list archive)
State New
Headers show
Series [01/12] useful: Add utility to find the next power of two | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-setupell success Prep - Setup ELL
prestwoj/iwd-ci-build success Build - Configure
prestwoj/iwd-ci-clang success clang PASS
prestwoj/iwd-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-ci-makecheck success Make Check
prestwoj/iwd-ci-makedistcheck success Make Distcheck
prestwoj/iwd-ci-testrunner success test-runner PASS

Commit Message

Denis Kenzior July 22, 2024, 7:04 p.m. UTC
---
 ell/useful.h | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Denis Kenzior July 23, 2024, 11:51 p.m. UTC | #1
On 7/22/24 2:04 PM, Denis Kenzior wrote:
> ---
>   ell/useful.h | 6 ++++++
>   1 file changed, 6 insertions(+)
> 

Applied
diff mbox series

Patch

diff --git a/ell/useful.h b/ell/useful.h
index 7bb924bcab8c..504ea089cb21 100644
--- a/ell/useful.h
+++ b/ell/useful.h
@@ -52,6 +52,12 @@  static inline unsigned char bit_field(const unsigned char oct,
 	return (oct >> start) & mask;
 }
 
+/* Must be called with n >= 2 and n <= ULONG_MAX / 2 + 1 */
+static inline unsigned long roundup_pow_of_two(unsigned long n)
+{
+	return 1UL << (sizeof(unsigned long) * 8 - __builtin_clzl(n - 1));
+}
+
 #define DIV_ROUND_CLOSEST(x, divisor)			\
 ({							\
 	typeof(divisor) _d = (divisor);			\