1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44char SCCSid[] = "@(#) @(#)dhry_1.c:3.4 -- 5/15/91 19:30:21";
45
46#include <common.h>
47#include <malloc.h>
48
49#include "dhry.h"
50
51unsigned long Run_Index;
52
53void report(void)
54{
55 printf("%ld loops\n", Run_Index);
56}
57
58
59
60Rec_Pointer Ptr_Glob,
61 Next_Ptr_Glob;
62int Int_Glob;
63Boolean Bool_Glob;
64char Ch_1_Glob,
65 Ch_2_Glob;
66int Arr_1_Glob [50];
67int Arr_2_Glob [50] [50];
68
69Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
70
71
72#ifndef REG
73 Boolean Reg = false;
74#define REG
75
76
77#else
78 Boolean Reg = true;
79#endif
80
81
82
83#ifdef TIMES
84#define Too_Small_Time 120
85
86#endif
87#ifdef TIME
88extern long time();
89
90#define Too_Small_Time 2
91
92#endif
93
94long Begin_Time,
95 End_Time,
96 User_Time;
97
98
99
100void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
101void Proc_2 (One_Fifty *Int_Par_Ref);
102void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
103void Proc_4 (void);
104void Proc_5 (void);
105
106
107extern Boolean Func_2(Str_30, Str_30);
108extern void Proc_6(Enumeration, Enumeration *);
109extern void Proc_7(One_Fifty, One_Fifty, One_Fifty *);
110extern void Proc_8(Arr_1_Dim, Arr_2_Dim, int, int);
111
112void dhry(int Number_Of_Runs)
113
114
115{
116 One_Fifty Int_1_Loc;
117 REG One_Fifty Int_2_Loc;
118 One_Fifty Int_3_Loc;
119 REG char Ch_Index;
120 Enumeration Enum_Loc;
121 Str_30 Str_1_Loc;
122 Str_30 Str_2_Loc;
123
124
125
126 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
127 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
128
129 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
130 Ptr_Glob->Discr = Ident_1;
131 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
132 Ptr_Glob->variant.var_1.Int_Comp = 40;
133 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
134 "DHRYSTONE PROGRAM, SOME STRING");
135 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
136
137 Arr_2_Glob [8][7] = 10;
138
139
140
141
142
143#ifdef PRATTLE
144 printf ("\n");
145 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
146 printf ("\n");
147 if (Reg)
148 {
149 printf ("Program compiled with 'register' attribute\n");
150 printf ("\n");
151 }
152 else
153 {
154 printf ("Program compiled without 'register' attribute\n");
155 printf ("\n");
156 }
157 printf ("Please give the number of runs through the benchmark: ");
158 {
159 int n;
160 scanf ("%d", &n);
161 Number_Of_Runs = n;
162 }
163 printf ("\n");
164
165 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
166#endif
167
168 Run_Index = 0;
169
170
171
172
173
174#ifdef SELF_TIMED
175#ifdef TIMES
176 times (&time_info);
177 Begin_Time = (long) time_info.tms_utime;
178#endif
179#ifdef TIME
180 Begin_Time = time ( (long *) 0);
181#endif
182#endif
183
184 for (Run_Index = 1; Run_Index < Number_Of_Runs; ++Run_Index)
185 {
186
187 Proc_5();
188 Proc_4();
189
190 Int_1_Loc = 2;
191 Int_2_Loc = 3;
192 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
193 Enum_Loc = Ident_2;
194 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
195
196 while (Int_1_Loc < Int_2_Loc)
197 {
198 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
199
200 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
201
202 Int_1_Loc += 1;
203 }
204
205 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
206
207 Proc_1 (Ptr_Glob);
208 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
209
210 {
211 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
212
213 {
214 Proc_6 (Ident_1, &Enum_Loc);
215 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
216 Int_2_Loc = Run_Index;
217 Int_Glob = Run_Index;
218 }
219 }
220
221 Int_2_Loc = Int_2_Loc * Int_1_Loc;
222 Int_1_Loc = Int_2_Loc / Int_3_Loc;
223 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
224
225 Proc_2 (&Int_1_Loc);
226
227
228 }
229
230
231
232
233#ifdef SELF_TIMED
234#ifdef TIMES
235 times (&time_info);
236 End_Time = (long) time_info.tms_utime;
237#endif
238#ifdef TIME
239 End_Time = time ( (long *) 0);
240#endif
241#endif
242
243
244#ifdef SELF_TIMED
245 printf ("Execution ends\n");
246 printf ("\n");
247 printf ("Final values of the variables used in the benchmark:\n");
248 printf ("\n");
249 printf ("Int_Glob: %d\n", Int_Glob);
250 printf (" should be: %d\n", 5);
251 printf ("Bool_Glob: %d\n", Bool_Glob);
252 printf (" should be: %d\n", 1);
253 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
254 printf (" should be: %c\n", 'A');
255 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
256 printf (" should be: %c\n", 'B');
257 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
258 printf (" should be: %d\n", 7);
259 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
260 printf (" should be: Number_Of_Runs + 10\n");
261 printf ("Ptr_Glob->\n");
262 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
263 printf (" should be: (implementation-dependent)\n");
264 printf (" Discr: %d\n", Ptr_Glob->Discr);
265 printf (" should be: %d\n", 0);
266 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
267 printf (" should be: %d\n", 2);
268 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
269 printf (" should be: %d\n", 17);
270 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
271 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
272 printf ("Next_Ptr_Glob->\n");
273 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
274 printf (" should be: (implementation-dependent), same as above\n");
275 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
276 printf (" should be: %d\n", 0);
277 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
278 printf (" should be: %d\n", 1);
279 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
280 printf (" should be: %d\n", 18);
281 printf (" Str_Comp: %s\n",
282 Next_Ptr_Glob->variant.var_1.Str_Comp);
283 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
284 printf ("Int_1_Loc: %d\n", Int_1_Loc);
285 printf (" should be: %d\n", 5);
286 printf ("Int_2_Loc: %d\n", Int_2_Loc);
287 printf (" should be: %d\n", 13);
288 printf ("Int_3_Loc: %d\n", Int_3_Loc);
289 printf (" should be: %d\n", 7);
290 printf ("Enum_Loc: %d\n", Enum_Loc);
291 printf (" should be: %d\n", 1);
292 printf ("Str_1_Loc: %s\n", Str_1_Loc);
293 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
294 printf ("Str_2_Loc: %s\n", Str_2_Loc);
295 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
296 printf ("\n");
297
298 User_Time = End_Time - Begin_Time;
299
300 if (User_Time < Too_Small_Time)
301 {
302 printf ("Measured time too small to obtain meaningful results\n");
303 printf ("Please increase number of runs\n");
304 printf ("\n");
305 }
306 else
307 {
308#ifdef TIME
309 Microseconds = (float) User_Time * Mic_secs_Per_Second
310 / (float) Number_Of_Runs;
311 Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
312#else
313 Microseconds = (float) User_Time * Mic_secs_Per_Second
314 / ((float) HZ * ((float) Number_Of_Runs));
315 Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
316 / (float) User_Time;
317#endif
318 printf ("Microseconds for one run through Dhrystone: ");
319 printf ("%6.1f \n", Microseconds);
320 printf ("Dhrystones per Second: ");
321 printf ("%6.1f \n", Dhrystones_Per_Second);
322 printf ("\n");
323 }
324#endif
325}
326
327
328void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
329
330{
331 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
332
333
334
335
336 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
337 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
338 Next_Record->variant.var_1.Int_Comp
339 = Ptr_Val_Par->variant.var_1.Int_Comp;
340 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
341 Proc_3 (&Next_Record->Ptr_Comp);
342
343
344 if (Next_Record->Discr == Ident_1)
345
346 {
347 Next_Record->variant.var_1.Int_Comp = 6;
348 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
349 &Next_Record->variant.var_1.Enum_Comp);
350 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
351 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
352 &Next_Record->variant.var_1.Int_Comp);
353 }
354 else
355 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
356}
357
358
359void Proc_2 (One_Fifty *Int_Par_Ref)
360
361
362{
363 One_Fifty Int_Loc;
364 Enumeration Enum_Loc;
365
366 Enum_Loc = 0;
367
368 Int_Loc = *Int_Par_Ref + 10;
369 do
370 if (Ch_1_Glob == 'A')
371
372 {
373 Int_Loc -= 1;
374 *Int_Par_Ref = Int_Loc - Int_Glob;
375 Enum_Loc = Ident_1;
376 }
377 while (Enum_Loc != Ident_1);
378}
379
380
381void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
382
383
384{
385 if (Ptr_Glob != Null)
386
387 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
388 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
389}
390
391
392void Proc_4 (void)
393
394{
395 Boolean Bool_Loc;
396
397 Bool_Loc = Ch_1_Glob == 'A';
398 Bool_Glob = Bool_Loc | Bool_Glob;
399 Ch_2_Glob = 'B';
400}
401
402void Proc_5 (void)
403
404
405{
406 Ch_1_Glob = 'A';
407 Bool_Glob = false;
408}
409
410
411
412
413#ifdef NOSTRUCTASSIGN
414memcpy (d, s, l)
415register char *d;
416register char *s;
417register int l;
418{
419 while (l--) *d++ = *s++;
420}
421#endif
422