]> gitweb.factorcode.org Git - factor.git/commitdiff
moved dispatch functions to vm
authorPhil Dawes <phil@phildawes.net>
Mon, 17 Aug 2009 20:37:08 +0000 (21:37 +0100)
committerPhil Dawes <phil@phildawes.net>
Wed, 16 Sep 2009 07:16:21 +0000 (08:16 +0100)
vm/dispatch.cpp [changed mode: 0644->0755]
vm/vm.hpp

old mode 100644 (file)
new mode 100755 (executable)
index 4a14117..fbfc0f7
@@ -6,7 +6,7 @@ namespace factor
 cell megamorphic_cache_hits;
 cell megamorphic_cache_misses;
 
-static cell search_lookup_alist(cell table, cell klass)
+cell factorvm::search_lookup_alist(cell table, cell klass)
 {
        array *elements = untag<array>(table);
        fixnum index = array_capacity(elements) - 2;
@@ -21,7 +21,12 @@ static cell search_lookup_alist(cell table, cell klass)
        return F;
 }
 
-static cell search_lookup_hash(cell table, cell klass, cell hashcode)
+cell search_lookup_alist(cell table, cell klass)
+{
+       return vm->search_lookup_alist(table,klass);
+}
+
+cell factorvm::search_lookup_hash(cell table, cell klass, cell hashcode)
 {
        array *buckets = untag<array>(table);
        cell bucket = array_nth(buckets,hashcode & (array_capacity(buckets) - 1));
@@ -31,19 +36,34 @@ static cell search_lookup_hash(cell table, cell klass, cell hashcode)
                return search_lookup_alist(bucket,klass);
 }
 
-static cell nth_superclass(tuple_layout *layout, fixnum echelon)
+cell search_lookup_hash(cell table, cell klass, cell hashcode)
+{
+       return vm->search_lookup_hash(table,klass,hashcode);
+}
+
+cell factorvm::nth_superclass(tuple_layout *layout, fixnum echelon)
 {
        cell *ptr = (cell *)(layout + 1);
        return ptr[echelon * 2];
 }
 
-static cell nth_hashcode(tuple_layout *layout, fixnum echelon)
+cell nth_superclass(tuple_layout *layout, fixnum echelon)
+{
+       return vm->nth_superclass(layout,echelon);
+}
+
+cell factorvm::nth_hashcode(tuple_layout *layout, fixnum echelon)
 {
        cell *ptr = (cell *)(layout + 1);
        return ptr[echelon * 2 + 1];
 }
 
-static cell lookup_tuple_method(cell obj, cell methods)
+cell nth_hashcode(tuple_layout *layout, fixnum echelon)
+{
+       return vm->nth_hashcode(layout,echelon);
+}
+
+cell factorvm::lookup_tuple_method(cell obj, cell methods)
 {
        tuple_layout *layout = untag<tuple_layout>(untag<tuple>(obj)->layout);
 
@@ -75,7 +95,12 @@ static cell lookup_tuple_method(cell obj, cell methods)
        return F;
 }
 
-static cell lookup_hi_tag_method(cell obj, cell methods)
+cell lookup_tuple_method(cell obj, cell methods)
+{
+       return vm->lookup_tuple_method(obj,methods);
+}
+
+cell factorvm::lookup_hi_tag_method(cell obj, cell methods)
 {
        array *hi_tag_methods = untag<array>(methods);
        cell tag = untag<object>(obj)->h.hi_tag() - HEADER_TYPE;
@@ -85,7 +110,12 @@ static cell lookup_hi_tag_method(cell obj, cell methods)
        return array_nth(hi_tag_methods,tag);
 }
 
-static cell lookup_hairy_method(cell obj, cell methods)
+cell lookup_hi_tag_method(cell obj, cell methods)
+{
+       return vm->lookup_hi_tag_method(obj,methods);
+}
+
+cell factorvm::lookup_hairy_method(cell obj, cell methods)
 {
        cell method = array_nth(untag<array>(methods),TAG(obj));
        if(tagged<object>(method).type_p(WORD_TYPE))
@@ -107,7 +137,12 @@ static cell lookup_hairy_method(cell obj, cell methods)
        }
 }
 
-cell lookup_method(cell obj, cell methods)
+cell lookup_hairy_method(cell obj, cell methods)
+{
+       return vm->lookup_hairy_method(obj,methods);
+}
+
+cell factorvm::lookup_method(cell obj, cell methods)
 {
        cell tag = TAG(obj);
        if(tag == TUPLE_TYPE || tag == OBJECT_TYPE)
@@ -116,14 +151,24 @@ cell lookup_method(cell obj, cell methods)
                return array_nth(untag<array>(methods),TAG(obj));
 }
 
-PRIMITIVE(lookup_method)
+cell lookup_method(cell obj, cell methods)
+{
+       return vm->lookup_method(obj,methods);
+}
+
+inline void factorvm::vmprim_lookup_method()
 {
        cell methods = dpop();
        cell obj = dpop();
        dpush(lookup_method(obj,methods));
 }
 
-cell object_class(cell obj)
+PRIMITIVE(lookup_method)
+{
+       PRIMITIVE_GETVM()->vmprim_lookup_method();
+}
+
+cell factorvm::object_class(cell obj)
 {
        switch(TAG(obj))
        {
@@ -136,13 +181,23 @@ cell object_class(cell obj)
        }
 }
 
-static cell method_cache_hashcode(cell klass, array *array)
+cell object_class(cell obj)
+{
+       return vm->object_class(obj);
+}
+
+cell factorvm::method_cache_hashcode(cell klass, array *array)
 {
        cell capacity = (array_capacity(array) >> 1) - 1;
        return ((klass >> TAG_BITS) & capacity) << 1;
 }
 
-static void update_method_cache(cell cache, cell klass, cell method)
+cell method_cache_hashcode(cell klass, array *array)
+{
+       return vm->method_cache_hashcode(klass,array);
+}
+
+void factorvm::update_method_cache(cell cache, cell klass, cell method)
 {
        array *cache_elements = untag<array>(cache);
        cell hashcode = method_cache_hashcode(klass,cache_elements);
@@ -150,7 +205,12 @@ static void update_method_cache(cell cache, cell klass, cell method)
        set_array_nth(cache_elements,hashcode + 1,method);
 }
 
-PRIMITIVE(mega_cache_miss)
+void update_method_cache(cell cache, cell klass, cell method)
+{
+       return vm->update_method_cache(cache,klass,method);
+}
+
+inline void factorvm::vmprim_mega_cache_miss()
 {
        megamorphic_cache_misses++;
 
@@ -167,12 +227,22 @@ PRIMITIVE(mega_cache_miss)
        dpush(method);
 }
 
-PRIMITIVE(reset_dispatch_stats)
+PRIMITIVE(mega_cache_miss)
+{
+       PRIMITIVE_GETVM()->vmprim_mega_cache_miss();
+}
+
+inline void factorvm::vmprim_reset_dispatch_stats()
 {
        megamorphic_cache_hits = megamorphic_cache_misses = 0;
 }
 
-PRIMITIVE(dispatch_stats)
+PRIMITIVE(reset_dispatch_stats)
+{
+       PRIMITIVE_GETVM()->vmprim_reset_dispatch_stats();
+}
+
+inline void factorvm::vmprim_dispatch_stats()
 {
        growable_array stats;
        stats.add(allot_cell(megamorphic_cache_hits));
@@ -181,6 +251,11 @@ PRIMITIVE(dispatch_stats)
        dpush(stats.elements.value());
 }
 
+PRIMITIVE(dispatch_stats)
+{
+       PRIMITIVE_GETVM()->vmprim_dispatch_stats();
+}
+
 void quotation_jit::emit_mega_cache_lookup(cell methods_, fixnum index, cell cache_)
 {
        gc_root<array> methods(methods_);
index bd3a01ac8f7313e723e5108ad1faaff2386b02df..9e3e802b4f7d564d3e9972dfa0d5b2618574de7c 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -466,6 +466,23 @@ struct factorvm {
        fixnum quot_code_offset_to_scan(cell quot_, cell offset);
        cell lazy_jit_compile_impl(cell quot_, stack_frame *stack);
        inline void vmprim_quot_compiled_p();
+
+       //dispatch
+       cell search_lookup_alist(cell table, cell klass);
+       cell search_lookup_hash(cell table, cell klass, cell hashcode);
+       cell nth_superclass(tuple_layout *layout, fixnum echelon);
+       cell nth_hashcode(tuple_layout *layout, fixnum echelon);
+       cell lookup_tuple_method(cell obj, cell methods);
+       cell lookup_hi_tag_method(cell obj, cell methods);
+       cell lookup_hairy_method(cell obj, cell methods);
+       cell lookup_method(cell obj, cell methods);
+       inline void vmprim_lookup_method();
+       cell object_class(cell obj);
+       cell method_cache_hashcode(cell klass, array *array);
+       void update_method_cache(cell cache, cell klass, cell method);
+       inline void vmprim_mega_cache_miss();
+       inline void vmprim_reset_dispatch_stats();
+       inline void vmprim_dispatch_stats();
        // next method here: