ncginl.pas 32 KB

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