From 810aeb2d91f0e54fdc1d6a4fd9bf1dd51b2d3bde Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Thu, 9 Feb 2023 15:14:26 -0500 Subject: YJIT: optimized codegen for `rb_ary_empty_p` (WIP) (#7242) * YJIT: add specialized implementation of rb_ary_empty_p() * Update yjit/src/codegen.rs Co-authored-by: Takashi Kokubun --------- Co-authored-by: Takashi Kokubun --- yjit/src/codegen.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'yjit/src') diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 8f439f9b0f..6726bb2bd4 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -4273,6 +4273,31 @@ fn jit_rb_str_concat( true } +// Codegen for rb_ary_empty_p() +fn jit_rb_ary_empty_p( + _jit: &mut JITState, + ctx: &mut Context, + asm: &mut Assembler, + _ocb: &mut OutlinedCb, + _ci: *const rb_callinfo, + _cme: *const rb_callable_method_entry_t, + _block: Option, + _argc: i32, + _known_recv_class: *const VALUE, +) -> bool { + let array_opnd = ctx.stack_pop(1); + let array_reg = asm.load(array_opnd); + let len_opnd = get_array_len(asm, array_reg); + + asm.test(len_opnd, len_opnd); + let bool_val = asm.csel_z(Qtrue.into(), Qfalse.into()); + + let out_opnd = ctx.stack_push(Type::UnknownImm); + asm.store(out_opnd, bool_val); + + return true; +} + fn jit_obj_respond_to( jit: &mut JITState, ctx: &mut Context, @@ -7698,6 +7723,9 @@ impl CodegenGlobals { self.yjit_reg_method(rb_cString, "<<", jit_rb_str_concat); self.yjit_reg_method(rb_cString, "+@", jit_rb_str_uplus); + // rb_ary_empty_p() method in array.c + self.yjit_reg_method(rb_cArray, "empty?", jit_rb_ary_empty_p); + self.yjit_reg_method(rb_mKernel, "respond_to?", jit_obj_respond_to); self.yjit_reg_method(rb_mKernel, "block_given?", jit_rb_f_block_given_p); -- cgit v1.2.1