tint642.pp 27 KB

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