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