]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: new megamorphic hashcode algorithm improves bootstrap speed
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 2 Nov 2009 07:37:58 +0000 (01:37 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 2 Nov 2009 07:37:58 +0000 (01:37 -0600)
basis/cpu/ppc/bootstrap.factor
basis/cpu/x86/bootstrap.factor
vm/dispatch.cpp

index cd877cfafe733f5178768340ea89d9a9597d4083..f7a7e58d7df776c20443afb27d8376d46d4e6aab 100644 (file)
@@ -224,8 +224,13 @@ CONSTANT: rs-reg 14
 [\r
     ! cache = ...\r
     0 3 LOAD32 rc-absolute-ppc-2/2 rt-immediate jit-rel\r
-    ! key = class\r
-    5 4 MR\r
+    ! key = hashcode(class)\r
+    5 4 3 SRAWI\r
+    6 4 8 SRAWI\r
+    5 5 6 ADD\r
+    6 4 13 SRAWI\r
+    5 5 6 ADD\r
+    5 5 3 SLWI\r
     ! key &= cache.length - 1\r
     5 5 mega-cache-size get 1 - bootstrap-cell * ANDI\r
     ! cache += array-start-offset\r
index 79309701933bc2401ab9cd520ce99f4d9ed14eaf..25a826cde40ed4ef7d97928152ffb702f3657120 100644 (file)
@@ -222,9 +222,16 @@ big-endian off
 [
     ! cache = ...
     temp0 0 MOV rc-absolute-cell rt-immediate jit-rel
-    ! key = class
+    ! key = hashcode(class)
     temp2 temp1 MOV
-    bootstrap-cell 8 = [ temp2 1 SHL ] when
+    temp2 3 SHR
+    temp3 temp1 MOV
+    temp3 8 SHR
+    temp2 temp3 ADD
+    temp3 temp1 MOV
+    temp3 13 SHR
+    temp2 temp3 ADD
+    temp2 bootstrap-cell 4 = 3 4 ? SHL
     ! key &= cache.length - 1
     temp2 mega-cache-size get 1 - bootstrap-cell * AND
     ! cache += array-start-offset
index e636012126118731f4e9802e5cb2afb072d6e100..333a49bfbe646deaec297d9437d118268681c76e 100755 (executable)
@@ -126,7 +126,7 @@ cell factor_vm::object_class(cell obj)
 cell factor_vm::method_cache_hashcode(cell klass, array *array)
 {
        cell capacity = (array_capacity(array) >> 1) - 1;
-       return ((klass >> TAG_BITS) & capacity) << 1;
+       return (((klass >> 3) + (klass >> 8) + (klass >> 13)) & capacity) << 1;
 }
 
 void factor_vm::update_method_cache(cell cache, cell klass, cell method)