]>
git.saurik.com Git - wxWidgets.git/blob - tests/lltest.cpp
122a148b108e5cf2866e3752ff428780a6e30387
1 #include "wx/longlong.h"
5 #if defined(__MWERKS__) && macintosh
10 static const unsigned long long NumberOfTests
= 100000ll;
12 //using namespace std;
13 int oddbits(unsigned int number
);
15 int oddbits(unsigned int number
)
26 void random(long& hi
, unsigned long& lo
);
28 void random(long& hi
, unsigned long& lo
)
33 for (int i
= 0; i
< 32; i
++)
35 hi
|= oddbits(rand()) << i
;
36 lo
|= oddbits(rand()) << i
;
44 std::cout
<< std::endl
<< "Starting shift tests." << endl
;
49 unsigned wxLongLong_t counter
= 0;
51 while (counter
< NumberOfTests
)
53 if ((counter
% 1000) == 999)
56 #if defined(__MWERKS__) && macintosh
57 GetNextEvent(0, NULL
);
62 wxLongLongWx
l1a(hi
, lo
);
63 wxLongLongWx
l1c(hi
, lo
);
65 wxLongLongNative
l2a(hi
, lo
);
66 wxLongLongNative
l2c(hi
, lo
);
69 int shift
= rand() % 64;
70 int leftshift
= oddbits(rand());
87 void *oneb
= l1b
.asArray();
88 void *twob
= l2b
.asArray();
89 void *onec
= l1c
.asArray();
90 void *twoc
= l2c
.asArray();
92 if ((memcmp(oneb
, twob
, 8) != 0) || (memcmp(onec
, twoc
, 8) != 0) || (memcmp(oneb
, onec
, 8) != 0))
94 std::cout
<< std::endl
<< "After " << counter
<< " successful trials: " << std::endl
;
95 std::cout
<< l1a
<< std::endl
;
96 std::cout
<< l2a
<< std::endl
;
101 std::cout
<< shift
<< std::endl
;
102 std::cout
<< l1b
<< std::endl
;
103 std::cout
<< l2b
<< std::endl
;
104 std::cout
<< l1c
<< std::endl
;
105 std::cout
<< l2c
<< std::endl
;
111 std::cout
<< std::endl
<< counter
<< " successful trial" << (counter
== 1 ? "." : "s.") << std::endl
;
120 std::cout
<< std::endl
<< "Starting first addition tests." << endl
;
123 unsigned long lo
= 0;
125 unsigned wxLongLong_t counter
= 0;
127 while (counter
< NumberOfTests
)
129 if ((counter
% 1000) == 999)
132 #if defined(__MWERKS__) && macintosh
133 GetNextEvent(0, NULL
);
138 wxLongLongWx
l1a(hi
, lo
);
139 wxLongLongNative
l2a(hi
, lo
);
140 wxLongLongWx
l1d(hi
, lo
);
141 wxLongLongNative
l2d(hi
, lo
);
143 wxLongLongWx
l1b(hi
, lo
);
144 wxLongLongNative
l2b(hi
, lo
);
146 wxLongLongNative l2c
;
153 void *onec
= l1c
.asArray();
154 void *twoc
= l2c
.asArray();
155 void *oned
= l1d
.asArray();
156 void *twod
= l2d
.asArray();
158 if ((memcmp(onec
, twoc
, 8) != 0) || (memcmp(oned
, twod
, 8) != 0) || (memcmp(onec
, oned
, 8) != 0))
160 std::cout
<< std::endl
<< "After " << counter
<< " successful trials: " << std::endl
;
161 std::cout
<< l1a
<< std::endl
;
162 std::cout
<< l2a
<< std::endl
;
163 std::cout
<< l1b
<< std::endl
;
164 std::cout
<< l2b
<< std::endl
;
165 std::cout
<< l1c
<< std::endl
;
166 std::cout
<< l2c
<< std::endl
;
172 std::cout
<< std::endl
<< counter
<< " successful trial" << (counter
== 1 ? "." : "s.") << std::endl
;
182 std::cout << std::endl << "Starting second addition tests." << endl;
185 unsigned long lo = 0;
187 unsigned wxLongLong_t counter = 0;
189 while (counter < NumberOfTests)
191 if ((counter % 1000) == 999)
194 #if defined(__MWERKS__) && macintosh
195 GetNextEvent(0, NULL);
200 wxLongLongWx l1a(hi, lo);
201 wxLongLongNative l2a(hi, lo);
202 wxLongLongWx l1c(hi, lo);
203 wxLongLongNative l2c(hi, lo);
205 wxLongLongWx l1b(hi, lo);
206 wxLongLongNative l2b(hi, lo);
211 void *one = l1b.asArray();
212 void *two = l2b.asArray();
214 if (memcmp(one, two, 8) != 0)
216 std::cout << std::endl << "After " << counter << " successful trials: " << std::endl;
217 std::cout << l1c << std::endl;
218 std::cout << l2c << std::endl;
219 std::cout << l1a << std::endl;
220 std::cout << l2a << std::endl;
221 std::cout << l1b << std::endl;
222 std::cout << l2b << std::endl;
228 std::cout << std::endl << counter << " successful trial" << (counter == 1 ? "." : "s.") << std::endl;
238 std::cout
<< std::endl
<< "Starting first subtraction tests." << endl
;
241 unsigned long lo
= 0;
243 unsigned wxLongLong_t counter
= 0;
245 while (counter
< NumberOfTests
)
247 if ((counter
% 1000) == 999)
250 #if defined(__MWERKS__) && macintosh
251 GetNextEvent(0, NULL
);
256 wxLongLongWx
l1a(hi
, lo
);
257 wxLongLongNative
l2a(hi
, lo
);
258 wxLongLongWx
l1d(hi
, lo
);
259 wxLongLongNative
l2d(hi
, lo
);
261 wxLongLongWx
l1b(hi
, lo
);
262 wxLongLongNative
l2b(hi
, lo
);
264 wxLongLongNative l2c
;
271 void *onec
= l1c
.asArray();
272 void *twoc
= l2c
.asArray();
273 void *oned
= l1d
.asArray();
274 void *twod
= l2d
.asArray();
276 if ((memcmp(onec
, twoc
, 8) != 0) || (memcmp(oned
, twod
, 8) != 0) || (memcmp(onec
, oned
, 8) != 0))
278 std::cout
<< std::endl
<< "After " << counter
<< " successful trials: " << std::endl
;
279 std::cout
<< l1a
<< std::endl
;
280 std::cout
<< l2a
<< std::endl
;
281 std::cout
<< l1b
<< std::endl
;
282 std::cout
<< l2b
<< std::endl
;
283 std::cout
<< l1c
<< std::endl
;
284 std::cout
<< l2c
<< std::endl
;
285 std::cout
<< l1d
<< std::endl
;
286 std::cout
<< l2d
<< std::endl
;
292 std::cout
<< std::endl
<< counter
<< " successful trial" << (counter
== 1 ? "." : "s.") << std::endl
;
302 std::cout << std::endl << "Starting second subtraction tests." << endl;
305 unsigned long lo = 0;
307 unsigned wxLongLong_t counter = 0;
309 while (counter < NumberOfTests)
311 if ((counter % 1000) == 999)
314 #if defined(__MWERKS__) && macintosh
315 GetNextEvent(0, NULL);
320 wxLongLongWx l1a(hi, lo);
321 wxLongLongNative l2a(hi, lo);
322 wxLongLongWx l1c(hi, lo);
323 wxLongLongNative l2c(hi, lo);
325 wxLongLongWx l1b(hi, lo);
326 wxLongLongNative l2b(hi, lo);
331 void *one = l1b.asArray();
332 void *two = l2b.asArray();
334 if (memcmp(one, two, 8) != 0)
336 std::cout << std::endl << "After " << counter << " successful trials: " << std::endl;
337 std::cout << l1c << std::endl;
338 std::cout << l2c << std::endl;
339 std::cout << l1a << std::endl;
340 std::cout << l2a << std::endl;
341 std::cout << l1b << std::endl;
342 std::cout << l2b << std::endl;
348 std::cout << std::endl << counter << " successful trial" << (counter == 1 ? "." : "s.") << std::endl;
359 std::cout
<< std::endl
<< "Starting pre/post increment/decrement tests." << endl
;
362 unsigned long lo
= 0;
364 unsigned wxLongLong_t counter
= 0;
366 while (counter
< NumberOfTests
)
368 if ((counter
% 1000) == 999)
371 #if defined(__MWERKS__) && macintosh
372 GetNextEvent(0, NULL
);
377 wxLongLongWx
l1a(hi
, lo
);
378 wxLongLongNative
l2a(hi
, lo
);
379 wxLongLongWx
l1b(hi
, lo
);
380 wxLongLongNative
l2b(hi
, lo
);
382 int increment
= oddbits(rand());
383 int pre
= oddbits(rand());
408 void *one
= l1b
.asArray();
409 void *two
= l2b
.asArray();
411 if (memcmp(one
, two
, 8) != 0)
413 std::cout
<< std::endl
<< "After " << counter
<< " successful trials: " << std::endl
;
414 std::cout
<< l1a
<< std::endl
;
415 std::cout
<< l2a
<< std::endl
;
416 std::cout
<< (pre
? "pre" : "post") << (increment
? "increment" : "decrement") << std::endl
;
417 std::cout
<< l1b
<< std::endl
;
418 std::cout
<< l2b
<< std::endl
;
424 std::cout
<< std::endl
<< counter
<< " successful trial" << (counter
== 1 ? "." : "s.") << std::endl
;
433 std::cout
<< std::endl
<< "Starting negation tests." << endl
;
436 unsigned long lo
= 0;
438 unsigned wxLongLong_t counter
= 0;
440 while (counter
< NumberOfTests
)
442 if ((counter
% 1000) == 999)
445 #if defined(__MWERKS__) && macintosh
446 GetNextEvent(0, NULL
);
451 wxLongLongWx
l1a(hi
, lo
);
452 wxLongLongNative
l2a(hi
, lo
);
453 wxLongLongWx
l1b(-l1a
);
454 wxLongLongNative
l2b(-l2a
);
456 void *one
= l1b
.asArray();
457 void *two
= l2b
.asArray();
459 if (memcmp(one
, two
, 8) != 0)
461 std::cout
<< std::endl
<< "After " << counter
<< " successful trials: " << std::endl
;
462 std::cout
<< l1a
<< std::endl
;
463 std::cout
<< l2a
<< std::endl
;
464 std::cout
<< l1b
<< std::endl
;
465 std::cout
<< l2b
<< std::endl
;
471 std::cout
<< std::endl
<< counter
<< " successful trial" << (counter
== 1 ? "." : "s.") << std::endl
;
476 int multiplicationtest();
478 int multiplicationtest()
480 std::cout
<< std::endl
<< "Starting multiplication tests." << endl
;
483 unsigned long lo
= 0;
485 unsigned wxLongLong_t counter
= 0;
487 while (counter
< NumberOfTests
)
489 if ((counter
% 1000) == 999)
492 #if defined(__MWERKS__) && macintosh
493 GetNextEvent(0, NULL
);
498 wxLongLongWx
l1a(hi
, lo
);
499 wxLongLongNative
l2a(hi
, lo
);
500 wxLongLongWx
l1d(hi
, lo
);
501 wxLongLongNative
l2d(hi
, lo
);
503 wxLongLongWx
l1b(hi
, lo
);
504 wxLongLongNative
l2b(hi
, lo
);
506 wxLongLongWx
l1c(l1a
* l1b
);
507 wxLongLongNative
l2c(l2a
* l2b
);
512 void *onec
= l1c
.asArray();
513 void *twoc
= l2c
.asArray();
514 void *oned
= l1c
.asArray();
515 void *twod
= l2c
.asArray();
517 if ((memcmp(onec
, twoc
, 8) != 0) || (memcmp(oned
, twod
, 8) != 0) || (memcmp(onec
, oned
, 8) != 0))
519 std::cout
<< std::endl
<< "After " << counter
<< " successful trials: " << std::endl
;
520 std::cout
<< l1a
<< std::endl
;
521 std::cout
<< l2a
<< std::endl
;
522 std::cout
<< l1b
<< std::endl
;
523 std::cout
<< l2b
<< std::endl
;
524 std::cout
<< l1c
<< std::endl
;
525 std::cout
<< l2c
<< std::endl
;
526 std::cout
<< l1d
<< std::endl
;
527 std::cout
<< l2d
<< std::endl
;
533 std::cout
<< std::endl
<< counter
<< " successful trial" << (counter
== 1 ? "." : "s.") << std::endl
;
542 std::cout
<< std::endl
<< "Starting bitwise tests." << endl
;
545 unsigned long lo
= 0;
547 unsigned wxLongLong_t counter
= 0;
549 while (counter
< NumberOfTests
)
551 if ((counter
% 1000) == 999)
554 #if defined(__MWERKS__) && macintosh
555 GetNextEvent(0, NULL
);
560 wxLongLongWx
l1a(hi
, lo
);
561 wxLongLongNative
l2a(hi
, lo
);
562 wxLongLongWx
l1d(hi
, lo
);
563 wxLongLongNative
l2d(hi
, lo
);
565 wxLongLongWx
l1b(hi
, lo
);
566 wxLongLongNative
l2b(hi
, lo
);
568 wxLongLongWx
l1c(l1a
* l1b
);
569 wxLongLongNative
l2c(l2a
* l2b
);
574 void *onec
= l1c
.asArray();
575 void *twoc
= l2c
.asArray();
576 void *oned
= l1c
.asArray();
577 void *twod
= l2c
.asArray();
579 if ((memcmp(onec
, twoc
, 8) != 0) || (memcmp(oned
, twod
, 8) != 0) || (memcmp(onec
, oned
, 8) != 0))
581 std::cout
<< std::endl
<< "After " << counter
<< " successful trials: " << std::endl
;
582 std::cout
<< l1a
<< std::endl
;
583 std::cout
<< l2a
<< std::endl
;
584 std::cout
<< l1b
<< std::endl
;
585 std::cout
<< l2b
<< std::endl
;
586 std::cout
<< l1c
<< std::endl
;
587 std::cout
<< l2c
<< std::endl
;
588 std::cout
<< l1d
<< std::endl
;
589 std::cout
<< l2d
<< std::endl
;
595 std::cout
<< std::endl
<< counter
<< " successful trial" << (counter
== 1 ? "." : "s.") << std::endl
;
602 #if defined(__MWERKS__) && macintosh
603 SIOUXSettings
.asktosaveonclose
= 0;
604 SIOUXSettings
.showstatusline
= 1;
605 SIOUXSettings
.autocloseonquit
= 0;
608 std::cout
<< "Starting tests." << endl
;
610 #if defined(__MWERKS__) && macintosh
611 GetNextEvent(0, NULL
);
616 if (!multiplicationtest())
640 std::cout
<< std::endl
<< "The tests are finished." << std::endl
;