Jovan Ivković
/
Benchmark_Whetstone
Whetstone benchmark DP for ARM Cortex M7 - ST Nucleo-144 STM32F7xx
main.cpp@0:43b96e9650ef, 2017-01-01 (annotated)
- Committer:
- JovanEps
- Date:
- Sun Jan 01 21:50:13 2017 +0000
- Revision:
- 0:43b96e9650ef
- Child:
- 1:be78b18b8347
ver1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JovanEps | 0:43b96e9650ef | 1 | //******************************************************** |
JovanEps | 0:43b96e9650ef | 2 | //** Nucleo-144 Stm32F746 and Stm32F767 benchmark ****** |
JovanEps | 0:43b96e9650ef | 3 | //** Jovan Ivkovic - 2016 ****** |
JovanEps | 0:43b96e9650ef | 4 | //******************************************************** |
JovanEps | 0:43b96e9650ef | 5 | #include "mbed.h" |
JovanEps | 0:43b96e9650ef | 6 | DigitalOut myled(LED1); |
JovanEps | 0:43b96e9650ef | 7 | Serial pc(USBTX, USBRX); |
JovanEps | 0:43b96e9650ef | 8 | Timer timer; |
JovanEps | 0:43b96e9650ef | 9 | |
JovanEps | 0:43b96e9650ef | 10 | #include <stdlib.h> |
JovanEps | 0:43b96e9650ef | 11 | #include <stdio.h> |
JovanEps | 0:43b96e9650ef | 12 | #include <string.h> |
JovanEps | 0:43b96e9650ef | 13 | #include <math.h> |
JovanEps | 0:43b96e9650ef | 14 | /* the following is optional depending on the timing function used */ |
JovanEps | 0:43b96e9650ef | 15 | #include <time.h> |
JovanEps | 0:43b96e9650ef | 16 | |
JovanEps | 0:43b96e9650ef | 17 | /* map the FORTRAN math functions, etc. to the C versions */ |
JovanEps | 0:43b96e9650ef | 18 | #define DSIN sin |
JovanEps | 0:43b96e9650ef | 19 | #define DCOS cos |
JovanEps | 0:43b96e9650ef | 20 | #define DATAN atan |
JovanEps | 0:43b96e9650ef | 21 | #define DLOG log |
JovanEps | 0:43b96e9650ef | 22 | #define DEXP exp |
JovanEps | 0:43b96e9650ef | 23 | #define DSQRT sqrt |
JovanEps | 0:43b96e9650ef | 24 | #define IF if |
JovanEps | 0:43b96e9650ef | 25 | |
JovanEps | 0:43b96e9650ef | 26 | /* function prototypes */ |
JovanEps | 0:43b96e9650ef | 27 | void POUT(long N, long J, long K, double X1, double X2, double X3, double X4); |
JovanEps | 0:43b96e9650ef | 28 | void PA(double E[]); |
JovanEps | 0:43b96e9650ef | 29 | void P0(void); |
JovanEps | 0:43b96e9650ef | 30 | void P3(double X, double Y, double *Z); |
JovanEps | 0:43b96e9650ef | 31 | #define USAGE "usage: whetdc [-c] [loops]\n" |
JovanEps | 0:43b96e9650ef | 32 | |
JovanEps | 0:43b96e9650ef | 33 | /* |
JovanEps | 0:43b96e9650ef | 34 | COMMON T,T1,T2,E1(4),J,K,L |
JovanEps | 0:43b96e9650ef | 35 | */ |
JovanEps | 0:43b96e9650ef | 36 | double T,T1,T2,E1[5]; |
JovanEps | 0:43b96e9650ef | 37 | int J,K,L; |
JovanEps | 0:43b96e9650ef | 38 | |
JovanEps | 0:43b96e9650ef | 39 | int argc=0;//Mod for nucleo. Change in code below if you want non-default loop count |
JovanEps | 0:43b96e9650ef | 40 | |
JovanEps | 0:43b96e9650ef | 41 | int whetstone() |
JovanEps | 0:43b96e9650ef | 42 | { |
JovanEps | 0:43b96e9650ef | 43 | pc.baud(115200); |
JovanEps | 0:43b96e9650ef | 44 | pc.printf("Beginning Whetstone benchmark at "); |
JovanEps | 0:43b96e9650ef | 45 | |
JovanEps | 0:43b96e9650ef | 46 | pc.printf("default 216 MHz ...\n"); |
JovanEps | 0:43b96e9650ef | 47 | /* used in the FORTRAN version */ |
JovanEps | 0:43b96e9650ef | 48 | long I; |
JovanEps | 0:43b96e9650ef | 49 | long N1, N2, N3, N4, N6, N7, N8, N9, N10, N11; |
JovanEps | 0:43b96e9650ef | 50 | double X1,X2,X3,X4,X,Y,Z; |
JovanEps | 0:43b96e9650ef | 51 | long LOOP; |
JovanEps | 0:43b96e9650ef | 52 | int II, JJ; |
JovanEps | 0:43b96e9650ef | 53 | |
JovanEps | 0:43b96e9650ef | 54 | /* added for this version */ |
JovanEps | 0:43b96e9650ef | 55 | long loopstart; |
JovanEps | 0:43b96e9650ef | 56 | long startsec, finisec; |
JovanEps | 0:43b96e9650ef | 57 | double KIPS; |
JovanEps | 0:43b96e9650ef | 58 | int continuous; |
JovanEps | 0:43b96e9650ef | 59 | |
JovanEps | 0:43b96e9650ef | 60 | loopstart = 3000; /* 1000 see the note about LOOP below */ |
JovanEps | 0:43b96e9650ef | 61 | continuous = 0; |
JovanEps | 0:43b96e9650ef | 62 | |
JovanEps | 0:43b96e9650ef | 63 | II = 1; /* start at the first arg (temp use of II here) */ |
JovanEps | 0:43b96e9650ef | 64 | |
JovanEps | 0:43b96e9650ef | 65 | LCONT: |
JovanEps | 0:43b96e9650ef | 66 | /* |
JovanEps | 0:43b96e9650ef | 67 | ******************************************** |
JovanEps | 0:43b96e9650ef | 68 | * Start benchmark timing at this point. |
JovanEps | 0:43b96e9650ef | 69 | ******************************************** |
JovanEps | 0:43b96e9650ef | 70 | */ |
JovanEps | 0:43b96e9650ef | 71 | timer.start(); |
JovanEps | 0:43b96e9650ef | 72 | //startsec = time(0); |
JovanEps | 0:43b96e9650ef | 73 | startsec = timer.read_ms(); |
JovanEps | 0:43b96e9650ef | 74 | |
JovanEps | 0:43b96e9650ef | 75 | /* |
JovanEps | 0:43b96e9650ef | 76 | ******************************************** |
JovanEps | 0:43b96e9650ef | 77 | * The actual benchmark starts here. |
JovanEps | 0:43b96e9650ef | 78 | ******************************************** |
JovanEps | 0:43b96e9650ef | 79 | */ |
JovanEps | 0:43b96e9650ef | 80 | T = .499975; |
JovanEps | 0:43b96e9650ef | 81 | T1 = 0.50025; |
JovanEps | 0:43b96e9650ef | 82 | T2 = 2.0; |
JovanEps | 0:43b96e9650ef | 83 | /* |
JovanEps | 0:43b96e9650ef | 84 | ******************************************** |
JovanEps | 0:43b96e9650ef | 85 | * With loopcount LOOP=10, one million Whetstone instructions |
JovanEps | 0:43b96e9650ef | 86 | * will be executed in EACH MAJOR LOOP..A MAJOR LOOP IS EXECUTED |
JovanEps | 0:43b96e9650ef | 87 | * 'II' TIMES TO INCREASE WALL-CLOCK TIMING ACCURACY. |
JovanEps | 0:43b96e9650ef | 88 | * |
JovanEps | 0:43b96e9650ef | 89 | * LOOP = 1000; |
JovanEps | 0:43b96e9650ef | 90 | */ |
JovanEps | 0:43b96e9650ef | 91 | LOOP = loopstart; |
JovanEps | 0:43b96e9650ef | 92 | II = 1; |
JovanEps | 0:43b96e9650ef | 93 | JJ = 1; |
JovanEps | 0:43b96e9650ef | 94 | |
JovanEps | 0:43b96e9650ef | 95 | IILOOP: |
JovanEps | 0:43b96e9650ef | 96 | N1 = 0; |
JovanEps | 0:43b96e9650ef | 97 | N2 = 12 * LOOP; |
JovanEps | 0:43b96e9650ef | 98 | N3 = 14 * LOOP; |
JovanEps | 0:43b96e9650ef | 99 | N4 = 345 * LOOP; |
JovanEps | 0:43b96e9650ef | 100 | N6 = 210 * LOOP; |
JovanEps | 0:43b96e9650ef | 101 | N7 = 32 * LOOP; |
JovanEps | 0:43b96e9650ef | 102 | N8 = 899 * LOOP; |
JovanEps | 0:43b96e9650ef | 103 | N9 = 616 * LOOP; |
JovanEps | 0:43b96e9650ef | 104 | N10 = 0; |
JovanEps | 0:43b96e9650ef | 105 | N11 = 93 * LOOP; |
JovanEps | 0:43b96e9650ef | 106 | /* |
JovanEps | 0:43b96e9650ef | 107 | ******************************************** |
JovanEps | 0:43b96e9650ef | 108 | * Module 1: Simple identifiers |
JovanEps | 0:43b96e9650ef | 109 | ******************************************** |
JovanEps | 0:43b96e9650ef | 110 | */ |
JovanEps | 0:43b96e9650ef | 111 | X1 = 1.0; |
JovanEps | 0:43b96e9650ef | 112 | X2 = -1.0; |
JovanEps | 0:43b96e9650ef | 113 | X3 = -1.0; |
JovanEps | 0:43b96e9650ef | 114 | X4 = -1.0; |
JovanEps | 0:43b96e9650ef | 115 | |
JovanEps | 0:43b96e9650ef | 116 | for (I = 1; I <= N1; I++) { |
JovanEps | 0:43b96e9650ef | 117 | X1 = (X1 + X2 + X3 - X4) * T; |
JovanEps | 0:43b96e9650ef | 118 | X2 = (X1 + X2 - X3 + X4) * T; |
JovanEps | 0:43b96e9650ef | 119 | X3 = (X1 - X2 + X3 + X4) * T; |
JovanEps | 0:43b96e9650ef | 120 | X4 = (-X1+ X2 + X3 + X4) * T; |
JovanEps | 0:43b96e9650ef | 121 | } |
JovanEps | 0:43b96e9650ef | 122 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 123 | IF (JJ==II)POUT(N1,N1,N1,X1,X2,X3,X4); |
JovanEps | 0:43b96e9650ef | 124 | #endif |
JovanEps | 0:43b96e9650ef | 125 | |
JovanEps | 0:43b96e9650ef | 126 | /* |
JovanEps | 0:43b96e9650ef | 127 | ******************************************** |
JovanEps | 0:43b96e9650ef | 128 | * Module 2: Array elements |
JovanEps | 0:43b96e9650ef | 129 | ******************************************** |
JovanEps | 0:43b96e9650ef | 130 | */ |
JovanEps | 0:43b96e9650ef | 131 | E1[1] = 1.0; |
JovanEps | 0:43b96e9650ef | 132 | E1[2] = -1.0; |
JovanEps | 0:43b96e9650ef | 133 | E1[3] = -1.0; |
JovanEps | 0:43b96e9650ef | 134 | E1[4] = -1.0; |
JovanEps | 0:43b96e9650ef | 135 | |
JovanEps | 0:43b96e9650ef | 136 | for (I = 1; I <= N2; I++) { |
JovanEps | 0:43b96e9650ef | 137 | E1[1] = ( E1[1] + E1[2] + E1[3] - E1[4]) * T; |
JovanEps | 0:43b96e9650ef | 138 | E1[2] = ( E1[1] + E1[2] - E1[3] + E1[4]) * T; |
JovanEps | 0:43b96e9650ef | 139 | E1[3] = ( E1[1] - E1[2] + E1[3] + E1[4]) * T; |
JovanEps | 0:43b96e9650ef | 140 | E1[4] = (-E1[1] + E1[2] + E1[3] + E1[4]) * T; |
JovanEps | 0:43b96e9650ef | 141 | } |
JovanEps | 0:43b96e9650ef | 142 | |
JovanEps | 0:43b96e9650ef | 143 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 144 | IF (JJ==II)POUT(N2,N3,N2,E1[1],E1[2],E1[3],E1[4]); |
JovanEps | 0:43b96e9650ef | 145 | #endif |
JovanEps | 0:43b96e9650ef | 146 | |
JovanEps | 0:43b96e9650ef | 147 | /* |
JovanEps | 0:43b96e9650ef | 148 | ******************************************** |
JovanEps | 0:43b96e9650ef | 149 | * Module 3: Array as parameter |
JovanEps | 0:43b96e9650ef | 150 | ******************************************** |
JovanEps | 0:43b96e9650ef | 151 | */ |
JovanEps | 0:43b96e9650ef | 152 | for (I = 1; I <= N3; I++) |
JovanEps | 0:43b96e9650ef | 153 | PA(E1); |
JovanEps | 0:43b96e9650ef | 154 | |
JovanEps | 0:43b96e9650ef | 155 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 156 | IF (JJ==II)POUT(N3,N2,N2,E1[1],E1[2],E1[3],E1[4]); |
JovanEps | 0:43b96e9650ef | 157 | #endif |
JovanEps | 0:43b96e9650ef | 158 | |
JovanEps | 0:43b96e9650ef | 159 | /* |
JovanEps | 0:43b96e9650ef | 160 | ******************************************** |
JovanEps | 0:43b96e9650ef | 161 | * Module 4: Conditional jumps |
JovanEps | 0:43b96e9650ef | 162 | ******************************************** |
JovanEps | 0:43b96e9650ef | 163 | */ |
JovanEps | 0:43b96e9650ef | 164 | J = 1; |
JovanEps | 0:43b96e9650ef | 165 | for (I = 1; I <= N4; I++) { |
JovanEps | 0:43b96e9650ef | 166 | if (J == 1) |
JovanEps | 0:43b96e9650ef | 167 | J = 2; |
JovanEps | 0:43b96e9650ef | 168 | else |
JovanEps | 0:43b96e9650ef | 169 | J = 3; |
JovanEps | 0:43b96e9650ef | 170 | |
JovanEps | 0:43b96e9650ef | 171 | if (J > 2) |
JovanEps | 0:43b96e9650ef | 172 | J = 0; |
JovanEps | 0:43b96e9650ef | 173 | else |
JovanEps | 0:43b96e9650ef | 174 | J = 1; |
JovanEps | 0:43b96e9650ef | 175 | |
JovanEps | 0:43b96e9650ef | 176 | if (J < 1) |
JovanEps | 0:43b96e9650ef | 177 | J = 1; |
JovanEps | 0:43b96e9650ef | 178 | else |
JovanEps | 0:43b96e9650ef | 179 | J = 0; |
JovanEps | 0:43b96e9650ef | 180 | } |
JovanEps | 0:43b96e9650ef | 181 | |
JovanEps | 0:43b96e9650ef | 182 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 183 | IF (JJ==II)POUT(N4,J,J,X1,X2,X3,X4); |
JovanEps | 0:43b96e9650ef | 184 | #endif |
JovanEps | 0:43b96e9650ef | 185 | |
JovanEps | 0:43b96e9650ef | 186 | /* |
JovanEps | 0:43b96e9650ef | 187 | ******************************************** |
JovanEps | 0:43b96e9650ef | 188 | * Module 5: Omitted |
JovanEps | 0:43b96e9650ef | 189 | * Module 6: Integer arithmetic |
JovanEps | 0:43b96e9650ef | 190 | ******************************************** |
JovanEps | 0:43b96e9650ef | 191 | */ |
JovanEps | 0:43b96e9650ef | 192 | |
JovanEps | 0:43b96e9650ef | 193 | J = 1; |
JovanEps | 0:43b96e9650ef | 194 | K = 2; |
JovanEps | 0:43b96e9650ef | 195 | L = 3; |
JovanEps | 0:43b96e9650ef | 196 | |
JovanEps | 0:43b96e9650ef | 197 | for (I = 1; I <= N6; I++) { |
JovanEps | 0:43b96e9650ef | 198 | J = J * (K-J) * (L-K); |
JovanEps | 0:43b96e9650ef | 199 | K = L * K - (L-J) * K; |
JovanEps | 0:43b96e9650ef | 200 | L = (L-K) * (K+J); |
JovanEps | 0:43b96e9650ef | 201 | E1[L-1] = J + K + L; |
JovanEps | 0:43b96e9650ef | 202 | E1[K-1] = J * K * L; |
JovanEps | 0:43b96e9650ef | 203 | } |
JovanEps | 0:43b96e9650ef | 204 | |
JovanEps | 0:43b96e9650ef | 205 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 206 | IF (JJ==II)POUT(N6,J,K,E1[1],E1[2],E1[3],E1[4]); |
JovanEps | 0:43b96e9650ef | 207 | #endif |
JovanEps | 0:43b96e9650ef | 208 | |
JovanEps | 0:43b96e9650ef | 209 | /* |
JovanEps | 0:43b96e9650ef | 210 | ******************************************** |
JovanEps | 0:43b96e9650ef | 211 | * Module 7: Trigonometric functions |
JovanEps | 0:43b96e9650ef | 212 | ******************************************** |
JovanEps | 0:43b96e9650ef | 213 | */ |
JovanEps | 0:43b96e9650ef | 214 | X = 0.5; |
JovanEps | 0:43b96e9650ef | 215 | Y = 0.5; |
JovanEps | 0:43b96e9650ef | 216 | |
JovanEps | 0:43b96e9650ef | 217 | for (I = 1; I <= N7; I++) { |
JovanEps | 0:43b96e9650ef | 218 | X = T * DATAN(T2*DSIN(X)*DCOS(X)/(DCOS(X+Y)+DCOS(X-Y)-1.0)); |
JovanEps | 0:43b96e9650ef | 219 | Y = T * DATAN(T2*DSIN(Y)*DCOS(Y)/(DCOS(X+Y)+DCOS(X-Y)-1.0)); |
JovanEps | 0:43b96e9650ef | 220 | } |
JovanEps | 0:43b96e9650ef | 221 | |
JovanEps | 0:43b96e9650ef | 222 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 223 | IF (JJ==II)POUT(N7,J,K,X,X,Y,Y); |
JovanEps | 0:43b96e9650ef | 224 | #endif |
JovanEps | 0:43b96e9650ef | 225 | |
JovanEps | 0:43b96e9650ef | 226 | /* |
JovanEps | 0:43b96e9650ef | 227 | ******************************************** |
JovanEps | 0:43b96e9650ef | 228 | * Module 8: Procedure calls |
JovanEps | 0:43b96e9650ef | 229 | ******************************************** |
JovanEps | 0:43b96e9650ef | 230 | */ |
JovanEps | 0:43b96e9650ef | 231 | X = 1.0; |
JovanEps | 0:43b96e9650ef | 232 | Y = 1.0; |
JovanEps | 0:43b96e9650ef | 233 | Z = 1.0; |
JovanEps | 0:43b96e9650ef | 234 | |
JovanEps | 0:43b96e9650ef | 235 | for (I = 1; I <= N8; I++) |
JovanEps | 0:43b96e9650ef | 236 | P3(X,Y,&Z); |
JovanEps | 0:43b96e9650ef | 237 | |
JovanEps | 0:43b96e9650ef | 238 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 239 | IF (JJ==II)POUT(N8,J,K,X,Y,Z,Z); |
JovanEps | 0:43b96e9650ef | 240 | #endif |
JovanEps | 0:43b96e9650ef | 241 | |
JovanEps | 0:43b96e9650ef | 242 | /* |
JovanEps | 0:43b96e9650ef | 243 | ******************************************** |
JovanEps | 0:43b96e9650ef | 244 | * Module 9: Array references |
JovanEps | 0:43b96e9650ef | 245 | ******************************************** |
JovanEps | 0:43b96e9650ef | 246 | */ |
JovanEps | 0:43b96e9650ef | 247 | J = 1; |
JovanEps | 0:43b96e9650ef | 248 | K = 2; |
JovanEps | 0:43b96e9650ef | 249 | L = 3; |
JovanEps | 0:43b96e9650ef | 250 | E1[1] = 1.0; |
JovanEps | 0:43b96e9650ef | 251 | E1[2] = 2.0; |
JovanEps | 0:43b96e9650ef | 252 | E1[3] = 3.0; |
JovanEps | 0:43b96e9650ef | 253 | |
JovanEps | 0:43b96e9650ef | 254 | for (I = 1; I <= N9; I++) |
JovanEps | 0:43b96e9650ef | 255 | P0(); |
JovanEps | 0:43b96e9650ef | 256 | |
JovanEps | 0:43b96e9650ef | 257 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 258 | IF (JJ==II)POUT(N9,J,K,E1[1],E1[2],E1[3],E1[4]); |
JovanEps | 0:43b96e9650ef | 259 | #endif |
JovanEps | 0:43b96e9650ef | 260 | |
JovanEps | 0:43b96e9650ef | 261 | /* |
JovanEps | 0:43b96e9650ef | 262 | ******************************************** |
JovanEps | 0:43b96e9650ef | 263 | * Module 10: Integer arithmetic |
JovanEps | 0:43b96e9650ef | 264 | ******************************************** |
JovanEps | 0:43b96e9650ef | 265 | */ |
JovanEps | 0:43b96e9650ef | 266 | J = 2; |
JovanEps | 0:43b96e9650ef | 267 | K = 3; |
JovanEps | 0:43b96e9650ef | 268 | |
JovanEps | 0:43b96e9650ef | 269 | for (I = 1; I <= N10; I++) { |
JovanEps | 0:43b96e9650ef | 270 | J = J + K; |
JovanEps | 0:43b96e9650ef | 271 | K = J + K; |
JovanEps | 0:43b96e9650ef | 272 | J = K - J; |
JovanEps | 0:43b96e9650ef | 273 | K = K - J - J; |
JovanEps | 0:43b96e9650ef | 274 | } |
JovanEps | 0:43b96e9650ef | 275 | |
JovanEps | 0:43b96e9650ef | 276 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 277 | IF (JJ==II)POUT(N10,J,K,X1,X2,X3,X4); |
JovanEps | 0:43b96e9650ef | 278 | #endif |
JovanEps | 0:43b96e9650ef | 279 | |
JovanEps | 0:43b96e9650ef | 280 | /* |
JovanEps | 0:43b96e9650ef | 281 | ******************************************** |
JovanEps | 0:43b96e9650ef | 282 | * Module 11: Standard functions |
JovanEps | 0:43b96e9650ef | 283 | ******************************************** |
JovanEps | 0:43b96e9650ef | 284 | */ |
JovanEps | 0:43b96e9650ef | 285 | X = 0.75; |
JovanEps | 0:43b96e9650ef | 286 | |
JovanEps | 0:43b96e9650ef | 287 | for (I = 1; I <= N11; I++) |
JovanEps | 0:43b96e9650ef | 288 | X = DSQRT(DEXP(DLOG(X)/T1)); |
JovanEps | 0:43b96e9650ef | 289 | |
JovanEps | 0:43b96e9650ef | 290 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 291 | IF (JJ==II)POUT(N11,J,K,X,X,X,X); |
JovanEps | 0:43b96e9650ef | 292 | #endif |
JovanEps | 0:43b96e9650ef | 293 | |
JovanEps | 0:43b96e9650ef | 294 | /* |
JovanEps | 0:43b96e9650ef | 295 | ******************************************** |
JovanEps | 0:43b96e9650ef | 296 | * THIS IS THE END OF THE MAJOR LOOP. |
JovanEps | 0:43b96e9650ef | 297 | ******************************************** |
JovanEps | 0:43b96e9650ef | 298 | */ |
JovanEps | 0:43b96e9650ef | 299 | if (++JJ <= II) |
JovanEps | 0:43b96e9650ef | 300 | goto IILOOP; |
JovanEps | 0:43b96e9650ef | 301 | |
JovanEps | 0:43b96e9650ef | 302 | /* |
JovanEps | 0:43b96e9650ef | 303 | ******************************************** |
JovanEps | 0:43b96e9650ef | 304 | * Stop benchmark timing at this point. |
JovanEps | 0:43b96e9650ef | 305 | ******************************************** |
JovanEps | 0:43b96e9650ef | 306 | */ |
JovanEps | 0:43b96e9650ef | 307 | // finisec = time(0); |
JovanEps | 0:43b96e9650ef | 308 | finisec = timer.read_ms(); |
JovanEps | 0:43b96e9650ef | 309 | timer.reset(); |
JovanEps | 0:43b96e9650ef | 310 | |
JovanEps | 0:43b96e9650ef | 311 | /* |
JovanEps | 0:43b96e9650ef | 312 | *-------------------------------------------------------------------- |
JovanEps | 0:43b96e9650ef | 313 | * Performance in Whetstone KIP's per second is given by |
JovanEps | 0:43b96e9650ef | 314 | * |
JovanEps | 0:43b96e9650ef | 315 | * (100*LOOP*II)/TIME |
JovanEps | 0:43b96e9650ef | 316 | * |
JovanEps | 0:43b96e9650ef | 317 | * where TIME is in seconds. |
JovanEps | 0:43b96e9650ef | 318 | *-------------------------------------------------------------------- |
JovanEps | 0:43b96e9650ef | 319 | */ |
JovanEps | 0:43b96e9650ef | 320 | pc.printf(" kraj \n"); |
JovanEps | 0:43b96e9650ef | 321 | double vreme; |
JovanEps | 0:43b96e9650ef | 322 | vreme = (finisec - startsec) / 1000; |
JovanEps | 0:43b96e9650ef | 323 | |
JovanEps | 0:43b96e9650ef | 324 | if (vreme <= 0) |
JovanEps | 0:43b96e9650ef | 325 | { |
JovanEps | 0:43b96e9650ef | 326 | pc.printf("Insufficient duration- Increase the LOOP count \n"); |
JovanEps | 0:43b96e9650ef | 327 | return 1; |
JovanEps | 0:43b96e9650ef | 328 | } |
JovanEps | 0:43b96e9650ef | 329 | |
JovanEps | 0:43b96e9650ef | 330 | pc.printf("Loops: %ld, Iterations: %d, Duration: %ld sec. \n", |
JovanEps | 0:43b96e9650ef | 331 | LOOP, II, vreme); |
JovanEps | 0:43b96e9650ef | 332 | |
JovanEps | 0:43b96e9650ef | 333 | KIPS = (100.0 * LOOP * II) / vreme ; |
JovanEps | 0:43b96e9650ef | 334 | |
JovanEps | 0:43b96e9650ef | 335 | // if (KIPS >= 1000.0) |
JovanEps | 0:43b96e9650ef | 336 | // pc.printf("C Converted Double Precision Whetstones: %.1f MIPS \n\n", KIPS / 1000); |
JovanEps | 0:43b96e9650ef | 337 | // else |
JovanEps | 0:43b96e9650ef | 338 | // pc.printf("C Converted Double Precision Whetstones: %.1f KIPS \n\n", KIPS); |
JovanEps | 0:43b96e9650ef | 339 | |
JovanEps | 0:43b96e9650ef | 340 | pc.printf("C Converted Double Precision Whetstones: %.1f KIPS \n\n", KIPS); |
JovanEps | 0:43b96e9650ef | 341 | |
JovanEps | 0:43b96e9650ef | 342 | if (continuous) |
JovanEps | 0:43b96e9650ef | 343 | goto LCONT; |
JovanEps | 0:43b96e9650ef | 344 | |
JovanEps | 0:43b96e9650ef | 345 | return 1; |
JovanEps | 0:43b96e9650ef | 346 | } |
JovanEps | 0:43b96e9650ef | 347 | |
JovanEps | 0:43b96e9650ef | 348 | void PA(double E[]) |
JovanEps | 0:43b96e9650ef | 349 | { |
JovanEps | 0:43b96e9650ef | 350 | J = 0; |
JovanEps | 0:43b96e9650ef | 351 | |
JovanEps | 0:43b96e9650ef | 352 | L10: |
JovanEps | 0:43b96e9650ef | 353 | E[1] = ( E[1] + E[2] + E[3] - E[4]) * T; |
JovanEps | 0:43b96e9650ef | 354 | E[2] = ( E[1] + E[2] - E[3] + E[4]) * T; |
JovanEps | 0:43b96e9650ef | 355 | E[3] = ( E[1] - E[2] + E[3] + E[4]) * T; |
JovanEps | 0:43b96e9650ef | 356 | E[4] = (-E[1] + E[2] + E[3] + E[4]) / T2; |
JovanEps | 0:43b96e9650ef | 357 | J += 1; |
JovanEps | 0:43b96e9650ef | 358 | |
JovanEps | 0:43b96e9650ef | 359 | if (J < 6) |
JovanEps | 0:43b96e9650ef | 360 | goto L10; |
JovanEps | 0:43b96e9650ef | 361 | } |
JovanEps | 0:43b96e9650ef | 362 | |
JovanEps | 0:43b96e9650ef | 363 | void P0(void) |
JovanEps | 0:43b96e9650ef | 364 | { |
JovanEps | 0:43b96e9650ef | 365 | E1[J] = E1[K]; |
JovanEps | 0:43b96e9650ef | 366 | E1[K] = E1[L]; |
JovanEps | 0:43b96e9650ef | 367 | E1[L] = E1[J]; |
JovanEps | 0:43b96e9650ef | 368 | } |
JovanEps | 0:43b96e9650ef | 369 | |
JovanEps | 0:43b96e9650ef | 370 | void P3(double X, double Y, double *Z) |
JovanEps | 0:43b96e9650ef | 371 | { |
JovanEps | 0:43b96e9650ef | 372 | double X1, Y1; |
JovanEps | 0:43b96e9650ef | 373 | |
JovanEps | 0:43b96e9650ef | 374 | X1 = X; |
JovanEps | 0:43b96e9650ef | 375 | Y1 = Y; |
JovanEps | 0:43b96e9650ef | 376 | X1 = T * (X1 + Y1); |
JovanEps | 0:43b96e9650ef | 377 | Y1 = T * (X1 + Y1); |
JovanEps | 0:43b96e9650ef | 378 | *Z = (X1 + Y1) / T2; |
JovanEps | 0:43b96e9650ef | 379 | } |
JovanEps | 0:43b96e9650ef | 380 | |
JovanEps | 0:43b96e9650ef | 381 | #ifdef PRINTOUT |
JovanEps | 0:43b96e9650ef | 382 | void POUT(long N, long J, long K, double X1, double X2, double X3, double X4) |
JovanEps | 0:43b96e9650ef | 383 | { |
JovanEps | 0:43b96e9650ef | 384 | pc.printf("%7ld %7ld %7ld %12.4e %12.4e %12.4e %12.4e\n", |
JovanEps | 0:43b96e9650ef | 385 | N, J, K, X1, X2, X3, X4); |
JovanEps | 0:43b96e9650ef | 386 | } |
JovanEps | 0:43b96e9650ef | 387 | #endif |
JovanEps | 0:43b96e9650ef | 388 | |
JovanEps | 0:43b96e9650ef | 389 | |
JovanEps | 0:43b96e9650ef | 390 | int main() { |
JovanEps | 0:43b96e9650ef | 391 | int rez; |
JovanEps | 0:43b96e9650ef | 392 | printf("\n My Benchamrk example for Whetstones \n"); |
JovanEps | 0:43b96e9650ef | 393 | |
JovanEps | 0:43b96e9650ef | 394 | while(1) { |
JovanEps | 0:43b96e9650ef | 395 | myled=1; |
JovanEps | 0:43b96e9650ef | 396 | rez = whetstone(); |
JovanEps | 0:43b96e9650ef | 397 | myled=0; |
JovanEps | 0:43b96e9650ef | 398 | } |
JovanEps | 0:43b96e9650ef | 399 | } |