diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2023-02-14 13:31:33 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-14 16:31:33 -0500 |
commit | 15ef2b2d7c6a7fb0d485d1e5a9b795a730ef7967 (patch) | |
tree | 8684cf4d8838b2d8cb4fc62c43b00d96f08c5c14 /yjit/src | |
parent | 6c5582815dcd02726354ff407b73aba25b036b74 (diff) | |
download | ruby-15ef2b2d7c6a7fb0d485d1e5a9b795a730ef7967.tar.gz |
YJIT: Optimize != for Integers and Strings (#7301)
Diffstat (limited to 'yjit/src')
-rw-r--r-- | yjit/src/codegen.rs | 34 | ||||
-rw-r--r-- | yjit/src/cruby_bindings.inc.rs | 1 |
2 files changed, 30 insertions, 5 deletions
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 4183085d2f..1616f90eb1 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -2687,6 +2687,7 @@ fn gen_equality_specialized( ctx: &mut Context, asm: &mut Assembler, ocb: &mut OutlinedCb, + gen_eq: bool, ) -> Option<bool> { // Create a side-exit to fall back to the interpreter let side_exit = get_side_exit(jit, ocb, ctx); @@ -2708,8 +2709,11 @@ fn gen_equality_specialized( guard_two_fixnums(jit, ctx, asm, ocb, side_exit); asm.cmp(a_opnd, b_opnd); - - let val = asm.csel_ne(Qfalse.into(), Qtrue.into()); + let val = if gen_eq { + asm.csel_e(Qtrue.into(), Qfalse.into()) + } else { + asm.csel_ne(Qtrue.into(), Qfalse.into()) + }; // Push the output on the stack ctx.stack_pop(2); @@ -2772,7 +2776,10 @@ fn gen_equality_specialized( } // Call rb_str_eql_internal(a, b) - let val = asm.ccall(rb_str_eql_internal as *const u8, vec![a_opnd, b_opnd]); + let val = asm.ccall( + if gen_eq { rb_str_eql_internal } else { rb_str_neq_internal } as *const u8, + vec![a_opnd, b_opnd], + ); // Push the output on the stack ctx.stack_pop(2); @@ -2781,7 +2788,7 @@ fn gen_equality_specialized( asm.jmp(ret); asm.write_label(equal); - asm.mov(dst, Qtrue.into()); + asm.mov(dst, if gen_eq { Qtrue } else { Qfalse }.into()); asm.write_label(ret); @@ -2797,7 +2804,7 @@ fn gen_opt_eq( asm: &mut Assembler, ocb: &mut OutlinedCb, ) -> CodegenStatus { - let specialized = match gen_equality_specialized(jit, ctx, asm, ocb) { + let specialized = match gen_equality_specialized(jit, ctx, asm, ocb, true) { Some(specialized) => specialized, None => { // Defer compilation so we can specialize base on a runtime receiver @@ -4038,6 +4045,22 @@ fn jit_rb_obj_equal( true } +// Codegen for rb_obj_not_equal() +// object identity comparison +fn jit_rb_obj_not_equal( + 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<IseqPtr>, + _argc: i32, + _known_recv_class: *const VALUE, +) -> bool { + gen_equality_specialized(jit, ctx, asm, ocb, false) == Some(true) +} + // Codegen for rb_int_equal() fn jit_rb_int_equal( jit: &mut JITState, @@ -7707,6 +7730,7 @@ impl CodegenGlobals { self.yjit_reg_method(rb_cBasicObject, "==", jit_rb_obj_equal); self.yjit_reg_method(rb_cBasicObject, "equal?", jit_rb_obj_equal); + self.yjit_reg_method(rb_cBasicObject, "!=", jit_rb_obj_not_equal); self.yjit_reg_method(rb_mKernel, "eql?", jit_rb_obj_equal); self.yjit_reg_method(rb_cModule, "==", jit_rb_obj_equal); self.yjit_reg_method(rb_cSymbol, "==", jit_rb_obj_equal); diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs index 989a0eb279..0e6f4fbc2e 100644 --- a/yjit/src/cruby_bindings.inc.rs +++ b/yjit/src/cruby_bindings.inc.rs @@ -1294,6 +1294,7 @@ extern "C" { pub fn rb_get_cfp_ep_level(cfp: *mut rb_control_frame_struct, lv: u32) -> *const VALUE; pub fn rb_yarv_class_of(obj: VALUE) -> VALUE; pub fn rb_yarv_str_eql_internal(str1: VALUE, str2: VALUE) -> VALUE; + pub fn rb_str_neq_internal(str1: VALUE, str2: VALUE) -> VALUE; pub fn rb_yarv_ary_entry_internal(ary: VALUE, offset: ::std::os::raw::c_long) -> VALUE; pub fn rb_yarv_fix_mod_fix(recv: VALUE, obj: VALUE) -> VALUE; pub fn rb_yjit_dump_iseq_loc(iseq: *const rb_iseq_t, insn_idx: u32); |