|
1 // Copyright (c) 1995-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 // e32test\math\t_i64.cpp |
|
15 // Tests TInt64 |
|
16 // Overview: |
|
17 // Test 64-bit integer functionality. |
|
18 // API Information: |
|
19 // TInt64. |
|
20 // Details: |
|
21 // - Construct TInt64 with specified range of integer, real, high |
|
22 // and low values and check constructor, copy constructor are as expected. |
|
23 // - Test all the operators for range of values and check it is as expected. |
|
24 // - Check the logical shift of specified number of bits is as expected. |
|
25 // - Check multiplication of 64 bit integer by the specified 64 bit integer |
|
26 // using MulTop, fast multiplication of 64 bit integer by 10. |
|
27 // - Verify the 64 bit integer divide and mod results are as expected. |
|
28 // Platforms/Drives/Compatibility: |
|
29 // All. |
|
30 // Assumptions/Requirement/Pre-requisites: |
|
31 // Failures and causes: |
|
32 // Base Port information: |
|
33 // |
|
34 // |
|
35 |
|
36 #include <e32test.h> |
|
37 #include <e32math.h> |
|
38 |
|
39 inline TInt __i64multop(TInt64& aX, TInt64& aValue) |
|
40 { Uint64 __lowResult; \ |
|
41 Uint64 __highResult; \ |
|
42 Math::UMul64(aX, aValue, __highResult, __lowResult); \ |
|
43 aX = static_cast<TInt64>(__highResult); \ |
|
44 return (__lowResult == UI64LIT(0x0000000000000000)) ? -2 : \ |
|
45 (__lowResult < UI64LIT(0x8000000000000000)) ? -1 : \ |
|
46 (__lowResult == UI64LIT(0x8000000000000000)) ? 0 : \ |
|
47 /*__lowResult > UI64LIT(0x8000000000000000)*/ 1; \ |
|
48 } |
|
49 |
|
50 #define I64MULTOP(x, value) __i64multop(x, (value)) |
|
51 |
|
52 |
|
53 TInt HexMulAdd(TUint8 a1,TUint8 a2,TUint8& answer,TUint8& carry) |
|
54 { |
|
55 TUint x1= a1>'9' ? a1-'a'+10 : a1-'0'; |
|
56 TUint x2= a2>'9' ? a2-'a'+10 : a2-'0'; |
|
57 TUint a= answer>'9' ? answer-'a'+10 : answer-'0'; |
|
58 TUint c= carry>'9' ? carry-'a'+10 : carry-'0'; |
|
59 if (x1>15) return (KErrArgument); |
|
60 if (x2>15) return (KErrArgument); |
|
61 if (a>15) return (KErrArgument); |
|
62 if (c>15) return (KErrArgument); |
|
63 a+=(x1*x2)+c; |
|
64 c=a/16; |
|
65 a=a%16; |
|
66 a= a>9 ? a-10+'a' : a+'0'; |
|
67 c= c>9 ? c-10+'a' : c+'0'; |
|
68 answer=(TUint8)a; |
|
69 carry=(TUint8)c; |
|
70 return(KErrNone); |
|
71 } |
|
72 |
|
73 TInt HexMul(TDesC8& a1,TDesC8& a2,TDes8& a3) |
|
74 // |
|
75 // Infinite precision hex multiplier |
|
76 // |
|
77 { |
|
78 TInt l1=a1.Length(); |
|
79 TInt l2=a2.Length(); |
|
80 TInt l3=l1+l2; |
|
81 if (a3.MaxLength()<l3) |
|
82 return(KErrArgument); |
|
83 a3.Zero(); |
|
84 TInt x; |
|
85 TInt y; |
|
86 TInt z; |
|
87 for (x=0;x<l3;x++) |
|
88 a3.Append('0'); |
|
89 for (y=0;y<l2;y++) |
|
90 { |
|
91 TUint8 carry='0'; |
|
92 for (z=0;z<l1;z++) |
|
93 { |
|
94 if(HexMulAdd(a2[l2-y-1],a1[l1-z-1],a3[l3-y-z-1],carry)!=KErrNone) |
|
95 return(KErrArgument); |
|
96 } |
|
97 if(HexMulAdd('0','0',a3[l3-y-l1-1],carry)!=KErrNone) |
|
98 return(KErrArgument); |
|
99 } |
|
100 return(KErrNone); |
|
101 } |
|
102 |
|
103 |
|
104 LOCAL_D RTest test(_L("T_I64")); |
|
105 |
|
106 LOCAL_C void SlowDivMod(const TInt64& aA, const TInt64& aB, TInt64& aDiv, TInt64& aMod) |
|
107 // |
|
108 // Calculate Division/Remainder using repeated subtraction |
|
109 // |
|
110 { |
|
111 TInt negative=0; |
|
112 TInt64 t=0; |
|
113 |
|
114 if (aA<0) |
|
115 { |
|
116 negative=1; |
|
117 aMod=-aA; |
|
118 } |
|
119 else |
|
120 { |
|
121 aMod=aA; |
|
122 } |
|
123 if (aB<0) |
|
124 { |
|
125 if (negative) |
|
126 negative=0; |
|
127 else |
|
128 negative=1; |
|
129 t=-aB; |
|
130 } |
|
131 else |
|
132 { |
|
133 t=aB; |
|
134 } |
|
135 aDiv=0; |
|
136 |
|
137 if ((t & UI64LIT(0xffffffff00000000)) == 0) |
|
138 { |
|
139 while (aMod >= (t << 31)) |
|
140 { |
|
141 aDiv += static_cast<TUint32>(1 << 31); |
|
142 aMod -= t << 31; |
|
143 } |
|
144 } |
|
145 if ((t & UI64LIT(0xffffff0000000000)) == 0) |
|
146 { |
|
147 while (aMod >= (t << 23)) |
|
148 { |
|
149 aDiv += 1 << 23; |
|
150 aMod -= t << 23; |
|
151 } |
|
152 } |
|
153 if ((t & UI64LIT(0xffff000000000000)) == 0) |
|
154 { |
|
155 while (aMod >= (t << 15)) |
|
156 { |
|
157 aDiv += 1 << 15; |
|
158 aMod -= t << 15; |
|
159 } |
|
160 } |
|
161 if ((t & UI64LIT(0xff00000000000000)) == 0) |
|
162 { |
|
163 while (aMod >= (t << 7)) |
|
164 { |
|
165 aDiv += 1 << 7; |
|
166 aMod -= t << 7; |
|
167 } |
|
168 } |
|
169 if ((t & UI64LIT(0xf000000000000000)) == 0) |
|
170 { |
|
171 while (aMod >= (t << 3)) |
|
172 { |
|
173 aDiv += 1 << 3; |
|
174 aMod -= t << 3; |
|
175 } |
|
176 } |
|
177 while (aMod >= t) |
|
178 { |
|
179 ++aDiv; |
|
180 aMod -= t; |
|
181 } |
|
182 |
|
183 if (negative) |
|
184 { |
|
185 aDiv=-aDiv; |
|
186 } |
|
187 |
|
188 if (aA < 0) |
|
189 { |
|
190 aMod =- aMod; |
|
191 } |
|
192 } |
|
193 |
|
194 LOCAL_C void DivModTest(const TInt64& aA, const TInt64& aB) |
|
195 // |
|
196 // Test DivMod against SlowDivMod |
|
197 // |
|
198 { |
|
199 |
|
200 if (aB!=0) |
|
201 { |
|
202 TInt64 n(aA),d(aB); |
|
203 TInt64 div=0,mod=0,res=0; |
|
204 |
|
205 SlowDivMod(n,d,div,mod); |
|
206 |
|
207 res = n % d; |
|
208 n /= d; |
|
209 |
|
210 test(n==div); |
|
211 test(res==mod); |
|
212 } |
|
213 } |
|
214 |
|
215 |
|
216 LOCAL_C void Test1() |
|
217 { |
|
218 // Test the constructors |
|
219 |
|
220 // TInt64() |
|
221 test.Start(_L("Default constructor")); |
|
222 TInt64 t1; |
|
223 t1 = 0; // to prevent uninitialised warnings |
|
224 (void)(t1 > 0); // to prevent unused warnings |
|
225 |
|
226 // TInt64(TInt aVal) |
|
227 test.Next(_L("TInt64(TInt aVal)")); |
|
228 TInt64 t2(0); |
|
229 test(I64LOW(t2)==0 && I64HIGH(t2)==0); |
|
230 TInt64 t3(1); |
|
231 test(I64LOW(t3)==1 && I64HIGH(t3)==0); |
|
232 TInt64 t4(KMaxTInt32); |
|
233 test(I64LOW(t4)==(TUint)KMaxTInt32 && I64HIGH(t4)==0); |
|
234 TInt64 t5(-1); |
|
235 test(I64INT(t5)==-1); |
|
236 test(I64LOW(t5)==KMaxTUint32 && I64HIGH(t5)==KMaxTUint32); |
|
237 TInt64 t6(KMinTInt32); |
|
238 test(I64INT(t6)==KMinTInt32); |
|
239 |
|
240 // TInt64(TUint aVal) |
|
241 test.Next(_L("TInt64(TUint aVal)")); |
|
242 TInt64 t7((TUint)0); |
|
243 test(I64LOW(t7)==0 && I64HIGH(t7)==0); |
|
244 TInt64 t8((TUint)1); |
|
245 test(I64LOW(t8)==1 && I64HIGH(t8)==0); |
|
246 TInt64 t9(KMaxTUint32); |
|
247 test(I64LOW(t9)==KMaxTUint32 && I64HIGH(t9)==0); |
|
248 |
|
249 // TInt64(TUint aHigh,TUint aLow) |
|
250 test.Next(_L("TInt64(TUint aHigh,TUint aLow)")); |
|
251 TInt64 t10 = MAKE_TINT64(0,0); |
|
252 test(I64LOW(t10)==0 && I64HIGH(t10)==0); |
|
253 TInt64 t11 = MAKE_TINT64(KMaxTUint32,KMaxTUint32); // highest value stored === (2**64)-1 |
|
254 test(I64LOW(t11)==KMaxTUint32 && I64HIGH(t11)==KMaxTUint32); |
|
255 |
|
256 // TInt64(TReal aVal) |
|
257 test.Next(_L("TInt64(TReal aVal)")); |
|
258 TInt64 t12((TInt64)1.0); |
|
259 test(I64LOW(t12)==1 && I64HIGH(t12)==0); |
|
260 TInt64 t15((TInt64)4.99); |
|
261 test(I64LOW(t15)==4 && I64HIGH(t15)==0); |
|
262 |
|
263 TReal x; |
|
264 |
|
265 x = -9.223372036854776831e18; // -2^63 - 2^10 (to ensure rounding outside of TInt64 range) |
|
266 TInt64 t16((TInt64)x); |
|
267 test(t16==KMinTInt64); |
|
268 TInt64 t17((TInt64)0.5); |
|
269 test(I64LOW(t17)==0 && I64HIGH(t17)==0); |
|
270 TInt64 t18((TInt64)0.0); |
|
271 test(I64LOW(t18)==0 && I64HIGH(t18)==0); |
|
272 TInt64 t19((TInt64)-123325.23411412); |
|
273 test(I64LOW(t19)==(TUint)(-123325) && I64HIGH(t19)==0xffffffff); |
|
274 TInt64 t20((TInt64)1.0E-1); |
|
275 test(I64LOW(t20)==0 && I64HIGH(t20)==0); |
|
276 |
|
277 // Make variable volatile to protect ourselves from compiler optimisations. Given that the |
|
278 // following test is negative with unspecified results, we don't really care if we do not have |
|
279 // FPU/compiler parity. |
|
280 volatile TReal xout; |
|
281 xout = 9.223372036854776831e18; // 2^63 + 2^10 (to ensure rounding outside of TInt64 range) |
|
282 TInt64 t21((TInt64)xout); |
|
283 |
|
284 // IEEE 754 does not specify the value to be returned when a conversion |
|
285 // is performed on a value that is outside the range of the target, only |
|
286 // that an invalid operation exception be raised if the io fp exception |
|
287 // is not masked. |
|
288 #if defined(__WINS__) || defined(__X86__) |
|
289 // The x86 FPU returns KMin... as the "indefinite number" |
|
290 test(t21 == KMinTInt64); |
|
291 #else |
|
292 // The target compiler support libraries return KMax... |
|
293 test(t21 == KMaxTInt64); |
|
294 #endif |
|
295 |
|
296 TReal limit=1048576.0*1048576.0*8192.0; // integers <2^53 in modulus can be represented exactly |
|
297 TInt64 t22((TInt64)limit); |
|
298 test(I64LOW(t22)==0 && I64HIGH(t22)==0x00200000); |
|
299 TInt64 t23((TInt64)(limit-1.0)); |
|
300 test(I64LOW(t23)==0xffffffff && I64HIGH(t23)==0x001fffff); |
|
301 TReal i64limit=limit*1024.0; // 2^63 |
|
302 // Make variable volatile to protect ourselves from compiler optimisations. Given that the |
|
303 // following test is negative with unspecified results, we don't really care if we do not have |
|
304 // FPU/compiler parity. |
|
305 volatile TReal i64limitout=i64limit; |
|
306 TInt64 t24((TInt64)i64limitout); |
|
307 |
|
308 // IEEE 754 does not specify the value to be returned when a conversion |
|
309 // is performed on a value that is outside the range of the target, only |
|
310 // that an invalid operation exception be raised if the io fp exception |
|
311 // is not masked. |
|
312 #if defined(__WINS__) || defined(__X86__) |
|
313 // The x86 FPU returns KMin... as the "indefinite number" |
|
314 test(t24 == KMinTInt64); |
|
315 #else |
|
316 // The target compiler support libraries return KMax... |
|
317 test(t24 == KMaxTInt64); |
|
318 #endif |
|
319 |
|
320 TInt64 t25((TInt64)(i64limit-1024.0)); |
|
321 test(I64LOW(t25)==0xfffffc00 && I64HIGH(t25)==0x7fffffff); |
|
322 TInt64 t26((TInt64)-i64limit); |
|
323 test(I64LOW(t26)==0x00000000 && I64HIGH(t26)==0x80000000); |
|
324 TInt64 t27((TInt64)(1024.0-i64limit)); |
|
325 test(I64LOW(t27)==0x00000400 && I64HIGH(t27)==0x80000000); |
|
326 |
|
327 |
|
328 TInt i; |
|
329 TInt64 l; |
|
330 for (i=-99; i<100; i++) |
|
331 { |
|
332 x=1; |
|
333 l=1; |
|
334 TReal a(i); |
|
335 TInt64 b(i); |
|
336 while (Abs(x)<limit) |
|
337 { |
|
338 // test.Printf(_L("Testing %g\n"),x); |
|
339 TInt64 ll((TInt64)x); |
|
340 test(ll==l); |
|
341 ll=0; |
|
342 ll = (TInt64)x; |
|
343 test(ll==l); |
|
344 x*=a; |
|
345 l*=b; |
|
346 if (i==1 || i==0 || (i==-1 && l==TInt64(1))) |
|
347 break; |
|
348 } |
|
349 } |
|
350 |
|
351 // TInt64::GetTReal |
|
352 test.Next(_L("TInt64::GetTReal")); |
|
353 |
|
354 // GCC does optimise large portions of the test code out and there can be small |
|
355 // differences in the way GCC and the FPU round floating point values. |
|
356 // We isolate the following test by giving it its own variables. This should |
|
357 // prevent values returned by the FPU from being compared with wrong GCC calculations. |
|
358 TInt64 m = MAKE_TINT64(0x7fffffff,0xffffffff); |
|
359 TReal xy = I64REAL(m); |
|
360 TReal xx = 1048576.0*1048576.0*1048576.0*8.0 - 1.0; // 2^63 - 1 |
|
361 test(xy == xx); |
|
362 // |
|
363 |
|
364 l = MAKE_TINT64(0x7fffffff,0xfffffc00); |
|
365 x = I64REAL(l); |
|
366 |
|
367 test(x == (i64limit - 1024.0)); |
|
368 |
|
369 l = MAKE_TINT64(0x80000000,0x00000000); |
|
370 x = I64REAL(l); |
|
371 |
|
372 test(x == -i64limit); |
|
373 |
|
374 l = MAKE_TINT64(0x80000000,0x00000400); |
|
375 x = I64REAL(l); |
|
376 |
|
377 test(x == (1024.0 - i64limit)); |
|
378 |
|
379 l = MAKE_TINT64(0x00000001,0x00000000); |
|
380 x = I64REAL(l); |
|
381 |
|
382 test(x == (65536.0 * 65536.0)); |
|
383 |
|
384 l = MAKE_TINT64(0xffffffff,0x00000000); |
|
385 x = I64REAL(l); |
|
386 |
|
387 test(x == (-65536.0 * 65536.0)); |
|
388 |
|
389 for (i=-99; i<100; i++) |
|
390 { |
|
391 x=1; |
|
392 l=1; |
|
393 TReal a(i); |
|
394 TInt64 b(i); |
|
395 while (Abs(x)<limit) |
|
396 { |
|
397 // test.Printf(_L("Testing %g\n"),x); |
|
398 TReal y = I64REAL(l); |
|
399 test(y==x); |
|
400 x*=a; |
|
401 l*=b; |
|
402 if (i==1 || i==0 || (i==-1 && l==TInt64(1))) |
|
403 break; |
|
404 } |
|
405 } |
|
406 |
|
407 // TInt64(const TInt64& aVal) |
|
408 test.Next(_L("Copy constructor")); |
|
409 TInt64 t13(t10); |
|
410 test(I64LOW(t13)==I64LOW(t10) && I64HIGH(t13)==I64HIGH(t10)); |
|
411 |
|
412 test.Next(_L("Set")); |
|
413 t13 = MAKE_TINT64(0, 0); |
|
414 test(I64LOW(t13)==0 && I64HIGH(t13)==0); |
|
415 test.End(); |
|
416 } |
|
417 |
|
418 LOCAL_C void Test1_2() |
|
419 // |
|
420 // Test Unary operators -, and + |
|
421 // |
|
422 { |
|
423 TInt64 r(0),q(0); |
|
424 |
|
425 r=1; |
|
426 test(-r==-1); |
|
427 test(+r==1); |
|
428 r=-100; |
|
429 test(-r==100); |
|
430 test(+r==-100); |
|
431 r = MAKE_TINT64(540423,21344); |
|
432 test(-r==(q-r)); |
|
433 test(+r==r); |
|
434 test(+r==MAKE_TINT64(540423,21344)); |
|
435 r=0; |
|
436 test(-r==0); |
|
437 test(+r==0); |
|
438 } |
|
439 |
|
440 |
|
441 LOCAL_C void Test2() |
|
442 { |
|
443 // Test the operators |
|
444 |
|
445 // = |
|
446 test.Start(_L("=")); |
|
447 TInt64 r=0,r2=0, a = MAKE_TINT64(12345,54321); |
|
448 r=KMaxTInt32; |
|
449 test(I64LOW(r)==(TUint)KMaxTInt32 && I64HIGH(r)==0); |
|
450 r2=r=KMinTInt32; |
|
451 test(I64INT(r)==KMinTInt32); |
|
452 test(I64INT(r2)==KMinTInt32); |
|
453 r2=r=KMaxTUint32; |
|
454 test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==0); |
|
455 test(I64LOW(r2)==KMaxTUint32 && I64HIGH(r2)==0); |
|
456 r2=r=a; |
|
457 test(I64LOW(r)==I64LOW(a) && I64HIGH(r)==I64HIGH(a)); |
|
458 test(I64LOW(r2)==I64LOW(a) && I64HIGH(r2)==I64HIGH(a)); |
|
459 |
|
460 r2=r=(TInt64)((TReal)1.2); |
|
461 test(r==1); |
|
462 test(r2==1); |
|
463 r2=r=(TInt64)((TReal)20.9); |
|
464 test(r==20); |
|
465 test(r2==20); |
|
466 r2=r=(TInt64)((TReal)-100.2); |
|
467 test(r==-100); |
|
468 test(r2==-100); |
|
469 |
|
470 |
|
471 |
|
472 // +=, -=, *=, /=, %=, >>=, <<=, >>, << |
|
473 // += |
|
474 test.Next(_L("+=")); |
|
475 r=-1; |
|
476 r+=1; |
|
477 test(I64INT(r)==0); |
|
478 |
|
479 r+=1; |
|
480 test(I64INT(r)==1); |
|
481 |
|
482 r=KMaxTUint32; |
|
483 r+=1; |
|
484 test(I64INT(r)-1==(TInt)KMaxTUint32); |
|
485 |
|
486 r=KMinTInt32; |
|
487 r+=1; |
|
488 test(I64INT(r)==KMinTInt32+1); |
|
489 |
|
490 r=0; |
|
491 r+=MAKE_TINT64(0,0x80000000u); |
|
492 test(r==MAKE_TINT64(0,0x80000000u)); |
|
493 |
|
494 // -= |
|
495 test.Next(_L("-=")); |
|
496 r=-1; |
|
497 r-=1; |
|
498 test(I64INT(r)==-2); |
|
499 r=0; |
|
500 r-=1; |
|
501 test(I64INT(r)==-1); |
|
502 r=1; |
|
503 r-=1; |
|
504 test(I64INT(r)==0); |
|
505 r=KMaxTUint32; |
|
506 r+=1; |
|
507 r-=1; |
|
508 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
509 test(I64INT(r)==(TInt)KMaxTUint32); |
|
510 r-=1; |
|
511 test(I64INT(r)==(TInt)(KMaxTUint32-1)); |
|
512 |
|
513 |
|
514 // *= |
|
515 test.Next(_L("*=")); |
|
516 r=KMaxTUint32; // ffffffff * 2 = 1 fffffffe |
|
517 r*=2; |
|
518 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1); |
|
519 |
|
520 r=KMaxTUint32-1; |
|
521 r*=2; |
|
522 r+=2; |
|
523 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1); |
|
524 |
|
525 r=KMaxTUint32; |
|
526 r+=1; |
|
527 r*=2; |
|
528 test(I64HIGH(r)==2 && I64LOW(r)==0); |
|
529 |
|
530 TUint PosMinTInt=(TUint)KMinTInt32; |
|
531 r=PosMinTInt; |
|
532 r*=-1; |
|
533 test(I64INT(r)==KMinTInt32); |
|
534 |
|
535 r=KMinTInt32; |
|
536 r*=-1; |
|
537 r-=1; |
|
538 test(I64INT(r)==KMaxTInt32); |
|
539 |
|
540 r=KMaxTUint32; // ffffffff * ffffffff + (2 * ffffffff) = ffffffff ffffffff |
|
541 r*=KMaxTUint32; |
|
542 r+=KMaxTUint32; |
|
543 r+=KMaxTUint32; |
|
544 test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32); |
|
545 |
|
546 r=KMaxTUint32; |
|
547 r+=1; |
|
548 r*=2; |
|
549 test(I64LOW(r)==0 && I64HIGH(r)==2); |
|
550 |
|
551 |
|
552 // /= |
|
553 test.Next(_L("/=")); |
|
554 r=4; |
|
555 r/=2; |
|
556 test(I64INT(r)==2); |
|
557 r=4; |
|
558 r/=-2; |
|
559 test(I64INT(r)==-2); |
|
560 r=-4; |
|
561 r/=1; |
|
562 test(I64INT(r)==-4); |
|
563 r=-8; |
|
564 |
|
565 r/=-2; |
|
566 test(I64INT(r)==4); |
|
567 r=4; |
|
568 |
|
569 r/=4; |
|
570 test(I64INT(r)==1); |
|
571 r=0; |
|
572 |
|
573 r/=4; |
|
574 test(I64INT(r)==0); |
|
575 r=KMaxTUint32; |
|
576 TInt64 z(KMaxTUint32); |
|
577 r/=z; |
|
578 test(I64INT(r)==1); |
|
579 r=KMinTInt32; |
|
580 z=KMinTInt32; |
|
581 r/=z; |
|
582 test(I64INT(r)==1); |
|
583 r=KMinTInt32; |
|
584 z = MAKE_TINT64(0,(TUint)KMinTInt32); |
|
585 r/=z; |
|
586 test(I64INT(r)==-1); |
|
587 r=KMaxTUint32; |
|
588 r*=2; |
|
589 r/=2; |
|
590 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
591 r=KMaxTUint32; |
|
592 a=KMaxTUint32; |
|
593 r*=z; |
|
594 r/=z; |
|
595 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
596 r = MAKE_TINT64(0,(TUint)KMinTInt32); |
|
597 r/=-1; |
|
598 test(I64LOW(r)==(TUint)KMinTInt32); |
|
599 r=0; |
|
600 r/=KMaxTUint32; |
|
601 test(I64INT(r)==0); |
|
602 r=0; |
|
603 r/=KMinTInt32; |
|
604 test(I64INT(r)==0); |
|
605 r=0; |
|
606 TInt64 b = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
607 r/=b; |
|
608 test(I64INT(r)==0); |
|
609 TInt64 c = MAKE_TINT64(KMaxTUint32,KMaxTUint32); // -1/Anything == 0 |
|
610 TInt64* cptr = &c; // MSVC compiler calculates -1/anything at compile time |
|
611 *cptr /= KMaxTUint32; // and gets it wrong if we don't use a pointer, bizarre. |
|
612 test(I64LOW(c)==0 && I64HIGH(c)==0); |
|
613 r=-1; |
|
614 z=1; |
|
615 r/=z; |
|
616 test(r==-1); |
|
617 r=-r; |
|
618 r/=z; |
|
619 test(r==1); |
|
620 r = MAKE_TINT64(0x01,KMaxTUint32); |
|
621 z=2; |
|
622 r/=z; |
|
623 test(r==TInt64(KMaxTUint32)); |
|
624 r = MAKE_TINT64(0x01,KMaxTUint32); |
|
625 z = MAKE_TINT64(0,KMaxTUint32); |
|
626 r/=z; |
|
627 test(r==TInt64(2)); |
|
628 r = MAKE_TINT64(1,0); |
|
629 r/=z; |
|
630 test(r==TInt64(1)); |
|
631 r = MAKE_TINT64(6221,5621243); |
|
632 z = MAKE_TINT64(3,42011); |
|
633 r/=z; |
|
634 test(r==2073); |
|
635 r=100; |
|
636 z=99; |
|
637 r/=z; |
|
638 test(r==1); |
|
639 r = MAKE_TINT64(17,KMaxTUint32); |
|
640 z = MAKE_TINT64(0,8); |
|
641 test((r/=z)==MAKE_TINT64(0x2, 0x3fffffff)); |
|
642 |
|
643 // %= |
|
644 test.Next(_L("%=")); |
|
645 r=4; |
|
646 r%=4; |
|
647 test(I64INT(r)==0); |
|
648 r=4; |
|
649 r%=1; |
|
650 test(I64INT(r)==0); |
|
651 r=5; |
|
652 r%=3; |
|
653 test(I64INT(r)==2); |
|
654 r=(-5); |
|
655 r%=3; |
|
656 test(I64INT(r)==(-2)); |
|
657 r = MAKE_TINT64(134,KMaxTUint32-10342); |
|
658 z = MAKE_TINT64(134,0); |
|
659 test((r%=z)==KMaxTUint32-10342); |
|
660 r = MAKE_TINT64(134,KMaxTUint32-10342); |
|
661 z = MAKE_TINT64(134,KMaxTUint32-10343); |
|
662 test((r%=z)==1); |
|
663 r = MAKE_TINT64(1363,0xfd432ab0u); |
|
664 z = MAKE_TINT64(0,16); |
|
665 test((r%=z)==0); |
|
666 |
|
667 r=-10; |
|
668 r%=3; |
|
669 test(r==-1); |
|
670 r=-10; |
|
671 r%=-3; |
|
672 test(r==-1); |
|
673 r=10; |
|
674 r%=3; |
|
675 test(r==1); |
|
676 r=10; |
|
677 r%=-3; |
|
678 test(r==1); |
|
679 |
|
680 // <<= and >>= |
|
681 // <<= |
|
682 test.Next(_L("<<=")); |
|
683 r=1; |
|
684 r<<=32; |
|
685 test(I64LOW(r)==0 && I64HIGH(r)==1); |
|
686 r<<=31; |
|
687 test(I64LOW(r)==0 && I64HIGH(r)==0x80000000); |
|
688 |
|
689 r=1; |
|
690 r<<=31; |
|
691 test(I64LOW(r)==0x80000000 && I64HIGH(r)==0); |
|
692 r<<=32; |
|
693 test(I64LOW(r)==0 && I64HIGH(r)==0x80000000); |
|
694 |
|
695 r=1; |
|
696 r<<=63; |
|
697 test(I64LOW(r)==0 && I64HIGH(r)==0x80000000); |
|
698 |
|
699 r=0; |
|
700 r<<=32; |
|
701 test(I64LOW(r)==0 && I64HIGH(r)==0); |
|
702 |
|
703 r=0xC0000000; // 1100000.......... |
|
704 r<<=1; |
|
705 test(I64HIGH(r)==1 && I64LOW(r)==0x80000000); // 100000....... |
|
706 r<<=1; |
|
707 test(I64HIGH(r)==3 && I64LOW(r)==0); |
|
708 r<<=1; |
|
709 test(I64HIGH(r)==6 && I64LOW(r)==0); |
|
710 |
|
711 r = MAKE_TINT64(0,KMaxTUint32); |
|
712 r<<=32; |
|
713 test(I64LOW(r)==0 && I64HIGH(r)==KMaxTUint32); |
|
714 |
|
715 // >>= |
|
716 test.Next(_L(">>=")); |
|
717 r = MAKE_TINT64(3,0); |
|
718 r>>=1; |
|
719 test(I64HIGH(r)==1 && I64LOW(r)==0x80000000); |
|
720 r>>=1; |
|
721 test(I64HIGH(r)==0 && I64LOW(r)==0xC0000000); |
|
722 |
|
723 r = MAKE_TINT64(0x80000000,0); |
|
724 r>>=(31); |
|
725 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0); |
|
726 r>>=(32); |
|
727 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
728 |
|
729 r = MAKE_TINT64(0x80000000,0); |
|
730 r>>=(32); |
|
731 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x80000000); |
|
732 |
|
733 r = MAKE_TINT64(0x80000000,0); |
|
734 r>>=63; |
|
735 test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32); |
|
736 |
|
737 r = MAKE_TINT64(KMaxTUint32, 0); |
|
738 r>>=32; |
|
739 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
740 |
|
741 // << |
|
742 test.Next(_L("<<")); |
|
743 r=1; |
|
744 TInt64 t = r<<32; |
|
745 test(I64LOW(t)==0 && I64HIGH(t)==1); |
|
746 t = t<<31; |
|
747 test(I64LOW(t)==0 && I64HIGH(t)==0x80000000); |
|
748 |
|
749 r=1; |
|
750 t = r<<31; |
|
751 test(I64LOW(t)==0x80000000 && I64HIGH(t)==0); |
|
752 t = t<<32; |
|
753 test(I64LOW(t)==0 && I64HIGH(t)==0x80000000); |
|
754 |
|
755 r=1; |
|
756 t = r<<63; |
|
757 test(I64LOW(t)==0 && I64HIGH(t)==0x80000000); |
|
758 |
|
759 r=0; |
|
760 t = r<<32; |
|
761 test(I64LOW(t)==0 && I64HIGH(t)==0); |
|
762 |
|
763 r=0xC0000000; // 1100000.......... |
|
764 t = r<<1; |
|
765 test(I64HIGH(t)==1 && I64LOW(t)==0x80000000); // 100000....... |
|
766 t = t<<1; |
|
767 test(I64HIGH(t)==3 && I64LOW(t)==0); |
|
768 t = t<<1; |
|
769 test(I64HIGH(t)==6 && I64LOW(t)==0); |
|
770 |
|
771 r = MAKE_TINT64(0,KMaxTUint32); |
|
772 t = r<<32; |
|
773 test(I64LOW(t)==0 && I64HIGH(t)==KMaxTUint32); |
|
774 |
|
775 // >> |
|
776 test.Next(_L(">>")); |
|
777 r = MAKE_TINT64(3,0); |
|
778 t = r>>1; |
|
779 test(I64HIGH(t)==1 && I64LOW(t)==0x80000000); |
|
780 t = t>>1; |
|
781 test(I64HIGH(t)==0 && I64LOW(t)==0xC0000000); |
|
782 |
|
783 r = MAKE_TINT64(0x80000000,0); |
|
784 t = r>>(31); |
|
785 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==0); |
|
786 t = t>>(32); |
|
787 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32); |
|
788 t = t>>1; |
|
789 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32); |
|
790 t = t>>16; |
|
791 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32); |
|
792 |
|
793 r = MAKE_TINT64(0x80000000,0); |
|
794 t = r>>(32); |
|
795 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==0x80000000); |
|
796 |
|
797 r = MAKE_TINT64(0x80000000,0); |
|
798 t = r>>63; |
|
799 test(I64LOW(t)==KMaxTUint32 && I64HIGH(t)==KMaxTUint32); |
|
800 |
|
801 r = MAKE_TINT64(KMaxTUint32, 0); |
|
802 t = r>>32; |
|
803 test(I64HIGH(t)==KMaxTUint32 && I64LOW(t)==KMaxTUint32); |
|
804 |
|
805 r = MAKE_TINT64(0x40000000,0); |
|
806 t = r>>30; |
|
807 test(I64HIGH(t)==1 && I64LOW(t)==0); |
|
808 t = r>>31; |
|
809 test(I64HIGH(t)==0 && I64LOW(t)==0x80000000); |
|
810 t = r>>62; |
|
811 test(I64HIGH(t)==0 && I64LOW(t)==1); |
|
812 t = r>>63; |
|
813 test(I64HIGH(t)==0 && I64LOW(t)==0); |
|
814 |
|
815 test.End(); |
|
816 } |
|
817 |
|
818 LOCAL_C void Test3() |
|
819 { |
|
820 // Test some more operators |
|
821 |
|
822 // unary - |
|
823 test.Start(_L("unary -")); |
|
824 TInt64 r=0, x(KMinTInt32); |
|
825 r=-x; |
|
826 test(I64INT(r)==KMinTInt32); |
|
827 |
|
828 x = MAKE_TINT64(0,0x80000000); |
|
829 r=-x; |
|
830 test(I64INT(r)==KMinTInt32); |
|
831 |
|
832 // ++ |
|
833 // post increment |
|
834 test.Next(_L("++")); |
|
835 x=-1; |
|
836 r=x++; |
|
837 test(I64INT(r)==-1 && I64INT(x)==0); |
|
838 r=x++; |
|
839 test(I64INT(r)==0 && I64INT(x)==1); |
|
840 r=x++; |
|
841 test(I64INT(r)==1 && I64INT(x)==2); |
|
842 |
|
843 x=KMinTInt32; |
|
844 r=x++; |
|
845 test(I64INT(r)==KMinTInt32 && I64INT(x)==KMinTInt32+1); |
|
846 |
|
847 x=KMaxTUint32; |
|
848 r=x++; |
|
849 test(I64INT(r)==(TInt)KMaxTUint32 && I64HIGH(x)==1 && I64LOW(x)==0); |
|
850 r=x++; |
|
851 test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==1 && I64LOW(x)==1); |
|
852 |
|
853 // pre increment; |
|
854 x=-1; |
|
855 r=++x; |
|
856 test(I64INT(r)==0 && I64INT(x)==0); |
|
857 r=++x; |
|
858 test(I64INT(r)==1 && I64INT(x)==1); |
|
859 r=++x; |
|
860 test(I64INT(r)==2 && I64INT(x)==2); |
|
861 |
|
862 x=KMinTInt32; |
|
863 r=++x; |
|
864 test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32+1); |
|
865 |
|
866 x=KMaxTUint32; |
|
867 r=++x; |
|
868 test(I64HIGH(r) && I64HIGH(x)==1 && I64LOW(x)==0); |
|
869 r=x++; |
|
870 test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==1 && I64LOW(x)==1); |
|
871 |
|
872 |
|
873 // -- |
|
874 test.Next(_L("--")); |
|
875 // post decrement |
|
876 x=1; |
|
877 r=x--; |
|
878 test(I64INT(r)==1 && I64INT(x)==0); |
|
879 r=x--; |
|
880 test(I64INT(r)==0 && I64INT(x)==-1); |
|
881 r=x--; |
|
882 test(I64INT(r)==-1 && I64INT(x)==-2); |
|
883 |
|
884 x=KMinTInt32+1; |
|
885 r=x--; |
|
886 test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32); |
|
887 |
|
888 x=KMaxTUint32; |
|
889 x+=1; |
|
890 r=x--; |
|
891 test(I64HIGH(r)==1 && I64LOW(r)==0 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32); |
|
892 r=x--; |
|
893 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32-1); |
|
894 |
|
895 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
896 r=x--; |
|
897 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==KMaxTUint32 && I64LOW(x)==KMaxTUint32-1); |
|
898 |
|
899 // pre decrement |
|
900 x=1; |
|
901 r=--x; |
|
902 test(I64INT(r)==0 && I64INT(x)==0); |
|
903 r=--x; |
|
904 test(I64INT(r)==-1 && I64INT(x)==-1); |
|
905 r=--x; |
|
906 test(I64INT(r)==-2 && I64INT(x)==-2); |
|
907 |
|
908 x=KMinTInt32+1; |
|
909 r=--x; |
|
910 test(I64INT(r)==KMinTInt32 && I64INT(x)==KMinTInt32); |
|
911 |
|
912 x=KMaxTUint32; |
|
913 x+=1; |
|
914 r=--x; |
|
915 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32); |
|
916 r=--x; |
|
917 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1 && I64HIGH(x)==0 && I64LOW(x)==KMaxTUint32-1); |
|
918 |
|
919 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
920 r=--x; |
|
921 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1 && I64HIGH(x)==KMaxTUint32 && I64LOW(x)==KMaxTUint32-1); |
|
922 |
|
923 |
|
924 |
|
925 // Binary + |
|
926 test.Next(_L("Binary +")); |
|
927 x=KMinTInt32; |
|
928 r=x+1; |
|
929 test(I64INT(r)==KMinTInt32+1 && I64INT(x)==KMinTInt32); |
|
930 |
|
931 x=-1; |
|
932 r=x+1; |
|
933 test(I64INT(r)==0 && I64INT(x)==-1); |
|
934 x=r+1; |
|
935 test(I64INT(r)==0 && I64INT(x)==1); |
|
936 |
|
937 x=KMaxTUint32; |
|
938 r=x+KMaxTUint32; |
|
939 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint-1); |
|
940 |
|
941 x=KMaxTUint32; |
|
942 x+=1; |
|
943 r=x+(-1); |
|
944 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
945 |
|
946 TInt64 y(0); |
|
947 x=KMaxTUint32; |
|
948 r=x+y; |
|
949 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
950 |
|
951 y=KMaxTUint32; |
|
952 r=x+y; |
|
953 test(I64HIGH(r)==1 && I64LOW(r)==KMaxTUint32-1); |
|
954 |
|
955 y=0; |
|
956 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
957 r=x+y; |
|
958 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
959 |
|
960 y=1; |
|
961 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
962 x-=1; |
|
963 r=x+y; |
|
964 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
965 |
|
966 y=0; |
|
967 x=KMinTInt32; |
|
968 r=x+y; |
|
969 test(I64INT(r)==KMinTInt32); |
|
970 |
|
971 y=-1; |
|
972 x=KMinTInt32; |
|
973 x+=1; |
|
974 r=x+y; |
|
975 test(I64INT(r)==KMinTInt32); |
|
976 |
|
977 y=-1; |
|
978 x=-1; |
|
979 r=x+y; |
|
980 test(I64INT(r)==-2); |
|
981 |
|
982 y=-1; |
|
983 x=KMaxTUint32; |
|
984 r=x+y; |
|
985 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1); |
|
986 y=-1; |
|
987 x+=1; |
|
988 r=x+y; |
|
989 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
990 y=-1; |
|
991 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
992 r=x+y; |
|
993 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1); |
|
994 |
|
995 y=KMinTInt32; |
|
996 x=KMaxTUint32; |
|
997 r=x+y; |
|
998 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-(TUint)KMinTInt32); |
|
999 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1000 r=x+y; |
|
1001 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x7fffffff); |
|
1002 |
|
1003 y=KMinTInt32; |
|
1004 x=-(KMinTInt32+1); |
|
1005 x+=1; |
|
1006 r=x+y; |
|
1007 test(I64INT(r)==0); |
|
1008 |
|
1009 |
|
1010 // Binary - |
|
1011 test.Next(_L("Binary -")); |
|
1012 x=KMinTInt32+1; |
|
1013 r=x-1; |
|
1014 test(I64INT(r)==KMinTInt32); |
|
1015 |
|
1016 x=2; |
|
1017 r=x-1; |
|
1018 test(I64INT(r)==1); |
|
1019 x=1; |
|
1020 r=x-1; |
|
1021 test(I64INT(r)==0); |
|
1022 x=0; |
|
1023 r=x-1; |
|
1024 test(I64INT(r)==-1); |
|
1025 |
|
1026 x=KMaxTUint32; |
|
1027 r=x-KMaxTUint32; |
|
1028 test(I64INT(r)==0); |
|
1029 |
|
1030 x=KMaxTUint32; |
|
1031 x+=1; |
|
1032 r=x-1; |
|
1033 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
1034 |
|
1035 x=KMaxTUint32; |
|
1036 r=x-1; |
|
1037 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1); |
|
1038 |
|
1039 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1040 r=x-1; |
|
1041 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1); |
|
1042 |
|
1043 |
|
1044 y=0; |
|
1045 x=KMaxTUint32; |
|
1046 r=x-y; |
|
1047 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
1048 |
|
1049 y=KMaxTUint32; |
|
1050 r=x-y; |
|
1051 test(I64INT(r)==0); |
|
1052 |
|
1053 x=KMaxTUint32; |
|
1054 x+=1; |
|
1055 y=1; |
|
1056 r=x-1; |
|
1057 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
1058 x-=1; |
|
1059 r=x-1; |
|
1060 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32-1); |
|
1061 |
|
1062 y=0; |
|
1063 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1064 r=x-y; |
|
1065 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
1066 |
|
1067 y=1; |
|
1068 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1069 r=x-y; |
|
1070 test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32-1); |
|
1071 |
|
1072 y=0; |
|
1073 x=KMinTInt32; |
|
1074 r=x-y; |
|
1075 test(I64INT(r)==KMinTInt32); |
|
1076 |
|
1077 y=1; |
|
1078 x=KMinTInt32; |
|
1079 x+=1; |
|
1080 r=x-y; |
|
1081 test(I64INT(r)==KMinTInt32); |
|
1082 |
|
1083 y=1; |
|
1084 x=1; |
|
1085 r=x-y; |
|
1086 test(I64INT(r)==0); |
|
1087 |
|
1088 y=-1; |
|
1089 x=-1; |
|
1090 r=x-y; |
|
1091 test(I64INT(r)==0); |
|
1092 |
|
1093 x=0; |
|
1094 y=KMinTInt32; |
|
1095 r=x-y; |
|
1096 test(I64INT(r)==KMinTInt32); |
|
1097 |
|
1098 x=KMinTInt32; |
|
1099 y=KMinTInt32; |
|
1100 r=x-y; |
|
1101 test(I64INT(r)==0); |
|
1102 |
|
1103 test.End(); |
|
1104 } |
|
1105 |
|
1106 |
|
1107 LOCAL_C void Test4() |
|
1108 // still more operators |
|
1109 { |
|
1110 // * |
|
1111 test.Start(_L("Binary *")); |
|
1112 TInt64 r(0), x(1), y(0); |
|
1113 r=x*y; |
|
1114 test(I64INT(r)==0); |
|
1115 |
|
1116 y=-1; |
|
1117 r=x*y; |
|
1118 test(I64INT(r)==-1); |
|
1119 |
|
1120 x=-1; |
|
1121 r=x*y; |
|
1122 test(I64INT(r)==1); |
|
1123 |
|
1124 x=KMinTInt32; |
|
1125 r=x*y; |
|
1126 test(I64INT(r)==KMinTInt32); |
|
1127 |
|
1128 y=0; |
|
1129 r=x*y; |
|
1130 test(I64INT(r)==0); |
|
1131 |
|
1132 y=KMinTInt32; |
|
1133 r=x*y; |
|
1134 test(I64LOW(r)==0 && I64HIGH(r)==0x40000000); |
|
1135 |
|
1136 y=KMaxTUint32; |
|
1137 x=KMaxTUint32; |
|
1138 r=x*y; |
|
1139 test(I64LOW(r)==1 && I64HIGH(r)==0xfffffffe); |
|
1140 |
|
1141 |
|
1142 // / |
|
1143 test.Next(_L("Binary /")); |
|
1144 x=5; |
|
1145 y=5; |
|
1146 r=x/y; |
|
1147 test(I64INT(r)==1); |
|
1148 |
|
1149 y=1; |
|
1150 r=x/y; |
|
1151 test(I64INT(r)==5); |
|
1152 |
|
1153 x=-5; |
|
1154 r=x/y; |
|
1155 test(I64INT(r)==-5); |
|
1156 |
|
1157 y=-1; |
|
1158 r=x/y; |
|
1159 test(I64INT(r)==5); |
|
1160 |
|
1161 x=-1; |
|
1162 r=x/y; |
|
1163 test(I64INT(r)==1); |
|
1164 |
|
1165 x=0; |
|
1166 r=x/y; |
|
1167 test(I64INT(r)==0); |
|
1168 |
|
1169 x=KMinTInt32; |
|
1170 y=-1; |
|
1171 r=x/y; |
|
1172 test(I64INT(r)==KMinTInt32); |
|
1173 |
|
1174 x=KMinTInt32; |
|
1175 y=KMinTInt32; |
|
1176 r=x/y; |
|
1177 test(I64INT(r)==1); |
|
1178 |
|
1179 x=KMaxTUint32; |
|
1180 y=KMaxTUint32; |
|
1181 r=x/y; |
|
1182 test(I64INT(r)==1); |
|
1183 |
|
1184 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1185 r=x/y; |
|
1186 test(I64INT(r)==0); |
|
1187 |
|
1188 y = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1189 r=x/y; |
|
1190 test(I64INT(r)==1); |
|
1191 |
|
1192 y=KMinTInt32; |
|
1193 r=x/y; |
|
1194 test(I64INT(r)==0); |
|
1195 |
|
1196 x = MAKE_TINT64(4,257629747); |
|
1197 y=KMaxTInt; |
|
1198 r=x/y; |
|
1199 test(I64LOW(r)==8 && I64HIGH(r)==0); |
|
1200 |
|
1201 x = MAKE_TINT64(3452,533254); |
|
1202 x=-x; |
|
1203 x=x/x; |
|
1204 test(x==1); |
|
1205 |
|
1206 // % |
|
1207 test.Next(_L("binary %%")); |
|
1208 x=2341; |
|
1209 y=2340; |
|
1210 test(x%y==1); |
|
1211 y=2; |
|
1212 test(x%y==1); |
|
1213 x = MAKE_TINT64(234893,23494); |
|
1214 test(x%x==0); |
|
1215 test(x%y==0); |
|
1216 x=-x; |
|
1217 y=10; |
|
1218 test(x%y==-2); |
|
1219 test(x%(-y)==-2); |
|
1220 |
|
1221 |
|
1222 // Lsr |
|
1223 test.Next(_L("Lsr")); |
|
1224 |
|
1225 r = MAKE_TINT64(3,0); |
|
1226 I64LSR(r, 1); |
|
1227 test(I64HIGH(r)==1 && I64LOW(r)==0x80000000); |
|
1228 I64LSR(r, 1); |
|
1229 test(I64HIGH(r)==0 && I64LOW(r)==0xC0000000); |
|
1230 |
|
1231 r = MAKE_TINT64(0x80000000,0); |
|
1232 I64LSR(r, 31); |
|
1233 test(I64HIGH(r)==1 && I64LOW(r)==0); |
|
1234 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0); |
|
1235 I64LSR(r, 32); |
|
1236 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
1237 test(I64HIGH(r)==0 && I64LOW(r)==1); |
|
1238 |
|
1239 r = MAKE_TINT64(0x80000000,0); |
|
1240 I64LSR(r, 32); |
|
1241 test(I64HIGH(r)==0 && I64LOW(r)==0x80000000); |
|
1242 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==0x80000000); |
|
1243 |
|
1244 r = MAKE_TINT64(0x80000000,0); |
|
1245 I64LSR(r, 63); |
|
1246 test(I64LOW(r)==1 && I64HIGH(r)==0); |
|
1247 //test(I64LOW(r)==KMaxTUint32 && I64HIGH(r)==KMaxTUint32); |
|
1248 |
|
1249 r = MAKE_TINT64(KMaxTUint32, 0); |
|
1250 I64LSR(r, 32); |
|
1251 test(I64HIGH(r)==0 && I64LOW(r)==KMaxTUint32); |
|
1252 //test(I64HIGH(r)==KMaxTUint32 && I64LOW(r)==KMaxTUint32); |
|
1253 |
|
1254 |
|
1255 // Mul10 |
|
1256 test.Next(_L("Mul10")); |
|
1257 const TInt64 KMaxDiv10= KMaxTInt64 / 10; |
|
1258 const TInt64 KStep=MAKE_TINT64(0x003dfe03, 0xf7ea23cd); |
|
1259 for(TInt64 jj=-KMaxDiv10; jj<=KMaxDiv10; jj+=KStep) |
|
1260 { |
|
1261 r=jj; |
|
1262 r *= 10; |
|
1263 test(r==jj*10); |
|
1264 r/=10; |
|
1265 test(r==jj); |
|
1266 } |
|
1267 |
|
1268 r=KMinTInt32/10; |
|
1269 r *= 10; |
|
1270 test(I64INT(r)==(KMinTInt/10)*10); |
|
1271 |
|
1272 r=KMaxTUint32; |
|
1273 r *= 10; |
|
1274 test(I64HIGH(r)==9 && I64LOW(r)==0xFFFFFFF6); |
|
1275 |
|
1276 r/=10; |
|
1277 test(r==MAKE_TINT64(0,KMaxTUint32)); |
|
1278 |
|
1279 |
|
1280 // DivMod |
|
1281 test.Next(_L("DivMod")); |
|
1282 TInt64 seed = MAKE_TINT64(0x0000336a,0xb2001a78); |
|
1283 for (TInt i=0; i<200; i++) |
|
1284 { |
|
1285 TInt o=Math::Rand(seed); |
|
1286 TInt p=Math::Rand(seed); |
|
1287 TInt r=Math::Rand(seed); |
|
1288 TInt q=Math::Rand(seed); |
|
1289 |
|
1290 DivModTest(MAKE_TINT64(0,q), MAKE_TINT64(0,r)); |
|
1291 DivModTest(MAKE_TINT64(r,q), MAKE_TINT64(o,p)); |
|
1292 DivModTest(MAKE_TINT64(p,q), MAKE_TINT64(0,o)); |
|
1293 DivModTest(MAKE_TINT64(0,p), MAKE_TINT64(r,o)); |
|
1294 |
|
1295 DivModTest(-MAKE_TINT64(0,q), -MAKE_TINT64(0,r)); |
|
1296 DivModTest( MAKE_TINT64(0,q), -MAKE_TINT64(0,r)); |
|
1297 DivModTest(-MAKE_TINT64(0,q), MAKE_TINT64(0,r)); |
|
1298 |
|
1299 DivModTest(-MAKE_TINT64(r,q), -MAKE_TINT64(o,p)); |
|
1300 DivModTest( MAKE_TINT64(r,q), -MAKE_TINT64(o,p)); |
|
1301 DivModTest(-MAKE_TINT64(r,q), MAKE_TINT64(o,p)); |
|
1302 |
|
1303 DivModTest(-MAKE_TINT64(0,p), -MAKE_TINT64(r,o)); |
|
1304 DivModTest( MAKE_TINT64(0,p), -MAKE_TINT64(r,o)); |
|
1305 DivModTest(-MAKE_TINT64(0,p), MAKE_TINT64(r,o)); |
|
1306 } |
|
1307 |
|
1308 test.End(); |
|
1309 } |
|
1310 |
|
1311 LOCAL_C void Test5() |
|
1312 // still more operators |
|
1313 { |
|
1314 |
|
1315 // fast multiply by 10 |
|
1316 test.Start(_L("Mul10")); |
|
1317 TInt64 r(0); |
|
1318 r *= 10; |
|
1319 test(I64INT(r)==0); |
|
1320 |
|
1321 r=-1; |
|
1322 r *= 10; |
|
1323 test(I64INT(r)==-10); |
|
1324 |
|
1325 r=KMinTInt32/10; |
|
1326 r *= 10; |
|
1327 test(I64INT(r)==KMinTInt32-(KMinTInt32%10)); |
|
1328 |
|
1329 r=1; |
|
1330 r *= 10; |
|
1331 test(I64INT(r)==10); |
|
1332 |
|
1333 r=KMaxTUint32/10; |
|
1334 r *= 10; |
|
1335 test(I64LOW(r)==(KMaxTUint32-(KMaxTUint%10)) && I64HIGH(r)==0); |
|
1336 |
|
1337 r *= 10; |
|
1338 test(r==TInt64(KMaxTUint32-(KMaxTUint%10))*10); |
|
1339 |
|
1340 r *= 10; |
|
1341 test(r==TInt64(KMaxTUint32-(KMaxTUint%10))*100); |
|
1342 |
|
1343 // Comparisons |
|
1344 test.Next(_L("Comparison operators")); |
|
1345 |
|
1346 // == , !=, <= and >= |
|
1347 test.Next(_L("==, !=, <= and >=")); |
|
1348 r=KMinTInt32; |
|
1349 TInt64 x(KMinTInt32); |
|
1350 TInt64 y(100); |
|
1351 test(r==x && r!=y && r>=x && r<=x); |
|
1352 |
|
1353 r=-1; |
|
1354 x=-1; |
|
1355 test(r==x && r!=y && r>=x && r<=x); |
|
1356 |
|
1357 r=0; |
|
1358 x=0; |
|
1359 test(r==x && r!=y && r>=x && r<=x); |
|
1360 |
|
1361 r=1; |
|
1362 x=1; |
|
1363 test(r==x && r!=y && r>=x && r<=x); |
|
1364 |
|
1365 r=KMaxTUint32; |
|
1366 x=KMaxTUint32; |
|
1367 test(r==x && r!=y && r>=x && r<=x); |
|
1368 |
|
1369 r = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1370 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1371 test(x==r && x!=y && x>=r && x<=r); |
|
1372 |
|
1373 //>=, <=, > and < |
|
1374 test.Next(_L(">=, <=, > and <")); |
|
1375 r=KMinTInt32; |
|
1376 x=KMinTInt32+1; |
|
1377 test(x>r && x>=r && r<x && r<=x); |
|
1378 |
|
1379 r=1; |
|
1380 x=-1; |
|
1381 test(r>x && x<r && r>=x && x<=r); |
|
1382 |
|
1383 r=KMaxTUint32; |
|
1384 x=KMaxTUint32-1; |
|
1385 test(r>x && x<r && r>=x && x<=r); |
|
1386 |
|
1387 r+=1; |
|
1388 x+=1; |
|
1389 test(r>x && x<r && r>=x && x<=r); |
|
1390 |
|
1391 r = MAKE_TINT64(KMaxTUint32,KMaxTUint32); |
|
1392 x = MAKE_TINT64(KMaxTUint32,KMaxTUint32-1); |
|
1393 test(r>x && x<r && r>=x && x<=r); |
|
1394 |
|
1395 r = MAKE_TINT64(0x80000000,0); |
|
1396 x = MAKE_TINT64(KMaxTInt32,KMaxTUint32); |
|
1397 test(r<x); |
|
1398 test(x>r); |
|
1399 test(x!=r); |
|
1400 test(r<=x); |
|
1401 test(x>=r); |
|
1402 test(r<0 && x>0); |
|
1403 |
|
1404 x = MAKE_TINT64(0x80000000,1); |
|
1405 test(r<x && x>r && x!=r && r<=x && x>=r); |
|
1406 |
|
1407 r = MAKE_TINT64(KMaxTInt32,KMaxTUint32); |
|
1408 --r; |
|
1409 test(r>x && x<r && x!=r && r>=x && x<=r); |
|
1410 |
|
1411 // multiply top bits |
|
1412 test.Next(_L("MulTop")); |
|
1413 r=0; |
|
1414 x=0; |
|
1415 I64MULTOP(r, x); |
|
1416 test(I64INT(r)==0); |
|
1417 |
|
1418 r=1; |
|
1419 x=1; |
|
1420 I64MULTOP(r, x); |
|
1421 test(I64INT(r)==0); |
|
1422 |
|
1423 r = MAKE_TINT64(KMaxTInt,KMaxTUint); |
|
1424 x=2; |
|
1425 I64MULTOP(r, x); |
|
1426 test(I64INT(r)==0); |
|
1427 |
|
1428 r = MAKE_TINT64(KMaxTInt,KMaxTUint); |
|
1429 x=4; |
|
1430 I64MULTOP(r, x); |
|
1431 test(I64INT(r)==1); |
|
1432 |
|
1433 r = MAKE_TINT64(0x80000000,0); |
|
1434 x = MAKE_TINT64(0x80000000,0); |
|
1435 I64MULTOP(r, x); |
|
1436 r>>=32; |
|
1437 test(I64INT(r)==0x40000000); |
|
1438 |
|
1439 r = MAKE_TINT64(0x18763529,0x93263921); |
|
1440 x = MAKE_TINT64(0x0abcdef0,0x647239ea); |
|
1441 TInt64 r2=r; |
|
1442 TInt64 x2=x; |
|
1443 I64MULTOP(r, x2); |
|
1444 I64MULTOP(x, r2); |
|
1445 test(r==x); |
|
1446 |
|
1447 // TInt64(0xac11b680,0x1e603000) * TInt64(0x014a5c20,0xc9d58740) |
|
1448 |
|
1449 TPtrC8 a4=_L8("ac11b6801e603000"); |
|
1450 TPtrC8 a5=_L8("014a5c20c9d58740"); |
|
1451 TBuf8<64> a6; |
|
1452 HexMul(a4,a5,a6); |
|
1453 |
|
1454 x = MAKE_TINT64(0x014a5c20,0xc9d58740); |
|
1455 |
|
1456 r = MAKE_TINT64(0xac11b680,0x1e603000); |
|
1457 y = MAKE_TINT64(0x0963fbc4,0x415c0000); // Expected result (bottom 64 bits) |
|
1458 |
|
1459 r *= x; |
|
1460 |
|
1461 test(r==y); |
|
1462 |
|
1463 r = MAKE_TINT64(0xac11b680,0x1e603000); |
|
1464 y = MAKE_TINT64(0x00de0cc1,0xa89d70dc); // Expected result (top 64 bits) |
|
1465 I64MULTOP(r, x); |
|
1466 test(r==y); |
|
1467 |
|
1468 test.End(); |
|
1469 } |
|
1470 |
|
1471 |
|
1472 GLDEF_C TInt E32Main() |
|
1473 { |
|
1474 test.Title(); |
|
1475 test.Start(_L("Constructors")); |
|
1476 Test1(); |
|
1477 test.Next(_L("Unary operators")); |
|
1478 Test1_2(); |
|
1479 test.Next(_L("Operators 1")); |
|
1480 Test2(); |
|
1481 test.Next(_L("Operators 2")); |
|
1482 Test3(); |
|
1483 test.Next(_L("Operators 3")); |
|
1484 Test4(); |
|
1485 test.Next(_L("Operators 4")); |
|
1486 Test5(); |
|
1487 test.End(); |
|
1488 return(KErrNone); |
|
1489 } |