ncgadd.pas 28 KB

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