| ... | @@ -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" { |
| 149 | | 149 | |
| 150 | test "vector @splat" { | 150 | test "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(); |