From 7e17c3077c7df8792cd0a9b6279691b99ca0c8ef Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 2 Nov 2009 01:37:58 -0600 Subject: [PATCH] vm: new megamorphic hashcode algorithm improves bootstrap speed --- basis/cpu/ppc/bootstrap.factor | 9 +++++++-- basis/cpu/x86/bootstrap.factor | 11 +++++++++-- vm/dispatch.cpp | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/basis/cpu/ppc/bootstrap.factor b/basis/cpu/ppc/bootstrap.factor index cd877cfafe..f7a7e58d7d 100644 --- a/basis/cpu/ppc/bootstrap.factor +++ b/basis/cpu/ppc/bootstrap.factor @@ -224,8 +224,13 @@ CONSTANT: rs-reg 14 [ ! cache = ... 0 3 LOAD32 rc-absolute-ppc-2/2 rt-immediate jit-rel - ! key = class - 5 4 MR + ! key = hashcode(class) + 5 4 3 SRAWI + 6 4 8 SRAWI + 5 5 6 ADD + 6 4 13 SRAWI + 5 5 6 ADD + 5 5 3 SLWI ! key &= cache.length - 1 5 5 mega-cache-size get 1 - bootstrap-cell * ANDI ! cache += array-start-offset diff --git a/basis/cpu/x86/bootstrap.factor b/basis/cpu/x86/bootstrap.factor index 7930970193..25a826cde4 100644 --- a/basis/cpu/x86/bootstrap.factor +++ b/basis/cpu/x86/bootstrap.factor @@ -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 diff --git a/vm/dispatch.cpp b/vm/dispatch.cpp index e636012126..333a49bfbe 100755 --- a/vm/dispatch.cpp +++ b/vm/dispatch.cpp @@ -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)