First public contribution.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\bench\t_whet.cpp
15 // Whetstone Benchmarks
22 #include <e32std_private.h>
27 #include "../server/t_server.h"
29 const TInt KSections=9;
31 LOCAL_D TReal64 loop_time[KSections];
32 LOCAL_D TReal64 loop_mops[KSections];
33 LOCAL_D TReal64 loop_mflops[KSections];
34 LOCAL_D TReal64 TimeUsed;
35 LOCAL_D TReal64 mwips;
36 LOCAL_D TBufC<50> headings[KSections];
37 LOCAL_D TReal64 Check;
38 LOCAL_D TReal64 results[KSections];
40 LOCAL_D TBuf<0x100> buf;
41 LOCAL_D TBuf8<0x100> buf8;
42 LOCAL_D const TFileName pathName = _L("C:\\E32-MATH\\");
43 #ifdef T_WHET_WITH_VFP
44 LOCAL_D const TFileName fileName = _L("WHETVFP.RES");
46 LOCAL_D const TFileName fileName = _L("WHET.RES");
48 LOCAL_D RFile outfile;
50 #ifdef T_WHET_WITH_VFP
51 GLDEF_D RTest test(_L("TReal64 C/C++ Whetstone Benchmark with VFP"));
53 GLDEF_D RTest test(_L("TReal64 C/C++ Whetstone Benchmark"));
56 LOCAL_C void appendString(const TDesC& aString)
60 buf.AppendFormat(_L("%S\n"),&aString);
61 buf8.Copy(buf); // Unicode
65 LOCAL_C void pa(TReal64* e,TReal64 t,TReal64 t2)
71 e[0]=(e[0]+e[1]+e[2]-e[3])*t;
72 e[1]=(e[0]+e[1]-e[2]+e[3])*t;
73 e[2]=(e[0]-e[1]+e[2]+e[3])*t;
74 e[3]=(-e[0]+e[1]+e[2]+e[3])/t2;
78 LOCAL_C void po(TReal64* e1,TInt j,TInt k,TInt l)
86 LOCAL_C void p3(TReal64 *x,TReal64 *y,TReal64 *z,TReal64 t,TReal64 t1,TReal64 t2)
96 LOCAL_C void pout(const TDesC& aTitle,TReal64 aOps,TInt aType,TReal64 aChecknum,TReal64 aTime,
97 TInt aCalibrate,TInt aSection)
103 loop_time[aSection]=aTime;
104 headings[aSection]=aTitle;
108 results[aSection]=aChecknum;
112 test.Printf(_L("%- 20S%- 18g"),&headings[aSection],results[aSection]);
117 mflops=aOps/(1E+6*aTime);
121 loop_mops[aSection]=99999.0;
122 loop_mflops[aSection]=mflops;
123 test.Printf(_L("%- 34g%- 7g\n"),loop_mflops[aSection],loop_time[aSection]);
128 mops=aOps/(1E+6*aTime);
132 loop_mops[aSection]=mops;
133 loop_mflops[aSection]=0.0;
134 test.Printf(_L(" %- 17g%- 7g\n"),loop_mops[aSection],loop_time[aSection]);
139 LOCAL_C void whetstones(TInt xtra,TInt x100,TInt calibrate)
143 TReal64 t=0.49999975;
146 TReal64 t1=0.50000025;
151 TInt n1,n2,n3,n4,n5,n6,n7,n8,n1mult;
162 // Section 1, Array elements
164 {1.0,-1.0,-1.0,-1.0};
168 for (ix=0; ix<xtra; ix++)
170 for(i=0; i<n1*n1mult; i++)
172 e1[0]=(e1[0]+e1[1]+e1[2]-e1[3])*t;
173 e1[1]=(e1[0]+e1[1]-e1[2]+e1[3])*t;
174 e1[2]=(e1[0]-e1[1]+e1[2]+e1[3])*t;
175 e1[3]=(-e1[0]+e1[1]+e1[2]+e1[3])*t;
181 TReal64 time=I64REAL(timeb.Int64()-timea.Int64())/(TReal64(n1mult)*1E+6);
183 pout(_L("N1 floating point "),TReal64(n1*16)*TReal64(xtra),1,e1[3],time,calibrate,1);
185 // Section 2, Array as parameter
188 for (ix=0; ix<xtra; ix++)
196 time=I64REAL(timeb.Int64()-timea.Int64())/1E+6;
198 pout(_L("N2 floating point "),TReal64(n2*96)*TReal64(xtra),1,e1[3],time,calibrate,2);
200 // Section 3, Conditional jumps
204 for (ix=0; ix<xtra; ix++)
223 time=I64REAL(timeb.Int64()-timea.Int64())/1E+6;
225 pout(_L("N3 if then else "),TReal64(n3*3)*TReal64(xtra),2,TReal64(j),time,calibrate,3);
227 // Section 4, Integer arithmetic
233 for (ix=0; ix<xtra; ix++)
245 time=I64REAL(timeb.Int64()-timea.Int64())/1E+6;
247 TReal64 x=e1[0]+e1[1];
249 pout(_L("N4 fixed point "),TReal64(n4*15)*TReal64(xtra),2,x,time,calibrate,4);
251 // Section 5, Trig functions
254 TReal64 trg1,trg2,trg3,trg4;
257 for (ix=0; ix<xtra; ix++)
265 Math::ATan(x,(t2*trg1*trg2)/(trg3+trg4-1.0));
271 Math::ATan(y,(t2*trg1*trg2)/(trg3+trg4-1.0));
278 time=I64REAL(timeb.Int64()-timea.Int64())/1E+6;
280 pout(_L("N5 sin,cos etc. "),TReal64(n5*26)*TReal64(xtra),2,y,time,calibrate,5);
282 // Section 6, Procedure calls
288 for (ix=0; ix<xtra; ix++)
291 p3(&x,&y,&z,t,t1,t2);
294 time=I64REAL(timeb.Int64()-timea.Int64())/1E+6;
296 pout(_L("N6 floating point "),TReal64(n6*6)*TReal64(xtra),1,z,time,calibrate,6);
298 // Section 7, Array refrences
307 for (ix=0; ix<xtra; ix++)
313 time=I64REAL(timeb.Int64()-timea.Int64())/1E+6;
315 pout(_L("N7 assignments "),TReal64(n7*3)*TReal64(xtra),2,e2[2],time,calibrate,7);
317 // Section 8, Standard functions
321 for (ix=0; ix<xtra; ix++)
326 Math::Exp(trg1,trg1/t1);
331 time=I64REAL(timeb.Int64()-timea.Int64())/1E+6;
334 pout(_L("N8 exp,sqrt etc. "),TReal64(n8*4)*TReal64(xtra),2,x,time,calibrate,8);
337 GLDEF_C void CallTestsL(void)
348 #ifdef T_WHET_WITH_VFP
350 if (HAL::Get(HALData::EHardwareFloatingPoint, supportedModes) != KErrNone)
352 test.Printf(_L("No VFP hardware, skipping test\n"));
357 // connect and make directory for write file
358 test.Start(_L("Making directory..."));
359 TInt r=TheFs.MkDirAll(pathName);
360 test(r==KErrNone || r==KErrAlreadyExists);
361 test(TheFs.SetSessionPath(pathName)==KErrNone);
362 test(outfile.Replace(TheFs,fileName,EFileWrite)==KErrNone);
365 test.Next(_L("Calibrating...\n"));
371 whetstones(xtra,x100,calibrate);
373 test.Printf(_L("%g Seconds %d Passes (x 100)\n"),TimeUsed,xtra);
385 TRealX TimeX(TimeUsed);
386 TInt TimeInt=TInt(TimeX);
387 xtra*=duration/TimeInt;
394 test.Printf(_L("\nUse %d passes (x 100)\n"),xtra);
396 test.Printf(_L("\nTReal64 C/C++ Whetstone Benchmark\n"));
397 test.Printf(_L("\nLoop content Result MFLOPS MOPS Seconds\n\n"));
400 whetstones(xtra,x100,calibrate);
402 test.Printf(_L("\nMWIPS "));
404 mwips=(TReal64)(xtra*x100)/(10.0*TimeUsed);
408 test.Printf(_L("%- 17g %- 7g\n\n"),mwips,TimeUsed);
410 if (Check==TReal64(0.0))
411 test.Printf(_L("Wrong answer "));
413 // Add results to output file whets.res
414 appendString(_L("Whetstone TReal64 Benchmark in C/C++\n"));
415 appendString(_L("\n\n"));
416 appendString(_L("Loop content Result MFLOPS MOPS Seconds\n\n"));
418 for (section=1; section<KSections; section++)
421 buf.AppendFormat(_L("%- 20S%- 20g"),&headings[section],results[section]);
422 buf8.Copy(buf); // Unicode
425 if (loop_mops[section]==99999.0f)
428 buf.AppendFormat(_L("%- 39g%- 8g\n"),loop_mflops[section],loop_time[section]);
429 buf8.Copy(buf); // Unicode
435 buf.AppendFormat(_L(" %- 21g%- 8g\n"),loop_mops[section],loop_time[section]);
436 buf8.Copy(buf); // Unicode
442 buf.AppendFormat(_L("\nMWIPS %- 18g %- 8g\n\n"),mwips,TimeUsed);
443 buf8.Copy(buf); // Unicode
447 test.Printf(_L("\nResults are in file whets.res"));