ncginl.pas 27 KB

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