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

ruby-changes:68810

From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:12:31 +0900 (JST)
Subject: [ruby-changes:68810] 97cffcf79a (master): Fix sneaky ujit side-exit bug. Reduce ujit call threshold to 1.

https://git.ruby-lang.org/ruby.git/commit/?id=97cffcf79a

From 97cffcf79a5586765d0046d3dc0d004a101f73ad Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Thu, 7 Jan 2021 13:32:46 -0500
Subject: Fix sneaky ujit side-exit bug. Reduce ujit call threshold to 1.

---
 ujit.h         |  2 +-
 ujit_codegen.c | 25 +++++++++++++++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/ujit.h b/ujit.h
index b4a83ae0e6..a4634ae2ce 100644
--- a/ujit.h
+++ b/ujit.h
@@ -41,7 +41,7 @@ bool rb_ujit_enabled_p(void) https://github.com/ruby/ruby/blob/trunk/ujit.h#L41
     return rb_ujit_enabled;
 }
 
-#define UJIT_CALL_THRESHOLD (10u)
+#define UJIT_CALL_THRESHOLD (1u)
 
 void rb_ujit_method_lookup_change(VALUE cme_or_cc);
 void rb_ujit_compile_iseq(const rb_iseq_t *iseq);
diff --git a/ujit_codegen.c b/ujit_codegen.c
index 7c5a2bd72b..a75ac9d9e7 100644
--- a/ujit_codegen.c
+++ b/ujit_codegen.c
@@ -88,19 +88,19 @@ Generate an out-of-line exit to return to the interpreter https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L88
 static uint8_t *
 ujit_side_exit(jitstate_t* jit, ctx_t* ctx)
 {
-    uint8_t* code_ptr = cb_get_ptr(ocb, cb->write_pos);
+    uint8_t* code_ptr = cb_get_ptr(ocb, ocb->write_pos);
 
     // Table mapping opcodes to interpreter handlers
-    const void * const *table = rb_vm_get_insns_address_table();
+    const void * const *handler_table = rb_vm_get_insns_address_table();
 
     // Write back the old instruction at the exit PC
     // Otherwise the interpreter may jump right back to the
     // JITted code we're trying to exit
     VALUE* exit_pc = &jit->iseq->body->iseq_encoded[jit->insn_idx];
     int exit_opcode = opcode_at_pc(jit->iseq, exit_pc);
-    void* exit_instr = (void*)table[exit_opcode];
+    void* handler_addr = (void*)handler_table[exit_opcode];
     mov(ocb, RAX, const_ptr_opnd(exit_pc));
-    mov(ocb, RCX, const_ptr_opnd(exit_instr));
+    mov(ocb, RCX, const_ptr_opnd(handler_addr));
     mov(ocb, mem_opnd(64, RAX, 0), RCX);
 
     // Generate the code to exit to the interpreters
@@ -932,8 +932,21 @@ gen_opt_send_without_block(jitstate_t* jit, ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_codegen.c#L932
 void 
 gen_branchunless_branch(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uint8_t shape)
 {
-    jz_ptr(cb, target0);
-    jmp_ptr(cb, target1);
+    switch (shape)
+    {
+        case SHAPE_NEXT0:
+        jnz_ptr(cb, target1);
+        break;
+
+        case SHAPE_NEXT1:
+        jz_ptr(cb, target0);
+        break;
+
+        case SHAPE_DEFAULT:
+        jz_ptr(cb, target0);
+        jmp_ptr(cb, target1);
+        break;
+    }
 }
 
 static bool
-- 
cgit v1.2.1


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

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