diff options
author | Matt Turner <mattst88@gmail.com> | 2008-11-12 22:51:00 +0000 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2008-11-12 22:51:00 +0000 |
commit | b50243af303373a0af9185dd12d86b21990dde14 (patch) | |
tree | 75584551061a95fdea4076ace750ac0dd09d01b4 /bitfield.c | |
parent | 8a639cb06e75d496a33f609b049dbf9e6145befc (diff) |
-- More cleanups for numsort.c and fpemulation.c
-- Begin cleaning bitfield.c
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@12 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
Diffstat (limited to 'bitfield.c')
-rw-r--r-- | bitfield.c | 222 |
1 files changed, 102 insertions, 120 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; + } } /************************ |