cgx86.pas 80 KB

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