source: soft/giet_vm/applications/dhrystone/dhry_1.c @ 760

Last change on this file since 760 was 386, checked in by alain, 10 years ago

Cosmetic

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