Fix BIONIC_ROUND_UP_POWER_OF_2 for 64 bit.
There were two bugs here:
- For 64 bit values, this did not properly round up.
- The macro rounded to the power of 2 less than value, not to the power
of 2 greater than value.
(cherry picked from commit 27047faf283cb9d3d025a984cd9934fd2c404407)
Change-Id: Idf1ec67854e1eb423704e599ae1c6b674d36618d
diff --git a/libc/private/bionic_macros.h b/libc/private/bionic_macros.h
index a3a6985..61794bd 100644
--- a/libc/private/bionic_macros.h
+++ b/libc/private/bionic_macros.h
@@ -37,6 +37,8 @@
(((value) + (alignment) - 1) & ~((alignment) - 1))
#define BIONIC_ROUND_UP_POWER_OF_2(value) \
- (1UL << (sizeof(value) * 8 - 1 - __builtin_clz(value)))
+ (sizeof(value) == 8) \
+ ? (1UL << (64 - __builtin_clzl(static_cast<unsigned long>(value)))) \
+ : (1UL << (32 - __builtin_clz(static_cast<unsigned int>(value))))
#endif // _BIONIC_MACROS_H_