cgx86.pas 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300
  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. cgbase,cgobj,
  25. aasmbase,aasmtai,aasmcpu,
  26. cpubase,cpuinfo,rgobj,rgx86,rgcpu,
  27. symconst,symtype;
  28. type
  29. tcgx86 = class(tcg)
  30. rgfpu : Trgx86fpu;
  31. procedure init_register_allocators;override;
  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. { passing parameters, per default the parameter is pushed }
  44. { nr gives the number of the parameter (enumerated from }
  45. { left to right), this allows to move the parameter to }
  46. { register, if the cpu supports register calling }
  47. { conventions }
  48. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);override;
  49. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);override;
  50. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);override;
  51. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);override;
  52. procedure a_call_name(list : taasmoutput;const s : string);override;
  53. procedure a_call_reg(list : taasmoutput;reg : tregister);override;
  54. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister); override;
  55. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference); override;
  56. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  57. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); override;
  58. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference); override;
  59. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  60. size: tcgsize; a: aword; src, dst: tregister); override;
  61. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  62. size: tcgsize; src1, src2, dst: tregister); override;
  63. { move instructions }
  64. procedure a_load_const_reg(list : taasmoutput; tosize: tcgsize; a : aword;reg : tregister);override;
  65. procedure a_load_const_ref(list : taasmoutput; tosize: tcgsize; a : aword;const ref : treference);override;
  66. procedure a_load_reg_ref(list : taasmoutput;fromsize,tosize: tcgsize; reg : tregister;const ref : treference);override;
  67. procedure a_load_ref_reg(list : taasmoutput;fromsize,tosize: tcgsize;const ref : treference;reg : tregister);override;
  68. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize: tcgsize;reg1,reg2 : tregister);override;
  69. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  70. { fpu move instructions }
  71. procedure a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister); override;
  72. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  73. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  74. { vector register move instructions }
  75. procedure a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); override;
  76. procedure a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  77. procedure a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); override;
  78. procedure a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); override;
  79. procedure a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);override;
  80. { comparison operations }
  81. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  82. l : tasmlabel);override;
  83. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  84. l : tasmlabel);override;
  85. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  86. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister; l : tasmlabel); override;
  87. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  88. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  89. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); override;
  90. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference); override;
  91. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  92. procedure g_exception_reason_save(list : taasmoutput; const href : treference);override;
  93. procedure g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aword);override;
  94. procedure g_exception_reason_load(list : taasmoutput; const href : treference);override;
  95. { entry/exit code helpers }
  96. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:aword);override;
  97. procedure g_interrupt_stackframe_entry(list : taasmoutput);override;
  98. procedure g_interrupt_stackframe_exit(list : taasmoutput;accused,acchiused:boolean);override;
  99. procedure g_profilecode(list : taasmoutput);override;
  100. procedure g_stackpointer_alloc(list : taasmoutput;localsize : longint);override;
  101. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  102. procedure g_restore_frame_pointer(list : taasmoutput);override;
  103. procedure g_return_from_proc(list : taasmoutput;parasize : aword);override;
  104. procedure g_save_standard_registers(list:Taasmoutput);override;
  105. procedure g_restore_standard_registers(list:Taasmoutput);override;
  106. procedure g_save_all_registers(list : taasmoutput);override;
  107. procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);override;
  108. procedure g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);override;
  109. protected
  110. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  111. procedure check_register_size(size:tcgsize;reg:tregister);
  112. procedure opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  113. private
  114. procedure sizes2load(s1,s2 : tcgsize;var op: tasmop; var s3: topsize);
  115. procedure floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  116. procedure floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  117. procedure floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  118. procedure floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  119. end;
  120. const
  121. {$ifdef x86_64}
  122. TCGSize2OpSize: Array[tcgsize] of topsize =
  123. (S_NO,S_B,S_W,S_L,S_D,S_B,S_W,S_L,S_D,
  124. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  125. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  126. {$else x86_64}
  127. TCGSize2OpSize: Array[tcgsize] of topsize =
  128. (S_NO,S_B,S_W,S_L,S_L,S_B,S_W,S_L,S_L,
  129. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  130. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  131. {$endif x86_64}
  132. implementation
  133. uses
  134. globtype,globals,verbose,systems,cutils,
  135. symdef,paramgr,tgobj,procinfo;
  136. {$ifndef NOTARGETWIN32}
  137. const
  138. winstackpagesize = 4096;
  139. {$endif NOTARGETWIN32}
  140. TOpCG2AsmOp: Array[topcg] of TAsmOp = (A_NONE,A_ADD,A_AND,A_DIV,
  141. A_IDIV,A_MUL, A_IMUL, A_NEG,A_NOT,A_OR,
  142. A_SAR,A_SHL,A_SHR,A_SUB,A_XOR);
  143. TOpCmp2AsmCond: Array[topcmp] of TAsmCond = (C_NONE,
  144. C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A);
  145. procedure Tcgx86.init_register_allocators;
  146. begin
  147. if cs_create_pic in aktmoduleswitches then
  148. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,[RS_EAX,RS_EDX,RS_ECX,RS_ESI,RS_EDI],first_int_imreg,[RS_EBP,RS_EBX])
  149. else
  150. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,[RS_EAX,RS_EDX,RS_ECX,RS_EBX,RS_ESI,RS_EDI],first_int_imreg,[RS_EBP]);
  151. rg[R_MMXREGISTER]:=trgcpu.create(R_MMXREGISTER,R_SUBNONE,[RS_MM0,RS_MM1,RS_MM2,RS_MM3,RS_MM4,RS_MM5,RS_MM6,RS_MM7],first_sse_imreg,[]);
  152. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,[RS_MM0,RS_MM1,RS_MM2,RS_MM3,RS_MM4,RS_MM5,RS_MM6,RS_MM7],first_sse_imreg,[]);
  153. rgfpu:=Trgx86fpu.create;
  154. end;
  155. procedure Tcgx86.done_register_allocators;
  156. begin
  157. rg[R_INTREGISTER].free;
  158. rg[R_INTREGISTER]:=nil;
  159. rg[R_MMREGISTER].free;
  160. rg[R_MMREGISTER]:=nil;
  161. rg[R_MMXREGISTER].free;
  162. rg[R_MMXREGISTER]:=nil;
  163. rgfpu.free;
  164. end;
  165. function Tcgx86.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  166. begin
  167. result:=rgfpu.getregisterfpu(list);
  168. end;
  169. function Tcgx86.getmmxregister(list:Taasmoutput):Tregister;
  170. begin
  171. if not assigned(rg[R_MMXREGISTER]) then
  172. internalerror(200312124);
  173. result:=rg[R_MMXREGISTER].getregister(list,R_SUBNONE);
  174. end;
  175. procedure Tcgx86.getexplicitregister(list:Taasmoutput;r:Tregister);
  176. begin
  177. if getregtype(r)=R_FPUREGISTER then
  178. internalerror(2003121210)
  179. else
  180. inherited getexplicitregister(list,r);
  181. end;
  182. procedure tcgx86.ungetregister(list:Taasmoutput;r:Tregister);
  183. begin
  184. if getregtype(r)=R_FPUREGISTER then
  185. rgfpu.ungetregisterfpu(list,r)
  186. else
  187. inherited ungetregister(list,r);
  188. end;
  189. procedure Tcgx86.allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  190. begin
  191. if rt<>R_FPUREGISTER then
  192. inherited allocexplicitregisters(list,rt,r);
  193. end;
  194. procedure Tcgx86.deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  195. begin
  196. if rt<>R_FPUREGISTER then
  197. inherited deallocexplicitregisters(list,rt,r);
  198. end;
  199. function Tcgx86.uses_registers(rt:Tregistertype):boolean;
  200. begin
  201. if rt=R_FPUREGISTER then
  202. result:=false
  203. else
  204. result:=inherited uses_registers(rt);
  205. end;
  206. procedure tcgx86.add_reg_instruction(instr:Tai;r:tregister);
  207. begin
  208. if getregtype(r)<>R_FPUREGISTER then
  209. inherited add_reg_instruction(instr,r);
  210. end;
  211. procedure tcgx86.dec_fpu_stack;
  212. begin
  213. dec(rgfpu.fpuvaroffset);
  214. end;
  215. procedure tcgx86.inc_fpu_stack;
  216. begin
  217. inc(rgfpu.fpuvaroffset);
  218. end;
  219. {****************************************************************************
  220. This is private property, keep out! :)
  221. ****************************************************************************}
  222. procedure tcgx86.sizes2load(s1,s2 : tcgsize; var op: tasmop; var s3: topsize);
  223. begin
  224. case s2 of
  225. OS_8,OS_S8 :
  226. if S1 in [OS_8,OS_S8] then
  227. s3 := S_B
  228. else internalerror(200109221);
  229. OS_16,OS_S16:
  230. case s1 of
  231. OS_8,OS_S8:
  232. s3 := S_BW;
  233. OS_16,OS_S16:
  234. s3 := S_W;
  235. else
  236. internalerror(200109222);
  237. end;
  238. OS_32,OS_S32:
  239. case s1 of
  240. OS_8,OS_S8:
  241. s3 := S_BL;
  242. OS_16,OS_S16:
  243. s3 := S_WL;
  244. OS_32,OS_S32:
  245. s3 := S_L;
  246. else
  247. internalerror(200109223);
  248. end;
  249. {$ifdef x86_64}
  250. OS_64,OS_S64:
  251. case s1 of
  252. OS_8,OS_S8:
  253. s3 := S_BQ;
  254. OS_16,OS_S16:
  255. s3 := S_WQ;
  256. OS_32,OS_S32:
  257. s3 := S_LQ;
  258. OS_64,OS_S64:
  259. s3 := S_Q;
  260. else
  261. internalerror(200304302);
  262. end;
  263. {$endif x86_64}
  264. else
  265. internalerror(200109227);
  266. end;
  267. if s3 in [S_B,S_W,S_L,S_Q] then
  268. op := A_MOV
  269. else if s1 in [OS_8,OS_16,OS_32,OS_64] then
  270. op := A_MOVZX
  271. else
  272. op := A_MOVSX;
  273. end;
  274. procedure tcgx86.floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  275. begin
  276. case t of
  277. OS_F32 :
  278. begin
  279. op:=A_FLD;
  280. s:=S_FS;
  281. end;
  282. OS_F64 :
  283. begin
  284. op:=A_FLD;
  285. { ???? }
  286. s:=S_FL;
  287. end;
  288. OS_F80 :
  289. begin
  290. op:=A_FLD;
  291. s:=S_FX;
  292. end;
  293. OS_C64 :
  294. begin
  295. op:=A_FILD;
  296. s:=S_IQ;
  297. end;
  298. else
  299. internalerror(200204041);
  300. end;
  301. end;
  302. procedure tcgx86.floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  303. var
  304. op : tasmop;
  305. s : topsize;
  306. begin
  307. floatloadops(t,op,s);
  308. list.concat(Taicpu.Op_ref(op,s,ref));
  309. inc_fpu_stack;
  310. end;
  311. procedure tcgx86.floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  312. begin
  313. case t of
  314. OS_F32 :
  315. begin
  316. op:=A_FSTP;
  317. s:=S_FS;
  318. end;
  319. OS_F64 :
  320. begin
  321. op:=A_FSTP;
  322. s:=S_FL;
  323. end;
  324. OS_F80 :
  325. begin
  326. op:=A_FSTP;
  327. s:=S_FX;
  328. end;
  329. OS_C64 :
  330. begin
  331. op:=A_FISTP;
  332. s:=S_IQ;
  333. end;
  334. else
  335. internalerror(200204042);
  336. end;
  337. end;
  338. procedure tcgx86.floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  339. var
  340. op : tasmop;
  341. s : topsize;
  342. begin
  343. floatstoreops(t,op,s);
  344. list.concat(Taicpu.Op_ref(op,s,ref));
  345. dec_fpu_stack;
  346. end;
  347. procedure tcgx86.check_register_size(size:tcgsize;reg:tregister);
  348. begin
  349. if TCGSize2OpSize[size]<>TCGSize2OpSize[reg_cgsize(reg)] then
  350. internalerror(200306031);
  351. end;
  352. {****************************************************************************
  353. Assembler code
  354. ****************************************************************************}
  355. { currently does nothing }
  356. procedure tcgx86.a_jmp_always(list : taasmoutput;l: tasmlabel);
  357. begin
  358. a_jmp_cond(list, OC_NONE, l);
  359. end;
  360. { we implement the following routines because otherwise we can't }
  361. { instantiate the class since it's abstract }
  362. procedure tcgx86.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);
  363. begin
  364. check_register_size(size,r);
  365. if (locpara.loc=LOC_REFERENCE) and
  366. (locpara.reference.index=NR_STACK_POINTER_REG) then
  367. begin
  368. case size of
  369. OS_8,OS_S8,
  370. OS_16,OS_S16:
  371. begin
  372. if locpara.alignment = 2 then
  373. list.concat(taicpu.op_reg(A_PUSH,S_W,makeregsize(r,OS_16)))
  374. else
  375. list.concat(taicpu.op_reg(A_PUSH,S_L,makeregsize(r,OS_32)));
  376. end;
  377. OS_32,OS_S32:
  378. begin
  379. if getsubreg(r)<>R_SUBD then
  380. internalerror(7843);
  381. list.concat(taicpu.op_reg(A_PUSH,S_L,r));
  382. end
  383. else
  384. internalerror(2002032212);
  385. end;
  386. end
  387. else
  388. inherited a_param_reg(list,size,r,locpara);
  389. end;
  390. procedure tcgx86.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  391. begin
  392. if (locpara.loc=LOC_REFERENCE) and
  393. (locpara.reference.index=NR_STACK_POINTER_REG) then
  394. begin
  395. case size of
  396. OS_8,OS_S8,OS_16,OS_S16:
  397. begin
  398. if locpara.alignment = 2 then
  399. list.concat(taicpu.op_const(A_PUSH,S_W,a))
  400. else
  401. list.concat(taicpu.op_const(A_PUSH,S_L,a));
  402. end;
  403. OS_32,OS_S32:
  404. list.concat(taicpu.op_const(A_PUSH,S_L,a));
  405. else
  406. internalerror(2002032213);
  407. end;
  408. end
  409. else
  410. inherited a_param_const(list,size,a,locpara);
  411. end;
  412. procedure tcgx86.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  413. var
  414. pushsize : tcgsize;
  415. tmpreg : tregister;
  416. begin
  417. if (locpara.loc=LOC_REFERENCE) and
  418. (locpara.reference.index=NR_STACK_POINTER_REG) then
  419. begin
  420. case size of
  421. OS_8,OS_S8,
  422. OS_16,OS_S16:
  423. begin
  424. if locpara.alignment = 2 then
  425. pushsize:=OS_16
  426. else
  427. pushsize:=OS_32;
  428. tmpreg:=getintregister(list,pushsize);
  429. a_load_ref_reg(list,size,pushsize,r,tmpreg);
  430. list.concat(taicpu.op_reg(A_PUSH,TCgsize2opsize[pushsize],tmpreg));
  431. ungetregister(list,tmpreg);
  432. end;
  433. OS_32,OS_S32:
  434. list.concat(taicpu.op_ref(A_PUSH,S_L,r));
  435. {$ifdef cpu64bit}
  436. OS_64,OS_S64:
  437. list.concat(taicpu.op_ref(A_PUSH,S_Q,r));
  438. {$endif cpu64bit}
  439. else
  440. internalerror(2002032214);
  441. end;
  442. end
  443. else
  444. inherited a_param_ref(list,size,r,locpara);
  445. end;
  446. procedure tcgx86.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  447. var
  448. tmpreg : tregister;
  449. begin
  450. if (r.segment<>NR_NO) then
  451. CGMessage(cg_e_cant_use_far_pointer_there);
  452. if (locpara.loc=LOC_REFERENCE) and
  453. (locpara.reference.index=NR_STACK_POINTER_REG) then
  454. begin
  455. if (r.base=NR_NO) and (r.index=NR_NO) then
  456. begin
  457. if assigned(r.symbol) then
  458. list.concat(Taicpu.Op_sym_ofs(A_PUSH,S_L,r.symbol,r.offset))
  459. else
  460. list.concat(Taicpu.Op_const(A_PUSH,S_L,r.offset));
  461. end
  462. else if (r.base=NR_NO) and (r.index<>NR_NO) and
  463. (r.offset=0) and (r.scalefactor=0) and (r.symbol=nil) then
  464. list.concat(Taicpu.Op_reg(A_PUSH,S_L,r.index))
  465. else if (r.base<>NR_NO) and (r.index=NR_NO) and
  466. (r.offset=0) and (r.symbol=nil) then
  467. list.concat(Taicpu.Op_reg(A_PUSH,S_L,r.base))
  468. else
  469. begin
  470. tmpreg:=getaddressregister(list);
  471. a_loadaddr_ref_reg(list,r,tmpreg);
  472. ungetregister(list,tmpreg);
  473. list.concat(taicpu.op_reg(A_PUSH,S_L,tmpreg));
  474. end;
  475. end
  476. else
  477. inherited a_paramaddr_ref(list,r,locpara);
  478. end;
  479. procedure tcgx86.a_call_name(list : taasmoutput;const s : string);
  480. begin
  481. list.concat(taicpu.op_sym(A_CALL,S_NO,objectlibrary.newasmsymbol(s)));
  482. end;
  483. procedure tcgx86.a_call_reg(list : taasmoutput;reg : tregister);
  484. begin
  485. list.concat(taicpu.op_reg(A_CALL,S_NO,reg));
  486. end;
  487. {********************** load instructions ********************}
  488. procedure tcgx86.a_load_const_reg(list : taasmoutput; tosize: TCGSize; a : aword; reg : TRegister);
  489. begin
  490. check_register_size(tosize,reg);
  491. { the optimizer will change it to "xor reg,reg" when loading zero, }
  492. { no need to do it here too (JM) }
  493. list.concat(taicpu.op_const_reg(A_MOV,TCGSize2OpSize[tosize],a,reg))
  494. end;
  495. procedure tcgx86.a_load_const_ref(list : taasmoutput; tosize: tcgsize; a : aword;const ref : treference);
  496. begin
  497. list.concat(taicpu.op_const_ref(A_MOV,TCGSize2OpSize[tosize],a,ref));
  498. end;
  499. procedure tcgx86.a_load_reg_ref(list : taasmoutput; fromsize,tosize: TCGSize; reg : tregister;const ref : treference);
  500. var
  501. op: tasmop;
  502. s: topsize;
  503. tmpreg : tregister;
  504. begin
  505. check_register_size(fromsize,reg);
  506. sizes2load(fromsize,tosize,op,s);
  507. case s of
  508. S_BW,S_BL,S_WL
  509. {$ifdef x86_64}
  510. ,S_BQ,S_WQ,S_LQ
  511. {$endif x86_64}
  512. :
  513. begin
  514. tmpreg:=getintregister(list,tosize);
  515. list.concat(taicpu.op_reg_reg(op,s,reg,tmpreg));
  516. a_load_reg_ref(list,tosize,tosize,tmpreg,ref);
  517. ungetregister(list,tmpreg);
  518. end;
  519. else
  520. list.concat(taicpu.op_reg_ref(op,s,reg,ref));
  521. end;
  522. end;
  523. procedure tcgx86.a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  524. var
  525. op: tasmop;
  526. s: topsize;
  527. begin
  528. check_register_size(tosize,reg);
  529. sizes2load(fromsize,tosize,op,s);
  530. list.concat(taicpu.op_ref_reg(op,s,ref,reg));
  531. end;
  532. procedure tcgx86.a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);
  533. var
  534. op: tasmop;
  535. s: topsize;
  536. eq:boolean;
  537. instr:Taicpu;
  538. begin
  539. check_register_size(fromsize,reg1);
  540. check_register_size(tosize,reg2);
  541. sizes2load(fromsize,tosize,op,s);
  542. eq:=getsupreg(reg1)=getsupreg(reg2);
  543. if eq then
  544. begin
  545. { "mov reg1, reg1" doesn't make sense }
  546. if op = A_MOV then
  547. exit;
  548. end;
  549. instr:=taicpu.op_reg_reg(op,s,reg1,reg2);
  550. {Notify the register allocator that we have written a move instruction so
  551. it can try to eliminate it.}
  552. add_move_instruction(instr);
  553. list.concat(instr);
  554. end;
  555. procedure tcgx86.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  556. begin
  557. if (ref.base=NR_NO) and (ref.index=NR_NO) then
  558. begin
  559. if assigned(ref.symbol) then
  560. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,ref.symbol,ref.offset,r))
  561. else
  562. a_load_const_reg(list,OS_INT,ref.offset,r);
  563. end
  564. else if (ref.base=NR_NO) and (ref.index<>NR_NO) and
  565. (ref.offset=0) and (ref.scalefactor=0) and (ref.symbol=nil) then
  566. a_load_reg_reg(list,OS_INT,OS_INT,ref.index,r)
  567. else if (ref.base<>NR_NO) and (ref.index=NR_NO) and
  568. (ref.offset=0) and (ref.symbol=nil) then
  569. a_load_reg_reg(list,OS_INT,OS_INT,ref.base,r)
  570. else
  571. list.concat(taicpu.op_ref_reg(A_LEA,S_L,ref,r));
  572. end;
  573. { all fpu load routines expect that R_ST[0-7] means an fpu regvar and }
  574. { R_ST means "the current value at the top of the fpu stack" (JM) }
  575. procedure tcgx86.a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister);
  576. begin
  577. if (reg1<>NR_ST) then
  578. begin
  579. list.concat(taicpu.op_reg(A_FLD,S_NO,rgfpu.correct_fpuregister(reg1,rgfpu.fpuvaroffset)));
  580. inc_fpu_stack;
  581. end;
  582. if (reg2<>NR_ST) then
  583. begin
  584. list.concat(taicpu.op_reg(A_FSTP,S_NO,rgfpu.correct_fpuregister(reg2,rgfpu.fpuvaroffset)));
  585. dec_fpu_stack;
  586. end;
  587. end;
  588. procedure tcgx86.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  589. begin
  590. floatload(list,size,ref);
  591. if (reg<>NR_ST) then
  592. a_loadfpu_reg_reg(list,size,NR_ST,reg);
  593. end;
  594. procedure tcgx86.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  595. begin
  596. if reg<>NR_ST then
  597. a_loadfpu_reg_reg(list,size,reg,NR_ST);
  598. floatstore(list,size,ref);
  599. end;
  600. function get_scalar_mm_op(fromsize,tosize : tcgsize) : tasmop;
  601. begin
  602. case fromsize of
  603. OS_F32:
  604. case tosize of
  605. OS_F64:
  606. result:=A_CVTSS2SD;
  607. OS_F32:
  608. result:=A_MOVSS;
  609. else
  610. internalerror(200312205);
  611. end;
  612. OS_F64:
  613. case tosize of
  614. OS_F64:
  615. result:=A_MOVSD;
  616. OS_F32:
  617. result:=A_CVTSD2SS;
  618. else
  619. internalerror(200312204);
  620. end;
  621. else
  622. internalerror(200312203);
  623. end;
  624. end;
  625. procedure tcgx86.a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle);
  626. begin
  627. if shuffle=nil then
  628. begin
  629. if fromsize=tosize then
  630. list.concat(taicpu.op_reg_reg(A_MOVAPS,S_NO,reg1,reg2))
  631. else
  632. internalerror(200312202);
  633. end
  634. else
  635. begin
  636. if shufflescalar(shuffle) then
  637. list.concat(taicpu.op_reg_reg(get_scalar_mm_op(fromsize,tosize),S_NO,reg1,reg2))
  638. else
  639. internalerror(200312201);
  640. end;
  641. end;
  642. procedure tcgx86.a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  643. begin
  644. list.concat(taicpu.op_ref_reg(A_MOVQ,S_NO,ref,reg));
  645. end;
  646. procedure tcgx86.a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle);
  647. begin
  648. list.concat(taicpu.op_reg_ref(A_MOVQ,S_NO,reg,ref));
  649. end;
  650. procedure tcgx86.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  651. var
  652. l : tlocation;
  653. begin
  654. l.loc:=LOC_REFERENCE;
  655. l.reference:=ref;
  656. l.size:=size;
  657. opmm_loc_reg(list,op,size,l,reg,shuffle);
  658. end;
  659. procedure tcgx86.a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);
  660. var
  661. l : tlocation;
  662. begin
  663. l.loc:=LOC_REGISTER;
  664. l.register:=src;
  665. l.size:=size;
  666. opmm_loc_reg(list,op,size,l,dst,shuffle);
  667. end;
  668. procedure tcgx86.opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  669. const
  670. opmm2asmop : array[0..1,OS_F32..OS_F64,topcg] of tasmop = (
  671. ( { scalar }
  672. ( { OS_F32 }
  673. A_NOP,A_ADDSS,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_NOP
  674. ),
  675. { Intel did again a "nice" job: they added packed double operations (*PD) to SSE2 but
  676. no scalar ones (*SD)
  677. }
  678. {$ifdef x86_64}
  679. ( { OS_F64 }
  680. A_NOP,{!!! A_ADDSD}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_NOP,A_NOP
  681. )
  682. {$else x86_64}
  683. ( { OS_F64 }
  684. 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_NOP,A_NOP,A_NOP
  685. )
  686. {$endif x86_64}
  687. ),
  688. ( { vectorized/packed }
  689. ( { OS_F32 }
  690. 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_NOP
  691. ),
  692. ( { OS_F64 }
  693. 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_NOP
  694. )
  695. )
  696. );
  697. var
  698. resultreg : tregister;
  699. asmop : tasmop;
  700. begin
  701. { this is an internally used procedure so the parameters have
  702. some constrains
  703. }
  704. if loc.size<>size then
  705. internalerror(200312213);
  706. resultreg:=dst;
  707. { deshuffle }
  708. //!!!
  709. if (shuffle<>nil) and not(shufflescalar(shuffle)) then
  710. begin
  711. end
  712. else if (shuffle=nil) then
  713. asmop:=opmm2asmop[1,size,op]
  714. else if shufflescalar(shuffle) then
  715. begin
  716. asmop:=opmm2asmop[0,size,op];
  717. { no scalar operation available? }
  718. if asmop=A_NOP then
  719. begin
  720. { do vectorized and shuffle finally }
  721. //!!!
  722. end;
  723. end
  724. else
  725. internalerror(200312211);
  726. if asmop=A_NOP then
  727. internalerror(200312215);
  728. case loc.loc of
  729. LOC_CREFERENCE,LOC_REFERENCE:
  730. list.concat(taicpu.op_ref_reg(asmop,S_NO,loc.reference,resultreg));
  731. LOC_CMMREGISTER,LOC_MMREGISTER:
  732. list.concat(taicpu.op_reg_reg(asmop,S_NO,loc.register,resultreg));
  733. else
  734. internalerror(200312214);
  735. end;
  736. { shuffle }
  737. if resultreg<>dst then
  738. begin
  739. internalerror(200312212);
  740. end;
  741. end;
  742. procedure tcgx86.a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister);
  743. var
  744. opcode: tasmop;
  745. power: longint;
  746. begin
  747. check_register_size(size,reg);
  748. case op of
  749. OP_DIV, OP_IDIV:
  750. begin
  751. if ispowerof2(a,power) then
  752. begin
  753. case op of
  754. OP_DIV:
  755. opcode := A_SHR;
  756. OP_IDIV:
  757. opcode := A_SAR;
  758. end;
  759. list.concat(taicpu.op_const_reg(opcode,TCgSize2OpSize[size],power,reg));
  760. exit;
  761. end;
  762. { the rest should be handled specifically in the code }
  763. { generator because of the silly register usage restraints }
  764. internalerror(200109224);
  765. end;
  766. OP_MUL,OP_IMUL:
  767. begin
  768. if not(cs_check_overflow in aktlocalswitches) and
  769. ispowerof2(a,power) then
  770. begin
  771. list.concat(taicpu.op_const_reg(A_SHL,TCgSize2OpSize[size],power,reg));
  772. exit;
  773. end;
  774. if op = OP_IMUL then
  775. list.concat(taicpu.op_const_reg(A_IMUL,TCgSize2OpSize[size],a,reg))
  776. else
  777. { OP_MUL should be handled specifically in the code }
  778. { generator because of the silly register usage restraints }
  779. internalerror(200109225);
  780. end;
  781. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  782. if not(cs_check_overflow in aktlocalswitches) and
  783. (a = 1) and
  784. (op in [OP_ADD,OP_SUB]) then
  785. if op = OP_ADD then
  786. list.concat(taicpu.op_reg(A_INC,TCgSize2OpSize[size],reg))
  787. else
  788. list.concat(taicpu.op_reg(A_DEC,TCgSize2OpSize[size],reg))
  789. else if (a = 0) then
  790. if (op <> OP_AND) then
  791. exit
  792. else
  793. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],0,reg))
  794. else if (a = high(aword)) and
  795. (op in [OP_AND,OP_OR,OP_XOR]) then
  796. begin
  797. case op of
  798. OP_AND:
  799. exit;
  800. OP_OR:
  801. list.concat(taicpu.op_const_reg(A_MOV,TCgSize2OpSize[size],high(aword),reg));
  802. OP_XOR:
  803. list.concat(taicpu.op_reg(A_NOT,TCgSize2OpSize[size],reg));
  804. end
  805. end
  806. else
  807. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a,reg));
  808. OP_SHL,OP_SHR,OP_SAR:
  809. begin
  810. if (a and 31) <> 0 Then
  811. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,reg));
  812. if (a shr 5) <> 0 Then
  813. internalerror(68991);
  814. end
  815. else internalerror(68992);
  816. end;
  817. end;
  818. procedure tcgx86.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference);
  819. var
  820. opcode: tasmop;
  821. power: longint;
  822. begin
  823. Case Op of
  824. OP_DIV, OP_IDIV:
  825. Begin
  826. if ispowerof2(a,power) then
  827. begin
  828. case op of
  829. OP_DIV:
  830. opcode := A_SHR;
  831. OP_IDIV:
  832. opcode := A_SAR;
  833. end;
  834. list.concat(taicpu.op_const_ref(opcode,
  835. TCgSize2OpSize[size],power,ref));
  836. exit;
  837. end;
  838. { the rest should be handled specifically in the code }
  839. { generator because of the silly register usage restraints }
  840. internalerror(200109231);
  841. End;
  842. OP_MUL,OP_IMUL:
  843. begin
  844. if not(cs_check_overflow in aktlocalswitches) and
  845. ispowerof2(a,power) then
  846. begin
  847. list.concat(taicpu.op_const_ref(A_SHL,TCgSize2OpSize[size],
  848. power,ref));
  849. exit;
  850. end;
  851. { can't multiply a memory location directly with a constant }
  852. if op = OP_IMUL then
  853. inherited a_op_const_ref(list,op,size,a,ref)
  854. else
  855. { OP_MUL should be handled specifically in the code }
  856. { generator because of the silly register usage restraints }
  857. internalerror(200109232);
  858. end;
  859. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  860. if not(cs_check_overflow in aktlocalswitches) and
  861. (a = 1) and
  862. (op in [OP_ADD,OP_SUB]) then
  863. if op = OP_ADD then
  864. list.concat(taicpu.op_ref(A_INC,TCgSize2OpSize[size],ref))
  865. else
  866. list.concat(taicpu.op_ref(A_DEC,TCgSize2OpSize[size],ref))
  867. else if (a = 0) then
  868. if (op <> OP_AND) then
  869. exit
  870. else
  871. a_load_const_ref(list,size,0,ref)
  872. else if (a = high(aword)) and
  873. (op in [OP_AND,OP_OR,OP_XOR]) then
  874. begin
  875. case op of
  876. OP_AND:
  877. exit;
  878. OP_OR:
  879. list.concat(taicpu.op_const_ref(A_MOV,TCgSize2OpSize[size],high(aword),ref));
  880. OP_XOR:
  881. list.concat(taicpu.op_ref(A_NOT,TCgSize2OpSize[size],ref));
  882. end
  883. end
  884. else
  885. list.concat(taicpu.op_const_ref(TOpCG2AsmOp[op],
  886. TCgSize2OpSize[size],a,ref));
  887. OP_SHL,OP_SHR,OP_SAR:
  888. begin
  889. if (a and 31) <> 0 then
  890. list.concat(taicpu.op_const_ref(
  891. TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,ref));
  892. if (a shr 5) <> 0 Then
  893. internalerror(68991);
  894. end
  895. else internalerror(68992);
  896. end;
  897. end;
  898. procedure tcgx86.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  899. var
  900. dstsize: topsize;
  901. instr:Taicpu;
  902. begin
  903. check_register_size(size,src);
  904. check_register_size(size,dst);
  905. dstsize := tcgsize2opsize[size];
  906. case op of
  907. OP_NEG,OP_NOT:
  908. begin
  909. if src<>dst then
  910. a_load_reg_reg(list,size,size,src,dst);
  911. list.concat(taicpu.op_reg(TOpCG2AsmOp[op],dstsize,dst));
  912. end;
  913. OP_MUL,OP_DIV,OP_IDIV:
  914. { special stuff, needs separate handling inside code }
  915. { generator }
  916. internalerror(200109233);
  917. OP_SHR,OP_SHL,OP_SAR:
  918. begin
  919. getexplicitregister(list,NR_CL);
  920. a_load_reg_reg(list,size,OS_8,dst,NR_CL);
  921. list.concat(taicpu.op_reg_reg(Topcg2asmop[op],S_B,src,NR_CL));
  922. ungetregister(list,NR_CL);
  923. end;
  924. else
  925. begin
  926. if reg2opsize(src) <> dstsize then
  927. internalerror(200109226);
  928. instr:=taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,src,dst);
  929. list.concat(instr);
  930. end;
  931. end;
  932. end;
  933. procedure tcgx86.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  934. begin
  935. check_register_size(size,reg);
  936. case op of
  937. OP_NEG,OP_NOT,OP_IMUL:
  938. begin
  939. inherited a_op_ref_reg(list,op,size,ref,reg);
  940. end;
  941. OP_MUL,OP_DIV,OP_IDIV:
  942. { special stuff, needs separate handling inside code }
  943. { generator }
  944. internalerror(200109239);
  945. else
  946. begin
  947. reg := makeregsize(reg,size);
  948. list.concat(taicpu.op_ref_reg(TOpCG2AsmOp[op],tcgsize2opsize[size],ref,reg));
  949. end;
  950. end;
  951. end;
  952. procedure tcgx86.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  953. begin
  954. check_register_size(size,reg);
  955. case op of
  956. OP_NEG,OP_NOT:
  957. begin
  958. if reg<>NR_NO then
  959. internalerror(200109237);
  960. list.concat(taicpu.op_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],ref));
  961. end;
  962. OP_IMUL:
  963. begin
  964. { this one needs a load/imul/store, which is the default }
  965. inherited a_op_ref_reg(list,op,size,ref,reg);
  966. end;
  967. OP_MUL,OP_DIV,OP_IDIV:
  968. { special stuff, needs separate handling inside code }
  969. { generator }
  970. internalerror(200109238);
  971. else
  972. begin
  973. list.concat(taicpu.op_reg_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],reg,ref));
  974. end;
  975. end;
  976. end;
  977. procedure tcgx86.a_op_const_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; a: aword; src, dst: tregister);
  978. var
  979. tmpref: treference;
  980. power: longint;
  981. begin
  982. check_register_size(size,src);
  983. check_register_size(size,dst);
  984. if not (size in [OS_32,OS_S32]) then
  985. begin
  986. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  987. exit;
  988. end;
  989. { if we get here, we have to do a 32 bit calculation, guaranteed }
  990. case op of
  991. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  992. OP_SAR:
  993. { can't do anything special for these }
  994. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  995. OP_IMUL:
  996. begin
  997. if not(cs_check_overflow in aktlocalswitches) and
  998. ispowerof2(a,power) then
  999. { can be done with a shift }
  1000. begin
  1001. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  1002. exit;
  1003. end;
  1004. list.concat(taicpu.op_const_reg_reg(A_IMUL,S_L,a,src,dst));
  1005. end;
  1006. OP_ADD, OP_SUB:
  1007. if (a = 0) then
  1008. a_load_reg_reg(list,size,size,src,dst)
  1009. else
  1010. begin
  1011. reference_reset(tmpref);
  1012. tmpref.base := src;
  1013. tmpref.offset := longint(a);
  1014. if op = OP_SUB then
  1015. tmpref.offset := -tmpref.offset;
  1016. list.concat(taicpu.op_ref_reg(A_LEA,S_L,tmpref,dst));
  1017. end
  1018. else internalerror(200112302);
  1019. end;
  1020. end;
  1021. procedure tcgx86.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;size: tcgsize; src1, src2, dst: tregister);
  1022. var
  1023. tmpref: treference;
  1024. begin
  1025. check_register_size(size,src1);
  1026. check_register_size(size,src2);
  1027. check_register_size(size,dst);
  1028. if not(size in [OS_32,OS_S32]) then
  1029. begin
  1030. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  1031. exit;
  1032. end;
  1033. { if we get here, we have to do a 32 bit calculation, guaranteed }
  1034. Case Op of
  1035. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  1036. OP_SAR,OP_SUB,OP_NOT,OP_NEG:
  1037. { can't do anything special for these }
  1038. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  1039. OP_IMUL:
  1040. list.concat(taicpu.op_reg_reg_reg(A_IMUL,S_L,src1,src2,dst));
  1041. OP_ADD:
  1042. begin
  1043. reference_reset(tmpref);
  1044. tmpref.base := src1;
  1045. tmpref.index := src2;
  1046. tmpref.scalefactor := 1;
  1047. list.concat(taicpu.op_ref_reg(A_LEA,S_L,tmpref,dst));
  1048. end
  1049. else internalerror(200112303);
  1050. end;
  1051. end;
  1052. {*************** compare instructructions ****************}
  1053. procedure tcgx86.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  1054. l : tasmlabel);
  1055. begin
  1056. if (a = 0) then
  1057. list.concat(taicpu.op_reg_reg(A_TEST,tcgsize2opsize[size],reg,reg))
  1058. else
  1059. list.concat(taicpu.op_const_reg(A_CMP,tcgsize2opsize[size],a,reg));
  1060. a_jmp_cond(list,cmp_op,l);
  1061. end;
  1062. procedure tcgx86.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  1063. l : tasmlabel);
  1064. begin
  1065. list.concat(taicpu.op_const_ref(A_CMP,TCgSize2OpSize[size],a,ref));
  1066. a_jmp_cond(list,cmp_op,l);
  1067. end;
  1068. procedure tcgx86.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  1069. reg1,reg2 : tregister;l : tasmlabel);
  1070. begin
  1071. check_register_size(size,reg1);
  1072. check_register_size(size,reg2);
  1073. list.concat(taicpu.op_reg_reg(A_CMP,TCgSize2OpSize[size],reg1,reg2));
  1074. a_jmp_cond(list,cmp_op,l);
  1075. end;
  1076. procedure tcgx86.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference; reg : tregister;l : tasmlabel);
  1077. begin
  1078. check_register_size(size,reg);
  1079. list.concat(taicpu.op_ref_reg(A_CMP,TCgSize2OpSize[size],ref,reg));
  1080. a_jmp_cond(list,cmp_op,l);
  1081. end;
  1082. procedure tcgx86.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  1083. var
  1084. ai : taicpu;
  1085. begin
  1086. if cond=OC_None then
  1087. ai := Taicpu.Op_sym(A_JMP,S_NO,l)
  1088. else
  1089. begin
  1090. ai:=Taicpu.Op_sym(A_Jcc,S_NO,l);
  1091. ai.SetCondition(TOpCmp2AsmCond[cond]);
  1092. end;
  1093. ai.is_jmp:=true;
  1094. list.concat(ai);
  1095. end;
  1096. procedure tcgx86.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  1097. var
  1098. ai : taicpu;
  1099. begin
  1100. ai := Taicpu.op_sym(A_Jcc,S_NO,l);
  1101. ai.SetCondition(flags_to_cond(f));
  1102. ai.is_jmp := true;
  1103. list.concat(ai);
  1104. end;
  1105. procedure tcgx86.g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister);
  1106. var
  1107. ai : taicpu;
  1108. hreg : tregister;
  1109. begin
  1110. hreg:=makeregsize(reg,OS_8);
  1111. ai:=Taicpu.op_reg(A_SETcc,S_B,hreg);
  1112. ai.setcondition(flags_to_cond(f));
  1113. list.concat(ai);
  1114. if (reg<>hreg) then
  1115. a_load_reg_reg(list,OS_8,size,hreg,reg);
  1116. end;
  1117. procedure tcgx86.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref: TReference);
  1118. var
  1119. ai : taicpu;
  1120. begin
  1121. if not(size in [OS_8,OS_S8]) then
  1122. a_load_const_ref(list,size,0,ref);
  1123. ai:=Taicpu.op_ref(A_SETcc,S_B,ref);
  1124. ai.setcondition(flags_to_cond(f));
  1125. list.concat(ai);
  1126. end;
  1127. { ************* concatcopy ************ }
  1128. procedure Tcgx86.g_concatcopy(list:Taasmoutput;const source,dest:Treference;
  1129. len:aword;delsource,loadref:boolean);
  1130. type copymode=(copy_move,copy_mmx,copy_string);
  1131. var srcref,dstref:Treference;
  1132. r,r0,r1,r2,r3:Tregister;
  1133. helpsize:aword;
  1134. copysize:byte;
  1135. cgsize:Tcgsize;
  1136. cm:copymode;
  1137. begin
  1138. cm:=copy_move;
  1139. helpsize:=12;
  1140. if cs_littlesize in aktglobalswitches then
  1141. helpsize:=8;
  1142. if (cs_mmx in aktlocalswitches) and
  1143. not(pi_uses_fpu in current_procinfo.flags) and
  1144. ((len=8) or (len=16) or (len=24) or (len=32)) then
  1145. cm:=copy_mmx;
  1146. if (cs_littlesize in aktglobalswitches) and
  1147. (len>helpsize) and
  1148. not((len<=16) and (cm=copy_mmx)) then
  1149. cm:=copy_string;
  1150. if loadref then
  1151. cm:=copy_string;
  1152. case cm of
  1153. copy_move:
  1154. begin
  1155. dstref:=dest;
  1156. srcref:=source;
  1157. copysize:=4;
  1158. cgsize:=OS_32;
  1159. while len<>0 do
  1160. begin
  1161. if len<2 then
  1162. begin
  1163. copysize:=1;
  1164. cgsize:=OS_8;
  1165. end
  1166. else if len<4 then
  1167. begin
  1168. copysize:=2;
  1169. cgsize:=OS_16;
  1170. end;
  1171. dec(len,copysize);
  1172. if (len=0) and delsource then
  1173. reference_release(list,source);
  1174. r:=getintregister(list,cgsize);
  1175. a_load_ref_reg(list,cgsize,cgsize,srcref,r);
  1176. ungetregister(list,r);
  1177. a_load_reg_ref(list,cgsize,cgsize,r,dstref);
  1178. inc(srcref.offset,copysize);
  1179. inc(dstref.offset,copysize);
  1180. end;
  1181. end;
  1182. copy_mmx:
  1183. begin
  1184. dstref:=dest;
  1185. srcref:=source;
  1186. r0:=getmmxregister(list);
  1187. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r0,nil);
  1188. if len>=16 then
  1189. begin
  1190. inc(srcref.offset,8);
  1191. r1:=getmmxregister(list);
  1192. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r1,nil);
  1193. end;
  1194. if len>=24 then
  1195. begin
  1196. inc(srcref.offset,8);
  1197. r2:=getmmxregister(list);
  1198. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r2,nil);
  1199. end;
  1200. if len>=32 then
  1201. begin
  1202. inc(srcref.offset,8);
  1203. r3:=getmmxregister(list);
  1204. a_loadmm_ref_reg(list,OS_M64,OS_M64,srcref,r3,nil);
  1205. end;
  1206. a_loadmm_reg_ref(list,OS_M64,OS_M64,r0,dstref,nil);
  1207. ungetregister(list,r0);
  1208. if len>=16 then
  1209. begin
  1210. inc(dstref.offset,8);
  1211. a_loadmm_reg_ref(list,OS_M64,OS_M64,r1,dstref,nil);
  1212. ungetregister(list,r1);
  1213. end;
  1214. if len>=24 then
  1215. begin
  1216. inc(dstref.offset,8);
  1217. a_loadmm_reg_ref(list,OS_M64,OS_M64,r2,dstref,nil);
  1218. ungetregister(list,r2);
  1219. end;
  1220. if len>=32 then
  1221. begin
  1222. inc(dstref.offset,8);
  1223. a_loadmm_reg_ref(list,OS_M64,OS_M64,r3,dstref,nil);
  1224. ungetregister(list,r3);
  1225. end;
  1226. end
  1227. else {copy_string, should be a good fallback in case of unhandled}
  1228. begin
  1229. getexplicitregister(list,NR_EDI);
  1230. a_loadaddr_ref_reg(list,dest,NR_EDI);
  1231. getexplicitregister(list,NR_ESI);
  1232. if loadref then
  1233. a_load_ref_reg(list,OS_ADDR,OS_ADDR,source,NR_ESI)
  1234. else
  1235. begin
  1236. a_loadaddr_ref_reg(list,source,NR_ESI);
  1237. if delsource then
  1238. begin
  1239. srcref:=source;
  1240. { Don't release ESI register yet, it's needed
  1241. by the movsl }
  1242. if (srcref.base=NR_ESI) then
  1243. srcref.base:=NR_NO
  1244. else if (srcref.index=NR_ESI) then
  1245. srcref.index:=NR_NO;
  1246. reference_release(list,srcref);
  1247. end;
  1248. end;
  1249. getexplicitregister(list,NR_ECX);
  1250. list.concat(Taicpu.op_none(A_CLD,S_NO));
  1251. if cs_littlesize in aktglobalswitches then
  1252. begin
  1253. a_load_const_reg(list,OS_INT,len,NR_ECX);
  1254. list.concat(Taicpu.op_none(A_REP,S_NO));
  1255. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1256. end
  1257. else
  1258. begin
  1259. helpsize:=len shr 2;
  1260. len:=len and 3;
  1261. if helpsize>1 then
  1262. begin
  1263. a_load_const_reg(list,OS_INT,helpsize,NR_ECX);
  1264. list.concat(Taicpu.op_none(A_REP,S_NO));
  1265. end;
  1266. if helpsize>0 then
  1267. list.concat(Taicpu.op_none(A_MOVSD,S_NO));
  1268. if len>1 then
  1269. begin
  1270. dec(len,2);
  1271. list.concat(Taicpu.op_none(A_MOVSW,S_NO));
  1272. end;
  1273. if len=1 then
  1274. list.concat(Taicpu.op_none(A_MOVSB,S_NO));
  1275. end;
  1276. ungetregister(list,NR_ECX);
  1277. ungetregister(list,NR_ESI);
  1278. ungetregister(list,NR_EDI);
  1279. end;
  1280. end;
  1281. if delsource then
  1282. tg.ungetiftemp(list,source);
  1283. end;
  1284. procedure tcgx86.g_exception_reason_save(list : taasmoutput; const href : treference);
  1285. begin
  1286. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1287. end;
  1288. procedure tcgx86.g_exception_reason_save_const(list : taasmoutput;const href : treference; a: aword);
  1289. begin
  1290. list.concat(Taicpu.op_const(A_PUSH,S_L,a));
  1291. end;
  1292. procedure tcgx86.g_exception_reason_load(list : taasmoutput; const href : treference);
  1293. begin
  1294. list.concat(Taicpu.op_reg(A_POP,S_L,NR_EAX));
  1295. end;
  1296. {****************************************************************************
  1297. Entry/Exit Code Helpers
  1298. ****************************************************************************}
  1299. procedure tcgx86.g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:aword);
  1300. var
  1301. power,len : longint;
  1302. opsize : topsize;
  1303. {$ifndef __NOWINPECOFF__}
  1304. again,ok : tasmlabel;
  1305. {$endif}
  1306. begin
  1307. { get stack space }
  1308. getexplicitregister(list,NR_EDI);
  1309. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,NR_EDI));
  1310. list.concat(Taicpu.op_reg(A_INC,S_L,NR_EDI));
  1311. if (elesize<>1) then
  1312. begin
  1313. if ispowerof2(elesize, power) then
  1314. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,NR_EDI))
  1315. else
  1316. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,NR_EDI));
  1317. end;
  1318. {$ifndef __NOWINPECOFF__}
  1319. { windows guards only a few pages for stack growing, }
  1320. { so we have to access every page first }
  1321. if target_info.system=system_i386_win32 then
  1322. begin
  1323. objectlibrary.getlabel(again);
  1324. objectlibrary.getlabel(ok);
  1325. a_label(list,again);
  1326. list.concat(Taicpu.op_const_reg(A_CMP,S_L,winstackpagesize,NR_EDI));
  1327. a_jmp_cond(list,OC_B,ok);
  1328. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,NR_ESP));
  1329. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EDI));
  1330. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize,NR_EDI));
  1331. a_jmp_always(list,again);
  1332. a_label(list,ok);
  1333. list.concat(Taicpu.op_reg_reg(A_SUB,S_L,NR_EDI,NR_ESP));
  1334. ungetregister(list,NR_EDI);
  1335. { now reload EDI }
  1336. getexplicitregister(list,NR_EDI);
  1337. list.concat(Taicpu.op_ref_reg(A_MOV,S_L,lenref,NR_EDI));
  1338. list.concat(Taicpu.op_reg(A_INC,S_L,NR_EDI));
  1339. if (elesize<>1) then
  1340. begin
  1341. if ispowerof2(elesize, power) then
  1342. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,NR_EDI))
  1343. else
  1344. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,elesize,NR_EDI));
  1345. end;
  1346. end
  1347. else
  1348. {$endif __NOWINPECOFF__}
  1349. list.concat(Taicpu.op_reg_reg(A_SUB,S_L,NR_EDI,NR_ESP));
  1350. { align stack on 4 bytes }
  1351. list.concat(Taicpu.op_const_reg(A_AND,S_L,$fffffff4,NR_ESP));
  1352. { load destination }
  1353. a_load_reg_reg(list,OS_INT,OS_INT,NR_ESP,NR_EDI);
  1354. { Allocate other registers }
  1355. getexplicitregister(list,NR_ECX);
  1356. getexplicitregister(list,NR_ESI);
  1357. { load count }
  1358. a_load_ref_reg(list,OS_INT,OS_INT,lenref,NR_ECX);
  1359. { load source }
  1360. a_load_ref_reg(list,OS_INT,OS_INT,ref,NR_ESI);
  1361. { scheduled .... }
  1362. list.concat(Taicpu.op_reg(A_INC,S_L,NR_ECX));
  1363. { calculate size }
  1364. len:=elesize;
  1365. opsize:=S_B;
  1366. if (len and 3)=0 then
  1367. begin
  1368. opsize:=S_L;
  1369. len:=len shr 2;
  1370. end
  1371. else
  1372. if (len and 1)=0 then
  1373. begin
  1374. opsize:=S_W;
  1375. len:=len shr 1;
  1376. end;
  1377. if ispowerof2(len, power) then
  1378. list.concat(Taicpu.op_const_reg(A_SHL,S_L,power,NR_ECX))
  1379. else
  1380. list.concat(Taicpu.op_const_reg(A_IMUL,S_L,len,NR_ECX));
  1381. list.concat(Taicpu.op_none(A_REP,S_NO));
  1382. case opsize of
  1383. S_B : list.concat(Taicpu.Op_none(A_MOVSB,S_NO));
  1384. S_W : list.concat(Taicpu.Op_none(A_MOVSW,S_NO));
  1385. S_L : list.concat(Taicpu.Op_none(A_MOVSD,S_NO));
  1386. end;
  1387. ungetregister(list,NR_EDI);
  1388. ungetregister(list,NR_ECX);
  1389. ungetregister(list,NR_ESI);
  1390. { patch the new address }
  1391. a_load_reg_ref(list,OS_INT,OS_INT,NR_ESP,ref);
  1392. end;
  1393. procedure tcgx86.g_interrupt_stackframe_entry(list : taasmoutput);
  1394. begin
  1395. { .... also the segment registers }
  1396. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_GS));
  1397. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_FS));
  1398. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_ES));
  1399. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_DS));
  1400. { save the registers of an interrupt procedure }
  1401. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDI));
  1402. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ESI));
  1403. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1404. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ECX));
  1405. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EBX));
  1406. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EAX));
  1407. end;
  1408. procedure tcgx86.g_interrupt_stackframe_exit(list : taasmoutput;accused,acchiused:boolean);
  1409. begin
  1410. if accused then
  1411. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,NR_ESP))
  1412. else
  1413. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EAX));
  1414. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EBX));
  1415. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_ECX));
  1416. if acchiused then
  1417. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,NR_ESP))
  1418. else
  1419. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EDX));
  1420. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_ESI));
  1421. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EDI));
  1422. { .... also the segment registers }
  1423. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_DS));
  1424. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_ES));
  1425. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_FS));
  1426. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_GS));
  1427. { this restores the flags }
  1428. list.concat(Taicpu.Op_none(A_IRET,S_NO));
  1429. end;
  1430. procedure tcgx86.g_profilecode(list : taasmoutput);
  1431. var
  1432. pl : tasmlabel;
  1433. mcountprefix : String[4];
  1434. begin
  1435. case target_info.system of
  1436. {$ifndef NOTARGETWIN32}
  1437. system_i386_win32,
  1438. {$endif}
  1439. system_i386_freebsd,
  1440. system_i386_netbsd,
  1441. // system_i386_openbsd,
  1442. system_i386_wdosx,
  1443. system_i386_linux:
  1444. begin
  1445. Case target_info.system Of
  1446. system_i386_freebsd : mcountprefix:='.';
  1447. system_i386_netbsd : mcountprefix:='__';
  1448. // system_i386_openbsd : mcountprefix:='.';
  1449. else
  1450. mcountPrefix:='';
  1451. end;
  1452. objectlibrary.getaddrlabel(pl);
  1453. list.concat(Tai_section.Create(sec_data));
  1454. list.concat(Tai_align.Create(4));
  1455. list.concat(Tai_label.Create(pl));
  1456. list.concat(Tai_const.Create_32bit(0));
  1457. list.concat(Tai_section.Create(sec_code));
  1458. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,pl,0,NR_EDX));
  1459. a_call_name(list,target_info.Cprefix+mcountprefix+'mcount');
  1460. include(rg[R_INTREGISTER].used_in_proc,RS_EDX);
  1461. end;
  1462. system_i386_go32v2,system_i386_watcom:
  1463. begin
  1464. a_call_name(list,'MCOUNT');
  1465. end;
  1466. end;
  1467. end;
  1468. procedure tcgx86.g_stackpointer_alloc(list : taasmoutput;localsize : longint);
  1469. var
  1470. href : treference;
  1471. i : integer;
  1472. again : tasmlabel;
  1473. begin
  1474. if localsize>0 then
  1475. begin
  1476. {$ifndef NOTARGETWIN32}
  1477. { windows guards only a few pages for stack growing, }
  1478. { so we have to access every page first }
  1479. if (target_info.system=system_i386_win32) and
  1480. (localsize>=winstackpagesize) then
  1481. begin
  1482. if localsize div winstackpagesize<=5 then
  1483. begin
  1484. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize-4,NR_ESP));
  1485. for i:=1 to localsize div winstackpagesize do
  1486. begin
  1487. reference_reset_base(href,NR_ESP,localsize-i*winstackpagesize);
  1488. list.concat(Taicpu.op_const_ref(A_MOV,S_L,0,href));
  1489. end;
  1490. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1491. end
  1492. else
  1493. begin
  1494. objectlibrary.getlabel(again);
  1495. getexplicitregister(list,NR_EDI);
  1496. list.concat(Taicpu.op_const_reg(A_MOV,S_L,localsize div winstackpagesize,NR_EDI));
  1497. a_label(list,again);
  1498. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,NR_ESP));
  1499. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1500. list.concat(Taicpu.op_reg(A_DEC,S_L,NR_EDI));
  1501. a_jmp_cond(list,OC_NE,again);
  1502. ungetregister(list,NR_EDI);
  1503. list.concat(Taicpu.op_const_reg(A_SUB,S_L,localsize mod winstackpagesize,NR_ESP));
  1504. end
  1505. end
  1506. else
  1507. {$endif NOTARGETWIN32}
  1508. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize,NR_ESP));
  1509. end;
  1510. end;
  1511. procedure tcgx86.g_stackframe_entry(list : taasmoutput;localsize : longint);
  1512. begin
  1513. list.concat(tai_regalloc.alloc(NR_EBP));
  1514. include(rg[R_INTREGISTER].preserved_by_proc,RS_EBP);
  1515. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EBP));
  1516. list.concat(Taicpu.op_reg_reg(A_MOV,S_L,NR_ESP,NR_EBP));
  1517. if localsize>0 then
  1518. g_stackpointer_alloc(list,localsize);
  1519. if cs_create_pic in aktmoduleswitches then
  1520. begin
  1521. a_call_name(list,'FPC_GETEIPINEBX');
  1522. list.concat(taicpu.op_sym_ofs_reg(A_ADD,S_L,objectlibrary.newasmsymboldata('_GLOBAL_OFFSET_TABLE_'),0,NR_EBX));
  1523. list.concat(tai_regalloc.alloc(NR_EBX));
  1524. end;
  1525. end;
  1526. procedure tcgx86.g_restore_frame_pointer(list : taasmoutput);
  1527. begin
  1528. if cs_create_pic in aktmoduleswitches then
  1529. list.concat(tai_regalloc.dealloc(NR_EBX));
  1530. list.concat(tai_regalloc.dealloc(NR_EBP));
  1531. list.concat(Taicpu.op_none(A_LEAVE,S_NO));
  1532. if assigned(rg[R_MMXREGISTER]) and (rg[R_MMXREGISTER].uses_registers) then
  1533. list.concat(Taicpu.op_none(A_EMMS,S_NO));
  1534. end;
  1535. procedure tcgx86.g_return_from_proc(list : taasmoutput;parasize : aword);
  1536. begin
  1537. { Routines with the poclearstack flag set use only a ret }
  1538. { also routines with parasize=0 }
  1539. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1540. begin
  1541. { complex return values are removed from stack in C code PM }
  1542. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,
  1543. current_procinfo.procdef.proccalloption) then
  1544. list.concat(Taicpu.Op_const(A_RET,S_NO,4))
  1545. else
  1546. list.concat(Taicpu.Op_none(A_RET,S_NO));
  1547. end
  1548. else if (parasize=0) then
  1549. list.concat(Taicpu.Op_none(A_RET,S_NO))
  1550. else
  1551. begin
  1552. { parameters are limited to 65535 bytes because }
  1553. { ret allows only imm16 }
  1554. if (parasize>65535) then
  1555. CGMessage(cg_e_parasize_too_big);
  1556. list.concat(Taicpu.Op_const(A_RET,S_NO,parasize));
  1557. end;
  1558. end;
  1559. procedure tcgx86.g_save_standard_registers(list:Taasmoutput);
  1560. var
  1561. href : treference;
  1562. size : longint;
  1563. begin
  1564. { Get temp }
  1565. size:=0;
  1566. if RS_EBX in rg[R_INTREGISTER].used_in_proc then
  1567. inc(size,POINTER_SIZE);
  1568. if RS_ESI in rg[R_INTREGISTER].used_in_proc then
  1569. inc(size,POINTER_SIZE);
  1570. if RS_EDI in rg[R_INTREGISTER].used_in_proc then
  1571. inc(size,POINTER_SIZE);
  1572. if size>0 then
  1573. begin
  1574. tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
  1575. { Copy registers to temp }
  1576. href:=current_procinfo.save_regs_ref;
  1577. if RS_EBX in rg[R_INTREGISTER].used_in_proc then
  1578. begin
  1579. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_EBX,href);
  1580. inc(href.offset,POINTER_SIZE);
  1581. end;
  1582. if RS_ESI in rg[R_INTREGISTER].used_in_proc then
  1583. begin
  1584. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_ESI,href);
  1585. inc(href.offset,POINTER_SIZE);
  1586. end;
  1587. if RS_EDI in rg[R_INTREGISTER].used_in_proc then
  1588. begin
  1589. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_EDI,href);
  1590. inc(href.offset,POINTER_SIZE);
  1591. end;
  1592. end;
  1593. include(rg[R_INTREGISTER].preserved_by_proc,RS_EBX);
  1594. include(rg[R_INTREGISTER].preserved_by_proc,RS_ESI);
  1595. include(rg[R_INTREGISTER].preserved_by_proc,RS_EDI);
  1596. end;
  1597. procedure tcgx86.g_restore_standard_registers(list:Taasmoutput);
  1598. var
  1599. href : treference;
  1600. begin
  1601. { Copy registers from temp }
  1602. href:=current_procinfo.save_regs_ref;
  1603. if RS_EBX in rg[R_INTREGISTER].used_in_proc then
  1604. begin
  1605. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_EBX);
  1606. inc(href.offset,POINTER_SIZE);
  1607. end;
  1608. if RS_ESI in rg[R_INTREGISTER].used_in_proc then
  1609. begin
  1610. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_ESI);
  1611. inc(href.offset,POINTER_SIZE);
  1612. end;
  1613. if RS_EDI in rg[R_INTREGISTER].used_in_proc then
  1614. begin
  1615. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_EDI);
  1616. inc(href.offset,POINTER_SIZE);
  1617. end;
  1618. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1619. end;
  1620. procedure tcgx86.g_save_all_registers(list : taasmoutput);
  1621. begin
  1622. list.concat(Taicpu.Op_none(A_PUSHA,S_L));
  1623. tg.GetTemp(list,POINTER_SIZE,tt_noreuse,current_procinfo.save_regs_ref);
  1624. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_ESP,current_procinfo.save_regs_ref);
  1625. end;
  1626. procedure tcgx86.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);
  1627. var
  1628. href : treference;
  1629. begin
  1630. a_load_ref_reg(list,OS_ADDR,OS_ADDR,current_procinfo.save_regs_ref,NR_ESP);
  1631. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1632. if acchiused then
  1633. begin
  1634. reference_reset_base(href,NR_ESP,20);
  1635. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,NR_EDX,href));
  1636. end;
  1637. if accused then
  1638. begin
  1639. reference_reset_base(href,NR_ESP,28);
  1640. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,NR_EAX,href));
  1641. end;
  1642. list.concat(Taicpu.Op_none(A_POPA,S_L));
  1643. { We add a NOP because of the 386DX CPU bugs with POPAD }
  1644. list.concat(taicpu.op_none(A_NOP,S_L));
  1645. end;
  1646. { produces if necessary overflowcode }
  1647. procedure tcgx86.g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);
  1648. var
  1649. hl : tasmlabel;
  1650. ai : taicpu;
  1651. cond : TAsmCond;
  1652. begin
  1653. if not(cs_check_overflow in aktlocalswitches) then
  1654. exit;
  1655. objectlibrary.getlabel(hl);
  1656. if not ((def.deftype=pointerdef) or
  1657. ((def.deftype=orddef) and
  1658. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1659. bool8bit,bool16bit,bool32bit]))) then
  1660. cond:=C_NO
  1661. else
  1662. cond:=C_NB;
  1663. ai:=Taicpu.Op_Sym(A_Jcc,S_NO,hl);
  1664. ai.SetCondition(cond);
  1665. ai.is_jmp:=true;
  1666. list.concat(ai);
  1667. a_call_name(list,'FPC_OVERFLOW');
  1668. a_label(list,hl);
  1669. end;
  1670. end.
  1671. {
  1672. $Log$
  1673. Revision 1.95 2003-12-24 01:47:23 florian
  1674. * first fixes to compile the x86-64 system unit
  1675. Revision 1.94 2003/12/24 00:10:03 florian
  1676. - delete parameter in cg64 methods removed
  1677. Revision 1.93 2003/12/21 19:42:43 florian
  1678. * fixed ppc inlining stuff
  1679. * fixed wrong unit writing
  1680. + added some sse stuff
  1681. Revision 1.92 2003/12/19 22:08:44 daniel
  1682. * Some work to restore the MMX capabilities
  1683. Revision 1.91 2003/12/15 21:25:49 peter
  1684. * reg allocations for imaginary register are now inserted just
  1685. before reg allocation
  1686. * tregister changed to enum to allow compile time check
  1687. * fixed several tregister-tsuperregister errors
  1688. Revision 1.90 2003/12/12 17:16:18 peter
  1689. * rg[tregistertype] added in tcg
  1690. Revision 1.89 2003/12/06 01:15:23 florian
  1691. * reverted Peter's alloctemp patch; hopefully properly
  1692. Revision 1.88 2003/12/03 23:13:20 peter
  1693. * delayed paraloc allocation, a_param_*() gets extra parameter
  1694. if it needs to allocate temp or real paralocation
  1695. * optimized/simplified int-real loading
  1696. Revision 1.87 2003/11/05 23:06:03 florian
  1697. * elesize of g_copyvaluepara_openarray changed
  1698. Revision 1.86 2003/10/30 18:53:53 marco
  1699. * profiling fix
  1700. Revision 1.85 2003/10/30 16:22:40 peter
  1701. * call firstpass before allocation and codegeneration is started
  1702. * move leftover code from pass_2.generatecode() to psub
  1703. Revision 1.84 2003/10/29 21:24:14 jonas
  1704. + support for fpu temp parameters
  1705. + saving/restoring of fpu register before/after a procedure call
  1706. Revision 1.83 2003/10/20 19:30:08 peter
  1707. * remove memdebug code for rg
  1708. Revision 1.82 2003/10/18 15:41:26 peter
  1709. * made worklists dynamic in size
  1710. Revision 1.81 2003/10/17 15:25:18 florian
  1711. * fixed more ppc stuff
  1712. Revision 1.80 2003/10/17 14:38:32 peter
  1713. * 64k registers supported
  1714. * fixed some memory leaks
  1715. Revision 1.79 2003/10/14 00:30:48 florian
  1716. + some code for PIC support added
  1717. Revision 1.78 2003/10/13 01:23:13 florian
  1718. * some ideas for mm support implemented
  1719. Revision 1.77 2003/10/11 16:06:42 florian
  1720. * fixed some MMX<->SSE
  1721. * started to fix ppc, needs an overhaul
  1722. + stabs info improve for spilling, not sure if it works correctly/completly
  1723. - MMX_SUPPORT removed from Makefile.fpc
  1724. Revision 1.76 2003/10/10 17:48:14 peter
  1725. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  1726. * tregisteralloctor renamed to trgobj
  1727. * removed rgobj from a lot of units
  1728. * moved location_* and reference_* to cgobj
  1729. * first things for mmx register allocation
  1730. Revision 1.75 2003/10/09 21:31:37 daniel
  1731. * Register allocator splitted, ans abstract now
  1732. Revision 1.74 2003/10/07 16:09:03 florian
  1733. * x86 supports only mem/reg to reg for movsx and movzx
  1734. Revision 1.73 2003/10/07 15:17:07 peter
  1735. * inline supported again, LOC_REFERENCEs are used to pass the
  1736. parameters
  1737. * inlineparasymtable,inlinelocalsymtable removed
  1738. * exitlabel inserting fixed
  1739. Revision 1.72 2003/10/03 22:00:33 peter
  1740. * parameter alignment fixes
  1741. Revision 1.71 2003/10/03 14:45:37 peter
  1742. * save ESP after pusha and restore before popa for save all registers
  1743. Revision 1.70 2003/10/01 20:34:51 peter
  1744. * procinfo unit contains tprocinfo
  1745. * cginfo renamed to cgbase
  1746. * moved cgmessage to verbose
  1747. * fixed ppc and sparc compiles
  1748. Revision 1.69 2003/09/30 19:53:47 peter
  1749. * fix pushw reg
  1750. Revision 1.68 2003/09/29 20:58:56 peter
  1751. * optimized releasing of registers
  1752. Revision 1.67 2003/09/28 13:37:19 peter
  1753. * a_call_ref removed
  1754. Revision 1.66 2003/09/25 21:29:16 peter
  1755. * change push/pop in getreg/ungetreg
  1756. Revision 1.65 2003/09/25 13:13:32 florian
  1757. * more x86-64 fixes
  1758. Revision 1.64 2003/09/11 11:55:00 florian
  1759. * improved arm code generation
  1760. * move some protected and private field around
  1761. * the temp. register for register parameters/arguments are now released
  1762. before the move to the parameter register is done. This improves
  1763. the code in a lot of cases.
  1764. Revision 1.63 2003/09/09 21:03:17 peter
  1765. * basics for x86 register calling
  1766. Revision 1.62 2003/09/09 20:59:27 daniel
  1767. * Adding register allocation order
  1768. Revision 1.61 2003/09/07 22:09:35 peter
  1769. * preparations for different default calling conventions
  1770. * various RA fixes
  1771. Revision 1.60 2003/09/05 17:41:13 florian
  1772. * merged Wiktor's Watcom patches in 1.1
  1773. Revision 1.59 2003/09/03 15:55:02 peter
  1774. * NEWRA branch merged
  1775. Revision 1.58.2.5 2003/08/31 20:40:50 daniel
  1776. * Fixed add_edges_used
  1777. Revision 1.58.2.4 2003/08/31 15:46:26 peter
  1778. * more updates for tregister
  1779. Revision 1.58.2.3 2003/08/29 17:29:00 peter
  1780. * next batch of updates
  1781. Revision 1.58.2.2 2003/08/28 18:35:08 peter
  1782. * tregister changed to cardinal
  1783. Revision 1.58.2.1 2003/08/27 21:06:34 peter
  1784. * more updates
  1785. Revision 1.58 2003/08/20 19:28:21 daniel
  1786. * Small NOTARGETWIN32 conditional tweak
  1787. Revision 1.57 2003/07/03 18:59:25 peter
  1788. * loadfpu_reg_reg size specifier
  1789. Revision 1.56 2003/06/14 14:53:50 jonas
  1790. * fixed newra cycle for x86
  1791. * added constants for indicating source and destination operands of the
  1792. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  1793. Revision 1.55 2003/06/13 21:19:32 peter
  1794. * current_procdef removed, use current_procinfo.procdef instead
  1795. Revision 1.54 2003/06/12 18:31:18 peter
  1796. * fix newra cycle for i386
  1797. Revision 1.53 2003/06/07 10:24:10 peter
  1798. * fixed copyvaluepara for left-to-right pushing
  1799. Revision 1.52 2003/06/07 10:06:55 jonas
  1800. * fixed cycling problem
  1801. Revision 1.51 2003/06/03 21:11:09 peter
  1802. * cg.a_load_* get a from and to size specifier
  1803. * makeregsize only accepts newregister
  1804. * i386 uses generic tcgnotnode,tcgunaryminus
  1805. Revision 1.50 2003/06/03 13:01:59 daniel
  1806. * Register allocator finished
  1807. Revision 1.49 2003/06/01 21:38:07 peter
  1808. * getregisterfpu size parameter added
  1809. * op_const_reg size parameter added
  1810. * sparc updates
  1811. Revision 1.48 2003/05/30 23:57:08 peter
  1812. * more sparc cleanup
  1813. * accumulator removed, splitted in function_return_reg (called) and
  1814. function_result_reg (caller)
  1815. Revision 1.47 2003/05/22 21:33:31 peter
  1816. * removed some unit dependencies
  1817. Revision 1.46 2003/05/16 14:33:31 peter
  1818. * regvar fixes
  1819. Revision 1.45 2003/05/15 18:58:54 peter
  1820. * removed selfpointer_offset, vmtpointer_offset
  1821. * tvarsym.adjusted_address
  1822. * address in localsymtable is now in the real direction
  1823. * removed some obsolete globals
  1824. Revision 1.44 2003/04/30 20:53:32 florian
  1825. * error when address of an abstract method is taken
  1826. * fixed some x86-64 problems
  1827. * merged some more x86-64 and i386 code
  1828. Revision 1.43 2003/04/27 11:21:36 peter
  1829. * aktprocdef renamed to current_procinfo.procdef
  1830. * procinfo renamed to current_procinfo
  1831. * procinfo will now be stored in current_module so it can be
  1832. cleaned up properly
  1833. * gen_main_procsym changed to create_main_proc and release_main_proc
  1834. to also generate a tprocinfo structure
  1835. * fixed unit implicit initfinal
  1836. Revision 1.42 2003/04/23 14:42:08 daniel
  1837. * Further register allocator work. Compiler now smaller with new
  1838. allocator than without.
  1839. * Somebody forgot to adjust ppu version number
  1840. Revision 1.41 2003/04/23 09:51:16 daniel
  1841. * Removed usage of edi in a lot of places when new register allocator used
  1842. + Added newra versions of g_concatcopy and secondadd_float
  1843. Revision 1.40 2003/04/22 13:47:08 peter
  1844. * fixed C style array of const
  1845. * fixed C array passing
  1846. * fixed left to right with high parameters
  1847. Revision 1.39 2003/04/22 10:09:35 daniel
  1848. + Implemented the actual register allocator
  1849. + Scratch registers unavailable when new register allocator used
  1850. + maybe_save/maybe_restore unavailable when new register allocator used
  1851. Revision 1.38 2003/04/17 16:48:21 daniel
  1852. * Added some code to keep track of move instructions in register
  1853. allocator
  1854. Revision 1.37 2003/03/28 19:16:57 peter
  1855. * generic constructor working for i386
  1856. * remove fixed self register
  1857. * esi added as address register for i386
  1858. Revision 1.36 2003/03/18 18:17:46 peter
  1859. * reg2opsize()
  1860. Revision 1.35 2003/03/13 19:52:23 jonas
  1861. * and more new register allocator fixes (in the i386 code generator this
  1862. time). At least now the ppc cross compiler can compile the linux
  1863. system unit again, but I haven't tested it.
  1864. Revision 1.34 2003/02/27 16:40:32 daniel
  1865. * Fixed ie 200301234 problem on Win32 target
  1866. Revision 1.33 2003/02/26 21:15:43 daniel
  1867. * Fixed the optimizer
  1868. Revision 1.32 2003/02/19 22:00:17 daniel
  1869. * Code generator converted to new register notation
  1870. - Horribily outdated todo.txt removed
  1871. Revision 1.31 2003/01/21 10:41:13 daniel
  1872. * Fixed another 200301081
  1873. Revision 1.30 2003/01/13 23:00:18 daniel
  1874. * Fixed internalerror
  1875. Revision 1.29 2003/01/13 14:54:34 daniel
  1876. * Further work to convert codegenerator register convention;
  1877. internalerror bug fixed.
  1878. Revision 1.28 2003/01/09 20:41:00 daniel
  1879. * Converted some code in cgx86.pas to new register numbering
  1880. Revision 1.27 2003/01/08 18:43:58 daniel
  1881. * Tregister changed into a record
  1882. Revision 1.26 2003/01/05 13:36:53 florian
  1883. * x86-64 compiles
  1884. + very basic support for float128 type (x86-64 only)
  1885. Revision 1.25 2003/01/02 16:17:50 peter
  1886. * align stack on 4 bytes in copyvalueopenarray
  1887. Revision 1.24 2002/12/24 15:56:50 peter
  1888. * stackpointer_alloc added for adjusting ESP. Win32 needs
  1889. this for the pageprotection
  1890. Revision 1.23 2002/11/25 18:43:34 carl
  1891. - removed the invalid if <> checking (Delphi is strange on this)
  1892. + implemented abstract warning on instance creation of class with
  1893. abstract methods.
  1894. * some error message cleanups
  1895. Revision 1.22 2002/11/25 17:43:29 peter
  1896. * splitted defbase in defutil,symutil,defcmp
  1897. * merged isconvertable and is_equal into compare_defs(_ext)
  1898. * made operator search faster by walking the list only once
  1899. Revision 1.21 2002/11/18 17:32:01 peter
  1900. * pass proccalloption to ret_in_xxx and push_xxx functions
  1901. Revision 1.20 2002/11/09 21:18:31 carl
  1902. * flags2reg() was not extending the byte register to the correct result size
  1903. Revision 1.19 2002/10/16 19:01:43 peter
  1904. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1905. implicit exception frames for procedures with initialized variables
  1906. and for constructors. The default is on for compatibility
  1907. Revision 1.18 2002/10/05 12:43:30 carl
  1908. * fixes for Delphi 6 compilation
  1909. (warning : Some features do not work under Delphi)
  1910. Revision 1.17 2002/09/17 18:54:06 jonas
  1911. * a_load_reg_reg() now has two size parameters: source and dest. This
  1912. allows some optimizations on architectures that don't encode the
  1913. register size in the register name.
  1914. Revision 1.16 2002/09/16 19:08:47 peter
  1915. * support references without registers and symbol in paramref_addr. It
  1916. pushes only the offset
  1917. Revision 1.15 2002/09/16 18:06:29 peter
  1918. * move CGSize2Opsize to interface
  1919. Revision 1.14 2002/09/01 14:42:41 peter
  1920. * removevaluepara added to fix the stackpointer so restoring of
  1921. saved registers works
  1922. Revision 1.13 2002/09/01 12:09:27 peter
  1923. + a_call_reg, a_call_loc added
  1924. * removed exprasmlist references
  1925. Revision 1.12 2002/08/17 09:23:50 florian
  1926. * first part of procinfo rewrite
  1927. Revision 1.11 2002/08/16 14:25:00 carl
  1928. * issameref() to test if two references are the same (then emit no opcodes)
  1929. + ret_in_reg to replace ret_in_acc
  1930. (fix some register allocation bugs at the same time)
  1931. + save_std_register now has an extra parameter which is the
  1932. usedinproc registers
  1933. Revision 1.10 2002/08/15 08:13:54 carl
  1934. - a_load_sym_ofs_reg removed
  1935. * loadvmt now calls loadaddr_ref_reg instead
  1936. Revision 1.9 2002/08/11 14:32:33 peter
  1937. * renamed current_library to objectlibrary
  1938. Revision 1.8 2002/08/11 13:24:20 peter
  1939. * saving of asmsymbols in ppu supported
  1940. * asmsymbollist global is removed and moved into a new class
  1941. tasmlibrarydata that will hold the info of a .a file which
  1942. corresponds with a single module. Added librarydata to tmodule
  1943. to keep the library info stored for the module. In the future the
  1944. objectfiles will also be stored to the tasmlibrarydata class
  1945. * all getlabel/newasmsymbol and friends are moved to the new class
  1946. Revision 1.7 2002/08/10 10:06:04 jonas
  1947. * fixed stupid bug of mine in g_flags2reg() when optimizations are on
  1948. Revision 1.6 2002/08/09 19:18:27 carl
  1949. * fix generic exception handling
  1950. Revision 1.5 2002/08/04 19:52:04 carl
  1951. + updated exception routines
  1952. Revision 1.4 2002/07/27 19:53:51 jonas
  1953. + generic implementation of tcg.g_flags2ref()
  1954. * tcg.flags2xxx() now also needs a size parameter
  1955. Revision 1.3 2002/07/26 21:15:46 florian
  1956. * rewrote the system handling
  1957. Revision 1.2 2002/07/21 16:55:34 jonas
  1958. * fixed bug in op_const_reg_reg() for imul
  1959. Revision 1.1 2002/07/20 19:28:47 florian
  1960. * splitting of i386\cgcpu.pas into x86\cgx86.pas and i386\cgcpu.pas
  1961. cgx86.pas will contain the common code for i386 and x86_64
  1962. }