tint642.pp 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. {$Q-} { this is necessary to avoid an overflow error below }
  2. {$mode objfpc}
  3. uses
  4. sysutils
  5. {$ifdef go32v2}
  6. ,dpmiexcp
  7. {$endif go32v2}
  8. ;
  9. type
  10. tqwordrec = packed record
  11. low,high : dword;
  12. end;
  13. procedure dumpqword(q : qword);
  14. begin
  15. write('$',hexstr(tqwordrec(q).high,8),' ',hexstr(tqwordrec(q).low,8));
  16. end;
  17. procedure dumpqwordln(q : qword);
  18. begin
  19. dumpqword(q);
  20. writeln;
  21. end;
  22. procedure assignqword(h,l : dword;var q : qword);
  23. begin
  24. tqwordrec(q).high:=h;
  25. tqwordrec(q).low:=l;
  26. end;
  27. procedure do_error(l : longint);
  28. begin
  29. writeln('Error near number ',l);
  30. halt(1);
  31. end;
  32. procedure do_error;
  33. begin
  34. do_error(0);
  35. end;
  36. procedure simpletestcmpqword;
  37. var
  38. q1,q2,q3,q4 : qword;
  39. begin
  40. assignqword(0,5,q1);
  41. assignqword(6,0,q2);
  42. assignqword(6,1,q3);
  43. assignqword(6,5,q4);
  44. { first test the code generation of the operators }
  45. if q1<>q1 then
  46. do_error(0);
  47. if q2<>q2 then
  48. do_error(0);
  49. if q3<>q3 then
  50. do_error(0);
  51. if not(q1=q1) then
  52. do_error(0);
  53. if not(q2=q2) then
  54. do_error(0);
  55. if not(q3=q3) then
  56. do_error(0);
  57. writeln(' <>,= succesfully tested');
  58. if q1>q2 then
  59. do_error(1100);
  60. if q2>q3 then
  61. do_error(1101);
  62. if q2<q1 then
  63. do_error(1102);
  64. if q3<q2 then
  65. do_error(1103);
  66. writeln(' <,> succesfully tested');
  67. if q1>=q2 then
  68. do_error(1104);
  69. if q2>=q3 then
  70. do_error(1105);
  71. if q2<=q1 then
  72. do_error(1106);
  73. if q3<=q2 then
  74. do_error(1107);
  75. writeln(' >=,<= succesfully tested');
  76. if q1=q2 then
  77. do_error(1108);
  78. if q2=q3 then
  79. do_error(1109);
  80. if q3=q1 then
  81. do_error(1111);
  82. if q1=q4 then
  83. do_error(1112);
  84. if q2=q4 then
  85. do_error(1113);
  86. if q3=q4 then
  87. do_error(1114);
  88. writeln(' More comparisations successful tested');
  89. end;
  90. procedure testaddqword;
  91. var
  92. q1,q2,q3,q4,q5,q6 : qword;
  93. begin
  94. { without overflow between 32 bit }
  95. assignqword(0,5,q1);
  96. assignqword(0,6,q2);
  97. assignqword(0,1,q3);
  98. assignqword(0,11,q4);
  99. assignqword(0,1,q5);
  100. if q1+q2<>q4 then
  101. do_error(1200);
  102. if q1+q3+q1<>q4 then
  103. do_error(1201);
  104. if q1+(q3+q1)<>q4 then
  105. do_error(1202);
  106. if (q1+q3)+q1<>q4 then
  107. do_error(1203);
  108. { a more complex expression }
  109. if ((((q5+q3)+(q3+q5))+((q5+q3)+(q3+q5)))+q5+q3+q5)<>q4 then
  110. do_error(1204);
  111. { with overflow between 32 bit }
  112. assignqword(0,$ffffffff,q1);
  113. assignqword(1,3,q2);
  114. assignqword(0,4,q3);
  115. assignqword(1,4,q4);
  116. assignqword(0,1,q5);
  117. assignqword(1,$fffffffe,q6);
  118. if q1+q3<>q2 then
  119. do_error(1205);
  120. if q3+q1<>q2 then
  121. do_error(1206);
  122. if q1+(q3+q5)<>q4 then
  123. do_error(1207);
  124. if (q1+q3)+q5<>q4 then
  125. do_error(1208);
  126. if (q1+q1)<>q6 then
  127. do_error(1209);
  128. end;
  129. procedure testcmpqword;
  130. var
  131. q1,q2,q3,q4,q5,q6 : qword;
  132. begin
  133. assignqword(0,$ffffffff,q1);
  134. assignqword(0,$ffffffff,q2);
  135. assignqword(1,$fffffffe,q3);
  136. assignqword(0,2,q4);
  137. assignqword(1,$fffffffc,q5);
  138. if (q1+q2)<>q3 then
  139. do_error(1300);
  140. if not(q3=(q1+q2)) then
  141. do_error(1301);
  142. if (q1+q2)>q3 then
  143. do_error(1302);
  144. if (q1+q2)<q3 then
  145. do_error(1303);
  146. if not(q3<=(q1+q2)) then
  147. do_error(1304);
  148. if not(q3>=(q1+q2)) then
  149. do_error(1305);
  150. if (q1+q2)<>(q4+q5) then
  151. do_error(1306);
  152. if not((q4+q5)=(q1+q2)) then
  153. do_error(1307);
  154. if (q1+q2)>(q4+q5) then
  155. do_error(1308);
  156. if (q1+q2)<(q4+q5) then
  157. do_error(1309);
  158. if not((q4+q5)<=(q1+q2)) then
  159. do_error(1310);
  160. if not((q4+q5)>=(q1+q2)) then
  161. do_error(1311);
  162. end;
  163. procedure testlogqword;
  164. var
  165. q0,q1,q2,q3,q4,q5,q6 : qword;
  166. begin
  167. assignqword(0,0,q0);
  168. assignqword($ffffffff,$ffffffff,q1);
  169. assignqword(0,$ffffffff,q2);
  170. assignqword($ffffffff,0,q3);
  171. assignqword($a0a0a0a0,$50505050,q4);
  172. assignqword(0,$50505050,q5);
  173. assignqword($a0a0a0a0,0,q6);
  174. { here we don't need to test all cases of locations, }
  175. { this is already done by the addtion test }
  176. if (q2 or q3)<>q1 then
  177. do_error(1400);
  178. if (q5 or q6)<>q4 then
  179. do_error(1401);
  180. if (q2 and q3)<>q0 then
  181. do_error(1402);
  182. if (q5 and q6)<>q0 then
  183. do_error(1403);
  184. if (q2 xor q3)<>q1 then
  185. do_error(1404);
  186. if (q5 xor q6)<>q4 then
  187. do_error(1405);
  188. { the test before could be also passed by the or operator! }
  189. if (q4 xor q4)<>q0 then
  190. do_error(1406);
  191. end;
  192. procedure testshlshrqword;
  193. var
  194. q0,q1,q2,q3,q4,q5 : qword;
  195. l1,l2 : longint;
  196. begin
  197. assignqword(0,0,q0);
  198. assignqword($ffff,$ffff0000,q1);
  199. assignqword(0,$ffffffff,q2);
  200. assignqword($ffffffff,0,q3);
  201. assignqword(0,1,q4);
  202. assignqword($80000000,0,q5);
  203. l1:=16;
  204. l2:=0;
  205. if (q1 shl 16)<>q3 then
  206. do_error(1500);
  207. if (q1 shl 48)<>q0 then
  208. do_error(1501);
  209. if (q1 shl 47)<>q5 then
  210. do_error(1501);
  211. if ((q1+q0) shl 16)<>q3 then
  212. do_error(1502);
  213. if ((q1+q0) shl 48)<>q0 then
  214. do_error(1503);
  215. if ((q1+q0) shl 47)<>q5 then
  216. do_error(15031);
  217. if (q1 shl l1)<>q3 then
  218. do_error(1504);
  219. if (q1 shl (3*l1))<>q0 then
  220. do_error(1505);
  221. if ((q1+q0) shl l1)<>q3 then
  222. do_error(1506);
  223. if ((q1+q0) shl (3*l1))<>q0 then
  224. do_error(1507);
  225. if ((q1+q0) shl (3*l1-1))<>q5 then
  226. do_error(15071);
  227. if (q1 shl (l1+l2))<>q3 then
  228. do_error(1508);
  229. if ((q1+q0) shl (l1+l2))<>q3 then
  230. do_error(1509);
  231. if (q1 shr 16)<>q2 then
  232. do_error(1510);
  233. if (q1 shr 48)<>q0 then
  234. do_error(1511);
  235. if (q1 shr 47)<>q4 then
  236. do_error(15111);
  237. if ((q1+q0) shr 16)<>q2 then
  238. do_error(1512);
  239. if ((q1+q0) shr 48)<>q0 then
  240. do_error(1513);
  241. if (q1 shr l1)<>q2 then
  242. do_error(1514);
  243. if (q1 shr (3*l1))<>q0 then
  244. do_error(1515);
  245. if (q1 shr (3*l1-1))<>q4 then
  246. do_error(15151);
  247. if ((q1+q0) shr l1)<>q2 then
  248. do_error(1516);
  249. if ((q1+q0) shr (3*l1))<>q0 then
  250. do_error(1517);
  251. if ((q1+q0) shr (3*l1-1))<>q4 then
  252. do_error(15171);
  253. if (q1 shr (l1+l2))<>q2 then
  254. do_error(1518);
  255. if ((q1+q0) shr (l1+l2))<>q2 then
  256. do_error(1519);
  257. end;
  258. procedure testsubqword;
  259. var
  260. q0,q1,q2,q3,q4,q5,q6 : qword;
  261. begin
  262. { without overflow between 32 bit }
  263. assignqword(0,0,q0);
  264. assignqword(0,6,q1);
  265. assignqword(0,5,q2);
  266. assignqword(0,1,q3);
  267. assignqword(0,11,q4);
  268. assignqword(0,1,q5);
  269. if q1-q2<>q3 then
  270. do_error(1600);
  271. if q1-q0-q1<>q0 then
  272. do_error(1601);
  273. if q1-(q0-q1)<>q1+q1 then
  274. do_error(1602);
  275. if (q1-q0)-q1<>q0 then
  276. do_error(1603);
  277. { a more complex expression }
  278. if ((((q5-q3)-(q3-q5))-((q5-q3)-(q3-q5))))<>q0 then
  279. do_error(1604);
  280. { with overflow between 32 bit }
  281. assignqword(1,0,q1);
  282. assignqword(0,$ffffffff,q2);
  283. assignqword(0,1,q3);
  284. assignqword(1,$ffffffff,q4);
  285. if q1-q2<>q3 then
  286. do_error(1605);
  287. if q1-q0-q2<>q3 then
  288. do_error(1606);
  289. if q1-(q0-q2)<>q4 then
  290. do_error(1607);
  291. if (q1-q0)-q1<>q0 then
  292. do_error(1608);
  293. assignqword(1,$ffffffff,q5);
  294. assignqword(1,$ffffffff,q4);
  295. { a more complex expression }
  296. if ((((q5-q3)-(q3-q5))-((q5-q3)-(q3-q5))))<>q0 then
  297. do_error(1609);
  298. end;
  299. procedure testnotqword;
  300. var
  301. q0,q1,q2,q3,q4 : qword;
  302. begin
  303. assignqword($f0f0f0f0,$f0f0f0f0,q1);
  304. assignqword($f0f0f0f,$f0f0f0f,q2);
  305. assignqword($f0f0f0f0,0,q3);
  306. assignqword(0,$f0f0f0f0,q4);
  307. if not(q1)<>q2 then
  308. do_error(1700);
  309. if not(q3 or q4)<>q2 then
  310. do_error(1701);
  311. { do a more complex expression to stress the register saving }
  312. if not(q3 or q4)<>not(q3 or q4) then
  313. do_error(1702);
  314. end;
  315. procedure testnegqword;
  316. var
  317. q0,q1,q2,q3,q4 : qword;
  318. begin
  319. assignqword($1,$0,q1);
  320. assignqword($0,1234,q2);
  321. if -q1<>(0-q1) then
  322. do_error(2700);
  323. if -q2<>(0-q2) then
  324. do_error(2701);
  325. if -(q1+q2)<>(0-(q1+q2)) then
  326. do_error(2702);
  327. end;
  328. procedure testmulqword;
  329. var
  330. q0,q1,q2,q3,q4,q5,q6 : qword;
  331. i : longint;
  332. begin
  333. assignqword(0,0,q0);
  334. assignqword(0,1,q1);
  335. assignqword(0,4,q2);
  336. assignqword(2,0,q3);
  337. assignqword(8,0,q4);
  338. assignqword(0,1,q5);
  339. assignqword($ffff,$12344321,q6);
  340. { to some trivial tests }
  341. { to test the code generation }
  342. if q1*q2<>q2 then
  343. do_error(1800);
  344. if q1*q2*q3<>q4 then
  345. do_error(1801);
  346. if q1*(q2*q3)<>q4 then
  347. do_error(1802);
  348. if (q1*q2)*q3<>q4 then
  349. do_error(1803);
  350. if (q6*q5)*(q1*q2)<>q1*q2*q5*q6 then
  351. do_error(1804);
  352. { a more complex expression }
  353. if ((((q1*q5)*(q1*q5))*((q5*q1)*(q1*q5)))*q5*q1*q5)<>q1 then
  354. do_error(1805);
  355. { now test the multiplication procedure with random bit patterns }
  356. writeln('Doing some random multiplications, takes a few seconds');
  357. writeln('.....................................100%');
  358. for i:=1 to 1000000 do
  359. begin
  360. tqwordrec(q1).high:=0;
  361. tqwordrec(q1).low:=random($7ffffffe);
  362. tqwordrec(q2).high:=0;
  363. tqwordrec(q2).low:=random($7ffffffe);
  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. for i:=1 to 1000000 do
  377. begin
  378. tqwordrec(q1).high:=0;
  379. tqwordrec(q1).low:=random($7ffffffe);
  380. q1:=q1 shl 16;
  381. tqwordrec(q2).high:=0;
  382. tqwordrec(q2).low:=random($fffe);
  383. if q1*q2<>q2*q1 then
  384. begin
  385. write('Multiplication of ');
  386. dumpqword(q1);
  387. write(' and ');
  388. dumpqword(q2);
  389. writeln(' failed');
  390. do_error(1806);
  391. end;
  392. if i mod 50000=0 then
  393. write('.');
  394. end;
  395. writeln(' OK');
  396. end;
  397. procedure testdivqword;
  398. var
  399. q0,q1,q2,q3,q4,q5,q6 : qword;
  400. i : longint;
  401. begin
  402. assignqword(0,0,q0);
  403. assignqword(0,1,q1);
  404. assignqword(0,4,q2);
  405. assignqword(2,0,q3);
  406. assignqword(8,0,q4);
  407. assignqword(0,1,q5);
  408. assignqword($ffff,$12344321,q6);
  409. { to some trivial tests }
  410. { to test the code generation }
  411. if q2 div q1<>q2 then
  412. do_error(1900);
  413. if q2 div q1 div q1<>q2 then
  414. do_error(1901);
  415. if q2 div (q4 div q3)<>q1 then
  416. do_error(1902);
  417. if (q4 div q3) div q2<>q1 then
  418. do_error(1903);
  419. { a more complex expression }
  420. if (q4 div q3) div (q2 div q1)<>(q2 div q1) div (q4 div q3) then
  421. do_error(1904);
  422. { now test the division procedure with random bit patterns }
  423. writeln('Doing some random divisions, takes a few seconds');
  424. writeln('.................100%');
  425. for i:=1 to 100000 do
  426. begin
  427. tqwordrec(q1).high:=random($7ffffffe);
  428. tqwordrec(q1).low:=random($7ffffffe);
  429. tqwordrec(q2).high:=random($7ffffffe);
  430. tqwordrec(q2).low:=random($7ffffffe);
  431. { avoid division by zero }
  432. if (tqwordrec(q2).low or tqwordrec(q2).high)=0 then
  433. tqwordrec(q2).low:=1;
  434. q3:=q1 div q2;
  435. { get a restless division }
  436. q1:=q2*q3;
  437. q3:=q1 div q2;
  438. if q3*q2<>q1 then
  439. begin
  440. write('Division of ');
  441. dumpqword(q1);
  442. write(' by ');
  443. dumpqword(q2);
  444. writeln(' failed');
  445. do_error(1906);
  446. end;
  447. if i mod 10000=0 then
  448. write('.');
  449. end;
  450. for i:=1 to 100000 do
  451. begin
  452. tqwordrec(q1).high:=0;
  453. tqwordrec(q1).low:=random($7ffffffe);
  454. tqwordrec(q2).high:=0;
  455. tqwordrec(q2).low:=random($7ffffffe);
  456. { avoid division by zero }
  457. if tqwordrec(q2).low=0 then
  458. tqwordrec(q2).low:=1;
  459. { get a restless division }
  460. q3:=q1*q2;
  461. q3:=q3 div q2;
  462. if q3<>q1 then
  463. begin
  464. write('Division of ');
  465. dumpqword(q1);
  466. write(' by ');
  467. dumpqword(q2);
  468. writeln(' failed');
  469. do_error(1907);
  470. end;
  471. if i mod 10000=0 then
  472. write('.');
  473. end;
  474. writeln(' OK');
  475. end;
  476. function testf : qword;
  477. var
  478. q : qword;
  479. begin
  480. assignqword($ffffffff,$a0a0a0a0,q);
  481. testf:=q;
  482. end;
  483. procedure testfuncqword;
  484. var
  485. q : qword;
  486. begin
  487. assignqword($ffffffff,$a0a0a0a0,q);
  488. if testf<>q then
  489. do_error(1900);
  490. if q<>testf then
  491. do_error(1901);
  492. end;
  493. procedure testtypecastqword;
  494. var
  495. s1,s2 : shortint;
  496. b1,b2 : byte;
  497. w1,w2 : word;
  498. i1,i2 : integer;
  499. l1,l2 : longint;
  500. d1,d2 : dword;
  501. q1,q2 : qword;
  502. r1,r2 : double;
  503. begin
  504. { shortint }
  505. s1:=75;
  506. s2:=0;
  507. q1:=s1;
  508. { mix up the processor a little bit }
  509. q2:=q1;
  510. if q2<>75 then
  511. begin
  512. dumpqword(q2);
  513. do_error(2006);
  514. end;
  515. s2:=q2;
  516. if s1<>s2 then
  517. do_error(2000);
  518. { byte }
  519. b1:=$ca;
  520. b2:=0;
  521. q1:=b1;
  522. { mix up the processor a little bit }
  523. q2:=q1;
  524. if q2<>$ca then
  525. do_error(2007);
  526. b2:=q2;
  527. if b1<>b2 then
  528. do_error(2001);
  529. { integer }
  530. i1:=12345;
  531. i2:=0;
  532. q1:=i1;
  533. { mix up the processor a little bit }
  534. q2:=q1;
  535. if q2<>12345 then
  536. do_error(2008);
  537. i2:=q2;
  538. if i1<>i2 then
  539. do_error(2002);
  540. { word }
  541. w1:=$a0ff;
  542. w2:=0;
  543. q1:=w1;
  544. { mix up the processor a little bit }
  545. q2:=q1;
  546. if q2<>$a0ff then
  547. do_error(2009);
  548. w2:=q2;
  549. if w1<>w2 then
  550. do_error(2003);
  551. { longint }
  552. l1:=12341234;
  553. l2:=0;
  554. q1:=l1;
  555. { mix up the processor a little bit }
  556. q2:=q1;
  557. if q2<>12341234 then
  558. do_error(2010);
  559. l2:=q2;
  560. if l1<>l2 then
  561. do_error(2004);
  562. { dword }
  563. d1:=$5bcdef01;
  564. b2:=0;
  565. q1:=d1;
  566. { mix up the processor a little bit }
  567. q2:=q1;
  568. if q2<>$5bcdef01 then
  569. do_error(2011);
  570. d2:=q2;
  571. if d1<>d2 then
  572. do_error(2005);
  573. { real }
  574. { memory location }
  575. q1:=12;
  576. d1:=q1;
  577. d2:=12;
  578. if d1<>d2 then
  579. do_error(2012);
  580. { register location }
  581. q1:=12;
  582. d1:=q1+1;
  583. d2:=13;
  584. if d1<>d2 then
  585. do_error(2013);
  586. // a constant which can't be loaded with fild
  587. q1:=$80000000;
  588. q1:=q1 shl 32;
  589. d1:=q1;
  590. d2:=$80000000;
  591. if d1<>d2*d2*2.0 then
  592. do_error(20);
  593. // register location
  594. d1:=q1+1;
  595. if d1<>d2*d2*2.0+1 then
  596. do_error(2014);
  597. end;
  598. procedure testioqword;
  599. var
  600. t : text;
  601. q1,q2 : qword;
  602. i : longint;
  603. begin
  604. assignqword($ffffffff,$a0a0a0a0,q1);
  605. assign(t,'testi642.tmp');
  606. rewrite(t);
  607. writeln(t,q1);
  608. close(t);
  609. reset(t);
  610. readln(t,q2);
  611. close(t);
  612. if q1<>q2 then
  613. do_error(2100);
  614. { do some random tests }
  615. for i:=1 to 100 do
  616. begin
  617. tqwordrec(q1).high:=random($7ffffffe);
  618. tqwordrec(q1).low:=random($7ffffffe);
  619. rewrite(t);
  620. writeln(t,q1);
  621. close(t);
  622. reset(t);
  623. readln(t,q2);
  624. close(t);
  625. if q1<>q2 then
  626. begin
  627. write('I/O of ');dumpqword(q1);writeln(' failed');
  628. do_error(2101);
  629. end;
  630. end;
  631. end;
  632. procedure teststringqword;
  633. var
  634. q1,q2 : qword;
  635. s : string;
  636. l : longint;
  637. a : ansistring;
  638. code : integer;
  639. begin
  640. { testing str: shortstring }
  641. // simple tests
  642. q1:=1;
  643. str(q1,s);
  644. if s<>'1' then
  645. do_error(2200);
  646. // simple tests
  647. q1:=0;
  648. str(q1,s);
  649. if s<>'0' then
  650. do_error(2201);
  651. // more complex tests
  652. q1:=4321;
  653. str(q1,s);
  654. if s<>'4321' then
  655. do_error(2202);
  656. str(q1:6,s);
  657. if s<>' 4321' then
  658. do_error(2203);
  659. // create a big qword:
  660. q2:=1234;
  661. l:=1000000000;
  662. q2:=q2*l;
  663. l:=54321;
  664. q2:=q2+l;
  665. str(q2,s);
  666. if s<>'1234000054321' then
  667. do_error(2204);
  668. { testing str: ansistring }
  669. // more complex tests
  670. q1:=4321;
  671. str(q1,a);
  672. if a<>'4321' then
  673. do_error(2205);
  674. str(q1:6,a);
  675. if a<>' 4321' then
  676. do_error(2206);
  677. // create a big qword:
  678. q2:=1234;
  679. l:=1000000000;
  680. q2:=q2*l;
  681. l:=54321;
  682. q2:=q2+l;
  683. str(q2,a);
  684. if a<>'1234000054321' then
  685. do_error(2207);
  686. { testing val for qword }
  687. assignqword($ffffffff,$ffffffff,q1);
  688. s:='18446744073709551615';
  689. a:=s;
  690. val(s,q2,code);
  691. if code<>0 then
  692. do_error(2208);
  693. if q1<>q2 then
  694. do_error(2209);
  695. val(a,q2,code);
  696. if code<>0 then
  697. do_error(2210);
  698. if q1<>q2 then
  699. do_error(2211);
  700. s:='18446744073709551616';
  701. val(s,q2,code);
  702. if code=0 then
  703. do_error(2212);
  704. end;
  705. procedure testmodqword;
  706. var
  707. q0,q1,q2,q3,q4,q5,q6 : qword;
  708. i : longint;
  709. begin
  710. assignqword(0,0,q0);
  711. assignqword(0,3,q1);
  712. assignqword(0,5,q2);
  713. assignqword(0,2,q3);
  714. assignqword(0,4,q4);
  715. assignqword(0,1,q5);
  716. assignqword($ffff,$12344321,q6);
  717. { to some trivial tests }
  718. { to test the code generation }
  719. if q2 mod q1<>q3 then
  720. do_error(2300);
  721. if q2 mod q1 mod q3<>q0 then
  722. do_error(2301);
  723. if q2 mod (q1 mod q3)<>q0 then
  724. do_error(2302);
  725. if (q1 mod q3) mod q2<>q5 then
  726. do_error(2303);
  727. if q1 mod q2<>q1 then
  728. do_error(2308);
  729. { a more complex expression }
  730. if (q2 mod q4) mod (q1 mod q3)<>(q1 mod q3) mod (q2 mod q4) then
  731. do_error(2304);
  732. { now test the modulo division procedure with random bit patterns }
  733. writeln('Doing some random module divisions, takes a few seconds');
  734. writeln('.................100%');
  735. for i:=1 to 100000 do
  736. begin
  737. tqwordrec(q1).high:=random($7ffffffe);
  738. tqwordrec(q1).low:=random($7ffffffe);
  739. tqwordrec(q2).high:=random($7ffffffe);
  740. tqwordrec(q2).low:=random($7ffffffe);
  741. { avoid division by zero }
  742. if (tqwordrec(q2).low or tqwordrec(q2).high)=0 then
  743. tqwordrec(q2).low:=1;
  744. q3:=q1 mod q2;
  745. if (q1-q3) mod q2<>q0 then
  746. begin
  747. write('Modulo division of ');
  748. dumpqword(q1);
  749. write(' by ');
  750. dumpqword(q2);
  751. writeln(' failed');
  752. do_error(2306);
  753. end;
  754. if i mod 10000=0 then
  755. write('.');
  756. end;
  757. for i:=1 to 100000 do
  758. begin
  759. tqwordrec(q1).high:=random($7ffffffe);
  760. tqwordrec(q1).low:=random($7ffffffe);
  761. tqwordrec(q2).high:=0;
  762. tqwordrec(q2).low:=random($7ffffffe);
  763. { avoid division by zero }
  764. if tqwordrec(q2).low=0 then
  765. tqwordrec(q2).low:=1;
  766. { get a restless division }
  767. q3:=q1 mod q2;
  768. if (q1-q3) mod q2<>q0 then
  769. begin
  770. write('Modulo division of ');
  771. dumpqword(q1);
  772. write(' by ');
  773. dumpqword(q2);
  774. writeln(' failed');
  775. do_error(2307);
  776. end;
  777. if i mod 10000=0 then
  778. write('.');
  779. end;
  780. writeln(' OK');
  781. end;
  782. const
  783. constqword : qword = 131975;
  784. procedure testconstassignqword;
  785. var
  786. q1,q2,q3 : qword;
  787. begin
  788. // constant assignments
  789. assignqword(0,5,q2);
  790. q1:=5;
  791. if q1<>q2 then
  792. do_error(2400);
  793. // constants in expressions
  794. q1:=1234;
  795. if q1<>1234 then
  796. do_error(2401);
  797. // typed constants
  798. assignqword(0,131975,q1);
  799. q2:=131975;
  800. if q1<>q2 then
  801. do_error(2402);
  802. //!!!!! large constants are still missed
  803. end;
  804. {$Q+}
  805. procedure testreqword;
  806. var
  807. q0,q1,q2,q3 : qword;
  808. begin
  809. q0:=0;
  810. assignqword($ffffffff,$ffffffff,q1);
  811. q2:=1;
  812. // addition
  813. try
  814. // expect an exception
  815. q3:=q1+q2;
  816. do_error(2500);
  817. except
  818. on eintoverflow do
  819. ;
  820. else
  821. do_error(2501);
  822. end;
  823. // subtraction
  824. try
  825. q3:=q0-q2;
  826. do_error(2502);
  827. except
  828. on eintoverflow do
  829. ;
  830. else
  831. do_error(2503);
  832. end;
  833. // multiplication
  834. q2:=2;
  835. try
  836. q3:=q2*q1;
  837. do_error(2504);
  838. except
  839. on eintoverflow do
  840. ;
  841. else
  842. do_error(2505);
  843. end;
  844. // division
  845. try
  846. q3:=q1 div q0;
  847. do_error(2506);
  848. except
  849. on edivbyzero do
  850. ;
  851. else
  852. do_error(2507);
  853. end;
  854. // modulo division
  855. try
  856. q3:=q1 mod q0;
  857. do_error(2508);
  858. except
  859. on edivbyzero do
  860. ;
  861. else
  862. do_error(2509);
  863. end;
  864. {$Q-}
  865. // now we do the same operations but without overflow
  866. // checking -> we should get no exceptions
  867. q2:=1;
  868. // addition
  869. try
  870. q3:=q1+q2;
  871. except
  872. do_error(2510);
  873. end;
  874. // subtraction
  875. try
  876. q3:=q0-q2;
  877. except
  878. do_error(2511);
  879. end;
  880. // multiplication
  881. q2:=2;
  882. try
  883. q3:=q2*q1;
  884. except
  885. do_error(2512);
  886. end;
  887. end;
  888. procedure testintqword;
  889. var
  890. q1,q2,q3 : qword;
  891. begin
  892. // lo/hi
  893. assignqword($fafafafa,$03030303,q1);
  894. if lo(q1)<>$03030303 then
  895. do_error(2600);
  896. if hi(q1)<>$fafafafa then
  897. do_error(2601);
  898. if lo(q1+1)<>$03030304 then
  899. do_error(2602);
  900. if hi(q1+$f0000000)<>$fafafafa then
  901. do_error(2603);
  902. // swap
  903. assignqword($03030303,$fafafafa,q2);
  904. if swap(q1)<>q2 then
  905. do_error(2604);
  906. // succ/pred
  907. assignqword(0,$1,q1);
  908. q3:=q1;
  909. q1:=succ(q1);
  910. q1:=succ(q1+1);
  911. q2:=pred(q1-1);
  912. q2:=pred(q2);
  913. if q3<>q2 then
  914. do_error(2605);
  915. assignqword(0,$ffffffff,q1);
  916. q3:=q1;
  917. q1:=succ(q1);
  918. q1:=succ(q1+1);
  919. q2:=pred(q1-1);
  920. q2:=pred(q2);
  921. if q3<>q2 then
  922. do_error(2606);
  923. end;
  924. procedure testcritical;
  925. var
  926. a : array[0..10,0..10,0..10] of qword;
  927. i,j,k : longint;
  928. d1,d2 : extended;
  929. q1,q2 : qword;
  930. i1,i2 : int64;
  931. begin
  932. i:=1;
  933. j:=3;
  934. k:=5;
  935. { check if it is handled correct if a register is used }
  936. { in a reference as well as temp. reg }
  937. a[i,j,k]:=1234;
  938. a[i,j,k]:=a[i,j,k]+a[i,j,k];
  939. if a[i,j,k]<>2468 then
  940. do_error(2700);
  941. if not(not(a[i,j,k]))<>a[i,j,k] then
  942. do_error(2701);
  943. if -(-(a[i,j,k]))<>a[i,j,k] then
  944. do_error(2702);
  945. if (a[i,j,k] shl (i-i))<>a[i,j,k] then
  946. do_error(2703);
  947. q1:=10;
  948. q2:=100;
  949. i1:=1000;
  950. i2:=10000;
  951. d1:=q1/q2;
  952. d2:=i1/i2;
  953. if (d1<>d2) then
  954. do_error(2704);
  955. end;
  956. var
  957. q : qword;
  958. begin
  959. randomize;
  960. writeln('------------------------------------------------------');
  961. writeln(' QWord test ');
  962. writeln('------------------------------------------------------');
  963. writeln;
  964. writeln('Testing assignqword and dumpqword ... ');
  965. assignqword($12345678,$9ABCDEF0,q);
  966. dumpqword(q);
  967. writeln;
  968. writeln('The output should be:');
  969. writeln('$12345678 9ABCDEF0');
  970. writeln;
  971. writeln('Testing simple QWord comparisations');
  972. simpletestcmpqword;
  973. writeln('Testing simple QWord comparisations was successful');
  974. writeln;
  975. writeln('Testing QWord additions');
  976. testaddqword;
  977. writeln('Testing QWord additions was successful');
  978. writeln;
  979. writeln('Testing more QWord comparisations');
  980. testcmpqword;
  981. writeln('Testing more QWord comparisations was successful');
  982. writeln;
  983. writeln('Testing QWord subtraction');
  984. testsubqword;
  985. writeln('Testing QWord subtraction was successful');
  986. writeln;
  987. writeln('Testing QWord constants');
  988. testconstassignqword;
  989. writeln('Testing QWord constants was successful');
  990. writeln;
  991. writeln('Testing QWord logical operators (or,xor,and)');
  992. testlogqword;
  993. writeln('Testing QWord logical operators (or,xor,and) was successful');
  994. writeln;
  995. writeln('Testing QWord logical not operator');
  996. testnotqword;
  997. writeln('Testing QWord logical not operator was successful');
  998. writeln;
  999. writeln('Testing QWord logical - operator');
  1000. testnegqword;
  1001. writeln('Testing QWord logical - operator was successful');
  1002. writeln;
  1003. writeln('Testing QWord logical shift operators (shr,shr)');
  1004. testshlshrqword;
  1005. writeln('Testing QWord logical shift operators (shr,shr) was successful');
  1006. writeln;
  1007. writeln('Testing QWord function results');
  1008. testfuncqword;
  1009. writeln('Testing QWord function results was successful');
  1010. writeln;
  1011. writeln('Testing QWord type casts');
  1012. testtypecastqword;
  1013. writeln('Testing QWord type casts was successful');
  1014. writeln;
  1015. writeln('Testing QWord internal procedures');
  1016. testintqword;
  1017. writeln('Testing QWord internal procedures was successful');
  1018. writeln;
  1019. writeln('Testing QWord multiplications');
  1020. testmulqword;
  1021. writeln('Testing QWord multiplications was successful');
  1022. writeln;
  1023. writeln('Testing QWord division');
  1024. testdivqword;
  1025. writeln('Testing QWord division was successful');
  1026. writeln;
  1027. writeln('Testing QWord modulo division');
  1028. testmodqword;
  1029. writeln('Testing QWord modulo division was successful');
  1030. writeln;
  1031. writeln('Testing QWord runtime errors');
  1032. testreqword;
  1033. writeln('Testing QWord runtime errors was successful');
  1034. writeln;
  1035. writeln('Testing QWord string conversion');
  1036. teststringqword;
  1037. writeln('Testing QWord string conversion was successful');
  1038. writeln;
  1039. writeln('Testing QWord input/output');
  1040. testioqword;
  1041. writeln('Testing QWord input/output was successful');
  1042. writeln;
  1043. writeln('Some extra tests for critical things');
  1044. testcritical;
  1045. writeln('Extra tests for critical things were successful');
  1046. writeln('------------------------------------------------------');
  1047. writeln(' QWord test successful');
  1048. writeln('------------------------------------------------------');
  1049. writeln;
  1050. writeln('------------------------------------------------------');
  1051. writeln(' Int64 test ');
  1052. writeln('------------------------------------------------------');
  1053. writeln;
  1054. writeln('------------------------------------------------------');
  1055. writeln(' Int64 test successful');
  1056. writeln('------------------------------------------------------');
  1057. halt(0);
  1058. end.