|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
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. |
|
17 // |
|
18 // |
|
19 |
|
20 #include <e32test.h> |
|
21 #include <f32file.h> |
|
22 #include <e32svr.h> |
|
23 #include "../server/t_server.h" |
|
24 #include "t_math.h" |
|
25 |
|
26 GLDEF_D RTest test(_L("T_GEN")); |
|
27 |
|
28 LOCAL_D const TFileName pathName = _L("C:\\F32-TST\\E32-MATH\\"); |
|
29 LOCAL_D TBuf<0x100> buf; |
|
30 LOCAL_D TBuf8<0x100> buf8; |
|
31 |
|
32 |
|
33 #define __GENERATE_SPECIAL_VALUES |
|
34 #ifdef __GENERATE_SPECIAL_VALUES |
|
35 |
|
36 LOCAL_D RFile fspw; // file for special values for WINS |
|
37 LOCAL_D RFile fspa; // file for special values for ARM |
|
38 |
|
39 LOCAL_D const TFileName fileNameWSp = _L("T_VALS.HWG"); |
|
40 LOCAL_D const TFileName fileNameASp = _L("T_VALS.HAG"); |
|
41 |
|
42 LOCAL_C void appendConstTI64(TPtrC aName,TReal64* aVal) |
|
43 { |
|
44 // for WINS |
|
45 buf=_L(""); |
|
46 buf.AppendFormat(_L("const TInt64 %S = TInt64(0x%x,0x%x);\n"),&aName,*(((TUint32*)aVal) + 1),*(TUint32*)aVal); |
|
47 buf8.Copy(buf); // Unicode |
|
48 fspw.Write(buf8); |
|
49 // for ARM |
|
50 buf=_L(""); |
|
51 buf.AppendFormat(_L("const TInt64 %S = TInt64(0x%x,0x%x);\n"),&aName,*(TUint32*)aVal,*(((TUint32*)aVal) + 1)); |
|
52 buf8.Copy(buf); |
|
53 fspa.Write(buf8); |
|
54 } |
|
55 |
|
56 LOCAL_C void appendConstTI32x(TPtrC aName,TReal32* aVal) |
|
57 { |
|
58 // for WINS and ARM |
|
59 buf=_L(""); |
|
60 buf.AppendFormat(_L("const TInt32x %S = TInt32x(0x%x);\n"),&aName,*(TUint32*)aVal); |
|
61 buf8.Copy(buf); // Unicode |
|
62 fspw.Write(buf8); |
|
63 fspa.Write(buf8); |
|
64 } |
|
65 |
|
66 LOCAL_C void appendConstTR64(TPtrC aName,TPtrC aIntName) |
|
67 { |
|
68 // for WINS and ARM |
|
69 buf=_L(""); |
|
70 buf.AppendFormat(_L("const TReal64 %S = *(TReal64*)&%S;\n"),&aName,&aIntName); |
|
71 buf8.Copy(buf); // Unicode |
|
72 fspw.Write(buf8); |
|
73 fspa.Write(buf8); |
|
74 } |
|
75 |
|
76 LOCAL_C void appendConstTR32(TPtrC aName,TPtrC aIntName) |
|
77 { |
|
78 // for WINS and ARM |
|
79 buf=_L(""); |
|
80 buf.AppendFormat(_L("const TReal32 %S = *(TReal32*)&%S;\n"),&aName,&aIntName); |
|
81 buf8.Copy(buf); |
|
82 fspw.Write(buf8); |
|
83 fspa.Write(buf8); |
|
84 } |
|
85 |
|
86 LOCAL_C void appendConstTR(TPtrC aName,TPtrC a64Name) |
|
87 { |
|
88 // for WINS and ARM |
|
89 buf=_L(""); |
|
90 buf.AppendFormat(_L("const TReal %S = TReal(%S);\n"),&aName,&a64Name); |
|
91 buf8.Copy(buf); // Unicode |
|
92 fspw.Write(buf8); |
|
93 fspa.Write(buf8); |
|
94 } |
|
95 |
|
96 LOCAL_C void appendStart() |
|
97 { |
|
98 // for WINS |
|
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")); |
|
104 |
|
105 // for ARM |
|
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")); |
|
111 } |
|
112 |
|
113 LOCAL_C void generateSpecialValues() |
|
114 // |
|
115 // The following are to avoid the errors in the compiler in converting from string |
|
116 // to floating point |
|
117 // |
|
118 // Initialise max/min values and square roots and write to header files |
|
119 // |
|
120 { |
|
121 |
|
122 TReal64 minTReal32in64; |
|
123 SReal64 *p64=(SReal64*)&minTReal32in64; |
|
124 p64->sign=0; |
|
125 p64->exp=0x381; |
|
126 p64->msm=0; |
|
127 p64->lsm=0; |
|
128 |
|
129 TReal64 maxTReal32in64; |
|
130 p64=(SReal64*)&maxTReal32in64; |
|
131 p64->sign=0; |
|
132 p64->exp=0x47E; |
|
133 p64->msm=0xfffff; |
|
134 p64->lsm=0xe0000000; |
|
135 |
|
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); |
|
142 |
|
143 TReal64 sqrtMaxTReal32in64,sqrtMinTReal32in64; |
|
144 |
|
145 TReal64 negZeroTReal64; |
|
146 p64=(SReal64*)&negZeroTReal64; |
|
147 p64->sign=1; |
|
148 p64->exp=0; |
|
149 p64->msm=0; |
|
150 p64->lsm=0; |
|
151 |
|
152 TReal64 posInfTReal64; |
|
153 p64=(SReal64*)&posInfTReal64; |
|
154 p64->sign=0; |
|
155 p64->exp=KTReal64SpecialExponent; |
|
156 p64->msm=0; |
|
157 p64->lsm=0; |
|
158 |
|
159 TReal64 negInfTReal64; |
|
160 p64=(SReal64*)&negInfTReal64; |
|
161 p64->sign=1; |
|
162 p64->exp=KTReal64SpecialExponent; |
|
163 p64->msm=0; |
|
164 p64->lsm=0; |
|
165 |
|
166 TReal64 NaNTReal64; |
|
167 p64=(SReal64*)&NaNTReal64; |
|
168 p64->sign=0; |
|
169 p64->exp=KTReal64SpecialExponent; |
|
170 p64->msm=0xfffffu; |
|
171 p64->lsm=0xffffffffu; |
|
172 |
|
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); |
|
177 |
|
178 TReal32 sqrtMinTReal32; |
|
179 const TReal arg4=minTReal32in64; |
|
180 ret=Math::Sqrt(sqrtMinTReal32in64,arg4); |
|
181 sqrtMinTReal32=TReal32(sqrtMinTReal32in64); |
|
182 |
|
183 TReal32 negZeroTReal32; |
|
184 SReal32 *p32=(SReal32*)&negZeroTReal32; |
|
185 p32->sign=1; |
|
186 p32->exp=0; |
|
187 p32->man=0; |
|
188 |
|
189 appendStart(); |
|
190 |
|
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); |
|
199 |
|
200 appendConstTI32x(_L("sqrtMaxTReal32"),&sqrtMaxTReal32); |
|
201 appendConstTI32x(_L("sqrtMinTReal32"),&sqrtMinTReal32); |
|
202 appendConstTI32x(_L("negZeroTReal32"),&negZeroTReal32); |
|
203 |
|
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")); |
|
212 |
|
213 appendConstTR32(_L("KSqrtMaxTReal32"),_L("sqrtMaxTReal32")); |
|
214 appendConstTR32(_L("KSqrtMinTReal32"),_L("sqrtMinTReal32")); |
|
215 appendConstTR32(_L("KNegZeroTReal32"),_L("negZeroTReal32")); |
|
216 |
|
217 appendConstTR(_L("KMinTReal32inTReal"),_L("KMinTReal32in64")); |
|
218 appendConstTR(_L("KMaxTReal32inTReal"),_L("KMaxTReal32in64")); |
|
219 appendConstTR(_L("KNegZeroTReal"),_L("KNegZeroTReal64")); |
|
220 } |
|
221 |
|
222 #endif |
|
223 |
|
224 //#define __GENERATE_TR64 |
|
225 #ifdef __GENERATE_TR64 |
|
226 |
|
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; |
|
240 |
|
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"); |
|
245 |
|
246 LOCAL_C void appendArrayName64(TDesC& aName) |
|
247 { |
|
248 buf=_L(""); |
|
249 buf.AppendFormat(_L("const TInt64 %S[] = \n{\n"),&aName); |
|
250 fw.Write(buf); |
|
251 fa.Write(buf); |
|
252 } |
|
253 |
|
254 LOCAL_C void appendValue64(TReal64* aVal) |
|
255 { |
|
256 buf=_L(""); |
|
257 buf.AppendFormat(_L(" TInt64(0x%x,0x%x),\n"),*(((TUint32*)aVal) + 1),*(TUint32*)aVal); |
|
258 fw.Write(buf); |
|
259 buf=_L(""); |
|
260 buf.AppendFormat(_L(" TInt64(0x%x,0x%x),\n"),*(TUint32*)aVal,*(((TUint32*)aVal) + 1)); |
|
261 fa.Write(buf); |
|
262 } |
|
263 |
|
264 LOCAL_C void appendArrayTerm() |
|
265 { |
|
266 buf=_L("};\n\n"); |
|
267 fw.Write(buf); |
|
268 fa.Write(buf); |
|
269 } |
|
270 |
|
271 LOCAL_C void createAddArray() |
|
272 // |
|
273 // Writes an array of results of additions to the header file |
|
274 // |
|
275 { |
|
276 TInt ii; |
|
277 TReal64 ff; |
|
278 |
|
279 appendArrayName64(_L("addArray")); |
|
280 for (ii=0; ii<sizeAdd-1; ii++) |
|
281 { |
|
282 ff=addInput[ii]+addInput[ii+1]; |
|
283 appendValue64(&ff); |
|
284 } |
|
285 appendArrayTerm(); |
|
286 } |
|
287 |
|
288 LOCAL_C void createSubArray() |
|
289 // |
|
290 // Writes an array of results of subtractions to the header file |
|
291 // |
|
292 { |
|
293 TInt ii; |
|
294 TReal64 ff; |
|
295 |
|
296 appendArrayName64(_L("subArray")); |
|
297 for (ii=0; ii<sizeSub-1; ii++) |
|
298 { |
|
299 ff=subInput[ii]-subInput[ii+1]; |
|
300 appendValue64(&ff); |
|
301 } |
|
302 appendArrayTerm(); |
|
303 } |
|
304 |
|
305 LOCAL_C void createMultArray() |
|
306 // |
|
307 // Writes an array of results of multiplications to the header file |
|
308 // |
|
309 { |
|
310 TInt ii; |
|
311 TReal64 ff; |
|
312 |
|
313 appendArrayName64(_L("multArray")); |
|
314 for (ii=0; ii<sizeMult-1; ii++) |
|
315 { |
|
316 ff=multInput[ii]*multInput[ii+1]; |
|
317 appendValue64(&ff); |
|
318 } |
|
319 appendArrayTerm(); |
|
320 } |
|
321 |
|
322 LOCAL_C void createDivArray() |
|
323 // |
|
324 // Writes an array of results of divisions to the header file |
|
325 // |
|
326 { |
|
327 TInt ii; |
|
328 TReal64 ff; |
|
329 |
|
330 appendArrayName64(_L("divArray")); |
|
331 for (ii=0; ii<sizeDiv-1; ii++) |
|
332 { |
|
333 if (divInput[ii+1]!=0) |
|
334 { |
|
335 ff=divInput[ii]/divInput[ii+1]; |
|
336 appendValue64(&ff); |
|
337 } |
|
338 } |
|
339 appendArrayTerm(); |
|
340 } |
|
341 |
|
342 LOCAL_C void createUnaryArray() |
|
343 // |
|
344 // Writes an array of results of unary operations to the header file |
|
345 // |
|
346 { |
|
347 TReal64 f; |
|
348 |
|
349 appendArrayName64(_L("unaryArray")); |
|
350 for (TInt ii=0; ii<sizeUnary; ii++) |
|
351 { |
|
352 f=-unaryInput[ii]; |
|
353 appendValue64(&f); |
|
354 } |
|
355 appendArrayTerm(); |
|
356 } |
|
357 |
|
358 LOCAL_C void createIncDecArrays() |
|
359 // |
|
360 // Writes an array of results of pre and post increment and decrement operations to the |
|
361 // header file |
|
362 // |
|
363 { |
|
364 TInt ii; |
|
365 TReal64 f; |
|
366 |
|
367 // Generate arrays for exact tests |
|
368 |
|
369 appendArrayName64(_L("preIncArray1")); |
|
370 for (ii=0; ii<sizeIncDec; ii++) |
|
371 { |
|
372 f=incDecInput[ii]; |
|
373 ++f; |
|
374 appendValue64(&f); |
|
375 } |
|
376 appendArrayTerm(); |
|
377 |
|
378 appendArrayName64(_L("preIncArray2")); |
|
379 for (ii=0; ii<sizeIncDec; ii++) |
|
380 { |
|
381 f=incDecInput[ii]; |
|
382 ++f; |
|
383 ++f; |
|
384 appendValue64(&f); |
|
385 } |
|
386 appendArrayTerm(); |
|
387 |
|
388 appendArrayName64(_L("preDecArray1")); |
|
389 for (ii=0; ii<sizeIncDec; ii++) |
|
390 { |
|
391 f=incDecInput[ii]; |
|
392 --f; |
|
393 appendValue64(&f); |
|
394 } |
|
395 appendArrayTerm(); |
|
396 |
|
397 appendArrayName64(_L("preDecArray2")); |
|
398 for (ii=0; ii<sizeIncDec; ii++) |
|
399 { |
|
400 f=incDecInput[ii]; |
|
401 --f; |
|
402 --f; |
|
403 appendValue64(&f); |
|
404 } |
|
405 appendArrayTerm(); |
|
406 |
|
407 appendArrayName64(_L("postIncArray1")); |
|
408 for (ii=0; ii<sizeIncDec; ii++) |
|
409 { |
|
410 f=incDecInput[ii]; |
|
411 f++; |
|
412 appendValue64(&f); |
|
413 } |
|
414 appendArrayTerm(); |
|
415 |
|
416 appendArrayName64(_L("postIncArray2")); |
|
417 for (ii=0; ii<sizeIncDec; ii++) |
|
418 { |
|
419 f=incDecInput[ii]; |
|
420 f++; |
|
421 f++; |
|
422 appendValue64(&f); |
|
423 } |
|
424 appendArrayTerm(); |
|
425 |
|
426 appendArrayName64(_L("postDecArray1")); |
|
427 for (ii=0; ii<sizeIncDec; ii++) |
|
428 { |
|
429 f=incDecInput[ii]; |
|
430 f--; |
|
431 appendValue64(&f); |
|
432 } |
|
433 appendArrayTerm(); |
|
434 |
|
435 appendArrayName64(_L("postDecArray2")); |
|
436 for (ii=0; ii<sizeIncDec; ii++) |
|
437 { |
|
438 f=incDecInput[ii]; |
|
439 f--; |
|
440 f--; |
|
441 appendValue64(&f); |
|
442 } |
|
443 appendArrayTerm(); |
|
444 } |
|
445 |
|
446 LOCAL_C void createArrays() |
|
447 // |
|
448 // Create and append to header file all arrays required for T_R64.CPP tests |
|
449 // |
|
450 { |
|
451 createAddArray(); |
|
452 createSubArray(); |
|
453 createMultArray(); |
|
454 createDivArray(); |
|
455 createUnaryArray(); |
|
456 createIncDecArrays(); |
|
457 } |
|
458 #endif |
|
459 |
|
460 GLDEF_C void CallTestsL(void) |
|
461 // |
|
462 // Generate TReal64s (and special values if required) and write to header files |
|
463 // |
|
464 { |
|
465 |
|
466 test.Title(); |
|
467 |
|
468 #ifdef __GENERATE_TR64 |
|
469 TFileName msg; |
|
470 msg=_L("Generating Maths constants to header files:\n "); |
|
471 msg+=pathName; |
|
472 msg+=fileNameW64; |
|
473 msg+=_L(" and "); |
|
474 msg+=fileNameA64; |
|
475 test.Start(msg); |
|
476 #endif |
|
477 |
|
478 TInt r=TheFs.MkDirAll(pathName); |
|
479 test(r==KErrNone || r==KErrAlreadyExists); |
|
480 test(TheFs.SetSessionPath(pathName)==KErrNone); |
|
481 |
|
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")); |
|
488 createArrays(); |
|
489 fw.Close(); |
|
490 fa.Close(); |
|
491 #endif |
|
492 |
|
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")); |
|
499 fspw.Close(); |
|
500 fspa.Close(); |
|
501 #endif |
|
502 |
|
503 |
|
504 test.End(); |
|
505 |
|
506 return; |
|
507 } |