cgx86.pas 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341
  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_releasevaluepara_openarray(list : taasmoutput;const ref:treference);override;
  98. procedure g_interrupt_stackframe_entry(list : taasmoutput);override;
  99. procedure g_interrupt_stackframe_exit(list : taasmoutput;accused,acchiused:boolean);override;
  100. procedure g_profilecode(list : taasmoutput);override;
  101. procedure g_stackpointer_alloc(list : taasmoutput;localsize : longint);override;
  102. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  103. procedure g_restore_frame_pointer(list : taasmoutput);override;
  104. procedure g_return_from_proc(list : taasmoutput;parasize : aword);override;
  105. procedure g_save_standard_registers(list:Taasmoutput);override;
  106. procedure g_restore_standard_registers(list:Taasmoutput);override;
  107. procedure g_save_all_registers(list : taasmoutput);override;
  108. procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);override;
  109. procedure g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);override;
  110. protected
  111. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  112. procedure check_register_size(size:tcgsize;reg:tregister);
  113. procedure opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  114. private
  115. procedure sizes2load(s1,s2 : tcgsize;var op: tasmop; var s3: topsize);
  116. procedure floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  117. procedure floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  118. procedure floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  119. procedure floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  120. end;
  121. function use_sse(def : tdef) : boolean;
  122. const
  123. {$ifdef x86_64}
  124. TCGSize2OpSize: Array[tcgsize] of topsize =
  125. (S_NO,S_B,S_W,S_L,S_D,S_B,S_W,S_L,S_D,
  126. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  127. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  128. {$else x86_64}
  129. TCGSize2OpSize: Array[tcgsize] of topsize =
  130. (S_NO,S_B,S_W,S_L,S_L,S_B,S_W,S_L,S_L,
  131. S_FS,S_FL,S_FX,S_IQ,S_FXX,
  132. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  133. {$endif x86_64}
  134. implementation
  135. uses
  136. globtype,globals,verbose,systems,cutils,
  137. symdef,defutil,paramgr,tgobj,procinfo;
  138. {$ifndef NOTARGETWIN32}
  139. const
  140. winstackpagesize = 4096;
  141. {$endif NOTARGETWIN32}
  142. TOpCG2AsmOp: Array[topcg] of TAsmOp = (A_NONE,A_ADD,A_AND,A_DIV,
  143. A_IDIV,A_MUL, A_IMUL, A_NEG,A_NOT,A_OR,
  144. A_SAR,A_SHL,A_SHR,A_SUB,A_XOR);
  145. TOpCmp2AsmCond: Array[topcmp] of TAsmCond = (C_NONE,
  146. C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A);
  147. function use_sse(def : tdef) : boolean;
  148. begin
  149. use_sse:=(is_single(def) and (aktfputype in sse_singlescalar)) or
  150. (is_double(def) and (aktfputype in sse_doublescalar));
  151. end;
  152. procedure Tcgx86.init_register_allocators;
  153. begin
  154. inherited init_register_allocators;
  155. if cs_create_pic in aktmoduleswitches then
  156. 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])
  157. else
  158. 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]);
  159. 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,[]);
  160. 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,[]);
  161. rgfpu:=Trgx86fpu.create;
  162. end;
  163. procedure Tcgx86.done_register_allocators;
  164. begin
  165. rg[R_INTREGISTER].free;
  166. rg[R_MMREGISTER].free;
  167. rg[R_MMXREGISTER].free;
  168. rgfpu.free;
  169. inherited done_register_allocators;
  170. end;
  171. function Tcgx86.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  172. begin
  173. result:=rgfpu.getregisterfpu(list);
  174. end;
  175. function Tcgx86.getmmxregister(list:Taasmoutput):Tregister;
  176. begin
  177. if not assigned(rg[R_MMXREGISTER]) then
  178. internalerror(200312124);
  179. result:=rg[R_MMXREGISTER].getregister(list,R_SUBNONE);
  180. end;
  181. procedure Tcgx86.getexplicitregister(list:Taasmoutput;r:Tregister);
  182. begin
  183. if getregtype(r)=R_FPUREGISTER then
  184. internalerror(2003121210)
  185. else
  186. inherited getexplicitregister(list,r);
  187. end;
  188. procedure tcgx86.ungetregister(list:Taasmoutput;r:Tregister);
  189. begin
  190. if getregtype(r)=R_FPUREGISTER then
  191. rgfpu.ungetregisterfpu(list,r)
  192. else
  193. inherited ungetregister(list,r);
  194. end;
  195. procedure Tcgx86.allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  196. begin
  197. if rt<>R_FPUREGISTER then
  198. inherited allocexplicitregisters(list,rt,r);
  199. end;
  200. procedure Tcgx86.deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  201. begin
  202. if rt<>R_FPUREGISTER then
  203. inherited deallocexplicitregisters(list,rt,r);
  204. end;
  205. function Tcgx86.uses_registers(rt:Tregistertype):boolean;
  206. begin
  207. if rt=R_FPUREGISTER then
  208. result:=false
  209. else
  210. result:=inherited uses_registers(rt);
  211. end;
  212. procedure tcgx86.add_reg_instruction(instr:Tai;r:tregister);
  213. begin
  214. if getregtype(r)<>R_FPUREGISTER then
  215. inherited add_reg_instruction(instr,r);
  216. end;
  217. procedure tcgx86.dec_fpu_stack;
  218. begin
  219. dec(rgfpu.fpuvaroffset);
  220. end;
  221. procedure tcgx86.inc_fpu_stack;
  222. begin
  223. inc(rgfpu.fpuvaroffset);
  224. end;
  225. {****************************************************************************
  226. This is private property, keep out! :)
  227. ****************************************************************************}
  228. procedure tcgx86.sizes2load(s1,s2 : tcgsize; var op: tasmop; var s3: topsize);
  229. begin
  230. case s2 of
  231. OS_8,OS_S8 :
  232. if S1 in [OS_8,OS_S8] then
  233. s3 := S_B
  234. else internalerror(200109221);
  235. OS_16,OS_S16:
  236. case s1 of
  237. OS_8,OS_S8:
  238. s3 := S_BW;
  239. OS_16,OS_S16:
  240. s3 := S_W;
  241. else
  242. internalerror(200109222);
  243. end;
  244. OS_32,OS_S32:
  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. else
  253. internalerror(200109223);
  254. end;
  255. {$ifdef x86_64}
  256. OS_64,OS_S64:
  257. case s1 of
  258. OS_8,OS_S8:
  259. s3 := S_BQ;
  260. OS_16,OS_S16:
  261. s3 := S_WQ;
  262. OS_32,OS_S32:
  263. s3 := S_LQ;
  264. OS_64,OS_S64:
  265. s3 := S_Q;
  266. else
  267. internalerror(200304302);
  268. end;
  269. {$endif x86_64}
  270. else
  271. internalerror(200109227);
  272. end;
  273. if s3 in [S_B,S_W,S_L,S_Q] then
  274. op := A_MOV
  275. else if s1 in [OS_8,OS_16,OS_32,OS_64] then
  276. op := A_MOVZX
  277. else
  278. op := A_MOVSX;
  279. end;
  280. procedure tcgx86.floatloadops(t : tcgsize;var op : tasmop;var s : topsize);
  281. begin
  282. case t of
  283. OS_F32 :
  284. begin
  285. op:=A_FLD;
  286. s:=S_FS;
  287. end;
  288. OS_F64 :
  289. begin
  290. op:=A_FLD;
  291. { ???? }
  292. s:=S_FL;
  293. end;
  294. OS_F80 :
  295. begin
  296. op:=A_FLD;
  297. s:=S_FX;
  298. end;
  299. OS_C64 :
  300. begin
  301. op:=A_FILD;
  302. s:=S_IQ;
  303. end;
  304. else
  305. internalerror(200204041);
  306. end;
  307. end;
  308. procedure tcgx86.floatload(list: taasmoutput; t : tcgsize;const ref : treference);
  309. var
  310. op : tasmop;
  311. s : topsize;
  312. begin
  313. floatloadops(t,op,s);
  314. list.concat(Taicpu.Op_ref(op,s,ref));
  315. inc_fpu_stack;
  316. end;
  317. procedure tcgx86.floatstoreops(t : tcgsize;var op : tasmop;var s : topsize);
  318. begin
  319. case t of
  320. OS_F32 :
  321. begin
  322. op:=A_FSTP;
  323. s:=S_FS;
  324. end;
  325. OS_F64 :
  326. begin
  327. op:=A_FSTP;
  328. s:=S_FL;
  329. end;
  330. OS_F80 :
  331. begin
  332. op:=A_FSTP;
  333. s:=S_FX;
  334. end;
  335. OS_C64 :
  336. begin
  337. op:=A_FISTP;
  338. s:=S_IQ;
  339. end;
  340. else
  341. internalerror(200204042);
  342. end;
  343. end;
  344. procedure tcgx86.floatstore(list: taasmoutput; t : tcgsize;const ref : treference);
  345. var
  346. op : tasmop;
  347. s : topsize;
  348. begin
  349. floatstoreops(t,op,s);
  350. list.concat(Taicpu.Op_ref(op,s,ref));
  351. dec_fpu_stack;
  352. end;
  353. procedure tcgx86.check_register_size(size:tcgsize;reg:tregister);
  354. begin
  355. if TCGSize2OpSize[size]<>TCGSize2OpSize[reg_cgsize(reg)] then
  356. internalerror(200306031);
  357. end;
  358. {****************************************************************************
  359. Assembler code
  360. ****************************************************************************}
  361. { currently does nothing }
  362. procedure tcgx86.a_jmp_always(list : taasmoutput;l: tasmlabel);
  363. begin
  364. a_jmp_cond(list, OC_NONE, l);
  365. end;
  366. { we implement the following routines because otherwise we can't }
  367. { instantiate the class since it's abstract }
  368. procedure tcgx86.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);
  369. begin
  370. check_register_size(size,r);
  371. if (locpara.loc=LOC_REFERENCE) and
  372. (locpara.reference.index=NR_STACK_POINTER_REG) then
  373. begin
  374. case size of
  375. OS_8,OS_S8,
  376. OS_16,OS_S16:
  377. begin
  378. if locpara.alignment = 2 then
  379. list.concat(taicpu.op_reg(A_PUSH,S_W,makeregsize(r,OS_16)))
  380. else
  381. list.concat(taicpu.op_reg(A_PUSH,S_L,makeregsize(r,OS_32)));
  382. end;
  383. OS_32,OS_S32:
  384. begin
  385. if getsubreg(r)<>R_SUBD then
  386. internalerror(7843);
  387. list.concat(taicpu.op_reg(A_PUSH,S_L,r));
  388. end
  389. else
  390. internalerror(2002032212);
  391. end;
  392. end
  393. else
  394. inherited a_param_reg(list,size,r,locpara);
  395. end;
  396. procedure tcgx86.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  397. begin
  398. if (locpara.loc=LOC_REFERENCE) and
  399. (locpara.reference.index=NR_STACK_POINTER_REG) then
  400. begin
  401. case size of
  402. OS_8,OS_S8,OS_16,OS_S16:
  403. begin
  404. if locpara.alignment = 2 then
  405. list.concat(taicpu.op_const(A_PUSH,S_W,a))
  406. else
  407. list.concat(taicpu.op_const(A_PUSH,S_L,a));
  408. end;
  409. OS_32,OS_S32:
  410. list.concat(taicpu.op_const(A_PUSH,S_L,a));
  411. else
  412. internalerror(2002032213);
  413. end;
  414. end
  415. else
  416. inherited a_param_const(list,size,a,locpara);
  417. end;
  418. procedure tcgx86.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  419. var
  420. pushsize : tcgsize;
  421. tmpreg : tregister;
  422. begin
  423. if (locpara.loc=LOC_REFERENCE) and
  424. (locpara.reference.index=NR_STACK_POINTER_REG) then
  425. begin
  426. case size of
  427. OS_8,OS_S8,
  428. OS_16,OS_S16:
  429. begin
  430. if locpara.alignment = 2 then
  431. pushsize:=OS_16
  432. else
  433. pushsize:=OS_32;
  434. tmpreg:=getintregister(list,pushsize);
  435. a_load_ref_reg(list,size,pushsize,r,tmpreg);
  436. list.concat(taicpu.op_reg(A_PUSH,TCgsize2opsize[pushsize],tmpreg));
  437. ungetregister(list,tmpreg);
  438. end;
  439. OS_32,OS_S32:
  440. list.concat(taicpu.op_ref(A_PUSH,S_L,r));
  441. {$ifdef cpu64bit}
  442. OS_64,OS_S64:
  443. list.concat(taicpu.op_ref(A_PUSH,S_Q,r));
  444. {$endif cpu64bit}
  445. else
  446. internalerror(2002032214);
  447. end;
  448. end
  449. else
  450. inherited a_param_ref(list,size,r,locpara);
  451. end;
  452. procedure tcgx86.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  453. var
  454. tmpreg : tregister;
  455. begin
  456. if (r.segment<>NR_NO) then
  457. CGMessage(cg_e_cant_use_far_pointer_there);
  458. if (locpara.loc=LOC_REFERENCE) and
  459. (locpara.reference.index=NR_STACK_POINTER_REG) then
  460. begin
  461. if (r.base=NR_NO) and (r.index=NR_NO) then
  462. begin
  463. if assigned(r.symbol) then
  464. list.concat(Taicpu.Op_sym_ofs(A_PUSH,S_L,r.symbol,r.offset))
  465. else
  466. list.concat(Taicpu.Op_const(A_PUSH,S_L,r.offset));
  467. end
  468. else if (r.base=NR_NO) and (r.index<>NR_NO) and
  469. (r.offset=0) and (r.scalefactor=0) and (r.symbol=nil) then
  470. list.concat(Taicpu.Op_reg(A_PUSH,S_L,r.index))
  471. else if (r.base<>NR_NO) and (r.index=NR_NO) and
  472. (r.offset=0) and (r.symbol=nil) then
  473. list.concat(Taicpu.Op_reg(A_PUSH,S_L,r.base))
  474. else
  475. begin
  476. tmpreg:=getaddressregister(list);
  477. a_loadaddr_ref_reg(list,r,tmpreg);
  478. ungetregister(list,tmpreg);
  479. list.concat(taicpu.op_reg(A_PUSH,S_L,tmpreg));
  480. end;
  481. end
  482. else
  483. inherited a_paramaddr_ref(list,r,locpara);
  484. end;
  485. procedure tcgx86.a_call_name(list : taasmoutput;const s : string);
  486. begin
  487. list.concat(taicpu.op_sym(A_CALL,S_NO,objectlibrary.newasmsymbol(s)));
  488. end;
  489. procedure tcgx86.a_call_reg(list : taasmoutput;reg : tregister);
  490. begin
  491. list.concat(taicpu.op_reg(A_CALL,S_NO,reg));
  492. end;
  493. {********************** load instructions ********************}
  494. procedure tcgx86.a_load_const_reg(list : taasmoutput; tosize: TCGSize; a : aword; reg : TRegister);
  495. begin
  496. check_register_size(tosize,reg);
  497. { the optimizer will change it to "xor reg,reg" when loading zero, }
  498. { no need to do it here too (JM) }
  499. list.concat(taicpu.op_const_reg(A_MOV,TCGSize2OpSize[tosize],a,reg))
  500. end;
  501. procedure tcgx86.a_load_const_ref(list : taasmoutput; tosize: tcgsize; a : aword;const ref : treference);
  502. begin
  503. list.concat(taicpu.op_const_ref(A_MOV,TCGSize2OpSize[tosize],a,ref));
  504. end;
  505. procedure tcgx86.a_load_reg_ref(list : taasmoutput; fromsize,tosize: TCGSize; reg : tregister;const ref : treference);
  506. var
  507. op: tasmop;
  508. s: topsize;
  509. tmpreg : tregister;
  510. begin
  511. check_register_size(fromsize,reg);
  512. sizes2load(fromsize,tosize,op,s);
  513. case s of
  514. S_BW,S_BL,S_WL
  515. {$ifdef x86_64}
  516. ,S_BQ,S_WQ,S_LQ
  517. {$endif x86_64}
  518. :
  519. begin
  520. tmpreg:=getintregister(list,tosize);
  521. list.concat(taicpu.op_reg_reg(op,s,reg,tmpreg));
  522. a_load_reg_ref(list,tosize,tosize,tmpreg,ref);
  523. ungetregister(list,tmpreg);
  524. end;
  525. else
  526. list.concat(taicpu.op_reg_ref(op,s,reg,ref));
  527. end;
  528. end;
  529. procedure tcgx86.a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  530. var
  531. op: tasmop;
  532. s: topsize;
  533. begin
  534. check_register_size(tosize,reg);
  535. sizes2load(fromsize,tosize,op,s);
  536. list.concat(taicpu.op_ref_reg(op,s,ref,reg));
  537. end;
  538. procedure tcgx86.a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);
  539. var
  540. op: tasmop;
  541. s: topsize;
  542. eq:boolean;
  543. instr:Taicpu;
  544. begin
  545. check_register_size(fromsize,reg1);
  546. check_register_size(tosize,reg2);
  547. sizes2load(fromsize,tosize,op,s);
  548. eq:=getsupreg(reg1)=getsupreg(reg2);
  549. if eq then
  550. begin
  551. { "mov reg1, reg1" doesn't make sense }
  552. if op = A_MOV then
  553. exit;
  554. end;
  555. instr:=taicpu.op_reg_reg(op,s,reg1,reg2);
  556. {Notify the register allocator that we have written a move instruction so
  557. it can try to eliminate it.}
  558. add_move_instruction(instr);
  559. list.concat(instr);
  560. end;
  561. procedure tcgx86.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  562. begin
  563. if (ref.base=NR_NO) and (ref.index=NR_NO) then
  564. begin
  565. if assigned(ref.symbol) then
  566. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,ref.symbol,ref.offset,r))
  567. else
  568. a_load_const_reg(list,OS_INT,ref.offset,r);
  569. end
  570. else if (ref.base=NR_NO) and (ref.index<>NR_NO) and
  571. (ref.offset=0) and (ref.scalefactor=0) and (ref.symbol=nil) then
  572. a_load_reg_reg(list,OS_INT,OS_INT,ref.index,r)
  573. else if (ref.base<>NR_NO) and (ref.index=NR_NO) and
  574. (ref.offset=0) and (ref.symbol=nil) then
  575. a_load_reg_reg(list,OS_INT,OS_INT,ref.base,r)
  576. else
  577. list.concat(taicpu.op_ref_reg(A_LEA,S_L,ref,r));
  578. end;
  579. { all fpu load routines expect that R_ST[0-7] means an fpu regvar and }
  580. { R_ST means "the current value at the top of the fpu stack" (JM) }
  581. procedure tcgx86.a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister);
  582. begin
  583. if (reg1<>NR_ST) then
  584. begin
  585. list.concat(taicpu.op_reg(A_FLD,S_NO,rgfpu.correct_fpuregister(reg1,rgfpu.fpuvaroffset)));
  586. inc_fpu_stack;
  587. end;
  588. if (reg2<>NR_ST) then
  589. begin
  590. list.concat(taicpu.op_reg(A_FSTP,S_NO,rgfpu.correct_fpuregister(reg2,rgfpu.fpuvaroffset)));
  591. dec_fpu_stack;
  592. end;
  593. end;
  594. procedure tcgx86.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  595. begin
  596. floatload(list,size,ref);
  597. if (reg<>NR_ST) then
  598. a_loadfpu_reg_reg(list,size,NR_ST,reg);
  599. end;
  600. procedure tcgx86.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  601. begin
  602. if reg<>NR_ST then
  603. a_loadfpu_reg_reg(list,size,reg,NR_ST);
  604. floatstore(list,size,ref);
  605. end;
  606. function get_scalar_mm_op(fromsize,tosize : tcgsize) : tasmop;
  607. begin
  608. case fromsize of
  609. OS_F32:
  610. case tosize of
  611. OS_F64:
  612. result:=A_CVTSS2SD;
  613. OS_F32:
  614. result:=A_MOVSS;
  615. else
  616. internalerror(200312205);
  617. end;
  618. OS_F64:
  619. case tosize of
  620. OS_F64:
  621. result:=A_MOVSD;
  622. OS_F32:
  623. result:=A_CVTSD2SS;
  624. else
  625. internalerror(200312204);
  626. end;
  627. else
  628. internalerror(200312203);
  629. end;
  630. end;
  631. procedure tcgx86.a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle);
  632. begin
  633. if shuffle=nil then
  634. begin
  635. if fromsize=tosize then
  636. list.concat(taicpu.op_reg_reg(A_MOVAPS,S_NO,reg1,reg2))
  637. else
  638. internalerror(200312202);
  639. end
  640. else if shufflescalar(shuffle) then
  641. list.concat(taicpu.op_reg_reg(get_scalar_mm_op(fromsize,tosize),S_NO,reg1,reg2))
  642. else
  643. internalerror(200312201);
  644. end;
  645. procedure tcgx86.a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  646. begin
  647. if shuffle=nil then
  648. begin
  649. list.concat(taicpu.op_ref_reg(A_MOVQ,S_NO,ref,reg));
  650. end
  651. else if shufflescalar(shuffle) then
  652. list.concat(taicpu.op_ref_reg(get_scalar_mm_op(fromsize,tosize),S_NO,ref,reg))
  653. else
  654. internalerror(200312252);
  655. end;
  656. procedure tcgx86.a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle);
  657. begin
  658. if shuffle=nil then
  659. begin
  660. list.concat(taicpu.op_ref_reg(A_MOVQ,S_NO,ref,reg));
  661. end
  662. else if shufflescalar(shuffle) then
  663. list.concat(taicpu.op_reg_ref(get_scalar_mm_op(fromsize,tosize),S_NO,reg,ref))
  664. else
  665. internalerror(200312252);
  666. end;
  667. procedure tcgx86.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  668. var
  669. l : tlocation;
  670. begin
  671. l.loc:=LOC_REFERENCE;
  672. l.reference:=ref;
  673. l.size:=size;
  674. opmm_loc_reg(list,op,size,l,reg,shuffle);
  675. end;
  676. procedure tcgx86.a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle);
  677. var
  678. l : tlocation;
  679. begin
  680. l.loc:=LOC_MMREGISTER;
  681. l.register:=src;
  682. l.size:=size;
  683. opmm_loc_reg(list,op,size,l,dst,shuffle);
  684. end;
  685. procedure tcgx86.opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;loc : tlocation;dst: tregister; shuffle : pmmshuffle);
  686. const
  687. opmm2asmop : array[0..1,OS_F32..OS_F64,topcg] of tasmop = (
  688. ( { scalar }
  689. ( { OS_F32 }
  690. 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
  691. ),
  692. ( { OS_F64 }
  693. 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
  694. )
  695. ),
  696. ( { vectorized/packed }
  697. { because the logical packed single instructions have shorter op codes, we use always
  698. these
  699. }
  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_XORPS
  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_XORPS
  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_MOVSL,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_MOVSL,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_releasevaluepara_openarray(list : taasmoutput;const ref:treference);
  1405. begin
  1406. { Nothing to release }
  1407. end;
  1408. procedure tcgx86.g_interrupt_stackframe_entry(list : taasmoutput);
  1409. begin
  1410. { .... also the segment registers }
  1411. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_GS));
  1412. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_FS));
  1413. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_ES));
  1414. list.concat(Taicpu.Op_reg(A_PUSH,S_W,NR_DS));
  1415. { save the registers of an interrupt procedure }
  1416. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDI));
  1417. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ESI));
  1418. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EDX));
  1419. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ECX));
  1420. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EBX));
  1421. list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EAX));
  1422. end;
  1423. procedure tcgx86.g_interrupt_stackframe_exit(list : taasmoutput;accused,acchiused:boolean);
  1424. begin
  1425. if accused then
  1426. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,NR_ESP))
  1427. else
  1428. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EAX));
  1429. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EBX));
  1430. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_ECX));
  1431. if acchiused then
  1432. list.concat(Taicpu.Op_const_reg(A_ADD,S_L,4,NR_ESP))
  1433. else
  1434. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EDX));
  1435. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_ESI));
  1436. list.concat(Taicpu.Op_reg(A_POP,S_L,NR_EDI));
  1437. { .... also the segment registers }
  1438. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_DS));
  1439. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_ES));
  1440. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_FS));
  1441. list.concat(Taicpu.Op_reg(A_POP,S_W,NR_GS));
  1442. { this restores the flags }
  1443. list.concat(Taicpu.Op_none(A_IRET,S_NO));
  1444. end;
  1445. procedure tcgx86.g_profilecode(list : taasmoutput);
  1446. var
  1447. pl : tasmlabel;
  1448. mcountprefix : String[4];
  1449. begin
  1450. case target_info.system of
  1451. {$ifndef NOTARGETWIN32}
  1452. system_i386_win32,
  1453. {$endif}
  1454. system_i386_freebsd,
  1455. system_i386_netbsd,
  1456. // system_i386_openbsd,
  1457. system_i386_wdosx,
  1458. system_i386_linux:
  1459. begin
  1460. Case target_info.system Of
  1461. system_i386_freebsd : mcountprefix:='.';
  1462. system_i386_netbsd : mcountprefix:='__';
  1463. // system_i386_openbsd : mcountprefix:='.';
  1464. else
  1465. mcountPrefix:='';
  1466. end;
  1467. objectlibrary.getaddrlabel(pl);
  1468. list.concat(Tai_section.Create(sec_data));
  1469. list.concat(Tai_align.Create(4));
  1470. list.concat(Tai_label.Create(pl));
  1471. list.concat(Tai_const.Create_32bit(0));
  1472. list.concat(Tai_section.Create(sec_code));
  1473. list.concat(Taicpu.Op_sym_ofs_reg(A_MOV,S_L,pl,0,NR_EDX));
  1474. a_call_name(list,target_info.Cprefix+mcountprefix+'mcount');
  1475. include(rg[R_INTREGISTER].used_in_proc,RS_EDX);
  1476. end;
  1477. system_i386_go32v2,system_i386_watcom:
  1478. begin
  1479. a_call_name(list,'MCOUNT');
  1480. end;
  1481. end;
  1482. end;
  1483. procedure tcgx86.g_stackpointer_alloc(list : taasmoutput;localsize : longint);
  1484. var
  1485. href : treference;
  1486. i : integer;
  1487. again : tasmlabel;
  1488. begin
  1489. if localsize>0 then
  1490. begin
  1491. {$ifndef NOTARGETWIN32}
  1492. { windows guards only a few pages for stack growing, }
  1493. { so we have to access every page first }
  1494. if (target_info.system=system_i386_win32) and
  1495. (localsize>=winstackpagesize) then
  1496. begin
  1497. if localsize div winstackpagesize<=5 then
  1498. begin
  1499. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize-4,NR_ESP));
  1500. for i:=1 to localsize div winstackpagesize do
  1501. begin
  1502. reference_reset_base(href,NR_ESP,localsize-i*winstackpagesize);
  1503. list.concat(Taicpu.op_const_ref(A_MOV,S_L,0,href));
  1504. end;
  1505. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1506. end
  1507. else
  1508. begin
  1509. objectlibrary.getlabel(again);
  1510. getexplicitregister(list,NR_EDI);
  1511. list.concat(Taicpu.op_const_reg(A_MOV,S_L,localsize div winstackpagesize,NR_EDI));
  1512. a_label(list,again);
  1513. list.concat(Taicpu.op_const_reg(A_SUB,S_L,winstackpagesize-4,NR_ESP));
  1514. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EAX));
  1515. list.concat(Taicpu.op_reg(A_DEC,S_L,NR_EDI));
  1516. a_jmp_cond(list,OC_NE,again);
  1517. ungetregister(list,NR_EDI);
  1518. list.concat(Taicpu.op_const_reg(A_SUB,S_L,localsize mod winstackpagesize,NR_ESP));
  1519. end
  1520. end
  1521. else
  1522. {$endif NOTARGETWIN32}
  1523. list.concat(Taicpu.Op_const_reg(A_SUB,S_L,localsize,NR_ESP));
  1524. end;
  1525. end;
  1526. procedure tcgx86.g_stackframe_entry(list : taasmoutput;localsize : longint);
  1527. begin
  1528. list.concat(tai_regalloc.alloc(NR_EBP));
  1529. include(rg[R_INTREGISTER].preserved_by_proc,RS_EBP);
  1530. list.concat(Taicpu.op_reg(A_PUSH,S_L,NR_EBP));
  1531. list.concat(Taicpu.op_reg_reg(A_MOV,S_L,NR_ESP,NR_EBP));
  1532. if localsize>0 then
  1533. g_stackpointer_alloc(list,localsize);
  1534. if cs_create_pic in aktmoduleswitches then
  1535. begin
  1536. a_call_name(list,'FPC_GETEIPINEBX');
  1537. list.concat(taicpu.op_sym_ofs_reg(A_ADD,S_L,objectlibrary.newasmsymboldata('_GLOBAL_OFFSET_TABLE_'),0,NR_EBX));
  1538. list.concat(tai_regalloc.alloc(NR_EBX));
  1539. end;
  1540. end;
  1541. procedure tcgx86.g_restore_frame_pointer(list : taasmoutput);
  1542. begin
  1543. if cs_create_pic in aktmoduleswitches then
  1544. list.concat(tai_regalloc.dealloc(NR_EBX));
  1545. list.concat(tai_regalloc.dealloc(NR_EBP));
  1546. list.concat(Taicpu.op_none(A_LEAVE,S_NO));
  1547. if assigned(rg[R_MMXREGISTER]) and (rg[R_MMXREGISTER].uses_registers) then
  1548. list.concat(Taicpu.op_none(A_EMMS,S_NO));
  1549. end;
  1550. procedure tcgx86.g_return_from_proc(list : taasmoutput;parasize : aword);
  1551. begin
  1552. { Routines with the poclearstack flag set use only a ret }
  1553. { also routines with parasize=0 }
  1554. if current_procinfo.procdef.proccalloption in clearstack_pocalls then
  1555. begin
  1556. { complex return values are removed from stack in C code PM }
  1557. if paramanager.ret_in_param(current_procinfo.procdef.rettype.def,
  1558. current_procinfo.procdef.proccalloption) then
  1559. list.concat(Taicpu.Op_const(A_RET,S_NO,4))
  1560. else
  1561. list.concat(Taicpu.Op_none(A_RET,S_NO));
  1562. end
  1563. else if (parasize=0) then
  1564. list.concat(Taicpu.Op_none(A_RET,S_NO))
  1565. else
  1566. begin
  1567. { parameters are limited to 65535 bytes because }
  1568. { ret allows only imm16 }
  1569. if (parasize>65535) then
  1570. CGMessage(cg_e_parasize_too_big);
  1571. list.concat(Taicpu.Op_const(A_RET,S_NO,parasize));
  1572. end;
  1573. end;
  1574. procedure tcgx86.g_save_standard_registers(list:Taasmoutput);
  1575. var
  1576. href : treference;
  1577. size : longint;
  1578. begin
  1579. { Get temp }
  1580. size:=0;
  1581. if RS_EBX in rg[R_INTREGISTER].used_in_proc then
  1582. inc(size,POINTER_SIZE);
  1583. if RS_ESI in rg[R_INTREGISTER].used_in_proc then
  1584. inc(size,POINTER_SIZE);
  1585. if RS_EDI in rg[R_INTREGISTER].used_in_proc then
  1586. inc(size,POINTER_SIZE);
  1587. if size>0 then
  1588. begin
  1589. tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
  1590. { Copy registers to temp }
  1591. href:=current_procinfo.save_regs_ref;
  1592. if RS_EBX in rg[R_INTREGISTER].used_in_proc then
  1593. begin
  1594. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_EBX,href);
  1595. inc(href.offset,POINTER_SIZE);
  1596. end;
  1597. if RS_ESI in rg[R_INTREGISTER].used_in_proc then
  1598. begin
  1599. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_ESI,href);
  1600. inc(href.offset,POINTER_SIZE);
  1601. end;
  1602. if RS_EDI in rg[R_INTREGISTER].used_in_proc then
  1603. begin
  1604. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_EDI,href);
  1605. inc(href.offset,POINTER_SIZE);
  1606. end;
  1607. end;
  1608. include(rg[R_INTREGISTER].preserved_by_proc,RS_EBX);
  1609. include(rg[R_INTREGISTER].preserved_by_proc,RS_ESI);
  1610. include(rg[R_INTREGISTER].preserved_by_proc,RS_EDI);
  1611. end;
  1612. procedure tcgx86.g_restore_standard_registers(list:Taasmoutput);
  1613. var
  1614. href : treference;
  1615. begin
  1616. { Copy registers from temp }
  1617. href:=current_procinfo.save_regs_ref;
  1618. if RS_EBX in rg[R_INTREGISTER].used_in_proc then
  1619. begin
  1620. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_EBX);
  1621. inc(href.offset,POINTER_SIZE);
  1622. end;
  1623. if RS_ESI in rg[R_INTREGISTER].used_in_proc then
  1624. begin
  1625. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_ESI);
  1626. inc(href.offset,POINTER_SIZE);
  1627. end;
  1628. if RS_EDI in rg[R_INTREGISTER].used_in_proc then
  1629. begin
  1630. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_EDI);
  1631. inc(href.offset,POINTER_SIZE);
  1632. end;
  1633. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1634. end;
  1635. procedure tcgx86.g_save_all_registers(list : taasmoutput);
  1636. begin
  1637. list.concat(Taicpu.Op_none(A_PUSHA,S_L));
  1638. tg.GetTemp(list,POINTER_SIZE,tt_noreuse,current_procinfo.save_regs_ref);
  1639. a_load_reg_ref(list,OS_ADDR,OS_ADDR,NR_ESP,current_procinfo.save_regs_ref);
  1640. end;
  1641. procedure tcgx86.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);
  1642. var
  1643. href : treference;
  1644. begin
  1645. a_load_ref_reg(list,OS_ADDR,OS_ADDR,current_procinfo.save_regs_ref,NR_ESP);
  1646. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1647. if acchiused then
  1648. begin
  1649. reference_reset_base(href,NR_ESP,20);
  1650. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,NR_EDX,href));
  1651. end;
  1652. if accused then
  1653. begin
  1654. reference_reset_base(href,NR_ESP,28);
  1655. list.concat(Taicpu.Op_reg_ref(A_MOV,S_L,NR_EAX,href));
  1656. end;
  1657. list.concat(Taicpu.Op_none(A_POPA,S_L));
  1658. { We add a NOP because of the 386DX CPU bugs with POPAD }
  1659. list.concat(taicpu.op_none(A_NOP,S_L));
  1660. end;
  1661. { produces if necessary overflowcode }
  1662. procedure tcgx86.g_overflowcheck(list: taasmoutput; const l:tlocation;def:tdef);
  1663. var
  1664. hl : tasmlabel;
  1665. ai : taicpu;
  1666. cond : TAsmCond;
  1667. begin
  1668. if not(cs_check_overflow in aktlocalswitches) then
  1669. exit;
  1670. objectlibrary.getlabel(hl);
  1671. if not ((def.deftype=pointerdef) or
  1672. ((def.deftype=orddef) and
  1673. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1674. bool8bit,bool16bit,bool32bit]))) then
  1675. cond:=C_NO
  1676. else
  1677. cond:=C_NB;
  1678. ai:=Taicpu.Op_Sym(A_Jcc,S_NO,hl);
  1679. ai.SetCondition(cond);
  1680. ai.is_jmp:=true;
  1681. list.concat(ai);
  1682. a_call_name(list,'FPC_OVERFLOW');
  1683. a_label(list,hl);
  1684. end;
  1685. end.
  1686. {
  1687. $Log$
  1688. Revision 1.101 2004-01-14 21:43:54 peter
  1689. * add release_openarrayvalue
  1690. Revision 1.100 2003/12/26 14:02:30 peter
  1691. * sparc updates
  1692. * use registertype in spill_register
  1693. Revision 1.99 2003/12/26 13:19:16 florian
  1694. * rtl and compiler compile with -Cfsse2
  1695. Revision 1.98 2003/12/26 00:32:22 florian
  1696. + fpu<->mm register conversion
  1697. Revision 1.97 2003/12/25 12:01:35 florian
  1698. + possible sse2 unit usage for double calculations
  1699. * some sse2 assembler issues fixed
  1700. Revision 1.96 2003/12/25 01:07:09 florian
  1701. + $fputype directive support
  1702. + single data type operations with sse unit
  1703. * fixed more x86-64 stuff
  1704. Revision 1.95 2003/12/24 01:47:23 florian
  1705. * first fixes to compile the x86-64 system unit
  1706. Revision 1.94 2003/12/24 00:10:03 florian
  1707. - delete parameter in cg64 methods removed
  1708. Revision 1.93 2003/12/21 19:42:43 florian
  1709. * fixed ppc inlining stuff
  1710. * fixed wrong unit writing
  1711. + added some sse stuff
  1712. Revision 1.92 2003/12/19 22:08:44 daniel
  1713. * Some work to restore the MMX capabilities
  1714. Revision 1.91 2003/12/15 21:25:49 peter
  1715. * reg allocations for imaginary register are now inserted just
  1716. before reg allocation
  1717. * tregister changed to enum to allow compile time check
  1718. * fixed several tregister-tsuperregister errors
  1719. Revision 1.90 2003/12/12 17:16:18 peter
  1720. * rg[tregistertype] added in tcg
  1721. Revision 1.89 2003/12/06 01:15:23 florian
  1722. * reverted Peter's alloctemp patch; hopefully properly
  1723. Revision 1.88 2003/12/03 23:13:20 peter
  1724. * delayed paraloc allocation, a_param_*() gets extra parameter
  1725. if it needs to allocate temp or real paralocation
  1726. * optimized/simplified int-real loading
  1727. Revision 1.87 2003/11/05 23:06:03 florian
  1728. * elesize of g_copyvaluepara_openarray changed
  1729. Revision 1.86 2003/10/30 18:53:53 marco
  1730. * profiling fix
  1731. Revision 1.85 2003/10/30 16:22:40 peter
  1732. * call firstpass before allocation and codegeneration is started
  1733. * move leftover code from pass_2.generatecode() to psub
  1734. Revision 1.84 2003/10/29 21:24:14 jonas
  1735. + support for fpu temp parameters
  1736. + saving/restoring of fpu register before/after a procedure call
  1737. Revision 1.83 2003/10/20 19:30:08 peter
  1738. * remove memdebug code for rg
  1739. Revision 1.82 2003/10/18 15:41:26 peter
  1740. * made worklists dynamic in size
  1741. Revision 1.81 2003/10/17 15:25:18 florian
  1742. * fixed more ppc stuff
  1743. Revision 1.80 2003/10/17 14:38:32 peter
  1744. * 64k registers supported
  1745. * fixed some memory leaks
  1746. Revision 1.79 2003/10/14 00:30:48 florian
  1747. + some code for PIC support added
  1748. Revision 1.78 2003/10/13 01:23:13 florian
  1749. * some ideas for mm support implemented
  1750. Revision 1.77 2003/10/11 16:06:42 florian
  1751. * fixed some MMX<->SSE
  1752. * started to fix ppc, needs an overhaul
  1753. + stabs info improve for spilling, not sure if it works correctly/completly
  1754. - MMX_SUPPORT removed from Makefile.fpc
  1755. Revision 1.76 2003/10/10 17:48:14 peter
  1756. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  1757. * tregisteralloctor renamed to trgobj
  1758. * removed rgobj from a lot of units
  1759. * moved location_* and reference_* to cgobj
  1760. * first things for mmx register allocation
  1761. Revision 1.75 2003/10/09 21:31:37 daniel
  1762. * Register allocator splitted, ans abstract now
  1763. Revision 1.74 2003/10/07 16:09:03 florian
  1764. * x86 supports only mem/reg to reg for movsx and movzx
  1765. Revision 1.73 2003/10/07 15:17:07 peter
  1766. * inline supported again, LOC_REFERENCEs are used to pass the
  1767. parameters
  1768. * inlineparasymtable,inlinelocalsymtable removed
  1769. * exitlabel inserting fixed
  1770. Revision 1.72 2003/10/03 22:00:33 peter
  1771. * parameter alignment fixes
  1772. Revision 1.71 2003/10/03 14:45:37 peter
  1773. * save ESP after pusha and restore before popa for save all registers
  1774. Revision 1.70 2003/10/01 20:34:51 peter
  1775. * procinfo unit contains tprocinfo
  1776. * cginfo renamed to cgbase
  1777. * moved cgmessage to verbose
  1778. * fixed ppc and sparc compiles
  1779. Revision 1.69 2003/09/30 19:53:47 peter
  1780. * fix pushw reg
  1781. Revision 1.68 2003/09/29 20:58:56 peter
  1782. * optimized releasing of registers
  1783. Revision 1.67 2003/09/28 13:37:19 peter
  1784. * a_call_ref removed
  1785. Revision 1.66 2003/09/25 21:29:16 peter
  1786. * change push/pop in getreg/ungetreg
  1787. Revision 1.65 2003/09/25 13:13:32 florian
  1788. * more x86-64 fixes
  1789. Revision 1.64 2003/09/11 11:55:00 florian
  1790. * improved arm code generation
  1791. * move some protected and private field around
  1792. * the temp. register for register parameters/arguments are now released
  1793. before the move to the parameter register is done. This improves
  1794. the code in a lot of cases.
  1795. Revision 1.63 2003/09/09 21:03:17 peter
  1796. * basics for x86 register calling
  1797. Revision 1.62 2003/09/09 20:59:27 daniel
  1798. * Adding register allocation order
  1799. Revision 1.61 2003/09/07 22:09:35 peter
  1800. * preparations for different default calling conventions
  1801. * various RA fixes
  1802. Revision 1.60 2003/09/05 17:41:13 florian
  1803. * merged Wiktor's Watcom patches in 1.1
  1804. Revision 1.59 2003/09/03 15:55:02 peter
  1805. * NEWRA branch merged
  1806. Revision 1.58.2.5 2003/08/31 20:40:50 daniel
  1807. * Fixed add_edges_used
  1808. Revision 1.58.2.4 2003/08/31 15:46:26 peter
  1809. * more updates for tregister
  1810. Revision 1.58.2.3 2003/08/29 17:29:00 peter
  1811. * next batch of updates
  1812. Revision 1.58.2.2 2003/08/28 18:35:08 peter
  1813. * tregister changed to cardinal
  1814. Revision 1.58.2.1 2003/08/27 21:06:34 peter
  1815. * more updates
  1816. Revision 1.58 2003/08/20 19:28:21 daniel
  1817. * Small NOTARGETWIN32 conditional tweak
  1818. Revision 1.57 2003/07/03 18:59:25 peter
  1819. * loadfpu_reg_reg size specifier
  1820. Revision 1.56 2003/06/14 14:53:50 jonas
  1821. * fixed newra cycle for x86
  1822. * added constants for indicating source and destination operands of the
  1823. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  1824. Revision 1.55 2003/06/13 21:19:32 peter
  1825. * current_procdef removed, use current_procinfo.procdef instead
  1826. Revision 1.54 2003/06/12 18:31:18 peter
  1827. * fix newra cycle for i386
  1828. Revision 1.53 2003/06/07 10:24:10 peter
  1829. * fixed copyvaluepara for left-to-right pushing
  1830. Revision 1.52 2003/06/07 10:06:55 jonas
  1831. * fixed cycling problem
  1832. Revision 1.51 2003/06/03 21:11:09 peter
  1833. * cg.a_load_* get a from and to size specifier
  1834. * makeregsize only accepts newregister
  1835. * i386 uses generic tcgnotnode,tcgunaryminus
  1836. Revision 1.50 2003/06/03 13:01:59 daniel
  1837. * Register allocator finished
  1838. Revision 1.49 2003/06/01 21:38:07 peter
  1839. * getregisterfpu size parameter added
  1840. * op_const_reg size parameter added
  1841. * sparc updates
  1842. Revision 1.48 2003/05/30 23:57:08 peter
  1843. * more sparc cleanup
  1844. * accumulator removed, splitted in function_return_reg (called) and
  1845. function_result_reg (caller)
  1846. Revision 1.47 2003/05/22 21:33:31 peter
  1847. * removed some unit dependencies
  1848. Revision 1.46 2003/05/16 14:33:31 peter
  1849. * regvar fixes
  1850. Revision 1.45 2003/05/15 18:58:54 peter
  1851. * removed selfpointer_offset, vmtpointer_offset
  1852. * tvarsym.adjusted_address
  1853. * address in localsymtable is now in the real direction
  1854. * removed some obsolete globals
  1855. Revision 1.44 2003/04/30 20:53:32 florian
  1856. * error when address of an abstract method is taken
  1857. * fixed some x86-64 problems
  1858. * merged some more x86-64 and i386 code
  1859. Revision 1.43 2003/04/27 11:21:36 peter
  1860. * aktprocdef renamed to current_procinfo.procdef
  1861. * procinfo renamed to current_procinfo
  1862. * procinfo will now be stored in current_module so it can be
  1863. cleaned up properly
  1864. * gen_main_procsym changed to create_main_proc and release_main_proc
  1865. to also generate a tprocinfo structure
  1866. * fixed unit implicit initfinal
  1867. Revision 1.42 2003/04/23 14:42:08 daniel
  1868. * Further register allocator work. Compiler now smaller with new
  1869. allocator than without.
  1870. * Somebody forgot to adjust ppu version number
  1871. Revision 1.41 2003/04/23 09:51:16 daniel
  1872. * Removed usage of edi in a lot of places when new register allocator used
  1873. + Added newra versions of g_concatcopy and secondadd_float
  1874. Revision 1.40 2003/04/22 13:47:08 peter
  1875. * fixed C style array of const
  1876. * fixed C array passing
  1877. * fixed left to right with high parameters
  1878. Revision 1.39 2003/04/22 10:09:35 daniel
  1879. + Implemented the actual register allocator
  1880. + Scratch registers unavailable when new register allocator used
  1881. + maybe_save/maybe_restore unavailable when new register allocator used
  1882. Revision 1.38 2003/04/17 16:48:21 daniel
  1883. * Added some code to keep track of move instructions in register
  1884. allocator
  1885. Revision 1.37 2003/03/28 19:16:57 peter
  1886. * generic constructor working for i386
  1887. * remove fixed self register
  1888. * esi added as address register for i386
  1889. Revision 1.36 2003/03/18 18:17:46 peter
  1890. * reg2opsize()
  1891. Revision 1.35 2003/03/13 19:52:23 jonas
  1892. * and more new register allocator fixes (in the i386 code generator this
  1893. time). At least now the ppc cross compiler can compile the linux
  1894. system unit again, but I haven't tested it.
  1895. Revision 1.34 2003/02/27 16:40:32 daniel
  1896. * Fixed ie 200301234 problem on Win32 target
  1897. Revision 1.33 2003/02/26 21:15:43 daniel
  1898. * Fixed the optimizer
  1899. Revision 1.32 2003/02/19 22:00:17 daniel
  1900. * Code generator converted to new register notation
  1901. - Horribily outdated todo.txt removed
  1902. Revision 1.31 2003/01/21 10:41:13 daniel
  1903. * Fixed another 200301081
  1904. Revision 1.30 2003/01/13 23:00:18 daniel
  1905. * Fixed internalerror
  1906. Revision 1.29 2003/01/13 14:54:34 daniel
  1907. * Further work to convert codegenerator register convention;
  1908. internalerror bug fixed.
  1909. Revision 1.28 2003/01/09 20:41:00 daniel
  1910. * Converted some code in cgx86.pas to new register numbering
  1911. Revision 1.27 2003/01/08 18:43:58 daniel
  1912. * Tregister changed into a record
  1913. Revision 1.26 2003/01/05 13:36:53 florian
  1914. * x86-64 compiles
  1915. + very basic support for float128 type (x86-64 only)
  1916. Revision 1.25 2003/01/02 16:17:50 peter
  1917. * align stack on 4 bytes in copyvalueopenarray
  1918. Revision 1.24 2002/12/24 15:56:50 peter
  1919. * stackpointer_alloc added for adjusting ESP. Win32 needs
  1920. this for the pageprotection
  1921. Revision 1.23 2002/11/25 18:43:34 carl
  1922. - removed the invalid if <> checking (Delphi is strange on this)
  1923. + implemented abstract warning on instance creation of class with
  1924. abstract methods.
  1925. * some error message cleanups
  1926. Revision 1.22 2002/11/25 17:43:29 peter
  1927. * splitted defbase in defutil,symutil,defcmp
  1928. * merged isconvertable and is_equal into compare_defs(_ext)
  1929. * made operator search faster by walking the list only once
  1930. Revision 1.21 2002/11/18 17:32:01 peter
  1931. * pass proccalloption to ret_in_xxx and push_xxx functions
  1932. Revision 1.20 2002/11/09 21:18:31 carl
  1933. * flags2reg() was not extending the byte register to the correct result size
  1934. Revision 1.19 2002/10/16 19:01:43 peter
  1935. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1936. implicit exception frames for procedures with initialized variables
  1937. and for constructors. The default is on for compatibility
  1938. Revision 1.18 2002/10/05 12:43:30 carl
  1939. * fixes for Delphi 6 compilation
  1940. (warning : Some features do not work under Delphi)
  1941. Revision 1.17 2002/09/17 18:54:06 jonas
  1942. * a_load_reg_reg() now has two size parameters: source and dest. This
  1943. allows some optimizations on architectures that don't encode the
  1944. register size in the register name.
  1945. Revision 1.16 2002/09/16 19:08:47 peter
  1946. * support references without registers and symbol in paramref_addr. It
  1947. pushes only the offset
  1948. Revision 1.15 2002/09/16 18:06:29 peter
  1949. * move CGSize2Opsize to interface
  1950. Revision 1.14 2002/09/01 14:42:41 peter
  1951. * removevaluepara added to fix the stackpointer so restoring of
  1952. saved registers works
  1953. Revision 1.13 2002/09/01 12:09:27 peter
  1954. + a_call_reg, a_call_loc added
  1955. * removed exprasmlist references
  1956. Revision 1.12 2002/08/17 09:23:50 florian
  1957. * first part of procinfo rewrite
  1958. Revision 1.11 2002/08/16 14:25:00 carl
  1959. * issameref() to test if two references are the same (then emit no opcodes)
  1960. + ret_in_reg to replace ret_in_acc
  1961. (fix some register allocation bugs at the same time)
  1962. + save_std_register now has an extra parameter which is the
  1963. usedinproc registers
  1964. Revision 1.10 2002/08/15 08:13:54 carl
  1965. - a_load_sym_ofs_reg removed
  1966. * loadvmt now calls loadaddr_ref_reg instead
  1967. Revision 1.9 2002/08/11 14:32:33 peter
  1968. * renamed current_library to objectlibrary
  1969. Revision 1.8 2002/08/11 13:24:20 peter
  1970. * saving of asmsymbols in ppu supported
  1971. * asmsymbollist global is removed and moved into a new class
  1972. tasmlibrarydata that will hold the info of a .a file which
  1973. corresponds with a single module. Added librarydata to tmodule
  1974. to keep the library info stored for the module. In the future the
  1975. objectfiles will also be stored to the tasmlibrarydata class
  1976. * all getlabel/newasmsymbol and friends are moved to the new class
  1977. Revision 1.7 2002/08/10 10:06:04 jonas
  1978. * fixed stupid bug of mine in g_flags2reg() when optimizations are on
  1979. Revision 1.6 2002/08/09 19:18:27 carl
  1980. * fix generic exception handling
  1981. Revision 1.5 2002/08/04 19:52:04 carl
  1982. + updated exception routines
  1983. Revision 1.4 2002/07/27 19:53:51 jonas
  1984. + generic implementation of tcg.g_flags2ref()
  1985. * tcg.flags2xxx() now also needs a size parameter
  1986. Revision 1.3 2002/07/26 21:15:46 florian
  1987. * rewrote the system handling
  1988. Revision 1.2 2002/07/21 16:55:34 jonas
  1989. * fixed bug in op_const_reg_reg() for imul
  1990. Revision 1.1 2002/07/20 19:28:47 florian
  1991. * splitting of i386\cgcpu.pas into x86\cgx86.pas and i386\cgcpu.pas
  1992. cgx86.pas will contain the common code for i386 and x86_64
  1993. }