Skip to content

Commit 2116916

Browse files
committed
ZJIT: Add asm.sub_into helper
1 parent a9d9b9d commit 2116916

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

zjit/src/backend/lir.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,11 @@ impl Assembler {
22332233
out
22342234
}
22352235

2236+
pub fn sub_into(&mut self, left: Opnd, right: Opnd) -> Opnd {
2237+
self.push_insn(Insn::Sub { left, right, out: left });
2238+
left
2239+
}
2240+
22362241
#[must_use]
22372242
pub fn mul(&mut self, left: Opnd, right: Opnd) -> Opnd {
22382243
let out = self.new_vreg(Opnd::match_num_bits(&[left, right]));

zjit/src/codegen.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,7 @@ fn gen_send_without_block_direct(
851851
asm.mov(SP, new_sp);
852852

853853
asm_comment!(asm, "switch to new CFP");
854-
let new_cfp = asm.sub(CFP, RUBY_SIZEOF_CONTROL_FRAME.into());
855-
asm.mov(CFP, new_cfp);
854+
asm.sub_into(CFP, RUBY_SIZEOF_CONTROL_FRAME.into());
856855
asm.store(Opnd::mem(64, EC, RUBY_OFFSET_EC_CFP), CFP);
857856

858857
// Set up arguments
@@ -876,8 +875,7 @@ fn gen_send_without_block_direct(
876875
asm.je(Target::SideExit { context: None, reason: CalleeSideExit, label: None });
877876

878877
asm_comment!(asm, "restore SP register for the caller");
879-
let new_sp = asm.sub(SP, sp_offset.into());
880-
asm.mov(SP, new_sp);
878+
asm.sub_into(SP, sp_offset.into());
881879

882880
Some(ret)
883881
}
@@ -1474,8 +1472,7 @@ fn gen_string_concat(jit: &mut JITState, asm: &mut Assembler, strings: Vec<Opnd>
14741472
let allocation_size = aligned_stack_bytes(n);
14751473

14761474
asm_comment!(asm, "allocate {} bytes on C stack for {} strings", allocation_size, n);
1477-
let new_sp = asm.sub(NATIVE_STACK_PTR, allocation_size.into());
1478-
asm.mov(NATIVE_STACK_PTR, new_sp);
1475+
asm.sub_into(NATIVE_STACK_PTR, allocation_size.into());
14791476

14801477
// Calculate the total offset from NATIVE_BASE_PTR to our buffer
14811478
let total_offset_from_base = (frame_size + allocation_size) as i32;

0 commit comments

Comments
 (0)