diff options
Diffstat (limited to 'fpemulation.c')
-rw-r--r-- | fpemulation.c | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/fpemulation.c b/fpemulation.c index e851cd9..61b016b 100644 --- a/fpemulation.c +++ b/fpemulation.c @@ -4,6 +4,7 @@ #include <string.h> #include <math.h> #include <limits.h> +#include <time.h> #include "nmglobal.h" #include "nbench1.h" @@ -23,18 +24,14 @@ void DoEmFloat(void) { - /* Error context string pointer */ - const char *errorcontext = "CPU:Floating Emulation"; - /* Local structure */ - EmFloatStruct *locemfloatstruct = &global_emfloatstruct; - - InternalFPF *abase = NULL; /* Base of A array */ - InternalFPF *bbase = NULL; /* Base of B array */ - InternalFPF *cbase = NULL; /* Base of C array */ - unsigned long accumtime; /* Accumulated time in ticks */ - double iterations; /* # of iterations */ - unsigned long tickcount; /* # of ticks */ - unsigned long loops; /* # of loops */ + const char* errorcontext = "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; abase = malloc(locemfloatstruct->arraysize * sizeof(InternalFPF)); if (!abase) { @@ -61,7 +58,9 @@ DoEmFloat(void) SetupCPUEmFloatArrays(abase, bbase, cbase, locemfloatstruct->arraysize); /* FIXME: ugly */ /* See if we need to do self-adjusting code.*/ - if (locemfloatstruct->adjust == 0) { + if (locemfloatstruct->adjust == FALSE) { + locemfloatstruct->adjust = TRUE; + locemfloatstruct->loops = 0; /* @@ -69,10 +68,8 @@ DoEmFloat(void) ** less than minimum, increase the loop count and try ** again. */ - for (loops = 1; loops < CPUEMFLOATLOOPMAX; loops += loops) { - tickcount = DoEmFloatIteration(abase, bbase, cbase, /* FIXME: ugly */ - locemfloatstruct->arraysize, loops); - if (tickcount > global_min_ticks) { + for (; loops < CPUEMFLOATLOOPMAX; loops += loops) { + if (DoEmFloatIteration(abase, bbase, cbase, locemfloatstruct->arraysize, loops) > global_min_ticks) { locemfloatstruct->loops = loops; break; } @@ -96,25 +93,14 @@ DoEmFloat(void) ** # of seconds requested. ** Each iteration performs arraysize * 3 operations. */ - accumtime = 0L; - iterations = 0.0; do { - accumtime += DoEmFloatIteration(abase, bbase, cbase, /* FIXME: ugly */ - locemfloatstruct->arraysize, locemfloatstruct->loops); - iterations += 1.0; - } while (TicksToSecs(accumtime) < locemfloatstruct->request_secs); + total_time += DoEmFloatIteration(abase, bbase, cbase, locemfloatstruct->arraysize, locemfloatstruct->loops); + ++iterations; + } while (total_time < locemfloatstruct->request_secs * CLOCKS_PER_SEC); - /* - ** Clean up, calculate results, and go home. - ** Also, indicate that adjustment is done. - */ free(abase); free(bbase); free(cbase); - locemfloatstruct->emflops = (iterations * (double)locemfloatstruct->loops) - / (double)TicksToFracSecs(accumtime); - if (locemfloatstruct->adjust == 0) { - locemfloatstruct->adjust = 1; - } + locemfloatstruct->emflops = (double)(iterations * locemfloatstruct->loops * CLOCKS_PER_SEC) / (double)total_time; } |