ncginl.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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. var
  422. href : treference;
  423. begin
  424. location_reset(location,LOC_REGISTER,OS_ADDR);
  425. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  426. reference_reset_symbol(href,RTTIWriter.get_rtti_label(left.resultdef,fullrtti),0,sizeof(pint));
  427. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,href,location.register);
  428. end;
  429. {*****************************************************************************
  430. INCLUDE/EXCLUDE GENERIC HANDLING
  431. *****************************************************************************}
  432. procedure tcginlinenode.second_IncludeExclude;
  433. var
  434. setpara, elepara: tnode;
  435. begin
  436. { the set }
  437. secondpass(tcallparanode(left).left);
  438. { the element to set }
  439. secondpass(tcallparanode(tcallparanode(left).right).left);
  440. setpara:=tcallparanode(left).left;
  441. elepara:=tcallparanode(tcallparanode(left).right).left;
  442. if elepara.location.loc=LOC_CONSTANT then
  443. begin
  444. hlcg.a_bit_set_const_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  445. setpara.resultdef,elepara.location.value-tsetdef(setpara.resultdef).setbase,setpara.location);
  446. end
  447. else
  448. begin
  449. hlcg.location_force_reg(current_asmdata.CurrAsmList,elepara.location,elepara.resultdef,u32inttype,true);
  450. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,elepara.location,tsetdef(setpara.resultdef).setbase);
  451. hlcg.a_bit_set_reg_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  452. u32inttype,setpara.resultdef,elepara.location.register,setpara.location);
  453. end;
  454. end;
  455. {*****************************************************************************
  456. FLOAT GENERIC HANDLING
  457. *****************************************************************************}
  458. {
  459. These routines all call internal RTL routines, so if they are
  460. called here, they give an internal error
  461. }
  462. procedure tcginlinenode.second_pi;
  463. begin
  464. internalerror(20020718);
  465. end;
  466. procedure tcginlinenode.second_arctan_real;
  467. begin
  468. internalerror(20020718);
  469. end;
  470. procedure tcginlinenode.second_abs_real;
  471. begin
  472. internalerror(20020718);
  473. end;
  474. procedure tcginlinenode.second_round_real;
  475. begin
  476. internalerror(20020718);
  477. end;
  478. procedure tcginlinenode.second_trunc_real;
  479. begin
  480. internalerror(20020718);
  481. end;
  482. procedure tcginlinenode.second_sqr_real;
  483. begin
  484. internalerror(20020718);
  485. end;
  486. procedure tcginlinenode.second_sqrt_real;
  487. begin
  488. internalerror(20020718);
  489. end;
  490. procedure tcginlinenode.second_ln_real;
  491. begin
  492. internalerror(20020718);
  493. end;
  494. procedure tcginlinenode.second_cos_real;
  495. begin
  496. internalerror(20020718);
  497. end;
  498. procedure tcginlinenode.second_sin_real;
  499. begin
  500. internalerror(20020718);
  501. end;
  502. procedure tcginlinenode.second_prefetch;
  503. begin
  504. end;
  505. procedure tcginlinenode.second_abs_long;
  506. var
  507. tempreg1, tempreg2: tregister;
  508. begin
  509. secondpass(left);
  510. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  511. location:=left.location;
  512. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  513. tempreg1:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  514. tempreg2:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  515. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,left.resultdef,left.resultdef.size*8-1,left.location.register,tempreg1);
  516. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_XOR,left.resultdef,left.location.register,tempreg1,tempreg2);
  517. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmlist,OP_SUB,left.resultdef,tempreg1,tempreg2,location.register);
  518. end;
  519. {*****************************************************************************
  520. ASSIGNED GENERIC HANDLING
  521. *****************************************************************************}
  522. procedure tcginlinenode.second_assigned;
  523. begin
  524. secondpass(tcallparanode(left).left);
  525. hlcg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,left.resultdef,OC_NE,0,tcallparanode(left).left.location,current_procinfo.CurrTrueLabel);
  526. hlcg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  527. location_reset(location,LOC_JUMP,OS_NO);
  528. end;
  529. procedure Tcginlinenode.second_get_frame;
  530. begin
  531. {$if defined(x86) or defined(arm)}
  532. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  533. begin
  534. location_reset(location,LOC_CONSTANT,OS_ADDR);
  535. location.value:=0;
  536. end
  537. else
  538. {$endif defined(x86) or defined(arm)}
  539. begin
  540. location_reset(location,LOC_CREGISTER,OS_ADDR);
  541. location.register:=current_procinfo.framepointer;
  542. end;
  543. end;
  544. procedure Tcginlinenode.second_get_caller_frame;
  545. var
  546. frame_reg:Tregister;
  547. use_frame_pointer:boolean;
  548. begin
  549. if left<>nil then
  550. begin
  551. secondpass(left);
  552. if left.location.loc=LOC_CONSTANT then
  553. use_frame_pointer:=true
  554. else
  555. begin
  556. hlcg.location_force_reg(current_asmdata.currasmlist,left.location,left.resultdef,voidpointertype,false);
  557. frame_reg:=left.location.register;
  558. use_frame_pointer:=false;
  559. end
  560. end
  561. else
  562. begin
  563. use_frame_pointer:=current_procinfo.framepointer=NR_STACK_POINTER_REG;
  564. frame_reg:=current_procinfo.framepointer;
  565. end;
  566. if use_frame_pointer then
  567. begin
  568. location_reset(location,LOC_CREGISTER,OS_ADDR);
  569. location.register:=NR_FRAME_POINTER_REG;
  570. end
  571. else
  572. begin
  573. location_reset_ref(location,LOC_REFERENCE,OS_ADDR,sizeof(pint));
  574. location.reference.base:=frame_reg;
  575. end;
  576. end;
  577. procedure Tcginlinenode.second_get_caller_addr;
  578. var
  579. frame_ref:Treference;
  580. begin
  581. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  582. begin
  583. location_reset(location,LOC_REGISTER,OS_ADDR);
  584. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  585. reference_reset_base(frame_ref,NR_STACK_POINTER_REG,{current_procinfo.calc_stackframe_size}tg.lasttemp,sizeof(pint));
  586. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  587. end
  588. else
  589. begin
  590. location_reset(location,LOC_REGISTER,OS_ADDR);
  591. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  592. reference_reset_base(frame_ref,current_procinfo.framepointer,sizeof(pint),sizeof(pint));
  593. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  594. end;
  595. end;
  596. procedure tcginlinenode.second_rox_sar;
  597. var
  598. op : topcg;
  599. op1,op2 : tnode;
  600. begin
  601. { one or two parameters? }
  602. if (left.nodetype=callparan) and
  603. assigned(tcallparanode(left).right) then
  604. begin
  605. op1:=tcallparanode(tcallparanode(left).right).left;
  606. op2:=tcallparanode(left).left;
  607. secondpass(op2);
  608. end
  609. else
  610. begin
  611. op1:=left;
  612. op2:=nil;
  613. end;
  614. secondpass(op1);
  615. case inlinenumber of
  616. in_ror_x,
  617. in_ror_x_y:
  618. op:=OP_ROR;
  619. in_rol_x,
  620. in_rol_x_y:
  621. op:=OP_ROL;
  622. in_sar_x,
  623. in_sar_x_y:
  624. op:=OP_SAR;
  625. end;
  626. hlcg.location_force_reg(current_asmdata.CurrAsmList,op1.location,op1.resultdef,resultdef,true);
  627. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  628. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  629. if assigned(op2) then
  630. begin
  631. { rotating by a constant directly coded: }
  632. if op2.nodetype=ordconstn then
  633. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,resultdef,
  634. tordconstnode(op2).value.uvalue and (resultdef.size*8-1),
  635. op1.location.register, location.register)
  636. else
  637. begin
  638. hlcg.location_force_reg(current_asmdata.CurrAsmList,op2.location,
  639. op2.resultdef,resultdef,true);
  640. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,op,resultdef,
  641. op2.location.register,op1.location.register,
  642. location.register);
  643. end;
  644. end
  645. else
  646. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,resultdef,1,
  647. op1.location.register,location.register);
  648. end;
  649. procedure tcginlinenode.second_BsfBsr;
  650. var
  651. reverse: boolean;
  652. opsize: tcgsize;
  653. begin
  654. reverse:=(inlinenumber = in_bsr_x);
  655. secondpass(left);
  656. opsize:=tcgsize2unsigned[left.location.size];
  657. if opsize < OS_32 then
  658. opsize:=OS_32;
  659. if (left.location.loc <> LOC_REGISTER) or
  660. (left.location.size <> opsize) then
  661. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,cgsize_orddef(opsize),true);
  662. location_reset(location,LOC_REGISTER,opsize);
  663. location.register := cg.getintregister(current_asmdata.CurrAsmList,opsize);
  664. cg.a_bit_scan_reg_reg(current_asmdata.CurrAsmList,reverse,opsize,left.location.register,location.register);
  665. end;
  666. procedure tcginlinenode.second_new;
  667. begin
  668. internalerror(2011012202);
  669. end;
  670. procedure tcginlinenode.second_popcnt;
  671. begin
  672. internalerror(2012082601);
  673. end;
  674. begin
  675. cinlinenode:=tcginlinenode;
  676. end. s