Update contrib.
1 // Copyright (c) 1996-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\math\t_gen.cpp
15 // Generates files to be used in testing whether arithmetic in TReal32 and TReal64 gives
16 // exactly the same results using the MSDEV complier as on the rack.
23 #include "../server/t_server.h"
26 GLDEF_D RTest test(_L("T_GEN"));
28 LOCAL_D const TFileName pathName = _L("C:\\F32-TST\\E32-MATH\\");
29 LOCAL_D TBuf<0x100> buf;
30 LOCAL_D TBuf8<0x100> buf8;
33 #define __GENERATE_SPECIAL_VALUES
34 #ifdef __GENERATE_SPECIAL_VALUES
36 LOCAL_D RFile fspw; // file for special values for WINS
37 LOCAL_D RFile fspa; // file for special values for ARM
39 LOCAL_D const TFileName fileNameWSp = _L("T_VALS.HWG");
40 LOCAL_D const TFileName fileNameASp = _L("T_VALS.HAG");
42 LOCAL_C void appendConstTI64(TPtrC aName,TReal64* aVal)
46 buf.AppendFormat(_L("const TInt64 %S = TInt64(0x%x,0x%x);\n"),&aName,*(((TUint32*)aVal) + 1),*(TUint32*)aVal);
47 buf8.Copy(buf); // Unicode
51 buf.AppendFormat(_L("const TInt64 %S = TInt64(0x%x,0x%x);\n"),&aName,*(TUint32*)aVal,*(((TUint32*)aVal) + 1));
56 LOCAL_C void appendConstTI32x(TPtrC aName,TReal32* aVal)
60 buf.AppendFormat(_L("const TInt32x %S = TInt32x(0x%x);\n"),&aName,*(TUint32*)aVal);
61 buf8.Copy(buf); // Unicode
66 LOCAL_C void appendConstTR64(TPtrC aName,TPtrC aIntName)
70 buf.AppendFormat(_L("const TReal64 %S = *(TReal64*)&%S;\n"),&aName,&aIntName);
71 buf8.Copy(buf); // Unicode
76 LOCAL_C void appendConstTR32(TPtrC aName,TPtrC aIntName)
80 buf.AppendFormat(_L("const TReal32 %S = *(TReal32*)&%S;\n"),&aName,&aIntName);
86 LOCAL_C void appendConstTR(TPtrC aName,TPtrC a64Name)
90 buf.AppendFormat(_L("const TReal %S = TReal(%S);\n"),&aName,&a64Name);
91 buf8.Copy(buf); // Unicode
96 LOCAL_C void appendStart()
99 fspw.Write(_L8("/* Generated by \\E32\\TMATH\\T_GEN.MAK for WINS (little-endian doubles) */\n\n"));
100 fspw.Write(_L8("#include <e32std.h>\n\n"));
101 fspw.Write(_L8("class TInt32x\n{\npublic:\n"));
102 fspw.Write(_L8("TInt32x(TInt32 aInt) {iInt=aInt;}\n"));
103 fspw.Write(_L8("public:\nTInt32 iInt;\n};\n\n"));
106 fspa.Write(_L8("/* Generated by \\E32\\TMATH\\T_GEN.MAK for ARM (big-endian doubles)*/\n\n"));
107 fspa.Write(_L8("#include <e32std.h>\n\n"));
108 fspa.Write(_L8("class TInt32x\n{\npublic:\n"));
109 fspa.Write(_L8("TInt32x(TInt32 aInt) {iInt=aInt;}\n"));
110 fspa.Write(_L8("public:\nTInt32 iInt;\n};\n\n"));
113 LOCAL_C void generateSpecialValues()
115 // The following are to avoid the errors in the compiler in converting from string
118 // Initialise max/min values and square roots and write to header files
122 TReal64 minTReal32in64;
123 SReal64 *p64=(SReal64*)&minTReal32in64;
129 TReal64 maxTReal32in64;
130 p64=(SReal64*)&maxTReal32in64;
136 TReal64 sqrtMaxTReal64;
137 const TReal64 arg1=KMaxTReal64-1.0E+299; // Take off this to avoid overflow
138 TInt ret=Math::Sqrt(sqrtMaxTReal64,arg1);
139 TReal64 sqrtMinTReal64;
140 const TReal64 arg2=KMinTReal64;
141 ret=Math::Sqrt(sqrtMinTReal64,arg2);
143 TReal64 sqrtMaxTReal32in64,sqrtMinTReal32in64;
145 TReal64 negZeroTReal64;
146 p64=(SReal64*)&negZeroTReal64;
152 TReal64 posInfTReal64;
153 p64=(SReal64*)&posInfTReal64;
155 p64->exp=KTReal64SpecialExponent;
159 TReal64 negInfTReal64;
160 p64=(SReal64*)&negInfTReal64;
162 p64->exp=KTReal64SpecialExponent;
167 p64=(SReal64*)&NaNTReal64;
169 p64->exp=KTReal64SpecialExponent;
171 p64->lsm=0xffffffffu;
173 TReal32 sqrtMaxTReal32;
174 const TReal arg3=maxTReal32in64-1.0E+32f; // Take off this to avoid overflow
175 ret=Math::Sqrt(sqrtMaxTReal32in64,arg3);
176 sqrtMaxTReal32=TReal32(sqrtMaxTReal32in64);
178 TReal32 sqrtMinTReal32;
179 const TReal arg4=minTReal32in64;
180 ret=Math::Sqrt(sqrtMinTReal32in64,arg4);
181 sqrtMinTReal32=TReal32(sqrtMinTReal32in64);
183 TReal32 negZeroTReal32;
184 SReal32 *p32=(SReal32*)&negZeroTReal32;
191 appendConstTI64(_L("minTReal32in64"),&minTReal32in64);
192 appendConstTI64(_L("maxTReal32in64"),&maxTReal32in64);
193 appendConstTI64(_L("sqrtMaxTReal64"),&sqrtMaxTReal64);
194 appendConstTI64(_L("sqrtMinTReal64"),&sqrtMinTReal64);
195 appendConstTI64(_L("negZeroTReal64"),&negZeroTReal64);
196 appendConstTI64(_L("posInfTReal64"),&posInfTReal64);
197 appendConstTI64(_L("negInfTReal64"),&negInfTReal64);
198 appendConstTI64(_L("NaNTReal64"),&NaNTReal64);
200 appendConstTI32x(_L("sqrtMaxTReal32"),&sqrtMaxTReal32);
201 appendConstTI32x(_L("sqrtMinTReal32"),&sqrtMinTReal32);
202 appendConstTI32x(_L("negZeroTReal32"),&negZeroTReal32);
204 appendConstTR64(_L("KMinTReal32in64"),_L("minTReal32in64"));
205 appendConstTR64(_L("KMaxTReal32in64"),_L("maxTReal32in64"));
206 appendConstTR64(_L("KSqrtMaxTReal64"),_L("sqrtMaxTReal64"));
207 appendConstTR64(_L("KSqrtMinTReal64"),_L("sqrtMinTReal64"));
208 appendConstTR64(_L("KNegZeroTReal64"),_L("negZeroTReal64"));
209 appendConstTR64(_L("KPosInfTReal64"),_L("posInfTReal64"));
210 appendConstTR64(_L("KNegInfTReal64"),_L("negInfTReal64"));
211 appendConstTR64(_L("KNaNTReal64"),_L("NaNTReal64"));
213 appendConstTR32(_L("KSqrtMaxTReal32"),_L("sqrtMaxTReal32"));
214 appendConstTR32(_L("KSqrtMinTReal32"),_L("sqrtMinTReal32"));
215 appendConstTR32(_L("KNegZeroTReal32"),_L("negZeroTReal32"));
217 appendConstTR(_L("KMinTReal32inTReal"),_L("KMinTReal32in64"));
218 appendConstTR(_L("KMaxTReal32inTReal"),_L("KMaxTReal32in64"));
219 appendConstTR(_L("KNegZeroTReal"),_L("KNegZeroTReal64"));
224 //#define __GENERATE_TR64
225 #ifdef __GENERATE_TR64
227 // Data for tests from T_R64DTA.cpp
228 GLREF_D TReal64 addInput[];
229 GLREF_D TReal64 subInput[];
230 GLREF_D TReal64 multInput[];
231 GLREF_D TReal64 divInput[];
232 GLREF_D TReal64 unaryInput[];
233 GLREF_D TReal64 incDecInput[];
234 GLREF_D TInt sizeAdd;
235 GLREF_D TInt sizeSub;
236 GLREF_D TInt sizeMult;
237 GLREF_D TInt sizeDiv;
238 GLREF_D TInt sizeUnary;
239 GLREF_D TInt sizeIncDec;
241 LOCAL_D RFile fw; // file for WINS
242 LOCAL_D RFile fa; // file for ARM
243 LOCAL_D const TFileName fileNameW64 = _L("T_REAL64.HWG");
244 LOCAL_D const TFileName fileNameA64 = _L("T_REAL64.HAG");
246 LOCAL_C void appendArrayName64(TDesC& aName)
249 buf.AppendFormat(_L("const TInt64 %S[] = \n{\n"),&aName);
254 LOCAL_C void appendValue64(TReal64* aVal)
257 buf.AppendFormat(_L(" TInt64(0x%x,0x%x),\n"),*(((TUint32*)aVal) + 1),*(TUint32*)aVal);
260 buf.AppendFormat(_L(" TInt64(0x%x,0x%x),\n"),*(TUint32*)aVal,*(((TUint32*)aVal) + 1));
264 LOCAL_C void appendArrayTerm()
271 LOCAL_C void createAddArray()
273 // Writes an array of results of additions to the header file
279 appendArrayName64(_L("addArray"));
280 for (ii=0; ii<sizeAdd-1; ii++)
282 ff=addInput[ii]+addInput[ii+1];
288 LOCAL_C void createSubArray()
290 // Writes an array of results of subtractions to the header file
296 appendArrayName64(_L("subArray"));
297 for (ii=0; ii<sizeSub-1; ii++)
299 ff=subInput[ii]-subInput[ii+1];
305 LOCAL_C void createMultArray()
307 // Writes an array of results of multiplications to the header file
313 appendArrayName64(_L("multArray"));
314 for (ii=0; ii<sizeMult-1; ii++)
316 ff=multInput[ii]*multInput[ii+1];
322 LOCAL_C void createDivArray()
324 // Writes an array of results of divisions to the header file
330 appendArrayName64(_L("divArray"));
331 for (ii=0; ii<sizeDiv-1; ii++)
333 if (divInput[ii+1]!=0)
335 ff=divInput[ii]/divInput[ii+1];
342 LOCAL_C void createUnaryArray()
344 // Writes an array of results of unary operations to the header file
349 appendArrayName64(_L("unaryArray"));
350 for (TInt ii=0; ii<sizeUnary; ii++)
358 LOCAL_C void createIncDecArrays()
360 // Writes an array of results of pre and post increment and decrement operations to the
367 // Generate arrays for exact tests
369 appendArrayName64(_L("preIncArray1"));
370 for (ii=0; ii<sizeIncDec; ii++)
378 appendArrayName64(_L("preIncArray2"));
379 for (ii=0; ii<sizeIncDec; ii++)
388 appendArrayName64(_L("preDecArray1"));
389 for (ii=0; ii<sizeIncDec; ii++)
397 appendArrayName64(_L("preDecArray2"));
398 for (ii=0; ii<sizeIncDec; ii++)
407 appendArrayName64(_L("postIncArray1"));
408 for (ii=0; ii<sizeIncDec; ii++)
416 appendArrayName64(_L("postIncArray2"));
417 for (ii=0; ii<sizeIncDec; ii++)
426 appendArrayName64(_L("postDecArray1"));
427 for (ii=0; ii<sizeIncDec; ii++)
435 appendArrayName64(_L("postDecArray2"));
436 for (ii=0; ii<sizeIncDec; ii++)
446 LOCAL_C void createArrays()
448 // Create and append to header file all arrays required for T_R64.CPP tests
456 createIncDecArrays();
460 GLDEF_C void CallTestsL(void)
462 // Generate TReal64s (and special values if required) and write to header files
468 #ifdef __GENERATE_TR64
470 msg=_L("Generating Maths constants to header files:\n ");
478 TInt r=TheFs.MkDirAll(pathName);
479 test(r==KErrNone || r==KErrAlreadyExists);
480 test(TheFs.SetSessionPath(pathName)==KErrNone);
482 #ifdef __GENERATE_TR64
483 test(fw.Replace(TheFs,fileNameW64,EFileWrite)==KErrNone);
484 test(fa.Replace(TheFs,fileNameA64,EFileWrite)==KErrNone);
485 test.Next(_L("Generating TReal64s"));
486 fw.Write(_L("// Generated by \\E32\\TMATH\\T_GEN.MAK for WINS (little-endian doubles)\n\n"));
487 fa.Write(_L("// Generated by \\E32\\TMATH\\T_GEN.MAK for ARM (big-endian doubles)\n\n"));
493 #ifdef __GENERATE_SPECIAL_VALUES
494 test(fspw.Replace(TheFs,fileNameWSp,EFileWrite)==KErrNone);
495 test(fspa.Replace(TheFs,fileNameASp,EFileWrite)==KErrNone);
496 test.Start(_L("Generate header file of special values for use in maths testing"));
497 generateSpecialValues();
498 test.Next(_L("Done - now closing files"));