# HG changeset patch # User Merten Sach # Date 1307377800 -7200 # Node ID f36e9ab2e0302d0e64569d21d6640d63032acb3d # Parent cfd2f7e54129e0b405ca5929ca0328a7537ec8ff separated asm singleton routines diff -r cfd2f7e54129 -r f36e9ab2e030 VPThread.s --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VPThread.s Mon Jun 06 18:30:00 2011 +0200 @@ -0,0 +1,23 @@ + +//Assembly code takes the return addr off the stack and saves +// into the singleton. The first field in the singleton is the +// "endInstrAddr" field, and the return addr is at 0x4(%ebp) +.globl asm_save_ret_to_singleton +asm_save_ret_to_singleton: + movl 0x4(%ebp), %eax #get ret address, ebp is the same as in the calling function + movl 0x4(%esp), %edx #get argument(singletonPtrAddr) from stack + movl %eax, (%edx) #write ret addr to endInstrAddr field + ret + + +//Assembly code changes the return addr on the stack to the one +// saved into the singleton by the end-singleton-fn +//The stack's return addr is at 0x4(%%ebp) +.globl asm_write_ret_from_singleton +asm_write_ret_from_singleton: + movl 0x4(%esp), %edx #get singleton addr from stack + movl (%edx), %eax #get endInstrAddr field + movl %eax, 0x4(%ebp) #write return addr to the stack of the caller + ret + + diff -r cfd2f7e54129 -r f36e9ab2e030 VPThread_lib.c --- a/VPThread_lib.c Thu Jun 02 14:47:50 2011 +0200 +++ b/VPThread_lib.c Mon Jun 06 18:30:00 2011 +0200 @@ -459,6 +459,10 @@ * trying to get the data through from different cores. */ +/*asm function declarations*/ +void asm_save_ret_to_singleton(VPThdSingleton **singletonPtrAddr); +void asm_write_ret_from_singleton(VPThdSingleton **singletonPtrAddr); + /*Fn singleton uses ID as index into array of singleton structs held in the * semantic environment. */ @@ -474,12 +478,8 @@ VMS__send_sem_request( &reqData, animPr ); if( animPr->dataRetFromReq ) //will be 0 or addr of label in end singleton { - asm volatile("movl %0, %%eax; \ - jmp *%%eax" \ - /* outputs */ : \ - /* inputs */ : "g"(animPr->dataRetFromReq) \ - /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx","%edi","%esi"\ - ); + VPThdSemEnv *semEnv = VMS__give_sem_env_for( animPr ); + asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); } } @@ -494,24 +494,16 @@ if( *singletonAddr && (*singletonAddr)->hasFinished ) goto JmpToEndSingleton; - // + reqData.reqType = singleton_data_start; reqData.singletonPtrAddr = singletonAddr; VMS__send_sem_request( &reqData, animPr ); if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr - { //Assembly code changes the return addr on the stack to the one - // saved into the singleton by the end-singleton-fn - //The stack's return addr is at 0x4(%%ebp) - JmpToEndSingleton: - asm volatile("movl %0, %%eax; \ - movl (%%eax), %%ebx; \ - movl (%%ebx), %%eax; \ - movl %%eax, 0x4(%%ebp);" \ - /* outputs */ : \ - /* inputs */ : "m"(singletonAddr) \ - /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx","%edi","%esi"\ - ); + { + JmpToEndSingleton: + asm_write_ret_from_singleton(*singletonAddr); + } //now, simply return //will exit either from the start singleton call or the end-singleton call @@ -528,18 +520,15 @@ { VPThdSemReq reqData; - //don't need this addr until after at least one singleton has reached - // this function + //don't need this addr until after at least one singleton has reached + // this function VPThdSemEnv *semEnv = VMS__give_sem_env_for( animPr ); - semEnv->fnSingletons[ singletonID].endInstrAddr = &&EndSingletonInstrAddr; + asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); reqData.reqType = singleton_fn_end; reqData.singletonID = singletonID; VMS__send_sem_request( &reqData, animPr ); - -EndSingletonInstrAddr: - return; } void @@ -553,19 +542,8 @@ // data singleton -- that data-singleton can only be given to exactly // one instance in the code of this function. However, can use this // function in different places for different data-singletons. -// (*(singletonAddr))->endInstrAddr = &&EndDataSingletonInstrAddr; - //Assembly code takes the return addr off the stack and saves - // into the singleton. The first field in the singleton is the - // "endInstrAddr" field, and the return addr is at 0x4(%%ebp) - asm volatile("movl 0x4(%%ebp), %%eax; \ - movl %0, %%ebx; \ - movl (%%ebx), %%ecx; \ - movl %%eax, (%%ecx);" \ - /* outputs */ : \ - /* inputs */ : "m"(singletonPtrAddr) \ - /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx","%edi","%esi"\ - ); + asm_save_ret_to_singleton(*singletonPtrAddr); reqData.reqType = singleton_data_end; reqData.singletonPtrAddr = singletonPtrAddr;