From 38fa18023d9f4aba682aaac4ef1e3359dcc2ed17 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 23 Jun 2026 11:39:19 +0100 Subject: [PATCH] Use `intrinsics.count_leading_zeros` internally for `math.next_power_of_two` --- core/math/math.odin | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/core/math/math.odin b/core/math/math.odin index 1ecb1da00..6fe872907 100644 --- a/core/math/math.odin +++ b/core/math/math.odin @@ -1613,17 +1613,11 @@ is_power_of_two :: proc "contextless" (x: int) -> bool { @(require_results) next_power_of_two :: proc "contextless" (x: int) -> int { - k := x -1 - when size_of(int) == 8 { - k = k | (k >> 32) + if x <= 1 { + return 1 } - k = k | (k >> 16) - k = k | (k >> 8) - k = k | (k >> 4) - k = k | (k >> 2) - k = k | (k >> 1) - k += 1 + int(x <= 0) - return k + n := uint(size_of(x) * 8) - uint(intrinsics.count_leading_zeros(uint(x) - 1)) + return int(1) << n } @(require_results)