dhry.h 19 KB

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