authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-09 17:24:47+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-20 08:38:10+01:00
logf2b4e6b2e7ba9da26f69e2d978978adaf8b3f55a
tree509176c106707c1bdd64281aa362fe3fe2d490bf
parent9c5eea9f40f7f879de2e645b45f9e58eea316357

Better coverage in @splat tests

Cover more common and uncommon cases.

1 files changed, 26 insertions(+), 8 deletions(-)

test/stage1/behavior/vector.zig+26-8
...@@ -149,15 +149,33 @@ test "vector casts of sizes not divisable by 8" {...@@ -149,15 +149,33 @@ test "vector casts of sizes not divisable by 8" {
149149
150test "vector @splat" {150test "vector @splat" {
151 const S = struct {151 const S = struct {
152 fn testForT(comptime N: comptime_int, v: anytype) void {
153 const T = @TypeOf(v);
154 var vec = @splat(N, v);
155 expectEqual(Vector(N, T), @TypeOf(vec));
156 var as_array = @as([N]T, vec);
157 for (as_array) |elem| expectEqual(v, elem);
158 }
152 fn doTheTest() void {159 fn doTheTest() void {
153 var v: u32 = 5;160 // Splats with multiple-of-8 bit types that fill a 128bit vector.
154 var x = @splat(4, v);161 testForT(16, @as(u8, 0xEE));
155 expect(@TypeOf(x) == Vector(4, u32));162 testForT(8, @as(u16, 0xBEEF));
156 var array_x: [4]u32 = x;163 testForT(4, @as(u32, 0xDEADBEEF));
157 expect(array_x[0] == 5);164 testForT(2, @as(u64, 0xCAFEF00DDEADBEEF));
158 expect(array_x[1] == 5);165
159 expect(array_x[2] == 5);166 testForT(8, @as(f16, 3.1415));
160 expect(array_x[3] == 5);167 testForT(4, @as(f32, 3.1415));
168 testForT(2, @as(f64, 3.1415));
169
170 // Same but fill more than 128 bits.
171 testForT(16 * 2, @as(u8, 0xEE));
172 testForT(8 * 2, @as(u16, 0xBEEF));
173 testForT(4 * 2, @as(u32, 0xDEADBEEF));
174 testForT(2 * 2, @as(u64, 0xCAFEF00DDEADBEEF));
175
176 testForT(8 * 2, @as(f16, 3.1415));
177 testForT(4 * 2, @as(f32, 3.1415));
178 testForT(2 * 2, @as(f64, 3.1415));
161 }179 }
162 };180 };
163 S.doTheTest();181 S.doTheTest();