Add TINI target
[fw/sdcc] / support / tests / dhrystone / dhry.c
index 9b44ddd969d1a4dcbe69759e780b466da0d369ef..a6e6dd47444871336fd868bd56980682fb6f701d 100644 (file)
     ...!uunet!pcrat!dry2       (results only)
 */
 
+#define NOENUM         1
+#define NOSTRUCTASSIGN 1
+#define REG
+
 #include "dhry.h"
 #include <string.h>
 /** For printf */
 #include <stdio.h>
 
-/** Returns the current device time in ticks.  Check HZ in the Makefile
-    as well - HZ ticks = 1 second.
+#ifdef SDCC_ds390
+#include "clock.h"
+#include <serial390.h>
+#undef PRINT_T_STATES
+#else
+/** For clock() */
+#include <time.h>
+#include <types.h>
+#define PRINT_T_STATES
+#endif
+
+/** Print the number of t-states this program has been executing for.
+    Optional :)
 */
-unsigned _clock(void);
+#ifdef PRINT_T_STATES
+void _printTStates(void);
+#endif
 
 /** Set to one to print more messages about expected values etc. 
  */
@@ -68,7 +85,6 @@ char            Ch_1_Glob,
 int             Arr_1_Glob [50];
 int             Arr_2_Glob [50] [50];
 
-
 /* Used instead of malloc() */
 static Rec_Type _r[2];
 
@@ -85,11 +101,9 @@ Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
 Boolean Func_2 (char *Str_1_Par_Ref, char *Str_2_Par_Ref);
 Boolean Func_3 (Enumeration Enum_Par_Val);
 
-#if SDCC
-int _main(void) 
-#else
+unsigned getsp(void);
+
 int main(void)
-#endif
 {
     One_Fifty       Int_1_Loc;
     REG   One_Fifty       Int_2_Loc;
@@ -100,8 +114,12 @@ int main(void)
     Str_30          Str_2_Loc;
     REG   int             Run_Index;
     REG   int             Number_Of_Runs;
-    unsigned runTime;
+    unsigned  long runTime;
 
+#ifdef SDCC_ds390
+    startTimer();
+#endif
+    
     printf("[dhry]\n");
 
     Next_Ptr_Glob = &_r[0];
@@ -112,7 +130,7 @@ int main(void)
     Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
     Ptr_Glob->variant.var_1.Int_Comp      = 40;
 
-    strcpy (Ptr_Glob->variant.var_1.Str_Comp, 
+    strcpy(Ptr_Glob->variant.var_1.Str_Comp, 
            "DHRYSTONE PROGRAM, SOME STRING");
     strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
 
@@ -124,13 +142,19 @@ int main(void)
     /* overflow may occur for this array element.                   */
 
     /* 32766 is the highest value for a 16 bitter */
-    Number_Of_Runs = 20000;
+#if DEBUG
+    Number_Of_Runs = 3;
+#else
+    Number_Of_Runs = 10000;
+#endif    
 
-    runTime = _clock();
+    runTime = clock();
 
     /* Main test loop */
     for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) {
        DPRINTF(("Run_Index = %d\n", Run_Index));
+       if (!(Run_Index & 1023))
+           printf("Loops: %u\r", Run_Index);
        Proc_5();
        Proc_4();
        /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
@@ -160,7 +184,7 @@ int main(void)
               Int_1_Loc, Int_2_Loc, Int_3_Loc));
 
        DPRINTF(("Proc_8\n"));
-       Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
+       Proc_8 (Arr_1_Glob, (int *)Arr_2_Glob, Int_1_Loc, Int_3_Loc);
        /* Int_Glob == 5 */
        DPRINTF(("Int_Glob %d == 5\n", Int_Glob));
        DPRINTF(("Proc_1\n"));
@@ -196,10 +220,15 @@ int main(void)
        DPRINTF(("Looping.\n"));
     } /* loop "for Run_Index" */
 
+#ifdef PRINT_T_STATES    
+    _printTStates();
+#endif    
+
     printf("Run_Index = %d\n", Run_Index);
 
-    runTime = _clock() - runTime;
+    runTime = clock() - runTime;
 
+#if 1
     printf ("Execution ends\n");
     printf ("\n");
     printf ("Final values of the variables used in the benchmark:\n");
@@ -214,7 +243,11 @@ int main(void)
     printf ("        should be:   %c\n", 'B');
     printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
     printf ("        should be:   %d\n", (int)7);
+#if 0
     printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
+#else
+    //    printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
+#endif
     printf ("        should be:   Number_Of_Runs + 10\n");
     printf ("Ptr_Glob->\n");
     printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
@@ -252,10 +285,13 @@ int main(void)
     printf ("Str_2_Loc:           %s\n", Str_2_Loc);
     printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
     printf ("\n");
-
-    printf("Time: %u ticks\n", runTime);
-    printf("Dhrystones/s = %u\n", Number_Of_Runs / (runTime/HZ));
+#endif
+    printf("Dhrystones/s = %lu\n", (unsigned long)Number_Of_Runs / (runTime/CLOCKS_PER_SEC));
     printf("MIPS = d/s/1757 = (sigh, need floats...)\n");
+#ifdef PRINT_T_STATES    
+    _printTStates();
+#endif    
+    printf("Time: %lu ticks\n", runTime);
 }
 
 void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
@@ -301,17 +337,17 @@ void Proc_2 (One_Fifty *Int_Par_Ref)
 
     Int_Loc = *Int_Par_Ref + 10;
     do {
-       DPRINTF(("1\n"));
+       DPRINTF(("1"));
        /* executed once */
        if (Ch_1_Glob == 'A')
            /* then, executed */
            {
-               DPRINTF(("2\n"));
+               DPRINTF(("2"));
                Int_Loc -= 1;
                *Int_Par_Ref = Int_Loc - Int_Glob;
                Enum_Loc = Ident_1;
            } /* if */
-       DPRINTF(("3\n"));
+       DPRINTF(("3"));
     } while (Enum_Loc != Ident_1); /* true */
     DPRINTF(("Proc_2 done.\n"));
 } /* Proc_2 */
@@ -454,7 +490,7 @@ void Proc_8 (int *Arr_1_Par_Ref, int *Arr_2_Par_Ref,
     DPRINTF(("-> Proc_8\n"));
     Int_Loc = Int_1_Par_Val + 5;
     Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
-    DPRINTF(("Int_Loc %d == 8\n", Int_Loc));
+    DPRINTF(("Int_Loc %d == 8 Int_2_Par_Val %d == 7\n", Int_Loc, Int_2_Par_Val));
 
     Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
     Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
@@ -463,6 +499,7 @@ void Proc_8 (int *Arr_1_Par_Ref, int *Arr_2_Par_Ref,
     Arr_2_Par_Ref [Int_Loc * 50 + Int_Loc-1] += 1;
     Arr_2_Par_Ref [(Int_Loc+20 *50) + Int_Loc] = Arr_1_Par_Ref [Int_Loc];
     Int_Glob = 5;
+    DPRINTF(("Arr_1_Glob[8] %d == 7\n", Arr_1_Par_Ref[8]));
 }
 
 /*********************************************************************/
@@ -526,3 +563,4 @@ Boolean Func_2 (char *Str_1_Par_Ref, char *Str_2_Par_Ref)
            }
        } /* if Ch_Loc */
 } /* Func_2 */
+