1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/math/t_gen.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,507 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// f32test\math\t_gen.cpp
1.18 +// Generates files to be used in testing whether arithmetic in TReal32 and TReal64 gives
1.19 +// exactly the same results using the MSDEV complier as on the rack.
1.20 +//
1.21 +//
1.22 +
1.23 +#include <e32test.h>
1.24 +#include <f32file.h>
1.25 +#include <e32svr.h>
1.26 +#include "../server/t_server.h"
1.27 +#include "t_math.h"
1.28 +
1.29 +GLDEF_D RTest test(_L("T_GEN"));
1.30 +
1.31 +LOCAL_D const TFileName pathName = _L("C:\\F32-TST\\E32-MATH\\");
1.32 +LOCAL_D TBuf<0x100> buf;
1.33 +LOCAL_D TBuf8<0x100> buf8;
1.34 +
1.35 +
1.36 +#define __GENERATE_SPECIAL_VALUES
1.37 +#ifdef __GENERATE_SPECIAL_VALUES
1.38 +
1.39 +LOCAL_D RFile fspw; // file for special values for WINS
1.40 +LOCAL_D RFile fspa; // file for special values for ARM
1.41 +
1.42 +LOCAL_D const TFileName fileNameWSp = _L("T_VALS.HWG");
1.43 +LOCAL_D const TFileName fileNameASp = _L("T_VALS.HAG");
1.44 +
1.45 +LOCAL_C void appendConstTI64(TPtrC aName,TReal64* aVal)
1.46 + {
1.47 + // for WINS
1.48 + buf=_L("");
1.49 + buf.AppendFormat(_L("const TInt64 %S = TInt64(0x%x,0x%x);\n"),&aName,*(((TUint32*)aVal) + 1),*(TUint32*)aVal);
1.50 + buf8.Copy(buf); // Unicode
1.51 + fspw.Write(buf8);
1.52 + // for ARM
1.53 + buf=_L("");
1.54 + buf.AppendFormat(_L("const TInt64 %S = TInt64(0x%x,0x%x);\n"),&aName,*(TUint32*)aVal,*(((TUint32*)aVal) + 1));
1.55 + buf8.Copy(buf);
1.56 + fspa.Write(buf8);
1.57 + }
1.58 +
1.59 +LOCAL_C void appendConstTI32x(TPtrC aName,TReal32* aVal)
1.60 + {
1.61 + // for WINS and ARM
1.62 + buf=_L("");
1.63 + buf.AppendFormat(_L("const TInt32x %S = TInt32x(0x%x);\n"),&aName,*(TUint32*)aVal);
1.64 + buf8.Copy(buf); // Unicode
1.65 + fspw.Write(buf8);
1.66 + fspa.Write(buf8);
1.67 + }
1.68 +
1.69 +LOCAL_C void appendConstTR64(TPtrC aName,TPtrC aIntName)
1.70 + {
1.71 + // for WINS and ARM
1.72 + buf=_L("");
1.73 + buf.AppendFormat(_L("const TReal64 %S = *(TReal64*)&%S;\n"),&aName,&aIntName);
1.74 + buf8.Copy(buf); // Unicode
1.75 + fspw.Write(buf8);
1.76 + fspa.Write(buf8);
1.77 + }
1.78 +
1.79 +LOCAL_C void appendConstTR32(TPtrC aName,TPtrC aIntName)
1.80 + {
1.81 + // for WINS and ARM
1.82 + buf=_L("");
1.83 + buf.AppendFormat(_L("const TReal32 %S = *(TReal32*)&%S;\n"),&aName,&aIntName);
1.84 + buf8.Copy(buf);
1.85 + fspw.Write(buf8);
1.86 + fspa.Write(buf8);
1.87 + }
1.88 +
1.89 +LOCAL_C void appendConstTR(TPtrC aName,TPtrC a64Name)
1.90 + {
1.91 + // for WINS and ARM
1.92 + buf=_L("");
1.93 + buf.AppendFormat(_L("const TReal %S = TReal(%S);\n"),&aName,&a64Name);
1.94 + buf8.Copy(buf); // Unicode
1.95 + fspw.Write(buf8);
1.96 + fspa.Write(buf8);
1.97 + }
1.98 +
1.99 +LOCAL_C void appendStart()
1.100 + {
1.101 + // for WINS
1.102 + fspw.Write(_L8("/* Generated by \\E32\\TMATH\\T_GEN.MAK for WINS (little-endian doubles) */\n\n"));
1.103 + fspw.Write(_L8("#include <e32std.h>\n\n"));
1.104 + fspw.Write(_L8("class TInt32x\n{\npublic:\n"));
1.105 + fspw.Write(_L8("TInt32x(TInt32 aInt) {iInt=aInt;}\n"));
1.106 + fspw.Write(_L8("public:\nTInt32 iInt;\n};\n\n"));
1.107 +
1.108 + // for ARM
1.109 + fspa.Write(_L8("/* Generated by \\E32\\TMATH\\T_GEN.MAK for ARM (big-endian doubles)*/\n\n"));
1.110 + fspa.Write(_L8("#include <e32std.h>\n\n"));
1.111 + fspa.Write(_L8("class TInt32x\n{\npublic:\n"));
1.112 + fspa.Write(_L8("TInt32x(TInt32 aInt) {iInt=aInt;}\n"));
1.113 + fspa.Write(_L8("public:\nTInt32 iInt;\n};\n\n"));
1.114 + }
1.115 +
1.116 +LOCAL_C void generateSpecialValues()
1.117 +//
1.118 +// The following are to avoid the errors in the compiler in converting from string
1.119 +// to floating point
1.120 +//
1.121 +// Initialise max/min values and square roots and write to header files
1.122 +//
1.123 + {
1.124 +
1.125 + TReal64 minTReal32in64;
1.126 + SReal64 *p64=(SReal64*)&minTReal32in64;
1.127 + p64->sign=0;
1.128 + p64->exp=0x381;
1.129 + p64->msm=0;
1.130 + p64->lsm=0;
1.131 +
1.132 + TReal64 maxTReal32in64;
1.133 + p64=(SReal64*)&maxTReal32in64;
1.134 + p64->sign=0;
1.135 + p64->exp=0x47E;
1.136 + p64->msm=0xfffff;
1.137 + p64->lsm=0xe0000000;
1.138 +
1.139 + TReal64 sqrtMaxTReal64;
1.140 + const TReal64 arg1=KMaxTReal64-1.0E+299; // Take off this to avoid overflow
1.141 + TInt ret=Math::Sqrt(sqrtMaxTReal64,arg1);
1.142 + TReal64 sqrtMinTReal64;
1.143 + const TReal64 arg2=KMinTReal64;
1.144 + ret=Math::Sqrt(sqrtMinTReal64,arg2);
1.145 +
1.146 + TReal64 sqrtMaxTReal32in64,sqrtMinTReal32in64;
1.147 +
1.148 + TReal64 negZeroTReal64;
1.149 + p64=(SReal64*)&negZeroTReal64;
1.150 + p64->sign=1;
1.151 + p64->exp=0;
1.152 + p64->msm=0;
1.153 + p64->lsm=0;
1.154 +
1.155 + TReal64 posInfTReal64;
1.156 + p64=(SReal64*)&posInfTReal64;
1.157 + p64->sign=0;
1.158 + p64->exp=KTReal64SpecialExponent;
1.159 + p64->msm=0;
1.160 + p64->lsm=0;
1.161 +
1.162 + TReal64 negInfTReal64;
1.163 + p64=(SReal64*)&negInfTReal64;
1.164 + p64->sign=1;
1.165 + p64->exp=KTReal64SpecialExponent;
1.166 + p64->msm=0;
1.167 + p64->lsm=0;
1.168 +
1.169 + TReal64 NaNTReal64;
1.170 + p64=(SReal64*)&NaNTReal64;
1.171 + p64->sign=0;
1.172 + p64->exp=KTReal64SpecialExponent;
1.173 + p64->msm=0xfffffu;
1.174 + p64->lsm=0xffffffffu;
1.175 +
1.176 + TReal32 sqrtMaxTReal32;
1.177 + const TReal arg3=maxTReal32in64-1.0E+32f; // Take off this to avoid overflow
1.178 + ret=Math::Sqrt(sqrtMaxTReal32in64,arg3);
1.179 + sqrtMaxTReal32=TReal32(sqrtMaxTReal32in64);
1.180 +
1.181 + TReal32 sqrtMinTReal32;
1.182 + const TReal arg4=minTReal32in64;
1.183 + ret=Math::Sqrt(sqrtMinTReal32in64,arg4);
1.184 + sqrtMinTReal32=TReal32(sqrtMinTReal32in64);
1.185 +
1.186 + TReal32 negZeroTReal32;
1.187 + SReal32 *p32=(SReal32*)&negZeroTReal32;
1.188 + p32->sign=1;
1.189 + p32->exp=0;
1.190 + p32->man=0;
1.191 +
1.192 + appendStart();
1.193 +
1.194 + appendConstTI64(_L("minTReal32in64"),&minTReal32in64);
1.195 + appendConstTI64(_L("maxTReal32in64"),&maxTReal32in64);
1.196 + appendConstTI64(_L("sqrtMaxTReal64"),&sqrtMaxTReal64);
1.197 + appendConstTI64(_L("sqrtMinTReal64"),&sqrtMinTReal64);
1.198 + appendConstTI64(_L("negZeroTReal64"),&negZeroTReal64);
1.199 + appendConstTI64(_L("posInfTReal64"),&posInfTReal64);
1.200 + appendConstTI64(_L("negInfTReal64"),&negInfTReal64);
1.201 + appendConstTI64(_L("NaNTReal64"),&NaNTReal64);
1.202 +
1.203 + appendConstTI32x(_L("sqrtMaxTReal32"),&sqrtMaxTReal32);
1.204 + appendConstTI32x(_L("sqrtMinTReal32"),&sqrtMinTReal32);
1.205 + appendConstTI32x(_L("negZeroTReal32"),&negZeroTReal32);
1.206 +
1.207 + appendConstTR64(_L("KMinTReal32in64"),_L("minTReal32in64"));
1.208 + appendConstTR64(_L("KMaxTReal32in64"),_L("maxTReal32in64"));
1.209 + appendConstTR64(_L("KSqrtMaxTReal64"),_L("sqrtMaxTReal64"));
1.210 + appendConstTR64(_L("KSqrtMinTReal64"),_L("sqrtMinTReal64"));
1.211 + appendConstTR64(_L("KNegZeroTReal64"),_L("negZeroTReal64"));
1.212 + appendConstTR64(_L("KPosInfTReal64"),_L("posInfTReal64"));
1.213 + appendConstTR64(_L("KNegInfTReal64"),_L("negInfTReal64"));
1.214 + appendConstTR64(_L("KNaNTReal64"),_L("NaNTReal64"));
1.215 +
1.216 + appendConstTR32(_L("KSqrtMaxTReal32"),_L("sqrtMaxTReal32"));
1.217 + appendConstTR32(_L("KSqrtMinTReal32"),_L("sqrtMinTReal32"));
1.218 + appendConstTR32(_L("KNegZeroTReal32"),_L("negZeroTReal32"));
1.219 +
1.220 + appendConstTR(_L("KMinTReal32inTReal"),_L("KMinTReal32in64"));
1.221 + appendConstTR(_L("KMaxTReal32inTReal"),_L("KMaxTReal32in64"));
1.222 + appendConstTR(_L("KNegZeroTReal"),_L("KNegZeroTReal64"));
1.223 + }
1.224 +
1.225 +#endif
1.226 +
1.227 +//#define __GENERATE_TR64
1.228 +#ifdef __GENERATE_TR64
1.229 +
1.230 +// Data for tests from T_R64DTA.cpp
1.231 +GLREF_D TReal64 addInput[];
1.232 +GLREF_D TReal64 subInput[];
1.233 +GLREF_D TReal64 multInput[];
1.234 +GLREF_D TReal64 divInput[];
1.235 +GLREF_D TReal64 unaryInput[];
1.236 +GLREF_D TReal64 incDecInput[];
1.237 +GLREF_D TInt sizeAdd;
1.238 +GLREF_D TInt sizeSub;
1.239 +GLREF_D TInt sizeMult;
1.240 +GLREF_D TInt sizeDiv;
1.241 +GLREF_D TInt sizeUnary;
1.242 +GLREF_D TInt sizeIncDec;
1.243 +
1.244 +LOCAL_D RFile fw; // file for WINS
1.245 +LOCAL_D RFile fa; // file for ARM
1.246 +LOCAL_D const TFileName fileNameW64 = _L("T_REAL64.HWG");
1.247 +LOCAL_D const TFileName fileNameA64 = _L("T_REAL64.HAG");
1.248 +
1.249 +LOCAL_C void appendArrayName64(TDesC& aName)
1.250 + {
1.251 + buf=_L("");
1.252 + buf.AppendFormat(_L("const TInt64 %S[] = \n{\n"),&aName);
1.253 + fw.Write(buf);
1.254 + fa.Write(buf);
1.255 + }
1.256 +
1.257 +LOCAL_C void appendValue64(TReal64* aVal)
1.258 + {
1.259 + buf=_L("");
1.260 + buf.AppendFormat(_L(" TInt64(0x%x,0x%x),\n"),*(((TUint32*)aVal) + 1),*(TUint32*)aVal);
1.261 + fw.Write(buf);
1.262 + buf=_L("");
1.263 + buf.AppendFormat(_L(" TInt64(0x%x,0x%x),\n"),*(TUint32*)aVal,*(((TUint32*)aVal) + 1));
1.264 + fa.Write(buf);
1.265 + }
1.266 +
1.267 +LOCAL_C void appendArrayTerm()
1.268 + {
1.269 + buf=_L("};\n\n");
1.270 + fw.Write(buf);
1.271 + fa.Write(buf);
1.272 + }
1.273 +
1.274 +LOCAL_C void createAddArray()
1.275 +//
1.276 +// Writes an array of results of additions to the header file
1.277 +//
1.278 + {
1.279 + TInt ii;
1.280 + TReal64 ff;
1.281 +
1.282 + appendArrayName64(_L("addArray"));
1.283 + for (ii=0; ii<sizeAdd-1; ii++)
1.284 + {
1.285 + ff=addInput[ii]+addInput[ii+1];
1.286 + appendValue64(&ff);
1.287 + }
1.288 + appendArrayTerm();
1.289 + }
1.290 +
1.291 +LOCAL_C void createSubArray()
1.292 +//
1.293 +// Writes an array of results of subtractions to the header file
1.294 +//
1.295 + {
1.296 + TInt ii;
1.297 + TReal64 ff;
1.298 +
1.299 + appendArrayName64(_L("subArray"));
1.300 + for (ii=0; ii<sizeSub-1; ii++)
1.301 + {
1.302 + ff=subInput[ii]-subInput[ii+1];
1.303 + appendValue64(&ff);
1.304 + }
1.305 + appendArrayTerm();
1.306 + }
1.307 +
1.308 +LOCAL_C void createMultArray()
1.309 +//
1.310 +// Writes an array of results of multiplications to the header file
1.311 +//
1.312 + {
1.313 + TInt ii;
1.314 + TReal64 ff;
1.315 +
1.316 + appendArrayName64(_L("multArray"));
1.317 + for (ii=0; ii<sizeMult-1; ii++)
1.318 + {
1.319 + ff=multInput[ii]*multInput[ii+1];
1.320 + appendValue64(&ff);
1.321 + }
1.322 + appendArrayTerm();
1.323 + }
1.324 +
1.325 +LOCAL_C void createDivArray()
1.326 +//
1.327 +// Writes an array of results of divisions to the header file
1.328 +//
1.329 + {
1.330 + TInt ii;
1.331 + TReal64 ff;
1.332 +
1.333 + appendArrayName64(_L("divArray"));
1.334 + for (ii=0; ii<sizeDiv-1; ii++)
1.335 + {
1.336 + if (divInput[ii+1]!=0)
1.337 + {
1.338 + ff=divInput[ii]/divInput[ii+1];
1.339 + appendValue64(&ff);
1.340 + }
1.341 + }
1.342 + appendArrayTerm();
1.343 + }
1.344 +
1.345 +LOCAL_C void createUnaryArray()
1.346 +//
1.347 +// Writes an array of results of unary operations to the header file
1.348 +//
1.349 + {
1.350 + TReal64 f;
1.351 +
1.352 + appendArrayName64(_L("unaryArray"));
1.353 + for (TInt ii=0; ii<sizeUnary; ii++)
1.354 + {
1.355 + f=-unaryInput[ii];
1.356 + appendValue64(&f);
1.357 + }
1.358 + appendArrayTerm();
1.359 + }
1.360 +
1.361 +LOCAL_C void createIncDecArrays()
1.362 +//
1.363 +// Writes an array of results of pre and post increment and decrement operations to the
1.364 +// header file
1.365 +//
1.366 + {
1.367 + TInt ii;
1.368 + TReal64 f;
1.369 +
1.370 + // Generate arrays for exact tests
1.371 +
1.372 + appendArrayName64(_L("preIncArray1"));
1.373 + for (ii=0; ii<sizeIncDec; ii++)
1.374 + {
1.375 + f=incDecInput[ii];
1.376 + ++f;
1.377 + appendValue64(&f);
1.378 + }
1.379 + appendArrayTerm();
1.380 +
1.381 + appendArrayName64(_L("preIncArray2"));
1.382 + for (ii=0; ii<sizeIncDec; ii++)
1.383 + {
1.384 + f=incDecInput[ii];
1.385 + ++f;
1.386 + ++f;
1.387 + appendValue64(&f);
1.388 + }
1.389 + appendArrayTerm();
1.390 +
1.391 + appendArrayName64(_L("preDecArray1"));
1.392 + for (ii=0; ii<sizeIncDec; ii++)
1.393 + {
1.394 + f=incDecInput[ii];
1.395 + --f;
1.396 + appendValue64(&f);
1.397 + }
1.398 + appendArrayTerm();
1.399 +
1.400 + appendArrayName64(_L("preDecArray2"));
1.401 + for (ii=0; ii<sizeIncDec; ii++)
1.402 + {
1.403 + f=incDecInput[ii];
1.404 + --f;
1.405 + --f;
1.406 + appendValue64(&f);
1.407 + }
1.408 + appendArrayTerm();
1.409 +
1.410 + appendArrayName64(_L("postIncArray1"));
1.411 + for (ii=0; ii<sizeIncDec; ii++)
1.412 + {
1.413 + f=incDecInput[ii];
1.414 + f++;
1.415 + appendValue64(&f);
1.416 + }
1.417 + appendArrayTerm();
1.418 +
1.419 + appendArrayName64(_L("postIncArray2"));
1.420 + for (ii=0; ii<sizeIncDec; ii++)
1.421 + {
1.422 + f=incDecInput[ii];
1.423 + f++;
1.424 + f++;
1.425 + appendValue64(&f);
1.426 + }
1.427 + appendArrayTerm();
1.428 +
1.429 + appendArrayName64(_L("postDecArray1"));
1.430 + for (ii=0; ii<sizeIncDec; ii++)
1.431 + {
1.432 + f=incDecInput[ii];
1.433 + f--;
1.434 + appendValue64(&f);
1.435 + }
1.436 + appendArrayTerm();
1.437 +
1.438 + appendArrayName64(_L("postDecArray2"));
1.439 + for (ii=0; ii<sizeIncDec; ii++)
1.440 + {
1.441 + f=incDecInput[ii];
1.442 + f--;
1.443 + f--;
1.444 + appendValue64(&f);
1.445 + }
1.446 + appendArrayTerm();
1.447 + }
1.448 +
1.449 +LOCAL_C void createArrays()
1.450 +//
1.451 +// Create and append to header file all arrays required for T_R64.CPP tests
1.452 +//
1.453 + {
1.454 + createAddArray();
1.455 + createSubArray();
1.456 + createMultArray();
1.457 + createDivArray();
1.458 + createUnaryArray();
1.459 + createIncDecArrays();
1.460 + }
1.461 +#endif
1.462 +
1.463 +GLDEF_C void CallTestsL(void)
1.464 +//
1.465 +// Generate TReal64s (and special values if required) and write to header files
1.466 +//
1.467 + {
1.468 +
1.469 + test.Title();
1.470 +
1.471 +#ifdef __GENERATE_TR64
1.472 + TFileName msg;
1.473 + msg=_L("Generating Maths constants to header files:\n ");
1.474 + msg+=pathName;
1.475 + msg+=fileNameW64;
1.476 + msg+=_L(" and ");
1.477 + msg+=fileNameA64;
1.478 + test.Start(msg);
1.479 +#endif
1.480 +
1.481 + TInt r=TheFs.MkDirAll(pathName);
1.482 + test(r==KErrNone || r==KErrAlreadyExists);
1.483 + test(TheFs.SetSessionPath(pathName)==KErrNone);
1.484 +
1.485 +#ifdef __GENERATE_TR64
1.486 + test(fw.Replace(TheFs,fileNameW64,EFileWrite)==KErrNone);
1.487 + test(fa.Replace(TheFs,fileNameA64,EFileWrite)==KErrNone);
1.488 + test.Next(_L("Generating TReal64s"));
1.489 + fw.Write(_L("// Generated by \\E32\\TMATH\\T_GEN.MAK for WINS (little-endian doubles)\n\n"));
1.490 + fa.Write(_L("// Generated by \\E32\\TMATH\\T_GEN.MAK for ARM (big-endian doubles)\n\n"));
1.491 + createArrays();
1.492 + fw.Close();
1.493 + fa.Close();
1.494 +#endif
1.495 +
1.496 +#ifdef __GENERATE_SPECIAL_VALUES
1.497 + test(fspw.Replace(TheFs,fileNameWSp,EFileWrite)==KErrNone);
1.498 + test(fspa.Replace(TheFs,fileNameASp,EFileWrite)==KErrNone);
1.499 + test.Start(_L("Generate header file of special values for use in maths testing"));
1.500 + generateSpecialValues();
1.501 + test.Next(_L("Done - now closing files"));
1.502 + fspw.Close();
1.503 + fspa.Close();
1.504 +#endif
1.505 +
1.506 +
1.507 + test.End();
1.508 +
1.509 + return;
1.510 + }