cranelift: Add MinGW fma regression tests (#4517)

* cranelift: Add MinGW `fma` regression tests

* cranelift: Fix FMA in interpreter

* cranelift: Add separate `fma` test suite for the interpreter

The interpreter can run `fma.clif` on most platforms, however on
`x86_64-pc-windows-gnu` we use libm which has issues with some inputs.
We should delete `fma-interpreter.clif` and enable the interpreter on
the main `fma.clif` file once those are fixed.
This commit is contained in:
Afonso Bordado
2022-07-29 15:09:37 +01:00
committed by GitHub
parent 46782b18c2
commit 1f058a02c0
6 changed files with 70 additions and 15 deletions

View File

@@ -555,10 +555,32 @@ impl Value for DataValue {
fn fma(self, b: Self, c: Self) -> ValueResult<Self> {
match (self, b, c) {
(DataValue::F32(a), DataValue::F32(b), DataValue::F32(c)) => {
Ok(DataValue::F32(a.mul_add(b, c)))
// The `fma` function for `x86_64-pc-windows-gnu` is incorrect. Use `libm`'s instead.
// See: https://github.com/bytecodealliance/wasmtime/issues/4512
#[cfg(all(target_arch = "x86_64", target_os = "windows", target_env = "gnu"))]
let res = libm::fmaf(a.as_f32(), b.as_f32(), c.as_f32());
#[cfg(not(all(
target_arch = "x86_64",
target_os = "windows",
target_env = "gnu"
)))]
let res = a.as_f32().mul_add(b.as_f32(), c.as_f32());
Ok(DataValue::F32(res.into()))
}
(DataValue::F64(a), DataValue::F64(b), DataValue::F64(c)) => {
Ok(DataValue::F64(a.mul_add(b, c)))
#[cfg(all(target_arch = "x86_64", target_os = "windows", target_env = "gnu"))]
let res = libm::fma(a.as_f64(), b.as_f64(), c.as_f64());
#[cfg(not(all(
target_arch = "x86_64",
target_os = "windows",
target_env = "gnu"
)))]
let res = a.as_f64().mul_add(b.as_f64(), c.as_f64());
Ok(DataValue::F64(res.into()))
}
(a, _b, _c) => Err(ValueError::InvalidType(ValueTypeClass::Float, a.ty())),
}