ncginl.pas 29 KB

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