| ... | ... | @@ -9,7 +9,7 @@ const builtin = @import("builtin"); |
| 9 | 9 | pub fn suggestVectorSizeForCpu(comptime T: type, comptime cpu: std.Target.Cpu) ?usize { |
| 10 | 10 | // This is guesswork, if you have better suggestions can add it or edit the current here |
| 11 | 11 | // This can run in comptime only, but stage 1 fails at it, stage 2 can understand it |
| 12 | | const element_bit_size = @maximum(8, std.math.ceilPowerOfTwo(T, @bitSizeOf(T)) catch unreachable); |
| 12 | const element_bit_size = @maximum(8, std.math.ceilPowerOfTwo(u16, @bitSizeOf(T)) catch unreachable); |
| 13 | 13 | const vector_bit_size: u16 = blk: { |
| 14 | 14 | if (cpu.arch.isX86()) { |
| 15 | 15 | if (T == bool and std.Target.x86.featureSetHas(.prefer_mask_registers)) return 64; |
| ... | ... | @@ -57,6 +57,15 @@ pub fn suggestVectorSize(comptime T: type) ?usize { |
| 57 | 57 | return suggestVectorSizeForCpu(T, builtin.cpu); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | test "suggestVectorSizeForCpu works with signed and unsigned values" { |
| 61 | comptime var cpu = std.Target.Cpu.baseline(std.Target.Cpu.Arch.x86_64); |
| 62 | comptime cpu.features.addFeature(@enumToInt(std.Target.x86.Feature.avx512f)); |
| 63 | const signed_integer_size = suggestVectorSizeForCpu(i32, cpu).?; |
| 64 | const unsigned_integer_size = suggestVectorSizeForCpu(u32, cpu).?; |
| 65 | try std.testing.expectEqual(@as(usize, 16), unsigned_integer_size); |
| 66 | try std.testing.expectEqual(@as(usize, 16), signed_integer_size); |
| 67 | } |
| 68 | |
| 60 | 69 | fn vectorLength(comptime VectorType: type) comptime_int { |
| 61 | 70 | return switch (@typeInfo(VectorType)) { |
| 62 | 71 | .Vector => |info| info.len, |