Skip to content

Commit 8090988

Browse files
committed
ZJIT: Inline ArrayLength into LIR
1 parent 6cebbf4 commit 8090988

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

zjit/src/codegen.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,14 @@ fn gen_array_pop(asm: &mut Assembler, array: Opnd, state: &FrameState) -> lir::O
14261426
}
14271427

14281428
fn gen_array_length(asm: &mut Assembler, array: Opnd) -> lir::Opnd {
1429-
asm_ccall!(asm, rb_jit_array_len, array)
1429+
let array = asm.load(array);
1430+
let flags = Opnd::mem(VALUE_BITS, array, RUBY_OFFSET_RBASIC_FLAGS);
1431+
let embedded_len = asm.and(flags, (RARRAY_EMBED_LEN_MASK as u64).into());
1432+
let embedded_len = asm.rshift(embedded_len, (RARRAY_EMBED_LEN_SHIFT as u64).into());
1433+
// cmov between the embedded length and heap length depending on the embed flag
1434+
asm.test(flags, (RARRAY_EMBED_FLAG as u64).into());
1435+
let heap_len = Opnd::mem(c_long::BITS as u8, array, RUBY_OFFSET_RARRAY_AS_HEAP_LEN);
1436+
asm.csel_nz(embedded_len, heap_len)
14301437
}
14311438

14321439
/// Compile opt_newarray_hash - create a hash from array elements

0 commit comments

Comments
 (0)