cranelift: Implement PartialEq on Ieee{32,64} (#4849)
* cranelift: Add `fcmp` tests
Some of these are disabled on aarch64 due to not being implemented yet.
* cranelift: Implement float PartialEq for Ieee{32,64} (fixes #4828)
Previously `PartialEq` was auto derived. This means that it was implemented in terms of PartialEq in a u32.
This is not correct for floats because `NaN != NaN`.
PartialOrd was manually implemented in 6d50099816, but it seems like it was an oversight to leave PartialEq out until now.
The test suite depends on the previous behaviour so we adjust it to keep comparing bits instead of floats.
* cranelift: Disable `fcmp ord` tests on aarch64
* cranelift: Disable `fcmp ueq` tests on aarch64
This commit is contained in:
@@ -39,10 +39,7 @@ impl RunCommand {
|
||||
}
|
||||
RunCommand::Run(invoke, compare, expected) => {
|
||||
let actual = invoke_fn(&invoke.func, &invoke.args)?;
|
||||
let matched = match compare {
|
||||
Comparison::Equals => *expected == actual,
|
||||
Comparison::NotEquals => *expected != actual,
|
||||
};
|
||||
let matched = Self::compare_results(compare, &actual, expected);
|
||||
if !matched {
|
||||
let actual = DisplayDataValues(&actual);
|
||||
return Err(format!("Failed test: {}, actual: {}", self, actual));
|
||||
@@ -51,6 +48,32 @@ impl RunCommand {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compare_results(
|
||||
compare: &Comparison,
|
||||
actual: &Vec<DataValue>,
|
||||
expected: &Vec<DataValue>,
|
||||
) -> bool {
|
||||
let are_equal = actual
|
||||
.into_iter()
|
||||
.zip(expected.into_iter())
|
||||
.all(|(a, b)| match (a, b) {
|
||||
// We need to bit compare the floats to ensure that we produce the correct values
|
||||
// on NaN's. The test suite expects to assert the precise bit pattern on NaN's or
|
||||
// works around it in the tests themselves.
|
||||
(DataValue::F32(a), DataValue::F32(b)) => a.bits() == b.bits(),
|
||||
(DataValue::F64(a), DataValue::F64(b)) => a.bits() == b.bits(),
|
||||
|
||||
// We don't need to worry about F32x4 / F64x2 Since we compare V128 which is already the
|
||||
// raw bytes anyway
|
||||
(a, b) => a == b,
|
||||
});
|
||||
|
||||
match compare {
|
||||
Comparison::Equals => are_equal,
|
||||
Comparison::NotEquals => !are_equal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for RunCommand {
|
||||
|
||||
Reference in New Issue
Block a user