From 5518a0aff2ab023e9021b74a0a14eb9fcfc094cc Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 5 Oct 2021 16:56:46 -0700 Subject: [PATCH] freestanding libc: export fmal libc requires this to use `long double` which is sometimes the same as f128, sometimes not. Also for an unknown reason, aarch64 is getting an invalid result for the `@mulAdd` behavior test for f128. See #9900. --- lib/std/math/fma.zig | 4 ++++ lib/std/special/c_stage1.zig | 4 ++++ test/behavior/muladd.zig | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/std/math/fma.zig b/lib/std/math/fma.zig index 54d4d071a2..dd76481e10 100644 --- a/lib/std/math/fma.zig +++ b/lib/std/math/fma.zig @@ -15,6 +15,10 @@ pub fn fma(comptime T: type, x: T, y: T, z: T) T { f32 => fma32(x, y, z), f64 => fma64(x, y, z), f128 => fma128(x, y, z), + + // TODO this is not correct for some targets + c_longdouble => @floatCast(c_longdouble, fma128(x, y, z)), + else => @compileError("fma not implemented for " ++ @typeName(T)), }; } diff --git a/lib/std/special/c_stage1.zig b/lib/std/special/c_stage1.zig index 7ea2b95704..c905e8ecac 100644 --- a/lib/std/special/c_stage1.zig +++ b/lib/std/special/c_stage1.zig @@ -656,6 +656,10 @@ export fn ceil(x: f64) f64 { return math.ceil(x); } +export fn fmal(a: c_longdouble, b: c_longdouble, c: c_longdouble) c_longdouble { + return math.fma(c_longdouble, a, b, c); +} + export fn fma(a: f64, b: f64, c: f64) f64 { return math.fma(f64, a, b, c); } diff --git a/test/behavior/muladd.zig b/test/behavior/muladd.zig index eaa30324df..5129303c92 100644 --- a/test/behavior/muladd.zig +++ b/test/behavior/muladd.zig @@ -24,7 +24,8 @@ fn testMulAdd() !void { var c: f64 = 6.25; try expect(@mulAdd(f64, a, b, c) == 20); } - { + // TODO https://github.com/ziglang/zig/issues/9900 + if (@import("builtin").cpu.arch != .aarch64) { var a: f16 = 5.5; var b: f128 = 2.5; var c: f128 = 6.25;