Attempt to merge in changes

F_FASTCALL
release
U-C4\Administrator 2007-09-27 15:10:37 -05:00
parent 07ba1de580
commit 9a0ac0e975
16 changed files with 63 additions and 65 deletions

View File

@ -361,19 +361,23 @@ cell 8 = [
[ ] [ B{ 1 2 3 4 5 } malloc-byte-array "b" set ] unit-test [ ] [ B{ 1 2 3 4 5 } malloc-byte-array "b" set ] unit-test
[ 3 ] [ "b" get 2 [ alien-unsigned-1 ] compile-1 ] unit-test "b" get [
[ 3 ] [ "b" get [ { simple-alien } declare 2 alien-unsigned-1 ] compile-1 ] unit-test [ 3 ] [ "b" get 2 [ alien-unsigned-1 ] compile-1 ] unit-test
[ 3 ] [ "b" get 2 [ { simple-alien fixnum } declare alien-unsigned-1 ] compile-1 ] unit-test [ 3 ] [ "b" get [ { simple-alien } declare 2 alien-unsigned-1 ] compile-1 ] unit-test
[ 3 ] [ "b" get 2 [ { simple-c-ptr fixnum } declare alien-unsigned-1 ] compile-1 ] unit-test [ 3 ] [ "b" get 2 [ { simple-alien fixnum } declare alien-unsigned-1 ] compile-1 ] unit-test
[ 3 ] [ "b" get 2 [ { simple-c-ptr fixnum } declare alien-unsigned-1 ] compile-1 ] unit-test
[ ] [ "b" get free ] unit-test [ ] [ "b" get free ] unit-test
] when
[ ] [ "hello world" malloc-char-string "s" set ] unit-test [ t ] [ "hello world" malloc-char-string "s" set ] unit-test
[ "hello world" ] [ "s" get <void*> [ { byte-array } declare *void* ] compile-1 alien>char-string ] unit-test "s" get [
[ "hello world" ] [ "s" get <void*> [ { simple-c-ptr } declare *void* ] compile-1 alien>char-string ] unit-test [ "hello world" ] [ "s" get <void*> [ { byte-array } declare *void* ] compile-1 alien>char-string ] unit-test
[ "hello world" ] [ "s" get <void*> [ { simple-c-ptr } declare *void* ] compile-1 alien>char-string ] unit-test
[ ] [ "s" get free ] unit-test [ ] [ "s" get free ] unit-test
] when
[ ALIEN: 1234 ] [ ALIEN: 1234 [ { simple-alien } declare <void*> ] compile-1 *void* ] unit-test [ ALIEN: 1234 ] [ ALIEN: 1234 [ { simple-alien } declare <void*> ] compile-1 *void* ] unit-test
[ ALIEN: 1234 ] [ ALIEN: 1234 [ { simple-c-ptr } declare <void*> ] compile-1 *void* ] unit-test [ ALIEN: 1234 ] [ ALIEN: 1234 [ { simple-c-ptr } declare <void*> ] compile-1 *void* ] unit-test

View File

@ -1,5 +1,5 @@
#define FACTOR_CPU_STRING "ppc" #define FACTOR_CPU_STRING "ppc"
#define FASTCALL #define F_FASTCALL
register CELL ds asm("r14"); register CELL ds asm("r14");
register CELL rs asm("r15"); register CELL rs asm("r15");

View File

@ -3,4 +3,5 @@
register CELL ds asm("esi"); register CELL ds asm("esi");
register CELL rs asm("edi"); register CELL rs asm("edi");
#define FASTCALL __attribute__ ((regparm (2))) #define F_FASTCALL __attribute__ ((regparm (2)))

View File

@ -3,4 +3,4 @@
register CELL ds asm("r14"); register CELL ds asm("r14");
register CELL rs asm("r15"); register CELL rs asm("r15");
#define FASTCALL #define F_FASTCALL

View File

@ -2,7 +2,7 @@
mov QUOT_XT_OFFSET(ARG0),XT_REG ; /* Load quot-xt */ \ mov QUOT_XT_OFFSET(ARG0),XT_REG ; /* Load quot-xt */ \
jmp *XT_REG /* Jump to quot-xt */ jmp *XT_REG /* Jump to quot-xt */
DEF(FASTCALL void,c_to_factor,(CELL quot)): DEF(F_FASTCALL void,c_to_factor,(CELL quot)):
PUSH_NONVOLATILE PUSH_NONVOLATILE
push ARG0 /* Save quot */ push ARG0 /* Save quot */
@ -17,38 +17,38 @@ DEF(FASTCALL void,c_to_factor,(CELL quot)):
POP_NONVOLATILE POP_NONVOLATILE
ret ret
DEF(FASTCALL void,undefined,(CELL word)): DEF(F_FASTCALL void,undefined,(CELL word)):
mov STACK_REG,ARG1 /* Pass callstack pointer */ mov STACK_REG,ARG1 /* Pass callstack pointer */
jmp MANGLE(undefined_error) /* This throws an error */ jmp MANGLE(undefined_error) /* This throws an error */
DEF(FASTCALL void,dosym,(CELL word)): DEF(F_FASTCALL void,dosym,(CELL word)):
add $CELL_SIZE,DS_REG /* Increment stack pointer */ add $CELL_SIZE,DS_REG /* Increment stack pointer */
mov ARG0,(DS_REG) /* Store word on stack */ mov ARG0,(DS_REG) /* Store word on stack */
ret ret
/* Here we have two entry points. The first one is taken when profiling is /* Here we have two entry points. The first one is taken when profiling is
enabled */ enabled */
DEF(FASTCALL void,docol_profiling,(CELL word)): DEF(F_FASTCALL void,docol_profiling,(CELL word)):
add $CELL_SIZE,PROFILING_OFFSET(ARG0) /* Increment profile-count slot */ add $CELL_SIZE,PROFILING_OFFSET(ARG0) /* Increment profile-count slot */
DEF(FASTCALL void,docol,(CELL word)): DEF(F_FASTCALL void,docol,(CELL word)):
mov WORD_DEF_OFFSET(ARG0),ARG0 /* Load word-def slot */ mov WORD_DEF_OFFSET(ARG0),ARG0 /* Load word-def slot */
JUMP_QUOT JUMP_QUOT
/* We must pass the XT to the quotation in ECX. */ /* We must pass the XT to the quotation in ECX. */
DEF(FASTCALL void,primitive_call,(void)): DEF(F_FASTCALL void,primitive_call,(void)):
mov (DS_REG),ARG0 /* Load quotation from data stack */ mov (DS_REG),ARG0 /* Load quotation from data stack */
sub $CELL_SIZE,DS_REG /* Pop data stack */ sub $CELL_SIZE,DS_REG /* Pop data stack */
JUMP_QUOT JUMP_QUOT
/* We pass the word in EAX and the XT in ECX. Don't mess up EDX, it's the /* We pass the word in EAX and the XT in ECX. Don't mess up EDX, it's the
callstack top parameter to primitives. */ callstack top parameter to primitives. */
DEF(FASTCALL void,primitive_execute,(void)): DEF(F_FASTCALL void,primitive_execute,(void)):
mov (DS_REG),ARG0 /* Load word from data stack */ mov (DS_REG),ARG0 /* Load word from data stack */
sub $CELL_SIZE,DS_REG /* Pop data stack */ sub $CELL_SIZE,DS_REG /* Pop data stack */
mov WORD_XT_OFFSET(ARG0),XT_REG /* Load word-xt slot */ mov WORD_XT_OFFSET(ARG0),XT_REG /* Load word-xt slot */
jmp *XT_REG /* Go */ jmp *XT_REG /* Go */
DEF(FASTCALL void,throw_impl,(CELL quot, F_STACK_FRAME *rewind_to)): DEF(F_FASTCALL void,throw_impl,(CELL quot, F_STACK_FRAME *rewind_to)):
mov ARG1,STACK_REG /* rewind_to */ mov ARG1,STACK_REG /* rewind_to */
JUMP_QUOT JUMP_QUOT

View File

@ -22,12 +22,12 @@ typedef struct _F_STACK_FRAME
INLINE void flush_icache(CELL start, CELL len) {} INLINE void flush_icache(CELL start, CELL len) {}
FASTCALL void c_to_factor(CELL quot); F_FASTCALL void c_to_factor(CELL quot);
FASTCALL void throw_impl(CELL quot, F_STACK_FRAME *rewind_to); F_FASTCALL void throw_impl(CELL quot, F_STACK_FRAME *rewind_to);
FASTCALL void undefined(CELL word); F_FASTCALL void undefined(CELL word);
FASTCALL void dosym(CELL word); F_FASTCALL void dosym(CELL word);
FASTCALL void docol_profiling(CELL word); F_FASTCALL void docol_profiling(CELL word);
FASTCALL void docol(CELL word); F_FASTCALL void docol(CELL word);
FASTCALL void lazy_jit_compile(CELL quot); F_FASTCALL void lazy_jit_compile(CELL quot);
void set_callstack(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy); void set_callstack(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy);

View File

@ -34,7 +34,7 @@ bool jit_stack_frame_p(F_ARRAY *array)
return false; return false;
} }
FASTCALL CELL jit_compile(CELL tagged, F_STACK_FRAME *stack) F_FASTCALL CELL jit_compile(CELL tagged, F_STACK_FRAME *stack)
{ {
stack_chain->callstack_top = stack; stack_chain->callstack_top = stack;

View File

@ -1,2 +1,2 @@
DLLEXPORT FASTCALL CELL jit_compile(CELL tagged, F_STACK_FRAME *stack); DLLEXPORT F_FASTCALL CELL jit_compile(CELL tagged, F_STACK_FRAME *stack);
XT quot_offset_to_pc(F_QUOTATION *quot, F_FIXNUM offset); XT quot_offset_to_pc(F_QUOTATION *quot, F_FIXNUM offset);

View File

@ -179,11 +179,6 @@ INLINE F_STACK_FRAME *uap_stack_pointer(void *uap)
return NULL; return NULL;
} }
void memory_signal_handler_impl(void)
{
memory_protection_error(signal_fault_addr,signal_callstack_top);
}
void memory_signal_handler(int signal, siginfo_t *siginfo, void *uap) void memory_signal_handler(int signal, siginfo_t *siginfo, void *uap)
{ {
signal_fault_addr = (CELL)siginfo->si_addr; signal_fault_addr = (CELL)siginfo->si_addr;
@ -191,11 +186,6 @@ void memory_signal_handler(int signal, siginfo_t *siginfo, void *uap)
UAP_PROGRAM_COUNTER(uap) = (CELL)memory_signal_handler_impl; UAP_PROGRAM_COUNTER(uap) = (CELL)memory_signal_handler_impl;
} }
void misc_signal_handler_impl(void)
{
signal_error(signal_number,signal_callstack_top);
}
void misc_signal_handler(int signal, siginfo_t *siginfo, void *uap) void misc_signal_handler(int signal, siginfo_t *siginfo, void *uap)
{ {
signal_number = signal; signal_number = signal;

View File

@ -27,10 +27,11 @@ long exception_handler(PEXCEPTION_POINTERS pe)
{ {
PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)pe->ExceptionRecord; PEXCEPTION_RECORD e = (PEXCEPTION_RECORD)pe->ExceptionRecord;
CONTEXT *c = (CONTEXT*)pe->ContextRecord; CONTEXT *c = (CONTEXT*)pe->ContextRecord;
void *signal_callstack_top = NULL;
if(in_code_heap_p(c->Eip)) if(in_code_heap_p(c->Eip))
signal_callstack_top = (void*)c->Esp; signal_callstack_top = (void*)c->Esp;
else
signal_callstack_top = NULL;
if(e->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) if(e->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
{ {
@ -58,18 +59,3 @@ void c_to_factor_toplevel(CELL quot)
c_to_factor(quot); c_to_factor(quot);
RemoveVectoredExceptionHandler((void*)exception_handler); RemoveVectoredExceptionHandler((void*)exception_handler);
} }
void memory_signal_handler_impl(void)
{
memory_protection_error(signal_fault_addr,signal_callstack_top);
}
void divide_by_zero_signal_handler_impl(void)
{
general_error(ERROR_DIVIDE_BY_ZERO,F,F,signal_callstack_top);
}
void misc_signal_handler_impl(void)
{
signal_error(signal_number,signal_callstack_top);
}

View File

@ -14,6 +14,8 @@ typedef char F_SYMBOL;
#define FACTOR_DLL L"factor-nt.dll" #define FACTOR_DLL L"factor-nt.dll"
#define FACTOR_DLL_NAME "factor-nt.dll" #define FACTOR_DLL_NAME "factor-nt.dll"
void c_to_factor_toplevel(CELL quot);
CELL signal_number; CELL signal_number;
CELL signal_fault_addr; CELL signal_fault_addr;
void *signal_callstack_top; void *signal_callstack_top;

View File

@ -14,19 +14,19 @@ DEFINE_PRIMITIVE(name)
Becomes Becomes
FASTCALL void primitive_name(CELL word, F_STACK_FRAME *callstack_top) F_FASTCALL void primitive_name(CELL word, F_STACK_FRAME *callstack_top)
{ {
stack_chain->callstack_top = callstack_top; stack_chain->callstack_top = callstack_top;
... CODE ... ... CODE ...
} }
On x86, FASTCALL expands into a GCC declaration which forces the two parameters On x86, F_FASTCALL expands into a GCC declaration which forces the two
to be passed in registers. This simplifies the quotation compiler and support parameters to be passed in registers. This simplifies the quotation compiler
code in cpu-x86.S. */ and support code in cpu-x86.S. */
#define DEFINE_PRIMITIVE(name) \ #define DEFINE_PRIMITIVE(name) \
INLINE void primitive_##name##_impl(void); \ INLINE void primitive_##name##_impl(void); \
\ \
FASTCALL void primitive_##name(CELL word, F_STACK_FRAME *callstack_top) \ F_FASTCALL void primitive_##name(CELL word, F_STACK_FRAME *callstack_top) \
{ \ { \
stack_chain->callstack_top = callstack_top; \ stack_chain->callstack_top = callstack_top; \
primitive_##name##_impl(); \ primitive_##name##_impl(); \
@ -36,4 +36,4 @@ code in cpu-x86.S. */
/* Prototype for header files */ /* Prototype for header files */
#define DECLARE_PRIMITIVE(name) \ #define DECLARE_PRIMITIVE(name) \
FASTCALL void primitive_##name(CELL word, F_STACK_FRAME *callstack_top) F_FASTCALL void primitive_##name(CELL word, F_STACK_FRAME *callstack_top)

View File

@ -197,7 +197,7 @@ void not_implemented_error(void)
} }
/* This function is called from the undefined function in cpu_*.S */ /* This function is called from the undefined function in cpu_*.S */
FASTCALL void undefined_error(CELL word, F_STACK_FRAME *callstack_top) F_FASTCALL void undefined_error(CELL word, F_STACK_FRAME *callstack_top)
{ {
stack_chain->callstack_top = callstack_top; stack_chain->callstack_top = callstack_top;
general_error(ERROR_UNDEFINED_WORD,word,F,NULL); general_error(ERROR_UNDEFINED_WORD,word,F,NULL);
@ -244,6 +244,21 @@ void divide_by_zero_error(F_STACK_FRAME *native_stack)
general_error(ERROR_DIVIDE_BY_ZERO,F,F,native_stack); general_error(ERROR_DIVIDE_BY_ZERO,F,F,native_stack);
} }
void memory_signal_handler_impl(void)
{
memory_protection_error(signal_fault_addr,signal_callstack_top);
}
void divide_by_zero_signal_handler_impl(void)
{
divide_by_zero_error(signal_callstack_top);
}
void misc_signal_handler_impl(void)
{
signal_error(signal_number,signal_callstack_top);
}
DEFINE_PRIMITIVE(throw) DEFINE_PRIMITIVE(throw)
{ {
uncurry(dpop()); uncurry(dpop());

View File

@ -197,7 +197,7 @@ void signal_error(int signal, F_STACK_FRAME *native_stack);
void type_error(CELL type, CELL tagged); void type_error(CELL type, CELL tagged);
void not_implemented_error(void); void not_implemented_error(void);
FASTCALL void undefined_error(CELL word, F_STACK_FRAME *callstack_top); F_FASTCALL void undefined_error(CELL word, F_STACK_FRAME *callstack_top);
DECLARE_PRIMITIVE(throw); DECLARE_PRIMITIVE(throw);

View File

@ -19,7 +19,7 @@ void fix_stacks(void)
} }
/* called before entry into Factor code. */ /* called before entry into Factor code. */
FASTCALL void save_callstack_bottom(F_STACK_FRAME *callstack_bottom) F_FASTCALL void save_callstack_bottom(F_STACK_FRAME *callstack_bottom)
{ {
stack_chain->callstack_bottom = callstack_bottom; stack_chain->callstack_bottom = callstack_bottom;
} }

View File

@ -48,7 +48,7 @@ CELL ds_size, rs_size;
void reset_datastack(void); void reset_datastack(void);
void reset_retainstack(void); void reset_retainstack(void);
void fix_stacks(void); void fix_stacks(void);
FASTCALL void save_callstack_bottom(F_STACK_FRAME *callstack_bottom); F_FASTCALL void save_callstack_bottom(F_STACK_FRAME *callstack_bottom);
DLLEXPORT void save_stacks(void); DLLEXPORT void save_stacks(void);
DLLEXPORT void nest_stacks(void); DLLEXPORT void nest_stacks(void);
DLLEXPORT void unnest_stacks(void); DLLEXPORT void unnest_stacks(void);