commit f2b4e6b2e7ba9da26f69e2d978978adaf8b3f55a (tree)
parent 9c5eea9f40f7f879de2e645b45f9e58eea316357
Author: LemonBoy <thatlemon@gmail.com>
Date: Mon, 9 Nov 2020 17:24:47 +0100
Better coverage in @splat tests
Cover more common and uncommon cases.
Diffstat:
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/test/stage1/behavior/vector.zig b/test/stage1/behavior/vector.zig
@@ -149,15 +149,33 @@ test "vector casts of sizes not divisable by 8" {
test "vector @splat" {
const S = struct {
+ fn testForT(comptime N: comptime_int, v: anytype) void {
+ const T = @TypeOf(v);
+ var vec = @splat(N, v);
+ expectEqual(Vector(N, T), @TypeOf(vec));
+ var as_array = @as([N]T, vec);
+ for (as_array) |elem| expectEqual(v, elem);
+ }
fn doTheTest() void {
- var v: u32 = 5;
- var x = @splat(4, v);
- expect(@TypeOf(x) == Vector(4, u32));
- var array_x: [4]u32 = x;
- expect(array_x[0] == 5);
- expect(array_x[1] == 5);
- expect(array_x[2] == 5);
- expect(array_x[3] == 5);
+ // Splats with multiple-of-8 bit types that fill a 128bit vector.
+ testForT(16, @as(u8, 0xEE));
+ testForT(8, @as(u16, 0xBEEF));
+ testForT(4, @as(u32, 0xDEADBEEF));
+ testForT(2, @as(u64, 0xCAFEF00DDEADBEEF));
+
+ testForT(8, @as(f16, 3.1415));
+ testForT(4, @as(f32, 3.1415));
+ testForT(2, @as(f64, 3.1415));
+
+ // Same but fill more than 128 bits.
+ testForT(16 * 2, @as(u8, 0xEE));
+ testForT(8 * 2, @as(u16, 0xBEEF));
+ testForT(4 * 2, @as(u32, 0xDEADBEEF));
+ testForT(2 * 2, @as(u64, 0xCAFEF00DDEADBEEF));
+
+ testForT(8 * 2, @as(f16, 3.1415));
+ testForT(4 * 2, @as(f32, 3.1415));
+ testForT(2 * 2, @as(f64, 3.1415));
}
};
S.doTheTest();