3 ** Header for nbench1.c
5 ** BYTE's Native Mode Benchmarks
6 ** Rick Grehan, BYTE Magazine
9 ** Revision: 3/95;10/95
12 ** The source, executable, and documentation files that comprise
13 ** the BYTEmark benchmarks are made available on an "as is" basis.
14 ** This means that we at BYTE Magazine have made every reasonable
15 ** effort to verify that the there are no errors in the source and
16 ** executable code. We cannot, however, guarantee that the programs
17 ** are error-free. Consequently, McGraw-HIll and BYTE Magazine make
18 ** no claims in regard to the fitness of the source code, executable
19 ** code, and documentation of the BYTEmark.
20 ** Furthermore, BYTE Magazine, McGraw-Hill, and all employees
21 ** of McGraw-Hill cannot be held responsible for any damages resulting
22 ** from the use of this code or the results obtained from using
34 extern ulong global_min_ticks;
36 extern SortStruct global_numsortstruct;
37 extern SortStruct global_strsortstruct;
38 extern BitOpStruct global_bitopstruct;
39 extern EmFloatStruct global_emfloatstruct;
40 extern FourierStruct global_fourierstruct;
41 extern AssignStruct global_assignstruct;
42 extern IDEAStruct global_ideastruct;
43 extern HuffStruct global_huffstruct;
44 extern NNetStruct global_nnetstruct;
45 extern LUStruct global_lustruct;
47 /* External PROTOTYPES */
48 /*extern unsigned long abs_randwc(unsigned long num);*/ /* From MISC */
49 /*extern long randnum(long lngval);*/
50 extern int32 randwc(int32 num);
51 extern u32 abs_randwc(u32 num);
52 extern int32 randnum(int32 lngval);
54 extern farvoid *AllocateMemory(unsigned long nbytes, /* From SYSSPEC */
56 extern void FreeMemory(farvoid *mempointer,
58 extern void MoveMemory(farvoid *destination,
59 farvoid *source, unsigned long nbytes);
60 extern void ReportError(char *context, int errorcode);
61 extern void ErrorExit();
62 extern unsigned long StartStopwatch();
63 extern unsigned long StopStopwatch(unsigned long startticks);
64 extern unsigned long TicksToSecs(unsigned long tickamount);
65 extern double TicksToFracSecs(unsigned long tickamount);
75 static ulong DoNumSortIteration(farlong *arraybase,
78 static void LoadNumArrayWithRand(farlong *array,
81 static void NumHeapSort(farlong *array,
84 static void NumSift(farlong *array,
98 void DoStringSort(void);
99 static ulong DoStringSortIteration(faruchar *arraybase,
102 static farulong *LoadStringArray(faruchar *strarray,
106 static void stradjust(farulong *optrarray,
111 static void StrHeapSort(farulong *optrarray,
116 static int str_is_less(farulong *optrarray,
121 static void strsift(farulong *optrarray,
127 /************************
128 ** BITFIELD OPERATIONS **
129 *************************
136 static ulong DoBitfieldIteration(farulong *bitarraybase,
137 farulong *bitoparraybase,
140 static void ToggleBitRun(farulong *bitmap,
144 static void FlipBitRun(farulong *bitmap,
148 /****************************
149 ** EMULATED FLOATING POINT **
150 ****************************/
153 u8 type; /* Indicates, NORMAL, SUBNORMAL, etc. */
154 u8 sign; /* Mantissa sign */
155 short exp; /* Signed exponent...no bias */
156 u16 mantissa[INTERNAL_FPF_PRECISION];
162 void DoEmFloat(void);
167 extern void SetupCPUEmFloatArrays(InternalFPF *abase,
168 InternalFPF *bbase, InternalFPF *cbase,
170 extern ulong DoEmFloatIteration(InternalFPF *abase,
171 InternalFPF *bbase, InternalFPF *cbase,
172 ulong arraysize, ulong loops);
174 /*************************
175 ** FOURIER COEFFICIENTS **
176 *************************/
181 void DoFourier(void);
182 static ulong DoFPUTransIteration(fardouble *abase,
185 static double TrapezoidIntegrate(double x0,
190 static double thefunction(double x,
194 /*************************
195 ** ASSIGNMENT ALGORITHM **
196 *************************/
202 #define ASSIGNROWS 101L
203 #define ASSIGNCOLS 101L
211 long (*ap)[ASSIGNROWS][ASSIGNCOLS];
219 static ulong DoAssignIteration(farlong *arraybase,
221 static void LoadAssignArrayWithRand(farlong *arraybase,
223 static void LoadAssign(farlong arraybase[][ASSIGNCOLS]);
224 static void CopyToAssign(farlong arrayfrom[][ASSIGNCOLS],
225 long arrayto[][ASSIGNCOLS]);
226 static void Assignment(farlong arraybase[][ASSIGNCOLS]);
227 static void calc_minimum_costs(long tableau[][ASSIGNCOLS]);
228 static int first_assignments(long tableau[][ASSIGNCOLS],
229 short assignedtableau[][ASSIGNCOLS]);
230 static void second_assignments(long tableau[][ASSIGNCOLS],
231 short assignedtableau[][ASSIGNCOLS]);
233 /********************
234 ** IDEA ENCRYPTION **
235 ********************/
240 #define IDEAKEYSIZE 16
241 #define IDEABLOCKSIZE 8
243 #define KEYLEN (6*ROUNDS+4)
248 #define low16(x) ((x) & 0x0FFFF)
249 #define MUL(x,y) (x=mul(low16(x),y))
252 typedef u16 IDEAkey[KEYLEN];
258 static ulong DoIDEAIteration(faruchar *plain1,
259 faruchar *crypt1, faruchar *plain2,
260 ulong arraysize, ulong nloops,
261 IDEAkey Z, IDEAkey DK);
262 static u16 mul(register u16 a, register u16 b);
263 static u16 inv(u16 x);
264 static void en_key_idea(u16 userkey[8], IDEAkey Z);
265 static void de_key_idea(IDEAkey Z, IDEAkey DK);
266 static void cipher_idea(u16 in[4], u16 out[4], IDEAkey Z);
268 /************************
269 ** HUFFMAN COMPRESSION **
270 ************************/
275 #define EXCLUDED 32000L /* Big positive value */
281 uchar c; /* Byte value */
282 float freq; /* Frequency */
283 int parent; /* Parent node */
284 int left; /* Left pointer = 0 */
285 int right; /* Right pointer = 1 */
291 static huff_node *hufftree; /* The huffman tree */
292 static long plaintextlen; /* Length of plaintext */
298 static void create_text_line(farchar *dt,long nchars);
299 static void create_text_block(farchar *tb, ulong tblen,
301 static ulong DoHuffIteration(farchar *plaintext,
302 farchar *comparray, farchar *decomparray,
303 ulong arraysize, ulong nloops, huff_node *hufftree);
304 static void SetCompBit(u8 *comparray, u32 bitoffset, char bitchar);
305 static int GetCompBit(u8 *comparray, u32 bitoffset);
307 /********************************
308 ** BACK PROPAGATION NEURAL NET **
309 ********************************/
314 #define T 1 /* TRUE */
315 #define F 0 /* FALSE */
317 #define MAXPATS 10 /* max number of patterns in data file */
318 #define IN_X_SIZE 5 /* number of neurodes/row of input layer */
319 #define IN_Y_SIZE 7 /* number of neurodes/col of input layer */
320 #define IN_SIZE 35 /* equals IN_X_SIZE*IN_Y_SIZE */
321 #define MID_SIZE 8 /* number of neurodes in middle layer */
322 #define OUT_SIZE 8 /* number of neurodes in output layer */
323 #define MARGIN 0.1 /* how near to 1,0 do we have to come to stop? */
324 #define BETA 0.09 /* beta learning constant */
325 #define ALPHA 0.09 /* momentum term constant */
326 #define STOP 0.1 /* when worst_error less than STOP, training is done */
331 double mid_wts[MID_SIZE][IN_SIZE]; /* middle layer weights */
332 double out_wts[OUT_SIZE][MID_SIZE]; /* output layer weights */
333 double mid_out[MID_SIZE]; /* middle layer output */
334 double out_out[OUT_SIZE]; /* output layer output */
335 double mid_error[MID_SIZE]; /* middle layer errors */
336 double out_error[OUT_SIZE]; /* output layer errors */
337 double mid_wt_change[MID_SIZE][IN_SIZE]; /* storage for last wt change */
338 double out_wt_change[OUT_SIZE][MID_SIZE]; /* storage for last wt change */
339 double in_pats[MAXPATS][IN_SIZE]; /* input patterns */
340 double out_pats[MAXPATS][OUT_SIZE]; /* desired output patterns */
341 double tot_out_error[MAXPATS]; /* measure of whether net is done */
342 double out_wt_cum_change[OUT_SIZE][MID_SIZE]; /* accumulated wt changes */
343 double mid_wt_cum_change[MID_SIZE][IN_SIZE]; /* accumulated wt changes */
345 double worst_error; /* worst error each pass through the data */
346 double average_error; /* average error each pass through the data */
347 double avg_out_error[MAXPATS]; /* average error each pattern */
349 int iteration_count; /* number of passes thru network so far */
350 int numpats; /* number of patterns in data file */
351 int numpasses; /* number of training passes through data file */
352 int learned; /* flag--if TRUE, network has learned all patterns */
355 ** The Neural Net test requires an input data file.
356 ** The name is specified here.
358 char *inpath="NNET.DAT";
364 static ulong DoNNetIteration(ulong nloops);
365 static void do_mid_forward(int patt);
366 static void do_out_forward();
367 void display_output(int patt);
368 static void do_forward_pass(int patt);
369 static void do_out_error(int patt);
370 static void worst_pass_error();
371 static void do_mid_error();
372 static void adjust_out_wts();
373 static void adjust_mid_wts();
374 static void do_back_pass(int patt);
375 static void move_wt_changes();
376 static int check_out_error();
377 static void zero_changes();
378 static void randomize_wts();
379 static int read_data_file();
380 /* static int initialize_net(); */
382 /***********************
383 ** LU DECOMPOSITION **
384 ** (Linear Equations) **
385 ***********************/
391 #define LUARRAYROWS 101L
392 #define LUARRAYCOLS 101L
400 fardouble (*ap)[][LUARRAYCOLS];
413 static void LUFreeMem(fardouble *a, fardouble *b,
414 fardouble *abase, fardouble *bbase);
415 static ulong DoLUIteration(fardouble *a, fardouble *b,
416 fardouble *abase, fardouble *bbase,
418 static void build_problem( double a[][LUARRAYCOLS],
419 int n, double b[LUARRAYROWS]);
420 static int ludcmp(double a[][LUARRAYCOLS],
421 int n, int indx[], int *d);
422 static void lubksb(double a[][LUARRAYCOLS],
423 int n, int indx[LUARRAYROWS],
424 double b[LUARRAYROWS]);
425 static int lusolve(double a[][LUARRAYCOLS],
426 int n, double b[LUARRAYROWS]);