home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / bytewarp.zip / NBENCH1.H < prev    next >
C/C++ Source or Header  |  1995-11-01  |  12KB  |  426 lines

  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.  
  51. extern farvoid *AllocateMemory(unsigned long nbytes,    /* From SYSSPEC */
  52.     int *errorcode);
  53. extern void FreeMemory(farvoid *mempointer,
  54.     int *errorcode);
  55. extern void MoveMemory(farvoid *destination,
  56.         farvoid *source, unsigned long nbytes);
  57. extern void ReportError(char *context, int errorcode);
  58. extern void ErrorExit();
  59. extern unsigned long StartStopwatch();
  60. extern unsigned long StopStopwatch(unsigned long startticks);
  61. extern unsigned long TicksToSecs(unsigned long tickamount);
  62. extern double TicksToFracSecs(unsigned long tickamount);
  63.  
  64. /*****************
  65. ** NUMERIC SORT **
  66. *****************/
  67.  
  68. /*
  69. ** PROTOTYPES
  70. */
  71. void DoNumSort(void);
  72. static ulong DoNumSortIteration(farlong *arraybase,
  73.         ulong arraysize,
  74.         uint numarrays);
  75. static void LoadNumArrayWithRand(farlong *array,
  76.         ulong arraysize,
  77.         uint numarrays);
  78. static void NumHeapSort(farlong *array,
  79.         ulong bottom,
  80.         ulong top);
  81. static void NumSift(farlong *array,
  82.         ulong i,
  83.         ulong j);
  84.  
  85.  
  86. /****************
  87. ** STRING SORT **
  88. *****************
  89. */
  90.  
  91.  
  92. /*
  93. ** PROTOTYPES
  94. */
  95. void DoStringSort(void);
  96. static ulong DoStringSortIteration(faruchar *arraybase,
  97.         uint numarrays,
  98.         ulong arraysize);
  99. static farulong *LoadStringArray(faruchar *strarray,
  100.         uint numarrays,
  101.         ulong *strings,
  102.         ulong arraysize);
  103. static void stradjust(farulong *optrarray,
  104.         faruchar *strarray,
  105.         ulong nstrings,
  106.         ulong i,
  107.         uchar l);
  108. static void StrHeapSort(farulong *optrarray,
  109.         faruchar *strarray,
  110.         ulong numstrings,
  111.         ulong bottom,
  112.         ulong top);
  113. static int str_is_less(farulong *optrarray,
  114.         faruchar *strarray,
  115.         ulong numstrings,
  116.         ulong a,
  117.         ulong b);
  118. static void strsift(farulong *optrarray,
  119.         faruchar *strarray,
  120.         ulong numstrings,
  121.         ulong i,
  122.         ulong j);
  123.  
  124. /************************
  125. ** BITFIELD OPERATIONS **
  126. *************************
  127. */
  128.  
  129. /*
  130. ** PROTOTYPES
  131. */
  132. void DoBitops(void);
  133. static ulong DoBitfieldIteration(farulong *bitarraybase,
  134.         farulong *bitoparraybase,
  135.         long bitoparraysize,
  136.         ulong *nbitops);
  137. static void ToggleBitRun(farulong *bitmap,
  138.         ulong bit_addr,
  139.         ulong nbits,
  140.         uint val);
  141. static void FlipBitRun(farulong *bitmap,
  142.         ulong bit_addr,
  143.         ulong nbits);
  144.  
  145. /****************************
  146. ** EMULATED FLOATING POINT **
  147. ****************************/
  148. typedef struct
  149. {
  150.     u8 type;        /* Indicates, NORMAL, SUBNORMAL, etc. */
  151.     u8 sign;        /* Mantissa sign */
  152.     short exp;      /* Signed exponent...no bias */
  153.     u16 mantissa[INTERNAL_FPF_PRECISION];
  154. } InternalFPF;
  155.  
  156. /*
  157. ** PROTOTYPES
  158. */
  159. void DoEmFloat(void);
  160.  
  161. /*
  162. ** EXTERNALS
  163. */
  164. extern void SetupCPUEmFloatArrays(InternalFPF *abase,
  165.     InternalFPF *bbase, InternalFPF *cbase,
  166.     ulong arraysize);
  167. extern ulong DoEmFloatIteration(InternalFPF *abase,
  168.     InternalFPF *bbase, InternalFPF *cbase,
  169.     ulong arraysize, ulong loops);
  170.  
  171. /*************************
  172. ** FOURIER COEFFICIENTS **
  173. *************************/
  174.  
  175. /*
  176. ** PROTOTYPES
  177. */
  178. void DoFourier(void);
  179. static ulong DoFPUTransIteration(fardouble *abase,
  180.         fardouble *bbase,
  181.         ulong arraysize);
  182. static double TrapezoidIntegrate(double x0,
  183.         double x1,
  184.         int nsteps,
  185.         double omegan,
  186.         int select);
  187. static double thefunction(double x,
  188.         double omegan,
  189.         int select);
  190.  
  191. /*************************
  192. ** ASSIGNMENT ALGORITHM **
  193. *************************/
  194.  
  195. /*
  196. ** DEFINES
  197. */
  198.  
  199. #define ASSIGNROWS 101L
  200. #define ASSIGNCOLS 101L
  201.  
  202. /*
  203. ** TYPEDEFS
  204. */
  205. typedef struct {
  206.     union {
  207.         long *p;
  208.         long (*ap)[ASSIGNROWS][ASSIGNCOLS];
  209.     } ptrs;
  210. } longptr;
  211.  
  212. /*
  213. ** PROTOTYPES
  214. */
  215. void DoAssign(void);
  216. static ulong DoAssignIteration(farlong *arraybase,
  217.         ulong numarrays);
  218. static void LoadAssignArrayWithRand(farlong *arraybase,
  219.         ulong numarrays);
  220. static void LoadAssign(farlong arraybase[][ASSIGNCOLS]);
  221. static void CopyToAssign(farlong arrayfrom[][ASSIGNCOLS],
  222.         long arrayto[][ASSIGNCOLS]);
  223. static void Assignment(farlong arraybase[][ASSIGNCOLS]);
  224. static void calc_minimum_costs(long tableau[][ASSIGNCOLS]);
  225. static int first_assignments(long tableau[][ASSIGNCOLS],
  226.         short assignedtableau[][ASSIGNCOLS]);
  227. static void second_assignments(long tableau[][ASSIGNCOLS],
  228.         short assignedtableau[][ASSIGNCOLS]);
  229.  
  230. /********************
  231. ** IDEA ENCRYPTION **
  232. ********************/
  233.  
  234. /*
  235. ** DEFINES
  236. */
  237. #define IDEAKEYSIZE 16
  238. #define IDEABLOCKSIZE 8
  239. #define ROUNDS 8
  240. #define KEYLEN (6*ROUNDS+4)
  241.  
  242. /*
  243. ** MACROS
  244. */
  245. #define low16(x) ((x) & 0x0FFFF)
  246. #define MUL(x,y) (x=mul(low16(x),y))
  247.  
  248.  
  249. typedef u16 IDEAkey[KEYLEN];
  250.  
  251. /*
  252. ** PROTOTYPES
  253. */
  254. void DoIDEA(void);
  255. static ulong DoIDEAIteration(faruchar *plain1,
  256.     faruchar *crypt1, faruchar *plain2,
  257.     ulong arraysize, ulong nloops,
  258.     IDEAkey Z, IDEAkey DK);
  259. static u16 mul(register u16 a, register u16 b);
  260. static u16 inv(u16 x);
  261. static void en_key_idea(u16 userkey[8], IDEAkey Z);
  262. static void de_key_idea(IDEAkey Z, IDEAkey DK);
  263. static void cipher_idea(u16 in[4], u16 out[4], IDEAkey Z);
  264.  
  265. /************************
  266. ** HUFFMAN COMPRESSION **
  267. ************************/
  268.  
  269. /*
  270. ** DEFINES
  271. */
  272. #define EXCLUDED 32000L          /* Big positive value */
  273.  
  274. /*
  275. ** TYPEDEFS
  276. */
  277. typedef struct {
  278.     uchar c;                /* Byte value */
  279.     float freq;             /* Frequency */
  280.     int parent;             /* Parent node */
  281.     int left;               /* Left pointer = 0 */
  282.     int right;              /* Right pointer = 1 */
  283. } huff_node;
  284.  
  285. /*
  286. ** GLOBALS
  287. */
  288. static huff_node *hufftree;             /* The huffman tree */
  289. static long plaintextlen;               /* Length of plaintext */
  290.  
  291. /*
  292. ** PROTOTYPES
  293. */
  294. void DoHuffman();
  295. static void create_text_line(farchar *dt,long nchars);
  296. static void create_text_block(farchar *tb, ulong tblen,
  297.         ushort maxlinlen);
  298. static ulong DoHuffIteration(farchar *plaintext,
  299.     farchar *comparray, farchar *decomparray,
  300.     ulong arraysize, ulong nloops, huff_node *hufftree);
  301. static void SetCompBit(u8 *comparray, u32 bitoffset, char bitchar);
  302. static int GetCompBit(u8 *comparray, u32 bitoffset);
  303.  
  304. /********************************
  305. ** BACK PROPAGATION NEURAL NET **
  306. ********************************/
  307.  
  308. /*
  309. ** DEFINES
  310. */
  311. #define T 1                     /* TRUE */
  312. #define F 0                     /* FALSE */
  313. #define ERR -1
  314. #define MAXPATS 10              /* max number of patterns in data file */
  315. #define IN_X_SIZE 5             /* number of neurodes/row of input layer */
  316. #define IN_Y_SIZE 7             /* number of neurodes/col of input layer */
  317. #define IN_SIZE 35              /* equals IN_X_SIZE*IN_Y_SIZE */
  318. #define MID_SIZE 8              /* number of neurodes in middle layer */
  319. #define OUT_SIZE 8              /* number of neurodes in output layer */
  320. #define MARGIN 0.1              /* how near to 1,0 do we have to come to stop? */
  321. #define BETA 0.09               /* beta learning constant */
  322. #define ALPHA 0.09              /* momentum term constant */
  323. #define STOP 0.1                /* when worst_error less than STOP, training is done */
  324.  
  325. /*
  326. ** GLOBALS
  327. */
  328. double  mid_wts[MID_SIZE][IN_SIZE];     /* middle layer weights */
  329. double  out_wts[OUT_SIZE][MID_SIZE];    /* output layer weights */
  330. double  mid_out[MID_SIZE];              /* middle layer output */
  331. double  out_out[OUT_SIZE];              /* output layer output */
  332. double  mid_error[MID_SIZE];            /* middle layer errors */
  333. double  out_error[OUT_SIZE];            /* output layer errors */
  334. double  mid_wt_change[MID_SIZE][IN_SIZE]; /* storage for last wt change */
  335. double  out_wt_change[OUT_SIZE][MID_SIZE]; /* storage for last wt change */
  336. double  in_pats[MAXPATS][IN_SIZE];      /* input patterns */
  337. double  out_pats[MAXPATS][OUT_SIZE];    /* desired output patterns */
  338. double  tot_out_error[MAXPATS];         /* measure of whether net is done */
  339. double  out_wt_cum_change[OUT_SIZE][MID_SIZE]; /* accumulated wt changes */
  340. double  mid_wt_cum_change[MID_SIZE][IN_SIZE];  /* accumulated wt changes */
  341.  
  342. double  worst_error; /* worst error each pass through the data */
  343. double  average_error; /* average error each pass through the data */
  344. double  avg_out_error[MAXPATS]; /* average error each pattern */
  345.  
  346. int iteration_count;    /* number of passes thru network so far */
  347. int numpats;            /* number of patterns in data file */
  348. int numpasses;          /* number of training passes through data file */
  349. int learned;            /* flag--if TRUE, network has learned all patterns */
  350.  
  351. /*
  352. ** The Neural Net test requires an input data file.
  353. ** The name is specified here.
  354. */
  355. char *inpath="NNET.DAT";
  356.  
  357. /*
  358. ** PROTOTYPES
  359. */
  360. void DoNNET(void);
  361. static ulong DoNNetIteration(ulong nloops);
  362. static void do_mid_forward(int patt);
  363. static void do_out_forward();
  364. void display_output(int patt);
  365. static void do_forward_pass(int patt);
  366. static void do_out_error(int patt);
  367. static void worst_pass_error();
  368. static void do_mid_error();
  369. static void adjust_out_wts();
  370. static void adjust_mid_wts();
  371. static void do_back_pass(int patt);
  372. static void move_wt_changes();
  373. static int check_out_error();
  374. static void zero_changes();
  375. static void randomize_wts();
  376. static int read_data_file();
  377. static int initialize_net();
  378.  
  379. /***********************
  380. **  LU DECOMPOSITION  **
  381. ** (Linear Equations) **
  382. ***********************/
  383.  
  384. /*
  385. ** DEFINES
  386. */
  387.  
  388. #define LUARRAYROWS 101L
  389. #define LUARRAYCOLS 101L
  390.  
  391. /*
  392. ** TYPEDEFS
  393. */
  394. typedef struct
  395. {       union
  396.     {       fardouble *p;
  397.         fardouble (*ap)[][LUARRAYCOLS];
  398.     } ptrs;
  399. } LUdblptr;
  400.  
  401. /*
  402. ** GLOBALS
  403. */
  404. fardouble *LUtempvv;
  405.  
  406. /*
  407. ** PROTOTYPES
  408. */
  409. void DoLU(void);
  410. static void LUFreeMem(fardouble *a, fardouble *b,
  411.     fardouble *abase, fardouble *bbase);
  412. static ulong DoLUIteration(fardouble *a, fardouble *b,
  413.     fardouble *abase, fardouble *bbase,
  414.     ulong numarrays);
  415. static void build_problem( double a[][LUARRAYCOLS],
  416.     int n, double b[LUARRAYROWS]);
  417. static int ludcmp(double a[][LUARRAYCOLS],
  418.     int n, int indx[], int *d);
  419. static void lubksb(double a[][LUARRAYCOLS],
  420.     int n, int indx[LUARRAYROWS],
  421.     double b[LUARRAYROWS]);
  422. static int lusolve(double a[][LUARRAYCOLS],
  423.     int n, double b[LUARRAYROWS]);
  424.  
  425.  
  426.