tadint64.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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. { The next statement would create an overflow }
  381. {$Q-}
  382. j := 1000000000 - i;
  383. k := k - i;
  384. if j <> k then
  385. result := false;
  386. { Since qword variable<>negative constant is always false according to the
  387. compiler (allowing it to optimize the if away) we need to do a preventive
  388. typecast to qword.}
  389. if j <> qword(1000000000-(qword(1000000000) * 10)) then
  390. result := false;
  391. j := (qword(1) shl 33);
  392. i := (qword(1) shl 34) - j;
  393. if (i <> (qword(1) shl 33)) then
  394. result := false;
  395. i := 1 - j;
  396. { Since qword variable<>negative constant is always false according to the
  397. compiler (allowing it to optimize the if away) we need to do a preventive
  398. typecast to qword.}
  399. if i <> qword(1-(qword(1) shl 33)) then
  400. result := false;
  401. i := 100000;
  402. i := i - 90000;
  403. if (i <> 10000) then
  404. result := false;
  405. if not result then
  406. Fail
  407. else
  408. WriteLn('Success.');
  409. end;
  410. procedure QwordTestMul;
  411. var
  412. i : qword;
  413. j : qword;
  414. k: qword;
  415. result: boolean;
  416. begin
  417. Write('qword * qword test...');
  418. result := true;
  419. i:=0;
  420. j:=0;
  421. i:=i * 32;
  422. if i <> 0 then
  423. result := false;
  424. i:=10;
  425. i:=i * 16;
  426. if i <> 160 then
  427. result := false;
  428. j:=10000;
  429. i:=10000;
  430. i:=i * j;
  431. if i <> 100000000 then
  432. result := false;
  433. i:=1;
  434. j:=10;
  435. k:=16;
  436. i := i * j * k;
  437. if i <> 160 then
  438. result := false;
  439. i := 1;
  440. j := 10;
  441. k := 16;
  442. i := i * 10 * j * i * j * 16 * k;
  443. if i <> 256000 then
  444. result := false;
  445. if not result then
  446. Fail
  447. else
  448. WriteLn('Success.');
  449. end;
  450. procedure QwordTestXor;
  451. var
  452. i, j : qword;
  453. result : boolean;
  454. begin
  455. Write('qword XOR qword test...');
  456. result := true;
  457. i := 0;
  458. j := 0;
  459. i := i xor $1000001;
  460. if i <> $1000001 then
  461. result := false;
  462. i:=0;
  463. j:=$10000001;
  464. i:=i xor j;
  465. if i <> $10000001 then
  466. result := false;
  467. i := 0;
  468. j := $55555555;
  469. i := i xor j xor $AAAAAAAA;
  470. if i <> $FFFFFFFF then
  471. result := false;
  472. if not result then
  473. Fail
  474. else
  475. WriteLn('Success.');
  476. end;
  477. procedure QwordTestOr;
  478. var
  479. i,j : qword;
  480. result : boolean;
  481. Begin
  482. Write('qword OR qword test...');
  483. result := true;
  484. i := 0;
  485. j := 0;
  486. i := i or $1000001;
  487. if i <> $1000001 then
  488. result := false;
  489. i:=0;
  490. j:=$10000001;
  491. i:=i or j;
  492. if i <> $10000001 then
  493. result := false;
  494. i := 0;
  495. j := $55555555;
  496. i := i or j or $AAAAAAAA;
  497. if i <> $FFFFFFFF then
  498. result := false;
  499. if not result then
  500. Fail
  501. else
  502. WriteLn('Success.');
  503. end;
  504. procedure QwordTestAnd;
  505. var
  506. i,j : qword;
  507. result : boolean;
  508. Begin
  509. Write('qword AND qword test...');
  510. result := true;
  511. i := $1000001;
  512. j := 0;
  513. i := i and $1000001;
  514. if i <> $1000001 then
  515. result := false;
  516. i:=0;
  517. j:=$10000001;
  518. i:=i and j;
  519. if i <> 0 then
  520. result := false;
  521. i := $FFFFFFFF;
  522. j := $55555555;
  523. i := i and j;
  524. if i <> $55555555 then
  525. result := false;
  526. i := $FFFFFFFF;
  527. i := i and $AAAAAAAA;
  528. if i <> $AAAAAAAA then
  529. result := false;
  530. i := 0;
  531. j := $55555555;
  532. i := i and j and $AAAAAAAA;
  533. if i <> 0 then
  534. result := false;
  535. if not result then
  536. Fail
  537. else
  538. WriteLn('Success.');
  539. end;
  540. procedure QwordTestEqual;
  541. var
  542. i,j : qword;
  543. result : boolean;
  544. Begin
  545. Write('qword = qword test...');
  546. result := true;
  547. i := $1000001;
  548. j := 0;
  549. if i = 0 then
  550. result := false;
  551. if i = j then
  552. result := false;
  553. if j = i then
  554. result := false;
  555. if not result then
  556. Fail
  557. else
  558. WriteLn('Success.');
  559. end;
  560. procedure QwordTestNotEqual;
  561. var
  562. i,j : qword;
  563. result : boolean;
  564. Begin
  565. Write('qword <> qword test...');
  566. result := true;
  567. i := $1000001;
  568. j := $1000001;
  569. if i <> $1000001 then
  570. result := false;
  571. if i <> j then
  572. result := false;
  573. if j <> i then
  574. result := false;
  575. if not result then
  576. Fail
  577. else
  578. WriteLn('Success.');
  579. end;
  580. procedure QwordTestLE;
  581. var
  582. i, j: qword;
  583. result : boolean;
  584. begin
  585. Write('qword <= qword test...');
  586. result := true;
  587. i := 1;
  588. j := 2;
  589. if j <= i then
  590. result := false;
  591. i := 2;
  592. j := $FFFF;
  593. if i >= j then
  594. result := false;
  595. i := $FFFFFFFF;
  596. if i <= $FFFFFFFE then
  597. result := false;
  598. j := $FFFFFFFF;
  599. if i <= j then
  600. begin
  601. if result then
  602. WriteLn('Success.')
  603. else
  604. Fail;
  605. end
  606. else
  607. Fail;
  608. end;
  609. procedure QwordTestGE;
  610. var
  611. i, j: qword;
  612. result : boolean;
  613. begin
  614. Write('qword >= qword test...');
  615. result := true;
  616. i := $FFFFFFFE;
  617. j := $FFFFFFFF;
  618. if i >= j then
  619. result := false;
  620. i := $FFFFFFFE;
  621. j := $FFFFFFFF;
  622. if i > j then
  623. result := false;
  624. i := $FFFFFFFE;
  625. if i > $FFFFFFFE then
  626. result := false;
  627. i := $FFFFFFFF;
  628. j := $FFFFFFFF;
  629. if i >= j then
  630. begin
  631. if result then
  632. WriteLn('Success.')
  633. else
  634. Fail;
  635. end
  636. else
  637. Fail;
  638. end;
  639. Begin
  640. { These should be tested first, since if they do not }
  641. { work, they will false all other results. }
  642. Int64TestEqual;
  643. Int64TestNotEqual;
  644. Int64TestAdd;
  645. Int64TestMul;
  646. Int64TestOr;
  647. Int64TestAnd;
  648. Int64TestXor;
  649. Int64TestLe;
  650. Int64TestGe;
  651. Int64TestSub;
  652. QwordTestEqual;
  653. QwordTestNotEqual;
  654. QwordTestAdd;
  655. QwordTestMul;
  656. QwordTestOr;
  657. QwordTestAnd;
  658. QwordTestXor;
  659. QwordTestLe;
  660. QwordTestGe;
  661. QwordTestSub;
  662. end.