ncgadd.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. {
  2. Copyright (c) 2000-2002 by the FPC development team
  3. Code generation for add nodes (generic version)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ncgadd;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,nadd,cpubase;
  22. type
  23. tcgaddnode = class(taddnode)
  24. { function pass_1: tnode; override;}
  25. procedure pass_2;override;
  26. protected
  27. { call secondpass for both left and right }
  28. procedure pass_left_right;
  29. { set the register of the result location }
  30. procedure set_result_location_reg;
  31. { load left and right nodes into registers }
  32. procedure force_reg_left_right(allow_swap,allow_constant:boolean);
  33. procedure second_opfloat;
  34. procedure second_opboolean;
  35. procedure second_opsmallset;
  36. procedure second_op64bit;
  37. procedure second_opordinal;
  38. procedure second_addstring;virtual;
  39. procedure second_addfloat;virtual;abstract;
  40. procedure second_addboolean;virtual;
  41. procedure second_addsmallset;virtual;
  42. {$ifdef x86}
  43. {$ifdef SUPPORT_MMX}
  44. procedure second_opmmxset;virtual;abstract;
  45. procedure second_opmmx;virtual;abstract;
  46. {$endif SUPPORT_MMX}
  47. {$endif x86}
  48. procedure second_add64bit;virtual;
  49. procedure second_addordinal;virtual;
  50. procedure second_cmpfloat;virtual;abstract;
  51. procedure second_cmpboolean;virtual;
  52. procedure second_cmpsmallset;virtual;abstract;
  53. procedure second_cmp64bit;virtual;abstract;
  54. procedure second_cmpordinal;virtual;abstract;
  55. end;
  56. implementation
  57. uses
  58. globtype,systems,
  59. cutils,verbose,globals,
  60. symconst,symdef,paramgr,
  61. aasmbase,aasmtai,defutil,
  62. cgbase,pass_2,
  63. ncon,nset,ncgutil,cgobj,cgutils
  64. ;
  65. {*****************************************************************************
  66. Helpers
  67. *****************************************************************************}
  68. procedure tcgaddnode.pass_left_right;
  69. var
  70. tmpreg : tregister;
  71. isjump,
  72. pushedfpu : boolean;
  73. otl,ofl : tasmlabel;
  74. begin
  75. { calculate the operator which is more difficult }
  76. firstcomplex(self);
  77. { in case of constant put it to the left }
  78. if (left.nodetype=ordconstn) then
  79. swapleftright;
  80. isjump:=(left.expectloc=LOC_JUMP);
  81. if isjump then
  82. begin
  83. otl:=truelabel;
  84. objectlibrary.getjumplabel(truelabel);
  85. ofl:=falselabel;
  86. objectlibrary.getjumplabel(falselabel);
  87. end;
  88. secondpass(left);
  89. if left.location.loc in [LOC_FLAGS,LOC_JUMP] then
  90. location_force_reg(exprasmlist,left.location,def_cgsize(resulttype.def),false);
  91. if isjump then
  92. begin
  93. truelabel:=otl;
  94. falselabel:=ofl;
  95. end;
  96. { are too few registers free? }
  97. if left.location.loc=LOC_FPUREGISTER then
  98. pushedfpu:=maybe_pushfpu(exprasmlist,right.registersfpu,left.location)
  99. else
  100. pushedfpu:=false;
  101. isjump:=(right.expectloc=LOC_JUMP);
  102. if isjump then
  103. begin
  104. otl:=truelabel;
  105. objectlibrary.getjumplabel(truelabel);
  106. ofl:=falselabel;
  107. objectlibrary.getjumplabel(falselabel);
  108. end;
  109. secondpass(right);
  110. if right.location.loc in [LOC_FLAGS,LOC_JUMP] then
  111. location_force_reg(exprasmlist,right.location,def_cgsize(resulttype.def),false);
  112. if isjump then
  113. begin
  114. truelabel:=otl;
  115. falselabel:=ofl;
  116. end;
  117. if pushedfpu then
  118. begin
  119. tmpreg := cg.getfpuregister(exprasmlist,left.location.size);
  120. cg.a_loadfpu_loc_reg(exprasmlist,left.location,tmpreg);
  121. location_reset(left.location,LOC_FPUREGISTER,left.location.size);
  122. left.location.register := tmpreg;
  123. {$ifdef x86}
  124. { left operand is now on top of the stack, instead of the right one! }
  125. toggleflag(nf_swaped);
  126. {$endif x86}
  127. end;
  128. end;
  129. procedure tcgaddnode.set_result_location_reg;
  130. begin
  131. location_reset(location,LOC_REGISTER,def_cgsize(resulttype.def));
  132. {$ifdef x86}
  133. if left.location.loc=LOC_REGISTER then
  134. begin
  135. if TCGSize2Size[left.location.size]<>TCGSize2Size[location.size] then
  136. internalerror(200307041);
  137. {$ifndef cpu64bit}
  138. if location.size in [OS_64,OS_S64] then
  139. begin
  140. location.register64.reglo := left.location.register64.reglo;
  141. location.register64.reghi := left.location.register64.reghi;
  142. end
  143. else
  144. {$endif}
  145. location.register := left.location.register;
  146. end
  147. else
  148. if right.location.loc=LOC_REGISTER then
  149. begin
  150. if TCGSize2Size[right.location.size]<>TCGSize2Size[location.size] then
  151. internalerror(200307042);
  152. {$ifndef cpu64bit}
  153. if location.size in [OS_64,OS_S64] then
  154. begin
  155. location.register64.reglo := right.location.register64.reglo;
  156. location.register64.reghi := right.location.register64.reghi;
  157. end
  158. else
  159. {$endif}
  160. location.register := right.location.register;
  161. end
  162. else
  163. {$endif}
  164. begin
  165. {$ifndef cpu64bit}
  166. if location.size in [OS_64,OS_S64] then
  167. begin
  168. location.register64.reglo := cg.getintregister(exprasmlist,OS_INT);
  169. location.register64.reghi := cg.getintregister(exprasmlist,OS_INT);
  170. end
  171. else
  172. {$endif}
  173. location.register := cg.getintregister(exprasmlist,location.size);
  174. end;
  175. end;
  176. procedure tcgaddnode.force_reg_left_right(allow_swap,allow_constant:boolean);
  177. begin
  178. if (left.location.loc<>LOC_REGISTER) and
  179. not(
  180. allow_constant and
  181. (left.location.loc in [LOC_CONSTANT,LOC_CREGISTER])
  182. ) then
  183. location_force_reg(exprasmlist,left.location,left.location.size,false);
  184. if (right.location.loc<>LOC_REGISTER) and
  185. not(
  186. allow_constant and
  187. (right.location.loc in [LOC_CONSTANT,LOC_CREGISTER]) and
  188. (left.location.loc<>LOC_CONSTANT)
  189. ) then
  190. location_force_reg(exprasmlist,right.location,right.location.size,false);
  191. { Left is always a register, right can be register or constant }
  192. if left.location.loc=LOC_CONSTANT then
  193. begin
  194. { when it is not allowed to swap we have a constant on
  195. left, that will give problems }
  196. if not allow_swap then
  197. internalerror(200307041);
  198. swapleftright;
  199. end;
  200. end;
  201. {*****************************************************************************
  202. Smallsets
  203. *****************************************************************************}
  204. procedure tcgaddnode.second_opsmallset;
  205. begin
  206. { when a setdef is passed, it has to be a smallset }
  207. if ((left.resulttype.def.deftype=setdef) and
  208. (tsetdef(left.resulttype.def).settype<>smallset)) or
  209. ((right.resulttype.def.deftype=setdef) and
  210. (tsetdef(right.resulttype.def).settype<>smallset)) then
  211. internalerror(200203301);
  212. if nodetype in [equaln,unequaln,gtn,gten,lten,ltn] then
  213. second_cmpsmallset
  214. else
  215. second_addsmallset;
  216. end;
  217. procedure tcgaddnode.second_addsmallset;
  218. var
  219. cgop : TOpCg;
  220. tmpreg : tregister;
  221. opdone : boolean;
  222. begin
  223. opdone := false;
  224. pass_left_right;
  225. force_reg_left_right(true,true);
  226. { setelementn is a special case, it must be on right.
  227. We need an extra check if left is a register because the
  228. default case can skip the register loading when the
  229. setelementn is in a register (PFV) }
  230. if (nf_swaped in flags) and
  231. (left.nodetype=setelementn) then
  232. swapleftright;
  233. if (right.nodetype=setelementn) and
  234. (left.location.loc<>LOC_REGISTER) then
  235. location_force_reg(exprasmlist,left.location,left.location.size,false);
  236. set_result_location_reg;
  237. case nodetype of
  238. addn :
  239. begin
  240. { are we adding set elements ? }
  241. if right.nodetype=setelementn then
  242. begin
  243. { no range support for smallsets! }
  244. if assigned(tsetelementnode(right).right) then
  245. internalerror(43244);
  246. if (right.location.loc = LOC_CONSTANT) then
  247. cg.a_op_const_reg_reg(exprasmlist,OP_OR,location.size,
  248. aint(1 shl right.location.value),
  249. left.location.register,location.register)
  250. else
  251. begin
  252. tmpreg := cg.getintregister(exprasmlist,location.size);
  253. cg.a_load_const_reg(exprasmlist,location.size,1,tmpreg);
  254. cg.a_op_reg_reg(exprasmlist,OP_SHL,location.size,
  255. right.location.register,tmpreg);
  256. if left.location.loc <> LOC_CONSTANT then
  257. cg.a_op_reg_reg_reg(exprasmlist,OP_OR,location.size,tmpreg,
  258. left.location.register,location.register)
  259. else
  260. cg.a_op_const_reg_reg(exprasmlist,OP_OR,location.size,
  261. left.location.value,tmpreg,location.register);
  262. end;
  263. opdone := true;
  264. end
  265. else
  266. cgop := OP_OR;
  267. end;
  268. symdifn :
  269. cgop:=OP_XOR;
  270. muln :
  271. cgop:=OP_AND;
  272. subn :
  273. begin
  274. cgop:=OP_AND;
  275. if (not(nf_swaped in flags)) then
  276. if (right.location.loc=LOC_CONSTANT) then
  277. right.location.value := not(right.location.value)
  278. else
  279. opdone := true
  280. else if (left.location.loc=LOC_CONSTANT) then
  281. left.location.value := not(left.location.value)
  282. else
  283. begin
  284. swapleftright;
  285. opdone := true;
  286. end;
  287. if opdone then
  288. begin
  289. if left.location.loc = LOC_CONSTANT then
  290. begin
  291. tmpreg := cg.getintregister(exprasmlist,location.size);
  292. cg.a_load_const_reg(exprasmlist,location.size,
  293. left.location.value,tmpreg);
  294. cg.a_op_reg_reg(exprasmlist,OP_NOT,location.size,right.location.register,right.location.register);
  295. cg.a_op_reg_reg(exprasmlist,OP_AND,location.size,right.location.register,tmpreg);
  296. cg.a_load_reg_reg(exprasmlist,OS_INT,location.size,tmpreg,location.register);
  297. end
  298. else
  299. begin
  300. cg.a_op_reg_reg(exprasmlist,OP_NOT,right.location.size,right.location.register,right.location.register);
  301. cg.a_op_reg_reg(exprasmlist,OP_AND,left.location.size,right.location.register,left.location.register);
  302. cg.a_load_reg_reg(exprasmlist,left.location.size,location.size,left.location.register,location.register);
  303. end;
  304. end;
  305. end;
  306. else
  307. internalerror(2002072701);
  308. end;
  309. if not opdone then
  310. begin
  311. // these are all commutative operations
  312. if (left.location.loc = LOC_CONSTANT) then
  313. swapleftright;
  314. if (right.location.loc = LOC_CONSTANT) then
  315. cg.a_op_const_reg_reg(exprasmlist,cgop,location.size,
  316. right.location.value,left.location.register,
  317. location.register)
  318. else
  319. cg.a_op_reg_reg_reg(exprasmlist,cgop,location.size,
  320. right.location.register,left.location.register,
  321. location.register);
  322. end;
  323. end;
  324. {*****************************************************************************
  325. Boolean
  326. *****************************************************************************}
  327. procedure tcgaddnode.second_opboolean;
  328. begin
  329. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  330. second_cmpboolean
  331. else
  332. second_addboolean;
  333. end;
  334. procedure tcgaddnode.second_addboolean;
  335. var
  336. cgop : TOpCg;
  337. otl,ofl : tasmlabel;
  338. begin
  339. { And,Or will only evaluate from left to right only the
  340. needed nodes unless full boolean evaluation is enabled }
  341. if (nodetype in [orn,andn]) and
  342. not(cs_full_boolean_eval in aktlocalswitches) then
  343. begin
  344. location_reset(location,LOC_JUMP,OS_NO);
  345. case nodetype of
  346. andn :
  347. begin
  348. otl:=truelabel;
  349. objectlibrary.getjumplabel(truelabel);
  350. secondpass(left);
  351. maketojumpbool(exprasmlist,left,lr_load_regvars);
  352. cg.a_label(exprasmlist,truelabel);
  353. truelabel:=otl;
  354. end;
  355. orn :
  356. begin
  357. ofl:=falselabel;
  358. objectlibrary.getjumplabel(falselabel);
  359. secondpass(left);
  360. maketojumpbool(exprasmlist,left,lr_load_regvars);
  361. cg.a_label(exprasmlist,falselabel);
  362. falselabel:=ofl;
  363. end;
  364. else
  365. internalerror(200307044);
  366. end;
  367. secondpass(right);
  368. maketojumpbool(exprasmlist,right,lr_load_regvars);
  369. end
  370. else
  371. begin
  372. pass_left_right;
  373. force_reg_left_right(false,true);
  374. set_result_location_reg;
  375. case nodetype of
  376. xorn :
  377. cgop:=OP_XOR;
  378. orn :
  379. cgop:=OP_OR;
  380. andn :
  381. cgop:=OP_AND;
  382. else
  383. internalerror(200203247);
  384. end;
  385. if right.location.loc <> LOC_CONSTANT then
  386. cg.a_op_reg_reg_reg(exprasmlist,cgop,location.size,
  387. left.location.register,right.location.register,
  388. location.register)
  389. else
  390. cg.a_op_const_reg_reg(exprasmlist,cgop,location.size,
  391. right.location.value,left.location.register,
  392. location.register);
  393. end;
  394. end;
  395. {*****************************************************************************
  396. 64-bit
  397. *****************************************************************************}
  398. procedure tcgaddnode.second_op64bit;
  399. begin
  400. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  401. second_cmp64bit
  402. else
  403. second_add64bit;
  404. end;
  405. procedure tcgaddnode.second_add64bit;
  406. var
  407. op : TOpCG;
  408. checkoverflow : boolean;
  409. ovloc : tlocation;
  410. begin
  411. ovloc.loc:=LOC_VOID;
  412. pass_left_right;
  413. force_reg_left_right(false,true);
  414. set_result_location_reg;
  415. { assume no overflow checking is required }
  416. checkoverflow := false;
  417. case nodetype of
  418. addn :
  419. begin
  420. op:=OP_ADD;
  421. checkoverflow:=true;
  422. end;
  423. subn :
  424. begin
  425. op:=OP_SUB;
  426. checkoverflow:=true;
  427. end;
  428. xorn:
  429. op:=OP_XOR;
  430. orn:
  431. op:=OP_OR;
  432. andn:
  433. op:=OP_AND;
  434. muln:
  435. begin
  436. { should be handled in pass_1 (JM) }
  437. internalerror(200109051);
  438. end;
  439. else
  440. internalerror(2002072705);
  441. end;
  442. {$ifdef cpu64bit}
  443. case nodetype of
  444. xorn,orn,andn,addn:
  445. begin
  446. if (right.location.loc = LOC_CONSTANT) then
  447. cg.a_op_const_reg_reg(exprasmlist,op,location.size,right.location.value,
  448. left.location.register,location.register)
  449. else
  450. cg.a_op_reg_reg_reg(exprasmlist,op,location.size,right.location.register,
  451. left.location.register,location.register);
  452. end;
  453. subn:
  454. begin
  455. if (nf_swaped in flags) then
  456. swapleftright;
  457. if left.location.loc <> LOC_CONSTANT then
  458. begin
  459. if right.location.loc <> LOC_CONSTANT then
  460. // reg64 - reg64
  461. cg.a_op_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  462. right.location.register,left.location.register,location.register,
  463. checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc)
  464. else
  465. // reg64 - const64
  466. cg.a_op_const_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  467. right.location.value,left.location.register,location.register,
  468. checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc);
  469. end
  470. else
  471. begin
  472. // const64 - reg64
  473. location_force_reg(exprasmlist,left.location,left.location.size,true);
  474. cg.a_op_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  475. right.location.register,left.location.register,location.register,
  476. checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc);
  477. end;
  478. end;
  479. else
  480. internalerror(2002072803);
  481. end;
  482. {$else cpu64bit}
  483. case nodetype of
  484. xorn,orn,andn,addn:
  485. begin
  486. if (right.location.loc = LOC_CONSTANT) then
  487. cg64.a_op64_const_reg_reg_checkoverflow(exprasmlist,op,location.size,right.location.value64,
  488. left.location.register64,location.register64,
  489. checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc)
  490. else
  491. cg64.a_op64_reg_reg_reg_checkoverflow(exprasmlist,op,location.size,right.location.register64,
  492. left.location.register64,location.register64,
  493. checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc);
  494. end;
  495. subn:
  496. begin
  497. if (nf_swaped in flags) then
  498. swapleftright;
  499. if left.location.loc <> LOC_CONSTANT then
  500. begin
  501. if right.location.loc <> LOC_CONSTANT then
  502. // reg64 - reg64
  503. cg64.a_op64_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  504. right.location.register64,left.location.register64,
  505. location.register64,
  506. checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc)
  507. else
  508. // reg64 - const64
  509. cg64.a_op64_const_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  510. right.location.value64,left.location.register64,
  511. location.register64,
  512. checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc)
  513. end
  514. else
  515. begin
  516. // const64 - reg64
  517. location_force_reg(exprasmlist,left.location,left.location.size,true);
  518. cg64.a_op64_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  519. right.location.register64,left.location.register64,
  520. location.register64,
  521. checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc);
  522. end;
  523. end;
  524. else
  525. internalerror(2002072803);
  526. end;
  527. {$endif cpu64bit}
  528. { emit overflow check if enabled }
  529. if checkoverflow then
  530. cg.g_overflowcheck_loc(exprasmlist,Location,ResultType.Def,ovloc);
  531. end;
  532. {*****************************************************************************
  533. Strings
  534. *****************************************************************************}
  535. procedure tcgaddnode.second_addstring;
  536. begin
  537. { this should already be handled in pass1 }
  538. internalerror(2002072402);
  539. end;
  540. {*****************************************************************************
  541. Floats
  542. *****************************************************************************}
  543. procedure tcgaddnode.second_opfloat;
  544. begin
  545. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  546. second_cmpfloat
  547. else
  548. second_addfloat;
  549. end;
  550. {*****************************************************************************
  551. Ordinals
  552. *****************************************************************************}
  553. procedure tcgaddnode.second_opordinal;
  554. begin
  555. if (nodetype in [ltn,lten,gtn,gten,equaln,unequaln]) then
  556. second_cmpordinal
  557. else
  558. second_addordinal;
  559. end;
  560. procedure tcgaddnode.second_addordinal;
  561. var
  562. unsigned,
  563. checkoverflow : boolean;
  564. cgop : topcg;
  565. tmpreg : tregister;
  566. ovloc : tlocation;
  567. begin
  568. ovloc.loc:=LOC_VOID;
  569. pass_left_right;
  570. force_reg_left_right(false,true);
  571. set_result_location_reg;
  572. { determine if the comparison will be unsigned }
  573. unsigned:=not(is_signed(left.resulttype.def)) or
  574. not(is_signed(right.resulttype.def));
  575. { assume no overflow checking is require }
  576. checkoverflow := false;
  577. case nodetype of
  578. addn:
  579. begin
  580. cgop:=OP_ADD;
  581. checkoverflow:=true;
  582. end;
  583. xorn :
  584. begin
  585. cgop:=OP_XOR;
  586. end;
  587. orn :
  588. begin
  589. cgop:=OP_OR;
  590. end;
  591. andn:
  592. begin
  593. cgop:=OP_AND;
  594. end;
  595. muln:
  596. begin
  597. checkoverflow:=true;
  598. if unsigned then
  599. cgop:=OP_MUL
  600. else
  601. cgop:=OP_IMUL;
  602. end;
  603. subn :
  604. begin
  605. checkoverflow:=true;
  606. cgop:=OP_SUB;
  607. end;
  608. end;
  609. if nodetype<>subn then
  610. begin
  611. if (right.location.loc<>LOC_CONSTANT) then
  612. cg.a_op_reg_reg_reg_checkoverflow(exprasmlist,cgop,location.size,
  613. left.location.register,right.location.register,
  614. location.register,checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc)
  615. else
  616. cg.a_op_const_reg_reg_checkoverflow(exprasmlist,cgop,location.size,
  617. right.location.value,left.location.register,
  618. location.register,checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc);
  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_checkoverflow(exprasmlist,OP_SUB,location.size,
  628. right.location.register,left.location.register,
  629. location.register,checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc)
  630. else
  631. cg.a_op_const_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  632. aword(right.location.value),left.location.register,
  633. location.register,checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc);
  634. end
  635. else
  636. begin
  637. tmpreg:=cg.getintregister(exprasmlist,location.size);
  638. cg.a_load_const_reg(exprasmlist,location.size,
  639. left.location.value,tmpreg);
  640. cg.a_op_reg_reg_reg_checkoverflow(exprasmlist,OP_SUB,location.size,
  641. right.location.register,tmpreg,location.register,checkoverflow and (cs_check_overflow in aktlocalswitches),ovloc);
  642. end;
  643. end;
  644. { emit overflow check if required }
  645. if checkoverflow then
  646. cg.g_overflowcheck_loc(exprasmlist,Location,ResultType.Def,ovloc);
  647. end;
  648. procedure tcgaddnode.second_cmpboolean;
  649. begin
  650. second_cmpordinal;
  651. end;
  652. {*****************************************************************************
  653. pass_2
  654. *****************************************************************************}
  655. procedure tcgaddnode.pass_2;
  656. begin
  657. case left.resulttype.def.deftype of
  658. orddef :
  659. begin
  660. { handling boolean expressions }
  661. if is_boolean(left.resulttype.def) and
  662. is_boolean(right.resulttype.def) then
  663. second_opboolean
  664. { 64bit operations }
  665. else if is_64bit(left.resulttype.def) then
  666. second_op64bit
  667. else
  668. second_opordinal;
  669. end;
  670. stringdef :
  671. begin
  672. second_addstring;
  673. end;
  674. setdef :
  675. begin
  676. {Normalsets are already handled in pass1 if mmx
  677. should not be used.}
  678. if (tsetdef(left.resulttype.def).settype<>smallset) then
  679. begin
  680. {$ifdef SUPPORT_MMX}
  681. {$ifdef i386}
  682. if cs_mmx in aktlocalswitches then
  683. second_opmmxset
  684. else
  685. {$endif}
  686. {$endif SUPPORT_MMX}
  687. internalerror(200109041);
  688. end
  689. else
  690. second_opsmallset;
  691. end;
  692. arraydef :
  693. begin
  694. { support dynarr=nil }
  695. if is_dynamic_array(left.resulttype.def) then
  696. second_opordinal
  697. {$ifdef SUPPORT_MMX}
  698. else
  699. if is_mmx_able_array(left.resulttype.def) then
  700. second_opmmx
  701. {$endif SUPPORT_MMX}
  702. else
  703. internalerror(200306016);
  704. end;
  705. floatdef :
  706. second_opfloat;
  707. else
  708. second_opordinal;
  709. end;
  710. end;
  711. begin
  712. caddnode:=tcgaddnode;
  713. end.