Skip to content

Commit 974b141

Browse files
committed
YJIT: Reuse get_array_{ptr,len}
1 parent ac1e9e4 commit 974b141

File tree

1 file changed

+4
-59
lines changed

1 file changed

+4
-59
lines changed

yjit/src/codegen.rs

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5888,24 +5888,8 @@ fn copy_splat_args_for_rest_callee(array: Opnd, num_args: u32, asm: &mut Assembl
58885888

58895889
asm_comment!(asm, "Push arguments from array");
58905890

5891-
// Load the address of the embedded array
5892-
// (struct RArray *)(obj)->as.ary
58935891
let array_reg = asm.load(array);
5894-
5895-
// Conditionally load the address of the heap array
5896-
// (struct RArray *)(obj)->as.heap.ptr
5897-
let flags_opnd = Opnd::mem(VALUE_BITS, array_reg, RUBY_OFFSET_RBASIC_FLAGS);
5898-
asm.test(flags_opnd, Opnd::UImm(RARRAY_EMBED_FLAG as u64));
5899-
let heap_ptr_opnd = Opnd::mem(
5900-
usize::BITS as u8,
5901-
array_reg,
5902-
RUBY_OFFSET_RARRAY_AS_HEAP_PTR,
5903-
);
5904-
// Load the address of the embedded array
5905-
// (struct RArray *)(obj)->as.ary
5906-
let ary_opnd = asm.lea(Opnd::mem(VALUE_BITS, array_reg, RUBY_OFFSET_RARRAY_AS_ARY));
5907-
let ary_opnd = asm.csel_nz(ary_opnd, heap_ptr_opnd);
5908-
5892+
let ary_opnd = get_array_ptr(asm, array_reg);
59095893
for i in 0..num_args {
59105894
let top = asm.stack_push(Type::Unknown);
59115895
asm.mov(top, Opnd::mem(64, ary_opnd, i as i32 * SIZEOF_VALUE_I32));
@@ -5919,38 +5903,14 @@ fn push_splat_args(required_args: u32, asm: &mut Assembler) {
59195903
asm_comment!(asm, "push_splat_args");
59205904

59215905
let array_opnd = asm.stack_opnd(0);
5922-
let array_reg = asm.load(array_opnd);
5923-
59245906
guard_object_is_array(
59255907
asm,
5926-
array_reg,
5908+
array_opnd,
59275909
array_opnd.into(),
59285910
Counter::guard_send_splat_not_array,
59295911
);
59305912

5931-
asm_comment!(asm, "Get array length for embedded or heap");
5932-
5933-
// Pull out the embed flag to check if it's an embedded array.
5934-
let flags_opnd = Opnd::mem(VALUE_BITS, array_reg, RUBY_OFFSET_RBASIC_FLAGS);
5935-
5936-
// Get the length of the array
5937-
let emb_len_opnd = asm.and(flags_opnd, (RARRAY_EMBED_LEN_MASK as u64).into());
5938-
let emb_len_opnd = asm.rshift(emb_len_opnd, (RARRAY_EMBED_LEN_SHIFT as u64).into());
5939-
5940-
// Conditionally move the length of the heap array
5941-
let flags_opnd = Opnd::mem(VALUE_BITS, array_reg, RUBY_OFFSET_RBASIC_FLAGS);
5942-
asm.test(flags_opnd, (RARRAY_EMBED_FLAG as u64).into());
5943-
5944-
// Need to repeat this here to deal with register allocation
5945-
let array_opnd = asm.stack_opnd(0);
5946-
let array_reg = asm.load(array_opnd);
5947-
5948-
let array_len_opnd = Opnd::mem(
5949-
std::os::raw::c_long::BITS as u8,
5950-
array_reg,
5951-
RUBY_OFFSET_RARRAY_AS_HEAP_LEN,
5952-
);
5953-
let array_len_opnd = asm.csel_nz(emb_len_opnd, array_len_opnd);
5913+
let array_len_opnd = get_array_len(asm, array_opnd);
59545914

59555915
asm_comment!(asm, "Guard for expected splat length");
59565916
asm.cmp(array_len_opnd, required_args.into());
@@ -5975,23 +5935,8 @@ fn push_splat_args(required_args: u32, asm: &mut Assembler) {
59755935
let array_opnd = asm.stack_pop(1);
59765936

59775937
if required_args > 0 {
5978-
// Load the address of the embedded array
5979-
// (struct RArray *)(obj)->as.ary
59805938
let array_reg = asm.load(array_opnd);
5981-
5982-
// Conditionally load the address of the heap array
5983-
// (struct RArray *)(obj)->as.heap.ptr
5984-
let flags_opnd = Opnd::mem(VALUE_BITS, array_reg, RUBY_OFFSET_RBASIC_FLAGS);
5985-
asm.test(flags_opnd, Opnd::UImm(RARRAY_EMBED_FLAG as u64));
5986-
let heap_ptr_opnd = Opnd::mem(
5987-
usize::BITS as u8,
5988-
array_reg,
5989-
RUBY_OFFSET_RARRAY_AS_HEAP_PTR,
5990-
);
5991-
// Load the address of the embedded array
5992-
// (struct RArray *)(obj)->as.ary
5993-
let ary_opnd = asm.lea(Opnd::mem(VALUE_BITS, array_reg, RUBY_OFFSET_RARRAY_AS_ARY));
5994-
let ary_opnd = asm.csel_nz(ary_opnd, heap_ptr_opnd);
5939+
let ary_opnd = get_array_ptr(asm, array_reg);
59955940

59965941
for i in 0..required_args {
59975942
let top = asm.stack_push(Type::Unknown);

0 commit comments

Comments
 (0)