SAMV71 Xplained Ultra Software Package 1.3

dhry_1.c

00001 /*
00002  * The 'old-style' K&R function declarations have been replaced with 
00003  * 'ANSI-C-style' function declarations (in dhry_1.c and dhry_2,c)
00004  */
00005 
00006 /*
00007  ****************************************************************************
00008  *
00009  *                   "DHRYSTONE" Benchmark Program
00010  *                   -----------------------------
00011  *                                                                            
00012  *  Version:    C, Version 2.1
00013  *                                                                            
00014  *  File:       dhry_1.c (part 2 of 3)
00015  *
00016  *  Date:       May 25, 1988
00017  *
00018  *  Author:     Reinhold P. Weicker
00019  *
00020  ****************************************************************************
00021  */
00022 #include <string.h>  
00023 #include <stdlib.h>
00024 #include "dhry.h " 
00025   
00026 
00027 /* Global Variables: */
00028 
00029 Rec_Pointer     Ptr_Glob,
00030                 Next_Ptr_Glob;
00031 int             Int_Glob;
00032 Boolean         Bool_Glob;
00033 char            Ch_1_Glob,
00034                 Ch_2_Glob;
00035 int             Arr_1_Glob [50];
00036 int             Arr_2_Glob [50] [50];
00037 
00038 //extern char     *malloc (int i );
00039 extern Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
00040 extern Boolean Func_2 (Str_30  Str_1_Par_Ref, Str_30  Str_2_Par_Ref) ;
00041   /* forward declaration necessary since Enumeration may not simply be int */
00042 extern Boolean Func_3 (Enumeration Enum_Par_Val);
00043 extern void Proc_6 ( Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par) ;
00044 extern void Proc_7 ( One_Fifty Int_1_Par_Val,
00045               One_Fifty Int_2_Par_Val,
00046               One_Fifty *Int_Par_Ref ) ;
00047 extern void Proc_8 ( Arr_1_Dim Arr_1_Par_Ref,
00048               Arr_2_Dim Arr_2_Par_Ref,
00049               int Int_1_Par_Val,
00050               int Int_2_Par_Val) ;
00051 void Proc_1 (Rec_Pointer Ptr_Val_Par) ;
00052 void Proc_2 (One_Fifty *Int_Par_Ref) ;
00053 void Proc_3 (Rec_Pointer *Ptr_Ref_Par) ;
00054 void Proc_4 ( void ) ;
00055 void Proc_5 ( void ) ;
00056 
00057 
00058 #ifndef REG
00059         Boolean Reg = false;
00060 #define REG
00061         /* REG becomes defined as empty */
00062         /* i.e. no register variables   */
00063 #else
00064         Boolean Reg = true;
00065 #endif
00066 
00067 /* variables for time measurement: */
00068 long            Begin_Time,
00069                 End_Time,
00070                 User_Time;
00071 float           Microseconds,
00072                 Dhrystones_Per_Second;
00073 
00074 /* end of variables for time measurement */
00075 
00076 
00077 void Proc_1 (Rec_Pointer Ptr_Val_Par)
00078 /******************/
00079 
00080     /* executed once */
00081 {
00082     REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
00083                                         /* == Ptr_Glob_Next */
00084     /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
00085     /* corresponds to "rename" in Ada, "with" in Pascal           */
00086 
00087     structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
00088     Ptr_Val_Par->variant.var_1.Int_Comp = 5;
00089     Next_Record->variant.var_1.Int_Comp = Ptr_Val_Par->variant.var_1.Int_Comp;
00090     Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
00091     Proc_3 (&Next_Record->Ptr_Comp);
00092     /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp == Ptr_Glob->Ptr_Comp */
00093     if (Next_Record->Discr == Ident_1)
00094     {
00095         Next_Record->variant.var_1.Int_Comp = 6;
00096         Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
00097                 &Next_Record->variant.var_1.Enum_Comp);
00098         Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
00099         Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
00100                 &Next_Record->variant.var_1.Int_Comp);
00101     }
00102     else
00103         structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
00104 } /* Proc_1 */
00105 
00106 
00107 void Proc_2 (One_Fifty *Int_Par_Ref)
00108 /******************/
00109     /* executed once */
00110     /* *Int_Par_Ref == 1, becomes 4 */
00111 
00112 {
00113     One_Fifty  Int_Loc;
00114     Enumeration   Enum_Loc;
00115 
00116     Int_Loc = *Int_Par_Ref + 10;
00117     do /* executed once */
00118         if (Ch_1_Glob == 'A')
00119         {
00120             Int_Loc -= 1;
00121             *Int_Par_Ref = Int_Loc - Int_Glob;
00122             Enum_Loc = Ident_1;
00123         }
00124     while (Enum_Loc != Ident_1); /* true */
00125 } /* Proc_2 */
00126 
00127 
00128 void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
00129 /******************/
00130     /* executed once */
00131     /* Ptr_Ref_Par becomes Ptr_Glob */
00132 {
00133     if (Ptr_Glob != Null)
00134         *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
00135     Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
00136 } /* Proc_3 */
00137 
00138 
00139 void Proc_4 ( void )
00140 /*******/
00141     /* executed once */
00142 {
00143     Boolean Bool_Loc;
00144 
00145     Bool_Loc = Ch_1_Glob == 'A';
00146     Bool_Glob = Bool_Loc | Bool_Glob;
00147     Ch_2_Glob = 'B';
00148 } /* Proc_4 */
00149 
00150 
00151 void Proc_5 ( void )
00152 /*******/
00153 {
00154     Ch_1_Glob = 'A';
00155     Bool_Glob = false;
00156 } /* Proc_5 */
00157 
00158 //int main ( void )
00159 void DHRY_testloop ( int Number_Of_Runs )
00160 /*****/
00161 
00162 /* main program, corresponds to procedures        */
00163 /* Main and Proc_0 in the Ada version             */
00164 {
00165     One_Fifty       Int_1_Loc;  
00166     REG One_Fifty   Int_2_Loc;
00167     One_Fifty       Int_3_Loc;
00168     REG char        Ch_Index;
00169     Enumeration     Enum_Loc;
00170     Str_30          Str_1_Loc;
00171     Str_30          Str_2_Loc;
00172     REG int         Run_Index;
00173 
00174 
00175     /* Initializations */
00176     Rec_Type alloc_NextGlob;
00177     Rec_Type alloc_Glob;
00178     Next_Ptr_Glob = (Rec_Pointer) &alloc_NextGlob;
00179     Ptr_Glob      = (Rec_Pointer) &alloc_Glob;
00180 
00181     //Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
00182     //Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
00183 
00184     Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
00185     Ptr_Glob->Discr                       = Ident_1;
00186     Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
00187     Ptr_Glob->variant.var_1.Int_Comp      = 40;
00188     strcpy (Ptr_Glob->variant.var_1.Str_Comp,
00189             "DHRYSTONE PROGRAM, SOME STRING");
00190     strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
00191 
00192     Arr_2_Glob [8][7] = 10;
00193         /* Was missing in published program. Without this statement,    */
00194         /* Arr_2_Glob [8][7] would have an undefined value.             */
00195         /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
00196         /* overflow may occur for this array element.                   */
00197 
00198 
00199     /***************/
00200     /* Start loop */
00201     /***************/
00202 
00203     for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
00204     {
00205         Proc_5();
00206         Proc_4(); 
00207         /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
00208         Int_1_Loc = 2;  
00209         Int_2_Loc = 3; 
00210         strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
00211         Enum_Loc = Ident_2;
00212         Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
00213         /* Bool_Glob == 1 */ 
00214         while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
00215         {
00216             Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
00217             /* Int_3_Loc == 7 */
00218             Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
00219             /* Int_3_Loc == 7 */
00220             Int_1_Loc += 1;
00221         } /* while */
00222         /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
00223         Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
00224         /* Int_Glob == 5 */
00225         Proc_1 (Ptr_Glob);
00226         for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
00227                              /* loop body executed twice */
00228         {
00229             if (Enum_Loc == Func_1 (Ch_Index, 'C'))
00230             /* then, not executed */
00231             {
00232                 Proc_6 (Ident_1, &Enum_Loc);
00233                 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
00234                 Int_2_Loc = Run_Index;
00235                 Int_Glob = Run_Index;
00236             }
00237         }
00238         /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
00239         Int_2_Loc = Int_2_Loc * Int_1_Loc;
00240         Int_1_Loc = Int_2_Loc / Int_3_Loc;
00241         Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
00242         /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
00243         Proc_2 (&Int_1_Loc);
00244         /* Int_1_Loc == 5 */
00245 
00246     } /* loop "for Run_Index" */
00247 
00248 }
00249 
00250 
00251 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines