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

ruby-changes:73204

From: Maxime <ko1@a...>
Date: Tue, 30 Aug 2022 01:00:25 +0900 (JST)
Subject: [ruby-changes:73204] 8259813bc3 (master): Temporarily simplify code for emit_conditional_jump to fix a bug

https://git.ruby-lang.org/ruby.git/commit/?id=8259813bc3

From 8259813bc30497986974633202f3052353295f95 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Wed, 20 Jul 2022 15:58:31 -0400
Subject: Temporarily simplify code for emit_conditional_jump to fix a bug

---
 yjit/src/backend/arm64/mod.rs | 24 ++++++++++++++++++++----
 yjit/src/virtualmem.rs        |  5 +++++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/yjit/src/backend/arm64/mod.rs b/yjit/src/backend/arm64/mod.rs
index 35026a520b..72cbd938b0 100644
--- a/yjit/src/backend/arm64/mod.rs
+++ b/yjit/src/backend/arm64/mod.rs
@@ -324,10 +324,24 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/arm64/mod.rs#L324
         fn emit_conditional_jump<const CONDITION: u8>(cb: &mut CodeBlock, target: Target) {
             match target {
                 Target::CodePtr(dst_ptr) => {
-                    let src_addr = cb.get_write_ptr().into_i64() + 4;
-                    let dst_addr = dst_ptr.into_i64();
-                    let offset = dst_addr - src_addr;
+                    let dst_addr = dst_ptr.into_u64();
+                    //let src_addr = cb.get_write_ptr().into_i64() + 4;
+                    //let offset = dst_addr - src_addr;
+
+                    // If the condition is met, then we'll skip past the
+                    // next instruction, put the address in a register, and
+                    // jump to it.
+                    bcond(cb, CONDITION, A64Opnd::new_imm(8));
+
+                    // If we get to this instruction, then the condition
+                    // wasn't met, in which case we'll jump past the
+                    // next instruction that perform the direct jump.
+
+                    b(cb, A64Opnd::new_imm(2i64 + emit_load_size(dst_addr) as i64));
+                    emit_load_value(cb, Assembler::SCRATCH0, dst_addr);
+                    br(cb, Assembler::SCRATCH0);
 
+                    /*
                     // If the jump offset fits into the conditional jump as an
                     // immediate value and it's properly aligned, then we can
                     // use the b.cond instruction directly. Otherwise, we need
@@ -339,7 +353,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/arm64/mod.rs#L353
                         // If the condition is met, then we'll skip past the
                         // next instruction, put the address in a register, and
                         // jump to it.
-                        bcond(cb, CONDITION, A64Opnd::new_imm(4));
+                        bcond(cb, CONDITION, A64Opnd::new_imm(8));
 
                         // If the offset fits into a direct jump, then we'll use
                         // that and the number of instructions will be shorter.
@@ -351,6 +365,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/arm64/mod.rs#L365
                             b(cb, A64Opnd::new_imm(1));
 
                             // Here we'll perform the direct jump to the target.
+                            let offset = dst_addr - cb.get_write_ptr().into_i64() + 4;
                             b(cb, A64Opnd::new_imm(offset / 4));
                         } else {
                             // If we get to this instruction, then the condition
@@ -363,6 +378,7 @@ impl Assembler https://github.com/ruby/ruby/blob/trunk/yjit/src/backend/arm64/mod.rs#L378
                             br(cb, Assembler::SCRATCH0);
                         }
                     }
+                    */
                 },
                 Target::Label(label_idx) => {
                     // Here we're going to save enough space for ourselves and
diff --git a/yjit/src/virtualmem.rs b/yjit/src/virtualmem.rs
index 6a8e27447e..8d34e521b9 100644
--- a/yjit/src/virtualmem.rs
+++ b/yjit/src/virtualmem.rs
@@ -192,6 +192,11 @@ impl CodePtr { https://github.com/ruby/ruby/blob/trunk/yjit/src/virtualmem.rs#L192
         ptr as i64
     }
 
+    pub fn into_u64(self) -> u64 {
+        let CodePtr(ptr) = self;
+        ptr as u64
+    }
+
     pub fn into_usize(self) -> usize {
         let CodePtr(ptr) = self;
         ptr as usize
-- 
cgit v1.2.1


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

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