authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-10-08 03:27:12-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-10-08 04:41:55-04:00
log35c9b717f752ceb1a031e0bcfc237a9c4f3bf6ad
tree2935b010fabe7ace5bd7a0030df95c4dc7158246
parent3bf9a8feb50c3ff20da80593a735ec3244cb5d89

x86_64: implement `@rem` for floats


2 files changed, 11 insertions(+), 5 deletions(-)

src/arch/x86_64/CodeGen.zig+9-4
...@@ -6831,12 +6831,12 @@ fn genBinOp(...@@ -6831,12 +6831,12 @@ fn genBinOp(
6831 const rhs_ty = self.typeOf(rhs_air);6831 const rhs_ty = self.typeOf(rhs_air);
6832 const abi_size: u32 = @intCast(lhs_ty.abiSize(mod));6832 const abi_size: u32 = @intCast(lhs_ty.abiSize(mod));
68336833
6834 if (lhs_ty.isRuntimeFloat() and switch (lhs_ty.floatBits(self.target.*)) {6834 if (lhs_ty.isRuntimeFloat() and (air_tag == .rem or switch (lhs_ty.floatBits(self.target.*)) {
6835 16 => !self.hasFeature(.f16c),6835 16 => !self.hasFeature(.f16c),
6836 32, 64 => false,6836 32, 64 => false,
6837 80, 128 => true,6837 80, 128 => true,
6838 else => unreachable,6838 else => unreachable,
6839 }) {6839 })) {
6840 var callee: ["__add?f3".len]u8 = undefined;6840 var callee: ["__add?f3".len]u8 = undefined;
6841 const result = try self.genCall(.{ .lib = .{6841 const result = try self.genCall(.{ .lib = .{
6842 .return_type = lhs_ty.toIntern(),6842 .return_type = lhs_ty.toIntern(),
...@@ -6852,9 +6852,14 @@ fn genBinOp(...@@ -6852,9 +6852,14 @@ fn genBinOp(
6852 @tagName(air_tag)[0..3],6852 @tagName(air_tag)[0..3],
6853 floatCompilerRtAbiName(lhs_ty.floatBits(self.target.*)),6853 floatCompilerRtAbiName(lhs_ty.floatBits(self.target.*)),
6854 }),6854 }),
6855 .min, .max => std.fmt.bufPrint(&callee, "{s}f{s}{s}", .{6855 .rem, .min, .max => std.fmt.bufPrint(&callee, "{s}f{s}{s}", .{
6856 floatLibcAbiPrefix(lhs_ty),6856 floatLibcAbiPrefix(lhs_ty),
6857 @tagName(air_tag),6857 switch (air_tag) {
6858 .rem => "mod",
6859 .min => "min",
6860 .max => "max",
6861 else => unreachable,
6862 },
6858 floatLibcAbiSuffix(lhs_ty),6863 floatLibcAbiSuffix(lhs_ty),
6859 }),6864 }),
6860 else => return self.fail("TODO implement genBinOp for {s} {}", .{6865 else => return self.fail("TODO implement genBinOp for {s} {}", .{
test/behavior/math.zig+2-1
...@@ -1332,6 +1332,7 @@ test "remainder division" {...@@ -1332,6 +1332,7 @@ test "remainder division" {
1332 try comptime remdiv(f80);1332 try comptime remdiv(f80);
1333 try comptime remdiv(f128);1333 try comptime remdiv(f128);
1334 try remdiv(f16);1334 try remdiv(f16);
1335 try remdiv(f32);
1335 try remdiv(f64);1336 try remdiv(f64);
1336 try remdiv(f80);1337 try remdiv(f80);
1337 try remdiv(f128);1338 try remdiv(f128);
...@@ -1356,7 +1357,7 @@ test "float remainder division using @rem" {...@@ -1356,7 +1357,7 @@ test "float remainder division using @rem" {
1356 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO1357 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1357 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1358 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1358 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1359 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1359 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO1360 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
13601361
1361 try comptime frem(f16);1362 try comptime frem(f16);
1362 try comptime frem(f32);1363 try comptime frem(f32);