ncginl.pas 32 KB

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