ncgadd.pas 27 KB

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