Machine code is now stored in a byte array instead of an array for add_code_block()

db4
Slava Pestov 2009-04-30 04:34:35 -05:00
parent 59d6131c7c
commit 5fb5c19d61
10 changed files with 22 additions and 66 deletions

View File

@ -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

View File

@ -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 ;

View File

@ -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

View File

@ -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 */

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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));
}

View File

@ -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));

View File

@ -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,