ncgadd.pas 28 KB

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