From 0adca625ee34ced92da68ba144de32f44e7300cd Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 7 Sep 2023 06:54:05 -0700 Subject: [PATCH] Remove function call for String#bytesize (#8389) * Remove function call for String#bytesize String size is stored in a consistent location, so we can eliminate the function call. * Update yjit/src/codegen.rs Co-authored-by: Takashi Kokubun --------- Co-authored-by: Maxime Chevalier-Boisvert Co-authored-by: Takashi Kokubun --- yjit/src/codegen.rs | 15 +++++++++++++-- yjit/src/cruby.rs | 1 - 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 92dd239c8b..a99594c3ab 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -4697,10 +4697,21 @@ fn jit_rb_str_bytesize( asm.comment("String#bytesize"); let recv = asm.stack_pop(1); - let ret_opnd = asm.ccall(rb_str_bytesize as *const u8, vec![recv]); + + asm.comment("get string length"); + let str_len_opnd = Opnd::mem( + std::os::raw::c_long::BITS as u8, + asm.load(recv), + RUBY_OFFSET_RSTRING_LEN as i32, + ); + + let len = asm.load(str_len_opnd); + let shifted_val = asm.lshift(len, Opnd::UImm(1)); + let out_val = asm.or(shifted_val, Opnd::UImm(RUBY_FIXNUM_FLAG as u64)); let out_opnd = asm.stack_push(Type::Fixnum); - asm.mov(out_opnd, ret_opnd); + + asm.mov(out_opnd, out_val); true } diff --git a/yjit/src/cruby.rs b/yjit/src/cruby.rs index a8234e744a..274331755f 100644 --- a/yjit/src/cruby.rs +++ b/yjit/src/cruby.rs @@ -135,7 +135,6 @@ extern "C" { ic: ICVARC, ) -> VALUE; pub fn rb_vm_ic_hit_p(ic: IC, reg_ep: *const VALUE) -> bool; - pub fn rb_str_bytesize(str: VALUE) -> VALUE; } // Renames