ncginl.pas 32 KB

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