dhry_1.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /*
  2. * (C) Copyright 2015 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. *
  6. * Dhrystone is widely available in the public domain. A GPL license is
  7. * chosen for U-Boot.
  8. */
  9. /*****************************************************************************
  10. * The BYTE UNIX Benchmarks - Release 3
  11. * Module: dhry_1.c SID: 3.4 5/15/91 19:30:21
  12. *
  13. *****************************************************************************
  14. * Bug reports, patches, comments, suggestions should be sent to:
  15. *
  16. * Ben Smith, Rick Grehan or Tom Yager
  17. * ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com
  18. *
  19. *****************************************************************************
  20. *
  21. * *** WARNING **** With BYTE's modifications applied, results obtained with
  22. * ******* this version of the Dhrystone program may not be applicable
  23. * to other versions.
  24. *
  25. * Modification Log:
  26. * 10/22/97 - code cleanup to remove ANSI C compiler warnings
  27. * Andy Kahn <kahn@zk3.dec.com>
  28. *
  29. * Adapted from:
  30. *
  31. * "DHRYSTONE" Benchmark Program
  32. * -----------------------------
  33. *
  34. * Version: C, Version 2.1
  35. *
  36. * File: dhry_1.c (part 2 of 3)
  37. *
  38. * Date: May 25, 1988
  39. *
  40. * Author: Reinhold P. Weicker
  41. *
  42. ***************************************************************************/
  43. char SCCSid[] = "@(#) @(#)dhry_1.c:3.4 -- 5/15/91 19:30:21";
  44. #include <common.h>
  45. #include <malloc.h>
  46. #include "dhry.h"
  47. unsigned long Run_Index;
  48. void report(void)
  49. {
  50. printf("%ld loops\n", Run_Index);
  51. }
  52. /* Global Variables: */
  53. Rec_Pointer Ptr_Glob,
  54. Next_Ptr_Glob;
  55. int Int_Glob;
  56. Boolean Bool_Glob;
  57. char Ch_1_Glob,
  58. Ch_2_Glob;
  59. int Arr_1_Glob [50];
  60. int Arr_2_Glob [50] [50];
  61. Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
  62. /* forward declaration necessary since Enumeration may not simply be int */
  63. #ifndef REG
  64. Boolean Reg = false;
  65. #define REG
  66. /* REG becomes defined as empty */
  67. /* i.e. no register variables */
  68. #else
  69. Boolean Reg = true;
  70. #endif
  71. /* variables for time measurement: */
  72. #ifdef TIMES
  73. #define Too_Small_Time 120
  74. /* Measurements should last at least about 2 seconds */
  75. #endif
  76. #ifdef TIME
  77. extern long time();
  78. /* see library function "time" */
  79. #define Too_Small_Time 2
  80. /* Measurements should last at least 2 seconds */
  81. #endif
  82. long Begin_Time,
  83. End_Time,
  84. User_Time;
  85. /* end of variables for time measurement */
  86. void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
  87. void Proc_2 (One_Fifty *Int_Par_Ref);
  88. void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
  89. void Proc_4 (void);
  90. void Proc_5 (void);
  91. extern Boolean Func_2(Str_30, Str_30);
  92. extern void Proc_6(Enumeration, Enumeration *);
  93. extern void Proc_7(One_Fifty, One_Fifty, One_Fifty *);
  94. extern void Proc_8(Arr_1_Dim, Arr_2_Dim, int, int);
  95. void dhry(int Number_Of_Runs)
  96. /* main program, corresponds to procedures */
  97. /* Main and Proc_0 in the Ada version */
  98. {
  99. One_Fifty Int_1_Loc;
  100. REG One_Fifty Int_2_Loc;
  101. One_Fifty Int_3_Loc;
  102. REG char Ch_Index;
  103. Enumeration Enum_Loc;
  104. Str_30 Str_1_Loc;
  105. Str_30 Str_2_Loc;
  106. /* Initializations */
  107. Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  108. Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  109. Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
  110. Ptr_Glob->Discr = Ident_1;
  111. Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
  112. Ptr_Glob->variant.var_1.Int_Comp = 40;
  113. strcpy (Ptr_Glob->variant.var_1.Str_Comp,
  114. "DHRYSTONE PROGRAM, SOME STRING");
  115. strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  116. Arr_2_Glob [8][7] = 10;
  117. /* Was missing in published program. Without this statement, */
  118. /* Arr_2_Glob [8][7] would have an undefined value. */
  119. /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
  120. /* overflow may occur for this array element. */
  121. #ifdef PRATTLE
  122. printf ("\n");
  123. printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
  124. printf ("\n");
  125. if (Reg)
  126. {
  127. printf ("Program compiled with 'register' attribute\n");
  128. printf ("\n");
  129. }
  130. else
  131. {
  132. printf ("Program compiled without 'register' attribute\n");
  133. printf ("\n");
  134. }
  135. printf ("Please give the number of runs through the benchmark: ");
  136. {
  137. int n;
  138. scanf ("%d", &n);
  139. Number_Of_Runs = n;
  140. }
  141. printf ("\n");
  142. printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
  143. #endif /* PRATTLE */
  144. Run_Index = 0;
  145. /***************/
  146. /* Start timer */
  147. /***************/
  148. #ifdef SELF_TIMED
  149. #ifdef TIMES
  150. times (&time_info);
  151. Begin_Time = (long) time_info.tms_utime;
  152. #endif
  153. #ifdef TIME
  154. Begin_Time = time ( (long *) 0);
  155. #endif
  156. #endif /* SELF_TIMED */
  157. for (Run_Index = 1; Run_Index < Number_Of_Runs; ++Run_Index)
  158. {
  159. Proc_5();
  160. Proc_4();
  161. /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  162. Int_1_Loc = 2;
  163. Int_2_Loc = 3;
  164. strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  165. Enum_Loc = Ident_2;
  166. Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  167. /* Bool_Glob == 1 */
  168. while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
  169. {
  170. Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  171. /* Int_3_Loc == 7 */
  172. Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  173. /* Int_3_Loc == 7 */
  174. Int_1_Loc += 1;
  175. } /* while */
  176. /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  177. Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  178. /* Int_Glob == 5 */
  179. Proc_1 (Ptr_Glob);
  180. for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  181. /* loop body executed twice */
  182. {
  183. if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  184. /* then, not executed */
  185. {
  186. Proc_6 (Ident_1, &Enum_Loc);
  187. strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  188. Int_2_Loc = Run_Index;
  189. Int_Glob = Run_Index;
  190. }
  191. }
  192. /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  193. Int_2_Loc = Int_2_Loc * Int_1_Loc;
  194. Int_1_Loc = Int_2_Loc / Int_3_Loc;
  195. Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  196. /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  197. Proc_2 (&Int_1_Loc);
  198. /* Int_1_Loc == 5 */
  199. } /* loop "for Run_Index" */
  200. /**************/
  201. /* Stop timer */
  202. /**************/
  203. #ifdef SELF_TIMED
  204. #ifdef TIMES
  205. times (&time_info);
  206. End_Time = (long) time_info.tms_utime;
  207. #endif
  208. #ifdef TIME
  209. End_Time = time ( (long *) 0);
  210. #endif
  211. #endif /* SELF_TIMED */
  212. /* BYTE version never executes this stuff */
  213. #ifdef SELF_TIMED
  214. printf ("Execution ends\n");
  215. printf ("\n");
  216. printf ("Final values of the variables used in the benchmark:\n");
  217. printf ("\n");
  218. printf ("Int_Glob: %d\n", Int_Glob);
  219. printf (" should be: %d\n", 5);
  220. printf ("Bool_Glob: %d\n", Bool_Glob);
  221. printf (" should be: %d\n", 1);
  222. printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
  223. printf (" should be: %c\n", 'A');
  224. printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
  225. printf (" should be: %c\n", 'B');
  226. printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
  227. printf (" should be: %d\n", 7);
  228. printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
  229. printf (" should be: Number_Of_Runs + 10\n");
  230. printf ("Ptr_Glob->\n");
  231. printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
  232. printf (" should be: (implementation-dependent)\n");
  233. printf (" Discr: %d\n", Ptr_Glob->Discr);
  234. printf (" should be: %d\n", 0);
  235. printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
  236. printf (" should be: %d\n", 2);
  237. printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
  238. printf (" should be: %d\n", 17);
  239. printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
  240. printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
  241. printf ("Next_Ptr_Glob->\n");
  242. printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
  243. printf (" should be: (implementation-dependent), same as above\n");
  244. printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
  245. printf (" should be: %d\n", 0);
  246. printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  247. printf (" should be: %d\n", 1);
  248. printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
  249. printf (" should be: %d\n", 18);
  250. printf (" Str_Comp: %s\n",
  251. Next_Ptr_Glob->variant.var_1.Str_Comp);
  252. printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
  253. printf ("Int_1_Loc: %d\n", Int_1_Loc);
  254. printf (" should be: %d\n", 5);
  255. printf ("Int_2_Loc: %d\n", Int_2_Loc);
  256. printf (" should be: %d\n", 13);
  257. printf ("Int_3_Loc: %d\n", Int_3_Loc);
  258. printf (" should be: %d\n", 7);
  259. printf ("Enum_Loc: %d\n", Enum_Loc);
  260. printf (" should be: %d\n", 1);
  261. printf ("Str_1_Loc: %s\n", Str_1_Loc);
  262. printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
  263. printf ("Str_2_Loc: %s\n", Str_2_Loc);
  264. printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
  265. printf ("\n");
  266. User_Time = End_Time - Begin_Time;
  267. if (User_Time < Too_Small_Time)
  268. {
  269. printf ("Measured time too small to obtain meaningful results\n");
  270. printf ("Please increase number of runs\n");
  271. printf ("\n");
  272. }
  273. else
  274. {
  275. #ifdef TIME
  276. Microseconds = (float) User_Time * Mic_secs_Per_Second
  277. / (float) Number_Of_Runs;
  278. Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
  279. #else
  280. Microseconds = (float) User_Time * Mic_secs_Per_Second
  281. / ((float) HZ * ((float) Number_Of_Runs));
  282. Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
  283. / (float) User_Time;
  284. #endif
  285. printf ("Microseconds for one run through Dhrystone: ");
  286. printf ("%6.1f \n", Microseconds);
  287. printf ("Dhrystones per Second: ");
  288. printf ("%6.1f \n", Dhrystones_Per_Second);
  289. printf ("\n");
  290. }
  291. #endif /* SELF_TIMED */
  292. }
  293. void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
  294. /* executed once */
  295. {
  296. REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
  297. /* == Ptr_Glob_Next */
  298. /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
  299. /* corresponds to "rename" in Ada, "with" in Pascal */
  300. structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
  301. Ptr_Val_Par->variant.var_1.Int_Comp = 5;
  302. Next_Record->variant.var_1.Int_Comp
  303. = Ptr_Val_Par->variant.var_1.Int_Comp;
  304. Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
  305. Proc_3 (&Next_Record->Ptr_Comp);
  306. /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
  307. == Ptr_Glob->Ptr_Comp */
  308. if (Next_Record->Discr == Ident_1)
  309. /* then, executed */
  310. {
  311. Next_Record->variant.var_1.Int_Comp = 6;
  312. Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
  313. &Next_Record->variant.var_1.Enum_Comp);
  314. Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
  315. Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
  316. &Next_Record->variant.var_1.Int_Comp);
  317. }
  318. else /* not executed */
  319. structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
  320. } /* Proc_1 */
  321. void Proc_2 (One_Fifty *Int_Par_Ref)
  322. /* executed once */
  323. /* *Int_Par_Ref == 1, becomes 4 */
  324. {
  325. One_Fifty Int_Loc;
  326. Enumeration Enum_Loc;
  327. Enum_Loc = 0;
  328. Int_Loc = *Int_Par_Ref + 10;
  329. do /* executed once */
  330. if (Ch_1_Glob == 'A')
  331. /* then, executed */
  332. {
  333. Int_Loc -= 1;
  334. *Int_Par_Ref = Int_Loc - Int_Glob;
  335. Enum_Loc = Ident_1;
  336. } /* if */
  337. while (Enum_Loc != Ident_1); /* true */
  338. } /* Proc_2 */
  339. void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
  340. /* executed once */
  341. /* Ptr_Ref_Par becomes Ptr_Glob */
  342. {
  343. if (Ptr_Glob != Null)
  344. /* then, executed */
  345. *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
  346. Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
  347. } /* Proc_3 */
  348. void Proc_4 (void) /* without parameters */
  349. /* executed once */
  350. {
  351. Boolean Bool_Loc;
  352. Bool_Loc = Ch_1_Glob == 'A';
  353. Bool_Glob = Bool_Loc | Bool_Glob;
  354. Ch_2_Glob = 'B';
  355. } /* Proc_4 */
  356. void Proc_5 (void) /* without parameters */
  357. /*******/
  358. /* executed once */
  359. {
  360. Ch_1_Glob = 'A';
  361. Bool_Glob = false;
  362. } /* Proc_5 */
  363. /* Procedure for the assignment of structures, */
  364. /* if the C compiler doesn't support this feature */
  365. #ifdef NOSTRUCTASSIGN
  366. memcpy (d, s, l)
  367. register char *d;
  368. register char *s;
  369. register int l;
  370. {
  371. while (l--) *d++ = *s++;
  372. }
  373. #endif