ncginl.pas 28 KB

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