ncgadd.pas 28 KB

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