testi642.pp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. {$ifdef go32v2}
  2. uses
  3. dpmiexcp;
  4. {$endif go32v2}
  5. {$i ..\rtl\inc\int64.inc}
  6. procedure dumpqword(q : qword);
  7. begin
  8. write('$',hexstr(tqwordrec(q).high,8),' ',hexstr(tqwordrec(q).low,8));
  9. end;
  10. procedure dumpqwordln(q : qword);
  11. begin
  12. dumpqword(q);
  13. writeln;
  14. end;
  15. procedure assignqword(h,l : dword;var q : qword);
  16. begin
  17. tqwordrec(q).high:=h;
  18. tqwordrec(q).low:=l;
  19. end;
  20. procedure do_error(l : longint);
  21. begin
  22. writeln('Error near number ',l);
  23. halt(1);
  24. end;
  25. procedure do_error;
  26. begin
  27. do_error(0);
  28. end;
  29. { $define error:=do_error({$line});}
  30. procedure simpletestcmpqword;
  31. var
  32. q1,q2,q3,q4 : qword;
  33. begin
  34. assignqword(0,5,q1);
  35. assignqword(6,0,q2);
  36. assignqword(6,1,q3);
  37. assignqword(6,5,q4);
  38. { first test the code generation of the operators }
  39. if q1<>q1 then
  40. do_error(0);
  41. if q2<>q2 then
  42. do_error(0);
  43. if q3<>q3 then
  44. do_error(0);
  45. if not(q1=q1) then
  46. do_error(0);
  47. if not(q2=q2) then
  48. do_error(0);
  49. if not(q3=q3) then
  50. do_error(0);
  51. writeln(' <>,= succesfully tested');
  52. if q1>q2 then
  53. do_error(1100);
  54. if q2>q3 then
  55. do_error(1101);
  56. if q2<q1 then
  57. do_error(1102);
  58. if q3<q2 then
  59. do_error(1103);
  60. writeln(' <,> succesfully tested');
  61. if q1>=q2 then
  62. do_error(1104);
  63. if q2>=q3 then
  64. do_error(1105);
  65. if q2<=q1 then
  66. do_error(1106);
  67. if q3<=q2 then
  68. do_error(1107);
  69. writeln(' >=,<= succesfully tested');
  70. if q1=q2 then
  71. do_error(1108);
  72. if q2=q3 then
  73. do_error(1109);
  74. if q3=q1 then
  75. do_error(1111);
  76. if q1=q4 then
  77. do_error(1112);
  78. if q2=q4 then
  79. do_error(1113);
  80. if q3=q4 then
  81. do_error(1114);
  82. writeln(' More comparisations successful tested');
  83. end;
  84. procedure testaddqword;
  85. var
  86. q1,q2,q3,q4,q5,q6 : qword;
  87. begin
  88. { without overflow between 32 bit }
  89. assignqword(0,5,q1);
  90. assignqword(0,6,q2);
  91. assignqword(0,1,q3);
  92. assignqword(0,11,q4);
  93. assignqword(0,1,q5);
  94. if q1+q2<>q4 then
  95. do_error(1200);
  96. if q1+q3+q1<>q4 then
  97. do_error(1201);
  98. if q1+(q3+q1)<>q4 then
  99. do_error(1202);
  100. if (q1+q3)+q1<>q4 then
  101. do_error(1203);
  102. { a more complex expression }
  103. if ((((q5+q3)+(q3+q5))+((q5+q3)+(q3+q5)))+q5+q3+q5)<>q4 then
  104. do_error(1204);
  105. { with overflow between 32 bit }
  106. assignqword(0,$ffffffff,q1);
  107. assignqword(1,3,q2);
  108. assignqword(0,4,q3);
  109. assignqword(1,4,q4);
  110. assignqword(0,1,q5);
  111. assignqword(1,$fffffffe,q6);
  112. if q1+q3<>q2 then
  113. do_error(1205);
  114. if q3+q1<>q2 then
  115. do_error(1206);
  116. if q1+(q3+q5)<>q4 then
  117. do_error(1207);
  118. if (q1+q3)+q5<>q4 then
  119. do_error(1208);
  120. if (q1+q1)<>q6 then
  121. do_error(1209);
  122. end;
  123. procedure testcmpqword;
  124. var
  125. q1,q2,q3,q4,q5,q6 : qword;
  126. begin
  127. assignqword(0,$ffffffff,q1);
  128. assignqword(0,$ffffffff,q2);
  129. assignqword(1,$fffffffe,q3);
  130. assignqword(0,2,q4);
  131. assignqword(1,$fffffffc,q5);
  132. if (q1+q2)<>q3 then
  133. do_error(1300);
  134. if not(q3=(q1+q2)) then
  135. do_error(1301);
  136. if (q1+q2)>q3 then
  137. do_error(1302);
  138. if (q1+q2)<q3 then
  139. do_error(1303);
  140. if not(q3<=(q1+q2)) then
  141. do_error(1304);
  142. if not(q3>=(q1+q2)) then
  143. do_error(1305);
  144. if (q1+q2)<>(q4+q5) then
  145. do_error(1306);
  146. if not((q4+q5)=(q1+q2)) then
  147. do_error(1307);
  148. if (q1+q2)>(q4+q5) then
  149. do_error(1308);
  150. if (q1+q2)<(q4+q5) then
  151. do_error(1309);
  152. if not((q4+q5)<=(q1+q2)) then
  153. do_error(1310);
  154. if not((q4+q5)>=(q1+q2)) then
  155. do_error(1311);
  156. end;
  157. procedure testlogqword;
  158. var
  159. q0,q1,q2,q3,q4,q5,q6 : qword;
  160. begin
  161. assignqword(0,0,q0);
  162. assignqword($ffffffff,$ffffffff,q1);
  163. assignqword(0,$ffffffff,q2);
  164. assignqword($ffffffff,0,q3);
  165. assignqword($a0a0a0a0,$50505050,q4);
  166. assignqword(0,$50505050,q5);
  167. assignqword($a0a0a0a0,0,q6);
  168. { here we don't need to test all cases of locations, }
  169. { this is already done by the addtion test }
  170. if (q2 or q3)<>q1 then
  171. do_error(1400);
  172. if (q5 or q6)<>q4 then
  173. do_error(1401);
  174. if (q2 and q3)<>q0 then
  175. do_error(1402);
  176. if (q5 and q6)<>q0 then
  177. do_error(1403);
  178. if (q2 xor q3)<>q1 then
  179. do_error(1404);
  180. if (q5 xor q6)<>q4 then
  181. do_error(1405);
  182. { the test before could be also passed by the or operator! }
  183. if (q4 xor q4)<>q0 then
  184. do_error(1406);
  185. end;
  186. procedure testshlshrqword;
  187. var
  188. q0,q1,q2,q3,q4,q5 : qword;
  189. l1,l2 : longint;
  190. begin
  191. assignqword(0,0,q0);
  192. assignqword($ffff,$ffff0000,q1);
  193. assignqword(0,$ffffffff,q2);
  194. assignqword($ffffffff,0,q3);
  195. assignqword(0,1,q4);
  196. assignqword($80000000,0,q5);
  197. l1:=16;
  198. l2:=0;
  199. if (q1 shl 16)<>q3 then
  200. do_error(1500);
  201. if (q1 shl 48)<>q0 then
  202. do_error(1501);
  203. if (q1 shl 47)<>q5 then
  204. do_error(1501);
  205. if ((q1+q0) shl 16)<>q3 then
  206. do_error(1502);
  207. if ((q1+q0) shl 48)<>q0 then
  208. do_error(1503);
  209. if ((q1+q0) shl 47)<>q5 then
  210. do_error(15031);
  211. if (q1 shl l1)<>q3 then
  212. do_error(1504);
  213. if (q1 shl (3*l1))<>q0 then
  214. do_error(1505);
  215. if ((q1+q0) shl l1)<>q3 then
  216. do_error(1506);
  217. if ((q1+q0) shl (3*l1))<>q0 then
  218. do_error(1507);
  219. if ((q1+q0) shl (3*l1-1))<>q5 then
  220. do_error(15071);
  221. if (q1 shl (l1+l2))<>q3 then
  222. do_error(1508);
  223. if ((q1+q0) shl (l1+l2))<>q3 then
  224. do_error(1509);
  225. if (q1 shr 16)<>q2 then
  226. do_error(1510);
  227. if (q1 shr 48)<>q0 then
  228. do_error(1511);
  229. if (q1 shr 47)<>q4 then
  230. do_error(15111);
  231. if ((q1+q0) shr 16)<>q2 then
  232. do_error(1512);
  233. if ((q1+q0) shr 48)<>q0 then
  234. do_error(1513);
  235. if (q1 shr l1)<>q2 then
  236. do_error(1514);
  237. if (q1 shr (3*l1))<>q0 then
  238. do_error(1515);
  239. if (q1 shr (3*l1-1))<>q4 then
  240. do_error(15151);
  241. if ((q1+q0) shr l1)<>q2 then
  242. do_error(1516);
  243. if ((q1+q0) shr (3*l1))<>q0 then
  244. do_error(1517);
  245. if ((q1+q0) shr (3*l1-1))<>q4 then
  246. do_error(15171);
  247. if (q1 shr (l1+l2))<>q2 then
  248. do_error(1518);
  249. if ((q1+q0) shr (l1+l2))<>q2 then
  250. do_error(1519);
  251. end;
  252. procedure testsubqword;
  253. var
  254. q0,q1,q2,q3,q4,q5,q6 : qword;
  255. begin
  256. { without overflow between 32 bit }
  257. assignqword(0,0,q0);
  258. assignqword(0,6,q1);
  259. assignqword(0,5,q2);
  260. assignqword(0,1,q3);
  261. assignqword(0,11,q4);
  262. assignqword(0,1,q5);
  263. if q1-q2<>q3 then
  264. do_error(1600);
  265. if q1-q0-q1<>q0 then
  266. do_error(1601);
  267. if q1-(q0-q1)<>q1+q1 then
  268. do_error(1602);
  269. if (q1-q0)-q1<>q0 then
  270. do_error(1603);
  271. { a more complex expression }
  272. if ((((q5-q3)-(q3-q5))-((q5-q3)-(q3-q5))))<>q0 then
  273. do_error(1604);
  274. { with overflow between 32 bit }
  275. assignqword(1,0,q1);
  276. assignqword(0,$ffffffff,q2);
  277. assignqword(0,1,q3);
  278. assignqword(1,$ffffffff,q4);
  279. if q1-q2<>q3 then
  280. do_error(1605);
  281. if q1-q0-q2<>q3 then
  282. do_error(1606);
  283. if q1-(q0-q2)<>q4 then
  284. do_error(1607);
  285. if (q1-q0)-q1<>q0 then
  286. do_error(1608);
  287. assignqword(1,$ffffffff,q5);
  288. assignqword(1,$ffffffff,q4);
  289. { a more complex expression }
  290. if ((((q5-q3)-(q3-q5))-((q5-q3)-(q3-q5))))<>q0 then
  291. do_error(1609);
  292. end;
  293. procedure testnotqword;
  294. var
  295. q0,q1,q2,q3,q4 : qword;
  296. begin
  297. assignqword($f0f0f0f0,$f0f0f0f0,q1);
  298. assignqword($f0f0f0f,$f0f0f0f,q2);
  299. assignqword($f0f0f0f0,0,q3);
  300. assignqword(0,$f0f0f0f0,q4);
  301. if not(q1)<>q2 then
  302. do_error(1700);
  303. if not(q3 or q4)<>q2 then
  304. do_error(1701);
  305. { do a more complex expression to stress the register saving }
  306. if not(q3 or q4)<>not(q3 or q4) then
  307. do_error(1702);
  308. end;
  309. procedure testmulqword;
  310. var
  311. q0,q1,q2,q3,q4,q5,q6 : qword;
  312. i : longint;
  313. begin
  314. assignqword(0,0,q0);
  315. assignqword(0,1,q1);
  316. assignqword(0,4,q2);
  317. assignqword(2,0,q3);
  318. assignqword(8,0,q4);
  319. assignqword(0,1,q5);
  320. assignqword($ffff,$12344321,q6);
  321. { to some trivial tests }
  322. { to test the code generation }
  323. if q1*q2<>q2 then
  324. do_error(1800);
  325. if q1*q2*q3<>q4 then
  326. do_error(1801);
  327. if q1*(q2*q3)<>q4 then
  328. do_error(1802);
  329. if (q1*q2)*q3<>q4 then
  330. do_error(1803);
  331. if (q6*q5)*(q1*q2)<>q1*q2*q5*q6 then
  332. do_error(1804);
  333. { a more complex expression }
  334. if ((((q1*q5)*(q1*q5))*((q5*q1)*(q1*q5)))*q5*q1*q5)<>q1 then
  335. do_error(1805);
  336. { now test the multiplication procedure with random bit patterns }
  337. writeln('Doing some random multiplications, takes a few seconds');
  338. writeln('.....................................100%');
  339. for i:=1 to 1000000 do
  340. begin
  341. tqwordrec(q1).high:=0;
  342. tqwordrec(q1).low:=random($ffffffff);
  343. tqwordrec(q2).high:=0;
  344. tqwordrec(q2).low:=random($ffffffff);
  345. if q1*q2<>q2*q1 then
  346. begin
  347. write('Multiplication of ');
  348. dumpqword(q1);
  349. write(' and ');
  350. dumpqword(q2);
  351. writeln(' failed');
  352. do_error(1806);
  353. end;
  354. if i mod 50000=0 then
  355. write('.');
  356. end;
  357. for i:=1 to 1000000 do
  358. begin
  359. tqwordrec(q1).high:=0;
  360. tqwordrec(q1).low:=random($ffffffff);
  361. q1:=q1 shl 16;
  362. tqwordrec(q2).high:=0;
  363. tqwordrec(q2).low:=random($ffff);
  364. if q1*q2<>q2*q1 then
  365. begin
  366. write('Multiplication of ');
  367. dumpqword(q1);
  368. write(' and ');
  369. dumpqword(q2);
  370. writeln(' failed');
  371. do_error(1806);
  372. end;
  373. if i mod 50000=0 then
  374. write('.');
  375. end;
  376. writeln(' OK');
  377. end;
  378. procedure testdivqword;
  379. var
  380. q0,q1,q2,q3,q4,q5,q6 : qword;
  381. i : longint;
  382. begin
  383. assignqword(0,0,q0);
  384. assignqword(0,1,q1);
  385. assignqword(0,4,q2);
  386. assignqword(2,0,q3);
  387. assignqword(8,0,q4);
  388. assignqword(0,1,q5);
  389. assignqword($ffff,$12344321,q6);
  390. { to some trivial tests }
  391. { to test the code generation }
  392. if q2 div q1<>q2 then
  393. do_error(1900);
  394. if q2 div q1 div q1<>q1 then
  395. do_error(1901);
  396. if q2 div (q4 div q3)<>q1 then
  397. do_error(1902);
  398. if (q4 div q3) div q2<>q1 then
  399. do_error(1903);
  400. { a more complex expression }
  401. if (q4 div q3) div (q2 div q1)<>(q2 div q1) div (q4 div q3) then
  402. do_error(1904);
  403. { now test the division procedure with random bit patterns }
  404. writeln('Doing some random divisions, takes a few seconds');
  405. writeln('.................100%');
  406. for i:=1 to 100000 do
  407. begin
  408. tqwordrec(q1).high:=random($ffffffff);
  409. tqwordrec(q1).low:=random($ffffffff);
  410. tqwordrec(q2).high:=random($ffffffff);
  411. tqwordrec(q2).low:=random($ffffffff);
  412. q3:=q1 div q2;
  413. { get a restless division }
  414. q1:=q2*q3;
  415. q3:=q1 div q2;
  416. if q3*q2<>q1 then
  417. begin
  418. write('Division of ');
  419. dumpqword(q1);
  420. write(' by ');
  421. dumpqword(q2);
  422. writeln(' failed');
  423. do_error(1906);
  424. end;
  425. if i mod 10000=0 then
  426. write('.');
  427. end;
  428. for i:=1 to 100000 do
  429. begin
  430. tqwordrec(q1).high:=random($ffffffff);
  431. tqwordrec(q1).low:=random($ffffffff);
  432. tqwordrec(q2).high:=0;
  433. tqwordrec(q2).low:=random($ffffffff);
  434. { get a restless division }
  435. q3:=q1 div q2;
  436. q1:=q2*q3;
  437. q3:=q1 div q2;
  438. if q3<>q1 then
  439. begin
  440. write('Division of ');
  441. dumpqword(q1);
  442. write(' by ');
  443. dumpqword(q2);
  444. writeln(' failed');
  445. do_error(1907);
  446. end;
  447. if i mod 10000=0 then
  448. write('.');
  449. end;
  450. writeln(' OK');
  451. end;
  452. function testf : qword;
  453. var
  454. q : qword;
  455. begin
  456. assignqword($ffffffff,$a0a0a0a0,q);
  457. testf:=q;
  458. end;
  459. procedure testfuncword;
  460. var
  461. q : qword;
  462. begin
  463. assignqword($ffffffff,$a0a0a0a0,q);
  464. if testf<>q then
  465. do_error(1900);
  466. if q<>testf then
  467. do_error(1901);
  468. end;
  469. var
  470. q : qword;
  471. begin
  472. randomize;
  473. writeln('------------------------------------------------------');
  474. writeln(' QWord test ');
  475. writeln('------------------------------------------------------');
  476. writeln;
  477. writeln('Testing assignqword and dumpqword ... ');
  478. assignqword($12345678,$9ABCDEF0,q);
  479. dumpqword(q);
  480. writeln;
  481. writeln('The output should be:');
  482. writeln('$12345678 9ABCDEF0');
  483. writeln;
  484. writeln('Testing simple QWord comparisations');
  485. simpletestcmpqword;
  486. writeln('Testing simple QWord comparisations was successful');
  487. writeln;
  488. writeln('Testing QWord additions');
  489. testaddqword;
  490. writeln('Testing QWord additions was successful');
  491. writeln;
  492. writeln('Testing more QWord comparisations');
  493. testcmpqword;
  494. writeln('Testing more QWord comparisations was successful');
  495. writeln;
  496. writeln('Testing QWord subtraction');
  497. testsubqword;
  498. writeln('Testing QWord subtraction was successful');
  499. writeln;
  500. writeln('Testing QWord logical operators (or,xor,and)');
  501. testlogqword;
  502. writeln('Testing QWord logical operators (or,xor,and) was successful');
  503. writeln;
  504. writeln('Testing QWord logical not operator');
  505. testnotqword;
  506. writeln('Testing QWord logical not operator was successful');
  507. writeln;
  508. writeln('Testing QWord logical shift operators (shr,shr)');
  509. testshlshrqword;
  510. writeln('Testing QWord logical shift operators (shr,shr) was successful');
  511. writeln;
  512. writeln('Testing QWord function results');
  513. testfuncword;
  514. writeln('Testing QWord function results was successful');
  515. writeln;
  516. writeln('Testing QWord division');
  517. testdivqword;
  518. writeln('Testing QWord division was successful');
  519. writeln;
  520. writeln('Testing QWord multiplications');
  521. testmulqword;
  522. writeln('Testing QWord multiplications was successful');
  523. writeln;
  524. writeln('------------------------------------------------------');
  525. writeln(' QWord test successful');
  526. writeln('------------------------------------------------------');
  527. halt(0);
  528. end.