Skip to content

Commit

Permalink
Use two operands for Winch's masm cmp_with_set method (#6511)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcharles committed Jun 2, 2023
1 parent 112e52d commit ace1388
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 39 deletions.
9 changes: 1 addition & 8 deletions winch/codegen/src/isa/aarch64/masm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,7 @@ impl Masm for MacroAssembler {
Address::offset(reg, offset as i64)
}

fn cmp_with_set(
&mut self,
_dst: RegImm,
_lhs: RegImm,
_rhs: RegImm,
_kind: CmpKind,
_size: OperandSize,
) {
fn cmp_with_set(&mut self, _src: RegImm, _dst: RegImm, _kind: CmpKind, _size: OperandSize) {
todo!()
}
}
Expand Down
21 changes: 3 additions & 18 deletions winch/codegen/src/isa/x64/masm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,9 @@ impl Masm for MacroAssembler {
Address::offset(reg, offset)
}

fn cmp_with_set(
&mut self,
dst: RegImm,
lhs: RegImm,
rhs: RegImm,
kind: CmpKind,
size: OperandSize,
) {
let (src, dst): (Operand, Operand) = if dst == lhs {
(rhs.into(), dst.into())
} else {
panic!(
"the destination and first source argument must be the same, dst={:?}, lhs={:?}",
dst, lhs
);
};

self.asm.cmp(src, dst, size);
fn cmp_with_set(&mut self, src: RegImm, dst: RegImm, kind: CmpKind, size: OperandSize) {
let dst = dst.into();
self.asm.cmp(src.into(), dst, size);
self.asm.setcc(kind, dst);
}
}
Expand Down
11 changes: 2 additions & 9 deletions winch/codegen/src/masm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,9 @@ pub(crate) trait MacroAssembler {
/// Calculate remainder.
fn rem(&mut self, context: &mut CodeGenContext, kind: RemKind, size: OperandSize);

/// Compare two operands and put the result in dst.
/// Compare src and dst and put the result in dst.
/// This function will potentially emit a series of instructions.
fn cmp_with_set(
&mut self,
dst: RegImm,
lhs: RegImm,
rhs: RegImm,
kind: CmpKind,
size: OperandSize,
);
fn cmp_with_set(&mut self, src: RegImm, dst: RegImm, kind: CmpKind, size: OperandSize);

/// Push the register to the stack, returning the offset.
fn push(&mut self, src: Reg) -> u32;
Expand Down
8 changes: 4 additions & 4 deletions winch/codegen/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ where
use OperandSize::*;

self.context.unop(self.masm, S32, &mut |masm, reg, size| {
masm.cmp_with_set(reg, reg, RegImm::imm(0), CmpKind::Eq, size);
masm.cmp_with_set(RegImm::imm(0), reg, CmpKind::Eq, size);
});
}

fn visit_i64_eqz(&mut self) {
use OperandSize::*;

self.context.unop(self.masm, S64, &mut |masm, reg, size| {
masm.cmp_with_set(reg, reg, RegImm::imm(0), CmpKind::Eq, size);
masm.cmp_with_set(RegImm::imm(0), reg, CmpKind::Eq, size);
});
}

Expand Down Expand Up @@ -330,14 +330,14 @@ where
fn cmp_i32s(&mut self, kind: CmpKind) {
self.context
.i32_binop(self.masm, &mut |masm, dst, src, size| {
masm.cmp_with_set(dst, dst, src, kind, size);
masm.cmp_with_set(src, dst, kind, size);
});
}

fn cmp_i64s(&mut self, kind: CmpKind) {
self.context
.i64_binop(self.masm, &mut move |masm, dst, src, size| {
masm.cmp_with_set(dst, dst, src, kind, size);
masm.cmp_with_set(src, dst, kind, size);
});
}
}
Expand Down

0 comments on commit ace1388

Please sign in to comment.