home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / a / armsi / !ArmSI / c / dhry_1 next >
Text File  |  1992-11-10  |  12KB  |  413 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 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. #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. #ifndef SILENT
  109.   printf ("\n");
  110.   printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
  111.   printf ("\n");
  112.   if (Reg)
  113.   {
  114.     printf ("Program compiled with 'register' attribute\n");
  115.     printf ("\n");
  116.   }
  117.   else
  118.   {
  119.     printf ("Program compiled without 'register' attribute\n");
  120.     printf ("\n");
  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.   printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
  131. #else
  132.   Number_Of_Runs = NORUNS;
  133. #endif
  134.  
  135.   /***************/
  136.   /* Start timer */
  137.   /***************/
  138.  
  139. #ifdef TIMES
  140.   times (&time_info);
  141.   Begin_Time = (long) time_info.tms_utime;
  142. #endif
  143. #ifdef TIME
  144.   Begin_Time = time ( (long *) 0);
  145. #endif
  146. #ifdef MSC_CLOCK
  147.   Begin_Time = clock();
  148. #endif
  149.  
  150.   for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
  151.   {
  152.  
  153.     Proc_5();
  154.     Proc_4();
  155.       /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  156.     Int_1_Loc = 2;
  157.     Int_2_Loc = 3;
  158.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  159.     Enum_Loc = Ident_2;
  160.     Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  161.       /* Bool_Glob == 1 */
  162.     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
  163.     {
  164.       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  165.         /* Int_3_Loc == 7 */
  166.       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  167.         /* Int_3_Loc == 7 */
  168.       Int_1_Loc += 1;
  169.     } /* while */
  170.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  171.     Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  172.       /* Int_Glob == 5 */
  173.     Proc_1 (Ptr_Glob);
  174.     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  175.                              /* loop body executed twice */
  176.     {
  177.       if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  178.           /* then, not executed */
  179.         {
  180.         Proc_6 (Ident_1, &Enum_Loc);
  181.         strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  182.         Int_2_Loc = Run_Index;
  183.         Int_Glob = Run_Index;
  184.         }
  185.     }
  186.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  187.     Int_2_Loc = Int_2_Loc * Int_1_Loc;
  188.     Int_1_Loc = Int_2_Loc / Int_3_Loc;
  189.     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  190.       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  191.     Proc_2 (&Int_1_Loc);
  192.       /* Int_1_Loc == 5 */
  193.  
  194.   } /* loop "for Run_Index" */
  195.  
  196.   /**************/
  197.   /* Stop timer */
  198.   /**************/
  199.   
  200. #ifdef TIMES
  201.   times (&time_info);
  202.   End_Time = (long) time_info.tms_utime;
  203. #endif
  204. #ifdef TIME
  205.   End_Time = time ( (long *) 0);
  206. #endif
  207. #ifdef MSC_CLOCK
  208.   End_Time = clock();
  209. #endif
  210.  
  211. #ifndef SILENT
  212.   printf ("Execution ends\n");
  213.   printf ("\n");
  214.   printf ("Final values of the variables used in the benchmark:\n");
  215.   printf ("\n");
  216.   printf ("Int_Glob:            %d\n", Int_Glob);
  217.   printf ("        should be:   %d\n", 5);
  218.   printf ("Bool_Glob:           %d\n", Bool_Glob);
  219.   printf ("        should be:   %d\n", 1);
  220.   printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
  221.   printf ("        should be:   %c\n", 'A');
  222.   printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
  223.   printf ("        should be:   %c\n", 'B');
  224.   printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
  225.   printf ("        should be:   %d\n", 7);
  226.   printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
  227.   printf ("        should be:   Number_Of_Runs + 10\n");
  228.   printf ("Ptr_Glob->\n");
  229.   printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
  230.   printf ("        should be:   (implementation-dependent)\n");
  231.   printf ("  Discr:             %d\n", Ptr_Glob->Discr);
  232.   printf ("        should be:   %d\n", 0);
  233.   printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
  234.   printf ("        should be:   %d\n", 2);
  235.   printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
  236.   printf ("        should be:   %d\n", 17);
  237.   printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
  238.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  239.   printf ("Next_Ptr_Glob->\n");
  240.   printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
  241.   printf ("        should be:   (implementation-dependent), same as above\n");
  242.   printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
  243.   printf ("        should be:   %d\n", 0);
  244.   printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  245.   printf ("        should be:   %d\n", 1);
  246.   printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
  247.   printf ("        should be:   %d\n", 18);
  248.   printf ("  Str_Comp:          %s\n",
  249.                                 Next_Ptr_Glob->variant.var_1.Str_Comp);
  250.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  251.   printf ("Int_1_Loc:           %d\n", Int_1_Loc);
  252.   printf ("        should be:   %d\n", 5);
  253.   printf ("Int_2_Loc:           %d\n", Int_2_Loc);
  254.   printf ("        should be:   %d\n", 13);
  255.   printf ("Int_3_Loc:           %d\n", Int_3_Loc);
  256.   printf ("        should be:   %d\n", 7);
  257.   printf ("Enum_Loc:            %d\n", Enum_Loc);
  258.   printf ("        s