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,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. ((location.loc<>LOC_REGISTER) or
  207. (
  208. (location.register.enum <> right.location.register.enum) and
  209. (location.register.number <> right.location.register.number)
  210. )
  211. ) then
  212. location_release(exprasmlist,right.location);
  213. if (left.location.loc in [LOC_REGISTER,LOC_FPUREGISTER]) and
  214. ((location.loc<>LOC_REGISTER) or
  215. (
  216. (location.register.enum <> left.location.register.enum) and
  217. (location.register.number <> left.location.register.number)
  218. )
  219. ) then
  220. location_release(exprasmlist,left.location);
  221. end;
  222. {*****************************************************************************
  223. Smallsets
  224. *****************************************************************************}
  225. procedure tcgaddnode.second_opsmallset;
  226. begin
  227. { when a setdef is passed, it has to be a smallset }
  228. if ((left.resulttype.def.deftype=setdef) and
  229. (tsetdef(left.resulttype.def).settype<>smallset)) or
  230. ((right.resulttype.def.deftype=setdef) and
  231. (tsetdef(right.resulttype.def).settype<>smallset)) then
  232. internalerror(200203301);
  233. if nodetype in [equaln,unequaln,gtn,gten,lten,ltn] then
  234. second_cmpsmallset
  235. else
  236. second_addsmallset;
  237. end;
  238. procedure tcgaddnode.second_addsmallset;
  239. var
  240. cgop : TOpCg;
  241. tmpreg : tregister;
  242. opdone : boolean;
  243. begin
  244. opdone := false;
  245. pass_left_right;
  246. force_reg_left_right(true,true);
  247. set_result_location_reg;
  248. case nodetype of
  249. addn :
  250. begin
  251. { non-commucative }
  252. if (nf_swaped in flags) and
  253. (left.nodetype=setelementn) then
  254. swapleftright;
  255. { are we adding set elements ? }
  256. if right.nodetype=setelementn then
  257. begin
  258. { no range support for smallsets! }
  259. if assigned(tsetelementnode(right).right) then
  260. internalerror(43244);
  261. if (right.location.loc = LOC_CONSTANT) then
  262. cg.a_op_const_reg_reg(exprasmlist,OP_OR,location.size,
  263. aword(1 shl aword(right.location.value)),
  264. left.location.register,location.register)
  265. else
  266. begin
  267. {$ifdef newra}
  268. tmpreg := rg.getregisterint(exprasmlist,location.size);
  269. {$else}
  270. tmpreg := cg.get_scratch_reg_int(exprasmlist,location.size);
  271. {$endif}
  272. cg.a_load_const_reg(exprasmlist,location.size,1,tmpreg);
  273. cg.a_op_reg_reg(exprasmlist,OP_SHL,location.size,
  274. right.location.register,tmpreg);
  275. if left.location.loc <> LOC_CONSTANT then
  276. cg.a_op_reg_reg_reg(exprasmlist,OP_OR,location.size,tmpreg,
  277. left.location.register,location.register)
  278. else
  279. cg.a_op_const_reg_reg(exprasmlist,OP_OR,location.size,
  280. aword(left.location.value),tmpreg,location.register);
  281. {$ifdef newra}
  282. rg.ungetregisterint(exprasmlist,tmpreg);
  283. {$else}
  284. cg.free_scratch_reg(exprasmlist,tmpreg);
  285. {$endif}
  286. end;
  287. opdone := true;
  288. end
  289. else
  290. cgop := OP_OR;
  291. end;
  292. symdifn :
  293. cgop:=OP_XOR;
  294. muln :
  295. cgop:=OP_AND;
  296. subn :
  297. begin
  298. cgop:=OP_AND;
  299. if (not(nf_swaped in flags)) then
  300. if (right.location.loc=LOC_CONSTANT) then
  301. right.location.value := not(right.location.value)
  302. else
  303. opdone := true
  304. else if (left.location.loc=LOC_CONSTANT) then
  305. left.location.value := not(left.location.value)
  306. else
  307. begin
  308. swapleftright;
  309. opdone := true;
  310. end;
  311. if opdone then
  312. begin
  313. if left.location.loc = LOC_CONSTANT then
  314. begin
  315. {$ifdef newra}
  316. tmpreg := rg.getregisterint(exprasmlist,location.size);
  317. {$else}
  318. tmpreg := cg.get_scratch_reg_int(exprasmlist,location.size);
  319. {$endif}
  320. cg.a_load_const_reg(exprasmlist,location.size,
  321. aword(left.location.value),tmpreg);
  322. cg.a_op_reg_reg(exprasmlist,OP_NOT,location.size,right.location.register,right.location.register);
  323. cg.a_op_reg_reg(exprasmlist,OP_AND,location.size,right.location.register,tmpreg);
  324. cg.a_load_reg_reg(exprasmlist,OS_INT,location.size,tmpreg,location.register);
  325. {$ifdef newra}
  326. rg.ungetregisterint(exprasmlist,tmpreg);
  327. {$else}
  328. cg.free_scratch_reg(exprasmlist,tmpreg);
  329. {$endif}
  330. end
  331. else
  332. begin
  333. cg.a_op_reg_reg(exprasmlist,OP_NOT,right.location.size,right.location.register,right.location.register);
  334. cg.a_op_reg_reg(exprasmlist,OP_AND,left.location.size,right.location.register,left.location.register);
  335. cg.a_load_reg_reg(exprasmlist,left.location.size,location.size,left.location.register,location.register);
  336. end;
  337. end;
  338. end;
  339. else
  340. internalerror(2002072701);
  341. end;
  342. if not opdone then
  343. begin
  344. // these are all commutative operations
  345. if (left.location.loc = LOC_CONSTANT) then
  346. swapleftright;
  347. if (right.location.loc = LOC_CONSTANT) then
  348. cg.a_op_const_reg_reg(exprasmlist,cgop,location.size,
  349. aword(right.location.value),left.location.register,
  350. location.register)
  351. else
  352. cg.a_op_reg_reg_reg(exprasmlist,cgop,location.size,
  353. right.location.register,left.location.register,
  354. location.register);
  355. end;
  356. release_reg_left_right;
  357. end;
  358. {*****************************************************************************
  359. Boolean
  360. *****************************************************************************}
  361. procedure tcgaddnode.second_opboolean;
  362. begin
  363. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  364. second_cmpboolean
  365. else
  366. second_addboolean;
  367. end;
  368. procedure tcgaddnode.second_addboolean;
  369. var
  370. cgop : TOpCg;
  371. otl,ofl : tasmlabel;
  372. begin
  373. { And,Or will only evaluate from left to right only the
  374. needed nodes unless full boolean evaluation is enabled }
  375. if (nodetype in [orn,andn]) and
  376. not(cs_full_boolean_eval in aktlocalswitches) then
  377. begin
  378. location_reset(location,LOC_JUMP,OS_NO);
  379. case nodetype of
  380. andn :
  381. begin
  382. otl:=truelabel;
  383. objectlibrary.getlabel(truelabel);
  384. secondpass(left);
  385. maketojumpbool(exprasmlist,left,lr_load_regvars);
  386. cg.a_label(exprasmlist,truelabel);
  387. truelabel:=otl;
  388. end;
  389. orn :
  390. begin
  391. ofl:=falselabel;
  392. objectlibrary.getlabel(falselabel);
  393. secondpass(left);
  394. maketojumpbool(exprasmlist,left,lr_load_regvars);
  395. cg.a_label(exprasmlist,falselabel);
  396. falselabel:=ofl;
  397. end;
  398. else
  399. internalerror(200307044);
  400. end;
  401. secondpass(right);
  402. maketojumpbool(exprasmlist,right,lr_load_regvars);
  403. end
  404. else
  405. begin
  406. pass_left_right;
  407. force_reg_left_right(false,true);
  408. set_result_location_reg;
  409. case nodetype of
  410. xorn :
  411. cgop:=OP_XOR;
  412. orn :
  413. cgop:=OP_OR;
  414. andn :
  415. cgop:=OP_AND;
  416. else
  417. internalerror(200203247);
  418. end;
  419. if right.location.loc <> LOC_CONSTANT then
  420. cg.a_op_reg_reg_reg(exprasmlist,cgop,location.size,
  421. left.location.register,right.location.register,
  422. location.register)
  423. else
  424. cg.a_op_const_reg_reg(exprasmlist,cgop,location.size,
  425. aword(right.location.value),left.location.register,
  426. location.register);
  427. end;
  428. release_reg_left_right;
  429. end;
  430. {*****************************************************************************
  431. 64-bit
  432. *****************************************************************************}
  433. procedure tcgaddnode.second_op64bit;
  434. begin
  435. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  436. second_cmp64bit
  437. else
  438. second_add64bit;
  439. end;
  440. procedure tcgaddnode.second_add64bit;
  441. var
  442. op : TOpCG;
  443. checkoverflow : boolean;
  444. begin
  445. pass_left_right;
  446. force_reg_left_right(false,(cs_check_overflow in aktlocalswitches) and
  447. (nodetype in [addn,subn]));
  448. set_result_location_reg;
  449. { assume no overflow checking is required }
  450. checkoverflow := false;
  451. case nodetype of
  452. addn :
  453. begin
  454. op:=OP_ADD;
  455. checkoverflow := true;
  456. end;
  457. subn :
  458. begin
  459. op:=OP_SUB;
  460. checkoverflow := true;
  461. end;
  462. xorn:
  463. op:=OP_XOR;
  464. orn:
  465. op:=OP_OR;
  466. andn:
  467. op:=OP_AND;
  468. muln:
  469. begin
  470. { should be handled in pass_1 (JM) }
  471. internalerror(200109051);
  472. end;
  473. else
  474. internalerror(2002072705);
  475. end;
  476. case nodetype of
  477. xorn,orn,andn,addn:
  478. begin
  479. if (right.location.loc = LOC_CONSTANT) then
  480. cg64.a_op64_const_reg_reg(exprasmlist,op,right.location.valueqword,
  481. left.location.register64,location.register64)
  482. else
  483. cg64.a_op64_reg_reg_reg(exprasmlist,op,right.location.register64,
  484. left.location.register64,location.register64);
  485. end;
  486. subn:
  487. begin
  488. if (nf_swaped in flags) then
  489. swapleftright;
  490. if left.location.loc <> LOC_CONSTANT then
  491. begin
  492. if right.location.loc <> LOC_CONSTANT then
  493. // reg64 - reg64
  494. cg64.a_op64_reg_reg_reg(exprasmlist,OP_SUB,
  495. right.location.register64,left.location.register64,
  496. location.register64)
  497. else
  498. // reg64 - const64
  499. cg64.a_op64_const_reg_reg(exprasmlist,OP_SUB,
  500. right.location.valueqword,left.location.register64,
  501. location.register64)
  502. end
  503. else
  504. begin
  505. // const64 - reg64
  506. location_force_reg(exprasmlist,left.location,left.location.size,true);
  507. cg64.a_op64_reg_reg_reg(exprasmlist,OP_SUB,
  508. right.location.register64,left.location.register64,
  509. location.register64);
  510. end;
  511. end;
  512. else
  513. internalerror(2002072803);
  514. end;
  515. { emit overflow check if enabled }
  516. if checkoverflow then
  517. cg.g_overflowcheck(exprasmlist,Location,ResultType.Def);
  518. end;
  519. {*****************************************************************************
  520. Floats
  521. *****************************************************************************}
  522. procedure tcgaddnode.second_opfloat;
  523. begin
  524. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  525. second_cmpfloat
  526. else
  527. second_addfloat;
  528. end;
  529. {*****************************************************************************
  530. Ordinals
  531. *****************************************************************************}
  532. procedure tcgaddnode.second_opordinal;
  533. begin
  534. if (nodetype in [ltn,lten,gtn,gten,equaln,unequaln]) then
  535. second_cmpordinal
  536. else
  537. second_addordinal;
  538. end;
  539. procedure tcgaddnode.second_addordinal;
  540. var
  541. unsigned,
  542. checkoverflow : boolean;
  543. cgop : topcg;
  544. tmpreg : tregister;
  545. begin
  546. pass_left_right;
  547. force_reg_left_right(false,(cs_check_overflow in aktlocalswitches) and
  548. (nodetype in [addn,subn,muln]));
  549. set_result_location_reg;
  550. { determine if the comparison will be unsigned }
  551. unsigned:=not(is_signed(left.resulttype.def)) or
  552. not(is_signed(right.resulttype.def));
  553. { assume no overflow checking is require }
  554. checkoverflow := false;
  555. case nodetype of
  556. addn:
  557. begin
  558. cgop := OP_ADD;
  559. checkoverflow := true;
  560. end;
  561. xorn :
  562. begin
  563. cgop := OP_XOR;
  564. end;
  565. orn :
  566. begin
  567. cgop := OP_OR;
  568. end;
  569. andn:
  570. begin
  571. cgop := OP_AND;
  572. end;
  573. muln:
  574. begin
  575. checkoverflow := true;
  576. if unsigned then
  577. cgop := OP_MUL
  578. else
  579. cgop := OP_IMUL;
  580. end;
  581. subn :
  582. begin
  583. checkoverflow := true;
  584. cgop := OP_SUB;
  585. end;
  586. end;
  587. if nodetype <> subn then
  588. begin
  589. if (right.location.loc <> LOC_CONSTANT) then
  590. cg.a_op_reg_reg_reg(exprasmlist,cgop,location.size,
  591. left.location.register,right.location.register,
  592. location.register)
  593. else
  594. cg.a_op_const_reg_reg(exprasmlist,cgop,location.size,
  595. aword(right.location.value),left.location.register,
  596. location.register);
  597. end
  598. else { subtract is a special case since its not commutative }
  599. begin
  600. if (nf_swaped in flags) then
  601. swapleftright;
  602. if left.location.loc <> LOC_CONSTANT then
  603. begin
  604. if right.location.loc <> LOC_CONSTANT then
  605. cg.a_op_reg_reg_reg(exprasmlist,OP_SUB,location.size,
  606. right.location.register,left.location.register,
  607. location.register)
  608. else
  609. cg.a_op_const_reg_reg(exprasmlist,OP_SUB,location.size,
  610. aword(right.location.value),left.location.register,
  611. location.register);
  612. end
  613. else
  614. begin
  615. {$ifdef newra}
  616. tmpreg := rg.getregisterint(exprasmlist,location.size);
  617. {$else}
  618. tmpreg := cg.get_scratch_reg_int(exprasmlist,location.size);
  619. {$endif}
  620. cg.a_load_const_reg(exprasmlist,location.size,
  621. aword(left.location.value),tmpreg);
  622. cg.a_op_reg_reg_reg(exprasmlist,OP_SUB,location.size,
  623. right.location.register,tmpreg,location.register);
  624. {$ifdef newra}
  625. rg.ungetregisterint(exprasmlist,tmpreg);
  626. {$else}
  627. cg.free_scratch_reg(exprasmlist,tmpreg);
  628. {$endif}
  629. end;
  630. end;
  631. { emit overflow check if required }
  632. if checkoverflow then
  633. cg.g_overflowcheck(exprasmlist,Location,ResultType.Def);
  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.14 2003-07-06 17:44:12 peter
  686. * cleanup and first sparc implementation
  687. Revision 1.13 2003/06/12 16:43:07 peter
  688. * newra compiles for sparc
  689. Revision 1.12 2003/06/10 20:46:17 mazen
  690. * fixing a general compile problem related to
  691. cg.g_overflowcheck declaration that has
  692. changed
  693. Revision 1.11 2003/06/01 21:38:06 peter
  694. * getregisterfpu size parameter added
  695. * op_const_reg size parameter added
  696. * sparc updates
  697. Revision 1.10 2003/05/23 14:27:35 peter
  698. * remove some unit dependencies
  699. * current_procinfo changes to store more info
  700. Revision 1.9 2003/04/30 22:15:59 florian
  701. * some 64 bit adaptions in ncgadd
  702. * x86-64 now uses ncgadd
  703. * tparamanager.ret_in_acc doesn't return true anymore for a void-def
  704. Revision 1.8 2003/04/23 20:16:04 peter
  705. + added currency support based on int64
  706. + is_64bit for use in cg units instead of is_64bitint
  707. * removed cgmessage from n386add, replace with internalerrors
  708. Revision 1.7 2003/04/22 23:50:22 peter
  709. * firstpass uses expectloc
  710. * checks if there are differences between the expectloc and
  711. location.loc from secondpass in EXTDEBUG
  712. Revision 1.6 2003/02/19 22:00:14 daniel
  713. * Code generator converted to new register notation
  714. - Horribily outdated todo.txt removed
  715. Revision 1.5 2003/02/02 19:25:54 carl
  716. * Several bugfixes for m68k target (register alloc., opcode emission)
  717. + VIS target
  718. + Generic add more complete (still not verified)
  719. Revision 1.4 2003/01/08 18:43:56 daniel
  720. * Tregister changed into a record
  721. Revision 1.3 2002/12/14 15:02:03 carl
  722. * maxoperands -> max_operands (for portability in rautils.pas)
  723. * fix some range-check errors with loadconst
  724. + add ncgadd unit to m68k
  725. * some bugfix of a_param_reg with LOC_CREFERENCE
  726. Revision 1.2 2002/12/08 15:02:17 carl
  727. + more fixes
  728. Revision 1.1 2002/12/07 19:51:35 carl
  729. + first version (uncompilable!)
  730. }