cgx86.pas 80 KB

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