diff options
Diffstat (limited to 'fpemulation.c')
-rw-r--r-- | fpemulation.c | 92 |
1 files changed, 91 insertions, 1 deletions
diff --git a/fpemulation.c b/fpemulation.c index b655c0c..cac88ee 100644 --- a/fpemulation.c +++ b/fpemulation.c @@ -15,6 +15,10 @@ ** FLOATING-POINT EMULATION ** *****************************/ +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); + /************** ** DoEmFloat ** *************** @@ -55,7 +59,7 @@ DoEmFloat(void) exit(1); } - SetupCPUEmFloatArrays(abase, bbase, cbase, locemfloatstruct->arraysize); /* FIXME: ugly */ + SetupCPUEmFloatArrays(abase, bbase, locemfloatstruct->arraysize); /* FIXME: ugly */ /* See if we need to do self-adjusting code.*/ if (locemfloatstruct->adjust == FALSE) { @@ -104,3 +108,89 @@ DoEmFloat(void) locemfloatstruct->emflops = (double)(iterations * locemfloatstruct->loops * CLOCKS_PER_SEC) / (double)total_time; } + +/*********************** +** DoEmFloatIteration ** +************************ +** Perform an iteration of the emulated floating-point +** benchmark. Note that "an iteration" can involve multiple +** loops through the benchmark. +*/ +static clock_t +DoEmFloatIteration(InternalFPF *abase, + InternalFPF *bbase, + InternalFPF *cbase, + unsigned long arraysize, 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}; +unsigned long i; + + start = clock(); + +/* +** Each pass through the array performs operations in +** the followingratios: +** 4 adds, 4 subtracts, 5 multiplies, 3 divides +** (adds and subtracts being nearly the same operation) +*/ +while(loops--) +{ + for(i=0;i<arraysize;i++) + switch(jtable[i % 16]) + { + case 0: /* Add */ + AddSubInternalFPF(0,abase+i, + bbase+i, + cbase+i); + break; + case 1: /* Subtract */ + AddSubInternalFPF(1,abase+i, + bbase+i, + cbase+i); + break; + case 2: /* Multiply */ + MultiplyInternalFPF(abase+i, + bbase+i, + cbase+i); + break; + case 3: /* Divide */ + DivideInternalFPF(abase+i, + bbase+i, + cbase+i); + break; + } + } + + stop = clock(); + + return stop - start; +} + +/************************** +** SetupCPUEmFloatArrays ** +*************************** +** Set up the arrays that will be used in the emulated +** floating-point tests. +** This is done by loading abase and bbase elements with +** random numbers. We use our long-to-floating point +** routine to set them up. +*/ +static void +SetupCPUEmFloatArrays(InternalFPF *abase, InternalFPF *bbase, unsigned long arraysize) +{ + unsigned long i; + InternalFPF locFPF1,locFPF2; + /* + ** Reset random number generator so things repeat. Inserted by Uwe F. Mayer. + */ + randnum(13); + + for (i = 0; i < arraysize; i++) { + Int32ToInternalFPF(randwc(50000),&locFPF1); + Int32ToInternalFPF(randwc(50000)+1,&locFPF2); + DivideInternalFPF(&locFPF1,&locFPF2,abase+i); + Int32ToInternalFPF(randwc(50000)+1,&locFPF2); + DivideInternalFPF(&locFPF1,&locFPF2,bbase+i); + } +} |