diff options
-rw-r--r-- | bitfield.c | 222 | ||||
-rw-r--r-- | fpemulation.c | 29 | ||||
-rw-r--r-- | numsort.c | 57 |
3 files changed, 148 insertions, 160 deletions
@@ -1,17 +1,11 @@ -#include <stdint.h> -/* #include <stdio.h> #include <stdlib.h> -#include <string.h> -#include <strings.h> -#include <math.h>*/ +#include <stdint.h> +#include <math.h> + #include "nmglobal.h" #include "nbench1.h" -#ifdef DEBUG -static int numsort_status=0; -static int stringsort_status=0; -#endif /************************ ** BITFIELD OPERATIONS ** @@ -23,118 +17,106 @@ static int stringsort_status=0; ** Perform the bit operations test portion of the CPU ** benchmark. Returns the iterations per second. */ -void DoBitops(void) -{ -BitOpStruct *locbitopstruct; /* Local bitop structure */ -unsigned long *bitarraybase; /* Base of bitmap array */ -unsigned long *bitoparraybase; /* Base of bitmap operations array */ -unsigned long nbitops; /* # of bitfield operations */ -unsigned long accumtime; /* Accumulated time in ticks */ -double iterations; /* # of iterations */ -char *errorcontext; /* Error context string */ -int systemerror; /* For holding error codes */ -int ticks; - -/* -** Link to global structure. -*/ -locbitopstruct=&global_bitopstruct; - -/* -** Set the error context. -*/ -errorcontext="CPU:Bitfields"; - -/* -** See if we need to run adjustment code. -*/ -if(locbitopstruct->adjust==0) -{ - bitarraybase=(unsigned long *)AllocateMemory(locbitopstruct->bitfieldarraysize * - sizeof(unsigned long),&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - } - - /* - ** Initialize bitfield operations array to [2,30] elements - */ - locbitopstruct->bitoparraysize=30L; - - while(1) - { - /* - ** Allocate space for operations array - */ - bitoparraybase=(unsigned long *)AllocateMemory(locbitopstruct->bitoparraysize*2L* - sizeof(unsigned long), - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - FreeMemory((void *)bitarraybase,&systemerror); - } - /* - ** Do an iteration of the bitmap test. If the - ** elapsed time is less than or equal to the permitted - ** minimum, then de-allocate the array, reallocate a - ** larger version, and try again. - */ - ticks=DoBitfieldIteration(bitarraybase, - bitoparraybase, - locbitopstruct->bitoparraysize, - &nbitops); - - if (ticks>global_min_ticks) break; /* We're ok...exit */ - - FreeMemory((void *)bitoparraybase,&systemerror); - locbitopstruct->bitoparraysize+=100L; - } -} -else +void +DoBitops(void) { - /* - ** Don't need to do self adjustment, just allocate - ** the array space. - */ - bitarraybase=(unsigned long *)AllocateMemory(locbitopstruct->bitfieldarraysize * - sizeof(unsigned long),&systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - } - bitoparraybase=(unsigned long *)AllocateMemory(locbitopstruct->bitoparraysize*2L* - sizeof(unsigned long), - &systemerror); - if(systemerror) - { ReportError(errorcontext,systemerror); - FreeMemory((void *)bitarraybase,&systemerror); - } -} - -/* -** All's well if we get here. Repeatedly perform bitops until the -** accumulated elapsed time is greater than # of seconds requested. -*/ -accumtime=0L; -iterations=(double)0.0; -do { - accumtime+=DoBitfieldIteration(bitarraybase, - bitoparraybase, - locbitopstruct->bitoparraysize,&nbitops); - iterations+=(double)nbitops; -} while(TicksToSecs(accumtime)<locbitopstruct->request_secs); - -/* -** Clean up, calculate results, and go home. -** Also, set adjustment flag to show that we don't have -** to do self adjusting in the future. -*/ -FreeMemory((void *)bitarraybase,&systemerror); -FreeMemory((void *)bitoparraybase,&systemerror); -locbitopstruct->bitopspersec=iterations /TicksToFracSecs(accumtime); -if(locbitopstruct->adjust==0) - locbitopstruct->adjust=1; - -return; + /* Error context string */ + const char *context = "CPU:Bitfields"; + /* Local bitop structure */ + BitOpStruct *locbitopstruct = &global_bitopstruct; + + unsigned long *bitarraybase = NULL; /* Base of bitmap array */ + unsigned long *bitoparraybase = NULL; /* Base of bitmap operations array */ + unsigned long nbitops; /* # of bitfield operations */ + unsigned long accumtime; /* Accumulated time in ticks */ + double iterations; /* # of iterations */ + int ticks; + + /* + ** See if we need to run adjustment code. + */ + if (locbitopstruct->adjust == 0) { + bitarraybase = realloc(bitarraybase, locbitopstruct->bitfieldarraysize * sizeof(unsigned long)); + if (!bitarraybase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + exit(1); + } + + /* + ** Initialize bitfield operations array to [2,30] elements + */ + locbitopstruct->bitoparraysize = 30L; + + while(1) { + bitoparraybase = malloc(locbitopstruct->bitoparraysize * 2 * sizeof(unsigned long)); + if (!bitoparraybase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(bitarraybase); + exit(1); + } + + /* + ** Do an iteration of the bitmap test. If the + ** elapsed time is less than or equal to the permitted + ** minimum, then de-allocate the array, reallocate a + ** larger version, and try again. + */ + ticks = DoBitfieldIteration(bitarraybase, + bitoparraybase, + locbitopstruct->bitoparraysize, + &nbitops); + + if (ticks > global_min_ticks) { + break; + } + + locbitopstruct->bitoparraysize += 100L; + } + } else { + /* + ** Don't need to do self adjustment, just allocate + ** the array space. + */ + bitarraybase = malloc(locbitopstruct->bitfieldarraysize * sizeof(unsigned long)); + if (!bitarraybase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + exit(1); + } + + bitoparraybase = malloc(locbitopstruct->bitoparraysize * 2 * sizeof(unsigned long)); + if (!bitoparraybase) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(bitarraybase); + exit(1); + } + } + + /* + ** All's well if we get here. Repeatedly perform bitops until the + ** accumulated elapsed time is greater than # of seconds requested. + */ + accumtime = 0L; + iterations = 0.0; + do { + accumtime += DoBitfieldIteration(bitarraybase, + bitoparraybase, + locbitopstruct->bitoparraysize,&nbitops); + iterations += (double)nbitops; + } while (TicksToSecs(accumtime) < locbitopstruct->request_secs); + + /* + ** Clean up, calculate results, and go home. + ** Also, set adjustment flag to show that we don't have + ** to do self adjusting in the future. + */ + free(bitarraybase); + free(bitoparraybase); + + locbitopstruct->bitopspersec = iterations / TicksToFracSecs(accumtime); + + if (locbitopstruct->adjust == 0) { + locbitopstruct->adjust = 1; + } } /************************ diff --git a/fpemulation.c b/fpemulation.c index b9b6235..26ce951 100644 --- a/fpemulation.c +++ b/fpemulation.c @@ -1,9 +1,8 @@ #include <stdio.h> #include <stdlib.h> -/* -#include <string.h> -#include <strings.h> -#include <math.h>*/ +#include <stdint.h> +#include <math.h> + #include "nmglobal.h" #include "nbench1.h" @@ -18,7 +17,9 @@ ** Perform the floating-point emulation routines portion of the ** CPU benchmark. Returns the operations per second. */ -void DoEmFloat(void) { +void +DoEmFloat(void) +{ /* Error context string pointer */ const char *errorcontext = "CPU:Floating Emulation"; /* Local structure */ @@ -56,21 +57,19 @@ void DoEmFloat(void) { SetupCPUEmFloatArrays(abase, bbase, cbase, locemfloatstruct->arraysize); /* FIXME: ugly */ - /* - ** See if we need to do self-adjusting code. - */ - if( locemfloatstruct->adjust == 0 ) { - locemfloatstruct->loops=0; + /* See if we need to do self-adjusting code.*/ + if (locemfloatstruct->adjust == 0) { + locemfloatstruct->loops = 0; /* ** Do an iteration of the tests. If the elapsed time is ** less than minimum, increase the loop count and try ** again. */ - for ( loops = 1; loops < CPUEMFLOATLOOPMAX; loops += loops ) { + for (loops = 1; loops < CPUEMFLOATLOOPMAX; loops += loops) { tickcount = DoEmFloatIteration(abase, bbase, cbase, /* FIXME: ugly */ locemfloatstruct->arraysize, loops); - if ( tickcount > global_min_ticks ) { + if (tickcount > global_min_ticks) { locemfloatstruct->loops = loops; break; } @@ -80,7 +79,7 @@ void DoEmFloat(void) { /* ** Verify that selft adjustment code worked. */ - if ( locemfloatstruct->loops == 0 ) { + if (locemfloatstruct->loops == 0) { puts("CPU:EMFPU -- CMPUEMFLOATLOOPMAX limit hit"); free(abase); free(bbase); @@ -100,7 +99,7 @@ void DoEmFloat(void) { accumtime += DoEmFloatIteration(abase, bbase, cbase, /* FIXME: ugly */ locemfloatstruct->arraysize, locemfloatstruct->loops); iterations += 1.0; - } while ( TicksToSecs(accumtime) < locemfloatstruct->request_secs ); + } while (TicksToSecs(accumtime) < locemfloatstruct->request_secs); /* ** Clean up, calculate results, and go home. @@ -112,7 +111,7 @@ void DoEmFloat(void) { locemfloatstruct->emflops = (iterations * (double)locemfloatstruct->loops) / (double)TicksToFracSecs(accumtime); - if ( locemfloatstruct->adjust == 0 ) { + if (locemfloatstruct->adjust == 0) { locemfloatstruct->adjust = 1; } } @@ -1,10 +1,12 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> +#include <math.h> #include "nmglobal.h" #include "nbench1.h" + /********************* ** NUMERIC HEAPSORT ** ********************** @@ -22,7 +24,9 @@ static inline void NumSift(long *array, unsigned long min, unsigned long max); ** This routine performs the CPU numeric sort test. */ -void DoNumSort(void) { +void +DoNumSort (void) +{ /* Error context string pointer */ const char *context = "CPU:Numeric Sort"; /* Local pointer to global struct */ @@ -35,15 +39,15 @@ void DoNumSort(void) { /* ** See if we need to do self adjustment code. */ - if(numsortstruct->adjust==0) { + if (numsortstruct->adjust == 0) { /* ** Self-adjustment code. The system begins by sorting 1 ** array. If it does that in no time, then two arrays ** are built and sorted. This process continues until ** enough arrays are built to handle the tolerance. */ - numsortstruct->numarrays=1; - while(1) { + numsortstruct->numarrays = 1; + while (1) { arraybase = realloc(arraybase, numsortstruct->numarrays * numsortstruct->arraysize * sizeof(long)); if (!arraybase) { fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); @@ -56,12 +60,12 @@ void DoNumSort(void) { ** minimum, then allocate for more arrays and ** try again. */ - if ( DoNumSortIteration(arraybase, numsortstruct->arraysize, numsortstruct->numarrays)>global_min_ticks ) { + if (DoNumSortIteration(arraybase, numsortstruct->arraysize, numsortstruct->numarrays)>global_min_ticks) { break; } - if(numsortstruct->numarrays > NUMNUMARRAYS) { - printf("CPU:NSORT -- NUMNUMARRAYS hit.\n"); + if (numsortstruct->numarrays > NUMNUMARRAYS) { + puts("CPU:NSORT -- NUMNUMARRAYS hit."); } ++numsortstruct->numarrays; } @@ -91,9 +95,9 @@ void DoNumSort(void) { */ free(arraybase); - numsortstruct->sortspersec=iterations * (double)numsortstruct->numarrays / TicksToFracSecs(accumtime); + numsortstruct->sortspersec = iterations * (double)numsortstruct->numarrays / TicksToFracSecs(accumtime); - if ( numsortstruct->adjust == 0 ) { + if (numsortstruct->adjust == 0) { numsortstruct->adjust = 1; } } @@ -105,7 +109,9 @@ void DoNumSort(void) { ** sort benchmark. It returns the number of ticks ** elapsed for the iteration. */ -static unsigned long DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarrays) { +static unsigned long +DoNumSortIteration(long *arraybase, unsigned long arraysize, unsigned int numarrays) +{ unsigned long elapsed; /* Elapsed ticks */ unsigned long i; @@ -122,7 +128,7 @@ static unsigned long DoNumSortIteration(long *arraybase, unsigned long arraysize /* ** Execute a heap of heapsorts */ - for(i = 0; i < numarrays; i++ ) { + for (i = 0; i < numarrays; i++) { NumHeapSort(arraybase + i * arraysize, 0L, arraysize - 1L); } @@ -139,21 +145,19 @@ static unsigned long DoNumSortIteration(long *arraybase, unsigned long arraysize ************************** ** Load up an array with random longs. */ -static void LoadNumArrayWithRand(long *array, /* Pointer to arrays */ +static void +LoadNumArrayWithRand(long *array, /* Pointer to arrays */ unsigned long arraysize, unsigned int numarrays) /* # of elements in array */ { long i; /* Used for index */ long *darray; /* Destination array pointer */ - /* - ** Initialize the random number generator - */ + + /* Initialize the random number generator */ randnum(13); - /* - ** Load up first array with randoms - */ - for( i = 0; i < arraysize; i++ ) { + /* Load up first array with randoms */ + for (i = 0; i < arraysize; i++) { array[i] = randnum(0); } @@ -162,7 +166,7 @@ static void LoadNumArrayWithRand(long *array, /* Pointer to arrays */ ** first into each of the others. */ darray = array; - while ( --numarrays ) { + while (--numarrays) { darray += arraysize; memcpy(darray, array, arraysize * sizeof(long)); } @@ -175,14 +179,16 @@ static void LoadNumArrayWithRand(long *array, /* Pointer to arrays */ ** integers. Also pass in minimum and maximum offsets. ** This routine performs a heap sort on that array. */ -static inline void NumHeapSort(long *array, unsigned long bottom, unsigned long top) { +static inline void +NumHeapSort(long *array, unsigned long bottom, unsigned long top) +{ unsigned long temp; /* Used to exchange elements */ unsigned long i; /* Loop index */ /* ** First, build a heap in the array */ - for (i = (top / 2L); i > 0; i-- ) { + for (i = (top / 2L); i > 0; i--) { NumSift(array, i, top); } @@ -191,7 +197,7 @@ static inline void NumHeapSort(long *array, unsigned long bottom, unsigned long ** end of the array. When we get done, we'll have a sorted ** array. */ - for ( i = top; i > 0; i-- ) { + for (i = top; i > 0; i--) { NumSift(array, bottom, i); temp = *array; @@ -206,7 +212,9 @@ static inline void NumHeapSort(long *array, unsigned long bottom, unsigned long ** Peforms the sift operation on a numeric array, ** constructing a heap in the array. */ -static inline void NumSift(long *array, unsigned long min, unsigned long max) { +static inline void +NumSift(long *array, unsigned long min, unsigned long max) +{ unsigned long k; unsigned long temp; /* Used for exchange */ @@ -228,4 +236,3 @@ static inline void NumSift(long *array, unsigned long min, unsigned long max) { } } } - |