Replace BIONIC_ROUND_UP_POWER_OF_2() with stdc_bit_ceil()/std::bit_ceil().
The standard functions have the behavior all of the callers actually wanted for 0 and powers of two.
Change-Id: I387fb6c0228ab25fd2723d2332c5d4a31b5077f4
diff --git a/libc/bionic/jemalloc_wrapper.cpp b/libc/bionic/jemalloc_wrapper.cpp
index 859baf5..4178703 100644
--- a/libc/bionic/jemalloc_wrapper.cpp
+++ b/libc/bionic/jemalloc_wrapper.cpp
@@ -17,6 +17,7 @@
#include <errno.h>
#include <inttypes.h>
#include <malloc.h>
+#include <stdbit.h>
#include <sys/param.h>
#include <unistd.h>
@@ -48,17 +49,12 @@
#undef je_memalign
#endif
-// The man page for memalign says it fails if boundary is not a power of 2,
-// but this is not true. Both glibc and dlmalloc round up to the next power
-// of 2, so we'll do the same.
void* je_memalign_round_up_boundary(size_t boundary, size_t size) {
- if (boundary != 0) {
- if (!powerof2(boundary)) {
- boundary = BIONIC_ROUND_UP_POWER_OF_2(boundary);
- }
- } else {
- boundary = 1;
- }
+ // The man page for memalign says it fails if boundary is not a power of 2,
+ // but this is not true. Both glibc and dlmalloc round up to the next power
+ // of 2, so we'll do the same.
+ boundary = stdc_bit_ceil(boundary);
+
return je_memalign(boundary, size);
}