summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-12 03:18:32 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-12 03:18:32 +0000
commite618b16d4cc89e46ec4bac40af34a93790a17f8e (patch)
tree280aec8bfeafc746e375c05eb9a7d83bb6cdbaf8
parent974755deb9bbea37752d2202844a1f485e59c8e7 (diff)
-- Cleanup fpemulation.c
-- Begin cleaning numsort.c git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@9 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
-rw-r--r--bitfield.c25
-rw-r--r--fpemulation.c226
-rw-r--r--numsort.c94
-rw-r--r--sysspec.c2
-rw-r--r--sysspec.h2
5 files changed, 134 insertions, 215 deletions
diff --git a/bitfield.c b/bitfield.c
index 78aba9e..7115524 100644
--- a/bitfield.c
+++ b/bitfield.c
@@ -83,31 +83,6 @@ if(locbitopstruct->adjust==0)
bitoparraybase,
locbitopstruct->bitoparraysize,
&nbitops);
-#ifdef DEBUG
-#ifdef LINUX
- if (locbitopstruct->bitoparraysize==30L){
- /* this is the first loop, write a debug file */
- FILE *file;
- unsigned long *running_base; /* same as unsigned long */
- long counter;
- file=fopen("debugbit.dat","w");
- running_base=bitarraybase;
- for (counter=0;counter<(long)(locbitopstruct->bitfieldarraysize);counter++){
-#ifdef _LP64
- fprintf(file,"%08X",(unsigned int)(*running_base&0xFFFFFFFFL));
- fprintf(file,"%08X",(unsigned int)((*running_base>>32)&0xFFFFFFFFL));
- if ((counter+1)%4==0) fprintf(file,"\n");
-#else
- fprintf(file,"%08lX",*running_base);
- if ((counter+1)%8==0) fprintf(file,"\n");
-#endif
- running_base=running_base+1;
- }
- fclose(file);
- printf("\nWrote the file debugbit.dat, you may want to compare it to debugbit.good\n");
- }
-#endif
-#endif
if (ticks>global_min_ticks) break; /* We're ok...exit */
diff --git a/fpemulation.c b/fpemulation.c
index d4332a3..7d631bf 100644
--- a/fpemulation.c
+++ b/fpemulation.c
@@ -1,6 +1,6 @@
#include <stdio.h>
-/*
#include <stdlib.h>
+/*
#include <string.h>
#include <strings.h>
#include <math.h>*/
@@ -18,130 +18,102 @@
** Perform the floating-point emulation routines portion of the
** CPU benchmark. Returns the operations per second.
*/
-void DoEmFloat(void)
-{
-EmFloatStruct *locemfloatstruct; /* Local structure */
-InternalFPF *abase; /* Base of A array */
-InternalFPF *bbase; /* Base of B array */
-InternalFPF *cbase; /* Base of C array */
-unsigned long accumtime; /* Accumulated time in ticks */
-double iterations; /* # of iterations */
-unsigned long tickcount; /* # of ticks */
-char *errorcontext; /* Error context string pointer */
-int systemerror; /* For holding error code */
-unsigned long loops; /* # of loops */
-
-/*
-** Link to global structure
-*/
-locemfloatstruct=&global_emfloatstruct;
-
-/*
-** Set the error context
-*/
-errorcontext="CPU:Floating Emulation";
-
-
-/*
-** Test the emulation routines.
-*/
-#ifdef DEBUG
-#endif
-
-abase=(InternalFPF *)AllocateMemory(locemfloatstruct->arraysize*sizeof(InternalFPF),
- &systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
- ErrorExit();
-}
-
-bbase=(InternalFPF *)AllocateMemory(locemfloatstruct->arraysize*sizeof(InternalFPF),
- &systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
- FreeMemory((void *)abase,&systemerror);
- ErrorExit();
-}
-
-cbase=(InternalFPF *)AllocateMemory(locemfloatstruct->arraysize*sizeof(InternalFPF),
- &systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
- FreeMemory((void *)abase,&systemerror);
- FreeMemory((void *)bbase,&systemerror);
- ErrorExit();
-}
-
-/*
-** Set up the arrays
-*/
-SetupCPUEmFloatArrays(abase,bbase,cbase,locemfloatstruct->arraysize);
-
-/*
-** See if we need to do self-adjusting code.
-*/
-if(locemfloatstruct->adjust==0)
-{
- 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=1;loops<CPUEMFLOATLOOPMAX;loops+=loops)
- { tickcount=DoEmFloatIteration(abase,bbase,cbase,
- locemfloatstruct->arraysize,
- loops);
- if(tickcount>global_min_ticks)
- { locemfloatstruct->loops=loops;
- break;
- }
- }
-}
-
-/*
-** Verify that selft adjustment code worked.
-*/
-if(locemfloatstruct->loops==0)
-{ printf("CPU:EMFPU -- CMPUEMFLOATLOOPMAX limit hit\n");
- FreeMemory((void *)abase,&systemerror);
- FreeMemory((void *)bbase,&systemerror);
- FreeMemory((void *)cbase,&systemerror);
- ErrorExit();
-}
-
-/*
-** 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.
-*/
-accumtime=0L;
-iterations=(double)0.0;
-do {
- accumtime+=DoEmFloatIteration(abase,bbase,cbase,
- locemfloatstruct->arraysize,
- locemfloatstruct->loops);
- iterations+=(double)1.0;
-} while(TicksToSecs(accumtime)<locemfloatstruct->request_secs);
-
-
-/*
-** Clean up, calculate results, and go home.
-** Also, indicate that adjustment is done.
-*/
-FreeMemory((void *)abase,&systemerror);
-FreeMemory((void *)bbase,&systemerror);
-FreeMemory((void *)cbase,&systemerror);
-
-locemfloatstruct->emflops=(iterations*(double)locemfloatstruct->loops)/
- (double)TicksToFracSecs(accumtime);
-if(locemfloatstruct->adjust==0)
- locemfloatstruct->adjust=1;
-
-#ifdef DEBUG
-printf("----------------------------------------------------------------------------\n");
-#endif
-return;
+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 */
+ int systemerror; /* For holding error code */
+ unsigned long loops; /* # of loops */
+
+ abase = malloc(locemfloatstruct->arraysize * sizeof(InternalFPF));
+ if (!abase) {
+ printf("ERROR CONDITION\nContext: %s\n", errorcontext);
+ exit(1);
+ }
+
+
+ bbase = malloc(locemfloatstruct->arraysize * sizeof(InternalFPF));
+ if (!bbase) {
+ printf("ERROR CONDITION\nContext: %s\n", errorcontext);
+ free(abase);
+ exit(1);
+ }
+
+ cbase = malloc(locemfloatstruct->arraysize * sizeof(InternalFPF));
+ if (!cbase) {
+ printf("ERROR CONDITION\nContext: %s\n", errorcontext);
+ free(abase);
+ free(bbase);
+ exit(1);
+ }
+
+ SetupCPUEmFloatArrays(abase, bbase, cbase, locemfloatstruct->arraysize); /* FIXME: ugly */
+
+ /*
+ ** See if we need to do self-adjusting code.
+ */
+ if( locemfloatstruct->adjust == 0 ) {
+ 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 = 1; loops < CPUEMFLOATLOOPMAX; loops += loops ) {
+ tickcount = DoEmFloatIteration(abase, bbase, cbase, /* FIXME: ugly */
+ locemfloatstruct->arraysize, loops);
+ if ( tickcount > global_min_ticks ) {
+ locemfloatstruct->loops = loops;
+ break;
+ }
+ }
+ }
+
+ /*
+ ** Verify that selft adjustment code worked.
+ */
+ if ( locemfloatstruct->loops == 0 ) {
+ puts("CPU:EMFPU -- CMPUEMFLOATLOOPMAX limit hit");
+ free(abase);
+ free(bbase);
+ free(cbase);
+ exit(1);
+ }
+
+ /*
+ ** 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.
+ */
+ 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 );
+
+ /*
+ ** 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;
+ }
}
diff --git a/numsort.c b/numsort.c
index 936b390..5756a31 100644
--- a/numsort.c
+++ b/numsort.c
@@ -25,24 +25,16 @@
** Not so; the routine returns # of iterations per sec.
*/
-void DoNumSort(void)
-{
-SortStruct *numsortstruct; /* Local pointer to global struct */
-long *arraybase; /* Base pointers of array */
-long accumtime; /* Accumulated time */
-double iterations; /* Iteration counter */
-char *errorcontext; /* Error context string pointer */
-int systemerror; /* For holding error codes */
+void DoNumSort(void) {
+ /* Error context string pointer */
+ const char *errorcontext = "CPU:Numeric Sort";
+ /* Local pointer to global struct */
+ SortStruct * numsortstruct = &global_numsortstruct;
-/*
-** Link to global structure
-*/
-numsortstruct=&global_numsortstruct;
-
-/*
-** Set the error context string.
-*/
-errorcontext="CPU:Numeric Sort";
+ long accumtime; /* Accumulated time */
+ double iterations; /* Iteration counter */
+ long *arraybase; /* Base pointers of array */
+ int systemerror; /* For holding error codes */
/*
** See if we need to do self adjustment code.
@@ -105,8 +97,8 @@ else
** All's well if we get here. Repeatedly perform sorts until the
** accumulated elapsed time is greater than # of seconds requested.
*/
-accumtime=0L;
-iterations=(double)0.0;
+accumtime = 0L;
+iterations = 0.0;
do {
accumtime+=DoNumSortIteration(arraybase,
@@ -127,11 +119,6 @@ numsortstruct->sortspersec=iterations *
if(numsortstruct->adjust==0)
numsortstruct->adjust=1;
-#ifdef DEBUG
-if (numsort_status==0) printf("Numeric sort: OK\n");
-numsort_status=0;
-#endif
-return;
}
/***********************
@@ -167,21 +154,6 @@ for(i=0;i<numarrays;i++)
** Get elapsed time
*/
elapsed=StopStopwatch(elapsed);
-#ifdef DEBUG
-{
- for(i=0;i<arraysize-1;i++)
- { /*
- ** Compare to check for proper
- ** sort.
- */
- if(arraybase[i+1]<arraybase[i])
- { printf("Sort Error\n");
- numsort_status=1;
- break;
- }
- }
-}
-#endif
return(elapsed);
}
@@ -264,29 +236,29 @@ return;
** Peforms the sift operation on a numeric array,
** constructing a heap in the array.
*/
-static void NumSift(long *array, /* Array of numbers */
- unsigned long i, /* Minimum of array */
- unsigned long j) /* Maximum of array */
+static void NumSift(long *array,/* Array of numbers */
+ unsigned long i, /* Minimum of array */
+ unsigned long j) /* Maximum of array */
{
-unsigned long k;
-long temp; /* Used for exchange */
+ unsigned long k;
+ unsigned long temp; /* Used for exchange */
-while((i+i)<=j)
-{
- k=i+i;
- if(k<j)
- if(array[k]<array[k+1L])
- ++k;
- if(array[i]<array[k])
- {
- temp=array[k];
- array[k]=array[i];
- array[i]=temp;
- i=k;
- }
- else
- i=j+1;
-}
-return;
+ while ( ( i + i ) <= j ) {
+ k = i + i;
+ if ( k < j ) {
+ if ( array[k] < array[k+1L] ) {
+ ++k;
+ }
+ }
+
+ if ( array[i] < array[k] ) {
+ temp = array[k];
+ array[k] = array[i];
+ array[i] = temp;
+ i = k;
+ } else {
+ i = j + 1;
+ }
+ }
}
diff --git a/sysspec.c b/sysspec.c
index ab6dc88..0f4e580 100644
--- a/sysspec.c
+++ b/sysspec.c
@@ -730,7 +730,7 @@ return;
** ReportError
** Report error message condition.
*/
-void ReportError(char *errorcontext, /* Error context string */
+void ReportError(const char *errorcontext, /* Error context string */
int errorcode) /* Error code number */
{
diff --git a/sysspec.h b/sysspec.h
index d612b78..af2bd27 100644
--- a/sysspec.h
+++ b/sysspec.h
@@ -110,7 +110,7 @@ int AddMemArray(unsigned long true_addr, unsigned long adj_addr);
int RemoveMemArray(unsigned long adj_addr,unsigned long *true_addr);
-void ReportError(char *context, int errorcode);
+void ReportError(const char *context, int errorcode);
void ErrorExit();