authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-12 19:13:26-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-07-12 19:13:26-07:00
loge05c242cd89d03ae67fa7b8d5fc33fb5dc42dbe3
treea9224a9d47bfda3873284718515cccda78ec32ba
parentd78517f4f0f540f0d0254a78e47a7b4a30e98c74
parent47d5bf26164b4ddb3228d17ae2158d1c29b8d040
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #16346 from antlilja/splat-rls

Apply RLS to @splat builtin, eliminating its length parameter

24 files changed, 174 insertions(+), 156 deletions(-)

doc/langref.html.in+7-7
......@@ -9239,10 +9239,10 @@ test "vector @shuffle" {
92399239 {#header_close#}
92409240
92419241 {#header_open|@splat#}
9242 <pre>{#syntax#}@splat(comptime len: u32, scalar: anytype) @Vector(len, @TypeOf(scalar)){#endsyntax#}</pre>
9242 <pre>{#syntax#}@splat(scalar: anytype) anytype{#endsyntax#}</pre>
92439243 <p>
9244 Produces a vector of length {#syntax#}len{#endsyntax#} where each element is the value
9245 {#syntax#}scalar{#endsyntax#}:
9244 Produces a vector where each element is the value {#syntax#}scalar{#endsyntax#}.
9245 The return type and thus the length of the vector is inferred.
92469246 </p>
92479247 {#code_begin|test|test_splat_builtin#}
92489248const std = @import("std");
......@@ -9250,8 +9250,7 @@ const expect = std.testing.expect;
92509250
92519251test "vector @splat" {
92529252 const scalar: u32 = 5;
9253 const result = @splat(4, scalar);
9254 try comptime expect(@TypeOf(result) == @Vector(4, u32));
9253 const result: @Vector(4, u32) = @splat(scalar);
92559254 try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
92569255}
92579256 {#code_end#}
......@@ -9292,8 +9291,9 @@ const std = @import("std");
92929291const expect = std.testing.expect;
92939292
92949293test "vector @reduce" {
9295 const value = @Vector(4, i32){ 1, -1, 1, -1 };
9296 const result = value > @splat(4, @as(i32, 0));
9294 const V = @Vector(4, i32);
9295 const value = V{ 1, -1, 1, -1 };
9296 const result = value > @as(V, @splat(0));
92979297 // result is { true, false, true, false };
92989298 try comptime expect(@TypeOf(result) == @Vector(4, bool));
92999299 const is_all_true = @reduce(.And, result);
lib/std/http/protocol.zig+2-2
......@@ -182,8 +182,8 @@ pub const HeadersParser = struct {
182182
183183 const chunk = bytes[index..][0..vector_len];
184184 const v: Vector = chunk.*;
185 const matches_r = @as(BitVector, @bitCast(v == @splat(vector_len, @as(u8, '\r'))));
186 const matches_n = @as(BitVector, @bitCast(v == @splat(vector_len, @as(u8, '\n'))));
185 const matches_r = @as(BitVector, @bitCast(v == @as(Vector, @splat('\r'))));
186 const matches_n = @as(BitVector, @bitCast(v == @as(Vector, @splat('\n'))));
187187 const matches_or: SizeVector = matches_r | matches_n;
188188
189189 const matches = @reduce(.Add, matches_or);
lib/std/json/stringify_test.zig+1-1
......@@ -197,7 +197,7 @@ test "stringify struct with custom stringifier" {
197197}
198198
199199test "stringify vector" {
200 try teststringify("[1,1]", @splat(2, @as(u32, 1)), StringifyOptions{});
200 try teststringify("[1,1]", @as(@Vector(2, u32), @splat(1)), StringifyOptions{});
201201}
202202
203203test "stringify tuple" {
lib/std/math.zig+31-21
......@@ -507,8 +507,8 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
507507 if (@typeInfo(T) == .Vector) {
508508 const C = @typeInfo(T).Vector.child;
509509 const len = @typeInfo(T).Vector.len;
510 if (abs_shift_amt >= @typeInfo(C).Int.bits) return @splat(len, @as(C, 0));
511 break :blk @splat(len, @as(Log2Int(C), @intCast(abs_shift_amt)));
510 if (abs_shift_amt >= @typeInfo(C).Int.bits) return @splat(0);
511 break :blk @as(@Vector(len, Log2Int(C)), @splat(@as(Log2Int(C), @intCast(abs_shift_amt))));
512512 } else {
513513 if (abs_shift_amt >= @typeInfo(T).Int.bits) return 0;
514514 break :blk @as(Log2Int(T), @intCast(abs_shift_amt));
......@@ -551,8 +551,8 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
551551 if (@typeInfo(T) == .Vector) {
552552 const C = @typeInfo(T).Vector.child;
553553 const len = @typeInfo(T).Vector.len;
554 if (abs_shift_amt >= @typeInfo(C).Int.bits) return @splat(len, @as(C, 0));
555 break :blk @splat(len, @as(Log2Int(C), @intCast(abs_shift_amt)));
554 if (abs_shift_amt >= @typeInfo(C).Int.bits) return @splat(0);
555 break :blk @as(@Vector(len, Log2Int(C)), @splat(@as(Log2Int(C), @intCast(abs_shift_amt))));
556556 } else {
557557 if (abs_shift_amt >= @typeInfo(T).Int.bits) return 0;
558558 break :blk @as(Log2Int(T), @intCast(abs_shift_amt));
......@@ -597,7 +597,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
597597 @compileError("cannot rotate signed integers");
598598 }
599599 const ar = @as(Log2Int(C), @intCast(@mod(r, @typeInfo(C).Int.bits)));
600 return (x >> @splat(@typeInfo(T).Vector.len, ar)) | (x << @splat(@typeInfo(T).Vector.len, 1 + ~ar));
600 return (x >> @splat(ar)) | (x << @splat(1 + ~ar));
601601 } else if (@typeInfo(T).Int.signedness == .signed) {
602602 @compileError("cannot rotate signed integer");
603603 } else {
......@@ -641,7 +641,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
641641 @compileError("cannot rotate signed integers");
642642 }
643643 const ar = @as(Log2Int(C), @intCast(@mod(r, @typeInfo(C).Int.bits)));
644 return (x << @splat(@typeInfo(T).Vector.len, ar)) | (x >> @splat(@typeInfo(T).Vector.len, 1 +% ~ar));
644 return (x << @splat(ar)) | (x >> @splat(1 +% ~ar));
645645 } else if (@typeInfo(T).Int.signedness == .signed) {
646646 @compileError("cannot rotate signed integer");
647647 } else {
......@@ -794,10 +794,10 @@ pub fn absInt(x: anytype) !@TypeOf(x) {
794794 switch (@typeInfo(vinfo.child)) {
795795 .Int => |info| {
796796 comptime assert(info.signedness == .signed); // must pass a signed integer to absInt
797 if (@reduce(.Or, x == @splat(vinfo.len, @as(vinfo.child, minInt(vinfo.child))))) {
797 if (@reduce(.Or, x == @as(T, @splat(minInt(vinfo.child))))) {
798798 return error.Overflow;
799799 }
800 const zero = @splat(vinfo.len, @as(vinfo.child, 0));
800 const zero: T = @splat(0);
801801 break :blk @select(vinfo.child, x > zero, x, -x);
802802 },
803803 else => @compileError("Expected vector of ints, found " ++ @typeName(T)),
......@@ -1368,9 +1368,9 @@ pub fn lerp(a: anytype, b: anytype, t: anytype) @TypeOf(a, b, t) {
13681368
13691369 switch (@typeInfo(Type)) {
13701370 .Float, .ComptimeFloat => assert(t >= 0 and t <= 1),
1371 .Vector => |vector| {
1372 const lower_bound = @reduce(.And, t >= @splat(vector.len, @as(vector.child, 0)));
1373 const upper_bound = @reduce(.And, t <= @splat(vector.len, @as(vector.child, 1)));
1371 .Vector => {
1372 const lower_bound = @reduce(.And, t >= @as(Type, @splat(0)));
1373 const upper_bound = @reduce(.And, t <= @as(Type, @splat(1)));
13741374 assert(lower_bound and upper_bound);
13751375 },
13761376 else => comptime unreachable,
......@@ -1392,14 +1392,24 @@ test "lerp" {
13921392 try testing.expectEqual(@as(f32, 1.0), lerp(@as(f32, 1.0e7), 1.0, 1.0));
13931393 try testing.expectEqual(@as(f64, 1.0), lerp(@as(f64, 1.0e15), 1.0, 1.0));
13941394
1395 try testing.expectEqual(
1396 lerp(@splat(3, @as(f32, 0)), @splat(3, @as(f32, 50)), @splat(3, @as(f32, 0.5))),
1397 @Vector(3, f32){ 25, 25, 25 },
1398 );
1399 try testing.expectEqual(
1400 lerp(@splat(3, @as(f64, 50)), @splat(3, @as(f64, 100)), @splat(3, @as(f64, 0.5))),
1401 @Vector(3, f64){ 75, 75, 75 },
1402 );
1395 {
1396 const a: @Vector(3, f32) = @splat(0);
1397 const b: @Vector(3, f32) = @splat(50);
1398 const t: @Vector(3, f32) = @splat(0.5);
1399 try testing.expectEqual(
1400 lerp(a, b, t),
1401 @Vector(3, f32){ 25, 25, 25 },
1402 );
1403 }
1404 {
1405 const a: @Vector(3, f64) = @splat(50);
1406 const b: @Vector(3, f64) = @splat(100);
1407 const t: @Vector(3, f64) = @splat(0.5);
1408 try testing.expectEqual(
1409 lerp(a, b, t),
1410 @Vector(3, f64){ 75, 75, 75 },
1411 );
1412 }
14031413}
14041414
14051415/// Returns the maximum value of integer type T.
......@@ -1719,8 +1729,8 @@ pub inline fn sign(i: anytype) @TypeOf(i) {
17191729 .Vector => |vinfo| blk: {
17201730 switch (@typeInfo(vinfo.child)) {
17211731 .Int, .Float => {
1722 const zero = @splat(vinfo.len, @as(vinfo.child, 0));
1723 const one = @splat(vinfo.len, @as(vinfo.child, 1));
1732 const zero: T = @splat(0);
1733 const one: T = @splat(1);
17241734 break :blk @select(vinfo.child, i > zero, one, zero) - @select(vinfo.child, i < zero, one, zero);
17251735 },
17261736 else => @compileError("Expected vector of ints or floats, found " ++ @typeName(T)),
lib/std/mem.zig+4-4
......@@ -289,7 +289,7 @@ pub fn zeroes(comptime T: type) T {
289289 return [_]info.child{zeroes(info.child)} ** info.len;
290290 },
291291 .Vector => |info| {
292 return @splat(info.len, zeroes(info.child));
292 return @splat(zeroes(info.child));
293293 },
294294 .Union => |info| {
295295 if (comptime meta.containerLayout(T) == .Extern) {
......@@ -393,9 +393,9 @@ test "zeroes" {
393393 for (b.array) |e| {
394394 try testing.expectEqual(@as(u32, 0), e);
395395 }
396 try testing.expectEqual(@splat(2, @as(u32, 0)), b.vector_u32);
397 try testing.expectEqual(@splat(2, @as(f32, 0.0)), b.vector_f32);
398 try testing.expectEqual(@splat(2, @as(bool, false)), b.vector_bool);
396 try testing.expectEqual(@as(@TypeOf(b.vector_u32), @splat(0)), b.vector_u32);
397 try testing.expectEqual(@as(@TypeOf(b.vector_f32), @splat(0.0)), b.vector_f32);
398 try testing.expectEqual(@as(@TypeOf(b.vector_bool), @splat(false)), b.vector_bool);
399399 try testing.expectEqual(@as(?u8, null), b.optional_int);
400400 for (b.sentinel) |e| {
401401 try testing.expectEqual(@as(u8, 0), e);
lib/std/meta.zig+4-3
......@@ -860,9 +860,10 @@ test "std.meta.eql" {
860860 try testing.expect(eql(EU.tst(false), EU.tst(false)));
861861 try testing.expect(!eql(EU.tst(false), EU.tst(true)));
862862
863 var v1 = @splat(4, @as(u32, 1));
864 var v2 = @splat(4, @as(u32, 1));
865 var v3 = @splat(4, @as(u32, 2));
863 const V = @Vector(4, u32);
864 var v1: V = @splat(1);
865 var v2: V = @splat(1);
866 var v3: V = @splat(2);
866867
867868 try testing.expect(eql(v1, v2));
868869 try testing.expect(!eql(v1, v3));
lib/std/simd.zig+34-25
......@@ -107,7 +107,7 @@ pub inline fn iota(comptime T: type, comptime len: usize) @Vector(len, T) {
107107pub fn repeat(comptime len: usize, vec: anytype) @Vector(len, std.meta.Child(@TypeOf(vec))) {
108108 const Child = std.meta.Child(@TypeOf(vec));
109109
110 return @shuffle(Child, vec, undefined, iota(i32, len) % @splat(len, @as(i32, @intCast(vectorLength(@TypeOf(vec))))));
110 return @shuffle(Child, vec, undefined, iota(i32, len) % @as(@Vector(len, i32), @splat(@intCast(vectorLength(@TypeOf(vec))))));
111111}
112112
113113/// Returns a vector containing all elements of the first vector at the lower indices followed by all elements of the second vector
......@@ -147,11 +147,12 @@ pub fn interlace(vecs: anytype) @Vector(vectorLength(@TypeOf(vecs[0])) * vecs.le
147147 const len = a_len + b_len;
148148
149149 const indices = comptime blk: {
150 const Vi32 = @Vector(len, i32);
150151 const count_up = iota(i32, len);
151 const cycle = @divFloor(count_up, @splat(len, @as(i32, @intCast(vecs_arr.len))));
152 const select_mask = repeat(len, join(@splat(a_vec_count, true), @splat(b_vec_count, false)));
153 const a_indices = count_up - cycle * @splat(len, @as(i32, @intCast(b_vec_count)));
154 const b_indices = shiftElementsRight(count_up - cycle * @splat(len, @as(i32, @intCast(a_vec_count))), a_vec_count, 0);
152 const cycle = @divFloor(count_up, @as(Vi32, @splat(@intCast(vecs_arr.len))));
153 const select_mask = repeat(len, join(@as(@Vector(a_vec_count, bool), @splat(true)), @as(@Vector(b_vec_count, bool), @splat(false))));
154 const a_indices = count_up - cycle * @as(Vi32, @splat(@intCast(b_vec_count)));
155 const b_indices = shiftElementsRight(count_up - cycle * @as(Vi32, @splat(@intCast(a_vec_count))), a_vec_count, 0);
155156 break :blk @select(i32, select_mask, a_indices, ~b_indices);
156157 };
157158
......@@ -174,7 +175,7 @@ pub fn deinterlace(
174175
175176 comptime var i: usize = 0; // for-loops don't work for this, apparently.
176177 inline while (i < out.len) : (i += 1) {
177 const indices = comptime iota(i32, vec_len) * @splat(vec_len, @as(i32, @intCast(vec_count))) + @splat(vec_len, @as(i32, @intCast(i)));
178 const indices = comptime iota(i32, vec_len) * @as(@Vector(vec_len, i32), @splat(@intCast(vec_count))) + @as(@Vector(vec_len, i32), @splat(@intCast(i)));
178179 out[i] = @shuffle(Child, interlaced, undefined, indices);
179180 }
180181
......@@ -191,7 +192,7 @@ pub fn extract(
191192
192193 std.debug.assert(@as(comptime_int, @intCast(first)) + @as(comptime_int, @intCast(count)) <= len);
193194
194 return @shuffle(Child, vec, undefined, iota(i32, count) + @splat(count, @as(i32, @intCast(first))));
195 return @shuffle(Child, vec, undefined, iota(i32, count) + @as(@Vector(count, i32), @splat(@intCast(first))));
195196}
196197
197198test "vector patterns" {
......@@ -236,17 +237,18 @@ pub fn shiftElementsRight(vec: anytype, comptime amount: VectorCount(@TypeOf(vec
236237 // It may be possible to implement shifts and rotates with a runtime-friendly slice of two joined vectors, as the length of the
237238 // slice would be comptime-known. This would permit vector shifts and rotates by a non-comptime-known amount.
238239 // However, I am unsure whether compiler optimizations would handle that well enough on all platforms.
239 const len = vectorLength(@TypeOf(vec));
240 const V = @TypeOf(vec);
241 const len = vectorLength(V);
240242
241 return mergeShift(@splat(len, shift_in), vec, len - amount);
243 return mergeShift(@as(V, @splat(shift_in)), vec, len - amount);
242244}
243245
244246/// Elements are shifted leftwards (towards lower indices). New elements are added to the right, and the leftmost elements are cut off
245247/// so that no elements with indices below 0 remain.
246248pub fn shiftElementsLeft(vec: anytype, comptime amount: VectorCount(@TypeOf(vec)), shift_in: std.meta.Child(@TypeOf(vec))) @TypeOf(vec) {
247 const len = vectorLength(@TypeOf(vec));
249 const V = @TypeOf(vec);
248250
249 return mergeShift(vec, @splat(len, shift_in), amount);
251 return mergeShift(vec, @as(V, @splat(shift_in)), amount);
250252}
251253
252254/// Elements are shifted leftwards (towards lower indices). Elements that leave to the left will reappear to the right in the same order.
......@@ -263,7 +265,7 @@ pub fn reverseOrder(vec: anytype) @TypeOf(vec) {
263265 const Child = std.meta.Child(@TypeOf(vec));
264266 const len = vectorLength(@TypeOf(vec));
265267
266 return @shuffle(Child, vec, undefined, @splat(len, @as(i32, @intCast(len)) - 1) - iota(i32, len));
268 return @shuffle(Child, vec, undefined, @as(@Vector(len, i32), @splat(@as(i32, @intCast(len)) - 1)) - iota(i32, len));
267269}
268270
269271test "vector shifting" {
......@@ -283,7 +285,8 @@ pub fn firstTrue(vec: anytype) ?VectorIndex(@TypeOf(vec)) {
283285 if (!@reduce(.Or, vec)) {
284286 return null;
285287 }
286 const indices = @select(IndexInt, vec, iota(IndexInt, len), @splat(len, ~@as(IndexInt, 0)));
288 const all_max: @Vector(len, IndexInt) = @splat(~@as(IndexInt, 0));
289 const indices = @select(IndexInt, vec, iota(IndexInt, len), all_max);
287290 return @reduce(.Min, indices);
288291}
289292
......@@ -294,7 +297,9 @@ pub fn lastTrue(vec: anytype) ?VectorIndex(@TypeOf(vec)) {
294297 if (!@reduce(.Or, vec)) {
295298 return null;
296299 }
297 const indices = @select(IndexInt, vec, iota(IndexInt, len), @splat(len, @as(IndexInt, 0)));
300
301 const all_zeroes: @Vector(len, IndexInt) = @splat(0);
302 const indices = @select(IndexInt, vec, iota(IndexInt, len), all_zeroes);
298303 return @reduce(.Max, indices);
299304}
300305
......@@ -302,26 +307,29 @@ pub fn countTrues(vec: anytype) VectorCount(@TypeOf(vec)) {
302307 const len = vectorLength(@TypeOf(vec));
303308 const CountIntType = VectorCount(@TypeOf(vec));
304309
305 const one_if_true = @select(CountIntType, vec, @splat(len, @as(CountIntType, 1)), @splat(len, @as(CountIntType, 0)));
310 const all_ones: @Vector(len, CountIntType) = @splat(1);
311 const all_zeroes: @Vector(len, CountIntType) = @splat(0);
312
313 const one_if_true = @select(CountIntType, vec, all_ones, all_zeroes);
306314 return @reduce(.Add, one_if_true);
307315}
308316
309317pub fn firstIndexOfValue(vec: anytype, value: std.meta.Child(@TypeOf(vec))) ?VectorIndex(@TypeOf(vec)) {
310 const len = vectorLength(@TypeOf(vec));
318 const V = @TypeOf(vec);
311319
312 return firstTrue(vec == @splat(len, value));
320 return firstTrue(vec == @as(V, @splat(value)));
313321}
314322
315323pub fn lastIndexOfValue(vec: anytype, value: std.meta.Child(@TypeOf(vec))) ?VectorIndex(@TypeOf(vec)) {
316 const len = vectorLength(@TypeOf(vec));
324 const V = @TypeOf(vec);
317325
318 return lastTrue(vec == @splat(len, value));
326 return lastTrue(vec == @as(V, @splat(value)));
319327}
320328
321329pub fn countElementsWithValue(vec: anytype, value: std.meta.Child(@TypeOf(vec))) VectorCount(@TypeOf(vec)) {
322 const len = vectorLength(@TypeOf(vec));
330 const V = @TypeOf(vec);
323331
324 return countTrues(vec == @splat(len, value));
332 return countTrues(vec == @as(V, @splat(value)));
325333}
326334
327335test "vector searching" {
......@@ -370,7 +378,6 @@ pub fn prefixScanWithFunc(
370378pub fn prefixScan(comptime op: std.builtin.ReduceOp, comptime hop: isize, vec: anytype) @TypeOf(vec) {
371379 const VecType = @TypeOf(vec);
372380 const Child = std.meta.Child(VecType);
373 const len = vectorLength(VecType);
374381
375382 const identity = comptime switch (@typeInfo(Child)) {
376383 .Bool => switch (op) {
......@@ -397,8 +404,8 @@ pub fn prefixScan(comptime op: std.builtin.ReduceOp, comptime hop: isize, vec: a
397404 const fn_container = struct {
398405 fn opFn(a: VecType, b: VecType) VecType {
399406 return if (Child == bool) switch (op) {
400 .And => @select(bool, a, b, @splat(len, false)),
401 .Or => @select(bool, a, @splat(len, true), b),
407 .And => @select(bool, a, b, @as(VecType, @splat(false))),
408 .Or => @select(bool, a, @as(VecType, @splat(true)), b),
402409 .Xor => a != b,
403410 else => unreachable,
404411 } else switch (op) {
......@@ -431,7 +438,9 @@ test "vector prefix scan" {
431438 const float_base = @Vector(4, f32){ 2, 0.5, -10, 6.54321 };
432439 const bool_base = @Vector(4, bool){ true, false, true, false };
433440
434 try std.testing.expectEqual(iota(u8, 32) + @splat(32, @as(u8, 1)), prefixScan(.Add, 1, @splat(32, @as(u8, 1))));
441 const ones: @Vector(32, u8) = @splat(1);
442
443 try std.testing.expectEqual(iota(u8, 32) + ones, prefixScan(.Add, 1, ones));
435444 try std.testing.expectEqual(@Vector(4, i32){ 11, 3, 1, 1 }, prefixScan(.And, 1, int_base));
436445 try std.testing.expectEqual(@Vector(4, i32){ 11, 31, 31, -1 }, prefixScan(.Or, 1, int_base));
437446 try std.testing.expectEqual(@Vector(4, i32){ 11, 28, 21, -2 }, prefixScan(.Xor, 1, int_base));
lib/std/testing.zig+3-3
......@@ -606,8 +606,8 @@ test "expectEqual nested array" {
606606}
607607
608608test "expectEqual vector" {
609 var a = @splat(4, @as(u32, 4));
610 var b = @splat(4, @as(u32, 4));
609 var a: @Vector(4, u32) = @splat(4);
610 var b: @Vector(4, u32) = @splat(4);
611611
612612 try expectEqual(a, b);
613613}
......@@ -903,7 +903,7 @@ test "expectEqualDeep composite type" {
903903 try expectEqualDeep([_][]const u8{ "a", "b", "c" }, [_][]const u8{ "a", "b", "c" });
904904
905905 // vector
906 try expectEqualDeep(@splat(4, @as(u32, 4)), @splat(4, @as(u32, 4)));
906 try expectEqualDeep(@as(@Vector(4, u32), @splat(4)), @as(@Vector(4, u32), @splat(4)));
907907
908908 // nested array
909909 {
src/AstGen.zig+10-3
......@@ -8591,10 +8591,17 @@ fn builtinCall(
85918591 },
85928592
85938593 .splat => {
8594 const len = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0]);
8595 const scalar = try expr(gz, scope, .{ .rl = .none }, params[1]);
8594 const result_type = try ri.rl.resultType(gz, node, "@splat");
8595 const elem_type = try gz.add(.{
8596 .tag = .elem_type_index,
8597 .data = .{ .bin = .{
8598 .lhs = result_type,
8599 .rhs = @as(Zir.Inst.Ref, @enumFromInt(0)),
8600 } },
8601 });
8602 const scalar = try expr(gz, scope, .{ .rl = .{ .ty = elem_type } }, params[0]);
85968603 const result = try gz.addPlNode(.splat, node, Zir.Inst.Bin{
8597 .lhs = len,
8604 .lhs = result_type,
85988605 .rhs = scalar,
85998606 });
86008607 return rvalue(gz, ri, result, node);
src/BuiltinFn.zig+1-1
......@@ -792,7 +792,7 @@ pub const list = list: {
792792 "@splat",
793793 .{
794794 .tag = .splat,
795 .param_count = 2,
795 .param_count = 1,
796796 },
797797 },
798798 .{
src/Sema.zig+24-25
......@@ -1820,7 +1820,7 @@ pub fn resolveType(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Ins
18201820 return ty;
18211821}
18221822
1823fn resolveCastDestType(
1823fn resolveDestType(
18241824 sema: *Sema,
18251825 block: *Block,
18261826 src: LazySrcLoc,
......@@ -8337,7 +8337,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
83378337 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
83388338 const src = inst_data.src();
83398339 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8340 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");
8340 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");
83418341 const operand = try sema.resolveInst(extra.rhs);
83428342
83438343 if (dest_ty.zigTypeTag(mod) != .Enum) {
......@@ -9666,7 +9666,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
96669666 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
96679667 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
96689668
9669 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast");
9669 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast");
96709670 const operand = try sema.resolveInst(extra.rhs);
96719671
96729672 return sema.intCast(block, inst_data.src(), dest_ty, src, operand, operand_src, true);
......@@ -9827,7 +9827,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
98279827 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
98289828 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
98299829
9830 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast");
9830 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast");
98319831 const operand = try sema.resolveInst(extra.rhs);
98329832 const operand_ty = sema.typeOf(operand);
98339833 switch (dest_ty.zigTypeTag(mod)) {
......@@ -9970,7 +9970,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
99709970 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
99719971 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
99729972
9973 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast");
9973 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast");
99749974 const operand = try sema.resolveInst(extra.rhs);
99759975
99769976 const target = mod.getTarget();
......@@ -20783,7 +20783,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2078320783 const src = inst_data.src();
2078420784 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2078520785 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20786 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat");
20786 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat");
2078720787 const operand = try sema.resolveInst(extra.rhs);
2078820788 const operand_ty = sema.typeOf(operand);
2078920789
......@@ -20823,7 +20823,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2082320823 const src = inst_data.src();
2082420824 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2082520825 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20826 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt");
20826 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt");
2082720827 const operand = try sema.resolveInst(extra.rhs);
2082820828 const operand_ty = sema.typeOf(operand);
2082920829
......@@ -20852,7 +20852,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2085220852 const operand_res = try sema.resolveInst(extra.rhs);
2085320853 const operand_coerced = try sema.coerce(block, Type.usize, operand_res, operand_src);
2085420854
20855 const ptr_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu, "@ptrFromInt");
20855 const ptr_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrFromInt");
2085620856 try sema.checkPtrType(block, src, ptr_ty);
2085720857 const elem_ty = ptr_ty.elemType2(mod);
2085820858 const ptr_align = try ptr_ty.ptrAlignmentAdvanced(mod, sema);
......@@ -20910,7 +20910,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2091020910 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2091120911 const src = LazySrcLoc.nodeOffset(extra.node);
2091220912 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
20913 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu_opt, "@errSetCast");
20913 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@errSetCast");
2091420914 const operand = try sema.resolveInst(extra.rhs);
2091520915 const operand_ty = sema.typeOf(operand);
2091620916 try sema.checkErrorSetType(block, src, dest_ty);
......@@ -20997,7 +20997,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa
2099720997 const src = LazySrcLoc.nodeOffset(extra.node);
2099820998 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };
2099920999 const operand = try sema.resolveInst(extra.rhs);
21000 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName());
21000 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName());
2100121001 return sema.ptrCastFull(
2100221002 block,
2100321003 flags,
......@@ -21013,7 +21013,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2101321013 const src = inst_data.src();
2101421014 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2101521015 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
21016 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu, "@ptrCast");
21016 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast");
2101721017 const operand = try sema.resolveInst(extra.rhs);
2101821018
2101921019 return sema.ptrCastFull(
......@@ -21426,7 +21426,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2142621426 const src = inst_data.src();
2142721427 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2142821428 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
21429 const dest_ty = try sema.resolveCastDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate");
21429 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate");
2143021430 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src);
2143121431 const operand = try sema.resolveInst(extra.rhs);
2143221432 const operand_ty = sema.typeOf(operand);
......@@ -22358,23 +22358,22 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2235822358 const mod = sema.mod;
2235922359 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2236022360 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
22361 const len_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
22362 const scalar_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
22363 const len = @as(u32, @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector splat destination length must be comptime-known")));
22364 const scalar = try sema.resolveInst(extra.rhs);
22365 const scalar_ty = sema.typeOf(scalar);
22366 try sema.checkVectorElemType(block, scalar_src, scalar_ty);
22367 const vector_ty = try mod.vectorType(.{
22368 .len = len,
22369 .child = scalar_ty.toIntern(),
22370 });
22361 const src = inst_data.src();
22362 const scalar_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22363 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat");
22364
22365 if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(mod)});
22366
22367 const operand = try sema.resolveInst(extra.rhs);
22368 const scalar_ty = dest_ty.childType(mod);
22369 const scalar = try sema.coerce(block, scalar_ty, operand, scalar_src);
2237122370 if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| {
22372 if (scalar_val.isUndef(mod)) return sema.addConstUndef(vector_ty);
22373 return sema.addConstant(try sema.splat(vector_ty, scalar_val));
22371 if (scalar_val.isUndef(mod)) return sema.addConstUndef(dest_ty);
22372 return sema.addConstant(try sema.splat(dest_ty, scalar_val));
2237422373 }
2237522374
2237622375 try sema.requireRuntimeBlock(block, inst_data.src(), scalar_src);
22377 return block.addTyOp(.splat, vector_ty, scalar);
22376 return block.addTyOp(.splat, dest_ty, scalar);
2237822377}
2237922378
2238022379fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
src/translate_c.zig+6-6
......@@ -2799,14 +2799,14 @@ fn transInitListExprVector(
27992799 const element_qt = vector_ty.getElementType();
28002800
28012801 if (init_count == 0) {
2802 const zero_node = try Tag.as.create(c.arena, .{
2803 .lhs = try transQualType(c, scope, element_qt, loc),
2804 .rhs = Tag.zero_literal.init(),
2802 const vec_node = try Tag.vector.create(c.arena, .{
2803 .lhs = try transCreateNodeNumber(c, num_elements, .int),
2804 .rhs = try transQualType(c, scope, element_qt, loc),
28052805 });
28062806
2807 return Tag.vector_zero_init.create(c.arena, .{
2808 .lhs = try transCreateNodeNumber(c, num_elements, .int),
2809 .rhs = zero_node,
2807 return Tag.as.create(c.arena, .{
2808 .lhs = vec_node,
2809 .rhs = try Tag.vector_zero_init.create(c.arena, Tag.zero_literal.init()),
28102810 });
28112811 }
28122812
src/translate_c/ast.zig+3-3
......@@ -153,7 +153,7 @@ pub const Node = extern union {
153153 div_exact,
154154 /// @offsetOf(lhs, rhs)
155155 offset_of,
156 /// @splat(lhs, rhs)
156 /// @splat(operand)
157157 vector_zero_init,
158158 /// @shuffle(type, a, b, mask)
159159 shuffle,
......@@ -284,6 +284,7 @@ pub const Node = extern union {
284284 .int_cast,
285285 .const_cast,
286286 .volatile_cast,
287 .vector_zero_init,
287288 => Payload.UnOp,
288289
289290 .add,
......@@ -334,7 +335,6 @@ pub const Node = extern union {
334335 .div_exact,
335336 .offset_of,
336337 .helpers_cast,
337 .vector_zero_init,
338338 => Payload.BinOp,
339339
340340 .integer_literal,
......@@ -1918,7 +1918,7 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
19181918 },
19191919 .vector_zero_init => {
19201920 const payload = node.castTag(.vector_zero_init).?.data;
1921 return renderBuiltinCall(c, "@splat", &.{ payload.lhs, payload.rhs });
1921 return renderBuiltinCall(c, "@splat", &.{payload});
19221922 },
19231923 .field_access => {
19241924 const payload = node.castTag(.field_access).?.data;
stage1/zig.h-6
......@@ -3178,12 +3178,6 @@ zig_bitCast_float(f64, uint64_t)
31783178zig_bitCast_float(f80, zig_u128)
31793179zig_bitCast_float(f128, zig_u128)
31803180
3181#define zig_cast_f16
3182#define zig_cast_f32
3183#define zig_cast_f64
3184#define zig_cast_f80
3185#define zig_cast_f128
3186
31873181#define zig_convert_builtin(ExternResType, ResType, operation, ExternArgType, ArgType, version) \
31883182 zig_extern ExternResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \
31893183 zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ExternArgType); \
stage1/zig1.wasm
Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ
test/behavior/bitcast.zig+1-1
......@@ -396,7 +396,7 @@ test "bitcast vector to integer and back" {
396396 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
397397
398398 const arr: [16]bool = [_]bool{ true, false } ++ [_]bool{true} ** 14;
399 var x = @splat(16, true);
399 var x: @Vector(16, bool) = @splat(true);
400400 x[1] = false;
401401 try expect(@as(u16, @bitCast(x)) == comptime @as(u16, @bitCast(@as(@Vector(16, bool), arr))));
402402}
test/behavior/cast.zig+1-1
......@@ -639,7 +639,7 @@ test "vector casts" {
639639 }
640640
641641 fn doTheTestFloat() !void {
642 var vec = @splat(2, @as(f32, 1234.0));
642 var vec: @Vector(2, f32) = @splat(1234.0);
643643 var wider: @Vector(2, f64) = vec;
644644 try expect(wider[0] == 1234.0);
645645 try expect(wider[1] == 1234.0);
test/behavior/math.zig+16-10
......@@ -111,13 +111,17 @@ test "@clz vectors" {
111111}
112112
113113fn testClzVectors() !void {
114 const Vu4 = @Vector(64, u4);
115 const Vu8 = @Vector(64, u8);
116 const Vu128 = @Vector(64, u128);
117
114118 @setEvalBranchQuota(10_000);
115 try testOneClzVector(u8, 64, @splat(64, @as(u8, 0b10001010)), @splat(64, @as(u4, 0)));
116 try testOneClzVector(u8, 64, @splat(64, @as(u8, 0b00001010)), @splat(64, @as(u4, 4)));
117 try testOneClzVector(u8, 64, @splat(64, @as(u8, 0b00011010)), @splat(64, @as(u4, 3)));
118 try testOneClzVector(u8, 64, @splat(64, @as(u8, 0b00000000)), @splat(64, @as(u4, 8)));
119 try testOneClzVector(u128, 64, @splat(64, @as(u128, 0xffffffffffffffff)), @splat(64, @as(u8, 64)));
120 try testOneClzVector(u128, 64, @splat(64, @as(u128, 0x10000000000000000)), @splat(64, @as(u8, 63)));
119 try testOneClzVector(u8, 64, @as(Vu8, @splat(0b10001010)), @as(Vu4, @splat(0)));
120 try testOneClzVector(u8, 64, @as(Vu8, @splat(0b00001010)), @as(Vu4, @splat(4)));
121 try testOneClzVector(u8, 64, @as(Vu8, @splat(0b00011010)), @as(Vu4, @splat(3)));
122 try testOneClzVector(u8, 64, @as(Vu8, @splat(0b00000000)), @as(Vu4, @splat(8)));
123 try testOneClzVector(u128, 64, @as(Vu128, @splat(0xffffffffffffffff)), @as(Vu8, @splat(64)));
124 try testOneClzVector(u128, 64, @as(Vu128, @splat(0x10000000000000000)), @as(Vu8, @splat(63)));
121125}
122126
123127fn testOneClzVector(
......@@ -180,11 +184,13 @@ test "@ctz vectors" {
180184}
181185
182186fn testCtzVectors() !void {
187 const Vu4 = @Vector(64, u4);
188 const Vu8 = @Vector(64, u8);
183189 @setEvalBranchQuota(10_000);
184 try testOneCtzVector(u8, 64, @splat(64, @as(u8, 0b10100000)), @splat(64, @as(u4, 5)));
185 try testOneCtzVector(u8, 64, @splat(64, @as(u8, 0b10001010)), @splat(64, @as(u4, 1)));
186 try testOneCtzVector(u8, 64, @splat(64, @as(u8, 0b00000000)), @splat(64, @as(u4, 8)));
187 try testOneCtzVector(u16, 64, @splat(64, @as(u16, 0b00000000)), @splat(64, @as(u5, 16)));
190 try testOneCtzVector(u8, 64, @as(Vu8, @splat(0b10100000)), @as(Vu4, @splat(5)));
191 try testOneCtzVector(u8, 64, @as(Vu8, @splat(0b10001010)), @as(Vu4, @splat(1)));
192 try testOneCtzVector(u8, 64, @as(Vu8, @splat(0b00000000)), @as(Vu4, @splat(8)));
193 try testOneCtzVector(u16, 64, @as(@Vector(64, u16), @splat(0b00000000)), @as(@Vector(64, u5), @splat(16)));
188194}
189195
190196fn testOneCtzVector(
test/behavior/vector.zig+21-18
......@@ -299,8 +299,7 @@ test "vector @splat" {
299299 const S = struct {
300300 fn testForT(comptime N: comptime_int, v: anytype) !void {
301301 const T = @TypeOf(v);
302 var vec = @splat(N, v);
303 try expect(@Vector(N, T) == @TypeOf(vec));
302 var vec: @Vector(N, T) = @splat(v);
304303 var as_array = @as([N]T, vec);
305304 for (as_array) |elem| try expect(v == elem);
306305 }
......@@ -458,26 +457,28 @@ test "vector comparison operators" {
458457 const S = struct {
459458 fn doTheTest() !void {
460459 {
461 var v1: @Vector(4, bool) = [_]bool{ true, false, true, false };
462 var v2: @Vector(4, bool) = [_]bool{ false, true, false, true };
463 try expect(mem.eql(bool, &@as([4]bool, @splat(4, true)), &@as([4]bool, v1 == v1)));
464 try expect(mem.eql(bool, &@as([4]bool, @splat(4, false)), &@as([4]bool, v1 == v2)));
465 try expect(mem.eql(bool, &@as([4]bool, @splat(4, true)), &@as([4]bool, v1 != v2)));
466 try expect(mem.eql(bool, &@as([4]bool, @splat(4, false)), &@as([4]bool, v2 != v2)));
460 const V = @Vector(4, bool);
461 var v1: V = [_]bool{ true, false, true, false };
462 var v2: V = [_]bool{ false, true, false, true };
463 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v1)));
464 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v2)));
465 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v2)));
466 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v2 != v2)));
467467 }
468468 {
469 var v1 = @splat(4, @as(u32, 0xc0ffeeee));
469 const V = @Vector(4, bool);
470 var v1: @Vector(4, u32) = @splat(0xc0ffeeee);
470471 var v2: @Vector(4, c_uint) = v1;
471 var v3 = @splat(4, @as(u32, 0xdeadbeef));
472 try expect(mem.eql(bool, &@as([4]bool, @splat(4, true)), &@as([4]bool, v1 == v2)));
473 try expect(mem.eql(bool, &@as([4]bool, @splat(4, false)), &@as([4]bool, v1 == v3)));
474 try expect(mem.eql(bool, &@as([4]bool, @splat(4, true)), &@as([4]bool, v1 != v3)));
475 try expect(mem.eql(bool, &@as([4]bool, @splat(4, false)), &@as([4]bool, v1 != v2)));
472 var v3: @Vector(4, u32) = @splat(0xdeadbeef);
473 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 == v2)));
474 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 == v3)));
475 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(true))), &@as([4]bool, v1 != v3)));
476 try expect(mem.eql(bool, &@as([4]bool, @as(V, @splat(false))), &@as([4]bool, v1 != v2)));
476477 }
477478 {
478479 // Comptime-known LHS/RHS
479480 var v1: @Vector(4, u32) = [_]u32{ 2, 1, 2, 1 };
480 const v2 = @splat(4, @as(u32, 2));
481 const v2: @Vector(4, u32) = @splat(2);
481482 const v3: @Vector(4, bool) = [_]bool{ true, false, true, false };
482483 try expect(mem.eql(bool, &@as([4]bool, v3), &@as([4]bool, v1 == v2)));
483484 try expect(mem.eql(bool, &@as([4]bool, v3), &@as([4]bool, v2 == v1)));
......@@ -847,8 +848,10 @@ test "vector @reduce comptime" {
847848 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
848849 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
849850
850 const value = @Vector(4, i32){ 1, -1, 1, -1 };
851 const result = value > @splat(4, @as(i32, 0));
851 const V = @Vector(4, i32);
852
853 const value = V{ 1, -1, 1, -1 };
854 const result = value > @as(V, @splat(0));
852855 // result is { true, false, true, false };
853856 try comptime expect(@TypeOf(result) == @Vector(4, bool));
854857 const is_all_true = @reduce(.And, result);
......@@ -1270,7 +1273,7 @@ test "array operands to shuffle are coerced to vectors" {
12701273 const mask = [5]i32{ -1, 0, 1, 2, 3 };
12711274
12721275 var a = [5]u32{ 3, 5, 7, 9, 0 };
1273 var b = @shuffle(u32, a, @splat(5, @as(u24, 0)), mask);
1276 var b = @shuffle(u32, a, @as(@Vector(5, u24), @splat(0)), mask);
12741277 try expectEqual([_]u32{ 0, 3, 5, 7, 9 }, b);
12751278}
12761279
test/cases/compile_errors/bad_splat_type.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 const c = 4;
3 var v = @splat(4, c);
4 _ = v;
5}
6
7// error
8// backend=stage2
9// target=native
10//
11// :3:23: error: expected integer, float, bool, or pointer for the vector element type; found 'comptime_int'
test/cases/compile_errors/branch_in_comptime_only_scope_uses_condbr_inline.zig+2-2
......@@ -1,13 +1,13 @@
11pub export fn entry1() void {
22 var x: u32 = 3;
3 _ = @shuffle(u32, [_]u32{0}, @splat(1, @as(u32, 0)), [_]i8{
3 _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{
44 if (x > 1) 1 else -1,
55 });
66}
77
88pub export fn entry2() void {
99 var y: ?i8 = -1;
10 _ = @shuffle(u32, [_]u32{0}, @splat(1, @as(u32, 0)), [_]i8{
10 _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{
1111 y orelse 1,
1212 });
1313}
test/cases/safety/signed-unsigned vector cast.zig +1-1
......@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010
1111pub fn main() !void {
12 var x = @splat(4, @as(i32, -2147483647));
12 var x: @Vector(4, i32) = @splat(-2147483647);
1313 var y: @Vector(4, u32) = @intCast(x);
1414 _ = y;
1515 return error.TestFailed;
test/cases/safety/truncating vector cast.zig +1-1
......@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010
1111pub fn main() !void {
12 var x = @splat(4, @as(u32, 0xdeadbeef));
12 var x: @Vector(4, u32) = @splat(0xdeadbeef);
1313 var y: @Vector(4, u16) = @intCast(x);
1414 _ = y;
1515 return error.TestFailed;
test/cases/safety/unsigned-signed vector cast.zig +1-1
......@@ -9,7 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
99}
1010
1111pub fn main() !void {
12 var x = @splat(4, @as(u32, 0x80000000));
12 var x: @Vector(4, u32) = @splat(0x80000000);
1313 var y: @Vector(4, i32) = @intCast(x);
1414 _ = y;
1515 return error.TestFailed;