/************************************************************************* * * Following are software versions of the leading zero and popcount * functions needed for those architectures without these features. * * The flags SW_POPCNT and SW_LEADZ are defined in the makefile * * It also contains versions of the timing routines. The timing * routines most likely will need to be modified for each architecture. * * Contents: * these 2 are copied from bitops.h * popcnt - Popcount function * leadz - Leading zero function * wall - Wall Clock timer function * cputime - CPU timer function * processTime - min, max, and average times for a subroutine * *************************************************************************/ typedef unsigned long uint64; #ifdef SW_POPCNT int popcnt( uint64 numb ) { uint64 x = numb; // bitops.h uses UI64(0X5555555555555555) etc - macro from micro64.h // concatenates uL or uLL at end uint64 MASK1BIT = 0X5555555555555555uL, MASK2BITS = 0X3333333333333333uL, MASK4BITS = 0X0f0f0f0f0f0f0f0fuL; x = x - ((x >> 1) & MASK1BIT ); x = (x & MASK2BITS ) + ((x >> 2) & MASK2BITS ); x = (x + (x >> 4)) & MASK4BITS; x = x + (x >> 8); x = x + (x >> 16); x = x + (x >> 32); return (int)(x & (uint64)0xffL); } #endif /* #ifdef SW_POPCNT */ #ifdef SW_LEADZ int leadz (uint64 numb) { uint64 x = numb; int i = 0; int LDZ_LKUP = 0X11112234; #if 0 i = (x >> 32) ? 0 : 32; x = (x >> 32) ? (x >> 32) : x; i += (x >> 16) ? 0 : 16; x = (x >> 16) ? (x >> 16) : x; i += (x >> 8) ? 0 : 8; x = (x >> 8) ? (x >> 8) : x; i += (x >> 4) ? 0 : 4; x = (x >> 4) ? (x >> 4) : x; /* 4-bit lookup of leadz vals */ i += (LDZ_LKUP >> (4*x)) & 0xf; #else if (x>>32) x = x >> 32; else i = 32; if (x>>16) x = x >> 16; else i += 16; if (x>>8) x = x >> 8; else i += 8; if (x>>4) x = x >> 4; else i += 4; /* 4-bit lookup of leadz vals */ i += (LDZ_LKUP >> (4*x)) & 0xf; #endif return i; } #endif /* #ifdef SW_LEADZ */ /************************************************************************* * * wall() computes the amount of wall clock time that has elapsed. * * Make suitable changes to provide access to wall clock time * on architecture being used. * *************************************************************************/ #include #include //#include // also has types struct timeval tim; struct timezone tz; double wall() { gettimeofday(&tim, &tz); return (double)tim.tv_sec + (double)(tim.tv_usec*0.000001); } char * date() { gettimeofday(&tim, &tz); return ctime(&tim.tv_sec); } /************************************************************************* * * cputime() computes the amount of cpu time that has elapsed. * * Make suitable changes to provide access to cpu time * on architecture being used. * *************************************************************************/ #include double cputime() { return ( 0.000001L * (double)clock() ); } /************************************************************************** * * Determine the min, max, and average time for a process to complete * a specific subroutine. * * Param array: an array of doubles which are the times for each process * Param asize: an integer indicating the size of 'array' * Param tbuff: an array of 3 doubles where index 0 is the max, index 1 is * the min, and index 2 is the average time * *************************************************************************/ void processTime(double array[], int asize, double tbuff[]) { double total, max, min, avg; int i; total = max = avg = 0.0; min = array[1]; for(i = 0; i < asize; i++) { if(array[i] > max) { max = array[i]; } if(array[i] < min) { min = array[i]; } total = total + array[i]; } avg = total/((double)asize); tbuff[0] = max; tbuff[1] = min; tbuff[2] = avg; }