nmat.pas 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  1. {
  2. Copyright (c) 2000-2005 by Florian Klaempfl
  3. Type checking and register allocation for math nodes
  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 nmat;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node;
  22. type
  23. tmoddivnode = class(tbinopnode)
  24. function pass_1 : tnode;override;
  25. function pass_typecheck:tnode;override;
  26. function simplify(forinline : boolean) : tnode;override;
  27. protected
  28. { override the following if you want to implement }
  29. { parts explicitely in the code generator (JM) }
  30. function use_moddiv64bitint_helper: boolean; virtual;
  31. function first_moddiv64bitint: tnode; virtual;
  32. function firstoptimize: tnode; virtual;
  33. function first_moddivint: tnode; virtual;
  34. end;
  35. tmoddivnodeclass = class of tmoddivnode;
  36. tshlshrnode = class(tbinopnode)
  37. function pass_1 : tnode;override;
  38. function pass_typecheck:tnode;override;
  39. function simplify(forinline : boolean) : tnode;override;
  40. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  41. { override the following if you want to implement }
  42. { parts explicitely in the code generator (CEC)
  43. Should return nil, if everything will be handled
  44. in the code generator
  45. }
  46. function first_shlshr64bitint: tnode; virtual;
  47. {$endif not cpu64bitalu and not cpuhighleveltarget}
  48. end;
  49. tshlshrnodeclass = class of tshlshrnode;
  50. tunaryminusnode = class(tunarynode)
  51. constructor create(expr : tnode);virtual;
  52. function pass_1 : tnode;override;
  53. function pass_typecheck:tnode;override;
  54. function simplify(forinline : boolean) : tnode;override;
  55. end;
  56. tunaryminusnodeclass = class of tunaryminusnode;
  57. tunaryplusnode = class(tunarynode)
  58. constructor create(expr : tnode);virtual;
  59. function pass_1 : tnode;override;
  60. function pass_typecheck:tnode;override;
  61. end;
  62. tunaryplusnodeclass = class of tunaryplusnode;
  63. tnotnode = class(tunarynode)
  64. constructor create(expr : tnode);virtual;
  65. function pass_1 : tnode;override;
  66. function pass_typecheck:tnode;override;
  67. function simplify(forinline : boolean) : tnode;override;
  68. {$ifdef state_tracking}
  69. function track_state_pass(exec_known:boolean):boolean;override;
  70. {$endif}
  71. end;
  72. tnotnodeclass = class of tnotnode;
  73. var
  74. cmoddivnode : tmoddivnodeclass = tmoddivnode;
  75. cshlshrnode : tshlshrnodeclass = tshlshrnode;
  76. cunaryminusnode : tunaryminusnodeclass = tunaryminusnode;
  77. cunaryplusnode : tunaryplusnodeclass = tunaryplusnode;
  78. cnotnode : tnotnodeclass = tnotnode;
  79. implementation
  80. uses
  81. systems,
  82. verbose,globals,cutils,compinnr,
  83. globtype,constexp,
  84. symconst,symtype,symdef,
  85. defcmp,defutil,
  86. htypechk,pass_1,
  87. cgbase,
  88. ncon,ncnv,ncal,nadd,nld,nbas,nflw,ninl,
  89. nutils;
  90. {****************************************************************************
  91. TMODDIVNODE
  92. ****************************************************************************}
  93. function tmoddivnode.simplify(forinline : boolean):tnode;
  94. var
  95. rv,lv : tconstexprint;
  96. begin
  97. result:=nil;
  98. if is_constintnode(right) then
  99. begin
  100. rv:=tordconstnode(right).value;
  101. if rv = 1 then
  102. begin
  103. case nodetype of
  104. modn:
  105. result := cordconstnode.create(0,left.resultdef,true);
  106. divn:
  107. result := left.getcopy;
  108. else
  109. internalerror(2019050518);
  110. end;
  111. exit;
  112. end;
  113. if rv = 0 then
  114. begin
  115. Message(parser_e_division_by_zero);
  116. { recover }
  117. tordconstnode(right).value := 1;
  118. end;
  119. { the following simplification is also required for correctness
  120. on x86, as its transformation of divisions by constants to
  121. multiplications and shifts does not handle -1 correctly }
  122. if (rv=-1) and
  123. (nodetype=divn) then
  124. begin
  125. result:=cunaryminusnode.create(left);
  126. left:=nil;
  127. exit;
  128. end;
  129. if (nf_isomod in flags) and
  130. (rv<=0) then
  131. begin
  132. Message(cg_e_mod_only_defined_for_pos_quotient);
  133. { recover }
  134. tordconstnode(right).value := 1;
  135. end;
  136. end;
  137. if is_constintnode(right) and is_constintnode(left) then
  138. begin
  139. rv:=tordconstnode(right).value;
  140. lv:=tordconstnode(left).value;
  141. case nodetype of
  142. modn:
  143. if nf_isomod in flags then
  144. begin
  145. if lv>=0 then
  146. result:=create_simplified_ord_const(lv mod rv,resultdef,forinline)
  147. else
  148. if ((-lv) mod rv)=0 then
  149. result:=create_simplified_ord_const((-lv) mod rv,resultdef,forinline)
  150. else
  151. result:=create_simplified_ord_const(rv-((-lv) mod rv),resultdef,forinline);
  152. end
  153. else
  154. result:=create_simplified_ord_const(lv mod rv,resultdef,forinline);
  155. divn:
  156. result:=create_simplified_ord_const(lv div rv,resultdef,forinline);
  157. else
  158. internalerror(2019050519);
  159. end;
  160. end;
  161. end;
  162. function tmoddivnode.use_moddiv64bitint_helper: boolean;
  163. begin
  164. { not with an ifdef around the call to this routine, because e.g. the
  165. Java VM has a signed 64 bit division opcode, but not an unsigned
  166. one }
  167. {$if defined(cpu64bitalu) or defined(cpuhighleveltarget)}
  168. result:=false;
  169. {$else cpu64bitalu or cpuhighleveltarget}
  170. result:=
  171. (left.resultdef.typ=orddef) and
  172. (right.resultdef.typ=orddef) and
  173. { include currency as well }
  174. (is_64bit(left.resultdef) or is_64bit(right.resultdef));
  175. {$endif cpu64bitalu or cpuhighleveltarget}
  176. end;
  177. function tmoddivnode.pass_typecheck:tnode;
  178. var
  179. else_block,
  180. hp,t : tnode;
  181. rd,ld : torddef;
  182. else_statements,
  183. statements : tstatementnode;
  184. result_data : ttempcreatenode;
  185. nd : torddef;
  186. begin
  187. result:=nil;
  188. typecheckpass(left);
  189. typecheckpass(right);
  190. { avoid any problems with type parameters later on }
  191. if is_typeparam(left.resultdef) or is_typeparam(right.resultdef) then
  192. begin
  193. resultdef:=cundefinedtype;
  194. exit;
  195. end;
  196. set_varstate(left,vs_read,[vsf_must_be_valid]);
  197. set_varstate(right,vs_read,[vsf_must_be_valid]);
  198. if codegenerror then
  199. exit;
  200. { tp procvar support }
  201. maybe_call_procvar(left,true);
  202. maybe_call_procvar(right,true);
  203. { allow operator overloading }
  204. t:=self;
  205. if isbinaryoverloaded(t,[]) then
  206. begin
  207. result:=t;
  208. exit;
  209. end;
  210. { we need 2 orddefs always }
  211. if (left.resultdef.typ<>orddef) then
  212. inserttypeconv(left,sinttype);
  213. if (right.resultdef.typ<>orddef) then
  214. inserttypeconv(right,sinttype);
  215. if codegenerror then
  216. exit;
  217. { Try only now to simply constant
  218. as otherwise you might create
  219. tconstnode with return type that are
  220. not compatible with tconst node
  221. as in bug report 21566 PM }
  222. result:=simplify(false);
  223. if assigned(result) then
  224. exit;
  225. rd:=torddef(right.resultdef);
  226. ld:=torddef(left.resultdef);
  227. { if one operand is a cardinal and the other is a positive constant, convert the }
  228. { constant to a cardinal as well so we don't have to do a 64bit division (JM) }
  229. { Do the same for qwords and positive constants as well, otherwise things like }
  230. { "qword mod 10" are evaluated with int64 as result, which is wrong if the }
  231. { "qword" was > high(int64) (JM) }
  232. { Additionally, do the same for cardinal/qwords and other positive types, but }
  233. { always in a way that a smaller type is converted to a bigger type }
  234. { (webtbs/tw8870) }
  235. if (rd.ordtype in [u8bit,u16bit,u32bit,u64bit]) and
  236. ((is_constintnode(left) and
  237. (tordconstnode(left).value >= 0) and
  238. (tordconstnode(left).value <= get_max_value(rd))) or
  239. (not is_signed(ld) and
  240. (rd.size >= ld.size))) then
  241. begin
  242. inserttypeconv(left,right.resultdef);
  243. ld:=torddef(left.resultdef);
  244. end;
  245. if (ld.ordtype in [u8bit,u16bit,u32bit,u64bit]) and
  246. ((is_constintnode(right) and
  247. (tordconstnode(right).value >= 0) and
  248. (tordconstnode(right).value <= get_max_value(ld))) or
  249. (not is_signed(rd) and
  250. (ld.size >= rd.size))) then
  251. begin
  252. inserttypeconv(right,left.resultdef);
  253. rd:=torddef(right.resultdef);
  254. end;
  255. { when there is one currency value, everything is done
  256. using currency }
  257. if (ld.ordtype=scurrency) or
  258. (rd.ordtype=scurrency) then
  259. begin
  260. if (ld.ordtype<>scurrency) then
  261. inserttypeconv(left,s64currencytype);
  262. if (rd.ordtype<>scurrency) then
  263. inserttypeconv(right,s64currencytype);
  264. resultdef:=left.resultdef;
  265. end
  266. else
  267. { when there is one 64bit value, everything is done
  268. in 64bit }
  269. if (is_64bitint(left.resultdef) or
  270. is_64bitint(right.resultdef)) then
  271. begin
  272. if is_signed(rd) or is_signed(ld) then
  273. begin
  274. if (ld.ordtype<>s64bit) then
  275. inserttypeconv(left,s64inttype);
  276. if (rd.ordtype<>s64bit) then
  277. inserttypeconv(right,s64inttype);
  278. end
  279. else
  280. begin
  281. if (ld.ordtype<>u64bit) then
  282. inserttypeconv(left,u64inttype);
  283. if (rd.ordtype<>u64bit) then
  284. inserttypeconv(right,u64inttype);
  285. end;
  286. resultdef:=left.resultdef;
  287. end
  288. else
  289. { is there a larger than the native int? }
  290. if is_oversizedint(ld) or is_oversizedint(rd) then
  291. begin
  292. nd:=get_common_intdef(ld,rd,false);
  293. if (ld.ordtype<>nd.ordtype) then
  294. inserttypeconv(left,nd);
  295. if (rd.ordtype<>nd.ordtype) then
  296. inserttypeconv(right,nd);
  297. resultdef:=left.resultdef;
  298. end
  299. else
  300. { when mixing unsigned and signed native ints, convert everything to a larger signed type (JM) }
  301. if (is_nativeuint(rd) and
  302. is_signed(ld)) or
  303. (is_nativeuint(ld) and
  304. is_signed(rd)) then
  305. begin
  306. CGMessage(type_h_mixed_signed_unsigned);
  307. { get a signed int, larger than the native int }
  308. nd:=get_common_intdef(torddef(sinttype),torddef(uinttype),false);
  309. if (ld.ordtype<>nd.ordtype) then
  310. inserttypeconv(left,nd);
  311. if (rd.ordtype<>nd.ordtype) then
  312. inserttypeconv(right,nd);
  313. resultdef:=left.resultdef;
  314. end
  315. else
  316. begin
  317. { Make everything always default singed int }
  318. if not(rd.ordtype in [torddef(sinttype).ordtype,torddef(uinttype).ordtype]) then
  319. inserttypeconv(right,sinttype);
  320. if not(ld.ordtype in [torddef(sinttype).ordtype,torddef(uinttype).ordtype]) then
  321. inserttypeconv(left,sinttype);
  322. resultdef:=right.resultdef;
  323. end;
  324. { when the result is currency we need some extra code for
  325. division. this should not be done when the divn node is
  326. created internally }
  327. if (nodetype=divn) and
  328. not(nf_is_currency in flags) and
  329. is_currency(resultdef) then
  330. begin
  331. hp:=caddnode.create(muln,getcopy,cordconstnode.create(10000,s64currencytype,false));
  332. include(hp.flags,nf_is_currency);
  333. result:=hp;
  334. end;
  335. if (nodetype=modn) and (nf_isomod in flags) then
  336. begin
  337. result:=internalstatements(statements);
  338. else_block:=internalstatements(else_statements);
  339. result_data:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  340. { right <=0? }
  341. addstatement(statements,cifnode.create_internal(caddnode.create_internal(lten,right.getcopy,cordconstnode.create(0,resultdef,false)),
  342. { then: result:=left mod right }
  343. ccallnode.createintern('fpc_divbyzero',nil),
  344. nil
  345. ));
  346. { prepare else block }
  347. { result:=(-left) mod right }
  348. addstatement(else_statements,cassignmentnode.create(ctemprefnode.create(result_data),cmoddivnode.create(modn,cunaryminusnode.create(left.getcopy),right.getcopy)));
  349. { result<>0? }
  350. addstatement(else_statements,cifnode.create_internal(caddnode.create_internal(unequaln,ctemprefnode.create(result_data),cordconstnode.create(0,resultdef,false)),
  351. { then: result:=right-result }
  352. cassignmentnode.create_internal(ctemprefnode.create(result_data),caddnode.create_internal(subn,right.getcopy,ctemprefnode.create(result_data))),
  353. nil
  354. ));
  355. addstatement(statements,result_data);
  356. { if left>=0 }
  357. addstatement(statements,cifnode.create_internal(caddnode.create_internal(gten,left.getcopy,cordconstnode.create(0,resultdef,false)),
  358. { then: result:=left mod right }
  359. cassignmentnode.create_internal(ctemprefnode.create(result_data),cmoddivnode.create(modn,left.getcopy,right.getcopy)),
  360. { else block }
  361. else_block
  362. ));
  363. addstatement(statements,ctempdeletenode.create_normal_temp(result_data));
  364. addstatement(statements,ctemprefnode.create(result_data));
  365. end;
  366. end;
  367. function tmoddivnode.first_moddivint: tnode;
  368. {$ifdef cpuneedsdivhelper}
  369. var
  370. procname: string[31];
  371. begin
  372. result := nil;
  373. { otherwise create a call to a helper }
  374. if nodetype = divn then
  375. procname := 'fpc_div_'
  376. else
  377. procname := 'fpc_mod_';
  378. { only qword needs the unsigned code, the
  379. signed code is also used for currency }
  380. case torddef(resultdef).ordtype of
  381. u8bit:
  382. procname := procname + 'byte';
  383. s8bit:
  384. procname := procname + 'shortint';
  385. u16bit:
  386. procname := procname + 'word';
  387. s16bit:
  388. procname := procname + 'smallint';
  389. u32bit:
  390. procname := procname + 'dword';
  391. s32bit:
  392. procname := procname + 'longint';
  393. scurrency:
  394. procname := procname + 'currency';
  395. else
  396. internalerror(2015070501);
  397. end;
  398. result := ccallnode.createintern(procname,ccallparanode.create(left,
  399. ccallparanode.create(right,nil)));
  400. left := nil;
  401. right := nil;
  402. firstpass(result);
  403. if result.resultdef.typ<>orddef then
  404. internalerror(2013031701);
  405. if resultdef.typ<>orddef then
  406. internalerror(2013031701);
  407. if torddef(result.resultdef).ordtype <> torddef(resultdef).ordtype then
  408. inserttypeconv(result,resultdef);
  409. end;
  410. {$else cpuneedsdivhelper}
  411. begin
  412. result:=nil;
  413. end;
  414. {$endif cpuneedsdiv32helper}
  415. function tmoddivnode.first_moddiv64bitint: tnode;
  416. var
  417. procname: string[31];
  418. begin
  419. result := nil;
  420. { when currency is used set the result of the
  421. parameters to s64bit, so they are not converted }
  422. if is_currency(resultdef) then
  423. begin
  424. left.resultdef:=s64inttype;
  425. right.resultdef:=s64inttype;
  426. end;
  427. { otherwise create a call to a helper }
  428. if nodetype = divn then
  429. procname := 'fpc_div_'
  430. else
  431. procname := 'fpc_mod_';
  432. { only qword needs the unsigned code, the
  433. signed code is also used for currency }
  434. if is_signed(resultdef) then
  435. procname := procname + 'int64'
  436. else
  437. procname := procname + 'qword';
  438. result := ccallnode.createintern(procname,ccallparanode.create(left,
  439. ccallparanode.create(right,nil)));
  440. left := nil;
  441. right := nil;
  442. firstpass(result);
  443. end;
  444. function tmoddivnode.firstoptimize: tnode;
  445. var
  446. power,shiftval : longint;
  447. statements : tstatementnode;
  448. temp,resulttemp : ttempcreatenode;
  449. masknode : tnode;
  450. invertsign: Boolean;
  451. begin
  452. result := nil;
  453. { divide/mod a number by a constant which is a power of 2? }
  454. if (right.nodetype = ordconstn) and
  455. isabspowerof2(tordconstnode(right).value,power) and
  456. {$if defined(cpu64bitalu) or defined(cpuhighleveltarget)}
  457. { for 64 bit, we leave the optimization to the cg }
  458. (not is_signed(resultdef)) then
  459. {$else cpu64bitalu or cpuhighleveltarget}
  460. (((nodetype=divn) and is_oversizedord(resultdef)) or
  461. (nodetype=modn) or
  462. not is_signed(resultdef)) then
  463. {$endif cpu64bitalu or cpuhighleveltarget}
  464. begin
  465. if nodetype=divn then
  466. begin
  467. if is_signed(resultdef) then
  468. begin
  469. invertsign:=tordconstnode(right).value<0;
  470. if is_64bitint(left.resultdef) then
  471. if not (cs_opt_size in current_settings.optimizerswitches) then
  472. shiftval:=63
  473. else
  474. { the shift code is a lot bigger than the call to }
  475. { the divide helper }
  476. exit
  477. else
  478. shiftval:=left.resultdef.size*8-1;
  479. result:=internalstatements(statements);
  480. temp:=ctempcreatenode.create(left.resultdef,left.resultdef.size,tt_persistent,true);
  481. resulttemp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  482. addstatement(statements,resulttemp);
  483. addstatement(statements,temp);
  484. addstatement(statements,cassignmentnode.create(ctemprefnode.create(temp),
  485. left));
  486. left:=nil;
  487. { masknode is (sar(temp,shiftval) and ((1 shl power)-1))
  488. for power=1 (i.e. division by 2), masknode is simply (temp shr shiftval)}
  489. if power=1 then
  490. masknode:=
  491. cshlshrnode.create(shrn,
  492. ctemprefnode.create(temp),
  493. cordconstnode.create(shiftval,u8inttype,false)
  494. )
  495. else
  496. masknode:=
  497. caddnode.create(andn,
  498. cinlinenode.create(in_sar_x_y,false,
  499. ccallparanode.create(cordconstnode.create(shiftval,u8inttype,false),
  500. ccallparanode.create(ctemprefnode.create(temp),nil))
  501. ),
  502. cordconstnode.create(tcgint((qword(1) shl power)-1),
  503. right.resultdef,false)
  504. );
  505. if invertsign then
  506. addstatement(statements,cassignmentnode.create(ctemprefnode.create(resulttemp),
  507. cunaryminusnode.create(
  508. cinlinenode.create(in_sar_x_y,false,
  509. ccallparanode.create(cordconstnode.create(power,u8inttype,false),
  510. ccallparanode.create(caddnode.create(addn,ctemprefnode.create(temp),
  511. masknode),nil
  512. )))))
  513. )
  514. else
  515. addstatement(statements,cassignmentnode.create(ctemprefnode.create(resulttemp),
  516. cinlinenode.create(in_sar_x_y,false,
  517. ccallparanode.create(cordconstnode.create(power,u8inttype,false),
  518. ccallparanode.create(caddnode.create(addn,ctemprefnode.create(temp),
  519. masknode),nil
  520. ))))
  521. );
  522. addstatement(statements,ctempdeletenode.create(temp));
  523. addstatement(statements,ctempdeletenode.create_normal_temp(resulttemp));
  524. addstatement(statements,ctemprefnode.create(resulttemp));
  525. right.Free;
  526. end
  527. else
  528. begin
  529. tordconstnode(right).value:=power;
  530. result:=cshlshrnode.create(shrn,left,right)
  531. end;
  532. end
  533. else if is_signed(resultdef) then { signed modulus }
  534. begin
  535. if (cs_opt_size in current_settings.optimizerswitches) then
  536. exit;
  537. shiftval:=left.resultdef.size*8-1;
  538. tordconstnode(right).value.uvalue:=qword((qword(1) shl power)-1);
  539. result:=internalstatements(statements);
  540. temp:=ctempcreatenode.create(left.resultdef,left.resultdef.size,tt_persistent,true);
  541. resulttemp:=ctempcreatenode.create(resultdef,resultdef.size,tt_persistent,true);
  542. addstatement(statements,resulttemp);
  543. addstatement(statements,temp);
  544. addstatement(statements,cassignmentnode.create(ctemprefnode.create(temp),left));
  545. { mask:=sar(left,sizeof(left)*8-1) and ((1 shl power)-1); }
  546. if power=1 then
  547. masknode:=
  548. cshlshrnode.create(shrn,
  549. ctemprefnode.create(temp),
  550. cordconstnode.create(shiftval,u8inttype,false)
  551. )
  552. else
  553. masknode:=
  554. caddnode.create(andn,
  555. cinlinenode.create(in_sar_x_y,false,
  556. ccallparanode.create(cordconstnode.create(shiftval,u8inttype,false),
  557. ccallparanode.create(ctemprefnode.create(temp),nil))
  558. ),
  559. cordconstnode.create(tcgint((qword(1) shl power)-1),
  560. right.resultdef,false)
  561. );
  562. addstatement(statements,cassignmentnode.create(ctemprefnode.create(resulttemp),masknode));
  563. { result:=((left+mask) and right)-mask; }
  564. addstatement(statements,cassignmentnode.create(ctemprefnode.create(resulttemp),
  565. caddnode.create(subn,
  566. caddnode.create(andn,
  567. right,
  568. caddnode.create(addn,
  569. ctemprefnode.create(temp),
  570. ctemprefnode.create(resulttemp))),
  571. ctemprefnode.create(resulttemp))
  572. ));
  573. addstatement(statements,ctempdeletenode.create(temp));
  574. addstatement(statements,ctempdeletenode.create_normal_temp(resulttemp));
  575. addstatement(statements,ctemprefnode.create(resulttemp));
  576. end
  577. else
  578. begin
  579. tordconstnode(right).value.uvalue:=qword((qword(1) shl power)-1);
  580. result := caddnode.create(andn,left,right);
  581. end;
  582. { left and right are reused }
  583. left := nil;
  584. right := nil;
  585. firstpass(result);
  586. exit;
  587. end;
  588. end;
  589. function tmoddivnode.pass_1 : tnode;
  590. begin
  591. result:=nil;
  592. firstpass(left);
  593. firstpass(right);
  594. if codegenerror then
  595. exit;
  596. { Try to optimize mod/div }
  597. result := firstoptimize;
  598. if assigned(result) then
  599. exit;
  600. { 64bit }
  601. if use_moddiv64bitint_helper then
  602. begin
  603. result := first_moddiv64bitint;
  604. if assigned(result) then
  605. exit;
  606. expectloc:=LOC_REGISTER;
  607. end
  608. else
  609. begin
  610. result := first_moddivint;
  611. if assigned(result) then
  612. exit;
  613. end;
  614. expectloc:=LOC_REGISTER;
  615. end;
  616. {****************************************************************************
  617. TSHLSHRNODE
  618. ****************************************************************************}
  619. function tshlshrnode.simplify(forinline : boolean):tnode;
  620. var
  621. lvalue,rvalue : Tconstexprint;
  622. begin
  623. result:=nil;
  624. { constant folding }
  625. if is_constintnode(right) then
  626. begin
  627. if forinline then
  628. begin
  629. { shl/shr are unsigned operations, so cut off upper bits }
  630. case resultdef.size of
  631. 1,2,4:
  632. rvalue:=tordconstnode(right).value and byte($1f);
  633. 8:
  634. rvalue:=tordconstnode(right).value and byte($3f);
  635. else
  636. internalerror(2013122302);
  637. end;
  638. end
  639. else
  640. rvalue:=tordconstnode(right).value;
  641. if is_constintnode(left) then
  642. begin
  643. if forinline then
  644. begin
  645. { shl/shr are unsigned operations, so cut off upper bits }
  646. case resultdef.size of
  647. 1:
  648. lvalue:=tordconstnode(left).value and byte($ff);
  649. 2:
  650. lvalue:=tordconstnode(left).value and word($ffff);
  651. 4:
  652. lvalue:=tordconstnode(left).value and dword($ffffffff);
  653. 8:
  654. lvalue:=tordconstnode(left).value and qword($ffffffffffffffff);
  655. else
  656. internalerror(2013122301);
  657. end;
  658. end
  659. else
  660. lvalue:=tordconstnode(left).value;
  661. case nodetype of
  662. shrn:
  663. result:=create_simplified_ord_const(lvalue shr rvalue,resultdef,forinline);
  664. shln:
  665. result:=create_simplified_ord_const(lvalue shl rvalue,resultdef,forinline);
  666. else
  667. internalerror(2019050517);
  668. end;
  669. end
  670. else if rvalue=0 then
  671. begin
  672. result:=left;
  673. left:=nil;
  674. end;
  675. end
  676. else if is_constintnode(left) then
  677. begin
  678. lvalue:=tordconstnode(left).value;
  679. { shl/shr are unsigned operations, so cut off upper bits }
  680. case resultdef.size of
  681. 1:
  682. lvalue:=tordconstnode(left).value and byte($ff);
  683. 2:
  684. lvalue:=tordconstnode(left).value and word($ffff);
  685. 4:
  686. lvalue:=tordconstnode(left).value and dword($ffffffff);
  687. 8:
  688. lvalue:=tordconstnode(left).value and qword($ffffffffffffffff);
  689. else
  690. internalerror(2013122301);
  691. end;
  692. { '0 shl x' and '0 shr x' are 0 }
  693. if (lvalue=0) and
  694. ((cs_opt_level4 in current_settings.optimizerswitches) or
  695. not might_have_sideeffects(right)) then
  696. result:=cordconstnode.create(0,resultdef,true);
  697. end;
  698. end;
  699. function tshlshrnode.pass_typecheck:tnode;
  700. var
  701. t : tnode;
  702. begin
  703. result:=nil;
  704. typecheckpass(left);
  705. typecheckpass(right);
  706. { avoid any problems with type parameters later on }
  707. if is_typeparam(left.resultdef) or is_typeparam(right.resultdef) then
  708. begin
  709. resultdef:=cundefinedtype;
  710. exit;
  711. end;
  712. set_varstate(right,vs_read,[vsf_must_be_valid]);
  713. set_varstate(left,vs_read,[vsf_must_be_valid]);
  714. if codegenerror then
  715. exit;
  716. { tp procvar support }
  717. maybe_call_procvar(left,true);
  718. maybe_call_procvar(right,true);
  719. { allow operator overloading }
  720. t:=self;
  721. if isbinaryoverloaded(t,[]) then
  722. begin
  723. result:=t;
  724. exit;
  725. end;
  726. {$ifdef SUPPORT_MMX}
  727. if (cs_mmx in current_settings.localswitches) and
  728. is_mmx_able_array(left.resultdef) and
  729. ((is_mmx_able_array(right.resultdef) and
  730. equal_defs(left.resultdef,right.resultdef)
  731. ) or is_constintnode(right)) then
  732. begin
  733. if not(mmx_type(left.resultdef) in [mmxu16bit,mmxs16bit,mmxfixed16,mmxu32bit,mmxs32bit,mmxu64bit,mmxs64bit]) then
  734. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),left.resultdef.typename,right.resultdef.typename);
  735. if not(is_mmx_able_array(right.resultdef)) then
  736. inserttypeconv(right,sinttype);
  737. end
  738. else
  739. {$endif SUPPORT_MMX}
  740. begin
  741. { calculations for ordinals < 32 bit have to be done in
  742. 32 bit for backwards compatibility. That way 'shl 33' is
  743. the same as 'shl 1'. It's ugly but compatible with delphi/tp/gcc }
  744. if (not is_64bit(left.resultdef)) and
  745. (torddef(left.resultdef).ordtype<>u32bit) then
  746. begin
  747. { keep singness of orignal type }
  748. if is_signed(left.resultdef) then
  749. begin
  750. {$if defined(cpu64bitalu) or defined(cpu32bitalu)}
  751. inserttypeconv(left,s32inttype)
  752. {$elseif defined(cpu16bitalu) or defined(cpu8bitalu)}
  753. inserttypeconv(left,get_common_intdef(torddef(left.resultdef),torddef(sinttype),true));
  754. {$else}
  755. internalerror(2013031301);
  756. {$endif}
  757. end
  758. else
  759. begin
  760. {$if defined(cpu64bitalu) or defined(cpu32bitalu)}
  761. inserttypeconv(left,u32inttype);
  762. {$elseif defined(cpu16bitalu) or defined(cpu8bitalu)}
  763. inserttypeconv(left,get_common_intdef(torddef(left.resultdef),torddef(uinttype),true));
  764. {$else}
  765. internalerror(2013031301);
  766. {$endif}
  767. end
  768. end;
  769. inserttypeconv(right,sinttype);
  770. end;
  771. resultdef:=left.resultdef;
  772. result:=simplify(false);
  773. if assigned(result) then
  774. exit;
  775. end;
  776. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  777. function tshlshrnode.first_shlshr64bitint: tnode;
  778. var
  779. procname: string[31];
  780. begin
  781. result := nil;
  782. { Normally already done below, but called again,
  783. just in case it is called directly }
  784. firstpass(left);
  785. { otherwise create a call to a helper }
  786. if is_signed(left.resultdef) then
  787. procname:='int64'
  788. else
  789. procname:='qword';
  790. if nodetype = shln then
  791. procname := 'fpc_shl_'+procname
  792. else
  793. procname := 'fpc_shr_'+procname;
  794. { this order of parameters works at least for the arm,
  795. however it should work for any calling conventions (FK) }
  796. result := ccallnode.createintern(procname,ccallparanode.create(right,
  797. ccallparanode.create(left,nil)));
  798. left := nil;
  799. right := nil;
  800. firstpass(result);
  801. end;
  802. {$endif not cpu64bitalu and not cpuhighleveltarget}
  803. function tshlshrnode.pass_1 : tnode;
  804. begin
  805. result:=nil;
  806. firstpass(left);
  807. firstpass(right);
  808. if codegenerror then
  809. exit;
  810. expectloc:=LOC_REGISTER;
  811. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  812. { 64 bit ints have their own shift handling }
  813. if is_64bit(left.resultdef) then
  814. result := first_shlshr64bitint;
  815. {$endif not cpu64bitalu and not cpuhighleveltarget}
  816. end;
  817. {****************************************************************************
  818. TUNARYMINUSNODE
  819. ****************************************************************************}
  820. constructor tunaryminusnode.create(expr : tnode);
  821. begin
  822. inherited create(unaryminusn,expr);
  823. end;
  824. function tunaryminusnode.simplify(forinline : boolean):tnode;
  825. begin
  826. result:=nil;
  827. { constant folding }
  828. if is_constintnode(left) then
  829. begin
  830. result:=create_simplified_ord_const(-tordconstnode(left).value,resultdef,forinline);
  831. exit;
  832. end;
  833. if is_constrealnode(left) then
  834. begin
  835. trealconstnode(left).value_real:=-trealconstnode(left).value_real;
  836. { Avoid integer overflow on x86_64 CPU for currency value }
  837. { i386 uses fildll/fchs/fistll instructions which never seem
  838. to raise any coprocessor flags .. }
  839. {$push}{$Q-}
  840. trealconstnode(left).value_currency:=-trealconstnode(left).value_currency;
  841. result:=left;
  842. {$pop}
  843. left:=nil;
  844. exit;
  845. end;
  846. end;
  847. function tunaryminusnode.pass_typecheck : tnode;
  848. var
  849. t : tnode;
  850. begin
  851. result:=nil;
  852. typecheckpass(left);
  853. { avoid any problems with type parameters later on }
  854. if is_typeparam(left.resultdef) then
  855. begin
  856. resultdef:=cundefinedtype;
  857. exit;
  858. end;
  859. set_varstate(left,vs_read,[vsf_must_be_valid]);
  860. if codegenerror then
  861. exit;
  862. result:=simplify(false);
  863. if assigned(result) then
  864. exit;
  865. resultdef:=left.resultdef;
  866. if (left.resultdef.typ=floatdef) or
  867. is_currency(left.resultdef) then
  868. begin
  869. end
  870. {$ifdef SUPPORT_MMX}
  871. else if (cs_mmx in current_settings.localswitches) and
  872. is_mmx_able_array(left.resultdef) then
  873. begin
  874. { if saturation is on, left.resultdef isn't
  875. "mmx able" (FK)
  876. if (cs_mmx_saturation in current_settings.localswitches^) and
  877. (torddef(tarraydef(resultdef).definition).typ in
  878. [s32bit,u32bit]) then
  879. CGMessage(type_e_mismatch);
  880. }
  881. end
  882. {$endif SUPPORT_MMX}
  883. else if is_oversizedord(left.resultdef) then
  884. begin
  885. if is_64bit(left.resultdef) then
  886. inserttypeconv(left,s64inttype)
  887. else if is_32bit(left.resultdef) then
  888. inserttypeconv(left,s32inttype)
  889. else if is_16bit(left.resultdef) then
  890. inserttypeconv(left,s16inttype)
  891. else
  892. internalerror(2013040701);
  893. resultdef:=left.resultdef;
  894. end
  895. else if (left.resultdef.typ=orddef) then
  896. begin
  897. inserttypeconv(left,sinttype);
  898. resultdef:=left.resultdef
  899. end
  900. else
  901. begin
  902. { allow operator overloading }
  903. t:=self;
  904. if isunaryoverloaded(t,[]) then
  905. begin
  906. result:=t;
  907. exit;
  908. end;
  909. CGMessage(type_e_mismatch);
  910. end;
  911. end;
  912. { generic code }
  913. { overridden by: }
  914. { i386 }
  915. function tunaryminusnode.pass_1 : tnode;
  916. var
  917. procname: string[31];
  918. begin
  919. result:=nil;
  920. firstpass(left);
  921. if codegenerror then
  922. exit;
  923. if (cs_fp_emulation in current_settings.moduleswitches) and (left.resultdef.typ=floatdef) then
  924. begin
  925. if not(target_info.system in systems_wince) then
  926. begin
  927. expectloc:=LOC_REGISTER;
  928. exit;
  929. end
  930. else
  931. begin
  932. case tfloatdef(resultdef).floattype of
  933. s32real:
  934. procname:='negs';
  935. s64real:
  936. procname:='negd';
  937. {!!! not yet implemented
  938. s128real:
  939. }
  940. else
  941. internalerror(2005082802);
  942. end;
  943. result:=ccallnode.createintern(procname,ccallparanode.create(left,nil));
  944. end;
  945. left:=nil;
  946. end
  947. else
  948. begin
  949. if (left.resultdef.typ=floatdef) then
  950. expectloc:=LOC_FPUREGISTER
  951. {$ifdef SUPPORT_MMX}
  952. else if (cs_mmx in current_settings.localswitches) and
  953. is_mmx_able_array(left.resultdef) then
  954. expectloc:=LOC_MMXREGISTER
  955. {$endif SUPPORT_MMX}
  956. else if (left.resultdef.typ=orddef) then
  957. expectloc:=LOC_REGISTER;
  958. end;
  959. end;
  960. {****************************************************************************
  961. TUNARYPLUSNODE
  962. ****************************************************************************}
  963. constructor tunaryplusnode.create(expr: tnode);
  964. begin
  965. inherited create(unaryplusn,expr);
  966. end;
  967. function tunaryplusnode.pass_1: tnode;
  968. begin
  969. result:=nil;
  970. { can never happen because all the conversions happen
  971. in pass_typecheck }
  972. internalerror(201012250);
  973. end;
  974. function tunaryplusnode.pass_typecheck: tnode;
  975. var
  976. t:tnode;
  977. begin
  978. result:=nil;
  979. typecheckpass(left);
  980. { avoid any problems with type parameters later on }
  981. if is_typeparam(left.resultdef) then
  982. begin
  983. resultdef:=cundefinedtype;
  984. exit;
  985. end;
  986. set_varstate(left,vs_read,[vsf_must_be_valid]);
  987. if codegenerror then
  988. exit;
  989. if is_constintnode(left) or
  990. is_constrealnode(left) or
  991. (left.resultdef.typ=floatdef) or
  992. is_currency(left.resultdef)
  993. {$ifdef SUPPORT_MMX}
  994. or ((cs_mmx in current_settings.localswitches) and
  995. is_mmx_able_array(left.resultdef))
  996. {$endif SUPPORT_MMX}
  997. then
  998. begin
  999. result:=left;
  1000. left:=nil;
  1001. end
  1002. else if is_oversizedord(left.resultdef) then
  1003. begin
  1004. if is_64bit(left.resultdef) then
  1005. inserttypeconv(left,s64inttype)
  1006. else if is_32bit(left.resultdef) then
  1007. inserttypeconv(left,s32inttype)
  1008. else if is_16bit(left.resultdef) then
  1009. inserttypeconv(left,s16inttype)
  1010. else
  1011. internalerror(2013040702);
  1012. result:=left;
  1013. left:=nil;
  1014. end
  1015. else if (left.resultdef.typ=orddef) then
  1016. begin
  1017. inserttypeconv(left,sinttype);
  1018. result:=left;
  1019. left:=nil;
  1020. end
  1021. else
  1022. begin
  1023. { allow operator overloading }
  1024. t:=self;
  1025. if isunaryoverloaded(t,[]) then
  1026. begin
  1027. result:=t;
  1028. exit;
  1029. end;
  1030. CGMessage(type_e_mismatch);
  1031. end;
  1032. end;
  1033. {****************************************************************************
  1034. TNOTNODE
  1035. ****************************************************************************}
  1036. const
  1037. boolean_reverse:array[ltn..unequaln] of Tnodetype=(
  1038. gten,gtn,lten,ltn,unequaln,equaln
  1039. );
  1040. constructor tnotnode.create(expr : tnode);
  1041. begin
  1042. inherited create(notn,expr);
  1043. end;
  1044. function tnotnode.simplify(forinline : boolean):tnode;
  1045. var
  1046. v : tconstexprint;
  1047. t : tnode;
  1048. def : tdef;
  1049. begin
  1050. result:=nil;
  1051. { Try optmimizing ourself away }
  1052. if left.nodetype=notn then
  1053. begin
  1054. { Double not. Remove both }
  1055. result:=Tnotnode(left).left;
  1056. tnotnode(left).left:=nil;
  1057. exit;
  1058. end;
  1059. if (left.nodetype in [ltn,lten,equaln,unequaln,gtn,gten]) then
  1060. begin
  1061. { Not of boolean expression. Turn around the operator and remove
  1062. the not. This is not allowed for sets with the gten/lten,
  1063. because there is no ltn/gtn support }
  1064. if (taddnode(left).left.resultdef.typ<>setdef) or
  1065. (left.nodetype in [equaln,unequaln]) then
  1066. begin
  1067. result:=left;
  1068. left.nodetype:=boolean_reverse[left.nodetype];
  1069. left:=nil;
  1070. exit;
  1071. end;
  1072. end;
  1073. { constant folding }
  1074. if (left.nodetype=ordconstn) and
  1075. (left.resultdef.typ=orddef) then
  1076. begin
  1077. v:=tordconstnode(left).value;
  1078. def:=left.resultdef;
  1079. case torddef(left.resultdef).ordtype of
  1080. pasbool1,
  1081. pasbool8,
  1082. pasbool16,
  1083. pasbool32,
  1084. pasbool64:
  1085. v:=byte(not(boolean(int64(v))));
  1086. bool8bit,
  1087. bool16bit,
  1088. bool32bit,
  1089. bool64bit:
  1090. begin
  1091. if v=0 then
  1092. v:=-1
  1093. else
  1094. v:=0;
  1095. end;
  1096. uchar,
  1097. uwidechar,
  1098. u8bit,
  1099. s8bit,
  1100. u16bit,
  1101. s16bit,
  1102. s32bit,
  1103. u32bit,
  1104. s64bit,
  1105. u64bit:
  1106. begin
  1107. { unsigned, equal or bigger than the native int size? }
  1108. if (torddef(left.resultdef).ordtype in [u64bit,u32bit,u16bit,u8bit,uchar,uwidechar]) and
  1109. (is_nativeord(left.resultdef) or is_oversizedord(left.resultdef)) then
  1110. begin
  1111. { Delphi-compatible: not dword = dword (not word = longint) }
  1112. { Extension: not qword = qword }
  1113. v:=qword(not qword(v));
  1114. { will be truncated by the ordconstnode for u32bit }
  1115. end
  1116. else
  1117. begin
  1118. v:=int64(not int64(v));
  1119. def:=get_common_intdef(torddef(left.resultdef),torddef(sinttype),false);
  1120. end;
  1121. end;
  1122. else
  1123. CGMessage(type_e_mismatch);
  1124. end;
  1125. { not-nodes are not range checked by the code generator -> also
  1126. don't range check while inlining; the resultdef is a bit tricky
  1127. though: the node's resultdef gets changed in most cases compared
  1128. to left, but the not-operation itself is caried out in the code
  1129. generator using the size of left
  1130. }
  1131. if not(forinline) then
  1132. t:=cordconstnode.create(v,def,false)
  1133. else
  1134. begin
  1135. { cut off the value if necessary }
  1136. t:=cordconstnode.create(v,left.resultdef,false);
  1137. { now convert to node's resultdef }
  1138. inserttypeconv_explicit(t,def);
  1139. end;
  1140. result:=t;
  1141. exit;
  1142. end;
  1143. end;
  1144. function tnotnode.pass_typecheck : tnode;
  1145. var
  1146. t : tnode;
  1147. begin
  1148. result:=nil;
  1149. typecheckpass(left);
  1150. { avoid any problems with type parameters later on }
  1151. if is_typeparam(left.resultdef) then
  1152. begin
  1153. resultdef:=cundefinedtype;
  1154. exit;
  1155. end;
  1156. set_varstate(left,vs_read,[vsf_must_be_valid]);
  1157. if codegenerror then
  1158. exit;
  1159. { tp procvar support }
  1160. maybe_call_procvar(left,true);
  1161. resultdef:=left.resultdef;
  1162. result:=simplify(false);
  1163. if assigned(result) then
  1164. exit;
  1165. if is_boolean(resultdef) then
  1166. begin
  1167. end
  1168. else
  1169. {$ifdef SUPPORT_MMX}
  1170. if (cs_mmx in current_settings.localswitches) and
  1171. is_mmx_able_array(left.resultdef) then
  1172. begin
  1173. end
  1174. else
  1175. {$endif SUPPORT_MMX}
  1176. {$ifndef cpu64bitaddr}
  1177. if is_64bitint(left.resultdef) then
  1178. begin
  1179. end
  1180. else
  1181. {$endif not cpu64bitaddr}
  1182. if is_integer(left.resultdef) then
  1183. begin
  1184. end
  1185. else
  1186. begin
  1187. { allow operator overloading }
  1188. t:=self;
  1189. if isunaryoverloaded(t,[]) then
  1190. begin
  1191. result:=t;
  1192. exit;
  1193. end;
  1194. CGMessage(type_e_mismatch);
  1195. end;
  1196. end;
  1197. function tnotnode.pass_1 : tnode;
  1198. begin
  1199. result:=nil;
  1200. firstpass(left);
  1201. if codegenerror then
  1202. exit;
  1203. expectloc:=left.expectloc;
  1204. if is_boolean(resultdef) then
  1205. begin
  1206. if (expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1207. expectloc:=LOC_REGISTER;
  1208. { before loading it into flags we need to load it into
  1209. a register thus 1 register is need PM }
  1210. {$ifdef cpuflags}
  1211. if left.expectloc<>LOC_JUMP then
  1212. expectloc:=LOC_FLAGS;
  1213. {$endif def cpuflags}
  1214. end
  1215. else
  1216. {$ifdef SUPPORT_MMX}
  1217. if (cs_mmx in current_settings.localswitches) and
  1218. is_mmx_able_array(left.resultdef) then
  1219. expectloc:=LOC_MMXREGISTER
  1220. else
  1221. {$endif SUPPORT_MMX}
  1222. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  1223. if is_64bit(left.resultdef) then
  1224. begin
  1225. if (expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1226. expectloc:=LOC_REGISTER;
  1227. end
  1228. else
  1229. {$endif not cpu64bitalu and not cpuhighleveltarget}
  1230. if is_integer(left.resultdef) then
  1231. expectloc:=LOC_REGISTER;
  1232. end;
  1233. {$ifdef state_tracking}
  1234. function Tnotnode.track_state_pass(exec_known:boolean):boolean;
  1235. begin
  1236. track_state_pass:=true;
  1237. if left.track_state_pass(exec_known) then
  1238. begin
  1239. left.resultdef:=nil;
  1240. do_typecheckpass(left);
  1241. end;
  1242. end;
  1243. {$endif}
  1244. end.