mirror of
https://github.com/odin-lang/Odin.git
synced 2026-07-11 02:19:30 +00:00
Use intrinsics.count_leading_zeros internally for math.next_power_of_two
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user