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

ruby-changes:63769

From: Takashi <ko1@a...>
Date: Fri, 27 Nov 2020 17:43:21 +0900 (JST)
Subject: [ruby-changes:63769] d409837729 (master): Cache access to reg_cfp->self on JIT

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

From d40983772966938828a28c6e89752a3e76447b9e Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Fri, 27 Nov 2020 00:36:02 -0800
Subject: Cache access to reg_cfp->self on JIT

```
$ benchmark-driver -v --rbenv 'before --jit;after --jit' --repeat-count=12 --alternate --output=all benchmark.yml
before --jit: ruby 3.0.0dev (2020-11-27T06:41:15Z master 8ce1711c25) +JIT [x86_64-linux]
after --jit: ruby 3.0.0dev (2020-11-27T08:36:02Z master 2c592126b9) +JIT [x86_64-linux]
last_commit=Cache access to reg_cfp->self on JIT
Calculating -------------------------------------
                                 before --jit           after --jit
Optcarrot Lan_Master.nes    82.40522392468650     82.66023870551237 fps
                            82.67998539899482     83.08660305312587
                            85.51280693947453     87.09311989553235
                            86.32925337181406     87.16115255191410
                            87.35617494926235     87.30699391518075
                            87.91865339426212     88.47590342996875
                            88.11573661006648     88.64778616696353
                            88.16060826662158     88.67015079203991
                            88.21639244865058     89.19630739497482
                            88.47241577897603     89.23443637947730
                            89.37087287229809     89.57052723997015
                            89.46969964699964     89.97803363889025
```

diff --git a/mjit_compile.c b/mjit_compile.c
index c1d8f34..8591b5c 100644
--- a/mjit_compile.c
+++ b/mjit_compile.c
@@ -348,6 +348,8 @@ mjit_compile_body(FILE *f, const rb_iseq_t *iseq, struct compile_status *status) https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L348
         fprintf(f, "    static const rb_iseq_t *original_iseq = (const rb_iseq_t *)0x%"PRIxVALUE";\n", (VALUE)iseq);
     fprintf(f, "    static const VALUE *const original_body_iseq = (VALUE *)0x%"PRIxVALUE";\n",
             (VALUE)body->iseq_encoded);
+    fprintf(f, "    VALUE cfp_self = reg_cfp->self;\n"); // cache self across the method
+    fprintf(f, "#define GET_SELF() cfp_self\n");
 
     // Generate merged ivar guards first if needed
     if (!status->compile_info->disable_ivar_cache && status->merge_ivar_guards_p) {
@@ -379,6 +381,7 @@ mjit_compile_body(FILE *f, const rb_iseq_t *iseq, struct compile_status *status) https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L381
 
     compile_insns(f, body, 0, 0, status);
     compile_cancel_handler(f, body, status);
+    fprintf(f, "#undef GET_SELF");
     return status->success;
 }
 
diff --git a/tool/ruby_vm/views/mjit_compile.inc.erb b/tool/ruby_vm/views/mjit_compile.inc.erb
index 6836d59..32fd65a 100644
--- a/tool/ruby_vm/views/mjit_compile.inc.erb
+++ b/tool/ruby_vm/views/mjit_compile.inc.erb
@@ -35,7 +35,7 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/mjit_compile.inc.erb#L35
 % #   GET_CFP(): refers to `reg_cfp`
 % #   GET_EP(): refers to `reg_cfp->ep`
 % #   GET_SP(): refers to `reg_cfp->sp`, or `(stack + stack_size)` if local_stack_p
-% #   GET_SELF(): refers to `reg_cfp->self`
+% #   GET_SELF(): refers to `cfp_self`
 % #   GET_LEP(): refers to `VM_EP_LEP(reg_cfp->ep)`
 % #   EXEC_EC_CFP(): refers to `val = vm_exec(ec, TRUE)` with frame setup
 % #   CALL_METHOD(): using `GET_CFP()` and `EXEC_EC_CFP()`
-- 
cgit v0.10.2


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

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