]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: ignore 'declare' calls in non-optimizing compiler
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 25 Sep 2009 23:08:21 +0000 (18:08 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 25 Sep 2009 23:08:21 +0000 (18:08 -0500)
basis/bootstrap/image/image.factor
vm/quotations.cpp
vm/quotations.hpp
vm/run.hpp

index ee081a14ca4b73d5c06e5a6d24724f21963d6dee..eee65c1eba719f5dbd293be9e888e1a417d93376 100644 (file)
@@ -163,6 +163,7 @@ USERENV: jit-3dip 40
 USERENV: jit-execute-word 41
 USERENV: jit-execute-jump 42
 USERENV: jit-execute-call 43
+USERENV: jit-declare-word 44
 
 ! PIC stubs
 USERENV: pic-load 47
@@ -493,6 +494,7 @@ M: quotation '
     \ inline-cache-miss-tail \ pic-miss-tail-word set
     \ mega-cache-lookup \ mega-lookup-word set
     \ mega-cache-miss \ mega-miss-word set
+    \ declare jit-declare-word set
     [ undefined ] undefined-quot set ;
 
 : emit-userenvs ( -- )
index 1bc6240481bbe16db90f2e129558b59b57a82fa8..34412149db775bce16d24bfcff794c7926603b4f 100755 (executable)
@@ -36,51 +36,47 @@ includes stack shufflers, some fixnum arithmetic words, and words such as tag,
 slot and eq?. A primitive call is relatively expensive (two subroutine calls)
 so this results in a big speedup for relatively little effort. */
 
-bool quotation_jit::primitive_call_p(cell i)
+bool quotation_jit::primitive_call_p(cell i, cell length)
 {
-       return (i + 2) == array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(FIXNUM_TYPE)
-               && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_PRIMITIVE_WORD];
+       return (i + 2) == length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_PRIMITIVE_WORD];
 }
 
-bool quotation_jit::fast_if_p(cell i)
+bool quotation_jit::fast_if_p(cell i, cell length)
 {
-       return (i + 3) == array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(QUOTATION_TYPE)
+       return (i + 3) == length
                && tagged<object>(array_nth(elements.untagged(),i + 1)).type_p(QUOTATION_TYPE)
                && array_nth(elements.untagged(),i + 2) == parent_vm->userenv[JIT_IF_WORD];
 }
 
-bool quotation_jit::fast_dip_p(cell i)
+bool quotation_jit::fast_dip_p(cell i, cell length)
 {
-       return (i + 2) <= array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(QUOTATION_TYPE)
-               && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_DIP_WORD];
+       return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_DIP_WORD];
 }
 
-bool quotation_jit::fast_2dip_p(cell i)
+bool quotation_jit::fast_2dip_p(cell i, cell length)
 {
-       return (i + 2) <= array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(QUOTATION_TYPE)
-               && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_2DIP_WORD];
+       return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_2DIP_WORD];
 }
 
-bool quotation_jit::fast_3dip_p(cell i)
+bool quotation_jit::fast_3dip_p(cell i, cell length)
 {
-       return (i + 2) <= array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(QUOTATION_TYPE)
-               && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_3DIP_WORD];
+       return (i + 2) <= length && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_3DIP_WORD];
 }
 
-bool quotation_jit::mega_lookup_p(cell i)
+bool quotation_jit::mega_lookup_p(cell i, cell length)
 {
-       return (i + 3) < array_capacity(elements.untagged())
-               && tagged<object>(array_nth(elements.untagged(),i)).type_p(ARRAY_TYPE)
+       return (i + 4) <= length
                && tagged<object>(array_nth(elements.untagged(),i + 1)).type_p(FIXNUM_TYPE)
                && tagged<object>(array_nth(elements.untagged(),i + 2)).type_p(ARRAY_TYPE)
                && array_nth(elements.untagged(),i + 3) == parent_vm->userenv[MEGA_LOOKUP_WORD];
 }
 
+bool quotation_jit::declare_p(cell i, cell length)
+{
+       return (i + 2) <= length
+               && array_nth(elements.untagged(),i + 1) == parent_vm->userenv[JIT_DECLARE_WORD];
+}
+
 bool quotation_jit::stack_frame_p()
 {
        fixnum length = array_capacity(elements.untagged());
@@ -96,7 +92,7 @@ bool quotation_jit::stack_frame_p()
                                return true;
                        break;
                case QUOTATION_TYPE:
-                       if(fast_dip_p(i) || fast_2dip_p(i) || fast_3dip_p(i))
+                       if(fast_dip_p(i,length) || fast_2dip_p(i,length) || fast_3dip_p(i,length))
                                return true;
                        break;
                default:
@@ -179,19 +175,21 @@ void quotation_jit::iterate_quotation()
                        break;
                case FIXNUM_TYPE:
                        /* Primitive calls */
-                       if(primitive_call_p(i))
+                       if(primitive_call_p(i,length))
                        {
                                emit_with(parent_vm->userenv[JIT_PRIMITIVE],obj.value());
 
                                i++;
 
                                tail_call = true;
-                               break;
                        }
+                       else
+                               push(obj.value());
+                       break;
                case QUOTATION_TYPE:
                        /* 'if' preceeded by two literal quotations (this is why if and ? are
                           mutually recursive in the library, but both still work) */
-                       if(fast_if_p(i))
+                       if(fast_if_p(i,length))
                        {
                                if(stack_frame) emit(parent_vm->userenv[JIT_EPILOG]);
                                tail_call = true;
@@ -207,39 +205,37 @@ void quotation_jit::iterate_quotation()
                                emit(parent_vm->userenv[JIT_IF]);
 
                                i += 2;
-
-                               break;
                        }
                        /* dip */
-                       else if(fast_dip_p(i))
+                       else if(fast_dip_p(i,length))
                        {
                                if(compiling)
                                        parent_vm->jit_compile(obj.value(),relocate);
                                emit_with(parent_vm->userenv[JIT_DIP],obj.value());
                                i++;
-                               break;
                        }
                        /* 2dip */
-                       else if(fast_2dip_p(i))
+                       else if(fast_2dip_p(i,length))
                        {
                                if(compiling)
                                        parent_vm->jit_compile(obj.value(),relocate);
                                emit_with(parent_vm->userenv[JIT_2DIP],obj.value());
                                i++;
-                               break;
                        }
                        /* 3dip */
-                       else if(fast_3dip_p(i))
+                       else if(fast_3dip_p(i,length))
                        {
                                if(compiling)
                                        parent_vm->jit_compile(obj.value(),relocate);
                                emit_with(parent_vm->userenv[JIT_3DIP],obj.value());
                                i++;
-                               break;
                        }
+                       else
+                               push(obj.value());
+                       break;
                case ARRAY_TYPE:
                        /* Method dispatch */
-                       if(mega_lookup_p(i))
+                       if(mega_lookup_p(i,length))
                        {
                                emit_mega_cache_lookup(
                                        array_nth(elements.untagged(),i),
@@ -247,8 +243,13 @@ void quotation_jit::iterate_quotation()
                                        array_nth(elements.untagged(),i + 2));
                                i += 3;
                                tail_call = true;
-                               break;
                        }
+                       /* Non-optimizing compiler ignores declarations */
+                       else if(declare_p(i,length))
+                               i++;
+                       else
+                               push(obj.value());
+                       break;
                default:
                        push(obj.value());
                        break;
index b21884a35bfc8c4601f6c538e20421fd6bf09537..3dc8fa585157d17ce2e9ffedba67253e9706aeac 100755 (executable)
@@ -12,12 +12,13 @@ struct quotation_jit : public jit {
                  relocate(relocate_){};
 
        void emit_mega_cache_lookup(cell methods, fixnum index, cell cache);
-       bool primitive_call_p(cell i);
-       bool fast_if_p(cell i);
-       bool fast_dip_p(cell i);
-       bool fast_2dip_p(cell i);
-       bool fast_3dip_p(cell i);
-       bool mega_lookup_p(cell i);
+       bool primitive_call_p(cell i, cell length);
+       bool fast_if_p(cell i, cell length);
+       bool fast_dip_p(cell i, cell length);
+       bool fast_2dip_p(cell i, cell length);
+       bool fast_3dip_p(cell i, cell length);
+       bool mega_lookup_p(cell i, cell length);
+       bool declare_p(cell i, cell length);
        bool stack_frame_p();
        void iterate_quotation();
 };
index d10a6678b821cd5e5125a84b06aa9e1ce7434c46..562eef92200cd0b693c2ffbaa68f13f046d24464 100755 (executable)
@@ -57,6 +57,7 @@ enum special_object {
        JIT_EXECUTE_WORD,
        JIT_EXECUTE_JUMP,
        JIT_EXECUTE_CALL,
+       JIT_DECLARE_WORD,
 
        /* Polymorphic inline cache generation in inline_cache.c */
        PIC_LOAD            = 47,