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

Subversion Repositories light52

[/] [light52/] [trunk/] [test/] [dhrystone/] [src/] [dhry21a.c] - Blame information for rev 3

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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