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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [sim/] [rtl_sim/] [src-c/] [dhrystone_v2.1/] [dhry_1.c] - Blame information for rev 200

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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