ruby-changes:73159
From: Maxime <ko1@a...>
Date: Tue, 30 Aug 2022 00:57:23 +0900 (JST)
Subject: [ruby-changes:73159] d0204e51e2 (master): Port guard_two_fixnums
https://git.ruby-lang.org/ruby.git/commit/?id=d0204e51e2 From d0204e51e270a1dacdfa3ae775892840b0e7b192 Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...> Date: Mon, 20 Jun 2022 15:12:22 -0400 Subject: Port guard_two_fixnums --- yjit/src/backend/ir.rs | 12 +++++++++++- yjit/src/backend/x86_64/mod.rs | 10 ++++++++++ yjit/src/codegen.rs | 28 +++++++++++++++------------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/yjit/src/backend/ir.rs b/yjit/src/backend/ir.rs index 6789720238..437cc24286 100644 --- a/yjit/src/backend/ir.rs +++ b/yjit/src/backend/ir.rs @@ -80,7 +80,10 @@ pub enum Op https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L80 // Compare two operands Cmp, - // Unconditional jump which takes an address operand + // Unconditional jump to a branch target + Jmp, + + // Unconditional jump which takes a reg/mem address operand JmpOpnd, // Low-level conditional jump instructions @@ -252,6 +255,12 @@ impl Target https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L255 } } +impl From<CodePtr> for Target { + fn from(code_ptr: CodePtr) -> Self { + Target::CodePtr(code_ptr) + } +} + /// YJIT IR instruction #[derive(Clone, Debug)] pub struct Insn @@ -758,6 +767,7 @@ macro_rules! def_push_2_opnd_no_out { https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/ir.rs#L767 } def_push_1_opnd_no_out!(jmp_opnd, Op::JmpOpnd); +def_push_jcc!(jmp, Op::Jmp); def_push_jcc!(je, Op::Je); def_push_jcc!(jbe, Op::Jbe); def_push_jcc!(jz, Op::Jz); diff --git a/yjit/src/backend/x86_64/mod.rs b/yjit/src/backend/x86_64/mod.rs index bca1eda855..894ae279bd 100644 --- a/yjit/src/backend/x86_64/mod.rs +++ b/yjit/src/backend/x86_64/mod.rs @@ -202,8 +202,18 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/x86_64/mod.rs#L202 Op::JmpOpnd => jmp_rm(cb, insn.opnds[0].into()), // Conditional jump to a label + Op::Jmp => { + match insn.target.unwrap() { + Target::CodePtr(code_ptr) => jmp_ptr(cb, code_ptr), + Target::Label(label_idx) => jmp_label(cb, label_idx), + _ => unreachable!() + } + } + Op::Je => je_label(cb, insn.target.unwrap().unwrap_label_idx()), + Op::Jz => jz_label(cb, insn.target.unwrap().unwrap_label_idx()), + Op::Jnz => { match insn.target.unwrap() { Target::CodePtr(code_ptr) => jnz_ptr(cb, code_ptr), diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index a1af23c974..61a2bc627b 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -2312,27 +2312,28 @@ fn gen_concatstrings( https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L2312 KeepCompiling } +*/ -fn guard_two_fixnums(ctx: &mut Context, cb: &mut CodeBlock, side_exit: CodePtr) { +fn guard_two_fixnums(ctx: &mut Context, asm: &mut Assembler, side_exit: CodePtr) { // Get the stack operand types let arg1_type = ctx.get_opnd_type(StackOpnd(0)); let arg0_type = ctx.get_opnd_type(StackOpnd(1)); if arg0_type.is_heap() || arg1_type.is_heap() { - add_comment(cb, "arg is heap object"); - jmp_ptr(cb, side_exit); + asm.comment("arg is heap object"); + asm.jmp(side_exit.into()); return; } if arg0_type != Type::Fixnum && arg0_type.is_specific() { - add_comment(cb, "arg0 not fixnum"); - jmp_ptr(cb, side_exit); + asm.comment("arg0 not fixnum"); + asm.jmp(side_exit.into()); return; } if arg1_type != Type::Fixnum && arg1_type.is_specific() { - add_comment(cb, "arg1 not fixnum"); - jmp_ptr(cb, side_exit); + asm.comment("arg1 not fixnum"); + asm.jmp(side_exit.into()); return; } @@ -2347,14 +2348,14 @@ fn guard_two_fixnums(ctx: &mut Context, cb: &mut CodeBlock, side_exit: CodePtr) https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L2348 // If not fixnums, fall back if arg0_type != Type::Fixnum { - add_comment(cb, "guard arg0 fixnum"); - test(cb, arg0, uimm_opnd(RUBY_FIXNUM_FLAG as u64)); - jz_ptr(cb, side_exit); + asm.comment("guard arg0 fixnum"); + asm.test(arg0, Opnd::UImm(RUBY_FIXNUM_FLAG as u64)); + asm.jz(side_exit.into()); } if arg1_type != Type::Fixnum { - add_comment(cb, "guard arg1 fixnum"); - test(cb, arg1, uimm_opnd(RUBY_FIXNUM_FLAG as u64)); - jz_ptr(cb, side_exit); + asm.comment("guard arg1 fixnum"); + asm.test(arg1, Opnd::UImm(RUBY_FIXNUM_FLAG as u64)); + asm.jz(side_exit.into()); } // Set stack types in context @@ -2362,6 +2363,7 @@ fn guard_two_fixnums(ctx: &mut Context, cb: &mut CodeBlock, side_exit: CodePtr) https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L2363 ctx.upgrade_opnd_type(StackOpnd(1), Type::Fixnum); } +/* // Conditional move operation used by comparison operators type CmovFn = fn(cb: &mut CodeBlock, opnd0: X86Opnd, opnd1: X86Opnd) -> (); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/