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

ruby-changes:68902

From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:13:05 +0900 (JST)
Subject: [ruby-changes:68902] 79d6e9618d (master): Make find_block_version() do list search

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

From 79d6e9618d8215f936a3c938d192753906412c02 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@s...>
Date: Fri, 22 Jan 2021 16:54:43 -0500
Subject: Make find_block_version() do list search

---
 ujit_core.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/ujit_core.c b/ujit_core.c
index 8e7ce31330..c7a2c7acab 100644
--- a/ujit_core.c
+++ b/ujit_core.c
@@ -106,16 +106,16 @@ ctx_get_top_type(ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L106
 /**
 Compute a difference score for two context objects
 Returns 0 if the two contexts are the same
-Returns -1 if incompatible
 Returns > 0 if different but compatible
+Returns INT_MAX if incompatible
 */
 int ctx_diff(const ctx_t* src, const ctx_t* dst)
 {
     if (dst->stack_size != src->stack_size)
-        return -1;
+        return INT_MAX;
 
     if (dst->self_is_object != src->self_is_object)
-        return -1;
+        return INT_MAX;
 
     // Difference sum
     int diff = 0;
@@ -132,7 +132,7 @@ int ctx_diff(const ctx_t* src, const ctx_t* dst) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L132
             if (t_dst == T_NONE)
                 diff += 1;
             else
-                return -1;
+                return INT_MAX;
         }
     }
 
@@ -158,14 +158,28 @@ block_t* find_block_version(blockid_t blockid, const ctx_t* ctx) https://github.com/ruby/ruby/blob/trunk/ujit_core.c#L158
     if (!rb_st_lookup(version_tbl, (st_data_t)&blockid, (st_data_t*)&first_version))
         return NULL;
 
-    //
-    // TODO: use the ctx parameter to search existing versions for a match
-    //
+    // Best match found
+    block_t* best_version = NULL;
+    int best_diff = INT_MAX;
+
+    // For each version matching the blockid
+    for (block_t* version = first_version; version != NULL; version = version->next)
+    {
+        int diff = ctx_diff(ctx, &version->ctx);
 
-    // Check that the version found is actually compatible
-    RUBY_ASSERT(ctx_diff(ctx, &first_version->ctx) >= 0);
+        if (diff < best_diff)
+        {
+            best_version = version;
+            best_diff = diff;
+        }
+    }
+
+    if (best_version == NULL)
+    {
+        return NULL;
+    }
 
-    return first_version;
+    return best_version;
 }
 // Compile a new block version immediately
 block_t* gen_block_version(blockid_t blockid, const ctx_t* start_ctx)
-- 
cgit v1.2.1


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

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