OSDN Git Service

Fix no pic
[uclinux-h8/uClinux-dist.git] / user / nbench / nbench1.h
1 /*
2 ** nbench1.h
3 ** Header for nbench1.c
4 ** BYTEmark (tm)
5 ** BYTE's Native Mode Benchmarks
6 ** Rick Grehan, BYTE Magazine
7 **
8 ** Creation:
9 ** Revision: 3/95;10/95
10 **
11 ** DISCLAIMER
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
23 ** this code.
24 */
25
26 /*
27 ** DEFINES
28 */
29 /* #define DEBUG */
30
31 /*
32 ** EXTERNALS
33 */
34 extern ulong global_min_ticks;
35
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;
46
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);
53
54 extern farvoid *AllocateMemory(unsigned long nbytes,    /* From SYSSPEC */
55         int *errorcode);
56 extern void FreeMemory(farvoid *mempointer,
57         int *errorcode);
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);
66
67 /*****************
68 ** NUMERIC SORT **
69 *****************/
70
71 /*
72 ** PROTOTYPES
73 */
74 void DoNumSort(void);
75 static ulong DoNumSortIteration(farlong *arraybase,
76                 ulong arraysize,
77                 uint numarrays);
78 static void LoadNumArrayWithRand(farlong *array,
79                 ulong arraysize,
80                 uint numarrays);
81 static void NumHeapSort(farlong *array,
82                 ulong bottom,
83                 ulong top);
84 static void NumSift(farlong *array,
85                 ulong i,
86                 ulong j);
87
88
89 /****************
90 ** STRING SORT **
91 *****************
92 */
93
94
95 /*
96 ** PROTOTYPES
97 */
98 void DoStringSort(void);
99 static ulong DoStringSortIteration(faruchar *arraybase,
100                 uint numarrays,
101                 ulong arraysize);
102 static farulong *LoadStringArray(faruchar *strarray,
103                 uint numarrays,
104                 ulong *strings,
105                 ulong arraysize);
106 static void stradjust(farulong *optrarray,
107                 faruchar *strarray,
108                 ulong nstrings,
109                 ulong i,
110                 uchar l);
111 static void StrHeapSort(farulong *optrarray,
112                 faruchar *strarray,
113                 ulong numstrings,
114                 ulong bottom,
115                 ulong top);
116 static int str_is_less(farulong *optrarray,
117                 faruchar *strarray,
118                 ulong numstrings,
119                 ulong a,
120                 ulong b);
121 static void strsift(farulong *optrarray,
122                 faruchar *strarray,
123                 ulong numstrings,
124                 ulong i,
125                 ulong j);
126
127 /************************
128 ** BITFIELD OPERATIONS **
129 *************************
130 */
131
132 /*
133 ** PROTOTYPES
134 */
135 void DoBitops(void);
136 static ulong DoBitfieldIteration(farulong *bitarraybase,
137                 farulong *bitoparraybase,
138                 long bitoparraysize,
139                 ulong *nbitops);
140 static void ToggleBitRun(farulong *bitmap,
141                 ulong bit_addr,
142                 ulong nbits,
143                 uint val);
144 static void FlipBitRun(farulong *bitmap,
145                 ulong bit_addr,
146                 ulong nbits);
147
148 /****************************
149 ** EMULATED FLOATING POINT **
150 ****************************/
151 typedef struct
152 {
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];
157 } InternalFPF;
158
159 /*
160 ** PROTOTYPES
161 */
162 void DoEmFloat(void);
163
164 /*
165 ** EXTERNALS
166 */
167 extern void SetupCPUEmFloatArrays(InternalFPF *abase,
168         InternalFPF *bbase, InternalFPF *cbase,
169         ulong arraysize);
170 extern ulong DoEmFloatIteration(InternalFPF *abase,
171         InternalFPF *bbase, InternalFPF *cbase,
172         ulong arraysize, ulong loops);
173
174 /*************************
175 ** FOURIER COEFFICIENTS **
176 *************************/
177
178 /*
179 ** PROTOTYPES
180 */
181 void DoFourier(void);
182 static ulong DoFPUTransIteration(fardouble *abase,
183                 fardouble *bbase,
184                 ulong arraysize);
185 static double TrapezoidIntegrate(double x0,
186                 double x1,
187                 int nsteps,
188                 double omegan,
189                 int select);
190 static double thefunction(double x,
191                 double omegan,
192                 int select);
193
194 /*************************
195 ** ASSIGNMENT ALGORITHM **
196 *************************/
197
198 /*
199 ** DEFINES
200 */
201
202 #define ASSIGNROWS 101L
203 #define ASSIGNCOLS 101L
204
205 /*
206 ** TYPEDEFS
207 */
208 typedef struct {
209         union {
210                 long *p;
211                 long (*ap)[ASSIGNROWS][ASSIGNCOLS];
212         } ptrs;
213 } longptr;
214
215 /*
216 ** PROTOTYPES
217 */
218 void DoAssign(void);
219 static ulong DoAssignIteration(farlong *arraybase,
220                 ulong numarrays);
221 static void LoadAssignArrayWithRand(farlong *arraybase,
222                 ulong numarrays);
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]);
232
233 /********************
234 ** IDEA ENCRYPTION **
235 ********************/
236
237 /*
238 ** DEFINES
239 */
240 #define IDEAKEYSIZE 16
241 #define IDEABLOCKSIZE 8
242 #define ROUNDS 8
243 #define KEYLEN (6*ROUNDS+4)
244
245 /*
246 ** MACROS
247 */
248 #define low16(x) ((x) & 0x0FFFF)
249 #define MUL(x,y) (x=mul(low16(x),y))
250
251
252 typedef u16 IDEAkey[KEYLEN];
253
254 /*
255 ** PROTOTYPES
256 */
257 void DoIDEA(void);
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);
267
268 /************************
269 ** HUFFMAN COMPRESSION **
270 ************************/
271
272 /*
273 ** DEFINES
274 */
275 #define EXCLUDED 32000L          /* Big positive value */
276
277 /*
278 ** TYPEDEFS
279 */
280 typedef struct {
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 */
286 } huff_node;
287
288 /*
289 ** GLOBALS
290 */
291 static huff_node *hufftree;             /* The huffman tree */
292 static long plaintextlen;               /* Length of plaintext */
293
294 /*
295 ** PROTOTYPES
296 */
297 void DoHuffman();
298 static void create_text_line(farchar *dt,long nchars);
299 static void create_text_block(farchar *tb, ulong tblen,
300                 ushort maxlinlen);
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);
306
307 /********************************
308 ** BACK PROPAGATION NEURAL NET **
309 ********************************/
310
311 /*
312 ** DEFINES
313 */
314 #define T 1                     /* TRUE */
315 #define F 0                     /* FALSE */
316 #define ERR -1
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 */
327
328 /*
329 ** GLOBALS
330 */
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 */
344
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 */
348
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 */
353
354 /*
355 ** The Neural Net test requires an input data file.
356 ** The name is specified here.
357 */
358 char *inpath="NNET.DAT";
359
360 /*
361 ** PROTOTYPES
362 */
363 void DoNNET(void);
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(); */
381
382 /***********************
383 **  LU DECOMPOSITION  **
384 ** (Linear Equations) **
385 ***********************/
386
387 /*
388 ** DEFINES
389 */
390
391 #define LUARRAYROWS 101L
392 #define LUARRAYCOLS 101L
393
394 /*
395 ** TYPEDEFS
396 */
397 typedef struct
398 {       union
399         {       fardouble *p;
400                 fardouble (*ap)[][LUARRAYCOLS];
401         } ptrs;
402 } LUdblptr;
403
404 /*
405 ** GLOBALS
406 */
407 fardouble *LUtempvv;
408
409 /*
410 ** PROTOTYPES
411 */
412 void DoLU(void);
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,
417         ulong numarrays);
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]);
427
428