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 and high in dynamic arrays 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. { Dynamic arrays do not have their length attached but their maximum index }
  292. if is_dynamic_array(left.resultdef) then
  293. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_ADD,OS_INT,1,hregister);
  294. cg.a_label(current_asmdata.CurrAsmList,lengthlab);
  295. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  296. location.register:=hregister;
  297. end;
  298. end;
  299. {*****************************************************************************
  300. PRED/SUCC GENERIC HANDLING
  301. *****************************************************************************}
  302. procedure tcginlinenode.second_PredSucc;
  303. var
  304. cgop : topcg;
  305. begin
  306. secondpass(left);
  307. if inlinenumber=in_pred_x then
  308. cgop:=OP_SUB
  309. else
  310. cgop:=OP_ADD;
  311. { we need a value in a register }
  312. location_copy(location,left.location);
  313. hlcg.location_force_reg(current_asmdata.CurrAsmList,location,resultdef,resultdef,false);
  314. {$ifndef cpu64bitalu}
  315. if def_cgsize(resultdef) in [OS_64,OS_S64] then
  316. cg64.a_op64_const_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),1,location.register64)
  317. else
  318. {$endif not cpu64bitalu}
  319. hlcg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,resultdef,1,location.register);
  320. end;
  321. {*****************************************************************************
  322. INC/DEC GENERIC HANDLING
  323. *****************************************************************************}
  324. procedure tcginlinenode.second_IncDec;
  325. const
  326. addsubop:array[in_inc_x..in_dec_x] of TOpCG=(OP_ADD,OP_SUB);
  327. var
  328. addvalue : TConstExprInt;
  329. addconstant : boolean;
  330. {$ifndef cpu64bitalu}
  331. hregisterhi,
  332. {$endif not cpu64bitalu}
  333. hregister : tregister;
  334. begin
  335. { set defaults }
  336. addconstant:=true;
  337. { first secondpass second argument, because if the first arg }
  338. { is used in that expression then SSL may move it to another }
  339. { register }
  340. if assigned(tcallparanode(left).right) then
  341. secondpass(tcallparanode(tcallparanode(left).right).left);
  342. { load first parameter, must be a reference }
  343. secondpass(tcallparanode(left).left);
  344. { get addvalue }
  345. case tcallparanode(left).left.resultdef.typ of
  346. orddef,
  347. enumdef :
  348. addvalue:=1;
  349. pointerdef :
  350. begin
  351. if is_void(tpointerdef(tcallparanode(left).left.resultdef).pointeddef) then
  352. addvalue:=1
  353. else
  354. addvalue:=tpointerdef(tcallparanode(left).left.resultdef).pointeddef.size;
  355. end;
  356. else
  357. internalerror(10081);
  358. end;
  359. { second_ argument specified?, must be a s32bit in register }
  360. if assigned(tcallparanode(left).right) then
  361. begin
  362. { when constant, just multiply the addvalue }
  363. if is_constintnode(tcallparanode(tcallparanode(left).right).left) then
  364. addvalue:=addvalue*get_ordinal_value(tcallparanode(tcallparanode(left).right).left)
  365. else if is_constpointernode(tcallparanode(tcallparanode(left).right).left) then
  366. addvalue:=addvalue*tpointerconstnode(tcallparanode(tcallparanode(left).right).left).value
  367. else
  368. begin
  369. hlcg.location_force_reg(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,tcallparanode(tcallparanode(left).right).left.resultdef,left.resultdef,addvalue<=1);
  370. hregister:=tcallparanode(tcallparanode(left).right).left.location.register;
  371. {$ifndef cpu64bitalu}
  372. hregisterhi:=tcallparanode(tcallparanode(left).right).left.location.register64.reghi;
  373. {$endif not cpu64bitalu}
  374. { insert multiply with addvalue if its >1 }
  375. if addvalue>1 then
  376. hlcg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,left.resultdef,addvalue.svalue,hregister);
  377. addconstant:=false;
  378. end;
  379. end;
  380. { write the add instruction }
  381. if addconstant then
  382. begin
  383. {$ifndef cpu64bitalu}
  384. if def_cgsize(left.resultdef) in [OS_64,OS_S64] then
  385. cg64.a_op64_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],def_cgsize(left.resultdef),addvalue,tcallparanode(left).left.location)
  386. else
  387. {$endif not cpu64bitalu}
  388. hlcg.a_op_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],left.resultdef,
  389. aint(addvalue.svalue),tcallparanode(left).left.location);
  390. end
  391. else
  392. begin
  393. {$ifndef cpu64bitalu}
  394. if def_cgsize(left.resultdef) in [OS_64,OS_S64] then
  395. cg64.a_op64_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],def_cgsize(left.resultdef),
  396. joinreg64(hregister,hregisterhi),tcallparanode(left).left.location)
  397. else
  398. {$endif not cpu64bitalu}
  399. hlcg.a_op_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],left.resultdef,
  400. hregister,tcallparanode(left).left.location);
  401. end;
  402. { no overflow checking for pointers (see ninl), and range checking }
  403. { is not applicable for them }
  404. if (tcallparanode(left).left.resultdef.typ <> pointerdef) then
  405. begin
  406. { things which can overflow must NOT pass via here, but have to be }
  407. { handled via a regular add node (conversion in tinlinenode.pass_1) }
  408. { Or someone has to rewrite the above to use a_op_const_reg_reg_ov }
  409. { and friends in case of overflow checking, and ask everyone to }
  410. { implement these methods since they don't exist for all cpus (JM) }
  411. { Similarly, range checking also has to be handled separately, }
  412. { see mantis #14841 (JM) }
  413. if ([cs_check_overflow,cs_check_range] * current_settings.localswitches <> []) then
  414. internalerror(2006111010);
  415. // cg.g_overflowcheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).resultdef);
  416. // cg.g_rangecheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).left.resultdef,
  417. // tcallparanode(left).left.resultdef);
  418. end;
  419. end;
  420. {*****************************************************************************
  421. TYPEINFO GENERIC HANDLING
  422. *****************************************************************************}
  423. procedure tcginlinenode.second_typeinfo;
  424. begin
  425. internalerror(2013060301);
  426. end;
  427. {*****************************************************************************
  428. INCLUDE/EXCLUDE GENERIC HANDLING
  429. *****************************************************************************}
  430. procedure tcginlinenode.second_IncludeExclude;
  431. var
  432. setpara, elepara: tnode;
  433. begin
  434. { the set }
  435. secondpass(tcallparanode(left).left);
  436. { the element to set }
  437. secondpass(tcallparanode(tcallparanode(left).right).left);
  438. setpara:=tcallparanode(left).left;
  439. elepara:=tcallparanode(tcallparanode(left).right).left;
  440. if elepara.location.loc=LOC_CONSTANT then
  441. begin
  442. hlcg.a_bit_set_const_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  443. setpara.resultdef,elepara.location.value-tsetdef(setpara.resultdef).setbase,setpara.location);
  444. end
  445. else
  446. begin
  447. hlcg.location_force_reg(current_asmdata.CurrAsmList,elepara.location,elepara.resultdef,u32inttype,true);
  448. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,elepara.location,tsetdef(setpara.resultdef).setbase);
  449. hlcg.a_bit_set_reg_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  450. u32inttype,setpara.resultdef,elepara.location.register,setpara.location);
  451. end;
  452. end;
  453. {*****************************************************************************
  454. FLOAT GENERIC HANDLING
  455. *****************************************************************************}
  456. {
  457. These routines all call internal RTL routines, so if they are
  458. called here, they give an internal error
  459. }
  460. procedure tcginlinenode.second_pi;
  461. begin
  462. internalerror(20020718);
  463. end;
  464. procedure tcginlinenode.second_arctan_real;
  465. begin
  466. internalerror(20020718);
  467. end;
  468. procedure tcginlinenode.second_abs_real;
  469. begin
  470. internalerror(20020718);
  471. end;
  472. procedure tcginlinenode.second_round_real;
  473. begin
  474. internalerror(20020718);
  475. end;
  476. procedure tcginlinenode.second_trunc_real;
  477. begin
  478. internalerror(20020718);
  479. end;
  480. procedure tcginlinenode.second_sqr_real;
  481. begin
  482. internalerror(20020718);
  483. end;
  484. procedure tcginlinenode.second_sqrt_real;
  485. begin
  486. internalerror(20020718);
  487. end;
  488. procedure tcginlinenode.second_ln_real;
  489. begin
  490. internalerror(20020718);
  491. end;
  492. procedure tcginlinenode.second_cos_real;
  493. begin
  494. internalerror(20020718);
  495. end;
  496. procedure tcginlinenode.second_sin_real;
  497. begin
  498. internalerror(20020718);
  499. end;
  500. procedure tcginlinenode.second_prefetch;
  501. begin
  502. end;
  503. procedure tcginlinenode.second_abs_long;
  504. var
  505. tempreg1, tempreg2: tregister;
  506. begin
  507. secondpass(left);
  508. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  509. location:=left.location;
  510. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  511. tempreg1:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  512. tempreg2:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  513. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,left.resultdef,left.resultdef.size*8-1,left.location.register,tempreg1);
  514. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_XOR,left.resultdef,left.location.register,tempreg1,tempreg2);
  515. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmlist,OP_SUB,left.resultdef,tempreg1,tempreg2,location.register);
  516. end;
  517. {*****************************************************************************
  518. ASSIGNED GENERIC HANDLING
  519. *****************************************************************************}
  520. procedure tcginlinenode.second_assigned;
  521. begin
  522. secondpass(tcallparanode(left).left);
  523. hlcg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,left.resultdef,OC_NE,0,tcallparanode(left).left.location,current_procinfo.CurrTrueLabel);
  524. hlcg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  525. location_reset(location,LOC_JUMP,OS_NO);
  526. end;
  527. procedure Tcginlinenode.second_get_frame;
  528. begin
  529. {$if defined(x86) or defined(arm)}
  530. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  531. begin
  532. location_reset(location,LOC_CONSTANT,OS_ADDR);
  533. location.value:=0;
  534. end
  535. else
  536. {$endif defined(x86) or defined(arm)}
  537. begin
  538. location_reset(location,LOC_CREGISTER,OS_ADDR);
  539. location.register:=current_procinfo.framepointer;
  540. end;
  541. end;
  542. procedure Tcginlinenode.second_get_caller_frame;
  543. var
  544. frame_reg:Tregister;
  545. use_frame_pointer:boolean;
  546. begin
  547. if left<>nil then
  548. begin
  549. secondpass(left);
  550. if left.location.loc=LOC_CONSTANT then
  551. use_frame_pointer:=true
  552. else
  553. begin
  554. hlcg.location_force_reg(current_asmdata.currasmlist,left.location,left.resultdef,voidpointertype,false);
  555. frame_reg:=left.location.register;
  556. use_frame_pointer:=false;
  557. end
  558. end
  559. else
  560. begin
  561. use_frame_pointer:=current_procinfo.framepointer=NR_STACK_POINTER_REG;
  562. frame_reg:=current_procinfo.framepointer;
  563. end;
  564. if use_frame_pointer then
  565. begin
  566. location_reset(location,LOC_CREGISTER,OS_ADDR);
  567. location.register:=NR_FRAME_POINTER_REG;
  568. end
  569. else
  570. begin
  571. location_reset_ref(location,LOC_REFERENCE,OS_ADDR,sizeof(pint));
  572. location.reference.base:=frame_reg;
  573. end;
  574. end;
  575. procedure Tcginlinenode.second_get_caller_addr;
  576. var
  577. frame_ref:Treference;
  578. begin
  579. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  580. begin
  581. location_reset(location,LOC_REGISTER,OS_ADDR);
  582. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  583. reference_reset_base(frame_ref,NR_STACK_POINTER_REG,{current_procinfo.calc_stackframe_size}tg.lasttemp,sizeof(pint));
  584. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  585. end
  586. else
  587. begin
  588. location_reset(location,LOC_REGISTER,OS_ADDR);
  589. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  590. reference_reset_base(frame_ref,current_procinfo.framepointer,sizeof(pint),sizeof(pint));
  591. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  592. end;
  593. end;
  594. procedure tcginlinenode.second_rox_sar;
  595. var
  596. op : topcg;
  597. op1,op2 : tnode;
  598. begin
  599. { one or two parameters? }
  600. if (left.nodetype=callparan) and
  601. assigned(tcallparanode(left).right) then
  602. begin
  603. op1:=tcallparanode(tcallparanode(left).right).left;
  604. op2:=tcallparanode(left).left;
  605. secondpass(op2);
  606. end
  607. else
  608. begin
  609. op1:=left;
  610. op2:=nil;
  611. end;
  612. secondpass(op1);
  613. case inlinenumber of
  614. in_ror_x,
  615. in_ror_x_y:
  616. op:=OP_ROR;
  617. in_rol_x,
  618. in_rol_x_y:
  619. op:=OP_ROL;
  620. in_sar_x,
  621. in_sar_x_y:
  622. op:=OP_SAR;
  623. end;
  624. hlcg.location_force_reg(current_asmdata.CurrAsmList,op1.location,op1.resultdef,resultdef,true);
  625. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  626. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  627. if assigned(op2) then
  628. begin
  629. { rotating by a constant directly coded: }
  630. if op2.nodetype=ordconstn then
  631. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,resultdef,
  632. tordconstnode(op2).value.uvalue and (resultdef.size*8-1),
  633. op1.location.register, location.register)
  634. else
  635. begin
  636. hlcg.location_force_reg(current_asmdata.CurrAsmList,op2.location,
  637. op2.resultdef,resultdef,true);
  638. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,op,resultdef,
  639. op2.location.register,op1.location.register,
  640. location.register);
  641. end;
  642. end
  643. else
  644. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,resultdef,1,
  645. op1.location.register,location.register);
  646. end;
  647. procedure tcginlinenode.second_BsfBsr;
  648. var
  649. reverse: boolean;
  650. opsize: tcgsize;
  651. begin
  652. reverse:=(inlinenumber = in_bsr_x);
  653. secondpass(left);
  654. opsize:=tcgsize2unsigned[left.location.size];
  655. if opsize < OS_32 then
  656. opsize:=OS_32;
  657. if (left.location.loc <> LOC_REGISTER) or
  658. (left.location.size <> opsize) then
  659. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,cgsize_orddef(opsize),true);
  660. location_reset(location,LOC_REGISTER,opsize);
  661. location.register := cg.getintregister(current_asmdata.CurrAsmList,opsize);
  662. cg.a_bit_scan_reg_reg(current_asmdata.CurrAsmList,reverse,opsize,left.location.register,location.register);
  663. end;
  664. procedure tcginlinenode.second_new;
  665. begin
  666. internalerror(2011012202);
  667. end;
  668. procedure tcginlinenode.second_popcnt;
  669. begin
  670. internalerror(2012082601);
  671. end;
  672. begin
  673. cinlinenode:=tcginlinenode;
  674. end. s