diff --git a/basis/bootstrap/image/image.factor b/basis/bootstrap/image/image.factor index 675c50732d..7b39cee101 100644 --- a/basis/bootstrap/image/image.factor +++ b/basis/bootstrap/image/image.factor @@ -93,24 +93,19 @@ CONSTANT: -1-offset 9 SYMBOL: sub-primitives -SYMBOL: jit-define-rc -SYMBOL: jit-define-rt -SYMBOL: jit-define-offset +SYMBOL: jit-relocations -: compute-offset ( -- offset ) - building get length jit-define-rc get rc-absolute-cell = bootstrap-cell 4 ? - ; +: compute-offset ( rc -- offset ) + [ building get length ] dip rc-absolute-cell = bootstrap-cell 4 ? - ; : jit-rel ( rc rt -- ) - jit-define-rt set - jit-define-rc set - compute-offset jit-define-offset set ; + over compute-offset 3array jit-relocations get push-all ; -: make-jit ( quot -- quad ) +: make-jit ( quot -- jit-data ) [ + V{ } clone jit-relocations set call( -- ) - jit-define-rc get - jit-define-rt get - jit-define-offset get 3array + jit-relocations get >array ] B{ } make prefix ; : jit-define ( quot name -- ) @@ -142,8 +137,7 @@ SYMBOL: jit-word-jump SYMBOL: jit-word-call SYMBOL: jit-push-immediate SYMBOL: jit-if-word -SYMBOL: jit-if-1 -SYMBOL: jit-if-2 +SYMBOL: jit-if SYMBOL: jit-dip-word SYMBOL: jit-dip SYMBOL: jit-2dip-word @@ -156,7 +150,6 @@ SYMBOL: jit-execute-call SYMBOL: jit-epilog SYMBOL: jit-return SYMBOL: jit-profiling -SYMBOL: jit-save-stack ! PIC stubs SYMBOL: pic-load @@ -188,13 +181,11 @@ SYMBOL: undefined-quot { jit-word-jump 26 } { jit-word-call 27 } { jit-if-word 28 } - { jit-if-1 29 } - { jit-if-2 30 } + { jit-if 29 } { jit-epilog 33 } { jit-return 34 } { jit-profiling 35 } { jit-push-immediate 36 } - { jit-save-stack 37 } { jit-dip-word 38 } { jit-dip 39 } { jit-2dip-word 40 } @@ -539,8 +530,7 @@ M: quotation ' jit-word-call jit-push-immediate jit-if-word - jit-if-1 - jit-if-2 + jit-if jit-dip-word jit-dip jit-2dip-word @@ -553,7 +543,6 @@ M: quotation ' jit-epilog jit-return jit-profiling - jit-save-stack pic-load pic-tag pic-hi-tag diff --git a/basis/cpu/ppc/bootstrap.factor b/basis/cpu/ppc/bootstrap.factor index 8001868e0c..768b919d4f 100644 --- a/basis/cpu/ppc/bootstrap.factor +++ b/basis/cpu/ppc/bootstrap.factor @@ -50,9 +50,6 @@ CONSTANT: rs-reg 14 0 6 LOAD32 rc-absolute-ppc-2/2 rt-stack-chain jit-rel 7 6 0 LWZ 1 7 0 STW -] jit-save-stack jit-define - -[ 0 6 LOAD32 rc-absolute-ppc-2/2 rt-primitive jit-rel 6 MTCTR BCTR @@ -68,11 +65,8 @@ CONSTANT: rs-reg 14 0 3 \ f tag-number CMPI 2 BEQ 0 B rc-relative-ppc-3 rt-xt jit-rel -] jit-if-1 jit-define - -[ 0 B rc-relative-ppc-3 rt-xt jit-rel -] jit-if-2 jit-define +] jit-if jit-define : jit->r ( -- ) 4 ds-reg 0 LWZ diff --git a/basis/cpu/x86/32/bootstrap.factor b/basis/cpu/x86/32/bootstrap.factor index 660a428dfb..490d37ccbc 100644 --- a/basis/cpu/x86/32/bootstrap.factor +++ b/basis/cpu/x86/32/bootstrap.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2007 Slava Pestov. +! Copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: bootstrap.image.private kernel namespaces system cpu.x86.assembler layouts vocabs parser compiler.constants ; @@ -26,9 +26,7 @@ IN: bootstrap.x86 temp0 0 [] MOV rc-absolute-cell rt-stack-chain jit-rel ! save stack pointer temp0 [] stack-reg MOV -] jit-save-stack jit-define - -[ + ! call the primitive 0 JMP rc-relative rt-primitive jit-rel ] jit-primitive jit-define diff --git a/basis/cpu/x86/64/bootstrap.factor b/basis/cpu/x86/64/bootstrap.factor index 8d1ed086e7..c5c7e63dbc 100644 --- a/basis/cpu/x86/64/bootstrap.factor +++ b/basis/cpu/x86/64/bootstrap.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2007 Slava Pestov. +! Copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: bootstrap.image.private kernel namespaces system cpu.x86.assembler layouts vocabs parser compiler.constants math ; @@ -25,9 +25,6 @@ IN: bootstrap.x86 temp0 temp0 [] MOV ! save stack pointer temp0 [] stack-reg MOV -] jit-save-stack jit-define - -[ ! load XT temp1 0 MOV rc-absolute-cell rt-primitive jit-rel ! go diff --git a/basis/cpu/x86/bootstrap.factor b/basis/cpu/x86/bootstrap.factor index 8d35d4ed8a..ee75281a9d 100644 --- a/basis/cpu/x86/bootstrap.factor +++ b/basis/cpu/x86/bootstrap.factor @@ -58,12 +58,9 @@ big-endian off temp0 \ f tag-number CMP ! jump to true branch if not equal 0 JNE rc-relative rt-xt jit-rel -] jit-if-1 jit-define - -[ ! jump to false branch if equal 0 JMP rc-relative rt-xt jit-rel -] jit-if-2 jit-define +] jit-if jit-define : jit->r ( -- ) rs-reg bootstrap-cell ADD diff --git a/vm/jit.cpp b/vm/jit.cpp index bb86506058..a3f222a953 100644 --- a/vm/jit.cpp +++ b/vm/jit.cpp @@ -23,24 +23,21 @@ jit::jit(cell type_, cell owner_) if(stack_traces_p()) literal(owner.value()); } -relocation_entry jit::rel_to_emit(cell code_template, bool *rel_p) +void jit::emit_relocation(cell code_template_) { - array *quadruple = untag(code_template); - cell rel_class = array_nth(quadruple,1); - cell rel_type = array_nth(quadruple,2); - cell offset = array_nth(quadruple,3); + gc_root code_template(code_template_); + cell capacity = array_capacity(code_template.untagged()); + for(cell i = 1; i < capacity; i += 3) + { + cell rel_class = array_nth(code_template.untagged(),i); + cell rel_type = array_nth(code_template.untagged(),i + 1); + cell offset = array_nth(code_template.untagged(),i + 2); - if(rel_class == F) - { - *rel_p = false; - return 0; - } - else - { - *rel_p = true; - return (untag_fixnum(rel_type) << 28) + relocation_entry new_entry + = (untag_fixnum(rel_type) << 28) | (untag_fixnum(rel_class) << 24) | ((code.count + untag_fixnum(offset))); + relocation.append_bytes(&new_entry,sizeof(relocation_entry)); } } @@ -49,9 +46,7 @@ void jit::emit(cell code_template_) { gc_root code_template(code_template_); - bool rel_p; - relocation_entry rel = rel_to_emit(code_template.value(),&rel_p); - if(rel_p) relocation.append_bytes(&rel,sizeof(relocation_entry)); + emit_relocation(code_template.value()); gc_root insns(array_nth(code_template.untagged(),0)); diff --git a/vm/jit.hpp b/vm/jit.hpp index 30b5163b4a..976be9ef3b 100644 --- a/vm/jit.hpp +++ b/vm/jit.hpp @@ -14,7 +14,7 @@ struct jit { jit(cell jit_type, cell owner); void compute_position(cell offset); - relocation_entry rel_to_emit(cell code_template, bool *rel_p); + void emit_relocation(cell code_template); void emit(cell code_template); void literal(cell literal) { literals.add(literal); } @@ -35,7 +35,7 @@ struct jit { void emit_subprimitive(cell word_) { gc_root word(word_); gc_root code_template(word->subprimitive); - if(array_nth(code_template.untagged(),1) != F) literal(T); + if(array_capacity(code_template.untagged()) > 1) literal(T); emit(code_template.value()); } diff --git a/vm/quotations.cpp b/vm/quotations.cpp index 555ecc6420..afd9fc3da2 100755 --- a/vm/quotations.cpp +++ b/vm/quotations.cpp @@ -165,7 +165,6 @@ void quotation_jit::iterate_quotation() /* Primitive calls */ if(primitive_call_p(i)) { - emit(userenv[JIT_SAVE_STACK]); emit_with(userenv[JIT_PRIMITIVE],obj.value()); i++; @@ -187,8 +186,9 @@ void quotation_jit::iterate_quotation() jit_compile(array_nth(elements.untagged(),i + 1),relocate); } - emit_with(userenv[JIT_IF_1],array_nth(elements.untagged(),i)); - emit_with(userenv[JIT_IF_2],array_nth(elements.untagged(),i + 1)); + literal(array_nth(elements.untagged(),i)); + literal(array_nth(elements.untagged(),i + 1)); + emit(userenv[JIT_IF]); i += 2; diff --git a/vm/run.hpp b/vm/run.hpp index 48ebb8cf41..2072580c79 100755 --- a/vm/run.hpp +++ b/vm/run.hpp @@ -42,14 +42,12 @@ enum special_object { JIT_WORD_JUMP, JIT_WORD_CALL, JIT_IF_WORD, - JIT_IF_1, - JIT_IF_2, + JIT_IF, JIT_EPILOG = 33, JIT_RETURN, JIT_PROFILING, JIT_PUSH_IMMEDIATE, - JIT_SAVE_STACK, - JIT_DIP_WORD, + JIT_DIP_WORD = 38, JIT_DIP, JIT_2DIP_WORD, JIT_2DIP,