testi642.pp 24 KB

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