ncginl.pas 32 KB

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