[前][次][番号順一覧][スレッド一覧]

ruby-changes:73214

From: Maxime <ko1@a...>
Date: Tue, 30 Aug 2022 01:03:00 +0900 (JST)
Subject: [ruby-changes:73214] 477c2df3fa (master): Work on opt_lt, fix x86 backend bug in cmp()

https://git.ruby-lang.org/ruby.git/commit/?id=477c2df3fa

From 477c2df3fad22271958b92bdfafbae7155fbebb4 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Thu, 21 Jul 2022 17:06:01 -0400
Subject: Work on opt_lt, fix x86 backend bug in cmp()

---
 yjit/src/backend/x86_64/mod.rs |  6 +++---
 yjit/src/codegen.rs            | 32 +++++++++++++++-----------------
 2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/yjit/src/backend/x86_64/mod.rs b/yjit/src/backend/x86_64/mod.rs
index 2efe920ddf..3140c86b2e 100644
--- a/yjit/src/backend/x86_64/mod.rs
+++ b/yjit/src/backend/x86_64/mod.rs
@@ -113,7 +113,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/x86_64/mod.rs#L113
             };
 
             match op {
-                Op::Add | Op::Sub | Op::And => {
+                Op::Add | Op::Sub | Op::And | Op::Cmp => {
                     let (opnd0, opnd1) = match (opnds[0], opnds[1]) {
                         (Opnd::Mem(_), Opnd::Mem(_)) => {
                             (asm.load(opnds[0]), asm.load(opnds[1]))
@@ -133,7 +133,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/x86_64/mod.rs#L133
                                 (opnds[0], opnds[1])
                             }
                         },
-                        // We have to load memory and register operands to avoid corrupting them
+                        // We have to load memory operands to avoid corrupting them
                         (Opnd::Mem(_) | Opnd::Reg(_), _) => {
                             (asm.load(opnds[0]), opnds[1])
                         },
@@ -343,7 +343,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/x86_64/mod.rs#L343
                 }
 
                 // Compare
-                Op::Cmp => test(cb, insn.opnds[0].into(), insn.opnds[1].into()),
+                Op::Cmp => cmp(cb, insn.opnds[0].into(), insn.opnds[1].into()),
 
                 // Test and set flags
                 Op::Test => test(cb, insn.opnds[0].into(), insn.opnds[1].into()),
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index 611c42c562..a1fd4df35d 100644
--- a/yjit/src/codegen.rs
+++ b/yjit/src/codegen.rs
@@ -2363,20 +2363,19 @@ fn guard_two_fixnums(ctx: &mut Context, asm: &mut Assembler, 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) -> ();
+type CmovFn = fn(cb: &mut Assembler, opnd0: Opnd, opnd1: Opnd) -> Opnd;
 
 fn gen_fixnum_cmp(
     jit: &mut JITState,
     ctx: &mut Context,
-    cb: &mut CodeBlock,
+    asm: &mut Assembler,
     ocb: &mut OutlinedCb,
     cmov_op: CmovFn,
 ) -> CodegenStatus {
     // Defer compilation so we can specialize base on a runtime receiver
     if !jit_at_current_insn(jit) {
-        defer_compilation(jit, ctx, cb, ocb);
+        defer_compilation(jit, ctx, asm, ocb);
         return EndBlock;
     }
 
@@ -2393,38 +2392,37 @@ fn gen_fixnum_cmp( https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L2392
         }
 
         // Check that both operands are fixnums
-        guard_two_fixnums(ctx, cb, side_exit);
+        guard_two_fixnums(ctx, asm, side_exit);
 
         // Get the operands from the stack
         let arg1 = ctx.stack_pop(1);
         let arg0 = ctx.stack_pop(1);
 
         // Compare the arguments
-        xor(cb, REG0_32, REG0_32); // REG0 = Qfalse
-        mov(cb, REG1, arg0);
-        cmp(cb, REG1, arg1);
-        mov(cb, REG1, uimm_opnd(Qtrue.into()));
-        cmov_op(cb, REG0, REG1);
+        asm.cmp(arg0, arg1);
+        let bool_opnd = cmov_op(asm, Qtrue.into(), Qfalse.into());
 
         // Push the output on the stack
         let dst = ctx.stack_push(Type::Unknown);
-        mov(cb, dst, REG0);
+        asm.mov(dst, bool_opnd);
 
         KeepCompiling
     } else {
-        gen_opt_send_without_block(jit, ctx, cb, ocb)
+        todo!("compare send path not yet implemented");
+        //gen_opt_send_without_block(jit, ctx, cb, ocb)
     }
 }
 
 fn gen_opt_lt(
     jit: &mut JITState,
     ctx: &mut Context,
-    cb: &mut CodeBlock,
+    asm: &mut Assembler,
     ocb: &mut OutlinedCb,
 ) -> CodegenStatus {
-    gen_fixnum_cmp(jit, ctx, cb, ocb, cmovl)
+    gen_fixnum_cmp(jit, ctx, asm, ocb, Assembler::csel_l)
 }
 
+/*
 fn gen_opt_le(
     jit: &mut JITState,
     ctx: &mut Context,
@@ -5990,10 +5988,10 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> { https://github.com/ruby/ruby/blob/trunk/yjit/src/codegen.rs#L5988
         YARVINSN_newhash => Some(gen_newhash),
         YARVINSN_duphash => Some(gen_duphash),
         YARVINSN_newarray => Some(gen_newarray),
+        //YARVINSN_duparray => Some(gen_duparray),
+        //YARVINSN_checktype => Some(gen_checktype),
+        //YARVINSN_opt_lt => Some(gen_opt_lt),
         /*
-        YARVINSN_duparray => Some(gen_duparray),
-        YARVINSN_checktype => Some(gen_checktype),
-        YARVINSN_opt_lt => Some(gen_opt_lt),
         YARVINSN_opt_le => Some(gen_opt_le),
         YARVINSN_opt_gt => Some(gen_opt_gt),
         YARVINSN_opt_ge => Some(gen_opt_ge),
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]