| ... | @@ -306,7 +306,14 @@ test "math.rotl" { | ... | @@ -306,7 +306,14 @@ test "math.rotl" { |
| 306 | } | 306 | } |
| 307 | | 307 | |
| 308 | pub fn Log2Int(comptime T: type) type { | 308 | pub fn Log2Int(comptime T: type) type { |
| 309 | return @IntType(false, log2(T.bit_count)); | 309 | // comptime ceil log2 |
| | 310 | comptime var count: usize = 0; |
| | 311 | comptime var s = T.bit_count - 1; |
| | 312 | inline while (s != 0) : (s >>= 1) { |
| | 313 | count += 1; |
| | 314 | } |
| | 315 | |
| | 316 | return @IntType(false, count); |
| 310 | } | 317 | } |
| 311 | | 318 | |
| 312 | test "math overflow functions" { | 319 | test "math overflow functions" { |