authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-07 22:48:34-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-10 16:45:29-07:00
log4d7f5a1917f569506682bbb6ee5af672ab1fd8e8
treeae2070a20f8aab228135891cca9a6e5132edce58
parent3c4e9b5983e49fa3179adec8e41e3198f3fd66ae

stage2: fix crash with comptime vector reduce


2 files changed, 27 insertions(+), 0 deletions(-)

src/value.zig+10
...@@ -1194,6 +1194,16 @@ pub const Value = extern union {...@@ -1194,6 +1194,16 @@ pub const Value = extern union {
1194 return switch (self.tag()) {1194 return switch (self.tag()) {
1195 .bool_true, .one => true,1195 .bool_true, .one => true,
1196 .bool_false, .zero => false,1196 .bool_false, .zero => false,
1197 .int_u64 => switch (self.castTag(.int_u64).?.data) {
1198 0 => false,
1199 1 => true,
1200 else => unreachable,
1201 },
1202 .int_i64 => switch (self.castTag(.int_i64).?.data) {
1203 0 => false,
1204 1 => true,
1205 else => unreachable,
1206 },
1197 else => unreachable,1207 else => unreachable,
1198 };1208 };
1199 }1209 }
test/behavior/vector.zig+17
...@@ -807,6 +807,23 @@ test "vector reduce operation" {...@@ -807,6 +807,23 @@ test "vector reduce operation" {
807 comptime try S.doTheTest();807 comptime try S.doTheTest();
808}808}
809809
810test "vector @reduce comptime" {
811 if (builtin.zig_backend == .stage1) return error.SkipZigTest;
812 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
813 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
814 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
815 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
816 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
817
818 const value = @Vector(4, i32){ 1, -1, 1, -1 };
819 const result = value > @splat(4, @as(i32, 0));
820 // result is { true, false, true, false };
821 comptime try expect(@TypeOf(result) == @Vector(4, bool));
822 const is_all_true = @reduce(.And, result);
823 comptime try expect(@TypeOf(is_all_true) == bool);
824 try expect(is_all_true == false);
825}
826
810test "mask parameter of @shuffle is comptime scope" {827test "mask parameter of @shuffle is comptime scope" {
811 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO828 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
812 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO829 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO