Advertisement
Guest User

Untitled

a guest
Oct 25th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 13.60 KB | None | 0 0
  1. void printf1(const char* format, ...);
  2. float second(void);
  3.  
  4. #define TIME
  5. #define REG  register
  6. #include <stdlib.h>
  7. #include <string.h>
  8. /*
  9.  ****************************************************************************
  10.  *
  11.  *                   "DHRYSTONE" Benchmark Program
  12.  *                   -----------------------------
  13.  *                                                                            
  14.  *  Version:    C, Version 2.1
  15.  *                                                                            
  16.  *  File:       dhry_1.c (part 2 of 3)
  17.  *
  18.  *  Date:       May 25, 1988
  19.  *
  20.  *  Author:     Reinhold P. Weicker
  21.  *
  22.  ****************************************************************************
  23.  */
  24.  
  25. #include "dhry.h"
  26.  
  27. /* Global Variables: */
  28.  
  29. Rec_Pointer     Ptr_Glob,
  30.                 Next_Ptr_Glob;
  31. int             Int_Glob;
  32. Boolean         Bool_Glob;
  33. char            Ch_1_Glob,
  34.                 Ch_2_Glob;
  35. int             Arr_1_Glob [50];
  36. int             Arr_2_Glob [50] [50];
  37.  
  38. /* extern char     *malloc (); */
  39. /* Enumeration     Func_1 (); */
  40.   /* forward declaration necessary since Enumeration may not simply be int */
  41.  
  42. #ifndef REG
  43.         Boolean Reg = false;
  44. #define REG
  45.         /* REG becomes defined as empty */
  46.         /* i.e. no register variables   */
  47. #else
  48.         Boolean Reg = true;
  49. #endif
  50.  
  51. /* variables for time measurement: */
  52.  
  53. #ifdef TIMES
  54. struct tms      time_info;
  55. /* extern  int     times (); */
  56.                 /* see library function "times" */
  57. #define Too_Small_Time (2 * HZ)
  58.                 /* Measurements should last at least about 2 seconds */
  59. #endif
  60. #ifdef TIME
  61. /*
  62. extern long     time();
  63. */
  64.                 /* see library function "time"  */
  65. #define Too_Small_Time 2
  66.                 /* Measurements should last at least 2 seconds */
  67. #endif
  68.  
  69. /* long            Begin_Time, */
  70. float           Begin_Time,
  71.                 End_Time,
  72.                 User_Time;
  73. float           Microseconds,
  74.                 Dhrystones_Per_Second;
  75.  
  76. /* end of variables for time measurement */
  77.  
  78. void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
  79. void Proc_2 (One_Fifty   *Int_Par_Ref);
  80. void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
  81. void Proc_4 (void); /* without parameters */
  82. void Proc_5 (void); /* without parameters */
  83. void Proc_6 (Enumeration  Enum_Val_Par, Enumeration *Enum_Ref_Par);
  84. void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref);
  85. void Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val);
  86. Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
  87. Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);
  88. Boolean Func_3 (Enumeration Enum_Par_Val);
  89.  
  90. /* main () */
  91. void main_a(int argc, char *argv[])
  92. /*****/
  93.  
  94.   /* main program, corresponds to procedures        */
  95.   /* Main and Proc_0 in the Ada version             */
  96. {
  97.         One_Fifty       Int_1_Loc;
  98.   REG   One_Fifty       Int_2_Loc;
  99.         One_Fifty       Int_3_Loc;
  100.   REG   char            Ch_Index;
  101.         Enumeration     Enum_Loc;
  102.         Str_30          Str_1_Loc;
  103.         Str_30          Str_2_Loc;
  104.   REG   int             Run_Index;
  105.   REG   int             Number_Of_Runs;
  106.  
  107.   /* Initializations */
  108.  
  109.   Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  110.   Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  111.  
  112.   Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
  113.   Ptr_Glob->Discr                       = Ident_1;
  114.   Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
  115.   Ptr_Glob->variant.var_1.Int_Comp      = 40;
  116.   strcpy (Ptr_Glob->variant.var_1.Str_Comp,
  117.           "DHRYSTONE PROGRAM, SOME STRING");
  118.   strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  119.  
  120.   Arr_2_Glob [8][7] = 10;
  121.         /* Was missing in published program. Without this statement,    */
  122.         /* Arr_2_Glob [8][7] would have an undefined value.             */
  123.         /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
  124.         /* overflow may occur for this array element.                   */
  125.  
  126.   printf1 ("\r\n");
  127.   printf1 ("Dhrystone Benchmark, Version 2.1 (Language: C)\r\n");
  128.   printf1 ("\r\n");
  129.   if (Reg)
  130.   {
  131.     printf1 ("Program compiled with 'register' attribute\r\n");
  132.     printf1 ("\r\n");
  133.   }
  134.   else
  135.   {
  136.     printf1 ("Program compiled without 'register' attribute\r\n");
  137.     printf1 ("\r\n");
  138.   }
  139.   printf1 ("Please give the number of runs through the benchmark: ");
  140.   {
  141.     int n;
  142. /*
  143.     scanf ("%d", &n);
  144. */
  145.     char *str01;
  146.     if (argc == 2) {
  147.         str01 = argv[1];        
  148.     } else {
  149.         str01 = "5000";
  150.     }
  151.  
  152.     n = atoi(str01);
  153.     if (n < 5000) {
  154.         n = 5000;
  155.     };
  156.  
  157.     Number_Of_Runs = n;
  158.   }
  159.   printf1 ("\r\n");
  160.   {
  161.   int  i00001;
  162.   for (i00001 = 0; i00001 < 20; i00001++) {
  163.  
  164.   printf1 ("Execution starts, %d runs through Dhrystone\r\n", Number_Of_Runs);
  165.  
  166.   /***************/
  167.   /* Start timer */
  168.   /***************/
  169.  
  170. #ifdef TIMES
  171.   times (&time_info);
  172.   Begin_Time = (long) time_info.tms_utime;
  173. #endif
  174. #ifdef TIME
  175.   /* Begin_Time = time ( (long *) 0);*/
  176.   Begin_Time = second();
  177. #endif
  178.  
  179.   for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
  180.   {
  181.  
  182.     Proc_5();
  183.     Proc_4();
  184.       /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  185.     Int_1_Loc = 2;
  186.     Int_2_Loc = 3;
  187.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  188.     Enum_Loc = Ident_2;
  189.     Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  190.       /* Bool_Glob == 1 */
  191.     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
  192.     {
  193.       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  194.         /* Int_3_Loc == 7 */
  195.       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  196.         /* Int_3_Loc == 7 */
  197.       Int_1_Loc += 1;
  198.     } /* while */
  199.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  200.     Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  201.       /* Int_Glob == 5 */
  202.     Proc_1 (Ptr_Glob);
  203.     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  204.                              /* loop body executed twice */
  205.     {
  206.       if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  207.           /* then, not executed */
  208.         {
  209.         Proc_6 (Ident_1, &Enum_Loc);
  210.         strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  211.         Int_2_Loc = Run_Index;
  212.         Int_Glob = Run_Index;
  213.         }
  214.     }
  215.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  216.     Int_2_Loc = Int_2_Loc * Int_1_Loc;
  217.     Int_1_Loc = Int_2_Loc / Int_3_Loc;
  218.     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  219.       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  220.     Proc_2 (&Int_1_Loc);
  221.       /* Int_1_Loc == 5 */
  222.  
  223.   } /* loop "for Run_Index" */
  224.  
  225.   /**************/
  226.   /* Stop timer */
  227.   /**************/
  228.  
  229. #ifdef TIMES
  230.   times (&time_info);
  231.   End_Time = (long) time_info.tms_utime;
  232. #endif
  233. #ifdef TIME
  234.   /* End_Time = time ( (long *) 0); */
  235.   End_Time = second();
  236. #endif
  237.  
  238.  
  239.   User_Time = End_Time - Begin_Time;
  240.  
  241.   if (User_Time < Too_Small_Time)
  242.   {
  243.     printf1 ("Measured time too small to obtain meaningful results\r\n");
  244.     printf1 ("Please increase number of runs\r\n");
  245.     printf1 ("\r\n");
  246.   } else {
  247.     break;
  248.   }
  249.  
  250.   Number_Of_Runs *= 10;
  251.  
  252.   }}
  253.  
  254.  
  255.  
  256.   printf1 ("Execution ends\r\n");
  257.   printf1 ("\r\n");
  258.   printf1 ("Final values of the variables used in the benchmark:\r\n");
  259.   printf1 ("\r\n");
  260.   printf1 ("Int_Glob:            %d\r\n", Int_Glob);
  261.   printf1 ("        should be:   %d\r\n", 5);
  262.   printf1 ("Bool_Glob:           %d\r\n", Bool_Glob);
  263.   printf1 ("        should be:   %d\r\n", 1);
  264.   printf1 ("Ch_1_Glob:           %c\r\n", Ch_1_Glob);
  265.   printf1 ("        should be:   %c\r\n", 'A');
  266.   printf1 ("Ch_2_Glob:           %c\r\n", Ch_2_Glob);
  267.   printf1 ("        should be:   %c\r\n", 'B');
  268.   printf1 ("Arr_1_Glob[8]:       %d\r\n", Arr_1_Glob[8]);
  269.   printf1 ("        should be:   %d\r\n", 7);
  270.   printf1 ("Arr_2_Glob[8][7]:    %d\r\n", Arr_2_Glob[8][7]);
  271.   printf1 ("        should be:   Number_Of_Runs + 10\r\n");
  272.   printf1 ("Ptr_Glob->\r\n");
  273.   printf1 ("  Ptr_Comp:          %d\r\n", (int) Ptr_Glob->Ptr_Comp);
  274.   printf1 ("        should be:   (implementation-dependent)\r\n");
  275.   printf1 ("  Discr:             %d\r\n", Ptr_Glob->Discr);
  276.   printf1 ("        should be:   %d\r\n", 0);
  277.   printf1 ("  Enum_Comp:         %d\r\n", Ptr_Glob->variant.var_1.Enum_Comp);
  278.   printf1 ("        should be:   %d\r\n", 2);
  279.   printf1 ("  Int_Comp:          %d\r\n", Ptr_Glob->variant.var_1.Int_Comp);
  280.   printf1 ("        should be:   %d\r\n", 17);
  281.   printf1 ("  Str_Comp:          %s\r\n", Ptr_Glob->variant.var_1.Str_Comp);
  282.   printf1 ("        should be:   DHRYSTONE PROGRAM, SOME STRING\r\n");
  283.   printf1 ("Next_Ptr_Glob->\r\n");
  284.   printf1 ("  Ptr_Comp:          %d\r\n", (int) Next_Ptr_Glob->Ptr_Comp);
  285.   printf1 ("        should be:   (implementation-dependent), same as above\r\n");
  286.   printf1 ("  Discr:             %d\r\n", Next_Ptr_Glob->Discr);
  287.   printf1 ("        should be:   %d\r\n", 0);
  288.   printf1 ("  Enum_Comp:         %d\r\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  289.   printf1 ("        should be:   %d\r\n", 1);
  290.   printf1 ("  Int_Comp:          %d\r\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
  291.   printf1 ("        should be:   %d\r\n", 18);
  292.   printf1 ("  Str_Comp:          %s\r\n",
  293.                                 Next_Ptr_Glob->variant.var_1.Str_Comp);
  294.   printf1 ("        should be:   DHRYSTONE PROGRAM, SOME STRING\r\n");
  295.   printf1 ("Int_1_Loc:           %d\r\n", Int_1_Loc);
  296.   printf1 ("        should be:   %d\r\n", 5);
  297.   printf1 ("Int_2_Loc:           %d\r\n", Int_2_Loc);
  298.   printf1 ("        should be:   %d\r\n", 13);
  299.   printf1 ("Int_3_Loc:           %d\r\n", Int_3_Loc);
  300.   printf1 ("        should be:   %d\r\n", 7);
  301.   printf1 ("Enum_Loc:            %d\r\n", Enum_Loc);
  302.   printf1 ("        should be:   %d\r\n", 1);
  303.   printf1 ("Str_1_Loc:           %s\r\n", Str_1_Loc);
  304.   printf1 ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\r\n");
  305.   printf1 ("Str_2_Loc:           %s\r\n", Str_2_Loc);
  306.   printf1 ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\r\n");
  307.   printf1 ("\r\n");
  308.  
  309.   User_Time = End_Time - Begin_Time;
  310.  
  311.   if (User_Time < Too_Small_Time)
  312.   {
  313.     printf1 ("Measured time too small to obtain meaningful results\r\n");
  314.     printf1 ("Please increase number of runs\r\n");
  315.     printf1 ("\r\n");
  316.   } else {
  317.  
  318. #ifdef TIME
  319.     Microseconds = (float) User_Time * Mic_secs_Per_Second
  320.                         / (float) Number_Of_Runs;
  321.     Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
  322. #else
  323.     Microseconds = (float) User_Time * Mic_secs_Per_Second
  324.                         / ((float) HZ * ((float) Number_Of_Runs));
  325.     Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
  326.                         / (float) User_Time;
  327.     printf1("User_time sec (times, HZ): %.3f (%d, %d)\r\n", (float)User_Time/HZ, User_Time, HZ);
  328. #endif
  329.     printf1 ("Microseconds for one run through Dhrystone: ");
  330.     printf1 ("%6.1f \r\n", Microseconds);
  331.     printf1 ("Dhrystones per Second:                      ");
  332.     printf1 ("%6.1f \r\n", Dhrystones_Per_Second);
  333.     printf1 ("\r\n");
  334.   }
  335.  
  336. }
  337.  
  338.  
  339. void Proc_1 (Ptr_Val_Par)
  340. /******************/
  341.  
  342. REG Rec_Pointer Ptr_Val_Par;
  343.     /* executed once */
  344. {
  345.   REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;  
  346.                                         /* == Ptr_Glob_Next */
  347.   /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
  348.   /* corresponds to "rename" in Ada, "with" in Pascal           */
  349.  
  350.   structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
  351.   Ptr_Val_Par->variant.var_1.Int_Comp = 5;
  352.   Next_Record->variant.var_1.Int_Comp
  353.         = Ptr_Val_Par->variant.var_1.Int_Comp;
  354.   Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
  355.   Proc_3 (&Next_Record->Ptr_Comp);
  356.     /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
  357.                         == Ptr_Glob->Ptr_Comp */
  358.   if (Next_Record->Discr == Ident_1)
  359.     /* then, executed */
  360.   {
  361.     Next_Record->variant.var_1.Int_Comp = 6;
  362.     Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
  363.            &Next_Record->variant.var_1.Enum_Comp);
  364.     Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
  365.     Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
  366.            &Next_Record->variant.var_1.Int_Comp);
  367.   }
  368.   else /* not executed */
  369.     structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
  370. } /* Proc_1 */
  371.  
  372.  
  373. void Proc_2 (Int_Par_Ref)
  374. /******************/
  375.     /* executed once */
  376.     /* *Int_Par_Ref == 1, becomes 4 */
  377.  
  378. One_Fifty   *Int_Par_Ref;
  379. {
  380.   One_Fifty  Int_Loc;  
  381.   Enumeration   Enum_Loc;
  382.  
  383.   Int_Loc = *Int_Par_Ref + 10;
  384.   do /* executed once */
  385.     if (Ch_1_Glob == 'A')
  386.       /* then, executed */
  387.     {
  388.       Int_Loc -= 1;
  389.       *Int_Par_Ref = Int_Loc - Int_Glob;
  390.       Enum_Loc = Ident_1;
  391.     } /* if */
  392.   while (Enum_Loc != Ident_1); /* true */
  393. } /* Proc_2 */
  394.  
  395.  
  396. void Proc_3 (Ptr_Ref_Par)
  397. /******************/
  398.     /* executed once */
  399.     /* Ptr_Ref_Par becomes Ptr_Glob */
  400.  
  401. Rec_Pointer *Ptr_Ref_Par;
  402.  
  403. {
  404.   if (Ptr_Glob != Null)
  405.     /* then, executed */
  406.     *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
  407.   Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
  408. } /* Proc_3 */
  409.  
  410.  
  411. void Proc_4 () /* without parameters */
  412. /*******/
  413.     /* executed once */
  414. {
  415.   Boolean Bool_Loc;
  416.  
  417.   Bool_Loc = Ch_1_Glob == 'A';
  418.   Bool_Glob = Bool_Loc | Bool_Glob;
  419.   Ch_2_Glob = 'B';
  420. } /* Proc_4 */
  421.  
  422.  
  423. void Proc_5 () /* without parameters */
  424. /*******/
  425.     /* executed once */
  426. {
  427.   Ch_1_Glob = 'A';
  428.   Bool_Glob = false;
  429. } /* Proc_5 */
  430.  
  431.  
  432.         /* Procedure for the assignment of structures,          */
  433.         /* if the C compiler doesn't support this feature       */
  434. #ifdef  NOSTRUCTASSIGN
  435. memcpy (d, s, l)
  436. register char   *d;
  437. register char   *s;
  438. register int    l;
  439. {
  440.         while (l--) *d++ = *s++;
  441. }
  442. #endif
  443.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement