YJIT: Optimize != for Integers and Strings (#7301)
This commit is contained in:
parent
6c5582815d
commit
15ef2b2d7c
Notes:
git
2023-02-14 21:31:58 +00:00
Merged-By: maximecb <maximecb@ruby-lang.org>
6
yjit.c
6
yjit.c
@ -840,6 +840,12 @@ rb_yarv_str_eql_internal(VALUE str1, VALUE str2)
|
||||
return rb_str_eql_internal(str1, str2);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_str_neq_internal(VALUE str1, VALUE str2)
|
||||
{
|
||||
return rb_str_eql_internal(str1, str2) == Qtrue ? Qfalse : Qtrue;
|
||||
}
|
||||
|
||||
// YJIT needs this function to never allocate and never raise
|
||||
VALUE
|
||||
rb_yarv_ary_entry_internal(VALUE ary, long offset)
|
||||
|
@ -402,6 +402,7 @@ fn main() {
|
||||
.allowlist_function("rb_get_cikw_keywords_idx")
|
||||
.allowlist_function("rb_get_call_data_ci")
|
||||
.allowlist_function("rb_yarv_str_eql_internal")
|
||||
.allowlist_function("rb_str_neq_internal")
|
||||
.allowlist_function("rb_yarv_ary_entry_internal")
|
||||
.allowlist_function("rb_yarv_fix_mod_fix")
|
||||
.allowlist_function("rb_FL_TEST")
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user