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

Subversion Repositories openmsp430

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

powered by: WebSVN 2.1.0

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