359 lines · c
1/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */2/*3 ****************************************************************************4 *5 * "DHRYSTONE" Benchmark Program6 * -----------------------------7 *8 * Version: C, Version 2.19 *10 * File: dhry.h (part 1 of 3)11 *12 * Date: May 25, 198813 *14 * Author: Reinhold P. Weicker15 * Siemens AG, AUT E 5116 * Postfach 322017 * 8520 Erlangen18 * Germany (West)19 * Phone: [+49]-9131-7-2033020 * (8-17 Central European Time)21 * Usenet: ..!mcsun!unido!estevax!weicker22 *23 * Original Version (in Ada) published in24 * "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),25 * pp. 1013 - 1030, together with the statistics26 * on which the distribution of statements etc. is based.27 *28 * In this C version, the following C library functions are used:29 * - strcpy, strcmp (inside the measurement loop)30 * - printf, scanf (outside the measurement loop)31 * In addition, Berkeley UNIX system calls "times ()" or "time ()"32 * are used for execution time measurement. For measurements33 * on other systems, these calls have to be changed.34 *35 * Collection of Results:36 * Reinhold Weicker (address see above) and37 *38 * Rick Richardson39 * PC Research. Inc.40 * 94 Apple Orchard Drive41 * Tinton Falls, NJ 0772442 * Phone: (201) 389-8963 (9-17 EST)43 * Usenet: ...!uunet!pcrat!rick44 *45 * Please send results to Rick Richardson and/or Reinhold Weicker.46 * Complete information should be given on hardware and software used.47 * Hardware information includes: Machine type, CPU, type and size48 * of caches; for microprocessors: clock frequency, memory speed49 * (number of wait states).50 * Software information includes: Compiler (and runtime library)51 * manufacturer and version, compilation switches, OS version.52 * The Operating System version may give an indication about the53 * compiler; Dhrystone itself performs no OS calls in the measurement loop.54 *55 * The complete output generated by the program should be mailed56 * such that at least some checks for correctness can be made.57 *58 ***************************************************************************59 *60 * History: This version C/2.1 has been made for two reasons:61 *62 * 1) There is an obvious need for a common C version of63 * Dhrystone, since C is at present the most popular system64 * programming language for the class of processors65 * (microcomputers, minicomputers) where Dhrystone is used most.66 * There should be, as far as possible, only one C version of67 * Dhrystone such that results can be compared without68 * restrictions. In the past, the C versions distributed69 * by Rick Richardson (Version 1.1) and by Reinhold Weicker70 * had small (though not significant) differences.71 *72 * 2) As far as it is possible without changes to the Dhrystone73 * statistics, optimizing compilers should be prevented from74 * removing significant statements.75 *76 * This C version has been developed in cooperation with77 * Rick Richardson (Tinton Falls, NJ), it incorporates many78 * ideas from the "Version 1.1" distributed previously by79 * him over the UNIX network Usenet.80 * I also thank Chaim Benedelac (National Semiconductor),81 * David Ditzel (SUN), Earl Killian and John Mashey (MIPS),82 * Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)83 * for their help with comments on earlier versions of the84 * benchmark.85 *86 * Changes: In the initialization part, this version follows mostly87 * Rick Richardson's version distributed via Usenet, not the88 * version distributed earlier via floppy disk by Reinhold Weicker.89 * As a concession to older compilers, names have been made90 * unique within the first 8 characters.91 * Inside the measurement loop, this version follows the92 * version previously distributed by Reinhold Weicker.93 *94 * At several places in the benchmark, code has been added,95 * but within the measurement loop only in branches that96 * are not executed. The intention is that optimizing compilers97 * should be prevented from moving code out of the measurement98 * loop, or from removing code altogether. Since the statements99 * that are executed within the measurement loop have NOT been100 * changed, the numbers defining the "Dhrystone distribution"101 * (distribution of statements, operand types and locality)102 * still hold. Except for sophisticated optimizing compilers,103 * execution times for this version should be the same as104 * for previous versions.105 *106 * Since it has proven difficult to subtract the time for the107 * measurement loop overhead in a correct way, the loop check108 * has been made a part of the benchmark. This does have109 * an impact - though a very minor one - on the distribution110 * statistics which have been updated for this version.111 *112 * All changes within the measurement loop are described113 * and discussed in the companion paper "Rationale for114 * Dhrystone version 2".115 *116 * Because of the self-imposed limitation that the order and117 * distribution of the executed statements should not be118 * changed, there are still cases where optimizing compilers119 * may not generate code for some statements. To a certain120 * degree, this is unavoidable for small synthetic benchmarks.121 * Users of the benchmark are advised to check code listings122 * whether code is generated for all statements of Dhrystone.123 *124 * Version 2.1 is identical to version 2.0 distributed via125 * the UNIX network Usenet in March 1988 except that it corrects126 * some minor deficiencies that were found by users of version 2.0.127 * The only change within the measurement loop is that a128 * non-executed "else" part was added to the "if" statement in129 * Func_3, and a non-executed "else" part removed from Proc_3.130 *131 ***************************************************************************132 *133 * Compilation model and measurement (IMPORTANT):134 *135 * This C version of Dhrystone consists of three files:136 * - dhry.h (this file, containing global definitions and comments)137 * - dhry_1.c (containing the code corresponding to Ada package Pack_1)138 * - dhry_2.c (containing the code corresponding to Ada package Pack_2)139 *140 * The following "ground rules" apply for measurements:141 * - Separate compilation142 * - No procedure merging143 * - Otherwise, compiler optimizations are allowed but should be indicated144 * - Default results are those without register declarations145 * See the companion paper "Rationale for Dhrystone Version 2" for a more146 * detailed discussion of these ground rules.147 *148 * For 16-Bit processors (e.g. 80186, 80286), times for all compilation149 * models ("small", "medium", "large" etc.) should be given if possible,150 * together with a definition of these models for the compiler system used.151 *152 **************************************************************************153 *154 * Dhrystone (C version) statistics:155 *156 * [Comment from the first distribution, updated for version 2.157 * Note that because of language differences, the numbers are slightly158 * different from the Ada version.]159 *160 * The following program contains statements of a high level programming161 * language (here: C) in a distribution considered representative:162 *163 * assignments 52 (51.0 %)164 * control statements 33 (32.4 %)165 * procedure, function calls 17 (16.7 %)166 *167 * 103 statements are dynamically executed. The program is balanced with168 * respect to the three aspects:169 *170 * - statement type171 * - operand type172 * - operand locality173 * operand global, local, parameter, or constant.174 *175 * The combination of these three aspects is balanced only approximately.176 *177 * 1. Statement Type:178 * ----------------- number179 *180 * V1 = V2 9181 * (incl. V1 = F(..)182 * V = Constant 12183 * Assignment, 7184 * with array element185 * Assignment, 6186 * with record component187 * --188 * 34 34189 *190 * X = Y +|-|"&&"|"|" Z 5191 * X = Y +|-|"==" Constant 6192 * X = X +|- 1 3193 * X = Y *|/ Z 2194 * X = Expression, 1195 * two operators196 * X = Expression, 1197 * three operators198 * --199 * 18 18200 *201 * if .... 14202 * with "else" 7203 * without "else" 7204 * executed 3205 * not executed 4206 * for ... 7 | counted every time207 * while ... 4 | the loop condition208 * do ... while 1 | is evaluated209 * switch ... 1210 * break 1211 * declaration with 1212 * initialization213 * --214 * 34 34215 *216 * P (...) procedure call 11217 * user procedure 10218 * library procedure 1219 * X = F (...)220 * function call 6221 * user function 5222 * library function 1223 * --224 * 17 17225 * ---226 * 103227 *228 * The average number of parameters in procedure or function calls229 * is 1.82 (not counting the function values as implicit parameters).230 *231 *232 * 2. Operators233 * ------------234 * number approximate235 * percentage236 *237 * Arithmetic 32 50.8238 *239 * + 21 33.3240 * - 7 11.1241 * * 3 4.8242 * / (int div) 1 1.6243 *244 * Comparison 27 42.8245 *246 * == 9 14.3247 * /= 4 6.3248 * > 1 1.6249 * < 3 4.8250 * >= 1 1.6251 * <= 9 14.3252 *253 * Logic 4 6.3254 *255 * && (AND-THEN) 1 1.6256 * | (OR) 1 1.6257 * ! (NOT) 2 3.2258 *259 * -- -----260 * 63 100.1261 *262 *263 * 3. Operand Type (counted once per operand reference):264 * ---------------265 * number approximate266 * percentage267 *268 * Integer 175 72.3 %269 * Character 45 18.6 %270 * Pointer 12 5.0 %271 * String30 6 2.5 %272 * Array 2 0.8 %273 * Record 2 0.8 %274 * --- -------275 * 242 100.0 %276 *277 * When there is an access path leading to the final operand (e.g. a record278 * component), only the final data type on the access path is counted.279 *280 *281 * 4. Operand Locality:282 * -------------------283 * number approximate284 * percentage285 *286 * local variable 114 47.1 %287 * global variable 22 9.1 %288 * parameter 45 18.6 %289 * value 23 9.5 %290 * reference 22 9.1 %291 * function result 6 2.5 %292 * constant 55 22.7 %293 * --- -------294 * 242 100.0 %295 *296 *297 * The program does not compute anything meaningful, but it is syntactically298 * and semantically correct. All variables have a value assigned to them299 * before they are used as a source operand.300 *301 * There has been no explicit effort to account for the effects of a302 * cache, or to balance the use of long or short displacements for code or303 * data.304 *305 ***************************************************************************306 */307 308typedef enum {309 Ident_1,310 Ident_2,311 Ident_3,312 Ident_4,313 Ident_5314} Enumeration; /* for boolean and enumeration types in Ada, Pascal */315 316/* General definitions: */317 318typedef int One_Thirty;319typedef int One_Fifty;320typedef char Capital_Letter;321typedef int Boolean;322typedef char Str_30[31];323typedef int Arr_1_Dim[50];324typedef int Arr_2_Dim[50][50];325 326typedef struct record {327 struct record *Ptr_Comp;328 Enumeration Discr;329 union {330 struct {331 Enumeration Enum_Comp;332 int Int_Comp;333 char Str_Comp[31];334 } var_1;335 struct {336 Enumeration E_Comp_2;337 char Str_2_Comp[31];338 } var_2;339 struct {340 char Ch_1_Comp;341 char Ch_2_Comp;342 } var_3;343 } variant;344} Rec_Type, *Rec_Pointer;345 346 347extern int Int_Glob;348extern char Ch_1_Glob;349 350void Proc_6(Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par);351void Proc_7(One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val,352 One_Fifty *Int_Par_Ref);353void Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref,354 int Int_1_Par_Val, int Int_2_Par_Val);355Enumeration Func_1(Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);356Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);357 358int dhry(int n);359