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