cg68kadd.pas 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Generate m68k assembler for add node
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {$ifdef FPC}
  19. {$goto on}
  20. {$endif FPC}
  21. unit cg68kadd;
  22. interface
  23. uses
  24. tree;
  25. procedure secondadd(var p : ptree);
  26. implementation
  27. uses
  28. globtype,systems,symconst,
  29. cobjects,verbose,globals,
  30. symtable,aasm,types,
  31. temp_gen,hcodegen,pass_2,cpubase,
  32. cga68k,tgen68k;
  33. {*****************************************************************************
  34. Helpers
  35. *****************************************************************************}
  36. procedure processcc(p: ptree);
  37. const
  38. { process condition codes bit definitions }
  39. CARRY_FLAG = $01;
  40. OVFL_FLAG = $02;
  41. ZERO_FLAG = $04;
  42. NEG_FLAG = $08;
  43. var
  44. label1,label2: pasmlabel;
  45. (*************************************************************************)
  46. (* Description: This routine handles the conversion of Floating point *)
  47. (* condition codes to normal cpu condition codes. *)
  48. (*************************************************************************)
  49. begin
  50. getlabel(label1);
  51. getlabel(label2);
  52. case p^.treetype of
  53. equaln,unequaln: begin
  54. { not equal clear zero flag }
  55. emitl(A_FBEQ,label1);
  56. exprasmlist^.concat(new(paicpu, op_const_reg(
  57. A_AND, S_B, NOT ZERO_FLAG, R_CCR)));
  58. emitl(A_BRA,label2);
  59. emitl(A_LABEL,label1);
  60. { equal - set zero flag }
  61. exprasmlist^.concat(new(paicpu, op_const_reg(
  62. A_OR,S_B, ZERO_FLAG, R_CCR)));
  63. emitl(A_LABEL,label2);
  64. end;
  65. ltn: begin
  66. emitl(A_FBLT,label1);
  67. { not less than }
  68. { clear N and V flags }
  69. exprasmlist^.concat(new(paicpu, op_const_reg(
  70. A_AND, S_B, NOT (NEG_FLAG OR OVFL_FLAG), R_CCR)));
  71. emitl(A_BRA,label2);
  72. emitl(A_LABEL,label1);
  73. { less than }
  74. exprasmlist^.concat(new(paicpu, op_const_reg(
  75. A_OR,S_B, NEG_FLAG, R_CCR)));
  76. exprasmlist^.concat(new(paicpu, op_const_reg(
  77. A_AND,S_B, NOT OVFL_FLAG, R_CCR)));
  78. emitl(A_LABEL,label2);
  79. end;
  80. gtn: begin
  81. emitl(A_FBGT,label1);
  82. { not greater than }
  83. { set Z flag }
  84. exprasmlist^.concat(new(paicpu, op_const_reg(
  85. A_OR, S_B, ZERO_FLAG, R_CCR)));
  86. emitl(A_BRA,label2);
  87. emitl(A_LABEL,label1);
  88. { greater than }
  89. { set N and V flags }
  90. exprasmlist^.concat(new(paicpu, op_const_reg(
  91. A_OR,S_B, NEG_FLAG OR OVFL_FLAG , R_CCR)));
  92. emitl(A_LABEL,label2);
  93. end;
  94. gten: begin
  95. emitl(A_FBGE,label1);
  96. { not greater or equal }
  97. { set N and clear V }
  98. exprasmlist^.concat(new(paicpu, op_const_reg(
  99. A_AND, S_B, NOT OVFL_FLAG, R_CCR)));
  100. exprasmlist^.concat(new(paicpu, op_const_reg(
  101. A_OR,S_B, NEG_FLAG, R_CCR)));
  102. emitl(A_BRA,label2);
  103. emitl(A_LABEL,label1);
  104. { greater or equal }
  105. { clear V and N flags }
  106. exprasmlist^.concat(new(paicpu, op_const_reg(
  107. A_AND, S_B, NOT (OVFL_FLAG OR NEG_FLAG), R_CCR)));
  108. emitl(A_LABEL,label2);
  109. end;
  110. lten: begin
  111. emitl(A_FBLE,label1);
  112. { not less or equal }
  113. { clear Z, N and V }
  114. exprasmlist^.concat(new(paicpu, op_const_reg(
  115. A_AND, S_B, NOT (ZERO_FLAG OR NEG_FLAG OR OVFL_FLAG), R_CCR)));
  116. emitl(A_BRA,label2);
  117. emitl(A_LABEL,label1);
  118. { less or equal }
  119. { set Z and N }
  120. { and clear V }
  121. exprasmlist^.concat(new(paicpu, op_const_reg(
  122. A_OR,S_B, ZERO_FLAG OR NEG_FLAG, R_CCR)));
  123. exprasmlist^.concat(new(paicpu, op_const_reg(
  124. A_AND,S_B, NOT OVFL_FLAG, R_CCR)));
  125. emitl(A_LABEL,label2);
  126. end;
  127. else
  128. begin
  129. InternalError(34);
  130. end;
  131. end; { end case }
  132. end;
  133. procedure SetResultLocation(cmpop,unsigned:boolean;var p :ptree);
  134. var
  135. flags : tresflags;
  136. begin
  137. { remove temporary location if not a set or string }
  138. { that's a hack (FK) }
  139. if (p^.left^.resulttype^.deftype<>stringdef) and
  140. ((p^.left^.resulttype^.deftype<>setdef) or (psetdef(p^.left^.resulttype)^.settype=smallset)) and
  141. (p^.left^.location.loc in [LOC_MEM,LOC_REFERENCE]) then
  142. ungetiftemp(p^.left^.location.reference);
  143. if (p^.right^.resulttype^.deftype<>stringdef) and
  144. ((p^.right^.resulttype^.deftype<>setdef) or (psetdef(p^.right^.resulttype)^.settype=smallset)) and
  145. (p^.right^.location.loc in [LOC_MEM,LOC_REFERENCE]) then
  146. ungetiftemp(p^.right^.location.reference);
  147. { in case of comparison operation the put result in the flags }
  148. if cmpop then
  149. begin
  150. if not(unsigned) then
  151. begin
  152. if p^.swaped then
  153. case p^.treetype of
  154. equaln : flags:=F_E;
  155. unequaln : flags:=F_NE;
  156. ltn : flags:=F_G;
  157. lten : flags:=F_GE;
  158. gtn : flags:=F_L;
  159. gten : flags:=F_LE;
  160. end
  161. else
  162. case p^.treetype of
  163. equaln : flags:=F_E;
  164. unequaln : flags:=F_NE;
  165. ltn : flags:=F_L;
  166. lten : flags:=F_LE;
  167. gtn : flags:=F_G;
  168. gten : flags:=F_GE;
  169. end;
  170. end
  171. else
  172. begin
  173. if p^.swaped then
  174. case p^.treetype of
  175. equaln : flags:=F_E;
  176. unequaln : flags:=F_NE;
  177. ltn : flags:=F_A;
  178. lten : flags:=F_AE;
  179. gtn : flags:=F_B;
  180. gten : flags:=F_BE;
  181. end
  182. else
  183. case p^.treetype of
  184. equaln : flags:=F_E;
  185. unequaln : flags:=F_NE;
  186. ltn : flags:=F_B;
  187. lten : flags:=F_BE;
  188. gtn : flags:=F_A;
  189. gten : flags:=F_AE;
  190. end;
  191. end;
  192. clear_location(p^.location);
  193. p^.location.loc:=LOC_FLAGS;
  194. p^.location.resflags:=flags;
  195. end;
  196. end;
  197. {*****************************************************************************
  198. Addstring
  199. *****************************************************************************}
  200. procedure addstring(var p : ptree);
  201. var
  202. pushedregs : tpushed;
  203. href : treference;
  204. pushed,
  205. cmpop : boolean;
  206. begin
  207. { string operations are not commutative }
  208. if p^.swaped then
  209. swaptree(p);
  210. case pstringdef(p^.left^.resulttype)^.string_typ of
  211. st_ansistring:
  212. begin
  213. case p^.treetype of
  214. addn :
  215. begin
  216. { we do not need destination anymore }
  217. del_reference(p^.left^.location.reference);
  218. del_reference(p^.right^.location.reference);
  219. { concatansistring(p); }
  220. end;
  221. ltn,lten,gtn,gten,
  222. equaln,unequaln :
  223. begin
  224. pushusedregisters(pushedregs,$ff);
  225. secondpass(p^.left);
  226. del_reference(p^.left^.location.reference);
  227. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  228. secondpass(p^.right);
  229. del_reference(p^.right^.location.reference);
  230. emitpushreferenceaddr(exprasmlist,p^.right^.location.reference);
  231. emitcall('FPC_ANSISTRCMP',true);
  232. maybe_loada5;
  233. popusedregisters(pushedregs);
  234. end;
  235. end;
  236. end;
  237. st_shortstring:
  238. begin
  239. case p^.treetype of
  240. addn : begin
  241. cmpop:=false;
  242. secondpass(p^.left);
  243. if (p^.left^.treetype<>addn) then
  244. begin
  245. { can only reference be }
  246. { string in register would be funny }
  247. { therefore produce a temporary string }
  248. { release the registers }
  249. del_reference(p^.left^.location.reference);
  250. gettempofsizereference(256,href);
  251. copystring(href,p^.left^.location.reference,255);
  252. ungetiftemp(p^.left^.location.reference);
  253. { does not hurt: }
  254. clear_location(p^.left^.location);
  255. p^.left^.location.loc:=LOC_MEM;
  256. p^.left^.location.reference:=href;
  257. end;
  258. secondpass(p^.right);
  259. { on the right we do not need the register anymore too }
  260. del_reference(p^.right^.location.reference);
  261. pushusedregisters(pushedregs,$ffff);
  262. { WE INVERSE THE PARAMETERS!!! }
  263. { Because parameters are inversed in the rtl }
  264. emitpushreferenceaddr(exprasmlist,p^.right^.location.reference);
  265. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  266. emitcall('FPC_STRCONCAT',true);
  267. maybe_loadA5;
  268. popusedregisters(pushedregs);
  269. set_location(p^.location,p^.left^.location);
  270. ungetiftemp(p^.right^.location.reference);
  271. end; { this case }
  272. ltn,lten,gtn,gten,
  273. equaln,unequaln :
  274. begin
  275. secondpass(p^.left);
  276. { are too few registers free? }
  277. pushed:=maybe_push(p^.right^.registers32,p);
  278. secondpass(p^.right);
  279. if pushed then restore(p);
  280. cmpop:=true;
  281. del_reference(p^.right^.location.reference);
  282. del_reference(p^.left^.location.reference);
  283. { generates better code }
  284. { s='' and s<>'' }
  285. if (p^.treetype in [equaln,unequaln]) and
  286. (
  287. ((p^.left^.treetype=stringconstn) and
  288. (str_length(p^.left)=0)) or
  289. ((p^.right^.treetype=stringconstn) and
  290. (str_length(p^.right)=0))
  291. ) then
  292. begin
  293. { only one node can be stringconstn }
  294. { else pass 1 would have evaluted }
  295. { this node }
  296. if p^.left^.treetype=stringconstn then
  297. exprasmlist^.concat(new(paicpu,op_ref(
  298. A_TST,S_B,newreference(p^.right^.location.reference))))
  299. else
  300. exprasmlist^.concat(new(paicpu,op_ref(
  301. A_TST,S_B,newreference(p^.left^.location.reference))));
  302. end
  303. else
  304. begin
  305. pushusedregisters(pushedregs,$ffff);
  306. { parameters are directly passed via registers }
  307. { this has several advantages, no loss of the flags }
  308. { on exit ,and MUCH faster on m68k machines }
  309. { speed difference (68000) }
  310. { normal routine: entry, exit code + push = 124 }
  311. { (best case) }
  312. { assembler routine: param setup (worst case) = 48 }
  313. exprasmlist^.concat(new(paicpu,op_ref_reg(
  314. A_LEA,S_L,newreference(p^.left^.location.reference),R_A0)));
  315. exprasmlist^.concat(new(paicpu,op_ref_reg(
  316. A_LEA,S_L,newreference(p^.right^.location.reference),R_A1)));
  317. {
  318. emitpushreferenceaddr(p^.left^.location.reference);
  319. emitpushreferenceaddr(p^.right^.location.reference); }
  320. emitcall('FPC_STRCMP',true);
  321. maybe_loada5;
  322. popusedregisters(pushedregs);
  323. end;
  324. ungetiftemp(p^.left^.location.reference);
  325. ungetiftemp(p^.right^.location.reference);
  326. end; { end this case }
  327. else CGMessage(type_e_mismatch);
  328. end;
  329. end; { end case }
  330. end;
  331. SetResultLocation(cmpop,true,p);
  332. end;
  333. {*****************************************************************************
  334. Addset
  335. *****************************************************************************}
  336. procedure addset(var p : ptree);
  337. var
  338. cmpop,
  339. pushed : boolean;
  340. href : treference;
  341. pushedregs : tpushed;
  342. begin
  343. cmpop:=false;
  344. { not commutative }
  345. if p^.swaped then
  346. swaptree(p);
  347. secondpass(p^.left);
  348. { are too few registers free? }
  349. pushed:=maybe_push(p^.right^.registers32,p);
  350. secondpass(p^.right);
  351. if codegenerror then
  352. exit;
  353. if pushed then
  354. restore(p);
  355. set_location(p^.location,p^.left^.location);
  356. { handle operations }
  357. case p^.treetype of
  358. equaln,
  359. unequaln : begin
  360. cmpop:=true;
  361. del_reference(p^.left^.location.reference);
  362. del_reference(p^.right^.location.reference);
  363. pushusedregisters(pushedregs,$ff);
  364. emitpushreferenceaddr(exprasmlist,p^.right^.location.reference);
  365. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  366. emitcall('FPC_SET_COMP_SETS',true);
  367. maybe_loada5;
  368. popusedregisters(pushedregs);
  369. ungetiftemp(p^.left^.location.reference);
  370. ungetiftemp(p^.right^.location.reference);
  371. end;
  372. addn : begin
  373. { add can be an other SET or Range or Element ! }
  374. del_reference(p^.left^.location.reference);
  375. del_reference(p^.right^.location.reference);
  376. pushusedregisters(pushedregs,$ff);
  377. href.symbol:=nil;
  378. gettempofsizereference(32,href);
  379. { add a range or a single element? }
  380. if p^.right^.treetype=setelementn then
  381. begin
  382. concatcopy(p^.left^.location.reference,href,32,false);
  383. if assigned(p^.right^.right) then
  384. begin
  385. loadsetelement(p^.right^.right);
  386. loadsetelement(p^.right^.left);
  387. emitpushreferenceaddr(exprasmlist,href);
  388. emitcall('FPC_SET_SET_RANGE',true);
  389. end
  390. else
  391. begin
  392. loadsetelement(p^.right^.left);
  393. emitpushreferenceaddr(exprasmlist,href);
  394. emitcall('FPC_SET_SET_BYTE',true);
  395. end;
  396. end
  397. else
  398. begin
  399. { must be an other set }
  400. emitpushreferenceaddr(exprasmlist,href);
  401. emitpushreferenceaddr(exprasmlist,p^.right^.location.reference);
  402. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  403. emitcall('FPC_SET_ADD_SETS',true);
  404. end;
  405. maybe_loada5;
  406. popusedregisters(pushedregs);
  407. ungetiftemp(p^.left^.location.reference);
  408. ungetiftemp(p^.right^.location.reference);
  409. p^.location.loc:=LOC_MEM;
  410. stringdispose(p^.location.reference.symbol);
  411. p^.location.reference:=href;
  412. end;
  413. subn,
  414. symdifn,
  415. muln : begin
  416. del_reference(p^.left^.location.reference);
  417. del_reference(p^.right^.location.reference);
  418. href.symbol:=nil;
  419. pushusedregisters(pushedregs,$ff);
  420. gettempofsizereference(32,href);
  421. emitpushreferenceaddr(exprasmlist,href);
  422. emitpushreferenceaddr(exprasmlist,p^.right^.location.reference);
  423. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  424. case p^.treetype of
  425. subn : emitcall('FPC_SET_SUB_SETS',true);
  426. symdifn : emitcall('FPC_SET_SYMDIF_SETS',true);
  427. muln : emitcall('FPC_SET_MUL_SETS',true);
  428. end;
  429. maybe_loada5;
  430. popusedregisters(pushedregs);
  431. ungetiftemp(p^.left^.location.reference);
  432. ungetiftemp(p^.right^.location.reference);
  433. p^.location.loc:=LOC_MEM;
  434. stringdispose(p^.location.reference.symbol);
  435. p^.location.reference:=href;
  436. end;
  437. else
  438. CGMessage(type_e_mismatch);
  439. end;
  440. SetResultLocation(cmpop,true,p);
  441. end;
  442. {*****************************************************************************
  443. SecondAdd
  444. *****************************************************************************}
  445. procedure secondadd(var p : ptree);
  446. { is also being used for xor, and "mul", "sub, or and comparative }
  447. { operators }
  448. label do_normal;
  449. var
  450. hregister : tregister;
  451. noswap,
  452. pushed,mboverflow,cmpop : boolean;
  453. op : tasmop;
  454. flags : tresflags;
  455. otl,ofl : pasmlabel;
  456. power : longint;
  457. opsize : topsize;
  458. hl4: pasmlabel;
  459. tmpref : treference;
  460. { true, if unsigned types are compared }
  461. unsigned : boolean;
  462. { true, if a small set is handled with the longint code }
  463. is_set : boolean;
  464. { is_in_dest if the result is put directly into }
  465. { the resulting refernce or varregister }
  466. is_in_dest : boolean;
  467. { true, if for sets subtractions the extra not should generated }
  468. extra_not : boolean;
  469. begin
  470. { to make it more readable, string and set (not smallset!) have their
  471. own procedures }
  472. case p^.left^.resulttype^.deftype of
  473. stringdef : begin
  474. addstring(p);
  475. exit;
  476. end;
  477. setdef : begin
  478. { normalsets are handled separate }
  479. if not(psetdef(p^.left^.resulttype)^.settype=smallset) then
  480. begin
  481. addset(p);
  482. exit;
  483. end;
  484. end;
  485. end;
  486. { defaults }
  487. unsigned:=false;
  488. is_in_dest:=false;
  489. extra_not:=false;
  490. noswap:=false;
  491. opsize:=S_L;
  492. { are we a (small)set, must be set here because the side can be
  493. swapped ! (PFV) }
  494. is_set:=(p^.left^.resulttype^.deftype=setdef);
  495. { calculate the operator which is more difficult }
  496. firstcomplex(p);
  497. { handling boolean expressions extra: }
  498. if ((p^.left^.resulttype^.deftype=orddef) and
  499. (porddef(p^.left^.resulttype)^.typ in [bool8bit,bool16bit,bool32bit])) or
  500. ((p^.right^.resulttype^.deftype=orddef) and
  501. (porddef(p^.right^.resulttype)^.typ in [bool8bit,bool16bit,bool32bit])) then
  502. begin
  503. if (porddef(p^.left^.resulttype)^.typ=bool8bit) or
  504. (porddef(p^.right^.resulttype)^.typ=bool8bit) then
  505. opsize:=S_B
  506. else
  507. if (porddef(p^.left^.resulttype)^.typ=bool16bit) or
  508. (porddef(p^.right^.resulttype)^.typ=bool16bit) then
  509. opsize:=S_W
  510. else
  511. opsize:=S_L;
  512. case p^.treetype of
  513. andn,
  514. orn : begin
  515. clear_location(p^.location);
  516. p^.location.loc:=LOC_JUMP;
  517. cmpop:=false;
  518. case p^.treetype of
  519. andn : begin
  520. otl:=truelabel;
  521. getlabel(truelabel);
  522. secondpass(p^.left);
  523. maketojumpbool(p^.left);
  524. emitl(A_LABEL,truelabel);
  525. truelabel:=otl;
  526. end;
  527. orn : begin
  528. ofl:=falselabel;
  529. getlabel(falselabel);
  530. secondpass(p^.left);
  531. maketojumpbool(p^.left);
  532. emitl(A_LABEL,falselabel);
  533. falselabel:=ofl;
  534. end;
  535. else
  536. CGMessage(type_e_mismatch);
  537. end;
  538. secondpass(p^.right);
  539. maketojumpbool(p^.right);
  540. end;
  541. unequaln,
  542. equaln,xorn : begin
  543. if p^.left^.treetype=ordconstn then
  544. swaptree(p);
  545. secondpass(p^.left);
  546. set_location(p^.location,p^.left^.location);
  547. { are enough registers free ? }
  548. pushed:=maybe_push(p^.right^.registers32,p);
  549. secondpass(p^.right);
  550. if pushed then restore(p);
  551. goto do_normal;
  552. end
  553. else
  554. CGMessage(type_e_mismatch);
  555. end
  556. end
  557. else
  558. begin
  559. { in case of constant put it to the left }
  560. if (p^.left^.treetype=ordconstn) then
  561. swaptree(p);
  562. secondpass(p^.left);
  563. { this will be complicated as
  564. a lot of code below assumes that
  565. p^.location and p^.left^.location are the same }
  566. {$ifdef test_dest_loc}
  567. if dest_loc_known and (dest_loc_tree=p) and
  568. ((dest_loc.loc=LOC_REGISTER) or (dest_loc.loc=LOC_CREGISTER)) then
  569. begin
  570. set_location(p^.location,dest_loc);
  571. in_dest_loc:=true;
  572. is_in_dest:=true;
  573. end
  574. else
  575. {$endif test_dest_loc}
  576. set_location(p^.location,p^.left^.location);
  577. { are too few registers free? }
  578. pushed:=maybe_push(p^.right^.registers32,p);
  579. secondpass(p^.right);
  580. if pushed then
  581. restore(p);
  582. if (p^.left^.resulttype^.deftype=pointerdef) or
  583. (p^.right^.resulttype^.deftype=pointerdef) or
  584. ((p^.right^.resulttype^.deftype=objectdef) and
  585. pobjectdef(p^.right^.resulttype)^.is_class and
  586. (p^.left^.resulttype^.deftype=objectdef) and
  587. pobjectdef(p^.left^.resulttype)^.is_class
  588. ) or
  589. (p^.left^.resulttype^.deftype=classrefdef) or
  590. (p^.left^.resulttype^.deftype=procvardef) or
  591. (p^.left^.resulttype^.deftype=enumdef) or
  592. ((p^.left^.resulttype^.deftype=orddef) and
  593. (porddef(p^.left^.resulttype)^.typ=s32bit)) or
  594. ((p^.right^.resulttype^.deftype=orddef) and
  595. (porddef(p^.right^.resulttype)^.typ=s32bit)) or
  596. ((p^.left^.resulttype^.deftype=orddef) and
  597. (porddef(p^.left^.resulttype)^.typ=u32bit)) or
  598. ((p^.right^.resulttype^.deftype=orddef) and
  599. (porddef(p^.right^.resulttype)^.typ=u32bit)) or
  600. { as well as small sets }
  601. is_set then
  602. begin
  603. do_normal:
  604. mboverflow:=false;
  605. cmpop:=false;
  606. if (p^.left^.resulttype^.deftype=pointerdef) or
  607. (p^.right^.resulttype^.deftype=pointerdef) or
  608. ((p^.left^.resulttype^.deftype=orddef) and
  609. (porddef(p^.left^.resulttype)^.typ=u32bit)) or
  610. ((p^.right^.resulttype^.deftype=orddef) and
  611. (porddef(p^.right^.resulttype)^.typ=u32bit)) then
  612. unsigned:=true;
  613. case p^.treetype of
  614. addn : begin
  615. if is_set then
  616. begin
  617. { adding elements is not commutative }
  618. if p^.swaped and (p^.left^.treetype=setelementn) then
  619. swaptree(p);
  620. { are we adding set elements ? }
  621. if p^.right^.treetype=setelementn then
  622. begin
  623. { no range support for smallsets! }
  624. if assigned(p^.right^.right) then
  625. internalerror(43244);
  626. { Not supported for m68k}
  627. Comment(V_Fatal,'No smallsets for m68k');
  628. end
  629. else
  630. op:=A_OR;
  631. mboverflow:=false;
  632. unsigned:=false;
  633. end
  634. else
  635. begin
  636. op:=A_ADD;
  637. mboverflow:=true;
  638. end;
  639. end;
  640. symdifn : begin
  641. { the symetric diff is only for sets }
  642. if is_set then
  643. begin
  644. op:=A_EOR;
  645. mboverflow:=false;
  646. unsigned:=false;
  647. end
  648. else
  649. CGMessage(type_e_mismatch);
  650. end;
  651. muln : begin
  652. if is_set then
  653. begin
  654. op:=A_AND;
  655. mboverflow:=false;
  656. unsigned:=false;
  657. end
  658. else
  659. begin
  660. if unsigned then
  661. op:=A_MULU
  662. else
  663. op:=A_MULS;
  664. mboverflow:=true;
  665. end;
  666. end;
  667. subn : begin
  668. if is_set then
  669. begin
  670. op:=A_AND;
  671. mboverflow:=false;
  672. unsigned:=false;
  673. extra_not:=true;
  674. end
  675. else
  676. begin
  677. op:=A_SUB;
  678. mboverflow:=true;
  679. end;
  680. end;
  681. ltn,lten,
  682. gtn,gten,
  683. equaln,unequaln : begin
  684. op:=A_CMP;
  685. cmpop:=true;
  686. end;
  687. xorn : op:=A_EOR;
  688. orn : op:=A_OR;
  689. andn : op:=A_AND;
  690. else
  691. CGMessage(type_e_mismatch);
  692. end;
  693. { left and right no register? }
  694. { then one must be demanded }
  695. if (p^.left^.location.loc<>LOC_REGISTER) and
  696. (p^.right^.location.loc<>LOC_REGISTER) then
  697. begin
  698. { register variable ? }
  699. if (p^.left^.location.loc=LOC_CREGISTER) then
  700. begin
  701. { it is OK if this is the destination }
  702. if is_in_dest then
  703. begin
  704. hregister:=p^.location.register;
  705. emit_reg_reg(A_MOVE,opsize,p^.left^.location.register,
  706. hregister);
  707. end
  708. else
  709. if cmpop then
  710. begin
  711. { do not disturb the register }
  712. hregister:=p^.location.register;
  713. end
  714. else
  715. begin
  716. hregister:=getregister32;
  717. emit_reg_reg(A_MOVE,opsize,p^.left^.location.register,
  718. hregister);
  719. end
  720. end
  721. else
  722. begin
  723. del_reference(p^.left^.location.reference);
  724. if is_in_dest then
  725. begin
  726. hregister:=p^.location.register;
  727. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,opsize,
  728. newreference(p^.left^.location.reference),hregister)));
  729. end
  730. else
  731. begin
  732. hregister:=getregister32;
  733. { first give free, then demand new register }
  734. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,opsize,
  735. newreference(p^.left^.location.reference),hregister)));
  736. end;
  737. end;
  738. clear_location(p^.location);
  739. p^.location.loc:=LOC_REGISTER;
  740. p^.location.register:=hregister;
  741. end
  742. else
  743. { if on the right the register then swap }
  744. if not(noswap) and (p^.right^.location.loc=LOC_REGISTER) then
  745. begin
  746. swap_location(p^.location,p^.right^.location);
  747. { newly swapped also set swapped flag }
  748. p^.swaped:=not(p^.swaped);
  749. end;
  750. { at this point, p^.location.loc should be LOC_REGISTER }
  751. { and p^.location.register should be a valid register }
  752. { containing the left result }
  753. if p^.right^.location.loc<>LOC_REGISTER then
  754. begin
  755. if (p^.treetype=subn) and p^.swaped then
  756. begin
  757. if p^.right^.location.loc=LOC_CREGISTER then
  758. begin
  759. if extra_not then
  760. exprasmlist^.concat(new(paicpu,op_reg(A_NOT,opsize,p^.location.register)));
  761. emit_reg_reg(A_MOVE,opsize,p^.right^.location.register,R_D6);
  762. emit_reg_reg(op,opsize,p^.location.register,R_D6);
  763. emit_reg_reg(A_MOVE,opsize,R_D6,p^.location.register);
  764. end
  765. else
  766. begin
  767. if extra_not then
  768. exprasmlist^.concat(new(paicpu,op_reg(A_NOT,opsize,p^.location.register)));
  769. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,opsize,
  770. newreference(p^.right^.location.reference),R_D6)));
  771. exprasmlist^.concat(new(paicpu,op_reg_reg(op,opsize,p^.location.register,R_D6)));
  772. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,opsize,R_D6,p^.location.register)));
  773. del_reference(p^.right^.location.reference);
  774. end;
  775. end
  776. else
  777. begin
  778. if (p^.right^.treetype=ordconstn) and (op=A_CMP) and
  779. (p^.right^.value=0) then
  780. exprasmlist^.concat(new(paicpu,op_reg(A_TST,opsize,p^.location.register)))
  781. else
  782. if (p^.right^.treetype=ordconstn) and (op=A_MULS) and
  783. (ispowerof2(p^.right^.value,power)) then
  784. begin
  785. if (power <= 8) then
  786. exprasmlist^.concat(new(paicpu,op_const_reg(A_ASL,opsize,power,
  787. p^.location.register)))
  788. else
  789. begin
  790. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,S_L,power,
  791. R_D6)));
  792. exprasmlist^.concat(new(paicpu,op_reg_reg(A_ASL,opsize,R_D6,
  793. p^.location.register)))
  794. end;
  795. end
  796. else
  797. begin
  798. if (p^.right^.location.loc=LOC_CREGISTER) then
  799. begin
  800. if extra_not then
  801. begin
  802. emit_reg_reg(A_MOVE,S_L,p^.right^.location.register,R_D6);
  803. exprasmlist^.concat(new(paicpu,op_reg(A_NOT,S_L,R_D6)));
  804. emit_reg_reg(A_AND,S_L,R_D6,
  805. p^.location.register);
  806. end
  807. else
  808. begin
  809. if (op=A_MULS) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  810. { Emulation for MC68000 }
  811. begin
  812. emit_reg_reg(A_MOVE,opsize,p^.right^.location.register,
  813. R_D0);
  814. emit_reg_reg(A_MOVE,opsize,p^.location.register,R_D1);
  815. emitcall('FPC_LONGMUL',true);
  816. emit_reg_reg(A_MOVE,opsize,R_D0,p^.location.register);
  817. end
  818. else
  819. if (op=A_MULU) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  820. CGMessage(cg_f_32bit_not_supported_in_68000)
  821. else
  822. emit_reg_reg(op,opsize,p^.right^.location.register,
  823. p^.location.register);
  824. end;
  825. end
  826. else
  827. begin
  828. if extra_not then
  829. begin
  830. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,newreference(
  831. p^.right^.location.reference),R_D6)));
  832. exprasmlist^.concat(new(paicpu,op_reg(A_NOT,S_L,R_D6)));
  833. emit_reg_reg(A_AND,S_L,R_D6,
  834. p^.location.register);
  835. end
  836. else
  837. begin
  838. if (op=A_MULS) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  839. { Emulation for MC68000 }
  840. begin
  841. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE, opsize,
  842. newreference(p^.right^.location.reference),R_D1)));
  843. emit_reg_reg(A_MOVE,opsize,p^.location.register,R_D0);
  844. emitcall('FPC_LONGMUL',true);
  845. emit_reg_reg(A_MOVE,opsize,R_D0,p^.location.register);
  846. end
  847. else
  848. if (op=A_MULU) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  849. CGMessage(cg_f_32bit_not_supported_in_68000)
  850. else
  851. { When one of the source/destination is a memory reference }
  852. { and the operator is EOR, the we must load it into the }
  853. { value into a register first since only EOR reg,reg exists }
  854. { on the m68k }
  855. if (op=A_EOR) then
  856. begin
  857. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,opsize,newreference(
  858. p^.right^.location.reference),R_D0)));
  859. exprasmlist^.concat(new(paicpu,op_reg_reg(op,opsize,R_D0,
  860. p^.location.register)));
  861. end
  862. else
  863. exprasmlist^.concat(new(paicpu,op_ref_reg(op,opsize,newreference(
  864. p^.right^.location.reference),p^.location.register)));
  865. end;
  866. del_reference(p^.right^.location.reference);
  867. end;
  868. end;
  869. end;
  870. end
  871. else
  872. begin
  873. { when swapped another result register }
  874. if (p^.treetype=subn) and p^.swaped then
  875. begin
  876. if extra_not then
  877. exprasmlist^.concat(new(paicpu,op_reg(A_NOT,S_L,p^.location.register)));
  878. exprasmlist^.concat(new(paicpu,op_reg_reg(op,opsize,
  879. p^.location.register,p^.right^.location.register)));
  880. swap_location(p^.location,p^.right^.location);
  881. { newly swapped also set swapped flag }
  882. { just to maintain ordering }
  883. p^.swaped:=not(p^.swaped);
  884. end
  885. else
  886. begin
  887. if extra_not then
  888. exprasmlist^.concat(new(paicpu,op_reg(A_NOT,S_L,p^.right^.location.register)));
  889. if (op=A_MULS) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  890. { Emulation for MC68000 }
  891. begin
  892. emit_reg_reg(A_MOVE,opsize,p^.right^.location.register,
  893. R_D0);
  894. emit_reg_reg(A_MOVE,opsize,p^.location.register,R_D1);
  895. emitcall('FPC_LONGMUL',true);
  896. emit_reg_reg(A_MOVE,opsize,R_D0,p^.location.register);
  897. end
  898. else
  899. if (op=A_MULU) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  900. CGMessage(cg_f_32bit_not_supported_in_68000)
  901. else
  902. exprasmlist^.concat(new(paicpu,op_reg_reg(op,opsize,
  903. p^.right^.location.register,
  904. p^.location.register)));
  905. end;
  906. ungetregister32(p^.right^.location.register);
  907. end;
  908. if cmpop then
  909. ungetregister32(p^.location.register);
  910. { only in case of overflow operations }
  911. { produce overflow code }
  912. if mboverflow then
  913. emitoverflowcheck(p);
  914. { only in case of overflow operations }
  915. { produce overflow code }
  916. { we must put it here directly, because sign of operation }
  917. { is in unsigned VAR!! }
  918. end
  919. else
  920. { Char type }
  921. if ((p^.left^.resulttype^.deftype=orddef) and
  922. (porddef(p^.left^.resulttype)^.typ=uchar)) then
  923. begin
  924. case p^.treetype of
  925. ltn,lten,gtn,gten,
  926. equaln,unequaln :
  927. cmpop:=true;
  928. else CGMessage(type_e_mismatch);
  929. end;
  930. unsigned:=true;
  931. { left and right no register? }
  932. { the one must be demanded }
  933. if (p^.location.loc<>LOC_REGISTER) and
  934. (p^.right^.location.loc<>LOC_REGISTER) then
  935. begin
  936. if p^.location.loc=LOC_CREGISTER then
  937. begin
  938. if cmpop then
  939. { do not disturb register }
  940. hregister:=p^.location.register
  941. else
  942. begin
  943. hregister:=getregister32;
  944. emit_reg_reg(A_MOVE,S_B,p^.location.register,
  945. hregister);
  946. end;
  947. end
  948. else
  949. begin
  950. del_reference(p^.location.reference);
  951. { first give free then demand new register }
  952. hregister:=getregister32;
  953. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_B,newreference(p^.location.reference),
  954. hregister)));
  955. end;
  956. clear_location(p^.location);
  957. p^.location.loc:=LOC_REGISTER;
  958. p^.location.register:=hregister;
  959. end;
  960. { now p always a register }
  961. if (p^.right^.location.loc=LOC_REGISTER) and
  962. (p^.location.loc<>LOC_REGISTER) then
  963. begin
  964. swap_location(p^.location,p^.right^.location);
  965. { newly swapped also set swapped flag }
  966. p^.swaped:=not(p^.swaped);
  967. end;
  968. if p^.right^.location.loc<>LOC_REGISTER then
  969. begin
  970. if p^.right^.location.loc=LOC_CREGISTER then
  971. begin
  972. emit_reg_reg(A_CMP,S_B,
  973. p^.right^.location.register,p^.location.register);
  974. end
  975. else
  976. begin
  977. exprasmlist^.concat(new(paicpu,op_ref_reg(A_CMP,S_B,newreference(
  978. p^.right^.location.reference),p^.location.register)));
  979. del_reference(p^.right^.location.reference);
  980. end;
  981. end
  982. else
  983. begin
  984. emit_reg_reg(A_CMP,S_B,p^.right^.location.register,
  985. p^.location.register);
  986. ungetregister32(p^.right^.location.register);
  987. end;
  988. ungetregister32(p^.location.register);
  989. end
  990. else
  991. { Floating point }
  992. if (p^.left^.resulttype^.deftype=floatdef) and
  993. (pfloatdef(p^.left^.resulttype)^.typ<>f32bit) then
  994. begin
  995. { real constants to the left }
  996. if p^.left^.treetype=realconstn then
  997. swaptree(p);
  998. cmpop:=false;
  999. case p^.treetype of
  1000. addn : op:=A_FADD;
  1001. muln : op:=A_FMUL;
  1002. subn : op:=A_FSUB;
  1003. slashn : op:=A_FDIV;
  1004. ltn,lten,gtn,gten,
  1005. equaln,unequaln : begin
  1006. op:=A_FCMP;
  1007. cmpop:=true;
  1008. end;
  1009. else CGMessage(type_e_mismatch);
  1010. end;
  1011. if (p^.left^.location.loc <> LOC_FPU) and
  1012. (p^.right^.location.loc <> LOC_FPU) then
  1013. begin
  1014. { we suppose left in reference }
  1015. del_reference(p^.left^.location.reference);
  1016. { get a copy, since we don't want to modify the same }
  1017. { node at the same time. }
  1018. tmpref:=p^.left^.location.reference;
  1019. if assigned(p^.left^.location.reference.symbol) then
  1020. tmpref.symbol:=stringdup(p^.left^.location.reference.symbol^);
  1021. floatload(pfloatdef(p^.left^.resulttype)^.typ, tmpref,
  1022. p^.left^.location);
  1023. clear_reference(tmpref);
  1024. end
  1025. else
  1026. begin
  1027. if (p^.right^.location.loc = LOC_FPU)
  1028. and(p^.left^.location.loc <> LOC_FPU) then
  1029. begin
  1030. swap_location(p^.left^.location, p^.right^.location);
  1031. p^.swaped := not(p^.swaped);
  1032. end
  1033. end;
  1034. { ---------------- LEFT = LOC_FPUREG -------------------- }
  1035. if ((p^.treetype =subn) or (p^.treetype = slashn)) and (p^.swaped) then
  1036. { fpu_reg = right(FP1) / fpu_reg }
  1037. { fpu_reg = right(FP1) - fpu_reg }
  1038. begin
  1039. if (cs_fp_emulation in aktmoduleswitches) then
  1040. begin
  1041. { fpu_reg = right / D1 }
  1042. { fpu_reg = right - D1 }
  1043. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,p^.left^.location.fpureg,R_D0)));
  1044. { load value into D1 }
  1045. if p^.right^.location.loc <> LOC_FPU then
  1046. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,
  1047. newreference(p^.right^.location.reference),R_D1)))
  1048. else
  1049. emit_reg_reg(A_MOVE,S_L,p^.right^.location.fpureg,R_D1);
  1050. { probably a faster way to do this but... }
  1051. case op of
  1052. A_FADD: emitcall('FPC_SINGLE_ADD',true);
  1053. A_FMUL: emitcall('FPC_SINGLE_MUL',true);
  1054. A_FSUB: emitcall('FPC_SINGLE_SUB',true);
  1055. A_FDIV: emitcall('FPC_SINGLE_DIV',true);
  1056. A_FCMP: emitcall('FPC_SINGLE_CMP',true);
  1057. end;
  1058. if not cmpop then { only flags are affected with cmpop }
  1059. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,R_D0,
  1060. p^.left^.location.fpureg)));
  1061. { if this was a reference, then delete as it }
  1062. { it no longer required. }
  1063. if p^.right^.location.loc <> LOC_FPU then
  1064. del_reference(p^.right^.location.reference);
  1065. end
  1066. else
  1067. begin
  1068. if p^.right^.location.loc <> LOC_FPU then
  1069. exprasmlist^.concat(new(paicpu,op_ref_reg(A_FMOVE,
  1070. getfloatsize(pfloatdef(p^.left^.resulttype)^.typ),
  1071. newreference(p^.right^.location.reference),
  1072. R_FP1)))
  1073. else
  1074. { FPm --> FPn must use extended precision }
  1075. emit_reg_reg(A_FMOVE,S_FX,p^.right^.location.fpureg,R_FP1);
  1076. { arithmetic expression performed in extended mode }
  1077. exprasmlist^.concat(new(paicpu,op_reg_reg(op,S_FX,
  1078. p^.left^.location.fpureg,R_FP1)));
  1079. { cmpop does not change any floating point register!! }
  1080. if not cmpop then
  1081. emit_reg_reg(A_FMOVE,S_FX,R_FP1,p^.left^.location.fpureg)
  1082. { exprasmlist^.concat(new(paicpu,op_reg_reg(A_FMOVE,
  1083. getfloatsize(pfloatdef(p^.left^.resulttype)^.typ),
  1084. R_FP1,p^.left^.location.fpureg)))}
  1085. else
  1086. { process comparison, to make it compatible with the rest of the code }
  1087. processcc(p);
  1088. { if this was a reference, then delete as it }
  1089. { it no longer required. }
  1090. if p^.right^.location.loc <> LOC_FPU then
  1091. del_reference(p^.right^.location.reference);
  1092. end;
  1093. end
  1094. else { everything is in the right order }
  1095. begin
  1096. { fpu_reg = fpu_reg / right }
  1097. { fpu_reg = fpu_reg - right }
  1098. { + commutative ops }
  1099. if cs_fp_emulation in aktmoduleswitches then
  1100. begin
  1101. { load value into D7 }
  1102. if p^.right^.location.loc <> LOC_FPU then
  1103. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,
  1104. newreference(p^.right^.location.reference),R_D0)))
  1105. else
  1106. emit_reg_reg(A_MOVE,S_L,p^.right^.location.fpureg,R_D0);
  1107. emit_reg_reg(A_MOVE,S_L,p^.left^.location.fpureg,R_D1);
  1108. { probably a faster way to do this but... }
  1109. case op of
  1110. A_FADD: emitcall('FPC_SINGLE_ADD',true);
  1111. A_FMUL: emitcall('FPC_SINGLE_MUL',true);
  1112. A_FSUB: emitcall('FPC_SINGLE_SUB',true);
  1113. A_FDIV: emitcall('FPC_SINGLE_DIV',true);
  1114. A_FCMP: emitcall('FPC_SINGLE_CMP',true);
  1115. end;
  1116. if not cmpop then { only flags are affected with cmpop }
  1117. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,R_D0,
  1118. p^.left^.location.fpureg)));
  1119. { if this was a reference, then delete as it }
  1120. { it no longer required. }
  1121. if p^.right^.location.loc <> LOC_FPU then
  1122. del_reference(p^.right^.location.reference);
  1123. end
  1124. else
  1125. begin
  1126. if p^.right^.location.loc <> LOC_FPU then
  1127. exprasmlist^.concat(new(paicpu,op_ref_reg(A_FMOVE,
  1128. getfloatsize(pfloatdef(p^.left^.resulttype)^.typ),
  1129. newreference(p^.right^.location.reference),R_FP1)))
  1130. else
  1131. emit_reg_reg(A_FMOVE,getfloatsize(pfloatdef(p^.left^.resulttype)^.typ),
  1132. p^.right^.location.fpureg,R_FP1);
  1133. emit_reg_reg(op,S_FX,R_FP1,p^.left^.location.fpureg);
  1134. if cmpop then
  1135. processcc(p);
  1136. { if this was a reference, then delete as it }
  1137. { it no longer required. }
  1138. if p^.right^.location.loc <> LOC_FPU then
  1139. del_reference(p^.right^.location.reference);
  1140. end
  1141. end; { endif treetype = .. }
  1142. if cmpop then
  1143. begin
  1144. { the register is now longer required }
  1145. if p^.left^.location.loc = LOC_FPU then
  1146. begin
  1147. ungetregister(p^.left^.location.fpureg);
  1148. end;
  1149. if p^.swaped then
  1150. case p^.treetype of
  1151. equaln: flags := F_E;
  1152. unequaln: flags := F_NE;
  1153. ltn : flags := F_G;
  1154. lten : flags := F_GE;
  1155. gtn : flags := F_L;
  1156. gten: flags := F_LE;
  1157. end
  1158. else
  1159. case p^.treetype of
  1160. equaln: flags := F_E;
  1161. unequaln : flags := F_NE;
  1162. ltn: flags := F_L;
  1163. lten : flags := F_LE;
  1164. gtn : flags := F_G;
  1165. gten: flags := F_GE;
  1166. end;
  1167. clear_location(p^.location);
  1168. p^.location.loc := LOC_FLAGS;
  1169. p^.location.resflags := flags;
  1170. cmpop := false;
  1171. end
  1172. else
  1173. begin
  1174. clear_location(p^.location);
  1175. p^.location.loc := LOC_FPU;
  1176. if p^.left^.location.loc = LOC_FPU then
  1177. { copy fpu register result . }
  1178. { HERE ON EXIT FPU REGISTER IS IN EXTENDED MODE! }
  1179. p^.location.fpureg := p^.left^.location.fpureg
  1180. else
  1181. begin
  1182. InternalError(34);
  1183. end;
  1184. end;
  1185. end
  1186. else CGMessage(type_e_mismatch);
  1187. end;
  1188. SetResultLocation(cmpop,unsigned,p);
  1189. end;
  1190. end.
  1191. {
  1192. $Log$
  1193. Revision 1.20 2000-03-01 00:04:31 pierre
  1194. Use $GOTO ON
  1195. Revision 1.19 2000/02/09 13:22:48 peter
  1196. * log truncated
  1197. Revision 1.18 2000/01/07 01:14:21 peter
  1198. * updated copyright to 2000
  1199. Revision 1.17 1999/09/16 23:05:51 florian
  1200. * m68k compiler is again compilable (only gas writer, no assembler reader)
  1201. Revision 1.16 1999/09/16 11:34:52 pierre
  1202. * typo correction
  1203. }