![]() |
|
|||
File indexing completed on 2025-05-11 08:24:28
0001 /* 0002 **************************************************************************** 0003 * 0004 * "DHRYSTONE" Benchmark Program 0005 * ----------------------------- 0006 * 0007 * Version: C, Version 2.1 0008 * 0009 * File: dhry.h (part 1 of 3) 0010 * 0011 * Date: May 25, 1988 0012 * 0013 * Author: Reinhold P. Weicker 0014 * Siemens AG, AUT E 51 0015 * Postfach 3220 0016 * 8520 Erlangen 0017 * Germany (West) 0018 * Phone: [+49]-9131-7-20330 0019 * (8-17 Central European Time) 0020 * Usenet: ..!mcsun!unido!estevax!weicker 0021 * 0022 * Original Version (in Ada) published in 0023 * "Communications of the ACM" vol. 27., no. 10 (Oct. 1984), 0024 * pp. 1013 - 1030, together with the statistics 0025 * on which the distribution of statements etc. is based. 0026 * 0027 * In this C version, the following C library functions are used: 0028 * - strcpy, strcmp (inside the measurement loop) 0029 * - printf, scanf (outside the measurement loop) 0030 * In addition, Berkeley UNIX system calls "times ()" or "time ()" 0031 * are used for execution time measurement. For measurements 0032 * on other systems, these calls have to be changed. 0033 * 0034 * Collection of Results: 0035 * Reinhold Weicker (address see above) and 0036 * 0037 * Rick Richardson 0038 * PC Research. Inc. 0039 * 94 Apple Orchard Drive 0040 * Tinton Falls, NJ 07724 0041 * Phone: (201) 389-8963 (9-17 EST) 0042 * Usenet: ...!uunet!pcrat!rick 0043 * 0044 * Please send results to Rick Richardson and/or Reinhold Weicker. 0045 * Complete information should be given on hardware and software used. 0046 * Hardware information includes: Machine type, CPU, type and size 0047 * of caches; for microprocessors: clock frequency, memory speed 0048 * (number of wait states). 0049 * Software information includes: Compiler (and runtime library) 0050 * manufacturer and version, compilation switches, OS version. 0051 * The Operating System version may give an indication about the 0052 * compiler; Dhrystone itself performs no OS calls in the measurement loop. 0053 * 0054 * The complete output generated by the program should be mailed 0055 * such that at least some checks for correctness can be made. 0056 * 0057 *************************************************************************** 0058 * 0059 * History: This version C/2.1 has been made for two reasons: 0060 * 0061 * 1) There is an obvious need for a common C version of 0062 * Dhrystone, since C is at present the most popular system 0063 * programming language for the class of processors 0064 * (microcomputers, minicomputers) where Dhrystone is used most. 0065 * There should be, as far as possible, only one C version of 0066 * Dhrystone such that results can be compared without 0067 * restrictions. In the past, the C versions distributed 0068 * by Rick Richardson (Version 1.1) and by Reinhold Weicker 0069 * had small (though not significant) differences. 0070 * 0071 * 2) As far as it is possible without changes to the Dhrystone 0072 * statistics, optimizing compilers should be prevented from 0073 * removing significant statements. 0074 * 0075 * This C version has been developed in cooperation with 0076 * Rick Richardson (Tinton Falls, NJ), it incorporates many 0077 * ideas from the "Version 1.1" distributed previously by 0078 * him over the UNIX network Usenet. 0079 * I also thank Chaim Benedelac (National Semiconductor), 0080 * David Ditzel (SUN), Earl Killian and John Mashey (MIPS), 0081 * Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley) 0082 * for their help with comments on earlier versions of the 0083 * benchmark. 0084 * 0085 * Changes: In the initialization part, this version follows mostly 0086 * Rick Richardson's version distributed via Usenet, not the 0087 * version distributed earlier via floppy disk by Reinhold Weicker. 0088 * As a concession to older compilers, names have been made 0089 * unique within the first 8 characters. 0090 * Inside the measurement loop, this version follows the 0091 * version previously distributed by Reinhold Weicker. 0092 * 0093 * At several places in the benchmark, code has been added, 0094 * but within the measurement loop only in branches that 0095 * are not executed. The intention is that optimizing compilers 0096 * should be prevented from moving code out of the measurement 0097 * loop, or from removing code altogether. Since the statements 0098 * that are executed within the measurement loop have NOT been 0099 * changed, the numbers defining the "Dhrystone distribution" 0100 * (distribution of statements, operand types and locality) 0101 * still hold. Except for sophisticated optimizing compilers, 0102 * execution times for this version should be the same as 0103 * for previous versions. 0104 * 0105 * Since it has proven difficult to subtract the time for the 0106 * measurement loop overhead in a correct way, the loop check 0107 * has been made a part of the benchmark. This does have 0108 * an impact - though a very minor one - on the distribution 0109 * statistics which have been updated for this version. 0110 * 0111 * All changes within the measurement loop are described 0112 * and discussed in the companion paper "Rationale for 0113 * Dhrystone version 2". 0114 * 0115 * Because of the self-imposed limitation that the order and 0116 * distribution of the executed statements should not be 0117 * changed, there are still cases where optimizing compilers 0118 * may not generate code for some statements. To a certain 0119 * degree, this is unavoidable for small synthetic benchmarks. 0120 * Users of the benchmark are advised to check code listings 0121 * whether code is generated for all statements of Dhrystone. 0122 * 0123 * Version 2.1 is identical to version 2.0 distributed via 0124 * the UNIX network Usenet in March 1988 except that it corrects 0125 * some minor deficiencies that were found by users of version 2.0. 0126 * The only change within the measurement loop is that a 0127 * non-executed "else" part was added to the "if" statement in 0128 * Func_3, and a non-executed "else" part removed from Proc_3. 0129 * 0130 *************************************************************************** 0131 * 0132 * Defines: The following "Defines" are possible: 0133 * -DREG=register (default: Not defined) 0134 * As an approximation to what an average C programmer 0135 * might do, the "register" storage class is applied 0136 * (if enabled by -DREG=register) 0137 * - for local variables, if they are used (dynamically) 0138 * five or more times 0139 * - for parameters if they are used (dynamically) 0140 * six or more times 0141 * Note that an optimal "register" strategy is 0142 * compiler-dependent, and that "register" declarations 0143 * do not necessarily lead to faster execution. 0144 * -DNOSTRUCTASSIGN (default: Not defined) 0145 * Define if the C compiler does not support 0146 * assignment of structures. 0147 * -DNOENUMS (default: Not defined) 0148 * Define if the C compiler does not support 0149 * enumeration types. 0150 * -DTIMES (default) 0151 * -DTIME 0152 * The "times" function of UNIX (returning process times) 0153 * or the "time" function (returning wallclock time) 0154 * is used for measurement. 0155 * For single user machines, "time ()" is adequate. For 0156 * multi-user machines where you cannot get single-user 0157 * access, use the "times ()" function. If you have 0158 * neither, use a stopwatch in the dead of night. 0159 * "printf"s are provided marking the points "Start Timer" 0160 * and "Stop Timer". DO NOT use the UNIX "time(1)" 0161 * command, as this will measure the total time to 0162 * run this program, which will (erroneously) include 0163 * the time to allocate storage (malloc) and to perform 0164 * the initialization. 0165 * -DHZ=nnn 0166 * In Berkeley UNIX, the function "times" returns process 0167 * time in 1/HZ seconds, with HZ = 60 for most systems. 0168 * CHECK YOUR SYSTEM DESCRIPTION BEFORE YOU JUST APPLY 0169 * A VALUE. 0170 * 0171 *************************************************************************** 0172 * 0173 * Compilation model and measurement (IMPORTANT): 0174 * 0175 * This C version of Dhrystone consists of three files: 0176 * - dhry.h (this file, containing global definitions and comments) 0177 * - dhry_1.c (containing the code corresponding to Ada package Pack_1) 0178 * - dhry_2.c (containing the code corresponding to Ada package Pack_2) 0179 * 0180 * The following "ground rules" apply for measurements: 0181 * - Separate compilation 0182 * - No procedure merging 0183 * - Otherwise, compiler optimizations are allowed but should be indicated 0184 * - Default results are those without register declarations 0185 * See the companion paper "Rationale for Dhrystone Version 2" for a more 0186 * detailed discussion of these ground rules. 0187 * 0188 * For 16-Bit processors (e.g. 80186, 80286), times for all compilation 0189 * models ("small", "medium", "large" etc.) should be given if possible, 0190 * together with a definition of these models for the compiler system used. 0191 * 0192 ************************************************************************** 0193 * 0194 * Dhrystone (C version) statistics: 0195 * 0196 * [Comment from the first distribution, updated for version 2. 0197 * Note that because of language differences, the numbers are slightly 0198 * different from the Ada version.] 0199 * 0200 * The following program contains statements of a high level programming 0201 * language (here: C) in a distribution considered representative: 0202 * 0203 * assignments 52 (51.0 %) 0204 * control statements 33 (32.4 %) 0205 * procedure, function calls 17 (16.7 %) 0206 * 0207 * 103 statements are dynamically executed. The program is balanced with 0208 * respect to the three aspects: 0209 * 0210 * - statement type 0211 * - operand type 0212 * - operand locality 0213 * operand global, local, parameter, or constant. 0214 * 0215 * The combination of these three aspects is balanced only approximately. 0216 * 0217 * 1. Statement Type: 0218 * ----------------- number 0219 * 0220 * V1 = V2 9 0221 * (incl. V1 = F(..) 0222 * V = Constant 12 0223 * Assignment, 7 0224 * with array element 0225 * Assignment, 6 0226 * with record component 0227 * -- 0228 * 34 34 0229 * 0230 * X = Y +|-|"&&"|"|" Z 5 0231 * X = Y +|-|"==" Constant 6 0232 * X = X +|- 1 3 0233 * X = Y *|/ Z 2 0234 * X = Expression, 1 0235 * two operators 0236 * X = Expression, 1 0237 * three operators 0238 * -- 0239 * 18 18 0240 * 0241 * if .... 14 0242 * with "else" 7 0243 * without "else" 7 0244 * executed 3 0245 * not executed 4 0246 * for ... 7 | counted every time 0247 * while ... 4 | the loop condition 0248 * do ... while 1 | is evaluated 0249 * switch ... 1 0250 * break 1 0251 * declaration with 1 0252 * initialization 0253 * -- 0254 * 34 34 0255 * 0256 * P (...) procedure call 11 0257 * user procedure 10 0258 * library procedure 1 0259 * X = F (...) 0260 * function call 6 0261 * user function 5 0262 * library function 1 0263 * -- 0264 * 17 17 0265 * --- 0266 * 103 0267 * 0268 * The average number of parameters in procedure or function calls 0269 * is 1.82 (not counting the function values as implicit parameters). 0270 * 0271 * 0272 * 2. Operators 0273 * ------------ 0274 * number approximate 0275 * percentage 0276 * 0277 * Arithmetic 32 50.8 0278 * 0279 * + 21 33.3 0280 * - 7 11.1 0281 * * 3 4.8 0282 * / (int div) 1 1.6 0283 * 0284 * Comparison 27 42.8 0285 * 0286 * == 9 14.3 0287 * /= 4 6.3 0288 * > 1 1.6 0289 * < 3 4.8 0290 * >= 1 1.6 0291 * <= 9 14.3 0292 * 0293 * Logic 4 6.3 0294 * 0295 * && (AND-THEN) 1 1.6 0296 * | (OR) 1 1.6 0297 * ! (NOT) 2 3.2 0298 * 0299 * -- ----- 0300 * 63 100.1 0301 * 0302 * 0303 * 3. Operand Type (counted once per operand reference): 0304 * --------------- 0305 * number approximate 0306 * percentage 0307 * 0308 * Integer 175 72.3 % 0309 * Character 45 18.6 % 0310 * Pointer 12 5.0 % 0311 * String30 6 2.5 % 0312 * Array 2 0.8 % 0313 * Record 2 0.8 % 0314 * --- ------- 0315 * 242 100.0 % 0316 * 0317 * When there is an access path leading to the final operand (e.g. a record 0318 * component), only the final data type on the access path is counted. 0319 * 0320 * 0321 * 4. Operand Locality: 0322 * ------------------- 0323 * number approximate 0324 * percentage 0325 * 0326 * local variable 114 47.1 % 0327 * global variable 22 9.1 % 0328 * parameter 45 18.6 % 0329 * value 23 9.5 % 0330 * reference 22 9.1 % 0331 * function result 6 2.5 % 0332 * constant 55 22.7 % 0333 * --- ------- 0334 * 242 100.0 % 0335 * 0336 * 0337 * The program does not compute anything meaningful, but it is syntactically 0338 * and semantically correct. All variables have a value assigned to them 0339 * before they are used as a source operand. 0340 * 0341 * There has been no explicit effort to account for the effects of a 0342 * cache, or to balance the use of long or short displacements for code or 0343 * data. 0344 * 0345 *************************************************************************** 0346 */ 0347 0348 #define TIME 0349 0350 /* Compiler and system dependent definitions: */ 0351 0352 #ifndef TIME 0353 #define TIMES 0354 #endif 0355 /* Use times(2) time function unless */ 0356 /* explicitly defined otherwise */ 0357 0358 #ifdef TIMES 0359 #include <sys/types.h> 0360 #include <sys/times.h> 0361 /* for "times" */ 0362 #endif 0363 0364 #define Mic_secs_Per_Second 1000000.0 0365 /* Berkeley UNIX C returns process times in seconds/HZ */ 0366 0367 #ifdef NOSTRUCTASSIGN 0368 #define structassign(d, s) memcpy(&(d), &(s), sizeof(d)) 0369 #else 0370 #define structassign(d, s) d = s 0371 #endif 0372 0373 #ifdef NOENUM 0374 #define Ident_1 0 0375 #define Ident_2 1 0376 #define Ident_3 2 0377 #define Ident_4 3 0378 #define Ident_5 4 0379 typedef int Enumeration; 0380 #else 0381 typedef enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5} 0382 Enumeration; 0383 #endif 0384 /* for boolean and enumeration types in Ada, Pascal */ 0385 0386 /* General definitions: */ 0387 0388 #include <stdio.h> 0389 /* for strcpy, strcmp */ 0390 0391 #define Null 0 0392 /* Value of a Null pointer */ 0393 #define true 1 0394 #define false 0 0395 0396 typedef int One_Thirty; 0397 typedef int One_Fifty; 0398 typedef char Capital_Letter; 0399 typedef int Boolean; 0400 typedef char Str_30 [31]; 0401 typedef int Arr_1_Dim [50]; 0402 typedef int Arr_2_Dim [50] [50]; 0403 0404 typedef struct record 0405 { 0406 struct record *Ptr_Comp; 0407 Enumeration Discr; 0408 union { 0409 struct { 0410 Enumeration Enum_Comp; 0411 int Int_Comp; 0412 char Str_Comp [31]; 0413 } var_1; 0414 struct { 0415 Enumeration E_Comp_2; 0416 char Str_2_Comp [31]; 0417 } var_2; 0418 struct { 0419 char Ch_1_Comp; 0420 char Ch_2_Comp; 0421 } var_3; 0422 } variant; 0423 } Rec_Type, *Rec_Pointer; 0424 0425 void Proc_1 (Rec_Pointer); 0426 void Proc_2 (One_Fifty *); 0427 void Proc_3 (Rec_Pointer *); 0428 void Proc_4 (void); 0429 void Proc_5 (void); 0430 void Proc_6 (Enumeration, Enumeration *); 0431 void Proc_7 (One_Fifty, One_Fifty, One_Fifty *); 0432 void Proc_8 (Arr_1_Dim, Arr_2_Dim, int, int); 0433 Enumeration Func_1 (Capital_Letter, Capital_Letter); 0434 Boolean Func_2 (Str_30, Str_30); 0435 Boolean Func_3 (Enumeration);
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |