zig
zig copied to clipboard
std.simd.suggestVectorLengthForCpu: fix crashing edge cases
This PR fixes two edge cases in the function std.simd.suggestVectorLengthForCpu which previously caused a compile error, namely:
- a type input of length greater than 8192 bytes (reaching
unreachable) - a RISC-V CPU with features
.vand.zvl65536b(attempting to assign65536to au16)
This approach seems a bit unfortunate for readability. Is there a reason we were using u16 in the first place?
@alexrp My rationale to use the log of the size instead of the size itself is to show that the only values you find as the vector lengths are powers of two, and to make clear that the size of the input type is rounded before the calculation - I find it somewhat easier to read, but if you think otherwise, I'll change it back.
As for using u16, I don't see a reason for it was chosen over any other (runtime available) integer type, we can bump it up to a u32, or better yet, make std.math.ceilPowerOfTwo accept comptime_ints.
I personally prefer the previous approach, yeah.
or better yet, make
std.math.ceilPowerOfTwoacceptcomptime_ints.
This seems like it'd be nice to do. There's been some effort to make other std.math functions accept comptime_int/comptime_float too.
I've made a PR to make std.math.ceilPowerOfTwo (and friends) accept comptime_ints - when that'll be merged (assuming no issues there) I'll update this PR to use the changes.