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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [stdalone/] [dhrystone/] [dhry_1.c] - Blame information for rev 280

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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