commit 35c9b717f752ceb1a031e0bcfc237a9c4f3bf6ad (tree)
parent 3bf9a8feb50c3ff20da80593a735ec3244cb5d89
Author: Jacob Young <jacobly0@users.noreply.github.com>
Date: Sun, 8 Oct 2023 03:27:12 -0400
x86_64: implement `@rem` for floats
Diffstat:
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig
@@ -6831,12 +6831,12 @@ fn genBinOp(
const rhs_ty = self.typeOf(rhs_air);
const abi_size: u32 = @intCast(lhs_ty.abiSize(mod));
- if (lhs_ty.isRuntimeFloat() and switch (lhs_ty.floatBits(self.target.*)) {
+ if (lhs_ty.isRuntimeFloat() and (air_tag == .rem or switch (lhs_ty.floatBits(self.target.*)) {
16 => !self.hasFeature(.f16c),
32, 64 => false,
80, 128 => true,
else => unreachable,
- }) {
+ })) {
var callee: ["__add?f3".len]u8 = undefined;
const result = try self.genCall(.{ .lib = .{
.return_type = lhs_ty.toIntern(),
@@ -6852,9 +6852,14 @@ fn genBinOp(
@tagName(air_tag)[0..3],
floatCompilerRtAbiName(lhs_ty.floatBits(self.target.*)),
}),
- .min, .max => std.fmt.bufPrint(&callee, "{s}f{s}{s}", .{
+ .rem, .min, .max => std.fmt.bufPrint(&callee, "{s}f{s}{s}", .{
floatLibcAbiPrefix(lhs_ty),
- @tagName(air_tag),
+ switch (air_tag) {
+ .rem => "mod",
+ .min => "min",
+ .max => "max",
+ else => unreachable,
+ },
floatLibcAbiSuffix(lhs_ty),
}),
else => return self.fail("TODO implement genBinOp for {s} {}", .{
diff --git a/test/behavior/math.zig b/test/behavior/math.zig
@@ -1332,6 +1332,7 @@ test "remainder division" {
try comptime remdiv(f80);
try comptime remdiv(f128);
try remdiv(f16);
+ try remdiv(f32);
try remdiv(f64);
try remdiv(f80);
try remdiv(f128);
@@ -1356,7 +1357,7 @@ test "float remainder division using @rem" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
try comptime frem(f16);
try comptime frem(f32);