Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc-extra / historygraphs / dhrystone-stm8 / dhry_1.c
blob43d6ffec56cc35b0e77124825ba7781d46836f2f
1 /*
2 ****************************************************************************
4 * "DHRYSTONE" Benchmark Program
5 * -----------------------------
6 *
7 * Version: C, Version 2.1
8 *
9 * File: dhry_1.c (part 2 of 3)
11 * Date: May 25, 1988
13 * Author: Reinhold P. Weicker
15 ****************************************************************************
18 #include "dhry.h"
20 /* Global Variables: */
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];
33 //extern void *malloc (unsigned int s);
34 int scanf(const char *format, ...);
35 /*Enumeration Func_1 (); Forward declaration now in dhry.h */
36 /* forward declaration necessary since Enumeration may not simply be int */
38 #ifndef REG
39 Boolean Reg = false;
40 #define REG
41 /* REG becomes defined as empty */
42 /* i.e. no register variables */
43 #else
44 Boolean Reg = true;
45 #endif
47 /* variables for time measurement: */
49 #ifdef TIMES
50 struct tms time_info;
51 extern int times ();
52 /* see library function "times" */
53 #define Too_Small_Time 120
54 /* Measurements should last at least about 2 seconds */
55 #endif
56 #ifdef TIME
57 extern long time(long *);
58 /* see library function "time" */
59 #define Too_Small_Time 2
60 /* Measurements should last at least 2 seconds */
61 #endif
63 #if 1
64 unsigned int clock(void);
65 #define CLOCKS_PER_SEC 1000
66 #define HZ CLOCKS_PER_SEC
67 #endif
69 #define Too_Small_Time 2000
71 long Begin_Time,
72 End_Time,
73 User_Time;
74 float Microseconds,
75 Dhrystones_Per_Second;
77 /* end of variables for time measurement */
79 void init(void);
81 Rec_Type malloc_1;
82 Rec_Type malloc_2;
84 void main (void)
85 /*****/
87 /* main program, corresponds to procedures */
88 /* Main and Proc_0 in the Ada version */
90 One_Fifty Int_1_Loc;
91 REG One_Fifty Int_2_Loc;
92 One_Fifty Int_3_Loc;
93 REG char Ch_Index;
94 Enumeration Enum_Loc;
95 Str_30 Str_1_Loc;
96 Str_30 Str_2_Loc;
97 REG int Run_Index;
98 REG int Number_Of_Runs;
100 /* Initializations */
102 init();
104 Next_Ptr_Glob = /*(Rec_Pointer) malloc (sizeof (Rec_Type))*/ &malloc_1;
105 Ptr_Glob = /*(Rec_Pointer) malloc (sizeof (Rec_Type))*/ &malloc_2;
107 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
108 Ptr_Glob->Discr = Ident_1;
109 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
110 Ptr_Glob->variant.var_1.Int_Comp = 40;
111 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
112 "DHRYSTONE PROGRAM, SOME STRING");
113 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
115 Arr_2_Glob [8][7] = 10;
116 /* Was missing in published program. Without this statement, */
117 /* Arr_2_Glob [8][7] would have an undefined value. */
118 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
119 /* overflow may occur for this array element. */
121 printf ("\n");
122 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
123 printf ("\n");
124 if (Reg)
126 printf ("Program compiled with 'register' attribute\n");
127 printf ("\n");
129 else
131 printf ("Program compiled without 'register' attribute\n");
132 printf ("\n");
134 printf ("Please give the number of runs through the benchmark: ");
136 int n;
137 /*scanf ("%d", &n)*/;
138 Number_Of_Runs = 25000/*n*/;
140 printf ("\n");
142 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
144 /***************/
145 /* Start timer */
146 /***************/
148 #ifdef TIMES
149 times (&time_info);
150 Begin_Time = (long) time_info.tms_utime;
151 #endif
152 #ifdef TIME
153 Begin_Time = time ( (long *) 0);
154 #endif
155 #if 1
156 Begin_Time = clock();
157 #endif
159 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
162 Proc_5();
163 Proc_4();
164 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
165 Int_1_Loc = 2;
166 Int_2_Loc = 3;
167 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
168 Enum_Loc = Ident_2;
169 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
170 /* Bool_Glob == 1 */
171 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
173 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
174 /* Int_3_Loc == 7 */
175 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
176 /* Int_3_Loc == 7 */
177 Int_1_Loc += 1;
178 } /* while */
179 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
180 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
181 /* Int_Glob == 5 */
182 Proc_1 (Ptr_Glob);
183 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
184 /* loop body executed twice */
186 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
187 /* then, not executed */
189 Proc_6 (Ident_1, &Enum_Loc);
190 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
191 Int_2_Loc = Run_Index;
192 Int_Glob = Run_Index;
195 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
196 Int_2_Loc = Int_2_Loc * Int_1_Loc;
197 Int_1_Loc = Int_2_Loc / Int_3_Loc;
198 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
199 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
200 Proc_2 (&Int_1_Loc);
201 /* Int_1_Loc == 5 */
203 } /* loop "for Run_Index" */
205 /**************/
206 /* Stop timer */
207 /**************/
209 #ifdef TIMES
210 times (&time_info);
211 End_Time = (long) time_info.tms_utime;
212 #endif
213 #ifdef TIME
214 End_Time = time ( (long *) 0);
215 #endif
216 #if 1
217 End_Time = clock();
218 #endif
220 printf ("Execution ends\n");
221 printf ("\n");
222 printf ("Final values of the variables used in the benchmark:\n");
223 printf ("\n");
224 printf ("Int_Glob: %d\n", Int_Glob);
225 printf (" should be: %d\n", 5);
226 printf ("Bool_Glob: %d\n", Bool_Glob);
227 printf (" should be: %d\n", 1);
228 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
229 printf (" should be: %c\n", 'A');
230 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
231 printf (" should be: %c\n", 'B');
232 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
233 printf (" should be: %d\n", 7);
234 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
235 printf (" should be: Number_Of_Runs + 10\n");
236 printf ("Ptr_Glob->\n");
237 printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
238 printf (" should be: (implementation-dependent)\n");
239 printf (" Discr: %d\n", Ptr_Glob->Discr);
240 printf (" should be: %d\n", 0);
241 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
242 printf (" should be: %d\n", 2);
243 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
244 printf (" should be: %d\n", 17);
245 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
246 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
247 printf ("Next_Ptr_Glob->\n");
248 printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
249 printf (" should be: (implementation-dependent), same as above\n");
250 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
251 printf (" should be: %d\n", 0);
252 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
253 printf (" should be: %d\n", 1);
254 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
255 printf (" should be: %d\n", 18);
256 printf (" Str_Comp: %s\n",
257 Next_Ptr_Glob->variant.var_1.Str_Comp);
258 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
259 printf ("Int_1_Loc: %d\n", Int_1_Loc);
260 printf (" should be: %d\n", 5);
261 printf ("Int_2_Loc: %d\n", Int_2_Loc);
262 printf (" should be: %d\n", 13);
263 printf ("Int_3_Loc: %d\n", Int_3_Loc);
264 printf (" should be: %d\n", 7);
265 printf ("Enum_Loc: %d\n", Enum_Loc);
266 printf (" should be: %d\n", 1);
267 printf ("Str_1_Loc: %s\n", Str_1_Loc);
268 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
269 printf ("Str_2_Loc: %s\n", Str_2_Loc);
270 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
271 printf ("\n");
273 User_Time = End_Time - Begin_Time;
275 if (User_Time < Too_Small_Time)
277 printf ("Measured time too small to obtain meaningful results\n");
278 printf ("Please increase number of runs\n");
279 printf ("\n");
281 else
283 #ifdef TIME
284 Microseconds = (float) User_Time * Mic_secs_Per_Second
285 / (float) Number_Of_Runs;
286 Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
287 #else
288 Microseconds = (float) User_Time * Mic_secs_Per_Second
289 / ((float) HZ * ((float) Number_Of_Runs));
290 Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
291 / (float) User_Time;
292 #endif
293 printf ("Microseconds for one run through Dhrystone: ");
294 //printf ("%6.1f \n", Microseconds);
295 printf ("%ld \n", (long int)Microseconds);
296 printf ("Dhrystones per Second: ");
297 //printf ("%6.1f \n", Dhrystones_Per_Second);
298 printf ("%ld \n", (long int)Dhrystones_Per_Second);
299 printf ("\n");
305 void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
306 /******************/
309 /* executed once */
311 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
312 /* == Ptr_Glob_Next */
313 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
314 /* corresponds to "rename" in Ada, "with" in Pascal */
316 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
317 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
318 Next_Record->variant.var_1.Int_Comp
319 = Ptr_Val_Par->variant.var_1.Int_Comp;
320 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
321 Proc_3 (&Next_Record->Ptr_Comp);
322 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
323 == Ptr_Glob->Ptr_Comp */
324 if (Next_Record->Discr == Ident_1)
325 /* then, executed */
327 Next_Record->variant.var_1.Int_Comp = 6;
328 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
329 &Next_Record->variant.var_1.Enum_Comp);
330 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
331 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
332 &Next_Record->variant.var_1.Int_Comp);
334 else /* not executed */
335 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
336 } /* Proc_1 */
339 void Proc_2 (One_Fifty *Int_Par_Ref)
340 /******************/
341 /* executed once */
342 /* *Int_Par_Ref == 1, becomes 4 */
345 One_Fifty Int_Loc;
346 Enumeration Enum_Loc;
348 Int_Loc = *Int_Par_Ref + 10;
349 do /* executed once */
350 if (Ch_1_Glob == 'A')
351 /* then, executed */
353 Int_Loc -= 1;
354 *Int_Par_Ref = Int_Loc - Int_Glob;
355 Enum_Loc = Ident_1;
356 } /* if */
357 while (Enum_Loc != Ident_1); /* true */
358 } /* Proc_2 */
361 void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
362 /******************/
363 /* executed once */
364 /* Ptr_Ref_Par becomes Ptr_Glob */
367 if (Ptr_Glob != Null)
368 /* then, executed */
369 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
370 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
371 } /* Proc_3 */
374 void Proc_4 (void) /* without parameters */
375 /*******/
376 /* executed once */
378 Boolean Bool_Loc;
379 Bool_Loc = Ch_1_Glob == 'A';
380 Bool_Glob = Bool_Loc | Bool_Glob;
381 Ch_2_Glob = 'B';
382 } /* Proc_4 */
385 void Proc_5 (void) /* without parameters */
386 /*******/
387 /* executed once */
389 Ch_1_Glob = 'A';
390 Bool_Glob = false;
391 } /* Proc_5 */
394 /* Procedure for the assignment of structures, */
395 /* if the C compiler doesn't support this feature */
396 #ifdef NOSTRUCTASSIGN
397 /*memcpy (d, s, l)
398 register char *d;
399 register char *s;
400 register int l;
402 while (l--) *d++ = *s++;
404 #endif