4 /****************** "DHRYSTONE" Benchmark Program ***************************/
5 #define Version "C, Version 2.2"
6 /* File: dhry_1.c (part 2 of 3)
7 * Author: Reinhold P. Weicker
8 * Siemens Nixdorf, Paderborn/Germany
9 * weicker@specbench.org
11 * Modified: Steven Pemberton, CWI, Amsterdam; Steven.Pemberton@cwi.nl
12 * Date: October, 1993; March 1995
13 * Included both files into one source, that gets compiled
14 * in two passes. Made program auto-compiling, and auto-running,
15 * and generally made it much easier to use.
17 * Original Version (in Ada) published in
18 * "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
19 * pp. 1013 - 1030, together with the statistics
20 * on which the distribution of statements etc. is based.
22 * In this C version, the following C library functions are used:
23 * - strcpy, strcmp (inside the measurement loop)
24 * - printf, scanf (outside the measurement loop)
25 * In addition, Berkeley UNIX system calls "times ()" or "time ()"
26 * are used for execution time measurement. For measurements
27 * on other systems, these calls have to be changed.
29 * Collection of Results:
30 * Reinhold Weicker (address see above) and
34 * 94 Apple Orchard Drive
35 * Tinton Falls, NJ 07724
36 * Phone: (201) 389-8963 (9-17 EST)
37 * Usenet: ...!uunet!pcrat!rick
39 * Please send results to Rick Richardson and/or Reinhold Weicker.
40 * Complete information should be given on hardware and software used.
41 * Hardware information includes: Machine type, CPU, type and size
42 * of caches; for microprocessors: clock frequency, memory speed
43 * (number of wait states).
44 * Software information includes: Compiler (and runtime library)
45 * manufacturer and version, compilation switches, OS version.
46 * The Operating System version may give an indication about the compiler;
47 * Dhrystone itself performs no OS calls in the measurement loop.
49 * The complete output generated by the program should be mailed
50 * such that at least some checks for correctness can be made.
52 ***************************************************************************
54 * Defines: The following "Defines" are possible:
55 * -DREG (default: Not defined)
56 * As an approximation to what an average C programmer
57 * might do, causes the "register" storage class to be applied
58 * - for local variables, if they are used (dynamically)
60 * - for parameters if they are used (dynamically)
62 * Note that an optimal "register" strategy is
63 * compiler-dependent, and that "register" declarations
64 * do not necessarily lead to faster execution.
65 * -DNOSTRUCTASSIGN (default: Not defined)
66 * Define if the C compiler does not support
67 * assignment of structures.
68 * -DNOENUMS (default: Not defined)
69 * Define if the C compiler does not support
73 * The "times" function of UNIX (returning process times)
74 * or the "time" function (returning wallclock time)
75 * is used for measurement.
76 * For single user machines, "time ()" is adequate. For
77 * multi-user machines where you cannot get single-user
78 * access, use the "times ()" function. If you have
79 * neither, use a stopwatch in the dead of night.
80 * "printf"s are provided marking the points "Start Timer"
81 * and "Stop Timer". DO NOT use the UNIX "time(1)"
82 * command, as this will measure the total time to
83 * run this program, which will (erroneously) include
84 * the time to allocate storage (malloc) and to perform
87 * In Berkeley UNIX, the function "times" returns process
88 * time in 1/HZ seconds, with HZ = 60 for most systems.
89 * CHECK YOUR SYSTEM DESCRIPTION BEFORE YOU JUST APPLY
92 ***************************************************************************
94 * History: Version C/2.1 was made for two reasons:
96 * 1) There was an obvious need for a common C version of
97 * Dhrystone, since C is at present the most popular system
98 * programming language for the class of processors
99 * (microcomputers, minicomputers) where Dhrystone is used most.
100 * There should be, as far as possible, only one C version of
101 * Dhrystone such that results can be compared without
102 * restrictions. In the past, the C versions distributed
103 * by Rick Richardson (Version 1.1) and by Reinhold Weicker
104 * had small (though not significant) differences.
106 * 2) As far as it is possible without changes to the Dhrystone
107 * statistics, optimizing compilers should be prevented from
108 * removing significant statements.
110 * This C version has been developed in cooperation with
111 * Rick Richardson (Tinton Falls, NJ), it incorporates many
112 * ideas from the "Version 1.1" distributed previously by
113 * him over the UNIX network Usenet.
114 * I also thank Chaim Benedelac (National Semiconductor),
115 * David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
116 * Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
117 * for their help with comments on earlier versions of the
120 * Changes: In the initialization part, this version follows mostly
121 * Rick Richardson's version distributed via Usenet, not the
122 * version distributed earlier via floppy disk by Reinhold Weicker.
123 * As a concession to older compilers, names have been made
124 * unique within the first 8 characters.
125 * Inside the measurement loop, this version follows the
126 * version previously distributed by Reinhold Weicker.
128 * At several places in the benchmark, code has been added,
129 * but within the measurement loop only in branches that
130 * are not executed. The intention is that optimizing compilers
131 * should be prevented from moving code out of the measurement
132 * loop, or from removing code altogether. Since the statements
133 * that are executed within the measurement loop have NOT been
134 * changed, the numbers defining the "Dhrystone distribution"
135 * (distribution of statements, operand types and locality)
136 * still hold. Except for sophisticated optimizing compilers,
137 * execution times for this version should be the same as
138 * for previous versions.
140 * Since it has proven difficult to subtract the time for the
141 * measurement loop overhead in a correct way, the loop check
142 * has been made a part of the benchmark. This does have
143 * an impact - though a very minor one - on the distribution
144 * statistics which have been updated for this version.
146 * All changes within the measurement loop are described
147 * and discussed in the companion paper "Rationale for
148 * Dhrystone version 2".
150 * Because of the self-imposed limitation that the order and
151 * distribution of the executed statements should not be
152 * changed, there are still cases where optimizing compilers
153 * may not generate code for some statements. To a certain
154 * degree, this is unavoidable for small synthetic benchmarks.
155 * Users of the benchmark are advised to check code listings
156 * whether code is generated for all statements of Dhrystone.
158 * Version 2.1 is identical to version 2.0 distributed via
159 * the UNIX network Usenet in March 1988 except that it corrects
160 * some minor deficiencies that were found by users of version 2.0.
161 * The only change within the measurement loop is that a
162 * non-executed "else" part was added to the "if" statement in
163 * Func_3, and a non-executed "else" part removed from Proc_3.
165 * Version C/2.2, Steven Pemberton, October 1993
166 * Functionally, identical to version 2.2; the changes are in
167 * how you compile and use it:
168 * - Everything is in one file now, but compiled in 2 passes
169 * - Compile (and run) by running the file through the shell: 'sh dhry.c"
170 * - Uses the system definition of HZ if one can be found
171 * - HZ must be defined, otherwise it won't compile (no defaults here)
172 * - The (uninteresting) output is printed to stderr (dhry2 > /dev/null)
173 * - The number of loops is passed as a parameter, rather than read
175 * - If the number of loops is insufficient to get a good result,
176 * it repeats it with loops*10 until it is enough (rather than just
178 * - Output says which sort of clock it is using, and the HZ value
179 * - You can use -DREG instead of the -DREG=register of previous versions
180 * - Some stylistic cleanups.
182 ***************************************************************************
184 * Compilation model and measurement (IMPORTANT):
186 * The following "ground rules" apply for measurements:
187 * - Separate compilation
188 * - No procedure merging
189 * - Otherwise, compiler optimizations are allowed but should be indicated
190 * - Default results are those without register declarations
191 * See the companion paper "Rationale for Dhrystone Version 2" for a more
192 * detailed discussion of these ground rules.
194 * For 16-Bit processors (e.g. 80186, 80286), times for all compilation
195 * models ("small", "medium", "large" etc.) should be given if possible,
196 * together with a definition of these models for the compiler system used.
198 **************************************************************************
200 * Dhrystone (C version) statistics:
202 * [Comment from the first distribution, updated for version 2.
203 * Note that because of language differences, the numbers are slightly
204 * different from the Ada version.]
206 * The following program contains statements of a high level programming
207 * language (here: C) in a distribution considered representative:
209 * assignments 52 (51.0 %)
210 * control statements 33 (32.4 %)
211 * procedure, function calls 17 (16.7 %)
213 * 103 statements are dynamically executed. The program is balanced with
214 * respect to the three aspects:
219 * operand global, local, parameter, or constant.
221 * The combination of these three aspects is balanced only approximately.
224 * ----------------- number
232 * with record component
236 * X = Y +|-|"&&"|"|" Z 5
237 * X = Y +|-|"==" Constant 6
252 * for ... 7 | counted every time
253 * while ... 4 | the loop condition
254 * do ... while 1 | is evaluated
262 * P (...) procedure call 11
264 * library procedure 1
274 * The average number of parameters in procedure or function calls
275 * is 1.82 (not counting the function values aX *
300 * && (AND-THEN) 1 1.6
308 * 3. Operand Type (counted once per operand reference):
314 * Character 45 18.6 %
322 * When there is an access path leading to the final operand (e.g. a record
323 * component), only the final data type on the access path is counted.
326 * 4. Operand Locality:
327 * -------------------
331 * local variable 114 47.1 %
332 * global variable 22 9.1 %
333 * parameter 45 18.6 %
336 * function result 6 2.5 %
341 * The program does not compute anything meaningful, but it is syntactically
342 * and semantically correct. All variables have a value assigned to them
343 * before they are used as a source operand.
345 * There has been no explicit effort to account for the effects of a
346 * cache, or to balance the use of long or short displacements for code or
349 ***************************************************************************
352 /* Compiler and system dependent definitions: */
354 /* variables for time measurement: */
358 #define CLOCK_TYPE "time()"
360 #define HZ (1) /* time() returns time in seconds */
361 extern long time(); /* see library function "time" */
362 #define Too_Small_Time 2 /* Measurements should last at least 2 seconds */
363 #define Start_Timer() Begin_Time = time ( (long *) 0)
364 #define Stop_Timer() End_Time = time ( (long *) 0)
368 #ifdef MSC_CLOCK /* Use Microsoft C hi-res clock */
374 #define CLOCK_TYPE "MSC clock()"
375 extern clock_t clock();
376 #define Too_Small_Time (2*HZ)
377 #define Start_Timer() Begin_Time = clock()
378 #define Stop_Timer() End_Time = clock()
380 #elif defined(__riscv)
383 #define Too_Small_Time 50
384 #define CLOCK_TYPE "rdcycle()"
385 #define Start_Timer() Begin_Time = rdcycle()/1024
386 #define Stop_Timer() End_Time = rdcycle()/1024
389 /* Use times(2) time function unless */
390 /* explicitly defined otherwise */
391 #define CLOCK_TYPE "times()"
392 #include <sys/types.h>
393 #include <sys/times.h>
394 #ifndef HZ /* Added by SP 900619 */
395 #include <sys/param.h> /* If your system doesn't have this, use -DHZ=xxx */
397 *** You must define HZ
!!! ***
400 struct tms time_info
;
402 /*extern int times ();*/
403 /* see library function "times" */
404 #define Too_Small_Time (2*HZ)
405 /* Measurements should last at least about 2 seconds */
406 #define Start_Timer() times(&time_info); Begin_Time=(long)time_info.tms_utime
407 #define Stop_Timer() times(&time_info); End_Time = (long)time_info.tms_utime
409 #endif /* MSC_CLOCK */
413 #define Mic_secs_Per_Second 1000000.0
414 #define NUMBER_OF_RUNS 500 /* Default number of runs */
416 #ifdef NOSTRUCTASSIGN
417 #define structassign(d, s) memcpy(&(d), &(s), sizeof(d))
419 #define structassign(d, s) d = s
428 typedef int Enumeration
;
430 typedef enum {Ident_1
, Ident_2
, Ident_3
, Ident_4
, Ident_5
}
433 /* for boolean and enumeration types in Ada, Pascal */
435 /* General definitions: */
439 /* for strcpy, strcmp */
442 /* Value of a Null pointer */
446 typedef int One_Thirty
;
447 typedef int One_Fifty
;
448 typedef char Capital_Letter
;
450 typedef char Str_30
[31];
451 typedef int Arr_1_Dim
[50];
452 typedef int Arr_2_Dim
[50] [50];
454 typedef struct record
456 struct record
*Ptr_Comp
;
460 Enumeration Enum_Comp
;
465 Enumeration E_Comp_2
;
466 char Str_2_Comp
[31];
473 } Rec_Type
, *Rec_Pointer
;
475 void Proc_1(Rec_Pointer Ptr_Val_Par
);
476 void Proc_2(int* Int_Par_Ref
);
477 void Proc_3(Rec_Pointer
* Ptr_Ref_Par
);
480 void Proc_6(Enumeration Enum_Val_Par
, Enumeration
* Enum_Ref_Par
);
481 void Proc_7(int Int_1_Par_Val
, int Int_2_Par_Val
, int* Int_Par_Ref
);
482 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
);
483 Enumeration
Func_1 (char Ch_1_Par_Val
, char Ch_2_Par_Val
);
484 Boolean
Func_2(Str_30 Str_1_Par_Ref
, Str_30 Str_2_Par_Ref
);
485 Boolean
Func_3(Enumeration Enum_Par_Val
);