summaryrefslogtreecommitdiff
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
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
-rw-r--r--assignment.c1
-rw-r--r--bitfield.c1
-rw-r--r--fourier.c60
-rw-r--r--fpemulation.c1
-rw-r--r--huffman.c69
-rw-r--r--idea.c58
-rw-r--r--linear.c8
-rw-r--r--nbench1.h4
-rw-r--r--neural.c6
-rw-r--r--numsort.c1
-rw-r--r--stringsort.c37
11 files changed, 131 insertions, 115 deletions
diff --git a/assignment.c b/assignment.c
index 70bdb2a..7d83507 100644
--- a/assignment.c
+++ b/assignment.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
#include <math.h>
#include <limits.h>
diff --git a/bitfield.c b/bitfield.c
index 7b5a2ed..8256e52 100644
--- a/bitfield.c
+++ b/bitfield.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
#include <math.h>
#include <limits.h>
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);
diff --git a/fpemulation.c b/fpemulation.c
index 51f068a..e851cd9 100644
--- a/fpemulation.c
+++ b/fpemulation.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
#include <math.h>
#include <limits.h>
diff --git a/huffman.c b/huffman.c
index 063b2ad..9d6aa7e 100644
--- a/huffman.c
+++ b/huffman.c
@@ -1,9 +1,13 @@
-#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
+#include <math.h>
+#include <limits.h>
+
#include "nmglobal.h"
#include "nbench1.h"
-
/************************
** HUFFMAN COMPRESSION **
************************/
@@ -112,13 +116,13 @@ char *wordcatarray[WORDCATSIZE] = { /* FIXME: const? */
void DoHuffman(void)
{
HuffStruct *lochuffstruct; /* Loc pointer to global data */
-char *errorcontext;
+char *context;
int systemerror;
unsigned long accumtime;
double iterations;
-char *comparray;
-char *decomparray;
-char *plaintext;
+char *comparray = NULL;
+char *decomparray = NULL;
+char *plaintext = NULL;
/*
** Link to global data
@@ -128,7 +132,7 @@ lochuffstruct=&global_huffstruct;
/*
** Set error context.
*/
-errorcontext="CPU:Huffman";
+context="CPU:Huffman";
/*
** Allocate memory for the plaintext and the compressed text.
@@ -141,29 +145,34 @@ errorcontext="CPU:Huffman";
** than 512 bytes. This is actually a super-conservative
** estimate...but, who cares?)
*/
-plaintext=(char *)AllocateMemory(lochuffstruct->arraysize,&systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
+plaintext = malloc(lochuffstruct->arraysize);
+if (!plaintext) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ exit(1);
}
-comparray=(char *)AllocateMemory(lochuffstruct->arraysize,&systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
- FreeMemory(plaintext,&systemerror);
+
+comparray = malloc(lochuffstruct->arraysize);
+if (!comparray) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(plaintext);
+ exit(1); /* FIXME: do I need exits here? */
}
-decomparray=(char *)AllocateMemory(lochuffstruct->arraysize,&systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
- FreeMemory(plaintext,&systemerror);
- FreeMemory(comparray,&systemerror);
+
+decomparray = malloc(lochuffstruct->arraysize);
+if (!decomparray) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(plaintext);
+ free(comparray);
+ exit(1);
}
-hufftree=(huff_node *)AllocateMemory(sizeof(huff_node) * 512,
- &systemerror);
-if(systemerror)
-{ ReportError(errorcontext,systemerror);
- FreeMemory(plaintext,&systemerror);
- FreeMemory(comparray,&systemerror);
- FreeMemory(decomparray,&systemerror);
+hufftree = malloc(sizeof(huff_node) * 512);
+if (!hufftree) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(plaintext);
+ free(comparray);
+ free(decomparray);
+ exit(1);
}
/*
@@ -221,10 +230,10 @@ do {
** Clean up, calculate results, and go home. Be sure to
** show that we don't have to rerun adjustment code.
*/
-FreeMemory((void *)plaintext,&systemerror);
-FreeMemory((void *)comparray,&systemerror);
-FreeMemory((void *)decomparray,&systemerror);
-FreeMemory((void *)hufftree,&systemerror);
+free(plaintext);
+free(comparray);
+free(decomparray);
+free(hufftree);
lochuffstruct->iterspersec=iterations / TicksToFracSecs(accumtime);
if(lochuffstruct->adjust==0)
diff --git a/idea.c b/idea.c
index 54881f8..6198446 100644
--- a/idea.c
+++ b/idea.c
@@ -1,6 +1,13 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <math.h>
+#include <limits.h>
+
#include "nmglobal.h"
#include "nbench1.h"
+
/********************
** IDEA Encryption **
*********************
@@ -55,11 +62,10 @@ IDEAkey Z,DK;
uint16_t userkey[8];
unsigned long accumtime;
double iterations;
-char *errorcontext;
-int systemerror;
-unsigned char *plain1; /* First plaintext buffer */
-unsigned char *crypt1; /* Encryption buffer */
-unsigned char *plain2; /* Second plaintext buffer */
+char *context;
+unsigned char *plain1 = NULL; /* First plaintext buffer */
+unsigned char *crypt1 = NULL; /* Encryption buffer */
+unsigned char *plain2 = NULL; /* Second plaintext buffer */
/*
** Link to global data
@@ -69,7 +75,7 @@ locideastruct=&global_ideastruct;
/*
** Set error context
*/
-errorcontext="CPU:IDEA";
+context="CPU:IDEA";
/*
** Re-init random-number generator.
@@ -99,28 +105,25 @@ de_key_idea(Z,DK);
** So, plain1 and plain2 should match.
** Also, fill up plain1 with sample text.
*/
-plain1=(unsigned char *)AllocateMemory(locideastruct->arraysize,&systemerror);
-if(systemerror)
-{
- ReportError(errorcontext,systemerror);
- ErrorExit();
+plain1 = malloc(locideastruct->arraysize);
+if (!plain1) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ exit(1);
}
-crypt1=(unsigned char *)AllocateMemory(locideastruct->arraysize,&systemerror);
-if(systemerror)
-{
- ReportError(errorcontext,systemerror);
- FreeMemory((void *)plain1,&systemerror);
- ErrorExit();
+crypt1 = malloc(locideastruct->arraysize);
+if (!crypt1) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(plain1);
+ exit(1);
}
-plain2=(unsigned char *)AllocateMemory(locideastruct->arraysize,&systemerror);
-if(systemerror)
-{
- ReportError(errorcontext,systemerror);
- FreeMemory((void *)plain1,&systemerror);
- FreeMemory((void *)crypt1,&systemerror);
- ErrorExit();
+plain2 = malloc(locideastruct->arraysize);
+if (!plain2) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(plain1);
+ free(plain2);
+ exit(1);
}
/*
** Note that we build the "plaintext" by simply loading
@@ -165,9 +168,10 @@ do {
** Clean up, calculate results, and go home. Be sure to
** show that we don't have to rerun adjustment code.
*/
-FreeMemory((void *)plain1,&systemerror);
-FreeMemory((void *)crypt1,&systemerror);
-FreeMemory((void *)plain2,&systemerror);
+free(plain1);
+free(crypt1);
+free(plain2);
+
locideastruct->iterspersec=iterations / TicksToFracSecs(accumtime);
if(locideastruct->adjust==0)
diff --git a/linear.c b/linear.c
index 77fd52d..8b65510 100644
--- a/linear.c
+++ b/linear.c
@@ -1,12 +1,14 @@
#include <stdio.h>
-/*#include <stdlib.h>
+#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
-#include <strings.h>*/
#include <math.h>
-#include <stddef.h>
+#include <limits.h>
+
#include "nmglobal.h"
#include "nbench1.h"
+
/***********************
** LU DECOMPOSITION **
** (Linear Equations) **
diff --git a/nbench1.h b/nbench1.h
index 3c68e19..6d0f63a 100644
--- a/nbench1.h
+++ b/nbench1.h
@@ -45,6 +45,7 @@ extern HuffStruct global_huffstruct;
extern NNetStruct global_nnetstruct;
extern LUStruct global_lustruct;
+#if 0
/* External PROTOTYPES */
/*extern unsigned long abs_randwc(unsigned long num);*/ /* From MISC */
/*extern long randnum(long lngval);*/
@@ -63,7 +64,6 @@ extern unsigned long StartStopwatch();
extern unsigned long StopStopwatch(unsigned long startticks);
extern unsigned long TicksToSecs(unsigned long tickamount);
extern double TicksToFracSecs(unsigned long tickamount);
-
/*****************
** NUMERIC SORT **
*****************/
@@ -144,4 +144,4 @@ void DoNNET(void);
***********************/
void DoLU(void);
-
+#endif
diff --git a/neural.c b/neural.c
index a767fb4..7ce58c5 100644
--- a/neural.c
+++ b/neural.c
@@ -1,8 +1,10 @@
-#include <stdio.h> /*
+#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"
diff --git a/numsort.c b/numsort.c
index 34e685f..41928f8 100644
--- a/numsort.c
+++ b/numsort.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
#include <math.h>
#include <limits.h>
diff --git a/stringsort.c b/stringsort.c
index 7670dea..bf38981 100644
--- a/stringsort.c
+++ b/stringsort.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
#include <math.h>
#include <limits.h>
@@ -52,10 +53,10 @@ void DoStringSort(void)
{
SortStruct *strsortstruct; /* Local for sort structure */
-unsigned char *arraybase; /* Base pointer of char array */
+unsigned char *arraybase = NULL; /* Base pointer of char array */
long accumtime; /* Accumulated time */
double iterations; /* # of iterations */
-char *errorcontext; /* Error context string pointer */
+char *context; /* Error context string pointer */
int systemerror; /* For holding error code */
/*
@@ -66,7 +67,7 @@ strsortstruct=&global_strsortstruct;
/*
** Set the error context
*/
-errorcontext="CPU:String Sort";
+context="CPU:String Sort";
/*
** See if we have to perform self-adjustment code
@@ -84,10 +85,10 @@ if(strsortstruct->adjust==0)
** bytes to protect memory as strings move around
** (this can happen during string adjustment)
*/
- arraybase=(unsigned char *)AllocateMemory((strsortstruct->arraysize+100L) *
- (long)strsortstruct->numarrays,&systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
+ arraybase = realloc(arraybase, (strsortstruct->arraysize + 100) * strsortstruct->numarrays);
+ if (!arraybase) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ exit(1);
}
/*
@@ -101,7 +102,6 @@ if(strsortstruct->adjust==0)
strsortstruct->arraysize)>global_min_ticks)
break; /* We're ok...exit */
- FreeMemory((void *)arraybase,&systemerror);
strsortstruct->numarrays+=1;
}
}
@@ -111,11 +111,11 @@ else
** We don't have to perform self adjustment code.
** Simply allocate the space for the array.
*/
- arraybase=(unsigned char *)AllocateMemory((strsortstruct->arraysize+100L) *
- (long)strsortstruct->numarrays,&systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- }
+ arraybase = malloc((strsortstruct->arraysize + 100) * strsortstruct->numarrays);
+ if (!arraybase) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ exit(1);
+ }
}
/*
** All's well if we get here. Repeatedly perform sorts until the
@@ -322,12 +322,11 @@ while(k<numarrays)
** Now the array is full, allocate enough space for an
** offset pointer array.
*/
-optrarray=(unsigned long *)AllocateMemory(*nstrings * sizeof(unsigned long) *
- numarrays,
- &systemerror);
-if(systemerror)
-{ ReportError("CPU:Stringsort",systemerror);
- FreeMemory((void *)strarray,&systemerror);
+optrarray = malloc(*nstrings * sizeof(unsigned long) * numarrays);
+if (!optrarray) {
+ /* FIXME: add error message */
+ free(strarray);
+ exit(1);
}
/*