Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 //******************************************************** 00002 //** "DHRYSTONE" Benchmark C, Version 2.1 ****** 00003 //** for ARM Cortex-M7 MCU C++ ****** 00004 //** ( ST Nucleo-144 Stm32F746 and Stm32F767 ) ****** 00005 //** Based on work by Ken Boakby for Ardiono IDE ****** 00006 //** modified by ****** 00007 //** Jovan Ivkovic 2017. ****** 00008 //** JovanEps (jovan.eps@gmail.com). ****** 00009 //******************************************************** 00010 #include "mbed.h" 00011 #include "dhry.h" 00012 DigitalOut myled(LED1); 00013 Serial pc(USBTX, USBRX); 00014 Timer timer; 00015 00016 #include <stdlib.h> 00017 #include <stdio.h> 00018 #include <string.h> 00019 #include <math.h> 00020 /* the following is optional depending on the timing function used */ 00021 #include <time.h> 00022 00023 00024 /* Global Variables: */ 00025 00026 Rec_Pointer Ptr_Glob,Next_Ptr_Glob; 00027 int Int_Glob; 00028 Booleann Bool_Glob; 00029 char Ch_1_Glob, Ch_2_Glob; 00030 int Arr_1_Glob[25]; /* <-- changed from 50 */ 00031 int Arr_2_Glob[25][25]; /* <-- changed from 50 */ 00032 00033 char Reg_Define[] = "Register option selected."; 00034 00035 #ifndef ROPT 00036 #define REG 00037 /* REG becomes defined as empty */ 00038 /* i.e. no register variables */ 00039 #else 00040 #define REG register 00041 #endif 00042 00043 00044 /* Procedure for the assignment of structures, */ 00045 /* if the C compiler doesn't support this feature */ 00046 #ifdef NOSTRUCTASSIGN 00047 memcpy (d, s, l) 00048 register char *d; 00049 register char *s; 00050 register int l; 00051 { 00052 while (l--) *d++ = *s++; 00053 } 00054 #endif 00055 00056 /* variables for time measurement: */ 00057 00058 #define Too_Small_Time 1000000 00059 /* Measurements should last at least 1-2 seconds */ 00060 00061 uint32_t Begin_Time, 00062 End_Time, 00063 User_Time; 00064 00065 double Microseconds, 00066 Dhrystones_Per_Second, 00067 Vax_Mips; 00068 00069 /* end of variables for time measurement */ 00070 00071 void Proc_1( REG Rec_Pointer Ptr_Val_Par ); 00072 void Proc_2( One_Fifty * Int_Par_Ref ); 00073 void Proc_3( Rec_Pointer * Ptr_Ref_Par ); 00074 void Proc_4( void ); 00075 void Proc_5( void ); 00076 00077 00078 00079 //************************************ 00080 //** "DHRYSTONE" Benchmark ** 00081 //** SUB ** 00082 //************************************ 00083 void DHRYSTONE() // ------------ Metoda ----------- 00084 { 00085 //* main program, corresponds to procedures */ 00086 //************************************************************** 00087 One_Fifty Int_1_Loc; 00088 REG One_Fifty Int_2_Loc; 00089 One_Fifty Int_3_Loc; 00090 REG char Ch_Index; 00091 Enumeration Enum_Loc; 00092 Str_30 Str_1_Loc; 00093 Str_30 Str_2_Loc; 00094 REG long Run_Index; 00095 REG long Number_Of_Runs; 00096 00097 //************************************************************** 00098 /* Initializations */ 00099 //************************************************************** 00100 00101 pc.printf("\n Dhrystone Benchmark, Version 2.1 (Language: C)"); 00102 pc.printf("Beginning DHRYSTONE Benchmark \n"); 00103 pc.printf("Default MCU clock is 216 MHz \n"); 00104 00105 Next_Ptr_Glob = (Rec_Pointer)malloc (sizeof (Rec_Type)); 00106 Ptr_Glob = (Rec_Pointer)malloc (sizeof (Rec_Type)); 00107 00108 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob; 00109 Ptr_Glob->Discr = Ident_1; 00110 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3; 00111 Ptr_Glob->variant.var_1.Int_Comp = 40; 00112 strcpy (Ptr_Glob->variant.var_1.Str_Comp, 00113 "DHRYSTONE PROGRAM, SOME STRING"); 00114 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); 00115 00116 Arr_2_Glob [8][7] = 10; 00117 /* Was missing in published program. Without this statement, */ 00118 /* Arr_2_Glob [8][7] would have an undefined value. */ 00119 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ 00120 /* overflow may occur for this array element. */ 00121 00122 Number_Of_Runs = 2000000; 00123 00124 pc.printf("Execution starts, "); 00125 pc.printf("%d", Number_Of_Runs); 00126 pc.printf("\n runs through Dhrystone"); 00127 pc.printf("\n") ; 00128 00129 /***************/ 00130 /* Start timer */ 00131 /***************/ 00132 timer.start(); 00133 Begin_Time = timer.read_us(); 00134 //**************************** 00135 00136 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index) { 00137 Proc_5(); 00138 Proc_4(); 00139 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */ 00140 Int_1_Loc = 2; 00141 Int_2_Loc = 3; 00142 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING"); 00143 Enum_Loc = Ident_2; 00144 Bool_Glob = !Func_2(Str_1_Loc, Str_2_Loc); 00145 /* Bool_Glob == 1 */ 00146 while (Int_1_Loc < Int_2_Loc) { /* loop body executed once */ 00147 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc; 00148 /* Int_3_Loc == 7 */ 00149 Proc_7(Int_1_Loc, Int_2_Loc, &Int_3_Loc); 00150 /* Int_3_Loc == 7 */ 00151 Int_1_Loc += 1; 00152 } /* while */ 00153 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ 00154 Proc_8(Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc); 00155 /* Int_Glob == 5 */ 00156 Proc_1 (Ptr_Glob); 00157 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) 00158 /* loop body executed twice */ 00159 { 00160 if (Enum_Loc == Func_1(Ch_Index, 'C')) 00161 /* then, not executed */ 00162 { 00163 Proc_6(Ident_1, &Enum_Loc); 00164 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING"); 00165 Int_2_Loc = Run_Index; 00166 Int_Glob = Run_Index; 00167 } 00168 } 00169 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */ 00170 Int_2_Loc = Int_2_Loc * Int_1_Loc; 00171 Int_1_Loc = Int_2_Loc / Int_3_Loc; 00172 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc; 00173 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */ 00174 Proc_2 (&Int_1_Loc); 00175 /* Int_1_Loc == 5 */ 00176 00177 } /* loop "for Run_Index" */ 00178 00179 /**************/ 00180 /* Stop timer */ 00181 /**************/ 00182 00183 End_Time = timer.read_us(); 00184 User_Time = End_Time - Begin_Time; 00185 00186 pc.printf("\n Execution ends in : "); 00187 pc.printf("%d us \n", User_Time); 00188 00189 if (User_Time < Too_Small_Time) { 00190 pc.printf("\n Measured time too small to obtain meaningful results"); 00191 pc.printf("\n Please increase number of runs"); 00192 pc.printf("\n"); 00193 } else { 00194 Microseconds = (double) User_Time / (double) Number_Of_Runs; 00195 Dhrystones_Per_Second = (double) Number_Of_Runs / ((double) User_Time / 1000000.0); 00196 Vax_Mips = Dhrystones_Per_Second / 1757.0; 00197 } 00198 pc.printf("\n Microseconds for one run through Dhrystone: "); 00199 pc.printf("%9.2f \n", Microseconds); 00200 pc.printf("\n Dhrystones per Second: "); 00201 pc.printf("%9.2f \n",Dhrystones_Per_Second); 00202 pc.printf("\n VAX MIPS rating = "); 00203 pc.printf("%9.2f \n",Vax_Mips); 00204 00205 timer.reset(); 00206 timer.stop(); 00207 } 00208 00209 //************************************************************** 00210 void Proc_1( REG Rec_Pointer Ptr_Val_Par ) 00211 //************************************************************** 00212 { 00213 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; 00214 /* == Ptr_Glob_Next */ 00215 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */ 00216 /* corresponds to "rename" in Ada, "with" in Pascal */ 00217 00218 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob); 00219 Ptr_Val_Par->variant.var_1.Int_Comp = 5; 00220 Next_Record->variant.var_1.Int_Comp 00221 = Ptr_Val_Par->variant.var_1.Int_Comp; 00222 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp; 00223 Proc_3 (&Next_Record->Ptr_Comp); 00224 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp 00225 == Ptr_Glob->Ptr_Comp */ 00226 if (Next_Record->Discr == Ident_1) 00227 /* then, executed */ 00228 { 00229 Next_Record->variant.var_1.Int_Comp = 6; 00230 Proc_6(Ptr_Val_Par->variant.var_1.Enum_Comp, 00231 &Next_Record->variant.var_1.Enum_Comp); 00232 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp; 00233 Proc_7(Next_Record->variant.var_1.Int_Comp, 10, 00234 &Next_Record->variant.var_1.Int_Comp); 00235 } else /* not executed */ 00236 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp); 00237 } /* Proc_1 */ 00238 00239 //************************************************************** 00240 void Proc_2( One_Fifty * Int_Par_Ref ) 00241 { 00242 //************************************************************** 00243 One_Fifty Int_Loc; 00244 Enumeration Enum_Loc; 00245 00246 Int_Loc = *Int_Par_Ref + 10; 00247 do /* executed once */ 00248 if (Ch_1_Glob == 'A') 00249 /* then, executed */ 00250 { 00251 Int_Loc -= 1; 00252 *Int_Par_Ref = Int_Loc - Int_Glob; 00253 Enum_Loc = Ident_1; 00254 } /* if */ 00255 while (Enum_Loc != Ident_1); /* true */ 00256 } 00257 00258 //************************************************************** 00259 void Proc_3( Rec_Pointer * Ptr_Ref_Par ) 00260 { 00261 //************************************************************** 00262 if (Ptr_Glob != Null) { 00263 /* then, executed */ 00264 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp; 00265 } 00266 Proc_7(10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp); 00267 } /* Proc_3 */ 00268 00269 //************************************************************** 00270 void Proc_4( void ) 00271 { 00272 //************************************************************** 00273 Booleann Bool_Loc; 00274 00275 Bool_Loc = Ch_1_Glob == 'A'; 00276 Bool_Glob = Bool_Loc | Bool_Glob; 00277 Ch_2_Glob = 'B'; 00278 } /* Proc_4 */ 00279 00280 //************************************************************** 00281 void Proc_5( void ) 00282 { 00283 //************************************************************** 00284 Ch_1_Glob = 'A'; 00285 Bool_Glob = false; 00286 } /* Proc_5 */ 00287 00288 00289 00290 Booleann Func_3( Enumeration Enum_Par_Val ); 00291 00292 //************************************************************** 00293 void Proc_6( Enumeration Enum_Val_Par, Enumeration * Enum_Ref_Par ) 00294 { 00295 //************************************************************** 00296 *Enum_Ref_Par = Enum_Val_Par; 00297 if (! Func_3 (Enum_Val_Par)) 00298 /* then, not executed */ 00299 *Enum_Ref_Par = Ident_4; 00300 switch (Enum_Val_Par) { 00301 case Ident_1: 00302 *Enum_Ref_Par = Ident_1; 00303 break; 00304 case Ident_2: 00305 if (Int_Glob > 100) 00306 /* then */ 00307 *Enum_Ref_Par = Ident_1; 00308 else *Enum_Ref_Par = Ident_4; 00309 break; 00310 case Ident_3: /* executed */ 00311 *Enum_Ref_Par = Ident_2; 00312 break; 00313 case Ident_4: 00314 break; 00315 case Ident_5: 00316 *Enum_Ref_Par = Ident_3; 00317 break; 00318 } /* switch */ 00319 } 00320 00321 //************************************************************** 00322 void Proc_7( One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, 00323 One_Fifty * Int_Par_Ref ) 00324 { 00325 //************************************************************** 00326 One_Fifty Int_Loc; 00327 00328 Int_Loc = Int_1_Par_Val + 2; 00329 *Int_Par_Ref = Int_2_Par_Val + Int_Loc; 00330 } /* Proc_7 */ 00331 00332 //************************************************************** 00333 void Proc_8( Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, 00334 int Int_1_Par_Val, int Int_2_Par_Val ) 00335 { 00336 //************************************************************** 00337 REG One_Fifty Int_Index; 00338 REG One_Fifty Int_Loc; 00339 00340 Int_Loc = Int_1_Par_Val + 5; 00341 Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val; 00342 Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc]; 00343 Arr_1_Par_Ref [Int_Loc+15] = Int_Loc; 00344 for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index) 00345 Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc; 00346 Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1; 00347 Arr_2_Par_Ref [Int_Loc+10] [Int_Loc] = Arr_1_Par_Ref [Int_Loc]; 00348 Int_Glob = 5; 00349 } /* Proc_8 */ 00350 00351 //************************************************************** 00352 Enumeration Func_1( Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val ) 00353 { 00354 //************************************************************** 00355 00356 Capital_Letter Ch_1_Loc; 00357 Capital_Letter Ch_2_Loc; 00358 00359 Ch_1_Loc = Ch_1_Par_Val; 00360 Ch_2_Loc = Ch_1_Loc; 00361 if (Ch_2_Loc != Ch_2_Par_Val) 00362 /* then, executed */ 00363 return (Ident_1); 00364 else { /* not executed */ 00365 Ch_1_Glob = Ch_1_Loc; 00366 return (Ident_2); 00367 } 00368 } /* Func_1 */ 00369 00370 //************************************************************** 00371 Booleann Func_2( Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref ) 00372 { 00373 //************************************************************** 00374 00375 REG One_Thirty Int_Loc; 00376 Capital_Letter Ch_Loc; 00377 00378 Int_Loc = 2; 00379 while (Int_Loc <= 2) /* loop body executed once */ 00380 if (Func_1 (Str_1_Par_Ref[Int_Loc], 00381 Str_2_Par_Ref[Int_Loc+1]) == Ident_1) 00382 /* then, executed */ 00383 { 00384 Ch_Loc = 'A'; 00385 Int_Loc += 1; 00386 } /* if, while */ 00387 if (Ch_Loc >= 'W' && Ch_Loc < 'Z') 00388 /* then, not executed */ 00389 Int_Loc = 7; 00390 if (Ch_Loc == 'R') 00391 /* then, not executed */ 00392 return (true); 00393 else { /* executed */ 00394 if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0) 00395 /* then, not executed */ 00396 { 00397 Int_Loc += 7; 00398 Int_Glob = Int_Loc; 00399 return (true); 00400 } else /* executed */ 00401 return (false); 00402 } /* if Ch_Loc */ 00403 } /* Func_2 */ 00404 00405 //************************************************************** 00406 Booleann Func_3( Enumeration Enum_Par_Val ) 00407 { 00408 //************************************************************** 00409 Enumeration Enum_Loc; 00410 00411 Enum_Loc = Enum_Par_Val; 00412 if (Enum_Loc == Ident_3) 00413 /* then, executed */ 00414 return (true); 00415 else /* not executed */ 00416 return (false); 00417 } /* Func_3 */ 00418 //************************************************************** 00419 00420 00421 00422 //********************************* 00423 //** MAIN block ** 00424 //********************************* 00425 int main() 00426 { 00427 pc.baud(9600); 00428 00429 while(1) { 00430 myled= !myled; 00431 00432 DHRYSTONE(); //Call 00433 00434 myled= !myled; 00435 wait_us(3); 00436 } 00437 } 00438 00439 00440 //**************************************************************
Generated on Thu Aug 4 2022 21:39:21 by
1.7.2