Remove smips/host-debugging cruft
[riscv-tests.git] / benchmarks / dhrystone / dhrystone_main.c
index a7557433c48323b243a5d4d0c27292559ce764ea..9c7bcf544ffc01d7e1d11650cb97593a70f888d1 100644 (file)
@@ -1,48 +1,17 @@
+// See LICENSE for license details.
+
 //**************************************************************************
 // Dhrystone bencmark
 //--------------------------------------------------------------------------
 //
 // This is the classic Dhrystone synthetic integer benchmark.
-// You should not change anything except the HOST_DEBUG and
-// PREALLOCATE macros for your timing run.
-
-#include "dhrystone.h"
-
-//--------------------------------------------------------------------------
-// Macros
-
-// Set HOST_DEBUG to 1 if you are going to compile this for a host
-// machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
-// to 0 if you are compiling with the smips-gcc toolchain.
-
-#ifndef HOST_DEBUG
-#define HOST_DEBUG 0
-#endif
-
-// Set PREALLOCATE to 1 if you want to preallocate the benchmark
-// function before starting stats. If you have instruction/data
-// caches and you don't want to count the overhead of misses, then
-// you will need to use preallocation.
-
-#ifndef PREALLOCATE
-#define PREALLOCATE 0
-#endif
+//
 
-// Set SET_STATS to 1 if you want to carve out the piece that actually
-// does the computation.
+#pragma GCC optimize ("no-inline")
 
-#ifndef SET_STATS
-#define SET_STATS 0
-#endif
+#include "dhrystone.h"
 
-#if HOST_DEBUG
-# define do_fprintf fprintf
-#else
-int __attribute__((noinline)) do_fprintf(FILE* f, const char* str, ...)
-{
-  return 0;
-}
-#endif
+void debug_printf(const char* str, ...);
 
 #include "util.h"
 
@@ -59,6 +28,9 @@ char            Ch_1_Glob,
 int             Arr_1_Glob [50];
 int             Arr_2_Glob [50] [50];
 
+Enumeration     Func_1 ();
+  /* forward declaration necessary since Enumeration may not simply be int */
+
 #ifndef REG
         Boolean Reg = false;
 #define REG
@@ -75,7 +47,7 @@ Boolean               Done;
 long            Begin_Time,
                 End_Time,
                 User_Time;
-float           Microseconds,
+long            Microseconds,
                 Dhrystones_Per_Second;
 
 /* end of variables for time measurement */
@@ -97,24 +69,7 @@ int main (int argc, char** argv)
   REG   int             Number_Of_Runs;
 
   /* Arguments */
-#if HOST_DEBUG
-  if (argc > 2)
-  {
-     do_fprintf (stdout, "Usage: %s [number of loops]\n", argv[0]);
-     exit (1);
-  }
-  if (argc == 2)
-  {
-     Number_Of_Runs = atoi (argv[1]);
-  } else
-#endif
-  {
-     Number_Of_Runs = NUMBER_OF_RUNS;
-  }
-  if (Number_Of_Runs <= 0)
-  {
-     Number_Of_Runs = NUMBER_OF_RUNS;
-  }
+  Number_Of_Runs = NUMBER_OF_RUNS;
 
   /* Initializations */
 
@@ -135,33 +90,29 @@ int main (int argc, char** argv)
         /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
         /* overflow may occur for this array element.                   */
 
-#if HOST_DEBUG
-  do_fprintf (stdout, "\n");
-  do_fprintf (stdout, "Dhrystone Benchmark, Version %s\n", Version);
+  debug_printf("\n");
+  debug_printf("Dhrystone Benchmark, Version %s\n", Version);
   if (Reg)
   {
-    do_fprintf (stdout, "Program compiled with 'register' attribute\n");
+    debug_printf("Program compiled with 'register' attribute\n");
   }
   else
   {
-    do_fprintf (stdout, "Program compiled without 'register' attribute\n");
+    debug_printf("Program compiled without 'register' attribute\n");
   }
-  do_fprintf (stdout, "Using %s, HZ=%d\n", CLOCK_TYPE, HZ);
-  do_fprintf (stdout, "\n");
-#endif
+  debug_printf("Using %s, HZ=%d\n", CLOCK_TYPE, HZ);
+  debug_printf("\n");
 
   Done = false;
   while (!Done) {
-#if HOST_DEBUG
-    do_fprintf (stdout, "Trying %d runs through Dhrystone:\n", Number_Of_Runs);
-#endif
+    debug_printf("Trying %d runs through Dhrystone:\n", Number_Of_Runs);
 
     /***************/
     /* Start timer */
     /***************/
 
-    Start_Timer();
     setStats(1);
+    Start_Timer();
 
     for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
     {
@@ -213,90 +164,85 @@ int main (int argc, char** argv)
     /* Stop timer */
     /**************/
 
-    setStats(0);
     Stop_Timer();
+    setStats(0);
 
     User_Time = End_Time - Begin_Time;
 
     if (User_Time < Too_Small_Time)
     {
-      do_fprintf (stdout, "Measured time too small to obtain meaningful results\n");
+      printf("Measured time too small to obtain meaningful results\n");
       Number_Of_Runs = Number_Of_Runs * 10;
-      do_fprintf (stdout, "\n");
+      printf("\n");
     } else Done = true;
   }
 
-  do_fprintf (stderr, "Final values of the variables used in the benchmark:\n");
-  do_fprintf (stderr, "\n");
-  do_fprintf (stderr, "Int_Glob:            %d\n", Int_Glob);
-  do_fprintf (stderr, "        should be:   %d\n", 5);
-  do_fprintf (stderr, "Bool_Glob:           %d\n", Bool_Glob);
-  do_fprintf (stderr, "        should be:   %d\n", 1);
-  do_fprintf (stderr, "Ch_1_Glob:           %c\n", Ch_1_Glob);
-  do_fprintf (stderr, "        should be:   %c\n", 'A');
-  do_fprintf (stderr, "Ch_2_Glob:           %c\n", Ch_2_Glob);
-  do_fprintf (stderr, "        should be:   %c\n", 'B');
-  do_fprintf (stderr, "Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
-  do_fprintf (stderr, "        should be:   %d\n", 7);
-  do_fprintf (stderr, "Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
-  do_fprintf (stderr, "        should be:   Number_Of_Runs + 10\n");
-  do_fprintf (stderr, "Ptr_Glob->\n");
-  do_fprintf (stderr, "  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
-  do_fprintf (stderr, "        should be:   (implementation-dependent)\n");
-  do_fprintf (stderr, "  Discr:             %d\n", Ptr_Glob->Discr);
-  do_fprintf (stderr, "        should be:   %d\n", 0);
-  do_fprintf (stderr, "  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
-  do_fprintf (stderr, "        should be:   %d\n", 2);
-  do_fprintf (stderr, "  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
-  do_fprintf (stderr, "        should be:   %d\n", 17);
-  do_fprintf (stderr, "  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
-  do_fprintf (stderr, "        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
-  do_fprintf (stderr, "Next_Ptr_Glob->\n");
-  do_fprintf (stderr, "  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
-  do_fprintf (stderr, "        should be:   (implementation-dependent), same as above\n");
-  do_fprintf (stderr, "  Discr:             %d\n", Next_Ptr_Glob->Discr);
-  do_fprintf (stderr, "        should be:   %d\n", 0);
-  do_fprintf (stderr, "  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
-  do_fprintf (stderr, "        should be:   %d\n", 1);
-  do_fprintf (stderr, "  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
-  do_fprintf (stderr, "        should be:   %d\n", 18);
-  do_fprintf (stderr, "  Str_Comp:          %s\n",
+  debug_printf("Final values of the variables used in the benchmark:\n");
+  debug_printf("\n");
+  debug_printf("Int_Glob:            %d\n", Int_Glob);
+  debug_printf("        should be:   %d\n", 5);
+  debug_printf("Bool_Glob:           %d\n", Bool_Glob);
+  debug_printf("        should be:   %d\n", 1);
+  debug_printf("Ch_1_Glob:           %c\n", Ch_1_Glob);
+  debug_printf("        should be:   %c\n", 'A');
+  debug_printf("Ch_2_Glob:           %c\n", Ch_2_Glob);
+  debug_printf("        should be:   %c\n", 'B');
+  debug_printf("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
+  debug_printf("        should be:   %d\n", 7);
+  debug_printf("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
+  debug_printf("        should be:   Number_Of_Runs + 10\n");
+  debug_printf("Ptr_Glob->\n");
+  debug_printf("  Ptr_Comp:          %d\n", (long) Ptr_Glob->Ptr_Comp);
+  debug_printf("        should be:   (implementation-dependent)\n");
+  debug_printf("  Discr:             %d\n", Ptr_Glob->Discr);
+  debug_printf("        should be:   %d\n", 0);
+  debug_printf("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
+  debug_printf("        should be:   %d\n", 2);
+  debug_printf("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
+  debug_printf("        should be:   %d\n", 17);
+  debug_printf("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
+  debug_printf("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
+  debug_printf("Next_Ptr_Glob->\n");
+  debug_printf("  Ptr_Comp:          %d\n", (long) Next_Ptr_Glob->Ptr_Comp);
+  debug_printf("        should be:   (implementation-dependent), same as above\n");
+  debug_printf("  Discr:             %d\n", Next_Ptr_Glob->Discr);
+  debug_printf("        should be:   %d\n", 0);
+  debug_printf("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
+  debug_printf("        should be:   %d\n", 1);
+  debug_printf("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
+  debug_printf("        should be:   %d\n", 18);
+  debug_printf("  Str_Comp:          %s\n",
                                 Next_Ptr_Glob->variant.var_1.Str_Comp);
-  do_fprintf (stderr, "        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
-  do_fprintf (stderr, "Int_1_Loc:           %d\n", Int_1_Loc);
-  do_fprintf (stderr, "        should be:   %d\n", 5);
-  do_fprintf (stderr, "Int_2_Loc:           %d\n", Int_2_Loc);
-  do_fprintf (stderr, "        should be:   %d\n", 13);
-  do_fprintf (stderr, "Int_3_Loc:           %d\n", Int_3_Loc);
-  do_fprintf (stderr, "        should be:   %d\n", 7);
-  do_fprintf (stderr, "Enum_Loc:            %d\n", Enum_Loc);
-  do_fprintf (stderr, "        should be:   %d\n", 1);
-  do_fprintf (stderr, "Str_1_Loc:           %s\n", Str_1_Loc);
-  do_fprintf (stderr, "        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
-  do_fprintf (stderr, "Str_2_Loc:           %s\n", Str_2_Loc);
-  do_fprintf (stderr, "        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
-  do_fprintf (stderr, "\n");
-
-
-#if HOST_DEBUG
-    Microseconds = (float) User_Time * Mic_secs_Per_Second 
-                        / ((float) HZ * ((float) Number_Of_Runs));
-    Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
-                        / (float) User_Time;
-
-    do_fprintf (stdout, "Microseconds for one run through Dhrystone: ");
-    do_fprintf (stdout, "%10.1f \n", Microseconds);
-    do_fprintf (stdout, "Dhrystones per Second:                      ");
-    do_fprintf (stdout, "%10.0f \n", Dhrystones_Per_Second);
-    do_fprintf (stdout, "\n");
-#endif
+  debug_printf("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
+  debug_printf("Int_1_Loc:           %d\n", Int_1_Loc);
+  debug_printf("        should be:   %d\n", 5);
+  debug_printf("Int_2_Loc:           %d\n", Int_2_Loc);
+  debug_printf("        should be:   %d\n", 13);
+  debug_printf("Int_3_Loc:           %d\n", Int_3_Loc);
+  debug_printf("        should be:   %d\n", 7);
+  debug_printf("Enum_Loc:            %d\n", Enum_Loc);
+  debug_printf("        should be:   %d\n", 1);
+  debug_printf("Str_1_Loc:           %s\n", Str_1_Loc);
+  debug_printf("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
+  debug_printf("Str_2_Loc:           %s\n", Str_2_Loc);
+  debug_printf("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
+  debug_printf("\n");
+
+
+  Microseconds = ((User_Time / Number_Of_Runs) * Mic_secs_Per_Second) / HZ;
+  Dhrystones_Per_Second = (HZ * Number_Of_Runs) / User_Time;
+
+  printf("Microseconds for one run through Dhrystone: %ld\n", Microseconds);
+  printf("Dhrystones per Second:                      %ld\n", Dhrystones_Per_Second);
 
   return 0;
 }
 
 
-void Proc_1(Rec_Pointer Ptr_Val_Par)
+Proc_1 (Ptr_Val_Par)
 /******************/
+
+REG Rec_Pointer Ptr_Val_Par;
     /* executed once */
 {
   REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;  
@@ -327,10 +273,12 @@ void Proc_1(Rec_Pointer Ptr_Val_Par)
 } /* Proc_1 */
 
 
-void Proc_2(int* Int_Par_Ref)
+Proc_2 (Int_Par_Ref)
 /******************/
     /* executed once */
     /* *Int_Par_Ref == 1, becomes 4 */
+
+One_Fifty   *Int_Par_Ref;
 {
   One_Fifty  Int_Loc;  
   Enumeration   Enum_Loc;
@@ -348,10 +296,13 @@ void Proc_2(int* Int_Par_Ref)
 } /* Proc_2 */
 
 
-void Proc_3(Rec_Pointer* Ptr_Ref_Par)
+Proc_3 (Ptr_Ref_Par)
 /******************/
     /* executed once */
     /* Ptr_Ref_Par becomes Ptr_Glob */
+
+Rec_Pointer *Ptr_Ref_Par;
+
 {
   if (Ptr_Glob != Null)
     /* then, executed */
@@ -360,7 +311,7 @@ void Proc_3(Rec_Pointer* Ptr_Ref_Par)
 } /* Proc_3 */
 
 
-void Proc_4()
+Proc_4 () /* without parameters */
 /*******/
     /* executed once */
 {
@@ -372,7 +323,7 @@ void Proc_4()
 } /* Proc_4 */
 
 
-void Proc_5()
+Proc_5 () /* without parameters */
 /*******/
     /* executed once */
 {