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 ;
SYMBOL: bootstrap-boot-quot
! JIT parameters
-SYMBOL: jit-code-format
SYMBOL: jit-prolog
SYMBOL: jit-primitive-word
SYMBOL: jit-primitive
H{
{ bootstrap-boot-quot 20 }
{ bootstrap-global 21 }
- { jit-code-format 22 }
{ jit-prolog 23 }
{ jit-primitive-word 24 }
{ jit-primitive 25 }
\ mega-cache-miss \ mega-miss-word set
[ undefined ] undefined-quot set
{
- jit-code-format
jit-prolog
jit-primitive-word
jit-primitive
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
literal-table get >array
relocation-table get >byte-array
label-table get resolve-labels
- ] { } make 4array ;
+ ] B{ } make 4array ;
big-endian off
-1 jit-code-format set
-
[
! Load word
temp0 0 MOV rc-absolute-cell rt-immediate jit-rel
}
/* 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);
}
}
-/* 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)
{
/* Might GC */
F_CODE_BLOCK *add_code_block(
CELL type,
- F_ARRAY *code,
+ F_BYTE_ARRAY *code,
F_ARRAY *labels,
CELL relocation,
CELL literals)
#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);
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 */
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;
F_CODE_BLOCK *add_code_block(
CELL type,
- F_ARRAY *code,
+ F_BYTE_ARRAY *code,
F_ARRAY *labels,
CELL relocation,
CELL literals);
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);
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);
/* 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);
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)));
}
}
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);
}
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;
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));
}
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; \
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));
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,