ncginl.pas 37 KB

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