cgx86.pas 80 KB

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