dhry.h 19 KB

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