testi642.pp 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  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. begin
  639. { testing str: shortstring }
  640. // simple tests
  641. q1:=1;
  642. str(q1,s);
  643. if s<>'1' then
  644. do_error(2200);
  645. // simple tests
  646. q1:=0;
  647. str(q1,s);
  648. if s<>'0' then
  649. do_error(2201);
  650. // more complex tests
  651. q1:=4321;
  652. str(q1,s);
  653. if s<>'4321' then
  654. do_error(2202);
  655. str(q1:6,s);
  656. if s<>' 4321' then
  657. do_error(2203);
  658. // create a big qword:
  659. q2:=1234;
  660. l:=1000000000;
  661. q2:=q2*l;
  662. l:=54321;
  663. q2:=q2+l;
  664. str(q2,s);
  665. if s<>'1234000054321' then
  666. do_error(2204);
  667. { testing str: ansistring }
  668. // more complex tests
  669. q1:=4321;
  670. str(q1,a);
  671. if a<>'4321' then
  672. do_error(2205);
  673. str(q1:6,a);
  674. if a<>' 4321' then
  675. do_error(2206);
  676. // create a big qword:
  677. q2:=1234;
  678. l:=1000000000;
  679. q2:=q2*l;
  680. l:=54321;
  681. q2:=q2+l;
  682. str(q2,a);
  683. if a<>'1234000054321' then
  684. do_error(2207);
  685. { testing val }
  686. { !!!!!!! }
  687. end;
  688. procedure testmodqword;
  689. var
  690. q0,q1,q2,q3,q4,q5,q6 : qword;
  691. i : longint;
  692. begin
  693. assignqword(0,0,q0);
  694. assignqword(0,3,q1);
  695. assignqword(0,5,q2);
  696. assignqword(0,2,q3);
  697. assignqword(0,4,q4);
  698. assignqword(0,1,q5);
  699. assignqword($ffff,$12344321,q6);
  700. { to some trivial tests }
  701. { to test the code generation }
  702. if q2 mod q1<>q3 then
  703. do_error(2300);
  704. if q2 mod q1 mod q3<>q0 then
  705. do_error(2301);
  706. if q2 mod (q1 mod q3)<>q0 then
  707. do_error(2302);
  708. if (q1 mod q3) mod q2<>q5 then
  709. do_error(2303);
  710. if q1 mod q2<>q1 then
  711. do_error(2308);
  712. { a more complex expression }
  713. if (q2 mod q4) mod (q1 mod q3)<>(q1 mod q3) mod (q2 mod q4) then
  714. do_error(2304);
  715. { now test the modulo division procedure with random bit patterns }
  716. writeln('Doing some random module divisions, takes a few seconds');
  717. writeln('.................100%');
  718. for i:=1 to 100000 do
  719. begin
  720. tqwordrec(q1).high:=random($7ffffffe);
  721. tqwordrec(q1).low:=random($7ffffffe);
  722. tqwordrec(q2).high:=random($7ffffffe);
  723. tqwordrec(q2).low:=random($7ffffffe);
  724. { avoid division by zero }
  725. if (tqwordrec(q2).low or tqwordrec(q2).high)=0 then
  726. tqwordrec(q2).low:=1;
  727. q3:=q1 mod q2;
  728. if (q1-q3) mod q2<>q0 then
  729. begin
  730. write('Modulo division of ');
  731. dumpqword(q1);
  732. write(' by ');
  733. dumpqword(q2);
  734. writeln(' failed');
  735. do_error(2306);
  736. end;
  737. if i mod 10000=0 then
  738. write('.');
  739. end;
  740. for i:=1 to 100000 do
  741. begin
  742. tqwordrec(q1).high:=random($7ffffffe);
  743. tqwordrec(q1).low:=random($7ffffffe);
  744. tqwordrec(q2).high:=0;
  745. tqwordrec(q2).low:=random($7ffffffe);
  746. { avoid division by zero }
  747. if tqwordrec(q2).low=0 then
  748. tqwordrec(q2).low:=1;
  749. { get a restless division }
  750. q3:=q1 mod q2;
  751. if (q1-q3) mod q2<>q0 then
  752. begin
  753. write('Modulo division of ');
  754. dumpqword(q1);
  755. write(' by ');
  756. dumpqword(q2);
  757. writeln(' failed');
  758. do_error(2307);
  759. end;
  760. if i mod 10000=0 then
  761. write('.');
  762. end;
  763. writeln(' OK');
  764. end;
  765. const
  766. constqword : qword = 131975;
  767. procedure testconstassignqword;
  768. var
  769. q1,q2,q3 : qword;
  770. begin
  771. // constant assignments
  772. assignqword(0,5,q2);
  773. q1:=5;
  774. if q1<>q2 then
  775. do_error(2400);
  776. // constants in expressions
  777. q1:=1234;
  778. if q1<>1234 then
  779. do_error(2401);
  780. // typed constants
  781. assignqword(0,131975,q1);
  782. q2:=131975;
  783. if q1<>q2 then
  784. do_error(2402);
  785. //!!!!! large constants are still missed
  786. end;
  787. {$Q+}
  788. procedure testreqword;
  789. var
  790. q0,q1,q2,q3 : qword;
  791. begin
  792. q0:=0;
  793. assignqword($ffffffff,$ffffffff,q1);
  794. q2:=1;
  795. // addition
  796. try
  797. // expect an exception
  798. q3:=q1+q2;
  799. do_error(2500);
  800. except
  801. on eintoverflow do
  802. ;
  803. else
  804. do_error(2501);
  805. end;
  806. // subtraction
  807. try
  808. q3:=q0-q2;
  809. do_error(2502);
  810. except
  811. on eintoverflow do
  812. ;
  813. else
  814. do_error(2503);
  815. end;
  816. // multiplication
  817. q2:=2;
  818. try
  819. q3:=q2*q1;
  820. do_error(2504);
  821. except
  822. on eintoverflow do
  823. ;
  824. else
  825. do_error(2505);
  826. end;
  827. // division
  828. try
  829. q3:=q1 div q0;
  830. do_error(2506);
  831. except
  832. on edivbyzero do
  833. ;
  834. else
  835. do_error(2507);
  836. end;
  837. // modulo division
  838. try
  839. q3:=q1 mod q0;
  840. do_error(2508);
  841. except
  842. on edivbyzero do
  843. ;
  844. else
  845. do_error(2509);
  846. end;
  847. {$Q-}
  848. // now we do the same operations but without overflow
  849. // checking -> we should get no exceptions
  850. q2:=1;
  851. // addition
  852. try
  853. q3:=q1+q2;
  854. except
  855. do_error(2510);
  856. end;
  857. // subtraction
  858. try
  859. q3:=q0-q2;
  860. except
  861. do_error(2511);
  862. end;
  863. // multiplication
  864. q2:=2;
  865. try
  866. q3:=q2*q1;
  867. except
  868. do_error(2512);
  869. end;
  870. end;
  871. procedure testintqword;
  872. var
  873. q1,q2,q3 : qword;
  874. begin
  875. // lo/hi
  876. assignqword($fafafafa,$03030303,q1);
  877. if lo(q1)<>$03030303 then
  878. do_error(2600);
  879. if hi(q1)<>$fafafafa then
  880. do_error(2601);
  881. if lo(q1+1)<>$03030304 then
  882. do_error(2602);
  883. if hi(q1+$f0000000)<>$fafafafa then
  884. do_error(2603);
  885. // swap
  886. assignqword($03030303,$fafafafa,q2);
  887. if swap(q1)<>q2 then
  888. do_error(2604);
  889. // succ/pred
  890. assignqword(0,$1,q1);
  891. q3:=q1;
  892. q1:=succ(q1);
  893. q1:=succ(q1+1);
  894. q2:=pred(q1-1);
  895. q2:=pred(q2);
  896. if q3<>q2 then
  897. do_error(2605);
  898. assignqword(0,$ffffffff,q1);
  899. q3:=q1;
  900. q1:=succ(q1);
  901. q1:=succ(q1+1);
  902. q2:=pred(q1-1);
  903. q2:=pred(q2);
  904. if q3<>q2 then
  905. do_error(2606);
  906. end;
  907. procedure testcritical;
  908. var
  909. a : array[0..10,0..10,0..10] of qword;
  910. i,j,k : longint;
  911. d1,d2 : extended;
  912. q1,q2 : qword;
  913. i1,i2 : int64;
  914. begin
  915. i:=1;
  916. j:=3;
  917. k:=5;
  918. { check if it is handled correct if a register is used }
  919. { in a reference as well as temp. reg }
  920. a[i,j,k]:=1234;
  921. a[i,j,k]:=a[i,j,k]+a[i,j,k];
  922. if a[i,j,k]<>2468 then
  923. do_error(2700);
  924. if not(not(a[i,j,k]))<>a[i,j,k] then
  925. do_error(2701);
  926. if -(-(a[i,j,k]))<>a[i,j,k] then
  927. do_error(2702);
  928. if (a[i,j,k] shl (i-i))<>a[i,j,k] then
  929. do_error(2703);
  930. q1:=10;
  931. q2:=100;
  932. i1:=1000;
  933. i2:=10000;
  934. d1:=q1/q2;
  935. d2:=i1/i2;
  936. if (d1<>d2) then
  937. do_error(2704);
  938. end;
  939. var
  940. q : qword;
  941. begin
  942. randomize;
  943. writeln('------------------------------------------------------');
  944. writeln(' QWord test ');
  945. writeln('------------------------------------------------------');
  946. writeln;
  947. writeln('Testing assignqword and dumpqword ... ');
  948. assignqword($12345678,$9ABCDEF0,q);
  949. dumpqword(q);
  950. writeln;
  951. writeln('The output should be:');
  952. writeln('$12345678 9ABCDEF0');
  953. writeln;
  954. writeln('Testing simple QWord comparisations');
  955. simpletestcmpqword;
  956. writeln('Testing simple QWord comparisations was successful');
  957. writeln;
  958. writeln('Testing QWord additions');
  959. testaddqword;
  960. writeln('Testing QWord additions was successful');
  961. writeln;
  962. writeln('Testing more QWord comparisations');
  963. testcmpqword;
  964. writeln('Testing more QWord comparisations was successful');
  965. writeln;
  966. writeln('Testing QWord subtraction');
  967. testsubqword;
  968. writeln('Testing QWord subtraction was successful');
  969. writeln;
  970. writeln('Testing QWord constants');
  971. testconstassignqword;
  972. writeln('Testing QWord constants was successful');
  973. writeln;
  974. writeln('Testing QWord logical operators (or,xor,and)');
  975. testlogqword;
  976. writeln('Testing QWord logical operators (or,xor,and) was successful');
  977. writeln;
  978. writeln('Testing QWord logical not operator');
  979. testnotqword;
  980. writeln('Testing QWord logical not operator was successful');
  981. writeln;
  982. writeln('Testing QWord logical - operator');
  983. testnegqword;
  984. writeln('Testing QWord logical - operator was successful');
  985. writeln;
  986. writeln('Testing QWord logical shift operators (shr,shr)');
  987. testshlshrqword;
  988. writeln('Testing QWord logical shift operators (shr,shr) was successful');
  989. writeln;
  990. writeln('Testing QWord function results');
  991. testfuncqword;
  992. writeln('Testing QWord function results was successful');
  993. writeln;
  994. writeln('Testing QWord type casts');
  995. testtypecastqword;
  996. writeln('Testing QWord type casts was successful');
  997. writeln;
  998. writeln('Testing QWord internal procedures');
  999. testintqword;
  1000. writeln('Testing QWord internal procedures was successful');
  1001. writeln;
  1002. writeln('Testing QWord multiplications');
  1003. testmulqword;
  1004. writeln('Testing QWord multiplications was successful');
  1005. writeln;
  1006. writeln('Testing QWord division');
  1007. testdivqword;
  1008. writeln('Testing QWord division was successful');
  1009. writeln;
  1010. writeln('Testing QWord modulo division');
  1011. testmodqword;
  1012. writeln('Testing QWord modulo division was successful');
  1013. writeln;
  1014. writeln('Testing QWord runtime errors');
  1015. testreqword;
  1016. writeln('Testing QWord runtime errors was successful');
  1017. writeln;
  1018. writeln('Testing QWord string conversion');
  1019. teststringqword;
  1020. writeln('Testing QWord string conversion was successful');
  1021. writeln;
  1022. writeln('Testing QWord input/output');
  1023. testioqword;
  1024. writeln('Testing QWord input/output was successful');
  1025. writeln;
  1026. writeln('Some extra tests for critical things');
  1027. testcritical;
  1028. writeln('Extra tests for critical things were successful');
  1029. writeln('------------------------------------------------------');
  1030. writeln(' QWord test successful');
  1031. writeln('------------------------------------------------------');
  1032. writeln;
  1033. writeln('------------------------------------------------------');
  1034. writeln(' Int64 test ');
  1035. writeln('------------------------------------------------------');
  1036. writeln;
  1037. writeln('------------------------------------------------------');
  1038. writeln(' Int64 test successful');
  1039. writeln('------------------------------------------------------');
  1040. halt(0);
  1041. end.