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

Subversion Repositories amber

[/] [amber/] [trunk/] [sw/] [dhry/] [dhry.c] - Blame information for rev 31

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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