ncginl.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl and Carl Eric Codere
  3. Generate generic inline 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 ncginl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ninl;
  22. type
  23. tcginlinenode = class(tinlinenode)
  24. procedure pass_generate_code;override;
  25. procedure second_sizeoftypeof;virtual;
  26. procedure second_length;virtual;
  27. procedure second_predsucc;virtual;
  28. procedure second_incdec;virtual;
  29. procedure second_typeinfo;virtual;
  30. procedure second_includeexclude;virtual;
  31. procedure second_pi; virtual;
  32. procedure second_arctan_real; virtual;
  33. procedure second_abs_real; virtual;
  34. procedure second_sqr_real; virtual;
  35. procedure second_sqrt_real; virtual;
  36. procedure second_ln_real; virtual;
  37. procedure second_cos_real; virtual;
  38. procedure second_sin_real; virtual;
  39. procedure second_assigned; virtual;
  40. procedure second_get_frame;virtual;
  41. procedure second_get_caller_frame;virtual;
  42. procedure second_get_caller_addr;virtual;
  43. procedure second_prefetch; virtual;
  44. procedure second_round_real; virtual;
  45. procedure second_trunc_real; virtual;
  46. procedure second_abs_long; virtual;
  47. procedure second_rox_sar; virtual;
  48. procedure second_bsfbsr; virtual;
  49. procedure second_new; virtual;
  50. procedure second_setlength; virtual; abstract;
  51. procedure second_box; virtual; abstract;
  52. procedure second_popcnt; virtual;
  53. end;
  54. implementation
  55. uses
  56. globtype,systems,constexp,
  57. cutils,verbose,globals,
  58. symconst,symdef,defutil,symsym,
  59. aasmbase,aasmtai,aasmdata,aasmcpu,parabase,
  60. cgbase,pass_1,pass_2,
  61. cpuinfo,cpubase,paramgr,procinfo,
  62. nbas,ncon,ncal,ncnv,nld,ncgrtti,
  63. tgobj,ncgutil,
  64. cgutils,cgobj,hlcgobj
  65. {$ifndef cpu64bitalu}
  66. ,cg64f32
  67. {$endif not cpu64bitalu}
  68. ;
  69. {*****************************************************************************
  70. TCGINLINENODE
  71. *****************************************************************************}
  72. procedure tcginlinenode.pass_generate_code;
  73. begin
  74. location_reset(location,LOC_VOID,OS_NO);
  75. case inlinenumber of
  76. in_sizeof_x,
  77. in_typeof_x :
  78. second_SizeofTypeOf;
  79. in_length_x :
  80. second_Length;
  81. in_pred_x,
  82. in_succ_x:
  83. second_PredSucc;
  84. in_dec_x,
  85. in_inc_x :
  86. second_IncDec;
  87. in_typeinfo_x:
  88. second_TypeInfo;
  89. in_include_x_y,
  90. in_exclude_x_y:
  91. second_IncludeExclude;
  92. in_pi_real:
  93. second_pi;
  94. in_sin_real:
  95. second_sin_real;
  96. in_arctan_real:
  97. second_arctan_real;
  98. in_abs_real:
  99. second_abs_real;
  100. in_abs_long:
  101. second_abs_long;
  102. in_round_real:
  103. second_round_real;
  104. in_trunc_real:
  105. second_trunc_real;
  106. in_sqr_real:
  107. second_sqr_real;
  108. in_sqrt_real:
  109. second_sqrt_real;
  110. in_ln_real:
  111. second_ln_real;
  112. in_cos_real:
  113. second_cos_real;
  114. in_prefetch_var:
  115. second_prefetch;
  116. in_assigned_x:
  117. second_assigned;
  118. in_get_frame:
  119. second_get_frame;
  120. in_get_caller_frame:
  121. second_get_caller_frame;
  122. in_get_caller_addr:
  123. second_get_caller_addr;
  124. in_unaligned_x:
  125. begin
  126. secondpass(tcallparanode(left).left);
  127. location:=tcallparanode(left).left.location;
  128. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  129. location.reference.alignment:=1;
  130. end;
  131. in_aligned_x:
  132. begin
  133. secondpass(tcallparanode(left).left);
  134. location:=tcallparanode(left).left.location;
  135. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  136. location.reference.alignment:=0;
  137. end;
  138. {$ifdef SUPPORT_MMX}
  139. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  140. begin
  141. location_reset(location,LOC_MMXREGISTER,OS_NO);
  142. if left.location.loc=LOC_REGISTER then
  143. begin
  144. {!!!!!!!}
  145. end
  146. else if tcallparanode(left).left.location.loc=LOC_REGISTER then
  147. begin
  148. {!!!!!!!}
  149. end
  150. else
  151. begin
  152. {!!!!!!!}
  153. end;
  154. end;
  155. {$endif SUPPORT_MMX}
  156. in_rol_x,
  157. in_rol_x_y,
  158. in_ror_x,
  159. in_ror_x_y,
  160. in_sar_x,
  161. in_sar_x_y:
  162. second_rox_sar;
  163. in_bsf_x,
  164. in_bsr_x:
  165. second_BsfBsr;
  166. in_new_x:
  167. second_new;
  168. in_setlength_x:
  169. second_setlength;
  170. in_box_x:
  171. second_box;
  172. in_popcnt_x:
  173. second_popcnt;
  174. else internalerror(9);
  175. end;
  176. end;
  177. {*****************************************************************************
  178. SIZEOF / TYPEOF GENERIC HANDLING
  179. *****************************************************************************}
  180. { second_handle_ the sizeof and typeof routines }
  181. procedure tcginlinenode.second_SizeOfTypeOf;
  182. var
  183. href,
  184. hrefvmt : treference;
  185. hregister : tregister;
  186. begin
  187. if inlinenumber=in_sizeof_x then
  188. location_reset(location,LOC_REGISTER,def_cgsize(resultdef))
  189. else
  190. location_reset(location,LOC_REGISTER,OS_ADDR);
  191. { for both cases load vmt }
  192. if left.nodetype=typen then
  193. begin
  194. hregister:=cg.getaddressregister(current_asmdata.CurrAsmList);
  195. reference_reset_symbol(href,current_asmdata.RefAsmSymbol(tobjectdef(left.resultdef).vmt_mangledname),0,sizeof(pint));
  196. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,href,hregister);
  197. end
  198. else
  199. begin
  200. secondpass(left);
  201. hregister:=cg.getaddressregister(current_asmdata.CurrAsmList);
  202. { handle self inside a method of a class }
  203. case left.location.loc of
  204. LOC_CREGISTER,
  205. LOC_REGISTER :
  206. begin
  207. if (left.resultdef.typ=classrefdef) or
  208. (po_staticmethod in current_procinfo.procdef.procoptions) then
  209. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.register,hregister)
  210. else
  211. begin
  212. { load VMT pointer }
  213. reference_reset_base(hrefvmt,left.location.register,tobjectdef(left.resultdef).vmt_offset,sizeof(pint));
  214. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,hrefvmt,hregister);
  215. end
  216. end;
  217. LOC_REFERENCE,
  218. LOC_CREFERENCE :
  219. begin
  220. if is_class(left.resultdef) then
  221. begin
  222. { deref class }
  223. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.reference,hregister);
  224. hlcg.g_maybe_testself(current_asmdata.CurrAsmList,left.resultdef,hregister);
  225. { load VMT pointer }
  226. reference_reset_base(hrefvmt,hregister,tobjectdef(left.resultdef).vmt_offset,sizeof(pint));
  227. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,hrefvmt,hregister);
  228. end
  229. else
  230. begin
  231. { load VMT pointer, but not for classrefdefs }
  232. if (left.resultdef.typ=objectdef) then
  233. begin
  234. inc(left.location.reference.offset,tobjectdef(left.resultdef).vmt_offset);
  235. left.location.reference.alignment:=newalignment(left.location.reference.alignment,tobjectdef(left.resultdef).vmt_offset);
  236. end;
  237. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.reference,hregister);
  238. end;
  239. end;
  240. else
  241. internalerror(200301301);
  242. end;
  243. end;
  244. { in sizeof load size }
  245. if inlinenumber=in_sizeof_x then
  246. begin
  247. reference_reset_base(href,hregister,0,sizeof(pint));
  248. hregister:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  249. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,href,hregister);
  250. end;
  251. location.register:=hregister;
  252. end;
  253. {*****************************************************************************
  254. LENGTH GENERIC HANDLING
  255. *****************************************************************************}
  256. procedure tcginlinenode.second_Length;
  257. var
  258. lengthlab : tasmlabel;
  259. hregister : tregister;
  260. href : treference;
  261. begin
  262. secondpass(left);
  263. if is_shortstring(left.resultdef) then
  264. begin
  265. location_copy(location,left.location);
  266. location.size:=OS_8;
  267. end
  268. else
  269. begin
  270. { length in ansi/wide strings is at offset -sizeof(pint) }
  271. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  272. current_asmdata.getjumplabel(lengthlab);
  273. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_ADDR,OC_EQ,0,left.location.register,lengthlab);
  274. if is_widestring(left.resultdef) and (tf_winlikewidestring in target_info.flags) then
  275. begin
  276. reference_reset_base(href,left.location.register,-sizeof(dword),sizeof(dword));
  277. hregister:=cg.makeregsize(current_asmdata.CurrAsmList,left.location.register,OS_INT);
  278. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_32,OS_INT,href,hregister);
  279. end
  280. else
  281. begin
  282. reference_reset_base(href,left.location.register,-sizeof(pint),sizeof(pint));
  283. hregister:=cg.makeregsize(current_asmdata.CurrAsmList,left.location.register,OS_INT);
  284. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,href,hregister);
  285. end;
  286. if is_widestring(left.resultdef) then
  287. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SHR,OS_INT,1,hregister);
  288. cg.a_label(current_asmdata.CurrAsmList,lengthlab);
  289. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  290. location.register:=hregister;
  291. end;
  292. end;
  293. {*****************************************************************************
  294. PRED/SUCC GENERIC HANDLING
  295. *****************************************************************************}
  296. procedure tcginlinenode.second_PredSucc;
  297. var
  298. cgop : topcg;
  299. begin
  300. secondpass(left);
  301. if inlinenumber=in_pred_x then
  302. cgop:=OP_SUB
  303. else
  304. cgop:=OP_ADD;
  305. { we need a value in a register }
  306. location_copy(location,left.location);
  307. hlcg.location_force_reg(current_asmdata.CurrAsmList,location,resultdef,resultdef,false);
  308. {$ifndef cpu64bitalu}
  309. if def_cgsize(resultdef) in [OS_64,OS_S64] then
  310. cg64.a_op64_const_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),1,location.register64)
  311. else
  312. {$endif not cpu64bitalu}
  313. hlcg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,resultdef,1,location.register);
  314. end;
  315. {*****************************************************************************
  316. INC/DEC GENERIC HANDLING
  317. *****************************************************************************}
  318. procedure tcginlinenode.second_IncDec;
  319. const
  320. addsubop:array[in_inc_x..in_dec_x] of TOpCG=(OP_ADD,OP_SUB);
  321. var
  322. addvalue : TConstExprInt;
  323. addconstant : boolean;
  324. {$ifndef cpu64bitalu}
  325. hregisterhi,
  326. {$endif not cpu64bitalu}
  327. hregister : tregister;
  328. begin
  329. { set defaults }
  330. addconstant:=true;
  331. { first secondpass second argument, because if the first arg }
  332. { is used in that expression then SSL may move it to another }
  333. { register }
  334. if assigned(tcallparanode(left).right) then
  335. secondpass(tcallparanode(tcallparanode(left).right).left);
  336. { load first parameter, must be a reference }
  337. secondpass(tcallparanode(left).left);
  338. { get addvalue }
  339. case tcallparanode(left).left.resultdef.typ of
  340. orddef,
  341. enumdef :
  342. addvalue:=1;
  343. pointerdef :
  344. begin
  345. if is_void(tpointerdef(tcallparanode(left).left.resultdef).pointeddef) then
  346. addvalue:=1
  347. else
  348. addvalue:=tpointerdef(tcallparanode(left).left.resultdef).pointeddef.size;
  349. end;
  350. else
  351. internalerror(10081);
  352. end;
  353. { second_ argument specified?, must be a s32bit in register }
  354. if assigned(tcallparanode(left).right) then
  355. begin
  356. { when constant, just multiply the addvalue }
  357. if is_constintnode(tcallparanode(tcallparanode(left).right).left) then
  358. addvalue:=addvalue*get_ordinal_value(tcallparanode(tcallparanode(left).right).left)
  359. else if is_constpointernode(tcallparanode(tcallparanode(left).right).left) then
  360. addvalue:=addvalue*tpointerconstnode(tcallparanode(tcallparanode(left).right).left).value
  361. else
  362. begin
  363. hlcg.location_force_reg(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,tcallparanode(tcallparanode(left).right).left.resultdef,left.resultdef,addvalue<=1);
  364. hregister:=tcallparanode(tcallparanode(left).right).left.location.register;
  365. {$ifndef cpu64bitalu}
  366. hregisterhi:=tcallparanode(tcallparanode(left).right).left.location.register64.reghi;
  367. {$endif not cpu64bitalu}
  368. { insert multiply with addvalue if its >1 }
  369. if addvalue>1 then
  370. hlcg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,left.resultdef,addvalue.svalue,hregister);
  371. addconstant:=false;
  372. end;
  373. end;
  374. { write the add instruction }
  375. if addconstant then
  376. begin
  377. {$ifndef cpu64bitalu}
  378. if def_cgsize(left.resultdef) in [OS_64,OS_S64] then
  379. cg64.a_op64_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],def_cgsize(left.resultdef),addvalue,tcallparanode(left).left.location)
  380. else
  381. {$endif not cpu64bitalu}
  382. hlcg.a_op_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],left.resultdef,
  383. aint(addvalue.svalue),tcallparanode(left).left.location);
  384. end
  385. else
  386. begin
  387. {$ifndef cpu64bitalu}
  388. if def_cgsize(left.resultdef) in [OS_64,OS_S64] then
  389. cg64.a_op64_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],def_cgsize(left.resultdef),
  390. joinreg64(hregister,hregisterhi),tcallparanode(left).left.location)
  391. else
  392. {$endif not cpu64bitalu}
  393. hlcg.a_op_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],left.resultdef,
  394. hregister,tcallparanode(left).left.location);
  395. end;
  396. { no overflow checking for pointers (see ninl), and range checking }
  397. { is not applicable for them }
  398. if (tcallparanode(left).left.resultdef.typ <> pointerdef) then
  399. begin
  400. { things which can overflow must NOT pass via here, but have to be }
  401. { handled via a regular add node (conversion in tinlinenode.pass_1) }
  402. { Or someone has to rewrite the above to use a_op_const_reg_reg_ov }
  403. { and friends in case of overflow checking, and ask everyone to }
  404. { implement these methods since they don't exist for all cpus (JM) }
  405. { Similarly, range checking also has to be handled separately, }
  406. { see mantis #14841 (JM) }
  407. if ([cs_check_overflow,cs_check_range] * current_settings.localswitches <> []) then
  408. internalerror(2006111010);
  409. // cg.g_overflowcheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).resultdef);
  410. // cg.g_rangecheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).left.resultdef,
  411. // tcallparanode(left).left.resultdef);
  412. end;
  413. end;
  414. {*****************************************************************************
  415. TYPEINFO GENERIC HANDLING
  416. *****************************************************************************}
  417. procedure tcginlinenode.second_typeinfo;
  418. var
  419. href : treference;
  420. begin
  421. location_reset(location,LOC_REGISTER,OS_ADDR);
  422. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  423. reference_reset_symbol(href,RTTIWriter.get_rtti_label(left.resultdef,fullrtti),0,sizeof(pint));
  424. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,href,location.register);
  425. end;
  426. {*****************************************************************************
  427. INCLUDE/EXCLUDE GENERIC HANDLING
  428. *****************************************************************************}
  429. procedure tcginlinenode.second_IncludeExclude;
  430. var
  431. setpara, elepara: tnode;
  432. begin
  433. { the set }
  434. secondpass(tcallparanode(left).left);
  435. { the element to set }
  436. secondpass(tcallparanode(tcallparanode(left).right).left);
  437. setpara:=tcallparanode(left).left;
  438. elepara:=tcallparanode(tcallparanode(left).right).left;
  439. if elepara.location.loc=LOC_CONSTANT then
  440. begin
  441. hlcg.a_bit_set_const_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  442. setpara.resultdef,elepara.location.value-tsetdef(setpara.resultdef).setbase,setpara.location);
  443. end
  444. else
  445. begin
  446. hlcg.location_force_reg(current_asmdata.CurrAsmList,elepara.location,elepara.resultdef,u32inttype,true);
  447. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,elepara.location,tsetdef(setpara.resultdef).setbase);
  448. hlcg.a_bit_set_reg_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  449. u32inttype,setpara.resultdef,elepara.location.register,setpara.location);
  450. end;
  451. end;
  452. {*****************************************************************************
  453. FLOAT GENERIC HANDLING
  454. *****************************************************************************}
  455. {
  456. These routines all call internal RTL routines, so if they are
  457. called here, they give an internal error
  458. }
  459. procedure tcginlinenode.second_pi;
  460. begin
  461. internalerror(20020718);
  462. end;
  463. procedure tcginlinenode.second_arctan_real;
  464. begin
  465. internalerror(20020718);
  466. end;
  467. procedure tcginlinenode.second_abs_real;
  468. begin
  469. internalerror(20020718);
  470. end;
  471. procedure tcginlinenode.second_round_real;
  472. begin
  473. internalerror(20020718);
  474. end;
  475. procedure tcginlinenode.second_trunc_real;
  476. begin
  477. internalerror(20020718);
  478. end;
  479. procedure tcginlinenode.second_sqr_real;
  480. begin
  481. internalerror(20020718);
  482. end;
  483. procedure tcginlinenode.second_sqrt_real;
  484. begin
  485. internalerror(20020718);
  486. end;
  487. procedure tcginlinenode.second_ln_real;
  488. begin
  489. internalerror(20020718);
  490. end;
  491. procedure tcginlinenode.second_cos_real;
  492. begin
  493. internalerror(20020718);
  494. end;
  495. procedure tcginlinenode.second_sin_real;
  496. begin
  497. internalerror(20020718);
  498. end;
  499. procedure tcginlinenode.second_prefetch;
  500. begin
  501. end;
  502. procedure tcginlinenode.second_abs_long;
  503. var
  504. tempreg1, tempreg2: tregister;
  505. begin
  506. secondpass(left);
  507. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  508. location:=left.location;
  509. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  510. tempreg1:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  511. tempreg2:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  512. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,left.resultdef,left.resultdef.size*8-1,left.location.register,tempreg1);
  513. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_XOR,left.resultdef,left.location.register,tempreg1,tempreg2);
  514. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmlist,OP_SUB,left.resultdef,tempreg1,tempreg2,location.register);
  515. end;
  516. {*****************************************************************************
  517. ASSIGNED GENERIC HANDLING
  518. *****************************************************************************}
  519. procedure tcginlinenode.second_assigned;
  520. begin
  521. secondpass(tcallparanode(left).left);
  522. hlcg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,left.resultdef,OC_NE,0,tcallparanode(left).left.location,current_procinfo.CurrTrueLabel);
  523. hlcg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  524. location_reset(location,LOC_JUMP,OS_NO);
  525. end;
  526. procedure Tcginlinenode.second_get_frame;
  527. begin
  528. {$if defined(x86) or defined(arm)}
  529. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  530. begin
  531. location_reset(location,LOC_CONSTANT,OS_ADDR);
  532. location.value:=0;
  533. end
  534. else
  535. {$endif defined(x86) or defined(arm)}
  536. begin
  537. location_reset(location,LOC_CREGISTER,OS_ADDR);
  538. location.register:=current_procinfo.framepointer;
  539. end;
  540. end;
  541. procedure Tcginlinenode.second_get_caller_frame;
  542. var
  543. frame_reg:Tregister;
  544. use_frame_pointer:boolean;
  545. begin
  546. if left<>nil then
  547. begin
  548. secondpass(left);
  549. if left.location.loc=LOC_CONSTANT then
  550. use_frame_pointer:=true
  551. else
  552. begin
  553. hlcg.location_force_reg(current_asmdata.currasmlist,left.location,left.resultdef,voidpointertype,false);
  554. frame_reg:=left.location.register;
  555. use_frame_pointer:=false;
  556. end
  557. end
  558. else
  559. begin
  560. use_frame_pointer:=current_procinfo.framepointer=NR_STACK_POINTER_REG;
  561. frame_reg:=current_procinfo.framepointer;
  562. end;
  563. if use_frame_pointer then
  564. begin
  565. location_reset(location,LOC_CREGISTER,OS_ADDR);
  566. location.register:=NR_FRAME_POINTER_REG;
  567. end
  568. else
  569. begin
  570. location_reset_ref(location,LOC_REFERENCE,OS_ADDR,sizeof(pint));
  571. location.reference.base:=frame_reg;
  572. end;
  573. end;
  574. procedure Tcginlinenode.second_get_caller_addr;
  575. var
  576. frame_ref:Treference;
  577. begin
  578. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  579. begin
  580. location_reset(location,LOC_REGISTER,OS_ADDR);
  581. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  582. reference_reset_base(frame_ref,NR_STACK_POINTER_REG,{current_procinfo.calc_stackframe_size}tg.lasttemp,sizeof(pint));
  583. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  584. end
  585. else
  586. begin
  587. location_reset(location,LOC_REGISTER,OS_ADDR);
  588. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  589. reference_reset_base(frame_ref,current_procinfo.framepointer,sizeof(pint),sizeof(pint));
  590. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  591. end;
  592. end;
  593. procedure tcginlinenode.second_rox_sar;
  594. var
  595. op : topcg;
  596. op1,op2 : tnode;
  597. begin
  598. { one or two parameters? }
  599. if (left.nodetype=callparan) and
  600. assigned(tcallparanode(left).right) then
  601. begin
  602. op1:=tcallparanode(tcallparanode(left).right).left;
  603. op2:=tcallparanode(left).left;
  604. secondpass(op2);
  605. end
  606. else
  607. begin
  608. op1:=left;
  609. op2:=nil;
  610. end;
  611. secondpass(op1);
  612. case inlinenumber of
  613. in_ror_x,
  614. in_ror_x_y:
  615. op:=OP_ROR;
  616. in_rol_x,
  617. in_rol_x_y:
  618. op:=OP_ROL;
  619. in_sar_x,
  620. in_sar_x_y:
  621. op:=OP_SAR;
  622. end;
  623. hlcg.location_force_reg(current_asmdata.CurrAsmList,op1.location,op1.resultdef,resultdef,true);
  624. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  625. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  626. if assigned(op2) then
  627. begin
  628. { rotating by a constant directly coded: }
  629. if op2.nodetype=ordconstn then
  630. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,resultdef,
  631. tordconstnode(op2).value.uvalue and (resultdef.size*8-1),
  632. op1.location.register, location.register)
  633. else
  634. begin
  635. hlcg.location_force_reg(current_asmdata.CurrAsmList,op2.location,
  636. op2.resultdef,resultdef,true);
  637. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,op,resultdef,
  638. op2.location.register,op1.location.register,
  639. location.register);
  640. end;
  641. end
  642. else
  643. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,resultdef,1,
  644. op1.location.register,location.register);
  645. end;
  646. procedure tcginlinenode.second_BsfBsr;
  647. var
  648. reverse: boolean;
  649. opsize: tcgsize;
  650. begin
  651. reverse:=(inlinenumber = in_bsr_x);
  652. secondpass(left);
  653. opsize:=tcgsize2unsigned[left.location.size];
  654. if opsize < OS_32 then
  655. opsize:=OS_32;
  656. if (left.location.loc <> LOC_REGISTER) or
  657. (left.location.size <> opsize) then
  658. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,hlcg.tcgsize2orddef(opsize),true);
  659. location_reset(location,LOC_REGISTER,opsize);
  660. location.register := cg.getintregister(current_asmdata.CurrAsmList,opsize);
  661. cg.a_bit_scan_reg_reg(current_asmdata.CurrAsmList,reverse,opsize,left.location.register,location.register);
  662. end;
  663. procedure tcginlinenode.second_new;
  664. begin
  665. internalerror(2011012202);
  666. end;
  667. procedure tcginlinenode.second_popcnt;
  668. begin
  669. internalerror(2012082601);
  670. end;
  671. begin
  672. cinlinenode:=tcginlinenode;
  673. end. s