source: rtems/testsuites/benchmarks/dhrystone/dhry_1.c @ 906e67f

5
Last change on this file since 906e67f was 906e67f, checked in by Joel Sherrill <joel@…>, on 04/23/17 at 16:50:46

dhrystone/dhry_1.c: Fix may be used uninitialized warning

  • Property mode set to 100644
File size: 11.7 KB
Line 
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 25, 1988
12 *
13 *  Author:     Reinhold P. Weicker
14 *
15 ****************************************************************************
16 */
17
18#include "dhry.h"
19
20#include <inttypes.h>
21#include <stdlib.h>
22#include <string.h>
23
24/* Global Variables: */
25
26Rec_Pointer     Ptr_Glob,
27                Next_Ptr_Glob;
28int             Int_Glob;
29Boolean         Bool_Glob;
30char            Ch_1_Glob,
31                Ch_2_Glob;
32int             Arr_1_Glob [50];
33int             Arr_2_Glob [50] [50];
34
35#ifndef REG
36        Boolean Reg = false;
37#define REG
38        /* REG becomes defined as empty */
39        /* i.e. no register variables   */
40#else
41        Boolean Reg = true;
42#endif
43
44/* variables for time measurement: */
45
46#ifdef TIMES
47struct tms      time_info;
48extern  int     times ();
49                /* see library function "times" */
50#define Too_Small_Time 120
51                /* Measurements should last at least about 2 seconds */
52#endif
53#ifdef TIME
54#include <sys/time.h>
55                /* see library function "time"  */
56#define time(x) Time()
57static double Time(void)
58{
59  struct timeval tv;
60
61  gettimeofday(&tv, NULL);
62  return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
63}
64#define Too_Small_Time 2
65                /* Measurements should last at least 2 seconds */
66#endif
67
68double          Begin_Time,
69                End_Time,
70                User_Time;
71double          Microseconds,
72                Dhrystones_Per_Second;
73
74/* end of variables for time measurement */
75
76
77int main (int argc, char **argv)
78/*****/
79
80  /* main program, corresponds to procedures        */
81  /* Main and Proc_0 in the Ada version             */
82{
83        One_Fifty       Int_1_Loc;
84  REG   One_Fifty       Int_2_Loc;
85        One_Fifty       Int_3_Loc;
86  REG   char            Ch_Index;
87        Enumeration     Enum_Loc;
88        Str_30          Str_1_Loc;
89        Str_30          Str_2_Loc;
90  REG   int             Run_Index;
91  REG   int             Number_Of_Runs;
92
93  /* Initializations */
94
95  Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
96  Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
97
98  Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
99  Ptr_Glob->Discr                       = Ident_1;
100  Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
101  Ptr_Glob->variant.var_1.Int_Comp      = 40;
102  strcpy (Ptr_Glob->variant.var_1.Str_Comp,
103          "DHRYSTONE PROGRAM, SOME STRING");
104  strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
105
106  Arr_2_Glob [8][7] = 10;
107        /* Was missing in published program. Without this statement,    */
108        /* Arr_2_Glob [8][7] would have an undefined value.             */
109        /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
110        /* overflow may occur for this array element.                   */
111
112  printf ("\n");
113  printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
114  printf ("\n");
115  if (Reg)
116  {
117    printf ("Program compiled with 'register' attribute\n");
118    printf ("\n");
119  }
120  else
121  {
122    printf ("Program compiled without 'register' attribute\n");
123    printf ("\n");
124  }
125
126  Number_Of_Runs = atoi(argv[1]);
127  if (Number_Of_Runs < 1) {
128    return 1;
129  }
130
131execution_start:
132  printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
133
134  /***************/
135  /* Start timer */
136  /***************/
137 
138#ifdef TIMES
139  times (&time_info);
140  Begin_Time = (long) time_info.tms_utime;
141#endif
142#ifdef TIME
143  Begin_Time = time ( (long *) 0);
144#endif
145
146#ifdef __rtems__
147  /* avoid used uninitialized warning */
148  Int_2_Loc = 0;
149#endif
150
151  for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
152  {
153
154    Proc_5();
155    Proc_4();
156      /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
157    Int_1_Loc = 2;
158    Int_2_Loc = 3;
159    strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
160    Enum_Loc = Ident_2;
161    Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
162      /* Bool_Glob == 1 */
163    while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
164    {
165      Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
166        /* Int_3_Loc == 7 */
167      Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
168        /* Int_3_Loc == 7 */
169      Int_1_Loc += 1;
170    } /* while */
171      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
172    Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
173      /* Int_Glob == 5 */
174    Proc_1 (Ptr_Glob);
175    for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
176                             /* loop body executed twice */
177    {
178      if (Enum_Loc == Func_1 (Ch_Index, 'C'))
179          /* then, not executed */
180        {
181        Proc_6 (Ident_1, &Enum_Loc);
182        strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
183        Int_2_Loc = Run_Index;
184        Int_Glob = Run_Index;
185        }
186    }
187      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
188    Int_2_Loc = Int_2_Loc * Int_1_Loc;
189    Int_1_Loc = Int_2_Loc / Int_3_Loc;
190    Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
191      /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
192    Proc_2 (&Int_1_Loc);
193      /* Int_1_Loc == 5 */
194
195  } /* loop "for Run_Index" */
196
197  /**************/
198  /* Stop timer */
199  /**************/
200 
201#ifdef TIMES
202  times (&time_info);
203  End_Time = (long) time_info.tms_utime;
204#endif
205#ifdef TIME
206  End_Time = time ( (long *) 0);
207#endif
208
209  printf ("Execution ends\n");
210  printf ("\n");
211  printf ("Final values of the variables used in the benchmark:\n");
212  printf ("\n");
213  printf ("Int_Glob:            %d\n", Int_Glob);
214  printf ("        should be:   %d\n", 5);
215  printf ("Bool_Glob:           %d\n", Bool_Glob);
216  printf ("        should be:   %d\n", 1);
217  printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
218  printf ("        should be:   %c\n", 'A');
219  printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
220  printf ("        should be:   %c\n", 'B');
221  printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
222  printf ("        should be:   %d\n", 7);
223  printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
224  printf ("        should be:   Number_Of_Runs + 10\n");
225  printf ("Ptr_Glob->\n");
226  printf ("  Ptr_Comp:          %" PRIdPTR "\n", (intptr_t) Ptr_Glob->Ptr_Comp);
227  printf ("        should be:   (implementation-dependent)\n");
228  printf ("  Discr:             %d\n", Ptr_Glob->Discr);
229  printf ("        should be:   %d\n", 0);
230  printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
231  printf ("        should be:   %d\n", 2);
232  printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
233  printf ("        should be:   %d\n", 17);
234  printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
235  printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
236  printf ("Next_Ptr_Glob->\n");
237  printf ("  Ptr_Comp:          %" PRIdPTR "\n", (intptr_t) Next_Ptr_Glob->Ptr_Comp);
238  printf ("        should be:   (implementation-dependent), same as above\n");
239  printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
240  printf ("        should be:   %d\n", 0);
241  printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
242  printf ("        should be:   %d\n", 1);
243  printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
244  printf ("        should be:   %d\n", 18);
245  printf ("  Str_Comp:          %s\n",
246                                Next_Ptr_Glob->variant.var_1.Str_Comp);
247  printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
248  printf ("Int_1_Loc:           %d\n", Int_1_Loc);
249  printf ("        should be:   %d\n", 5);
250  printf ("Int_2_Loc:           %d\n", Int_2_Loc);
251  printf ("        should be:   %d\n", 13);
252  printf ("Int_3_Loc:           %d\n", Int_3_Loc);
253  printf ("        should be:   %d\n", 7);
254  printf ("Enum_Loc:            %d\n", Enum_Loc);
255  printf ("        should be:   %d\n", 1);
256  printf ("Str_1_Loc:           %s\n", Str_1_Loc);
257  printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
258  printf ("Str_2_Loc:           %s\n", Str_2_Loc);
259  printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
260  printf ("\n");
261
262  User_Time = End_Time - Begin_Time;
263
264  if (User_Time < Too_Small_Time)
265  {
266    printf ("Measured time too small to obtain meaningful results\n");
267    printf ("Please increase number of runs\n");
268    printf ("\n");
269    Number_Of_Runs *= 2;
270    goto execution_start;
271  }
272  else
273  {
274#ifdef TIME
275    Microseconds = User_Time * Mic_secs_Per_Second / Number_Of_Runs;
276    Dhrystones_Per_Second = Number_Of_Runs / User_Time;
277#else
278    Microseconds = (float) User_Time * Mic_secs_Per_Second
279                        / ((float) HZ * ((float) Number_Of_Runs));
280    Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
281                        / (float) User_Time;
282#endif
283    printf ("Microseconds for one run through Dhrystone: ");
284    printf ("%6.1f \n", Microseconds);
285    printf ("Dhrystones per Second:                      ");
286    printf ("%6.1f \n", Dhrystones_Per_Second);
287    printf ("DMIPS:                                      ");
288    printf ("%5.2f \n", Dhrystones_Per_Second / 1757.0);
289    printf ("\n");
290  }
291 
292  return 0;
293}
294
295
296void Proc_1 (Ptr_Val_Par)
297/******************/
298
299REG Rec_Pointer Ptr_Val_Par;
300    /* executed once */
301{
302  REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; 
303                                        /* == Ptr_Glob_Next */
304  /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
305  /* corresponds to "rename" in Ada, "with" in Pascal           */
306 
307  structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
308  Ptr_Val_Par->variant.var_1.Int_Comp = 5;
309  Next_Record->variant.var_1.Int_Comp
310        = Ptr_Val_Par->variant.var_1.Int_Comp;
311  Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
312  Proc_3 (&Next_Record->Ptr_Comp);
313    /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
314                        == Ptr_Glob->Ptr_Comp */
315  if (Next_Record->Discr == Ident_1)
316    /* then, executed */
317  {
318    Next_Record->variant.var_1.Int_Comp = 6;
319    Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
320           &Next_Record->variant.var_1.Enum_Comp);
321    Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
322    Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
323           &Next_Record->variant.var_1.Int_Comp);
324  }
325  else /* not executed */
326    structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
327} /* Proc_1 */
328
329
330void Proc_2 (Int_Par_Ref)
331/******************/
332    /* executed once */
333    /* *Int_Par_Ref == 1, becomes 4 */
334
335One_Fifty   *Int_Par_Ref;
336{
337  One_Fifty  Int_Loc; 
338  Enumeration   Enum_Loc;
339
340  Int_Loc = *Int_Par_Ref + 10;
341  do /* executed once */
342    if (Ch_1_Glob == 'A')
343      /* then, executed */
344    {
345      Int_Loc -= 1;
346      *Int_Par_Ref = Int_Loc - Int_Glob;
347      Enum_Loc = Ident_1;
348    } /* if */
349  while (Enum_Loc != Ident_1); /* true */
350} /* Proc_2 */
351
352
353void Proc_3 (Ptr_Ref_Par)
354/******************/
355    /* executed once */
356    /* Ptr_Ref_Par becomes Ptr_Glob */
357
358Rec_Pointer *Ptr_Ref_Par;
359
360{
361  if (Ptr_Glob != Null)
362    /* then, executed */
363    *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
364  Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
365} /* Proc_3 */
366
367
368void Proc_4 (void) /* without parameters */
369/*******/
370    /* executed once */
371{
372  Boolean Bool_Loc;
373
374  Bool_Loc = Ch_1_Glob == 'A';
375  Bool_Glob = Bool_Loc | Bool_Glob;
376  Ch_2_Glob = 'B';
377} /* Proc_4 */
378
379
380void Proc_5 (void) /* without parameters */
381/*******/
382    /* executed once */
383{
384  Ch_1_Glob = 'A';
385  Bool_Glob = false;
386} /* Proc_5 */
387
388
389        /* Procedure for the assignment of structures,          */
390        /* if the C compiler doesn't support this feature       */
391#ifdef  NOSTRUCTASSIGN
392memcpy (d, s, l)
393register char   *d;
394register char   *s;
395register int    l;
396{
397        while (l--) *d++ = *s++;
398}
399#endif
400
401
Note: See TracBrowser for help on using the repository browser.