/* Must be compiled with gcc */ #include #include #include #include #include #include #include /*#define WORK 256*/ typedef int smt_hw_lock_t; struct timespec currTime; smt_hw_lock_t _lock_malloc; smt_hw_lock_t _lock_printf; int sc_myid = 0; struct timeval sc_tp; unsigned Total_Proc=0x1; smt_hw_lock_t lockarray[32]; void bump_counter_slave(); void bump_counter(); #define smt_lock(lk) \ asm ("bis %0,$31,$2"::"r" (lk):"$2"); \ asm volatile ("bis $31,0x1f,$31") #define smt_release(lk) \ asm ("bis %0,$31,$2"::"r" (lk):"$2"); \ asm volatile ("bis $31,0x20,$31") #define smt_terminate() \ asm("bis $31, 0x2c, $31") #define smt_fork(args, function) \ asm("bis %0, $31, $4" : /*no output*/: "r" (function+8): "$4");\ asm("bis %0, $31, $16" : /*no output*/: "g" (args): "$16");\ asm("bis $31, 0, $31") struct barrierTYP { volatile unsigned entry_count; smt_hw_lock_t entrylock; smt_hw_lock_t waitlocks[8]; } barrier; static void init_smt_barrier() { int i; barrier.entrylock = 0; barrier.entry_count = 0x0; for (i=0;i<8;i++) { barrier.waitlocks[i] = 0; smt_lock(&barrier.waitlocks[i]); } } static void smt_barrier() { int temp; smt_lock(&barrier.entrylock); temp = ++barrier.entry_count; if (temp < 8) { smt_release(&barrier.entrylock); smt_lock(&barrier.waitlocks[temp-1]); smt_release(&barrier.waitlocks[temp]); } else { smt_release(&barrier.waitlocks[0]); smt_lock(&barrier.waitlocks[8-1]); barrier.entry_count = 0; smt_release(&barrier.entrylock); } } double A[10000]; double W[512]; void bump_counter_slave(int *id) { bump_counter(*id); smt_terminate(); } int WORK; void bump_counter(int id) { int i,j,w; register double temp; int nextid; nextid = (id + 1) % 8; if (id != 0) { smt_lock(&lockarray[id]); } smt_barrier(); for (j=0;j<10;j++) for (i=id;i<10000;i+=8) { temp = 0; for (w=0;w