dhry_1.c 15 KB

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