diff options
| author | kcbanner <kcbanner@gmail.com> | 2024-11-06 20:38:20 -0500 |
|---|---|---|
| committer | kcbanner <kcbanner@gmail.com> | 2025-03-03 15:35:07 -0500 |
| commit | 71d0d4bbfe4cad69afa4d6ca2262f81e6b528018 (patch) | |
| tree | 05e0e5a39a153338376201a778c0ca6aece94cd6 /test/behavior/floatop.zig | |
| parent | 981f84157ce9e37cdc7ea96ea736808b1273142e (diff) | |
| download | zig-71d0d4bbfe4cad69afa4d6ca2262f81e6b528018.tar.gz zig-71d0d4bbfe4cad69afa4d6ca2262f81e6b528018.zip | |
test: separate out float vector tests and skip them on unsupported backends
Diffstat (limited to 'test/behavior/floatop.zig')
| -rw-r--r-- | test/behavior/floatop.zig | 95 |
1 files changed, 90 insertions, 5 deletions
diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig index 0eb1bd2d93..de7d3fd127 100644 --- a/test/behavior/floatop.zig +++ b/test/behavior/floatop.zig @@ -132,13 +132,19 @@ test "cmp f16" { try comptime testCmp(f16); } -test "cmp f32/f64" { +test "cmp f32" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; if (builtin.cpu.arch.isArm() and builtin.target.abi.float() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 try testCmp(f32); try comptime testCmp(f32); +} + +test "cmp f64" { + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest; + if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 + try testCmp(f64); try comptime testCmp(f64); } @@ -194,7 +200,7 @@ fn testCmp(comptime T: type) !void { try expect(x <= 2.0); } - @setEvalBranchQuota(4_000); + @setEvalBranchQuota(2_000); var edges = [_]T{ -math.inf(T), -math.floatMax(T), @@ -210,7 +216,6 @@ fn testCmp(comptime T: type) !void { }; _ = &edges; for (edges, 0..) |rhs, rhs_i| { - const rhs_v: @Vector(4, T) = @splat(rhs); for (edges, 0..) |lhs, lhs_i| { const no_nan = lhs_i != 5 and rhs_i != 5; const lhs_order = if (lhs_i < 5) lhs_i else lhs_i - 2; @@ -221,8 +226,88 @@ fn testCmp(comptime T: type) !void { try expect((lhs > rhs) == (no_nan and lhs_order > rhs_order)); try expect((lhs <= rhs) == (no_nan and lhs_order <= rhs_order)); try expect((lhs >= rhs) == (no_nan and lhs_order >= rhs_order)); + } + } +} + +test "vector cmp f16" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; + if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 + + try testCmpVector(f16); + try comptime testCmpVector(f16); +} + +test "vector cmp f32" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; + if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 + + try testCmpVector(f32); + try comptime testCmpVector(f32); +} + +test "vector cmp f64" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; + if (builtin.cpu.arch.isArm() and builtin.target.floatAbi() == .soft) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21234 + + try testCmpVector(f64); + try comptime testCmpVector(f64); +} + +test "vector cmp f128" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_c and builtin.cpu.arch.isArm()) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; + + try testCmpVector(f128); + try comptime testCmpVector(f128); +} - const lhs_v: @Vector(4, T) = @splat(lhs); +test "vector cmp f80/c_longdouble" { + if (true) return error.SkipZigTest; + + try testCmpVector(f80); + try comptime testCmpVector(f80); + try testCmpVector(c_longdouble); + try comptime testCmpVector(c_longdouble); +} +fn testCmpVector(comptime T: type) !void { + @setEvalBranchQuota(4_000); + var edges = [_]T{ + -math.inf(T), + -math.floatMax(T), + -math.floatMin(T), + -math.floatTrueMin(T), + -0.0, + math.nan(T), + 0.0, + math.floatTrueMin(T), + math.floatMin(T), + math.floatMax(T), + math.inf(T), + }; + _ = &edges; + for (edges, 0..) |rhs, rhs_i| { + const rhs_v: @Vector(4, T) = .{ rhs, rhs, rhs, rhs }; + for (edges, 0..) |lhs, lhs_i| { + const no_nan = lhs_i != 5 and rhs_i != 5; + const lhs_order = if (lhs_i < 5) lhs_i else lhs_i - 2; + const rhs_order = if (rhs_i < 5) rhs_i else rhs_i - 2; + const lhs_v: @Vector(4, T) = .{ lhs, lhs, lhs, lhs }; try expect(@reduce(.And, (lhs_v == rhs_v)) == (no_nan and lhs_order == rhs_order)); try expect(@reduce(.And, (lhs_v != rhs_v)) == !(no_nan and lhs_order == rhs_order)); try expect(@reduce(.And, (lhs_v < rhs_v)) == (no_nan and lhs_order < rhs_order)); |
