OpenCores
URL https://opencores.org/ocsvn/fwrisc/fwrisc/trunk

Subversion Repositories fwrisc

[/] [fwrisc/] [trunk/] [ve/] [fwrisc/] [tests/] [dhrystone/] [src/] [dhrystone_main.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
// See LICENSE for license details.
2
 
3
//**************************************************************************
4
// Dhrystone bencmark
5
//--------------------------------------------------------------------------
6
//
7
// This is the classic Dhrystone synthetic integer benchmark.
8
//
9
 
10
#pragma GCC optimize ("no-inline")
11
 
12
#include "dhrystone.h"
13
 
14
void debug_printf(const char* str, ...);
15
 
16
#include "util.h"
17
 
18
// #include <alloca.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
#undef REG
42
#define REG register
43
#endif
44
 
45
Boolean         Done;
46
 
47
long            Begin_Time,
48
                End_Time,
49
                User_Time;
50
long            Microseconds,
51
                Dhrystones_Per_Second;
52
 
53
/* end of variables for time measurement */
54
 
55
 
56
int main (int argc, char** argv)
57
/*****/
58
  /* main program, corresponds to procedures        */
59
  /* Main and Proc_0 in the Ada version             */
60
{
61
        One_Fifty       Int_1_Loc;
62
  REG   One_Fifty       Int_2_Loc;
63
        One_Fifty       Int_3_Loc;
64
  REG   char            Ch_Index;
65
        Enumeration     Enum_Loc;
66
        Str_30          Str_1_Loc;
67
        Str_30          Str_2_Loc;
68
  REG   int             Run_Index;
69
  REG   int             Number_Of_Runs;
70
 
71
  // MSB: instead of calling alloca
72
  Rec_Type                              Rec_Type_alloc1, Rec_Type_alloc2;
73
 
74
  /* Arguments */
75
  Number_Of_Runs = NUMBER_OF_RUNS;
76
 
77
  /* Initializations */
78
 
79
//  Next_Ptr_Glob = (Rec_Pointer) alloca (sizeof (Rec_Type));
80
//  Ptr_Glob = (Rec_Pointer) alloca (sizeof (Rec_Type));
81
  Next_Ptr_Glob = &Rec_Type_alloc1;
82
  Ptr_Glob = &Rec_Type_alloc2;
83
 
84
  Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
85
  Ptr_Glob->Discr                       = Ident_1;
86
  Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
87
  Ptr_Glob->variant.var_1.Int_Comp      = 40;
88
  strcpy (Ptr_Glob->variant.var_1.Str_Comp,
89
          "DHRYSTONE PROGRAM, SOME STRING");
90
  strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
91
 
92
  Arr_2_Glob [8][7] = 10;
93
        /* Was missing in published program. Without this statement,    */
94
        /* Arr_2_Glob [8][7] would have an undefined value.             */
95
        /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
96
        /* overflow may occur for this array element.                   */
97
 
98
  debug_printf("\n");
99
  debug_printf("Dhrystone Benchmark, Version %s\n", Version);
100
  if (Reg)
101
  {
102
    debug_printf("Program compiled with 'register' attribute\n");
103
  }
104
  else
105
  {
106
    debug_printf("Program compiled without 'register' attribute\n");
107
  }
108
  debug_printf("Using %s, HZ=%d\n", CLOCK_TYPE, HZ);
109
  debug_printf("\n");
110
 
111
  Done = false;
112
  while (!Done) {
113
    debug_printf("Trying %d runs through Dhrystone:\n", Number_Of_Runs);
114
 
115
    /***************/
116
    /* Start timer */
117
    /***************/
118
 
119
//MSB:    setStats(1);
120
    Start_Timer();
121
 
122
    for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
123
    {
124
 
125
      Proc_5();
126
      Proc_4();
127
        /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
128
      Int_1_Loc = 2;
129
      Int_2_Loc = 3;
130
      strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
131
      Enum_Loc = Ident_2;
132
      Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
133
        /* Bool_Glob == 1 */
134
      while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
135
      {
136
        Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
137
          /* Int_3_Loc == 7 */
138
        Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
139
          /* Int_3_Loc == 7 */
140
        Int_1_Loc += 1;
141
      } /* while */
142
        /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
143
      Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
144
        /* Int_Glob == 5 */
145
      Proc_1 (Ptr_Glob);
146
      for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
147
                               /* loop body executed twice */
148
      {
149
        if (Enum_Loc == Func_1 (Ch_Index, 'C'))
150
            /* then, not executed */
151
          {
152
          Proc_6 (Ident_1, &Enum_Loc);
153
          strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
154
          Int_2_Loc = Run_Index;
155
          Int_Glob = Run_Index;
156
          }
157
      }
158
        /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
159
      Int_2_Loc = Int_2_Loc * Int_1_Loc;
160
      Int_1_Loc = Int_2_Loc / Int_3_Loc;
161
      Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
162
        /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
163
      Proc_2 (&Int_1_Loc);
164
        /* Int_1_Loc == 5 */
165
 
166
    } /* loop "for Run_Index" */
167
 
168
    /**************/
169
    /* Stop timer */
170
    /**************/
171
 
172
    Stop_Timer();
173
//MSB:    setStats(0);
174
 
175
    User_Time = End_Time - Begin_Time;
176
 
177
    if (User_Time < Too_Small_Time)
178
    {
179
      printf("Measured time too small to obtain meaningful results\n");
180
      Number_Of_Runs = Number_Of_Runs * 10;
181
      printf("\n");
182
    } else Done = true;
183
  }
184
 
185
  debug_printf("Final values of the variables used in the benchmark:\n");
186
  debug_printf("\n");
187
  debug_printf("Int_Glob:            %d\n", Int_Glob);
188
  debug_printf("        should be:   %d\n", 5);
189
  debug_printf("Bool_Glob:           %d\n", Bool_Glob);
190
  debug_printf("        should be:   %d\n", 1);
191
  debug_printf("Ch_1_Glob:           %c\n", Ch_1_Glob);
192
  debug_printf("        should be:   %c\n", 'A');
193
  debug_printf("Ch_2_Glob:           %c\n", Ch_2_Glob);
194
  debug_printf("        should be:   %c\n", 'B');
195
  debug_printf("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
196
  debug_printf("        should be:   %d\n", 7);
197
  debug_printf("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
198
  debug_printf("        should be:   Number_Of_Runs + 10\n");
199
  debug_printf("Ptr_Glob->\n");
200
  debug_printf("  Ptr_Comp:          %d\n", (long) Ptr_Glob->Ptr_Comp);
201
  debug_printf("        should be:   (implementation-dependent)\n");
202
  debug_printf("  Discr:             %d\n", Ptr_Glob->Discr);
203
  debug_printf("        should be:   %d\n", 0);
204
  debug_printf("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
205
  debug_printf("        should be:   %d\n", 2);
206
  debug_printf("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
207
  debug_printf("        should be:   %d\n", 17);
208
  debug_printf("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
209
  debug_printf("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
210
  debug_printf("Next_Ptr_Glob->\n");
211
  debug_printf("  Ptr_Comp:          %d\n", (long) Next_Ptr_Glob->Ptr_Comp);
212
  debug_printf("        should be:   (implementation-dependent), same as above\n");
213
  debug_printf("  Discr:             %d\n", Next_Ptr_Glob->Discr);
214
  debug_printf("        should be:   %d\n", 0);
215
  debug_printf("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
216
  debug_printf("        should be:   %d\n", 1);
217
  debug_printf("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
218
  debug_printf("        should be:   %d\n", 18);
219
  debug_printf("  Str_Comp:          %s\n",
220
                                Next_Ptr_Glob->variant.var_1.Str_Comp);
221
  debug_printf("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
222
  debug_printf("Int_1_Loc:           %d\n", Int_1_Loc);
223
  debug_printf("        should be:   %d\n", 5);
224
  debug_printf("Int_2_Loc:           %d\n", Int_2_Loc);
225
  debug_printf("        should be:   %d\n", 13);
226
  debug_printf("Int_3_Loc:           %d\n", Int_3_Loc);
227
  debug_printf("        should be:   %d\n", 7);
228
  debug_printf("Enum_Loc:            %d\n", Enum_Loc);
229
  debug_printf("        should be:   %d\n", 1);
230
  debug_printf("Str_1_Loc:           %s\n", Str_1_Loc);
231
  debug_printf("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
232
  debug_printf("Str_2_Loc:           %s\n", Str_2_Loc);
233
  debug_printf("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
234
  debug_printf("\n");
235
 
236
 
237
  Microseconds = ((User_Time / Number_Of_Runs) * Mic_secs_Per_Second) / HZ;
238
//  Dhrystones_Per_Second = (HZ * Number_Of_Runs) / User_Time;
239
  Dhrystones_Per_Second = Number_Of_Runs * (HZ / User_Time);
240
 
241
  printf("start=%ld ; end=%ld\n", Begin_Time, End_Time);
242
  printf("Microseconds for one run through Dhrystone: %ld\n", Microseconds);
243
  printf("Dhrystones per Second:                      %ld\n", Dhrystones_Per_Second);
244
 
245
  return 0;
246
}
247
 
248
 
249
void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
250
    /* executed once */
251
{
252
  REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
253
                                        /* == Ptr_Glob_Next */
254
  /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
255
  /* corresponds to "rename" in Ada, "with" in Pascal           */
256
 
257
  structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
258
  Ptr_Val_Par->variant.var_1.Int_Comp = 5;
259
  Next_Record->variant.var_1.Int_Comp
260
        = Ptr_Val_Par->variant.var_1.Int_Comp;
261
  Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
262
  Proc_3 (&Next_Record->Ptr_Comp);
263
    /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
264
                        == Ptr_Glob->Ptr_Comp */
265
  if (Next_Record->Discr == Ident_1)
266
    /* then, executed */
267
  {
268
    Next_Record->variant.var_1.Int_Comp = 6;
269
    Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
270
           &Next_Record->variant.var_1.Enum_Comp);
271
    Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
272
    Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
273
           &Next_Record->variant.var_1.Int_Comp);
274
  }
275
  else /* not executed */
276
    structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
277
} /* Proc_1 */
278
 
279
 
280
void Proc_2 (One_Fifty   *Int_Par_Ref)
281
/******************/
282
    /* executed once */
283
    /* *Int_Par_Ref == 1, becomes 4 */
284
{
285
  One_Fifty  Int_Loc;
286
  Enumeration   Enum_Loc;
287
 
288
  Int_Loc = *Int_Par_Ref + 10;
289
  do /* executed once */
290
    if (Ch_1_Glob == 'A')
291
      /* then, executed */
292
    {
293
      Int_Loc -= 1;
294
      *Int_Par_Ref = Int_Loc - Int_Glob;
295
      Enum_Loc = Ident_1;
296
    } /* if */
297
  while (Enum_Loc != Ident_1); /* true */
298
} /* Proc_2 */
299
 
300
 
301
void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
302
 
303
{
304
  if (Ptr_Glob != Null)
305
    /* then, executed */
306
    *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
307
  Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
308
} /* Proc_3 */
309
 
310
 
311
void Proc_4 () /* without parameters */
312
/*******/
313
    /* executed once */
314
{
315
  Boolean Bool_Loc;
316
 
317
  Bool_Loc = Ch_1_Glob == 'A';
318
  Bool_Glob = Bool_Loc | Bool_Glob;
319
  Ch_2_Glob = 'B';
320
} /* Proc_4 */
321
 
322
 
323
void Proc_5 () /* without parameters */
324
/*******/
325
    /* executed once */
326
{
327
  Ch_1_Glob = 'A';
328
  Bool_Glob = false;
329
} /* Proc_5 */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.