ncgadd.pas 27 KB

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