changeset 5:f36e9ab2e030

separated asm singleton routines
author Merten Sach <msach@mailbox.tu-berlin.de>
date Mon, 06 Jun 2011 18:30:00 +0200
parents cfd2f7e54129
children ce4ad44fcc23
files VPThread.s VPThread_lib.c
diffstat 2 files changed, 38 insertions(+), 37 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/VPThread.s	Mon Jun 06 18:30:00 2011 +0200
     1.3 @@ -0,0 +1,23 @@
     1.4 +
     1.5 +//Assembly code takes the return addr off the stack and saves
     1.6 +// into the singleton.  The first field in the singleton is the
     1.7 +// "endInstrAddr" field, and the return addr is at 0x4(%ebp)
     1.8 +.globl asm_save_ret_to_singleton
     1.9 +asm_save_ret_to_singleton:
    1.10 +    movl 0x4(%ebp),     %eax   #get ret address, ebp is the same as in the calling function
    1.11 +    movl 0x4(%esp),     %edx   #get argument(singletonPtrAddr) from stack
    1.12 +    movl      %eax,     (%edx) #write ret addr to endInstrAddr field
    1.13 +    ret
    1.14 +
    1.15 +
    1.16 +//Assembly code changes the return addr on the stack to the one
    1.17 +// saved into the singleton by the end-singleton-fn
    1.18 +//The stack's return addr is at 0x4(%%ebp)
    1.19 +.globl asm_write_ret_from_singleton
    1.20 +asm_write_ret_from_singleton:
    1.21 +    movl 0x4(%esp),    %edx  #get singleton addr from stack
    1.22 +    movl    (%edx),    %eax  #get endInstrAddr field
    1.23 +    movl      %eax,    0x4(%ebp) #write return addr to the stack of the caller
    1.24 +    ret
    1.25 +
    1.26 +
     2.1 --- a/VPThread_lib.c	Thu Jun 02 14:47:50 2011 +0200
     2.2 +++ b/VPThread_lib.c	Mon Jun 06 18:30:00 2011 +0200
     2.3 @@ -459,6 +459,10 @@
     2.4   * trying to get the data through from different cores.
     2.5   */
     2.6  
     2.7 +/*asm function declarations*/
     2.8 +void asm_save_ret_to_singleton(VPThdSingleton **singletonPtrAddr);
     2.9 +void asm_write_ret_from_singleton(VPThdSingleton **singletonPtrAddr);
    2.10 +
    2.11  /*Fn singleton uses ID as index into array of singleton structs held in the
    2.12   * semantic environment.
    2.13   */
    2.14 @@ -474,12 +478,8 @@
    2.15     VMS__send_sem_request( &reqData, animPr );
    2.16     if( animPr->dataRetFromReq ) //will be 0 or addr of label in end singleton
    2.17      {
    2.18 -      asm volatile("movl         %0,      %%eax;  \
    2.19 -                    jmp                  *%%eax"  \
    2.20 -      /* outputs */ :                             \
    2.21 -      /* inputs  */ : "g"(animPr->dataRetFromReq) \
    2.22 -      /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx","%edi","%esi"\
    2.23 -                   );
    2.24 +       VPThdSemEnv *semEnv = VMS__give_sem_env_for( animPr );
    2.25 +       asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
    2.26      }
    2.27   }
    2.28  
    2.29 @@ -494,24 +494,16 @@
    2.30  
    2.31     if( *singletonAddr && (*singletonAddr)->hasFinished )
    2.32        goto JmpToEndSingleton;
    2.33 -      //
    2.34 +      
    2.35     reqData.reqType       = singleton_data_start;
    2.36     reqData.singletonPtrAddr = singletonAddr;
    2.37  
    2.38     VMS__send_sem_request( &reqData, animPr );
    2.39     if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr
    2.40 -    {    //Assembly code changes the return addr on the stack to the one
    2.41 -         // saved into the singleton by the end-singleton-fn
    2.42 -         //The stack's return addr is at 0x4(%%ebp)
    2.43 -      JmpToEndSingleton:
    2.44 -      asm volatile("movl        %0,      %%eax;   \
    2.45 -                    movl    (%%eax),     %%ebx;   \
    2.46 -                    movl    (%%ebx),     %%eax;   \
    2.47 -                    movl     %%eax,  0x4(%%ebp);" \
    2.48 -      /* outputs */ :                             \
    2.49 -      /* inputs  */ : "m"(singletonAddr) \
    2.50 -      /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx","%edi","%esi"\
    2.51 -                   );
    2.52 +    {    
    2.53 +       JmpToEndSingleton:
    2.54 +       asm_write_ret_from_singleton(*singletonAddr);
    2.55 +
    2.56      }
    2.57     //now, simply return
    2.58     //will exit either from the start singleton call or the end-singleton call
    2.59 @@ -528,18 +520,15 @@
    2.60   {
    2.61     VPThdSemReq  reqData;
    2.62  
    2.63 -      //don't need this addr until after at least one singleton has reached
    2.64 -      // this function
    2.65 +   //don't need this addr until after at least one singleton has reached
    2.66 +   // this function
    2.67     VPThdSemEnv *semEnv = VMS__give_sem_env_for( animPr );
    2.68 -   semEnv->fnSingletons[ singletonID].endInstrAddr = &&EndSingletonInstrAddr;
    2.69 +   asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
    2.70  
    2.71     reqData.reqType     = singleton_fn_end;
    2.72     reqData.singletonID = singletonID;
    2.73  
    2.74     VMS__send_sem_request( &reqData, animPr );
    2.75 -
    2.76 -EndSingletonInstrAddr:
    2.77 -   return;
    2.78   }
    2.79  
    2.80  void
    2.81 @@ -553,19 +542,8 @@
    2.82        // data singleton -- that data-singleton can only be given to exactly
    2.83        // one instance in the code of this function.  However, can use this
    2.84        // function in different places for different data-singletons.
    2.85 -//   (*(singletonAddr))->endInstrAddr =  &&EndDataSingletonInstrAddr;
    2.86  
    2.87 -         //Assembly code takes the return addr off the stack and saves
    2.88 -         // into the singleton.  The first field in the singleton is the
    2.89 -         // "endInstrAddr" field, and the return addr is at 0x4(%%ebp)
    2.90 -      asm volatile("movl 0x4(%%ebp),     %%eax;   \
    2.91 -                    movl        %0,      %%ebx;   \
    2.92 -                    movl    (%%ebx),     %%ecx;   \
    2.93 -                    movl     %%eax,     (%%ecx);" \
    2.94 -      /* outputs */ :                             \
    2.95 -      /* inputs  */ : "m"(singletonPtrAddr) \
    2.96 -      /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx","%edi","%esi"\
    2.97 -                   );
    2.98 +   asm_save_ret_to_singleton(*singletonPtrAddr);
    2.99  
   2.100     reqData.reqType          = singleton_data_end;
   2.101     reqData.singletonPtrAddr = singletonPtrAddr;