x86_64: implement @rem for floats

This commit is contained in:
Jacob Young 2023-10-08 03:27:12 -04:00
parent 3bf9a8feb5
commit 35c9b717f7
2 changed files with 11 additions and 5 deletions

View File

@ -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} {}", .{

View File

@ -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);