ncgadd.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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. end;
  125. end;
  126. procedure tcgaddnode.set_result_location_reg;
  127. begin
  128. location_reset(location,LOC_REGISTER,def_cgsize(resulttype.def));
  129. {$ifdef x86}
  130. if left.location.loc=LOC_REGISTER then
  131. begin
  132. if TCGSize2Size[left.location.size]<>TCGSize2Size[location.size] then
  133. internalerror(200307041);
  134. {$ifndef cpu64bit}
  135. if location.size in [OS_64,OS_S64] then
  136. begin
  137. location.register64.reglo := left.location.register64.reglo;
  138. location.register64.reghi := left.location.register64.reghi;
  139. end
  140. else
  141. {$endif}
  142. location.register := left.location.register;
  143. end
  144. else
  145. if right.location.loc=LOC_REGISTER then
  146. begin
  147. if TCGSize2Size[right.location.size]<>TCGSize2Size[location.size] then
  148. internalerror(200307042);
  149. {$ifndef cpu64bit}
  150. if location.size in [OS_64,OS_S64] then
  151. begin
  152. location.register64.reglo := right.location.register64.reglo;
  153. location.register64.reghi := right.location.register64.reghi;
  154. end
  155. else
  156. {$endif}
  157. location.register := right.location.register;
  158. end
  159. else
  160. {$endif}
  161. begin
  162. {$ifndef cpu64bit}
  163. if location.size in [OS_64,OS_S64] then
  164. begin
  165. location.register64.reglo := cg.getintregister(exprasmlist,OS_INT);
  166. location.register64.reghi := 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 in [LOC_CONSTANT,LOC_CREGISTER])
  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 in [LOC_CONSTANT,LOC_CREGISTER]) 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_CONSTANT 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. {*****************************************************************************
  199. Smallsets
  200. *****************************************************************************}
  201. procedure tcgaddnode.second_opsmallset;
  202. begin
  203. { when a setdef is passed, it has to be a smallset }
  204. if ((left.resulttype.def.deftype=setdef) and
  205. (tsetdef(left.resulttype.def).settype<>smallset)) or
  206. ((right.resulttype.def.deftype=setdef) and
  207. (tsetdef(right.resulttype.def).settype<>smallset)) then
  208. internalerror(200203301);
  209. if nodetype in [equaln,unequaln,gtn,gten,lten,ltn] then
  210. second_cmpsmallset
  211. else
  212. second_addsmallset;
  213. end;
  214. procedure tcgaddnode.second_addsmallset;
  215. var
  216. cgop : TOpCg;
  217. tmpreg : tregister;
  218. opdone : boolean;
  219. begin
  220. opdone := false;
  221. pass_left_right;
  222. force_reg_left_right(true,true);
  223. { setelementn is a special case, it must be on right.
  224. We need an extra check if left is a register because the
  225. default case can skip the register loading when the
  226. setelementn is in a register (PFV) }
  227. if (nf_swaped in flags) and
  228. (left.nodetype=setelementn) then
  229. swapleftright;
  230. if (right.nodetype=setelementn) and
  231. (left.location.loc<>LOC_REGISTER) then
  232. location_force_reg(exprasmlist,left.location,left.location.size,false);
  233. set_result_location_reg;
  234. case nodetype of
  235. addn :
  236. begin
  237. { are we adding set elements ? }
  238. if right.nodetype=setelementn then
  239. begin
  240. { no range support for smallsets! }
  241. if assigned(tsetelementnode(right).right) then
  242. internalerror(43244);
  243. if (right.location.loc = LOC_CONSTANT) then
  244. cg.a_op_const_reg_reg(exprasmlist,OP_OR,location.size,
  245. aint(1 shl right.location.value),
  246. left.location.register,location.register)
  247. else
  248. begin
  249. tmpreg := cg.getintregister(exprasmlist,location.size);
  250. cg.a_load_const_reg(exprasmlist,location.size,1,tmpreg);
  251. cg.a_op_reg_reg(exprasmlist,OP_SHL,location.size,
  252. right.location.register,tmpreg);
  253. if left.location.loc <> LOC_CONSTANT then
  254. cg.a_op_reg_reg_reg(exprasmlist,OP_OR,location.size,tmpreg,
  255. left.location.register,location.register)
  256. else
  257. cg.a_op_const_reg_reg(exprasmlist,OP_OR,location.size,
  258. left.location.value,tmpreg,location.register);
  259. end;
  260. opdone := true;
  261. end
  262. else
  263. cgop := OP_OR;
  264. end;
  265. symdifn :
  266. cgop:=OP_XOR;
  267. muln :
  268. cgop:=OP_AND;
  269. subn :
  270. begin
  271. cgop:=OP_AND;
  272. if (not(nf_swaped in flags)) then
  273. if (right.location.loc=LOC_CONSTANT) then
  274. right.location.value := not(right.location.value)
  275. else
  276. opdone := true
  277. else if (left.location.loc=LOC_CONSTANT) then
  278. left.location.value := not(left.location.value)
  279. else
  280. begin
  281. swapleftright;
  282. opdone := true;
  283. end;
  284. if opdone then
  285. begin
  286. if left.location.loc = LOC_CONSTANT then
  287. begin
  288. tmpreg := cg.getintregister(exprasmlist,location.size);
  289. cg.a_load_const_reg(exprasmlist,location.size,
  290. left.location.value,tmpreg);
  291. cg.a_op_reg_reg(exprasmlist,OP_NOT,location.size,right.location.register,right.location.register);
  292. cg.a_op_reg_reg(exprasmlist,OP_AND,location.size,right.location.register,tmpreg);
  293. cg.a_load_reg_reg(exprasmlist,OS_INT,location.size,tmpreg,location.register);
  294. end
  295. else
  296. begin
  297. cg.a_op_reg_reg(exprasmlist,OP_NOT,right.location.size,right.location.register,right.location.register);
  298. cg.a_op_reg_reg(exprasmlist,OP_AND,left.location.size,right.location.register,left.location.register);
  299. cg.a_load_reg_reg(exprasmlist,left.location.size,location.size,left.location.register,location.register);
  300. end;
  301. end;
  302. end;
  303. else
  304. internalerror(2002072701);
  305. end;
  306. if not opdone then
  307. begin
  308. // these are all commutative operations
  309. if (left.location.loc = LOC_CONSTANT) then
  310. swapleftright;
  311. if (right.location.loc = LOC_CONSTANT) then
  312. cg.a_op_const_reg_reg(exprasmlist,cgop,location.size,
  313. right.location.value,left.location.register,
  314. location.register)
  315. else
  316. cg.a_op_reg_reg_reg(exprasmlist,cgop,location.size,
  317. right.location.register,left.location.register,
  318. location.register);
  319. end;
  320. end;
  321. {*****************************************************************************
  322. Boolean
  323. *****************************************************************************}
  324. procedure tcgaddnode.second_opboolean;
  325. begin
  326. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  327. second_cmpboolean
  328. else
  329. second_addboolean;
  330. end;
  331. procedure tcgaddnode.second_addboolean;
  332. var
  333. cgop : TOpCg;
  334. otl,ofl : tasmlabel;
  335. begin
  336. { And,Or will only evaluate from left to right only the
  337. needed nodes unless full boolean evaluation is enabled }
  338. if (nodetype in [orn,andn]) and
  339. not(cs_full_boolean_eval in aktlocalswitches) then
  340. begin
  341. location_reset(location,LOC_JUMP,OS_NO);
  342. case nodetype of
  343. andn :
  344. begin
  345. otl:=truelabel;
  346. objectlibrary.getlabel(truelabel);
  347. secondpass(left);
  348. maketojumpbool(exprasmlist,left,lr_load_regvars);
  349. cg.a_label(exprasmlist,truelabel);
  350. truelabel:=otl;
  351. end;
  352. orn :
  353. begin
  354. ofl:=falselabel;
  355. objectlibrary.getlabel(falselabel);
  356. secondpass(left);
  357. maketojumpbool(exprasmlist,left,lr_load_regvars);
  358. cg.a_label(exprasmlist,falselabel);
  359. falselabel:=ofl;
  360. end;
  361. else
  362. internalerror(200307044);
  363. end;
  364. secondpass(right);
  365. maketojumpbool(exprasmlist,right,lr_load_regvars);
  366. end
  367. else
  368. begin
  369. pass_left_right;
  370. force_reg_left_right(false,true);
  371. set_result_location_reg;
  372. case nodetype of
  373. xorn :
  374. cgop:=OP_XOR;
  375. orn :
  376. cgop:=OP_OR;
  377. andn :
  378. cgop:=OP_AND;
  379. else
  380. internalerror(200203247);
  381. end;
  382. if right.location.loc <> LOC_CONSTANT then
  383. cg.a_op_reg_reg_reg(exprasmlist,cgop,location.size,
  384. left.location.register,right.location.register,
  385. location.register)
  386. else
  387. cg.a_op_const_reg_reg(exprasmlist,cgop,location.size,
  388. right.location.value,left.location.register,
  389. location.register);
  390. end;
  391. end;
  392. {*****************************************************************************
  393. 64-bit
  394. *****************************************************************************}
  395. procedure tcgaddnode.second_op64bit;
  396. begin
  397. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  398. second_cmp64bit
  399. else
  400. second_add64bit;
  401. end;
  402. procedure tcgaddnode.second_add64bit;
  403. var
  404. op : TOpCG;
  405. checkoverflow : boolean;
  406. ovloc : tlocation;
  407. begin
  408. pass_left_right;
  409. force_reg_left_right(false,(cs_check_overflow in aktlocalswitches) and
  410. (nodetype in [addn,subn]));
  411. set_result_location_reg;
  412. { assume no overflow checking is required }
  413. checkoverflow := false;
  414. case nodetype of
  415. addn :
  416. begin
  417. op:=OP_ADD;
  418. checkoverflow:=true;
  419. end;
  420. subn :
  421. begin
  422. op:=OP_SUB;
  423. checkoverflow:=true;
  424. end;
  425. xorn:
  426. op:=OP_XOR;
  427. orn:
  428. op:=OP_OR;
  429. andn:
  430. op:=OP_AND;
  431. muln:
  432. begin
  433. { should be handled in pass_1 (JM) }
  434. internalerror(200109051);
  435. end;
  436. else
  437. internalerror(2002072705);
  438. end;
  439. {$ifdef cpu64bit}
  440. case nodetype of
  441. xorn,orn,andn,addn:
  442. begin
  443. if (right.location.loc = LOC_CONSTANT) then
  444. cg.a_op_const_reg_reg(exprasmlist,op,location.size,right.location.value,
  445. left.location.register,location.register)
  446. else
  447. cg.a_op_reg_reg_reg(exprasmlist,op,location.size,right.location.register,
  448. left.location.register,location.register);
  449. end;
  450. subn:
  451. begin
  452. if (nf_swaped in flags) then
  453. swapleftright;
  454. if left.location.loc <> LOC_CONSTANT then
  455. begin
  456. if right.location.loc <> LOC_CONSTANT then
  457. // reg64 - reg64
  458. cg.a_op_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  459. right.location.register,left.location.register,location.register,checkoverflow,ovloc)
  460. else
  461. // reg64 - const64
  462. cg.a_op_const_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  463. right.location.value,left.location.register,location.register,checkoverflow,ovloc);
  464. end
  465. else
  466. begin
  467. // const64 - reg64
  468. location_force_reg(exprasmlist,left.location,left.location.size,true);
  469. cg.a_op_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  470. right.location.register,left.location.register,location.register,checkoverflow,ovloc);
  471. end;
  472. end;
  473. else
  474. internalerror(2002072803);
  475. end;
  476. {$else cpu64bit}
  477. case nodetype of
  478. xorn,orn,andn,addn:
  479. begin
  480. if (right.location.loc = LOC_CONSTANT) then
  481. cg64.a_op64_const_reg_reg_checkoverflow(exprasmlist,op,right.location.value64,
  482. left.location.register64,location.register64,checkoverflow,ovloc)
  483. else
  484. cg64.a_op64_reg_reg_reg_checkoverflow(exprasmlist,op,right.location.register64,
  485. left.location.register64,location.register64,checkoverflow,ovloc);
  486. end;
  487. subn:
  488. begin
  489. if (nf_swaped in flags) then
  490. swapleftright;
  491. if left.location.loc <> LOC_CONSTANT then
  492. begin
  493. if right.location.loc <> LOC_CONSTANT then
  494. // reg64 - reg64
  495. cg64.a_op64_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,
  496. right.location.register64,left.location.register64,
  497. location.register64,checkoverflow,ovloc)
  498. else
  499. // reg64 - const64
  500. cg64.a_op64_const_reg_reg_checkoverflow(exprasmlist,OP_SUB,
  501. right.location.value64,left.location.register64,
  502. location.register64,checkoverflow,ovloc)
  503. end
  504. else
  505. begin
  506. // const64 - reg64
  507. location_force_reg(exprasmlist,left.location,left.location.size,true);
  508. cg64.a_op64_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,
  509. right.location.register64,left.location.register64,
  510. location.register64,checkoverflow,ovloc);
  511. end;
  512. end;
  513. else
  514. internalerror(2002072803);
  515. end;
  516. {$endif cpu64bit}
  517. { emit overflow check if enabled }
  518. if checkoverflow then
  519. cg.g_overflowcheck(exprasmlist,Location,ResultType.Def);
  520. end;
  521. {*****************************************************************************
  522. Strings
  523. *****************************************************************************}
  524. procedure tcgaddnode.second_addstring;
  525. begin
  526. { this should already be handled in pass1 }
  527. internalerror(2002072402);
  528. end;
  529. {*****************************************************************************
  530. Floats
  531. *****************************************************************************}
  532. procedure tcgaddnode.second_opfloat;
  533. begin
  534. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  535. second_cmpfloat
  536. else
  537. second_addfloat;
  538. end;
  539. {*****************************************************************************
  540. Ordinals
  541. *****************************************************************************}
  542. procedure tcgaddnode.second_opordinal;
  543. begin
  544. if (nodetype in [ltn,lten,gtn,gten,equaln,unequaln]) then
  545. second_cmpordinal
  546. else
  547. second_addordinal;
  548. end;
  549. procedure tcgaddnode.second_addordinal;
  550. var
  551. unsigned,
  552. checkoverflow : boolean;
  553. cgop : topcg;
  554. tmpreg : tregister;
  555. ovloc : tlocation;
  556. begin
  557. pass_left_right;
  558. force_reg_left_right(false,(cs_check_overflow in aktlocalswitches) and
  559. (nodetype in [addn,subn,muln]));
  560. set_result_location_reg;
  561. { determine if the comparison will be unsigned }
  562. unsigned:=not(is_signed(left.resulttype.def)) or
  563. not(is_signed(right.resulttype.def));
  564. { assume no overflow checking is require }
  565. checkoverflow := false;
  566. case nodetype of
  567. addn:
  568. begin
  569. cgop:=OP_ADD;
  570. checkoverflow:=true;
  571. end;
  572. xorn :
  573. begin
  574. cgop:=OP_XOR;
  575. end;
  576. orn :
  577. begin
  578. cgop:=OP_OR;
  579. end;
  580. andn:
  581. begin
  582. cgop:=OP_AND;
  583. end;
  584. muln:
  585. begin
  586. checkoverflow:=true;
  587. if unsigned then
  588. cgop:=OP_MUL
  589. else
  590. cgop:=OP_IMUL;
  591. end;
  592. subn :
  593. begin
  594. checkoverflow:=true;
  595. cgop:=OP_SUB;
  596. end;
  597. end;
  598. if nodetype<>subn then
  599. begin
  600. if (right.location.loc >LOC_CONSTANT) then
  601. cg.a_op_reg_reg_reg_checkoverflow(exprasmlist,cgop,location.size,
  602. left.location.register,right.location.register,
  603. location.register,checkoverflow,ovloc)
  604. else
  605. cg.a_op_const_reg_reg_checkoverflow(exprasmlist,cgop,location.size,
  606. right.location.value,left.location.register,
  607. location.register,checkoverflow,ovloc);
  608. end
  609. else { subtract is a special case since its not commutative }
  610. begin
  611. if (nf_swaped in flags) then
  612. swapleftright;
  613. if left.location.loc<>LOC_CONSTANT then
  614. begin
  615. if right.location.loc<>LOC_CONSTANT then
  616. cg.a_op_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  617. right.location.register,left.location.register,
  618. location.register,checkoverflow,ovloc)
  619. else
  620. cg.a_op_const_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  621. aword(right.location.value),left.location.register,
  622. location.register,checkoverflow,ovloc);
  623. end
  624. else
  625. begin
  626. tmpreg:=cg.getintregister(exprasmlist,location.size);
  627. cg.a_load_const_reg(exprasmlist,location.size,
  628. aword(left.location.value),tmpreg);
  629. cg.a_op_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  630. right.location.register,tmpreg,location.register,checkoverflow,ovloc);
  631. end;
  632. end;
  633. { emit overflow check if required }
  634. if checkoverflow then
  635. cg.g_overflowcheck_loc(exprasmlist,Location,ResultType.Def,ovloc);
  636. end;
  637. procedure tcgaddnode.second_cmpboolean;
  638. begin
  639. second_cmpordinal;
  640. end;
  641. {*****************************************************************************
  642. pass_2
  643. *****************************************************************************}
  644. procedure tcgaddnode.pass_2;
  645. begin
  646. case left.resulttype.def.deftype of
  647. orddef :
  648. begin
  649. { handling boolean expressions }
  650. if is_boolean(left.resulttype.def) and
  651. is_boolean(right.resulttype.def) then
  652. second_opboolean
  653. { 64bit operations }
  654. else if is_64bit(left.resulttype.def) then
  655. second_op64bit
  656. else
  657. second_opordinal;
  658. end;
  659. stringdef :
  660. begin
  661. second_addstring;
  662. end;
  663. setdef :
  664. begin
  665. {Normalsets are already handled in pass1 if mmx
  666. should not be used.}
  667. if (tsetdef(left.resulttype.def).settype<>smallset) then
  668. begin
  669. {$ifdef SUPPORT_MMX}
  670. {$ifdef i386}
  671. if cs_mmx in aktlocalswitches then
  672. second_opmmxset
  673. else
  674. {$endif}
  675. {$endif SUPPORT_MMX}
  676. internalerror(200109041);
  677. end
  678. else
  679. second_opsmallset;
  680. end;
  681. arraydef :
  682. begin
  683. { support dynarr=nil }
  684. if is_dynamic_array(left.resulttype.def) then
  685. second_opordinal
  686. {$ifdef SUPPORT_MMX}
  687. else
  688. if is_mmx_able_array(left.resulttype.def) then
  689. second_opmmx;
  690. {$endif SUPPORT_MMX}
  691. else
  692. internalerror(200306016);
  693. end;
  694. floatdef :
  695. second_opfloat;
  696. else
  697. second_opordinal;
  698. end;
  699. end;
  700. begin
  701. caddnode:=tcgaddnode;
  702. end.
  703. {
  704. $Log$
  705. Revision 1.40 2005-01-29 00:40:18 peter
  706. * fixed x86_64 compile
  707. Revision 1.39 2005/01/27 20:32:51 florian
  708. + implemented overflow checking for 64 bit types on sparc
  709. Revision 1.38 2005/01/20 21:28:52 florian
  710. * optimized register usage for non-x86 e.g. 3 operand cpus
  711. Revision 1.37 2005/01/01 14:32:53 florian
  712. * maybe_constant means also that a loc can be CREGISTER
  713. Revision 1.36 2004/11/01 17:41:28 florian
  714. * fixed arm compilation with cgutils
  715. * ...
  716. Revision 1.35 2004/10/31 21:45:03 peter
  717. * generic tlocation
  718. * move tlocation to cgutils
  719. Revision 1.34 2004/09/29 18:55:40 florian
  720. * fixed more sparc overflow stuff
  721. * fixed some op64 stuff for sparc
  722. Revision 1.33 2004/09/26 21:04:35 florian
  723. + partial overflow checking on sparc; multiplication still missing
  724. Revision 1.32 2004/09/25 14:23:54 peter
  725. * ungetregister is now only used for cpuregisters, renamed to
  726. ungetcpuregister
  727. * renamed (get|unget)explicitregister(s) to ..cpuregister
  728. * removed location-release/reference_release
  729. Revision 1.31 2004/06/20 08:55:29 florian
  730. * logs truncated
  731. Revision 1.30 2004/06/16 20:07:08 florian
  732. * dwarf branch merged
  733. Revision 1.29.2.5 2004/06/13 10:51:16 florian
  734. * fixed several register allocator problems (sparc/arm)
  735. Revision 1.29.2.4 2004/06/12 17:01:01 florian
  736. * fixed compilation of arm compiler
  737. Revision 1.29.2.3 2004/06/02 20:59:05 peter
  738. * fix negative consts
  739. Revision 1.29.2.2 2004/05/30 17:54:14 florian
  740. + implemented cmp64bit
  741. * started to fix spilling
  742. * fixed int64 sub partially
  743. }