ncgadd.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by the FPC development team
  4. Code generation for add nodes (generic version)
  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 ncgadd;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,nadd,cpubase;
  23. type
  24. tcgaddnode = class(taddnode)
  25. { function pass_1: tnode; override;}
  26. procedure pass_2;override;
  27. protected
  28. { call secondpass for both left and right }
  29. procedure pass_left_right;
  30. { set the register of the result location }
  31. procedure set_result_location_reg;
  32. { load left and right nodes into registers }
  33. procedure force_reg_left_right(allow_swap,allow_constant:boolean);
  34. { free used registers, except result location }
  35. procedure release_reg_left_right;
  36. procedure second_opfloat;
  37. procedure second_opboolean;
  38. procedure second_opsmallset;
  39. procedure second_op64bit;
  40. procedure second_opordinal;
  41. procedure second_addstring;virtual;
  42. procedure second_addfloat;virtual;abstract;
  43. procedure second_addboolean;virtual;
  44. procedure second_addsmallset;virtual;
  45. {$ifdef i386}
  46. {$ifdef SUPPORT_MMX}
  47. procedure second_addmmxset;virtual;abstract;
  48. procedure second_addmmx;virtual;abstract;
  49. {$endif SUPPORT_MMX}
  50. {$endif}
  51. procedure second_add64bit;virtual;
  52. procedure second_addordinal;virtual;
  53. procedure second_cmpfloat;virtual;abstract;
  54. procedure second_cmpboolean;virtual;
  55. procedure second_cmpsmallset;virtual;abstract;
  56. procedure second_cmp64bit;virtual;abstract;
  57. procedure second_cmpordinal;virtual;abstract;
  58. end;
  59. implementation
  60. uses
  61. globtype,systems,
  62. cutils,verbose,globals,
  63. symconst,symdef,paramgr,
  64. aasmbase,aasmtai,defutil,
  65. cgbase,cpuinfo,pass_2,
  66. ncon,nset,ncgutil,cgobj
  67. ;
  68. {*****************************************************************************
  69. Helpers
  70. *****************************************************************************}
  71. procedure tcgaddnode.pass_left_right;
  72. var
  73. tmpreg : tregister;
  74. isjump,
  75. pushedfpu : boolean;
  76. otl,ofl : tasmlabel;
  77. begin
  78. { calculate the operator which is more difficult }
  79. firstcomplex(self);
  80. { in case of constant put it to the left }
  81. if (left.nodetype=ordconstn) then
  82. swapleftright;
  83. isjump:=(left.expectloc=LOC_JUMP);
  84. if isjump then
  85. begin
  86. otl:=truelabel;
  87. objectlibrary.getlabel(truelabel);
  88. ofl:=falselabel;
  89. objectlibrary.getlabel(falselabel);
  90. end;
  91. secondpass(left);
  92. if left.location.loc in [LOC_FLAGS,LOC_JUMP] then
  93. location_force_reg(exprasmlist,left.location,def_cgsize(resulttype.def),false);
  94. if isjump then
  95. begin
  96. truelabel:=otl;
  97. falselabel:=ofl;
  98. end;
  99. { are too few registers free? }
  100. if left.location.loc=LOC_FPUREGISTER then
  101. pushedfpu:=maybe_pushfpu(exprasmlist,right.registersfpu,left.location)
  102. else
  103. pushedfpu:=false;
  104. isjump:=(right.expectloc=LOC_JUMP);
  105. if isjump then
  106. begin
  107. otl:=truelabel;
  108. objectlibrary.getlabel(truelabel);
  109. ofl:=falselabel;
  110. objectlibrary.getlabel(falselabel);
  111. end;
  112. secondpass(right);
  113. if right.location.loc in [LOC_FLAGS,LOC_JUMP] then
  114. location_force_reg(exprasmlist,right.location,def_cgsize(resulttype.def),false);
  115. if isjump then
  116. begin
  117. truelabel:=otl;
  118. falselabel:=ofl;
  119. end;
  120. if pushedfpu then
  121. begin
  122. tmpreg := cg.getfpuregister(exprasmlist,left.location.size);
  123. cg.a_loadfpu_loc_reg(exprasmlist,left.location,tmpreg);
  124. location_reset(left.location,LOC_FPUREGISTER,left.location.size);
  125. left.location.register := tmpreg;
  126. end;
  127. end;
  128. procedure tcgaddnode.set_result_location_reg;
  129. begin
  130. location_reset(location,LOC_REGISTER,def_cgsize(resulttype.def));
  131. if left.location.loc=LOC_REGISTER then
  132. begin
  133. if TCGSize2Size[left.location.size]<>TCGSize2Size[location.size] then
  134. internalerror(200307041);
  135. {$ifndef cpu64bit}
  136. if location.size in [OS_64,OS_S64] then
  137. begin
  138. location.registerlow := left.location.registerlow;
  139. location.registerhigh := left.location.registerhigh;
  140. end
  141. else
  142. {$endif}
  143. location.register := left.location.register;
  144. end
  145. else
  146. if right.location.loc=LOC_REGISTER then
  147. begin
  148. if TCGSize2Size[right.location.size]<>TCGSize2Size[location.size] then
  149. internalerror(200307042);
  150. {$ifndef cpu64bit}
  151. if location.size in [OS_64,OS_S64] then
  152. begin
  153. location.registerlow := right.location.registerlow;
  154. location.registerhigh := right.location.registerhigh;
  155. end
  156. else
  157. {$endif}
  158. location.register := right.location.register;
  159. end
  160. else
  161. begin
  162. {$ifndef cpu64bit}
  163. if location.size in [OS_64,OS_S64] then
  164. begin
  165. location.registerlow := cg.getintregister(exprasmlist,OS_INT);
  166. location.registerhigh := cg.getintregister(exprasmlist,OS_INT);
  167. end
  168. else
  169. {$endif}
  170. location.register := cg.getintregister(exprasmlist,location.size);
  171. end;
  172. end;
  173. procedure tcgaddnode.force_reg_left_right(allow_swap,allow_constant:boolean);
  174. begin
  175. if (left.location.loc<>LOC_REGISTER) and
  176. not(
  177. allow_constant and
  178. (left.location.loc=LOC_CONSTANT)
  179. ) then
  180. location_force_reg(exprasmlist,left.location,left.location.size,false);
  181. if (right.location.loc<>LOC_REGISTER) and
  182. not(
  183. allow_constant and
  184. (right.location.loc=LOC_CONSTANT) and
  185. (left.location.loc<>LOC_CONSTANT)
  186. ) then
  187. location_force_reg(exprasmlist,right.location,right.location.size,false);
  188. { Left is always a register, right can be register or constant }
  189. if left.location.loc<>LOC_REGISTER then
  190. begin
  191. { when it is not allowed to swap we have a constant on
  192. left, that will give problems }
  193. if not allow_swap then
  194. internalerror(200307041);
  195. swapleftright;
  196. end;
  197. end;
  198. procedure tcgaddnode.release_reg_left_right;
  199. begin
  200. if (right.location.loc in [LOC_REGISTER,LOC_FPUREGISTER]) and
  201. not(
  202. (location.loc = right.location.loc) and
  203. (location.register=right.location.register)
  204. ) then
  205. location_release(exprasmlist,right.location);
  206. if (left.location.loc in [LOC_REGISTER,LOC_FPUREGISTER]) and
  207. not(
  208. (location.loc = left.location.loc) and
  209. (location.register=left.location.register)
  210. ) then
  211. location_release(exprasmlist,left.location);
  212. end;
  213. {*****************************************************************************
  214. Smallsets
  215. *****************************************************************************}
  216. procedure tcgaddnode.second_opsmallset;
  217. begin
  218. { when a setdef is passed, it has to be a smallset }
  219. if ((left.resulttype.def.deftype=setdef) and
  220. (tsetdef(left.resulttype.def).settype<>smallset)) or
  221. ((right.resulttype.def.deftype=setdef) and
  222. (tsetdef(right.resulttype.def).settype<>smallset)) then
  223. internalerror(200203301);
  224. if nodetype in [equaln,unequaln,gtn,gten,lten,ltn] then
  225. second_cmpsmallset
  226. else
  227. second_addsmallset;
  228. end;
  229. procedure tcgaddnode.second_addsmallset;
  230. var
  231. cgop : TOpCg;
  232. tmpreg : tregister;
  233. opdone : boolean;
  234. begin
  235. opdone := false;
  236. pass_left_right;
  237. force_reg_left_right(true,true);
  238. { setelementn is a special case, it must be on right.
  239. We need an extra check if left is a register because the
  240. default case can skip the register loading when the
  241. setelementn is in a register (PFV) }
  242. if (nf_swaped in flags) and
  243. (left.nodetype=setelementn) then
  244. swapleftright;
  245. if (right.nodetype=setelementn) and
  246. (left.location.loc<>LOC_REGISTER) then
  247. location_force_reg(exprasmlist,left.location,left.location.size,false);
  248. set_result_location_reg;
  249. case nodetype of
  250. addn :
  251. begin
  252. { are we adding set elements ? }
  253. if right.nodetype=setelementn then
  254. begin
  255. { no range support for smallsets! }
  256. if assigned(tsetelementnode(right).right) then
  257. internalerror(43244);
  258. if (right.location.loc = LOC_CONSTANT) then
  259. cg.a_op_const_reg_reg(exprasmlist,OP_OR,location.size,
  260. aint(1 shl right.location.value),
  261. left.location.register,location.register)
  262. else
  263. begin
  264. tmpreg := cg.getintregister(exprasmlist,location.size);
  265. cg.a_load_const_reg(exprasmlist,location.size,1,tmpreg);
  266. cg.a_op_reg_reg(exprasmlist,OP_SHL,location.size,
  267. right.location.register,tmpreg);
  268. if left.location.loc <> LOC_CONSTANT then
  269. cg.a_op_reg_reg_reg(exprasmlist,OP_OR,location.size,tmpreg,
  270. left.location.register,location.register)
  271. else
  272. cg.a_op_const_reg_reg(exprasmlist,OP_OR,location.size,
  273. left.location.value,tmpreg,location.register);
  274. cg.ungetregister(exprasmlist,tmpreg);
  275. end;
  276. opdone := true;
  277. end
  278. else
  279. cgop := OP_OR;
  280. end;
  281. symdifn :
  282. cgop:=OP_XOR;
  283. muln :
  284. cgop:=OP_AND;
  285. subn :
  286. begin
  287. cgop:=OP_AND;
  288. if (not(nf_swaped in flags)) then
  289. if (right.location.loc=LOC_CONSTANT) then
  290. right.location.value := not(right.location.value)
  291. else
  292. opdone := true
  293. else if (left.location.loc=LOC_CONSTANT) then
  294. left.location.value := not(left.location.value)
  295. else
  296. begin
  297. swapleftright;
  298. opdone := true;
  299. end;
  300. if opdone then
  301. begin
  302. if left.location.loc = LOC_CONSTANT then
  303. begin
  304. tmpreg := cg.getintregister(exprasmlist,location.size);
  305. cg.a_load_const_reg(exprasmlist,location.size,
  306. left.location.value,tmpreg);
  307. cg.a_op_reg_reg(exprasmlist,OP_NOT,location.size,right.location.register,right.location.register);
  308. cg.a_op_reg_reg(exprasmlist,OP_AND,location.size,right.location.register,tmpreg);
  309. cg.a_load_reg_reg(exprasmlist,OS_INT,location.size,tmpreg,location.register);
  310. cg.ungetregister(exprasmlist,tmpreg);
  311. end
  312. else
  313. begin
  314. cg.a_op_reg_reg(exprasmlist,OP_NOT,right.location.size,right.location.register,right.location.register);
  315. cg.a_op_reg_reg(exprasmlist,OP_AND,left.location.size,right.location.register,left.location.register);
  316. cg.a_load_reg_reg(exprasmlist,left.location.size,location.size,left.location.register,location.register);
  317. end;
  318. end;
  319. end;
  320. else
  321. internalerror(2002072701);
  322. end;
  323. if not opdone then
  324. begin
  325. // these are all commutative operations
  326. if (left.location.loc = LOC_CONSTANT) then
  327. swapleftright;
  328. if (right.location.loc = LOC_CONSTANT) then
  329. cg.a_op_const_reg_reg(exprasmlist,cgop,location.size,
  330. right.location.value,left.location.register,
  331. location.register)
  332. else
  333. cg.a_op_reg_reg_reg(exprasmlist,cgop,location.size,
  334. right.location.register,left.location.register,
  335. location.register);
  336. end;
  337. release_reg_left_right;
  338. end;
  339. {*****************************************************************************
  340. Boolean
  341. *****************************************************************************}
  342. procedure tcgaddnode.second_opboolean;
  343. begin
  344. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  345. second_cmpboolean
  346. else
  347. second_addboolean;
  348. end;
  349. procedure tcgaddnode.second_addboolean;
  350. var
  351. cgop : TOpCg;
  352. otl,ofl : tasmlabel;
  353. begin
  354. { And,Or will only evaluate from left to right only the
  355. needed nodes unless full boolean evaluation is enabled }
  356. if (nodetype in [orn,andn]) and
  357. not(cs_full_boolean_eval in aktlocalswitches) then
  358. begin
  359. location_reset(location,LOC_JUMP,OS_NO);
  360. case nodetype of
  361. andn :
  362. begin
  363. otl:=truelabel;
  364. objectlibrary.getlabel(truelabel);
  365. secondpass(left);
  366. maketojumpbool(exprasmlist,left,lr_load_regvars);
  367. cg.a_label(exprasmlist,truelabel);
  368. truelabel:=otl;
  369. end;
  370. orn :
  371. begin
  372. ofl:=falselabel;
  373. objectlibrary.getlabel(falselabel);
  374. secondpass(left);
  375. maketojumpbool(exprasmlist,left,lr_load_regvars);
  376. cg.a_label(exprasmlist,falselabel);
  377. falselabel:=ofl;
  378. end;
  379. else
  380. internalerror(200307044);
  381. end;
  382. secondpass(right);
  383. maketojumpbool(exprasmlist,right,lr_load_regvars);
  384. end
  385. else
  386. begin
  387. pass_left_right;
  388. force_reg_left_right(false,true);
  389. set_result_location_reg;
  390. case nodetype of
  391. xorn :
  392. cgop:=OP_XOR;
  393. orn :
  394. cgop:=OP_OR;
  395. andn :
  396. cgop:=OP_AND;
  397. else
  398. internalerror(200203247);
  399. end;
  400. if right.location.loc <> LOC_CONSTANT then
  401. cg.a_op_reg_reg_reg(exprasmlist,cgop,location.size,
  402. left.location.register,right.location.register,
  403. location.register)
  404. else
  405. cg.a_op_const_reg_reg(exprasmlist,cgop,location.size,
  406. right.location.value,left.location.register,
  407. location.register);
  408. end;
  409. release_reg_left_right;
  410. end;
  411. {*****************************************************************************
  412. 64-bit
  413. *****************************************************************************}
  414. procedure tcgaddnode.second_op64bit;
  415. begin
  416. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  417. second_cmp64bit
  418. else
  419. second_add64bit;
  420. end;
  421. procedure tcgaddnode.second_add64bit;
  422. var
  423. op : TOpCG;
  424. checkoverflow : boolean;
  425. begin
  426. pass_left_right;
  427. force_reg_left_right(false,(cs_check_overflow in aktlocalswitches) and
  428. (nodetype in [addn,subn]));
  429. set_result_location_reg;
  430. { assume no overflow checking is required }
  431. checkoverflow := false;
  432. case nodetype of
  433. addn :
  434. begin
  435. op:=OP_ADD;
  436. checkoverflow := true;
  437. end;
  438. subn :
  439. begin
  440. op:=OP_SUB;
  441. checkoverflow := true;
  442. end;
  443. xorn:
  444. op:=OP_XOR;
  445. orn:
  446. op:=OP_OR;
  447. andn:
  448. op:=OP_AND;
  449. muln:
  450. begin
  451. { should be handled in pass_1 (JM) }
  452. internalerror(200109051);
  453. end;
  454. else
  455. internalerror(2002072705);
  456. end;
  457. {$ifdef cpu64bit}
  458. case nodetype of
  459. xorn,orn,andn,addn:
  460. begin
  461. if (right.location.loc = LOC_CONSTANT) then
  462. cg.a_op_const_reg_reg(exprasmlist,op,location.size,right.location.value,
  463. left.location.register64,location.register)
  464. else
  465. cg.a_op_reg_reg_reg(exprasmlist,op,location.size,right.location.register,
  466. left.location.register64,location.register);
  467. end;
  468. subn:
  469. begin
  470. if (nf_swaped in flags) then
  471. swapleftright;
  472. if left.location.loc <> LOC_CONSTANT then
  473. begin
  474. if (location.registerlow = NR_NO) then
  475. begin
  476. location.registerlow := cg.getintregister(exprasmlist,OS_INT);
  477. location.registerhigh := cg.getintregister(exprasmlist,OS_INT);
  478. end;
  479. if right.location.loc <> LOC_CONSTANT then
  480. // reg64 - reg64
  481. cg.a_op_reg_reg_reg(exprasmlist,OP_SUB,location.size,
  482. right.location.register,left.location.register,location.register)
  483. else
  484. // reg64 - const64
  485. cg.a_op_const_reg_reg(exprasmlist,OP_SUB,location.size,
  486. right.location.value,left.location.register,location.register);
  487. end
  488. else
  489. begin
  490. // const64 - reg64
  491. location_force_reg(exprasmlist,left.location,left.location.size,true);
  492. cg.a_op_reg_reg_reg(exprasmlist,OP_SUB,location.size,
  493. right.location.register,left.location.register,location.register);
  494. end;
  495. end;
  496. else
  497. internalerror(2002072803);
  498. end;
  499. {$else cpu64bit}
  500. case nodetype of
  501. xorn,orn,andn,addn:
  502. begin
  503. if (right.location.loc = LOC_CONSTANT) then
  504. cg64.a_op64_const_reg_reg(exprasmlist,op,right.location.value64,
  505. left.location.register64,location.register64)
  506. else
  507. cg64.a_op64_reg_reg_reg(exprasmlist,op,right.location.register64,
  508. left.location.register64,location.register64);
  509. end;
  510. subn:
  511. begin
  512. if (nf_swaped in flags) then
  513. swapleftright;
  514. if left.location.loc <> LOC_CONSTANT then
  515. begin
  516. if right.location.loc <> LOC_CONSTANT then
  517. // reg64 - reg64
  518. cg64.a_op64_reg_reg_reg(exprasmlist,OP_SUB,
  519. right.location.register64,left.location.register64,
  520. location.register64)
  521. else
  522. // reg64 - const64
  523. cg64.a_op64_const_reg_reg(exprasmlist,OP_SUB,
  524. right.location.value64,left.location.register64,
  525. location.register64)
  526. end
  527. else
  528. begin
  529. // const64 - reg64
  530. location_force_reg(exprasmlist,left.location,left.location.size,true);
  531. cg64.a_op64_reg_reg_reg(exprasmlist,OP_SUB,
  532. right.location.register64,left.location.register64,
  533. location.register64);
  534. end;
  535. end;
  536. else
  537. internalerror(2002072803);
  538. end;
  539. {$endif cpu64bit}
  540. { emit overflow check if enabled }
  541. if checkoverflow then
  542. cg.g_overflowcheck(exprasmlist,Location,ResultType.Def);
  543. release_reg_left_right;
  544. end;
  545. {*****************************************************************************
  546. Strings
  547. *****************************************************************************}
  548. procedure tcgaddnode.second_addstring;
  549. begin
  550. { this should already be handled in pass1 }
  551. internalerror(2002072402);
  552. end;
  553. {*****************************************************************************
  554. Floats
  555. *****************************************************************************}
  556. procedure tcgaddnode.second_opfloat;
  557. begin
  558. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  559. second_cmpfloat
  560. else
  561. second_addfloat;
  562. end;
  563. {*****************************************************************************
  564. Ordinals
  565. *****************************************************************************}
  566. procedure tcgaddnode.second_opordinal;
  567. begin
  568. if (nodetype in [ltn,lten,gtn,gten,equaln,unequaln]) then
  569. second_cmpordinal
  570. else
  571. second_addordinal;
  572. end;
  573. procedure tcgaddnode.second_addordinal;
  574. var
  575. unsigned,
  576. checkoverflow : boolean;
  577. cgop : topcg;
  578. tmpreg : tregister;
  579. begin
  580. pass_left_right;
  581. force_reg_left_right(false,(cs_check_overflow in aktlocalswitches) and
  582. (nodetype in [addn,subn,muln]));
  583. set_result_location_reg;
  584. { determine if the comparison will be unsigned }
  585. unsigned:=not(is_signed(left.resulttype.def)) or
  586. not(is_signed(right.resulttype.def));
  587. { assume no overflow checking is require }
  588. checkoverflow := false;
  589. case nodetype of
  590. addn:
  591. begin
  592. cgop := OP_ADD;
  593. checkoverflow := true;
  594. end;
  595. xorn :
  596. begin
  597. cgop := OP_XOR;
  598. end;
  599. orn :
  600. begin
  601. cgop := OP_OR;
  602. end;
  603. andn:
  604. begin
  605. cgop := OP_AND;
  606. end;
  607. muln:
  608. begin
  609. checkoverflow := true;
  610. if unsigned then
  611. cgop := OP_MUL
  612. else
  613. cgop := OP_IMUL;
  614. end;
  615. subn :
  616. begin
  617. checkoverflow := true;
  618. cgop := OP_SUB;
  619. end;
  620. end;
  621. if nodetype <> subn then
  622. begin
  623. if (right.location.loc <> LOC_CONSTANT) then
  624. cg.a_op_reg_reg_reg(exprasmlist,cgop,location.size,
  625. left.location.register,right.location.register,
  626. location.register)
  627. else
  628. cg.a_op_const_reg_reg(exprasmlist,cgop,location.size,
  629. right.location.value,left.location.register,
  630. location.register);
  631. end
  632. else { subtract is a special case since its not commutative }
  633. begin
  634. if (nf_swaped in flags) then
  635. swapleftright;
  636. if left.location.loc <> LOC_CONSTANT then
  637. begin
  638. if right.location.loc <> LOC_CONSTANT then
  639. cg.a_op_reg_reg_reg(exprasmlist,OP_SUB,location.size,
  640. right.location.register,left.location.register,
  641. location.register)
  642. else
  643. cg.a_op_const_reg_reg(exprasmlist,OP_SUB,location.size,
  644. aword(right.location.value),left.location.register,
  645. location.register);
  646. end
  647. else
  648. begin
  649. tmpreg := cg.getintregister(exprasmlist,location.size);
  650. cg.a_load_const_reg(exprasmlist,location.size,
  651. aword(left.location.value),tmpreg);
  652. cg.a_op_reg_reg_reg(exprasmlist,OP_SUB,location.size,
  653. right.location.register,tmpreg,location.register);
  654. cg.ungetregister(exprasmlist,tmpreg);
  655. end;
  656. end;
  657. { emit overflow check if required }
  658. if checkoverflow then
  659. cg.g_overflowcheck(exprasmlist,Location,ResultType.Def);
  660. release_reg_left_right;
  661. end;
  662. procedure tcgaddnode.second_cmpboolean;
  663. begin
  664. second_cmpordinal;
  665. end;
  666. {*****************************************************************************
  667. pass_2
  668. *****************************************************************************}
  669. procedure tcgaddnode.pass_2;
  670. begin
  671. case left.resulttype.def.deftype of
  672. orddef :
  673. begin
  674. { handling boolean expressions }
  675. if is_boolean(left.resulttype.def) and
  676. is_boolean(right.resulttype.def) then
  677. second_opboolean
  678. { 64bit operations }
  679. else if is_64bit(left.resulttype.def) then
  680. second_op64bit
  681. else
  682. second_opordinal;
  683. end;
  684. stringdef :
  685. begin
  686. second_addstring;
  687. end;
  688. setdef :
  689. begin
  690. {Normalsets are already handled in pass1 if mmx
  691. should not be used.}
  692. if (tsetdef(left.resulttype.def).settype<>smallset) then
  693. begin
  694. {$ifdef SUPPORT_MMX}
  695. {$ifdef i386}
  696. if cs_mmx in aktlocalswitches then
  697. second_opmmxset
  698. else
  699. {$endif}
  700. {$endif SUPPORT_MMX}
  701. internalerror(200109041);
  702. end
  703. else
  704. second_opsmallset;
  705. end;
  706. arraydef :
  707. begin
  708. { support dynarr=nil }
  709. if is_dynamic_array(left.resulttype.def) then
  710. second_opordinal
  711. {$ifdef SUPPORT_MMX}
  712. else
  713. if is_mmx_able_array(left.resulttype.def) then
  714. second_opmmx;
  715. {$endif SUPPORT_MMX}
  716. else
  717. internalerror(200306016);
  718. end;
  719. floatdef :
  720. second_opfloat;
  721. else
  722. second_opordinal;
  723. end;
  724. end;
  725. begin
  726. caddnode:=tcgaddnode;
  727. end.
  728. {
  729. $Log$
  730. Revision 1.31 2004-06-20 08:55:29 florian
  731. * logs truncated
  732. Revision 1.30 2004/06/16 20:07:08 florian
  733. * dwarf branch merged
  734. Revision 1.29.2.5 2004/06/13 10:51:16 florian
  735. * fixed several register allocator problems (sparc/arm)
  736. Revision 1.29.2.4 2004/06/12 17:01:01 florian
  737. * fixed compilation of arm compiler
  738. Revision 1.29.2.3 2004/06/02 20:59:05 peter
  739. * fix negative consts
  740. Revision 1.29.2.2 2004/05/30 17:54:14 florian
  741. + implemented cmp64bit
  742. * started to fix spilling
  743. * fixed int64 sub partially
  744. }