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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [tests/] [dhrystone.c] - Blame information for rev 289

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//=============================================================================
2
//####UNSUPPORTEDBEGIN####
3
//
4
// -------------------------------------------
5
// This source file has been contributed to eCos/Red Hat. It may have been
6
// changed slightly to provide an interface consistent with those of other 
7
// files.
8
//
9
// The functionality and contents of this file is supplied "AS IS"
10
// without any form of support and will not necessarily be kept up
11
// to date by Red Hat.
12
//
13
// The style of programming used in this file may not comply with the
14
// eCos programming guidelines. Please do not use as a base for other
15
// files.
16
//
17
// All inquiries about this file, or the functionality provided by it,
18
// should be directed to the 'ecos-discuss' mailing list (see
19
// http://sourceware.cygnus.com/ecos/intouch.html for details).
20
//
21
// -------------------------------------------
22
//
23
//####UNSUPPORTEDEND####
24
//=============================================================================
25
// Originally three different files, dhry.h, dhry21a.c and dhry21b.c
26
// Merged into one file and changed a little to avoid compilation warnings.
27
// The files were found at:
28
// FTP ftp.nosc.mil/pub/aburto/dhrystone
29
//=============================================================================
30
 
31
#include <pkgconf/system.h>
32
#include <pkgconf/infra.h>
33
#include <pkgconf/kernel.h>
34
#include <cyg/infra/cyg_type.h>
35
#include <cyg/infra/testcase.h>
36
 
37
#if !defined(CYGPKG_ISOINFRA)
38
# define NA_MSG "Requires CYGPKG_ISOINFRA"
39
#else
40
# include <pkgconf/isoinfra.h>
41
 
42
# if !defined(CYGFUN_KERNEL_API_C) \
43
    || !defined(CYGINT_ISO_STDIO_FORMATTED_IO) \
44
    || CYGINT_ISO_MALLOC == 0 \
45
    || !defined(CYGINT_ISO_STRING_STRFUNCS)
46
 
47
#  define NA_MSG "Requires CYGFUN_KERNEL_API_C && CYGINT_ISO_STDIO_FORMATTED_IO && CYGINT_ISO_MALLOC && CYGINT_ISO_STRING_STRFUNCS"
48
 
49
# elif !defined(__OPTIMIZE__) \
50
    || defined(CYGPKG_INFRA_DEBUG) \
51
    || defined(CYGPKG_KERNEL_INSTRUMENT)
52
#  define NA_MSG "Only runs with optimized code, no tracing and no asserts"
53
# elif defined(CYGDBG_INFRA_DIAG_USE_DEVICE)
54
#  define NA_MSG "Must use HAL diag output to avoid background DSR activity"
55
# endif
56
#endif
57
 
58
#ifndef NA_MSG
59
 
60
#include <cyg/hal/hal_cache.h>
61
#include <cyg/kernel/kapi.h>
62
#include <stdlib.h>
63
#include <string.h>
64
 
65
// Time in seconds.
66
double
67
dtime(void)
68
{
69
    return (double) cyg_current_time() / 100;
70
}
71
 
72
// Number of loops to run.
73
#if defined(CYGPRI_KERNEL_TESTS_DHRYSTONE_PASSES)
74
# define PASSES CYGPRI_KERNEL_TESTS_DHRYSTONE_PASSES
75
#else
76
# define PASSES 400000
77
#endif
78
 
79
// Used in the code below to mark changes to the code.
80
#define __ECOS__
81
 
82
#undef true
83
#undef false
84
 
85
 
86
/*
87
 *************************************************************************
88
 *
89
 *                   "DHRYSTONE" Benchmark Program
90
 *                   -----------------------------
91
 *
92
 *  Version:    C, Version 2.1
93
 *
94
 *  File:       dhry.h (part 1 of 3)
95
 *
96
 *  Date:       May 25, 1988
97
 *
98
 *  Author:     Reinhold P. Weicker
99
 *              Siemens Nixdorf Inf. Syst.
100
 *              STM OS 32
101
 *              Otto-Hahn-Ring 6
102
 *              W-8000 Muenchen 83
103
 *              Germany
104
 *                      Phone:    [+49]-89-636-42436
105
 *                                (8-17 Central European Time)
106
 *                      UUCP:     weicker@ztivax.uucp@unido.uucp
107
 *                      Internet: weicker@ztivax.siemens.com
108
 *
109
 *              Original Version (in Ada) published in
110
 *              "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
111
 *              pp. 1013 - 1030, together with the statistics
112
 *              on which the distribution of statements etc. is based.
113
 *
114
 *              In this C version, the following C library functions are
115
 *              used:
116
 *              - strcpy, strcmp (inside the measurement loop)
117
 *              - printf, scanf (outside the measurement loop)
118
 *
119
 *  Collection of Results:
120
 *              Reinhold Weicker (address see above) and
121
 *
122
 *              Rick Richardson
123
 *              PC Research. Inc.
124
 *              94 Apple Orchard Drive
125
 *              Tinton Falls, NJ 07724
126
 *                      Phone:  (201) 834-1378 (9-17 EST)
127
 *                      UUCP:   ...!uunet!pcrat!rick
128
 *
129
 *      Please send results to Rick Richardson and/or Reinhold Weicker.
130
 *      Complete information should be given on hardware and software
131
 *      used. Hardware information includes: Machine type, CPU, type and
132
 *      size of caches; for microprocessors: clock frequency, memory speed
133
 *      (number of wait states). Software information includes: Compiler
134
 *      (and runtime library) manufacturer and version, compilation
135
 *      switches, OS version. The Operating System version may give an
136
 *      indication about the compiler; Dhrystone itself performs no OS
137
 *      calls in the measurement loop.
138
 *
139
 *      The complete output generated by the program should be mailed
140
 *      such that at least some checks for correctness can be made.
141
 *
142
 *************************************************************************
143
 *
144
 *  History:    This version C/2.1 has been made for two reasons:
145
 *
146
 *              1) There is an obvious need for a common C version of
147
 *              Dhrystone, since C is at present the most popular system
148
 *              programming language for the class of processors
149
 *              (microcomputers, minicomputers) where Dhrystone is used
150
 *              most. There should be, as far as possible, only one C
151
 *              version of Dhrystone such that results can be compared
152
 *              without restrictions. In the past, the C versions
153
 *              distributed by Rick Richardson (Version 1.1) and by
154
 *              Reinhold Weicker had small (though not significant)
155
 *              differences.
156
 *
157
 *              2) As far as it is possible without changes to the
158
 *              Dhrystone statistics, optimizing compilers should be
159
 *              prevented from removing significant statements.
160
 *
161
 *              This C version has been developed in cooperation with
162
 *              Rick Richardson (Tinton Falls, NJ), it incorporates many
163
 *              ideas from the "Version 1.1" distributed previously by
164
 *              him over the UNIX network Usenet.
165
 *              I also thank Chaim Benedelac (National Semiconductor),
166
 *              David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
167
 *              Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
168
 *              for their help with comments on earlier versions of the
169
 *              benchmark.
170
 *
171
 *  Changes:    In the initialization part, this version follows mostly
172
 *              Rick Richardson's version distributed via Usenet, not the
173
 *              version distributed earlier via floppy disk by Reinhold
174
 *              Weicker. As a concession to older compilers, names have
175
 *              been made unique within the first 8 characters. Inside the
176
 *              measurement loop, this version follows the version
177
 *              previously distributed by Reinhold Weicker.
178
 *
179
 *              At several places in the benchmark, code has been added,
180
 *              but within the measurement loop only in branches that
181
 *              are not executed. The intention is that optimizing
182
 *              compilers should be prevented from moving code out of the
183
 *              measurement loop, or from removing code altogether. Since
184
 *              the statements that are executed within the measurement
185
 *              loop have NOT been changed, the numbers defining the
186
 *              "Dhrystone distribution" (distribution of statements,
187
 *              operand types and locality) still hold. Except for
188
 *              sophisticated optimizing compilers, execution times for
189
 *              this version should be the same as for previous versions.
190
 *
191
 *              Since it has proven difficult to subtract the time for the
192
 *              measurement loop overhead in a correct way, the loop check
193
 *              has been made a part of the benchmark. This does have
194
 *              an impact - though a very minor one - on the distribution
195
 *              statistics which have been updated for this version.
196
 *
197
 *              All changes within the measurement loop are described
198
 *              and discussed in the companion paper "Rationale for
199
 *              Dhrystone version 2".
200
 *
201
 *              Because of the self-imposed limitation that the order and
202
 *              distribution of the executed statements should not be
203
 *              changed, there are still cases where optimizing compilers
204
 *              may not generate code for some statements. To a certain
205
 *              degree, this is unavoidable for small synthetic
206
 *              benchmarks. Users of the benchmark are advised to check
207
 *              code listings whether code is generated for all statements
208
 *              of Dhrystone.
209
 *
210
 *              Version 2.1 is identical to version 2.0 distributed via
211
 *              the UNIX network Usenet in March 1988 except that it
212
 *              corrects some minor deficiencies that were found by users
213
 *              of version 2.0. The only change within the measurement
214
 *              loop is that a non-executed "else" part was added to the
215
 *              "if" statement in Func_3, and a non-executed "else" part
216
 *              removed from Proc_3.
217
 *
218
 *************************************************************************
219
 *
220
 * Defines:     The following "Defines" are possible:
221
 *              -DROPT         (default: Not defined)
222
 *                      As an approximation to what an average C
223
 *                      programmer might do, the "register" storage class
224
 *                      is applied (if enabled by -DROPT)
225
 *                      - for local variables, if they are used
226
 *                        (dynamically) five or more times
227
 *                      - for parameters if they are used (dynamically)
228
 *                        six or more times
229
 *                      Note that an optimal "register" strategy is
230
 *                      compiler-dependent, and that "register"
231
 *                      declarations do not necessarily lead to faster
232
 *                      execution.
233
 *              -DNOSTRUCTASSIGN        (default: Not defined)
234
 *                      Define if the C compiler does not support
235
 *                      assignment of structures.
236
 *              -DNOENUMS               (default: Not defined)
237
 *                      Define if the C compiler does not support
238
 *                      enumeration types.
239
 *
240
 *************************************************************************
241
 *
242
 *  Compilation model and measurement (IMPORTANT):
243
 *
244
 *  This C version of Dhrystone consists of three files:
245
 *  - dhry.h (this file, containing global definitions and comments)
246
 *  - dhry_1.c (containing the code corresponding to Ada package Pack_1)
247
 *  - dhry_2.c (containing the code corresponding to Ada package Pack_2)
248
 *
249
 *  The following "ground rules" apply for measurements:
250
 *  - Separate compilation
251
 *  - No procedure merging
252
 *  - Otherwise, compiler optimizations are allowed but should be
253
 *    indicated
254
 *  - Default results are those without register declarations
255
 *  See the companion paper "Rationale for Dhrystone Version 2" for a more
256
 *  detailed discussion of these ground rules.
257
 *
258
 *  For 16-Bit processors (e.g. 80186, 80286), times for all compilation
259
 *  models ("small", "medium", "large" etc.) should be given if possible,
260
 *  together with a definition of these models for the compiler system
261
 *  used.
262
 *
263
 *************************************************************************
264
 *
265
 *  Dhrystone (C version) statistics:
266
 *
267
 *  [Comment from the first distribution, updated for version 2.
268
 *   Note that because of language differences, the numbers are slightly
269
 *   different from the Ada version.]
270
 *
271
 *  The following program contains statements of a high level programming
272
 *  language (here: C) in a distribution considered representative:
273
 *
274
 *    assignments                  52 (51.0 %)
275
 *    control statements           33 (32.4 %)
276
 *    procedure, function calls    17 (16.7 %)
277
 *
278
 *  103 statements are dynamically executed. The program is balanced with
279
 *  respect to the three aspects:
280
 *
281
 *    - statement type
282
 *    - operand type
283
 *    - operand locality
284
 *         operand global, local, parameter, or constant.
285
 *
286
 *  The combination of these three aspects is balanced only approximately.
287
 *
288
 *  1. Statement Type:
289
 *  -----------------             number
290
 *
291
 *     V1 = V2                     9
292
 *       (incl. V1 = F(..)
293
 *     V = Constant               12
294
 *     Assignment,                 7
295
 *       with array element
296
 *     Assignment,                 6
297
 *       with record component
298
 *                                --
299
 *                                34       34
300
 *
301
 *     X = Y +|-|"&&"|"|" Z        5
302
 *     X = Y +|-|"==" Constant     6
303
 *     X = X +|- 1                 3
304
 *     X = Y *|/ Z                 2
305
 *     X = Expression,             1
306
 *           two operators
307
 *     X = Expression,             1
308
 *           three operators
309
 *                                --
310
 *                                18       18
311
 *
312
 *     if ....                    14
313
 *       with "else"      7
314
 *       without "else"   7
315
 *           executed        3
316
 *           not executed    4
317
 *     for ...                     7  |  counted every time
318
 *     while ...                   4  |  the loop condition
319
 *     do ... while                1  |  is evaluated
320
 *     switch ...                  1
321
 *     break                       1
322
 *     declaration with            1
323
 *       initialization
324
 *                                --
325
 *                                34       34
326
 *
327
 *     P (...)  procedure call    11
328
 *       user procedure      10
329
 *       library procedure    1
330
 *     X = F (...)
331
 *             function  call      6
332
 *       user function        5
333
 *       library function     1
334
 *                                --
335
 *                                17       17
336
 *                                        ---
337
 *                                        103
338
 *
339
 *    The average number of parameters in procedure or function calls
340
 *    is 1.82 (not counting the function values as implicit parameters).
341
 *
342
 *
343
 *  2. Operators
344
 *  ------------
345
 *                          number    approximate
346
 *                                    percentage
347
 *
348
 *    Arithmetic             32          50.8
349
 *
350
 *       +                     21          33.3
351
 *       -                      7          11.1
352
 *       *                      3           4.8
353
 *       / (int div)            1           1.6
354
 *
355
 *    Comparison             27           42.8
356
 *
357
 *       ==                     9           14.3
358
 *       /=                     4            6.3
359
 *       >                      1            1.6
360
 *       <                      3            4.8
361
 *       >=                     1            1.6
362
 *       <=                     9           14.3
363
 *
364
 *    Logic                   4            6.3
365
 *
366
 *       && (AND-THEN)          1            1.6
367
 *       |  (OR)                1            1.6
368
 *       !  (NOT)               2            3.2
369
 *
370
 *                           --          -----
371
 *                           63          100.1
372
 *
373
 *
374
 *  3. Operand Type (counted once per operand reference):
375
 *  ---------------
376
 *                          number    approximate
377
 *                                    percentage
378
 *
379
 *     Integer               175        72.3 %
380
 *     Character              45        18.6 %
381
 *     Pointer                12         5.0 %
382
 *     String30                6         2.5 %
383
 *     Array                   2         0.8 %
384
 *     Record                  2         0.8 %
385
 *                           ---       -------
386
 *                           242       100.0 %
387
 *
388
 *  When there is an access path leading to the final operand (e.g. a
389
 *  record component), only the final data type on the access path is
390
 *  counted.
391
 *
392
 *
393
 *  4. Operand Locality:
394
 *  -------------------
395
 *                                number    approximate
396
 *                                          percentage
397
 *
398
 *     local variable              114        47.1 %
399
 *     global variable              22         9.1 %
400
 *     parameter                    45        18.6 %
401
 *        value                        23         9.5 %
402
 *        reference                    22         9.1 %
403
 *     function result               6         2.5 %
404
 *     constant                     55        22.7 %
405
 *                                 ---       -------
406
 *                                 242       100.0 %
407
 *
408
 *
409
 *  The program does not compute anything meaningful, but it is
410
 *  syntactically and semantically correct. All variables have a value
411
 *  assigned to them before they are used as a source operand.
412
 *
413
 *  There has been no explicit effort to account for the effects of a
414
 *  cache, or to balance the use of long or short displacements for code
415
 *  or data.
416
 *
417
 *************************************************************************
418
 */
419
 
420
/* Compiler and system dependent definitions: */
421
 
422
#define Mic_secs_Per_Second     1000000.0
423
                /* Berkeley UNIX C returns process times in seconds/HZ */
424
 
425
#ifdef  NOSTRUCTASSIGN
426
#define structassign(d, s)      memcpy(&(d), &(s), sizeof(d))
427
#else
428
#define structassign(d, s)      d = s
429
#endif
430
 
431
#ifdef  NOENUM
432
#define Ident_1 0
433
#define Ident_2 1
434
#define Ident_3 2
435
#define Ident_4 3
436
#define Ident_5 4
437
  typedef int   Enumeration;
438
#else
439
  typedef       enum    {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
440
                Enumeration;
441
#endif
442
        /* for boolean and enumeration types in Ada, Pascal */
443
 
444
/* General definitions: */
445
 
446
#include <stdio.h>
447
                /* for strcpy, strcmp */
448
 
449
#define Null 0 
450
                /* Value of a Null pointer */
451
#define true  1
452
#define false 0
453
 
454
typedef int     One_Thirty;
455
typedef int     One_Fifty;
456
typedef char    Capital_Letter;
457
typedef int     Boolean;
458
typedef char    Str_30 [31];
459
typedef int     Arr_1_Dim [50];
460
typedef int     Arr_2_Dim [50] [50];
461
 
462
typedef struct record
463
    {
464
    struct record *Ptr_Comp;
465
    Enumeration    Discr;
466
    union {
467
          struct {
468
                  Enumeration Enum_Comp;
469
                  int         Int_Comp;
470
                  char        Str_Comp [31];
471
                  } var_1;
472
          struct {
473
                  Enumeration E_Comp_2;
474
                  char        Str_2_Comp [31];
475
                  } var_2;
476
          struct {
477
                  char        Ch_1_Comp;
478
                  char        Ch_2_Comp;
479
                  } var_3;
480
          } variant;
481
      } Rec_Type, *Rec_Pointer;
482
 
483
#ifdef __ECOS__
484
 
485
#ifndef ROPT
486
#define REG
487
        /* REG becomes defined as empty */
488
        /* i.e. no register variables   */
489
#else
490
#define REG register
491
#endif
492
 
493
Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);
494
Boolean Func_3 (Enumeration Enum_Par_Val);
495
 
496
void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
497
void Proc_2 (One_Fifty* Int_Par_Ref);
498
void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
499
void Proc_4 (void);
500
void Proc_5 (void);
501
void Proc_6 (Enumeration Enum_Val_Par, Enumeration* Enum_Ref_Par);
502
void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val,
503
            One_Fifty* Int_Par_Ref);
504
void Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref,
505
             int Int_1_Par_Val, int Int_2_Par_Val);
506
Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
507
 
508
#endif // __ECOS__
509
 
510
/*
511
 *************************************************************************
512
 *
513
 *                   "DHRYSTONE" Benchmark Program
514
 *                   -----------------------------
515
 *
516
 *  Version:    C, Version 2.1
517
 *
518
 *  File:       dhry_1.c (part 2 of 3)
519
 *
520
 *  Date:       May 25, 1988
521
 *
522
 *  Author:     Reinhold P. Weicker
523
 *
524
 *************************************************************************
525
 */
526
 
527
#include <stdio.h>
528
#ifndef __ECOS__
529
#include "dhry.h"
530
#endif // __ECOS__
531
 
532
/* Global Variables: */
533
 
534
Rec_Pointer     Ptr_Glob,
535
                Next_Ptr_Glob;
536
int             Int_Glob;
537
Boolean         Bool_Glob;
538
char            Ch_1_Glob,
539
                Ch_2_Glob;
540
int             Arr_1_Glob [50];
541
int             Arr_2_Glob [50] [50];
542
 
543
char Reg_Define[] = "Register option selected.";
544
 
545
#ifndef __ECOS__
546
extern char     *malloc ();
547
Enumeration     Func_1 ();
548
#endif
549
  /*
550
  forward declaration necessary since Enumeration may not simply be int
551
  */
552
 
553
#ifndef __ECOS__
554
#ifndef ROPT
555
#define REG
556
        /* REG becomes defined as empty */
557
        /* i.e. no register variables   */
558
#else
559
#define REG register
560
#endif
561
#endif
562
 
563
/* variables for time measurement: */
564
 
565
#define Too_Small_Time 2
566
                /* Measurements should last at least 2 seconds */
567
 
568
double          Begin_Time,
569
                End_Time,
570
                User_Time;
571
 
572
double          Microseconds,
573
                Dhrystones_Per_Second,
574
                Vax_Mips;
575
 
576
/* end of variables for time measurement */
577
 
578
 
579
#ifndef __ECOS__
580
void main ()
581
#else // __ECOS__
582
int main (void)
583
#endif // __ECOS__
584
/*****/
585
 
586
  /* main program, corresponds to procedures        */
587
  /* Main and Proc_0 in the Ada version             */
588
{
589
#ifndef __ECOS__
590
  double   dtime();
591
#endif // __ECOS__
592
 
593
        One_Fifty       Int_1_Loc;
594
  REG   One_Fifty       Int_2_Loc;
595
        One_Fifty       Int_3_Loc;
596
  REG   char            Ch_Index;
597
        Enumeration     Enum_Loc;
598
        Str_30          Str_1_Loc;
599
        Str_30          Str_2_Loc;
600
  REG   int             Run_Index;
601
  REG   int             Number_Of_Runs;
602
 
603
 
604
#ifdef __ECOS__
605
 
606
    CYG_TEST_INIT();
607
 
608
#ifdef CYG_HAL_I386_LINUX
609
    CYG_TEST_NA("Only runs on hardware...");
610
#else
611
    if (cyg_test_is_simulator)
612
        CYG_TEST_NA("Only runs on hardware...");
613
#endif
614
 
615
#else // __ECOS__
616
        FILE            *Ap;
617
 
618
  /* Initializations */
619
 
620
  if ((Ap = fopen("dhry.res","a+")) == NULL)
621
    {
622
       printf("Can not open dhry.res\n\n");
623
       exit(1);
624
    }
625
#endif // __ECOS__
626
 
627
  Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
628
  Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
629
 
630
  Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
631
  Ptr_Glob->Discr                       = Ident_1;
632
  Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
633
  Ptr_Glob->variant.var_1.Int_Comp      = 40;
634
  strcpy (Ptr_Glob->variant.var_1.Str_Comp,
635
          "DHRYSTONE PROGRAM, SOME STRING");
636
  strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
637
 
638
  Arr_2_Glob [8][7] = 10;
639
        /* Was missing in published program. Without this statement,    */
640
        /* Arr_2_Glob [8][7] would have an undefined value.             */
641
        /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
642
        /* overflow may occur for this array element.                   */
643
 
644
  printf ("\n");
645
  printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
646
  printf ("\n");
647
/*
648
  if (Reg)
649
  {
650
    printf ("Program compiled with 'register' attribute\n");
651
    printf ("\n");
652
  }
653
  else
654
  {
655
    printf ("Program compiled without 'register' attribute\n");
656
    printf ("\n");
657
  }
658
*/
659
#ifdef __ECOS__
660
  Number_Of_Runs = PASSES;
661
#else // __ECOS__
662
  printf ("Please give the number of runs through the benchmark: ");
663
  {
664
    int n;
665
    scanf ("%d", &n);
666
    Number_Of_Runs = n;
667
  }
668
  printf ("\n");
669
#endif // __ECOS__
670
 
671
  printf ("Execution starts, %d runs through Dhrystone\n",Number_Of_Runs);
672
 
673
  /***************/
674
  /* Start timer */
675
  /***************/
676
 
677
  Begin_Time = dtime();
678
 
679
  for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
680
  {
681
 
682
    Proc_5();
683
    Proc_4();
684
      /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
685
    Int_1_Loc = 2;
686
    Int_2_Loc = 3;
687
    strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
688
    Enum_Loc = Ident_2;
689
    Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
690
      /* Bool_Glob == 1 */
691
    while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
692
    {
693
      Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
694
        /* Int_3_Loc == 7 */
695
      Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
696
        /* Int_3_Loc == 7 */
697
      Int_1_Loc += 1;
698
    } /* while */
699
      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
700
    Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
701
      /* Int_Glob == 5 */
702
    Proc_1 (Ptr_Glob);
703
    for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
704
                             /* loop body executed twice */
705
    {
706
      if (Enum_Loc == Func_1 (Ch_Index, 'C'))
707
          /* then, not executed */
708
        {
709
        Proc_6 (Ident_1, &Enum_Loc);
710
        strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
711
        Int_2_Loc = Run_Index;
712
        Int_Glob = Run_Index;
713
        }
714
    }
715
      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
716
    Int_2_Loc = Int_2_Loc * Int_1_Loc;
717
    Int_1_Loc = Int_2_Loc / Int_3_Loc;
718
    Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
719
      /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
720
    Proc_2 (&Int_1_Loc);
721
      /* Int_1_Loc == 5 */
722
 
723
  } /* loop "for Run_Index" */
724
 
725
  /**************/
726
  /* Stop timer */
727
  /**************/
728
 
729
  End_Time = dtime();
730
 
731
  printf ("Execution ends\n");
732
  printf ("\n");
733
  printf ("Final values of the variables used in the benchmark:\n");
734
  printf ("\n");
735
  printf ("Int_Glob:            %d\n", Int_Glob);
736
  printf ("        should be:   %d\n", 5);
737
  printf ("Bool_Glob:           %d\n", Bool_Glob);
738
  printf ("        should be:   %d\n", 1);
739
  printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
740
  printf ("        should be:   %c\n", 'A');
741
  printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
742
  printf ("        should be:   %c\n", 'B');
743
  printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
744
  printf ("        should be:   %d\n", 7);
745
  printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
746
  printf ("        should be:   Number_Of_Runs + 10\n");
747
  printf ("Ptr_Glob->\n");
748
  printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
749
  printf ("        should be:   (implementation-dependent)\n");
750
  printf ("  Discr:             %d\n", Ptr_Glob->Discr);
751
  printf ("        should be:   %d\n", 0);
752
  printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
753
  printf ("        should be:   %d\n", 2);
754
  printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
755
  printf ("        should be:   %d\n", 17);
756
  printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
757
  printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
758
  printf ("Next_Ptr_Glob->\n");
759
  printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
760
  printf ("        should be:   (implementation-dependent), same as above\n");
761
  printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
762
  printf ("        should be:   %d\n", 0);
763
  printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
764
  printf ("        should be:   %d\n", 1);
765
  printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
766
  printf ("        should be:   %d\n", 18);
767
  printf ("  Str_Comp:          %s\n", Next_Ptr_Glob->variant.var_1.Str_Comp);
768
  printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
769
  printf ("Int_1_Loc:           %d\n", Int_1_Loc);
770
  printf ("        should be:   %d\n", 5);
771
  printf ("Int_2_Loc:           %d\n", Int_2_Loc);
772
  printf ("        should be:   %d\n", 13);
773
  printf ("Int_3_Loc:           %d\n", Int_3_Loc);
774
  printf ("        should be:   %d\n", 7);
775
  printf ("Enum_Loc:            %d\n", Enum_Loc);
776
  printf ("        should be:   %d\n", 1);
777
  printf ("Str_1_Loc:           %s\n", Str_1_Loc);
778
  printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
779
  printf ("Str_2_Loc:           %s\n", Str_2_Loc);
780
  printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
781
  printf ("\n");
782
 
783
  User_Time = End_Time - Begin_Time;
784
 
785
  if (User_Time < Too_Small_Time)
786
  {
787
    printf ("Measured time too small to obtain meaningful results\n");
788
    printf ("Please increase number of runs\n");
789
    printf ("\n");
790
  }
791
  else
792
  {
793
    Microseconds = User_Time * Mic_secs_Per_Second
794
                        / (double) Number_Of_Runs;
795
    Dhrystones_Per_Second = (double) Number_Of_Runs / User_Time;
796
    Vax_Mips = Dhrystones_Per_Second / 1757.0;
797
 
798
#ifdef ROPT
799
    printf ("Register option selected?  YES\n");
800
#else
801
    printf ("Register option selected?  NO\n");
802
#ifndef __ECOS__
803
    strcpy(Reg_Define, "Register option not selected.");
804
#endif // __ECOS__
805
#endif
806
    printf ("Microseconds for one run through Dhrystone: ");
807
#ifdef __ECOS__
808
    printf ("%7.1f \n", Microseconds);
809
    printf ("Dhrystones per Second:                      ");
810
    printf ("%10.1f \n", Dhrystones_Per_Second);
811
    printf ("VAX MIPS rating = %10.3f \n",Vax_Mips);
812
    printf ("\n");
813
#else // __ECOS__
814
    printf ("%7.1lf \n", Microseconds);
815
    printf ("Dhrystones per Second:                      ");
816
    printf ("%10.1lf \n", Dhrystones_Per_Second);
817
    printf ("VAX MIPS rating = %10.3lf \n",Vax_Mips);
818
    printf ("\n");
819
 
820
  fprintf(Ap,"\n");
821
  fprintf(Ap,"Dhrystone Benchmark, Version 2.1 (Language: C)\n");
822
  fprintf(Ap,"%s\n",Reg_Define);
823
  fprintf(Ap,"Microseconds for one loop: %7.1lf\n",Microseconds);
824
  fprintf(Ap,"Dhrystones per second: %10.1lf\n",Dhrystones_Per_Second);
825
  fprintf(Ap,"VAX MIPS rating: %10.3lf\n",Vax_Mips);
826
  fclose(Ap);
827
#endif // __ECOS__  
828
  }
829
 
830
#ifdef __ECOS__
831
  CYG_TEST_PASS_FINISH("Dhrystone test");
832
#endif // __ECOS__
833
}
834
 
835
 
836
#ifdef __ECOS__
837
void
838
#endif // __ECOS__
839
Proc_1 (Ptr_Val_Par)
840
/******************/
841
 
842
REG Rec_Pointer Ptr_Val_Par;
843
    /* executed once */
844
{
845
  REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
846
                                        /* == Ptr_Glob_Next */
847
  /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
848
  /* corresponds to "rename" in Ada, "with" in Pascal           */
849
 
850
  structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
851
  Ptr_Val_Par->variant.var_1.Int_Comp = 5;
852
  Next_Record->variant.var_1.Int_Comp
853
        = Ptr_Val_Par->variant.var_1.Int_Comp;
854
  Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
855
  Proc_3 (&Next_Record->Ptr_Comp);
856
    /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
857
                        == Ptr_Glob->Ptr_Comp */
858
  if (Next_Record->Discr == Ident_1)
859
    /* then, executed */
860
  {
861
    Next_Record->variant.var_1.Int_Comp = 6;
862
    Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
863
           &Next_Record->variant.var_1.Enum_Comp);
864
    Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
865
    Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
866
           &Next_Record->variant.var_1.Int_Comp);
867
  }
868
  else /* not executed */
869
    structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
870
} /* Proc_1 */
871
 
872
 
873
#ifdef __ECOS__
874
void
875
#endif // __ECOS__
876
Proc_2 (Int_Par_Ref)
877
/******************/
878
    /* executed once */
879
    /* *Int_Par_Ref == 1, becomes 4 */
880
 
881
One_Fifty   *Int_Par_Ref;
882
{
883
  One_Fifty  Int_Loc;
884
#ifdef __ECOS__
885
  Enumeration   Enum_Loc = Ident_1;
886
#else // __ECOS__
887
  Enumeration   Enum_Loc;
888
#endif // __ECOS__
889
 
890
  Int_Loc = *Int_Par_Ref + 10;
891
  do /* executed once */
892
    if (Ch_1_Glob == 'A')
893
      /* then, executed */
894
    {
895
      Int_Loc -= 1;
896
      *Int_Par_Ref = Int_Loc - Int_Glob;
897
      Enum_Loc = Ident_1;
898
    } /* if */
899
  while (Enum_Loc != Ident_1); /* true */
900
} /* Proc_2 */
901
 
902
 
903
#ifdef __ECOS__
904
void
905
#endif // __ECOS__
906
Proc_3 (Ptr_Ref_Par)
907
/******************/
908
    /* executed once */
909
    /* Ptr_Ref_Par becomes Ptr_Glob */
910
 
911
Rec_Pointer *Ptr_Ref_Par;
912
 
913
{
914
  if (Ptr_Glob != Null)
915
    /* then, executed */
916
    *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
917
  Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
918
} /* Proc_3 */
919
 
920
 
921
#ifdef __ECOS__
922
void
923
#endif // __ECOS__
924
Proc_4 () /* without parameters */
925
/*******/
926
    /* executed once */
927
{
928
  Boolean Bool_Loc;
929
 
930
  Bool_Loc = Ch_1_Glob == 'A';
931
  Bool_Glob = Bool_Loc | Bool_Glob;
932
  Ch_2_Glob = 'B';
933
} /* Proc_4 */
934
 
935
 
936
#ifdef __ECOS__
937
void
938
#endif // __ECOS__
939
Proc_5 () /* without parameters */
940
/*******/
941
    /* executed once */
942
{
943
  Ch_1_Glob = 'A';
944
  Bool_Glob = false;
945
} /* Proc_5 */
946
 
947
 
948
        /* Procedure for the assignment of structures,          */
949
        /* if the C compiler doesn't support this feature       */
950
#ifdef  NOSTRUCTASSIGN
951
memcpy (d, s, l)
952
register char   *d;
953
register char   *s;
954
register int    l;
955
{
956
        while (l--) *d++ = *s++;
957
}
958
#endif
959
 
960
/*
961
 *************************************************************************
962
 *
963
 *                   "DHRYSTONE" Benchmark Program
964
 *                   -----------------------------
965
 *
966
 *  Version:    C, Version 2.1
967
 *
968
 *  File:       dhry_2.c (part 3 of 3)
969
 *
970
 *  Date:       May 25, 1988
971
 *
972
 *  Author:     Reinhold P. Weicker
973
 *
974
 *************************************************************************
975
 */
976
 
977
#ifndef __ECOS__
978
#include "dhry.h"
979
 
980
#ifndef REG
981
#define REG
982
        /* REG becomes defined as empty */
983
        /* i.e. no register variables   */
984
#else
985
#define REG register
986
#endif
987
#endif // __ECOS__
988
 
989
extern  int     Int_Glob;
990
extern  char    Ch_1_Glob;
991
 
992
#ifdef __ECOS__
993
void
994
#endif // __ECOS__
995
Proc_6 (Enum_Val_Par, Enum_Ref_Par)
996
/*********************************/
997
    /* executed once */
998
    /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
999
 
1000
Enumeration  Enum_Val_Par;
1001
Enumeration *Enum_Ref_Par;
1002
{
1003
  *Enum_Ref_Par = Enum_Val_Par;
1004
  if (! Func_3 (Enum_Val_Par))
1005
    /* then, not executed */
1006
    *Enum_Ref_Par = Ident_4;
1007
  switch (Enum_Val_Par)
1008
  {
1009
    case Ident_1:
1010
      *Enum_Ref_Par = Ident_1;
1011
      break;
1012
    case Ident_2:
1013
      if (Int_Glob > 100)
1014
        /* then */
1015
      *Enum_Ref_Par = Ident_1;
1016
      else *Enum_Ref_Par = Ident_4;
1017
      break;
1018
    case Ident_3: /* executed */
1019
      *Enum_Ref_Par = Ident_2;
1020
      break;
1021
    case Ident_4: break;
1022
    case Ident_5:
1023
      *Enum_Ref_Par = Ident_3;
1024
      break;
1025
  } /* switch */
1026
} /* Proc_6 */
1027
 
1028
 
1029
#ifdef __ECOS__
1030
void
1031
#endif // __ECOS__
1032
Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref)
1033
/**********************************************/
1034
    /* executed three times                                      */
1035
    /* first call:      Int_1_Par_Val == 2, Int_2_Par_Val == 3,  */
1036
    /*                  Int_Par_Ref becomes 7                    */
1037
    /* second call:     Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
1038
    /*                  Int_Par_Ref becomes 17                   */
1039
    /* third call:      Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
1040
    /*                  Int_Par_Ref becomes 18                   */
1041
One_Fifty       Int_1_Par_Val;
1042
One_Fifty       Int_2_Par_Val;
1043
One_Fifty      *Int_Par_Ref;
1044
{
1045
  One_Fifty Int_Loc;
1046
 
1047
  Int_Loc = Int_1_Par_Val + 2;
1048
  *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
1049
} /* Proc_7 */
1050
 
1051
 
1052
#ifdef __ECOS__
1053
void
1054
#endif // __ECOS__
1055
Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val)
1056
/*********************************************************************/
1057
    /* executed once      */
1058
    /* Int_Par_Val_1 == 3 */
1059
    /* Int_Par_Val_2 == 7 */
1060
Arr_1_Dim       Arr_1_Par_Ref;
1061
Arr_2_Dim       Arr_2_Par_Ref;
1062
int             Int_1_Par_Val;
1063
int             Int_2_Par_Val;
1064
{
1065
  REG One_Fifty Int_Index;
1066
  REG One_Fifty Int_Loc;
1067
 
1068
  Int_Loc = Int_1_Par_Val + 5;
1069
  Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
1070
  Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
1071
  Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
1072
  for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
1073
    Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
1074
  Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
1075
  Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
1076
  Int_Glob = 5;
1077
} /* Proc_8 */
1078
 
1079
 
1080
Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val)
1081
/*************************************************/
1082
    /* executed three times                                         */
1083
    /* first call:      Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R'    */
1084
    /* second call:     Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C'    */
1085
    /* third call:      Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C'    */
1086
 
1087
Capital_Letter   Ch_1_Par_Val;
1088
Capital_Letter   Ch_2_Par_Val;
1089
{
1090
  Capital_Letter        Ch_1_Loc;
1091
  Capital_Letter        Ch_2_Loc;
1092
 
1093
  Ch_1_Loc = Ch_1_Par_Val;
1094
  Ch_2_Loc = Ch_1_Loc;
1095
  if (Ch_2_Loc != Ch_2_Par_Val)
1096
    /* then, executed */
1097
    return (Ident_1);
1098
  else  /* not executed */
1099
  {
1100
    Ch_1_Glob = Ch_1_Loc;
1101
    return (Ident_2);
1102
   }
1103
} /* Func_1 */
1104
 
1105
 
1106
Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref)
1107
/*************************************************/
1108
    /* executed once */
1109
    /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
1110
    /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
1111
 
1112
Str_30  Str_1_Par_Ref;
1113
Str_30  Str_2_Par_Ref;
1114
{
1115
  REG One_Thirty        Int_Loc;
1116
#ifdef __ECOS__
1117
      Capital_Letter    Ch_Loc = 'A';
1118
#else // __ECOS__
1119
      Capital_Letter    Ch_Loc;
1120
#endif // __ECOS__
1121
 
1122
  Int_Loc = 2;
1123
  while (Int_Loc <= 2) /* loop body executed once */
1124
    if (Func_1 (Str_1_Par_Ref[Int_Loc],
1125
                Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
1126
      /* then, executed */
1127
    {
1128
      Ch_Loc = 'A';
1129
      Int_Loc += 1;
1130
    } /* if, while */
1131
  if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
1132
    /* then, not executed */
1133
    Int_Loc = 7;
1134
  if (Ch_Loc == 'R')
1135
    /* then, not executed */
1136
    return (true);
1137
  else /* executed */
1138
  {
1139
    if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
1140
      /* then, not executed */
1141
    {
1142
      Int_Loc += 7;
1143
      Int_Glob = Int_Loc;
1144
      return (true);
1145
    }
1146
    else /* executed */
1147
      return (false);
1148
  } /* if Ch_Loc */
1149
} /* Func_2 */
1150
 
1151
 
1152
Boolean Func_3 (Enum_Par_Val)
1153
/***************************/
1154
    /* executed once        */
1155
    /* Enum_Par_Val == Ident_3 */
1156
Enumeration Enum_Par_Val;
1157
{
1158
  Enumeration Enum_Loc;
1159
 
1160
  Enum_Loc = Enum_Par_Val;
1161
  if (Enum_Loc == Ident_3)
1162
    /* then, executed */
1163
    return (true);
1164
  else /* not executed */
1165
    return (false);
1166
} /* Func_3 */
1167
 
1168
#else /* ifndef NA_MSG */
1169
 
1170
externC void
1171
cyg_start( void )
1172
{
1173
    CYG_TEST_INIT();
1174
    CYG_TEST_NA(NA_MSG);
1175
}
1176
#endif

powered by: WebSVN 2.1.0

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