#include "bench7.h" /************************************************************************* * * 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: * popcnt - Popcount function * leadz - Leading zero function * wall - Wall Clock timer function * cputime - CPU timer function * *************************************************************************/ #ifdef SW_POPCNT #define _MASK1BIT 0x5555555555555555L #define _MASK2BITS 0x3333333333333333L #define _MASK4BITS 0x0f0f0f0f0f0f0f0fL int64 popcnt (uint64 x) { x = x - ((x >> 1) & _MASK1BIT); x = ((x >> 2) & _MASK2BITS) + (x & _MASK2BITS); x = ((x >> 4) + x) & _MASK4BITS; x = (x >> 8) + x; x = (x >> 16) + x; x = (x >> 32) + x; return x & 0xff; } #endif // #ifdef SW_POPCNT #ifdef SW_LEADZ #define _LDZ_LKUP 0x0000000011112234L int64 leadz (uint64 x) { int64 i; 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; 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 struct timeval tim; struct timezone tz; double wall() { gettimeofday(&tim, &tz); return (double)tim.tv_sec + (double)(tim.tv_usec*0.000001); } char * date(void) { gettimeofday(&tim, &tz); return ctime(&tim.tv_sec); } /************************************************************************* * * Computes the amount of cpu time that has elapsed. * * Make suitable changes to provide access to cpu time on * architecture being used. * *************************************************************************/ 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; }