(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.misc-tests/
dhry.c
       1  /*
       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 "dhry.h"
      19  
      20  /* Global Variables: */
      21  
      22  Rec_Pointer     Ptr_Glob,
      23                  Next_Ptr_Glob;
      24  int             Int_Glob;
      25  Boolean         Bool_Glob;
      26  char            Ch_1_Glob,
      27                  Ch_2_Glob;
      28  int             Arr_1_Glob [50];
      29  int             Arr_2_Glob [50] [50];
      30  
      31  extern char     *malloc ();
      32  Enumeration     Func_1 ();
      33    /* forward declaration necessary since Enumeration may not simply be int */
      34  
      35  #ifndef REG
      36          Boolean Reg = false;
      37  #define REG
      38          /* REG becomes defined as empty */
      39          /* i.e. no register variables   */
      40  #else
      41          Boolean Reg = true;
      42  #endif
      43  
      44  /* variables for time measurement: */
      45  
      46  /*
      47  #ifdef TIMES
      48  struct tms      time_info;
      49  extern  int     times ();
      50  #endif
      51  */           
      52  /*
      53  #ifdef TIME
      54  extern long     time();
      55  #endif
      56  */
      57  #define Too_Small_Time 2
      58                  /* Measurements should last at least 2 seconds */
      59  
      60  long            Begin_Time,
      61                  End_Time,
      62                  User_Time;
      63  float           Microseconds,
      64                  Dhrystones_Per_Second;
      65  
      66  /* end of variables for time measurement */
      67  
      68  
      69  main ()
      70  /*****/
      71  
      72    /* main program, corresponds to procedures        */
      73    /* Main and Proc_0 in the Ada version             */
      74  {
      75          One_Fifty       Int_1_Loc;
      76    REG   One_Fifty       Int_2_Loc;
      77          One_Fifty       Int_3_Loc;
      78    REG   char            Ch_Index;
      79          Enumeration     Enum_Loc;
      80          Str_30          Str_1_Loc;
      81          Str_30          Str_2_Loc;
      82    REG   int             Run_Index;
      83    REG   int             Number_Of_Runs;
      84  
      85    /* Initializations */
      86  
      87    Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
      88    Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
      89  
      90    Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
      91    Ptr_Glob->Discr                       = Ident_1;
      92    Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
      93    Ptr_Glob->variant.var_1.Int_Comp      = 40;
      94    strcpy (Ptr_Glob->variant.var_1.Str_Comp, 
      95            "DHRYSTONE PROGRAM, SOME STRING");
      96    strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
      97  
      98    Arr_2_Glob [8][7] = 10;
      99          /* Was missing in published program. Without this statement,    */
     100          /* Arr_2_Glob [8][7] would have an undefined value.             */
     101          /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
     102          /* overflow may occur for this array element.                   */
     103  
     104  /*
     105    printf ("\n");
     106    printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
     107    printf ("\n");
     108  */
     109    if (Reg)
     110    {
     111  /*
     112      printf ("Program compiled with 'register' attribute\n");
     113      printf ("\n");
     114  */
     115    }
     116    else
     117    {
     118  /*
     119      printf ("Program compiled without 'register' attribute\n");
     120      printf ("\n");
     121  */
     122    }
     123  /*
     124    printf ("Please give the number of runs through the benchmark: ");
     125  */
     126    {
     127      int n;
     128  /*
     129      scanf ("%d", &n);
     130  */
     131      Number_Of_Runs = n=1000;
     132    }
     133  /*
     134    printf ("\n");
     135  
     136    printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
     137  */
     138  
     139    /***************/
     140    /* Start timer */
     141    /***************/
     142  
     143  /* 
     144  #ifdef TIMES
     145    times (&time_info);
     146    Begin_Time = (long) time_info.tms_utime;
     147  #endif
     148  #ifdef TIME
     149    Begin_Time = time ( (long *) 0);
     150  #endif
     151  */
     152  
     153    for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
     154    {
     155  
     156      Proc_5();
     157      Proc_4();
     158        /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
     159      Int_1_Loc = 2;
     160      Int_2_Loc = 3;
     161      strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
     162      Enum_Loc = Ident_2;
     163      Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
     164        /* Bool_Glob == 1 */
     165      while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
     166      {
     167        Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
     168          /* Int_3_Loc == 7 */
     169        Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
     170          /* Int_3_Loc == 7 */
     171        Int_1_Loc += 1;
     172      } /* while */
     173        /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
     174      Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
     175        /* Int_Glob == 5 */
     176      Proc_1 (Ptr_Glob);
     177      for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
     178                               /* loop body executed twice */
     179      {
     180        if (Enum_Loc == Func_1 (Ch_Index, 'C'))
     181            /* then, not executed */
     182          {
     183          Proc_6 (Ident_1, &Enum_Loc);
     184          strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
     185          Int_2_Loc = Run_Index;
     186          Int_Glob = Run_Index;
     187          }
     188      }
     189        /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
     190      Int_2_Loc = Int_2_Loc * Int_1_Loc;
     191      Int_1_Loc = Int_2_Loc / Int_3_Loc;
     192      Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
     193        /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
     194      Proc_2 (&Int_1_Loc);
     195        /* Int_1_Loc == 5 */
     196  
     197    } /* loop "for Run_Index" */
     198  
     199    /**************/
     200    /* Stop timer */
     201    /**************/
     202   
     203  /* 
     204  #ifdef TIMES
     205    times (&time_info);
     206    End_Time = (long) time_info.tms_utime;
     207  #endif
     208  #ifdef TIME
     209    End_Time = time ( (long *) 0);
     210  #endif
     211  */
     212  
     213  /*
     214    printf ("Execution ends\n");
     215    printf ("\n");
     216    printf ("Final values of the variables used in the benchmark:\n");
     217    printf ("\n");
     218    printf ("Int_Glob:            %d\n", Int_Glob);
     219    printf ("        should be:   %d\n", 5);
     220    printf ("Bool_Glob:           %d\n", Bool_Glob);
     221    printf ("        should be:   %d\n", 1);
     222    printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
     223    printf ("        should be:   %c\n", 'A');
     224    printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
     225    printf ("        should be:   %c\n", 'B');
     226    printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
     227    printf ("        should be:   %d\n", 7);
     228    printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
     229    printf ("        should be:   Number_Of_Runs + 10\n");
     230    printf ("Ptr_Glob->\n");
     231    printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
     232    printf ("        should be:   (implementation-dependent)\n");
     233    printf ("  Discr:             %d\n", Ptr_Glob->Discr);
     234    printf ("        should be:   %d\n", 0);
     235    printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
     236    printf ("        should be:   %d\n", 2);
     237    printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
     238    printf ("        should be:   %d\n", 17);
     239    printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
     240    printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
     241    printf ("Next_Ptr_Glob->\n");
     242    printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
     243    printf ("        should be:   (implementation-dependent), same as above\n");
     244    printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
     245    printf ("        should be:   %d\n", 0);
     246    printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
     247    printf ("        should be:   %d\n", 1);
     248    printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
     249    printf ("        should be:   %d\n", 18);
     250    printf ("  Str_Comp:          %s\n",
     251                                  Next_Ptr_Glob->variant.var_1.Str_Comp);
     252    printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
     253    printf ("Int_1_Loc:           %d\n", Int_1_Loc);
     254    printf ("        should be:   %d\n", 5);
     255    printf ("Int_2_Loc:           %d\n", Int_2_Loc);
     256    printf ("        should be:   %d\n", 13);
     257    printf ("Int_3_Loc:           %d\n", Int_3_Loc);
     258    printf ("        should be:   %d\n", 7);
     259    printf ("Enum_Loc:            %d\n", Enum_Loc);
     260    printf ("        should be:   %d\n", 1);
     261    printf ("Str_1_Loc:           %s\n", Str_1_Loc);
     262    printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
     263    printf ("Str_2_Loc:           %s\n", Str_2_Loc);
     264    printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
     265    printf ("\n");
     266  */
     267  
     268    User_Time = End_Time - Begin_Time;
     269  
     270    if (User_Time < Too_Small_Time)
     271    {
     272  /*
     273      printf ("Measured time too small to obtain meaningful results\n");
     274      printf ("Please increase number of runs\n");
     275      printf ("\n");
     276  */
     277    }
     278    else
     279    {
     280  #ifdef TIME
     281  /*
     282      Microseconds = (float) User_Time * Mic_secs_Per_Second 
     283                          / (float) Number_Of_Runs;
     284      Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
     285  */
     286  #else
     287  /*
     288      Microseconds = (float) User_Time * Mic_secs_Per_Second 
     289                          / ((float) HZ * ((float) Number_Of_Runs));
     290      Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
     291                          / (float) User_Time;
     292  */
     293  #endif
     294  /*
     295      printf ("Microseconds for one run through Dhrystone: ");
     296      printf ("%6.1f \n", Microseconds);
     297      printf ("Dhrystones per Second:                      ");
     298      printf ("%6.1f \n", Dhrystones_Per_Second);
     299      printf ("\n");
     300  */
     301    }
     302  
     303    exit (0);
     304  }
     305  
     306  
     307  Proc_1 (Ptr_Val_Par)
     308  /******************/
     309  
     310  REG Rec_Pointer Ptr_Val_Par;
     311      /* executed once */
     312  {
     313    REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;  
     314                                          /* == Ptr_Glob_Next */
     315    /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
     316    /* corresponds to "rename" in Ada, "with" in Pascal           */
     317    
     318    structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); 
     319    Ptr_Val_Par->variant.var_1.Int_Comp = 5;
     320    Next_Record->variant.var_1.Int_Comp 
     321          = Ptr_Val_Par->variant.var_1.Int_Comp;
     322    Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
     323    Proc_3 (&Next_Record->Ptr_Comp);
     324      /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp 
     325                          == Ptr_Glob->Ptr_Comp */
     326    if (Next_Record->Discr == Ident_1)
     327      /* then, executed */
     328    {
     329      Next_Record->variant.var_1.Int_Comp = 6;
     330      Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, 
     331             &Next_Record->variant.var_1.Enum_Comp);
     332      Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
     333      Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, 
     334             &Next_Record->variant.var_1.Int_Comp);
     335    }
     336    else /* not executed */
     337      structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
     338  } /* Proc_1 */
     339  
     340  
     341  Proc_2 (Int_Par_Ref)
     342  /******************/
     343      /* executed once */
     344      /* *Int_Par_Ref == 1, becomes 4 */
     345  
     346  One_Fifty   *Int_Par_Ref;
     347  {
     348    One_Fifty  Int_Loc;  
     349    Enumeration   Enum_Loc;
     350  
     351    Int_Loc = *Int_Par_Ref + 10;
     352    do /* executed once */
     353      if (Ch_1_Glob == 'A')
     354        /* then, executed */
     355      {
     356        Int_Loc -= 1;
     357        *Int_Par_Ref = Int_Loc - Int_Glob;
     358        Enum_Loc = Ident_1;
     359      } /* if */
     360    while (Enum_Loc != Ident_1); /* true */
     361  } /* Proc_2 */
     362  
     363  
     364  Proc_3 (Ptr_Ref_Par)
     365  /******************/
     366      /* executed once */
     367      /* Ptr_Ref_Par becomes Ptr_Glob */
     368  
     369  Rec_Pointer *Ptr_Ref_Par;
     370  
     371  {
     372    if (Ptr_Glob != Null)
     373      /* then, executed */
     374      *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
     375    Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
     376  } /* Proc_3 */
     377  
     378  
     379  Proc_4 () /* without parameters */
     380  /*******/
     381      /* executed once */
     382  {
     383    Boolean Bool_Loc;
     384  
     385    Bool_Loc = Ch_1_Glob == 'A';
     386    Bool_Glob = Bool_Loc | Bool_Glob;
     387    Ch_2_Glob = 'B';
     388  } /* Proc_4 */
     389  
     390  
     391  Proc_5 () /* without parameters */
     392  /*******/
     393      /* executed once */
     394  {
     395    Ch_1_Glob = 'A';
     396    Bool_Glob = false;
     397  } /* Proc_5 */
     398  
     399  
     400          /* Procedure for the assignment of structures,          */
     401          /* if the C compiler doesn't support this feature       */
     402  #ifdef  NOSTRUCTASSIGN
     403  memcpy (d, s, l)
     404  register char   *d;
     405  register char   *s;
     406  register int    l;
     407  {
     408          while (l--) *d++ = *s++;
     409  }
     410  #endif
     411  
     412  
     413  /*
     414   ****************************************************************************
     415   *
     416   *                   "DHRYSTONE" Benchmark Program
     417   *                   -----------------------------
     418   *                                                                            
     419   *  Version:    C, Version 2.1
     420   *                                                                            
     421   *  File:       dhry_2.c (part 3 of 3)
     422   *
     423   *  Date:       May 25, 1988
     424   *
     425   *  Author:     Reinhold P. Weicker
     426   *
     427   ****************************************************************************
     428   */
     429  
     430  #ifndef REG
     431  #define REG
     432          /* REG becomes defined as empty */
     433          /* i.e. no register variables   */
     434  #endif
     435  
     436  extern  int     Int_Glob;
     437  extern  char    Ch_1_Glob;
     438  
     439  
     440  Proc_6 (Enum_Val_Par, Enum_Ref_Par)
     441  /*********************************/
     442      /* executed once */
     443      /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
     444  
     445  Enumeration  Enum_Val_Par;
     446  Enumeration *Enum_Ref_Par;
     447  {
     448    *Enum_Ref_Par = Enum_Val_Par;
     449    if (! Func_3 (Enum_Val_Par))
     450      /* then, not executed */
     451      *Enum_Ref_Par = Ident_4;
     452    switch (Enum_Val_Par)
     453    {
     454      case Ident_1: 
     455        *Enum_Ref_Par = Ident_1;
     456        break;
     457      case Ident_2: 
     458        if (Int_Glob > 100)
     459          /* then */
     460        *Enum_Ref_Par = Ident_1;
     461        else *Enum_Ref_Par = Ident_4;
     462        break;
     463      case Ident_3: /* executed */
     464        *Enum_Ref_Par = Ident_2;
     465        break;
     466      case Ident_4: break;
     467      case Ident_5: 
     468        *Enum_Ref_Par = Ident_3;
     469        break;
     470    } /* switch */
     471  } /* Proc_6 */
     472  
     473  
     474  Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref)
     475  /**********************************************/
     476      /* executed three times                                      */ 
     477      /* first call:      Int_1_Par_Val == 2, Int_2_Par_Val == 3,  */
     478      /*                  Int_Par_Ref becomes 7                    */
     479      /* second call:     Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
     480      /*                  Int_Par_Ref becomes 17                   */
     481      /* third call:      Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
     482      /*                  Int_Par_Ref becomes 18                   */
     483  One_Fifty       Int_1_Par_Val;
     484  One_Fifty       Int_2_Par_Val;
     485  One_Fifty      *Int_Par_Ref;
     486  {
     487    One_Fifty Int_Loc;
     488  
     489    Int_Loc = Int_1_Par_Val + 2;
     490    *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
     491  } /* Proc_7 */
     492  
     493  
     494  Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val)
     495  /*********************************************************************/
     496      /* executed once      */
     497      /* Int_Par_Val_1 == 3 */
     498      /* Int_Par_Val_2 == 7 */
     499  Arr_1_Dim       Arr_1_Par_Ref;
     500  Arr_2_Dim       Arr_2_Par_Ref;
     501  int             Int_1_Par_Val;
     502  int             Int_2_Par_Val;
     503  {
     504    REG One_Fifty Int_Index;
     505    REG One_Fifty Int_Loc;
     506  
     507    Int_Loc = Int_1_Par_Val + 5;
     508    Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
     509    Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
     510    Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
     511    for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
     512      Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
     513    Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
     514    Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
     515    Int_Glob = 5;
     516  } /* Proc_8 */
     517  
     518  
     519  Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val)
     520  /*************************************************/
     521      /* executed three times                                         */
     522      /* first call:      Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R'    */
     523      /* second call:     Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C'    */
     524      /* third call:      Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C'    */
     525  
     526  Capital_Letter   Ch_1_Par_Val;
     527  Capital_Letter   Ch_2_Par_Val;
     528  {
     529    Capital_Letter        Ch_1_Loc;
     530    Capital_Letter        Ch_2_Loc;
     531  
     532    Ch_1_Loc = Ch_1_Par_Val;
     533    Ch_2_Loc = Ch_1_Loc;
     534    if (Ch_2_Loc != Ch_2_Par_Val)
     535      /* then, executed */
     536      return (Ident_1);
     537    else  /* not executed */
     538    {
     539      Ch_1_Glob = Ch_1_Loc;
     540      return (Ident_2);
     541     }
     542  } /* Func_1 */
     543  
     544  
     545  Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref)
     546  /*************************************************/
     547      /* executed once */
     548      /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
     549      /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
     550  
     551  Str_30  Str_1_Par_Ref;
     552  Str_30  Str_2_Par_Ref;
     553  {
     554    REG One_Thirty        Int_Loc;
     555        Capital_Letter    Ch_Loc;
     556  
     557    Int_Loc = 2;
     558    while (Int_Loc <= 2) /* loop body executed once */
     559      if (Func_1 (Str_1_Par_Ref[Int_Loc],
     560                  Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
     561        /* then, executed */
     562      {
     563        Ch_Loc = 'A';
     564        Int_Loc += 1;
     565      } /* if, while */
     566    if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
     567      /* then, not executed */
     568      Int_Loc = 7;
     569    if (Ch_Loc == 'R')
     570      /* then, not executed */
     571      return (true);
     572    else /* executed */
     573    {
     574      if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
     575        /* then, not executed */
     576      {
     577        Int_Loc += 7;
     578        Int_Glob = Int_Loc;
     579        return (true);
     580      }
     581      else /* executed */
     582        return (false);
     583    } /* if Ch_Loc */
     584  } /* Func_2 */
     585  
     586  
     587  Boolean Func_3 (Enum_Par_Val)
     588  /***************************/
     589      /* executed once        */
     590      /* Enum_Par_Val == Ident_3 */
     591  Enumeration Enum_Par_Val;
     592  {
     593    Enumeration Enum_Loc;
     594  
     595    Enum_Loc = Enum_Par_Val;
     596    if (Enum_Loc == Ident_3)
     597      /* then, executed */
     598      return (true);
     599    else /* not executed */
     600      return (false);
     601  } /* Func_3 */
     602