mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
add support for the LEA instruction
This commit is contained in:
parent
28146c939f
commit
5a297248e2
1 changed files with 42 additions and 0 deletions
|
@ -1172,6 +1172,21 @@ impl Assembler<X86_64GeneralReg, X86_64FloatReg> for X86_64Assembler {
|
|||
});
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn function_pointer(
|
||||
buf: &mut Vec<'_, u8>,
|
||||
relocs: &mut Vec<'_, Relocation>,
|
||||
fn_name: String,
|
||||
dst: X86_64GeneralReg,
|
||||
) {
|
||||
lea_reg64(buf, dst);
|
||||
|
||||
relocs.push(Relocation::LinkedFunction {
|
||||
offset: buf.len() as u64 - 4,
|
||||
name: fn_name,
|
||||
});
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn imul_reg64_reg64_reg64(
|
||||
buf: &mut Vec<'_, u8>,
|
||||
|
@ -2398,6 +2413,24 @@ fn mov_reg64_imm64(buf: &mut Vec<'_, u8>, dst: X86_64GeneralReg, imm: i64) {
|
|||
}
|
||||
}
|
||||
|
||||
/// `LEA r64, m` -> Store effective address for m in register r64.
|
||||
#[inline(always)]
|
||||
fn lea_reg64(buf: &mut Vec<'_, u8>, dst: X86_64GeneralReg) {
|
||||
let rex = add_opcode_extension(dst, REX_W);
|
||||
let rex = add_reg_extension(dst, rex);
|
||||
let dst_mod = dst as u8 % 8;
|
||||
|
||||
buf.extend([
|
||||
rex,
|
||||
0x8d,
|
||||
0b00_000_101 | (dst_mod << 3),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
])
|
||||
}
|
||||
|
||||
/// `MOV r/m64,r64` -> Move r64 to r/m64.
|
||||
/// This will not generate anything if dst and src are the same.
|
||||
#[inline(always)]
|
||||
|
@ -3413,6 +3446,15 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lea_reg64() {
|
||||
disassembler_test!(
|
||||
lea_reg64,
|
||||
|reg| format!("lea {}, [rip]", reg),
|
||||
ALL_GENERAL_REGS
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mov_reg64_reg64() {
|
||||
disassembler_test!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue