メディア

FPGAのソフトコアCPUをベンチマークで測定する(ソースコード)(2/2 ページ)

» 2016年09月09日 10時00分 公開
[PR/MONOist]
前のページへ 1|2       
PR

NIOS IIで動かすためのDhrystoneコード(List 2)

  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. *
  15. *************************************************************************
  16. */
  17. #include <stdio.h>
  18. #include "sys/alt_timestamp.h"
  19. #include "alt_types.h"
  20. #include "dhry.h"
  21. /* Global Variables: */
  22. Rec_Pointer Ptr_Glob,
  23. Next_Ptr_Glob;
  24. int Int_Glob;
  25. Boolean Bool_Glob;
  26. char Ch_1_Glob,
  27. Ch_2_Glob;
  28. int Arr_1_Glob [50];
  29. int Arr_2_Glob [50] [50];
  30. char Reg_Define[] = "Register option selected.";
  31. extern char *malloc ();
  32. Enumeration Func_1 ();
  33. /*
  34. forward declaration necessary since Enumeration may not simply be int
  35. */
  36. #ifndef ROPT
  37. #define REG
  38. /* REG becomes defined as empty */
  39. /* i.e. no register variables */
  40. #else
  41. #define REG register
  42. #endif
  43. /* variables for time measurement: */
  44. #define Too_Small_Time 2
  45. /* Measurements should last at least 2 seconds */
  46. alt_u32 Begin_Time,
  47. End_Time;
  48. int User_Time;
  49. /* end of variables for time measurement */
  50. void main ()
  51. /*****/
  52. /* main program, corresponds to procedures */
  53. /* Main and Proc_0 in the Ada version */
  54. {
  55. // double dtime();
  56. One_Fifty Int_1_Loc;
  57. REG One_Fifty Int_2_Loc;
  58. One_Fifty Int_3_Loc;
  59. REG char Ch_Index;
  60. Enumeration Enum_Loc;
  61. Str_30 Str_1_Loc;
  62. Str_30 Str_2_Loc;
  63. REG int Run_Index;
  64. REG int Number_Of_Runs;
  65. // FILE *Ap;
  66. /* Initializations */
  67. Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  68. Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  69. Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
  70. Ptr_Glob->Discr = Ident_1;
  71. Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
  72. Ptr_Glob->variant.var_1.Int_Comp = 40;
  73. strcpy (Ptr_Glob->variant.var_1.Str_Comp,
  74. "DHRYSTONE PROGRAM, SOME STRING");
  75. strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  76. Arr_2_Glob [8][7] = 10;
  77. /* Was missing in published program. Without this statement, */
  78. /* Arr_2_Glob [8][7] would have an undefined value. */
  79. /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
  80. /* overflow may occur for this array element. */
  81. printf ("\n");
  82. printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
  83. printf ("\n");
  84. Number_Of_Runs = 100000;
  85. /***************/
  86. /* Start timer */
  87. /***************/
  88. if (alt_timestamp_start() < 0)
  89. {
  90. printf("Timestamp Failure\n");
  91. }
  92. Begin_Time = alt_timestamp();
  93. for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
  94. {
  95. Proc_5();
  96. Proc_4();
  97. /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  98. Int_1_Loc = 2;
  99. Int_2_Loc = 3;
  100. strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  101. Enum_Loc = Ident_2;
  102. Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  103. /* Bool_Glob == 1 */
  104. while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
  105. {
  106. Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  107. /* Int_3_Loc == 7 */
  108. Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  109. /* Int_3_Loc == 7 */
  110. Int_1_Loc += 1;
  111. } /* while */
  112. /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  113. Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  114. /* Int_Glob == 5 */
  115. Proc_1 (Ptr_Glob);
  116. for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  117. /* loop body executed twice */
  118. {
  119. if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  120. /* then, not executed */
  121. {
  122. Proc_6 (Ident_1, &Enum_Loc);
  123. strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  124. Int_2_Loc = Run_Index;
  125. Int_Glob = Run_Index;
  126. }
  127. }
  128. /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  129. Int_2_Loc = Int_2_Loc * Int_1_Loc;
  130. Int_1_Loc = Int_2_Loc / Int_3_Loc;
  131. Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  132. /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  133. Proc_2 (&Int_1_Loc);
  134. /* Int_1_Loc == 5 */
  135. } /* loop "for Run_Index" */
  136. /**************/
  137. /* Stop timer */
  138. /**************/
  139. End_Time = alt_timestamp();
  140. printf ("Execution ends\n");
  141. printf ("\n");
  142. printf ("Final values of the variables used in the benchmark:\n");
  143. printf ("\n");
  144. printf ("Int_Glob: %d\n", Int_Glob);
  145. printf (" should be: %d\n", 5);
  146. printf ("Bool_Glob: %d\n", Bool_Glob);
  147. printf (" should be: %d\n", 1);
  148. printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
  149. printf (" should be: %c\n", 'A');
  150. printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
  151. printf (" should be: %c\n", 'B');
  152. printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
  153. printf (" should be: %d\n", 7);
  154. printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
  155. printf (" should be: Number_Of_Runs + 10\n");
  156. printf ("Ptr_Glob->\n");
  157. printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
  158. printf (" should be: (implementation-dependent)\n");
  159. printf (" Discr: %d\n", Ptr_Glob->Discr);
  160. printf (" should be: %d\n", 0);
  161. printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
  162. printf (" should be: %d\n", 2);
  163. printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
  164. printf (" should be: %d\n", 17);
  165. printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
  166. printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
  167. printf ("Next_Ptr_Glob->\n");
  168. printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
  169. printf (" should be: (implementation-dependent), same as above\n");
  170. printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
  171. printf (" should be: %d\n", 0);
  172. printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  173. printf (" should be: %d\n", 1);
  174. printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
  175. printf (" should be: %d\n", 18);
  176. printf (" Str_Comp: %s\n", Next_Ptr_Glob->variant.var_1.Str_Comp);
  177. printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
  178. printf ("Int_1_Loc: %d\n", Int_1_Loc);
  179. printf (" should be: %d\n", 5);
  180. printf ("Int_2_Loc: %d\n", Int_2_Loc);
  181. printf (" should be: %d\n", 13);
  182. printf ("Int_3_Loc: %d\n", Int_3_Loc);
  183. printf (" should be: %d\n", 7);
  184. printf ("Enum_Loc: %d\n", Enum_Loc);
  185. printf (" should be: %d\n", 1);
  186. printf ("Str_1_Loc: %s\n", Str_1_Loc);
  187. printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
  188. printf ("Str_2_Loc: %s\n", Str_2_Loc);
  189. printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
  190. printf ("\n");
  191. User_Time = (int)(End_Time - Begin_Time);
  192. printf ( "Elapsed : %d Tics\n", User_Time );
  193. }
  194. Proc_1 (Ptr_Val_Par)
  195. /******************/
  196. REG Rec_Pointer Ptr_Val_Par;
  197. /* executed once */
  198. {
  199. REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
  200. /* == Ptr_Glob_Next */
  201. /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
  202. /* corresponds to "rename" in Ada, "with" in Pascal */
  203. structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
  204. Ptr_Val_Par->variant.var_1.Int_Comp = 5;
  205. Next_Record->variant.var_1.Int_Comp
  206. = Ptr_Val_Par->variant.var_1.Int_Comp;
  207. Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
  208. Proc_3 (&Next_Record->Ptr_Comp);
  209. /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
  210. == Ptr_Glob->Ptr_Comp */
  211. if (Next_Record->Discr == Ident_1)
  212. /* then, executed */
  213. {
  214. Next_Record->variant.var_1.Int_Comp = 6;
  215. Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
  216. &Next_Record->variant.var_1.Enum_Comp);
  217. Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
  218. Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
  219. &Next_Record->variant.var_1.Int_Comp);
  220. }
  221. else /* not executed */
  222. structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
  223. } /* Proc_1 */
  224. Proc_2 (Int_Par_Ref)
  225. /******************/
  226. /* executed once */
  227. /* *Int_Par_Ref == 1, becomes 4 */
  228. One_Fifty *Int_Par_Ref;
  229. {
  230. One_Fifty Int_Loc;
  231. Enumeration Enum_Loc;
  232. Int_Loc = *Int_Par_Ref + 10;
  233. do /* executed once */
  234. if (Ch_1_Glob == 'A')
  235. /* then, executed */
  236. {
  237. Int_Loc -= 1;
  238. *Int_Par_Ref = Int_Loc - Int_Glob;
  239. Enum_Loc = Ident_1;
  240. } /* if */
  241. while (Enum_Loc != Ident_1); /* true */
  242. } /* Proc_2 */
  243. Proc_3 (Ptr_Ref_Par)
  244. /******************/
  245. /* executed once */
  246. /* Ptr_Ref_Par becomes Ptr_Glob */
  247. Rec_Pointer *Ptr_Ref_Par;
  248. {
  249. if (Ptr_Glob != Null)
  250. /* then, executed */
  251. *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
  252. Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
  253. } /* Proc_3 */
  254. Proc_4 () /* without parameters */
  255. /*******/
  256. /* executed once */
  257. {
  258. Boolean Bool_Loc;
  259. Bool_Loc = Ch_1_Glob == 'A';
  260. Bool_Glob = Bool_Loc | Bool_Glob;
  261. Ch_2_Glob = 'B';
  262. } /* Proc_4 */
  263. Proc_5 () /* without parameters */
  264. /*******/
  265. /* executed once */
  266. {
  267. Ch_1_Glob = 'A';
  268. Bool_Glob = false;
  269. } /* Proc_5 */
  270. /* Procedure for the assignment of structures, */
  271. /* if the C compiler doesn't support this feature */
  272. #ifdef NOSTRUCTASSIGN
  273. memcpy (d, s, l)
  274. register char *d;
  275. register char *s;
  276. register int l;
  277. {
  278. while (l--) *d++ = *s++;
  279. }
  280. #endif
List2


前のページへ 1|2       

提供:日本アルテラ株式会社
アイティメディア営業企画/制作:MONOist 編集部/掲載内容有効期限:2016年10月10日

Copyright © ITmedia, Inc. All Rights Reserved.