Benchmark of DP, SP and Int. Arithmetic operations for ARM Cortex M7 MCU, Nucleo-144 Stm32F746 and Stm32F767 (modified from ddown post at "Arduino for STM32") by Jovan Ivković (JovanEps)

Dependencies:   mbed

Revision:
1:be78b18b8347
Parent:
0:43b96e9650ef
Child:
2:03cf226a5ba3
--- a/main.cpp	Sun Jan 01 21:50:13 2017 +0000
+++ b/main.cpp	Mon Jan 02 02:55:50 2017 +0000
@@ -35,10 +35,13 @@
 */
 double T,T1,T2,E1[5];
 int J,K,L;
+int argc = 0;   //Mod for nucleo. Change in code below if you want non-default loop count
 
-int argc=0;//Mod for nucleo. Change in code below if you want non-default loop count
-
-int whetstone()
+//************************************
+//**    Whetstone    64b-DP         **
+//**        SUB                     **
+//************************************
+int Whetstone() // ------------ Metoda -----------
 {
     pc.baud(115200);
     pc.printf("Beginning Whetstone benchmark at ");
@@ -52,12 +55,12 @@
     int II, JJ;
 
     /* added for this version */
-    long loopstart;
-    long startsec, finisec;
+    long loopstart = 0;
+    long startsec,finisec = 0;
     double KIPS;
     int continuous;
 
-    loopstart = 3000;       /* 1000 see the note about LOOP below */
+    loopstart = 25000;       /* 1000 see the note about LOOP below */
     continuous = 0;
 
     II = 1;     /* start at the first arg (temp use of II here) */
@@ -69,8 +72,9 @@
 ********************************************
 */
     timer.start();
-    //startsec = time(0);
-    startsec = timer.read_ms();
+    startsec = 0;
+    finisec = 0;
+    startsec = timer.read_us();
 
 /*
 ********************************************
@@ -113,14 +117,15 @@
     X3  = -1.0;
     X4  = -1.0;
 
-    for (I = 1; I <= N1; I++) {
+    for (I = 1; I <= N1; I++)
+    {
         X1 = (X1 + X2 + X3 - X4) * T;
         X2 = (X1 + X2 - X3 + X4) * T;
         X3 = (X1 - X2 + X3 + X4) * T;
         X4 = (-X1+ X2 + X3 + X4) * T;
     }
 #ifdef PRINTOUT
-    IF (JJ==II)POUT(N1,N1,N1,X1,X2,X3,X4);
+    IF (JJ==II) POUT(N1,N1,N1,X1,X2,X3,X4);
 #endif
 
 /*
@@ -133,7 +138,8 @@
     E1[3] = -1.0;
     E1[4] = -1.0;
 
-    for (I = 1; I <= N2; I++) {
+    for (I = 1; I <= N2; I++)
+    {
         E1[1] = ( E1[1] + E1[2] + E1[3] - E1[4]) * T;
         E1[2] = ( E1[1] + E1[2] - E1[3] + E1[4]) * T;
         E1[3] = ( E1[1] - E1[2] + E1[3] + E1[4]) * T;
@@ -141,7 +147,7 @@
     }
 
 #ifdef PRINTOUT
-    IF (JJ==II)POUT(N2,N3,N2,E1[1],E1[2],E1[3],E1[4]);
+    IF (JJ==II) POUT(N2,N3,N2,E1[1],E1[2],E1[3],E1[4]);
 #endif
 
 /*
@@ -150,10 +156,11 @@
 ********************************************
 */
     for (I = 1; I <= N3; I++)
+    {
         PA(E1);
-
+    }
 #ifdef PRINTOUT
-    IF (JJ==II)POUT(N3,N2,N2,E1[1],E1[2],E1[3],E1[4]);
+    IF (JJ==II) POUT(N3,N2,N2,E1[1],E1[2],E1[3],E1[4]);
 #endif
 
 /*
@@ -162,7 +169,8 @@
 ********************************************
 */
     J = 1;
-    for (I = 1; I <= N4; I++) {
+    for (I = 1; I <= N4; I++)
+    {
         if (J == 1)
             J = 2;
         else
@@ -180,7 +188,7 @@
     }
 
 #ifdef PRINTOUT
-    IF (JJ==II)POUT(N4,J,J,X1,X2,X3,X4);
+    IF (JJ==II) POUT(N4,J,J,X1,X2,X3,X4);
 #endif
 
 /*
@@ -194,7 +202,8 @@
     K = 2;
     L = 3;
 
-    for (I = 1; I <= N6; I++) {
+    for (I = 1; I <= N6; I++)
+    {
         J = J * (K-J) * (L-K);
         K = L * K - (L-J) * K;
         L = (L-K) * (K+J);
@@ -203,7 +212,7 @@
     }
 
 #ifdef PRINTOUT
-    IF (JJ==II)POUT(N6,J,K,E1[1],E1[2],E1[3],E1[4]);
+    IF (JJ==II) POUT(N6,J,K,E1[1],E1[2],E1[3],E1[4]);
 #endif
 
 /*
@@ -214,7 +223,8 @@
     X = 0.5;
     Y = 0.5;
 
-    for (I = 1; I <= N7; I++) {
+    for (I = 1; I <= N7; I++)
+    {
         X = T * DATAN(T2*DSIN(X)*DCOS(X)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
         Y = T * DATAN(T2*DSIN(Y)*DCOS(Y)/(DCOS(X+Y)+DCOS(X-Y)-1.0));
     }
@@ -233,8 +243,9 @@
     Z = 1.0;
 
     for (I = 1; I <= N8; I++)
+    {
         P3(X,Y,&Z);
-
+    }
 #ifdef PRINTOUT
     IF (JJ==II)POUT(N8,J,K,X,Y,Z,Z);
 #endif
@@ -252,10 +263,11 @@
     E1[3] = 3.0;
 
     for (I = 1; I <= N9; I++)
+    {
         P0();
-
+    }
 #ifdef PRINTOUT
-    IF (JJ==II)POUT(N9,J,K,E1[1],E1[2],E1[3],E1[4]);
+    IF (JJ==II) POUT(N9,J,K,E1[1],E1[2],E1[3],E1[4]);
 #endif
 
 /*
@@ -266,7 +278,8 @@
     J = 2;
     K = 3;
 
-    for (I = 1; I <= N10; I++) {
+    for (I = 1; I <= N10; I++)
+    {
         J = J + K;
         K = J + K;
         J = K - J;
@@ -274,7 +287,7 @@
     }
 
 #ifdef PRINTOUT
-    IF (JJ==II)POUT(N10,J,K,X1,X2,X3,X4);
+    IF (JJ==II) POUT(N10,J,K,X1,X2,X3,X4);
 #endif
 
 /*
@@ -285,10 +298,11 @@
     X = 0.75;
 
     for (I = 1; I <= N11; I++)
+    {
         X = DSQRT(DEXP(DLOG(X)/T1));
-
+    }
 #ifdef PRINTOUT
-    IF (JJ==II)POUT(N11,J,K,X,X,X,X);
+    IF (JJ==II) POUT(N11,J,K,X,X,X,X);
 #endif
 
 /*
@@ -305,8 +319,8 @@
 ********************************************
 */
    // finisec = time(0);
-    finisec = timer.read_ms();
-    timer.reset();
+    finisec = timer.read_us();
+    //timer.reset();
 
 /*
 *--------------------------------------------------------------------
@@ -319,29 +333,33 @@
 */
     pc.printf(" kraj \n");
     double vreme;
-    vreme = (finisec - startsec) / 1000;
+    vreme = (finisec - startsec) / 1000000;
     
     if (vreme <= 0)
      {
         pc.printf("Insufficient duration- Increase the LOOP count \n");
+        finisec = 0; 
+        startsec = 0;
         return 1;
      }
 
-    pc.printf("Loops: %ld, Iterations: %d, Duration: %ld sec. \n",
+    pc.printf("Loops: %ld , \t Iterations: %d, \t Duration: %.3f sec. \n",
             LOOP, II, vreme);
 
     KIPS = (100.0 * LOOP * II) / vreme ;
    
   //  if (KIPS >= 1000.0)
-  //      pc.printf("C Converted Double Precision Whetstones: %.1f MIPS \n\n", KIPS / 1000);
+  //      pc.printf("C Converted Double Precision Whetstones: %.3f MIPS \n\n", KIPS / 1000);
   //  else
-  //      pc.printf("C Converted Double Precision Whetstones: %.1f KIPS \n\n", KIPS);
+  //      pc.printf("C Converted Double Precision Whetstones: %.3f KIPS \n\n", KIPS);
         
-        pc.printf("C Converted Double Precision Whetstones: %.1f KIPS \n\n", KIPS);
+        pc.printf("C Converted Double Precision Whetstones: %.3f MIPS \n\n", KIPS / 1000);
 
     if (continuous)
         goto LCONT;
 
+    finisec = 0; 
+    startsec = 0;
     return 1;
 }
 
@@ -386,14 +404,21 @@
 }
 #endif   
 
-
-int main() {
-    int rez;  
+//*********************************
+//**         MAIN block          **
+//*********************************
+int main()
+{
+    int rez=0;  
     printf("\n My Benchamrk example for Whetstones \n");
     
-    while(1) {
-        myled=1;
-        rez = whetstone();
-        myled=0;
-     }
+    while(1)
+    {
+        myled=1-rez;
+    
+        rez = Whetstone(); //Call of Whetstone banch metod
+    
+        myled=1-rez;
+        wait_us(0.3);
+    }
 }
\ No newline at end of file