tint642.pp 27 KB

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