Experimental optimizations
parent
9490207615
commit
2aaf860f47
|
@ -69,6 +69,9 @@ SYMBOL: literal-table
|
||||||
: rel-literal ( literal class -- )
|
: rel-literal ( literal class -- )
|
||||||
>r add-literal r> rt-literal rel-fixup ;
|
>r add-literal r> rt-literal rel-fixup ;
|
||||||
|
|
||||||
|
: rel-immediate ( literal class -- )
|
||||||
|
>r add-literal r> rt-immediate rel-fixup ;
|
||||||
|
|
||||||
: rel-this ( class -- )
|
: rel-this ( class -- )
|
||||||
0 swap rt-label rel-fixup ;
|
0 swap rt-label rel-fixup ;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ big-endian off
|
||||||
[
|
[
|
||||||
! Load word
|
! Load word
|
||||||
temp-reg 0 MOV
|
temp-reg 0 MOV
|
||||||
temp-reg dup [] MOV
|
|
||||||
! Bump profiling counter
|
! Bump profiling counter
|
||||||
temp-reg profile-count-offset [+] 1 tag-fixnum ADD
|
temp-reg profile-count-offset [+] 1 tag-fixnum ADD
|
||||||
! Load word->code
|
! Load word->code
|
||||||
|
@ -22,7 +21,7 @@ big-endian off
|
||||||
temp-reg compiled-header-size ADD
|
temp-reg compiled-header-size ADD
|
||||||
! Jump to XT
|
! Jump to XT
|
||||||
temp-reg JMP
|
temp-reg JMP
|
||||||
] rc-absolute-cell rt-literal 1 rex-length + jit-profiling jit-define
|
] rc-absolute-cell rt-immediate 1 rex-length + jit-profiling jit-define
|
||||||
|
|
||||||
[
|
[
|
||||||
temp-reg 0 MOV ! load XT
|
temp-reg 0 MOV ! load XT
|
||||||
|
@ -65,14 +64,13 @@ big-endian off
|
||||||
|
|
||||||
[
|
[
|
||||||
arg1 0 MOV ! load dispatch table
|
arg1 0 MOV ! load dispatch table
|
||||||
arg1 dup [] MOV
|
|
||||||
arg0 ds-reg [] MOV ! load index
|
arg0 ds-reg [] MOV ! load index
|
||||||
fixnum>slot@ ! turn it into an array offset
|
fixnum>slot@ ! turn it into an array offset
|
||||||
ds-reg bootstrap-cell SUB ! pop index
|
ds-reg bootstrap-cell SUB ! pop index
|
||||||
arg0 arg1 ADD ! compute quotation location
|
arg0 arg1 ADD ! compute quotation location
|
||||||
arg0 arg0 array-start-offset [+] MOV ! load quotation
|
arg0 arg0 array-start-offset [+] MOV ! load quotation
|
||||||
arg0 quot-xt-offset [+] JMP ! execute branch
|
arg0 quot-xt-offset [+] JMP ! execute branch
|
||||||
] rc-absolute-cell rt-literal 1 rex-length + jit-dispatch jit-define
|
] rc-absolute-cell rt-immediate 1 rex-length + jit-dispatch jit-define
|
||||||
|
|
||||||
: jit->r ( -- )
|
: jit->r ( -- )
|
||||||
rs-reg bootstrap-cell ADD
|
rs-reg bootstrap-cell ADD
|
||||||
|
|
|
@ -18,7 +18,7 @@ M: x86 %load-immediate MOV ;
|
||||||
|
|
||||||
HOOK: rel-literal-x86 cpu ( literal -- )
|
HOOK: rel-literal-x86 cpu ( literal -- )
|
||||||
|
|
||||||
M: x86 %load-indirect swap 0 [] MOV rel-literal-x86 ;
|
M: x86 %load-indirect swap 0 MOV rc-absolute-cell rel-immediate ;
|
||||||
|
|
||||||
HOOK: ds-reg cpu ( -- reg )
|
HOOK: ds-reg cpu ( -- reg )
|
||||||
HOOK: rs-reg cpu ( -- reg )
|
HOOK: rs-reg cpu ( -- reg )
|
||||||
|
|
40
vm/code_gc.c
40
vm/code_gc.c
|
@ -259,13 +259,43 @@ void iterate_code_heap(CODE_HEAP_ITERATOR iter)
|
||||||
/* Copy all literals referenced from a code block to newspace */
|
/* Copy all literals referenced from a code block to newspace */
|
||||||
void collect_literals_step(F_COMPILED *compiled, CELL code_start, CELL literals_start)
|
void collect_literals_step(F_COMPILED *compiled, CELL code_start, CELL literals_start)
|
||||||
{
|
{
|
||||||
CELL scan;
|
if(collecting_gen >= compiled->last_scan)
|
||||||
CELL literal_end = literals_start + compiled->literals_length;
|
{
|
||||||
|
CELL scan;
|
||||||
|
CELL literal_end = literals_start + compiled->literals_length;
|
||||||
|
|
||||||
copy_handle(&compiled->relocation);
|
if(collecting_accumulation_gen_p())
|
||||||
|
compiled->last_scan = collecting_gen;
|
||||||
|
else
|
||||||
|
compiled->last_scan = collecting_gen + 1;
|
||||||
|
|
||||||
for(scan = literals_start; scan < literal_end; scan += CELLS)
|
for(scan = literals_start; scan < literal_end; scan += CELLS)
|
||||||
copy_handle((CELL*)scan);
|
copy_handle((CELL*)scan);
|
||||||
|
|
||||||
|
if(compiled->relocation != F)
|
||||||
|
{
|
||||||
|
copy_handle(&compiled->relocation);
|
||||||
|
|
||||||
|
F_BYTE_ARRAY *relocation = untag_object(compiled->relocation);
|
||||||
|
|
||||||
|
F_REL *rel = (F_REL *)(relocation + 1);
|
||||||
|
F_REL *rel_end = (F_REL *)((char *)rel + byte_array_capacity(relocation));
|
||||||
|
|
||||||
|
while(rel < rel_end)
|
||||||
|
{
|
||||||
|
if(REL_TYPE(rel) == RT_IMMEDIATE)
|
||||||
|
{
|
||||||
|
CELL offset = rel->offset + code_start;
|
||||||
|
F_FIXNUM absolute_value = get(CREF(literals_start,REL_ARGUMENT(rel)));
|
||||||
|
apply_relocation(REL_CLASS(rel),offset,absolute_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
rel++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flush_icache(code_start,literals_start - code_start);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy literals referenced from all code blocks to newspace */
|
/* Copy literals referenced from all code blocks to newspace */
|
||||||
|
|
|
@ -7,8 +7,6 @@ void undefined_symbol(void)
|
||||||
general_error(ERROR_UNDEFINED_SYMBOL,F,F,NULL);
|
general_error(ERROR_UNDEFINED_SYMBOL,F,F,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CREF(array,i) ((CELL)(array) + CELLS * (i))
|
|
||||||
|
|
||||||
INLINE CELL get_literal(CELL literals_start, CELL num)
|
INLINE CELL get_literal(CELL literals_start, CELL num)
|
||||||
{
|
{
|
||||||
return get(CREF(literals_start,num));
|
return get(CREF(literals_start,num));
|
||||||
|
@ -283,6 +281,7 @@ F_COMPILED *add_compiled_block(
|
||||||
/* compiled header */
|
/* compiled header */
|
||||||
F_COMPILED *header = (void *)here;
|
F_COMPILED *header = (void *)here;
|
||||||
header->type = type;
|
header->type = type;
|
||||||
|
header->last_scan = NURSERY;
|
||||||
header->code_length = code_length;
|
header->code_length = code_length;
|
||||||
header->literals_length = literals_length;
|
header->literals_length = literals_length;
|
||||||
header->relocation = relocation;
|
header->relocation = relocation;
|
||||||
|
|
|
@ -57,6 +57,10 @@ typedef struct {
|
||||||
unsigned int offset;
|
unsigned int offset;
|
||||||
} F_REL;
|
} F_REL;
|
||||||
|
|
||||||
|
#define CREF(array,i) ((CELL)(array) + CELLS * (i))
|
||||||
|
|
||||||
|
void apply_relocation(CELL class, CELL offset, F_FIXNUM absolute_value);
|
||||||
|
|
||||||
void relocate_code_block(F_COMPILED *relocating, CELL code_start, CELL literals_start);
|
void relocate_code_block(F_COMPILED *relocating, CELL code_start, CELL literals_start);
|
||||||
|
|
||||||
void default_word_code(F_WORD *word, bool relocate);
|
void default_word_code(F_WORD *word, bool relocate);
|
||||||
|
|
18
vm/data_gc.c
18
vm/data_gc.c
|
@ -303,21 +303,13 @@ void primitive_end_scan(void)
|
||||||
/* Scan all the objects in the card */
|
/* Scan all the objects in the card */
|
||||||
void collect_card(F_CARD *ptr, CELL gen, CELL here)
|
void collect_card(F_CARD *ptr, CELL gen, CELL here)
|
||||||
{
|
{
|
||||||
CELL offset = CARD_OFFSET(ptr);
|
CELL card_scan = (CELL)CARD_TO_ADDR(ptr) + CARD_OFFSET(ptr);
|
||||||
|
CELL card_end = (CELL)CARD_TO_ADDR(ptr + 1);
|
||||||
|
|
||||||
if(offset != INVALID_ALLOT_MARKER)
|
while(card_scan < card_end && card_scan < here)
|
||||||
{
|
card_scan = collect_next(card_scan);
|
||||||
if(offset & TAG_MASK)
|
|
||||||
critical_error("Bad card",(CELL)ptr);
|
|
||||||
|
|
||||||
CELL card_scan = (CELL)CARD_TO_ADDR(ptr) + offset;
|
cards_scanned++;
|
||||||
CELL card_end = (CELL)CARD_TO_ADDR(ptr + 1);
|
|
||||||
|
|
||||||
while(card_scan < card_end && card_scan < here)
|
|
||||||
card_scan = collect_next(card_scan);
|
|
||||||
|
|
||||||
cards_scanned++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void collect_card_deck(F_DECK *deck, CELL gen, F_CARD mask, F_CARD unmask)
|
void collect_card_deck(F_DECK *deck, CELL gen, F_CARD mask, F_CARD unmask)
|
||||||
|
|
|
@ -104,7 +104,8 @@ typedef struct {
|
||||||
/* The compiled code heap is structured into blocks. */
|
/* The compiled code heap is structured into blocks. */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
CELL type; /* this is WORD_TYPE or QUOTATION_TYPE */
|
char type; /* this is WORD_TYPE or QUOTATION_TYPE */
|
||||||
|
char last_scan; /* the youngest generation in which this block's literals may live */
|
||||||
CELL code_length; /* # bytes */
|
CELL code_length; /* # bytes */
|
||||||
CELL literals_length; /* # bytes */
|
CELL literals_length; /* # bytes */
|
||||||
CELL relocation; /* tagged pointer to byte-array or f */
|
CELL relocation; /* tagged pointer to byte-array or f */
|
||||||
|
|
|
@ -315,7 +315,7 @@ void jit_compile(CELL quot, bool relocate)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
GROWABLE_ARRAY_ADD(literals,obj);
|
GROWABLE_ARRAY_ADD(literals,obj);
|
||||||
EMIT(userenv[immediate_p(obj) ? JIT_PUSH_IMMEDIATE : JIT_PUSH_LITERAL],literals_count - 1);
|
EMIT(userenv[JIT_PUSH_IMMEDIATE],literals_count - 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue