Experimental optimizations

db4
Slava Pestov 2008-11-24 06:40:51 -06:00
parent 9490207615
commit 2aaf860f47
9 changed files with 54 additions and 27 deletions

View File

@ -69,6 +69,9 @@ SYMBOL: literal-table
: rel-literal ( literal class -- )
>r add-literal r> rt-literal rel-fixup ;
: rel-immediate ( literal class -- )
>r add-literal r> rt-immediate rel-fixup ;
: rel-this ( class -- )
0 swap rt-label rel-fixup ;

View File

@ -13,7 +13,6 @@ big-endian off
[
! Load word
temp-reg 0 MOV
temp-reg dup [] MOV
! Bump profiling counter
temp-reg profile-count-offset [+] 1 tag-fixnum ADD
! Load word->code
@ -22,7 +21,7 @@ big-endian off
temp-reg compiled-header-size ADD
! Jump to XT
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
@ -65,14 +64,13 @@ big-endian off
[
arg1 0 MOV ! load dispatch table
arg1 dup [] MOV
arg0 ds-reg [] MOV ! load index
fixnum>slot@ ! turn it into an array offset
ds-reg bootstrap-cell SUB ! pop index
arg0 arg1 ADD ! compute quotation location
arg0 arg0 array-start-offset [+] MOV ! load quotation
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 ( -- )
rs-reg bootstrap-cell ADD

View File

@ -18,7 +18,7 @@ M: x86 %load-immediate MOV ;
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: rs-reg cpu ( -- reg )

View File

@ -259,13 +259,43 @@ void iterate_code_heap(CODE_HEAP_ITERATOR iter)
/* Copy all literals referenced from a code block to newspace */
void collect_literals_step(F_COMPILED *compiled, CELL code_start, CELL literals_start)
{
CELL scan;
CELL literal_end = literals_start + compiled->literals_length;
if(collecting_gen >= compiled->last_scan)
{
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)
copy_handle((CELL*)scan);
for(scan = literals_start; scan < literal_end; scan += CELLS)
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 */

View File

@ -7,8 +7,6 @@ void undefined_symbol(void)
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)
{
return get(CREF(literals_start,num));
@ -283,6 +281,7 @@ F_COMPILED *add_compiled_block(
/* compiled header */
F_COMPILED *header = (void *)here;
header->type = type;
header->last_scan = NURSERY;
header->code_length = code_length;
header->literals_length = literals_length;
header->relocation = relocation;

View File

@ -57,6 +57,10 @@ typedef struct {
unsigned int offset;
} 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 default_word_code(F_WORD *word, bool relocate);

View File

@ -303,21 +303,13 @@ void primitive_end_scan(void)
/* Scan all the objects in the card */
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)
{
if(offset & TAG_MASK)
critical_error("Bad card",(CELL)ptr);
while(card_scan < card_end && card_scan < here)
card_scan = collect_next(card_scan);
CELL card_scan = (CELL)CARD_TO_ADDR(ptr) + offset;
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++;
}
cards_scanned++;
}
void collect_card_deck(F_DECK *deck, CELL gen, F_CARD mask, F_CARD unmask)

View File

@ -104,7 +104,8 @@ typedef struct {
/* The compiled code heap is structured into blocks. */
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 literals_length; /* # bytes */
CELL relocation; /* tagged pointer to byte-array or f */

View File

@ -315,7 +315,7 @@ void jit_compile(CELL quot, bool relocate)
}
default:
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;
}
}