divert(-1) /************************ start of T800exec file *************************/ dnl (c)INRIA 1995 contact: syndex-support@inria.fr dnl SynDEx v4.0 include file for C on T800 Transputers dnl include(Cexec)dnl generic include file for C ifdef(`Cexec',, `errprint(`m4:'__file__:__line__: Cexec must be included first')') /******************** Synchronizers ********************/ ifelse(` dnl compact version not yet tested: dnl typedef struct context dnl { char *buf; /*-3:0 address of communication buffer */ dnl context *next; /*-2:1 address of next context of same priority */ dnl void (*iptr)(); /*-1:2 address of pending instruction when sleeping */ dnl int wksp; /* 0:3 workspace base, word used as input buffer */ dnl Channel pre; /* 1:4 channel for synchronization with pre_ */ dnl Channel suc; /* 2:5 channel for synchronization with suc_ */ dnl } context; def(`semaphores_', `void *sem[6*$1]; void initSems(void){int i=$1; while(i--){sem[6*i+2]=semFunc; __asm{ld &sem[6*i+3]; runp;}} return; semFunc: __asm{mint; stl 1; mint; stl 2; /* initialize sync channels */ semL: ldlp 0; ldlp 1; ldc 1; in; ldlp 0; ldlp 2; ldc 1; in; j semL; } }') define(`pre_', `__asm{ldlp 0; ld &sem[6*$1+4]; ldc 1; out;}') define(`suc_', `__asm{ldlp 0; ld &sem[6*$1+5]; ldc 1; out;}') def(`Pre0_', `pre_($@)') def(`Suc0_', `suc_($@)') def(`Pre1_', `pre_($@)') def(`Suc1_', `suc_($@)') ') dnl semaphores_(n) Pre0_(i) Suc0_(i) Pre1_(i) Suc1_(i) def(`semaphores_', ` /* Communication sequences context template: */ typedef struct{void *addr, *next, (*iptr)(); int wksp;} com_context_; /* Synchronization semaphores context array: */ struct{void *addr, *next, (*iptr)(); int wksp; Channel pre, suc;} sem[$1]; void semFunc(void){__asm{mint; stl 1; mint; stl 2; semL: ldlp 0; ldlp 1; ldc 1; in; ldlp 0; ldlp 2; ldc 1; in; j semL; }} void initSems(void) /* to be called at the beginning of main */ {int i=$1; while(i--){sem[i].iptr=semFunc; __asm{ld &sem[i].wksp; runp;}}}') define(`pre_', `__asm{ld &sem[$1].pre; ldc 1; out;}') define(`suc_', `__asm{ld &sem[$1].suc; ldc 1; out;}') def(`Pre0_', `pre_($@)') def(`Suc0_', `suc_($@)') def(`Pre1_', `pre_($@)') def(`Suc1_', `suc_($@)') dnl main_ini_() ; see also `semaphores_' def(`main_ini_', `void main(void){initSems();') dnl main_end_() def(`main_end_', `exit_terminate(EXIT_SUCCESS); } /* end of main */') dnl thread_(linkNumber) ; start of a communication sequence def(`thread_', ` com_context_ com$1_context_; void com$1_thread_(void){') dnl spawn_(linkNumber) ; spawn the pseudo-parallel execution of a com.seq. def(`spawn_', `dnl com$1_context_.iptr=com$1_thread_; __asm{ld &com$1_context_.wksp; runp;} ProcRunHigh(ProcAlloc(com$1_thread_,0,0));') /******************** Communications ********************/ dnl PPL_ini_(linkNumber) def(`PPL_ini_', `dnl') dnl PPL_end_(linkNumber) def(`PPL_end_', `} /* end of com$1_thread_ */') dnl $1=linkNumber, $2=arraySize, $3=arrayAddr define(`PPL_i_byte', `__asm{ld &$3; mint; ldnlp $1+4; ldc $2; in; }') define(`PPL_o_byte', `__asm{ld &$3; mint; ldnlp $1; ldc $2; out;}') def(`PPL_i_integer', `PPL_i_byte($1,`$2; bcnt',$3)') def(`PPL_o_integer', `PPL_o_byte($1,`$2; bcnt',$3)') def(`PPL_i_real', `PPL_i_byte($1,eval(4*$2),$3)') def(`PPL_o_real', `PPL_o_byte($1,eval(4*$2),$3)') /******************** Chronometric functions ********************/ define(`Chronometric_functions_', `` /* Chronometric functions */ int GetTime(void) { int t; __asm{ldtimer; st t;} return t; } void SendInt(int commport, int value) /* send int to commport */ { __asm{ld &value; mint; ld commport; wsub; ldc 1; bcnt; out;} } int RecvInt(int commport) /* receive int from commport */ { int i; __asm{ld &i; mint; ldnlp 4; ld commport; wsub; ldc 1; bcnt; in;} return i; }'') /************************ end of T800exec file *************************/ divert`'dnl