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

ruby-changes:71026

From: Jemma <ko1@a...>
Date: Thu, 27 Jan 2022 02:03:18 +0900 (JST)
Subject: [ruby-changes:71026] 1a180b7e18 (master): Streamline cached attr reader / writer indexes

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

From 1a180b7e18a2d415282df637e27a446c71246ef7 Mon Sep 17 00:00:00 2001
From: Jemma Issroff <jemmaissroff@g...>
Date: Tue, 25 Jan 2022 16:04:17 -0500
Subject: Streamline cached attr reader / writer indexes

This commit removes the need to increment and decrement the indexes
used by vm_cc_attr_index getters and setters. It also introduces a
vm_cc_attr_index_p predicate function, and a vm_cc_attr_index_initalize
function.
---
 vm_callinfo.h   | 19 +++++++++++++++++--
 vm_insnhelper.c | 16 ++++++++--------
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/vm_callinfo.h b/vm_callinfo.h
index 09f755c818d..3d41e039c94 100644
--- a/vm_callinfo.h
+++ b/vm_callinfo.h
@@ -353,7 +353,14 @@ static inline unsigned int https://github.com/ruby/ruby/blob/trunk/vm_callinfo.h#L353
 vm_cc_attr_index(const struct rb_callcache *cc)
 {
     VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
-    return cc->aux_.attr_index;
+    return cc->aux_.attr_index - 1;
+}
+
+static inline bool
+vm_cc_attr_index_p(const struct rb_callcache *cc)
+{
+    VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
+    return cc->aux_.attr_index > 0;
 }
 
 static inline unsigned int
@@ -406,7 +413,15 @@ vm_cc_attr_index_set(const struct rb_callcache *cc, int index) https://github.com/ruby/ruby/blob/trunk/vm_callinfo.h#L413
 {
     VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
     VM_ASSERT(cc != vm_cc_empty());
-    *(int *)&cc->aux_.attr_index = index;
+    *(int *)&cc->aux_.attr_index = index + 1;
+}
+
+static inline void
+vm_cc_attr_index_initialize(const struct rb_callcache *cc)
+{
+    VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
+    VM_ASSERT(cc != vm_cc_empty());
+    *(int *)&cc->aux_.attr_index = 0;
 }
 
 static inline void
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 271b347d3bc..27d9d13aaca 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1108,7 +1108,7 @@ fill_ivar_cache(const rb_iseq_t *iseq, IVC ic, const struct rb_callcache *cc, in https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1108
         RB_OBJ_WRITTEN(iseq, Qundef, ent->class_value);
     }
     else {
-        vm_cc_attr_index_set(cc, (int)ent->index + 1);
+        vm_cc_attr_index_set(cc, ent->index);
     }
 }
 
@@ -1123,10 +1123,10 @@ vm_getivar(VALUE obj, ID id, const rb_iseq_t *iseq, IVC ic, const struct rb_call https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1123
         // frozen?
     }
     else if (LIKELY(is_attr ?
-                    RB_DEBUG_COUNTER_INC_UNLESS(ivar_get_ic_miss_unset, vm_cc_attr_index(cc) > 0) :
+                    RB_DEBUG_COUNTER_INC_UNLESS(ivar_get_ic_miss_unset, vm_cc_attr_index_p(cc)) :
                     RB_DEBUG_COUNTER_INC_UNLESS(ivar_get_ic_miss_serial,
                                                 ic->entry && ic->entry->class_serial == RCLASS_SERIAL(RBASIC(obj)->klass)))) {
-        uint32_t index = !is_attr ? ic->entry->index : (vm_cc_attr_index(cc) - 1);
+        uint32_t index = !is_attr ? ic->entry->index: (vm_cc_attr_index(cc));
 
         RB_DEBUG_COUNTER_INC(ivar_get_ic_hit);
 
@@ -1215,7 +1215,7 @@ vm_setivar_slowpath(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1215
                 rb_raise(rb_eArgError, "too many instance variables");
             }
             else {
-                vm_cc_attr_index_set(cc, (int)(ent->index + 1));
+                vm_cc_attr_index_set(cc, (int)(ent->index));
             }
 
             uint32_t index = ent->index;
@@ -1258,8 +1258,8 @@ vm_setivar(VALUE obj, ID id, VALUE val, const rb_iseq_t *iseq, IVC ic, const str https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1258
 
 	if (LIKELY(
 	    (!is_attr && RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_serial, ic->entry && ic->entry->class_serial  == RCLASS_SERIAL(RBASIC(obj)->klass))) ||
-            ( is_attr && RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_unset, vm_cc_attr_index(cc) > 0)))) {
-            uint32_t index = !is_attr ? ic->entry->index : vm_cc_attr_index(cc)-1;
+            ( is_attr && RB_DEBUG_COUNTER_INC_UNLESS(ivar_set_ic_miss_unset, vm_cc_attr_index_p(cc))))) {
+            uint32_t index = !is_attr ? ic->entry->index : vm_cc_attr_index(cc);
 
             if (UNLIKELY(index >= ROBJECT_NUMIV(obj))) {
                 rb_init_iv_list(obj);
@@ -3643,7 +3643,7 @@ vm_call_method_each_type(rb_execution_context_t *ec, rb_control_frame_t *cfp, st https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3643
         CALLER_REMOVE_EMPTY_KW_SPLAT(cfp, calling, ci);
 
 	rb_check_arity(calling->argc, 1, 1);
-	vm_cc_attr_index_set(cc, 0);
+	vm_cc_attr_index_initialize(cc);
         const unsigned int aset_mask = (VM_CALL_ARGS_SPLAT | VM_CALL_KW_SPLAT | VM_CALL_KWARG);
         VM_CALL_METHOD_ATTR(v,
                             vm_call_attrset(ec, cfp, calling),
@@ -3654,7 +3654,7 @@ vm_call_method_each_type(rb_execution_context_t *ec, rb_control_frame_t *cfp, st https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3654
         CALLER_SETUP_ARG(cfp, calling, ci);
         CALLER_REMOVE_EMPTY_KW_SPLAT(cfp, calling, ci);
 	rb_check_arity(calling->argc, 0, 0);
-	vm_cc_attr_index_set(cc, 0);
+	vm_cc_attr_index_initialize(cc);
         const unsigned int ivar_mask = (VM_CALL_ARGS_SPLAT | VM_CALL_KW_SPLAT);
         VM_CALL_METHOD_ATTR(v,
                             vm_call_ivar(ec, cfp, calling),
-- 
cgit v1.2.1


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

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