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

Subversion Repositories amber

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

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

powered by: WebSVN 2.1.0

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