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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [sim/] [rtl_sim/] [src-c/] [dhrystone_4mcu/] [original_files/] [dhry21a.c] - Blame information for rev 145

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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