dhrystone.h 19 KB

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