diff options
author | Matt Turner <mattst88@gmail.com> | 2008-11-15 02:19:34 +0000 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2008-11-15 02:19:34 +0000 |
commit | 332747f6df0cd2af6535d81ccde00ade374563fa (patch) | |
tree | 67ec63e56bdd6220146e0d42d676fcb165999f09 | |
parent | 27b6cc8fd26d7d3f31308a4137436e4f455c0daf (diff) |
Clean out fpemulation struct. Replace members with local static variables
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@48 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
-rw-r--r-- | cleanbench.c | 3 | ||||
-rw-r--r-- | emfloat.h | 11 | ||||
-rw-r--r-- | fpemulation.c | 60 | ||||
-rw-r--r-- | nmglobal.h | 25 |
4 files changed, 36 insertions, 63 deletions
diff --git a/cleanbench.c b/cleanbench.c index 93a6c82..abb9994 100644 --- a/cleanbench.c +++ b/cleanbench.c @@ -81,7 +81,6 @@ for (i = 0; i < NUMTESTS; i++) { ** Initialize test data structures to default ** values. */ -global_emfloatstruct.arraysize=EMFARRAYSIZE; global_ideastruct.arraysize=IDEAARRAYSIZE; global_huffstruct.arraysize=HUFFARRAYSIZE; @@ -92,7 +91,7 @@ puts("\nTEST : Iterations/sec. : Old Index : New Index"); puts(" : : Pentium 90* : AMD K6/233*"); puts("--------------------:------------------:-------------:------------"); -for(i=0;i<NUMTESTS;i++) +for(i=FPEMULATION;i<NUMTESTS;i++) { if(tests_to_do[i]) { printf("%s :",ftestnames[i]); @@ -73,15 +73,7 @@ #define OPERAND_INFINITY 3 #define OPERAND_NAN 4 -/* -** Following already defined in NMGLOBAL.H -** #define INTERNAL_FPF_PRECISION 4 -*/ - -/* -** TYPEDEFS -*/ typedef struct { @@ -91,9 +83,6 @@ typedef struct uint16_t mantissa[INTERNAL_FPF_PRECISION]; } InternalFPF; -/* -** PROTOTYPES -*/ void AddSubInternalFPF(unsigned char operation,InternalFPF *x, InternalFPF *y, InternalFPF *z); void MultiplyInternalFPF(InternalFPF *x,InternalFPF *y, InternalFPF *z); void DivideInternalFPF(InternalFPF *x,InternalFPF *y, InternalFPF *z); diff --git a/fpemulation.c b/fpemulation.c index 234c1ec..b0c5459 100644 --- a/fpemulation.c +++ b/fpemulation.c @@ -15,9 +15,20 @@ ** FLOATING-POINT EMULATION ** *****************************/ +/* +** The following constant is the maximum number of loops +** of the emulated floating point test that the system +** will allow before flagging an error. This is not a +** critical constant, and can be altered if your system is +** a real barn-burner. +*/ +#define LOOP_MAX 500000L + +#define ARRAY_SIZE 3000L + static clock_t DoEmFloatIteration(InternalFPF *abase, InternalFPF *bbase, InternalFPF *cbase, - unsigned long arraysize, unsigned long loops); -static void SetupCPUEmFloatArrays(InternalFPF *abase, InternalFPF *bbase, unsigned long arraysize); + unsigned long loops); +static void SetupCPUEmFloatArrays(InternalFPF *abase, InternalFPF *bbase); /************** ** DoEmFloat ** @@ -28,54 +39,53 @@ static void SetupCPUEmFloatArrays(InternalFPF *abase, InternalFPF *bbase, unsign void DoEmFloat(void) { - const char* errorcontext = "CPU:Floating Emulation"; + const char* context = "CPU:Floating Emulation"; EmFloatStruct* locemfloatstruct = &global_emfloatstruct; InternalFPF* abase = NULL; InternalFPF* bbase = NULL; InternalFPF* cbase = NULL; clock_t total_time = 0; int iterations = 0; - unsigned long loops = 1; + unsigned long i = 1; static int is_adjusted = FALSE; + static long loops = 0; - abase = malloc(locemfloatstruct->arraysize * sizeof(InternalFPF)); + abase = malloc(ARRAY_SIZE * sizeof(InternalFPF)); if (!abase) { - printf("ERROR CONDITION\nContext: %s\n", errorcontext); + printf("ERROR CONDITION\nContext: %s\n", context); exit(1); } - bbase = malloc(locemfloatstruct->arraysize * sizeof(InternalFPF)); + bbase = malloc(ARRAY_SIZE * sizeof(InternalFPF)); if (!bbase) { - printf("ERROR CONDITION\nContext: %s\n", errorcontext); + printf("ERROR CONDITION\nContext: %s\n", context); free(abase); exit(1); } - cbase = malloc(locemfloatstruct->arraysize * sizeof(InternalFPF)); + cbase = malloc(ARRAY_SIZE * sizeof(InternalFPF)); if (!cbase) { - printf("ERROR CONDITION\nContext: %s\n", errorcontext); + printf("ERROR CONDITION\nContext: %s\n", context); free(abase); free(bbase); exit(1); } - SetupCPUEmFloatArrays(abase, bbase, locemfloatstruct->arraysize); /* FIXME: ugly */ + SetupCPUEmFloatArrays(abase, bbase); /* FIXME: ugly */ /* See if we need to do self-adjusting code.*/ if (is_adjusted == FALSE) { is_adjusted = TRUE; - 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 < CPUEMFLOATLOOPMAX; loops += loops) { - if (DoEmFloatIteration(abase, bbase, cbase, locemfloatstruct->arraysize, loops) > MINIMUM_TICKS) { - locemfloatstruct->loops = loops; + for (; i < LOOP_MAX; i += i) { + if (DoEmFloatIteration(abase, bbase, cbase, i) > MINIMUM_TICKS) { + loops = i; break; } } @@ -84,8 +94,8 @@ DoEmFloat(void) /* ** Verify that selft adjustment code worked. */ - if (locemfloatstruct->loops == 0) { - puts("CPU:EMFPU -- CMPUEMFLOATLOOPMAX limit hit"); + if (loops == 0) { + fputs("CPU:EMFPU -- CMPUEMFLOATLOOPMAX limit hit", stderr); free(abase); free(bbase); free(cbase); @@ -96,10 +106,10 @@ DoEmFloat(void) ** All's well if we get here. Repeatedly perform floating ** tests until the accumulated time is greater than the ** # of seconds requested. - ** Each iteration performs arraysize * 3 operations. + ** Each iteration performs ARRAY_SIZE * 3 operations. */ do { - total_time += DoEmFloatIteration(abase, bbase, cbase, locemfloatstruct->arraysize, locemfloatstruct->loops); + total_time += DoEmFloatIteration(abase, bbase, cbase, loops); ++iterations; } while (total_time < MINIMUM_SECONDS * CLOCKS_PER_SEC); @@ -107,7 +117,7 @@ DoEmFloat(void) free(bbase); free(cbase); - locemfloatstruct->results = (double)(iterations * locemfloatstruct->loops * CLOCKS_PER_SEC) / (double)total_time; + locemfloatstruct->results = (double)(iterations * loops * CLOCKS_PER_SEC) / (double)total_time; } /*********************** @@ -121,7 +131,7 @@ static clock_t DoEmFloatIteration(InternalFPF *abase, InternalFPF *bbase, InternalFPF *cbase, - unsigned long arraysize, unsigned long loops) + unsigned long loops) { clock_t start, stop; static unsigned char jtable[16] = {0,0,0,0,1,1,1,1,2,2,2,2,2,3,3,3}; @@ -137,7 +147,7 @@ unsigned long i; */ while(loops--) { - for(i=0;i<arraysize;i++) + for(i=0;i<ARRAY_SIZE;i++) switch(jtable[i % 16]) { case 0: /* Add */ @@ -178,7 +188,7 @@ while(loops--) ** routine to set them up. */ static void -SetupCPUEmFloatArrays(InternalFPF *abase, InternalFPF *bbase, unsigned long arraysize) +SetupCPUEmFloatArrays(InternalFPF *abase, InternalFPF *bbase) { unsigned long i; InternalFPF locFPF1,locFPF2; @@ -187,7 +197,7 @@ SetupCPUEmFloatArrays(InternalFPF *abase, InternalFPF *bbase, unsigned long arra */ randnum(13); - for (i = 0; i < arraysize; i++) { + for (i = 0; i < ARRAY_SIZE; i++) { Int32ToInternalFPF(randwc(50000),&locFPF1); Int32ToInternalFPF(randwc(50000)+1,&locFPF2); DivideInternalFPF(&locFPF1,&locFPF2,abase+i); @@ -43,36 +43,11 @@ typedef struct { double results; /* # of bitfield ops per sec */ } BitOpStruct; -/**************************** -** EMULATED FLOATING POINT ** -****************************/ -/* -** DEFINES -*/ -#define INTERNAL_FPF_PRECISION 4 - -/* -** The following constant is the maximum number of loops -** of the emulated floating point test that the system -** will allow before flagging an error. This is not a -** critical constant, and can be altered if your system is -** a real barn-burner. -*/ -/*#define CPUEMFLOATLOOPMAX 50000L*/ -#define CPUEMFLOATLOOPMAX 500000L - -/* -** Set size of array -*/ -#define EMFARRAYSIZE 3000L - /* ** TYPEDEFS */ typedef struct { double results; /* Results */ - unsigned long arraysize; /* Size of array */ - unsigned long loops; /* Loops per iterations */ } EmFloatStruct; /************************* |