cpupara.pas 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  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 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 cpupara;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. cpubase,cgbase,cgutils,
  23. symconst,symtype,symsym,symdef,
  24. aasmtai,aasmdata,
  25. parabase,paramgr;
  26. type
  27. tx86_64paramanager = class(tparamanager)
  28. private
  29. procedure create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee;paras:tparalist;
  30. var intparareg,mmparareg,parasize:longint;varargsparas: boolean);
  31. public
  32. function param_use_paraloc(const cgpara:tcgpara):boolean;override;
  33. function push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;override;
  34. function ret_in_param(def:tdef;pd:tabstractprocdef):boolean;override;
  35. procedure getintparaloc(pd : tabstractprocdef; nr : longint; var cgpara : tcgpara);override;
  36. function get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;override;
  37. function get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;override;
  38. function get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;override;
  39. function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;override;
  40. function create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;override;
  41. function get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): tcgpara;override;
  42. end;
  43. implementation
  44. uses
  45. cutils,verbose,
  46. systems,
  47. defutil,
  48. symtable;
  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. {
  55. The argument classification code largely comes from libffi:
  56. ffi64.c - Copyright (c) 2002, 2007 Bo Thorsen <[email protected]>
  57. Copyright (c) 2008 Red Hat, Inc.
  58. x86-64 Foreign Function Interface
  59. Permission is hereby granted, free of charge, to any person obtaining
  60. a copy of this software and associated documentation files (the
  61. ``Software''), to deal in the Software without restriction, including
  62. without limitation the rights to use, copy, modify, merge, publish,
  63. distribute, sublicense, and/or sell copies of the Software, and to
  64. permit persons to whom the Software is furnished to do so, subject to
  65. the following conditions:
  66. The above copyright notice and this permission notice shall be included
  67. in all copies or substantial portions of the Software.
  68. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  69. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  70. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  71. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  72. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  73. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  74. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  75. DEALINGS IN THE SOFTWARE.
  76. ----------------------------------------------------------------------- *)
  77. }
  78. const
  79. MAX_PARA_CLASSES = 4;
  80. type
  81. tx64paraclass = (
  82. X86_64_NO_CLASS,
  83. X86_64_INTEGER_CLASS,X86_64_INTEGERSI_CLASS,
  84. X86_64_SSE_CLASS,X86_64_SSESF_CLASS,X86_64_SSEDF_CLASS,X86_64_SSEUP_CLASS,
  85. X86_64_X87_CLASS,X86_64_X87UP_CLASS,
  86. X86_64_COMPLEX_X87_CLASS,
  87. X86_64_MEMORY_CLASS
  88. );
  89. tx64paraclasses = array[0..MAX_PARA_CLASSES-1] of tx64paraclass;
  90. { Win64-specific helper }
  91. function aggregate_in_registers_win64(varspez:tvarspez;size:longint):boolean;
  92. begin
  93. { TODO: Temporary hack: vs_const parameters are always passed by reference for win64}
  94. result:=(varspez=vs_value) and (size in [1,2,4,8])
  95. end;
  96. (* x86-64 register passing implementation. See x86-64 ABI for details. Goal
  97. of this code is to classify each 8bytes of incoming argument by the register
  98. class and assign registers accordingly. *)
  99. (* Return the union class of CLASS1 and CLASS2.
  100. See the x86-64 PS ABI for details. *)
  101. function merge_classes(class1, class2: tx64paraclass): tx64paraclass;
  102. begin
  103. (* Rule #1: If both classes are equal, this is the resulting class. *)
  104. if (class1=class2) then
  105. exit(class1);
  106. (* Rule #2: If one of the classes is NO_CLASS, the resulting class is
  107. the other class. *)
  108. if (class1=X86_64_NO_CLASS) then
  109. exit(class2);
  110. if (class2=X86_64_NO_CLASS) then
  111. exit(class1);
  112. (* Rule #3: If one of the classes is MEMORY, the result is MEMORY. *)
  113. if (class1=X86_64_MEMORY_CLASS) or
  114. (class2=X86_64_MEMORY_CLASS) then
  115. exit(X86_64_MEMORY_CLASS);
  116. (* Rule #4: If one of the classes is INTEGER, the result is INTEGER. *)
  117. { 32 bit }
  118. if ((class1=X86_64_INTEGERSI_CLASS) and
  119. (class2=X86_64_SSESF_CLASS)) or
  120. ((class2=X86_64_INTEGERSI_CLASS) and
  121. (class1=X86_64_SSESF_CLASS)) then
  122. exit(X86_64_INTEGERSI_CLASS);
  123. { 64 bit }
  124. if (class1 in [X86_64_INTEGER_CLASS,X86_64_INTEGERSI_CLASS]) or
  125. (class2 in [X86_64_INTEGER_CLASS,X86_64_INTEGERSI_CLASS]) then
  126. exit(X86_64_INTEGER_CLASS);
  127. (* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
  128. MEMORY is used. *)
  129. if (class1 in [X86_64_X87_CLASS,X86_64_X87UP_CLASS,X86_64_COMPLEX_X87_CLASS]) or
  130. (class2 in [X86_64_X87_CLASS,X86_64_X87UP_CLASS,X86_64_COMPLEX_X87_CLASS]) then
  131. exit(X86_64_MEMORY_CLASS);
  132. (* Rule #6: Otherwise class SSE is used. *)
  133. result:=X86_64_SSE_CLASS;
  134. end;
  135. (* Classify the argument of type TYPE and mode MODE.
  136. CLASSES will be filled by the register class used to pass each word
  137. of the operand. The number of words is returned. In case the parameter
  138. should be passed in memory, 0 is returned. As a special case for zero
  139. sized containers, classes[0] will be NO_CLASS and 1 is returned.
  140. real_size contains either def.size, or a value derived from
  141. def.bitpackedsize and the field offset denoting the number of bytes
  142. spanned by a bitpacked field
  143. See the x86-64 PS ABI for details.
  144. *)
  145. function classify_as_integer_argument(real_size: aint; var classes: tx64paraclasses; byte_offset: aint): longint;
  146. var
  147. size: aint;
  148. begin
  149. size:=byte_offset+real_size;
  150. if size<=4 then
  151. classes[0]:=X86_64_INTEGERSI_CLASS
  152. else
  153. classes[0]:=X86_64_INTEGER_CLASS;
  154. if size<=8 then
  155. result:=1
  156. else
  157. begin
  158. if size<=12 then
  159. classes[1]:=X86_64_INTEGERSI_CLASS
  160. else if (size<=16) then
  161. classes[1]:=X86_64_INTEGER_CLASS
  162. else
  163. internalerror(2010021401);
  164. result:=2;
  165. end
  166. end;
  167. function classify_argument(def: tdef; varspez: tvarspez; real_size: aint; var classes: tx64paraclasses; byte_offset: aint): longint; forward;
  168. function init_aggregate_classification(def: tdef; varspez: tvarspez; byte_offset: aint; out words: longint; out classes: tx64paraclasses): longint;
  169. var
  170. i: longint;
  171. begin
  172. words:=0;
  173. { win64 follows a different convention here }
  174. if (target_info.system=system_x86_64_win64) then
  175. begin
  176. if aggregate_in_registers_win64(varspez,def.size) then
  177. begin
  178. classes[0]:=X86_64_INTEGER_CLASS;
  179. result:=1;
  180. end
  181. else
  182. result:=0;
  183. exit;
  184. end;
  185. (* If the struct is larger than 32 bytes, pass it on the stack. *)
  186. if def.size > 32 then
  187. exit(0);
  188. { if a struct starts an offset not divisible by 8, it can span extra
  189. words }
  190. words:=(def.size+byte_offset mod 8+7) div 8;
  191. (* Zero sized arrays or structures are NO_CLASS. We return 0 to
  192. signal memory class, so handle it as special case. *)
  193. if (words=0) then
  194. begin
  195. classes[0]:=X86_64_NO_CLASS;
  196. exit(1);
  197. end;
  198. { we'll be merging the classes elements with the subclasses
  199. elements, so initialise them first }
  200. for i:=low(classes) to high(classes) do
  201. classes[i]:=X86_64_NO_CLASS;
  202. result:=words;
  203. end;
  204. function classify_aggregate_element(def: tdef; varspez: tvarspez; real_size: aint; var classes: tx64paraclasses; new_byte_offset: aint): longint;
  205. var
  206. subclasses: tx64paraclasses;
  207. i,
  208. pos: longint;
  209. begin
  210. result:=classify_argument(def,varspez,real_size,subclasses,new_byte_offset mod 8);
  211. if (result=0) then
  212. exit;
  213. pos:=new_byte_offset div 8;
  214. if result-1+pos>high(classes) then
  215. internalerror(2010053108);
  216. for i:=0 to result-1 do
  217. begin
  218. classes[i+pos] :=
  219. merge_classes(subclasses[i],classes[i+pos]);
  220. end;
  221. inc(result,pos);
  222. end;
  223. function finalize_aggregate_classification(def: tdef; words: longint; var classes: tx64paraclasses): longint;
  224. var
  225. i: longint;
  226. begin
  227. if (words>2) then
  228. begin
  229. (* When size > 16 bytes, if the first one isn't
  230. X86_64_SSE_CLASS or any other ones aren't
  231. X86_64_SSEUP_CLASS, everything should be passed in
  232. memory. *)
  233. if (classes[0]<>X86_64_SSE_CLASS) then
  234. exit(0);
  235. for i:=1 to words-1 do
  236. if (classes[i]<>X86_64_SSEUP_CLASS) then
  237. exit(0);
  238. end;
  239. (* Final merger cleanup. *)
  240. (* The first one must never be X86_64_SSEUP_CLASS or
  241. X86_64_X87UP_CLASS. *)
  242. if (classes[0]=X86_64_SSEUP_CLASS) or
  243. (classes[0]=X86_64_X87UP_CLASS) then
  244. internalerror(2010021402);
  245. for i:=0 to words-1 do
  246. begin
  247. (* If one class is MEMORY, everything should be passed in
  248. memory. *)
  249. if (classes[i]=X86_64_MEMORY_CLASS) then
  250. exit(0);
  251. (* The X86_64_SSEUP_CLASS should be always preceded by
  252. X86_64_SSE_CLASS or X86_64_SSEUP_CLASS. *)
  253. if (classes[i]=X86_64_SSEUP_CLASS) and
  254. (classes[i-1]<>X86_64_SSE_CLASS) and
  255. (classes[i-1]<>X86_64_SSEUP_CLASS) then
  256. classes[i]:=X86_64_SSE_CLASS;
  257. (* If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
  258. everything should be passed in memory. *)
  259. if (classes[i]=X86_64_X87UP_CLASS) and
  260. (classes[i-1]<>X86_64_X87_CLASS) then
  261. exit(0);
  262. end;
  263. { FIXME: in case a record contains empty padding space, e.g. a
  264. "single" field followed by a "double", then we have a problem
  265. because the cgpara helpers cannot figure out that they should
  266. skip 4 bytes after storing the single (LOC_MMREGISTER with size
  267. OS_F32) to memory before storing the double -> for now scale
  268. such locations always up to 64 bits, although this loads/stores
  269. some superfluous data }
  270. { 1) the first part is 32 bit while there is still a second part }
  271. if (classes[1]<>X86_64_NO_CLASS) then
  272. case classes[0] of
  273. X86_64_INTEGERSI_CLASS:
  274. classes[0]:=X86_64_INTEGER_CLASS;
  275. X86_64_SSESF_CLASS:
  276. classes[0]:=X86_64_SSE_CLASS;
  277. end;
  278. { 2) the second part is 32 bit, but the total size is > 12 bytes }
  279. if (def.size>12) then
  280. case classes[1] of
  281. X86_64_INTEGERSI_CLASS:
  282. classes[1]:=X86_64_INTEGER_CLASS;
  283. X86_64_SSESF_CLASS:
  284. classes[1]:=X86_64_SSE_CLASS;
  285. end;
  286. result:=words;
  287. end;
  288. function classify_record(def: tdef; varspez: tvarspez; var classes: tx64paraclasses; byte_offset: aint): longint;
  289. var
  290. vs: tfieldvarsym;
  291. size,
  292. new_byte_offset: aint;
  293. i,
  294. words,
  295. num: longint;
  296. checkalignment: boolean;
  297. begin
  298. result:=init_aggregate_classification(def,varspez,byte_offset,words,classes);
  299. if (words=0) then
  300. exit;
  301. (* Merge the fields of the structure. *)
  302. for i:=0 to tabstractrecorddef(def).symtable.symlist.count-1 do
  303. begin
  304. if tsym(tabstractrecorddef(def).symtable.symlist[i]).typ<>fieldvarsym then
  305. continue;
  306. vs:=tfieldvarsym(tabstractrecorddef(def).symtable.symlist[i]);
  307. num:=-1;
  308. checkalignment:=true;
  309. if not tabstractrecordsymtable(tabstractrecorddef(def).symtable).is_packed then
  310. begin
  311. new_byte_offset:=byte_offset+vs.fieldoffset;
  312. size:=vs.vardef.size;
  313. end
  314. else
  315. begin
  316. new_byte_offset:=byte_offset+vs.fieldoffset div 8;
  317. if (vs.vardef.typ in [orddef,enumdef]) then
  318. begin
  319. { calculate the number of bytes spanned by
  320. this bitpacked field }
  321. size:=((vs.fieldoffset+vs.vardef.packedbitsize+7) div 8)-(vs.fieldoffset div 8);
  322. { our bitpacked fields are interpreted as always being
  323. aligned, because unlike in C we don't have char:1, int:1
  324. etc (so everything is basically a char:x) }
  325. checkalignment:=false;
  326. end
  327. else
  328. size:=vs.vardef.size;
  329. end;
  330. { If [..] an object [..] contains unaligned fields, it has class
  331. MEMORY }
  332. if checkalignment and
  333. (align(new_byte_offset,vs.vardef.structalignment)<>new_byte_offset) then
  334. begin
  335. result:=0;
  336. exit;
  337. end;
  338. num:=classify_aggregate_element(vs.vardef,varspez,size,classes,new_byte_offset);
  339. if (num=0) then
  340. exit(0);
  341. end;
  342. result:=finalize_aggregate_classification(def,words,classes);
  343. end;
  344. function classify_normal_array(def: tarraydef; varspez: tvarspez; var classes: tx64paraclasses; byte_offset: aint): longint;
  345. var
  346. i, elecount: aword;
  347. size,
  348. elesize,
  349. new_byte_offset,
  350. bitoffset: aint;
  351. words,
  352. num: longint;
  353. isbitpacked: boolean;
  354. begin
  355. result:=init_aggregate_classification(def,varspez,byte_offset,words,classes);
  356. if (words=0) then
  357. exit;
  358. isbitpacked:=is_packed_array(def);
  359. if not isbitpacked then
  360. begin
  361. elesize:=def.elesize;
  362. size:=elesize;
  363. end
  364. else
  365. begin
  366. elesize:=def.elepackedbitsize;
  367. bitoffset:=0;
  368. end;
  369. (* Merge the elements of the array. *)
  370. i:=0;
  371. elecount:=def.elecount;
  372. repeat
  373. if not isbitpacked then
  374. begin
  375. { size does not change }
  376. new_byte_offset:=byte_offset+i*elesize;
  377. { If [..] an object [..] contains unaligned fields, it has class
  378. MEMORY }
  379. if align(new_byte_offset,def.alignment)<>new_byte_offset then
  380. begin
  381. result:=0;
  382. exit;
  383. end;
  384. end
  385. else
  386. begin
  387. { calculate the number of bytes spanned by this bitpacked
  388. element }
  389. size:=((bitoffset+elesize+7) div 8)-(bitoffset div 8);
  390. new_byte_offset:=byte_offset+(elesize*i) div 8;
  391. { bit offset of next element }
  392. inc(bitoffset,elesize);
  393. end;
  394. num:=classify_aggregate_element(def.elementdef,varspez,size,classes,new_byte_offset);
  395. if (num=0) then
  396. exit(0);
  397. inc(i);
  398. until (i=elecount);
  399. result:=finalize_aggregate_classification(def,words,classes);
  400. end;
  401. function classify_argument(def: tdef; varspez: tvarspez; real_size: aint; var classes: tx64paraclasses; byte_offset: aint): longint;
  402. begin
  403. case def.typ of
  404. orddef,
  405. enumdef,
  406. pointerdef,
  407. classrefdef:
  408. result:=classify_as_integer_argument(real_size,classes,byte_offset);
  409. formaldef:
  410. result:=classify_as_integer_argument(voidpointertype.size,classes,byte_offset);
  411. floatdef:
  412. begin
  413. case tfloatdef(def).floattype of
  414. s32real:
  415. begin
  416. if byte_offset=0 then
  417. classes[0]:=X86_64_SSESF_CLASS
  418. else
  419. { if we have e.g. a record with two successive "single"
  420. fields, we need a 64 bit rather than a 32 bit load }
  421. classes[0]:=X86_64_SSE_CLASS;
  422. result:=1;
  423. end;
  424. s64real:
  425. begin
  426. classes[0]:=X86_64_SSEDF_CLASS;
  427. result:=1;
  428. end;
  429. s80real,
  430. sc80real:
  431. begin
  432. classes[0]:=X86_64_X87_CLASS;
  433. classes[1]:=X86_64_X87UP_CLASS;
  434. result:=2;
  435. end;
  436. s64comp,
  437. s64currency:
  438. begin
  439. classes[0]:=X86_64_INTEGER_CLASS;
  440. result:=1;
  441. end;
  442. s128real:
  443. begin
  444. classes[0]:=X86_64_SSE_CLASS;
  445. classes[1]:=X86_64_SSEUP_CLASS;
  446. result:=2;
  447. end;
  448. else
  449. internalerror(2010060301);
  450. end;
  451. end;
  452. recorddef:
  453. result:=classify_record(def,varspez,classes,byte_offset);
  454. objectdef:
  455. begin
  456. if is_object(def) then
  457. { pass by reference, like ppc and i386 }
  458. result:=0
  459. else
  460. { all kinds of pointer types: class, objcclass, interface, ... }
  461. result:=classify_as_integer_argument(voidpointertype.size,classes,byte_offset);
  462. end;
  463. setdef:
  464. begin
  465. if is_smallset(def) then
  466. result:=classify_as_integer_argument(def.size,classes,byte_offset)
  467. else
  468. result:=0;
  469. end;
  470. stringdef:
  471. begin
  472. if (tstringdef(def).stringtype in [st_shortstring,st_longstring]) then
  473. result:=0
  474. else
  475. result:=classify_as_integer_argument(def.size,classes,byte_offset);
  476. end;
  477. arraydef:
  478. begin
  479. { a dynamic array is treated like a pointer }
  480. if is_dynamic_array(def) then
  481. result:=classify_as_integer_argument(voidpointertype.size,classes,byte_offset)
  482. { other special arrays are passed on the stack }
  483. else if is_open_array(def) or
  484. is_array_of_const(def) then
  485. result:=0
  486. else
  487. { normal array }
  488. result:=classify_normal_array(tarraydef(def),varspez,classes,byte_offset);
  489. end;
  490. { the file record is definitely too big }
  491. filedef:
  492. result:=0;
  493. procvardef:
  494. begin
  495. if (po_methodpointer in tprocvardef(def).procoptions) then
  496. begin
  497. { treat as TMethod record }
  498. def:=search_system_type('TMETHOD').typedef;
  499. result:=classify_argument(def,varspez,def.size,classes,byte_offset);
  500. end
  501. else
  502. { pointer }
  503. result:=classify_as_integer_argument(def.size,classes,byte_offset);
  504. end;
  505. variantdef:
  506. begin
  507. { same as tvardata record }
  508. def:=search_system_type('TVARDATA').typedef;
  509. result:=classify_argument(def,varspez,def.size,classes,byte_offset);
  510. end;
  511. else
  512. internalerror(2010021405);
  513. end;
  514. end;
  515. procedure getvalueparaloc(varspez:tvarspez;def:tdef;var loc1,loc2:tx64paraclass);
  516. var
  517. size: aint;
  518. i: longint;
  519. classes: tx64paraclasses;
  520. numclasses: longint;
  521. begin
  522. { init the classes array, because even if classify_argument inits only
  523. one element we copy both to loc1/loc2 in case "1" is returned }
  524. for i:=low(classes) to high(classes) do
  525. classes[i]:=X86_64_NO_CLASS;
  526. { def.size internalerrors for open arrays and dynamic arrays, since
  527. their size cannot be determined at compile-time.
  528. classify_argument does not look at the realsize argument for arrays
  529. cases, but we obviously do have to pass something... }
  530. if is_special_array(def) then
  531. size:=-1
  532. else
  533. size:=def.size;
  534. numclasses:=classify_argument(def,varspez,size,classes,0);
  535. case numclasses of
  536. 0:
  537. begin
  538. loc1:=X86_64_MEMORY_CLASS;
  539. loc2:=X86_64_NO_CLASS;
  540. end;
  541. 1,2:
  542. begin
  543. { If the class is X87, X87UP or COMPLEX_X87, it is passed in memory }
  544. if classes[0] in [X86_64_X87_CLASS,X86_64_X87UP_CLASS,X86_64_COMPLEX_X87_CLASS] then
  545. classes[0]:=X86_64_MEMORY_CLASS;
  546. if classes[1] in [X86_64_X87_CLASS,X86_64_X87UP_CLASS,X86_64_COMPLEX_X87_CLASS] then
  547. classes[1]:=X86_64_MEMORY_CLASS;
  548. loc1:=classes[0];
  549. loc2:=classes[1];
  550. end
  551. else
  552. { 4 can only happen for _m256 vectors, not yet supported }
  553. internalerror(2010021501);
  554. end;
  555. end;
  556. function tx86_64paramanager.ret_in_param(def:tdef;pd:tabstractprocdef):boolean;
  557. var
  558. classes: tx64paraclasses;
  559. numclasses: longint;
  560. begin
  561. if handle_common_ret_in_param(def,pd,result) then
  562. exit;
  563. case def.typ of
  564. { for records it depends on their contents and size }
  565. recorddef,
  566. { make sure we handle 'procedure of object' correctly }
  567. procvardef:
  568. begin
  569. numclasses:=classify_argument(def,vs_value,def.size,classes,0);
  570. result:=(numclasses=0);
  571. end;
  572. else
  573. result:=inherited ret_in_param(def,pd);
  574. end;
  575. end;
  576. function tx86_64paramanager.param_use_paraloc(const cgpara:tcgpara):boolean;
  577. var
  578. paraloc : pcgparalocation;
  579. begin
  580. if not assigned(cgpara.location) then
  581. internalerror(200410102);
  582. result:=true;
  583. { All locations are LOC_REFERENCE }
  584. paraloc:=cgpara.location;
  585. while assigned(paraloc) do
  586. begin
  587. if (paraloc^.loc<>LOC_REFERENCE) then
  588. begin
  589. result:=false;
  590. exit;
  591. end;
  592. paraloc:=paraloc^.next;
  593. end;
  594. end;
  595. { true if a parameter is too large to copy and only the address is pushed }
  596. function tx86_64paramanager.push_addr_param(varspez:tvarspez;def : tdef;calloption : tproccalloption) : boolean;
  597. var
  598. classes: tx64paraclasses;
  599. numclasses: longint;
  600. begin
  601. result:=false;
  602. { var,out,constref always require address }
  603. if varspez in [vs_var,vs_out,vs_constref] then
  604. begin
  605. result:=true;
  606. exit;
  607. end;
  608. { Only vs_const, vs_value here }
  609. case def.typ of
  610. formaldef :
  611. result:=true;
  612. recorddef :
  613. begin
  614. { MetroWerks Pascal: const records always passed by reference
  615. (for Mac OS X interfaces) }
  616. if (calloption=pocall_mwpascal) and
  617. (varspez=vs_const) then
  618. result:=true
  619. { Win ABI depends on size to pass it in a register or not }
  620. else if (target_info.system=system_x86_64_win64) then
  621. result:=not aggregate_in_registers_win64(varspez,def.size)
  622. { pass constant parameters that would be passed via memory by
  623. reference for non-cdecl/cppdecl, and make sure that the tmethod
  624. record (size=16) is passed the same way as a complex procvar }
  625. else if ((varspez=vs_const) and
  626. not(calloption in cdecl_pocalls)) or
  627. (def.size=16) then
  628. begin
  629. numclasses:=classify_argument(def,vs_value,def.size,classes,0);
  630. result:=numclasses=0;
  631. end
  632. else
  633. { SysV ABI always passes it as value parameter }
  634. result:=false;
  635. end;
  636. arraydef :
  637. begin
  638. { cdecl array of const need to be ignored and therefor be puhsed
  639. as value parameter with length 0 }
  640. if ((calloption in cdecl_pocalls) and
  641. is_array_of_const(def)) or
  642. is_dynamic_array(def) then
  643. result:=false
  644. else
  645. { pass all arrays by reference to be compatible with C (passing
  646. an array by value (= copying it on the stack) does not exist,
  647. because an array is the same as a pointer there }
  648. result:=true
  649. end;
  650. objectdef :
  651. begin
  652. { don't treat objects like records, because we only know wheter
  653. or not they'll have a VMT after the entire object is parsed
  654. -> if they are used as function result from one of their own
  655. methods, their size can still change after we've determined
  656. whether this function result should be returned by reference or
  657. by value }
  658. if is_object(def) then
  659. result:=true;
  660. end;
  661. variantdef,
  662. stringdef,
  663. procvardef,
  664. setdef :
  665. begin
  666. numclasses:=classify_argument(def,vs_value,def.size,classes,0);
  667. result:=numclasses=0;
  668. end;
  669. end;
  670. end;
  671. function tx86_64paramanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
  672. begin
  673. if target_info.system=system_x86_64_win64 then
  674. result:=[RS_RAX,RS_RCX,RS_RDX,RS_R8,RS_R9,RS_R10,RS_R11]
  675. else
  676. result:=[RS_RAX,RS_RCX,RS_RDX,RS_RSI,RS_RDI,RS_R8,RS_R9,RS_R10,RS_R11];
  677. end;
  678. function tx86_64paramanager.get_volatile_registers_mm(calloption : tproccalloption):tcpuregisterset;
  679. begin
  680. if target_info.system=system_x86_64_win64 then
  681. result:=[RS_XMM0..RS_XMM5]
  682. else
  683. result:=[RS_XMM0..RS_XMM15];
  684. end;
  685. function tx86_64paramanager.get_volatile_registers_fpu(calloption : tproccalloption):tcpuregisterset;
  686. begin
  687. result:=[RS_ST0..RS_ST7];
  688. end;
  689. procedure tx86_64paramanager.getintparaloc(pd : tabstractprocdef; nr : longint; var cgpara : tcgpara);
  690. var
  691. paraloc : pcgparalocation;
  692. def : tdef;
  693. begin
  694. def:=tparavarsym(pd.paras[nr-1]).vardef;
  695. cgpara.reset;
  696. cgpara.size:=def_cgsize(def);
  697. cgpara.intsize:=tcgsize2size[cgpara.size];
  698. cgpara.alignment:=get_para_align(pd.proccalloption);
  699. cgpara.def:=def;
  700. paraloc:=cgpara.add_location;
  701. with paraloc^ do
  702. begin
  703. size:=OS_INT;
  704. if target_info.system=system_x86_64_win64 then
  705. begin
  706. if nr<1 then
  707. internalerror(200304303)
  708. else if nr<=high(paraintsupregs_winx64)+1 then
  709. begin
  710. loc:=LOC_REGISTER;
  711. register:=newreg(R_INTREGISTER,paraintsupregs_winx64[nr-1],R_SUBWHOLE);
  712. end
  713. else
  714. begin
  715. loc:=LOC_REFERENCE;
  716. reference.index:=NR_STACK_POINTER_REG;
  717. reference.offset:=(nr-6)*sizeof(aint);
  718. end;
  719. end
  720. else
  721. begin
  722. if nr<1 then
  723. internalerror(200304303)
  724. else if nr<=high(paraintsupregs)+1 then
  725. begin
  726. loc:=LOC_REGISTER;
  727. register:=newreg(R_INTREGISTER,paraintsupregs[nr-1],R_SUBWHOLE);
  728. end
  729. else
  730. begin
  731. loc:=LOC_REFERENCE;
  732. reference.index:=NR_STACK_POINTER_REG;
  733. reference.offset:=(nr-6)*sizeof(aint);
  734. end;
  735. end;
  736. end;
  737. end;
  738. function tx86_64paramanager.get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): tcgpara;
  739. const
  740. intretregs: array[0..1] of tregister = (NR_FUNCTION_RETURN_REG,NR_FUNCTION_RETURN_REG_HIGH);
  741. mmretregs: array[0..1] of tregister = (NR_MM_RESULT_REG,NR_MM_RESULT_REG_HIGH);
  742. var
  743. classes: tx64paraclasses;
  744. i,
  745. numclasses: longint;
  746. intretregidx,
  747. mmretregidx: longint;
  748. retcgsize : tcgsize;
  749. paraloc : pcgparalocation;
  750. begin
  751. if set_common_funcretloc_info(p,forcetempdef,retcgsize,result) then
  752. exit;
  753. { integer sizes < 32 bit have to be sign/zero extended to 32 bit on
  754. the callee side (caller can expect those bits are valid) }
  755. if (side=calleeside) and
  756. (retcgsize in [OS_8,OS_S8,OS_16,OS_S16]) then
  757. begin
  758. retcgsize:=OS_S32;
  759. result.def:=s32inttype;
  760. result.intsize:=4;
  761. result.size:=retcgsize;
  762. end;
  763. { Return in FPU register? -> don't use classify_argument(), because
  764. currency and comp need special treatment here (they are integer class
  765. when passing as parameter, but LOC_FPUREGISTER as function result) }
  766. if result.def.typ=floatdef then
  767. begin
  768. paraloc:=result.add_location;
  769. case tfloatdef(result.def).floattype of
  770. s32real:
  771. begin
  772. paraloc^.loc:=LOC_MMREGISTER;
  773. paraloc^.register:=newreg(R_MMREGISTER,RS_MM_RESULT_REG,R_SUBMMS);
  774. paraloc^.size:=OS_F32;
  775. end;
  776. s64real:
  777. begin
  778. paraloc^.loc:=LOC_MMREGISTER;
  779. paraloc^.register:=newreg(R_MMREGISTER,RS_MM_RESULT_REG,R_SUBMMD);
  780. paraloc^.size:=OS_F64;
  781. end;
  782. { the first two only exist on targets with an x87, on others
  783. they are replace by int64 }
  784. s64currency,
  785. s64comp,
  786. s80real,
  787. sc80real:
  788. begin
  789. paraloc^.loc:=LOC_FPUREGISTER;
  790. paraloc^.register:=NR_FPU_RESULT_REG;
  791. paraloc^.size:=retcgsize;
  792. end;
  793. else
  794. internalerror(200405034);
  795. end;
  796. end
  797. else
  798. { Return in register }
  799. begin
  800. numclasses:=classify_argument(result.def,vs_value,result.def.size,classes,0);
  801. { this would mean a memory return }
  802. if (numclasses=0) then
  803. internalerror(2010021502);
  804. { this would mean an _m256 vector (valid, but not yet supported) }
  805. if (numclasses>2) then
  806. internalerror(2010021503);
  807. intretregidx:=0;
  808. mmretregidx:=0;
  809. for i:=0 to numclasses-1 do
  810. begin
  811. paraloc:=result.add_location;
  812. case classes[i] of
  813. X86_64_INTEGERSI_CLASS,
  814. X86_64_INTEGER_CLASS:
  815. begin
  816. paraloc^.loc:=LOC_REGISTER;
  817. paraloc^.register:=intretregs[intretregidx];
  818. if classes[i]=X86_64_INTEGER_CLASS then
  819. paraloc^.size:=OS_64
  820. else if result.intsize in [1,2,4] then
  821. paraloc^.size:=retcgsize
  822. else
  823. paraloc^.size:=OS_32;
  824. setsubreg(paraloc^.register,cgsize2subreg(R_INTREGISTER,paraloc^.size));
  825. inc(intretregidx);
  826. end;
  827. X86_64_SSE_CLASS,
  828. X86_64_SSEUP_CLASS,
  829. X86_64_SSESF_CLASS,
  830. X86_64_SSEDF_CLASS:
  831. begin
  832. paraloc^.loc:=LOC_MMREGISTER;
  833. paraloc^.register:=mmretregs[mmretregidx];
  834. case classes[i] of
  835. X86_64_SSESF_CLASS:
  836. begin
  837. setsubreg(paraloc^.register,R_SUBMMS);
  838. paraloc^.size:=OS_F32;
  839. end;
  840. X86_64_SSEDF_CLASS:
  841. begin
  842. setsubreg(paraloc^.register,R_SUBMMD);
  843. paraloc^.size:=OS_F64;
  844. end;
  845. else
  846. begin
  847. setsubreg(paraloc^.register,R_SUBQ);
  848. paraloc^.size:=OS_M64;
  849. end;
  850. end;
  851. inc(mmretregidx);
  852. end;
  853. X86_64_NO_CLASS:
  854. begin
  855. { empty record/array }
  856. if (i<>0) or
  857. (numclasses<>1) then
  858. internalerror(2010060302);
  859. paraloc^.loc:=LOC_VOID;
  860. end;
  861. else
  862. internalerror(2010021504);
  863. end;
  864. end;
  865. end;
  866. end;
  867. procedure tx86_64paramanager.create_paraloc_info_intern(p : tabstractprocdef; side: tcallercallee;paras:tparalist;
  868. var intparareg,mmparareg,parasize:longint;varargsparas: boolean);
  869. var
  870. hp : tparavarsym;
  871. paradef : tdef;
  872. paraloc : pcgparalocation;
  873. subreg : tsubregister;
  874. pushaddr : boolean;
  875. paracgsize : tcgsize;
  876. loc : array[1..2] of tx64paraclass;
  877. needintloc,
  878. needmmloc,
  879. paralen,
  880. locidx,
  881. i,
  882. varalign,
  883. paraalign : longint;
  884. begin
  885. paraalign:=get_para_align(p.proccalloption);
  886. { Register parameters are assigned from left to right }
  887. for i:=0 to paras.count-1 do
  888. begin
  889. hp:=tparavarsym(paras[i]);
  890. paradef:=hp.vardef;
  891. pushaddr:=push_addr_param(hp.varspez,paradef,p.proccalloption);
  892. if pushaddr then
  893. begin
  894. loc[1]:=X86_64_INTEGER_CLASS;
  895. loc[2]:=X86_64_NO_CLASS;
  896. paracgsize:=OS_ADDR;
  897. paralen:=sizeof(pint);
  898. paradef:=getpointerdef(paradef);
  899. end
  900. else
  901. begin
  902. getvalueparaloc(hp.varspez,paradef,loc[1],loc[2]);
  903. paralen:=push_size(hp.varspez,paradef,p.proccalloption);
  904. paracgsize:=def_cgsize(paradef);
  905. { integer sizes < 32 bit have to be sign/zero extended to 32 bit
  906. on the caller side }
  907. if (side=callerside) and
  908. (paracgsize in [OS_8,OS_S8,OS_16,OS_S16]) then
  909. begin
  910. paracgsize:=OS_S32;
  911. paralen:=4;
  912. paradef:=s32inttype;
  913. end;
  914. end;
  915. { cheat for now, we should copy the value to an mm reg as well (FK) }
  916. if varargsparas and
  917. (target_info.system = system_x86_64_win64) and
  918. (paradef.typ = floatdef) then
  919. begin
  920. loc[2]:=X86_64_NO_CLASS;
  921. if paracgsize=OS_F64 then
  922. begin
  923. loc[1]:=X86_64_INTEGER_CLASS;
  924. paracgsize:=OS_64;
  925. paradef:=u64inttype;
  926. end
  927. else
  928. begin
  929. loc[1]:=X86_64_INTEGERSI_CLASS;
  930. paracgsize:=OS_32;
  931. paradef:=u32inttype;
  932. end;
  933. end;
  934. hp.paraloc[side].reset;
  935. hp.paraloc[side].size:=paracgsize;
  936. hp.paraloc[side].intsize:=paralen;
  937. hp.paraloc[side].Alignment:=paraalign;
  938. hp.paraloc[side].def:=paradef;
  939. if paralen>0 then
  940. begin
  941. { Enough registers free? }
  942. needintloc:=0;
  943. needmmloc:=0;
  944. for locidx:=low(loc) to high(loc) do
  945. case loc[locidx] of
  946. X86_64_INTEGER_CLASS,
  947. X86_64_INTEGERSI_CLASS:
  948. inc(needintloc);
  949. X86_64_SSE_CLASS,
  950. X86_64_SSESF_CLASS,
  951. X86_64_SSEDF_CLASS,
  952. X86_64_SSEUP_CLASS:
  953. inc(needmmloc);
  954. end;
  955. { the "-1" is because we can also use the current register }
  956. if ((target_info.system=system_x86_64_win64) and
  957. ((intparareg+needintloc-1 > high(paraintsupregs_winx64)) or
  958. (mmparareg+needmmloc-1 > high(parammsupregs_winx64)))) or
  959. ((target_info.system<>system_x86_64_win64) and
  960. ((intparareg+needintloc-1 > high(paraintsupregs)) or
  961. (mmparareg+needmmloc-1 > high(parammsupregs)))) then
  962. begin
  963. { If there are no registers available for any
  964. eightbyte of an argument, the whole argument is
  965. passed on the stack. }
  966. loc[low(loc)]:=X86_64_MEMORY_CLASS;
  967. for locidx:=succ(low(loc)) to high(loc) do
  968. loc[locidx]:=X86_64_NO_CLASS;
  969. end;
  970. locidx:=1;
  971. while (paralen>0) do
  972. begin
  973. if locidx>2 then
  974. internalerror(200501283);
  975. { Allocate }
  976. case loc[locidx] of
  977. X86_64_INTEGER_CLASS,
  978. X86_64_INTEGERSI_CLASS:
  979. begin
  980. paraloc:=hp.paraloc[side].add_location;
  981. paraloc^.loc:=LOC_REGISTER;
  982. if (paracgsize=OS_NO) or (loc[2]<>X86_64_NO_CLASS) then
  983. begin
  984. if loc[locidx]=X86_64_INTEGER_CLASS then
  985. begin
  986. paraloc^.size:=OS_INT;
  987. subreg:=R_SUBWHOLE;
  988. end
  989. else
  990. begin
  991. paraloc^.size:=OS_32;
  992. subreg:=R_SUBD;
  993. end;
  994. end
  995. else
  996. begin
  997. paraloc^.size:=paracgsize;
  998. { s64comp is pushed in an int register }
  999. if paraloc^.size=OS_C64 then
  1000. paraloc^.size:=OS_64;
  1001. subreg:=cgsize2subreg(R_INTREGISTER,paraloc^.size);
  1002. end;
  1003. { winx64 uses different registers }
  1004. if target_info.system=system_x86_64_win64 then
  1005. paraloc^.register:=newreg(R_INTREGISTER,paraintsupregs_winx64[intparareg],subreg)
  1006. else
  1007. paraloc^.register:=newreg(R_INTREGISTER,paraintsupregs[intparareg],subreg);
  1008. { matching mm register must be skipped }
  1009. if target_info.system=system_x86_64_win64 then
  1010. inc(mmparareg);
  1011. inc(intparareg);
  1012. dec(paralen,tcgsize2size[paraloc^.size]);
  1013. end;
  1014. X86_64_SSE_CLASS,
  1015. X86_64_SSESF_CLASS,
  1016. X86_64_SSEDF_CLASS,
  1017. X86_64_SSEUP_CLASS:
  1018. begin
  1019. paraloc:=hp.paraloc[side].add_location;
  1020. paraloc^.loc:=LOC_MMREGISTER;
  1021. case loc[locidx] of
  1022. X86_64_SSESF_CLASS:
  1023. begin
  1024. subreg:=R_SUBMMS;
  1025. paraloc^.size:=OS_F32;
  1026. end;
  1027. X86_64_SSEDF_CLASS:
  1028. begin
  1029. subreg:=R_SUBMMD;
  1030. paraloc^.size:=OS_F64;
  1031. end;
  1032. else
  1033. begin
  1034. subreg:=R_SUBQ;
  1035. paraloc^.size:=OS_M64;
  1036. end;
  1037. end;
  1038. { winx64 uses different registers }
  1039. if target_info.system=system_x86_64_win64 then
  1040. paraloc^.register:=newreg(R_MMREGISTER,parammsupregs_winx64[mmparareg],subreg)
  1041. else
  1042. paraloc^.register:=newreg(R_MMREGISTER,parammsupregs[mmparareg],subreg);
  1043. { matching int register must be skipped }
  1044. if target_info.system=system_x86_64_win64 then
  1045. inc(intparareg);
  1046. inc(mmparareg);
  1047. dec(paralen,tcgsize2size[paraloc^.size]);
  1048. end;
  1049. X86_64_MEMORY_CLASS :
  1050. begin
  1051. paraloc:=hp.paraloc[side].add_location;
  1052. paraloc^.loc:=LOC_REFERENCE;
  1053. {Hack alert!!! We should modify int_cgsize to handle OS_128,
  1054. however, since int_cgsize is called in many places in the
  1055. compiler where only a few can already handle OS_128, fixing it
  1056. properly is out of the question to release 2.2.0 in time. (DM)}
  1057. if paracgsize=OS_128 then
  1058. if paralen=8 then
  1059. paraloc^.size:=OS_64
  1060. else if paralen=16 then
  1061. paraloc^.size:=OS_128
  1062. else
  1063. internalerror(200707143)
  1064. else if paracgsize in [OS_F32,OS_F64,OS_F80,OS_F128] then
  1065. paraloc^.size:=int_float_cgsize(paralen)
  1066. else
  1067. paraloc^.size:=int_cgsize(paralen);
  1068. if side=callerside then
  1069. paraloc^.reference.index:=NR_STACK_POINTER_REG
  1070. else
  1071. paraloc^.reference.index:=NR_FRAME_POINTER_REG;
  1072. varalign:=used_align(size_2_align(paralen),paraalign,paraalign);
  1073. paraloc^.reference.offset:=parasize;
  1074. parasize:=align(parasize+paralen,varalign);
  1075. paralen:=0;
  1076. end;
  1077. else
  1078. internalerror(2010053113);
  1079. end;
  1080. if (locidx<2) and
  1081. (loc[locidx+1]<>X86_64_NO_CLASS) then
  1082. inc(locidx);
  1083. end;
  1084. end
  1085. else
  1086. begin
  1087. paraloc:=hp.paraloc[side].add_location;
  1088. paraloc^.loc:=LOC_VOID;
  1089. end;
  1090. end;
  1091. { Register parameters are assigned from left-to-right, but the
  1092. offsets on the stack are right-to-left. There is no need
  1093. to reverse the offset, only adapt the calleeside with the
  1094. start offset of the first param on the stack }
  1095. if side=calleeside then
  1096. begin
  1097. for i:=0 to paras.count-1 do
  1098. begin
  1099. hp:=tparavarsym(paras[i]);
  1100. paraloc:=hp.paraloc[side].location;
  1101. while paraloc<>nil do
  1102. begin
  1103. with paraloc^ do
  1104. if (loc=LOC_REFERENCE) then
  1105. inc(reference.offset,target_info.first_parm_offset);
  1106. paraloc:=paraloc^.next;
  1107. end;
  1108. end;
  1109. end;
  1110. end;
  1111. function tx86_64paramanager.create_varargs_paraloc_info(p : tabstractprocdef; varargspara:tvarargsparalist):longint;
  1112. var
  1113. intparareg,mmparareg,
  1114. parasize : longint;
  1115. begin
  1116. intparareg:=0;
  1117. mmparareg:=0;
  1118. if target_info.system=system_x86_64_win64 then
  1119. parasize:=4*8
  1120. else
  1121. parasize:=0;
  1122. { calculate the registers for the normal parameters }
  1123. create_paraloc_info_intern(p,callerside,p.paras,intparareg,mmparareg,parasize,false);
  1124. { append the varargs }
  1125. create_paraloc_info_intern(p,callerside,varargspara,intparareg,mmparareg,parasize,true);
  1126. { store used no. of SSE registers, that needs to be passed in %AL }
  1127. varargspara.mmregsused:=mmparareg;
  1128. result:=parasize;
  1129. end;
  1130. function tx86_64paramanager.create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
  1131. var
  1132. intparareg,mmparareg,
  1133. parasize : longint;
  1134. begin
  1135. intparareg:=0;
  1136. mmparareg:=0;
  1137. if target_info.system=system_x86_64_win64 then
  1138. parasize:=4*8
  1139. else
  1140. parasize:=0;
  1141. create_paraloc_info_intern(p,side,p.paras,intparareg,mmparareg,parasize,false);
  1142. { Create Function result paraloc }
  1143. create_funcretloc_info(p,side);
  1144. { We need to return the size allocated on the stack }
  1145. result:=parasize;
  1146. end;
  1147. begin
  1148. paramanager:=tx86_64paramanager.create;
  1149. end.