cranelift-codegen: Add support for immediate to memory moves in x64 (#5461)

This change adds support for immediate to memory moves in x64 which
are needed by Winch for zeroing local slots.

This change follows the guideline in `isa/x64/inst/emit` and uses
other instructions (immediate to register moves) as a base for the
test cases.

The instruction encoding expectation was derived by assembling each
instruction and inspecting the assembly with `objdump`.
This commit is contained in:
Saúl Cabrera
2022-12-19 16:54:45 -05:00
committed by GitHub
parent 921f6ca3b1
commit 962a911163
4 changed files with 184 additions and 0 deletions

View File

@@ -90,6 +90,7 @@ impl Inst {
| Inst::LoadExtName { .. }
| Inst::LockCmpxchg { .. }
| Inst::Mov64MR { .. }
| Inst::MovImmM { .. }
| Inst::MovRM { .. }
| Inst::MovRR { .. }
| Inst::MovFromPReg { .. }
@@ -1252,6 +1253,25 @@ impl PrettyPrint for Inst {
}
}
Inst::MovImmM { size, simm64, dst } => {
let dst = dst.pretty_print(size.to_bytes(), allocs);
let suffix = suffix_bwlq(*size);
let instruction = ljustify2("mov".to_string(), suffix);
match *size {
OperandSize::Size8 => {
format!("{} ${}, {}", instruction, (*simm64 as u8) as i8, dst)
}
OperandSize::Size16 => {
format!("{} ${}, {}", instruction, (*simm64 as u16) as i16, dst)
}
OperandSize::Size32 => {
format!("{} ${}, {}", instruction, (*simm64 as u32) as i32, dst)
}
OperandSize::Size64 => format!("{} ${}, {}", instruction, *simm64 as i64, dst),
}
}
Inst::MovRR { size, src, dst } => {
let src = pretty_print_reg(src.to_reg(), size.to_bytes(), allocs);
let dst = pretty_print_reg(dst.to_reg().to_reg(), size.to_bytes(), allocs);
@@ -1990,6 +2010,11 @@ fn x64_get_operands<F: Fn(VReg) -> VReg>(inst: &Inst, collector: &mut OperandCol
collector.reg_early_def(tmp_xmm.to_writable_reg());
collector.reg_early_def(tmp_xmm2.to_writable_reg());
}
Inst::MovImmM { dst, .. } => {
dst.get_operands(collector);
}
Inst::MovzxRmR { src, dst, .. } => {
collector.reg_def(dst.to_writable_reg());
src.get_operands(collector);