cgx86.pas 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183
  1. {
  2. Copyright (c) 1998-2005 by Florian Klaempfl
  3. This unit implements the common parts of the code generator for the i386 and the x86-64.
  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. { This unit implements the common parts of the code generator for the i386 and the x86-64.
  18. }
  19. unit cgx86;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. globtype,
  24. cgbase,cgutils,cgobj,
  25. aasmbase,aasmtai,aasmdata,aasmcpu,
  26. cpubase,cpuinfo,rgobj,rgx86,rgcpu,
  27. symconst,symtype,symdef;
  28. type
  29. tcgx86 = class(tcg)
  30. rgfpu : Trgx86fpu;
  31. procedure done_register_allocators;override;
  32. function getfpuregister(list:TAsmList;size:Tcgsize):Tregister;override;
  33. function getmmxregister(list:TAsmList):Tregister;
  34. function getmmregister(list:TAsmList;size:Tcgsize):Tregister;override;
  35. procedure getcpuregister(list:TAsmList;r:Tregister);override;
  36. procedure ungetcpuregister(list:TAsmList;r:Tregister);override;
  37. procedure alloccpuregisters(list:TAsmList;rt:Tregistertype;const r:Tcpuregisterset);override;
  38. procedure dealloccpuregisters(list:TAsmList;rt:Tregistertype;const r:Tcpuregisterset);override;
  39. function uses_registers(rt:Tregistertype):boolean;override;
  40. procedure add_reg_instruction(instr:Tai;r:tregister);override;
  41. procedure dec_fpu_stack;
  42. procedure inc_fpu_stack;
  43. procedure a_call_name(list : TAsmList;const s : string; weak: boolean);override;
  44. procedure a_call_reg(list : TAsmList;reg : tregister);override;
  45. procedure a_call_ref(list : TAsmList;ref : treference);override;
  46. procedure a_call_name_static(list : TAsmList;const s : string);override;
  47. procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister); override;
  48. procedure a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference); override;
  49. procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  50. procedure a_op_ref_reg(list : TAsmList; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); override;
  51. procedure a_op_reg_ref(list : TAsmList; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference); override;
  52. { move instructions }
  53. procedure a_load_const_reg(list : TAsmList; tosize: tcgsize; a : aint;reg : tregister);override;
  54. procedure a_load_const_ref(list : TAsmList; tosize: tcgsize; a : aint;const ref : treference);override;
  55. procedure a_load_reg_ref(list : TAsmList;fromsize,tosize: tcgsize; reg : tregister;const ref : treference);override;
  56. procedure a_load_ref_reg(list : TAsmList;fromsize,tosize: tcgsize;const ref : treference;reg : tregister);override;
  57. procedure a_load_reg_reg(list : TAsmList;fromsize,tosize: tcgsize;reg1,reg2 : tregister);override;
  58. procedure a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);override;
  59. { fpu move instructions }
  60. procedure a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize: tcgsize; reg1, reg2: tregister); override;
  61. procedure a_loadfpu_ref_reg(list: TAsmList; fromsize, tosize: tcgsize; const ref: treference; reg: tregister); override;
  62. procedure a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference); override;
  63. { vector register move instructions }
  64. procedure a_loadmm_reg_reg(list: TAsmList; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); override;
  65. procedure a_loadmm_ref_reg(list: TAsmList; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  66. procedure a_loadmm_reg_ref(list: TAsmList; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); override;
  67. procedure a_opmm_ref_reg(list: TAsmList; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  68. procedure a_opmm_reg_reg(list: TAsmList; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);override;
  69. { comparison operations }
  70. procedure a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  71. l : tasmlabel);override;
  72. procedure a_cmp_const_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  73. l : tasmlabel);override;
  74. procedure a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  75. procedure a_cmp_ref_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister; l : tasmlabel); override;
  76. procedure a_cmp_reg_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); override;
  77. procedure a_jmp_name(list : TAsmList;const s : string);override;
  78. procedure a_jmp_always(list : TAsmList;l: tasmlabel); override;
  79. procedure a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel); override;
  80. procedure g_flags2reg(list: TAsmList; size: TCgSize; const f: tresflags; reg: TRegister); override;
  81. procedure g_flags2ref(list: TAsmList; size: TCgSize; const f: tresflags; const ref: TReference); override;
  82. procedure g_concatcopy(list : TAsmList;const source,dest : treference;len : aint);override;
  83. { entry/exit code helpers }
  84. procedure g_profilecode(list : TAsmList);override;
  85. procedure g_stackpointer_alloc(list : TAsmList;localsize : longint);override;
  86. procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);override;
  87. procedure g_overflowcheck(list: TAsmList; const l:tlocation;def:tdef);override;
  88. procedure g_external_wrapper(list: TAsmList; procdef: tprocdef; const externalname: string); override;
  89. procedure make_simple_ref(list:TAsmList;var ref: treference);
  90. protected
  91. procedure a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
  92. procedure check_register_size(size:tcgsize;reg:tregister);
  93. procedure opmm_loc_reg(list: TAsmList; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  94. function get_darwin_call_stub(const s: string; weak: boolean): tasmsymbol;
  95. private
  96. procedure sizes2load(s1,s2 : tcgsize;var op: tasmop; var s3: topsize);
  97. procedure floatload(list: TAsmList; t : tcgsize;const ref : treference);
  98. procedure floatstore(list: TAsmList; t : tcgsize;const ref : treference);
  99. procedure floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  100. procedure floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  101. end;
  102. const
  103. {$ifdef x86_64}
  104. TCGSize2OpSize: Array[tcgsize] of topsize =
  105. (S_NO,S_B,S_W,S_L,S_Q,S_T,S_B,S_W,S_L,S_Q,S_Q,
  106. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  107. S_NO,S_NO,S_NO,S_MD,S_T,
  108. S_NO,S_NO,S_NO,S_NO,S_T);
  109. {$else x86_64}
  110. TCGSize2OpSize: Array[tcgsize] of topsize =
  111. (S_NO,S_B,S_W,S_L,S_L,S_T,S_B,S_W,S_L,S_L,S_L,
  112. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  113. S_NO,S_NO,S_NO,S_MD,S_T,
  114. S_NO,S_NO,S_NO,S_NO,S_T);
  115. {$endif x86_64}
  116. {$ifndef NOTARGETWIN}
  117. winstackpagesize = 4096;
  118. {$endif NOTARGETWIN}
  119. implementation
  120. uses
  121. globals,verbose,systems,cutils,
  122. defutil,paramgr,procinfo,
  123. tgobj,ncgutil,
  124. fmodule;
  125. const
  126. TOpCG2AsmOp: Array[topcg] of TAsmOp = (A_NONE,A_MOV,A_ADD,A_AND,A_DIV,
  127. A_IDIV,A_IMUL,A_MUL,A_NEG,A_NOT,A_OR,
  128. A_SAR,A_SHL,A_SHR,A_SUB,A_XOR,A_ROL,A_ROR);
  129. TOpCmp2AsmCond: Array[topcmp] of TAsmCond = (C_NONE,
  130. C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A);
  131. procedure Tcgx86.done_register_allocators;
  132. begin
  133. rg[R_INTREGISTER].free;
  134. rg[R_MMREGISTER].free;
  135. rg[R_MMXREGISTER].free;
  136. rgfpu.free;
  137. inherited done_register_allocators;
  138. end;
  139. function Tcgx86.getfpuregister(list:TAsmList;size:Tcgsize):Tregister;
  140. begin
  141. result:=rgfpu.getregisterfpu(list);
  142. end;
  143. function Tcgx86.getmmxregister(list:TAsmList):Tregister;
  144. begin
  145. if not assigned(rg[R_MMXREGISTER]) then
  146. internalerror(2003121214);
  147. result:=rg[R_MMXREGISTER].getregister(list,R_SUBNONE);
  148. end;
  149. function Tcgx86.getmmregister(list:TAsmList;size:Tcgsize):Tregister;
  150. begin
  151. if not assigned(rg[R_MMREGISTER]) then
  152. internalerror(2003121234);
  153. case size of
  154. OS_F64:
  155. result:=rg[R_MMREGISTER].getregister(list,R_SUBMMD);
  156. OS_F32:
  157. result:=rg[R_MMREGISTER].getregister(list,R_SUBMMS);
  158. OS_M128:
  159. result:=rg[R_MMREGISTER].getregister(list,R_SUBMMWHOLE);
  160. else
  161. internalerror(200506041);
  162. end;
  163. end;
  164. procedure Tcgx86.getcpuregister(list:TAsmList;r:Tregister);
  165. begin
  166. if getregtype(r)=R_FPUREGISTER then
  167. internalerror(2003121210)
  168. else
  169. inherited getcpuregister(list,r);
  170. end;
  171. procedure tcgx86.ungetcpuregister(list:TAsmList;r:Tregister);
  172. begin
  173. if getregtype(r)=R_FPUREGISTER then
  174. rgfpu.ungetregisterfpu(list,r)
  175. else
  176. inherited ungetcpuregister(list,r);
  177. end;
  178. procedure Tcgx86.alloccpuregisters(list:TAsmList;rt:Tregistertype;const r:Tcpuregisterset);
  179. begin
  180. if rt<>R_FPUREGISTER then
  181. inherited alloccpuregisters(list,rt,r);
  182. end;
  183. procedure Tcgx86.dealloccpuregisters(list:TAsmList;rt:Tregistertype;const r:Tcpuregisterset);
  184. begin
  185. if rt<>R_FPUREGISTER then
  186. inherited dealloccpuregisters(list,rt,r);
  187. end;
  188. function Tcgx86.uses_registers(rt:Tregistertype):boolean;
  189. begin
  190. if rt=R_FPUREGISTER then
  191. result:=false
  192. else
  193. result:=inherited uses_registers(rt);
  194. end;
  195. procedure tcgx86.add_reg_instruction(instr:Tai;r:tregister);
  196. begin
  197. if getregtype(r)<>R_FPUREGISTER then
  198. inherited add_reg_instruction(instr,r);
  199. end;
  200. procedure tcgx86.dec_fpu_stack;
  201. begin
  202. if rgfpu.fpuvaroffset<=0 then
  203. internalerror(200604201);
  204. dec(rgfpu.fpuvaroffset);
  205. end;
  206. procedure tcgx86.inc_fpu_stack;
  207. begin
  208. inc(rgfpu.fpuvaroffset);
  209. end;
  210. {****************************************************************************
  211. This is private property, keep out! :)
  212. ****************************************************************************}
  213. procedure tcgx86.sizes2load(s1,s2 : tcgsize; var op: tasmop; var s3: topsize);
  214. begin
  215. { ensure to have always valid sizes }
  216. if s1=OS_NO then
  217. s1:=s2;
  218. if s2=OS_NO then
  219. s2:=s1;
  220. case s2 of
  221. OS_8,OS_S8 :
  222. if S1 in [OS_8,OS_S8] then
  223. s3 := S_B
  224. else
  225. internalerror(200109221);
  226. OS_16,OS_S16:
  227. case s1 of
  228. OS_8,OS_S8:
  229. s3 := S_BW;
  230. OS_16,OS_S16:
  231. s3 := S_W;
  232. else
  233. internalerror(200109222);
  234. end;
  235. OS_32,OS_S32:
  236. case s1 of
  237. OS_8,OS_S8:
  238. s3 := S_BL;
  239. OS_16,OS_S16:
  240. s3 := S_WL;
  241. OS_32,OS_S32:
  242. s3 := S_L;
  243. else
  244. internalerror(200109223);
  245. end;
  246. {$ifdef x86_64}
  247. OS_64,OS_S64:
  248. case s1 of
  249. OS_8:
  250. s3 := S_BL;
  251. OS_S8:
  252. s3 := S_BQ;
  253. OS_16:
  254. s3 := S_WL;
  255. OS_S16:
  256. s3 := S_WQ;
  257. OS_32:
  258. s3 := S_L;
  259. OS_S32:
  260. s3 := S_LQ;
  261. OS_64,OS_S64:
  262. s3 := S_Q;
  263. else
  264. internalerror(200304302);
  265. end;
  266. {$endif x86_64}
  267. else
  268. internalerror(200109227);
  269. end;
  270. if s3 in [S_B,S_W,S_L,S_Q] then
  271. op := A_MOV
  272. else if s1 in [OS_8,OS_16,OS_32,OS_64] then
  273. op := A_MOVZX
  274. else
  275. {$ifdef x86_64}
  276. if s3 in [S_LQ] then
  277. op := A_MOVSXD
  278. else
  279. {$endif x86_64}
  280. op := A_MOVSX;
  281. end;
  282. procedure tcgx86.make_simple_ref(list:TAsmList;var ref: treference);
  283. var
  284. hreg : tregister;
  285. href : treference;
  286. {$ifndef x86_64}
  287. add_hreg: boolean;
  288. {$endif not x86_64}
  289. begin
  290. { make_simple_ref() may have already been called earlier, and in that
  291. case make sure we don't perform the PIC-simplifications twice }
  292. if (ref.refaddr in [addr_pic,addr_pic_no_got]) then
  293. exit;
  294. {$ifdef x86_64}
  295. { Only 32bit is allowed }
  296. if ((ref.offset<low(longint)) or (ref.offset>high(longint))) then
  297. begin
  298. { Load constant value to register }
  299. hreg:=GetAddressRegister(list);
  300. list.concat(taicpu.op_const_reg(A_MOV,S_Q,ref.offset,hreg));
  301. ref.offset:=0;
  302. {if assigned(ref.symbol) then
  303. begin
  304. list.concat(taicpu.op_sym_ofs_reg(A_ADD,S_Q,ref.symbol,0,hreg));
  305. ref.symbol:=nil;
  306. end;}
  307. { Add register to reference }
  308. if ref.index=NR_NO then
  309. ref.index:=hreg
  310. else
  311. begin
  312. if ref.scalefactor<>0 then
  313. begin
  314. list.concat(taicpu.op_reg_reg(A_ADD,S_Q,ref.base,hreg));
  315. ref.base:=hreg;
  316. end
  317. else
  318. begin
  319. list.concat(taicpu.op_reg_reg(A_ADD,S_Q,ref.index,hreg));
  320. ref.index:=hreg;
  321. end;
  322. end;
  323. end;
  324. if assigned(ref.symbol) and not((ref.symbol.bind=AB_LOCAL) and (ref.symbol.typ in [AT_LABEL,AT_FUNCTION])) then
  325. begin
  326. if cs_create_pic in current_settings.moduleswitches then
  327. begin
  328. if (ref.symbol.bind=AB_LOCAL) and
  329. (ref.symbol.typ=AT_DATA) then
  330. begin
  331. { Local data symbols don't have to go via the GOT (and in
  332. case of darwin must not in some cases), but they still
  333. have to be addressed using PIC (RIP-relative).
  334. }
  335. { unfortunately, RIP-based addresses don't support an index }
  336. if (ref.base<>NR_NO) or
  337. (ref.index<>NR_NO) then
  338. begin
  339. reference_reset_symbol(href,ref.symbol,0,ref.alignment);
  340. hreg:=getaddressregister(list);
  341. href.refaddr:=addr_pic_no_got;
  342. href.base:=NR_RIP;
  343. list.concat(taicpu.op_ref_reg(A_LEA,S_Q,href,hreg));
  344. ref.symbol:=nil;
  345. end
  346. else
  347. begin
  348. ref.refaddr:=addr_pic_no_got;
  349. hreg:=NR_NO;
  350. ref.base:=NR_RIP;
  351. end;
  352. end
  353. else
  354. begin
  355. reference_reset_symbol(href,ref.symbol,0,ref.alignment);
  356. hreg:=getaddressregister(list);
  357. href.refaddr:=addr_pic;
  358. href.base:=NR_RIP;
  359. list.concat(taicpu.op_ref_reg(A_MOV,S_Q,href,hreg));
  360. ref.symbol:=nil;
  361. end;
  362. if ref.base=NR_NO then
  363. ref.base:=hreg
  364. else if ref.index=NR_NO then
  365. begin
  366. ref.index:=hreg;
  367. ref.scalefactor:=1;
  368. end
  369. else
  370. begin
  371. list.concat(taicpu.op_reg_reg(A_ADD,S_Q,ref.base,hreg));
  372. ref.base:=hreg;
  373. end;
  374. end
  375. else
  376. { Always use RIP relative symbol addressing for Windows and Darwin targets. }
  377. if (target_info.system in (system_all_windows+[system_x86_64_darwin])) and (ref.base<>NR_RIP) then
  378. begin
  379. if (ref.refaddr=addr_no) and (ref.base=NR_NO) and (ref.index=NR_NO) then
  380. begin
  381. { Set RIP relative addressing for simple symbol references }
  382. ref.base:=NR_RIP;
  383. ref.refaddr:=addr_pic_no_got
  384. end
  385. else
  386. begin
  387. { Use temp register to load calculated 64-bit symbol address for complex references }
  388. reference_reset_symbol(href,ref.symbol,0,sizeof(pint));
  389. href.base:=NR_RIP;
  390. href.refaddr:=addr_pic_no_got;
  391. hreg:=GetAddressRegister(list);
  392. list.concat(taicpu.op_ref_reg(A_LEA,S_Q,href,hreg));
  393. ref.symbol:=nil;
  394. if ref.base=NR_NO then
  395. ref.base:=hreg
  396. else if ref.index=NR_NO then
  397. begin
  398. ref.index:=hreg;
  399. ref.scalefactor:=0;
  400. end
  401. else
  402. begin
  403. list.concat(taicpu.op_reg_reg(A_ADD,S_Q,ref.base,hreg));
  404. ref.base:=hreg;
  405. end;
  406. end;
  407. end;
  408. end;
  409. {$else x86_64}
  410. add_hreg:=false;
  411. if (target_info.system=system_i386_darwin) then
  412. begin
  413. if assigned(ref.symbol) and
  414. not(assigned(ref.relsymbol)) and
  415. ((ref.symbol.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL]) or
  416. (cs_create_pic in current_settings.moduleswitches)) then
  417. begin
  418. if (ref.symbol.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL]) or
  419. ((cs_create_pic in current_settings.moduleswitches) and
  420. (ref.symbol.bind in [AB_COMMON,AB_GLOBAL])) then
  421. begin
  422. hreg:=g_indirect_sym_load(list,ref.symbol.name,ref.symbol.bind=AB_WEAK_EXTERNAL);
  423. ref.symbol:=nil;
  424. end
  425. else
  426. begin
  427. include(current_procinfo.flags,pi_needs_got);
  428. hreg:=current_procinfo.got;
  429. ref.relsymbol:=current_procinfo.CurrGOTLabel;
  430. end;
  431. add_hreg:=true
  432. end
  433. end
  434. else if (cs_create_pic in current_settings.moduleswitches) and
  435. assigned(ref.symbol) and
  436. not((ref.symbol.bind=AB_LOCAL) and
  437. (ref.symbol.typ in [AT_LABEL,AT_FUNCTION])) then
  438. begin
  439. reference_reset_symbol(href,ref.symbol,0,sizeof(pint));
  440. href.base:=current_procinfo.got;
  441. href.refaddr:=addr_pic;
  442. include(current_procinfo.flags,pi_needs_got);
  443. hreg:=cg.getaddressregister(list);
  444. list.concat(taicpu.op_ref_reg(A_MOV,S_L,href,hreg));
  445. ref.symbol:=nil;
  446. add_hreg:=true;
  447. end;
  448. if add_hreg then
  449. begin
  450. if ref.base=NR_NO then
  451. ref.base:=hreg
  452. else if ref.index=NR_NO then
  453. begin
  454. ref.index:=hreg;
  455. ref.scalefactor:=1;
  456. end
  457. else
  458. begin
  459. list.concat(taicpu.op_reg_reg(A_ADD,S_L,ref.base,hreg));
  460. ref.base:=hreg;
  461. end;
  462. end;
  463. {$endif x86_64}
  464. end;
  465. procedure tcgx86.floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  466. begin
  467. case t of
  468. OS_F32 :
  469. begin
  470. op:=A_FLD;
  471. s:=S_FS;
  472. end;
  473. OS_F64 :
  474. begin
  475. op:=A_FLD;
  476. s:=S_FL;
  477. end;
  478. OS_F80 :
  479. begin
  480. op:=A_FLD;
  481. s:=S_FX;
  482. end;
  483. OS_C64 :
  484. begin
  485. op:=A_FILD;
  486. s:=S_IQ;
  487. end;
  488. else
  489. internalerror(200204043);
  490. end;
  491. end;
  492. procedure tcgx86.floatload(list: TAsmList; t : tcgsize;const ref : treference);
  493. var
  494. op : tasmop;
  495. s : topsize;
  496. tmpref : treference;
  497. begin
  498. tmpref:=ref;
  499. make_simple_ref(list,tmpref);
  500. floatloadops(t,op,s);
  501. list.concat(Taicpu.Op_ref(op,s,tmpref));
  502. inc_fpu_stack;
  503. end;
  504. procedure tcgx86.floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  505. begin
  506. case t of
  507. OS_F32 :
  508. begin
  509. op:=A_FSTP;
  510. s:=S_FS;
  511. end;
  512. OS_F64 :
  513. begin
  514. op:=A_FSTP;
  515. s:=S_FL;
  516. end;
  517. OS_F80 :
  518. begin
  519. op:=A_FSTP;
  520. s:=S_FX;
  521. end;
  522. OS_C64 :
  523. begin
  524. op:=A_FISTP;
  525. s:=S_IQ;
  526. end;
  527. else
  528. internalerror(200204042);
  529. end;
  530. end;
  531. procedure tcgx86.floatstore(list: TAsmList; t : tcgsize;const ref : treference);
  532. var
  533. op : tasmop;
  534. s : topsize;
  535. tmpref : treference;
  536. begin
  537. tmpref:=ref;
  538. make_simple_ref(list,tmpref);
  539. floatstoreops(t,op,s);
  540. list.concat(Taicpu.Op_ref(op,s,tmpref));
  541. { storing non extended floats can cause a floating point overflow }
  542. if (t<>OS_F80) and
  543. (cs_fpu_fwait in current_settings.localswitches) then
  544. list.concat(Taicpu.Op_none(A_FWAIT,S_NO));
  545. dec_fpu_stack;
  546. end;
  547. procedure tcgx86.check_register_size(size:tcgsize;reg:tregister);
  548. begin
  549. if TCGSize2OpSize[size]<>TCGSize2OpSize[reg_cgsize(reg)] then
  550. internalerror(200306031);
  551. end;
  552. {****************************************************************************
  553. Assembler code
  554. ****************************************************************************}
  555. procedure tcgx86.a_jmp_name(list : TAsmList;const s : string);
  556. var
  557. r: treference;
  558. begin
  559. if (target_info.system<>system_i386_darwin) then
  560. list.concat(taicpu.op_sym(A_JMP,S_NO,current_asmdata.RefAsmSymbol(s)))
  561. else
  562. begin
  563. reference_reset_symbol(r,get_darwin_call_stub(s,false),0,sizeof(pint));
  564. r.refaddr:=addr_full;
  565. list.concat(taicpu.op_ref(A_JMP,S_NO,r));
  566. end;
  567. end;
  568. procedure tcgx86.a_jmp_always(list : TAsmList;l: tasmlabel);
  569. begin
  570. a_jmp_cond(list, OC_NONE, l);
  571. end;
  572. function tcgx86.get_darwin_call_stub(const s: string; weak: boolean): tasmsymbol;
  573. var
  574. stubname: string;
  575. begin
  576. stubname := 'L'+s+'$stub';
  577. result := current_asmdata.getasmsymbol(stubname);
  578. if assigned(result) then
  579. exit;
  580. if current_asmdata.asmlists[al_imports]=nil then
  581. current_asmdata.asmlists[al_imports]:=TAsmList.create;
  582. current_asmdata.asmlists[al_imports].concat(Tai_section.create(sec_stub,'',0));
  583. result := current_asmdata.RefAsmSymbol(stubname);
  584. current_asmdata.asmlists[al_imports].concat(Tai_symbol.Create(result,0));
  585. { register as a weak symbol if necessary }
  586. if weak then
  587. current_asmdata.weakrefasmsymbol(s);
  588. current_asmdata.asmlists[al_imports].concat(tai_directive.create(asd_indirect_symbol,s));
  589. current_asmdata.asmlists[al_imports].concat(taicpu.op_none(A_HLT));
  590. current_asmdata.asmlists[al_imports].concat(taicpu.op_none(A_HLT));
  591. current_asmdata.asmlists[al_imports].concat(taicpu.op_none(A_HLT));
  592. current_asmdata.asmlists[al_imports].concat(taicpu.op_none(A_HLT));
  593. current_asmdata.asmlists[al_imports].concat(taicpu.op_none(A_HLT));
  594. end;
  595. procedure tcgx86.a_call_name(list : TAsmList;const s : string; weak: boolean);
  596. var
  597. sym : tasmsymbol;
  598. r : treference;
  599. begin
  600. if (target_info.system <> system_i386_darwin) then
  601. begin
  602. if not(weak) then
  603. sym:=current_asmdata.RefAsmSymbol(s)
  604. else
  605. sym:=current_asmdata.WeakRefAsmSymbol(s);
  606. reference_reset_symbol(r,sym,0,sizeof(pint));
  607. if (cs_create_pic in current_settings.moduleswitches) and
  608. { darwin/x86_64's assembler doesn't want @PLT after call symbols }
  609. (target_info.system<>system_x86_64_darwin) then
  610. begin
  611. {$ifdef i386}
  612. include(current_procinfo.flags,pi_needs_got);
  613. {$endif i386}
  614. r.refaddr:=addr_pic
  615. end
  616. else
  617. r.refaddr:=addr_full;
  618. end
  619. else
  620. begin
  621. reference_reset_symbol(r,get_darwin_call_stub(s,weak),0,sizeof(pint));
  622. r.refaddr:=addr_full;
  623. end;
  624. list.concat(taicpu.op_ref(A_CALL,S_NO,r));
  625. end;
  626. procedure tcgx86.a_call_name_static(list : TAsmList;const s : string);
  627. var
  628. sym : tasmsymbol;
  629. r : treference;
  630. begin
  631. sym:=current_asmdata.RefAsmSymbol(s);
  632. reference_reset_symbol(r,sym,0,sizeof(pint));
  633. r.refaddr:=addr_full;
  634. list.concat(taicpu.op_ref(A_CALL,S_NO,r));
  635. end;
  636. procedure tcgx86.a_call_reg(list : TAsmList;reg : tregister);
  637. begin
  638. list.concat(taicpu.op_reg(A_CALL,S_NO,reg));
  639. end;
  640. procedure tcgx86.a_call_ref(list : TAsmList;ref : treference);
  641. begin
  642. list.concat(taicpu.op_ref(A_CALL,S_NO,ref));
  643. end;
  644. {********************** load instructions ********************}
  645. procedure tcgx86.a_load_const_reg(list : TAsmList; tosize: TCGSize; a : aint; reg : TRegister);
  646. begin
  647. check_register_size(tosize,reg);
  648. { the optimizer will change it to "xor reg,reg" when loading zero, }
  649. { no need to do it here too (JM) }
  650. list.concat(taicpu.op_const_reg(A_MOV,TCGSize2OpSize[tosize],a,reg))
  651. end;
  652. procedure tcgx86.a_load_const_ref(list : TAsmList; tosize: tcgsize; a : aint;const ref : treference);
  653. var
  654. tmpref : treference;
  655. begin
  656. tmpref:=ref;
  657. make_simple_ref(list,tmpref);
  658. {$ifdef x86_64}
  659. { x86_64 only supports signed 32 bits constants directly }
  660. if (tosize in [OS_S64,OS_64]) and
  661. ((a<low(longint)) or (a>high(longint))) then
  662. begin
  663. a_load_const_ref(list,OS_32,longint(a and $ffffffff),tmpref);
  664. inc(tmpref.offset,4);
  665. a_load_const_ref(list,OS_32,longint(a shr 32),tmpref);
  666. end
  667. else
  668. {$endif x86_64}
  669. list.concat(taicpu.op_const_ref(A_MOV,TCGSize2OpSize[tosize],a,tmpref));
  670. end;
  671. procedure tcgx86.a_load_reg_ref(list : TAsmList; fromsize,tosize: TCGSize; reg : tregister;const ref : treference);
  672. var
  673. op: tasmop;
  674. s: topsize;
  675. tmpsize : tcgsize;
  676. tmpreg : tregister;
  677. tmpref : treference;
  678. begin
  679. tmpref:=ref;
  680. make_simple_ref(list,tmpref);
  681. check_register_size(fromsize,reg);
  682. sizes2load(fromsize,tosize,op,s);
  683. case s of
  684. {$ifdef x86_64}
  685. S_BQ,S_WQ,S_LQ,
  686. {$endif x86_64}
  687. S_BW,S_BL,S_WL :
  688. begin
  689. tmpreg:=getintregister(list,tosize);
  690. {$ifdef x86_64}
  691. { zero extensions to 64 bit on the x86_64 are simply done by writting to the lower 32 bit
  692. which clears the upper 64 bit too, so it could be that s is S_L while the reg is
  693. 64 bit (FK) }
  694. if s in [S_BL,S_WL,S_L] then
  695. begin
  696. tmpreg:=makeregsize(list,tmpreg,OS_32);
  697. tmpsize:=OS_32;
  698. end
  699. else
  700. {$endif x86_64}
  701. tmpsize:=tosize;
  702. list.concat(taicpu.op_reg_reg(op,s,reg,tmpreg));
  703. a_load_reg_ref(list,tmpsize,tosize,tmpreg,tmpref);
  704. end;
  705. else
  706. list.concat(taicpu.op_reg_ref(op,s,reg,tmpref));
  707. end;
  708. end;
  709. procedure tcgx86.a_load_ref_reg(list : TAsmList;fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  710. var
  711. op: tasmop;
  712. s: topsize;
  713. tmpref : treference;
  714. begin
  715. tmpref:=ref;
  716. make_simple_ref(list,tmpref);
  717. check_register_size(tosize,reg);
  718. sizes2load(fromsize,tosize,op,s);
  719. {$ifdef x86_64}
  720. { zero extensions to 64 bit on the x86_64 are simply done by writting to the lower 32 bit
  721. which clears the upper 64 bit too, so it could be that s is S_L while the reg is
  722. 64 bit (FK) }
  723. if s in [S_BL,S_WL,S_L] then
  724. reg:=makeregsize(list,reg,OS_32);
  725. {$endif x86_64}
  726. list.concat(taicpu.op_ref_reg(op,s,tmpref,reg));
  727. end;
  728. procedure tcgx86.a_load_reg_reg(list : TAsmList;fromsize,tosize : tcgsize;reg1,reg2 : tregister);
  729. var
  730. op: tasmop;
  731. s: topsize;
  732. instr:Taicpu;
  733. begin
  734. check_register_size(fromsize,reg1);
  735. check_register_size(tosize,reg2);
  736. if tcgsize2size[fromsize]>tcgsize2size[tosize] then
  737. begin
  738. reg1:=makeregsize(list,reg1,tosize);
  739. s:=tcgsize2opsize[tosize];
  740. op:=A_MOV;
  741. end
  742. else
  743. sizes2load(fromsize,tosize,op,s);
  744. {$ifdef x86_64}
  745. { zero extensions to 64 bit on the x86_64 are simply done by writting to the lower 32 bit
  746. which clears the upper 64 bit too, so it could be that s is S_L while the reg is
  747. 64 bit (FK)
  748. }
  749. if s in [S_BL,S_WL,S_L] then
  750. reg2:=makeregsize(list,reg2,OS_32);
  751. {$endif x86_64}
  752. if (reg1<>reg2) then
  753. begin
  754. instr:=taicpu.op_reg_reg(op,s,reg1,reg2);
  755. { Notify the register allocator that we have written a move instruction so
  756. it can try to eliminate it. }
  757. if (reg1<>current_procinfo.framepointer) and (reg1<>NR_STACK_POINTER_REG) then
  758. add_move_instruction(instr);
  759. list.concat(instr);
  760. end;
  761. {$ifdef x86_64}
  762. { avoid merging of registers and killing the zero extensions (FK) }
  763. if (tosize in [OS_64,OS_S64]) and (s=S_L) then
  764. list.concat(taicpu.op_const_reg(A_AND,S_L,$ffffffff,reg2));
  765. {$endif x86_64}
  766. end;
  767. procedure tcgx86.a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);
  768. var
  769. tmpref : treference;
  770. begin
  771. with ref do
  772. begin
  773. if (base=NR_NO) and (index=NR_NO) then
  774. begin
  775. if assigned(ref.symbol) then
  776. begin
  777. if (target_info.system=system_i386_darwin) and
  778. ((ref.symbol.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL]) or
  779. (cs_create_pic in current_settings.moduleswitches)) then
  780. begin
  781. if (ref.symbol.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL]) or
  782. ((cs_create_pic in current_settings.moduleswitches) and
  783. (ref.symbol.bind in [AB_COMMON,AB_GLOBAL])) then
  784. begin
  785. reference_reset_base(tmpref,
  786. g_indirect_sym_load(list,ref.symbol.name,ref.symbol.bind=AB_WEAK_EXTERNAL),
  787. offset,sizeof(pint));
  788. a_loadaddr_ref_reg(list,tmpref,r);
  789. end
  790. else
  791. begin
  792. include(current_procinfo.flags,pi_needs_got);
  793. reference_reset_base(tmpref,current_procinfo.got,offset,ref.alignment);
  794. tmpref.symbol:=symbol;
  795. tmpref.relsymbol:=current_procinfo.CurrGOTLabel;
  796. list.concat(Taicpu.op_ref_reg(A_LEA,tcgsize2opsize[OS_ADDR],tmpref,r));
  797. end;
  798. end
  799. else if (cs_create_pic in current_settings.moduleswitches)
  800. {$ifdef x86_64}
  801. and not((ref.symbol.bind=AB_LOCAL) and (ref.symbol.typ=AT_DATA))
  802. {$endif x86_64}
  803. then
  804. begin
  805. {$ifdef x86_64}
  806. reference_reset_symbol(tmpref,ref.symbol,0,ref.alignment);
  807. tmpref.refaddr:=addr_pic;
  808. tmpref.base:=NR_RIP;
  809. list.concat(taicpu.op_ref_reg(A_MOV,S_Q,tmpref,r));
  810. {$else x86_64}
  811. reference_reset_symbol(tmpref,ref.symbol,0,ref.alignment);
  812. tmpref.refaddr:=addr_pic;
  813. tmpref.base:=current_procinfo.got;
  814. include(current_procinfo.flags,pi_needs_got);
  815. list.concat(taicpu.op_ref_reg(A_MOV,S_L,tmpref,r));
  816. {$endif x86_64}
  817. if offset<>0 then
  818. a_op_const_reg(list,OP_ADD,OS_ADDR,offset,r);
  819. end
  820. {$ifdef x86_64}
  821. else if (target_info.system in (system_all_windows+[system_x86_64_darwin])) then
  822. begin
  823. { Win64 and Darwin/x86_64 always require RIP-relative addressing }
  824. tmpref:=ref;
  825. tmpref.base:=NR_RIP;
  826. tmpref.refaddr:=addr_pic_no_got;
  827. list.concat(Taicpu.op_ref_reg(A_LEA,S_Q,tmpref,r));
  828. end
  829. {$endif x86_64}
  830. else
  831. begin
  832. tmpref:=ref;
  833. tmpref.refaddr:=ADDR_FULL;
  834. list.concat(Taicpu.op_ref_reg(A_MOV,tcgsize2opsize[OS_ADDR],tmpref,r));
  835. end
  836. end
  837. else
  838. a_load_const_reg(list,OS_ADDR,offset,r)
  839. end
  840. else if (base=NR_NO) and (index<>NR_NO) and
  841. (offset=0) and (scalefactor=0) and (symbol=nil) then
  842. a_load_reg_reg(list,OS_ADDR,OS_ADDR,index,r)
  843. else if (base<>NR_NO) and (index=NR_NO) and
  844. (offset=0) and (symbol=nil) then
  845. a_load_reg_reg(list,OS_ADDR,OS_ADDR,base,r)
  846. else
  847. begin
  848. tmpref:=ref;
  849. make_simple_ref(list,tmpref);
  850. list.concat(Taicpu.op_ref_reg(A_LEA,tcgsize2opsize[OS_ADDR],tmpref,r));
  851. end;
  852. if segment<>NR_NO then
  853. begin
  854. if (tf_section_threadvars in target_info.flags) then
  855. begin
  856. { Convert thread local address to a process global addres
  857. as we cannot handle far pointers.}
  858. case target_info.system of
  859. system_i386_linux:
  860. if segment=NR_GS then
  861. begin
  862. reference_reset_symbol(tmpref,current_asmdata.RefAsmSymbol('___fpc_threadvar_offset'),0,ref.alignment);
  863. tmpref.segment:=NR_GS;
  864. list.concat(Taicpu.op_ref_reg(A_ADD,tcgsize2opsize[OS_ADDR],tmpref,r));
  865. end
  866. else
  867. cgmessage(cg_e_cant_use_far_pointer_there);
  868. system_i386_win32:
  869. if segment=NR_FS then
  870. begin
  871. allocallcpuregisters(list);
  872. a_call_name(list,'GetTls',false);
  873. deallocallcpuregisters(list);
  874. list.concat(Taicpu.op_reg_reg(A_ADD,tcgsize2opsize[OS_ADDR],NR_EAX,r));
  875. end
  876. else
  877. cgmessage(cg_e_cant_use_far_pointer_there);
  878. else
  879. cgmessage(cg_e_cant_use_far_pointer_there);
  880. end;
  881. end
  882. else
  883. cgmessage(cg_e_cant_use_far_pointer_there);
  884. end;
  885. end;
  886. end;
  887. { all fpu load routines expect that R_ST[0-7] means an fpu regvar and }
  888. { R_ST means "the current value at the top of the fpu stack" (JM) }
  889. procedure tcgx86.a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize: tcgsize; reg1, reg2: tregister);
  890. var
  891. href: treference;
  892. op: tasmop;
  893. s: topsize;
  894. begin
  895. if (reg1<>NR_ST) then
  896. begin
  897. floatloadops(tosize,op,s);
  898. list.concat(taicpu.op_reg(op,s,rgfpu.correct_fpuregister(reg1,rgfpu.fpuvaroffset)));
  899. inc_fpu_stack;
  900. end;
  901. if (reg2<>NR_ST) then
  902. begin
  903. floatstoreops(tosize,op,s);
  904. list.concat(taicpu.op_reg(op,s,rgfpu.correct_fpuregister(reg2,rgfpu.fpuvaroffset)));
  905. dec_fpu_stack;
  906. end;
  907. { OS_F80 < OS_C64, but OS_C64 fits perfectly in OS_F80 }
  908. if (reg1=NR_ST) and
  909. (reg2=NR_ST) and
  910. (tosize<>OS_F80) and
  911. (tosize<fromsize) then
  912. begin
  913. { can't round down to lower precision in x87 :/ }
  914. tg.gettemp(list,tcgsize2size[tosize],tcgsize2size[tosize],tt_normal,href);
  915. a_loadfpu_reg_ref(list,fromsize,tosize,NR_ST,href);
  916. a_loadfpu_ref_reg(list,tosize,tosize,href,NR_ST);
  917. tg.ungettemp(list,href);
  918. end;
  919. end;
  920. procedure tcgx86.a_loadfpu_ref_reg(list: TAsmList; fromsize, tosize: tcgsize; const ref: treference; reg: tregister);
  921. begin
  922. floatload(list,fromsize,ref);
  923. a_loadfpu_reg_reg(list,fromsize,tosize,NR_ST,reg);
  924. end;
  925. procedure tcgx86.a_loadfpu_reg_ref(list: TAsmList; fromsize,tosize: tcgsize; reg: tregister; const ref: treference);
  926. begin
  927. if reg<>NR_ST then
  928. a_loadfpu_reg_reg(list,fromsize,tosize,reg,NR_ST);
  929. floatstore(list,tosize,ref);
  930. end;
  931. function get_scalar_mm_op(fromsize,tosize : tcgsize) : tasmop;
  932. const
  933. convertop : array[OS_F32..OS_F128,OS_F32..OS_F128] of tasmop = (
  934. (A_MOVSS,A_CVTSS2SD,A_NONE,A_NONE,A_NONE),
  935. (A_CVTSD2SS,A_MOVSD,A_NONE,A_NONE,A_NONE),
  936. (A_NONE,A_NONE,A_NONE,A_NONE,A_NONE),
  937. (A_NONE,A_NONE,A_NONE,A_MOVQ,A_NONE),
  938. (A_NONE,A_NONE,A_NONE,A_NONE,A_NONE));
  939. begin
  940. result:=convertop[fromsize,tosize];
  941. if result=A_NONE then
  942. internalerror(200312205);
  943. end;
  944. procedure tcgx86.a_loadmm_reg_reg(list: TAsmList; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle);
  945. var
  946. instr : taicpu;
  947. begin
  948. if shuffle=nil then
  949. begin
  950. if fromsize=tosize then
  951. { needs correct size in case of spilling }
  952. case fromsize of
  953. OS_F32:
  954. instr:=taicpu.op_reg_reg(A_MOVAPS,S_NO,reg1,reg2);
  955. OS_F64:
  956. instr:=taicpu.op_reg_reg(A_MOVAPD,S_NO,reg1,reg2);
  957. else
  958. internalerror(2006091201);
  959. end
  960. else
  961. internalerror(200312202);
  962. end
  963. else if shufflescalar(shuffle) then
  964. instr:=taicpu.op_reg_reg(get_scalar_mm_op(fromsize,tosize),S_NO,reg1,reg2)
  965. else
  966. internalerror(200312201);
  967. case get_scalar_mm_op(fromsize,tosize) of
  968. A_MOVSS,
  969. A_MOVSD,
  970. A_MOVQ:
  971. add_move_instruction(instr);
  972. end;
  973. list.concat(instr);
  974. end;
  975. procedure tcgx86.a_loadmm_ref_reg(list: TAsmList; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  976. var
  977. tmpref : treference;
  978. begin
  979. tmpref:=ref;
  980. make_simple_ref(list,tmpref);
  981. if shuffle=nil then
  982. begin
  983. if fromsize=OS_M64 then
  984. list.concat(taicpu.op_ref_reg(A_MOVQ,S_NO,tmpref,reg))
  985. else
  986. {$ifdef x86_64}
  987. { x86-64 has always properly aligned data }
  988. list.concat(taicpu.op_ref_reg(A_MOVDQA,S_NO,tmpref,reg));
  989. {$else x86_64}
  990. list.concat(taicpu.op_ref_reg(A_MOVDQU,S_NO,tmpref,reg));
  991. {$endif x86_64}
  992. end
  993. else if shufflescalar(shuffle) then
  994. list.concat(taicpu.op_ref_reg(get_scalar_mm_op(fromsize,tosize),S_NO,tmpref,reg))
  995. else
  996. internalerror(200312252);
  997. end;
  998. procedure tcgx86.a_loadmm_reg_ref(list: TAsmList; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle);
  999. var
  1000. hreg : tregister;
  1001. tmpref : treference;
  1002. begin
  1003. tmpref:=ref;
  1004. make_simple_ref(list,tmpref);
  1005. if shuffle=nil then
  1006. begin
  1007. if fromsize=OS_M64 then
  1008. list.concat(taicpu.op_reg_ref(A_MOVQ,S_NO,reg,tmpref))
  1009. else
  1010. {$ifdef x86_64}
  1011. { x86-64 has always properly aligned data }
  1012. list.concat(taicpu.op_reg_ref(A_MOVDQA,S_NO,reg,tmpref))
  1013. {$else x86_64}
  1014. list.concat(taicpu.op_reg_ref(A_MOVDQU,S_NO,reg,tmpref))
  1015. {$endif x86_64}
  1016. end
  1017. else if shufflescalar(shuffle) then
  1018. begin
  1019. if tosize<>fromsize then
  1020. begin
  1021. hreg:=getmmregister(list,tosize);
  1022. list.concat(taicpu.op_reg_reg(get_scalar_mm_op(fromsize,tosize),S_NO,reg,hreg));
  1023. list.concat(taicpu.op_reg_ref(get_scalar_mm_op(tosize,tosize),S_NO,hreg,tmpref));
  1024. end
  1025. else
  1026. list.concat(taicpu.op_reg_ref(get_scalar_mm_op(fromsize,tosize),S_NO,reg,tmpref));
  1027. end
  1028. else
  1029. internalerror(200312252);
  1030. end;
  1031. procedure tcgx86.a_opmm_ref_reg(list: TAsmList; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  1032. var
  1033. l : tlocation;
  1034. begin
  1035. l.loc:=LOC_REFERENCE;
  1036. l.reference:=ref;
  1037. l.size:=size;
  1038. opmm_loc_reg(list,op,size,l,reg,shuffle);
  1039. end;
  1040. procedure tcgx86.a_opmm_reg_reg(list: TAsmList; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);
  1041. var
  1042. l : tlocation;
  1043. begin
  1044. l.loc:=LOC_MMREGISTER;
  1045. l.register:=src;
  1046. l.size:=size;
  1047. opmm_loc_reg(list,op,size,l,dst,shuffle);
  1048. end;
  1049. procedure tcgx86.opmm_loc_reg(list: TAsmList; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  1050. const
  1051. opmm2asmop : array[0..1,OS_F32..OS_F64,topcg] of tasmop = (
  1052. ( { scalar }
  1053. ( { OS_F32 }
  1054. A_NOP,A_NOP,A_ADDSS,A_NOP,A_DIVSS,A_NOP,A_NOP,A_MULSS,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_SUBSS,A_NOP,A_NOP,A_NOP
  1055. ),
  1056. ( { OS_F64 }
  1057. A_NOP,A_NOP,A_ADDSD,A_NOP,A_DIVSD,A_NOP,A_NOP,A_MULSD,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_SUBSD,A_NOP,A_NOP,A_NOP
  1058. )
  1059. ),
  1060. ( { vectorized/packed }
  1061. { because the logical packed single instructions have shorter op codes, we use always
  1062. these
  1063. }
  1064. ( { OS_F32 }
  1065. A_NOP,A_NOP,A_ADDPS,A_NOP,A_DIVPS,A_NOP,A_NOP,A_MULPS,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_SUBPS,A_XORPS,A_NOP,A_NOP
  1066. ),
  1067. ( { OS_F64 }
  1068. A_NOP,A_NOP,A_ADDPD,A_NOP,A_DIVPD,A_NOP,A_NOP,A_MULPD,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_SUBPD,A_XORPD,A_NOP,A_NOP
  1069. )
  1070. )
  1071. );
  1072. var
  1073. resultreg : tregister;
  1074. asmop : tasmop;
  1075. begin
  1076. { this is an internally used procedure so the parameters have
  1077. some constrains
  1078. }
  1079. if loc.size<>size then
  1080. internalerror(200312213);
  1081. resultreg:=dst;
  1082. { deshuffle }
  1083. //!!!
  1084. if (shuffle<>nil) and not(shufflescalar(shuffle)) then
  1085. begin
  1086. end
  1087. else if (shuffle=nil) then
  1088. asmop:=opmm2asmop[1,size,op]
  1089. else if shufflescalar(shuffle) then
  1090. begin
  1091. asmop:=opmm2asmop[0,size,op];
  1092. { no scalar operation available? }
  1093. if asmop=A_NOP then
  1094. begin
  1095. { do vectorized and shuffle finally }
  1096. //!!!
  1097. end;
  1098. end
  1099. else
  1100. internalerror(200312211);
  1101. if asmop=A_NOP then
  1102. internalerror(200312216);
  1103. case loc.loc of
  1104. LOC_CREFERENCE,LOC_REFERENCE:
  1105. begin
  1106. make_simple_ref(current_asmdata.CurrAsmList,loc.reference);
  1107. list.concat(taicpu.op_ref_reg(asmop,S_NO,loc.reference,resultreg));
  1108. end;
  1109. LOC_CMMREGISTER,LOC_MMREGISTER:
  1110. list.concat(taicpu.op_reg_reg(asmop,S_NO,loc.register,resultreg));
  1111. else
  1112. internalerror(200312214);
  1113. end;
  1114. { shuffle }
  1115. if resultreg<>dst then
  1116. begin
  1117. internalerror(200312212);
  1118. end;
  1119. end;
  1120. procedure tcgx86.a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister);
  1121. var
  1122. opcode : tasmop;
  1123. power : longint;
  1124. {$ifdef x86_64}
  1125. tmpreg : tregister;
  1126. {$endif x86_64}
  1127. begin
  1128. optimize_op_const(op, a);
  1129. {$ifdef x86_64}
  1130. { x86_64 only supports signed 32 bits constants directly }
  1131. if not(op in [OP_NONE,OP_MOVE]) and
  1132. (size in [OS_S64,OS_64]) and
  1133. ((a<low(longint)) or (a>high(longint))) then
  1134. begin
  1135. tmpreg:=getintregister(list,size);
  1136. a_load_const_reg(list,size,a,tmpreg);
  1137. a_op_reg_reg(list,op,size,tmpreg,reg);
  1138. exit;
  1139. end;
  1140. {$endif x86_64}
  1141. check_register_size(size,reg);
  1142. case op of
  1143. OP_NONE :
  1144. begin
  1145. { Opcode is optimized away }
  1146. end;
  1147. OP_MOVE :
  1148. begin
  1149. { Optimized, replaced with a simple load }
  1150. a_load_const_reg(list,size,a,reg);
  1151. end;
  1152. OP_DIV, OP_IDIV:
  1153. begin
  1154. if ispowerof2(int64(a),power) then
  1155. begin
  1156. case op of
  1157. OP_DIV:
  1158. opcode := A_SHR;
  1159. OP_IDIV:
  1160. opcode := A_SAR;
  1161. end;
  1162. list.concat(taicpu.op_const_reg(opcode,TCgSize2OpSize[size],power,reg));
  1163. exit;
  1164. end;
  1165. { the rest should be handled specifically in the code }
  1166. { generator because of the silly register usage restraints }
  1167. internalerror(200109224);
  1168. end;
  1169. OP_MUL,OP_IMUL:
  1170. begin
  1171. if not(cs_check_overflow in current_settings.localswitches) and
  1172. ispowerof2(int64(a),power) then
  1173. begin
  1174. list.concat(taicpu.op_const_reg(A_SHL,TCgSize2OpSize[size],power,reg));
  1175. exit;
  1176. end;
  1177. if op = OP_IMUL then
  1178. list.concat(taicpu.op_const_reg(A_IMUL,TCgSize2OpSize[size],a,reg))
  1179. else
  1180. { OP_MUL should be handled specifically in the code }
  1181. { generator because of the silly register usage restraints }
  1182. internalerror(200109225);
  1183. end;
  1184. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  1185. if not(cs_check_overflow in current_settings.localswitches) and
  1186. (a = 1) and
  1187. (op in [OP_ADD,OP_SUB]) then
  1188. if op = OP_ADD then
  1189. list.concat(taicpu.op_reg(A_INC,TCgSize2OpSize[size],reg))
  1190. else
  1191. list.concat(taicpu.op_reg(A_DEC,TCgSize2OpSize[size],reg))
  1192. else if (a = 0) then
  1193. if (op <> OP_AND) then
  1194. exit
  1195. else
  1196. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],0,reg))
  1197. else if (aword(a) = high(aword)) and
  1198. (op in [OP_AND,OP_OR,OP_XOR]) then
  1199. begin
  1200. case op of
  1201. OP_AND:
  1202. exit;
  1203. OP_OR:
  1204. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],aint(high(aword)),reg));
  1205. OP_XOR:
  1206. list.concat(taicpu.op_reg(A_NOT,TCgSize2OpSize[size],reg));
  1207. end
  1208. end
  1209. else
  1210. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a,reg));
  1211. OP_SHL,OP_SHR,OP_SAR,OP_ROL,OP_ROR:
  1212. begin
  1213. {$ifdef x86_64}
  1214. if (a and 63) <> 0 Then
  1215. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 63,reg));
  1216. if (a shr 6) <> 0 Then
  1217. internalerror(200609073);
  1218. {$else x86_64}
  1219. if (a and 31) <> 0 Then
  1220. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,reg));
  1221. if (a shr 5) <> 0 Then
  1222. internalerror(200609071);
  1223. {$endif x86_64}
  1224. end
  1225. else internalerror(200609072);
  1226. end;
  1227. end;
  1228. procedure tcgx86.a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
  1229. var
  1230. opcode: tasmop;
  1231. power: longint;
  1232. {$ifdef x86_64}
  1233. tmpreg : tregister;
  1234. {$endif x86_64}
  1235. tmpref : treference;
  1236. begin
  1237. optimize_op_const(op, a);
  1238. tmpref:=ref;
  1239. make_simple_ref(list,tmpref);
  1240. {$ifdef x86_64}
  1241. { x86_64 only supports signed 32 bits constants directly }
  1242. if not(op in [OP_NONE,OP_MOVE]) and
  1243. (size in [OS_S64,OS_64]) and
  1244. ((a<low(longint)) or (a>high(longint))) then
  1245. begin
  1246. tmpreg:=getintregister(list,size);
  1247. a_load_const_reg(list,size,a,tmpreg);
  1248. a_op_reg_ref(list,op,size,tmpreg,tmpref);
  1249. exit;
  1250. end;
  1251. {$endif x86_64}
  1252. Case Op of
  1253. OP_NONE :
  1254. begin
  1255. { Opcode is optimized away }
  1256. end;
  1257. OP_MOVE :
  1258. begin
  1259. { Optimized, replaced with a simple load }
  1260. a_load_const_ref(list,size,a,ref);
  1261. end;
  1262. OP_DIV, OP_IDIV:
  1263. Begin
  1264. if ispowerof2(int64(a),power) then
  1265. begin
  1266. case op of
  1267. OP_DIV:
  1268. opcode := A_SHR;
  1269. OP_IDIV:
  1270. opcode := A_SAR;
  1271. end;
  1272. list.concat(taicpu.op_const_ref(opcode,
  1273. TCgSize2OpSize[size],power,tmpref));
  1274. exit;
  1275. end;
  1276. { the rest should be handled specifically in the code }
  1277. { generator because of the silly register usage restraints }
  1278. internalerror(200109231);
  1279. End;
  1280. OP_MUL,OP_IMUL:
  1281. begin
  1282. if not(cs_check_overflow in current_settings.localswitches) and
  1283. ispowerof2(int64(a),power) then
  1284. begin
  1285. list.concat(taicpu.op_const_ref(A_SHL,TCgSize2OpSize[size],
  1286. power,tmpref));
  1287. exit;
  1288. end;
  1289. { can't multiply a memory location directly with a constant }
  1290. if op = OP_IMUL then
  1291. inherited a_op_const_ref(list,op,size,a,tmpref)
  1292. else
  1293. { OP_MUL should be handled specifically in the code }
  1294. { generator because of the silly register usage restraints }
  1295. internalerror(200109232);
  1296. end;
  1297. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  1298. if not(cs_check_overflow in current_settings.localswitches) and
  1299. (a = 1) and
  1300. (op in [OP_ADD,OP_SUB]) then
  1301. if op = OP_ADD then
  1302. list.concat(taicpu.op_ref(A_INC,TCgSize2OpSize[size],tmpref))
  1303. else
  1304. list.concat(taicpu.op_ref(A_DEC,TCgSize2OpSize[size],tmpref))
  1305. else if (a = 0) then
  1306. if (op <> OP_AND) then
  1307. exit
  1308. else
  1309. a_load_const_ref(list,size,0,tmpref)
  1310. else if (aword(a) = high(aword)) and
  1311. (op in [OP_AND,OP_OR,OP_XOR]) then
  1312. begin
  1313. case op of
  1314. OP_AND:
  1315. exit;
  1316. OP_OR:
  1317. list.concat(taicpu.op_const_ref(A_MOV,TCgSize2OpSize[size],aint(high(aword)),tmpref));
  1318. OP_XOR:
  1319. list.concat(taicpu.op_ref(A_NOT,TCgSize2OpSize[size],tmpref));
  1320. end
  1321. end
  1322. else
  1323. list.concat(taicpu.op_const_ref(TOpCG2AsmOp[op],
  1324. TCgSize2OpSize[size],a,tmpref));
  1325. OP_SHL,OP_SHR,OP_SAR,OP_ROL,OP_ROR:
  1326. begin
  1327. if (a and 31) <> 0 then
  1328. list.concat(taicpu.op_const_ref(
  1329. TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,tmpref));
  1330. if (a shr 5) <> 0 Then
  1331. internalerror(68991);
  1332. end
  1333. else internalerror(68992);
  1334. end;
  1335. end;
  1336. procedure tcgx86.a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  1337. var
  1338. dstsize: topsize;
  1339. instr:Taicpu;
  1340. begin
  1341. check_register_size(size,src);
  1342. check_register_size(size,dst);
  1343. dstsize := tcgsize2opsize[size];
  1344. case op of
  1345. OP_NEG,OP_NOT:
  1346. begin
  1347. if src<>dst then
  1348. a_load_reg_reg(list,size,size,src,dst);
  1349. list.concat(taicpu.op_reg(TOpCG2AsmOp[op],dstsize,dst));
  1350. end;
  1351. OP_MUL,OP_DIV,OP_IDIV:
  1352. { special stuff, needs separate handling inside code }
  1353. { generator }
  1354. internalerror(200109233);
  1355. OP_SHR,OP_SHL,OP_SAR,OP_ROL,OP_ROR:
  1356. begin
  1357. { Use ecx to load the value, that allows better coalescing }
  1358. getcpuregister(list,NR_ECX);
  1359. a_load_reg_reg(list,size,OS_32,src,NR_ECX);
  1360. list.concat(taicpu.op_reg_reg(Topcg2asmop[op],tcgsize2opsize[size],NR_CL,dst));
  1361. ungetcpuregister(list,NR_ECX);
  1362. end;
  1363. else
  1364. begin
  1365. if reg2opsize(src) <> dstsize then
  1366. internalerror(200109226);
  1367. instr:=taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,src,dst);
  1368. list.concat(instr);
  1369. end;
  1370. end;
  1371. end;
  1372. procedure tcgx86.a_op_ref_reg(list : TAsmList; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  1373. var
  1374. tmpref : treference;
  1375. begin
  1376. tmpref:=ref;
  1377. make_simple_ref(list,tmpref);
  1378. check_register_size(size,reg);
  1379. case op of
  1380. OP_NEG,OP_NOT,OP_IMUL:
  1381. begin
  1382. inherited a_op_ref_reg(list,op,size,tmpref,reg);
  1383. end;
  1384. OP_MUL,OP_DIV,OP_IDIV:
  1385. { special stuff, needs separate handling inside code }
  1386. { generator }
  1387. internalerror(200109239);
  1388. else
  1389. begin
  1390. reg := makeregsize(list,reg,size);
  1391. list.concat(taicpu.op_ref_reg(TOpCG2AsmOp[op],tcgsize2opsize[size],tmpref,reg));
  1392. end;
  1393. end;
  1394. end;
  1395. procedure tcgx86.a_op_reg_ref(list : TAsmList; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  1396. var
  1397. tmpref : treference;
  1398. begin
  1399. tmpref:=ref;
  1400. make_simple_ref(list,tmpref);
  1401. check_register_size(size,reg);
  1402. case op of
  1403. OP_NEG,OP_NOT:
  1404. begin
  1405. if reg<>NR_NO then
  1406. internalerror(200109237);
  1407. list.concat(taicpu.op_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],tmpref));
  1408. end;
  1409. OP_IMUL:
  1410. begin
  1411. { this one needs a load/imul/store, which is the default }
  1412. inherited a_op_ref_reg(list,op,size,tmpref,reg);
  1413. end;
  1414. OP_MUL,OP_DIV,OP_IDIV:
  1415. { special stuff, needs separate handling inside code }
  1416. { generator }
  1417. internalerror(200109238);
  1418. else
  1419. begin
  1420. list.concat(taicpu.op_reg_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],reg,tmpref));
  1421. end;
  1422. end;
  1423. end;
  1424. {*************** compare instructructions ****************}
  1425. procedure tcgx86.a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  1426. l : tasmlabel);
  1427. {$ifdef x86_64}
  1428. var
  1429. tmpreg : tregister;
  1430. {$endif x86_64}
  1431. begin
  1432. {$ifdef x86_64}
  1433. { x86_64 only supports signed 32 bits constants directly }
  1434. if (size in [OS_S64,OS_64]) and
  1435. ((a<low(longint)) or (a>high(longint))) then
  1436. begin
  1437. tmpreg:=getintregister(list,size);
  1438. a_load_const_reg(list,size,a,tmpreg);
  1439. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1440. exit;
  1441. end;
  1442. {$endif x86_64}
  1443. if (a = 0) then
  1444. list.concat(taicpu.op_reg_reg(A_TEST,tcgsize2opsize[size],reg,reg))
  1445. else
  1446. list.concat(taicpu.op_const_reg(A_CMP,tcgsize2opsize[size],a,reg));
  1447. a_jmp_cond(list,cmp_op,l);
  1448. end;
  1449. procedure tcgx86.a_cmp_const_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  1450. l : tasmlabel);
  1451. var
  1452. {$ifdef x86_64}
  1453. tmpreg : tregister;
  1454. {$endif x86_64}
  1455. tmpref : treference;
  1456. begin
  1457. tmpref:=ref;
  1458. make_simple_ref(list,tmpref);
  1459. {$ifdef x86_64}
  1460. { x86_64 only supports signed 32 bits constants directly }
  1461. if (size in [OS_S64,OS_64]) and
  1462. ((a<low(longint)) or (a>high(longint))) then
  1463. begin
  1464. tmpreg:=getintregister(list,size);
  1465. a_load_const_reg(list,size,a,tmpreg);
  1466. a_cmp_reg_ref_label(list,size,cmp_op,tmpreg,tmpref,l);
  1467. exit;
  1468. end;
  1469. {$endif x86_64}
  1470. list.concat(taicpu.op_const_ref(A_CMP,TCgSize2OpSize[size],a,tmpref));
  1471. a_jmp_cond(list,cmp_op,l);
  1472. end;
  1473. procedure tcgx86.a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;
  1474. reg1,reg2 : tregister;l : tasmlabel);
  1475. begin
  1476. check_register_size(size,reg1);
  1477. check_register_size(size,reg2);
  1478. list.concat(taicpu.op_reg_reg(A_CMP,TCgSize2OpSize[size],reg1,reg2));
  1479. a_jmp_cond(list,cmp_op,l);
  1480. end;
  1481. procedure tcgx86.a_cmp_ref_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister;l : tasmlabel);
  1482. var
  1483. tmpref : treference;
  1484. begin
  1485. tmpref:=ref;
  1486. make_simple_ref(list,tmpref);
  1487. check_register_size(size,reg);
  1488. list.concat(taicpu.op_ref_reg(A_CMP,TCgSize2OpSize[size],tmpref,reg));
  1489. a_jmp_cond(list,cmp_op,l);
  1490. end;
  1491. procedure tcgx86.a_cmp_reg_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg : tregister;const ref: treference; l : tasmlabel);
  1492. var
  1493. tmpref : treference;
  1494. begin
  1495. tmpref:=ref;
  1496. make_simple_ref(list,tmpref);
  1497. check_register_size(size,reg);
  1498. list.concat(taicpu.op_reg_ref(A_CMP,TCgSize2OpSize[size],reg,tmpref));
  1499. a_jmp_cond(list,cmp_op,l);
  1500. end;
  1501. procedure tcgx86.a_jmp_cond(list : TAsmList;cond : TOpCmp;l: tasmlabel);
  1502. var
  1503. ai : taicpu;
  1504. begin
  1505. if cond=OC_None then
  1506. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  1507. else
  1508. begin
  1509. ai:=Taicpu.Op_sym(A_Jcc,S_NO,l);
  1510. ai.SetCondition(TOpCmp2AsmCond[cond]);
  1511. end;
  1512. ai.is_jmp:=true;
  1513. list.concat(ai);
  1514. end;
  1515. procedure tcgx86.a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel);
  1516. var
  1517. ai : taicpu;
  1518. begin
  1519. ai := Taicpu.op_sym(A_Jcc,S_NO,l);
  1520. ai.SetCondition(flags_to_cond(f));
  1521. ai.is_jmp := true;
  1522. list.concat(ai);
  1523. end;
  1524. procedure tcgx86.g_flags2reg(list: TAsmList; size: TCgSize; const f: tresflags; reg: TRegister);
  1525. var
  1526. ai : taicpu;
  1527. hreg : tregister;
  1528. begin
  1529. hreg:=makeregsize(list,reg,OS_8);
  1530. ai:=Taicpu.op_reg(A_SETcc,S_B,hreg);
  1531. ai.setcondition(flags_to_cond(f));
  1532. list.concat(ai);
  1533. if (reg<>hreg) then
  1534. a_load_reg_reg(list,OS_8,size,hreg,reg);
  1535. end;
  1536. procedure tcgx86.g_flags2ref(list: TAsmList; size: TCgSize; const f: tresflags; const ref: TReference);
  1537. var
  1538. ai : taicpu;
  1539. tmpref : treference;
  1540. begin
  1541. tmpref:=ref;
  1542. make_simple_ref(list,tmpref);
  1543. if not(size in [OS_8,OS_S8]) then
  1544. a_load_const_ref(list,size,0,tmpref);
  1545. ai:=Taicpu.op_ref(A_SETcc,S_B,tmpref);
  1546. ai.setcondition(flags_to_cond(f));
  1547. list.concat(ai);
  1548. end;
  1549. { ************* concatcopy ************ }
  1550. procedure Tcgx86.g_concatcopy(list:TAsmList;const source,dest:Treference;len:aint);
  1551. const
  1552. {$ifdef cpu64bitalu}
  1553. REGCX=NR_RCX;
  1554. REGSI=NR_RSI;
  1555. REGDI=NR_RDI;
  1556. {$else cpu64bitalu}
  1557. REGCX=NR_ECX;
  1558. REGSI=NR_ESI;
  1559. REGDI=NR_EDI;
  1560. {$endif cpu64bitalu}
  1561. type copymode=(copy_move,copy_mmx,copy_string);
  1562. var srcref,dstref:Treference;
  1563. r,r0,r1,r2,r3:Tregister;
  1564. helpsize:aint;
  1565. copysize:byte;
  1566. cgsize:Tcgsize;
  1567. cm:copymode;
  1568. begin
  1569. cm:=copy_move;
  1570. helpsize:=3*sizeof(aword);
  1571. if cs_opt_size in current_settings.optimizerswitches then
  1572. helpsize:=2*sizeof(aword);
  1573. if (cs_mmx in current_settings.localswitches) and
  1574. not(pi_uses_fpu in current_procinfo.flags) and
  1575. ((len=8) or (len=16) or (len=24) or (len=32)) then
  1576. cm:=copy_mmx;
  1577. if (len>helpsize) then
  1578. cm:=copy_string;
  1579. if (cs_opt_size in current_settings.optimizerswitches) and
  1580. not((len<=16) and (cm=copy_mmx)) then
  1581. cm:=copy_string;
  1582. if (source.segment<>NR_NO) or
  1583. (dest.segment<>NR_NO) then
  1584. cm:=copy_string;
  1585. case cm of
  1586. copy_move:
  1587. begin
  1588. dstref:=dest;
  1589. srcref:=source;
  1590. copysize:=sizeof(aint);
  1591. cgsize:=int_cgsize(copysize);
  1592. while len<>0 do
  1593. begin
  1594. if len<2 then
  1595. begin
  1596. copysize:=1;
  1597. cgsize:=OS_8;
  1598. end
  1599. else if len<4 then
  1600. begin
  1601. copysize:=2;
  1602. cgsize:=OS_16;
  1603. end
  1604. else if len<8 then
  1605. begin
  1606. copysize:=4;
  1607. cgsize:=OS_32;
  1608. end
  1609. {$ifdef cpu64bitalu}
  1610. else if len<16 then
  1611. begin
  1612. copysize:=8;
  1613. cgsize:=OS_64;
  1614. end
  1615. {$endif}
  1616. ;
  1617. dec(len,copysize);
  1618. r:=getintregister(list,cgsize);
  1619. a_load_ref_reg(list,cgsize,cgsize,srcref,r);
  1620. a_load_reg_ref(list,cgsize,cgsize,r,dstref);
  1621. inc(srcref.offset,copysize);
  1622. inc(dstref.offset,copysize);
  1623. end;
  1624. end;
  1625. copy_mmx:
  1626. begin
  1627. dstref:=dest;
  1628. srcref:=source;
  1629. r0:=getmmxregister(list);
  1630. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r0,nil);
  1631. if len>=16 then
  1632. begin
  1633. inc(srcref.offset,8);
  1634. r1:=getmmxregister(list);
  1635. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r1,nil);
  1636. end;
  1637. if len>=24 then
  1638. begin
  1639. inc(srcref.offset,8);
  1640. r2:=getmmxregister(list);
  1641. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r2,nil);
  1642. end;
  1643. if len>=32 then
  1644. begin
  1645. inc(srcref.offset,8);
  1646. r3:=getmmxregister(list);
  1647. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r3,nil);
  1648. end;
  1649. a_loadmm_reg_ref(list,OS_M64,OS_M64,r0,dstref,nil);
  1650. if len>=16 then
  1651. begin
  1652. inc(dstref.offset,8);
  1653. a_loadmm_reg_ref(list,OS_M64,OS_M64,r1,dstref,nil);
  1654. end;
  1655. if len>=24 then
  1656. begin
  1657. inc(dstref.offset,8);
  1658. a_loadmm_reg_ref(list,OS_M64,OS_M64,r2,dstref,nil);
  1659. end;
  1660. if len>=32 then
  1661. begin
  1662. inc(dstref.offset,8);
  1663. a_loadmm_reg_ref(list,OS_M64,OS_M64,r3,dstref,nil);
  1664. end;
  1665. end
  1666. else {copy_string, should be a good fallback in case of unhandled}
  1667. begin
  1668. getcpuregister(list,REGDI);
  1669. if (dest.segment=NR_NO) then
  1670. a_loadaddr_ref_reg(list,dest,REGDI)
  1671. else
  1672. begin
  1673. dstref:=dest;
  1674. dstref.segment:=NR_NO;
  1675. a_loadaddr_ref_reg(list,dstref,REGDI);
  1676. list.concat(taicpu.op_reg(A_PUSH,S_L,NR_ES));
  1677. list.concat(taicpu.op_reg(A_PUSH,S_L,dest.segment));
  1678. list.concat(taicpu.op_reg(A_POP,S_L,NR_ES));
  1679. end;
  1680. getcpuregister(list,REGSI);
  1681. if (source.segment=NR_NO) then
  1682. a_loadaddr_ref_reg(list,source,REGSI)
  1683. else
  1684. begin
  1685. srcref:=source;
  1686. srcref.segment:=NR_NO;
  1687. a_loadaddr_ref_reg(list,srcref,REGSI);
  1688. list.concat(taicpu.op_reg(A_PUSH,S_L,NR_DS));
  1689. list.concat(taicpu.op_reg(A_PUSH,S_L,source.segment));
  1690. list.concat(taicpu.op_reg(A_POP,S_L,NR_DS));
  1691. end;
  1692. getcpuregister(list,REGCX);
  1693. {$ifdef i386}
  1694. list.concat(Taicpu.op_none(A_CLD,S_NO));
  1695. {$endif i386}
  1696. if (cs_opt_size in current_settings.optimizerswitches) and
  1697. (len>sizeof(aint)+(sizeof(aint) div 2)) then
  1698. begin
  1699. a_load_const_reg(list,OS_INT,len,REGCX);
  1700. list.concat(Taicpu.op_none(A_REP,S_NO));
  1701. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1702. end
  1703. else
  1704. begin
  1705. helpsize:=len div sizeof(aint);
  1706. len:=len mod sizeof(aint);
  1707. if helpsize>1 then
  1708. begin
  1709. a_load_const_reg(list,OS_INT,helpsize,REGCX);
  1710. list.concat(Taicpu.op_none(A_REP,S_NO));
  1711. end;
  1712. if helpsize>0 then
  1713. begin
  1714. {$ifdef cpu64bitalu}
  1715. list.concat(Taicpu.op_none(A_MOVSQ,S_NO))
  1716. {$else}
  1717. list.concat(Taicpu.op_none(A_MOVSD,S_NO));
  1718. {$endif cpu64bitalu}
  1719. end;
  1720. if len>=4 then
  1721. begin
  1722. dec(len,4);
  1723. list.concat(Taicpu.op_none(A_MOVSD,S_NO));
  1724. end;
  1725. if len>=2 then
  1726. begin
  1727. dec(len,2);
  1728. list.concat(Taicpu.op_none(A_MOVSW,S_NO));
  1729. end;
  1730. if len=1 then
  1731. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1732. end;
  1733. ungetcpuregister(list,REGCX);
  1734. ungetcpuregister(list,REGSI);
  1735. ungetcpuregister(list,REGDI);
  1736. if (source.segment<>NR_NO) then
  1737. list.concat(taicpu.op_reg(A_POP,S_L,NR_DS));
  1738. if (dest.segment<>NR_NO) then
  1739. list.concat(taicpu.op_reg(A_POP,S_L,NR_ES));
  1740. end;
  1741. end;
  1742. end;
  1743. {****************************************************************************
  1744. Entry/Exit Code Helpers
  1745. ****************************************************************************}
  1746. procedure tcgx86.g_profilecode(list : TAsmList);
  1747. var
  1748. pl : tasmlabel;
  1749. mcountprefix : String[4];
  1750. begin
  1751. case target_info.system of
  1752. {$ifndef NOTARGETWIN}
  1753. system_i386_win32,
  1754. {$endif}
  1755. system_i386_freebsd,
  1756. system_i386_netbsd,
  1757. // system_i386_openbsd,
  1758. system_i386_wdosx :
  1759. begin
  1760. Case target_info.system Of
  1761. system_i386_freebsd : mcountprefix:='.';
  1762. system_i386_netbsd : mcountprefix:='__';
  1763. // system_i386_openbsd : mcountprefix:='.';
  1764. else
  1765. mcountPrefix:='';
  1766. end;
  1767. current_asmdata.getaddrlabel(pl);
  1768. new_section(list,sec_data,lower(current_procinfo.procdef.mangledname),sizeof(pint));
  1769. list.concat(Tai_label.Create(pl));
  1770. list.concat(Tai_const.Create_32bit(0));
  1771. new_section(list,sec_code,lower(current_procinfo.procdef.mangledname),0);
  1772. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1773. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,pl,0,NR_EDX));
  1774. a_call_name(list,target_info.Cprefix+mcountprefix+'mcount',false);
  1775. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EDX));
  1776. end;
  1777. system_i386_linux:
  1778. a_call_name(list,target_info.Cprefix+'mcount',false);
  1779. system_i386_go32v2,system_i386_watcom:
  1780. begin
  1781. a_call_name(list,'MCOUNT',false);
  1782. end;
  1783. system_x86_64_linux,
  1784. system_x86_64_darwin:
  1785. begin
  1786. a_call_name(list,'mcount',false);
  1787. end;
  1788. end;
  1789. end;
  1790. procedure tcgx86.g_stackpointer_alloc(list : TAsmList;localsize : longint);
  1791. {$ifdef x86}
  1792. {$ifndef NOTARGETWIN}
  1793. var
  1794. href : treference;
  1795. i : integer;
  1796. again : tasmlabel;
  1797. {$endif NOTARGETWIN}
  1798. {$endif x86}
  1799. begin
  1800. if localsize>0 then
  1801. begin
  1802. {$ifdef i386}
  1803. {$ifndef NOTARGETWIN}
  1804. { windows guards only a few pages for stack growing,
  1805. so we have to access every page first }
  1806. if (target_info.system in [system_i386_win32,system_i386_wince]) and
  1807. (localsize>=winstackpagesize) then
  1808. begin
  1809. if localsize div winstackpagesize<=5 then
  1810. begin
  1811. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize-4,NR_ESP));
  1812. for i:=1 to localsize div winstackpagesize do
  1813. begin
  1814. reference_reset_base(href,NR_ESP,localsize-i*winstackpagesize,4);
  1815. list.concat(Taicpu.op_reg_ref(A_MOV,S_L,NR_EAX,href));
  1816. end;
  1817. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1818. end
  1819. else
  1820. begin
  1821. current_asmdata.getjumplabel(again);
  1822. getcpuregister(list,NR_EDI);
  1823. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EDI));
  1824. list.concat(Taicpu.op_const_reg(A_MOV,S_L,localsize div winstackpagesize,NR_EDI));
  1825. a_label(list,again);
  1826. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,NR_ESP));
  1827. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1828. list.concat(Taicpu.op_reg(A_DEC,S_L,NR_EDI));
  1829. a_jmp_cond(list,OC_NE,again);
  1830. list.concat(Taicpu.op_const_reg(A_SUB,S_L,localsize mod winstackpagesize - 4,NR_ESP));
  1831. reference_reset_base(href,NR_ESP,localsize-4,4);
  1832. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,href,NR_EDI));
  1833. ungetcpuregister(list,NR_EDI);
  1834. end
  1835. end
  1836. else
  1837. {$endif NOTARGETWIN}
  1838. {$endif i386}
  1839. {$ifdef x86_64}
  1840. {$ifndef NOTARGETWIN}
  1841. { windows guards only a few pages for stack growing,
  1842. so we have to access every page first }
  1843. if (target_info.system=system_x86_64_win64) and
  1844. (localsize>=winstackpagesize) then
  1845. begin
  1846. if localsize div winstackpagesize<=5 then
  1847. begin
  1848. list.concat(Taicpu.Op_const_reg(A_SUB,S_Q,localsize,NR_RSP));
  1849. for i:=1 to localsize div winstackpagesize do
  1850. begin
  1851. reference_reset_base(href,NR_RSP,localsize-i*winstackpagesize+4,4);
  1852. list.concat(Taicpu.op_reg_ref(A_MOV,S_L,NR_EAX,href));
  1853. end;
  1854. reference_reset_base(href,NR_RSP,0,4);
  1855. list.concat(Taicpu.op_reg_ref(A_MOV,S_L,NR_EAX,href));
  1856. end
  1857. else
  1858. begin
  1859. current_asmdata.getjumplabel(again);
  1860. getcpuregister(list,NR_R10);
  1861. list.concat(Taicpu.op_const_reg(A_MOV,S_Q,localsize div winstackpagesize,NR_R10));
  1862. a_label(list,again);
  1863. list.concat(Taicpu.op_const_reg(A_SUB,S_Q,winstackpagesize,NR_RSP));
  1864. reference_reset_base(href,NR_RSP,0,4);
  1865. list.concat(Taicpu.op_reg_ref(A_MOV,S_L,NR_EAX,href));
  1866. list.concat(Taicpu.op_reg(A_DEC,S_Q,NR_R10));
  1867. a_jmp_cond(list,OC_NE,again);
  1868. list.concat(Taicpu.op_const_reg(A_SUB,S_Q,localsize mod winstackpagesize,NR_RSP));
  1869. ungetcpuregister(list,NR_R10);
  1870. end
  1871. end
  1872. else
  1873. {$endif NOTARGETWIN}
  1874. {$endif x86_64}
  1875. list.concat(Taicpu.Op_const_reg(A_SUB,tcgsize2opsize[OS_ADDR],localsize,NR_STACK_POINTER_REG));
  1876. end;
  1877. end;
  1878. procedure tcgx86.g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);
  1879. var
  1880. stackmisalignment: longint;
  1881. begin
  1882. {$ifdef i386}
  1883. { interrupt support for i386 }
  1884. if (po_interrupt in current_procinfo.procdef.procoptions) and
  1885. { this messes up stack alignment }
  1886. (target_info.system <> system_i386_darwin) then
  1887. begin
  1888. { .... also the segment registers }
  1889. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_GS));
  1890. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_FS));
  1891. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_ES));
  1892. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_DS));
  1893. { save the registers of an interrupt procedure }
  1894. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDI));
  1895. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ESI));
  1896. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1897. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ECX));
  1898. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EBX));
  1899. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EAX));
  1900. end;
  1901. {$endif i386}
  1902. { save old framepointer }
  1903. if not nostackframe then
  1904. begin
  1905. { return address }
  1906. stackmisalignment := sizeof(pint);
  1907. list.concat(tai_regalloc.alloc(current_procinfo.framepointer,nil));
  1908. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  1909. CGmessage(cg_d_stackframe_omited)
  1910. else
  1911. begin
  1912. { push <frame_pointer> }
  1913. inc(stackmisalignment,sizeof(pint));
  1914. include(rg[R_INTREGISTER].preserved_by_proc,RS_FRAME_POINTER_REG);
  1915. list.concat(Taicpu.op_reg(A_PUSH,tcgsize2opsize[OS_ADDR],NR_FRAME_POINTER_REG));
  1916. { Return address and FP are both on stack }
  1917. current_asmdata.asmcfi.cfa_def_cfa_offset(list,2*sizeof(pint));
  1918. current_asmdata.asmcfi.cfa_offset(list,NR_FRAME_POINTER_REG,-(2*sizeof(pint)));
  1919. list.concat(Taicpu.op_reg_reg(A_MOV,tcgsize2opsize[OS_ADDR],NR_STACK_POINTER_REG,NR_FRAME_POINTER_REG));
  1920. current_asmdata.asmcfi.cfa_def_cfa_register(list,NR_FRAME_POINTER_REG);
  1921. end;
  1922. { allocate stackframe space }
  1923. if (localsize<>0) or
  1924. ((target_info.system in [system_i386_darwin,system_x86_64_darwin,
  1925. system_x86_64_win64,system_x86_64_linux,system_x86_64_freebsd]) and
  1926. (stackmisalignment <> 0) and
  1927. ((pi_do_call in current_procinfo.flags) or
  1928. (po_assembler in current_procinfo.procdef.procoptions))) then
  1929. begin
  1930. if (target_info.system in [system_i386_darwin,system_x86_64_darwin,
  1931. system_x86_64_win64,system_x86_64_linux,system_x86_64_freebsd]) then
  1932. localsize := align(localsize+stackmisalignment,16)-stackmisalignment;
  1933. cg.g_stackpointer_alloc(list,localsize);
  1934. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  1935. current_asmdata.asmcfi.cfa_def_cfa_offset(list,localsize+sizeof(pint));
  1936. end;
  1937. end;
  1938. end;
  1939. { produces if necessary overflowcode }
  1940. procedure tcgx86.g_overflowcheck(list: TAsmList; const l:tlocation;def:tdef);
  1941. var
  1942. hl : tasmlabel;
  1943. ai : taicpu;
  1944. cond : TAsmCond;
  1945. begin
  1946. if not(cs_check_overflow in current_settings.localswitches) then
  1947. exit;
  1948. current_asmdata.getjumplabel(hl);
  1949. if not ((def.typ=pointerdef) or
  1950. ((def.typ=orddef) and
  1951. (torddef(def).ordtype in [u64bit,u16bit,u32bit,u8bit,uchar,pasbool]))) then
  1952. cond:=C_NO
  1953. else
  1954. cond:=C_NB;
  1955. ai:=Taicpu.Op_Sym(A_Jcc,S_NO,hl);
  1956. ai.SetCondition(cond);
  1957. ai.is_jmp:=true;
  1958. list.concat(ai);
  1959. a_call_name(list,'FPC_OVERFLOW',false);
  1960. a_label(list,hl);
  1961. end;
  1962. procedure tcgx86.g_external_wrapper(list: TAsmList; procdef: tprocdef; const externalname: string);
  1963. var
  1964. ref : treference;
  1965. sym : tasmsymbol;
  1966. begin
  1967. if (target_info.system=system_i386_darwin) then
  1968. begin
  1969. { a_jmp_name jumps to a stub which is always pic-safe on darwin }
  1970. inherited g_external_wrapper(list,procdef,externalname);
  1971. exit;
  1972. end;
  1973. sym:=current_asmdata.RefAsmSymbol(externalname);
  1974. reference_reset_symbol(ref,sym,0,sizeof(pint));
  1975. { create pic'ed? }
  1976. if (cs_create_pic in current_settings.moduleswitches) and
  1977. { darwin/x86_64's assembler doesn't want @PLT after call symbols }
  1978. (target_info.system<>system_x86_64_darwin) then
  1979. ref.refaddr:=addr_pic
  1980. else
  1981. ref.refaddr:=addr_full;
  1982. list.concat(taicpu.op_ref(A_JMP,S_NO,ref));
  1983. end;
  1984. end.