testi642.pp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  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 testnegqword;
  315. var
  316. q0,q1,q2,q3,q4 : qword;
  317. begin
  318. assignqword($1,$0,q1);
  319. assignqword($0,1234,q2);
  320. if -q1<>(0-q1) then
  321. do_error(2700);
  322. if -q2<>(0-q2) then
  323. do_error(2701);
  324. if -(q1+q2)<>(0-(q1+q2)) then
  325. do_error(2702);
  326. end;
  327. procedure testmulqword;
  328. var
  329. q0,q1,q2,q3,q4,q5,q6 : qword;
  330. i : longint;
  331. begin
  332. assignqword(0,0,q0);
  333. assignqword(0,1,q1);
  334. assignqword(0,4,q2);
  335. assignqword(2,0,q3);
  336. assignqword(8,0,q4);
  337. assignqword(0,1,q5);
  338. assignqword($ffff,$12344321,q6);
  339. { to some trivial tests }
  340. { to test the code generation }
  341. if q1*q2<>q2 then
  342. do_error(1800);
  343. if q1*q2*q3<>q4 then
  344. do_error(1801);
  345. if q1*(q2*q3)<>q4 then
  346. do_error(1802);
  347. if (q1*q2)*q3<>q4 then
  348. do_error(1803);
  349. if (q6*q5)*(q1*q2)<>q1*q2*q5*q6 then
  350. do_error(1804);
  351. { a more complex expression }
  352. if ((((q1*q5)*(q1*q5))*((q5*q1)*(q1*q5)))*q5*q1*q5)<>q1 then
  353. do_error(1805);
  354. { now test the multiplication procedure with random bit patterns }
  355. writeln('Doing some random multiplications, takes a few seconds');
  356. writeln('.....................................100%');
  357. for i:=1 to 1000000 do
  358. begin
  359. tqwordrec(q1).high:=0;
  360. tqwordrec(q1).low:=random($7ffffffe);
  361. tqwordrec(q2).high:=0;
  362. tqwordrec(q2).low:=random($7ffffffe);
  363. if q1*q2<>q2*q1 then
  364. begin
  365. write('Multiplication of ');
  366. dumpqword(q1);
  367. write(' and ');
  368. dumpqword(q2);
  369. writeln(' failed');
  370. do_error(1806);
  371. end;
  372. if i mod 50000=0 then
  373. write('.');
  374. end;
  375. for i:=1 to 1000000 do
  376. begin
  377. tqwordrec(q1).high:=0;
  378. tqwordrec(q1).low:=random($7ffffffe);
  379. q1:=q1 shl 16;
  380. tqwordrec(q2).high:=0;
  381. tqwordrec(q2).low:=random($fffe);
  382. if q1*q2<>q2*q1 then
  383. begin
  384. write('Multiplication of ');
  385. dumpqword(q1);
  386. write(' and ');
  387. dumpqword(q2);
  388. writeln(' failed');
  389. do_error(1806);
  390. end;
  391. if i mod 50000=0 then
  392. write('.');
  393. end;
  394. writeln(' OK');
  395. end;
  396. procedure testdivqword;
  397. var
  398. q0,q1,q2,q3,q4,q5,q6 : qword;
  399. i : longint;
  400. begin
  401. assignqword(0,0,q0);
  402. assignqword(0,1,q1);
  403. assignqword(0,4,q2);
  404. assignqword(2,0,q3);
  405. assignqword(8,0,q4);
  406. assignqword(0,1,q5);
  407. assignqword($ffff,$12344321,q6);
  408. { to some trivial tests }
  409. { to test the code generation }
  410. if q2 div q1<>q2 then
  411. do_error(1900);
  412. if q2 div q1 div q1<>q2 then
  413. do_error(1901);
  414. if q2 div (q4 div q3)<>q1 then
  415. do_error(1902);
  416. if (q4 div q3) div q2<>q1 then
  417. do_error(1903);
  418. { a more complex expression }
  419. if (q4 div q3) div (q2 div q1)<>(q2 div q1) div (q4 div q3) then
  420. do_error(1904);
  421. { now test the division procedure with random bit patterns }
  422. writeln('Doing some random divisions, takes a few seconds');
  423. writeln('.................100%');
  424. for i:=1 to 100000 do
  425. begin
  426. tqwordrec(q1).high:=random($7ffffffe);
  427. tqwordrec(q1).low:=random($7ffffffe);
  428. tqwordrec(q2).high:=random($7ffffffe);
  429. tqwordrec(q2).low:=random($7ffffffe);
  430. { avoid division by zero }
  431. if (tqwordrec(q2).low or tqwordrec(q2).high)=0 then
  432. tqwordrec(q2).low:=1;
  433. q3:=q1 div q2;
  434. { get a restless division }
  435. q1:=q2*q3;
  436. q3:=q1 div q2;
  437. if q3*q2<>q1 then
  438. begin
  439. write('Division of ');
  440. dumpqword(q1);
  441. write(' by ');
  442. dumpqword(q2);
  443. writeln(' failed');
  444. do_error(1906);
  445. end;
  446. if i mod 10000=0 then
  447. write('.');
  448. end;
  449. for i:=1 to 100000 do
  450. begin
  451. tqwordrec(q1).high:=0;
  452. tqwordrec(q1).low:=random($7ffffffe);
  453. tqwordrec(q2).high:=0;
  454. tqwordrec(q2).low:=random($7ffffffe);
  455. { avoid division by zero }
  456. if tqwordrec(q2).low=0 then
  457. tqwordrec(q2).low:=1;
  458. { get a restless division }
  459. q3:=q1*q2;
  460. q3:=q3 div q2;
  461. if q3<>q1 then
  462. begin
  463. write('Division of ');
  464. dumpqword(q1);
  465. write(' by ');
  466. dumpqword(q2);
  467. writeln(' failed');
  468. do_error(1907);
  469. end;
  470. if i mod 10000=0 then
  471. write('.');
  472. end;
  473. writeln(' OK');
  474. end;
  475. function testf : qword;
  476. var
  477. q : qword;
  478. begin
  479. assignqword($ffffffff,$a0a0a0a0,q);
  480. testf:=q;
  481. end;
  482. procedure testfuncqword;
  483. var
  484. q : qword;
  485. begin
  486. assignqword($ffffffff,$a0a0a0a0,q);
  487. if testf<>q then
  488. do_error(1900);
  489. if q<>testf then
  490. do_error(1901);
  491. end;
  492. procedure testtypecastqword;
  493. var
  494. s1,s2 : shortint;
  495. b1,b2 : byte;
  496. w1,w2 : word;
  497. i1,i2 : integer;
  498. l1,l2 : longint;
  499. d1,d2 : dword;
  500. q1,q2 : qword;
  501. d1,d2 : double;
  502. begin
  503. { shortint }
  504. s1:=75;
  505. s2:=0;
  506. q1:=s1;
  507. { mix up the processor a little bit }
  508. q2:=q1;
  509. if q2<>75 then
  510. begin
  511. dumpqword(q2);
  512. do_error(2006);
  513. end;
  514. s2:=q2;
  515. if s1<>s2 then
  516. do_error(2000);
  517. { byte }
  518. b1:=$ca;
  519. b2:=0;
  520. q1:=b1;
  521. { mix up the processor a little bit }
  522. q2:=q1;
  523. if q2<>$ca then
  524. do_error(2007);
  525. b2:=q2;
  526. if b1<>b2 then
  527. do_error(2001);
  528. { integer }
  529. i1:=12345;
  530. i2:=0;
  531. q1:=i1;
  532. { mix up the processor a little bit }
  533. q2:=q1;
  534. if q2<>12345 then
  535. do_error(2008);
  536. i2:=q2;
  537. if i1<>i2 then
  538. do_error(2002);
  539. { word }
  540. w1:=$a0ff;
  541. w2:=0;
  542. q1:=w1;
  543. { mix up the processor a little bit }
  544. q2:=q1;
  545. if q2<>$a0ff then
  546. do_error(2009);
  547. w2:=q2;
  548. if w1<>w2 then
  549. do_error(2003);
  550. { longint }
  551. l1:=12341234;
  552. l2:=0;
  553. q1:=l1;
  554. { mix up the processor a little bit }
  555. q2:=q1;
  556. if q2<>12341234 then
  557. do_error(2010);
  558. l2:=q2;
  559. if l1<>l2 then
  560. do_error(2004);
  561. { dword }
  562. d1:=$5bcdef01;
  563. b2:=0;
  564. q1:=d1;
  565. { mix up the processor a little bit }
  566. q2:=q1;
  567. if q2<>$5bcdef01 then
  568. do_error(2011);
  569. d2:=q2;
  570. if d1<>d2 then
  571. do_error(2005);
  572. { real }
  573. { memory location }
  574. q1:=12;
  575. d1:=q1;
  576. d2:=12;
  577. if d1<>d2 then
  578. do_error(2012);
  579. { register location }
  580. q1:=12;
  581. d1:=q1+1;
  582. d2:=13;
  583. if d1<>d2 then
  584. do_error(2013);
  585. // a constant which can't be loaded with fild
  586. q1:=$80000000;
  587. q1:=q1 shl 32;
  588. d1:=q1;
  589. d2:=$80000000;
  590. if d1<>d2*d2*2.0 then
  591. do_error(20);
  592. // register location
  593. d1:=q1+1;
  594. if d1<>d2*d2*2.0+1 then
  595. do_error(2014);
  596. end;
  597. procedure testioqword;
  598. var
  599. t : text;
  600. q1,q2 : qword;
  601. i : longint;
  602. begin
  603. assignqword($ffffffff,$a0a0a0a0,q1);
  604. assign(t,'testi642.tmp');
  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. do_error(2100);
  613. { do some random tests }
  614. for i:=1 to 100 do
  615. begin
  616. tqwordrec(q1).high:=random($7ffffffe);
  617. tqwordrec(q1).low:=random($7ffffffe);
  618. rewrite(t);
  619. writeln(t,q1);
  620. close(t);
  621. reset(t);
  622. readln(t,q2);
  623. close(t);
  624. if q1<>q2 then
  625. begin
  626. write('I/O of ');dumpqword(q1);writeln(' failed');
  627. do_error(2101);
  628. end;
  629. end;
  630. end;
  631. procedure teststringqword;
  632. var
  633. q1,q2 : qword;
  634. s : string;
  635. l : longint;
  636. a : ansistring;
  637. begin
  638. { testing str: shortstring }
  639. // simple tests
  640. q1:=1;
  641. str(q1,s);
  642. if s<>'1' then
  643. do_error(2200);
  644. // simple tests
  645. q1:=0;
  646. str(q1,s);
  647. if s<>'0' then
  648. do_error(2201);
  649. // more complex tests
  650. q1:=4321;
  651. str(q1,s);
  652. if s<>'4321' then
  653. do_error(2202);
  654. str(q1:6,s);
  655. if s<>' 4321' then
  656. do_error(2203);
  657. // create a big qword:
  658. q2:=1234;
  659. l:=1000000000;
  660. q2:=q2*l;
  661. l:=54321;
  662. q2:=q2+l;
  663. str(q2,s);
  664. if s<>'1234000054321' then
  665. do_error(2204);
  666. { testing str: ansistring }
  667. // more complex tests
  668. q1:=4321;
  669. str(q1,a);
  670. if a<>'4321' then
  671. do_error(2205);
  672. str(q1:6,a);
  673. if a<>' 4321' then
  674. do_error(2206);
  675. // create a big qword:
  676. q2:=1234;
  677. l:=1000000000;
  678. q2:=q2*l;
  679. l:=54321;
  680. q2:=q2+l;
  681. str(q2,a);
  682. if a<>'1234000054321' then
  683. do_error(2207);
  684. { testing val }
  685. { !!!!!!! }
  686. end;
  687. procedure testmodqword;
  688. var
  689. q0,q1,q2,q3,q4,q5,q6 : qword;
  690. i : longint;
  691. begin
  692. assignqword(0,0,q0);
  693. assignqword(0,3,q1);
  694. assignqword(0,5,q2);
  695. assignqword(0,2,q3);
  696. assignqword(0,4,q4);
  697. assignqword(0,1,q5);
  698. assignqword($ffff,$12344321,q6);
  699. { to some trivial tests }
  700. { to test the code generation }
  701. if q2 mod q1<>q3 then
  702. do_error(2300);
  703. if q2 mod q1 mod q3<>q0 then
  704. do_error(2301);
  705. if q2 mod (q1 mod q3)<>q0 then
  706. do_error(2302);
  707. if (q1 mod q3) mod q2<>q5 then
  708. do_error(2303);
  709. { a more complex expression }
  710. if (q2 mod q4) mod (q1 mod q3)<>(q1 mod q3) mod (q2 mod q4) then
  711. do_error(2304);
  712. { now test the modulo division procedure with random bit patterns }
  713. writeln('Doing some random module divisions, takes a few seconds');
  714. writeln('.................100%');
  715. for i:=1 to 100000 do
  716. begin
  717. tqwordrec(q1).high:=random($7ffffffe);
  718. tqwordrec(q1).low:=random($7ffffffe);
  719. tqwordrec(q2).high:=random($7ffffffe);
  720. tqwordrec(q2).low:=random($7ffffffe);
  721. { avoid division by zero }
  722. if (tqwordrec(q2).low or tqwordrec(q2).high)=0 then
  723. tqwordrec(q2).low:=1;
  724. q3:=q1 mod q2;
  725. if (q1-q3) mod q2<>q0 then
  726. begin
  727. write('Modulo division of ');
  728. dumpqword(q1);
  729. write(' by ');
  730. dumpqword(q2);
  731. writeln(' failed');
  732. do_error(2306);
  733. end;
  734. if i mod 10000=0 then
  735. write('.');
  736. end;
  737. for i:=1 to 100000 do
  738. begin
  739. tqwordrec(q1).high:=random($7ffffffe);
  740. tqwordrec(q1).low:=random($7ffffffe);
  741. tqwordrec(q2).high:=0;
  742. tqwordrec(q2).low:=random($7ffffffe);
  743. { avoid division by zero }
  744. if tqwordrec(q2).low=0 then
  745. tqwordrec(q2).low:=1;
  746. { get a restless division }
  747. q3:=q1 mod q2;
  748. if (q1-q3) mod q2<>q0 then
  749. begin
  750. write('Modulo division of ');
  751. dumpqword(q1);
  752. write(' by ');
  753. dumpqword(q2);
  754. writeln(' failed');
  755. do_error(2307);
  756. end;
  757. if i mod 10000=0 then
  758. write('.');
  759. end;
  760. writeln(' OK');
  761. end;
  762. const
  763. constqword : qword = 131975;
  764. procedure testconstassignqword;
  765. var
  766. q1,q2,q3 : qword;
  767. begin
  768. // constant assignments
  769. assignqword(0,5,q2);
  770. q1:=5;
  771. if q1<>q2 then
  772. do_error(2400);
  773. // constants in expressions
  774. q1:=1234;
  775. if q1<>1234 then
  776. do_error(2401);
  777. // typed constants
  778. assignqword(0,131975,q1);
  779. q2:=131975;
  780. if q1<>q2 then
  781. do_error(2402);
  782. //!!!!! large constants are still missed
  783. end;
  784. {$Q+}
  785. procedure testreqword;
  786. var
  787. q0,q1,q2,q3 : qword;
  788. begin
  789. q0:=0;
  790. assignqword($ffffffff,$ffffffff,q1);
  791. q2:=1;
  792. // addition
  793. try
  794. // expect an exception
  795. q3:=q1+q2;
  796. do_error(2500);
  797. except
  798. on eintoverflow do
  799. ;
  800. else
  801. do_error(2501);
  802. end;
  803. // subtraction
  804. try
  805. q3:=q0-q2;
  806. do_error(2502);
  807. except
  808. on eintoverflow do
  809. ;
  810. else
  811. do_error(2503);
  812. end;
  813. // multiplication
  814. q2:=2;
  815. try
  816. q3:=q2*q1;
  817. do_error(2504);
  818. except
  819. on eintoverflow do
  820. ;
  821. else
  822. do_error(2505);
  823. end;
  824. // division
  825. try
  826. q3:=q1 div q0;
  827. do_error(2506);
  828. except
  829. on edivbyzero do
  830. ;
  831. else
  832. do_error(2507);
  833. end;
  834. // modulo division
  835. try
  836. q3:=q1 mod q0;
  837. do_error(2508);
  838. except
  839. on edivbyzero do
  840. ;
  841. else
  842. do_error(2509);
  843. end;
  844. {$Q-}
  845. // now we do the same operations but without overflow
  846. // checking -> we should get no exceptions
  847. q2:=1;
  848. // addition
  849. try
  850. q3:=q1+q2;
  851. except
  852. do_error(2510);
  853. end;
  854. // subtraction
  855. try
  856. q3:=q0-q2;
  857. except
  858. do_error(2511);
  859. end;
  860. // multiplication
  861. q2:=2;
  862. try
  863. q3:=q2*q1;
  864. except
  865. do_error(2512);
  866. end;
  867. end;
  868. procedure testintqword;
  869. var
  870. q1,q2,q3 : qword;
  871. begin
  872. // lo/hi
  873. assignqword($fafafafa,$03030303,q1);
  874. if lo(q1)<>$03030303 then
  875. do_error(2600);
  876. if hi(q1)<>$fafafafa then
  877. do_error(2601);
  878. if lo(q1+1)<>$03030304 then
  879. do_error(2602);
  880. if hi(q1+$f0000000)<>$fafafafa then
  881. do_error(2603);
  882. // swap
  883. assignqword($03030303,$fafafafa,q2);
  884. if swap(q1)<>q2 then
  885. do_error(2604);
  886. // succ/pred
  887. assignqword(0,$1,q1);
  888. q3:=q1;
  889. q1:=succ(q1);
  890. q1:=succ(q1+1);
  891. q2:=pred(q1-1);
  892. q2:=pred(q2);
  893. if q3<>q2 then
  894. do_error(2605);
  895. assignqword(0,$ffffffff,q1);
  896. q3:=q1;
  897. q1:=succ(q1);
  898. q1:=succ(q1+1);
  899. q2:=pred(q1-1);
  900. q2:=pred(q2);
  901. if q3<>q2 then
  902. do_error(2606);
  903. end;
  904. procedure testcritical;
  905. var
  906. a : array[0..10,0..10,0..10] of qword;
  907. i,j,k : longint;
  908. begin
  909. i:=1;
  910. j:=3;
  911. k:=5;
  912. { check if it is handled correct if a register is used }
  913. { in a reference as well as temp. reg }
  914. a[i,j,k]:=1234;
  915. a[i,j,k]:=a[i,j,k]+a[i,j,k];
  916. if a[i,j,k]<>2468 then
  917. do_error(2700);
  918. if not(not(a[i,j,k]))<>a[i,j,k] then
  919. do_error(2701);
  920. if -(-(a[i,j,k]))<>a[i,j,k] then
  921. do_error(2702);
  922. if (a[i,j,k] shl (i-i))<>a[i,j,k] then
  923. do_error(2703);
  924. end;
  925. var
  926. q : qword;
  927. begin
  928. randomize;
  929. writeln('------------------------------------------------------');
  930. writeln(' QWord test ');
  931. writeln('------------------------------------------------------');
  932. writeln;
  933. writeln('Testing assignqword and dumpqword ... ');
  934. assignqword($12345678,$9ABCDEF0,q);
  935. dumpqword(q);
  936. writeln;
  937. writeln('The output should be:');
  938. writeln('$12345678 9ABCDEF0');
  939. writeln;
  940. writeln('Testing simple QWord comparisations');
  941. simpletestcmpqword;
  942. writeln('Testing simple QWord comparisations was successful');
  943. writeln;
  944. writeln('Testing QWord additions');
  945. testaddqword;
  946. writeln('Testing QWord additions was successful');
  947. writeln;
  948. writeln('Testing more QWord comparisations');
  949. testcmpqword;
  950. writeln('Testing more QWord comparisations was successful');
  951. writeln;
  952. writeln('Testing QWord subtraction');
  953. testsubqword;
  954. writeln('Testing QWord subtraction was successful');
  955. writeln;
  956. writeln('Testing QWord constants');
  957. testconstassignqword;
  958. writeln('Testing QWord constants was successful');
  959. writeln;
  960. writeln('Testing QWord logical operators (or,xor,and)');
  961. testlogqword;
  962. writeln('Testing QWord logical operators (or,xor,and) was successful');
  963. writeln;
  964. writeln('Testing QWord logical not operator');
  965. testnotqword;
  966. writeln('Testing QWord logical not operator was successful');
  967. writeln;
  968. writeln('Testing QWord logical - operator');
  969. testnegqword;
  970. writeln('Testing QWord logical - operator was successful');
  971. writeln;
  972. writeln('Testing QWord logical shift operators (shr,shr)');
  973. testshlshrqword;
  974. writeln('Testing QWord logical shift operators (shr,shr) was successful');
  975. writeln;
  976. writeln('Testing QWord function results');
  977. testfuncqword;
  978. writeln('Testing QWord function results was successful');
  979. writeln;
  980. writeln('Testing QWord type casts');
  981. testtypecastqword;
  982. writeln('Testing QWord type casts was successful');
  983. writeln;
  984. writeln('Testing QWord internal procedures');
  985. testintqword;
  986. writeln('Testing QWord internal procedures was successful');
  987. writeln;
  988. writeln('Testing QWord multiplications');
  989. testmulqword;
  990. writeln('Testing QWord multiplications was successful');
  991. writeln;
  992. writeln('Testing QWord division');
  993. testdivqword;
  994. writeln('Testing QWord division was successful');
  995. writeln;
  996. writeln('Testing QWord modulo division');
  997. testmodqword;
  998. writeln('Testing QWord modulo division was successful');
  999. writeln;
  1000. writeln('Testing QWord runtime errors');
  1001. testreqword;
  1002. writeln('Testing QWord runtime errors was successful');
  1003. writeln;
  1004. writeln('Testing QWord string conversion');
  1005. teststringqword;
  1006. writeln('Testing QWord string conversion was successful');
  1007. writeln;
  1008. writeln('Testing QWord input/output');
  1009. testioqword;
  1010. writeln('Testing QWord input/output was successful');
  1011. writeln;
  1012. writeln('Some extra tests for critical things');
  1013. testcritical;
  1014. writeln('Extra tests for critical things were successful');
  1015. writeln('------------------------------------------------------');
  1016. writeln(' QWord test successful');
  1017. writeln('------------------------------------------------------');
  1018. writeln;
  1019. writeln('------------------------------------------------------');
  1020. writeln(' Int64 test ');
  1021. writeln('------------------------------------------------------');
  1022. writeln;
  1023. writeln('------------------------------------------------------');
  1024. writeln(' Int64 test successful');
  1025. writeln('------------------------------------------------------');
  1026. halt(0);
  1027. end.