Skip to content

Commit 18aa730

Browse files
authored
ZJIT: Refactor gen_new_hash (ruby#14293)
We can use the `gen_push_opnds` and `gen_pop_opnds` helpers added in ruby#14200 to simplify the code.
1 parent ad4b4f2 commit 18aa730

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

zjit/src/codegen.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,35 +1005,11 @@ fn gen_new_hash(
10051005
pairs.push(val);
10061006
}
10071007

1008-
let n = pairs.len();
1009-
1010-
// Calculate the compile-time NATIVE_STACK_PTR offset from NATIVE_BASE_PTR
1011-
// At this point, frame_setup(&[], jit.c_stack_slots) has been called,
1012-
// which allocated aligned_stack_bytes(jit.c_stack_slots) on the stack
1013-
let frame_size = aligned_stack_bytes(jit.c_stack_slots);
1014-
let allocation_size = aligned_stack_bytes(n);
1015-
1016-
asm_comment!(asm, "allocate {} bytes on C stack for {} hash elements", allocation_size, n);
1017-
asm.sub_into(NATIVE_STACK_PTR, allocation_size.into());
1018-
1019-
// Calculate the total offset from NATIVE_BASE_PTR to our buffer
1020-
let total_offset_from_base = (frame_size + allocation_size) as i32;
1021-
1022-
for (idx, &pair_opnd) in pairs.iter().enumerate() {
1023-
let slot_offset = -total_offset_from_base + (idx as i32 * SIZEOF_VALUE_I32);
1024-
asm.mov(
1025-
Opnd::mem(VALUE_BITS, NATIVE_BASE_PTR, slot_offset),
1026-
pair_opnd
1027-
);
1028-
}
1029-
1030-
let argv = asm.lea(Opnd::mem(64, NATIVE_BASE_PTR, -total_offset_from_base));
1031-
1008+
let argv = gen_push_opnds(jit, asm, &pairs);
10321009
let argc = (elements.len() * 2) as ::std::os::raw::c_long;
10331010
asm_ccall!(asm, rb_hash_bulk_insert, lir::Opnd::Imm(argc), argv, new_hash);
10341011

1035-
asm_comment!(asm, "restore C stack pointer");
1036-
asm.add_into(NATIVE_STACK_PTR, allocation_size.into());
1012+
gen_pop_opnds(asm, &pairs);
10371013
}
10381014

10391015
new_hash

0 commit comments

Comments
 (0)