cgx86.pas 79 KB

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