1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

YJIT: add chain guards in guard_two_fixnums (#6422)

* Add chain guards in guard_two_fixnums, opt_eq with symbols

* Remove symbol comparison in gen_equality_specialized
This commit is contained in:
Maxime Chevalier-Boisvert 2022-09-22 17:47:54 -04:00 committed by GitHub
parent 4b97f1e525
commit 4e40fdbcee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2022-09-23 06:48:16 +09:00
Merged-By: maximecb <maximecb@ruby-lang.org>

View file

@ -1150,7 +1150,7 @@ fn gen_opt_plus(
} }
// Check that both operands are fixnums // Check that both operands are fixnums
guard_two_fixnums(ctx, asm, side_exit); guard_two_fixnums(jit, ctx, asm, ocb, side_exit);
// Get the operands from the stack // Get the operands from the stack
let arg1 = ctx.stack_pop(1); let arg1 = ctx.stack_pop(1);
@ -2320,7 +2320,13 @@ fn gen_concatstrings(
KeepCompiling KeepCompiling
} }
fn guard_two_fixnums(ctx: &mut Context, asm: &mut Assembler, side_exit: CodePtr) { fn guard_two_fixnums(
jit: &mut JITState,
ctx: &mut Context,
asm: &mut Assembler,
ocb: &mut OutlinedCb,
side_exit: CodePtr
) {
// Get the stack operand types // Get the stack operand types
let arg1_type = ctx.get_opnd_type(StackOpnd(0)); let arg1_type = ctx.get_opnd_type(StackOpnd(0));
let arg0_type = ctx.get_opnd_type(StackOpnd(1)); let arg0_type = ctx.get_opnd_type(StackOpnd(1));
@ -2352,16 +2358,34 @@ fn guard_two_fixnums(ctx: &mut Context, asm: &mut Assembler, side_exit: CodePtr)
let arg1 = ctx.stack_opnd(0); let arg1 = ctx.stack_opnd(0);
let arg0 = ctx.stack_opnd(1); let arg0 = ctx.stack_opnd(1);
// If not fixnums, fall back // If not fixnums at run-time, fall back
if arg0_type != Type::Fixnum { if arg0_type != Type::Fixnum {
asm.comment("guard arg0 fixnum"); asm.comment("guard arg0 fixnum");
asm.test(arg0, Opnd::UImm(RUBY_FIXNUM_FLAG as u64)); asm.test(arg0, Opnd::UImm(RUBY_FIXNUM_FLAG as u64));
asm.jz(side_exit.into());
jit_chain_guard(
JCC_JZ,
jit,
&ctx,
asm,
ocb,
SEND_MAX_DEPTH,
side_exit,
);
} }
if arg1_type != Type::Fixnum { if arg1_type != Type::Fixnum {
asm.comment("guard arg1 fixnum"); asm.comment("guard arg1 fixnum");
asm.test(arg1, Opnd::UImm(RUBY_FIXNUM_FLAG as u64)); asm.test(arg1, Opnd::UImm(RUBY_FIXNUM_FLAG as u64));
asm.jz(side_exit.into());
jit_chain_guard(
JCC_JZ,
jit,
&ctx,
asm,
ocb,
SEND_MAX_DEPTH,
side_exit,
);
} }
// Set stack types in context // Set stack types in context
@ -2398,7 +2422,7 @@ fn gen_fixnum_cmp(
} }
// Check that both operands are fixnums // Check that both operands are fixnums
guard_two_fixnums(ctx, asm, side_exit); guard_two_fixnums(jit, ctx, asm, ocb, side_exit);
// Get the operands from the stack // Get the operands from the stack
let arg1 = ctx.stack_pop(1); let arg1 = ctx.stack_pop(1);
@ -2475,7 +2499,7 @@ fn gen_equality_specialized(
return false; return false;
} }
guard_two_fixnums(ctx, asm, side_exit); guard_two_fixnums(jit, ctx, asm, ocb, side_exit);
asm.cmp(a_opnd, b_opnd); asm.cmp(a_opnd, b_opnd);
@ -2487,7 +2511,8 @@ fn gen_equality_specialized(
asm.mov(dst, val); asm.mov(dst, val);
true true
} else if unsafe { comptime_a.class_of() == rb_cString && comptime_b.class_of() == rb_cString } }
else if unsafe { comptime_a.class_of() == rb_cString && comptime_b.class_of() == rb_cString }
{ {
if !assume_bop_not_redefined(jit, ocb, STRING_REDEFINED_OP_FLAG, BOP_EQ) { if !assume_bop_not_redefined(jit, ocb, STRING_REDEFINED_OP_FLAG, BOP_EQ) {
// if overridden, emit the generic version // if overridden, emit the generic version
@ -2851,7 +2876,7 @@ fn gen_opt_and(
} }
// Check that both operands are fixnums // Check that both operands are fixnums
guard_two_fixnums(ctx, asm, side_exit); guard_two_fixnums(jit, ctx, asm, ocb, side_exit);
// Get the operands and destination from the stack // Get the operands and destination from the stack
let arg1 = ctx.stack_pop(1); let arg1 = ctx.stack_pop(1);
@ -2896,7 +2921,7 @@ fn gen_opt_or(
} }
// Check that both operands are fixnums // Check that both operands are fixnums
guard_two_fixnums(ctx, asm, side_exit); guard_two_fixnums(jit, ctx, asm, ocb, side_exit);
// Get the operands and destination from the stack // Get the operands and destination from the stack
let arg1 = ctx.stack_pop(1); let arg1 = ctx.stack_pop(1);
@ -2941,7 +2966,7 @@ fn gen_opt_minus(
} }
// Check that both operands are fixnums // Check that both operands are fixnums
guard_two_fixnums(ctx, asm, side_exit); guard_two_fixnums(jit, ctx, asm, ocb, side_exit);
// Get the operands and destination from the stack // Get the operands and destination from the stack
let arg1 = ctx.stack_pop(1); let arg1 = ctx.stack_pop(1);
@ -3008,7 +3033,7 @@ fn gen_opt_mod(
} }
// Check that both operands are fixnums // Check that both operands are fixnums
guard_two_fixnums(ctx, asm, side_exit); guard_two_fixnums(jit, ctx, asm, ocb, side_exit);
// Get the operands and destination from the stack // Get the operands and destination from the stack
let arg1 = ctx.stack_pop(1); let arg1 = ctx.stack_pop(1);
@ -5068,7 +5093,6 @@ fn gen_send_general(
return CantCompile; return CantCompile;
} }
if flags & VM_CALL_ARGS_BLOCKARG != 0 { if flags & VM_CALL_ARGS_BLOCKARG != 0 {
gen_counter_incr!(asm, send_block_arg); gen_counter_incr!(asm, send_block_arg);
return CantCompile; return CantCompile;