summaryrefslogtreecommitdiff
path: root/fpemulation.c
diff options
context:
space:
mode:
Diffstat (limited to 'fpemulation.c')
-rw-r--r--fpemulation.c60
1 files changed, 35 insertions, 25 deletions
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);