summaryrefslogtreecommitdiff
path: root/yjit
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2023-09-07 06:54:05 -0700
committerGitHub <noreply@github.com>2023-09-07 09:54:05 -0400
commit0adca625ee34ced92da68ba144de32f44e7300cd (patch)
treed5939e014e7f986e00bb13f837e0b26fe5a4dced /yjit
parent0c8928721e19dda1ce7b1a8797b18d199207708c (diff)
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 <takashikkbn@gmail.com> --------- Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com> Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
Notes
Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
Diffstat (limited to 'yjit')
-rw-r--r--yjit/src/codegen.rs15
-rw-r--r--yjit/src/cruby.rs1
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