From 37438ca202a9a1f4e782f1d1803686fc6b65e918 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Wed, 12 Nov 2008 23:25:26 +0000 Subject: Move static function prototypes from nbench1.h to appropriate files git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@14 0d43b9a7-5ab2-4d7b-af9d-f64450cef757 --- assignment.c | 34 ++++++++ bitfield.c | 12 +++ fourier.c | 12 +++ fpemulation.c | 1 + huffman.c | 51 ++++++++++-- idea.c | 30 +++++++ linear.c | 40 +++++++++ nbench1.h | 264 +--------------------------------------------------------- neural.c | 75 +++++++++++++++-- nmglobal.h | 2 + stringsort.c | 52 ++++++++---- 11 files changed, 283 insertions(+), 290 deletions(-) diff --git a/assignment.c b/assignment.c index 29f79c8..70bdb2a 100644 --- a/assignment.c +++ b/assignment.c @@ -12,6 +12,40 @@ ** ASSIGNMENT ALGORITHM ** *************************/ +/* +** DEFINES +*/ + +#define ASSIGNROWS 101L +#define ASSIGNCOLS 101L + +/* +** TYPEDEFS +*/ +typedef struct { + union { + long *p; + long (*ap)[ASSIGNROWS][ASSIGNCOLS]; + } ptrs; +} longptr; + +/* +** PROTOTYPES +*/ +static unsigned long DoAssignIteration(long *arraybase, + unsigned long numarrays); +static void LoadAssignArrayWithRand(long *arraybase, + unsigned long numarrays); +static void LoadAssign(long arraybase[][ASSIGNCOLS]); +static void CopyToAssign(long arrayfrom[][ASSIGNCOLS], + long arrayto[][ASSIGNCOLS]); +static void Assignment(long arraybase[][ASSIGNCOLS]); +static void calc_minimum_costs(long tableau[][ASSIGNCOLS]); +static int first_assignments(long tableau[][ASSIGNCOLS], + short assignedtableau[][ASSIGNCOLS]); +static void second_assignments(long tableau[][ASSIGNCOLS], + short assignedtableau[][ASSIGNCOLS]); + /************* ** DoAssign ** ************** diff --git a/bitfield.c b/bitfield.c index 5f85e34..7b5a2ed 100644 --- a/bitfield.c +++ b/bitfield.c @@ -12,6 +12,18 @@ ** BITFIELD OPERATIONS ** *************************/ +static unsigned long DoBitfieldIteration(unsigned long *bitarraybase, + unsigned long *bitoparraybase, + long bitoparraysize, + unsigned long *nbitops); +static void ToggleBitRun(unsigned long *bitmap, + unsigned long bit_addr, + unsigned long nbits, + unsigned int val); +static void FlipBitRun(unsigned long *bitmap, + unsigned long bit_addr, + unsigned long nbits); + /************* ** DoBitops ** ************** diff --git a/fourier.c b/fourier.c index b6f40c8..4ce1153 100644 --- a/fourier.c +++ b/fourier.c @@ -11,6 +11,18 @@ ** FOURIER COEFFICIENTS ** *************************/ +static unsigned long DoFPUTransIteration(double *abase, + double *bbase, + unsigned long arraysize); +static double TrapezoidIntegrate(double x0, + double x1, + int nsteps, + double omegan, + int select); +static double thefunction(double x, + double omegan, + int select); + /************** ** DoFourier ** *************** diff --git a/fpemulation.c b/fpemulation.c index ac24bd9..51f068a 100644 --- a/fpemulation.c +++ b/fpemulation.c @@ -6,6 +6,7 @@ #include "nmglobal.h" #include "nbench1.h" +#include "emfloat.h" /***************************** diff --git a/huffman.c b/huffman.c index 961fc08..063b2ad 100644 --- a/huffman.c +++ b/huffman.c @@ -3,13 +3,52 @@ #include "nmglobal.h" #include "nbench1.h" + +/************************ +** HUFFMAN COMPRESSION ** +************************/ + +/* +** DEFINES +*/ +#define EXCLUDED 32000L /* Big positive value */ + +/* +** TYPEDEFS +*/ +typedef struct { + unsigned char c; /* Byte value */ + float freq; /* Frequency */ + int parent; /* Parent node */ + int left; /* Left pointer = 0 */ + int right; /* Right pointer = 1 */ +} huff_node; + +/* +** GLOBALS +*/ +static huff_node *hufftree; /* The huffman tree */ +static long plaintextlen; /* Length of plaintext */ + +/* +** PROTOTYPES +*/ +static void create_text_line(char *dt,long nchars); +static void create_text_block(char *tb, unsigned long tblen, + unsigned short maxlinlen); +static unsigned long DoHuffIteration(char *plaintext, + char *comparray, char *decomparray, + unsigned long arraysize, unsigned long nloops, huff_node *hufftree); +static void SetCompBit(uint8_t *comparray, uint32_t bitoffset, char bitchar); +static int GetCompBit(uint8_t *comparray, uint32_t bitoffset); + /* ** Word catalog */ #define WORDCATSIZE 50 -char *wordcatarray[WORDCATSIZE] = -{ "Hello", +char *wordcatarray[WORDCATSIZE] = { /* FIXME: const? */ + "Hello", "He", "Him", "the", @@ -58,12 +97,8 @@ char *wordcatarray[WORDCATSIZE] = "used", "shown", "you", - "know" }; - - -/************************ -** HUFFMAN COMPRESSION ** -************************/ + "know" +}; /************** ** DoHuffman ** diff --git a/idea.c b/idea.c index 464dc74..54881f8 100644 --- a/idea.c +++ b/idea.c @@ -11,6 +11,36 @@ ** */ +/* +** DEFINES +*/ +#define IDEAKEYSIZE 16 +#define IDEABLOCKSIZE 8 +#define ROUNDS 8 +#define KEYLEN (6*ROUNDS+4) + +/* +** MACROS +*/ +#define low16(x) ((x) & 0x0FFFF) +#define MUL(x,y) (x=mul(low16(x),y)) + + +typedef uint16_t IDEAkey[KEYLEN]; + +/* +** PROTOTYPES +*/ +static unsigned long DoIDEAIteration(unsigned char *plain1, + unsigned char *crypt1, unsigned char *plain2, + unsigned long arraysize, unsigned long nloops, + IDEAkey Z, IDEAkey DK); +static uint16_t mul(register uint16_t a, register uint16_t b); +static uint16_t inv(uint16_t x); +static void en_key_idea(uint16_t userkey[8], IDEAkey Z); +static void de_key_idea(IDEAkey Z, IDEAkey DK); +static void cipher_idea(uint16_t in[4], uint16_t out[4], IDEAkey Z); + /*********** ** DoIDEA ** ************ diff --git a/linear.c b/linear.c index 714eef1..77fd52d 100644 --- a/linear.c +++ b/linear.c @@ -18,6 +18,46 @@ ** matrix). */ +/* +** DEFINES +*/ + +#define LUARRAYROWS 101L +#define LUARRAYCOLS 101L + +/* +** TYPEDEFS +*/ +typedef struct +{ union + { double *p; + double (*ap)[][LUARRAYCOLS]; + } ptrs; +} LUdblptr; + +/* +** GLOBALS +*/ +double *LUtempvv; + +/* +** PROTOTYPES +*/ +static void LUFreeMem(double *a, double *b, + double *abase, double *bbase); +static unsigned long DoLUIteration(double *a, double *b, + double *abase, double *bbase, + unsigned long numarrays); +static void build_problem( double a[][LUARRAYCOLS], + int n, double b[LUARRAYROWS]); +static int ludcmp(double a[][LUARRAYCOLS], + int n, int indx[], int *d); +static void lubksb(double a[][LUARRAYCOLS], + int n, int indx[LUARRAYROWS], + double b[LUARRAYROWS]); +static int lusolve(double a[][LUARRAYCOLS], + int n, double b[LUARRAYROWS]); + /********* ** DoLU ** ********** diff --git a/nbench1.h b/nbench1.h index 7d53d5a..3c68e19 100644 --- a/nbench1.h +++ b/nbench1.h @@ -83,33 +83,6 @@ void DoNumSort(void); ** PROTOTYPES */ void DoStringSort(void); -static unsigned long DoStringSortIteration(unsigned char *arraybase, - unsigned int numarrays, - unsigned long arraysize); -static unsigned long *LoadStringArray(unsigned char *strarray, - unsigned int numarrays, - unsigned long *strings, - unsigned long arraysize); -static void stradjust(unsigned long *optrarray, - unsigned char *strarray, - unsigned long nstrings, - unsigned long i, - unsigned char l); -static void StrHeapSort(unsigned long *optrarray, - unsigned char *strarray, - unsigned long numstrings, - unsigned long bottom, - unsigned long top); -static int str_is_less(unsigned long *optrarray, - unsigned char *strarray, - unsigned long numstrings, - unsigned long a, - unsigned long b); -static void strsift(unsigned long *optrarray, - unsigned char *strarray, - unsigned long numstrings, - unsigned long i, - unsigned long j); /************************ ** BITFIELD OPERATIONS ** @@ -120,43 +93,16 @@ static void strsift(unsigned long *optrarray, ** PROTOTYPES */ void DoBitops(void); -static unsigned long DoBitfieldIteration(unsigned long *bitarraybase, - unsigned long *bitoparraybase, - long bitoparraysize, - unsigned long *nbitops); -static void ToggleBitRun(unsigned long *bitmap, - unsigned long bit_addr, - unsigned long nbits, - unsigned int val); -static void FlipBitRun(unsigned long *bitmap, - unsigned long bit_addr, - unsigned long nbits); /**************************** ** EMULATED FLOATING POINT ** ****************************/ -typedef struct -{ - uint8_t type; /* Indicates, NORMAL, SUBNORMAL, etc. */ - uint8_t sign; /* Mantissa sign */ - short exp; /* Signed exponent...no bias */ - uint16_t mantissa[INTERNAL_FPF_PRECISION]; -} InternalFPF; /* ** PROTOTYPES */ void DoEmFloat(void); -/* -** EXTERNALS -*/ -extern void SetupCPUEmFloatArrays(InternalFPF *abase, - InternalFPF *bbase, InternalFPF *cbase, - unsigned long arraysize); -extern unsigned long DoEmFloatIteration(InternalFPF *abase, - InternalFPF *bbase, InternalFPF *cbase, - unsigned long arraysize, unsigned long loops); /************************* ** FOURIER COEFFICIENTS ** @@ -166,244 +112,36 @@ extern unsigned long DoEmFloatIteration(InternalFPF *abase, ** PROTOTYPES */ void DoFourier(void); -static unsigned long DoFPUTransIteration(double *abase, - double *bbase, - unsigned long arraysize); -static double TrapezoidIntegrate(double x0, - double x1, - int nsteps, - double omegan, - int select); -static double thefunction(double x, - double omegan, - int select); /************************* ** ASSIGNMENT ALGORITHM ** *************************/ -/* -** DEFINES -*/ - -#define ASSIGNROWS 101L -#define ASSIGNCOLS 101L - -/* -** TYPEDEFS -*/ -typedef struct { - union { - long *p; - long (*ap)[ASSIGNROWS][ASSIGNCOLS]; - } ptrs; -} longptr; - -/* -** PROTOTYPES -*/ void DoAssign(void); -static unsigned long DoAssignIteration(long *arraybase, - unsigned long numarrays); -static void LoadAssignArrayWithRand(long *arraybase, - unsigned long numarrays); -static void LoadAssign(long arraybase[][ASSIGNCOLS]); -static void CopyToAssign(long arrayfrom[][ASSIGNCOLS], - long arrayto[][ASSIGNCOLS]); -static void Assignment(long arraybase[][ASSIGNCOLS]); -static void calc_minimum_costs(long tableau[][ASSIGNCOLS]); -static int first_assignments(long tableau[][ASSIGNCOLS], - short assignedtableau[][ASSIGNCOLS]); -static void second_assignments(long tableau[][ASSIGNCOLS], - short assignedtableau[][ASSIGNCOLS]); /******************** ** IDEA ENCRYPTION ** ********************/ -/* -** DEFINES -*/ -#define IDEAKEYSIZE 16 -#define IDEABLOCKSIZE 8 -#define ROUNDS 8 -#define KEYLEN (6*ROUNDS+4) - -/* -** MACROS -*/ -#define low16(x) ((x) & 0x0FFFF) -#define MUL(x,y) (x=mul(low16(x),y)) - - -typedef uint16_t IDEAkey[KEYLEN]; - -/* -** PROTOTYPES -*/ void DoIDEA(void); -static unsigned long DoIDEAIteration(unsigned char *plain1, - unsigned char *crypt1, unsigned char *plain2, - unsigned long arraysize, unsigned long nloops, - IDEAkey Z, IDEAkey DK); -static uint16_t mul(register uint16_t a, register uint16_t b); -static uint16_t inv(uint16_t x); -static void en_key_idea(uint16_t userkey[8], IDEAkey Z); -static void de_key_idea(IDEAkey Z, IDEAkey DK); -static void cipher_idea(uint16_t in[4], uint16_t out[4], IDEAkey Z); /************************ ** HUFFMAN COMPRESSION ** ************************/ -/* -** DEFINES -*/ -#define EXCLUDED 32000L /* Big positive value */ +void DoHuffman(void); -/* -** TYPEDEFS -*/ -typedef struct { - unsigned char c; /* Byte value */ - float freq; /* Frequency */ - int parent; /* Parent node */ - int left; /* Left pointer = 0 */ - int right; /* Right pointer = 1 */ -} huff_node; - -/* -** GLOBALS -*/ -static huff_node *hufftree; /* The huffman tree */ -static long plaintextlen; /* Length of plaintext */ - -/* -** PROTOTYPES -*/ -void DoHuffman(); -static void create_text_line(char *dt,long nchars); -static void create_text_block(char *tb, unsigned long tblen, - unsigned short maxlinlen); -static unsigned long DoHuffIteration(char *plaintext, - char *comparray, char *decomparray, - unsigned long arraysize, unsigned long nloops, huff_node *hufftree); -static void SetCompBit(uint8_t *comparray, uint32_t bitoffset, char bitchar); -static int GetCompBit(uint8_t *comparray, uint32_t bitoffset); /******************************** ** BACK PROPAGATION NEURAL NET ** ********************************/ -/* -** DEFINES -*/ -#define T 1 /* TRUE */ -#define F 0 /* FALSE */ -#define ERR -1 -#define MAXPATS 10 /* max number of patterns in data file */ -#define IN_X_SIZE 5 /* number of neurodes/row of input layer */ -#define IN_Y_SIZE 7 /* number of neurodes/col of input layer */ -#define IN_SIZE 35 /* equals IN_X_SIZE*IN_Y_SIZE */ -#define MID_SIZE 8 /* number of neurodes in middle layer */ -#define OUT_SIZE 8 /* number of neurodes in output layer */ -#define MARGIN 0.1 /* how near to 1,0 do we have to come to stop? */ -#define BETA 0.09 /* beta learning constant */ -#define ALPHA 0.09 /* momentum term constant */ -#define STOP 0.1 /* when worst_error less than STOP, training is done */ - -/* -** GLOBALS -*/ -double mid_wts[MID_SIZE][IN_SIZE]; /* middle layer weights */ -double out_wts[OUT_SIZE][MID_SIZE]; /* output layer weights */ -double mid_out[MID_SIZE]; /* middle layer output */ -double out_out[OUT_SIZE]; /* output layer output */ -double mid_error[MID_SIZE]; /* middle layer errors */ -double out_error[OUT_SIZE]; /* output layer errors */ -double mid_wt_change[MID_SIZE][IN_SIZE]; /* storage for last wt change */ -double out_wt_change[OUT_SIZE][MID_SIZE]; /* storage for last wt change */ -double in_pats[MAXPATS][IN_SIZE]; /* input patterns */ -double out_pats[MAXPATS][OUT_SIZE]; /* desired output patterns */ -double tot_out_error[MAXPATS]; /* measure of whether net is done */ -double out_wt_cum_change[OUT_SIZE][MID_SIZE]; /* accumulated wt changes */ -double mid_wt_cum_change[MID_SIZE][IN_SIZE]; /* accumulated wt changes */ - -double worst_error; /* worst error each pass through the data */ -double average_error; /* average error each pass through the data */ -double avg_out_error[MAXPATS]; /* average error each pattern */ - -int iteration_count; /* number of passes thru network so far */ -int numpats; /* number of patterns in data file */ -int numpasses; /* number of training passes through data file */ -int learned; /* flag--if TRUE, network has learned all patterns */ - -/* -** PROTOTYPES -*/ void DoNNET(void); -static unsigned long DoNNetIteration(unsigned long nloops); -static void do_mid_forward(int patt); -static void do_out_forward(); -void display_output(int patt); -static void do_forward_pass(int patt); -static void do_out_error(int patt); -static void worst_pass_error(); -static void do_mid_error(); -static void adjust_out_wts(); -static void adjust_mid_wts(); -static void do_back_pass(int patt); -static void move_wt_changes(); -static int check_out_error(); -static void zero_changes(); -static void randomize_wts(); -static int read_data_file(); -/* static int initialize_net(); */ /*********************** ** LU DECOMPOSITION ** ** (Linear Equations) ** ***********************/ -/* -** DEFINES -*/ - -#define LUARRAYROWS 101L -#define LUARRAYCOLS 101L - -/* -** TYPEDEFS -*/ -typedef struct -{ union - { double *p; - double (*ap)[][LUARRAYCOLS]; - } ptrs; -} LUdblptr; - -/* -** GLOBALS -*/ -double *LUtempvv; - -/* -** PROTOTYPES -*/ void DoLU(void); -static void LUFreeMem(double *a, double *b, - double *abase, double *bbase); -static unsigned long DoLUIteration(double *a, double *b, - double *abase, double *bbase, - unsigned long numarrays); -static void build_problem( double a[][LUARRAYCOLS], - int n, double b[LUARRAYROWS]); -static int ludcmp(double a[][LUARRAYCOLS], - int n, int indx[], int *d); -static void lubksb(double a[][LUARRAYCOLS], - int n, int indx[LUARRAYROWS], - double b[LUARRAYROWS]); -static int lusolve(double a[][LUARRAYCOLS], - int n, double b[LUARRAYROWS]); - diff --git a/neural.c b/neural.c index 04d49fe..a767fb4 100644 --- a/neural.c +++ b/neural.c @@ -6,11 +6,6 @@ #include "nmglobal.h" #include "nbench1.h" -/* -** The Neural Net test requires an input data file. -** The name is specified here. -*/ -char *inpath="NNET.DAT"; /******************************** ** BACK PROPAGATION NEURAL NET ** @@ -37,6 +32,76 @@ char *inpath="NNET.DAT"; ** on systems other than a Macintosh -- RG */ +/* +** DEFINES +*/ +#define T 1 /* TRUE */ +#define F 0 /* FALSE */ +#define ERR -1 +#define MAXPATS 10 /* max number of patterns in data file */ +#define IN_X_SIZE 5 /* number of neurodes/row of input layer */ +#define IN_Y_SIZE 7 /* number of neurodes/col of input layer */ +#define IN_SIZE 35 /* equals IN_X_SIZE*IN_Y_SIZE */ +#define MID_SIZE 8 /* number of neurodes in middle layer */ +#define OUT_SIZE 8 /* number of neurodes in output layer */ +#define MARGIN 0.1 /* how near to 1,0 do we have to come to stop? */ +#define BETA 0.09 /* beta learning constant */ +#define ALPHA 0.09 /* momentum term constant */ +#define STOP 0.1 /* when worst_error less than STOP, training is done */ + +/* +** The Neural Net test requires an input data file. +** The name is specified here. +*/ +char *inpath="NNET.DAT"; + +/* +** GLOBALS +*/ +double mid_wts[MID_SIZE][IN_SIZE]; /* middle layer weights */ +double out_wts[OUT_SIZE][MID_SIZE]; /* output layer weights */ +double mid_out[MID_SIZE]; /* middle layer output */ +double out_out[OUT_SIZE]; /* output layer output */ +double mid_error[MID_SIZE]; /* middle layer errors */ +double out_error[OUT_SIZE]; /* output layer errors */ +double mid_wt_change[MID_SIZE][IN_SIZE]; /* storage for last wt change */ +double out_wt_change[OUT_SIZE][MID_SIZE]; /* storage for last wt change */ +double in_pats[MAXPATS][IN_SIZE]; /* input patterns */ +double out_pats[MAXPATS][OUT_SIZE]; /* desired output patterns */ +double tot_out_error[MAXPATS]; /* measure of whether net is done */ +double out_wt_cum_change[OUT_SIZE][MID_SIZE]; /* accumulated wt changes */ +double mid_wt_cum_change[MID_SIZE][IN_SIZE]; /* accumulated wt changes */ + +double worst_error; /* worst error each pass through the data */ +double average_error; /* average error each pass through the data */ +double avg_out_error[MAXPATS]; /* average error each pattern */ + +int iteration_count; /* number of passes thru network so far */ +int numpats; /* number of patterns in data file */ +int numpasses; /* number of training passes through data file */ +int learned; /* flag--if TRUE, network has learned all patterns */ + +/* +** PROTOTYPES +*/ +static unsigned long DoNNetIteration(unsigned long nloops); +static void do_mid_forward(int patt); +static void do_out_forward(); +void display_output(int patt); +static void do_forward_pass(int patt); +static void do_out_error(int patt); +static void worst_pass_error(); +static void do_mid_error(); +static void adjust_out_wts(); +static void adjust_mid_wts(); +static void do_back_pass(int patt); +static void move_wt_changes(); +static int check_out_error(); +static void zero_changes(); +static void randomize_wts(); +static int read_data_file(); +/* static int initialize_net(); */ + /*********** ** DoNNet ** ************ diff --git a/nmglobal.h b/nmglobal.h index cb7a6e3..f99b376 100644 --- a/nmglobal.h +++ b/nmglobal.h @@ -29,6 +29,8 @@ ** SYSTEM DEFINES */ #include +#define TRUE 1 +#define FALSE 0 /* +++ MEMORY +++ */ diff --git a/stringsort.c b/stringsort.c index 5d7c67d..7670dea 100644 --- a/stringsort.c +++ b/stringsort.c @@ -1,21 +1,45 @@ -#include -/*#include +#include #include -#include -#include -#include */ +#include +#include +#include + #include "nmglobal.h" #include "nbench1.h" -#ifdef DEBUG -static int numsort_status=0; -static int stringsort_status=0; -#endif /******************** ** STRING HEAPSORT ** ********************/ +static unsigned long DoStringSortIteration(unsigned char *arraybase, + unsigned int numarrays, + unsigned long arraysize); +static unsigned long *LoadStringArray(unsigned char *strarray, + unsigned int numarrays, + unsigned long *strings, + unsigned long arraysize); +static void stradjust(unsigned long *optrarray, + unsigned char *strarray, + unsigned long nstrings, + unsigned long i, + unsigned char l); +static void StrHeapSort(unsigned long *optrarray, + unsigned char *strarray, + unsigned long numstrings, + unsigned long bottom, + unsigned long top); +static int str_is_less(unsigned long *optrarray, + unsigned char *strarray, + unsigned long numstrings, + unsigned long a, + unsigned long b); +static void strsift(unsigned long *optrarray, + unsigned char *strarray, + unsigned long numstrings, + unsigned long i, + unsigned long j); + /***************** ** DoStringSort ** ****************** @@ -504,18 +528,18 @@ slen=strncmp((char *)(strarray+*(optrarray+a)), if(slen==0) { /* - ** They match. Return true if the length of a + ** They match. Return TRUE if the length of a ** is greater than the length of b. */ if(*(strarray+*(optrarray+a)) > *(strarray+*(optrarray+b))) - return(TRUE); - return(FALSE); + return TRUE; + return FALSE; } -if(slen<0) return(TRUE); /* a is strictly less than b */ +if(slen<0) return TRUE; /* a is strictly less than b */ -return(FALSE); /* Only other possibility */ +return FALSE; /* Only other possibility */ } /************ -- cgit v1.2.3