From 285caff08ed9a0cd4c280132bf068f2c0d6801cb Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 28 Dec 2009 12:40:45 +1300 Subject: [PATCH] Updating non-optimizing PowerPC backend for register variable removal (untested) --- basis/cpu/ppc/bootstrap.factor | 30 +++-- vm/cpu-ppc.S | 193 +++++++++++++++++++++------------ 2 files changed, 145 insertions(+), 78 deletions(-) diff --git a/basis/cpu/ppc/bootstrap.factor b/basis/cpu/ppc/bootstrap.factor index 40fa5c4b78..fc525b7f4e 100644 --- a/basis/cpu/ppc/bootstrap.factor +++ b/basis/cpu/ppc/bootstrap.factor @@ -12,6 +12,7 @@ big-endian on CONSTANT: ds-reg 13 CONSTANT: rs-reg 14 +CONSTANT: vm-reg 15 : factor-area-size ( -- n ) 4 bootstrap-cells ; @@ -25,9 +26,15 @@ CONSTANT: rs-reg 14 [ '[ bootstrap-cell /i 1 + @ ] ] dip jit-conditional ; inline : jit-save-context ( -- ) - 0 3 LOAD32 rc-absolute-ppc-2/2 rt-context jit-rel - 4 3 0 LWZ - 1 4 0 STW ; + 4 vm-reg 0 LWZ + 1 4 0 STW + ds-reg vm-reg 8 STW + rs-reg vm-reg 12 STW ; + +: jit-load-context ( -- ) + 4 vm-reg 0 LWZ + ds-reg vm-reg 8 LWZ + rs-reg vm-reg 12 LWZ ; [ 0 3 LOAD32 rc-absolute-ppc-2/2 rt-literal jit-rel @@ -57,10 +64,11 @@ CONSTANT: rs-reg 14 [ jit-save-context - 0 3 LOAD32 rc-absolute-ppc-2/2 rt-vm jit-rel + 3 vm-reg MR 0 4 LOAD32 rc-absolute-ppc-2/2 rt-primitive jit-rel 4 MTLR BLRL + jit-load-context ] jit-primitive jit-define [ 0 BL rc-relative-ppc-3 rt-xt-pic jit-rel ] jit-word-call jit-define @@ -235,7 +243,7 @@ CONSTANT: rs-reg 14 [ 3 ds-reg 0 LWZ ds-reg dup 4 SUBI - 0 4 LOAD32 0 rc-absolute-ppc-2/2 jit-vm + 4 vm-reg MR 5 3 quot-xt-offset LWZ ] [ 5 MTLR BLRL ] @@ -502,7 +510,7 @@ CONSTANT: rs-reg 14 : jit-inline-cache-miss ( -- ) jit-save-context 3 6 MR - 0 4 LOAD32 0 rc-absolute-ppc-2/2 jit-vm + 4 vm-reg MR 0 5 LOAD32 "inline_cache_miss" f rc-absolute-ppc-2/2 jit-dlsym 5 MTLR BLRL ; @@ -529,10 +537,10 @@ CONSTANT: rs-reg 14 6 ds-reg 0 STW [ BNO ] [ - 0 5 LOAD32 0 rc-absolute-ppc-2/2 jit-vm - 0 6 LOAD32 func f rc-absolute-ppc-2/2 jit-dlsym - 6 MTLR - BLRL + 5 vm-reg MR + 0 6 LOAD32 func f rc-absolute-ppc-2/2 jit-dlsym + 6 MTLR + BLRL ] jit-conditional* ; @@ -553,7 +561,7 @@ CONSTANT: rs-reg 14 [ BNO ] [ 4 4 tag-bits get SRAWI - 0 5 LOAD32 0 rc-absolute-ppc-2/2 jit-vm + 5 vm-reg MR 0 6 LOAD32 "overflow_fixnum_multiply" f rc-absolute-ppc-2/2 jit-dlsym 6 MTLR BLRL diff --git a/vm/cpu-ppc.S b/vm/cpu-ppc.S index 9517154e1a..ba3b5a55d3 100644 --- a/vm/cpu-ppc.S +++ b/vm/cpu-ppc.S @@ -3,6 +3,8 @@ in the public domain. */ #include "asm.h" #define DS_REG r13 +#define RS_REG r14 +#define VM_REG r15 #define CALL_OR_JUMP_QUOT \ lwz r11,12(r3) /* load quotation-xt slot */ XX \ @@ -70,25 +72,27 @@ the Factor compiler treats the entire register file as volatile. */ DEF(void,c_to_factor,(cell quot, void *vm)): PROLOGUE - SAVE_INT(r15,0) /* save GPRs */ - SAVE_INT(r16,1) - SAVE_INT(r17,2) - SAVE_INT(r18,3) - SAVE_INT(r19,4) - SAVE_INT(r20,5) - SAVE_INT(r21,6) - SAVE_INT(r22,7) - SAVE_INT(r23,8) - SAVE_INT(r24,9) - SAVE_INT(r25,10) - SAVE_INT(r26,11) - SAVE_INT(r27,12) - SAVE_INT(r28,13) - SAVE_INT(r29,14) - SAVE_INT(r30,15) - SAVE_INT(r31,16) + SAVE_INT(r13,0) + SAVE_INT(r14,1) + SAVE_INT(VM_REG,2) + SAVE_INT(r16,3) + SAVE_INT(r17,4) + SAVE_INT(r18,5) + SAVE_INT(r19,6) + SAVE_INT(r20,7) + SAVE_INT(r21,8) + SAVE_INT(r22,9) + SAVE_INT(r23,10) + SAVE_INT(r24,11) + SAVE_INT(r25,12) + SAVE_INT(r26,13) + SAVE_INT(r27,14) + SAVE_INT(r28,15) + SAVE_INT(r29,16) + SAVE_INT(r30,17) + SAVE_INT(r31,18) - SAVE_FP(f14,20) /* save FPRs */ + SAVE_FP(f14,20) SAVE_FP(f15,22) SAVE_FP(f16,24) SAVE_FP(f17,26) @@ -133,19 +137,31 @@ DEF(void,c_to_factor,(cell quot, void *vm)): lvxl v0,r2,r1 mtvscr v0 - /* save args in non-volatile regs */ - mr r15,r3 - mr r16,r4 - /* pass call stack pointer as an argument */ - mr r3,r1 - bl MANGLE(save_callstack_bottom) + /* Load context */ + mr VM_REG,r4 + lwz r16,0(VM_REG) + + /* Load ctx->datastack */ + lwz DS_REG,8(r16) + + /* Load ctx->retainstack */ + lwz RS_REG,12(r16) + + /* Save ctx->callstack_bottom */ + stw r1,4(r16) - /* restore quotation args */ - mr r3,r15 - mr r4,r16 CALL_QUOT + /* Load context */ + lwz r16,0(VM_REG) + + /* Save ctx->datastack */ + stw DS_REG,8(r16) + + /* Save ctx->retainstack */ + stw RS_REG,12(r16) + RESTORE_V(v0,104) mtvscr v0 @@ -162,7 +178,6 @@ DEF(void,c_to_factor,(cell quot, void *vm)): RESTORE_V(v21,60) RESTORE_V(v20,56) - /* Restore FPRs */ RESTORE_FP(f31,54) RESTORE_FP(f30,52) RESTORE_FP(f29,50) @@ -182,56 +197,100 @@ DEF(void,c_to_factor,(cell quot, void *vm)): RESTORE_FP(f15,22) RESTORE_FP(f14,20) - /* restore GPRs */ - RESTORE_INT(r31,16) - RESTORE_INT(r30,15) - RESTORE_INT(r29,14) - RESTORE_INT(r28,13) - RESTORE_INT(r27,12) - RESTORE_INT(r26,11) - RESTORE_INT(r25,10) - RESTORE_INT(r24,9) - RESTORE_INT(r23,8) - RESTORE_INT(r22,7) - RESTORE_INT(r21,6) - RESTORE_INT(r20,5) - RESTORE_INT(r19,4) - RESTORE_INT(r18,3) - RESTORE_INT(r17,2) - RESTORE_INT(r16,1) - RESTORE_INT(r15,0) + RESTORE_INT(r31,18) + RESTORE_INT(r30,17) + RESTORE_INT(r29,16) + RESTORE_INT(r28,15) + RESTORE_INT(r27,14) + RESTORE_INT(r26,13) + RESTORE_INT(r25,12) + RESTORE_INT(r24,11) + RESTORE_INT(r23,10) + RESTORE_INT(r22,9) + RESTORE_INT(r21,8) + RESTORE_INT(r20,7) + RESTORE_INT(r19,6) + RESTORE_INT(r18,5) + RESTORE_INT(r17,4) + RESTORE_INT(r16,3) + RESTORE_INT(VM_REG,2) + RESTORE_INT(r14,1) + RESTORE_INT(r13,0) EPILOGUE blr -/* We pass a function pointer to memcpy in r6 to work around a Mac OS X ABI -limitation which would otherwise require us to do a bizzaro PC-relative -trampoline to retrieve the function address */ -DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, cell length, void *memcpy)): - sub r1,r3,r5 /* compute new stack pointer */ - mr r3,r1 /* start of destination of memcpy() */ - stwu r1,-64(r1) /* setup fake stack frame for memcpy() */ - mtlr r6 /* prepare to call memcpy() */ - blrl /* go */ - lwz r1,0(r1) /* tear down fake stack frame */ - lwz r0,LR_SAVE(r1) /* we have restored the stack; load return address */ - mtlr r0 /* prepare to return to restored callstack */ - blr /* go */ +DEF(void,set_callstack,(void *vm, stack_frame *to, stack_frame *from, cell length, void *memcpy)): + /* Compute new stack pointer */ + sub r1,r4,r6 -DEF(void,throw_impl,(cell quot, F_STACK_FRAME *rewind_to, void *vm)): - mr r1,r4 /* compute new stack pointer */ - mr r4,r5 /* make vm ptr 2nd arg in case quot_xt = lazy_jit_compile */ - lwz r0,LR_SAVE(r1) /* we have rewound the stack; load return address */ + /* Call memcpy() */ + mr r4,r1 + stwu r1,-64(r1) + mtlr r7 + blrl + lwz r1,0(r1) + + /* Load context */ + mr VM_REG,r3 + lwz r16,0(VM_REG) + + /* Load ctx->datastack */ + lwz DS_REG,8(r16) + + /* Load ctx->retainstack */ + lwz RS_REG,12(r16) + + /* We have changed the stack; load return address again */ + lwz r0,LR_SAVE(r1) mtlr r0 - JUMP_QUOT /* call the quotation */ + blr + +DEF(void,throw_impl,(cell quot, void *new_stack, void *vm)): + /* compute new stack pointer */ + mr r1,r4 + + /* make vm ptr 2nd arg in case quot->xt == lazy_jit_compile */ + mr r4,r5 + + /* Load context */ + mr VM_REG,r5 + lwz r16,0(VM_REG) + + /* Load ctx->datastack */ + lwz DS_REG,8(r16) + + /* Load ctx->retainstack */ + lwz RS_REG,12(r16) + + /* We have changed the stack; load return address again */ + lwz r0,LR_SAVE(r1) + mtlr r0 + + /* Call the quotation */ + JUMP_QUOT DEF(void,lazy_jit_compile_impl,(cell quot, void *vm)): - mr r5,r4 /* vm ptr is 3rd arg */ - mr r4,r1 /* save stack pointer */ + /* Load context */ + mr VM_REG,r4 + lwz r16,0(VM_REG) + + /* Save ctx->datastack */ + stw DS_REG,8(r16) + + /* Save ctx->retainstack */ + stw RS_REG,12(r16) + + /* Save ctx->callstack_top */ + stw r1,0(r16) + + /* Compile quotation */ PROLOGUE bl MANGLE(lazy_jit_compile) EPILOGUE - JUMP_QUOT /* call the quotation */ + + /* Call the quotation */ + JUMP_QUOT /* Thanks to Joshua Grams for this code.