cgx86.pas 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the common parts of the code generator for the i386 and the x86-64.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. { This unit implements the common parts of the code generator for the i386 and the x86-64.
  19. }
  20. unit cgx86;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. globtype,
  25. cgbase,cgobj,
  26. aasmbase,aasmtai,aasmcpu,
  27. cpubase,cpuinfo,rgobj,rgx86,rgcpu,
  28. symconst,symtype;
  29. type
  30. tcgx86 = class(tcg)
  31. rgfpu : Trgx86fpu;
  32. procedure done_register_allocators;override;
  33. function getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;override;
  34. function getmmxregister(list:Taasmoutput):Tregister;
  35. procedure getexplicitregister(list:Taasmoutput;r:Tregister);override;
  36. procedure ungetregister(list:Taasmoutput;r:Tregister);override;
  37. procedure allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);override;
  38. procedure deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;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 : taasmoutput;const s : string);override;
  44. procedure a_call_reg(list : taasmoutput;reg : tregister);override;
  45. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister); override;
  46. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference); override;
  47. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  48. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); override;
  49. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference); override;
  50. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  51. size: tcgsize; a: aint; src, dst: tregister); override;
  52. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  53. size: tcgsize; src1, src2, dst: tregister); override;
  54. { move instructions }
  55. procedure a_load_const_reg(list : taasmoutput; tosize: tcgsize; a : aint;reg : tregister);override;
  56. procedure a_load_const_ref(list : taasmoutput; tosize: tcgsize; a : aint;const ref : treference);override;
  57. procedure a_load_reg_ref(list : taasmoutput;fromsize,tosize: tcgsize; reg : tregister;const ref : treference);override;
  58. procedure a_load_ref_reg(list : taasmoutput;fromsize,tosize: tcgsize;const ref : treference;reg : tregister);override;
  59. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize: tcgsize;reg1,reg2 : tregister);override;
  60. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  61. { fpu move instructions }
  62. procedure a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister); override;
  63. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  64. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  65. { vector register move instructions }
  66. procedure a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); override;
  67. procedure a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  68. procedure a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); override;
  69. procedure a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  70. procedure a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);override;
  71. { comparison operations }
  72. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  73. l : tasmlabel);override;
  74. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  75. l : tasmlabel);override;
  76. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  77. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister; l : tasmlabel); override;
  78. procedure a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); override;
  79. procedure a_jmp_name(list : taasmoutput;const s : string);override;
  80. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  81. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  82. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); override;
  83. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference); override;
  84. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aint; delsource,loadref : boolean);override;
  85. { entry/exit code helpers }
  86. procedure g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);override;
  87. procedure g_profilecode(list : taasmoutput);override;
  88. procedure g_stackpointer_alloc(list : taasmoutput;localsize : longint);override;
  89. procedure g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);override;
  90. procedure g_save_standard_registers(list:Taasmoutput);override;
  91. procedure g_restore_standard_registers(list:Taasmoutput);override;
  92. procedure g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);override;
  93. protected
  94. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  95. procedure check_register_size(size:tcgsize;reg:tregister);
  96. procedure opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  97. private
  98. procedure sizes2load(s1,s2 : tcgsize;var op: tasmop; var s3: topsize);
  99. procedure floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  100. procedure floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  101. procedure floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  102. procedure floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  103. end;
  104. function use_sse(def : tdef) : boolean;
  105. const
  106. {$ifdef x86_64}
  107. TCGSize2OpSize: Array[tcgsize] of topsize =
  108. (S_NO,S_B,S_W,S_L,S_Q,S_Q,S_B,S_W,S_L,S_Q,S_Q,
  109. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  110. S_NO,S_NO,S_NO,S_MD,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  111. {$else x86_64}
  112. TCGSize2OpSize: Array[tcgsize] of topsize =
  113. (S_NO,S_B,S_W,S_L,S_L,S_L,S_B,S_W,S_L,S_L,S_L,
  114. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  115. S_NO,S_NO,S_NO,S_MD,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  116. {$endif x86_64}
  117. {$ifndef NOTARGETWIN32}
  118. winstackpagesize = 4096;
  119. {$endif NOTARGETWIN32}
  120. implementation
  121. uses
  122. globals,verbose,systems,cutils,
  123. cgutils,
  124. dwarf,
  125. symdef,defutil,paramgr,tgobj,procinfo;
  126. const
  127. TOpCG2AsmOp: Array[topcg] of TAsmOp = (A_NONE,A_ADD,A_AND,A_DIV,
  128. A_IDIV,A_MUL, A_IMUL, A_NEG,A_NOT,A_OR,
  129. A_SAR,A_SHL,A_SHR,A_SUB,A_XOR);
  130. TOpCmp2AsmCond: Array[topcmp] of TAsmCond = (C_NONE,
  131. C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A);
  132. function use_sse(def : tdef) : boolean;
  133. begin
  134. use_sse:=(is_single(def) and (aktfputype in sse_singlescalar)) or
  135. (is_double(def) and (aktfputype in sse_doublescalar));
  136. end;
  137. procedure Tcgx86.done_register_allocators;
  138. begin
  139. rg[R_INTREGISTER].free;
  140. rg[R_MMREGISTER].free;
  141. rg[R_MMXREGISTER].free;
  142. rgfpu.free;
  143. inherited done_register_allocators;
  144. end;
  145. function Tcgx86.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  146. begin
  147. result:=rgfpu.getregisterfpu(list);
  148. end;
  149. function Tcgx86.getmmxregister(list:Taasmoutput):Tregister;
  150. begin
  151. if not assigned(rg[R_MMXREGISTER]) then
  152. internalerror(200312124);
  153. result:=rg[R_MMXREGISTER].getregister(list,R_SUBNONE);
  154. end;
  155. procedure Tcgx86.getexplicitregister(list:Taasmoutput;r:Tregister);
  156. begin
  157. if getregtype(r)=R_FPUREGISTER then
  158. internalerror(2003121210)
  159. else
  160. inherited getexplicitregister(list,r);
  161. end;
  162. procedure tcgx86.ungetregister(list:Taasmoutput;r:Tregister);
  163. begin
  164. if getregtype(r)=R_FPUREGISTER then
  165. rgfpu.ungetregisterfpu(list,r)
  166. else
  167. inherited ungetregister(list,r);
  168. end;
  169. procedure Tcgx86.allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  170. begin
  171. if rt<>R_FPUREGISTER then
  172. inherited allocexplicitregisters(list,rt,r);
  173. end;
  174. procedure Tcgx86.deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  175. begin
  176. if rt<>R_FPUREGISTER then
  177. inherited deallocexplicitregisters(list,rt,r);
  178. end;
  179. function Tcgx86.uses_registers(rt:Tregistertype):boolean;
  180. begin
  181. if rt=R_FPUREGISTER then
  182. result:=false
  183. else
  184. result:=inherited uses_registers(rt);
  185. end;
  186. procedure tcgx86.add_reg_instruction(instr:Tai;r:tregister);
  187. begin
  188. if getregtype(r)<>R_FPUREGISTER then
  189. inherited add_reg_instruction(instr,r);
  190. end;
  191. procedure tcgx86.dec_fpu_stack;
  192. begin
  193. dec(rgfpu.fpuvaroffset);
  194. end;
  195. procedure tcgx86.inc_fpu_stack;
  196. begin
  197. inc(rgfpu.fpuvaroffset);
  198. end;
  199. {****************************************************************************
  200. This is private property, keep out! :)
  201. ****************************************************************************}
  202. procedure tcgx86.sizes2load(s1,s2 : tcgsize; var op: tasmop; var s3: topsize);
  203. begin
  204. case s2 of
  205. OS_8,OS_S8 :
  206. if S1 in [OS_8,OS_S8] then
  207. s3 := S_B
  208. else
  209. internalerror(200109221);
  210. OS_16,OS_S16:
  211. case s1 of
  212. OS_8,OS_S8:
  213. s3 := S_BW;
  214. OS_16,OS_S16:
  215. s3 := S_W;
  216. else
  217. internalerror(200109222);
  218. end;
  219. OS_32,OS_S32:
  220. case s1 of
  221. OS_8,OS_S8:
  222. s3 := S_BL;
  223. OS_16,OS_S16:
  224. s3 := S_WL;
  225. OS_32,OS_S32:
  226. s3 := S_L;
  227. else
  228. internalerror(200109223);
  229. end;
  230. {$ifdef x86_64}
  231. OS_64,OS_S64:
  232. case s1 of
  233. OS_8:
  234. s3 := S_BL;
  235. OS_S8:
  236. s3 := S_BQ;
  237. OS_16:
  238. s3 := S_WL;
  239. OS_S16:
  240. s3 := S_WQ;
  241. OS_32:
  242. s3 := S_L;
  243. OS_S32:
  244. s3 := S_LQ;
  245. OS_64,OS_S64:
  246. s3 := S_Q;
  247. else
  248. internalerror(200304302);
  249. end;
  250. {$endif x86_64}
  251. else
  252. internalerror(200109227);
  253. end;
  254. if s3 in [S_B,S_W,S_L,S_Q] then
  255. op := A_MOV
  256. else if s1 in [OS_8,OS_16,OS_32,OS_64] then
  257. op := A_MOVZX
  258. else
  259. {$ifdef x86_64}
  260. if s3 in [S_LQ] then
  261. op := A_MOVSXD
  262. else
  263. {$endif x86_64}
  264. op := A_MOVSX;
  265. end;
  266. procedure tcgx86.floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  267. begin
  268. case t of
  269. OS_F32 :
  270. begin
  271. op:=A_FLD;
  272. s:=S_FS;
  273. end;
  274. OS_F64 :
  275. begin
  276. op:=A_FLD;
  277. { ???? }
  278. s:=S_FL;
  279. end;
  280. OS_F80 :
  281. begin
  282. op:=A_FLD;
  283. s:=S_FX;
  284. end;
  285. OS_C64 :
  286. begin
  287. op:=A_FILD;
  288. s:=S_IQ;
  289. end;
  290. else
  291. internalerror(200204041);
  292. end;
  293. end;
  294. procedure tcgx86.floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  295. var
  296. op : tasmop;
  297. s : topsize;
  298. begin
  299. floatloadops(t,op,s);
  300. list.concat(Taicpu.Op_ref(op,s,ref));
  301. inc_fpu_stack;
  302. end;
  303. procedure tcgx86.floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  304. begin
  305. case t of
  306. OS_F32 :
  307. begin
  308. op:=A_FSTP;
  309. s:=S_FS;
  310. end;
  311. OS_F64 :
  312. begin
  313. op:=A_FSTP;
  314. s:=S_FL;
  315. end;
  316. OS_F80 :
  317. begin
  318. op:=A_FSTP;
  319. s:=S_FX;
  320. end;
  321. OS_C64 :
  322. begin
  323. op:=A_FISTP;
  324. s:=S_IQ;
  325. end;
  326. else
  327. internalerror(200204042);
  328. end;
  329. end;
  330. procedure tcgx86.floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  331. var
  332. op : tasmop;
  333. s : topsize;
  334. begin
  335. floatstoreops(t,op,s);
  336. list.concat(Taicpu.Op_ref(op,s,ref));
  337. dec_fpu_stack;
  338. end;
  339. procedure tcgx86.check_register_size(size:tcgsize;reg:tregister);
  340. begin
  341. if TCGSize2OpSize[size]<>TCGSize2OpSize[reg_cgsize(reg)] then
  342. internalerror(200306031);
  343. end;
  344. {****************************************************************************
  345. Assembler code
  346. ****************************************************************************}
  347. procedure tcgx86.a_jmp_name(list : taasmoutput;const s : string);
  348. begin
  349. list.concat(taicpu.op_sym(A_JMP,S_NO,objectlibrary.newasmsymbol(s,AB_EXTERNAL,AT_FUNCTION)));
  350. end;
  351. procedure tcgx86.a_jmp_always(list : taasmoutput;l: tasmlabel);
  352. begin
  353. a_jmp_cond(list, OC_NONE, l);
  354. end;
  355. procedure tcgx86.a_call_name(list : taasmoutput;const s : string);
  356. begin
  357. list.concat(taicpu.op_sym(A_CALL,S_NO,objectlibrary.newasmsymbol(s,AB_EXTERNAL,AT_FUNCTION)));
  358. end;
  359. procedure tcgx86.a_call_reg(list : taasmoutput;reg : tregister);
  360. begin
  361. list.concat(taicpu.op_reg(A_CALL,S_NO,reg));
  362. end;
  363. {********************** load instructions ********************}
  364. procedure tcgx86.a_load_const_reg(list : taasmoutput; tosize: TCGSize; a : aint; reg : TRegister);
  365. begin
  366. check_register_size(tosize,reg);
  367. { the optimizer will change it to "xor reg,reg" when loading zero, }
  368. { no need to do it here too (JM) }
  369. list.concat(taicpu.op_const_reg(A_MOV,TCGSize2OpSize[tosize],a,reg))
  370. end;
  371. procedure tcgx86.a_load_const_ref(list : taasmoutput; tosize: tcgsize; a : aint;const ref : treference);
  372. {$ifdef x86_64}
  373. var
  374. href : treference;
  375. {$endif x86_64}
  376. begin
  377. {$ifdef x86_64}
  378. { x86_64 only supports signed 32 bits constants directly }
  379. if (tosize in [OS_S64,OS_64]) and
  380. ((a<low(longint)) or (a>high(longint))) then
  381. begin
  382. href:=ref;
  383. a_load_const_ref(list,OS_32,longint(a and $ffffffff),href);
  384. inc(href.offset,4);
  385. a_load_const_ref(list,OS_32,longint(a shr 32),href);
  386. end
  387. else
  388. {$endif x86_64}
  389. list.concat(taicpu.op_const_ref(A_MOV,TCGSize2OpSize[tosize],a,ref));
  390. end;
  391. procedure tcgx86.a_load_reg_ref(list : taasmoutput; fromsize,tosize: TCGSize; reg : tregister;const ref : treference);
  392. var
  393. op: tasmop;
  394. s: topsize;
  395. tmpreg : tregister;
  396. begin
  397. check_register_size(fromsize,reg);
  398. sizes2load(fromsize,tosize,op,s);
  399. case s of
  400. {$ifdef x86_64}
  401. S_BQ,S_WQ,S_LQ,
  402. {$endif x86_64}
  403. S_BW,S_BL,S_WL :
  404. begin
  405. tmpreg:=getintregister(list,tosize);
  406. {$ifdef x86_64}
  407. { zero extensions to 64 bit on the x86_64 are simply done by writting to the lower 32 bit
  408. which clears the upper 64 bit too, so it could be that s is S_L while the reg is
  409. 64 bit (FK) }
  410. if s in [S_BL,S_WL,S_L] then
  411. tmpreg:=makeregsize(list,tmpreg,OS_32);
  412. {$endif x86_64}
  413. list.concat(taicpu.op_reg_reg(op,s,reg,tmpreg));
  414. a_load_reg_ref(list,tosize,tosize,tmpreg,ref);
  415. ungetregister(list,tmpreg);
  416. end;
  417. else
  418. list.concat(taicpu.op_reg_ref(op,s,reg,ref));
  419. end;
  420. end;
  421. procedure tcgx86.a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  422. var
  423. op: tasmop;
  424. s: topsize;
  425. begin
  426. check_register_size(tosize,reg);
  427. sizes2load(fromsize,tosize,op,s);
  428. {$ifdef x86_64}
  429. { zero extensions to 64 bit on the x86_64 are simply done by writting to the lower 32 bit
  430. which clears the upper 64 bit too, so it could be that s is S_L while the reg is
  431. 64 bit (FK) }
  432. if s in [S_BL,S_WL,S_L] then
  433. reg:=makeregsize(list,reg,OS_32);
  434. {$endif x86_64}
  435. list.concat(taicpu.op_ref_reg(op,s,ref,reg));
  436. end;
  437. procedure tcgx86.a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);
  438. var
  439. op: tasmop;
  440. s: topsize;
  441. instr:Taicpu;
  442. begin
  443. check_register_size(fromsize,reg1);
  444. check_register_size(tosize,reg2);
  445. if tcgsize2size[fromsize]>tcgsize2size[tosize] then
  446. begin
  447. reg1:=makeregsize(list,reg1,tosize);
  448. s:=tcgsize2opsize[tosize];
  449. op:=A_MOV;
  450. end
  451. else
  452. sizes2load(fromsize,tosize,op,s);
  453. {$ifdef x86_64}
  454. { zero extensions to 64 bit on the x86_64 are simply done by writting to the lower 32 bit
  455. which clears the upper 64 bit too, so it could be that s is S_L while the reg is
  456. 64 bit (FK) }
  457. if s in [S_BL,S_WL,S_L] then
  458. reg2:=makeregsize(list,reg2,OS_32);
  459. {$endif x86_64}
  460. instr:=taicpu.op_reg_reg(op,s,reg1,reg2);
  461. { Notify the register allocator that we have written a move instruction so
  462. it can try to eliminate it. }
  463. add_move_instruction(instr);
  464. list.concat(instr);
  465. end;
  466. procedure tcgx86.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  467. begin
  468. with ref do
  469. if (base=NR_NO) and (index=NR_NO) then
  470. begin
  471. if assigned(ref.symbol) then
  472. list.concat(Taicpu.op_sym_ofs_reg(A_MOV,tcgsize2opsize[OS_ADDR],symbol,offset,r))
  473. else
  474. a_load_const_reg(list,OS_ADDR,offset,r);
  475. end
  476. else if (base=NR_NO) and (index<>NR_NO) and
  477. (offset=0) and (scalefactor=0) and (symbol=nil) then
  478. a_load_reg_reg(list,OS_ADDR,OS_ADDR,index,r)
  479. else if (base<>NR_NO) and (index=NR_NO) and
  480. (offset=0) and (symbol=nil) then
  481. a_load_reg_reg(list,OS_ADDR,OS_ADDR,base,r)
  482. else
  483. list.concat(taicpu.op_ref_reg(A_LEA,tcgsize2opsize[OS_ADDR],ref,r));
  484. end;
  485. { all fpu load routines expect that R_ST[0-7] means an fpu regvar and }
  486. { R_ST means "the current value at the top of the fpu stack" (JM) }
  487. procedure tcgx86.a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister);
  488. begin
  489. if (reg1<>NR_ST) then
  490. begin
  491. list.concat(taicpu.op_reg(A_FLD,S_NO,rgfpu.correct_fpuregister(reg1,rgfpu.fpuvaroffset)));
  492. inc_fpu_stack;
  493. end;
  494. if (reg2<>NR_ST) then
  495. begin
  496. list.concat(taicpu.op_reg(A_FSTP,S_NO,rgfpu.correct_fpuregister(reg2,rgfpu.fpuvaroffset)));
  497. dec_fpu_stack;
  498. end;
  499. end;
  500. procedure tcgx86.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  501. begin
  502. floatload(list,size,ref);
  503. if (reg<>NR_ST) then
  504. a_loadfpu_reg_reg(list,size,NR_ST,reg);
  505. end;
  506. procedure tcgx86.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  507. begin
  508. if reg<>NR_ST then
  509. a_loadfpu_reg_reg(list,size,reg,NR_ST);
  510. floatstore(list,size,ref);
  511. end;
  512. function get_scalar_mm_op(fromsize,tosize : tcgsize) : tasmop;
  513. const
  514. convertop : array[OS_F32..OS_F128,OS_F32..OS_F128] of tasmop = (
  515. (A_MOVSS,A_CVTSS2SD,A_NONE,A_NONE,A_NONE),
  516. (A_CVTSD2SS,A_MOVSD,A_NONE,A_NONE,A_NONE),
  517. (A_NONE,A_NONE,A_NONE,A_NONE,A_NONE),
  518. (A_NONE,A_NONE,A_NONE,A_MOVQ,A_NONE),
  519. (A_NONE,A_NONE,A_NONE,A_NONE,A_NONE));
  520. begin
  521. result:=convertop[fromsize,tosize];
  522. if result=A_NONE then
  523. internalerror(200312205);
  524. end;
  525. procedure tcgx86.a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle);
  526. begin
  527. if shuffle=nil then
  528. begin
  529. if fromsize=tosize then
  530. list.concat(taicpu.op_reg_reg(A_MOVAPS,S_NO,reg1,reg2))
  531. else
  532. internalerror(200312202);
  533. end
  534. else if shufflescalar(shuffle) then
  535. list.concat(taicpu.op_reg_reg(get_scalar_mm_op(fromsize,tosize),S_NO,reg1,reg2))
  536. else
  537. internalerror(200312201);
  538. end;
  539. procedure tcgx86.a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  540. begin
  541. if shuffle=nil then
  542. begin
  543. list.concat(taicpu.op_ref_reg(A_MOVQ,S_NO,ref,reg));
  544. end
  545. else if shufflescalar(shuffle) then
  546. list.concat(taicpu.op_ref_reg(get_scalar_mm_op(fromsize,tosize),S_NO,ref,reg))
  547. else
  548. internalerror(200312252);
  549. end;
  550. procedure tcgx86.a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle);
  551. begin
  552. if shuffle=nil then
  553. begin
  554. list.concat(taicpu.op_reg_ref(A_MOVQ,S_NO,reg,ref));
  555. end
  556. else if shufflescalar(shuffle) then
  557. list.concat(taicpu.op_reg_ref(get_scalar_mm_op(fromsize,tosize),S_NO,reg,ref))
  558. else
  559. internalerror(200312252);
  560. end;
  561. procedure tcgx86.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  562. var
  563. l : tlocation;
  564. begin
  565. l.loc:=LOC_REFERENCE;
  566. l.reference:=ref;
  567. l.size:=size;
  568. opmm_loc_reg(list,op,size,l,reg,shuffle);
  569. end;
  570. procedure tcgx86.a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);
  571. var
  572. l : tlocation;
  573. begin
  574. l.loc:=LOC_MMREGISTER;
  575. l.register:=src;
  576. l.size:=size;
  577. opmm_loc_reg(list,op,size,l,dst,shuffle);
  578. end;
  579. procedure tcgx86.opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  580. const
  581. opmm2asmop : array[0..1,OS_F32..OS_F64,topcg] of tasmop = (
  582. ( { scalar }
  583. ( { OS_F32 }
  584. 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
  585. ),
  586. ( { OS_F64 }
  587. 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
  588. )
  589. ),
  590. ( { vectorized/packed }
  591. { because the logical packed single instructions have shorter op codes, we use always
  592. these
  593. }
  594. ( { OS_F32 }
  595. A_NOP,A_ADDPS,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_XORPS
  596. ),
  597. ( { OS_F64 }
  598. A_NOP,A_ADDPD,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_NOP,A_XORPS
  599. )
  600. )
  601. );
  602. var
  603. resultreg : tregister;
  604. asmop : tasmop;
  605. begin
  606. { this is an internally used procedure so the parameters have
  607. some constrains
  608. }
  609. if loc.size<>size then
  610. internalerror(200312213);
  611. resultreg:=dst;
  612. { deshuffle }
  613. //!!!
  614. if (shuffle<>nil) and not(shufflescalar(shuffle)) then
  615. begin
  616. end
  617. else if (shuffle=nil) then
  618. asmop:=opmm2asmop[1,size,op]
  619. else if shufflescalar(shuffle) then
  620. begin
  621. asmop:=opmm2asmop[0,size,op];
  622. { no scalar operation available? }
  623. if asmop=A_NOP then
  624. begin
  625. { do vectorized and shuffle finally }
  626. //!!!
  627. end;
  628. end
  629. else
  630. internalerror(200312211);
  631. if asmop=A_NOP then
  632. internalerror(200312215);
  633. case loc.loc of
  634. LOC_CREFERENCE,LOC_REFERENCE:
  635. list.concat(taicpu.op_ref_reg(asmop,S_NO,loc.reference,resultreg));
  636. LOC_CMMREGISTER,LOC_MMREGISTER:
  637. list.concat(taicpu.op_reg_reg(asmop,S_NO,loc.register,resultreg));
  638. else
  639. internalerror(200312214);
  640. end;
  641. { shuffle }
  642. if resultreg<>dst then
  643. begin
  644. internalerror(200312212);
  645. end;
  646. end;
  647. procedure tcgx86.a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister);
  648. var
  649. opcode : tasmop;
  650. power : longint;
  651. {$ifdef x86_64}
  652. tmpreg : tregister;
  653. {$endif x86_64}
  654. begin
  655. {$ifdef x86_64}
  656. { x86_64 only supports signed 32 bits constants directly }
  657. if (size in [OS_S64,OS_64]) and
  658. ((a<low(longint)) or (a>high(longint))) then
  659. begin
  660. tmpreg:=getintregister(list,size);
  661. a_load_const_reg(list,size,a,tmpreg);
  662. a_op_reg_reg(list,op,size,tmpreg,reg);
  663. exit;
  664. end;
  665. {$endif x86_64}
  666. check_register_size(size,reg);
  667. case op of
  668. OP_DIV, OP_IDIV:
  669. begin
  670. if ispowerof2(int64(a),power) then
  671. begin
  672. case op of
  673. OP_DIV:
  674. opcode := A_SHR;
  675. OP_IDIV:
  676. opcode := A_SAR;
  677. end;
  678. list.concat(taicpu.op_const_reg(opcode,TCgSize2OpSize[size],power,reg));
  679. exit;
  680. end;
  681. { the rest should be handled specifically in the code }
  682. { generator because of the silly register usage restraints }
  683. internalerror(200109224);
  684. end;
  685. OP_MUL,OP_IMUL:
  686. begin
  687. if not(cs_check_overflow in aktlocalswitches) and
  688. ispowerof2(int64(a),power) then
  689. begin
  690. list.concat(taicpu.op_const_reg(A_SHL,TCgSize2OpSize[size],power,reg));
  691. exit;
  692. end;
  693. if op = OP_IMUL then
  694. list.concat(taicpu.op_const_reg(A_IMUL,TCgSize2OpSize[size],a,reg))
  695. else
  696. { OP_MUL should be handled specifically in the code }
  697. { generator because of the silly register usage restraints }
  698. internalerror(200109225);
  699. end;
  700. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  701. if not(cs_check_overflow in aktlocalswitches) and
  702. (a = 1) and
  703. (op in [OP_ADD,OP_SUB]) then
  704. if op = OP_ADD then
  705. list.concat(taicpu.op_reg(A_INC,TCgSize2OpSize[size],reg))
  706. else
  707. list.concat(taicpu.op_reg(A_DEC,TCgSize2OpSize[size],reg))
  708. else if (a = 0) then
  709. if (op <> OP_AND) then
  710. exit
  711. else
  712. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],0,reg))
  713. else if (aword(a) = high(aword)) and
  714. (op in [OP_AND,OP_OR,OP_XOR]) then
  715. begin
  716. case op of
  717. OP_AND:
  718. exit;
  719. OP_OR:
  720. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],aint(high(aword)),reg));
  721. OP_XOR:
  722. list.concat(taicpu.op_reg(A_NOT,TCgSize2OpSize[size],reg));
  723. end
  724. end
  725. else
  726. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a,reg));
  727. OP_SHL,OP_SHR,OP_SAR:
  728. begin
  729. if (a and 31) <> 0 Then
  730. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,reg));
  731. if (a shr 5) <> 0 Then
  732. internalerror(68991);
  733. end
  734. else internalerror(68992);
  735. end;
  736. end;
  737. procedure tcgx86.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
  738. var
  739. opcode: tasmop;
  740. power: longint;
  741. {$ifdef x86_64}
  742. tmpreg : tregister;
  743. {$endif x86_64}
  744. begin
  745. {$ifdef x86_64}
  746. { x86_64 only supports signed 32 bits constants directly }
  747. if (size in [OS_S64,OS_64]) and
  748. ((a<low(longint)) or (a>high(longint))) then
  749. begin
  750. tmpreg:=getintregister(list,size);
  751. a_load_const_reg(list,size,a,tmpreg);
  752. a_op_reg_ref(list,op,size,tmpreg,ref);
  753. exit;
  754. end;
  755. {$endif x86_64}
  756. Case Op of
  757. OP_DIV, OP_IDIV:
  758. Begin
  759. if ispowerof2(int64(a),power) then
  760. begin
  761. case op of
  762. OP_DIV:
  763. opcode := A_SHR;
  764. OP_IDIV:
  765. opcode := A_SAR;
  766. end;
  767. list.concat(taicpu.op_const_ref(opcode,
  768. TCgSize2OpSize[size],power,ref));
  769. exit;
  770. end;
  771. { the rest should be handled specifically in the code }
  772. { generator because of the silly register usage restraints }
  773. internalerror(200109231);
  774. End;
  775. OP_MUL,OP_IMUL:
  776. begin
  777. if not(cs_check_overflow in aktlocalswitches) and
  778. ispowerof2(int64(a),power) then
  779. begin
  780. list.concat(taicpu.op_const_ref(A_SHL,TCgSize2OpSize[size],
  781. power,ref));
  782. exit;
  783. end;
  784. { can't multiply a memory location directly with a constant }
  785. if op = OP_IMUL then
  786. inherited a_op_const_ref(list,op,size,a,ref)
  787. else
  788. { OP_MUL should be handled specifically in the code }
  789. { generator because of the silly register usage restraints }
  790. internalerror(200109232);
  791. end;
  792. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  793. if not(cs_check_overflow in aktlocalswitches) and
  794. (a = 1) and
  795. (op in [OP_ADD,OP_SUB]) then
  796. if op = OP_ADD then
  797. list.concat(taicpu.op_ref(A_INC,TCgSize2OpSize[size],ref))
  798. else
  799. list.concat(taicpu.op_ref(A_DEC,TCgSize2OpSize[size],ref))
  800. else if (a = 0) then
  801. if (op <> OP_AND) then
  802. exit
  803. else
  804. a_load_const_ref(list,size,0,ref)
  805. else if (aword(a) = high(aword)) and
  806. (op in [OP_AND,OP_OR,OP_XOR]) then
  807. begin
  808. case op of
  809. OP_AND:
  810. exit;
  811. OP_OR:
  812. list.concat(taicpu.op_const_ref(A_MOV,TCgSize2OpSize[size],aint(high(aword)),ref));
  813. OP_XOR:
  814. list.concat(taicpu.op_ref(A_NOT,TCgSize2OpSize[size],ref));
  815. end
  816. end
  817. else
  818. list.concat(taicpu.op_const_ref(TOpCG2AsmOp[op],
  819. TCgSize2OpSize[size],a,ref));
  820. OP_SHL,OP_SHR,OP_SAR:
  821. begin
  822. if (a and 31) <> 0 then
  823. list.concat(taicpu.op_const_ref(
  824. TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,ref));
  825. if (a shr 5) <> 0 Then
  826. internalerror(68991);
  827. end
  828. else internalerror(68992);
  829. end;
  830. end;
  831. procedure tcgx86.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  832. var
  833. dstsize: topsize;
  834. instr:Taicpu;
  835. begin
  836. check_register_size(size,src);
  837. check_register_size(size,dst);
  838. dstsize := tcgsize2opsize[size];
  839. case op of
  840. OP_NEG,OP_NOT:
  841. begin
  842. if src<>dst then
  843. a_load_reg_reg(list,size,size,src,dst);
  844. list.concat(taicpu.op_reg(TOpCG2AsmOp[op],dstsize,dst));
  845. end;
  846. OP_MUL,OP_DIV,OP_IDIV:
  847. { special stuff, needs separate handling inside code }
  848. { generator }
  849. internalerror(200109233);
  850. OP_SHR,OP_SHL,OP_SAR:
  851. begin
  852. getexplicitregister(list,NR_CL);
  853. a_load_reg_reg(list,OS_8,OS_8,makeregsize(list,src,OS_8),NR_CL);
  854. list.concat(taicpu.op_reg_reg(Topcg2asmop[op],tcgsize2opsize[size],NR_CL,src));
  855. ungetregister(list,NR_CL);
  856. end;
  857. else
  858. begin
  859. if reg2opsize(src) <> dstsize then
  860. internalerror(200109226);
  861. instr:=taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,src,dst);
  862. list.concat(instr);
  863. end;
  864. end;
  865. end;
  866. procedure tcgx86.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  867. begin
  868. check_register_size(size,reg);
  869. case op of
  870. OP_NEG,OP_NOT,OP_IMUL:
  871. begin
  872. inherited a_op_ref_reg(list,op,size,ref,reg);
  873. end;
  874. OP_MUL,OP_DIV,OP_IDIV:
  875. { special stuff, needs separate handling inside code }
  876. { generator }
  877. internalerror(200109239);
  878. else
  879. begin
  880. reg := makeregsize(list,reg,size);
  881. list.concat(taicpu.op_ref_reg(TOpCG2AsmOp[op],tcgsize2opsize[size],ref,reg));
  882. end;
  883. end;
  884. end;
  885. procedure tcgx86.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  886. begin
  887. check_register_size(size,reg);
  888. case op of
  889. OP_NEG,OP_NOT:
  890. begin
  891. if reg<>NR_NO then
  892. internalerror(200109237);
  893. list.concat(taicpu.op_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],ref));
  894. end;
  895. OP_IMUL:
  896. begin
  897. { this one needs a load/imul/store, which is the default }
  898. inherited a_op_ref_reg(list,op,size,ref,reg);
  899. end;
  900. OP_MUL,OP_DIV,OP_IDIV:
  901. { special stuff, needs separate handling inside code }
  902. { generator }
  903. internalerror(200109238);
  904. else
  905. begin
  906. list.concat(taicpu.op_reg_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],reg,ref));
  907. end;
  908. end;
  909. end;
  910. procedure tcgx86.a_op_const_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister);
  911. var
  912. tmpref: treference;
  913. power: longint;
  914. {$ifdef x86_64}
  915. tmpreg : tregister;
  916. {$endif x86_64}
  917. begin
  918. {$ifdef x86_64}
  919. { x86_64 only supports signed 32 bits constants directly }
  920. if (size in [OS_S64,OS_64]) and
  921. ((a<low(longint)) or (a>high(longint))) then
  922. begin
  923. tmpreg:=getintregister(list,size);
  924. a_load_const_reg(list,size,a,tmpreg);
  925. a_op_reg_reg_reg(list,op,size,tmpreg,src,dst);
  926. exit;
  927. end;
  928. {$endif x86_64}
  929. check_register_size(size,src);
  930. check_register_size(size,dst);
  931. if tcgsize2size[size]<>tcgsize2size[OS_INT] then
  932. begin
  933. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  934. exit;
  935. end;
  936. { if we get here, we have to do a 32 bit calculation, guaranteed }
  937. case op of
  938. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  939. OP_SAR:
  940. { can't do anything special for these }
  941. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  942. OP_IMUL:
  943. begin
  944. if not(cs_check_overflow in aktlocalswitches) and
  945. ispowerof2(int64(a),power) then
  946. { can be done with a shift }
  947. begin
  948. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  949. exit;
  950. end;
  951. list.concat(taicpu.op_const_reg_reg(A_IMUL,tcgsize2opsize[size],a,src,dst));
  952. end;
  953. OP_ADD, OP_SUB:
  954. if (a = 0) then
  955. a_load_reg_reg(list,size,size,src,dst)
  956. else
  957. begin
  958. reference_reset(tmpref);
  959. tmpref.base := src;
  960. tmpref.offset := longint(a);
  961. if op = OP_SUB then
  962. tmpref.offset := -tmpref.offset;
  963. list.concat(taicpu.op_ref_reg(A_LEA,tcgsize2opsize[size],tmpref,dst));
  964. end
  965. else internalerror(200112302);
  966. end;
  967. end;
  968. procedure tcgx86.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;size: tcgsize; src1, src2, dst: tregister);
  969. var
  970. tmpref: treference;
  971. begin
  972. check_register_size(size,src1);
  973. check_register_size(size,src2);
  974. check_register_size(size,dst);
  975. if tcgsize2size[size]<>tcgsize2size[OS_INT] then
  976. begin
  977. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  978. exit;
  979. end;
  980. { if we get here, we have to do a 32 bit calculation, guaranteed }
  981. Case Op of
  982. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  983. OP_SAR,OP_SUB,OP_NOT,OP_NEG:
  984. { can't do anything special for these }
  985. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  986. OP_IMUL:
  987. list.concat(taicpu.op_reg_reg_reg(A_IMUL,tcgsize2opsize[size],src1,src2,dst));
  988. OP_ADD:
  989. begin
  990. reference_reset(tmpref);
  991. tmpref.base := src1;
  992. tmpref.index := src2;
  993. tmpref.scalefactor := 1;
  994. list.concat(taicpu.op_ref_reg(A_LEA,tcgsize2opsize[size],tmpref,dst));
  995. end
  996. else internalerror(200112303);
  997. end;
  998. end;
  999. {*************** compare instructructions ****************}
  1000. procedure tcgx86.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  1001. l : tasmlabel);
  1002. {$ifdef x86_64}
  1003. var
  1004. tmpreg : tregister;
  1005. {$endif x86_64}
  1006. begin
  1007. {$ifdef x86_64}
  1008. { x86_64 only supports signed 32 bits constants directly }
  1009. if (size in [OS_S64,OS_64]) and
  1010. ((a<low(longint)) or (a>high(longint))) then
  1011. begin
  1012. tmpreg:=getintregister(list,size);
  1013. a_load_const_reg(list,size,a,tmpreg);
  1014. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1015. exit;
  1016. end;
  1017. {$endif x86_64}
  1018. if (a = 0) then
  1019. list.concat(taicpu.op_reg_reg(A_TEST,tcgsize2opsize[size],reg,reg))
  1020. else
  1021. list.concat(taicpu.op_const_reg(A_CMP,tcgsize2opsize[size],a,reg));
  1022. a_jmp_cond(list,cmp_op,l);
  1023. end;
  1024. procedure tcgx86.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  1025. l : tasmlabel);
  1026. {$ifdef x86_64}
  1027. var
  1028. tmpreg : tregister;
  1029. {$endif x86_64}
  1030. begin
  1031. {$ifdef x86_64}
  1032. { x86_64 only supports signed 32 bits constants directly }
  1033. if (size in [OS_S64,OS_64]) and
  1034. ((a<low(longint)) or (a>high(longint))) then
  1035. begin
  1036. tmpreg:=getintregister(list,size);
  1037. a_load_const_reg(list,size,a,tmpreg);
  1038. a_cmp_reg_ref_label(list,size,cmp_op,tmpreg,ref,l);
  1039. exit;
  1040. end;
  1041. {$endif x86_64}
  1042. list.concat(taicpu.op_const_ref(A_CMP,TCgSize2OpSize[size],a,ref));
  1043. a_jmp_cond(list,cmp_op,l);
  1044. end;
  1045. procedure tcgx86.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  1046. reg1,reg2 : tregister;l : tasmlabel);
  1047. begin
  1048. check_register_size(size,reg1);
  1049. check_register_size(size,reg2);
  1050. list.concat(taicpu.op_reg_reg(A_CMP,TCgSize2OpSize[size],reg1,reg2));
  1051. a_jmp_cond(list,cmp_op,l);
  1052. end;
  1053. procedure tcgx86.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister;l : tasmlabel);
  1054. begin
  1055. check_register_size(size,reg);
  1056. list.concat(taicpu.op_ref_reg(A_CMP,TCgSize2OpSize[size],ref,reg));
  1057. a_jmp_cond(list,cmp_op,l);
  1058. end;
  1059. procedure tcgx86.a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg : tregister;const ref: treference; l : tasmlabel);
  1060. begin
  1061. check_register_size(size,reg);
  1062. list.concat(taicpu.op_reg_ref(A_CMP,TCgSize2OpSize[size],reg,ref));
  1063. a_jmp_cond(list,cmp_op,l);
  1064. end;
  1065. procedure tcgx86.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  1066. var
  1067. ai : taicpu;
  1068. begin
  1069. if cond=OC_None then
  1070. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  1071. else
  1072. begin
  1073. ai:=Taicpu.Op_sym(A_Jcc,S_NO,l);
  1074. ai.SetCondition(TOpCmp2AsmCond[cond]);
  1075. end;
  1076. ai.is_jmp:=true;
  1077. list.concat(ai);
  1078. end;
  1079. procedure tcgx86.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  1080. var
  1081. ai : taicpu;
  1082. begin
  1083. ai := Taicpu.op_sym(A_Jcc,S_NO,l);
  1084. ai.SetCondition(flags_to_cond(f));
  1085. ai.is_jmp := true;
  1086. list.concat(ai);
  1087. end;
  1088. procedure tcgx86.g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister);
  1089. var
  1090. ai : taicpu;
  1091. hreg : tregister;
  1092. begin
  1093. hreg:=makeregsize(list,reg,OS_8);
  1094. ai:=Taicpu.op_reg(A_SETcc,S_B,hreg);
  1095. ai.setcondition(flags_to_cond(f));
  1096. list.concat(ai);
  1097. if (reg<>hreg) then
  1098. a_load_reg_reg(list,OS_8,size,hreg,reg);
  1099. end;
  1100. procedure tcgx86.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference);
  1101. var
  1102. ai : taicpu;
  1103. begin
  1104. if not(size in [OS_8,OS_S8]) then
  1105. a_load_const_ref(list,size,0,ref);
  1106. ai:=Taicpu.op_ref(A_SETcc,S_B,ref);
  1107. ai.setcondition(flags_to_cond(f));
  1108. list.concat(ai);
  1109. end;
  1110. { ************* concatcopy ************ }
  1111. procedure Tcgx86.g_concatcopy(list:Taasmoutput;const source,dest:Treference;
  1112. len:aint;delsource,loadref:boolean);
  1113. const
  1114. {$ifdef cpu64bit}
  1115. REGCX=NR_RCX;
  1116. REGSI=NR_RSI;
  1117. REGDI=NR_RDI;
  1118. {$else cpu64bit}
  1119. REGCX=NR_ECX;
  1120. REGSI=NR_ESI;
  1121. REGDI=NR_EDI;
  1122. {$endif cpu64bit}
  1123. type copymode=(copy_move,copy_mmx,copy_string);
  1124. var srcref,dstref:Treference;
  1125. r,r0,r1,r2,r3:Tregister;
  1126. helpsize:aint;
  1127. copysize:byte;
  1128. cgsize:Tcgsize;
  1129. cm:copymode;
  1130. begin
  1131. cm:=copy_move;
  1132. helpsize:=12;
  1133. if cs_littlesize in aktglobalswitches then
  1134. helpsize:=8;
  1135. if (cs_mmx in aktlocalswitches) and
  1136. not(pi_uses_fpu in current_procinfo.flags) and
  1137. ((len=8) or (len=16) or (len=24) or (len=32)) then
  1138. cm:=copy_mmx;
  1139. if (len>helpsize) then
  1140. cm:=copy_string;
  1141. if (cs_littlesize in aktglobalswitches) and
  1142. not((len<=16) and (cm=copy_mmx)) then
  1143. cm:=copy_string;
  1144. if loadref then
  1145. cm:=copy_string;
  1146. case cm of
  1147. copy_move:
  1148. begin
  1149. dstref:=dest;
  1150. srcref:=source;
  1151. copysize:=sizeof(aint);
  1152. cgsize:=int_cgsize(copysize);
  1153. while len<>0 do
  1154. begin
  1155. if len<2 then
  1156. begin
  1157. copysize:=1;
  1158. cgsize:=OS_8;
  1159. end
  1160. else if len<4 then
  1161. begin
  1162. copysize:=2;
  1163. cgsize:=OS_16;
  1164. end
  1165. else if len<8 then
  1166. begin
  1167. copysize:=4;
  1168. cgsize:=OS_32;
  1169. end;
  1170. dec(len,copysize);
  1171. if (len=0) and delsource then
  1172. reference_release(list,source);
  1173. r:=getintregister(list,cgsize);
  1174. a_load_ref_reg(list,cgsize,cgsize,srcref,r);
  1175. ungetregister(list,r);
  1176. a_load_reg_ref(list,cgsize,cgsize,r,dstref);
  1177. inc(srcref.offset,copysize);
  1178. inc(dstref.offset,copysize);
  1179. end;
  1180. end;
  1181. copy_mmx:
  1182. begin
  1183. dstref:=dest;
  1184. srcref:=source;
  1185. r0:=getmmxregister(list);
  1186. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r0,nil);
  1187. if len>=16 then
  1188. begin
  1189. inc(srcref.offset,8);
  1190. r1:=getmmxregister(list);
  1191. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r1,nil);
  1192. end;
  1193. if len>=24 then
  1194. begin
  1195. inc(srcref.offset,8);
  1196. r2:=getmmxregister(list);
  1197. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r2,nil);
  1198. end;
  1199. if len>=32 then
  1200. begin
  1201. inc(srcref.offset,8);
  1202. r3:=getmmxregister(list);
  1203. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r3,nil);
  1204. end;
  1205. a_loadmm_reg_ref(list,OS_M64,OS_M64,r0,dstref,nil);
  1206. ungetregister(list,r0);
  1207. if len>=16 then
  1208. begin
  1209. inc(dstref.offset,8);
  1210. a_loadmm_reg_ref(list,OS_M64,OS_M64,r1,dstref,nil);
  1211. ungetregister(list,r1);
  1212. end;
  1213. if len>=24 then
  1214. begin
  1215. inc(dstref.offset,8);
  1216. a_loadmm_reg_ref(list,OS_M64,OS_M64,r2,dstref,nil);
  1217. ungetregister(list,r2);
  1218. end;
  1219. if len>=32 then
  1220. begin
  1221. inc(dstref.offset,8);
  1222. a_loadmm_reg_ref(list,OS_M64,OS_M64,r3,dstref,nil);
  1223. ungetregister(list,r3);
  1224. end;
  1225. end
  1226. else {copy_string, should be a good fallback in case of unhandled}
  1227. begin
  1228. getexplicitregister(list,REGDI);
  1229. a_loadaddr_ref_reg(list,dest,REGDI);
  1230. getexplicitregister(list,REGSI);
  1231. if loadref then
  1232. a_load_ref_reg(list,OS_ADDR,OS_ADDR,source,REGSI)
  1233. else
  1234. begin
  1235. a_loadaddr_ref_reg(list,source,REGSI);
  1236. if delsource then
  1237. begin
  1238. srcref:=source;
  1239. { Don't release ESI register yet, it's needed
  1240. by the movsl }
  1241. if (srcref.base=REGSI) then
  1242. srcref.base:=NR_NO
  1243. else if (srcref.index=REGSI) then
  1244. srcref.index:=NR_NO;
  1245. reference_release(list,srcref);
  1246. end;
  1247. end;
  1248. getexplicitregister(list,REGCX);
  1249. list.concat(Taicpu.op_none(A_CLD,S_NO));
  1250. if cs_littlesize in aktglobalswitches then
  1251. begin
  1252. a_load_const_reg(list,OS_INT,len,REGCX);
  1253. list.concat(Taicpu.op_none(A_REP,S_NO));
  1254. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1255. end
  1256. else
  1257. begin
  1258. helpsize:=len div sizeof(aint);
  1259. len:=len mod sizeof(aint);
  1260. if helpsize>1 then
  1261. begin
  1262. a_load_const_reg(list,OS_INT,helpsize,REGCX);
  1263. list.concat(Taicpu.op_none(A_REP,S_NO));
  1264. end;
  1265. if helpsize>0 then
  1266. begin
  1267. {$ifdef cpu64bit}
  1268. if sizeof(aint)=8 then
  1269. list.concat(Taicpu.op_none(A_MOVSQ,S_NO))
  1270. else
  1271. {$endif cpu64bit}
  1272. list.concat(Taicpu.op_none(A_MOVSD,S_NO));
  1273. end;
  1274. if len>=4 then
  1275. begin
  1276. dec(len,4);
  1277. list.concat(Taicpu.op_none(A_MOVSD,S_NO));
  1278. end;
  1279. if len>=2 then
  1280. begin
  1281. dec(len,2);
  1282. list.concat(Taicpu.op_none(A_MOVSW,S_NO));
  1283. end;
  1284. if len=1 then
  1285. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1286. end;
  1287. ungetregister(list,REGCX);
  1288. ungetregister(list,REGSI);
  1289. ungetregister(list,REGDI);
  1290. end;
  1291. end;
  1292. if delsource then
  1293. tg.ungetiftemp(list,source);
  1294. end;
  1295. {****************************************************************************
  1296. Entry/Exit Code Helpers
  1297. ****************************************************************************}
  1298. procedure tcgx86.g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);
  1299. begin
  1300. { Nothing to release }
  1301. end;
  1302. procedure tcgx86.g_profilecode(list : taasmoutput);
  1303. var
  1304. pl : tasmlabel;
  1305. mcountprefix : String[4];
  1306. begin
  1307. case target_info.system of
  1308. {$ifndef NOTARGETWIN32}
  1309. system_i386_win32,
  1310. {$endif}
  1311. system_i386_freebsd,
  1312. system_i386_netbsd,
  1313. // system_i386_openbsd,
  1314. system_i386_wdosx :
  1315. begin
  1316. Case target_info.system Of
  1317. system_i386_freebsd : mcountprefix:='.';
  1318. system_i386_netbsd : mcountprefix:='__';
  1319. // system_i386_openbsd : mcountprefix:='.';
  1320. else
  1321. mcountPrefix:='';
  1322. end;
  1323. objectlibrary.getaddrlabel(pl);
  1324. new_section(list,sec_data,lower(current_procinfo.procdef.mangledname),sizeof(aint));
  1325. list.concat(Tai_label.Create(pl));
  1326. list.concat(Tai_const.Create_32bit(0));
  1327. new_section(list,sec_code,lower(current_procinfo.procdef.mangledname),0);
  1328. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1329. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,pl,0,NR_EDX));
  1330. a_call_name(list,target_info.Cprefix+mcountprefix+'mcount');
  1331. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EDX));
  1332. end;
  1333. system_i386_linux:
  1334. a_call_name(list,target_info.Cprefix+'mcount');
  1335. system_i386_go32v2,system_i386_watcom:
  1336. begin
  1337. a_call_name(list,'MCOUNT');
  1338. end;
  1339. end;
  1340. end;
  1341. procedure tcgx86.g_stackpointer_alloc(list : taasmoutput;localsize : longint);
  1342. {$ifdef i386}
  1343. {$ifndef NOTARGETWIN32}
  1344. var
  1345. href : treference;
  1346. i : integer;
  1347. again : tasmlabel;
  1348. {$endif NOTARGETWIN32}
  1349. {$endif i386}
  1350. begin
  1351. if localsize>0 then
  1352. begin
  1353. {$ifdef i386}
  1354. {$ifndef NOTARGETWIN32}
  1355. { windows guards only a few pages for stack growing, }
  1356. { so we have to access every page first }
  1357. if (target_info.system=system_i386_win32) and
  1358. (localsize>=winstackpagesize) then
  1359. begin
  1360. if localsize div winstackpagesize<=5 then
  1361. begin
  1362. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize-4,NR_ESP));
  1363. for i:=1 to localsize div winstackpagesize do
  1364. begin
  1365. reference_reset_base(href,NR_ESP,localsize-i*winstackpagesize);
  1366. list.concat(Taicpu.op_const_ref(A_MOV,S_L,0,href));
  1367. end;
  1368. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1369. end
  1370. else
  1371. begin
  1372. objectlibrary.getlabel(again);
  1373. getexplicitregister(list,NR_EDI);
  1374. list.concat(Taicpu.op_const_reg(A_MOV,S_L,localsize div winstackpagesize,NR_EDI));
  1375. a_label(list,again);
  1376. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,NR_ESP));
  1377. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1378. list.concat(Taicpu.op_reg(A_DEC,S_L,NR_EDI));
  1379. a_jmp_cond(list,OC_NE,again);
  1380. ungetregister(list,NR_EDI);
  1381. list.concat(Taicpu.op_const_reg(A_SUB,S_L,localsize mod winstackpagesize,NR_ESP));
  1382. end
  1383. end
  1384. else
  1385. {$endif NOTARGETWIN32}
  1386. {$endif i386}
  1387. list.concat(Taicpu.Op_const_reg(A_SUB,tcgsize2opsize[OS_ADDR],localsize,NR_STACK_POINTER_REG));
  1388. end;
  1389. end;
  1390. procedure tcgx86.g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);
  1391. begin
  1392. {$ifdef i386}
  1393. { interrupt support for i386 }
  1394. if (po_interrupt in current_procinfo.procdef.procoptions) then
  1395. begin
  1396. { .... also the segment registers }
  1397. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_GS));
  1398. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_FS));
  1399. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_ES));
  1400. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_DS));
  1401. { save the registers of an interrupt procedure }
  1402. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDI));
  1403. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ESI));
  1404. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1405. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ECX));
  1406. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EBX));
  1407. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EAX));
  1408. end;
  1409. {$endif i386}
  1410. { save old framepointer }
  1411. if not nostackframe then
  1412. begin
  1413. if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then
  1414. CGmessage(cg_d_stackframe_omited)
  1415. else
  1416. begin
  1417. list.concat(tai_regalloc.alloc(NR_FRAME_POINTER_REG));
  1418. include(rg[R_INTREGISTER].preserved_by_proc,RS_FRAME_POINTER_REG);
  1419. list.concat(Taicpu.op_reg(A_PUSH,tcgsize2opsize[OS_ADDR],NR_FRAME_POINTER_REG));
  1420. { Return address and FP are both on stack }
  1421. dwarfcfi.cfa_def_cfa_offset(list,2*sizeof(aint));
  1422. dwarfcfi.cfa_offset(list,NR_FRAME_POINTER_REG,-(2*sizeof(aint)));
  1423. list.concat(Taicpu.op_reg_reg(A_MOV,tcgsize2opsize[OS_ADDR],NR_STACK_POINTER_REG,NR_FRAME_POINTER_REG));
  1424. dwarfcfi.cfa_def_cfa_register(list,NR_FRAME_POINTER_REG);
  1425. end;
  1426. { allocate stackframe space }
  1427. if localsize<>0 then
  1428. begin
  1429. cg.g_stackpointer_alloc(list,localsize);
  1430. end;
  1431. end;
  1432. { allocate PIC register }
  1433. if cs_create_pic in aktmoduleswitches then
  1434. begin
  1435. a_call_name(list,'FPC_GETEIPINEBX');
  1436. list.concat(taicpu.op_sym_ofs_reg(A_ADD,tcgsize2opsize[OS_ADDR],objectlibrary.newasmsymbol('_GLOBAL_OFFSET_TABLE_',AB_EXTERNAL,AT_DATA),0,NR_PIC_OFFSET_REG));
  1437. list.concat(tai_regalloc.alloc(NR_PIC_OFFSET_REG));
  1438. end;
  1439. end;
  1440. procedure tcgx86.g_save_standard_registers(list:Taasmoutput);
  1441. var
  1442. href : treference;
  1443. size : longint;
  1444. r : integer;
  1445. begin
  1446. { Get temp }
  1447. size:=0;
  1448. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1449. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1450. inc(size,sizeof(aint));
  1451. if size>0 then
  1452. begin
  1453. tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
  1454. { Copy registers to temp }
  1455. href:=current_procinfo.save_regs_ref;
  1456. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1457. begin
  1458. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1459. begin
  1460. a_load_reg_ref(list,OS_ADDR,OS_ADDR,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE),href);
  1461. inc(href.offset,sizeof(aint));
  1462. end;
  1463. include(rg[R_INTREGISTER].preserved_by_proc,saved_standard_registers[r]);
  1464. end;
  1465. end;
  1466. end;
  1467. procedure tcgx86.g_restore_standard_registers(list:Taasmoutput);
  1468. var
  1469. href : treference;
  1470. r : integer;
  1471. begin
  1472. { Copy registers from temp }
  1473. href:=current_procinfo.save_regs_ref;
  1474. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1475. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1476. begin
  1477. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE));
  1478. inc(href.offset,sizeof(aint));
  1479. end;
  1480. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1481. end;
  1482. { produces if necessary overflowcode }
  1483. procedure tcgx86.g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);
  1484. var
  1485. hl : tasmlabel;
  1486. ai : taicpu;
  1487. cond : TAsmCond;
  1488. begin
  1489. if not(cs_check_overflow in aktlocalswitches) then
  1490. exit;
  1491. objectlibrary.getlabel(hl);
  1492. if not ((def.deftype=pointerdef) or
  1493. ((def.deftype=orddef) and
  1494. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1495. bool8bit,bool16bit,bool32bit]))) then
  1496. cond:=C_NO
  1497. else
  1498. cond:=C_NB;
  1499. ai:=Taicpu.Op_Sym(A_Jcc,S_NO,hl);
  1500. ai.SetCondition(cond);
  1501. ai.is_jmp:=true;
  1502. list.concat(ai);
  1503. a_call_name(list,'FPC_OVERFLOW');
  1504. a_label(list,hl);
  1505. end;
  1506. end.
  1507. {
  1508. $Log$
  1509. Revision 1.124 2004-06-20 08:55:32 florian
  1510. * logs truncated
  1511. Revision 1.123 2004/06/16 20:07:11 florian
  1512. * dwarf branch merged
  1513. Revision 1.122 2004/05/22 23:34:28 peter
  1514. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1515. Revision 1.121 2004/04/28 15:19:03 florian
  1516. + syscall directive support for MorphOS added
  1517. Revision 1.120 2004/04/09 14:36:05 peter
  1518. * A_MOVSL renamed to A_MOVSD
  1519. Revision 1.119.2.22 2004/05/28 20:29:50 florian
  1520. * fixed currency trouble on x86-64
  1521. }