home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / byteunix.lzh / byte.4 / dhry.h < prev   
Text File  |  1990-05-11  |  19KB  |  448 lines

  1. /*******************************************************************************
  2.  *  The BYTE UNIX Benchmarks - Release 2
  3.  *          Module: dhry.h   SID: 2.4 4/17/90 16:45:38
  4.  *          
  5.  *******************************************************************************
  6.  * Bug reports, patches, comments, suggestions should be sent to:
  7.  *
  8.  *    Ben Smith or Rick Grehan at BYTE Magazine
  9.  *    bensmith@bixpb.UUCP    rick_g@bixpb.UUCP
  10.  *
  11.  *******************************************************************************
  12.  *  Modification Log:
  13.  * addapted from:
  14.  *
  15.  ******************************************************************************/
  16. /*
  17.  ****************************************************************************
  18.  *
  19.  *                   "DHRYSTONE" Benchmark Program
  20.  *                   -----------------------------
  21.  *                                                                            
  22.  *  Version:    C, Version 2.0
  23.  *                                                                            
  24.  *  File:       dhry_global.h (part 1 of 3)
  25.  *
  26.  *  Date:       March 3, 1988
  27.  *
  28.  *  Author:     Reinhold P. Weicker
  29.  *                      Siemens AG, E STE 35
  30.  *                      Postfach 3240
  31.  *                      8520 Erlangen
  32.  *                      Germany (West)
  33.  *                              Phone:  [xxx-49]-9131-7-20330
  34.  *                                      (8-17 Central European Time)
  35.  *                              Usenet: ..!mcvax!unido!estevax!weicker
  36.  *
  37.  *              Original Version (in Ada) published in
  38.  *              "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
  39.  *              pp. 1013 - 1030, together with the statistics
  40.  *              on which the distribution of statements etc. is based.
  41.  *
  42.  *              In this C version, the following C library functions are used:
  43.  *              - strcpy, strcmp (inside the measurement loop)
  44.  *              - printf, scanf (outside the measurement loop)
  45.  *              In addition, UNIX system calls "times ()" or "time ()"
  46.  *              are used for execution time measurement. For measurements
  47.  *              on other systems, these calls have to be changed.
  48.  *
  49.  *  Collection of Results:
  50.  *              Reinhold Weicker (address see above) and
  51.  *              
  52.  *              Rick Richardson
  53.  *              PC Research. Inc.
  54.  *              94 Apple Orchard Drive
  55.  *              Tinton Falls, NJ 07724
  56.  *                      Phone:  (201) 834-1378 (9-17 EST)               
  57.  *                      Usenet: ...!seismo!uunet!pcrat!rick
  58.  *
  59.  *      Please send results to Reinhold Weicker and/or Rick Richardson.
  60.  *      Complete information should be given on hardware and software used.
  61.  *      Hardware information includes: Machine type, CPU, type and size
  62.  *      of caches; for microprocessors: clock frequency, memory speed
  63.  *      (number of wait states).
  64.  *      Software information includes: Compiler (and runtime library)
  65.  *      manufacturer and version, compilation switches, OS version.
  66.  *      The Operating System version may give an indication about the
  67.  *      compiler; Dhrystone itself performs no OS calls in the measurement loop.
  68.  *
  69.  *      The complete output generated by the program should be mailed
  70.  *      such that at least some checks for correctness can be made.
  71.  *
  72.  ***************************************************************************
  73.  *
  74.  *  History:    This version C/2.0 has been made for two reasons:
  75.  *
  76.  *              1) There is an obvious need for a common C version of
  77.  *              Dhrystone, since C is at present the most popular system
  78.  *              programming language for the class of processors
  79.  *              (microcomputers, minicomputers) where Dhrystone is used most.
  80.  *              There should be, as far as possible, only one C version of
  81.  *              Dhrystone such that results can be compared without
  82.  *              restrictions. In the past, the C versions distributed
  83.  *              by Rick Richardson (Version 1.1) and by Reinhold Weicker
  84.  *              had small (though not significant) differences.
  85.  *
  86.  *              2) As far as it is possible without changes to the Dhrystone
  87.  *              statistics, optimizing compilers should be prevented from
  88.  *              removing significant statements.
  89.  *
  90.  *              This C version has been developed in cooperation with
  91.  *              Rick Richardson (Tinton Falls, NJ), it incorporates many
  92.  *              ideas from the "Version 1.1" distributed previously by
  93.  *              him over the UNIX network Usenet.
  94.  *              I also thank Chaim Benedelac (National Semiconductor),
  95.  *              David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
  96.  *              Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
  97.  *              for their help with comments on earlier versions of the
  98.  *              benchmark.
  99.  *
  100.  *  Changes:    In the initialization part, this version follows mostly
  101.  *              Rick Richardson's version distributed via Usenet, not the
  102.  *              version distributed earlier via floppy disk by Reinhold Weicker.
  103.  *              As a concession to older compilers, names have been made
  104.  *              unique within the first 8 characters.
  105.  *              Inside the measurement loop, this version follows the
  106.  *              version previously distributed by Reinhold Weicker.
  107.  *
  108.  *              At several places in the benchmark, code has been added,
  109.  *              but within the measurement loop only in branches that 
  110.  *              are not executed. The intention is that optimizing compilers
  111.  *              should be prevented from moving code out of the measurement
  112.  *              loop, or from removing code altogether. Since the statements
  113.  *              that are executed within the measurement loop have NOT been
  114.  *              changed, the numbers defining the "Dhrystone distribution"
  115.  *              (distribution of statements, operand types and locality)
  116.  *              still hold. Except for sophisticated optimizing compilers,
  117.  *              execution times for this version should be the same as
  118.  *              for previous versions.
  119.  *              
  120.  *              Since it has proven difficult to subtract the time for the
  121.  *              measurement loop overhead in a correct way, the loop check
  122.  *              has been made a part of the benchmark. This does have
  123.  *              an impact - though a very minor one - on the distribution
  124.  *              statistics which have been updated for this version.
  125.  *
  126.  *              All changes within the measurement loop are described
  127.  *              and discussed in the companion paper "Rationale for
  128.  *              Dhrystone version 2".
  129.  *
  130.  *              Because of the self-imposed limitation that the order and
  131.  *              distribution of the executed statements should not be
  132.  *              changed, there are still cases where optimizing compilers
  133.  *              may not generate code for some statements. To a certain
  134.  *              degree, this is unavoidable for small synthetic benchmarks.
  135.  *              Users of the benchmark are advised to check code listings
  136.  *              whether code is generated for all statements of Dhrystone.
  137.  *
  138.  ***************************************************************************
  139.  *
  140.  * Defines:     The following "Defines" are possible:
  141.  *              -DREG=register          (default: Not defined)
  142.  *                      As an approximation to what an average C programmer
  143.  *                      might do, the "register" storage class is applied
  144.  *                      (if enabled by -DREG=register)
  145.  *                      - for local variables, if they are used (dynamically)
  146.  *                        five or more times
  147.  *                      - for parameters if they are used (dynamically)
  148.  *                        six or more times
  149.  *                      Note that an optimal "register" strategy is
  150.  *                      compiler-dependent, and that "register" declarations
  151.  *                      do not necessarily lead to faster execution.
  152.  *              -DNOSTRUCTASSIGN        (default: Not defined)
  153.  *                      Define if the C compiler does not support
  154.  *                      assignment of structures.
  155.  *              -DNOENUMS               (default: Not defined)
  156.  *                      Define if the C compiler does not support
  157.  *                      enumeration types.
  158.  *              -DTIMES                 (default)
  159.  *              -DTIME
  160.  *                      The "times" function of UNIX (returning process times)
  161.  *                      or the "time" function (returning wallclock time)
  162.  *                      is used for measurement. 
  163.  *                      For single user machines, "time ()" is adequate. For
  164.  *                      multi-user machines where you cannot get single-user
  165.  *                      access, use the "times ()" function. If you have
  166.  *                      neither, use a stopwatch in the dead of night.
  167.  *                      "printf"s are provided marking the points "Start Timer"
  168.  *                      and "Stop Timer". DO NOT use the UNIX "time(1)"
  169.  *                      command, as this will measure the total time to
  170.  *                      run this program, which will (erroneously) include
  171.  *                      the time to allocate storage (malloc) and to perform
  172.  *                      the initialization.
  173.  *              -DHZ=nnn                (default: 60)
  174.  *                      The function "times" returns process times in
  175.  *                      1/HZ seconds, with HZ = 60 for most systems.
  176.  *                      CHECK YOUR SYSTEM DESCRIPTION BEFORE YOU JUST APPLY
  177.  *                      THE DEFAULT VALUE.
  178.  *
  179.  ***************************************************************************
  180.  *
  181.  *  Compilation model and measurement (IMPORTANT):
  182.  *
  183.  *  This C version of Dhrystone consists of three files:
  184.  *  - dhry_global.h (this file, containing global definitions and comments)
  185.  *  - dhry_pack_1.c (containing the code corresponding to Ada package Pack_1)
  186.  *  - dhry_pack_2.c (containing the code corresponding to Ada package Pack_2)
  187.  *
  188.  *  The following "ground rules" apply for measurements:
  189.  *  - Separate compilation
  190.  *  - No procedure merging
  191.  *  - Otherwise, compiler optimizations are allowed but should be indicated
  192.  *  - Default results are those without register declarations
  193.  *  See the companion paper "Rationale for Dhrystone Version 2" for a more
  194.  *  detailed discussion of these ground rules.
  195.  *
  196.  *  For 16-Bit processors (e.g. 80186, 80286), times for all compilation
  197.  *  models ("small", "medium", "large" etc.) should be given if possible,
  198.  *  together with a definition of these models for the compiler system used.
  199.  *
  200.  **************************************************************************
  201.  *
  202.  *  Dhrystone (C version) statistics:
  203.  *
  204.  *  [Comment from the first distribution, updated for version 2.
  205.  *   Note that because of language differences, the numbers are slightly
  206.  *   different from the Ada version.]
  207.  *
  208.  *  The following program contains statements of a high level programming
  209.  *  language (here: C) in a distribution considered representative:           
  210.  *
  211.  *    assignments                  52 (51.0 %)
  212.  *    control statements           33 (32.4 %)
  213.  *    procedure, function calls    17 (16.7 %)
  214.  *
  215.  *  103 statements are dynamically executed. The program is balanced with
  216.  *  respect to the three aspects:                                             
  217.  *
  218.  *    - statement type
  219.  *    - operand type
  220.  *    - operand locality
  221.  *         operand global, local, parameter, or constant.                     
  222.  *
  223.  *  The combination of these three aspects is balanced only approximately.    
  224.  *
  225.  *  1. Statement Type:                                                        
  226.  *  -----------------             number
  227.  *
  228.  *     V1 = V2                     9
  229.  *       (incl. V1 = F(..)
  230.  *     V = Constant               12
  231.  *     Assignment,                 7
  232.  *       with array element
  233.  *     Assignment,                 6
  234.  *       with record component
  235.  *                                --
  236.  *                                34       34
  237.  *
  238.  *     X = Y +|-|"&&"|"|" Z        5
  239.  *     X = Y +|-|"==" Constant     6
  240.  *     X = X +|- 1                 3
  241.  *     X = Y *|/ Z                 2
  242.  *     X = Expression,             1
  243.  *           two operators
  244.  *     X = Expression,             1
  245.  *           three operators
  246.  *                                --
  247.  *                                18       18
  248.  *
  249.  *     if ....                    14
  250.  *       with "else"      7
  251.  *       without "else"   7
  252.  *           executed        3
  253.  *           not executed    4
  254.  *     for ...                     7  |  counted every time
  255.  *     while ...                   4  |  the loop condition
  256.  *     do ... while                1  |  is evaluated
  257.  *     switch ...                  1
  258.  *     break                       1
  259.  *     declaration with            1
  260.  *       initialization
  261.  *                                --
  262.  *                                34       34
  263.  *
  264.  *     P (...)  procedure call    11
  265.  *       user procedure      10
  266.  *       library procedure    1
  267.  *     X = F (...)
  268.  *             function  call      6
  269.  *       user function        5                                         
  270.  *       library function     1                                               
  271.  *                                --                                          
  272.  *                                17       17
  273.  *                                        ---
  274.  *                                        103
  275.  *
  276.  *    The average number of parameters in procedure or function calls
  277.  *    is 1.82 (not counting the function values as implicit parameters).
  278.  *
  279.  *
  280.  *  2. Operators
  281.  *  ------------
  282.  *                          number    approximate
  283.  *                                    percentage
  284.  *
  285.  *    Arithmetic             32          50.8                                 
  286.  *
  287.  *       +                     21          33.3                              
  288.  *       -                      7          11.1                              
  289.  *       *                      3           4.8
  290.  *       / (int div)            1           1.6
  291.  *
  292.  *    Comparison             27           42.8
  293.  *
  294.  *       ==                     9           14.3
  295.  *       /=                     4            6.3
  296.  *       >                      1            1.6
  297.  *       <                      3            4.8
  298.  *       >=                     1            1.6
  299.  *       <=                     9           14.3
  300.  *
  301.  *    Logic                   4            6.3
  302.  *
  303.  *       && (AND-THEN)          1            1.6
  304.  *       |  (OR)                1            1.6
  305.  *       !  (NOT)               2            3.2
  306.  * 
  307.  *                           --          -----
  308.  *                           63          100.1
  309.  *
  310.  *
  311.  *  3. Operand Type (counted once per operand reference):
  312.  *  ---------------
  313.  *                          number    approximate
  314.  *                                    percentage
  315.  *
  316.  *     Integer               175        72.3 %
  317.  *     Character              45        18.6 %
  318.  *     Pointer                12         5.0 %
  319.  *     String30                6         2.5 %
  320.  *     Array                   2         0.8 %
  321.  *     Record                  2         0.8 %
  322.  *                           ---       -------
  323.  *                           242       100.0 %
  324.  *
  325.  *  When there is an access path leading to the final operand (e.g. a record
  326.  *  component), only the final data type on the access path is counted.       
  327.  *
  328.  *
  329.  *  4. Operand Locality:                                                      
  330.  *  -------------------
  331.  *                                number    approximate
  332.  *                                          percentage
  333.  *
  334.  *     local variable              114        47.1 %
  335.  *     global variable              22         9.1 %
  336.  *     parameter                    45        18.6 %
  337.  *        value                        23         9.5 %
  338.  *        reference                    22         9.1 %
  339.  *     function result               6         2.5 %
  340.  *     constant                     55        22.7 %
  341.  *                                 ---       -------
  342.  *                                 242       100.0 %
  343.  *
  344.  *
  345.  *  The program does not compute anything meaningful, but it is syntactically
  346.  *  and semantically correct. All variables have a value assigned to them
  347.  *  before they are used as a source operand.
  348.  *
  349.  *  There has been no explicit effort to account for the effects of a
  350.  *  cache, or to balance the use of long or short displacements for code or
  351.  *  data.
  352.  *
  353.  ***************************************************************************
  354.  */
  355. /* CONSTANTS */
  356. #define INT_GLOB    5
  357. #define BOOL_GLOB    1
  358. #define ARR_1_SZ    8
  359. #define ARR_1_VAL    7
  360. #define STR_0_PAR_REF     "DHRYSTONE PROGRAM, SOME STRING"
  361. #define STR_1_PAR_REF    "DHRYSTONE PROGRAM, 1'ST STRING"
  362. #define STR_2_PAR_REF    "DHRYSTONE PROGRAM, 2'ND STRING"
  363.  
  364.  
  365. /* Compiler and system dependent definitions: */
  366.  
  367. #ifndef TIME
  368. #ifndef TIMES
  369. #define TIMES
  370. #endif
  371. #endif
  372.                 /* Use "times" function for measurement */
  373.                 /* unless explicitly defined otherwise  */
  374. #ifndef HZ
  375. #define HZ      60
  376. #endif
  377.                 /* Use HZ = 60 for "times" function     */
  378.                 /* unless explicitly defined otherwise  */
  379.  
  380. #ifdef TIMES
  381. #include <sys/types.h>
  382. #include <sys/times.h>
  383.                 /* for "times" */
  384. #endif
  385.  
  386. #define Mic_secs_Per_Second     1000000.0
  387.                 /* UNIX C returns process times in seconds/HZ */
  388.  
  389. #ifdef  NOSTRUCTASSIGN
  390. #define structassign(d, s)      memcpy(&(d), &(s), sizeof(d))
  391. #else
  392. #define structassign(d, s)      d = s
  393. #endif
  394.  
  395. #ifdef  NOENUM
  396. #define Ident_1 0
  397. #define Ident_2 1
  398. #define Ident_3 2
  399. #define Ident_4 3
  400. #define Ident_5 4
  401.   typedef int   Enumeration;
  402. #else
  403.   typedef       enum    {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
  404.                 Enumeration;
  405. #endif
  406.         /* for boolean and enumeration types in Ada, Pascal */
  407.  
  408. /* General definitions: */
  409.  
  410. #include <stdio.h>
  411.                 /* for strcpy, strcmp */
  412.  
  413. #define Null 0 
  414.                 /* Value of a Null pointer */
  415. #define true  1
  416. #define false 0
  417.  
  418. typedef int     One_Thirty;
  419. typedef int     One_Fifty;
  420. typedef char    Capital_Letter;
  421. typedef int     Boolean;
  422. typedef char    Str_30 [31];
  423. typedef int     Arr_1_Dim [50];
  424. typedef int     Arr_2_Dim [50] [50];
  425.  
  426. typedef struct record 
  427.     {
  428.     struct record *Ptr_Comp;
  429.     Enumeration    Discr;
  430.     union {
  431.           struct {
  432.                   Enumeration Enum_Comp;
  433.                   int         Int_Comp;
  434.                   char        Str_Comp [31];
  435.                   } var_1;
  436.           struct {
  437.                   Enumeration E_Comp_2;
  438.                   char        Str_2_Comp [31];
  439.                   } var_2;
  440.           struct {
  441.                   char        Ch_1_Comp;
  442.                   char        Ch_2_Comp;
  443.                   } var_3;
  444.           } variant;
  445.       } Rec_Type, *Rec_Pointer;
  446.  
  447.  
  448.