From b14c683b3283020eeb89f9f6f9b0fb1b28ed2407 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 25 Sep 2009 18:08:21 -0500 Subject: [PATCH] vm: ignore 'declare' calls in non-optimizing compiler --- basis/bootstrap/image/image.factor | 2 + vm/quotations.cpp | 73 +++++++++++++++--------------- vm/quotations.hpp | 13 +++--- vm/run.hpp | 1 + 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/basis/bootstrap/image/image.factor b/basis/bootstrap/image/image.factor index ee081a14ca..eee65c1eba 100644 --- a/basis/bootstrap/image/image.factor +++ b/basis/bootstrap/image/image.factor @@ -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 ( -- ) diff --git a/vm/quotations.cpp b/vm/quotations.cpp index 1bc6240481..34412149db 100755 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -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(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(array_nth(elements.untagged(),i)).type_p(QUOTATION_TYPE) + return (i + 3) == length && tagged(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(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(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(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(array_nth(elements.untagged(),i)).type_p(ARRAY_TYPE) + return (i + 4) <= length && tagged(array_nth(elements.untagged(),i + 1)).type_p(FIXNUM_TYPE) && tagged(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; diff --git a/vm/quotations.hpp b/vm/quotations.hpp index b21884a35b..3dc8fa5851 100755 --- a/vm/quotations.hpp +++ b/vm/quotations.hpp @@ -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(); }; diff --git a/vm/run.hpp b/vm/run.hpp index d10a6678b8..562eef9220 100755 --- a/vm/run.hpp +++ b/vm/run.hpp @@ -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,