winch: Add full support for integer sub and add instructions (#5737)

This patch adds complete support for the `sub` and `add` WebAssembly instructions
for x64, and complete support for the `add` WebAssembly instruction for aarch64.

This patch also refactors how the binary operations get constructed within the
`VisitOperator` trait implementation. The refactor adds methods in the
`CodeGenContext` to abstract all the common steps to emit binary operations,
making this process less repetitive and less brittle (e.g. omitting to push the resulting value
to the stack, or omitting to free registers after used).

This patch also improves test coverage and refactors the filetests directory to make it
easier to add tests for other instructions.
This commit is contained in:
Saúl Cabrera
2023-02-08 20:01:44 -05:00
committed by GitHub
parent 9637840b4b
commit 7c5c7e4b6d
59 changed files with 992 additions and 120 deletions

View File

@@ -18,8 +18,8 @@ pub(crate) enum OperandSize {
pub(crate) enum RegImm {
/// A register.
Reg(Reg),
/// An immediate.
Imm(i32),
/// 64-bit signed immediate.
Imm(i64),
}
impl RegImm {
@@ -29,7 +29,7 @@ impl RegImm {
}
/// Immediate constructor.
pub fn imm(imm: i32) -> Self {
pub fn imm(imm: i64) -> Self {
RegImm::Imm(imm)
}
}
@@ -88,6 +88,9 @@ pub(crate) trait MacroAssembler {
/// Perform add operation.
fn add(&mut self, dst: RegImm, lhs: RegImm, rhs: RegImm, size: OperandSize);
/// Perform subtraction operation.
fn sub(&mut self, dst: RegImm, lhs: RegImm, rhs: RegImm, size: OperandSize);
/// Push the register to the stack, returning the offset.
fn push(&mut self, src: Reg) -> u32;