diff --git a/basis/bootstrap/image/image.factor b/basis/bootstrap/image/image.factor index 5bf3c30097..dde945e9af 100644 --- a/basis/bootstrap/image/image.factor +++ b/basis/bootstrap/image/image.factor @@ -111,7 +111,7 @@ SYMBOL: jit-define-offset jit-define-rc get jit-define-rt get jit-define-offset get 3array - ] { } make prefix ; + ] B{ } make prefix ; : jit-define ( quot name -- ) [ make-jit ] dip set ; @@ -135,7 +135,6 @@ SYMBOL: bootstrap-global SYMBOL: bootstrap-boot-quot ! JIT parameters -SYMBOL: jit-code-format SYMBOL: jit-prolog SYMBOL: jit-primitive-word SYMBOL: jit-primitive @@ -185,7 +184,6 @@ SYMBOL: undefined-quot H{ { bootstrap-boot-quot 20 } { bootstrap-global 21 } - { jit-code-format 22 } { jit-prolog 23 } { jit-primitive-word 24 } { jit-primitive 25 } @@ -538,7 +536,6 @@ M: quotation ' \ mega-cache-miss \ mega-miss-word set [ undefined ] undefined-quot set { - jit-code-format jit-prolog jit-primitive-word jit-primitive diff --git a/basis/compiler/codegen/fixup/fixup.factor b/basis/compiler/codegen/fixup/fixup.factor index 45d87b3270..99f258d93c 100755 --- a/basis/compiler/codegen/fixup/fixup.factor +++ b/basis/compiler/codegen/fixup/fixup.factor @@ -9,9 +9,7 @@ IN: compiler.codegen.fixup GENERIC: fixup* ( obj -- ) -: code-format ( -- n ) 22 getenv ; - -: compiled-offset ( -- n ) building get length code-format * ; +: compiled-offset ( -- n ) building get length ; SYMBOL: relocation-table SYMBOL: label-table @@ -91,4 +89,4 @@ SYMBOL: literal-table literal-table get >array relocation-table get >byte-array label-table get resolve-labels - ] { } make 4array ; + ] B{ } make 4array ; diff --git a/basis/cpu/x86/bootstrap.factor b/basis/cpu/x86/bootstrap.factor index 4f9a94a58b..f89839aa83 100644 --- a/basis/cpu/x86/bootstrap.factor +++ b/basis/cpu/x86/bootstrap.factor @@ -8,8 +8,6 @@ IN: bootstrap.x86 big-endian off -1 jit-code-format set - [ ! Load word temp0 0 MOV rc-absolute-cell rt-immediate jit-rel diff --git a/vm/code_block.c b/vm/code_block.c index 4331291083..1d428e4fcd 100644 --- a/vm/code_block.c +++ b/vm/code_block.c @@ -396,7 +396,7 @@ void relocate_code_block(F_CODE_BLOCK *compiled) } /* Fixup labels. This is done at compile time, not image load time */ -void fixup_labels(F_ARRAY *labels, CELL code_format, F_CODE_BLOCK *compiled) +void fixup_labels(F_ARRAY *labels, F_CODE_BLOCK *compiled) { CELL i; CELL size = array_capacity(labels); @@ -413,31 +413,6 @@ void fixup_labels(F_ARRAY *labels, CELL code_format, F_CODE_BLOCK *compiled) } } -/* Write a sequence of integers to memory, with 'format' bytes per integer */ -void deposit_integers(CELL here, F_ARRAY *array, CELL format) -{ - CELL count = array_capacity(array); - CELL i; - - for(i = 0; i < count; i++) - { - F_FIXNUM value = to_fixnum(array_nth(array,i)); - if(format == 1) - bput(here + i,value); - else if(format == sizeof(unsigned int)) - *(unsigned int *)(here + format * i) = value; - else if(format == sizeof(CELL)) - *(CELL *)(here + format * i) = value; - else - critical_error("Bad format in deposit_integers()",format); - } -} - -CELL compiled_code_format(void) -{ - return untag_fixnum_fast(userenv[JIT_CODE_FORMAT]); -} - /* Might GC */ F_CODE_BLOCK *allot_code_block(CELL size) { @@ -469,7 +444,7 @@ F_CODE_BLOCK *allot_code_block(CELL size) /* Might GC */ F_CODE_BLOCK *add_code_block( CELL type, - F_ARRAY *code, + F_BYTE_ARRAY *code, F_ARRAY *labels, CELL relocation, CELL literals) @@ -477,11 +452,10 @@ F_CODE_BLOCK *add_code_block( #ifdef FACTOR_DEBUG type_check(ARRAY_TYPE,literals); type_check(BYTE_ARRAY_TYPE,relocation); - assert(untag_header(code->header) == ARRAY_TYPE); + assert(untag_header(code->header) == BYTE_ARRAY_TYPE); #endif - CELL code_format = compiled_code_format(); - CELL code_length = align8(array_capacity(code) * code_format); + CELL code_length = align8(array_capacity(code)); REGISTER_ROOT(literals); REGISTER_ROOT(relocation); @@ -506,16 +480,11 @@ F_CODE_BLOCK *add_code_block( compiled->literals = literals; compiled->relocation = relocation; -#ifdef FACTOR_DEBUG - type_check(ARRAY_TYPE,compiled->literals); - type_check(BYTE_ARRAY_TYPE,compiled->relocation); -#endif - /* code */ - deposit_integers((CELL)(compiled + 1),code,code_format); + memcpy(compiled + 1,code + 1,code_length); /* fixup labels */ - if(labels) fixup_labels(labels,code_format,compiled); + if(labels) fixup_labels(labels,compiled); /* next time we do a minor GC, we have to scan the code heap for literals */ diff --git a/vm/code_block.h b/vm/code_block.h index b8201c44a1..385f414f88 100644 --- a/vm/code_block.h +++ b/vm/code_block.h @@ -79,8 +79,6 @@ void mark_object_code_block(CELL scan); void relocate_code_block(F_CODE_BLOCK *relocating); -CELL compiled_code_format(void); - INLINE bool stack_traces_p(void) { return userenv[STACK_TRACES_ENV] != F; @@ -88,7 +86,7 @@ INLINE bool stack_traces_p(void) F_CODE_BLOCK *add_code_block( CELL type, - F_ARRAY *code, + F_BYTE_ARRAY *code, F_ARRAY *labels, CELL relocation, CELL literals); diff --git a/vm/code_heap.c b/vm/code_heap.c index 0ae3d6b3fa..6ba98dfa77 100755 --- a/vm/code_heap.c +++ b/vm/code_heap.c @@ -93,7 +93,7 @@ void primitive_modify_code_heap(void) CELL literals = array_nth(compiled_code,0); CELL relocation = array_nth(compiled_code,1); F_ARRAY *labels = untag_array(array_nth(compiled_code,2)); - F_ARRAY *code = untag_array(array_nth(compiled_code,3)); + F_BYTE_ARRAY *code = untag_byte_array(array_nth(compiled_code,3)); REGISTER_UNTAGGED(alist); REGISTER_UNTAGGED(word); diff --git a/vm/jit.c b/vm/jit.c index 8421b79468..8145d18b36 100644 --- a/vm/jit.c +++ b/vm/jit.c @@ -13,9 +13,8 @@ void jit_init(F_JIT *jit, CELL jit_type, CELL owner) REGISTER_ROOT(jit->owner); jit->type = jit_type; - jit->code_format = compiled_code_format(); - jit->code = make_growable_array(); + jit->code = make_growable_byte_array(); REGISTER_ROOT(jit->code.array); jit->relocation = make_growable_byte_array(); REGISTER_ROOT(jit->relocation.array); @@ -29,7 +28,7 @@ void jit_init(F_JIT *jit, CELL jit_type, CELL owner) /* Allocates memory */ F_CODE_BLOCK *jit_make_code_block(F_JIT *jit) { - growable_array_trim(&jit->code); + growable_byte_array_trim(&jit->code); growable_byte_array_trim(&jit->relocation); growable_array_trim(&jit->literals); @@ -66,9 +65,9 @@ static F_REL rel_to_emit(F_JIT *jit, CELL template, bool *rel_p) else { *rel_p = true; - return (to_fixnum(rel_type) << 28) - | (to_fixnum(rel_class) << 24) - | ((jit->code.count + to_fixnum(offset)) * jit->code_format); + return (untag_fixnum_fast(rel_type) << 28) + | (untag_fixnum_fast(rel_class) << 24) + | ((jit->code.count + untag_fixnum_fast(offset))); } } @@ -79,7 +78,8 @@ void jit_emit(F_JIT *jit, CELL template) bool rel_p; F_REL rel = rel_to_emit(jit,template,&rel_p); if(rel_p) growable_byte_array_append(&jit->relocation,&rel,sizeof(F_REL)); - growable_array_append(&jit->code,code_to_emit(template)); + F_BYTE_ARRAY *code = code_to_emit(template); + growable_byte_array_append(&jit->code,code + 1,array_capacity(code)); UNREGISTER_ROOT(template); } diff --git a/vm/jit.h b/vm/jit.h index 0e27f2a7ab..2085c8c8bd 100644 --- a/vm/jit.h +++ b/vm/jit.h @@ -1,8 +1,7 @@ typedef struct { CELL type; CELL owner; - CELL code_format; - F_GROWABLE_ARRAY code; + F_GROWABLE_BYTE_ARRAY code; F_GROWABLE_BYTE_ARRAY relocation; F_GROWABLE_ARRAY literals; } F_JIT; @@ -11,7 +10,7 @@ void jit_init(F_JIT *jit, CELL jit_type, CELL owner); F_CODE_BLOCK *jit_make_code_block(F_JIT *jit); void jit_dispose(F_JIT *jit); -INLINE F_ARRAY *code_to_emit(CELL template) +INLINE F_BYTE_ARRAY *code_to_emit(CELL template) { return untag_object(array_nth(untag_object(template),0)); } diff --git a/vm/quotations.c b/vm/quotations.c index 0e24297ac1..d358a2c571 100755 --- a/vm/quotations.c +++ b/vm/quotations.c @@ -310,7 +310,7 @@ worse than the duplication itself (eg, putting all state in some global struct.) */ #define COUNT(name,scan) \ { \ - CELL size = array_capacity(code_to_emit(name)) * code_format; \ + CELL size = array_capacity(code_to_emit(name)); \ if(offset == 0) return scan - 1; \ if(offset < size) return scan + 1; \ offset -= size; \ @@ -324,8 +324,6 @@ struct.) */ F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset) { - CELL code_format = compiled_code_format(); - CELL array = untag_quotation(quot)->array; bool stack_frame = jit_stack_frame_p(untag_object(array)); diff --git a/vm/run.h b/vm/run.h index e3e7aacf6f..d32a91e67a 100755 --- a/vm/run.h +++ b/vm/run.h @@ -33,8 +33,7 @@ typedef enum { GLOBAL_ENV, /* global namespace */ /* Quotation compilation in quotations.c */ - JIT_CODE_FORMAT = 22, - JIT_PROLOG, + JIT_PROLOG = 23, JIT_PRIMITIVE_WORD, JIT_PRIMITIVE, JIT_WORD_JUMP,