cpupara.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. Generates the argument location information for x86-64 target
  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 bymethodpointer
  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 cpupara;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. cpubase,cgbase,
  23. symconst,symtype,symsym,symdef,
  24. aasmtai,aasmdata,
  25. parabase,paramgr;
  26. type
  27. tx86_64paramanager = class(tparamanager)
  28. private
  29. procedure create_funcretloc_info(p : tabstractprocdef; side: tcallercallee);
  30. procedure create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee;paras:tparalist;
  31. var intparareg,mmparareg,parasize:longint;varargsparas: boolean);
  32. public
  33. function param_use_paraloc(const cgpara:tcgpara):boolean;override;
  34. function push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;override;
  35. function ret_in_param(def : tdef;calloption : tproccalloption) : boolean;override;
  36. procedure getintparaloc(calloption : tproccalloption; nr : longint;var cgpara:TCGPara);override;
  37. function get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;override;
  38. function get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;override;
  39. function get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;override;
  40. function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override;
  41. function create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;override;
  42. end;
  43. implementation
  44. uses
  45. cutils,verbose,
  46. systems,
  47. defutil,
  48. cgutils;
  49. const
  50. paraintsupregs : array[0..5] of tsuperregister = (RS_RDI,RS_RSI,RS_RDX,RS_RCX,RS_R8,RS_R9);
  51. parammsupregs : array[0..7] of tsuperregister = (RS_XMM0,RS_XMM1,RS_XMM2,RS_XMM3,RS_XMM4,RS_XMM5,RS_XMM6,RS_XMM7);
  52. paraintsupregs_winx64 : array[0..3] of tsuperregister = (RS_RCX,RS_RDX,RS_R8,RS_R9);
  53. parammsupregs_winx64 : array[0..3] of tsuperregister = (RS_XMM0,RS_XMM1,RS_XMM2,RS_XMM3);
  54. function structure_in_registers(varspez:tvarspez;size:longint):boolean;
  55. begin
  56. if (target_info.system=system_x86_64_win64) then
  57. {$warning Temporary hack: vs_const parameters are always passed by reference for win64}
  58. result:=(varspez=vs_value) and (size in [1,2,4,8])
  59. else
  60. result:=(size<=16);
  61. end;
  62. procedure getvalueparaloc(varspez:tvarspez;p : tdef;var loc1,loc2:tcgloc);
  63. begin
  64. loc1:=LOC_INVALID;
  65. loc2:=LOC_INVALID;
  66. case p.typ of
  67. orddef:
  68. begin
  69. loc1:=LOC_REGISTER;
  70. {$warning TODO 128bit also needs lochigh}
  71. end;
  72. floatdef:
  73. begin
  74. case tfloatdef(p).floattype of
  75. s80real:
  76. loc1:=LOC_REFERENCE;
  77. s32real,
  78. s64real :
  79. loc1:=LOC_MMREGISTER;
  80. s64currency,
  81. s64comp :
  82. loc1:=LOC_REGISTER;
  83. s128real:
  84. begin
  85. loc1:=LOC_MMREGISTER;
  86. loc2:=LOC_MMREGISTER;
  87. {$warning TODO float 128bit needs SSEUP lochigh}
  88. end;
  89. end;
  90. end;
  91. recorddef:
  92. begin
  93. if structure_in_registers(varspez,p.size) then
  94. begin
  95. loc1:=LOC_REGISTER;
  96. if p.size>8 then
  97. loc2:=LOC_REGISTER;
  98. end
  99. else
  100. loc1:=LOC_REFERENCE;
  101. end;
  102. objectdef:
  103. begin
  104. if is_object(p) then
  105. begin
  106. if structure_in_registers(varspez,p.size) then
  107. loc1:=LOC_REGISTER
  108. else
  109. loc1:=LOC_REFERENCE;
  110. end
  111. else
  112. loc1:=LOC_REGISTER;
  113. end;
  114. arraydef:
  115. begin
  116. if not(is_special_array(p)) and
  117. (target_info.system=system_x86_64_win64) and
  118. structure_in_registers(varspez,p.size) then
  119. begin
  120. loc1:=LOC_REGISTER;
  121. if p.size>8 then
  122. loc2:=LOC_REGISTER;
  123. end
  124. else
  125. loc1:=LOC_REFERENCE;
  126. end;
  127. variantdef:
  128. { linux abi }
  129. if target_info.system<>system_x86_64_win64 then
  130. loc1:=LOC_REGISTER
  131. else
  132. loc1:=LOC_REFERENCE;
  133. stringdef:
  134. if is_shortstring(p) or is_longstring(p) then
  135. begin
  136. { handle long and shortstrings like arrays }
  137. if structure_in_registers(varspez,p.size) then
  138. begin
  139. loc1:=LOC_REGISTER;
  140. if p.size>8 then
  141. loc2:=LOC_REGISTER;
  142. end
  143. else
  144. loc1:=LOC_REFERENCE;
  145. end
  146. else
  147. loc1:=LOC_REGISTER;
  148. setdef:
  149. if is_smallset(p) then
  150. loc1:=LOC_REGISTER
  151. else
  152. loc1:=LOC_REFERENCE;
  153. procvardef:
  154. begin
  155. if (po_methodpointer in tprocvardef(p).procoptions) then
  156. begin
  157. { This is a record of 16 bytes }
  158. if structure_in_registers(varspez,p.size) then
  159. begin
  160. loc1:=LOC_REGISTER;
  161. loc2:=LOC_REGISTER;
  162. end
  163. else
  164. loc1:=LOC_REFERENCE;
  165. end
  166. else
  167. loc1:=LOC_REGISTER;
  168. end;
  169. else
  170. begin
  171. { default for pointers,enums,etc }
  172. loc1:=LOC_REGISTER;
  173. end;
  174. end;
  175. end;
  176. function tx86_64paramanager.ret_in_param(def : tdef;calloption : tproccalloption) : boolean;
  177. var
  178. l,loc1,loc2 : tcgloc;
  179. i : longint;
  180. begin
  181. case target_info.system of
  182. system_x86_64_win64:
  183. result:=(calloption=pocall_safecall) or
  184. (def.size>8) or not(def.size in [1,2,4,8])
  185. else
  186. { handle objectdefs by the default code because they have no equivalence in C }
  187. if (def.typ in [recorddef {,arraydef }]) and (def.size<=16) then
  188. begin
  189. case def.typ of
  190. recorddef:
  191. begin
  192. l:=LOC_MMREGISTER;
  193. for i:=0 to tabstractrecorddef(def).symtable.SymList.count-1 do
  194. begin
  195. getvalueparaloc(vs_value,tfieldvarsym(tabstractrecorddef(def).symtable.SymList[i]).vardef,loc1,loc2);
  196. case loc1 of
  197. LOC_REGISTER:
  198. if l<>LOC_REFERENCE then
  199. l:=LOC_REGISTER;
  200. LOC_MMREGISTER:
  201. ;
  202. else
  203. l:=LOC_REFERENCE;
  204. end;
  205. end;
  206. end;
  207. arraydef:
  208. begin
  209. getvalueparaloc(vs_value,tarraydef(def).elementdef,l,loc2);
  210. if not(l in [LOC_MMREGISTER,LOC_REGISTER]) then
  211. l:=LOC_REFERENCE;
  212. end;
  213. end;
  214. result:=l=LOC_REFERENCE;
  215. end
  216. else
  217. result:=inherited ret_in_param(def,calloption);
  218. end;
  219. end;
  220. function tx86_64paramanager.param_use_paraloc(const cgpara:tcgpara):boolean;
  221. var
  222. paraloc : pcgparalocation;
  223. begin
  224. if not assigned(cgpara.location) then
  225. internalerror(200410102);
  226. result:=true;
  227. { All locations are LOC_REFERENCE }
  228. paraloc:=cgpara.location;
  229. while assigned(paraloc) do
  230. begin
  231. if (paraloc^.loc<>LOC_REFERENCE) then
  232. begin
  233. result:=false;
  234. exit;
  235. end;
  236. paraloc:=paraloc^.next;
  237. end;
  238. end;
  239. { true if a parameter is too large to copy and only the address is pushed }
  240. function tx86_64paramanager.push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;
  241. begin
  242. result:=false;
  243. { var,out always require address }
  244. if varspez in [vs_var,vs_out] then
  245. begin
  246. result:=true;
  247. exit;
  248. end;
  249. { Only vs_const, vs_value here }
  250. case def.typ of
  251. variantdef,
  252. formaldef :
  253. result:=true;
  254. recorddef :
  255. begin
  256. { Win ABI depends on size to pass it in a register or not }
  257. if (target_info.system=system_x86_64_win64) then
  258. result:=not structure_in_registers(varspez,def.size)
  259. else
  260. { linux ABI always passes it as value parameter }
  261. result:=false;
  262. end;
  263. arraydef :
  264. begin
  265. { cdecl array of const need to be ignored and therefor be puhsed
  266. as value parameter with length 0 }
  267. if (calloption in [pocall_cdecl,pocall_cppdecl]) and
  268. (is_array_of_const(def) or
  269. is_dynamic_array(def)) then
  270. result:=false
  271. else
  272. result:=true;
  273. end;
  274. objectdef :
  275. begin
  276. if is_object(def) then
  277. result:=not structure_in_registers(varspez,def.size);
  278. end;
  279. stringdef :
  280. begin
  281. if (tstringdef(def).stringtype in [st_shortstring,st_longstring]) then
  282. result:=not structure_in_registers(varspez,def.size);
  283. end;
  284. procvardef :
  285. begin
  286. if (po_methodpointer in tprocvardef(def).procoptions) then
  287. result:=not structure_in_registers(varspez,def.size);
  288. end;
  289. setdef :
  290. result:=(tsetdef(def).settype<>smallset);
  291. end;
  292. end;
  293. function tx86_64paramanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
  294. begin
  295. if target_info.system=system_x86_64_win64 then
  296. result:=[RS_RAX,RS_RCX,RS_RDX,RS_R8,RS_R9,RS_R10,RS_R11]
  297. else
  298. result:=[RS_RAX,RS_RCX,RS_RDX,RS_RSI,RS_RDI,RS_R8,RS_R9,RS_R10,RS_R11];
  299. end;
  300. function tx86_64paramanager.get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;
  301. begin
  302. if target_info.system=system_x86_64_win64 then
  303. result:=[RS_XMM0..RS_XMM5]
  304. else
  305. result:=[RS_XMM0..RS_XMM15];
  306. end;
  307. function tx86_64paramanager.get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;
  308. begin
  309. result:=[RS_ST0..RS_ST7];
  310. end;
  311. procedure tx86_64paramanager.getintparaloc(calloption : tproccalloption; nr : longint;var cgpara:TCGPara);
  312. var
  313. paraloc : pcgparalocation;
  314. begin
  315. cgpara.reset;
  316. cgpara.size:=OS_INT;
  317. cgpara.intsize:=tcgsize2size[OS_INT];
  318. cgpara.alignment:=get_para_align(calloption);
  319. paraloc:=cgpara.add_location;
  320. with paraloc^ do
  321. begin
  322. size:=OS_INT;
  323. if target_info.system=system_x86_64_win64 then
  324. begin
  325. if nr<1 then
  326. internalerror(200304303)
  327. else if nr<=high(paraintsupregs_winx64)+1 then
  328. begin
  329. loc:=LOC_REGISTER;
  330. register:=newreg(R_INTREGISTER,paraintsupregs_winx64[nr-1],R_SUBWHOLE);
  331. end
  332. else
  333. begin
  334. loc:=LOC_REFERENCE;
  335. reference.index:=NR_STACK_POINTER_REG;
  336. reference.offset:=(nr-6)*sizeof(aint);
  337. end;
  338. end
  339. else
  340. begin
  341. if nr<1 then
  342. internalerror(200304303)
  343. else if nr<=high(paraintsupregs)+1 then
  344. begin
  345. loc:=LOC_REGISTER;
  346. register:=newreg(R_INTREGISTER,paraintsupregs[nr-1],R_SUBWHOLE);
  347. end
  348. else
  349. begin
  350. loc:=LOC_REFERENCE;
  351. reference.index:=NR_STACK_POINTER_REG;
  352. reference.offset:=(nr-6)*sizeof(aint);
  353. end;
  354. end;
  355. end;
  356. end;
  357. procedure tx86_64paramanager.create_funcretloc_info(p : tabstractprocdef; side: tcallercallee);
  358. var
  359. retcgsize : tcgsize;
  360. begin
  361. { Constructors return self instead of a boolean }
  362. if (p.proctypeoption=potype_constructor) then
  363. retcgsize:=OS_ADDR
  364. else
  365. retcgsize:=def_cgsize(p.returndef);
  366. location_reset(p.funcretloc[side],LOC_INVALID,OS_NO);
  367. { void has no location }
  368. if is_void(p.returndef) then
  369. begin
  370. location_reset(p.funcretloc[side],LOC_VOID,OS_NO);
  371. exit;
  372. end;
  373. { Return is passed as var parameter }
  374. if ret_in_param(p.returndef,p.proccalloption) then
  375. begin
  376. p.funcretloc[side].loc:=LOC_REFERENCE;
  377. p.funcretloc[side].size:=retcgsize;
  378. exit;
  379. end;
  380. { Return in FPU register? }
  381. if p.returndef.typ=floatdef then
  382. begin
  383. case tfloatdef(p.returndef).floattype of
  384. s32real,s64real:
  385. begin
  386. p.funcretloc[side].loc:=LOC_MMREGISTER;
  387. p.funcretloc[side].register:=NR_MM_RESULT_REG;
  388. p.funcretloc[side].size:=retcgsize;
  389. end;
  390. s64currency,
  391. s64comp,
  392. s80real:
  393. begin
  394. p.funcretloc[side].loc:=LOC_FPUREGISTER;
  395. p.funcretloc[side].register:=NR_FPU_RESULT_REG;
  396. p.funcretloc[side].size:=retcgsize;
  397. end;
  398. else
  399. internalerror(200405034);
  400. end;
  401. end
  402. else
  403. { Return in register }
  404. begin
  405. p.funcretloc[side].loc:=LOC_REGISTER;
  406. if p.returndef.size>8 then
  407. begin
  408. p.funcretloc[side].size:=OS_128;
  409. p.funcretloc[side].register:=newreg(R_INTREGISTER,RS_FUNCTION_RESULT_REG,R_SUBWHOLE);
  410. p.funcretloc[side].registerhi:=newreg(R_INTREGISTER,RS_RDX,R_SUBWHOLE);
  411. end
  412. else
  413. begin
  414. p.funcretloc[side].size:=retcgsize;
  415. if side=callerside then
  416. p.funcretloc[side].register:=newreg(R_INTREGISTER,RS_FUNCTION_RESULT_REG,cgsize2subreg(retcgsize))
  417. else
  418. p.funcretloc[side].register:=newreg(R_INTREGISTER,RS_FUNCTION_RETURN_REG,cgsize2subreg(retcgsize));
  419. end;
  420. end;
  421. end;
  422. procedure tx86_64paramanager.create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee;paras:tparalist;
  423. var intparareg,mmparareg,parasize:longint;varargsparas: boolean);
  424. var
  425. hp : tparavarsym;
  426. paraloc : pcgparalocation;
  427. subreg : tsubregister;
  428. pushaddr : boolean;
  429. paracgsize : tcgsize;
  430. loc : array[1..2] of tcgloc;
  431. paralen,
  432. locidx,
  433. l,i,
  434. varalign,
  435. paraalign : longint;
  436. begin
  437. paraalign:=get_para_align(p.proccalloption);
  438. { Register parameters are assigned from left to right }
  439. for i:=0 to paras.count-1 do
  440. begin
  441. hp:=tparavarsym(paras[i]);
  442. pushaddr:=push_addr_param(hp.varspez,hp.vardef,p.proccalloption);
  443. if pushaddr then
  444. begin
  445. loc[1]:=LOC_REGISTER;
  446. loc[2]:=LOC_INVALID;
  447. paracgsize:=OS_ADDR;
  448. paralen:=sizeof(aint);
  449. end
  450. else
  451. begin
  452. getvalueparaloc(hp.varspez,hp.vardef,loc[1],loc[2]);
  453. paralen:=push_size(hp.varspez,hp.vardef,p.proccalloption);
  454. paracgsize:=def_cgsize(hp.vardef);
  455. end;
  456. { cheat for now, we should copy the value to an mm reg as well (FK) }
  457. if varargsparas and
  458. (target_info.system = system_x86_64_win64) and
  459. (hp.vardef.typ = floatdef) then
  460. begin
  461. loc[1] := LOC_REGISTER;
  462. loc[2] := LOC_INVALID;
  463. if paracgsize = OS_F64 then
  464. paracgsize := OS_64
  465. else
  466. paracgsize := OS_32;
  467. end;
  468. hp.paraloc[side].reset;
  469. hp.paraloc[side].size:=paracgsize;
  470. hp.paraloc[side].intsize:=paralen;
  471. hp.paraloc[side].Alignment:=paraalign;
  472. if paralen>0 then
  473. begin
  474. locidx:=1;
  475. while (paralen>0) do
  476. begin
  477. if locidx>2 then
  478. internalerror(200501283);
  479. { Enough registers free? }
  480. case loc[locidx] of
  481. LOC_REGISTER :
  482. begin
  483. { winx64 uses different registers }
  484. if ((target_info.system=system_x86_64_win64) and
  485. (intparareg>high(paraintsupregs_winx64))) or
  486. ((target_info.system<>system_x86_64_win64) and
  487. (intparareg>high(paraintsupregs))) then
  488. loc[locidx]:=LOC_REFERENCE;
  489. end;
  490. LOC_MMREGISTER :
  491. begin
  492. { winx64 uses different registers }
  493. if ((target_info.system=system_x86_64_win64) and
  494. (mmparareg>high(parammsupregs_winx64))) or
  495. ((target_info.system<>system_x86_64_win64) and
  496. (mmparareg>high(parammsupregs))) then
  497. loc[locidx]:=LOC_REFERENCE;
  498. end;
  499. end;
  500. { Allocate }
  501. case loc[locidx] of
  502. LOC_REGISTER :
  503. begin
  504. paraloc:=hp.paraloc[side].add_location;
  505. paraloc^.loc:=LOC_REGISTER;
  506. if (paracgsize=OS_NO) or (loc[2]<>LOC_INVALID) then
  507. begin
  508. paraloc^.size:=OS_INT;
  509. subreg:=R_SUBWHOLE;
  510. end
  511. else
  512. begin
  513. paraloc^.size:=paracgsize;
  514. { s64comp is pushed in an int register }
  515. if paraloc^.size=OS_C64 then
  516. paraloc^.size:=OS_64;
  517. subreg:=cgsize2subreg(paraloc^.size);
  518. end;
  519. { winx64 uses different registers }
  520. if target_info.system=system_x86_64_win64 then
  521. paraloc^.register:=newreg(R_INTREGISTER,paraintsupregs_winx64[intparareg],subreg)
  522. else
  523. paraloc^.register:=newreg(R_INTREGISTER,paraintsupregs[intparareg],subreg);
  524. { matching mm register must be skipped }
  525. if target_info.system=system_x86_64_win64 then
  526. inc(mmparareg);
  527. inc(intparareg);
  528. dec(paralen,tcgsize2size[paraloc^.size]);
  529. end;
  530. LOC_MMREGISTER :
  531. begin
  532. paraloc:=hp.paraloc[side].add_location;
  533. paraloc^.loc:=LOC_MMREGISTER;
  534. { winx64 uses different registers }
  535. if target_info.system=system_x86_64_win64 then
  536. paraloc^.register:=newreg(R_MMREGISTER,parammsupregs_winx64[mmparareg],R_SUBNONE)
  537. else
  538. paraloc^.register:=newreg(R_MMREGISTER,parammsupregs[mmparareg],R_SUBNONE);
  539. if paracgsize=OS_F128 then
  540. paraloc^.size:=OS_F64
  541. else
  542. paraloc^.size:=paracgsize;
  543. { matching int register must be skipped }
  544. if target_info.system=system_x86_64_win64 then
  545. inc(intparareg);
  546. inc(mmparareg);
  547. dec(paralen,tcgsize2size[paraloc^.size]);
  548. end;
  549. LOC_REFERENCE :
  550. begin
  551. paraloc:=hp.paraloc[side].add_location;
  552. paraloc^.loc:=LOC_REFERENCE;
  553. {Hack alert!!! We should modify int_cgsize to handle OS_128,
  554. however, since int_cgsize is called in many places in the
  555. compiler where only a few can already handle OS_128, fixing it
  556. properly is out of the question to release 2.2.0 in time. (DM)}
  557. if paracgsize=OS_128 then
  558. if paralen=8 then
  559. paraloc^.size:=OS_64
  560. else if paralen=16 then
  561. paraloc^.size:=OS_128
  562. else
  563. internalerror(200707143)
  564. else if paracgsize in [OS_F32,OS_F64,OS_F80,OS_F128] then
  565. paraloc^.size:=int_float_cgsize(paralen)
  566. else
  567. paraloc^.size:=int_cgsize(paralen);
  568. if side=callerside then
  569. paraloc^.reference.index:=NR_STACK_POINTER_REG
  570. else
  571. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  572. varalign:=used_align(size_2_align(paralen),paraalign,paraalign);
  573. paraloc^.reference.offset:=parasize;
  574. parasize:=align(parasize+paralen,varalign);
  575. paralen:=0;
  576. end;
  577. end;
  578. if (locidx<2) and
  579. (loc[locidx+1]<>LOC_INVALID) then
  580. inc(locidx);
  581. end;
  582. end
  583. else
  584. begin
  585. paraloc:=hp.paraloc[side].add_location;
  586. paraloc^.loc:=LOC_VOID;
  587. end;
  588. end;
  589. { Register parameters are assigned from left-to-right, but the
  590. offsets on the stack are right-to-left. There is no need
  591. to reverse the offset, only adapt the calleeside with the
  592. start offset of the first param on the stack }
  593. if side=calleeside then
  594. begin
  595. for i:=0 to paras.count-1 do
  596. begin
  597. hp:=tparavarsym(paras[i]);
  598. paraloc:=hp.paraloc[side].location;
  599. while paraloc<>nil do
  600. begin
  601. with paraloc^ do
  602. if (loc=LOC_REFERENCE) then
  603. inc(reference.offset,target_info.first_parm_offset);
  604. paraloc:=paraloc^.next;
  605. end;
  606. end;
  607. end;
  608. end;
  609. function tx86_64paramanager.create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;
  610. var
  611. intparareg,mmparareg,
  612. parasize : longint;
  613. begin
  614. intparareg:=0;
  615. mmparareg:=0;
  616. if target_info.system=system_x86_64_win64 then
  617. parasize:=4*8
  618. else
  619. parasize:=0;
  620. { calculate the registers for the normal parameters }
  621. create_paraloc_info_intern(p,callerside,p.paras,intparareg,mmparareg,parasize,false);
  622. { append the varargs }
  623. create_paraloc_info_intern(p,callerside,varargspara,intparareg,mmparareg,parasize,true);
  624. { store used no. of SSE registers, that needs to be passed in %AL }
  625. varargspara.mmregsused:=mmparareg;
  626. result:=parasize;
  627. end;
  628. function tx86_64paramanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
  629. var
  630. intparareg,mmparareg,
  631. parasize : longint;
  632. begin
  633. intparareg:=0;
  634. mmparareg:=0;
  635. if target_info.system=system_x86_64_win64 then
  636. parasize:=4*8
  637. else
  638. parasize:=0;
  639. create_paraloc_info_intern(p,side,p.paras,intparareg,mmparareg,parasize,false);
  640. { Create Function result paraloc }
  641. create_funcretloc_info(p,side);
  642. { We need to return the size allocated on the stack }
  643. result:=parasize;
  644. end;
  645. begin
  646. paramanager:=tx86_64paramanager.create;
  647. end.