dhry.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. #ifndef DHRY_H
  2. #define DHRY_H
  3. /*
  4. ****************************************************************************
  5. *
  6. * "DHRYSTONE" Benchmark Program
  7. * -----------------------------
  8. *
  9. * Version: C, Version 2.1
  10. *
  11. * File: dhry.h (part 1 of 3)
  12. *
  13. * Date: May 25, 1988
  14. *
  15. * Author: Reinhold P. Weicker
  16. * Siemens AG, AUT E 51
  17. * Postfach 3220
  18. * 8520 Erlangen
  19. * Germany (West)
  20. * Phone: [+49]-9131-7-20330
  21. * (8-17 Central European Time)
  22. * Usenet: ..!mcsun!unido!estevax!weicker
  23. *
  24. * converted to ANSI C by Jeremy Johnson. 1/20/00
  25. *
  26. * Original Version (in Ada) published in
  27. * "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
  28. * pp. 1013 - 1030, together with the statistics
  29. * on which the distribution of statements etc. is based.
  30. *
  31. * In this C version, the following C library functions are used:
  32. * - strcpy, strcmp (inside the measurement loop)
  33. * - printf, scanf (outside the measurement loop)
  34. * In addition, Berkeley UNIX system calls "times ()" or "time ()"
  35. * are used for execution time measurement. For measurements
  36. * on other systems, these calls have to be changed.
  37. *
  38. * Collection of Results:
  39. * Reinhold Weicker (address see above) and
  40. *
  41. * Rick Richardson
  42. * PC Research. Inc.
  43. * 94 Apple Orchard Drive
  44. * Tinton Falls, NJ 07724
  45. * Phone: (201) 389-8963 (9-17 EST)
  46. * Usenet: ...!uunet!pcrat!rick
  47. *
  48. * Please send results to Rick Richardson and/or Reinhold Weicker.
  49. * Complete information should be given on hardware and software used.
  50. * Hardware information includes: Machine type, CPU, type and size
  51. * of caches; for microprocessors: clock frequency, memory speed
  52. * (number of wait states).
  53. * Software information includes: Compiler (and runtime library)
  54. * manufacturer and version, compilation switches, OS version.
  55. * The Operating System version may give an indication about the
  56. * compiler; Dhrystone itself performs no OS calls in the measurement loop.
  57. *
  58. * The complete output generated by the program should be mailed
  59. * such that at least some checks for correctness can be made.
  60. *
  61. ***************************************************************************
  62. *
  63. * History: This version C/2.1 has been made for two reasons:
  64. *
  65. * 1) There is an obvious need for a common C version of
  66. * Dhrystone, since C is at present the most popular system
  67. * programming language for the class of processors
  68. * (microcomputers, minicomputers) where Dhrystone is used most.
  69. * There should be, as far as possible, only one C version of
  70. * Dhrystone such that results can be compared without
  71. * restrictions. In the past, the C versions distributed
  72. * by Rick Richardson (Version 1.1) and by Reinhold Weicker
  73. * had small (though not significant) differences.
  74. *
  75. * 2) As far as it is possible without changes to the Dhrystone
  76. * statistics, optimizing compilers should be prevented from
  77. * removing significant statements.
  78. *
  79. * This C version has been developed in cooperation with
  80. * Rick Richardson (Tinton Falls, NJ), it incorporates many
  81. * ideas from the "Version 1.1" distributed previously by
  82. * him over the UNIX network Usenet.
  83. * I also thank Chaim Benedelac (National Semiconductor),
  84. * David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
  85. * Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
  86. * for their help with comments on earlier versions of the
  87. * benchmark.
  88. *
  89. * Changes: In the initialization part, this version follows mostly
  90. * Rick Richardson's version distributed via Usenet, not the
  91. * version distributed earlier via floppy disk by Reinhold Weicker.
  92. * As a concession to older compilers, names have been made
  93. * unique within the first 8 characters.
  94. * Inside the measurement loop, this version follows the
  95. * version previously distributed by Reinhold Weicker.
  96. *
  97. * At several places in the benchmark, code has been added,
  98. * but within the measurement loop only in branches that
  99. * are not executed. The intention is that optimizing compilers
  100. * should be prevented from moving code out of the measurement
  101. * loop, or from removing code altogether. Since the statements
  102. * that are executed within the measurement loop have NOT been
  103. * changed, the numbers defining the "Dhrystone distribution"
  104. * (distribution of statements, operand types and locality)
  105. * still hold. Except for sophisticated optimizing compilers,
  106. * execution times for this version should be the same as
  107. * for previous versions.
  108. *
  109. * Since it has proven difficult to subtract the time for the
  110. * measurement loop overhead in a correct way, the loop check
  111. * has been made a part of the benchmark. This does have
  112. * an impact - though a very minor one - on the distribution
  113. * statistics which have been updated for this version.
  114. *
  115. * All changes within the measurement loop are described
  116. * and discussed in the companion paper "Rationale for
  117. * Dhrystone version 2".
  118. *
  119. * Because of the self-imposed limitation that the order and
  120. * distribution of the executed statements should not be
  121. * changed, there are still cases where optimizing compilers
  122. * may not generate code for some statements. To a certain
  123. * degree, this is unavoidable for small synthetic benchmarks.
  124. * Users of the benchmark are advised to check code listings
  125. * whether code is generated for all statements of Dhrystone.
  126. *
  127. * Version 2.1 is identical to version 2.0 distributed via
  128. * the UNIX network Usenet in March 1988 except that it corrects
  129. * some minor deficiencies that were found by users of version 2.0.
  130. * The only change within the measurement loop is that a
  131. * non-executed "else" part was added to the "if" statement in
  132. * Func_3, and a non-executed "else" part removed from Proc_3.
  133. *
  134. ***************************************************************************
  135. *
  136. * Defines: The following "Defines" are possible:
  137. * -DREG=register (default: Not defined)
  138. * As an approximation to what an average C programmer
  139. * might do, the "register" storage class is applied
  140. * (if enabled by -DREG=register)
  141. * - for local variables, if they are used (dynamically)
  142. * five or more times
  143. * - for parameters if they are used (dynamically)
  144. * six or more times
  145. * Note that an optimal "register" strategy is
  146. * compiler-dependent, and that "register" declarations
  147. * do not necessarily lead to faster execution.
  148. * -DNOSTRUCTASSIGN (default: Not defined)
  149. * Define if the C compiler does not support
  150. * assignment of structures.
  151. * -DNOENUMS (default: Not defined)
  152. * Define if the C compiler does not support
  153. * enumeration types.
  154. * -DTIMES (default)
  155. * -DTIME
  156. * The "times" function of UNIX (returning process times)
  157. * or the "time" function (returning wallclock time)
  158. * is used for measurement.
  159. * For single user machines, "time ()" is adequate. For
  160. * multi-user machines where you cannot get single-user
  161. * access, use the "times ()" function. If you have
  162. * neither, use a stopwatch in the dead of night.
  163. * "printf"s are provided marking the points "Start Timer"
  164. * and "Stop Timer". DO NOT use the UNIX "time(1)"
  165. * command, as this will measure the total time to
  166. * run this program, which will (erroneously) include
  167. * the time to allocate storage (malloc) and to perform
  168. * the initialization.
  169. * -DHZ=nnn
  170. * In Berkeley UNIX, the function "times" returns process
  171. * time in 1/HZ seconds, with HZ = 60 for most systems.
  172. * CHECK YOUR SYSTEM DESCRIPTION BEFORE YOU JUST APPLY
  173. * A VALUE.
  174. *
  175. ***************************************************************************
  176. *
  177. * Compilation model and measurement (IMPORTANT):
  178. *
  179. * This C version of Dhrystone consists of three files:
  180. * - dhry.h (this file, containing global definitions and comments)
  181. * - dhry_1.c (containing the code corresponding to Ada package Pack_1)
  182. * - dhry_2.c (containing the code corresponding to Ada package Pack_2)
  183. *
  184. * The following "ground rules" apply for measurements:
  185. * - Separate compilation
  186. * - No procedure merging
  187. * - Otherwise, compiler optimizations are allowed but should be indicated
  188. * - Default results are those without register declarations
  189. * See the companion paper "Rationale for Dhrystone Version 2" for a more
  190. * detailed discussion of these ground rules.
  191. *
  192. * For 16-Bit processors (e.g. 80186, 80286), times for all compilation
  193. * models ("small", "medium", "large" etc.) should be given if possible,
  194. * together with a definition of these models for the compiler system used.
  195. *
  196. **************************************************************************
  197. *
  198. * Dhrystone (C version) statistics:
  199. *
  200. * [Comment from the first distribution, updated for version 2.
  201. * Note that because of language differences, the numbers are slightly
  202. * different from the Ada version.]
  203. *
  204. * The following program contains statements of a high level programming
  205. * language (here: C) in a distribution considered representative:
  206. *
  207. * assignments 52 (51.0 %)
  208. * control statements 33 (32.4 %)
  209. * procedure, function calls 17 (16.7 %)
  210. *
  211. * 103 statements are dynamically executed. The program is balanced with
  212. * respect to the three aspects:
  213. *
  214. * - statement type
  215. * - operand type
  216. * - operand locality
  217. * operand global, local, parameter, or constant.
  218. *
  219. * The combination of these three aspects is balanced only approximately.
  220. *
  221. * 1. Statement Type:
  222. * ----------------- number
  223. *
  224. * V1 = V2 9
  225. * (incl. V1 = F(..)
  226. * V = Constant 12
  227. * Assignment, 7
  228. * with array element
  229. * Assignment, 6
  230. * with record component
  231. * --
  232. * 34 34
  233. *
  234. * X = Y +|-|"&&"|"|" Z 5
  235. * X = Y +|-|"==" Constant 6
  236. * X = X +|- 1 3
  237. * X = Y *|/ Z 2
  238. * X = Expression, 1
  239. * two operators
  240. * X = Expression, 1
  241. * three operators
  242. * --
  243. * 18 18
  244. *
  245. * if .... 14
  246. * with "else" 7
  247. * without "else" 7
  248. * executed 3
  249. * not executed 4
  250. * for ... 7 | counted every time
  251. * while ... 4 | the loop condition
  252. * do ... while 1 | is evaluated
  253. * switch ... 1
  254. * break 1
  255. * declaration with 1
  256. * initialization
  257. * --
  258. * 34 34
  259. *
  260. * P (...) procedure call 11
  261. * user procedure 10
  262. * library procedure 1
  263. * X = F (...)
  264. * function call 6
  265. * user function 5
  266. * library function 1
  267. * --
  268. * 17 17
  269. * ---
  270. * 103
  271. *
  272. * The average number of parameters in procedure or function calls
  273. * is 1.82 (not counting the function values as implicit parameters).
  274. *
  275. *
  276. * 2. Operators
  277. * ------------
  278. * number approximate
  279. * percentage
  280. *
  281. * Arithmetic 32 50.8
  282. *
  283. * + 21 33.3
  284. * - 7 11.1
  285. * * 3 4.8
  286. * / (int div) 1 1.6
  287. *
  288. * Comparison 27 42.8
  289. *
  290. * == 9 14.3
  291. * /= 4 6.3
  292. * > 1 1.6
  293. * < 3 4.8
  294. * >= 1 1.6
  295. * <= 9 14.3
  296. *
  297. * Logic 4 6.3
  298. *
  299. * && (AND-THEN) 1 1.6
  300. * | (OR) 1 1.6
  301. * ! (NOT) 2 3.2
  302. *
  303. * -- -----
  304. * 63 100.1
  305. *
  306. *
  307. * 3. Operand Type (counted once per operand reference):
  308. * ---------------
  309. * number approximate
  310. * percentage
  311. *
  312. * Integer 175 72.3 %
  313. * Character 45 18.6 %
  314. * Pointer 12 5.0 %
  315. * String30 6 2.5 %
  316. * Array 2 0.8 %
  317. * Record 2 0.8 %
  318. * --- -------
  319. * 242 100.0 %
  320. *
  321. * When there is an access path leading to the final operand (e.g. a record
  322. * component), only the final data type on the access path is counted.
  323. *
  324. *
  325. * 4. Operand Locality:
  326. * -------------------
  327. * number approximate
  328. * percentage
  329. *
  330. * local variable 114 47.1 %
  331. * global variable 22 9.1 %
  332. * parameter 45 18.6 %
  333. * value 23 9.5 %
  334. * reference 22 9.1 %
  335. * function result 6 2.5 %
  336. * constant 55 22.7 %
  337. * --- -------
  338. * 242 100.0 %
  339. *
  340. *
  341. * The program does not compute anything meaningful, but it is syntactically
  342. * and semantically correct. All variables have a value assigned to them
  343. * before they are used as a source operand.
  344. *
  345. * There has been no explicit effort to account for the effects of a
  346. * cache, or to balance the use of long or short displacements for code or
  347. * data.
  348. *
  349. ***************************************************************************
  350. */
  351. /* Compiler and system dependent definitions: */
  352. #define CLOCK
  353. #ifdef CLOCK
  354. #include <time.h>
  355. #endif
  356. /*
  357. #ifndef TIME
  358. #define TIMES
  359. #endif
  360. */
  361. /* Use times(2) time function unless */
  362. /* explicitly defined otherwise */
  363. #ifdef TIMES
  364. #include <sys/types.h>
  365. #include <sys/times.h>
  366. #endif /* for "times" */
  367. #define Mic_secs_Per_Second 1000000.0
  368. /* Berkeley UNIX C returns process times in seconds/HZ */
  369. #ifdef NOSTRUCTASSIGN
  370. #define structassign(d, s) memcpy(&(d), &(s), sizeof(d))
  371. #else
  372. #define structassign(d, s) d = s
  373. #endif
  374. #ifdef NOENUM
  375. #define Ident_1 0
  376. #define Ident_2 1
  377. #define Ident_3 2
  378. #define Ident_4 3
  379. #define Ident_5 4
  380. typedef int Enumeration;
  381. #else
  382. typedef enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
  383. Enumeration;
  384. #endif
  385. /* for boolean and enumeration types in Ada, Pascal */
  386. /* General definitions: */
  387. #include <stdio.h>
  388. /* Added by JRJ. for strcpy and strcmp. */
  389. #include <string.h>
  390. /* Added by JRJ for malloc. */
  391. #include <stdlib.h>
  392. //#include <cmalloc.h>
  393. #define Null 0
  394. /* Value of a Null pointer */
  395. #define true 1
  396. #define false 0
  397. typedef int One_Thirty;
  398. typedef int One_Fifty;
  399. typedef char Capital_Letter;
  400. typedef int Boolean;
  401. typedef char Str_30 [31];
  402. typedef int Arr_1_Dim [50];
  403. typedef int Arr_2_Dim [50] [50];
  404. typedef struct record
  405. {
  406. struct record *Ptr_Comp;
  407. Enumeration Discr;
  408. union {
  409. struct {
  410. Enumeration Enum_Comp;
  411. int Int_Comp;
  412. char Str_Comp [31];
  413. } var_1;
  414. struct {
  415. Enumeration E_Comp_2;
  416. char Str_2_Comp [31];
  417. } var_2;
  418. struct {
  419. char Ch_1_Comp;
  420. char Ch_2_Comp;
  421. } var_3;
  422. } variant;
  423. } Rec_Type, *Rec_Pointer;
  424. extern void Proc_1 (Rec_Pointer Ptr_Val_Par);
  425. extern void Proc_2 (One_Fifty *Int_Par_Ref);
  426. extern void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
  427. extern void Proc_4 (void);
  428. extern void Proc_5 (void);
  429. extern void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par);
  430. extern void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref);
  431. extern void Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val);
  432. extern Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
  433. extern Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);
  434. extern Boolean Func_3 (Enumeration Enum_Par_Val);
  435. int dhrystoneRun (int Number_Of_Runs);
  436. #endif // DHRY_H