home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / 9 < prev    next >
Encoding:
Text File  |  1992-04-14  |  12.5 KB  |  415 lines

  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 17, 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. #ifdef TIMES
  47. struct tms      time_info;
  48. extern  int     times ();
  49.                 /* see library function "times" */
  50. #define Too_Small_Time (2*HZ)
  51.                 /* Measurements should last at least about 2 seconds */
  52. #endif
  53. #ifdef TIME
  54. extern long     time();
  55.                 /* see library function "time"  */
  56. #define Too_Small_Time 2
  57.                 /* Measurements should last at least 2 seconds */
  58. #endif
  59. #ifdef MSC_CLOCK
  60. extern clock_t    clock();
  61. #define Too_Small_Time (2*HZ)
  62. #endif
  63.  
  64. long            Begin_Time,
  65.                 End_Time,
  66.                 User_Time;
  67. float           Microseconds,
  68.                 Dhrystones_Per_Second;
  69.  
  70. /* end of variables for time measurement */
  71.  
  72.  
  73. main ()
  74. /*****/
  75.  
  76.   /* main program, corresponds to procedures        */
  77.   /* Main and Proc_0 in the Ada version             */
  78. {
  79.         One_Fifty       Int_1_Loc;
  80.   REG   One_Fifty       Int_2_Loc;
  81.         One_Fifty       Int_3_Loc;
  82.   REG   char            Ch_Index;
  83.         Enumeration     Enum_Loc;
  84.         Str_30          Str_1_Loc;
  85.         Str_30          Str_2_Loc;
  86.   REG   int             Run_Index;
  87.   REG   int             Number_Of_Runs;
  88.  
  89.   /* Initializations */
  90.  
  91.   Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  92.   Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  93.  
  94.   Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
  95.   Ptr_Glob->Discr                       = Ident_1;
  96.   Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
  97.   Ptr_Glob->variant.var_1.Int_Comp      = 40;
  98.   strcpy (Ptr_Glob->variant.var_1.Str_Comp, 
  99.           "DHRYSTONE PROGRAM, SOME STRING");
  100.   strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  101.  
  102.   Arr_2_Glob [8][7] = 10;
  103.         /* Was missing in published program. Without this statement,    */
  104.         /* Arr_2_Glob [8][7] would have an undefined value.             */
  105.         /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
  106.         /* overflow may occur for this array element.                   */
  107.  
  108.   printf ("\n");
  109.   printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
  110.   printf ("\n");
  111.   if (Reg)
  112.   {
  113.     printf ("Program compiled with 'register' attribute\n");
  114.     printf ("\n");
  115.   }
  116.   else
  117.   {
  118.     printf ("Program compiled without 'register' attribute\n");
  119.     printf ("\n");
  120.   }
  121. /*
  122.   printf ("Please give the number of runs through the benchmark: ");
  123.   {
  124.     int n;
  125.     scanf ("%d", &n);
  126.     Number_Of_Runs = n;
  127.   }
  128.   printf ("\n");
  129. */
  130. #ifndef LOOPS
  131. #define LOOPS 2500000
  132. #endif
  133.   Number_Of_Runs = LOOPS;
  134.  
  135.   printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
  136.  
  137.   /***************/
  138.   /* Start timer */
  139.   /***************/
  140.  
  141. #ifdef TIMES
  142.   times (&time_info);
  143.   Begin_Time = (long) time_info.tms_utime;
  144. #endif
  145. #ifdef TIME
  146.   Begin_Time = time ( (long *) 0);
  147. #endif
  148. #ifdef MSC_CLOCK
  149.   Begin_Time = clock();
  150. #endif
  151.  
  152.   for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
  153.   {
  154.  
  155.     Proc_5();
  156.     Proc_4();
  157.       /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  158.     Int_1_Loc = 2;
  159.     Int_2_Loc = 3;
  160.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  161.     Enum_Loc = Ident_2;
  162.     Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  163.       /* Bool_Glob == 1 */
  164.     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
  165.     {
  166.       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  167.         /* Int_3_Loc == 7 */
  168.       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  169.         /* Int_3_Loc == 7 */
  170.       Int_1_Loc += 1;
  171.     } /* while */
  172.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  173.     Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  174.       /* Int_Glob == 5 */
  175.     Proc_1 (Ptr_Glob);
  176.     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  177.                              /* loop body executed twice */
  178.     {
  179.       if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  180.           /* then, not executed */
  181.         {
  182.         Proc_6 (Ident_1, &Enum_Loc);
  183.         strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  184.         Int_2_Loc = Run_Index;
  185.         Int_Glob = Run_Index;
  186.         }
  187.     }
  188.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  189.     Int_2_Loc = Int_2_Loc * Int_1_Loc;
  190.     Int_1_Loc = Int_2_Loc / Int_3_Loc;
  191.     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  192.       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  193.     Proc_2 (&Int_1_Loc);
  194.       /* Int_1_Loc == 5 */
  195.  
  196.   } /* loop "for Run_Index" */
  197.  
  198.   /**************/
  199.   /* Stop timer */
  200.   /**************/
  201.   
  202. #ifdef TIMES
  203.   times (&time_info);
  204.   End_Time = (long) time_info.tms_utime;
  205. #endif
  206. #ifdef TIME
  207.   End_Time = time ( (long *) 0);
  208. #endif
  209. #ifdef MSC_CLOCK
  210.   End_Time = clock();
  211. #endif
  212.  
  213.   printf ("Execution ends\n");
  214.   printf ("\n");
  215.   printf ("Final values of the variables used in the benchmark:\n");
  216.   printf ("\n");
  217.   printf ("Int_Glob:            %d\n", Int_Glob);
  218.   printf ("        should be:   %d\n", 5);
  219.   printf ("Bool_Glob:           %d\n", Bool_Glob);
  220.   printf ("        should be:   %d\n", 1);
  221.   printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
  222.   printf ("        should be:   %c\n", 'A');
  223.   printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
  224.   printf ("        should be:   %c\n", 'B');
  225.   printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
  226.   printf ("        should be:   %d\n", 7);
  227.   printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
  228.   printf ("        should be:   Number_Of_Runs + 10\n");
  229.   printf ("Ptr_Glob->\n");
  230.   printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
  231.   printf ("        should be:   (implementation-dependent)\n");
  232.   printf ("  Discr:             %d\n", Ptr_Glob->Discr);
  233.   printf ("        should be:   %d\n", 0);
  234.   printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
  235.   printf ("        should be:   %d\n", 2);
  236.   printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
  237.   printf ("        should be:   %d\n", 17);
  238.   printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
  239.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  240.   printf ("Next_Ptr_Glob->\n");
  241.   printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
  242.   printf ("        should be:   (implementation-dependent), same as above\n");
  243.   printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
  244.   printf ("        should be:   %d\n", 0);
  245.   printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  246.   printf ("        should be:   %d\n", 1);
  247.   printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
  248.   printf ("        should be:   %d\n", 18);
  249.   printf ("  Str_Comp:          %s\n",
  250.                                 Next_Ptr_Glob->variant.var_1.Str_Comp);
  251.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  252.   printf ("Int_1_Loc:           %d\n", Int_1_Loc);
  253.   printf ("        should be:   %d\n", 5);
  254.   printf ("Int_2_Loc:           %d\n", Int_2_Loc);
  255.   printf ("        should be:   %d\n", 13);
  256.   printf ("Int_3_Loc:           %d\n", Int_3_Loc);
  257.   printf ("        should be:   %d\n", 7);
  258.   printf ("Enum_Loc:            %d\n", Enum_Loc);
  259.   printf ("        should be:   %d\n", 1);
  260.   printf ("Str_1_Loc:           %s\n", Str_1_Loc);
  261.   printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
  262.   printf ("Str_2_Loc:           %s\n", Str_2_Loc);
  263.   printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
  264.   printf ("\n");
  265.  
  266.   User_Time = End_Time - Begin_Time;
  267.  
  268.   if (User_Time < Too_Small_Time)
  269.   {
  270.     printf ("Measured time too small to obtain meaningful results\n");
  271.     printf ("Please increase number of runs\n");
  272.     printf ("\n");
  273.   }
  274.   else
  275.   {
  276. #ifdef TIME
  277.  
  278. #ifdef SIMULATOR
  279.     /* time.c returns the simulator clock.  this need to be scaled by
  280.     /* the clock frequency to get the actual number of seconds */
  281.     Microseconds = (float) User_Time * Mic_secs_Per_Second / (float) MHZ
  282.                         / (float) Number_Of_Runs;
  283.     Dhrystones_Per_Second = (float) Number_Of_Runs * (float) MHZ
  284.             / (float) User_Time;
  285.  
  286. #else
  287.     Microseconds = (float) User_Time * Mic_secs_Per_Second 
  288.                         / (float) Number_Of_Runs;
  289.     Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
  290. #endif
  291.  
  292. #else
  293.     Microseconds = (float) User_Time * Mic_secs_Per_Second 
  294.                         / ((float) HZ * ((float) Number_Of_Runs));
  295.     Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
  296.                         / (float) User_Time;
  297. #endif
  298.     printf ("Microseconds for one run through Dhrystone: ");
  299.     printf ("%6.1f \n", Microseconds);
  300.     printf ("Dhrystones per Second:                      ");
  301.     printf ("%6.1f \n", Dhrystones_Per_Second);
  302.     printf ("\n");
  303.   }
  304.   
  305.    exit(0);        /* wyu */
  306. }
  307.  
  308.  
  309. Proc_1 (Ptr_Val_Par)
  310. /******************/
  311.  
  312. REG Rec_Pointer Ptr_Val_Par;
  313.     /* executed once */
  314. {
  315.   REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;  
  316.                                         /* == Ptr_Glob_Next */
  317.   /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
  318.   /* corresponds to "rename" in Ada, "with" in Pascal           */
  319.   
  320.   structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); 
  321.   Ptr_Val_Par->variant.var_1.Int_Comp = 5;
  322.   Next_Record->variant.var_1.Int_Comp 
  323.         = Ptr_Val_Par->variant.var_1.Int_Comp;
  324.   Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
  325.   Proc_3 (&Next_Record->Ptr_Comp);
  326.     /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp 
  327.                         == Ptr_Glob->Ptr_Comp */
  328.   if (Next_Record->Discr == Ident_1)
  329.     /* then, executed */
  330.   {
  331.     Next_Record->variant.var_1.Int_Comp = 6;
  332.     Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, 
  333.            &Next_Record->variant.var_1.Enum_Comp);
  334.     Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
  335.     Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, 
  336.            &Next_Record->variant.var_1.Int_Comp);
  337.   }
  338.   else /* not executed */
  339.     structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
  340. } /* Proc_1 */
  341.  
  342.  
  343. Proc_2 (Int_Par_Ref)
  344. /******************/
  345.     /* executed once */
  346.     /* *Int_Par_Ref == 1, becomes 4 */
  347.  
  348. One_Fifty   *Int_Par_Ref;
  349. {
  350.   One_Fifty  Int_Loc;  
  351.   Enumeration   Enum_Loc;
  352.  
  353.   Int_Loc = *Int_Par_Ref + 10;
  354.   do /* executed once */
  355.     if (Ch_1_Glob == 'A')
  356.       /* then, executed */
  357.     {
  358.       Int_Loc -= 1;
  359.       *Int_Par_Ref = Int_Loc - Int_Glob;
  360.       Enum_Loc = Ident_1;
  361.     } /* if */
  362.   while (Enum_Loc != Ident_1); /* true */
  363. } /* Proc_2 */
  364.  
  365.  
  366. Proc_3 (Ptr_Ref_Par)
  367. /******************/
  368.     /* executed once */
  369.     /* Ptr_Ref_Par becomes Ptr_Glob */
  370.  
  371. Rec_Pointer *Ptr_Ref_Par;
  372.  
  373. {
  374.   if (Ptr_Glob != Null)
  375.     /* then, executed */
  376.     *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
  377.   Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
  378. } /* Proc_3 */
  379.  
  380.  
  381. Proc_4 () /* without parameters */
  382. /*******/
  383.     /* executed once */
  384. {
  385.   Boolean Bool_Loc;
  386.  
  387.   Bool_Loc = Ch_1_Glob == 'A';
  388.   Bool_Glob = Bool_Loc | Bool_Glob;
  389.   Ch_2_Glob = 'B';
  390. } /* Proc_4 */
  391.  
  392.  
  393. Proc_5 () /* without parameters */
  394. /*******/
  395.     /* executed once */
  396. {
  397.   Ch_1_Glob = 'A';
  398.   Bool_Glob = false;
  399. } /* Proc_5 */
  400.  
  401.  
  402.         /* Procedure for the assignment of structures,          */
  403.         /* if the C compiler doesn't support this feature       */
  404. #ifdef  NOSTRUCTASSIGN
  405. memcpy (d, s, l)
  406. register char   *d;
  407. register char   *s;
  408. register int    l;
  409. {
  410.         while (l--) *d++ = *s++;
  411. }
  412. #endif
  413.  
  414.  
  415.