summaryrefslogtreecommitdiff
path: root/fourier.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-13 03:40:02 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-13 03:40:02 +0000
commit113c4ba4d6780449afd4681e56b6aba07908402f (patch)
treecd9336ae17b88153a4a1fc452ef6be1320f66ee7 /fourier.c
parent37438ca202a9a1f4e782f1d1803686fc6b65e918 (diff)
-- Still working toward killing nbench1.h
-- Removing AllocateMemory and FreeMemory calls git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@15 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
Diffstat (limited to 'fourier.c')
-rw-r--r--fourier.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/fourier.c b/fourier.c
index 4ce1153..5596e7a 100644
--- a/fourier.c
+++ b/fourier.c
@@ -1,9 +1,10 @@
-/*
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
-#include <strings.h>*/
#include <math.h>
+#include <limits.h>
+
#include "nmglobal.h"
#include "nbench1.h"
@@ -34,11 +35,11 @@ static double thefunction(double x,
void DoFourier(void)
{
FourierStruct *locfourierstruct; /* Local fourier struct */
-double *abase; /* Base of A[] coefficients array */
-double *bbase; /* Base of B[] coefficients array */
+double *abase = NULL; /* Base of A[] coefficients array */
+double *bbase = NULL; /* Base of B[] coefficients array */
unsigned long accumtime; /* Accumulated time in ticks */
double iterations; /* # of iterations */
-char *errorcontext; /* Error context string pointer */
+char *context; /* Error context string pointer */
int systemerror; /* For error code */
/*
@@ -49,7 +50,7 @@ locfourierstruct=&global_fourierstruct;
/*
** Set error context string
*/
-errorcontext="FPU:Transcendental";
+context="FPU:Transcendental";
/*
** See if we need to do self-adjustment code.
@@ -59,21 +60,18 @@ if(locfourierstruct->adjust==0)
locfourierstruct->arraysize=100L; /* Start at 100 elements */
while(1)
{
-
- abase=(double *)AllocateMemory(locfourierstruct->arraysize*sizeof(double),
- &systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- ErrorExit();
+ abase = realloc(abase, locfourierstruct->arraysize * sizeof(double));
+ if (!abase) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ exit(1);
}
- bbase=(double *)AllocateMemory(locfourierstruct->arraysize*sizeof(double),
- &systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- FreeMemory((void *)abase,&systemerror);
- ErrorExit();
- }
+ bbase = realloc(bbase, locfourierstruct->arraysize * sizeof(double));
+ if (!bbase) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(abase);
+ exit(1);
+ }
/*
** Do an iteration of the tests. If the elapsed time is
** less than or equal to the permitted minimum, re-allocate
@@ -96,19 +94,17 @@ else
** Don't need self-adjustment. Just allocate the
** arrays, and go.
*/
- abase=(double *)AllocateMemory(locfourierstruct->arraysize*sizeof(double),
- &systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- ErrorExit();
+ abase = malloc(locfourierstruct->arraysize * sizeof(double));
+ if (!abase) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ exit(1);
}
- bbase=(double *)AllocateMemory(locfourierstruct->arraysize*sizeof(double),
- &systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- FreeMemory((void *)abase,&systemerror);
- ErrorExit();
+ bbase = malloc(locfourierstruct->arraysize * sizeof(double));
+ if (!bbase) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(abase);
+ exit(1);
}
}
/*
@@ -128,8 +124,8 @@ do {
** Clean up, calculate results, and go home.
** Also set adjustment flag to indicate no adjust code needed.
*/
-FreeMemory((void *)abase,&systemerror);
-FreeMemory((void *)bbase,&systemerror);
+free(abase);
+free(bbase);
locfourierstruct->fflops=iterations/(double)TicksToFracSecs(accumtime);