authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-04 18:27:52-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-04 18:37:53-07:00
log079f62881ee8291e1b290848c1081c822ea8389f
tree82708449c58daee3f1d00b9cd3b104810cd3ea32
parent5d9429579dbab98d5d565e291dfe89f9b8261526

std.simd.iota: make it always called at comptime

There's no reason for this to ever run at runtime; it should always be used to generate a constant.

1 files changed, 11 insertions(+), 9 deletions(-)

lib/std/simd.zig+11-9
......@@ -86,16 +86,18 @@ pub fn VectorCount(comptime VectorType: type) type {
8686
8787/// Returns a vector containing the first `len` integers in order from 0 to `len`-1.
8888/// For example, `iota(i32, 8)` will return a vector containing `.{0, 1, 2, 3, 4, 5, 6, 7}`.
89pub fn iota(comptime T: type, comptime len: usize) @Vector(len, T) {
90 var out: [len]T = undefined;
91 for (out) |*element, i| {
92 element.* = switch (@typeInfo(T)) {
93 .Int => @intCast(T, i),
94 .Float => @intToFloat(T, i),
95 else => @compileError("Can't use type " ++ @typeName(T) ++ " in iota."),
96 };
89pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) {
90 comptime {
91 var out: [len]T = undefined;
92 for (out) |*element, i| {
93 element.* = switch (@typeInfo(T)) {
94 .Int => @intCast(T, i),
95 .Float => @intToFloat(T, i),
96 else => @compileError("Can't use type " ++ @typeName(T) ++ " in iota."),
97 };
98 }
99 return @as(@Vector(len, T), out);
97100 }
98 return @as(@Vector(len, T), out);
99101}
100102
101103/// Returns a vector containing the same elements as the input, but repeated until the desired length is reached.