taddset2.pp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. { %cpu=i386 }
  2. {****************************************************************}
  3. { CODE GENERATOR TEST PROGRAM }
  4. {****************************************************************}
  5. { NODE TESTED : secondadd() }
  6. {****************************************************************}
  7. { PRE-REQUISITES: secondload() }
  8. { secondassign() }
  9. { secondsetelement() }
  10. {****************************************************************}
  11. { DEFINES: }
  12. { FPC = Target is FreePascal compiler }
  13. {****************************************************************}
  14. { REMARKS: }
  15. { This test uses MMX instructions }
  16. { }
  17. { }
  18. {****************************************************************}
  19. Program tneg;
  20. {$mmx+}
  21. var
  22. Err : boolean;
  23. type
  24. { DO NOT CHANGE THE VALUES OF THESE ENUMERATIONS! }
  25. tsmallenum = (dA,dB,dC,dd,de,df,dg,dh,di,dj,dk,dl,dm,dn,dop,dp,dq,dr);
  26. tasmop = (A_ABCD,
  27. A_ADD,A_ADDA,A_ADDI,A_ADDQ,A_ADDX,A_AND,A_ANDI,
  28. A_ASL,A_ASR,A_BCC,A_BCS,A_BEQ,A_BGE,A_BGT,A_BHI,
  29. A_BLE,A_BLS,A_BLT,A_BMI,A_BNE,A_BPL,A_BVC,A_BVS,
  30. A_BCHG,A_BCLR,A_BRA,A_BSET,A_BSR,A_BTST,A_CHK,
  31. A_CLR,A_CMP,A_CMPA,A_CMPI,A_CMPM,A_DBCC,A_DBCS,A_DBEQ,A_DBGE,
  32. A_DBGT,A_DBHI,A_DBLE,A_DBLS,A_DBLT,A_DBMI,A_DBNE,A_DBRA,
  33. A_DBPL,A_DBT,A_DBVC,A_DBVS,A_DBF,A_DIVS,A_DIVU,
  34. A_EOR,A_EORI,A_EXG,A_ILLEGAL,A_EXT,A_JMP,A_JSR,
  35. A_LEA,A_LINK,A_LSL,A_LSR,A_MOVE,A_MOVEA,A_MOVEI,A_MOVEQ,
  36. A_MOVEM,A_MOVEP,A_MULS,A_MULU,A_NBCD,A_NEG,A_NEGX,
  37. A_NOP,A_NOT,A_OR,A_ORI,A_PEA,A_ROL,A_ROR,A_ROXL,
  38. A_ROXR,A_RTR,A_RTS,A_SBCD,A_SCC,A_SCS,A_SEQ,A_SGE,
  39. A_SGT,A_SHI,A_SLE,A_SLS,A_SLT,A_SMI,A_SNE,
  40. A_SPL,A_ST,A_SVC,A_SVS,A_SF,A_SUB,A_SUBA,A_SUBI,A_SUBQ,
  41. A_SUBX,A_SWAP,A_TAS,A_TRAP,A_TRAPV,A_TST,A_UNLK,
  42. A_RTE,A_RESET,A_STOP,
  43. { MC68010 instructions }
  44. A_BKPT,A_MOVEC,A_MOVES,A_RTD,
  45. { MC68020 instructions }
  46. A_BFCHG,A_BFCLR,A_BFEXTS,A_BFEXTU,A_BFFFO,
  47. A_BFINS,A_BFSET,A_BFTST,A_CALLM,A_CAS,A_CAS2,
  48. A_CHK2,A_CMP2,A_DIVSL,A_DIVUL,A_EXTB,A_PACK,A_RTM,
  49. A_TRAPCC,A_TRACS,A_TRAPEQ,A_TRAPF,A_TRAPGE,A_TRAPGT,
  50. A_TRAPHI,A_TRAPLE,A_TRAPLS,A_TRAPLT,A_TRAPMI,A_TRAPNE,
  51. A_TRAPPL,A_TRAPT,A_TRAPVC,A_TRAPVS,A_UNPK,
  52. { FPU Processor instructions - directly supported only. }
  53. { IEEE aware and misc. condition codes not supported }
  54. A_FABS,A_FADD,
  55. A_FBEQ,A_FBNE,A_FBNGT,A_FBGT,A_FBGE,A_FBNGE,
  56. A_FBLT,A_FBNLT,A_FBLE,A_FBGL,A_FBNGL,A_FBGLE,A_FBNGLE,
  57. A_FDBEQ,A_FDBNE,A_FDBGT,A_FDBNGT,A_FDBGE,A_FDBNGE,
  58. A_FDBLT,A_FDBNLT,A_FDBLE,A_FDBGL,A_FDBNGL,A_FDBGLE,A_FBDNGLE,
  59. A_FSEQ,A_FSNE,A_FSGT,A_FSNGT,A_FSGE,A_FSNGE,
  60. A_FSLT,A_FSNLT,A_FSLE,A_FSGL,A_FSNGL,A_FSGLE,A_FSNGLE,
  61. A_FCMP,A_FDIV,A_FMOVE,A_FMOVEM,
  62. A_FMUL,A_FNEG,A_FNOP,A_FSQRT,A_FSUB,A_FSGLDIV,
  63. A_FSFLMUL,A_FTST,
  64. A_FTRAPEQ,A_FTRAPNE,A_FTRAPGT,A_FTRAPNGT,A_FTRAPGE,A_FTRAPNGE,
  65. A_FTRAPLT,A_FTRAPNLT,A_FTRAPLE,A_FTRAPGL,A_FTRAPNGL,A_FTRAPGLE,A_FTRAPNGLE,
  66. { Protected instructions }
  67. A_CPRESTORE,A_CPSAVE,
  68. { FPU Unit protected instructions }
  69. { and 68030/68851 common MMU instructions }
  70. { (this may include 68040 MMU instructions) }
  71. A_FRESTORE,A_FSAVE,A_PFLUSH,A_PFLUSHA,A_PLOAD,A_PMOVE,A_PTEST,
  72. { Useful for assembly langage output }
  73. A_LABEL,A_NONE);
  74. type
  75. topset = set of tasmop;
  76. tsmallset = set of tsmallenum;
  77. const
  78. { NORMAL SETS }
  79. constset1 : array[1..3] of topset =
  80. (
  81. { 66 } { 210 } { 225 }
  82. ([A_MOVE, { 66 : LONG 2 - BIT 2 }
  83. A_FTST, { 210 : LONG 6 - BIT 18 }
  84. A_CPSAVE]),{ 225 : LONG 7 - BIT 1 }
  85. { 1..8 }
  86. ([A_ADD..A_ASL]),
  87. { 134 }
  88. ([A_CHK2])
  89. );
  90. constset2 : array[1..3] of topset =
  91. (
  92. ([A_MOVE,A_FTST,A_CPSAVE]),
  93. ([A_ADD..A_ASL]),
  94. ([A_CHK2])
  95. );
  96. { SMALL SETS }
  97. constset3 : array[1..3] of tsmallset =
  98. (
  99. ([DA, { 0 : LONG 0 : bit 0 }
  100. DD, { 3 : LONG 0 : bit 3 }
  101. DM]), { 12 : LONG 0 : bit 12 }
  102. ([DB..DI]), { 1..8 : LONG 0 : bits 1-8 }
  103. ([DR]) { 17 : LONG 0 : bit 17 }
  104. );
  105. constset4 : array[1..3] of tsmallset =
  106. (
  107. ([DA,DD,DM]),
  108. ([DB..DI]),
  109. ([DR])
  110. );
  111. procedure CheckPassed(passed:boolean);
  112. begin
  113. if passed then
  114. WriteLn('Success.')
  115. else
  116. begin
  117. WriteLn('Failure.');
  118. Halt(1);
  119. Err:=true;
  120. end;
  121. end;
  122. procedure SetTestEqual;
  123. { FPC_SET_COMP_SETS }
  124. var
  125. op2list :set of tasmop;
  126. oplist: set of tasmop;
  127. passed : boolean;
  128. Begin
  129. Write('Normal Set == Normal Set test...');
  130. passed := true;
  131. op2list:=[];
  132. oplist:=[];
  133. if not (oplist=op2list) then
  134. passed := false;
  135. if not (constset1[2] = constset2[2]) then
  136. passed := false;
  137. if (constset1[1] = constset2[2]) then
  138. passed := false;
  139. if not (constset1[1] = [A_MOVE,A_FTST,A_CPSAVE]) then
  140. passed := false;
  141. CheckPassed(passed);
  142. end;
  143. procedure SetTestNotEqual;
  144. { FPC_SET_COMP_SETS }
  145. var
  146. op2list :set of tasmop;
  147. oplist: set of tasmop;
  148. passed : boolean;
  149. Begin
  150. Write('Normal Set <> Normal Set test...');
  151. passed := true;
  152. op2list:=[];
  153. oplist:=[];
  154. if not (oplist=op2list) then
  155. passed := false;
  156. if (constset1[2] <> constset2[2]) then
  157. passed := false;
  158. if not (constset1[1] <> constset2[2]) then
  159. passed := false;
  160. { if ( [A_ADD] <> [A_ADD] ) then optimized out.
  161. passed := false;
  162. if ( [A_BLE..A_BPL] <> [A_BLE..A_BPL] ) then
  163. passed := false; }
  164. if (constset1[1] <> [A_MOVE,A_FTST,A_CPSAVE]) then
  165. passed := false;
  166. CheckPassed(passed);
  167. end;
  168. procedure SetTestLt;
  169. var
  170. op2list :set of tasmop;
  171. oplist: set of tasmop;
  172. passed : boolean;
  173. begin
  174. Write('Normal Set <= Normal Set test...');
  175. passed := true;
  176. if constset1[1] <= constset2[2] then
  177. passed := false;
  178. oplist := [];
  179. op2list := [A_MOVE];
  180. if op2list <= oplist then
  181. passed := false;
  182. oplist := [A_MOVE,A_CPRESTORE..A_CPSAVE];
  183. if oplist <= op2list then
  184. passed := false;
  185. CheckPassed(passed);
  186. end;
  187. Procedure SetTestAddOne;
  188. { FPC_SET_SET_BYTE }
  189. { FPC_SET_ADD_SETS }
  190. var
  191. op : tasmop;
  192. oplist: set of tasmop;
  193. Begin
  194. Write('Set + Set element testing...');
  195. op:=A_LABEL;
  196. oplist:=[];
  197. oplist:=oplist+[op];
  198. CheckPassed(oplist = [A_LABEL]);
  199. end;
  200. Procedure SetTestAddTwo;
  201. { SET_ADD_SETS }
  202. var
  203. op2list :set of tasmop;
  204. oplist: set of tasmop;
  205. Begin
  206. Write('Complex Set + Set element testing...');
  207. op2list:=[];
  208. oplist:=[];
  209. oplist:=[A_MOVE]+[A_JSR];
  210. op2list:=[A_LABEL];
  211. oplist:=op2list+oplist;
  212. CheckPassed(oplist = [A_MOVE,A_JSR,A_LABEL]);
  213. end;
  214. Procedure SetTestSubOne;
  215. { SET_SUB_SETS }
  216. var
  217. op2list :set of tasmop;
  218. oplist: set of tasmop;
  219. op :tasmop;
  220. passed : boolean;
  221. Begin
  222. Write('Set - Set element testing...');
  223. passed := true;
  224. op2list:=[];
  225. oplist:=[];
  226. op := A_TRACS;
  227. oplist:=[A_MOVE]+[A_JSR]+[op];
  228. op2list:=[A_MOVE]+[A_JSR];
  229. oplist:=oplist-op2list;
  230. if oplist <> [A_TRACS] then
  231. passed := false;
  232. oplist:=[A_MOVE]+[A_JSR]+[op];
  233. op2list:=[A_MOVE]+[A_JSR];
  234. oplist:=op2list-oplist;
  235. if oplist <> [] then
  236. passed := false;
  237. CheckPassed(passed);
  238. end;
  239. Procedure SetTestSubTwo;
  240. { FPC_SET_SUB_SETS }
  241. const
  242. b: tasmop = (A_BSR);
  243. var
  244. op2list :set of tasmop;
  245. oplist: set of tasmop;
  246. op : tasmop;
  247. passed : boolean;
  248. Begin
  249. Write('Complex Set - Set element testing...');
  250. op := A_BKPT;
  251. passed := true;
  252. oplist:=[A_MOVE]+[A_JSR]-[op];
  253. op2list:=[A_MOVE]+[A_JSR];
  254. if oplist <> op2list then
  255. passed := false;
  256. oplist := [A_MOVE];
  257. oplist := oplist - [A_MOVE];
  258. if oplist <> [] then
  259. passed := false;
  260. oplist := oplist + [b];
  261. if oplist <> [b] then
  262. passed := false;
  263. oplist := oplist - [b];
  264. if oplist <> [] then
  265. passed := false;
  266. CheckPassed(passed);
  267. end;
  268. Procedure SetTestMulSets;
  269. { FPC_SET_MUL_SETS }
  270. var
  271. op2list :set of tasmop;
  272. oplist: set of tasmop;
  273. passed : boolean;
  274. Begin
  275. passed := true;
  276. Write('Set * Set element testing...');
  277. op2list:=[];
  278. oplist:=[];
  279. oplist:=[A_MOVE]+[A_JSR];
  280. op2list:=[A_MOVE];
  281. oplist:=oplist*op2list;
  282. if oplist <> [A_JSR] then
  283. passed := false;
  284. oplist := [A_MOVE,A_FTST];
  285. op2list := [A_MOVE,A_FTST];
  286. oplist := oplist * op2list;
  287. if oplist <> [A_MOVE,A_FTST] then
  288. passed := false;
  289. CheckPassed(passed);
  290. end;
  291. procedure SetTestRange;
  292. var
  293. op2list :set of tasmop;
  294. oplist: set of tasmop;
  295. passed : boolean;
  296. op1 : tasmop;
  297. op2 : tasmop;
  298. begin
  299. passed := true;
  300. Write('Range Set + element testing...');
  301. op1 := A_ADD;
  302. op2 := A_ASL;
  303. oplist := [];
  304. oplist := [op1..op2];
  305. if oplist <> constset1[2] then
  306. passed := false;
  307. CheckPassed(passed);
  308. end;
  309. procedure SetTestByte;
  310. var
  311. op2list :set of tasmop;
  312. oplist: set of tasmop;
  313. passed : boolean;
  314. op1 : tasmop;
  315. op2 : tasmop;
  316. op : tasmop;
  317. begin
  318. Write('Simple Set + element testing...');
  319. passed := true;
  320. op := A_LABEL;
  321. oplist := [A_MOVE,op,A_JSR];
  322. if oplist <> [A_MOVE,A_LABEL,A_JSR] then
  323. passed := false;
  324. CheckPassed(passed);
  325. end;
  326. {------------------------------ TESTS FOR SMALL VALUES ---------------------}
  327. procedure SmallSetTestEqual;
  328. var
  329. op2list :set of tsmallenum;
  330. oplist: set of tsmallenum;
  331. passed : boolean;
  332. Begin
  333. Write('Small Set == Small Set test...');
  334. passed := true;
  335. op2list:=[];
  336. oplist:=[];
  337. if not (oplist=op2list) then
  338. passed := false;
  339. if not (constset3[2] = constset4[2]) then
  340. passed := false;
  341. if (constset3[1] = constset4[2]) then
  342. passed := false;
  343. if not (constset3[1] = [DA,DD,DM]) then
  344. passed := false;
  345. CheckPassed(passed);
  346. end;
  347. procedure SmallSetTestNotEqual;
  348. var
  349. op2list :set of tsmallenum;
  350. oplist: set of tsmallenum;
  351. passed : boolean;
  352. Begin
  353. Write('Small Set <> Small Set test...');
  354. passed := true;
  355. op2list:=[];
  356. oplist:=[];
  357. if not (oplist=op2list) then
  358. passed := false;
  359. if (constset3[2] <> constset4[2]) then
  360. passed := false;
  361. if not (constset3[1] <> constset4[2]) then
  362. passed := false;
  363. { if ( [A_ADD] <> [A_ADD] ) then optimized out.
  364. passed := false;
  365. if ( [A_BLE..A_BPL] <> [A_BLE..A_BPL] ) then
  366. passed := false; }
  367. if (constset3[1] <> [DA,DD,DM]) then
  368. passed := false;
  369. CheckPassed(passed);
  370. end;
  371. procedure SmallSetTestLt;
  372. var
  373. op2list :set of tsmallenum;
  374. oplist: set of tsmallenum;
  375. passed : boolean;
  376. begin
  377. Write('Small Set <= Small Set test...');
  378. passed := true;
  379. if constset3[1] <= constset4[2] then
  380. passed := false;
  381. oplist := [];
  382. op2list := [DC];
  383. if op2list <= oplist then
  384. passed := false;
  385. oplist := [DC,DF..DM];
  386. if oplist <= op2list then
  387. passed := false;
  388. CheckPassed(passed);
  389. end;
  390. Procedure SmallSetTestAddOne;
  391. var
  392. op : tsmallenum;
  393. oplist: set of tsmallenum;
  394. Begin
  395. Write('Small Set + Small Set element testing...');
  396. op:=DG;
  397. oplist:=[];
  398. oplist:=oplist+[op];
  399. CheckPassed( oplist = [DG] );
  400. end;
  401. Procedure SmallSetTestAddTwo;
  402. var
  403. op2list :set of tsmallenum;
  404. oplist: set of tsmallenum;
  405. Begin
  406. Write('Small Complex Set + Small Set element testing...');
  407. op2list:=[];
  408. oplist:=[];
  409. oplist:=[DG]+[DI];
  410. op2list:=[DM];
  411. oplist:=op2list+oplist;
  412. CheckPassed( oplist = [DG,DI,DM] );
  413. end;
  414. Procedure SmallSetTestSubOne;
  415. var
  416. op2list :set of tsmallenum;
  417. oplist: set of tsmallenum;
  418. op :tsmallenum;
  419. passed : boolean;
  420. Begin
  421. Write('Small Set - Small Set element testing...');
  422. passed := true;
  423. op2list:=[];
  424. oplist:=[];
  425. op := DL;
  426. oplist:=[DG]+[DI]+[op];
  427. op2list:=[DG]+[DI];
  428. oplist:=oplist-op2list;
  429. if oplist <> [DL] then
  430. passed := false;
  431. oplist:=[DG]+[DI]+[op];
  432. op2list:=[DG]+[DI];
  433. oplist:=op2list-oplist;
  434. if oplist <> [] then
  435. passed := false;
  436. CheckPassed(passed);
  437. end;
  438. Procedure SmallSetTestSubTwo;
  439. const
  440. b: tsmallenum = (DH);
  441. var
  442. op2list :set of tsmallenum;
  443. oplist: set of tsmallenum;
  444. op : tsmallenum;
  445. passed : boolean;
  446. Begin
  447. Write('Small Complex Set - Small Set element testing...');
  448. op := DL;
  449. passed := true;
  450. oplist:=[DG]+[DI]-[op];
  451. op2list:=[DG]+[DI];
  452. if oplist <> op2list then
  453. passed := false;
  454. oplist := [DG];
  455. oplist := oplist - [DG];
  456. if oplist <> [] then
  457. passed := false;
  458. oplist := oplist + [b];
  459. if oplist <> [b] then
  460. passed := false;
  461. oplist := oplist - [b];
  462. if oplist <> [] then
  463. passed := false;
  464. CheckPassed(passed);
  465. end;
  466. Procedure SmallSetTestMulSets;
  467. var
  468. op2list : set of tsmallenum;
  469. oplist: set of tsmallenum;
  470. passed : boolean;
  471. Begin
  472. passed := true;
  473. Write('Small Set * Small Set element testing...');
  474. op2list:=[];
  475. oplist:=[];
  476. oplist:=[DG]+[DI];
  477. op2list:=[DG];
  478. oplist:=oplist*op2list;
  479. if oplist <> [DI] then
  480. passed := false;
  481. oplist := [DG,DK];
  482. op2list := [DG,DK];
  483. oplist := oplist * op2list;
  484. if oplist <> [DG,DK] then
  485. passed := false;
  486. CheckPassed(passed);
  487. end;
  488. procedure SmallSetTestRange;
  489. var
  490. op2list :set of tsmallenum;
  491. oplist: set of tsmallenum;
  492. passed : boolean;
  493. op1 : tsmallenum;
  494. op2 : tsmallenum;
  495. begin
  496. passed := true;
  497. Write('Small Range Set + element testing...');
  498. op1 := DB;
  499. op2 := DI;
  500. oplist := [];
  501. oplist := [op1..op2];
  502. if oplist <> constset3[2] then
  503. passed := false;
  504. CheckPassed(passed);
  505. end;
  506. procedure SmallSetTestByte;
  507. var
  508. op2list : set of tsmallenum;
  509. oplist: set of tsmallenum;
  510. passed : boolean;
  511. op1 : tsmallenum;
  512. op2 : tsmallenum;
  513. op : tsmallenum;
  514. begin
  515. Write('Small Simple Set + element testing...');
  516. passed := true;
  517. op := DD;
  518. oplist := [DG,op,DI];
  519. if oplist <> [DG,DD,DI] then
  520. passed := false;
  521. CheckPassed(passed);
  522. end;
  523. (*
  524. const
  525. b: myenum = (dA);
  526. var
  527. enum: set of myenum;
  528. oplist: set of tasmop;
  529. l : word;
  530. Begin
  531. SetTestEqual;
  532. SetTestNotEqual;
  533. { small sets }
  534. enum:=[];
  535. { add }
  536. enum:=enum+[da];
  537. { subtract }
  538. enum:=enum-[da];
  539. if DA in enum then
  540. WriteLn('Found A_LABEL');
  541. { very large sets }
  542. { copy loop test }
  543. WRITELN('LARGE SETS:');
  544. oplist := [A_LABEL];
  545. { secondin test }
  546. if A_LABEL in oplist then
  547. WriteLn('TESTING SIMPLE SECOND_IN: PASSED.');
  548. { }
  549. oplist:=[];
  550. if A_LABEL in oplist then
  551. WriteLn('SECOND IN FAILED.');
  552. { SecondinSets;}
  553. SetSetByte;
  554. SetAddSets;
  555. SetSubSets;
  556. SetCompSets;
  557. SetMulSets;
  558. WRITELN('SMALL SETS:');
  559. SmallInSets;
  560. SmallAddSets;
  561. SmallSubSets;
  562. SmallCompSets;
  563. SmallMulSets;
  564. l:=word(A_CPRESTORE);
  565. if l = word(A_CPRESTORE) then
  566. Begin
  567. end;
  568. *)
  569. Begin
  570. WriteLn('----------------------- Normal sets -----------------------');
  571. { Normal sets }
  572. SetTestEqual;
  573. SetTestNotEqual;
  574. SetTestAddOne;
  575. SetTestAddTwo;
  576. SetTestSubOne;
  577. SetTestSubTwo;
  578. SetTestRange;
  579. SetTestLt;
  580. SetTestByte;
  581. { Small sets }
  582. WriteLn('----------------------- Small sets -----------------------');
  583. SmallSetTestEqual;
  584. SmallSetTestNotEqual;
  585. SmallSetTestAddOne;
  586. SmallSetTestAddTwo;
  587. SmallSetTestSubOne;
  588. SmallSetTestSubTwo;
  589. SmallSetTestRange;
  590. SmallSetTestLt;
  591. SmallSetTestByte;
  592. if Err then
  593. Halt(1);
  594. end.