From cff90e3ae0b14da5163ea0c3283557f402001c67 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Mon, 10 Mar 2025 10:30:44 -0400 Subject: x86_64: implement select of register mask --- test/behavior/select.zig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/behavior/select.zig') diff --git a/test/behavior/select.zig b/test/behavior/select.zig index f551ff9533..604227b17f 100644 --- a/test/behavior/select.zig +++ b/test/behavior/select.zig @@ -66,3 +66,23 @@ fn selectArrays() !void { const xyz = @select(f32, x, y, z); try expect(mem.eql(f32, &@as([4]f32, xyz), &[4]f32{ 0.0, 312.1, -145.9, -3381.233 })); } + +test "@select compare result" { + if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; + + const S = struct { + fn min(comptime V: type, lhs: V, rhs: V) V { + return @select(@typeInfo(V).vector.child, lhs < rhs, lhs, rhs); + } + + fn doTheTest() !void { + try expect(@reduce(.And, min(@Vector(4, f32), .{ -1, 2, -3, 4 }, .{ 1, -2, 3, -4 }) == @Vector(4, f32){ -1, -2, -3, -4 })); + try expect(@reduce(.And, min(@Vector(2, f64), .{ -1, 2 }, .{ 1, -2 }) == @Vector(2, f64){ -1, -2 })); + } + }; + + try S.doTheTest(); + try comptime S.doTheTest(); +} -- cgit v1.2.3