1 /*
2 ****************************************************************************
3 *
4 * "DHRYSTONE" Benchmark Program
5 * -----------------------------
6 *
7 * Version: C, Version 2.1
8 *
9 * File: dhry_1.c (part 2 of 3)
10 *
11 * Date: May 17, 1988
12 *
13 * Author: Reinhold P. Weicker
14 *
15 ****************************************************************************
16 */
17
18 #include "dhry.h"
19
20 /* Global Variables: */
21
22 Rec_Pointer Ptr_Glob,
23 Next_Ptr_Glob;
24 int Int_Glob;
25 Boolean Bool_Glob;
26 char Ch_1_Glob,
27 Ch_2_Glob;
28 int Arr_1_Glob [50];
29 int Arr_2_Glob [50] [50];
30
31 Enumeration Func_1 ();
32 /* forward declaration necessary since Enumeration may not simply be int */
33
34 #ifndef REG
35 Boolean Reg = false;
36 #define REG
37 /* REG becomes defined as empty */
38 /* i.e. no register variables */
39 #else
40 Boolean Reg = true;
41 #endif
42
43 /* variables for time measurement: */
44
45 #ifdef TIMES
46 struct tms time_info;
47 extern int times ();
48 /* see library function "times" */
49 #define Too_Small_Time (2*HZ)
50 /* Measurements should last at least about 2 seconds */
51 #endif
52 #ifdef TIME
53 extern long time();
54 /* see library function "time" */
55 #define Too_Small_Time 2
56 /* Measurements should last at least 2 seconds */
57 #endif
58 #ifdef MSC_CLOCK
59 extern clock_t clock();
60 #define Too_Small_Time (2*HZ)
61 #endif
62
63 long Begin_Time,
64 End_Time,
65 User_Time;
66 float Microseconds,
67 Dhrystones_Per_Second;
68
69 /* end of variables for time measurement */
70
71
main()72 main ()
73 /*****/
74
75 /* main program, corresponds to procedures */
76 /* Main and Proc_0 in the Ada version */
77 {
78 One_Fifty Int_1_Loc;
79 REG One_Fifty Int_2_Loc;
80 One_Fifty Int_3_Loc;
81 REG char Ch_Index;
82 Enumeration Enum_Loc;
83 Str_30 Str_1_Loc;
84 Str_30 Str_2_Loc;
85 REG int Run_Index;
86 REG int Number_Of_Runs;
87
88 /* Initializations */
89
90 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
91 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
92
93 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
94 Ptr_Glob->Discr = Ident_1;
95 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
96 Ptr_Glob->variant.var_1.Int_Comp = 40;
97 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
98 "DHRYSTONE PROGRAM, SOME STRING");
99 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
100
101 Arr_2_Glob [8][7] = 10;
102 /* Was missing in published program. Without this statement, */
103 /* Arr_2_Glob [8][7] would have an undefined value. */
104 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
105 /* overflow may occur for this array element. */
106 int n;
107 scanf ("%d", &n);
108 Number_Of_Runs = n;
109
110
111 /***************/
112 /* Start timer */
113 /***************/
114
115 #ifdef TIMES
116 times (&time_info);
117 Begin_Time = (long) time_info.tms_utime;
118 #endif
119 #ifdef TIME
120 Begin_Time = time ( (long *) 0);
121 #endif
122 #ifdef MSC_CLOCK
123 Begin_Time = clock();
124 #endif
125
126 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
127 {
128
129 Proc_5();
130 Proc_4();
131 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
132 Int_1_Loc = 2;
133 Int_2_Loc = 3;
134 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
135 Enum_Loc = Ident_2;
136 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
137 /* Bool_Glob == 1 */
138 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
139 {
140 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
141 /* Int_3_Loc == 7 */
142 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
143 /* Int_3_Loc == 7 */
144 Int_1_Loc += 1;
145 } /* while */
146 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
147 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
148 /* Int_Glob == 5 */
149 Proc_1 (Ptr_Glob);
150 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
151 /* loop body executed twice */
152 {
153 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
154 /* then, not executed */
155 {
156 Proc_6 (Ident_1, &Enum_Loc);
157 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
158 Int_2_Loc = Run_Index;
159 Int_Glob = Run_Index;
160 }
161 }
162 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
163 Int_2_Loc = Int_2_Loc * Int_1_Loc;
164 Int_1_Loc = Int_2_Loc / Int_3_Loc;
165 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
166 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
167 Proc_2 (&Int_1_Loc);
168 /* Int_1_Loc == 5 */
169
170 } /* loop "for Run_Index" */
171
172 /**************/
173 /* Stop timer */
174 /**************/
175
176 #ifdef TIMES
177 times (&time_info);
178 End_Time = (long) time_info.tms_utime;
179 #endif
180 #ifdef TIME
181 End_Time = time ( (long *) 0);
182 #endif
183 #ifdef MSC_CLOCK
184 End_Time = clock();
185 #endif
186 User_Time = End_Time - Begin_Time;
187
188 if (User_Time < Too_Small_Time)
189 {
190 printf ("Measured time too small to obtain meaningful results\n");
191 printf ("Please increase number of runs\n");
192 printf ("\n");
193 }
194 else
195 {
196 #ifdef TIME
197 Microseconds = (float) User_Time * Mic_secs_Per_Second
198 / (float) Number_Of_Runs;
199 Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
200 #else
201 Microseconds = (float) User_Time * Mic_secs_Per_Second
202 / ((float) HZ * ((float) Number_Of_Runs));
203 Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
204 / (float) User_Time;
205 #endif
206 printf ("%6.1f \n", Dhrystones_Per_Second);
207 }
208
209 }
210
211
Proc_1(Ptr_Val_Par)212 Proc_1 (Ptr_Val_Par)
213 /******************/
214
215 REG Rec_Pointer Ptr_Val_Par;
216 /* executed once */
217 {
218 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
219 /* == Ptr_Glob_Next */
220 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
221 /* corresponds to "rename" in Ada, "with" in Pascal */
222
223 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
224 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
225 Next_Record->variant.var_1.Int_Comp
226 = Ptr_Val_Par->variant.var_1.Int_Comp;
227 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
228 Proc_3 (&Next_Record->Ptr_Comp);
229 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
230 == Ptr_Glob->Ptr_Comp */
231 if (Next_Record->Discr == Ident_1)
232 /* then, executed */
233 {
234 Next_Record->variant.var_1.Int_Comp = 6;
235 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
236 &Next_Record->variant.var_1.Enum_Comp);
237 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
238 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
239 &Next_Record->variant.var_1.Int_Comp);
240 }
241 else /* not executed */
242 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
243 return 0; } /* Proc_1 */
244
245
Proc_2(Int_Par_Ref)246 Proc_2 (Int_Par_Ref)
247 /******************/
248 /* executed once */
249 /* *Int_Par_Ref == 1, becomes 4 */
250
251 One_Fifty *Int_Par_Ref;
252 {
253 One_Fifty Int_Loc;
254 Enumeration Enum_Loc;
255
256 Int_Loc = *Int_Par_Ref + 10;
257 do /* executed once */
258 if (Ch_1_Glob == 'A')
259 /* then, executed */
260 {
261 Int_Loc -= 1;
262 *Int_Par_Ref = Int_Loc - Int_Glob;
263 Enum_Loc = Ident_1;
264 } /* if */
265 while (Enum_Loc != Ident_1); /* true */
266 return 0; } /* Proc_2 */
267
268
Proc_3(Ptr_Ref_Par)269 Proc_3 (Ptr_Ref_Par)
270 /******************/
271 /* executed once */
272 /* Ptr_Ref_Par becomes Ptr_Glob */
273
274 Rec_Pointer *Ptr_Ref_Par;
275
276 {
277 if (Ptr_Glob != Null)
278 /* then, executed */
279 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
280 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
281 return 0; } /* Proc_3 */
282
283
Proc_4()284 Proc_4 () /* without parameters */
285 /*******/
286 /* executed once */
287 {
288 Boolean Bool_Loc;
289
290 Bool_Loc = Ch_1_Glob == 'A';
291 Bool_Glob = Bool_Loc | Bool_Glob;
292 Ch_2_Glob = 'B';
293 return 0; } /* Proc_4 */
294
295
Proc_5()296 Proc_5 () /* without parameters */
297 /*******/
298 /* executed once */
299 {
300 Ch_1_Glob = 'A';
301 Bool_Glob = false;
302 return 0; } /* Proc_5 */
303
304
305 /* Procedure for the assignment of structures, */
306 /* if the C compiler doesn't support this feature */
307 #ifdef NOSTRUCTASSIGN
memcpy(d,s,l)308 memcpy (d, s, l)
309 register char *d;
310 register char *s;
311 register int l;
312 {
313 while (l--) *d++ = *s++;
314 }
315 #endif
316
317
318