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

Subversion Repositories mblite

[/] [mblite/] [tags/] [1.0/] [sw/] [dhrystone/] [testbench.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 takar
/*
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
#include "testbench.h"
19
#include "stdio.h"
20
#include <stdio.h>
21
 
22
/* Global Variables: */
23
 
24
Rec_Pointer     Ptr_Glob,
25
                Next_Ptr_Glob;
26
int             Int_Glob;
27
Boolean         Bool_Glob;
28
char            Ch_1_Glob,
29
                Ch_2_Glob;
30
int             Arr_1_Glob [50];
31
int             Arr_2_Glob [50] [50];
32
 
33
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
int main ()
46
{
47
        One_Fifty       Int_1_Loc;
48
  REG   One_Fifty       Int_2_Loc;
49
        One_Fifty       Int_3_Loc;
50
  REG   char            Ch_Index;
51
        Enumeration     Enum_Loc;
52
        Str_30          Str_1_Loc;
53
        Str_30          Str_2_Loc;
54
  REG   int             Run_Index;
55
  REG   int             Number_Of_Runs;
56
 
57
  /* Initializations */
58
 
59
  Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
60
  Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
61
 
62
  Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
63
  Ptr_Glob->Discr                       = Ident_1;
64
  Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
65
  Ptr_Glob->variant.var_1.Int_Comp      = 40;
66
  strcpy (Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING");
67
  strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
68
 
69
  Arr_2_Glob [8][7] = 10;
70
        /* Was missing in published program. Without this statement,    */
71
        /* Arr_2_Glob [8][7] would have an undefined value.             */
72
        /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
73
        /* overflow may occur for this array element.                   */
74
 
75
  Number_Of_Runs = 1000;
76
 
77
  for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
78
  {
79
 
80
    Proc_5();
81
    Proc_4();
82
      /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
83
    Int_1_Loc = 2;
84
    Int_2_Loc = 3;
85
    strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
86
    Enum_Loc = Ident_2;
87
    Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
88
      /* Bool_Glob == 1 */
89
    while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
90
    {
91
      Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
92
        /* Int_3_Loc == 7 */
93
      Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
94
        /* Int_3_Loc == 7 */
95
      Int_1_Loc += 1;
96
    } /* while */
97
      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
98
    Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
99
      /* Int_Glob == 5 */
100
    Proc_1 (Ptr_Glob);
101
    for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
102
                             /* loop body executed twice */
103
    {
104
      if (Enum_Loc == Func_1 (Ch_Index, 'C'))
105
        {
106
        Proc_6 (Ident_1, &Enum_Loc);
107
        strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
108
        Int_2_Loc = Run_Index;
109
        Int_Glob = Run_Index;
110
        }
111
    }
112
    Int_2_Loc = Int_2_Loc * Int_1_Loc;
113
    Int_1_Loc = Int_2_Loc / Int_3_Loc;
114
    Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
115
    Proc_2 (&Int_1_Loc);
116
  }
117
  return 0;
118
}
119
 
120
 
121
void Proc_1 (Ptr_Val_Par)
122
REG Rec_Pointer Ptr_Val_Par;
123
{
124
  REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
125
                                        /* == Ptr_Glob_Next */
126
  /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
127
  /* corresponds to "rename" in Ada, "with" in Pascal           */
128
 
129
  structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
130
  Ptr_Val_Par->variant.var_1.Int_Comp = 5;
131
  Next_Record->variant.var_1.Int_Comp
132
        = Ptr_Val_Par->variant.var_1.Int_Comp;
133
  Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
134
  Proc_3 (&Next_Record->Ptr_Comp);
135
  if (Next_Record->Discr == Ident_1)
136
  {
137
    Next_Record->variant.var_1.Int_Comp = 6;
138
    Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
139
           &Next_Record->variant.var_1.Enum_Comp);
140
    Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
141
    Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
142
           &Next_Record->variant.var_1.Int_Comp);
143
  }
144
  else
145
    structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
146
}
147
 
148
 
149
void Proc_2 (Int_Par_Ref)
150
 
151
One_Fifty   *Int_Par_Ref;
152
{
153
  One_Fifty  Int_Loc;
154
  Enumeration   Enum_Loc;
155
 
156
  Int_Loc = *Int_Par_Ref + 10;
157
  do /* executed once */
158
    if (Ch_1_Glob == 'A')
159
      /* then, executed */
160
    {
161
      Int_Loc -= 1;
162
      *Int_Par_Ref = Int_Loc - Int_Glob;
163
      Enum_Loc = Ident_1;
164
    } /* if */
165
  while (Enum_Loc != Ident_1); /* true */
166
} /* Proc_2 */
167
 
168
 
169
void Proc_3 (Ptr_Ref_Par)
170
/******************/
171
    /* executed once */
172
    /* Ptr_Ref_Par becomes Ptr_Glob */
173
 
174
Rec_Pointer *Ptr_Ref_Par;
175
 
176
{
177
  if (Ptr_Glob != Null)
178
    /* then, executed */
179
    *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
180
  Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
181
} /* Proc_3 */
182
 
183
 
184
void Proc_4 () /* without parameters */
185
/*******/
186
    /* executed once */
187
{
188
  Boolean Bool_Loc;
189
 
190
  Bool_Loc = Ch_1_Glob == 'A';
191
  Bool_Glob = Bool_Loc | Bool_Glob;
192
  Ch_2_Glob = 'B';
193
} /* Proc_4 */
194
 
195
 
196
void Proc_5 () /* without parameters */
197
/*******/
198
    /* executed once */
199
{
200
  Ch_1_Glob = 'A';
201
  Bool_Glob = false;
202
} /* Proc_5 */
203
 
204
 
205
        /* Procedure for the assignment of structures,          */
206
        /* if the C compiler doesn't support this feature       */
207
#ifdef  NOSTRUCTASSIGN
208
memcpy (d, s, l)
209
register char   *d;
210
register char   *s;
211
register int    l;
212
{
213
        while (l--) *d++ = *s++;
214
}
215
#endif
216
 
217
 
218
/*
219
 ****************************************************************************
220
 *
221
 *                   "DHRYSTONE" Benchmark Program
222
 *                   -----------------------------
223
 *
224
 *  Version:    C, Version 2.1
225
 *
226
 *  File:       dhry_2.c (part 3 of 3)
227
 *
228
 *  Date:       May 25, 1988
229
 *
230
 *  Author:     Reinhold P. Weicker
231
 *
232
 ****************************************************************************
233
 */
234
 
235
#ifndef REG
236
#define REG
237
        /* REG becomes defined as empty */
238
        /* i.e. no register variables   */
239
#endif
240
 
241
extern  int     Int_Glob;
242
extern  char    Ch_1_Glob;
243
 
244
 
245
void Proc_6 (Enum_Val_Par, Enum_Ref_Par)
246
/*********************************/
247
    /* executed once */
248
    /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
249
 
250
Enumeration  Enum_Val_Par;
251
Enumeration *Enum_Ref_Par;
252
{
253
  *Enum_Ref_Par = Enum_Val_Par;
254
  if (! Func_3 (Enum_Val_Par))
255
    /* then, not executed */
256
    *Enum_Ref_Par = Ident_4;
257
  switch (Enum_Val_Par)
258
  {
259
    case Ident_1:
260
      *Enum_Ref_Par = Ident_1;
261
      break;
262
    case Ident_2:
263
      if (Int_Glob > 100)
264
        /* then */
265
      *Enum_Ref_Par = Ident_1;
266
      else *Enum_Ref_Par = Ident_4;
267
      break;
268
    case Ident_3: /* executed */
269
      *Enum_Ref_Par = Ident_2;
270
      break;
271
    case Ident_4: break;
272
    case Ident_5:
273
      *Enum_Ref_Par = Ident_3;
274
      break;
275
  } /* switch */
276
} /* Proc_6 */
277
 
278
 
279
void Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref)
280
/**********************************************/
281
    /* executed three times                                      */
282
    /* first call:      Int_1_Par_Val == 2, Int_2_Par_Val == 3,  */
283
    /*                  Int_Par_Ref becomes 7                    */
284
    /* second call:     Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
285
    /*                  Int_Par_Ref becomes 17                   */
286
    /* third call:      Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
287
    /*                  Int_Par_Ref becomes 18                   */
288
One_Fifty       Int_1_Par_Val;
289
One_Fifty       Int_2_Par_Val;
290
One_Fifty      *Int_Par_Ref;
291
{
292
  One_Fifty Int_Loc;
293
 
294
  Int_Loc = Int_1_Par_Val + 2;
295
  *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
296
} /* Proc_7 */
297
 
298
 
299
void Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val)
300
/*********************************************************************/
301
    /* executed once      */
302
    /* Int_Par_Val_1 == 3 */
303
    /* Int_Par_Val_2 == 7 */
304
Arr_1_Dim       Arr_1_Par_Ref;
305
Arr_2_Dim       Arr_2_Par_Ref;
306
int             Int_1_Par_Val;
307
int             Int_2_Par_Val;
308
{
309
  REG One_Fifty Int_Index;
310
  REG One_Fifty Int_Loc;
311
 
312
  Int_Loc = Int_1_Par_Val + 5;
313
  Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
314
  Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
315
  Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
316
  for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
317
    Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
318
  Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
319
  Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
320
  Int_Glob = 5;
321
} /* Proc_8 */
322
 
323
 
324
Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val)
325
/*************************************************/
326
    /* executed three times                                         */
327
    /* first call:      Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R'    */
328
    /* second call:     Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C'    */
329
    /* third call:      Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C'    */
330
 
331
Capital_Letter   Ch_1_Par_Val;
332
Capital_Letter   Ch_2_Par_Val;
333
{
334
  Capital_Letter        Ch_1_Loc;
335
  Capital_Letter        Ch_2_Loc;
336
 
337
  Ch_1_Loc = Ch_1_Par_Val;
338
  Ch_2_Loc = Ch_1_Loc;
339
  if (Ch_2_Loc != Ch_2_Par_Val)
340
    /* then, executed */
341
    return (Ident_1);
342
  else  /* not executed */
343
  {
344
    Ch_1_Glob = Ch_1_Loc;
345
    return (Ident_2);
346
   }
347
} /* Func_1 */
348
 
349
 
350
Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref)
351
/*************************************************/
352
    /* executed once */
353
    /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
354
    /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
355
 
356
Str_30  Str_1_Par_Ref;
357
Str_30  Str_2_Par_Ref;
358
{
359
  REG One_Thirty        Int_Loc;
360
      Capital_Letter    Ch_Loc;
361
 
362
  Int_Loc = 2;
363
  while (Int_Loc <= 2) /* loop body executed once */
364
    if (Func_1 (Str_1_Par_Ref[Int_Loc],
365
                Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
366
      /* then, executed */
367
    {
368
      Ch_Loc = 'A';
369
      Int_Loc += 1;
370
    } /* if, while */
371
  if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
372
    /* then, not executed */
373
    Int_Loc = 7;
374
  if (Ch_Loc == 'R')
375
    /* then, not executed */
376
    return (true);
377
  else /* executed */
378
  {
379
    if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
380
      /* then, not executed */
381
    {
382
      Int_Loc += 7;
383
      Int_Glob = Int_Loc;
384
      return (true);
385
    }
386
    else /* executed */
387
      return (false);
388
  } /* if Ch_Loc */
389
} /* Func_2 */
390
 
391
 
392
Boolean Func_3 (Enum_Par_Val)
393
/***************************/
394
    /* executed once        */
395
    /* Enum_Par_Val == Ident_3 */
396
Enumeration Enum_Par_Val;
397
{
398
  Enumeration Enum_Loc;
399
 
400
  Enum_Loc = Enum_Par_Val;
401
  if (Enum_Loc == Ident_3)
402
    /* then, executed */
403
    return (true);
404
  else /* not executed */
405
    return (false);
406
} /* Func_3 */
407
 

powered by: WebSVN 2.1.0

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