Browse Source

winch: Ensure the right return type for f64 comparisons (#8685)

Fixes: https://github.com/bytecodealliance/wasmtime/issues/8632

This commit fixes the handling of f64 comparison operations in Winch.
f64 comparison operations are defined as

	[f64 f64] -> [i32]

The previous implemementation was widening the result to `[i64]`  which
caused issues which stack shuffling in multi-value returns.
pull/8597/head
Saúl Cabrera 6 months ago
committed by GitHub
parent
commit
f52cbbc9de
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 13
      tests/misc_testsuite/winch/float-comparison.wast
  2. 6
      winch/codegen/src/codegen/context.rs
  3. 2
      winch/codegen/src/codegen/control.rs

13
tests/misc_testsuite/winch/float-comparison.wast

@ -0,0 +1,13 @@
(module
(func (result i32 i32 i32)
i32.const 1
i32.eqz
f64.const 0
f64.const 1
f64.ne
i32.const 1111
)
(export "d" (func 0))
)
(assert_return (invoke "d") (i32.const 0) (i32.const 1) (i32.const 1111))

6
winch/codegen/src/codegen/context.rs

@ -261,8 +261,10 @@ impl<'a> CodeGenContext<'a> {
self.free_reg(src2);
let dst = match size {
OperandSize::S32 => TypedReg::i32(dst),
OperandSize::S64 => TypedReg::i64(dst),
// Float comparison operators are defined as
// [f64 f64] -> i32
// https://webassembly.github.io/spec/core/appendix/index-instructions.html
OperandSize::S32 | OperandSize::S64 => TypedReg::i32(dst),
OperandSize::S8 | OperandSize::S16 | OperandSize::S128 => unreachable!(),
};
self.stack.push(dst.into());

2
winch/codegen/src/codegen/control.rs

@ -608,7 +608,7 @@ impl ControlStackFrame {
}
}
/// Orchestrates how blocks results are handled.
/// Orchestrates how block results are handled.
/// Results are handled in reverse order, starting from register results
/// continuing to memory values. This guarantees that the stack ordering
/// invariant is maintained. See [ABIResults] for more details.

Loading…
Cancel
Save