summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/common.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/common/common.c b/common/common.c
index 5068995ded..0552bddda4 100644
--- a/common/common.c
+++ b/common/common.c
@@ -344,9 +344,10 @@ unsigned int mp_log2(uint32_t v)
// mp_round_next_power_of_2(UINT32_MAX) == 0
uint32_t mp_round_next_power_of_2(uint32_t v)
{
- for (int n = 0; n < 30; n++) {
- if ((1 << n) >= v)
- return 1 << n;
- }
- return 0;
+ if (!v)
+ return 1;
+ if (!(v & (v - 1)))
+ return v;
+ int l = mp_log2(v) + 1;
+ return l == 32 ? 0 : (uint32_t)1 << l;
}