tadint64.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. { Program to test Code generator secondadd() }
  2. { with int64 values }
  3. { FUNCTIONAL PRE-REQUISITES: }
  4. { - assignments function correctly. }
  5. { - if statements function correctly. }
  6. { - subroutine calls function correctly. }
  7. procedure fail;
  8. begin
  9. WriteLn('Failed!');
  10. halt(1);
  11. end;
  12. procedure int64TestAdd;
  13. var
  14. i: int64;
  15. j: int64;
  16. result : boolean;
  17. begin
  18. Write('int64 + int64 test...');
  19. result := true;
  20. i:=0;
  21. j:=0;
  22. i := i + -10000;
  23. if i <> -10000 then
  24. result := false;
  25. j := 32767;
  26. i := i + j;
  27. if i <> 22767 then
  28. result := false;
  29. i := i + j + 50000;
  30. if i <> 105534 then
  31. result := false;
  32. i:=0;
  33. j:=10000;
  34. i:= i + j + j + i + j;
  35. if i <> 30000 then
  36. result := false;
  37. if not result then
  38. Fail
  39. else
  40. WriteLn('Success.');
  41. end;
  42. procedure int64TestSub;
  43. var
  44. i, j, k : int64;
  45. result : boolean;
  46. begin
  47. Write('int64 - int64 test...');
  48. result := true;
  49. i:=100000;
  50. j:=54;
  51. k:=56;
  52. i:= i - 100;
  53. if i <> 99900 then
  54. result := false;
  55. i := i - j - k - 100;
  56. if i <> 99690 then
  57. result := false;
  58. i:=100;
  59. j:=1000;
  60. k:=100;
  61. i:= j - i - k;
  62. if i <> 800 then
  63. result := false;
  64. j := 900 - i;
  65. if (j <> 100) then
  66. result := false;
  67. i := 1000000000;
  68. k := i;
  69. i := i * 10;
  70. j := 1000000000 - i;
  71. k := k - i;
  72. if j <> k then
  73. result := false;
  74. if j <> (1000000000-(int64(1000000000) * 10)) then
  75. result := false;
  76. j := (int64(1) shl 33);
  77. i := (int64(1) shl 34) - j;
  78. if (i <> (int64(1) shl 33)) then
  79. result := false;
  80. i := 1 - j;
  81. if (i <> (1-(int64(1) shl 33))) then
  82. result := false;
  83. i := 100000;
  84. i := i - 90000;
  85. if (i <> 10000) then
  86. result := false;
  87. if not result then
  88. Fail
  89. else
  90. WriteLn('Success.');
  91. end;
  92. procedure int64TestMul;
  93. var
  94. i : int64;
  95. j : int64;
  96. k: int64;
  97. result: boolean;
  98. begin
  99. Write('int64 * int64 test...');
  100. result := true;
  101. i:=0;
  102. j:=0;
  103. i:=i * 32;
  104. if i <> 0 then
  105. result := false;
  106. i:=10;
  107. i:=i * -16;
  108. if i <> -160 then
  109. result := false;
  110. j:=10000;
  111. i:=-10000;
  112. i:=i * j;
  113. if i <> -100000000 then
  114. result := false;
  115. i:=1;
  116. j:=10;
  117. k:=16;
  118. i := i * j * k;
  119. if i <> 160 then
  120. result := false;
  121. i := 1;
  122. j := 10;
  123. k := 16;
  124. i := i * 10 * j * i * j * 16 * k;
  125. if i <> 256000 then
  126. result := false;
  127. if not result then
  128. Fail
  129. else
  130. WriteLn('Success.');
  131. end;
  132. procedure int64TestXor;
  133. var
  134. i, j : int64;
  135. result : boolean;
  136. begin
  137. Write('int64 XOR int64 test...');
  138. result := true;
  139. i := 0;
  140. j := 0;
  141. i := i xor $1000001;
  142. if i <> $1000001 then
  143. result := false;
  144. i:=0;
  145. j:=$10000001;
  146. i:=i xor j;
  147. if i <> $10000001 then
  148. result := false;
  149. i := 0;
  150. j := $55555555;
  151. i := i xor j xor $AAAAAAAA;
  152. if i <> $FFFFFFFF then
  153. result := false;
  154. if not result then
  155. Fail
  156. else
  157. WriteLn('Success.');
  158. end;
  159. procedure int64TestOr;
  160. var
  161. i,j : int64;
  162. result : boolean;
  163. Begin
  164. Write('int64 OR int64 test...');
  165. result := true;
  166. i := 0;
  167. j := 0;
  168. i := i or $1000001;
  169. if i <> $1000001 then
  170. result := false;
  171. i:=0;
  172. j:=$10000001;
  173. i:=i or j;
  174. if i <> $10000001 then
  175. result := false;
  176. i := 0;
  177. j := $55555555;
  178. i := i or j or $AAAAAAAA;
  179. if i <> $FFFFFFFF then
  180. result := false;
  181. if not result then
  182. Fail
  183. else
  184. WriteLn('Success.');
  185. end;
  186. procedure int64TestAnd;
  187. var
  188. i,j : int64;
  189. result : boolean;
  190. Begin
  191. Write('int64 AND int64 test...');
  192. result := true;
  193. i := $1000001;
  194. j := 0;
  195. i := i and $1000001;
  196. if i <> $1000001 then
  197. result := false;
  198. i:=0;
  199. j:=$10000001;
  200. i:=i and j;
  201. if i <> 0 then
  202. result := false;
  203. i := $FFFFFFFF;
  204. j := $55555555;
  205. i := i and j;
  206. if i <> $55555555 then
  207. result := false;
  208. i := $FFFFFFFF;
  209. i := i and $AAAAAAAA;
  210. if i <> $AAAAAAAA then
  211. result := false;
  212. i := 0;
  213. j := $55555555;
  214. i := i and j and $AAAAAAAA;
  215. if i <> 0 then
  216. result := false;
  217. if not result then
  218. Fail
  219. else
  220. WriteLn('Success.');
  221. end;
  222. procedure int64TestEqual;
  223. var
  224. i,j : int64;
  225. result : boolean;
  226. Begin
  227. Write('int64 = int64 test...');
  228. result := true;
  229. i := $1000001;
  230. j := 0;
  231. if i = 0 then
  232. result := false;
  233. if i = j then
  234. result := false;
  235. if j = i then
  236. result := false;
  237. if not result then
  238. Fail
  239. else
  240. WriteLn('Success.');
  241. end;
  242. procedure int64TestNotEqual;
  243. var
  244. i,j : int64;
  245. result : boolean;
  246. Begin
  247. Write('int64 <> int64 test...');
  248. result := true;
  249. i := $1000001;
  250. j := $1000001;
  251. if i <> $1000001 then
  252. result := false;
  253. if i <> j then
  254. result := false;
  255. if j <> i then
  256. result := false;
  257. if not result then
  258. Fail
  259. else
  260. WriteLn('Success.');
  261. end;
  262. procedure int64TestLE;
  263. var
  264. i, j: int64;
  265. result : boolean;
  266. begin
  267. Write('int64 <= int64 test...');
  268. result := true;
  269. i := -1;
  270. j := -2;
  271. if i <= j then
  272. result := false;
  273. i := -2;
  274. j := $FFFF;
  275. if i >= j then
  276. result := false;
  277. i := $FFFFFFFF;
  278. if i <= $FFFFFFFE then
  279. result := false;
  280. j := $FFFFFFFF;
  281. if i <= j then
  282. begin
  283. if result then
  284. WriteLn('Success.')
  285. else
  286. Fail;
  287. end
  288. else
  289. Fail;
  290. end;
  291. procedure int64TestGE;
  292. var
  293. i, j: int64;
  294. result : boolean;
  295. begin
  296. Write('int64 >= int64 test...');
  297. result := true;
  298. i := $FFFFFFFE;
  299. j := $FFFFFFFF;
  300. if i >= j then
  301. result := false;
  302. i := $FFFFFFFE;
  303. j := $FFFFFFFF;
  304. if i > j then
  305. result := false;
  306. i := $FFFFFFFE;
  307. if i > $FFFFFFFE then
  308. result := false;
  309. i := $FFFFFFFF;
  310. j := $FFFFFFFF;
  311. if i >= j then
  312. begin
  313. if result then
  314. WriteLn('Success.')
  315. else
  316. Fail;
  317. end
  318. else
  319. Fail;
  320. end;
  321. { QWord testing }
  322. procedure qwordTestAdd;
  323. var
  324. i: qword;
  325. j: qword;
  326. result : boolean;
  327. begin
  328. Write('qword + qword test...');
  329. result := true;
  330. i:=0;
  331. j:=0;
  332. i := i + 10000;
  333. if i <> 10000 then
  334. result := false;
  335. j := 32767;
  336. i := i + j;
  337. if i <> 42767 then
  338. result := false;
  339. i := i + j + 50000;
  340. if i <> 125534 then
  341. result := false;
  342. i:=0;
  343. j:=10000;
  344. i:= i + j + j + i + j;
  345. if i <> 30000 then
  346. result := false;
  347. if not result then
  348. Fail
  349. else
  350. WriteLn('Success.');
  351. end;
  352. procedure QwordTestSub;
  353. var
  354. i, j, k : qword;
  355. result : boolean;
  356. begin
  357. Write('qword - qword test...');
  358. result := true;
  359. i:=100000;
  360. j:=54;
  361. k:=56;
  362. i:= i - 100;
  363. if i <> 99900 then
  364. result := false;
  365. i := i - j - k - 100;
  366. if i <> 99690 then
  367. result := false;
  368. i:=100;
  369. j:=1000;
  370. k:=100;
  371. i:= j - i - k;
  372. if i <> 800 then
  373. result := false;
  374. j := 900 - i;
  375. if (j <> 100) then
  376. result := false;
  377. i := 1000000000;
  378. k := i;
  379. i := i * 10;
  380. j := 1000000000 - i;
  381. k := k - i;
  382. if j <> k then
  383. result := false;
  384. if j <> (1000000000-(qword(1000000000) * 10)) then
  385. result := false;
  386. j := (qword(1) shl 33);
  387. i := (qword(1) shl 34) - j;
  388. if (i <> (qword(1) shl 33)) then
  389. result := false;
  390. i := 1 - j;
  391. if (i <> (1-(qword(1) shl 33))) then
  392. result := false;
  393. i := 100000;
  394. i := i - 90000;
  395. if (i <> 10000) then
  396. result := false;
  397. if not result then
  398. Fail
  399. else
  400. WriteLn('Success.');
  401. end;
  402. procedure QwordTestMul;
  403. var
  404. i : qword;
  405. j : qword;
  406. k: qword;
  407. result: boolean;
  408. begin
  409. Write('qword * qword test...');
  410. result := true;
  411. i:=0;
  412. j:=0;
  413. i:=i * 32;
  414. if i <> 0 then
  415. result := false;
  416. i:=10;
  417. i:=i * 16;
  418. if i <> 160 then
  419. result := false;
  420. j:=10000;
  421. i:=10000;
  422. i:=i * j;
  423. if i <> 100000000 then
  424. result := false;
  425. i:=1;
  426. j:=10;
  427. k:=16;
  428. i := i * j * k;
  429. if i <> 160 then
  430. result := false;
  431. i := 1;
  432. j := 10;
  433. k := 16;
  434. i := i * 10 * j * i * j * 16 * k;
  435. if i <> 256000 then
  436. result := false;
  437. if not result then
  438. Fail
  439. else
  440. WriteLn('Success.');
  441. end;
  442. procedure QwordTestXor;
  443. var
  444. i, j : qword;
  445. result : boolean;
  446. begin
  447. Write('qword XOR qword test...');
  448. result := true;
  449. i := 0;
  450. j := 0;
  451. i := i xor $1000001;
  452. if i <> $1000001 then
  453. result := false;
  454. i:=0;
  455. j:=$10000001;
  456. i:=i xor j;
  457. if i <> $10000001 then
  458. result := false;
  459. i := 0;
  460. j := $55555555;
  461. i := i xor j xor $AAAAAAAA;
  462. if i <> $FFFFFFFF then
  463. result := false;
  464. if not result then
  465. Fail
  466. else
  467. WriteLn('Success.');
  468. end;
  469. procedure QwordTestOr;
  470. var
  471. i,j : qword;
  472. result : boolean;
  473. Begin
  474. Write('qword OR qword test...');
  475. result := true;
  476. i := 0;
  477. j := 0;
  478. i := i or $1000001;
  479. if i <> $1000001 then
  480. result := false;
  481. i:=0;
  482. j:=$10000001;
  483. i:=i or j;
  484. if i <> $10000001 then
  485. result := false;
  486. i := 0;
  487. j := $55555555;
  488. i := i or j or $AAAAAAAA;
  489. if i <> $FFFFFFFF then
  490. result := false;
  491. if not result then
  492. Fail
  493. else
  494. WriteLn('Success.');
  495. end;
  496. procedure QwordTestAnd;
  497. var
  498. i,j : qword;
  499. result : boolean;
  500. Begin
  501. Write('qword AND qword test...');
  502. result := true;
  503. i := $1000001;
  504. j := 0;
  505. i := i and $1000001;
  506. if i <> $1000001 then
  507. result := false;
  508. i:=0;
  509. j:=$10000001;
  510. i:=i and j;
  511. if i <> 0 then
  512. result := false;
  513. i := $FFFFFFFF;
  514. j := $55555555;
  515. i := i and j;
  516. if i <> $55555555 then
  517. result := false;
  518. i := $FFFFFFFF;
  519. i := i and $AAAAAAAA;
  520. if i <> $AAAAAAAA then
  521. result := false;
  522. i := 0;
  523. j := $55555555;
  524. i := i and j and $AAAAAAAA;
  525. if i <> 0 then
  526. result := false;
  527. if not result then
  528. Fail
  529. else
  530. WriteLn('Success.');
  531. end;
  532. procedure QwordTestEqual;
  533. var
  534. i,j : qword;
  535. result : boolean;
  536. Begin
  537. Write('qword = qword test...');
  538. result := true;
  539. i := $1000001;
  540. j := 0;
  541. if i = 0 then
  542. result := false;
  543. if i = j then
  544. result := false;
  545. if j = i then
  546. result := false;
  547. if not result then
  548. Fail
  549. else
  550. WriteLn('Success.');
  551. end;
  552. procedure QwordTestNotEqual;
  553. var
  554. i,j : qword;
  555. result : boolean;
  556. Begin
  557. Write('qword <> qword test...');
  558. result := true;
  559. i := $1000001;
  560. j := $1000001;
  561. if i <> $1000001 then
  562. result := false;
  563. if i <> j then
  564. result := false;
  565. if j <> i then
  566. result := false;
  567. if not result then
  568. Fail
  569. else
  570. WriteLn('Success.');
  571. end;
  572. procedure QwordTestLE;
  573. var
  574. i, j: qword;
  575. result : boolean;
  576. begin
  577. Write('qword <= qword test...');
  578. result := true;
  579. i := 1;
  580. j := 2;
  581. if j <= i then
  582. result := false;
  583. i := 2;
  584. j := $FFFF;
  585. if i >= j then
  586. result := false;
  587. i := $FFFFFFFF;
  588. if i <= $FFFFFFFE then
  589. result := false;
  590. j := $FFFFFFFF;
  591. if i <= j then
  592. begin
  593. if result then
  594. WriteLn('Success.')
  595. else
  596. Fail;
  597. end
  598. else
  599. Fail;
  600. end;
  601. procedure QwordTestGE;
  602. var
  603. i, j: qword;
  604. result : boolean;
  605. begin
  606. Write('qword >= qword test...');
  607. result := true;
  608. i := $FFFFFFFE;
  609. j := $FFFFFFFF;
  610. if i >= j then
  611. result := false;
  612. i := $FFFFFFFE;
  613. j := $FFFFFFFF;
  614. if i > j then
  615. result := false;
  616. i := $FFFFFFFE;
  617. if i > $FFFFFFFE then
  618. result := false;
  619. i := $FFFFFFFF;
  620. j := $FFFFFFFF;
  621. if i >= j then
  622. begin
  623. if result then
  624. WriteLn('Success.')
  625. else
  626. Fail;
  627. end
  628. else
  629. Fail;
  630. end;
  631. Begin
  632. { These should be tested first, since if they do not }
  633. { work, they will false all other results. }
  634. Int64TestEqual;
  635. Int64TestNotEqual;
  636. Int64TestAdd;
  637. Int64TestMul;
  638. Int64TestOr;
  639. Int64TestAnd;
  640. Int64TestXor;
  641. Int64TestLe;
  642. Int64TestGe;
  643. Int64TestSub;
  644. QwordTestEqual;
  645. QwordTestNotEqual;
  646. QwordTestAdd;
  647. QwordTestMul;
  648. QwordTestOr;
  649. QwordTestAnd;
  650. QwordTestXor;
  651. QwordTestLe;
  652. QwordTestGe;
  653. QwordTestSub;
  654. end.
  655. {
  656. $Log$
  657. Revision 1.7 2002-09-29 14:37:22 carl
  658. * must more 64-bit testing (to detect endian specific problems)
  659. Revision 1.6 2002/09/08 20:29:36 jonas
  660. * some extra int64 - int64 tests for RISC processors
  661. Revision 1.5 2002/09/07 15:40:49 peter
  662. * old logs removed and tabs fixed
  663. Revision 1.4 2002/04/13 21:02:48 carl
  664. * fixed typos
  665. Revision 1.3 2002/03/05 21:55:11 carl
  666. * Adapted for automated testing
  667. Revision 1.2 2001/06/24 23:58:14 carl
  668. * fixed problem with log
  669. }