Skip to content

Commit 41bbc45

Browse files
authored
x64: Remove MovImmM and MovRM (bytecodealliance#11021)
This commit removes these two instruction variants although nothing new was added to the new assembler as all the necessary instructions were already supported.
1 parent fcf4e0e commit 41bbc45

35 files changed

+502
-1033
lines changed

cranelift/codegen/src/isa/x64/abi.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -662,25 +662,18 @@ impl ABIMachineSpec for X64ABIMachineSpec {
662662

663663
// Move the saved frame pointer down by `incoming_args_diff`.
664664
let addr = Amode::imm_reg(incoming_args_diff, regs::rsp());
665-
let r11 = Writable::from_reg(regs::r11());
665+
let r11 = Writable::from_reg(Gpr::unwrap_new(regs::r11()));
666666
let inst = asm::inst::movq_rm::new(r11, addr).into();
667667
insts.push(Inst::External { inst });
668-
insts.push(Inst::mov_r_m(
669-
OperandSize::Size64,
670-
regs::r11(),
671-
Amode::imm_reg(0, regs::rsp()),
672-
));
668+
let inst = asm::inst::movq_mr::new(Amode::imm_reg(0, regs::rsp()), r11.to_reg()).into();
669+
insts.push(Inst::External { inst });
673670

674671
// Move the saved return address down by `incoming_args_diff`.
675672
let addr = Amode::imm_reg(incoming_args_diff + 8, regs::rsp());
676-
let r11 = Writable::from_reg(regs::r11());
677673
let inst = asm::inst::movq_rm::new(r11, addr).into();
678674
insts.push(Inst::External { inst });
679-
insts.push(Inst::mov_r_m(
680-
OperandSize::Size64,
681-
regs::r11(),
682-
Amode::imm_reg(8, regs::rsp()),
683-
));
675+
let inst = asm::inst::movq_mr::new(Amode::imm_reg(8, regs::rsp()), r11.to_reg()).into();
676+
insts.push(Inst::External { inst });
684677
}
685678

686679
// We need to factor `incoming_args_diff` into the offset upward here, as we have grown

cranelift/codegen/src/isa/x64/inst.isle

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,6 @@
5959
(dst WritableGpr)
6060
(size OperandSize))
6161

62-
;; Immediate store.
63-
(MovImmM (size OperandSize)
64-
(simm32 i32)
65-
(dst SyntheticAmode))
66-
67-
;; Integer stores: mov (b w l q) reg addr.
68-
(MovRM (size OperandSize) ;; 1, 2, 4, or 8
69-
(src Gpr)
70-
(dst SyntheticAmode))
71-
7262
;; Integer comparisons/tests: cmp or test (b w l q) (reg addr imm) reg.
7363
(CmpRmiR (size OperandSize) ;; 1, 2, 4, or 8
7464
(opcode CmpOpcode)
@@ -2083,14 +2073,16 @@
20832073
(decl x64_movrm (Type SyntheticAmode Gpr) SideEffectNoResult)
20842074
(spec (x64_movrm ty addr data)
20852075
(provide (= result (store_effect (extract 79 64 addr) ty (conv_to ty data) (extract 63 0 addr)))))
2086-
(rule (x64_movrm ty addr data)
2087-
(let ((size OperandSize (raw_operand_size_of_type ty)))
2088-
(SideEffectNoResult.Inst (MInst.MovRM size data addr))))
2076+
(rule (x64_movrm $I8 addr data) (x64_movb_mr_mem addr data))
2077+
(rule (x64_movrm $I16 addr data) (x64_movw_mr_mem addr data))
2078+
(rule (x64_movrm $I32 addr data) (x64_movl_mr_mem addr data))
2079+
(rule (x64_movrm $I64 addr data) (x64_movq_mr_mem addr data))
20892080

20902081
(decl x64_movimm_m (Type SyntheticAmode i32) SideEffectNoResult)
2091-
(rule (x64_movimm_m ty addr imm)
2092-
(let ((size OperandSize (raw_operand_size_of_type ty)))
2093-
(SideEffectNoResult.Inst (MInst.MovImmM size imm addr))))
2082+
(rule (x64_movimm_m $I8 addr (i8_try_from_i32 imm)) (x64_movb_mi_mem addr (i8_as_u8 imm)))
2083+
(rule (x64_movimm_m $I16 addr (i16_try_from_i32 imm)) (x64_movw_mi_mem addr (i16_as_u16 imm)))
2084+
(rule (x64_movimm_m $I32 addr imm) (x64_movl_mi_mem addr (i32_as_u32 imm)))
2085+
(rule (x64_movimm_m $I64 addr imm) (x64_movq_mi_sxl_mem addr imm))
20942086

20952087
(decl xmm_movrm_vex (AvxOpcode SyntheticAmode Xmm) SideEffectNoResult)
20962088
(rule (xmm_movrm_vex op addr data)

cranelift/codegen/src/isa/x64/inst/emit.rs

Lines changed: 22 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -288,32 +288,6 @@ pub(crate) fn emit(
288288
}
289289
}
290290

291-
Inst::MovImmM { size, simm32, dst } => {
292-
let dst = &dst.finalize(state.frame_layout(), sink).clone();
293-
let default_rex = RexFlags::clear_w();
294-
let default_opcode = 0xC7;
295-
let bytes = size.to_bytes();
296-
let prefix = LegacyPrefixes::None;
297-
298-
let (opcode, rex, size, prefix) = match *size {
299-
// In the 8-bit case, we don't need to enforce REX flags via
300-
// `always_emit_if_8bit_needed()` since the destination
301-
// operand is a memory operand, not a possibly 8-bit register.
302-
OperandSize::Size8 => (0xC6, default_rex, bytes, prefix),
303-
OperandSize::Size16 => (0xC7, default_rex, bytes, LegacyPrefixes::_66),
304-
OperandSize::Size64 => (default_opcode, RexFlags::from(*size), bytes, prefix),
305-
306-
_ => (default_opcode, default_rex, bytes, prefix),
307-
};
308-
309-
// 8-bit C6 /0 ib
310-
// 16-bit 0x66 C7 /0 iw
311-
// 32-bit C7 /0 id
312-
// 64-bit REX.W C7 /0 id
313-
emit_std_enc_mem(sink, prefix, opcode, 1, /*subopcode*/ 0, dst, rex, 0);
314-
emit_simm(sink, size, *simm32 as u32);
315-
}
316-
317291
Inst::MovRR { size, src, dst } => {
318292
let src = src.to_reg();
319293
let dst = dst.to_reg().to_reg();
@@ -429,32 +403,6 @@ pub(crate) fn emit(
429403
};
430404
}
431405

432-
Inst::MovRM { size, src, dst } => {
433-
let src = src.to_reg();
434-
let dst = &dst.finalize(state.frame_layout(), sink).clone();
435-
436-
let prefix = match size {
437-
OperandSize::Size16 => LegacyPrefixes::_66,
438-
_ => LegacyPrefixes::None,
439-
};
440-
441-
let opcode = match size {
442-
OperandSize::Size8 => 0x88,
443-
_ => 0x89,
444-
};
445-
446-
// This is one of the few places where the presence of a
447-
// redundant REX prefix changes the meaning of the
448-
// instruction.
449-
let rex = RexFlags::from((*size, src));
450-
451-
// 8-bit: MOV r8, r/m8 is (REX.W==0) 88 /r
452-
// 16-bit: MOV r16, r/m16 is 66 (REX.W==0) 89 /r
453-
// 32-bit: MOV r32, r/m32 is (REX.W==0) 89 /r
454-
// 64-bit: MOV r64, r/m64 is (REX.W==1) 89 /r
455-
emit_std_reg_mem(sink, prefix, opcode, 1, src, dst, rex, 0);
456-
}
457-
458406
Inst::CmpRmiR {
459407
size,
460408
src1: reg_g,
@@ -664,12 +612,12 @@ pub(crate) fn emit(
664612
// Probe the stack! We don't use Inst::gen_store_stack here because we need a predictable
665613
// instruction size.
666614
// mov [rsp], rsp
667-
let inst = Inst::mov_r_m(
668-
OperandSize::Size32, // Use Size32 since it saves us one byte
669-
regs::rsp(),
670-
SyntheticAmode::Real(Amode::imm_reg(0, regs::rsp())),
671-
);
672-
inst.emit(sink, info, state);
615+
let inst = asm::inst::movl_mr::new(
616+
Amode::imm_reg(0, regs::rsp()),
617+
Gpr::unwrap_new(regs::rsp()),
618+
)
619+
.into();
620+
Inst::External { inst }.emit(sink, info, state);
673621

674622
// Compare and jump if we are not done yet
675623
// cmp rsp, tmp_reg
@@ -916,11 +864,12 @@ pub(crate) fn emit(
916864
let inst = asm::inst::movq_rm::new(tmp1, addr).into();
917865
Inst::External { inst }.emit(sink, info, state);
918866

919-
let inst = Inst::MovRM {
920-
size: OperandSize::Size64,
921-
src: Gpr::new(reg).unwrap(),
922-
dst: Amode::imm_reg(offset, **store_context_ptr).into(),
923-
};
867+
let inst = asm::inst::movq_mr::new(
868+
Amode::imm_reg(offset, **store_context_ptr),
869+
Gpr::new(reg).unwrap(),
870+
)
871+
.into();
872+
let inst = Inst::External { inst };
924873
emit(&inst, sink, info, state);
925874

926875
let dst = Writable::from_reg(reg);
@@ -947,11 +896,12 @@ pub(crate) fn emit(
947896
let inst = Inst::lea(amode, tmp2.map(Reg::from));
948897
inst.emit(sink, info, state);
949898

950-
let inst = Inst::MovRM {
951-
size: OperandSize::Size64,
952-
src: tmp2.to_reg(),
953-
dst: Amode::imm_reg(pc_offset, **store_context_ptr).into(),
954-
};
899+
let inst = asm::inst::movq_mr::new(
900+
Amode::imm_reg(pc_offset, **store_context_ptr),
901+
tmp2.to_reg(),
902+
)
903+
.into();
904+
let inst = Inst::External { inst };
955905
emit(&inst, sink, info, state);
956906

957907
let inst = Inst::JmpUnknown {
@@ -3298,12 +3248,12 @@ fn emit_return_call_common_sequence<T>(
32983248
let addr = Amode::imm_reg(0, regs::rsp());
32993249
let inst = asm::inst::movq_rm::new(tmp, addr).into();
33003250
Inst::External { inst }.emit(sink, info, state);
3301-
Inst::mov_r_m(
3302-
OperandSize::Size64,
3303-
tmp.to_reg(),
3251+
let inst = asm::inst::movq_mr::new(
33043252
Amode::imm_reg(i32::try_from(incoming_args_diff).unwrap(), regs::rsp()),
3253+
Gpr::unwrap_new(tmp.to_reg()),
33053254
)
3306-
.emit(sink, info, state);
3255+
.into();
3256+
Inst::External { inst }.emit(sink, info, state);
33073257

33083258
// Increment the stack pointer to shrink the argument area for the new
33093259
// call.

0 commit comments

Comments
 (0)