cg386add.pas 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. Generate i386 assembler for in 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. unit cg386add;
  19. interface
  20. uses
  21. tree;
  22. procedure secondadd(var p : ptree);
  23. implementation
  24. uses
  25. cobjects,verbose,globals,systems,
  26. symtable,aasm,types,
  27. hcodegen,temp_gen,pass_2,
  28. i386,cgai386,tgeni386;
  29. {*****************************************************************************
  30. Helpers
  31. *****************************************************************************}
  32. procedure SetResultLocation(cmpop,unsigned:boolean;var p :ptree);
  33. var
  34. flags : tresflags;
  35. begin
  36. { remove temporary location if not a set or string }
  37. { that's a bad hack (FK) who did this ? }
  38. if (p^.left^.resulttype^.deftype<>stringdef) and
  39. ((p^.left^.resulttype^.deftype<>setdef) or (psetdef(p^.left^.resulttype)^.settype=smallset)) and
  40. (p^.left^.location.loc in [LOC_MEM,LOC_REFERENCE]) then
  41. ungetiftemp(p^.left^.location.reference);
  42. if (p^.right^.resulttype^.deftype<>stringdef) and
  43. ((p^.right^.resulttype^.deftype<>setdef) or (psetdef(p^.right^.resulttype)^.settype=smallset)) and
  44. (p^.right^.location.loc in [LOC_MEM,LOC_REFERENCE]) then
  45. ungetiftemp(p^.right^.location.reference);
  46. { in case of comparison operation the put result in the flags }
  47. if cmpop then
  48. begin
  49. if not(unsigned) then
  50. begin
  51. if p^.swaped then
  52. case p^.treetype of
  53. equaln : flags:=F_E;
  54. unequaln : flags:=F_NE;
  55. ltn : flags:=F_G;
  56. lten : flags:=F_GE;
  57. gtn : flags:=F_L;
  58. gten : flags:=F_LE;
  59. end
  60. else
  61. case p^.treetype of
  62. equaln : flags:=F_E;
  63. unequaln : flags:=F_NE;
  64. ltn : flags:=F_L;
  65. lten : flags:=F_LE;
  66. gtn : flags:=F_G;
  67. gten : flags:=F_GE;
  68. end;
  69. end
  70. else
  71. begin
  72. if p^.swaped then
  73. case p^.treetype of
  74. equaln : flags:=F_E;
  75. unequaln : flags:=F_NE;
  76. ltn : flags:=F_A;
  77. lten : flags:=F_AE;
  78. gtn : flags:=F_B;
  79. gten : flags:=F_BE;
  80. end
  81. else
  82. case p^.treetype of
  83. equaln : flags:=F_E;
  84. unequaln : flags:=F_NE;
  85. ltn : flags:=F_B;
  86. lten : flags:=F_BE;
  87. gtn : flags:=F_A;
  88. gten : flags:=F_AE;
  89. end;
  90. end;
  91. clear_location(p^.location);
  92. p^.location.loc:=LOC_FLAGS;
  93. p^.location.resflags:=flags;
  94. end;
  95. end;
  96. {*****************************************************************************
  97. Addstring
  98. *****************************************************************************}
  99. procedure addstring(var p : ptree);
  100. var
  101. pushedregs : tpushed;
  102. href : treference;
  103. pushed,
  104. cmpop : boolean;
  105. savedunused : tregisterset;
  106. hr : treference;
  107. begin
  108. { string operations are not commutative }
  109. if p^.swaped then
  110. swaptree(p);
  111. case pstringdef(p^.left^.resulttype)^.string_typ of
  112. st_ansistring:
  113. begin
  114. case p^.treetype of
  115. addn:
  116. begin
  117. cmpop:=false;
  118. secondpass(p^.left);
  119. pushed:=maybe_push(p^.right^.registers32,p);
  120. secondpass(p^.right);
  121. if pushed then restore(p);
  122. { release used registers }
  123. case p^.right^.location.loc of
  124. LOC_REFERENCE,LOC_MEM:
  125. del_reference(p^.right^.location.reference);
  126. LOC_REGISTER,LOC_CREGISTER:
  127. ungetregister32(p^.right^.location.register);
  128. end;
  129. case p^.left^.location.loc of
  130. LOC_REFERENCE,LOC_MEM:
  131. del_reference(p^.left^.location.reference);
  132. LOC_REGISTER,LOC_CREGISTER:
  133. ungetregister32(p^.left^.location.register);
  134. end;
  135. savedunused:=unused;
  136. { push the still used registers }
  137. pushusedregisters(pushedregs,$ff);
  138. { push data }
  139. case p^.right^.location.loc of
  140. LOC_REFERENCE,LOC_MEM:
  141. emit_push_mem(p^.right^.location.reference);
  142. LOC_REGISTER,LOC_CREGISTER:
  143. exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,p^.right^.location.register)));
  144. end;
  145. case p^.left^.location.loc of
  146. LOC_REFERENCE,LOC_MEM:
  147. emit_push_mem(p^.left^.location.reference);
  148. LOC_REGISTER,LOC_CREGISTER:
  149. exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,p^.left^.location.register)));
  150. end;
  151. emitcall('FPC_ANSICAT',true);
  152. unused:=savedunused;
  153. p^.location.register:=getexplicitregister32(R_EAX);
  154. emit_reg_reg(A_MOV,S_L,R_EAX,p^.location.register);
  155. popusedregisters(pushedregs);
  156. maybe_loadesi;
  157. ungetiftemp(p^.left^.location.reference);
  158. ungetiftemp(p^.right^.location.reference);
  159. gettempofsizereference(4,hr);
  160. temptoremove^.concat(new(ptemptodestroy,init(hr,p^.resulttype)));
  161. exprasmlist^.concat(new(pai386,op_reg_ref(A_MOV,S_L,p^.location.register,
  162. newreference(hr))));
  163. end;
  164. ltn,lten,gtn,gten,
  165. equaln,unequaln:
  166. begin
  167. secondpass(p^.left);
  168. pushed:=maybe_push(p^.right^.registers32,p);
  169. secondpass(p^.right);
  170. if pushed then restore(p);
  171. { release used registers }
  172. case p^.right^.location.loc of
  173. LOC_REFERENCE,LOC_MEM:
  174. del_reference(p^.right^.location.reference);
  175. LOC_REGISTER,LOC_CREGISTER:
  176. ungetregister32(p^.right^.location.register);
  177. end;
  178. case p^.left^.location.loc of
  179. LOC_REFERENCE,LOC_MEM:
  180. del_reference(p^.left^.location.reference);
  181. LOC_REGISTER,LOC_CREGISTER:
  182. ungetregister32(p^.left^.location.register);
  183. end;
  184. { push the still used registers }
  185. pushusedregisters(pushedregs,$ff);
  186. { push data }
  187. case p^.right^.location.loc of
  188. LOC_REFERENCE,LOC_MEM:
  189. emit_push_mem(p^.right^.location.reference);
  190. LOC_REGISTER,LOC_CREGISTER:
  191. exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,p^.right^.location.register)));
  192. end;
  193. case p^.left^.location.loc of
  194. LOC_REFERENCE,LOC_MEM:
  195. emit_push_mem(p^.left^.location.reference);
  196. LOC_REGISTER,LOC_CREGISTER:
  197. exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,p^.left^.location.register)));
  198. end;
  199. emitcall('FPC_ANSICOMPARE',true);
  200. emit_reg_reg(A_OR,S_L,R_EAX,R_EAX);
  201. popusedregisters(pushedregs);
  202. maybe_loadesi;
  203. ungetiftemp(p^.left^.location.reference);
  204. ungetiftemp(p^.right^.location.reference);
  205. end;
  206. end;
  207. { the result of ansicompare is signed }
  208. SetResultLocation(cmpop,false,p);
  209. end;
  210. st_shortstring:
  211. begin
  212. case p^.treetype of
  213. addn:
  214. begin
  215. cmpop:=false;
  216. secondpass(p^.left);
  217. { if str_concat is set in expr
  218. s:=s+ ... no need to create a temp string (PM) }
  219. if (p^.left^.treetype<>addn) and not (p^.use_strconcat) then
  220. begin
  221. { can only reference be }
  222. { string in register would be funny }
  223. { therefore produce a temporary string }
  224. { release the registers }
  225. del_reference(p^.left^.location.reference);
  226. gettempofsizereference(256,href);
  227. copystring(href,p^.left^.location.reference,255);
  228. ungetiftemp(p^.left^.location.reference);
  229. { does not hurt: }
  230. clear_location(p^.left^.location);
  231. p^.left^.location.loc:=LOC_MEM;
  232. p^.left^.location.reference:=href;
  233. end;
  234. secondpass(p^.right);
  235. { on the right we do not need the register anymore too }
  236. del_reference(p^.right^.location.reference);
  237. {
  238. if p^.right^.resulttype^.deftype=orddef then
  239. begin
  240. pushusedregisters(pushedregs,$ff);
  241. exprasmlist^.concat(new(pai386,op_ref_reg(
  242. A_LEA,S_L,newreference(p^.left^.location.reference),R_EDI)));
  243. exprasmlist^.concat(new(pai386,op_reg_reg(
  244. A_XOR,S_L,R_EBX,R_EBX)));
  245. reset_reference(href);
  246. href.base:=R_EDI;
  247. exprasmlist^.concat(new(pai386,op_ref_reg(
  248. A_MOV,S_B,newreference(href),R_BL)));
  249. exprasmlist^.concat(new(pai386,op_reg(
  250. A_INC,S_L,R_EBX)));
  251. exprasmlist^.concat(new(pai386,op_reg_ref(
  252. A_MOV,S_B,R_BL,newreference(href))));
  253. href.index:=R_EBX;
  254. if p^.right^.treetype=ordconstn then
  255. exprasmlist^.concat(new(pai386,op_const_ref(
  256. A_MOV,S_L,p^.right^.value,newreference(href))))
  257. else
  258. begin
  259. if p^.right^.location.loc in [LOC_CREGISTER,LOC_REGISTER] then
  260. exprasmlist^.concat(new(pai386,op_reg_ref(
  261. A_MOV,S_B,p^.right^.location.register,newreference(href))))
  262. else
  263. begin
  264. exprasmlist^.concat(new(pai386,op_ref_reg(
  265. A_MOV,S_L,newreference(p^.right^.location.reference),R_EAX)));
  266. exprasmlist^.concat(new(pai386,op_reg_ref(
  267. A_MOV,S_B,R_AL,newreference(href))));
  268. end;
  269. end;
  270. popusedregisters(pushedregs);
  271. end
  272. else }
  273. begin
  274. pushusedregisters(pushedregs,$ff);
  275. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  276. emitpushreferenceaddr(exprasmlist,p^.right^.location.reference);
  277. emitcall('FPC_STRCONCAT',true);
  278. maybe_loadesi;
  279. popusedregisters(pushedregs);
  280. end;
  281. set_location(p^.location,p^.left^.location);
  282. ungetiftemp(p^.right^.location.reference);
  283. end;
  284. ltn,lten,gtn,gten,
  285. equaln,unequaln :
  286. begin
  287. cmpop:=true;
  288. { generate better code for s='' and s<>'' }
  289. if (p^.treetype in [equaln,unequaln]) and
  290. (((p^.left^.treetype=stringconstn) and (str_length(p^.left)=0)) or
  291. ((p^.right^.treetype=stringconstn) and (str_length(p^.right)=0))) then
  292. begin
  293. secondpass(p^.left);
  294. { are too few registers free? }
  295. pushed:=maybe_push(p^.right^.registers32,p);
  296. secondpass(p^.right);
  297. if pushed then restore(p);
  298. del_reference(p^.right^.location.reference);
  299. del_reference(p^.left^.location.reference);
  300. { only one node can be stringconstn }
  301. { else pass 1 would have evaluted }
  302. { this node }
  303. if p^.left^.treetype=stringconstn then
  304. exprasmlist^.concat(new(pai386,op_const_ref(
  305. A_CMP,S_B,0,newreference(p^.right^.location.reference))))
  306. else
  307. exprasmlist^.concat(new(pai386,op_const_ref(
  308. A_CMP,S_B,0,newreference(p^.left^.location.reference))));
  309. end
  310. else
  311. begin
  312. pushusedregisters(pushedregs,$ff);
  313. secondpass(p^.left);
  314. del_reference(p^.left^.location.reference);
  315. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  316. secondpass(p^.right);
  317. del_reference(p^.right^.location.reference);
  318. emitpushreferenceaddr(exprasmlist,p^.right^.location.reference);
  319. emitcall('FPC_STRCMP',true);
  320. maybe_loadesi;
  321. popusedregisters(pushedregs);
  322. end;
  323. ungetiftemp(p^.left^.location.reference);
  324. ungetiftemp(p^.right^.location.reference);
  325. end;
  326. else CGMessage(type_e_mismatch);
  327. end;
  328. SetResultLocation(cmpop,true,p);
  329. end;
  330. end;
  331. end;
  332. {*****************************************************************************
  333. Addset
  334. *****************************************************************************}
  335. procedure addset(var p : ptree);
  336. var
  337. cmpop,
  338. pushed : boolean;
  339. href : treference;
  340. pushedregs : tpushed;
  341. begin
  342. cmpop:=false;
  343. { not commutative }
  344. if p^.swaped then
  345. swaptree(p);
  346. secondpass(p^.left);
  347. { are too few registers free? }
  348. pushed:=maybe_push(p^.right^.registers32,p);
  349. secondpass(p^.right);
  350. if codegenerror then
  351. exit;
  352. if pushed then
  353. restore(p);
  354. set_location(p^.location,p^.left^.location);
  355. { handle operations }
  356. case p^.treetype of
  357. equaln,
  358. unequaln : begin
  359. cmpop:=true;
  360. del_reference(p^.left^.location.reference);
  361. del_reference(p^.right^.location.reference);
  362. pushusedregisters(pushedregs,$ff);
  363. emitpushreferenceaddr(exprasmlist,p^.right^.location.reference);
  364. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  365. emitcall('FPC_SET_COMP_SETS',true);
  366. maybe_loadesi;
  367. popusedregisters(pushedregs);
  368. ungetiftemp(p^.left^.location.reference);
  369. ungetiftemp(p^.right^.location.reference);
  370. end;
  371. addn : begin
  372. { add can be an other SET or Range or Element ! }
  373. del_reference(p^.left^.location.reference);
  374. del_reference(p^.right^.location.reference);
  375. pushusedregisters(pushedregs,$ff);
  376. href.symbol:=nil;
  377. gettempofsizereference(32,href);
  378. { add a range or a single element? }
  379. if p^.right^.treetype=setelementn then
  380. begin
  381. concatcopy(p^.left^.location.reference,href,32,false);
  382. if assigned(p^.right^.right) then
  383. begin
  384. pushsetelement(p^.right^.right);
  385. pushsetelement(p^.right^.left);
  386. emitpushreferenceaddr(exprasmlist,href);
  387. emitcall('FPC_SET_SET_RANGE',true);
  388. end
  389. else
  390. begin
  391. pushsetelement(p^.right^.left);
  392. emitpushreferenceaddr(exprasmlist,href);
  393. emitcall('FPC_SET_SET_BYTE',true);
  394. end;
  395. end
  396. else
  397. begin
  398. { must be an other set }
  399. emitpushreferenceaddr(exprasmlist,href);
  400. emitpushreferenceaddr(exprasmlist,p^.right^.location.reference);
  401. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  402. emitcall('FPC_SET_ADD_SETS',true);
  403. end;
  404. maybe_loadesi;
  405. popusedregisters(pushedregs);
  406. ungetiftemp(p^.left^.location.reference);
  407. ungetiftemp(p^.right^.location.reference);
  408. p^.location.loc:=LOC_MEM;
  409. stringdispose(p^.location.reference.symbol);
  410. p^.location.reference:=href;
  411. end;
  412. subn,
  413. symdifn,
  414. muln : begin
  415. del_reference(p^.left^.location.reference);
  416. del_reference(p^.right^.location.reference);
  417. href.symbol:=nil;
  418. pushusedregisters(pushedregs,$ff);
  419. gettempofsizereference(32,href);
  420. emitpushreferenceaddr(exprasmlist,href);
  421. emitpushreferenceaddr(exprasmlist,p^.right^.location.reference);
  422. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  423. case p^.treetype of
  424. subn : emitcall('FPC_SET_SUB_SETS',true);
  425. symdifn : emitcall('FPC_SET_SYMDIF_SETS',true);
  426. muln : emitcall('FPC_SET_MUL_SETS',true);
  427. end;
  428. maybe_loadesi;
  429. popusedregisters(pushedregs);
  430. ungetiftemp(p^.left^.location.reference);
  431. ungetiftemp(p^.right^.location.reference);
  432. p^.location.loc:=LOC_MEM;
  433. stringdispose(p^.location.reference.symbol);
  434. p^.location.reference:=href;
  435. end;
  436. else
  437. CGMessage(type_e_mismatch);
  438. end;
  439. SetResultLocation(cmpop,true,p);
  440. end;
  441. {*****************************************************************************
  442. SecondAdd
  443. *****************************************************************************}
  444. procedure secondadd(var p : ptree);
  445. { is also being used for xor, and "mul", "sub, or and comparative }
  446. { operators }
  447. label do_normal;
  448. var
  449. hregister : tregister;
  450. noswap,popeax,popedx,
  451. pushed,mboverflow,cmpop : boolean;
  452. op : tasmop;
  453. flags : tresflags;
  454. otl,ofl : plabel;
  455. power : longint;
  456. opsize : topsize;
  457. hl4: plabel;
  458. { true, if unsigned types are compared }
  459. unsigned : boolean;
  460. { true, if a small set is handled with the longint code }
  461. is_set : boolean;
  462. { is_in_dest if the result is put directly into }
  463. { the resulting refernce or varregister }
  464. is_in_dest : boolean;
  465. { true, if for sets subtractions the extra not should generated }
  466. extra_not : boolean;
  467. {$ifdef SUPPORT_MMX}
  468. mmxbase : tmmxtype;
  469. {$endif SUPPORT_MMX}
  470. begin
  471. { to make it more readable, string and set (not smallset!) have their
  472. own procedures }
  473. case p^.left^.resulttype^.deftype of
  474. stringdef : begin
  475. addstring(p);
  476. exit;
  477. end;
  478. setdef : begin
  479. { normalsets are handled separate }
  480. if not(psetdef(p^.left^.resulttype)^.settype=smallset) then
  481. begin
  482. addset(p);
  483. exit;
  484. end;
  485. end;
  486. end;
  487. { defaults }
  488. unsigned:=false;
  489. is_in_dest:=false;
  490. extra_not:=false;
  491. noswap:=false;
  492. opsize:=S_L;
  493. { are we a (small)set, must be set here because the side can be
  494. swapped ! (PFV) }
  495. is_set:=(p^.left^.resulttype^.deftype=setdef);
  496. { calculate the operator which is more difficult }
  497. firstcomplex(p);
  498. { handling boolean expressions extra: }
  499. if ((p^.left^.resulttype^.deftype=orddef) and
  500. (porddef(p^.left^.resulttype)^.typ in [bool8bit,bool16bit,bool32bit])) or
  501. ((p^.right^.resulttype^.deftype=orddef) and
  502. (porddef(p^.right^.resulttype)^.typ in [bool8bit,bool16bit,bool32bit])) then
  503. begin
  504. if (porddef(p^.left^.resulttype)^.typ=bool8bit) or
  505. (porddef(p^.right^.resulttype)^.typ=bool8bit) then
  506. opsize:=S_B
  507. else
  508. if (porddef(p^.left^.resulttype)^.typ=bool16bit) or
  509. (porddef(p^.right^.resulttype)^.typ=bool16bit) then
  510. opsize:=S_W
  511. else
  512. opsize:=S_L;
  513. case p^.treetype of
  514. andn,
  515. orn : begin
  516. clear_location(p^.location);
  517. p^.location.loc:=LOC_JUMP;
  518. cmpop:=false;
  519. case p^.treetype of
  520. andn : begin
  521. otl:=truelabel;
  522. getlabel(truelabel);
  523. secondpass(p^.left);
  524. maketojumpbool(p^.left);
  525. emitl(A_LABEL,truelabel);
  526. truelabel:=otl;
  527. end;
  528. orn : begin
  529. ofl:=falselabel;
  530. getlabel(falselabel);
  531. secondpass(p^.left);
  532. maketojumpbool(p^.left);
  533. emitl(A_LABEL,falselabel);
  534. falselabel:=ofl;
  535. end;
  536. else
  537. CGMessage(type_e_mismatch);
  538. end;
  539. secondpass(p^.right);
  540. maketojumpbool(p^.right);
  541. end;
  542. unequaln,
  543. equaln,xorn : begin
  544. if p^.left^.treetype=ordconstn then
  545. swaptree(p);
  546. secondpass(p^.left);
  547. set_location(p^.location,p^.left^.location);
  548. {p^.location:=p^.left^.location;
  549. created a bug !!! PM
  550. because symbol was used twice }
  551. { are enough registers free ? }
  552. pushed:=maybe_push(p^.right^.registers32,p);
  553. secondpass(p^.right);
  554. if pushed then restore(p);
  555. goto do_normal;
  556. end
  557. else
  558. CGMessage(type_e_mismatch);
  559. end
  560. end
  561. else
  562. begin
  563. { in case of constant put it to the left }
  564. if (p^.left^.treetype=ordconstn) then
  565. swaptree(p);
  566. secondpass(p^.left);
  567. { this will be complicated as
  568. a lot of code below assumes that
  569. p^.location and p^.left^.location are the same }
  570. {$ifdef test_dest_loc}
  571. if dest_loc_known and (dest_loc_tree=p) and
  572. ((dest_loc.loc=LOC_REGISTER) or (dest_loc.loc=LOC_CREGISTER)) then
  573. begin
  574. set_location(p^.location,dest_loc);
  575. in_dest_loc:=true;
  576. is_in_dest:=true;
  577. end
  578. else
  579. {$endif test_dest_loc}
  580. set_location(p^.location,p^.left^.location);
  581. { are too few registers free? }
  582. pushed:=maybe_push(p^.right^.registers32,p);
  583. secondpass(p^.right);
  584. if pushed then
  585. restore(p);
  586. if (p^.left^.resulttype^.deftype=pointerdef) or
  587. (p^.right^.resulttype^.deftype=pointerdef) or
  588. ((p^.right^.resulttype^.deftype=objectdef) and
  589. pobjectdef(p^.right^.resulttype)^.isclass and
  590. (p^.left^.resulttype^.deftype=objectdef) and
  591. pobjectdef(p^.left^.resulttype)^.isclass
  592. ) or
  593. (p^.left^.resulttype^.deftype=classrefdef) or
  594. (p^.left^.resulttype^.deftype=procvardef) or
  595. (p^.left^.resulttype^.deftype=enumdef) or
  596. ((p^.left^.resulttype^.deftype=orddef) and
  597. (porddef(p^.left^.resulttype)^.typ=s32bit)) or
  598. ((p^.right^.resulttype^.deftype=orddef) and
  599. (porddef(p^.right^.resulttype)^.typ=s32bit)) or
  600. ((p^.left^.resulttype^.deftype=orddef) and
  601. (porddef(p^.left^.resulttype)^.typ=u32bit)) or
  602. ((p^.right^.resulttype^.deftype=orddef) and
  603. (porddef(p^.right^.resulttype)^.typ=u32bit)) or
  604. { as well as small sets }
  605. is_set then
  606. begin
  607. do_normal:
  608. mboverflow:=false;
  609. cmpop:=false;
  610. if (p^.left^.resulttype^.deftype=pointerdef) or
  611. (p^.right^.resulttype^.deftype=pointerdef) or
  612. ((p^.left^.resulttype^.deftype=orddef) and
  613. (porddef(p^.left^.resulttype)^.typ=u32bit)) or
  614. ((p^.right^.resulttype^.deftype=orddef) and
  615. (porddef(p^.right^.resulttype)^.typ=u32bit)) then
  616. unsigned:=true;
  617. case p^.treetype of
  618. addn : begin
  619. if is_set then
  620. begin
  621. { adding elements is not commutative }
  622. if p^.swaped and (p^.left^.treetype=setelementn) then
  623. swaptree(p);
  624. { are we adding set elements ? }
  625. if p^.right^.treetype=setelementn then
  626. begin
  627. { no range support for smallsets! }
  628. if assigned(p^.right^.right) then
  629. internalerror(43244);
  630. { bts requires both elements to be registers }
  631. if p^.left^.location.loc in [LOC_MEM,LOC_REFERENCE] then
  632. begin
  633. ungetiftemp(p^.left^.location.reference);
  634. del_reference(p^.left^.location.reference);
  635. hregister:=getregister32;
  636. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,opsize,
  637. newreference(p^.left^.location.reference),hregister)));
  638. clear_location(p^.left^.location);
  639. p^.left^.location.loc:=LOC_REGISTER;
  640. p^.left^.location.register:=hregister;
  641. set_location(p^.location,p^.left^.location);
  642. end;
  643. if p^.right^.location.loc in [LOC_MEM,LOC_REFERENCE] then
  644. begin
  645. ungetiftemp(p^.right^.location.reference);
  646. del_reference(p^.right^.location.reference);
  647. hregister:=getregister32;
  648. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,opsize,
  649. newreference(p^.right^.location.reference),hregister)));
  650. clear_location(p^.right^.location);
  651. p^.right^.location.loc:=LOC_REGISTER;
  652. p^.right^.location.register:=hregister;
  653. end;
  654. op:=A_BTS;
  655. noswap:=true;
  656. end
  657. else
  658. op:=A_OR;
  659. mboverflow:=false;
  660. unsigned:=false;
  661. end
  662. else
  663. begin
  664. op:=A_ADD;
  665. mboverflow:=true;
  666. end;
  667. end;
  668. symdifn : begin
  669. { the symetric diff is only for sets }
  670. if is_set then
  671. begin
  672. op:=A_XOR;
  673. mboverflow:=false;
  674. unsigned:=false;
  675. end
  676. else
  677. CGMessage(type_e_mismatch);
  678. end;
  679. muln : begin
  680. if is_set then
  681. begin
  682. op:=A_AND;
  683. mboverflow:=false;
  684. unsigned:=false;
  685. end
  686. else
  687. begin
  688. if unsigned then
  689. op:=A_MUL
  690. else
  691. op:=A_IMUL;
  692. mboverflow:=true;
  693. end;
  694. end;
  695. subn : begin
  696. if is_set then
  697. begin
  698. op:=A_AND;
  699. mboverflow:=false;
  700. unsigned:=false;
  701. extra_not:=true;
  702. end
  703. else
  704. begin
  705. op:=A_SUB;
  706. mboverflow:=true;
  707. end;
  708. end;
  709. ltn,lten,
  710. gtn,gten,
  711. equaln,unequaln : begin
  712. op:=A_CMP;
  713. cmpop:=true;
  714. end;
  715. xorn : op:=A_XOR;
  716. orn : op:=A_OR;
  717. andn : op:=A_AND;
  718. else
  719. CGMessage(type_e_mismatch);
  720. end;
  721. { filter MUL, which requires special handling }
  722. if op=A_MUL then
  723. begin
  724. popeax:=false;
  725. popedx:=false;
  726. p^.location.register:=getregister32;
  727. p^.location.loc:=LOC_REGISTER;
  728. if not(R_EAX in unused) and (p^.location.register<>R_EAX) then
  729. begin
  730. exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,R_EAX)));
  731. popeax:=true;
  732. end;
  733. if not(R_EDX in unused) and (p^.location.register<>R_EDX) then
  734. begin
  735. exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,R_EDX)));
  736. popedx:=true;
  737. end;
  738. emitloadord2reg(p^.left^.location,u32bitdef,R_EDI,true);
  739. emitloadord2reg(p^.right^.location,u32bitdef,R_EAX,true);
  740. exprasmlist^.concat(new(pai386,op_reg(A_MUL,S_L,R_EDI)));
  741. emit_reg_reg(A_MOV,S_L,R_EAX,p^.location.register);
  742. if popeax then
  743. exprasmlist^.concat(new(pai386,op_reg(A_POP,S_L,R_EAX)));
  744. if popedx then
  745. exprasmlist^.concat(new(pai386,op_reg(A_POP,S_L,R_EDX)));
  746. SetResultLocation(false,true,p);
  747. exit;
  748. end;
  749. { left and right no register? }
  750. { then one must be demanded }
  751. if (p^.left^.location.loc<>LOC_REGISTER) and
  752. (p^.right^.location.loc<>LOC_REGISTER) then
  753. begin
  754. { register variable ? }
  755. if (p^.left^.location.loc=LOC_CREGISTER) then
  756. begin
  757. { it is OK if this is the destination }
  758. if is_in_dest then
  759. begin
  760. hregister:=p^.location.register;
  761. emit_reg_reg(A_MOV,opsize,p^.left^.location.register,
  762. hregister);
  763. end
  764. else
  765. if cmpop then
  766. begin
  767. { do not disturb the register }
  768. hregister:=p^.location.register;
  769. end
  770. else
  771. begin
  772. case opsize of
  773. S_L : hregister:=getregister32;
  774. S_B : hregister:=reg32toreg8(getregister32);
  775. end;
  776. emit_reg_reg(A_MOV,opsize,p^.left^.location.register,
  777. hregister);
  778. end
  779. end
  780. else
  781. begin
  782. del_reference(p^.left^.location.reference);
  783. if is_in_dest then
  784. begin
  785. hregister:=p^.location.register;
  786. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,opsize,
  787. newreference(p^.left^.location.reference),hregister)));
  788. end
  789. else
  790. begin
  791. { first give free, then demand new register }
  792. case opsize of
  793. S_L : hregister:=getregister32;
  794. S_W : hregister:=reg32toreg16(getregister32);
  795. S_B : hregister:=reg32toreg8(getregister32);
  796. end;
  797. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,opsize,
  798. newreference(p^.left^.location.reference),hregister)));
  799. end;
  800. end;
  801. clear_location(p^.location);
  802. p^.location.loc:=LOC_REGISTER;
  803. p^.location.register:=hregister;
  804. end
  805. else
  806. { if on the right the register then swap }
  807. if not(noswap) and (p^.right^.location.loc=LOC_REGISTER) then
  808. begin
  809. swap_location(p^.location,p^.right^.location);
  810. { newly swapped also set swapped flag }
  811. p^.swaped:=not(p^.swaped);
  812. end;
  813. { at this point, p^.location.loc should be LOC_REGISTER }
  814. { and p^.location.register should be a valid register }
  815. { containing the left result }
  816. if p^.right^.location.loc<>LOC_REGISTER then
  817. begin
  818. if (p^.treetype=subn) and p^.swaped then
  819. begin
  820. if p^.right^.location.loc=LOC_CREGISTER then
  821. begin
  822. if extra_not then
  823. exprasmlist^.concat(new(pai386,op_reg(A_NOT,opsize,p^.location.register)));
  824. emit_reg_reg(A_MOV,opsize,p^.right^.location.register,R_EDI);
  825. emit_reg_reg(op,opsize,p^.location.register,R_EDI);
  826. emit_reg_reg(A_MOV,opsize,R_EDI,p^.location.register);
  827. end
  828. else
  829. begin
  830. if extra_not then
  831. exprasmlist^.concat(new(pai386,op_reg(A_NOT,opsize,p^.location.register)));
  832. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,opsize,
  833. newreference(p^.right^.location.reference),R_EDI)));
  834. exprasmlist^.concat(new(pai386,op_reg_reg(op,opsize,p^.location.register,R_EDI)));
  835. exprasmlist^.concat(new(pai386,op_reg_reg(A_MOV,opsize,R_EDI,p^.location.register)));
  836. del_reference(p^.right^.location.reference);
  837. end;
  838. end
  839. else
  840. begin
  841. if (p^.right^.treetype=ordconstn) and
  842. (op=A_CMP) and
  843. (p^.right^.value=0) then
  844. begin
  845. exprasmlist^.concat(new(pai386,op_reg_reg(A_TEST,opsize,p^.location.register,
  846. p^.location.register)));
  847. end
  848. else if (p^.right^.treetype=ordconstn) and
  849. (op=A_ADD) and
  850. (p^.right^.value=1) then
  851. begin
  852. exprasmlist^.concat(new(pai386,op_reg(A_INC,opsize,
  853. p^.location.register)));
  854. end
  855. else if (p^.right^.treetype=ordconstn) and
  856. (op=A_SUB) and
  857. (p^.right^.value=1) then
  858. begin
  859. exprasmlist^.concat(new(pai386,op_reg(A_DEC,opsize,
  860. p^.location.register)));
  861. end
  862. else if (p^.right^.treetype=ordconstn) and
  863. (op=A_IMUL) and
  864. (ispowerof2(p^.right^.value,power)) then
  865. begin
  866. exprasmlist^.concat(new(pai386,op_const_reg(A_SHL,opsize,power,
  867. p^.location.register)));
  868. end
  869. else
  870. begin
  871. if (p^.right^.location.loc=LOC_CREGISTER) then
  872. begin
  873. if extra_not then
  874. begin
  875. emit_reg_reg(A_MOV,S_L,p^.right^.location.register,R_EDI);
  876. exprasmlist^.concat(new(pai386,op_reg(A_NOT,S_L,R_EDI)));
  877. emit_reg_reg(A_AND,S_L,R_EDI,
  878. p^.location.register);
  879. end
  880. else
  881. begin
  882. emit_reg_reg(op,opsize,p^.right^.location.register,
  883. p^.location.register);
  884. end;
  885. end
  886. else
  887. begin
  888. if extra_not then
  889. begin
  890. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_L,newreference(
  891. p^.right^.location.reference),R_EDI)));
  892. exprasmlist^.concat(new(pai386,op_reg(A_NOT,S_L,R_EDI)));
  893. emit_reg_reg(A_AND,S_L,R_EDI,
  894. p^.location.register);
  895. end
  896. else
  897. begin
  898. exprasmlist^.concat(new(pai386,op_ref_reg(op,opsize,newreference(
  899. p^.right^.location.reference),p^.location.register)));
  900. end;
  901. del_reference(p^.right^.location.reference);
  902. end;
  903. end;
  904. end;
  905. end
  906. else
  907. begin
  908. { when swapped another result register }
  909. if (p^.treetype=subn) and p^.swaped then
  910. begin
  911. if extra_not then
  912. exprasmlist^.concat(new(pai386,op_reg(A_NOT,S_L,p^.location.register)));
  913. exprasmlist^.concat(new(pai386,op_reg_reg(op,opsize,
  914. p^.location.register,p^.right^.location.register)));
  915. swap_location(p^.location,p^.right^.location);
  916. { newly swapped also set swapped flag }
  917. { just to maintain ordering }
  918. p^.swaped:=not(p^.swaped);
  919. end
  920. else
  921. begin
  922. if extra_not then
  923. exprasmlist^.concat(new(pai386,op_reg(A_NOT,S_L,p^.right^.location.register)));
  924. exprasmlist^.concat(new(pai386,op_reg_reg(op,opsize,
  925. p^.right^.location.register,
  926. p^.location.register)));
  927. end;
  928. case opsize of
  929. S_L : ungetregister32(p^.right^.location.register);
  930. S_B : ungetregister32(reg8toreg32(p^.right^.location.register));
  931. end;
  932. end;
  933. if cmpop then
  934. case opsize of
  935. S_L : ungetregister32(p^.location.register);
  936. S_B : ungetregister32(reg8toreg32(p^.location.register));
  937. end;
  938. { only in case of overflow operations }
  939. { produce overflow code }
  940. { we must put it here directly, because sign of operation }
  941. { is in unsigned VAR!! }
  942. if mboverflow then
  943. begin
  944. if cs_check_overflow in aktlocalswitches then
  945. begin
  946. getlabel(hl4);
  947. if unsigned then
  948. emitl(A_JNB,hl4)
  949. else
  950. emitl(A_JNO,hl4);
  951. emitcall('FPC_OVERFLOW',true);
  952. emitl(A_LABEL,hl4);
  953. end;
  954. end;
  955. end
  956. else
  957. { Char type }
  958. if ((p^.left^.resulttype^.deftype=orddef) and
  959. (porddef(p^.left^.resulttype)^.typ=uchar)) then
  960. begin
  961. case p^.treetype of
  962. ltn,lten,gtn,gten,
  963. equaln,unequaln :
  964. cmpop:=true;
  965. else CGMessage(type_e_mismatch);
  966. end;
  967. unsigned:=true;
  968. { left and right no register? }
  969. { the one must be demanded }
  970. if (p^.location.loc<>LOC_REGISTER) and
  971. (p^.right^.location.loc<>LOC_REGISTER) then
  972. begin
  973. if p^.location.loc=LOC_CREGISTER then
  974. begin
  975. if cmpop then
  976. { do not disturb register }
  977. hregister:=p^.location.register
  978. else
  979. begin
  980. hregister:=reg32toreg8(getregister32);
  981. emit_reg_reg(A_MOV,S_B,p^.location.register,
  982. hregister);
  983. end;
  984. end
  985. else
  986. begin
  987. del_reference(p^.location.reference);
  988. { first give free then demand new register }
  989. hregister:=reg32toreg8(getregister32);
  990. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_B,newreference(p^.location.reference),
  991. hregister)));
  992. end;
  993. clear_location(p^.location);
  994. p^.location.loc:=LOC_REGISTER;
  995. p^.location.register:=hregister;
  996. end;
  997. { now p always a register }
  998. if (p^.right^.location.loc=LOC_REGISTER) and
  999. (p^.location.loc<>LOC_REGISTER) then
  1000. begin
  1001. swap_location(p^.location,p^.right^.location);
  1002. { newly swapped also set swapped flag }
  1003. p^.swaped:=not(p^.swaped);
  1004. end;
  1005. if p^.right^.location.loc<>LOC_REGISTER then
  1006. begin
  1007. if p^.right^.location.loc=LOC_CREGISTER then
  1008. begin
  1009. emit_reg_reg(A_CMP,S_B,
  1010. p^.right^.location.register,p^.location.register);
  1011. end
  1012. else
  1013. begin
  1014. exprasmlist^.concat(new(pai386,op_ref_reg(A_CMP,S_B,newreference(
  1015. p^.right^.location.reference),p^.location.register)));
  1016. del_reference(p^.right^.location.reference);
  1017. end;
  1018. end
  1019. else
  1020. begin
  1021. emit_reg_reg(A_CMP,S_B,p^.right^.location.register,
  1022. p^.location.register);
  1023. ungetregister32(reg8toreg32(p^.right^.location.register));
  1024. end;
  1025. ungetregister32(reg8toreg32(p^.location.register));
  1026. end
  1027. else
  1028. { Floating point }
  1029. if (p^.left^.resulttype^.deftype=floatdef) and
  1030. (pfloatdef(p^.left^.resulttype)^.typ<>f32bit) then
  1031. begin
  1032. { real constants to the left }
  1033. if p^.left^.treetype=realconstn then
  1034. swaptree(p);
  1035. cmpop:=false;
  1036. case p^.treetype of
  1037. addn : op:=A_FADDP;
  1038. muln : op:=A_FMULP;
  1039. subn : op:=A_FSUBP;
  1040. slashn : op:=A_FDIVP;
  1041. ltn,lten,gtn,gten,
  1042. equaln,unequaln : begin
  1043. op:=A_FCOMPP;
  1044. cmpop:=true;
  1045. end;
  1046. else CGMessage(type_e_mismatch);
  1047. end;
  1048. if (p^.right^.location.loc<>LOC_FPU) then
  1049. begin
  1050. floatload(pfloatdef(p^.right^.resulttype)^.typ,p^.right^.location.reference);
  1051. if (p^.left^.location.loc<>LOC_FPU) then
  1052. floatload(pfloatdef(p^.left^.resulttype)^.typ,p^.left^.location.reference)
  1053. { left was on the stack => swap }
  1054. else
  1055. p^.swaped:=not(p^.swaped);
  1056. { releases the right reference }
  1057. del_reference(p^.right^.location.reference);
  1058. end
  1059. { the nominator in st0 }
  1060. else if (p^.left^.location.loc<>LOC_FPU) then
  1061. floatload(pfloatdef(p^.left^.resulttype)^.typ,p^.left^.location.reference)
  1062. { fpu operands are always in the wrong order on the stack }
  1063. else
  1064. p^.swaped:=not(p^.swaped);
  1065. { releases the left reference }
  1066. if (p^.left^.location.loc<>LOC_FPU) then
  1067. del_reference(p^.left^.location.reference);
  1068. { if we swaped the tree nodes, then use the reverse operator }
  1069. if p^.swaped then
  1070. begin
  1071. if (p^.treetype=slashn) then
  1072. op:=A_FDIVRP
  1073. else if (p^.treetype=subn) then
  1074. op:=A_FSUBRP;
  1075. end;
  1076. { to avoid the pentium bug
  1077. if (op=FDIVP) and (opt_processors=pentium) then
  1078. exprasmlist^.concat(new(pai386,op_CALL,S_NO,'EMUL_FDIVP')
  1079. else
  1080. }
  1081. { the Intel assemblers want operands }
  1082. if op<>A_FCOMPP then
  1083. exprasmlist^.concat(new(pai386,op_reg_reg(op,S_NO,R_ST,R_ST1)))
  1084. else
  1085. exprasmlist^.concat(new(pai386,op_none(op,S_NO)));
  1086. { on comparison load flags }
  1087. if cmpop then
  1088. begin
  1089. if not(R_EAX in unused) then
  1090. emit_reg_reg(A_MOV,S_L,R_EAX,R_EDI);
  1091. exprasmlist^.concat(new(pai386,op_reg(A_FNSTSW,S_NO,R_AX)));
  1092. exprasmlist^.concat(new(pai386,op_none(A_SAHF,S_NO)));
  1093. if not(R_EAX in unused) then
  1094. emit_reg_reg(A_MOV,S_L,R_EDI,R_EAX);
  1095. if p^.swaped then
  1096. begin
  1097. case p^.treetype of
  1098. equaln : flags:=F_E;
  1099. unequaln : flags:=F_NE;
  1100. ltn : flags:=F_A;
  1101. lten : flags:=F_AE;
  1102. gtn : flags:=F_B;
  1103. gten : flags:=F_BE;
  1104. end;
  1105. end
  1106. else
  1107. begin
  1108. case p^.treetype of
  1109. equaln : flags:=F_E;
  1110. unequaln : flags:=F_NE;
  1111. ltn : flags:=F_B;
  1112. lten : flags:=F_BE;
  1113. gtn : flags:=F_A;
  1114. gten : flags:=F_AE;
  1115. end;
  1116. end;
  1117. clear_location(p^.location);
  1118. p^.location.loc:=LOC_FLAGS;
  1119. p^.location.resflags:=flags;
  1120. cmpop:=false;
  1121. end
  1122. else
  1123. begin
  1124. clear_location(p^.location);
  1125. p^.location.loc:=LOC_FPU;
  1126. end;
  1127. end
  1128. {$ifdef SUPPORT_MMX}
  1129. else
  1130. { MMX Arrays }
  1131. if is_mmx_able_array(p^.left^.resulttype) then
  1132. begin
  1133. cmpop:=false;
  1134. mmxbase:=mmx_type(p^.left^.resulttype);
  1135. case p^.treetype of
  1136. addn : begin
  1137. if (cs_mmx_saturation in aktlocalswitches) then
  1138. begin
  1139. case mmxbase of
  1140. mmxs8bit:
  1141. op:=A_PADDSB;
  1142. mmxu8bit:
  1143. op:=A_PADDUSB;
  1144. mmxs16bit,mmxfixed16:
  1145. op:=A_PADDSB;
  1146. mmxu16bit:
  1147. op:=A_PADDUSW;
  1148. end;
  1149. end
  1150. else
  1151. begin
  1152. case mmxbase of
  1153. mmxs8bit,mmxu8bit:
  1154. op:=A_PADDB;
  1155. mmxs16bit,mmxu16bit,mmxfixed16:
  1156. op:=A_PADDW;
  1157. mmxs32bit,mmxu32bit:
  1158. op:=A_PADDD;
  1159. end;
  1160. end;
  1161. end;
  1162. muln : begin
  1163. case mmxbase of
  1164. mmxs16bit,mmxu16bit:
  1165. op:=A_PMULLW;
  1166. mmxfixed16:
  1167. op:=A_PMULHW;
  1168. end;
  1169. end;
  1170. subn : begin
  1171. if (cs_mmx_saturation in aktlocalswitches) then
  1172. begin
  1173. case mmxbase of
  1174. mmxs8bit:
  1175. op:=A_PSUBSB;
  1176. mmxu8bit:
  1177. op:=A_PSUBUSB;
  1178. mmxs16bit,mmxfixed16:
  1179. op:=A_PSUBSB;
  1180. mmxu16bit:
  1181. op:=A_PSUBUSW;
  1182. end;
  1183. end
  1184. else
  1185. begin
  1186. case mmxbase of
  1187. mmxs8bit,mmxu8bit:
  1188. op:=A_PSUBB;
  1189. mmxs16bit,mmxu16bit,mmxfixed16:
  1190. op:=A_PSUBW;
  1191. mmxs32bit,mmxu32bit:
  1192. op:=A_PSUBD;
  1193. end;
  1194. end;
  1195. end;
  1196. {
  1197. ltn,lten,gtn,gten,
  1198. equaln,unequaln :
  1199. begin
  1200. op:=A_CMP;
  1201. cmpop:=true;
  1202. end;
  1203. }
  1204. xorn:
  1205. op:=A_PXOR;
  1206. orn:
  1207. op:=A_POR;
  1208. andn:
  1209. op:=A_PAND;
  1210. else CGMessage(type_e_mismatch);
  1211. end;
  1212. { left and right no register? }
  1213. { then one must be demanded }
  1214. if (p^.left^.location.loc<>LOC_MMXREGISTER) and
  1215. (p^.right^.location.loc<>LOC_MMXREGISTER) then
  1216. begin
  1217. { register variable ? }
  1218. if (p^.left^.location.loc=LOC_CMMXREGISTER) then
  1219. begin
  1220. { it is OK if this is the destination }
  1221. if is_in_dest then
  1222. begin
  1223. hregister:=p^.location.register;
  1224. emit_reg_reg(A_MOVQ,S_NO,p^.left^.location.register,
  1225. hregister);
  1226. end
  1227. else
  1228. begin
  1229. hregister:=getregistermmx;
  1230. emit_reg_reg(A_MOVQ,S_NO,p^.left^.location.register,
  1231. hregister);
  1232. end
  1233. end
  1234. else
  1235. begin
  1236. del_reference(p^.left^.location.reference);
  1237. if is_in_dest then
  1238. begin
  1239. hregister:=p^.location.register;
  1240. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOVQ,S_NO,
  1241. newreference(p^.left^.location.reference),hregister)));
  1242. end
  1243. else
  1244. begin
  1245. hregister:=getregistermmx;
  1246. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOVQ,S_NO,
  1247. newreference(p^.left^.location.reference),hregister)));
  1248. end;
  1249. end;
  1250. clear_location(p^.location);
  1251. p^.location.loc:=LOC_MMXREGISTER;
  1252. p^.location.register:=hregister;
  1253. end
  1254. else
  1255. { if on the right the register then swap }
  1256. if (p^.right^.location.loc=LOC_MMXREGISTER) then
  1257. begin
  1258. swap_location(p^.location,p^.right^.location);
  1259. { newly swapped also set swapped flag }
  1260. p^.swaped:=not(p^.swaped);
  1261. end;
  1262. { at this point, p^.location.loc should be LOC_MMXREGISTER }
  1263. { and p^.location.register should be a valid register }
  1264. { containing the left result }
  1265. if p^.right^.location.loc<>LOC_MMXREGISTER then
  1266. begin
  1267. if (p^.treetype=subn) and p^.swaped then
  1268. begin
  1269. if p^.right^.location.loc=LOC_CMMXREGISTER then
  1270. begin
  1271. emit_reg_reg(A_MOVQ,S_NO,p^.right^.location.register,R_MM7);
  1272. emit_reg_reg(op,S_NO,p^.location.register,R_EDI);
  1273. emit_reg_reg(A_MOVQ,S_NO,R_MM7,p^.location.register);
  1274. end
  1275. else
  1276. begin
  1277. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOVQ,S_NO,
  1278. newreference(p^.right^.location.reference),R_MM7)));
  1279. exprasmlist^.concat(new(pai386,op_reg_reg(op,S_NO,p^.location.register,
  1280. R_MM7)));
  1281. exprasmlist^.concat(new(pai386,op_reg_reg(A_MOVQ,S_NO,
  1282. R_MM7,p^.location.register)));
  1283. del_reference(p^.right^.location.reference);
  1284. end;
  1285. end
  1286. else
  1287. begin
  1288. if (p^.right^.location.loc=LOC_CREGISTER) then
  1289. begin
  1290. emit_reg_reg(op,S_NO,p^.right^.location.register,
  1291. p^.location.register);
  1292. end
  1293. else
  1294. begin
  1295. exprasmlist^.concat(new(pai386,op_ref_reg(op,S_NO,newreference(
  1296. p^.right^.location.reference),p^.location.register)));
  1297. del_reference(p^.right^.location.reference);
  1298. end;
  1299. end;
  1300. end
  1301. else
  1302. begin
  1303. { when swapped another result register }
  1304. if (p^.treetype=subn) and p^.swaped then
  1305. begin
  1306. exprasmlist^.concat(new(pai386,op_reg_reg(op,S_NO,
  1307. p^.location.register,p^.right^.location.register)));
  1308. swap_location(p^.location,p^.right^.location);
  1309. { newly swapped also set swapped flag }
  1310. { just to maintain ordering }
  1311. p^.swaped:=not(p^.swaped);
  1312. end
  1313. else
  1314. begin
  1315. exprasmlist^.concat(new(pai386,op_reg_reg(op,S_NO,
  1316. p^.right^.location.register,
  1317. p^.location.register)));
  1318. end;
  1319. ungetregistermmx(p^.right^.location.register);
  1320. end;
  1321. end
  1322. {$endif SUPPORT_MMX}
  1323. else CGMessage(type_e_mismatch);
  1324. end;
  1325. SetResultLocation(cmpop,unsigned,p);
  1326. end;
  1327. end.
  1328. {
  1329. $Log$
  1330. Revision 1.24 1998-11-07 12:49:30 peter
  1331. * fixed ansicompare which returns signed
  1332. Revision 1.23 1998/10/29 15:42:43 florian
  1333. + partial disposing of temp. ansistrings
  1334. Revision 1.22 1998/10/28 18:26:12 pierre
  1335. * removed some erros after other errors (introduced by useexcept)
  1336. * stabs works again correctly (for how long !)
  1337. Revision 1.21 1998/10/25 23:32:48 peter
  1338. * fixed unsigned mul
  1339. Revision 1.20 1998/10/21 08:39:56 florian
  1340. + ansistring operator +
  1341. + $h and string[n] for n>255 added
  1342. * small problem with TP fixed
  1343. Revision 1.19 1998/10/20 15:09:21 florian
  1344. + binary operators for ansi strings
  1345. Revision 1.18 1998/10/20 08:06:38 pierre
  1346. * several memory corruptions due to double freemem solved
  1347. => never use p^.loc.location:=p^.left^.loc.location;
  1348. + finally I added now by default
  1349. that ra386dir translates global and unit symbols
  1350. + added a first field in tsymtable and
  1351. a nextsym field in tsym
  1352. (this allows to obtain ordered type info for
  1353. records and objects in gdb !)
  1354. Revision 1.17 1998/10/09 11:47:45 pierre
  1355. * still more memory leaks fixes !!
  1356. Revision 1.16 1998/10/09 08:56:21 pierre
  1357. * several memory leaks fixed
  1358. Revision 1.15 1998/10/08 17:17:10 pierre
  1359. * current_module old scanner tagged as invalid if unit is recompiled
  1360. + added ppheap for better info on tracegetmem of heaptrc
  1361. (adds line column and file index)
  1362. * several memory leaks removed ith help of heaptrc !!
  1363. Revision 1.14 1998/09/28 16:57:13 pierre
  1364. * changed all length(p^.value_str^) into str_length(p)
  1365. to get it work with and without ansistrings
  1366. * changed sourcefiles field of tmodule to a pointer
  1367. Revision 1.13 1998/09/17 09:42:09 peter
  1368. + pass_2 for cg386
  1369. * Message() -> CGMessage() for pass_1/pass_2
  1370. Revision 1.12 1998/09/14 10:43:44 peter
  1371. * all internal RTL functions start with FPC_
  1372. Revision 1.11 1998/09/07 18:45:52 peter
  1373. * update smartlinking, uses getdatalabel
  1374. * renamed ptree.value vars to value_str,value_real,value_set
  1375. Revision 1.10 1998/09/04 10:05:04 florian
  1376. * ugly fix for STRCAT, nevertheless it needs more fixing !!!!!!!
  1377. we need an new version of STRCAT which takes a length parameter
  1378. Revision 1.9 1998/09/04 08:41:36 peter
  1379. * updated some error CGMessages
  1380. Revision 1.8 1998/08/28 10:54:18 peter
  1381. * fixed smallset generation from elements, it has never worked before!
  1382. Revision 1.7 1998/08/19 14:56:59 peter
  1383. * forgot to removed some unused code in addset for set<>set
  1384. Revision 1.6 1998/08/18 09:24:35 pierre
  1385. * small warning position bug fixed
  1386. * support_mmx switches splitting was missing
  1387. * rhide error and warning output corrected
  1388. Revision 1.5 1998/08/14 18:18:37 peter
  1389. + dynamic set contruction
  1390. * smallsets are now working (always longint size)
  1391. Revision 1.4 1998/08/10 14:49:42 peter
  1392. + localswitches, moduleswitches, globalswitches splitting
  1393. Revision 1.3 1998/06/25 08:48:04 florian
  1394. * first version of rtti support
  1395. Revision 1.2 1998/06/08 13:13:28 pierre
  1396. + temporary variables now in temp_gen.pas unit
  1397. because it is processor independent
  1398. * mppc68k.bat modified to undefine i386 and support_mmx
  1399. (which are defaults for i386)
  1400. Revision 1.1 1998/06/05 17:44:10 peter
  1401. * splitted cgi386
  1402. }