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