cgobj.pas 124 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018
  1. {
  2. Copyright (c) 1998-2005 by Florian Klaempfl
  3. Member of the Free Pascal development team
  4. This unit implements the basic code generator object
  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. {# @abstract(Abstract code generator unit)
  19. Abstreact code generator unit. This contains the base class
  20. to implement for all new supported processors.
  21. WARNING: None of the routines implemented in these modules,
  22. or their descendants, should use the temp. allocator, as
  23. these routines may be called inside genentrycode, and the
  24. stack frame is already setup!
  25. }
  26. unit cgobj;
  27. {$i fpcdefs.inc}
  28. interface
  29. uses
  30. globtype,constexp,
  31. cpubase,cgbase,cgutils,parabase,
  32. aasmbase,aasmtai,aasmdata,aasmcpu,
  33. symconst,symtype,symdef,rgobj
  34. ;
  35. type
  36. talignment = (AM_NATURAL,AM_NONE,AM_2BYTE,AM_4BYTE,AM_8BYTE);
  37. {# @abstract(Abstract code generator)
  38. This class implements an abstract instruction generator. Some of
  39. the methods of this class are generic, while others must
  40. be overridden for all new processors which will be supported
  41. by Free Pascal. For 32-bit processors, the base class
  42. should be @link(tcg64f32) and not @var(tcg).
  43. }
  44. { tcg }
  45. tcg = class
  46. { how many times is this current code executed }
  47. executionweight : longint;
  48. alignment : talignment;
  49. rg : array[tregistertype] of trgobj;
  50. {$ifdef flowgraph}
  51. aktflownode:word;
  52. {$endif}
  53. {************************************************}
  54. { basic routines }
  55. constructor create;
  56. {# Initialize the register allocators needed for the codegenerator.}
  57. procedure init_register_allocators;virtual;
  58. {# Clean up the register allocators needed for the codegenerator.}
  59. procedure done_register_allocators;virtual;
  60. {# Set whether live_start or live_end should be updated when allocating registers, needed when e.g. generating initcode after the rest of the code. }
  61. procedure set_regalloc_live_range_direction(dir: TRADirection);
  62. {$ifdef flowgraph}
  63. procedure init_flowgraph;
  64. procedure done_flowgraph;
  65. {$endif}
  66. {# Gets a register suitable to do integer operations on.}
  67. function getintregister(list:TAsmList;size:Tcgsize):Tregister;virtual;
  68. {# Gets a register suitable to do integer operations on.}
  69. function getaddressregister(list:TAsmList):Tregister;virtual;
  70. function getfpuregister(list:TAsmList;size:Tcgsize):Tregister;virtual;
  71. function getmmregister(list:TAsmList;size:Tcgsize):Tregister;virtual;
  72. function getflagregister(list:TAsmList;size:Tcgsize):Tregister;virtual;
  73. {Does the generic cg need SIMD registers, like getmmxregister? Or should
  74. the cpu specific child cg object have such a method?}
  75. procedure add_reg_instruction(instr:Tai;r:tregister);virtual;
  76. procedure add_move_instruction(instr:Taicpu);virtual;
  77. function uses_registers(rt:Tregistertype):boolean;virtual;
  78. {# Get a specific register.}
  79. procedure getcpuregister(list:TAsmList;r:Tregister);virtual;
  80. procedure ungetcpuregister(list:TAsmList;r:Tregister);virtual;
  81. {# Get multiple registers specified.}
  82. procedure alloccpuregisters(list:TAsmList;rt:Tregistertype;const r:Tcpuregisterset);virtual;
  83. {# Free multiple registers specified.}
  84. procedure dealloccpuregisters(list:TAsmList;rt:Tregistertype;const r:Tcpuregisterset);virtual;
  85. procedure allocallcpuregisters(list:TAsmList);virtual;
  86. procedure deallocallcpuregisters(list:TAsmList);virtual;
  87. procedure do_register_allocation(list:TAsmList;headertai:tai);virtual;
  88. procedure translate_register(var reg : tregister);
  89. function makeregsize(list:TAsmList;reg:Tregister;size:Tcgsize):Tregister;
  90. {# Emit a label to the instruction stream. }
  91. procedure a_label(list : TAsmList;l : tasmlabel);virtual;
  92. {# Allocates register r by inserting a pai_realloc record }
  93. procedure a_reg_alloc(list : TAsmList;r : tregister);
  94. {# Deallocates register r by inserting a pa_regdealloc record}
  95. procedure a_reg_dealloc(list : TAsmList;r : tregister);
  96. { Synchronize register, make sure it is still valid }
  97. procedure a_reg_sync(list : TAsmList;r : tregister);
  98. {# Pass a parameter, which is located in a register, to a routine.
  99. This routine should push/send the parameter to the routine, as
  100. required by the specific processor ABI and routine modifiers.
  101. It must generate register allocation information for the cgpara in
  102. case it consists of cpuregisters.
  103. @param(size size of the operand in the register)
  104. @param(r register source of the operand)
  105. @param(cgpara where the parameter will be stored)
  106. }
  107. procedure a_load_reg_cgpara(list : TAsmList;size : tcgsize;r : tregister;const cgpara : TCGPara);virtual;
  108. {# Pass a parameter, which is a constant, to a routine.
  109. A generic version is provided. This routine should
  110. be overridden for optimization purposes if the cpu
  111. permits directly sending this type of parameter.
  112. It must generate register allocation information for the cgpara in
  113. case it consists of cpuregisters.
  114. @param(size size of the operand in constant)
  115. @param(a value of constant to send)
  116. @param(cgpara where the parameter will be stored)
  117. }
  118. procedure a_load_const_cgpara(list : TAsmList;size : tcgsize;a : tcgint;const cgpara : TCGPara);virtual;
  119. {# Pass the value of a parameter, which is located in memory, to a routine.
  120. A generic version is provided. This routine should
  121. be overridden for optimization purposes if the cpu
  122. permits directly sending this type of parameter.
  123. It must generate register allocation information for the cgpara in
  124. case it consists of cpuregisters.
  125. @param(size size of the operand in constant)
  126. @param(r Memory reference of value to send)
  127. @param(cgpara where the parameter will be stored)
  128. }
  129. procedure a_load_ref_cgpara(list : TAsmList;size : tcgsize;const r : treference;const cgpara : TCGPara);virtual;
  130. {# Pass the value of a parameter, which can be located either in a register or memory location,
  131. to a routine.
  132. A generic version is provided.
  133. @param(l location of the operand to send)
  134. @param(nr parameter number (starting from one) of routine (from left to right))
  135. @param(cgpara where the parameter will be stored)
  136. }
  137. procedure a_load_loc_cgpara(list : TAsmList;const l : tlocation;const cgpara : TCGPara);
  138. {# Pass the address of a reference to a routine. This routine
  139. will calculate the address of the reference, and pass this
  140. calculated address as a parameter.
  141. It must generate register allocation information for the cgpara in
  142. case it consists of cpuregisters.
  143. A generic version is provided. This routine should
  144. be overridden for optimization purposes if the cpu
  145. permits directly sending this type of parameter.
  146. @param(r reference to get address from)
  147. @param(nr parameter number (starting from one) of routine (from left to right))
  148. }
  149. procedure a_loadaddr_ref_cgpara(list : TAsmList;const r : treference;const cgpara : TCGPara);virtual;
  150. {# Load a cgparaloc into a memory reference.
  151. It must generate register allocation information for the cgpara in
  152. case it consists of cpuregisters.
  153. @param(paraloc the source parameter sublocation)
  154. @param(ref the destination reference)
  155. @param(sizeleft indicates the total number of bytes left in all of
  156. the remaining sublocations of this parameter (the current
  157. sublocation and all of the sublocations coming after it).
  158. In case this location is also a reference, it is assumed
  159. to be the final part sublocation of the parameter and that it
  160. contains all of the "sizeleft" bytes).)
  161. @param(align the alignment of the paraloc in case it's a reference)
  162. }
  163. procedure a_load_cgparaloc_ref(list : TAsmList;const paraloc : TCGParaLocation;const ref : treference;sizeleft : tcgint;align : longint);
  164. {# Load a cgparaloc into any kind of register (int, fp, mm).
  165. @param(regsize the size of the destination register)
  166. @param(paraloc the source parameter sublocation)
  167. @param(reg the destination register)
  168. @param(align the alignment of the paraloc in case it's a reference)
  169. }
  170. procedure a_load_cgparaloc_anyreg(list : TAsmList;regsize : tcgsize;const paraloc : TCGParaLocation;reg : tregister;align : longint);
  171. { Remarks:
  172. * If a method specifies a size you have only to take care
  173. of that number of bits, i.e. load_const_reg with OP_8 must
  174. only load the lower 8 bit of the specified register
  175. the rest of the register can be undefined
  176. if necessary the compiler will call a method
  177. to zero or sign extend the register
  178. * The a_load_XX_XX with OP_64 needn't to be
  179. implemented for 32 bit
  180. processors, the code generator takes care of that
  181. * the addr size is for work with the natural pointer
  182. size
  183. * the procedures without fpu/mm are only for integer usage
  184. * normally the first location is the source and the
  185. second the destination
  186. }
  187. {# Emits instruction to call the method specified by symbol name.
  188. This routine must be overridden for each new target cpu.
  189. }
  190. procedure a_call_name(list : TAsmList;const s : string; weak: boolean);virtual; abstract;
  191. procedure a_call_reg(list : TAsmList;reg : tregister);virtual; abstract;
  192. { same as a_call_name, might be overridden on certain architectures to emit
  193. static calls without usage of a got trampoline }
  194. procedure a_call_name_static(list : TAsmList;const s : string);virtual;
  195. { move instructions }
  196. procedure a_load_const_reg(list : TAsmList;size : tcgsize;a : tcgint;register : tregister);virtual; abstract;
  197. procedure a_load_const_ref(list : TAsmList;size : tcgsize;a : tcgint;const ref : treference);virtual;
  198. procedure a_load_const_loc(list : TAsmList;a : tcgint;const loc : tlocation);
  199. procedure a_load_reg_ref(list : TAsmList;fromsize,tosize : tcgsize;register : tregister;const ref : treference);virtual; abstract;
  200. procedure a_load_reg_ref_unaligned(list : TAsmList;fromsize,tosize : tcgsize;register : tregister;const ref : treference);virtual;
  201. procedure a_load_reg_reg(list : TAsmList;fromsize,tosize : tcgsize;reg1,reg2 : tregister);virtual; abstract;
  202. procedure a_load_reg_loc(list : TAsmList;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  203. procedure a_load_ref_reg(list : TAsmList;fromsize,tosize : tcgsize;const ref : treference;register : tregister);virtual; abstract;
  204. procedure a_load_ref_reg_unaligned(list : TAsmList;fromsize,tosize : tcgsize;const ref : treference;register : tregister);virtual;
  205. procedure a_load_ref_ref(list : TAsmList;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);virtual;
  206. procedure a_load_loc_reg(list : TAsmList;tosize: tcgsize; const loc: tlocation; reg : tregister);
  207. procedure a_load_loc_ref(list : TAsmList;tosize: tcgsize; const loc: tlocation; const ref : treference);
  208. procedure a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);virtual; abstract;
  209. { bit scan instructions }
  210. procedure a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; srcsize, dstsize: tcgsize; src, dst: TRegister); virtual;
  211. { Multiplication with doubling result size.
  212. dstlo or dsthi may be NR_NO, in which case corresponding half of result is discarded. }
  213. procedure a_mul_reg_reg_pair(list: TAsmList; size: tcgsize; src1,src2,dstlo,dsthi: TRegister);virtual;
  214. { fpu move instructions }
  215. procedure a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize:tcgsize; reg1, reg2: tregister); virtual; abstract;
  216. procedure a_loadfpu_ref_reg(list: TAsmList; fromsize, tosize: tcgsize; const ref: treference; reg: tregister); virtual; abstract;
  217. procedure a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference); virtual; abstract;
  218. procedure a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tcgsize; const ref1,ref2: treference);
  219. procedure a_loadfpu_loc_reg(list: TAsmList; tosize: tcgsize; const loc: tlocation; const reg: tregister);
  220. procedure a_loadfpu_reg_loc(list: TAsmList; fromsize: tcgsize; const reg: tregister; const loc: tlocation);
  221. procedure a_loadfpu_reg_cgpara(list : TAsmList;size : tcgsize;const r : tregister;const cgpara : TCGPara);virtual;
  222. procedure a_loadfpu_ref_cgpara(list : TAsmList;size : tcgsize;const ref : treference;const cgpara : TCGPara);virtual;
  223. { vector register move instructions }
  224. procedure a_loadmm_reg_reg(list: TAsmList; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); virtual;
  225. procedure a_loadmm_ref_reg(list: TAsmList; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual;
  226. procedure a_loadmm_reg_ref(list: TAsmList; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); virtual;
  227. procedure a_loadmm_loc_reg(list: TAsmList; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  228. procedure a_loadmm_reg_loc(list: TAsmList; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  229. procedure a_loadmm_reg_cgpara(list: TAsmList; size: tcgsize; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  230. procedure a_loadmm_ref_cgpara(list: TAsmList; size: tcgsize; const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  231. procedure a_loadmm_loc_cgpara(list: TAsmList; const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  232. procedure a_opmm_reg_reg(list: TAsmList; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle); virtual;
  233. procedure a_opmm_ref_reg(list: TAsmList; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual;
  234. procedure a_opmm_loc_reg(list: TAsmList; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle); virtual;
  235. procedure a_opmm_reg_ref(list: TAsmList; Op: TOpCG; size : tcgsize;reg: tregister;const ref: treference; shuffle : pmmshuffle); virtual;
  236. procedure a_opmm_loc_reg_reg(list: TAsmList;Op : TOpCG;size : tcgsize;const loc : tlocation;src,dst : tregister;shuffle : pmmshuffle); virtual;
  237. procedure a_opmm_reg_reg_reg(list: TAsmList; Op: TOpCG; size : tcgsize;src1,src2,dst: tregister;shuffle : pmmshuffle); virtual;
  238. procedure a_opmm_ref_reg_reg(list: TAsmList; Op: TOpCG; size : tcgsize;const ref: treference; src,dst: tregister;shuffle : pmmshuffle); virtual;
  239. procedure a_loadmm_intreg_reg(list: TAsmList; fromsize, tosize : tcgsize; intreg, mmreg: tregister; shuffle: pmmshuffle); virtual;
  240. procedure a_loadmm_reg_intreg(list: TAsmList; fromsize, tosize : tcgsize; mmreg, intreg: tregister; shuffle : pmmshuffle); virtual;
  241. { basic arithmetic operations }
  242. { note: for operators which require only one argument (not, neg), use }
  243. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  244. { that in this case the *second* operand is used as both source and }
  245. { destination (JM) }
  246. procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: tcgint; reg: TRegister); virtual; abstract;
  247. procedure a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: tcgint; const ref: TReference); virtual;
  248. procedure a_op_const_loc(list : TAsmList; Op: TOpCG; a: tcgint; const loc: tlocation);
  249. procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); virtual; abstract;
  250. procedure a_op_reg_ref(list : TAsmList; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); virtual;
  251. procedure a_op_ref_reg(list : TAsmList; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); virtual;
  252. procedure a_op_reg_loc(list : TAsmList; Op: TOpCG; reg: tregister; const loc: tlocation);
  253. procedure a_op_ref_loc(list : TAsmList; Op: TOpCG; const ref: TReference; const loc: tlocation);
  254. { trinary operations for processors that support them, 'emulated' }
  255. { on others. None with "ref" arguments since I don't think there }
  256. { are any processors that support it (JM) }
  257. procedure a_op_const_reg_reg(list: TAsmList; op: TOpCg; size: tcgsize; a: tcgint; src, dst: tregister); virtual;
  258. procedure a_op_reg_reg_reg(list: TAsmList; op: TOpCg; size: tcgsize; src1, src2, dst: tregister); virtual;
  259. procedure a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; a: tcgint; src, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  260. procedure a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  261. { comparison operations }
  262. procedure a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : tcgint;reg : tregister;
  263. l : tasmlabel); virtual;
  264. procedure a_cmp_const_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : tcgint;const ref : treference;
  265. l : tasmlabel); virtual;
  266. procedure a_cmp_const_loc_label(list: TAsmList; size: tcgsize;cmp_op: topcmp; a: tcgint; const loc: tlocation;
  267. l : tasmlabel);
  268. procedure a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  269. procedure a_cmp_ref_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  270. procedure a_cmp_reg_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); virtual;
  271. procedure a_cmp_loc_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  272. procedure a_cmp_reg_loc_label(list : TAsmList;size : tcgsize;cmp_op : topcmp; reg: tregister; const loc: tlocation; l : tasmlabel);
  273. procedure a_cmp_ref_loc_label(list: TAsmList; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation;
  274. l : tasmlabel);
  275. procedure a_jmp_name(list : TAsmList;const s : string); virtual; abstract;
  276. procedure a_jmp_always(list : TAsmList;l: tasmlabel); virtual; abstract;
  277. {$ifdef cpuflags}
  278. procedure a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel); virtual; abstract;
  279. {# Depending on the value to check in the flags, either sets the register reg to one (if the flag is set)
  280. or zero (if the flag is cleared). The size parameter indicates the destination size register.
  281. }
  282. procedure g_flags2reg(list: TAsmList; size: TCgSize; const f: tresflags; reg: TRegister); virtual; abstract;
  283. procedure g_flags2ref(list: TAsmList; size: TCgSize; const f: tresflags; const ref:TReference); virtual;
  284. {$endif cpuflags}
  285. {
  286. This routine tries to optimize the op_const_reg/ref opcode, and should be
  287. called at the start of a_op_const_reg/ref. It returns the actual opcode
  288. to emit, and the constant value to emit. This function can opcode OP_NONE to
  289. remove the opcode and OP_MOVE to replace it with a simple load
  290. @param(size Size of the operand in constant)
  291. @param(op The opcode to emit, returns the opcode which must be emitted)
  292. @param(a The constant which should be emitted, returns the constant which must
  293. be emitted)
  294. }
  295. procedure optimize_op_const(size: TCGSize; var op: topcg; var a : tcgint);virtual;
  296. {#
  297. This routine is used in exception management nodes. It should
  298. save the exception reason currently in the FUNCTION_RETURN_REG. The
  299. save should be done either to a temp (pointed to by href).
  300. or on the stack (pushing the value on the stack).
  301. The size of the value to save is OS_S32. The default version
  302. saves the exception reason to a temp. memory area.
  303. }
  304. procedure g_exception_reason_save(list : TAsmList; const href : treference);virtual;
  305. {#
  306. This routine is used in exception management nodes. It should
  307. save the exception reason constant. The
  308. save should be done either to a temp (pointed to by href).
  309. or on the stack (pushing the value on the stack).
  310. The size of the value to save is OS_S32. The default version
  311. saves the exception reason to a temp. memory area.
  312. }
  313. procedure g_exception_reason_save_const(list : TAsmList; const href : treference; a: tcgint);virtual;
  314. {#
  315. This routine is used in exception management nodes. It should
  316. load the exception reason to the FUNCTION_RETURN_REG. The saved value
  317. should either be in the temp. area (pointed to by href , href should
  318. *NOT* be freed) or on the stack (the value should be popped).
  319. The size of the value to save is OS_S32. The default version
  320. saves the exception reason to a temp. memory area.
  321. }
  322. procedure g_exception_reason_load(list : TAsmList; const href : treference);virtual;
  323. procedure g_maybe_testvmt(list : TAsmList;reg:tregister;objdef:tobjectdef);
  324. {# This should emit the opcode to copy len bytes from the source
  325. to destination.
  326. It must be overridden for each new target processor.
  327. @param(source Source reference of copy)
  328. @param(dest Destination reference of copy)
  329. }
  330. procedure g_concatcopy(list : TAsmList;const source,dest : treference;len : tcgint);virtual; abstract;
  331. {# This should emit the opcode to copy len bytes from the an unaligned source
  332. to destination.
  333. It must be overridden for each new target processor.
  334. @param(source Source reference of copy)
  335. @param(dest Destination reference of copy)
  336. }
  337. procedure g_concatcopy_unaligned(list : TAsmList;const source,dest : treference;len : tcgint);virtual;
  338. {# Generates overflow checking code for a node }
  339. procedure g_overflowcheck(list: TAsmList; const Loc:tlocation; def:tdef); virtual;abstract;
  340. procedure g_overflowCheck_loc(List:TAsmList;const Loc:TLocation;def:TDef;ovloc : tlocation);virtual;
  341. {# Emits instructions when compilation is done in profile
  342. mode (this is set as a command line option). The default
  343. behavior does nothing, should be overridden as required.
  344. }
  345. procedure g_profilecode(list : TAsmList);virtual;
  346. {# Emits instruction for allocating @var(size) bytes at the stackpointer
  347. @param(size Number of bytes to allocate)
  348. }
  349. procedure g_stackpointer_alloc(list : TAsmList;size : longint);virtual;
  350. {# Emits instruction for allocating the locals in entry
  351. code of a routine. This is one of the first
  352. routine called in @var(genentrycode).
  353. @param(localsize Number of bytes to allocate as locals)
  354. }
  355. procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);virtual; abstract;
  356. {# Emits instructions for returning from a subroutine.
  357. Should also restore the framepointer and stack.
  358. @param(parasize Number of bytes of parameters to deallocate from stack)
  359. }
  360. procedure g_proc_exit(list : TAsmList;parasize:longint;nostackframe:boolean);virtual;abstract;
  361. {# This routine is called when generating the code for the entry point
  362. of a routine. It should save all registers which are not used in this
  363. routine, and which should be declared as saved in the std_saved_registers
  364. set.
  365. This routine is mainly used when linking to code which is generated
  366. by ABI-compliant compilers (like GCC), to make sure that the reserved
  367. registers of that ABI are not clobbered.
  368. @param(usedinproc Registers which are used in the code of this routine)
  369. }
  370. procedure g_save_registers(list:TAsmList);virtual;
  371. {# This routine is called when generating the code for the exit point
  372. of a routine. It should restore all registers which were previously
  373. saved in @var(g_save_standard_registers).
  374. @param(usedinproc Registers which are used in the code of this routine)
  375. }
  376. procedure g_restore_registers(list:TAsmList);virtual;
  377. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);virtual;abstract;
  378. procedure g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: tcgint);virtual;
  379. { generate a stub which only purpose is to pass control the given external method,
  380. setting up any additional environment before doing so (if required).
  381. The default implementation issues a jump instruction to the external name. }
  382. procedure g_external_wrapper(list : TAsmList; procdef: tprocdef; const externalname: string); virtual;
  383. { initialize the pic/got register }
  384. procedure g_maybe_got_init(list: TAsmList); virtual;
  385. { allocallcpuregisters, a_call_name, deallocallcpuregisters sequence }
  386. procedure g_call(list: TAsmList; const s: string);
  387. { Generate code to exit an unwind-protected region. The default implementation
  388. produces a simple jump to destination label. }
  389. procedure g_local_unwind(list: TAsmList; l: TAsmLabel);virtual;
  390. { Generate code for integer division by constant,
  391. generic version is suitable for 3-address CPUs }
  392. procedure g_div_const_reg_reg(list:tasmlist; size: TCgSize; a: tcgint; src,dst: tregister); virtual;
  393. protected
  394. function g_indirect_sym_load(list:TAsmList;const symname: string; const flags: tindsymflags): tregister;virtual;
  395. end;
  396. {$ifdef cpu64bitalu}
  397. { This class implements an abstract code generator class
  398. for 128 Bit operations, it applies currently only to 64 Bit CPUs and supports only simple operations
  399. }
  400. tcg128 = class
  401. procedure a_load128_reg_reg(list : TAsmList;regsrc,regdst : tregister128);virtual;
  402. procedure a_load128_reg_ref(list : TAsmList;reg : tregister128;const ref : treference);virtual;
  403. procedure a_load128_ref_reg(list : TAsmList;const ref : treference;reg : tregister128);virtual;
  404. procedure a_load128_loc_ref(list : TAsmList;const l : tlocation;const ref : treference);virtual;
  405. procedure a_load128_reg_loc(list : TAsmList;reg : tregister128;const l : tlocation);virtual;
  406. procedure a_load128_const_reg(list : TAsmList;valuelo,valuehi : int64;reg : tregister128);virtual;
  407. procedure a_load128_loc_cgpara(list : TAsmList;const l : tlocation;const paraloc : TCGPara);virtual;
  408. procedure a_load128_ref_cgpara(list: TAsmList; const r: treference;const paraloc: tcgpara);
  409. procedure a_load128_reg_cgpara(list: TAsmList; reg: tregister128;const paraloc: tcgpara);
  410. end;
  411. { Creates a tregister128 record from 2 64 Bit registers. }
  412. function joinreg128(reglo,reghi : tregister) : tregister128;
  413. {$else cpu64bitalu}
  414. {# @abstract(Abstract code generator for 64 Bit operations)
  415. This class implements an abstract code generator class
  416. for 64 Bit operations.
  417. }
  418. tcg64 = class
  419. procedure a_load64_const_ref(list : TAsmList;value : int64;const ref : treference);virtual;abstract;
  420. procedure a_load64_reg_ref(list : TAsmList;reg : tregister64;const ref : treference);virtual;abstract;
  421. procedure a_load64_ref_reg(list : TAsmList;const ref : treference;reg : tregister64);virtual;abstract;
  422. procedure a_load64_reg_reg(list : TAsmList;regsrc,regdst : tregister64);virtual;abstract;
  423. procedure a_load64_const_reg(list : TAsmList;value : int64;reg : tregister64);virtual;abstract;
  424. procedure a_load64_loc_reg(list : TAsmList;const l : tlocation;reg : tregister64);virtual;abstract;
  425. procedure a_load64_loc_ref(list : TAsmList;const l : tlocation;const ref : treference);virtual;abstract;
  426. procedure a_load64_const_loc(list : TAsmList;value : int64;const l : tlocation);virtual;abstract;
  427. procedure a_load64_reg_loc(list : TAsmList;reg : tregister64;const l : tlocation);virtual;abstract;
  428. procedure a_load64_subsetref_reg(list : TAsmList; const sref: tsubsetreference; destreg: tregister64);virtual;abstract;
  429. procedure a_load64_reg_subsetref(list : TAsmList; fromreg: tregister64; const sref: tsubsetreference);virtual;abstract;
  430. procedure a_load64_const_subsetref(list: TAsmlist; a: int64; const sref: tsubsetreference);virtual;abstract;
  431. procedure a_load64_ref_subsetref(list : TAsmList; const fromref: treference; const sref: tsubsetreference);virtual;abstract;
  432. procedure a_load64_subsetref_subsetref(list: TAsmlist; const fromsref, tosref: tsubsetreference); virtual;abstract;
  433. procedure a_load64_subsetref_ref(list : TAsmList; const sref: tsubsetreference; const destref: treference); virtual;abstract;
  434. procedure a_load64_loc_subsetref(list : TAsmList; const l: tlocation; const sref : tsubsetreference);
  435. procedure a_load64_subsetref_loc(list: TAsmlist; const sref: tsubsetreference; const l: tlocation);
  436. procedure a_load64high_reg_ref(list : TAsmList;reg : tregister;const ref : treference);virtual;abstract;
  437. procedure a_load64low_reg_ref(list : TAsmList;reg : tregister;const ref : treference);virtual;abstract;
  438. procedure a_load64high_ref_reg(list : TAsmList;const ref : treference;reg : tregister);virtual;abstract;
  439. procedure a_load64low_ref_reg(list : TAsmList;const ref : treference;reg : tregister);virtual;abstract;
  440. procedure a_load64high_loc_reg(list : TAsmList;const l : tlocation;reg : tregister);virtual;abstract;
  441. procedure a_load64low_loc_reg(list : TAsmList;const l : tlocation;reg : tregister);virtual;abstract;
  442. procedure a_op64_ref_reg(list : TAsmList;op:TOpCG;size : tcgsize;const ref : treference;reg : tregister64);virtual;abstract;
  443. procedure a_op64_reg_reg(list : TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);virtual;abstract;
  444. procedure a_op64_reg_ref(list : TAsmList;op:TOpCG;size : tcgsize;regsrc : tregister64;const ref : treference);virtual;abstract;
  445. procedure a_op64_const_reg(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;regdst : tregister64);virtual;abstract;
  446. procedure a_op64_const_ref(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;const ref : treference);virtual;abstract;
  447. procedure a_op64_const_loc(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;const l: tlocation);virtual;abstract;
  448. procedure a_op64_reg_loc(list : TAsmList;op:TOpCG;size : tcgsize;reg : tregister64;const l : tlocation);virtual;abstract;
  449. procedure a_op64_loc_reg(list : TAsmList;op:TOpCG;size : tcgsize;const l : tlocation;reg64 : tregister64);virtual;abstract;
  450. procedure a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);virtual;
  451. procedure a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);virtual;
  452. procedure a_op64_const_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);virtual;
  453. procedure a_op64_reg_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);virtual;
  454. procedure a_op64_const_subsetref(list : TAsmList; Op : TOpCG; size : TCGSize; a : int64; const sref: tsubsetreference);
  455. procedure a_op64_reg_subsetref(list : TAsmList; Op : TOpCG; size : TCGSize; reg: tregister64; const sref: tsubsetreference);
  456. procedure a_op64_ref_subsetref(list : TAsmList; Op : TOpCG; size : TCGSize; const ref: treference; const sref: tsubsetreference);
  457. procedure a_op64_subsetref_subsetref(list : TAsmList; Op : TOpCG; size : TCGSize; const ssref,dsref: tsubsetreference);
  458. procedure a_load64_reg_cgpara(list : TAsmList;reg64 : tregister64;const loc : TCGPara);virtual;abstract;
  459. procedure a_load64_const_cgpara(list : TAsmList;value : int64;const loc : TCGPara);virtual;abstract;
  460. procedure a_load64_ref_cgpara(list : TAsmList;const r : treference;const loc : TCGPara);virtual;abstract;
  461. procedure a_load64_loc_cgpara(list : TAsmList;const l : tlocation;const loc : TCGPara);virtual;abstract;
  462. procedure a_loadmm_intreg64_reg(list: TAsmList; mmsize: tcgsize; intreg: tregister64; mmreg: tregister); virtual;abstract;
  463. procedure a_loadmm_reg_intreg64(list: TAsmList; mmsize: tcgsize; mmreg: tregister; intreg: tregister64); virtual;abstract;
  464. {
  465. This routine tries to optimize the const_reg opcode, and should be
  466. called at the start of a_op64_const_reg. It returns the actual opcode
  467. to emit, and the constant value to emit. If this routine returns
  468. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  469. @param(op The opcode to emit, returns the opcode which must be emitted)
  470. @param(a The constant which should be emitted, returns the constant which must
  471. be emitted)
  472. @param(reg The register to emit the opcode with, returns the register with
  473. which the opcode will be emitted)
  474. }
  475. function optimize64_op_const_reg(list: TAsmList; var op: topcg; var a : int64; var reg: tregister64): boolean;virtual;abstract;
  476. { override to catch 64bit rangechecks }
  477. procedure g_rangecheck64(list: TAsmList; const l:tlocation; fromdef,todef: tdef);virtual;abstract;
  478. end;
  479. { Creates a tregister64 record from 2 32 Bit registers. }
  480. function joinreg64(reglo,reghi : tregister) : tregister64;
  481. {$endif cpu64bitalu}
  482. var
  483. { Main code generator class }
  484. cg : tcg;
  485. {$ifdef cpu64bitalu}
  486. { Code generator class for all operations working with 128-Bit operands }
  487. cg128 : tcg128;
  488. {$else cpu64bitalu}
  489. { Code generator class for all operations working with 64-Bit operands }
  490. cg64 : tcg64;
  491. {$endif cpu64bitalu}
  492. function asmsym2indsymflags(sym: TAsmSymbol): tindsymflags;
  493. procedure destroy_codegen;
  494. implementation
  495. uses
  496. globals,systems,
  497. verbose,paramgr,symtable,symsym,
  498. tgobj,cutils,procinfo;
  499. {*****************************************************************************
  500. basic functionallity
  501. ******************************************************************************}
  502. constructor tcg.create;
  503. begin
  504. end;
  505. {*****************************************************************************
  506. register allocation
  507. ******************************************************************************}
  508. procedure tcg.init_register_allocators;
  509. begin
  510. fillchar(rg,sizeof(rg),0);
  511. add_reg_instruction_hook:=@add_reg_instruction;
  512. executionweight:=1;
  513. end;
  514. procedure tcg.done_register_allocators;
  515. begin
  516. { Safety }
  517. fillchar(rg,sizeof(rg),0);
  518. add_reg_instruction_hook:=nil;
  519. end;
  520. {$ifdef flowgraph}
  521. procedure Tcg.init_flowgraph;
  522. begin
  523. aktflownode:=0;
  524. end;
  525. procedure Tcg.done_flowgraph;
  526. begin
  527. end;
  528. {$endif}
  529. function tcg.getintregister(list:TAsmList;size:Tcgsize):Tregister;
  530. begin
  531. if not assigned(rg[R_INTREGISTER]) then
  532. internalerror(200312122);
  533. result:=rg[R_INTREGISTER].getregister(list,cgsize2subreg(R_INTREGISTER,size));
  534. end;
  535. function tcg.getfpuregister(list:TAsmList;size:Tcgsize):Tregister;
  536. begin
  537. if not assigned(rg[R_FPUREGISTER]) then
  538. internalerror(200312123);
  539. result:=rg[R_FPUREGISTER].getregister(list,cgsize2subreg(R_FPUREGISTER,size));
  540. end;
  541. function tcg.getmmregister(list:TAsmList;size:Tcgsize):Tregister;
  542. begin
  543. if not assigned(rg[R_MMREGISTER]) then
  544. internalerror(2003121214);
  545. result:=rg[R_MMREGISTER].getregister(list,cgsize2subreg(R_MMREGISTER,size));
  546. end;
  547. function tcg.getaddressregister(list:TAsmList):Tregister;
  548. begin
  549. if assigned(rg[R_ADDRESSREGISTER]) then
  550. result:=rg[R_ADDRESSREGISTER].getregister(list,R_SUBWHOLE)
  551. else
  552. begin
  553. if not assigned(rg[R_INTREGISTER]) then
  554. internalerror(200312121);
  555. result:=rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  556. end;
  557. end;
  558. function Tcg.makeregsize(list:TAsmList;reg:Tregister;size:Tcgsize):Tregister;
  559. var
  560. subreg:Tsubregister;
  561. begin
  562. subreg:=cgsize2subreg(getregtype(reg),size);
  563. result:=reg;
  564. setsubreg(result,subreg);
  565. { notify RA }
  566. if result<>reg then
  567. list.concat(tai_regalloc.resize(result));
  568. end;
  569. procedure tcg.getcpuregister(list:TAsmList;r:Tregister);
  570. begin
  571. if not assigned(rg[getregtype(r)]) then
  572. internalerror(200312125);
  573. rg[getregtype(r)].getcpuregister(list,r);
  574. end;
  575. procedure tcg.ungetcpuregister(list:TAsmList;r:Tregister);
  576. begin
  577. if not assigned(rg[getregtype(r)]) then
  578. internalerror(200312126);
  579. rg[getregtype(r)].ungetcpuregister(list,r);
  580. end;
  581. procedure tcg.alloccpuregisters(list:TAsmList;rt:Tregistertype;const r:Tcpuregisterset);
  582. begin
  583. if assigned(rg[rt]) then
  584. rg[rt].alloccpuregisters(list,r)
  585. else
  586. internalerror(200310092);
  587. end;
  588. procedure tcg.allocallcpuregisters(list:TAsmList);
  589. begin
  590. alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  591. if uses_registers(R_ADDRESSREGISTER) then
  592. alloccpuregisters(list,R_ADDRESSREGISTER,paramanager.get_volatile_registers_address(pocall_default));
  593. {$if not(defined(i386)) and not(defined(i8086)) and not(defined(avr))}
  594. if uses_registers(R_FPUREGISTER) then
  595. alloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  596. {$ifdef cpumm}
  597. if uses_registers(R_MMREGISTER) then
  598. alloccpuregisters(list,R_MMREGISTER,paramanager.get_volatile_registers_mm(pocall_default));
  599. {$endif cpumm}
  600. {$endif not(defined(i386)) and not(defined(i8086)) and not(defined(avr))}
  601. end;
  602. procedure tcg.dealloccpuregisters(list:TAsmList;rt:Tregistertype;const r:Tcpuregisterset);
  603. begin
  604. if assigned(rg[rt]) then
  605. rg[rt].dealloccpuregisters(list,r)
  606. else
  607. internalerror(200310093);
  608. end;
  609. procedure tcg.deallocallcpuregisters(list:TAsmList);
  610. begin
  611. dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  612. if uses_registers(R_ADDRESSREGISTER) then
  613. dealloccpuregisters(list,R_ADDRESSREGISTER,paramanager.get_volatile_registers_address(pocall_default));
  614. {$if not(defined(i386)) and not(defined(i8086)) and not(defined(avr))}
  615. if uses_registers(R_FPUREGISTER) then
  616. dealloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  617. {$ifdef cpumm}
  618. if uses_registers(R_MMREGISTER) then
  619. dealloccpuregisters(list,R_MMREGISTER,paramanager.get_volatile_registers_mm(pocall_default));
  620. {$endif cpumm}
  621. {$endif not(defined(i386)) and not(defined(i8086)) and not(defined(avr))}
  622. end;
  623. function tcg.uses_registers(rt:Tregistertype):boolean;
  624. begin
  625. if assigned(rg[rt]) then
  626. result:=rg[rt].uses_registers
  627. else
  628. result:=false;
  629. end;
  630. procedure tcg.add_reg_instruction(instr:Tai;r:tregister);
  631. var
  632. rt : tregistertype;
  633. begin
  634. rt:=getregtype(r);
  635. { Only add it when a register allocator is configured.
  636. No IE can be generated, because the VMT is written
  637. without a valid rg[] }
  638. if assigned(rg[rt]) then
  639. rg[rt].add_reg_instruction(instr,r,executionweight);
  640. end;
  641. procedure tcg.add_move_instruction(instr:Taicpu);
  642. var
  643. rt : tregistertype;
  644. begin
  645. rt:=getregtype(instr.oper[O_MOV_SOURCE]^.reg);
  646. if assigned(rg[rt]) then
  647. rg[rt].add_move_instruction(instr)
  648. else
  649. internalerror(200310095);
  650. end;
  651. procedure tcg.set_regalloc_live_range_direction(dir: TRADirection);
  652. var
  653. rt : tregistertype;
  654. begin
  655. for rt:=low(rg) to high(rg) do
  656. begin
  657. if assigned(rg[rt]) then
  658. rg[rt].live_range_direction:=dir;
  659. end;
  660. end;
  661. procedure tcg.do_register_allocation(list:TAsmList;headertai:tai);
  662. var
  663. rt : tregistertype;
  664. begin
  665. for rt:=R_FPUREGISTER to R_SPECIALREGISTER do
  666. begin
  667. if assigned(rg[rt]) then
  668. rg[rt].do_register_allocation(list,headertai);
  669. end;
  670. { running the other register allocator passes could require addition int/addr. registers
  671. when spilling so run int/addr register allocation at the end }
  672. if assigned(rg[R_INTREGISTER]) then
  673. rg[R_INTREGISTER].do_register_allocation(list,headertai);
  674. if assigned(rg[R_ADDRESSREGISTER]) then
  675. rg[R_ADDRESSREGISTER].do_register_allocation(list,headertai);
  676. end;
  677. procedure tcg.translate_register(var reg : tregister);
  678. var
  679. rt: tregistertype;
  680. begin
  681. { Getting here without assigned rg is possible for an "assembler nostackframe"
  682. function returning x87 float, compiler tries to translate NR_ST which is used for
  683. result. }
  684. rt:=getregtype(reg);
  685. if assigned(rg[rt]) then
  686. rg[rt].translate_register(reg);
  687. end;
  688. procedure tcg.a_reg_alloc(list : TAsmList;r : tregister);
  689. begin
  690. list.concat(tai_regalloc.alloc(r,nil));
  691. end;
  692. procedure tcg.a_reg_dealloc(list : TAsmList;r : tregister);
  693. begin
  694. if (r<>NR_NO) then
  695. list.concat(tai_regalloc.dealloc(r,nil));
  696. end;
  697. procedure tcg.a_reg_sync(list : TAsmList;r : tregister);
  698. var
  699. instr : tai;
  700. begin
  701. instr:=tai_regalloc.sync(r);
  702. list.concat(instr);
  703. add_reg_instruction(instr,r);
  704. end;
  705. procedure tcg.a_label(list : TAsmList;l : tasmlabel);
  706. begin
  707. list.concat(tai_label.create(l));
  708. end;
  709. {*****************************************************************************
  710. for better code generation these methods should be overridden
  711. ******************************************************************************}
  712. procedure tcg.a_load_reg_cgpara(list : TAsmList;size : tcgsize;r : tregister;const cgpara : TCGPara);
  713. var
  714. ref : treference;
  715. tmpreg : tregister;
  716. begin
  717. if assigned(cgpara.location^.next) then
  718. begin
  719. tg.gethltemp(list,cgpara.def,cgpara.def.size,tt_persistent,ref);
  720. a_load_reg_ref(list,size,size,r,ref);
  721. a_load_ref_cgpara(list,size,ref,cgpara);
  722. tg.ungettemp(list,ref);
  723. exit;
  724. end;
  725. paramanager.alloccgpara(list,cgpara);
  726. if cgpara.location^.shiftval<0 then
  727. begin
  728. tmpreg:=getintregister(list,cgpara.location^.size);
  729. a_op_const_reg_reg(list,OP_SHL,cgpara.location^.size,-cgpara.location^.shiftval,r,tmpreg);
  730. r:=tmpreg;
  731. end;
  732. case cgpara.location^.loc of
  733. LOC_REGISTER,LOC_CREGISTER:
  734. a_load_reg_reg(list,size,cgpara.location^.size,r,cgpara.location^.register);
  735. LOC_REFERENCE,LOC_CREFERENCE:
  736. begin
  737. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  738. a_load_reg_ref(list,size,cgpara.location^.size,r,ref);
  739. end;
  740. LOC_MMREGISTER,LOC_CMMREGISTER:
  741. a_loadmm_intreg_reg(list,size,cgpara.location^.size,r,cgpara.location^.register,mms_movescalar);
  742. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  743. begin
  744. tg.GetTemp(list,TCGSize2Size[size],TCGSize2Size[size],tt_normal,ref);
  745. a_load_reg_ref(list,size,size,r,ref);
  746. a_loadfpu_ref_cgpara(list,cgpara.location^.size,ref,cgpara);
  747. tg.Ungettemp(list,ref);
  748. end
  749. else
  750. internalerror(2002071004);
  751. end;
  752. end;
  753. procedure tcg.a_load_const_cgpara(list : TAsmList;size : tcgsize;a : tcgint;const cgpara : TCGPara);
  754. var
  755. ref : treference;
  756. begin
  757. cgpara.check_simple_location;
  758. paramanager.alloccgpara(list,cgpara);
  759. if cgpara.location^.shiftval<0 then
  760. a:=a shl -cgpara.location^.shiftval;
  761. case cgpara.location^.loc of
  762. LOC_REGISTER,LOC_CREGISTER:
  763. a_load_const_reg(list,cgpara.location^.size,a,cgpara.location^.register);
  764. LOC_REFERENCE,LOC_CREFERENCE:
  765. begin
  766. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  767. a_load_const_ref(list,cgpara.location^.size,a,ref);
  768. end
  769. else
  770. internalerror(2010053109);
  771. end;
  772. end;
  773. procedure tcg.a_load_ref_cgpara(list : TAsmList;size : tcgsize;const r : treference;const cgpara : TCGPara);
  774. var
  775. tmpref, ref: treference;
  776. tmpreg: tregister;
  777. location: pcgparalocation;
  778. orgsizeleft,
  779. sizeleft: tcgint;
  780. reghasvalue: boolean;
  781. begin
  782. location:=cgpara.location;
  783. tmpref:=r;
  784. sizeleft:=cgpara.intsize;
  785. while assigned(location) do
  786. begin
  787. paramanager.allocparaloc(list,location);
  788. case location^.loc of
  789. LOC_REGISTER,LOC_CREGISTER:
  790. begin
  791. { Parameter locations are often allocated in multiples of
  792. entire registers. If a parameter only occupies a part of
  793. such a register (e.g. a 16 bit int on a 32 bit
  794. architecture), the size of this parameter can only be
  795. determined by looking at the "size" parameter of this
  796. method -> if the size parameter is <= sizeof(aint), then
  797. we check that there is only one parameter location and
  798. then use this "size" to load the value into the parameter
  799. location }
  800. if (size<>OS_NO) and
  801. (tcgsize2size[size]<=sizeof(aint)) then
  802. begin
  803. cgpara.check_simple_location;
  804. a_load_ref_reg(list,size,location^.size,tmpref,location^.register);
  805. if location^.shiftval<0 then
  806. a_op_const_reg(list,OP_SHL,location^.size,-location^.shiftval,location^.register);
  807. end
  808. { there's a lot more data left, and the current paraloc's
  809. register is entirely filled with part of that data }
  810. else if (sizeleft>sizeof(aint)) then
  811. begin
  812. a_load_ref_reg(list,location^.size,location^.size,tmpref,location^.register);
  813. end
  814. { we're at the end of the data, and it can be loaded into
  815. the current location's register with a single regular
  816. load }
  817. else if sizeleft in [1,2,4,8] then
  818. begin
  819. a_load_ref_reg(list,int_cgsize(sizeleft),location^.size,tmpref,location^.register);
  820. if location^.shiftval<0 then
  821. a_op_const_reg(list,OP_SHL,location^.size,-location^.shiftval,location^.register);
  822. end
  823. { we're at the end of the data, and we need multiple loads
  824. to get it in the register because it's an irregular size }
  825. else
  826. begin
  827. { should be the last part }
  828. if assigned(location^.next) then
  829. internalerror(2010052907);
  830. { load the value piecewise to get it into the register }
  831. orgsizeleft:=sizeleft;
  832. reghasvalue:=false;
  833. {$ifdef cpu64bitalu}
  834. if sizeleft>=4 then
  835. begin
  836. a_load_ref_reg(list,OS_32,location^.size,tmpref,location^.register);
  837. dec(sizeleft,4);
  838. if target_info.endian=endian_big then
  839. a_op_const_reg(list,OP_SHL,location^.size,sizeleft*8,location^.register);
  840. inc(tmpref.offset,4);
  841. reghasvalue:=true;
  842. end;
  843. {$endif cpu64bitalu}
  844. if sizeleft>=2 then
  845. begin
  846. tmpreg:=getintregister(list,location^.size);
  847. a_load_ref_reg(list,OS_16,location^.size,tmpref,tmpreg);
  848. dec(sizeleft,2);
  849. if reghasvalue then
  850. begin
  851. if target_info.endian=endian_big then
  852. a_op_const_reg(list,OP_SHL,location^.size,sizeleft*8,tmpreg)
  853. else
  854. a_op_const_reg(list,OP_SHL,location^.size,(orgsizeleft-(sizeleft+2))*8,tmpreg);
  855. a_op_reg_reg(list,OP_OR,location^.size,tmpreg,location^.register);
  856. end
  857. else
  858. begin
  859. if target_info.endian=endian_big then
  860. a_op_const_reg_reg(list,OP_SHL,location^.size,sizeleft*8,tmpreg,location^.register)
  861. else
  862. a_load_reg_reg(list,location^.size,location^.size,tmpreg,location^.register);
  863. end;
  864. inc(tmpref.offset,2);
  865. reghasvalue:=true;
  866. end;
  867. if sizeleft=1 then
  868. begin
  869. tmpreg:=getintregister(list,location^.size);
  870. a_load_ref_reg(list,OS_8,location^.size,tmpref,tmpreg);
  871. dec(sizeleft,1);
  872. if reghasvalue then
  873. begin
  874. if target_info.endian=endian_little then
  875. a_op_const_reg(list,OP_SHL,location^.size,(orgsizeleft-(sizeleft+1))*8,tmpreg);
  876. a_op_reg_reg(list,OP_OR,location^.size,tmpreg,location^.register)
  877. end
  878. else
  879. a_load_reg_reg(list,location^.size,location^.size,tmpreg,location^.register);
  880. inc(tmpref.offset);
  881. end;
  882. if location^.shiftval<0 then
  883. a_op_const_reg(list,OP_SHL,location^.size,-location^.shiftval,location^.register);
  884. { the loop will already adjust the offset and sizeleft }
  885. dec(tmpref.offset,orgsizeleft);
  886. sizeleft:=orgsizeleft;
  887. end;
  888. end;
  889. LOC_REFERENCE,LOC_CREFERENCE:
  890. begin
  891. if assigned(location^.next) then
  892. internalerror(2010052906);
  893. reference_reset_base(ref,location^.reference.index,location^.reference.offset,newalignment(cgpara.alignment,cgpara.intsize-sizeleft));
  894. if (size <> OS_NO) and
  895. (tcgsize2size[size] <= sizeof(aint)) then
  896. a_load_ref_ref(list,size,location^.size,tmpref,ref)
  897. else
  898. { use concatcopy, because the parameter can be larger than }
  899. { what the OS_* constants can handle }
  900. g_concatcopy(list,tmpref,ref,sizeleft);
  901. end;
  902. LOC_MMREGISTER,LOC_CMMREGISTER:
  903. begin
  904. case location^.size of
  905. OS_F32,
  906. OS_F64,
  907. OS_F128:
  908. a_loadmm_ref_reg(list,location^.size,location^.size,tmpref,location^.register,mms_movescalar);
  909. OS_M8..OS_M128,
  910. OS_MS8..OS_MS128:
  911. a_loadmm_ref_reg(list,location^.size,location^.size,tmpref,location^.register,nil);
  912. else
  913. internalerror(2010053101);
  914. end;
  915. end
  916. else
  917. internalerror(2010053111);
  918. end;
  919. inc(tmpref.offset,tcgsize2size[location^.size]);
  920. dec(sizeleft,tcgsize2size[location^.size]);
  921. location:=location^.next;
  922. end;
  923. end;
  924. procedure tcg.a_load_loc_cgpara(list : TAsmList;const l:tlocation;const cgpara : TCGPara);
  925. begin
  926. case l.loc of
  927. LOC_REGISTER,
  928. LOC_CREGISTER :
  929. a_load_reg_cgpara(list,l.size,l.register,cgpara);
  930. LOC_CONSTANT :
  931. a_load_const_cgpara(list,l.size,l.value,cgpara);
  932. LOC_CREFERENCE,
  933. LOC_REFERENCE :
  934. a_load_ref_cgpara(list,l.size,l.reference,cgpara);
  935. else
  936. internalerror(2002032211);
  937. end;
  938. end;
  939. procedure tcg.a_loadaddr_ref_cgpara(list : TAsmList;const r : treference;const cgpara : TCGPara);
  940. var
  941. hr : tregister;
  942. begin
  943. cgpara.check_simple_location;
  944. if cgpara.location^.loc in [LOC_CREGISTER,LOC_REGISTER] then
  945. begin
  946. paramanager.allocparaloc(list,cgpara.location);
  947. a_loadaddr_ref_reg(list,r,cgpara.location^.register)
  948. end
  949. else
  950. begin
  951. hr:=getaddressregister(list);
  952. a_loadaddr_ref_reg(list,r,hr);
  953. a_load_reg_cgpara(list,OS_ADDR,hr,cgpara);
  954. end;
  955. end;
  956. procedure tcg.a_load_cgparaloc_ref(list : TAsmList;const paraloc : TCGParaLocation;const ref : treference;sizeleft : tcgint;align : longint);
  957. var
  958. href : treference;
  959. hreg : tregister;
  960. cgsize: tcgsize;
  961. begin
  962. case paraloc.loc of
  963. LOC_REGISTER :
  964. begin
  965. hreg:=paraloc.register;
  966. cgsize:=paraloc.size;
  967. if paraloc.shiftval>0 then
  968. a_op_const_reg_reg(list,OP_SHL,OS_INT,paraloc.shiftval,paraloc.register,paraloc.register)
  969. else if (paraloc.shiftval<0) and
  970. (sizeleft in [1,2,4]) then
  971. begin
  972. a_op_const_reg_reg(list,OP_SHR,OS_INT,-paraloc.shiftval,paraloc.register,paraloc.register);
  973. { convert to a register of 1/2/4 bytes in size, since the
  974. original register had to be made larger to be able to hold
  975. the shifted value }
  976. cgsize:=int_cgsize(tcgsize2size[OS_INT]-(-paraloc.shiftval div 8));
  977. hreg:=getintregister(list,cgsize);
  978. a_load_reg_reg(list,OS_INT,cgsize,paraloc.register,hreg);
  979. end;
  980. a_load_reg_ref(list,paraloc.size,cgsize,hreg,ref);
  981. end;
  982. LOC_MMREGISTER :
  983. begin
  984. case paraloc.size of
  985. OS_F32,
  986. OS_F64,
  987. OS_F128:
  988. a_loadmm_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref,mms_movescalar);
  989. OS_M8..OS_M128,
  990. OS_MS8..OS_MS128:
  991. a_loadmm_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref,nil);
  992. else
  993. internalerror(2010053102);
  994. end;
  995. end;
  996. LOC_FPUREGISTER :
  997. a_loadfpu_reg_ref(list,paraloc.size,paraloc.size,paraloc.register,ref);
  998. LOC_REFERENCE :
  999. begin
  1000. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset,align);
  1001. { use concatcopy, because it can also be a float which fails when
  1002. load_ref_ref is used. Don't copy data when the references are equal }
  1003. if not((href.base=ref.base) and (href.offset=ref.offset)) then
  1004. g_concatcopy(list,href,ref,sizeleft);
  1005. end;
  1006. else
  1007. internalerror(2002081302);
  1008. end;
  1009. end;
  1010. procedure tcg.a_load_cgparaloc_anyreg(list: TAsmList;regsize: tcgsize;const paraloc: TCGParaLocation;reg: tregister;align: longint);
  1011. var
  1012. href : treference;
  1013. begin
  1014. case paraloc.loc of
  1015. LOC_REGISTER :
  1016. begin
  1017. if paraloc.shiftval<0 then
  1018. a_op_const_reg_reg(list,OP_SHR,OS_INT,-paraloc.shiftval,paraloc.register,paraloc.register);
  1019. case getregtype(reg) of
  1020. R_ADDRESSREGISTER,
  1021. R_INTREGISTER:
  1022. a_load_reg_reg(list,paraloc.size,regsize,paraloc.register,reg);
  1023. R_MMREGISTER:
  1024. a_loadmm_intreg_reg(list,paraloc.size,regsize,paraloc.register,reg,mms_movescalar);
  1025. else
  1026. internalerror(2009112422);
  1027. end;
  1028. end;
  1029. LOC_MMREGISTER :
  1030. begin
  1031. case getregtype(reg) of
  1032. R_ADDRESSREGISTER,
  1033. R_INTREGISTER:
  1034. a_loadmm_reg_intreg(list,paraloc.size,regsize,paraloc.register,reg,mms_movescalar);
  1035. R_MMREGISTER:
  1036. begin
  1037. case paraloc.size of
  1038. OS_F32,
  1039. OS_F64,
  1040. OS_F128:
  1041. a_loadmm_reg_reg(list,paraloc.size,regsize,paraloc.register,reg,mms_movescalar);
  1042. OS_M8..OS_M128,
  1043. OS_MS8..OS_MS128:
  1044. a_loadmm_reg_reg(list,paraloc.size,paraloc.size,paraloc.register,reg,nil);
  1045. else
  1046. internalerror(2010053102);
  1047. end;
  1048. end;
  1049. else
  1050. internalerror(2010053104);
  1051. end;
  1052. end;
  1053. LOC_FPUREGISTER :
  1054. begin
  1055. case getregtype(reg) of
  1056. R_FPUREGISTER:
  1057. a_loadfpu_reg_reg(list,paraloc.size,regsize,paraloc.register,reg)
  1058. else
  1059. internalerror(2015031401);
  1060. end;
  1061. end;
  1062. LOC_REFERENCE :
  1063. begin
  1064. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset,align);
  1065. case getregtype(reg) of
  1066. R_ADDRESSREGISTER,
  1067. R_INTREGISTER :
  1068. a_load_ref_reg(list,paraloc.size,regsize,href,reg);
  1069. R_FPUREGISTER :
  1070. a_loadfpu_ref_reg(list,paraloc.size,regsize,href,reg);
  1071. R_MMREGISTER :
  1072. { not paraloc.size, because it may be OS_64 instead of
  1073. OS_F64 in case the parameter is passed using integer
  1074. conventions (e.g., on ARM) }
  1075. a_loadmm_ref_reg(list,regsize,regsize,href,reg,mms_movescalar);
  1076. else
  1077. internalerror(2004101012);
  1078. end;
  1079. end;
  1080. else
  1081. internalerror(2002081302);
  1082. end;
  1083. end;
  1084. {****************************************************************************
  1085. some generic implementations
  1086. ****************************************************************************}
  1087. { memory/register loading }
  1088. procedure tcg.a_load_reg_ref_unaligned(list : TAsmList;fromsize,tosize : tcgsize;register : tregister;const ref : treference);
  1089. var
  1090. tmpref : treference;
  1091. tmpreg : tregister;
  1092. i : longint;
  1093. begin
  1094. if ref.alignment<tcgsize2size[fromsize] then
  1095. begin
  1096. tmpref:=ref;
  1097. { we take care of the alignment now }
  1098. tmpref.alignment:=0;
  1099. case FromSize of
  1100. OS_16,OS_S16:
  1101. begin
  1102. tmpreg:=getintregister(list,OS_16);
  1103. a_load_reg_reg(list,fromsize,OS_16,register,tmpreg);
  1104. if target_info.endian=endian_big then
  1105. inc(tmpref.offset);
  1106. tmpreg:=makeregsize(list,tmpreg,OS_8);
  1107. a_load_reg_ref(list,OS_8,OS_8,tmpreg,tmpref);
  1108. tmpreg:=makeregsize(list,tmpreg,OS_16);
  1109. a_op_const_reg(list,OP_SHR,OS_16,8,tmpreg);
  1110. if target_info.endian=endian_big then
  1111. dec(tmpref.offset)
  1112. else
  1113. inc(tmpref.offset);
  1114. tmpreg:=makeregsize(list,tmpreg,OS_8);
  1115. a_load_reg_ref(list,OS_8,OS_8,tmpreg,tmpref);
  1116. end;
  1117. OS_32,OS_S32:
  1118. begin
  1119. { could add an optimised case for ref.alignment=2 }
  1120. tmpreg:=getintregister(list,OS_32);
  1121. a_load_reg_reg(list,fromsize,OS_32,register,tmpreg);
  1122. if target_info.endian=endian_big then
  1123. inc(tmpref.offset,3);
  1124. tmpreg:=makeregsize(list,tmpreg,OS_8);
  1125. a_load_reg_ref(list,OS_8,OS_8,tmpreg,tmpref);
  1126. tmpreg:=makeregsize(list,tmpreg,OS_32);
  1127. for i:=1 to 3 do
  1128. begin
  1129. a_op_const_reg(list,OP_SHR,OS_32,8,tmpreg);
  1130. if target_info.endian=endian_big then
  1131. dec(tmpref.offset)
  1132. else
  1133. inc(tmpref.offset);
  1134. tmpreg:=makeregsize(list,tmpreg,OS_8);
  1135. a_load_reg_ref(list,OS_8,OS_8,tmpreg,tmpref);
  1136. tmpreg:=makeregsize(list,tmpreg,OS_32);
  1137. end;
  1138. end
  1139. else
  1140. a_load_reg_ref(list,fromsize,tosize,register,tmpref);
  1141. end;
  1142. end
  1143. else
  1144. a_load_reg_ref(list,fromsize,tosize,register,ref);
  1145. end;
  1146. procedure tcg.a_load_ref_reg_unaligned(list : TAsmList;fromsize,tosize : tcgsize;const ref : treference;register : tregister);
  1147. var
  1148. tmpref : treference;
  1149. tmpreg,
  1150. tmpreg2 : tregister;
  1151. i : longint;
  1152. hisize : tcgsize;
  1153. begin
  1154. if ref.alignment in [1,2] then
  1155. begin
  1156. tmpref:=ref;
  1157. { we take care of the alignment now }
  1158. tmpref.alignment:=0;
  1159. case FromSize of
  1160. OS_16,OS_S16:
  1161. if ref.alignment=2 then
  1162. a_load_ref_reg(list,fromsize,tosize,tmpref,register)
  1163. else
  1164. begin
  1165. if FromSize=OS_16 then
  1166. hisize:=OS_8
  1167. else
  1168. hisize:=OS_S8;
  1169. { first load in tmpreg, because the target register }
  1170. { may be used in ref as well }
  1171. if target_info.endian=endian_little then
  1172. inc(tmpref.offset);
  1173. tmpreg:=getintregister(list,OS_8);
  1174. a_load_ref_reg(list,hisize,hisize,tmpref,tmpreg);
  1175. tmpreg:=makeregsize(list,tmpreg,FromSize);
  1176. a_op_const_reg(list,OP_SHL,FromSize,8,tmpreg);
  1177. if target_info.endian=endian_little then
  1178. dec(tmpref.offset)
  1179. else
  1180. inc(tmpref.offset);
  1181. tmpreg2:=makeregsize(list,register,OS_16);
  1182. a_load_ref_reg(list,OS_8,OS_16,tmpref,tmpreg2);
  1183. a_op_reg_reg(list,OP_OR,OS_16,tmpreg,tmpreg2);
  1184. a_load_reg_reg(list,OS_16,tosize,tmpreg2,register);
  1185. end;
  1186. OS_32,OS_S32:
  1187. if ref.alignment=2 then
  1188. begin
  1189. if target_info.endian=endian_little then
  1190. inc(tmpref.offset,2);
  1191. tmpreg:=getintregister(list,OS_32);
  1192. a_load_ref_reg(list,OS_16,OS_32,tmpref,tmpreg);
  1193. a_op_const_reg(list,OP_SHL,OS_32,16,tmpreg);
  1194. if target_info.endian=endian_little then
  1195. dec(tmpref.offset,2)
  1196. else
  1197. inc(tmpref.offset,2);
  1198. tmpreg2:=makeregsize(list,register,OS_32);
  1199. a_load_ref_reg(list,OS_16,OS_32,tmpref,tmpreg2);
  1200. a_op_reg_reg(list,OP_OR,OS_32,tmpreg,tmpreg2);
  1201. a_load_reg_reg(list,OS_32,tosize,tmpreg2,register);
  1202. end
  1203. else
  1204. begin
  1205. if target_info.endian=endian_little then
  1206. inc(tmpref.offset,3);
  1207. tmpreg:=getintregister(list,OS_32);
  1208. a_load_ref_reg(list,OS_8,OS_32,tmpref,tmpreg);
  1209. tmpreg2:=getintregister(list,OS_32);
  1210. for i:=1 to 3 do
  1211. begin
  1212. a_op_const_reg(list,OP_SHL,OS_32,8,tmpreg);
  1213. if target_info.endian=endian_little then
  1214. dec(tmpref.offset)
  1215. else
  1216. inc(tmpref.offset);
  1217. a_load_ref_reg(list,OS_8,OS_32,tmpref,tmpreg2);
  1218. a_op_reg_reg(list,OP_OR,OS_32,tmpreg2,tmpreg);
  1219. end;
  1220. a_load_reg_reg(list,OS_32,tosize,tmpreg,register);
  1221. end
  1222. else
  1223. a_load_ref_reg(list,fromsize,tosize,tmpref,register);
  1224. end;
  1225. end
  1226. else
  1227. a_load_ref_reg(list,fromsize,tosize,ref,register);
  1228. end;
  1229. procedure tcg.a_load_ref_ref(list : TAsmList;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
  1230. var
  1231. tmpreg: tregister;
  1232. begin
  1233. { verify if we have the same reference }
  1234. if references_equal(sref,dref) then
  1235. exit;
  1236. tmpreg:=getintregister(list,tosize);
  1237. a_load_ref_reg(list,fromsize,tosize,sref,tmpreg);
  1238. a_load_reg_ref(list,tosize,tosize,tmpreg,dref);
  1239. end;
  1240. procedure tcg.a_load_const_ref(list : TAsmList;size : tcgsize;a : tcgint;const ref : treference);
  1241. var
  1242. tmpreg: tregister;
  1243. begin
  1244. tmpreg:=getintregister(list,size);
  1245. a_load_const_reg(list,size,a,tmpreg);
  1246. a_load_reg_ref(list,size,size,tmpreg,ref);
  1247. end;
  1248. procedure tcg.a_load_const_loc(list : TAsmList;a : tcgint;const loc: tlocation);
  1249. begin
  1250. case loc.loc of
  1251. LOC_REFERENCE,LOC_CREFERENCE:
  1252. a_load_const_ref(list,loc.size,a,loc.reference);
  1253. LOC_REGISTER,LOC_CREGISTER:
  1254. a_load_const_reg(list,loc.size,a,loc.register);
  1255. else
  1256. internalerror(200203272);
  1257. end;
  1258. end;
  1259. procedure tcg.a_load_reg_loc(list : TAsmList;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  1260. begin
  1261. case loc.loc of
  1262. LOC_REFERENCE,LOC_CREFERENCE:
  1263. a_load_reg_ref(list,fromsize,loc.size,reg,loc.reference);
  1264. LOC_REGISTER,LOC_CREGISTER:
  1265. a_load_reg_reg(list,fromsize,loc.size,reg,loc.register);
  1266. LOC_MMREGISTER,LOC_CMMREGISTER:
  1267. a_loadmm_intreg_reg(list,fromsize,loc.size,reg,loc.register,mms_movescalar);
  1268. else
  1269. internalerror(200203271);
  1270. end;
  1271. end;
  1272. procedure tcg.a_load_loc_reg(list : TAsmList; tosize: tcgsize; const loc: tlocation; reg : tregister);
  1273. begin
  1274. case loc.loc of
  1275. LOC_REFERENCE,LOC_CREFERENCE:
  1276. a_load_ref_reg(list,loc.size,tosize,loc.reference,reg);
  1277. LOC_REGISTER,LOC_CREGISTER:
  1278. a_load_reg_reg(list,loc.size,tosize,loc.register,reg);
  1279. LOC_CONSTANT:
  1280. a_load_const_reg(list,tosize,loc.value,reg);
  1281. else
  1282. internalerror(200109092);
  1283. end;
  1284. end;
  1285. procedure tcg.a_load_loc_ref(list : TAsmList;tosize: tcgsize; const loc: tlocation; const ref : treference);
  1286. begin
  1287. case loc.loc of
  1288. LOC_REFERENCE,LOC_CREFERENCE:
  1289. a_load_ref_ref(list,loc.size,tosize,loc.reference,ref);
  1290. LOC_REGISTER,LOC_CREGISTER:
  1291. a_load_reg_ref(list,loc.size,tosize,loc.register,ref);
  1292. LOC_CONSTANT:
  1293. a_load_const_ref(list,tosize,loc.value,ref);
  1294. else
  1295. internalerror(200109302);
  1296. end;
  1297. end;
  1298. procedure tcg.optimize_op_const(size: TCGSize; var op: topcg; var a : tcgint);
  1299. var
  1300. powerval : longint;
  1301. signext_a, zeroext_a: tcgint;
  1302. begin
  1303. case size of
  1304. OS_64,OS_S64:
  1305. begin
  1306. signext_a:=int64(a);
  1307. zeroext_a:=int64(a);
  1308. end;
  1309. OS_32,OS_S32:
  1310. begin
  1311. signext_a:=longint(a);
  1312. zeroext_a:=dword(a);
  1313. end;
  1314. OS_16,OS_S16:
  1315. begin
  1316. signext_a:=smallint(a);
  1317. zeroext_a:=word(a);
  1318. end;
  1319. OS_8,OS_S8:
  1320. begin
  1321. signext_a:=shortint(a);
  1322. zeroext_a:=byte(a);
  1323. end
  1324. else
  1325. begin
  1326. { Should we internalerror() here instead? }
  1327. signext_a:=a;
  1328. zeroext_a:=a;
  1329. end;
  1330. end;
  1331. case op of
  1332. OP_OR :
  1333. begin
  1334. { or with zero returns same result }
  1335. if a = 0 then
  1336. op:=OP_NONE
  1337. else
  1338. { or with max returns max }
  1339. if signext_a = -1 then
  1340. op:=OP_MOVE;
  1341. end;
  1342. OP_AND :
  1343. begin
  1344. { and with max returns same result }
  1345. if (signext_a = -1) then
  1346. op:=OP_NONE
  1347. else
  1348. { and with 0 returns 0 }
  1349. if a=0 then
  1350. op:=OP_MOVE;
  1351. end;
  1352. OP_DIV :
  1353. begin
  1354. { division by 1 returns result }
  1355. if a = 1 then
  1356. op:=OP_NONE
  1357. else if ispowerof2(int64(zeroext_a), powerval) and not(cs_check_overflow in current_settings.localswitches) then
  1358. begin
  1359. a := powerval;
  1360. op:= OP_SHR;
  1361. end;
  1362. end;
  1363. OP_IDIV:
  1364. begin
  1365. if a = 1 then
  1366. op:=OP_NONE;
  1367. end;
  1368. OP_MUL,OP_IMUL:
  1369. begin
  1370. if a = 1 then
  1371. op:=OP_NONE
  1372. else
  1373. if a=0 then
  1374. op:=OP_MOVE
  1375. else if ispowerof2(int64(zeroext_a), powerval) and not(cs_check_overflow in current_settings.localswitches) then
  1376. begin
  1377. a := powerval;
  1378. op:= OP_SHL;
  1379. end;
  1380. end;
  1381. OP_ADD,OP_SUB:
  1382. begin
  1383. if a = 0 then
  1384. op:=OP_NONE;
  1385. end;
  1386. OP_SAR,OP_SHL,OP_SHR,OP_ROL,OP_ROR:
  1387. begin
  1388. if a = 0 then
  1389. op:=OP_NONE;
  1390. end;
  1391. end;
  1392. end;
  1393. procedure tcg.a_loadfpu_loc_reg(list: TAsmList; tosize: tcgsize; const loc: tlocation; const reg: tregister);
  1394. begin
  1395. case loc.loc of
  1396. LOC_REFERENCE, LOC_CREFERENCE:
  1397. a_loadfpu_ref_reg(list,loc.size,tosize,loc.reference,reg);
  1398. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  1399. a_loadfpu_reg_reg(list,loc.size,tosize,loc.register,reg);
  1400. else
  1401. internalerror(200203301);
  1402. end;
  1403. end;
  1404. procedure tcg.a_loadfpu_reg_loc(list: TAsmList; fromsize: tcgsize; const reg: tregister; const loc: tlocation);
  1405. begin
  1406. case loc.loc of
  1407. LOC_REFERENCE, LOC_CREFERENCE:
  1408. a_loadfpu_reg_ref(list,fromsize,loc.size,reg,loc.reference);
  1409. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  1410. a_loadfpu_reg_reg(list,fromsize,loc.size,reg,loc.register);
  1411. else
  1412. internalerror(48991);
  1413. end;
  1414. end;
  1415. procedure tcg.a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tcgsize; const ref1,ref2: treference);
  1416. var
  1417. reg: tregister;
  1418. regsize: tcgsize;
  1419. begin
  1420. if (fromsize>=tosize) then
  1421. regsize:=fromsize
  1422. else
  1423. regsize:=tosize;
  1424. reg:=getfpuregister(list,regsize);
  1425. a_loadfpu_ref_reg(list,fromsize,regsize,ref1,reg);
  1426. a_loadfpu_reg_ref(list,regsize,tosize,reg,ref2);
  1427. end;
  1428. procedure tcg.a_loadfpu_reg_cgpara(list : TAsmList;size : tcgsize;const r : tregister;const cgpara : TCGPara);
  1429. var
  1430. ref : treference;
  1431. begin
  1432. paramanager.alloccgpara(list,cgpara);
  1433. case cgpara.location^.loc of
  1434. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  1435. begin
  1436. cgpara.check_simple_location;
  1437. a_loadfpu_reg_reg(list,size,size,r,cgpara.location^.register);
  1438. end;
  1439. LOC_REFERENCE,LOC_CREFERENCE:
  1440. begin
  1441. cgpara.check_simple_location;
  1442. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  1443. a_loadfpu_reg_ref(list,size,size,r,ref);
  1444. end;
  1445. LOC_REGISTER,LOC_CREGISTER:
  1446. begin
  1447. { paramfpu_ref does the check_simpe_location check here if necessary }
  1448. tg.GetTemp(list,TCGSize2Size[size],TCGSize2Size[size],tt_normal,ref);
  1449. a_loadfpu_reg_ref(list,size,size,r,ref);
  1450. a_loadfpu_ref_cgpara(list,size,ref,cgpara);
  1451. tg.Ungettemp(list,ref);
  1452. end;
  1453. else
  1454. internalerror(2010053112);
  1455. end;
  1456. end;
  1457. procedure tcg.a_loadfpu_ref_cgpara(list : TAsmList;size : tcgsize;const ref : treference;const cgpara : TCGPara);
  1458. var
  1459. href : treference;
  1460. hsize: tcgsize;
  1461. paraloc: PCGParaLocation;
  1462. begin
  1463. case cgpara.location^.loc of
  1464. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  1465. begin
  1466. paramanager.alloccgpara(list,cgpara);
  1467. paraloc:=cgpara.location;
  1468. href:=ref;
  1469. while assigned(paraloc) do
  1470. begin
  1471. if not(paraloc^.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
  1472. internalerror(2015031501);
  1473. a_loadfpu_ref_reg(list,paraloc^.size,paraloc^.size,href,paraloc^.register);
  1474. inc(href.offset,tcgsize2size[paraloc^.size]);
  1475. paraloc:=paraloc^.next;
  1476. end;
  1477. end;
  1478. LOC_REFERENCE,LOC_CREFERENCE:
  1479. begin
  1480. cgpara.check_simple_location;
  1481. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  1482. { concatcopy should choose the best way to copy the data }
  1483. g_concatcopy(list,ref,href,tcgsize2size[size]);
  1484. end;
  1485. LOC_REGISTER,LOC_CREGISTER:
  1486. begin
  1487. { force integer size }
  1488. hsize:=int_cgsize(tcgsize2size[size]);
  1489. {$ifndef cpu64bitalu}
  1490. if (hsize in [OS_S64,OS_64]) then
  1491. cg64.a_load64_ref_cgpara(list,ref,cgpara)
  1492. else
  1493. {$endif not cpu64bitalu}
  1494. begin
  1495. cgpara.check_simple_location;
  1496. a_load_ref_cgpara(list,hsize,ref,cgpara)
  1497. end;
  1498. end
  1499. else
  1500. internalerror(200402201);
  1501. end;
  1502. end;
  1503. procedure tcg.a_op_const_ref(list : TAsmList; Op: TOpCG; size: TCGSize; a: tcgint; const ref: TReference);
  1504. var
  1505. tmpreg : tregister;
  1506. begin
  1507. tmpreg:=getintregister(list,size);
  1508. a_load_ref_reg(list,size,size,ref,tmpreg);
  1509. a_op_const_reg(list,op,size,a,tmpreg);
  1510. a_load_reg_ref(list,size,size,tmpreg,ref);
  1511. end;
  1512. procedure tcg.a_op_const_loc(list : TAsmList; Op: TOpCG; a: tcgint; const loc: tlocation);
  1513. begin
  1514. case loc.loc of
  1515. LOC_REGISTER, LOC_CREGISTER:
  1516. a_op_const_reg(list,op,loc.size,a,loc.register);
  1517. LOC_REFERENCE, LOC_CREFERENCE:
  1518. a_op_const_ref(list,op,loc.size,a,loc.reference);
  1519. else
  1520. internalerror(200109061);
  1521. end;
  1522. end;
  1523. procedure tcg.a_op_reg_ref(list : TAsmList; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  1524. var
  1525. tmpreg : tregister;
  1526. begin
  1527. tmpreg:=getintregister(list,size);
  1528. a_load_ref_reg(list,size,size,ref,tmpreg);
  1529. a_op_reg_reg(list,op,size,reg,tmpreg);
  1530. a_load_reg_ref(list,size,size,tmpreg,ref);
  1531. end;
  1532. procedure tcg.a_op_ref_reg(list : TAsmList; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  1533. var
  1534. tmpreg: tregister;
  1535. begin
  1536. case op of
  1537. OP_NOT,OP_NEG:
  1538. { handle it as "load ref,reg; op reg" }
  1539. begin
  1540. a_load_ref_reg(list,size,size,ref,reg);
  1541. a_op_reg_reg(list,op,size,reg,reg);
  1542. end;
  1543. else
  1544. begin
  1545. tmpreg:=getintregister(list,size);
  1546. a_load_ref_reg(list,size,size,ref,tmpreg);
  1547. a_op_reg_reg(list,op,size,tmpreg,reg);
  1548. end;
  1549. end;
  1550. end;
  1551. procedure tcg.a_op_reg_loc(list : TAsmList; Op: TOpCG; reg: tregister; const loc: tlocation);
  1552. begin
  1553. case loc.loc of
  1554. LOC_REGISTER, LOC_CREGISTER:
  1555. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  1556. LOC_REFERENCE, LOC_CREFERENCE:
  1557. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  1558. else
  1559. internalerror(200109061);
  1560. end;
  1561. end;
  1562. procedure tcg.a_op_ref_loc(list : TAsmList; Op: TOpCG; const ref: TReference; const loc: tlocation);
  1563. var
  1564. tmpreg: tregister;
  1565. begin
  1566. case loc.loc of
  1567. LOC_REGISTER,LOC_CREGISTER:
  1568. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  1569. LOC_REFERENCE,LOC_CREFERENCE:
  1570. begin
  1571. tmpreg:=getintregister(list,loc.size);
  1572. a_load_ref_reg(list,loc.size,loc.size,ref,tmpreg);
  1573. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  1574. end;
  1575. else
  1576. internalerror(200109061);
  1577. end;
  1578. end;
  1579. procedure Tcg.a_op_const_reg_reg(list:TAsmList;op:Topcg;size:Tcgsize;
  1580. a:tcgint;src,dst:Tregister);
  1581. begin
  1582. a_load_reg_reg(list,size,size,src,dst);
  1583. a_op_const_reg(list,op,size,a,dst);
  1584. end;
  1585. procedure tcg.a_op_reg_reg_reg(list: TAsmList; op: TOpCg;
  1586. size: tcgsize; src1, src2, dst: tregister);
  1587. var
  1588. tmpreg: tregister;
  1589. begin
  1590. if (dst<>src1) then
  1591. begin
  1592. a_load_reg_reg(list,size,size,src2,dst);
  1593. a_op_reg_reg(list,op,size,src1,dst);
  1594. end
  1595. else
  1596. begin
  1597. { can we do a direct operation on the target register ? }
  1598. if op in [OP_ADD,OP_MUL,OP_AND,OP_MOVE,OP_XOR,OP_IMUL,OP_OR] then
  1599. a_op_reg_reg(list,op,size,src2,dst)
  1600. else
  1601. begin
  1602. tmpreg:=getintregister(list,size);
  1603. a_load_reg_reg(list,size,size,src2,tmpreg);
  1604. a_op_reg_reg(list,op,size,src1,tmpreg);
  1605. a_load_reg_reg(list,size,size,tmpreg,dst);
  1606. end;
  1607. end;
  1608. end;
  1609. procedure tcg.a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; a: tcgint; src, dst: tregister;setflags : boolean;var ovloc : tlocation);
  1610. begin
  1611. a_op_const_reg_reg(list,op,size,a,src,dst);
  1612. ovloc.loc:=LOC_VOID;
  1613. end;
  1614. procedure tcg.a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation);
  1615. begin
  1616. a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  1617. ovloc.loc:=LOC_VOID;
  1618. end;
  1619. procedure tcg.a_cmp_const_reg_label(list: TAsmList; size: tcgsize;
  1620. cmp_op: topcmp; a: tcgint; reg: tregister; l: tasmlabel);
  1621. var
  1622. tmpreg: tregister;
  1623. begin
  1624. tmpreg:=getintregister(list,size);
  1625. a_load_const_reg(list,size,a,tmpreg);
  1626. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1627. end;
  1628. procedure tcg.a_cmp_const_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : tcgint;const ref : treference;
  1629. l : tasmlabel);
  1630. var
  1631. tmpreg: tregister;
  1632. begin
  1633. tmpreg:=getintregister(list,size);
  1634. a_load_ref_reg(list,size,size,ref,tmpreg);
  1635. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1636. end;
  1637. procedure tcg.a_cmp_const_loc_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : tcgint;const loc : tlocation;
  1638. l : tasmlabel);
  1639. begin
  1640. case loc.loc of
  1641. LOC_REGISTER,LOC_CREGISTER:
  1642. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1643. LOC_REFERENCE,LOC_CREFERENCE:
  1644. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1645. else
  1646. internalerror(200109061);
  1647. end;
  1648. end;
  1649. procedure tcg.a_cmp_ref_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  1650. var
  1651. tmpreg: tregister;
  1652. begin
  1653. tmpreg:=getintregister(list,size);
  1654. a_load_ref_reg(list,size,size,ref,tmpreg);
  1655. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1656. end;
  1657. procedure tcg.a_cmp_reg_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp; reg : tregister; const ref: treference; l : tasmlabel);
  1658. var
  1659. tmpreg: tregister;
  1660. begin
  1661. tmpreg:=getintregister(list,size);
  1662. a_load_ref_reg(list,size,size,ref,tmpreg);
  1663. a_cmp_reg_reg_label(list,size,cmp_op,reg,tmpreg,l);
  1664. end;
  1665. procedure tcg.a_cmp_reg_loc_label(list : TAsmList;size : tcgsize;cmp_op : topcmp; reg: tregister; const loc: tlocation; l : tasmlabel);
  1666. begin
  1667. a_cmp_loc_reg_label(list,size,swap_opcmp(cmp_op),loc,reg,l);
  1668. end;
  1669. procedure tcg.a_cmp_loc_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  1670. begin
  1671. case loc.loc of
  1672. LOC_REGISTER,
  1673. LOC_CREGISTER:
  1674. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1675. LOC_REFERENCE,
  1676. LOC_CREFERENCE :
  1677. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1678. LOC_CONSTANT:
  1679. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1680. else
  1681. internalerror(200203231);
  1682. end;
  1683. end;
  1684. procedure tcg.a_cmp_ref_loc_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  1685. l : tasmlabel);
  1686. var
  1687. tmpreg: tregister;
  1688. begin
  1689. case loc.loc of
  1690. LOC_REGISTER,LOC_CREGISTER:
  1691. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1692. LOC_REFERENCE,LOC_CREFERENCE:
  1693. begin
  1694. tmpreg:=getintregister(list,size);
  1695. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1696. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1697. end;
  1698. else
  1699. internalerror(200109061);
  1700. end;
  1701. end;
  1702. procedure tcg.a_loadmm_loc_reg(list: TAsmList; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  1703. begin
  1704. case loc.loc of
  1705. LOC_MMREGISTER,LOC_CMMREGISTER:
  1706. a_loadmm_reg_reg(list,loc.size,size,loc.register,reg,shuffle);
  1707. LOC_REFERENCE,LOC_CREFERENCE:
  1708. a_loadmm_ref_reg(list,loc.size,size,loc.reference,reg,shuffle);
  1709. LOC_REGISTER,LOC_CREGISTER:
  1710. a_loadmm_intreg_reg(list,loc.size,size,loc.register,reg,shuffle);
  1711. else
  1712. internalerror(200310121);
  1713. end;
  1714. end;
  1715. procedure tcg.a_loadmm_reg_loc(list: TAsmList; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  1716. begin
  1717. case loc.loc of
  1718. LOC_MMREGISTER,LOC_CMMREGISTER:
  1719. a_loadmm_reg_reg(list,size,loc.size,reg,loc.register,shuffle);
  1720. LOC_REFERENCE,LOC_CREFERENCE:
  1721. a_loadmm_reg_ref(list,size,loc.size,reg,loc.reference,shuffle);
  1722. else
  1723. internalerror(200310122);
  1724. end;
  1725. end;
  1726. procedure tcg.a_loadmm_reg_cgpara(list: TAsmList; size: tcgsize; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle);
  1727. var
  1728. href : treference;
  1729. {$ifndef cpu64bitalu}
  1730. tmpreg : tregister;
  1731. reg64 : tregister64;
  1732. {$endif not cpu64bitalu}
  1733. begin
  1734. {$ifndef cpu64bitalu}
  1735. if not(cgpara.location^.loc in [LOC_REGISTER,LOC_CREGISTER]) or
  1736. (size<>OS_F64) then
  1737. {$endif not cpu64bitalu}
  1738. cgpara.check_simple_location;
  1739. paramanager.alloccgpara(list,cgpara);
  1740. case cgpara.location^.loc of
  1741. LOC_MMREGISTER,LOC_CMMREGISTER:
  1742. a_loadmm_reg_reg(list,size,cgpara.location^.size,reg,cgpara.location^.register,shuffle);
  1743. LOC_REFERENCE,LOC_CREFERENCE:
  1744. begin
  1745. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  1746. a_loadmm_reg_ref(list,size,cgpara.location^.size,reg,href,shuffle);
  1747. end;
  1748. LOC_REGISTER,LOC_CREGISTER:
  1749. begin
  1750. if assigned(shuffle) and
  1751. not shufflescalar(shuffle) then
  1752. internalerror(2009112510);
  1753. {$ifndef cpu64bitalu}
  1754. if (size=OS_F64) then
  1755. begin
  1756. if not assigned(cgpara.location^.next) or
  1757. assigned(cgpara.location^.next^.next) then
  1758. internalerror(2009112512);
  1759. case cgpara.location^.next^.loc of
  1760. LOC_REGISTER,LOC_CREGISTER:
  1761. tmpreg:=cgpara.location^.next^.register;
  1762. LOC_REFERENCE,LOC_CREFERENCE:
  1763. tmpreg:=getintregister(list,OS_32);
  1764. else
  1765. internalerror(2009112910);
  1766. end;
  1767. if (target_info.endian=ENDIAN_BIG) then
  1768. begin
  1769. { paraloc^ -> high
  1770. paraloc^.next -> low }
  1771. reg64.reghi:=cgpara.location^.register;
  1772. reg64.reglo:=tmpreg;
  1773. end
  1774. else
  1775. begin
  1776. { paraloc^ -> low
  1777. paraloc^.next -> high }
  1778. reg64.reglo:=cgpara.location^.register;
  1779. reg64.reghi:=tmpreg;
  1780. end;
  1781. cg64.a_loadmm_reg_intreg64(list,size,reg,reg64);
  1782. if (cgpara.location^.next^.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  1783. begin
  1784. if not(cgpara.location^.next^.size in [OS_32,OS_S32]) then
  1785. internalerror(2009112911);
  1786. reference_reset_base(href,cgpara.location^.next^.reference.index,cgpara.location^.next^.reference.offset,cgpara.alignment);
  1787. a_load_reg_ref(list,OS_32,cgpara.location^.next^.size,tmpreg,href);
  1788. end;
  1789. end
  1790. else
  1791. {$endif not cpu64bitalu}
  1792. a_loadmm_reg_intreg(list,size,cgpara.location^.size,reg,cgpara.location^.register,mms_movescalar);
  1793. end
  1794. else
  1795. internalerror(200310123);
  1796. end;
  1797. end;
  1798. procedure tcg.a_loadmm_ref_cgpara(list: TAsmList; size: tcgsize;const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle);
  1799. var
  1800. hr : tregister;
  1801. hs : tmmshuffle;
  1802. begin
  1803. cgpara.check_simple_location;
  1804. hr:=getmmregister(list,cgpara.location^.size);
  1805. a_loadmm_ref_reg(list,size,cgpara.location^.size,ref,hr,shuffle);
  1806. if realshuffle(shuffle) then
  1807. begin
  1808. hs:=shuffle^;
  1809. removeshuffles(hs);
  1810. a_loadmm_reg_cgpara(list,cgpara.location^.size,hr,cgpara,@hs);
  1811. end
  1812. else
  1813. a_loadmm_reg_cgpara(list,cgpara.location^.size,hr,cgpara,shuffle);
  1814. end;
  1815. procedure tcg.a_loadmm_loc_cgpara(list: TAsmList;const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle);
  1816. begin
  1817. case loc.loc of
  1818. LOC_MMREGISTER,LOC_CMMREGISTER:
  1819. a_loadmm_reg_cgpara(list,loc.size,loc.register,cgpara,shuffle);
  1820. LOC_REFERENCE,LOC_CREFERENCE:
  1821. a_loadmm_ref_cgpara(list,loc.size,loc.reference,cgpara,shuffle);
  1822. else
  1823. internalerror(200310123);
  1824. end;
  1825. end;
  1826. procedure tcg.a_opmm_ref_reg(list: TAsmList; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  1827. var
  1828. hr : tregister;
  1829. hs : tmmshuffle;
  1830. begin
  1831. hr:=getmmregister(list,size);
  1832. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1833. if realshuffle(shuffle) then
  1834. begin
  1835. hs:=shuffle^;
  1836. removeshuffles(hs);
  1837. a_opmm_reg_reg(list,op,size,hr,reg,@hs);
  1838. end
  1839. else
  1840. a_opmm_reg_reg(list,op,size,hr,reg,shuffle);
  1841. end;
  1842. procedure tcg.a_opmm_reg_ref(list: TAsmList; Op: TOpCG; size : tcgsize;reg: tregister; const ref: treference; shuffle : pmmshuffle);
  1843. var
  1844. hr : tregister;
  1845. hs : tmmshuffle;
  1846. begin
  1847. hr:=getmmregister(list,size);
  1848. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1849. if realshuffle(shuffle) then
  1850. begin
  1851. hs:=shuffle^;
  1852. removeshuffles(hs);
  1853. a_opmm_reg_reg(list,op,size,reg,hr,@hs);
  1854. a_loadmm_reg_ref(list,size,size,hr,ref,@hs);
  1855. end
  1856. else
  1857. begin
  1858. a_opmm_reg_reg(list,op,size,reg,hr,shuffle);
  1859. a_loadmm_reg_ref(list,size,size,hr,ref,shuffle);
  1860. end;
  1861. end;
  1862. procedure tcg.a_loadmm_intreg_reg(list: tasmlist; fromsize,tosize: tcgsize; intreg,mmreg: tregister; shuffle: pmmshuffle);
  1863. var
  1864. tmpref: treference;
  1865. begin
  1866. if (tcgsize2size[fromsize]<>4) or
  1867. (tcgsize2size[tosize]<>4) then
  1868. internalerror(2009112503);
  1869. tg.gettemp(list,4,4,tt_normal,tmpref);
  1870. a_load_reg_ref(list,fromsize,fromsize,intreg,tmpref);
  1871. a_loadmm_ref_reg(list,tosize,tosize,tmpref,mmreg,shuffle);
  1872. tg.ungettemp(list,tmpref);
  1873. end;
  1874. procedure tcg.a_loadmm_reg_intreg(list: tasmlist; fromsize,tosize: tcgsize; mmreg,intreg: tregister; shuffle: pmmshuffle);
  1875. var
  1876. tmpref: treference;
  1877. begin
  1878. if (tcgsize2size[fromsize]<>4) or
  1879. (tcgsize2size[tosize]<>4) then
  1880. internalerror(2009112504);
  1881. tg.gettemp(list,8,8,tt_normal,tmpref);
  1882. a_loadmm_reg_ref(list,fromsize,fromsize,mmreg,tmpref,shuffle);
  1883. a_load_ref_reg(list,tosize,tosize,tmpref,intreg);
  1884. tg.ungettemp(list,tmpref);
  1885. end;
  1886. procedure tcg.a_opmm_loc_reg(list: TAsmList; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle);
  1887. begin
  1888. case loc.loc of
  1889. LOC_CMMREGISTER,LOC_MMREGISTER:
  1890. a_opmm_reg_reg(list,op,size,loc.register,reg,shuffle);
  1891. LOC_CREFERENCE,LOC_REFERENCE:
  1892. a_opmm_ref_reg(list,op,size,loc.reference,reg,shuffle);
  1893. else
  1894. internalerror(200312232);
  1895. end;
  1896. end;
  1897. procedure tcg.a_opmm_loc_reg_reg(list: TAsmList; Op: TOpCG; size : tcgsize;const loc: tlocation; src,dst: tregister;shuffle : pmmshuffle);
  1898. begin
  1899. case loc.loc of
  1900. LOC_CMMREGISTER,LOC_MMREGISTER:
  1901. a_opmm_reg_reg_reg(list,op,size,loc.register,src,dst,shuffle);
  1902. LOC_CREFERENCE,LOC_REFERENCE:
  1903. a_opmm_ref_reg_reg(list,op,size,loc.reference,src,dst,shuffle);
  1904. else
  1905. internalerror(200312232);
  1906. end;
  1907. end;
  1908. procedure tcg.a_opmm_reg_reg_reg(list : TAsmList;Op : TOpCG;size : tcgsize;
  1909. src1,src2,dst : tregister;shuffle : pmmshuffle);
  1910. begin
  1911. internalerror(2013061102);
  1912. end;
  1913. procedure tcg.a_opmm_ref_reg_reg(list : TAsmList;Op : TOpCG;size : tcgsize;
  1914. const ref : treference;src,dst : tregister;shuffle : pmmshuffle);
  1915. begin
  1916. internalerror(2013061101);
  1917. end;
  1918. procedure tcg.g_concatcopy_unaligned(list : TAsmList;const source,dest : treference;len : tcgint);
  1919. begin
  1920. g_concatcopy(list,source,dest,len);
  1921. end;
  1922. procedure tcg.g_overflowCheck_loc(List:TAsmList;const Loc:TLocation;def:TDef;ovloc : tlocation);
  1923. begin
  1924. g_overflowCheck(list,loc,def);
  1925. end;
  1926. {$ifdef cpuflags}
  1927. procedure tcg.g_flags2ref(list: TAsmList; size: TCgSize; const f: tresflags; const ref:TReference);
  1928. var
  1929. tmpreg : tregister;
  1930. begin
  1931. tmpreg:=getintregister(list,size);
  1932. g_flags2reg(list,size,f,tmpreg);
  1933. a_load_reg_ref(list,size,size,tmpreg,ref);
  1934. end;
  1935. {$endif cpuflags}
  1936. procedure tcg.g_maybe_testvmt(list : TAsmList;reg:tregister;objdef:tobjectdef);
  1937. var
  1938. hrefvmt : treference;
  1939. cgpara1,cgpara2 : TCGPara;
  1940. pd: tprocdef;
  1941. begin
  1942. cgpara1.init;
  1943. cgpara2.init;
  1944. if (cs_check_object in current_settings.localswitches) then
  1945. begin
  1946. pd:=search_system_proc('fpc_check_object_ext');
  1947. paramanager.getintparaloc(pd,1,cgpara1);
  1948. paramanager.getintparaloc(pd,2,cgpara2);
  1949. reference_reset_symbol(hrefvmt,current_asmdata.RefAsmSymbol(objdef.vmt_mangledname,AT_DATA),0,sizeof(pint));
  1950. if pd.is_pushleftright then
  1951. begin
  1952. a_load_reg_cgpara(list,OS_ADDR,reg,cgpara1);
  1953. a_loadaddr_ref_cgpara(list,hrefvmt,cgpara2);
  1954. end
  1955. else
  1956. begin
  1957. a_loadaddr_ref_cgpara(list,hrefvmt,cgpara2);
  1958. a_load_reg_cgpara(list,OS_ADDR,reg,cgpara1);
  1959. end;
  1960. paramanager.freecgpara(list,cgpara1);
  1961. paramanager.freecgpara(list,cgpara2);
  1962. allocallcpuregisters(list);
  1963. a_call_name(list,'fpc_check_object_ext',false);
  1964. deallocallcpuregisters(list);
  1965. end
  1966. else
  1967. if (cs_check_range in current_settings.localswitches) then
  1968. begin
  1969. pd:=search_system_proc('fpc_check_object');
  1970. paramanager.getintparaloc(pd,1,cgpara1);
  1971. a_load_reg_cgpara(list,OS_ADDR,reg,cgpara1);
  1972. paramanager.freecgpara(list,cgpara1);
  1973. allocallcpuregisters(list);
  1974. a_call_name(list,'fpc_check_object',false);
  1975. deallocallcpuregisters(list);
  1976. end;
  1977. cgpara1.done;
  1978. cgpara2.done;
  1979. end;
  1980. {*****************************************************************************
  1981. Entry/Exit Code Functions
  1982. *****************************************************************************}
  1983. procedure tcg.g_save_registers(list:TAsmList);
  1984. var
  1985. href : treference;
  1986. size : longint;
  1987. r : integer;
  1988. begin
  1989. { calculate temp. size }
  1990. size:=0;
  1991. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1992. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1993. inc(size,sizeof(aint));
  1994. if uses_registers(R_ADDRESSREGISTER) then
  1995. for r:=low(saved_address_registers) to high(saved_address_registers) do
  1996. if saved_address_registers[r] in rg[R_ADDRESSREGISTER].used_in_proc then
  1997. inc(size,sizeof(aint));
  1998. { mm registers }
  1999. if uses_registers(R_MMREGISTER) then
  2000. begin
  2001. { Make sure we reserve enough space to do the alignment based on the offset
  2002. later on. We can't use the size for this, because the alignment of the start
  2003. of the temp is smaller than needed for an OS_VECTOR }
  2004. inc(size,tcgsize2size[OS_VECTOR]);
  2005. for r:=low(saved_mm_registers) to high(saved_mm_registers) do
  2006. if saved_mm_registers[r] in rg[R_MMREGISTER].used_in_proc then
  2007. inc(size,tcgsize2size[OS_VECTOR]);
  2008. end;
  2009. if size>0 then
  2010. begin
  2011. tg.GetTemp(list,size,sizeof(aint),tt_noreuse,current_procinfo.save_regs_ref);
  2012. include(current_procinfo.flags,pi_has_saved_regs);
  2013. { Copy registers to temp }
  2014. href:=current_procinfo.save_regs_ref;
  2015. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  2016. begin
  2017. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  2018. begin
  2019. a_load_reg_ref(list,OS_ADDR,OS_ADDR,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE),href);
  2020. inc(href.offset,sizeof(aint));
  2021. end;
  2022. include(rg[R_INTREGISTER].preserved_by_proc,saved_standard_registers[r]);
  2023. end;
  2024. if uses_registers(R_ADDRESSREGISTER) then
  2025. for r:=low(saved_address_registers) to high(saved_address_registers) do
  2026. begin
  2027. if saved_address_registers[r] in rg[R_ADDRESSREGISTER].used_in_proc then
  2028. begin
  2029. a_load_reg_ref(list,OS_ADDR,OS_ADDR,newreg(R_ADDRESSREGISTER,saved_address_registers[r],R_SUBWHOLE),href);
  2030. inc(href.offset,sizeof(aint));
  2031. end;
  2032. include(rg[R_ADDRESSREGISTER].preserved_by_proc,saved_address_registers[r]);
  2033. end;
  2034. if uses_registers(R_MMREGISTER) then
  2035. begin
  2036. if (href.offset mod tcgsize2size[OS_VECTOR])<>0 then
  2037. inc(href.offset,tcgsize2size[OS_VECTOR]-(href.offset mod tcgsize2size[OS_VECTOR]));
  2038. for r:=low(saved_mm_registers) to high(saved_mm_registers) do
  2039. begin
  2040. { the array has to be declared even if no MM registers are saved
  2041. (such as with SSE on i386), and since 0-element arrays don't
  2042. exist, they contain a single RS_INVALID element in that case
  2043. }
  2044. if saved_mm_registers[r]<>RS_INVALID then
  2045. begin
  2046. if saved_mm_registers[r] in rg[R_MMREGISTER].used_in_proc then
  2047. begin
  2048. a_loadmm_reg_ref(list,OS_VECTOR,OS_VECTOR,newreg(R_MMREGISTER,saved_mm_registers[r],R_SUBMMWHOLE),href,nil);
  2049. inc(href.offset,tcgsize2size[OS_VECTOR]);
  2050. end;
  2051. include(rg[R_MMREGISTER].preserved_by_proc,saved_mm_registers[r]);
  2052. end;
  2053. end;
  2054. end;
  2055. end;
  2056. end;
  2057. procedure tcg.g_restore_registers(list:TAsmList);
  2058. var
  2059. href : treference;
  2060. r : integer;
  2061. hreg : tregister;
  2062. begin
  2063. if not(pi_has_saved_regs in current_procinfo.flags) then
  2064. exit;
  2065. { Copy registers from temp }
  2066. href:=current_procinfo.save_regs_ref;
  2067. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  2068. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  2069. begin
  2070. hreg:=newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE);
  2071. { Allocate register so the optimizer does not remove the load }
  2072. a_reg_alloc(list,hreg);
  2073. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,hreg);
  2074. inc(href.offset,sizeof(aint));
  2075. end;
  2076. if uses_registers(R_ADDRESSREGISTER) then
  2077. for r:=low(saved_address_registers) to high(saved_address_registers) do
  2078. if saved_address_registers[r] in rg[R_ADDRESSREGISTER].used_in_proc then
  2079. begin
  2080. hreg:=newreg(R_ADDRESSREGISTER,saved_address_registers[r],R_SUBWHOLE);
  2081. { Allocate register so the optimizer does not remove the load }
  2082. a_reg_alloc(list,hreg);
  2083. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,hreg);
  2084. inc(href.offset,sizeof(aint));
  2085. end;
  2086. if uses_registers(R_MMREGISTER) then
  2087. begin
  2088. if (href.offset mod tcgsize2size[OS_VECTOR])<>0 then
  2089. inc(href.offset,tcgsize2size[OS_VECTOR]-(href.offset mod tcgsize2size[OS_VECTOR]));
  2090. for r:=low(saved_mm_registers) to high(saved_mm_registers) do
  2091. begin
  2092. if saved_mm_registers[r] in rg[R_MMREGISTER].used_in_proc then
  2093. begin
  2094. hreg:=newreg(R_MMREGISTER,saved_mm_registers[r],R_SUBMMWHOLE);
  2095. { Allocate register so the optimizer does not remove the load }
  2096. a_reg_alloc(list,hreg);
  2097. a_loadmm_ref_reg(list,OS_VECTOR,OS_VECTOR,href,hreg,nil);
  2098. inc(href.offset,tcgsize2size[OS_VECTOR]);
  2099. end;
  2100. end;
  2101. end;
  2102. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  2103. end;
  2104. procedure tcg.g_profilecode(list : TAsmList);
  2105. begin
  2106. end;
  2107. procedure tcg.g_exception_reason_save(list : TAsmList; const href : treference);
  2108. begin
  2109. a_load_reg_ref(list, OS_INT, OS_INT, NR_FUNCTION_RESULT_REG, href);
  2110. end;
  2111. procedure tcg.g_exception_reason_save_const(list : TAsmList; const href : treference; a: tcgint);
  2112. begin
  2113. a_load_const_ref(list, OS_INT, a, href);
  2114. end;
  2115. procedure tcg.g_exception_reason_load(list : TAsmList; const href : treference);
  2116. begin
  2117. a_reg_alloc(list,NR_FUNCTION_RESULT_REG);
  2118. a_load_ref_reg(list, OS_INT, OS_INT, href, NR_FUNCTION_RESULT_REG);
  2119. end;
  2120. procedure tcg.g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: tcgint);
  2121. var
  2122. hsym : tsym;
  2123. href : treference;
  2124. paraloc : Pcgparalocation;
  2125. begin
  2126. { calculate the parameter info for the procdef }
  2127. procdef.init_paraloc_info(callerside);
  2128. hsym:=tsym(procdef.parast.Find('self'));
  2129. if not(assigned(hsym) and
  2130. (hsym.typ=paravarsym)) then
  2131. internalerror(200305251);
  2132. paraloc:=tparavarsym(hsym).paraloc[callerside].location;
  2133. while paraloc<>nil do
  2134. with paraloc^ do
  2135. begin
  2136. case loc of
  2137. LOC_REGISTER:
  2138. a_op_const_reg(list,OP_SUB,size,ioffset,register);
  2139. LOC_REFERENCE:
  2140. begin
  2141. { offset in the wrapper needs to be adjusted for the stored
  2142. return address }
  2143. reference_reset_base(href,reference.index,reference.offset+sizeof(pint),sizeof(pint));
  2144. a_op_const_ref(list,OP_SUB,size,ioffset,href);
  2145. end
  2146. else
  2147. internalerror(200309189);
  2148. end;
  2149. paraloc:=next;
  2150. end;
  2151. end;
  2152. procedure tcg.g_external_wrapper(list : TAsmList; procdef: tprocdef; const externalname: string);
  2153. begin
  2154. a_jmp_name(list,externalname);
  2155. end;
  2156. procedure tcg.a_call_name_static(list : TAsmList;const s : string);
  2157. begin
  2158. a_call_name(list,s,false);
  2159. end;
  2160. function tcg.g_indirect_sym_load(list:TAsmList;const symname: string; const flags: tindsymflags): tregister;
  2161. var
  2162. l: tasmsymbol;
  2163. ref: treference;
  2164. nlsymname: string;
  2165. begin
  2166. result := NR_NO;
  2167. case target_info.system of
  2168. system_powerpc_darwin,
  2169. system_i386_darwin,
  2170. system_i386_iphonesim,
  2171. system_powerpc64_darwin,
  2172. system_arm_darwin:
  2173. begin
  2174. nlsymname:='L'+symname+'$non_lazy_ptr';
  2175. l:=current_asmdata.getasmsymbol(nlsymname);
  2176. if not(assigned(l)) then
  2177. begin
  2178. new_section(current_asmdata.asmlists[al_picdata],sec_data_nonlazy,'',sizeof(pint));
  2179. l:=current_asmdata.DefineAsmSymbol(nlsymname,AB_LOCAL,AT_DATA);
  2180. current_asmdata.asmlists[al_picdata].concat(tai_symbol.create(l,0));
  2181. if not(is_weak in flags) then
  2182. current_asmdata.asmlists[al_picdata].concat(tai_directive.Create(asd_indirect_symbol,current_asmdata.RefAsmSymbol(symname).Name))
  2183. else
  2184. current_asmdata.asmlists[al_picdata].concat(tai_directive.Create(asd_indirect_symbol,current_asmdata.WeakRefAsmSymbol(symname).Name));
  2185. {$ifdef cpu64bitaddr}
  2186. current_asmdata.asmlists[al_picdata].concat(tai_const.create_64bit(0));
  2187. {$else cpu64bitaddr}
  2188. current_asmdata.asmlists[al_picdata].concat(tai_const.create_32bit(0));
  2189. {$endif cpu64bitaddr}
  2190. end;
  2191. result := getaddressregister(list);
  2192. reference_reset_symbol(ref,l,0,sizeof(pint));
  2193. { a_load_ref_reg will turn this into a pic-load if needed }
  2194. a_load_ref_reg(list,OS_ADDR,OS_ADDR,ref,result);
  2195. end;
  2196. end;
  2197. end;
  2198. procedure tcg.g_maybe_got_init(list: TAsmList);
  2199. begin
  2200. end;
  2201. procedure tcg.g_call(list: TAsmList;const s: string);
  2202. begin
  2203. allocallcpuregisters(list);
  2204. a_call_name(list,s,false);
  2205. deallocallcpuregisters(list);
  2206. end;
  2207. procedure tcg.g_local_unwind(list: TAsmList; l: TAsmLabel);
  2208. begin
  2209. a_jmp_always(list,l);
  2210. end;
  2211. procedure tcg.a_loadmm_reg_reg(list: TAsmList; fromsize, tosize: tcgsize; reg1, reg2: tregister; shuffle: pmmshuffle);
  2212. begin
  2213. internalerror(200807231);
  2214. end;
  2215. procedure tcg.a_loadmm_ref_reg(list: TAsmList; fromsize, tosize: tcgsize; const ref: treference; reg: tregister; shuffle: pmmshuffle);
  2216. begin
  2217. internalerror(200807232);
  2218. end;
  2219. procedure tcg.a_loadmm_reg_ref(list: TAsmList; fromsize, tosize: tcgsize; reg: tregister; const ref: treference; shuffle: pmmshuffle);
  2220. begin
  2221. internalerror(200807233);
  2222. end;
  2223. procedure tcg.a_opmm_reg_reg(list: TAsmList; Op: TOpCG; size: tcgsize; src, dst: tregister; shuffle: pmmshuffle);
  2224. begin
  2225. internalerror(200807234);
  2226. end;
  2227. function tcg.getflagregister(list: TAsmList; size: Tcgsize): Tregister;
  2228. begin
  2229. Result:=TRegister(0);
  2230. internalerror(200807238);
  2231. end;
  2232. procedure tcg.a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; srcsize, dstsize: tcgsize; src, dst: TRegister);
  2233. begin
  2234. internalerror(2014070601);
  2235. end;
  2236. procedure tcg.g_stackpointer_alloc(list: TAsmList; size: longint);
  2237. begin
  2238. internalerror(2014070602);
  2239. end;
  2240. procedure tcg.a_mul_reg_reg_pair(list: TAsmList; size: TCgSize; src1,src2,dstlo,dsthi: TRegister);
  2241. begin
  2242. internalerror(2014060801);
  2243. end;
  2244. procedure tcg.g_div_const_reg_reg(list:tasmlist; size: TCgSize; a: tcgint; src,dst: tregister);
  2245. var
  2246. divreg: tregister;
  2247. magic: aInt;
  2248. u_magic: aWord;
  2249. u_shift: byte;
  2250. u_add: boolean;
  2251. begin
  2252. divreg:=getintregister(list,OS_INT);
  2253. if (size in [OS_S32,OS_S64]) then
  2254. begin
  2255. calc_divconst_magic_signed(tcgsize2size[size]*8,a,magic,u_shift);
  2256. { load magic value }
  2257. a_load_const_reg(list,OS_INT,magic,divreg);
  2258. { multiply, discarding low bits }
  2259. a_mul_reg_reg_pair(list,size,src,divreg,NR_NO,dst);
  2260. { add/subtract numerator }
  2261. if (a>0) and (magic<0) then
  2262. a_op_reg_reg_reg(list,OP_ADD,OS_INT,src,dst,dst)
  2263. else if (a<0) and (magic>0) then
  2264. a_op_reg_reg_reg(list,OP_SUB,OS_INT,src,dst,dst);
  2265. { shift shift places to the right (arithmetic) }
  2266. a_op_const_reg_reg(list,OP_SAR,OS_INT,u_shift,dst,dst);
  2267. { extract and add sign bit }
  2268. if (a>=0) then
  2269. a_op_const_reg_reg(list,OP_SHR,OS_INT,tcgsize2size[size]*8-1,src,divreg)
  2270. else
  2271. a_op_const_reg_reg(list,OP_SHR,OS_INT,tcgsize2size[size]*8-1,dst,divreg);
  2272. a_op_reg_reg_reg(list,OP_ADD,OS_INT,dst,divreg,dst);
  2273. end
  2274. else if (size in [OS_32,OS_64]) then
  2275. begin
  2276. calc_divconst_magic_unsigned(tcgsize2size[size]*8,a,u_magic,u_add,u_shift);
  2277. { load magic in divreg }
  2278. a_load_const_reg(list,OS_INT,tcgint(u_magic),divreg);
  2279. { multiply, discarding low bits }
  2280. a_mul_reg_reg_pair(list,size,src,divreg,NR_NO,dst);
  2281. if (u_add) then
  2282. begin
  2283. { Calculate "(numerator+result) shr u_shift", avoiding possible overflow }
  2284. a_op_reg_reg_reg(list,OP_SUB,OS_INT,dst,src,divreg);
  2285. { divreg=(numerator-result) }
  2286. a_op_const_reg_reg(list,OP_SHR,OS_INT,1,divreg,divreg);
  2287. { divreg=(numerator-result)/2 }
  2288. a_op_reg_reg_reg(list,OP_ADD,OS_INT,divreg,dst,divreg);
  2289. { divreg=(numerator+result)/2, already shifted by 1, so decrease u_shift. }
  2290. a_op_const_reg_reg(list,OP_SHR,OS_INT,u_shift-1,divreg,dst);
  2291. end
  2292. else
  2293. a_op_const_reg_reg(list,OP_SHR,OS_INT,u_shift,dst,dst);
  2294. end
  2295. else
  2296. InternalError(2014060601);
  2297. end;
  2298. {*****************************************************************************
  2299. TCG64
  2300. *****************************************************************************}
  2301. {$ifndef cpu64bitalu}
  2302. function joinreg64(reglo,reghi : tregister) : tregister64;
  2303. begin
  2304. result.reglo:=reglo;
  2305. result.reghi:=reghi;
  2306. end;
  2307. procedure tcg64.a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64; regsrc,regdst : tregister64);
  2308. begin
  2309. a_load64_reg_reg(list,regsrc,regdst);
  2310. a_op64_const_reg(list,op,size,value,regdst);
  2311. end;
  2312. procedure tcg64.a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  2313. var
  2314. tmpreg64 : tregister64;
  2315. begin
  2316. { when src1=dst then we need to first create a temp to prevent
  2317. overwriting src1 with src2 }
  2318. if (regsrc1.reghi=regdst.reghi) or
  2319. (regsrc1.reglo=regdst.reghi) or
  2320. (regsrc1.reghi=regdst.reglo) or
  2321. (regsrc1.reglo=regdst.reglo) then
  2322. begin
  2323. tmpreg64.reglo:=cg.getintregister(list,OS_32);
  2324. tmpreg64.reghi:=cg.getintregister(list,OS_32);
  2325. a_load64_reg_reg(list,regsrc2,tmpreg64);
  2326. a_op64_reg_reg(list,op,size,regsrc1,tmpreg64);
  2327. a_load64_reg_reg(list,tmpreg64,regdst);
  2328. end
  2329. else
  2330. begin
  2331. a_load64_reg_reg(list,regsrc2,regdst);
  2332. a_op64_reg_reg(list,op,size,regsrc1,regdst);
  2333. end;
  2334. end;
  2335. procedure tcg64.a_op64_const_subsetref(list : TAsmList; Op : TOpCG; size : TCGSize; a : int64; const sref: tsubsetreference);
  2336. var
  2337. tmpreg64 : tregister64;
  2338. begin
  2339. tmpreg64.reglo:=cg.getintregister(list,OS_32);
  2340. tmpreg64.reghi:=cg.getintregister(list,OS_32);
  2341. a_load64_subsetref_reg(list,sref,tmpreg64);
  2342. a_op64_const_reg(list,op,size,a,tmpreg64);
  2343. a_load64_reg_subsetref(list,tmpreg64,sref);
  2344. end;
  2345. procedure tcg64.a_op64_reg_subsetref(list : TAsmList; Op : TOpCG; size : TCGSize; reg: tregister64; const sref: tsubsetreference);
  2346. var
  2347. tmpreg64 : tregister64;
  2348. begin
  2349. tmpreg64.reglo:=cg.getintregister(list,OS_32);
  2350. tmpreg64.reghi:=cg.getintregister(list,OS_32);
  2351. a_load64_subsetref_reg(list,sref,tmpreg64);
  2352. a_op64_reg_reg(list,op,size,reg,tmpreg64);
  2353. a_load64_reg_subsetref(list,tmpreg64,sref);
  2354. end;
  2355. procedure tcg64.a_op64_ref_subsetref(list : TAsmList; Op : TOpCG; size : TCGSize; const ref: treference; const sref: tsubsetreference);
  2356. var
  2357. tmpreg64 : tregister64;
  2358. begin
  2359. tmpreg64.reglo:=cg.getintregister(list,OS_32);
  2360. tmpreg64.reghi:=cg.getintregister(list,OS_32);
  2361. a_load64_subsetref_reg(list,sref,tmpreg64);
  2362. a_op64_ref_reg(list,op,size,ref,tmpreg64);
  2363. a_load64_reg_subsetref(list,tmpreg64,sref);
  2364. end;
  2365. procedure tcg64.a_op64_subsetref_subsetref(list : TAsmList; Op : TOpCG; size : TCGSize; const ssref,dsref: tsubsetreference);
  2366. var
  2367. tmpreg64 : tregister64;
  2368. begin
  2369. tmpreg64.reglo:=cg.getintregister(list,OS_32);
  2370. tmpreg64.reghi:=cg.getintregister(list,OS_32);
  2371. a_load64_subsetref_reg(list,ssref,tmpreg64);
  2372. a_op64_reg_subsetref(list,op,size,tmpreg64,dsref);
  2373. end;
  2374. procedure tcg64.a_op64_const_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  2375. begin
  2376. a_op64_const_reg_reg(list,op,size,value,regsrc,regdst);
  2377. ovloc.loc:=LOC_VOID;
  2378. end;
  2379. procedure tcg64.a_op64_reg_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  2380. begin
  2381. a_op64_reg_reg_reg(list,op,size,regsrc1,regsrc2,regdst);
  2382. ovloc.loc:=LOC_VOID;
  2383. end;
  2384. procedure tcg64.a_load64_loc_subsetref(list : TAsmList;const l: tlocation; const sref : tsubsetreference);
  2385. begin
  2386. case l.loc of
  2387. LOC_REFERENCE, LOC_CREFERENCE:
  2388. a_load64_ref_subsetref(list,l.reference,sref);
  2389. LOC_REGISTER,LOC_CREGISTER:
  2390. a_load64_reg_subsetref(list,l.register64,sref);
  2391. LOC_CONSTANT :
  2392. a_load64_const_subsetref(list,l.value64,sref);
  2393. LOC_SUBSETREF,LOC_CSUBSETREF:
  2394. a_load64_subsetref_subsetref(list,l.sref,sref);
  2395. else
  2396. internalerror(2006082210);
  2397. end;
  2398. end;
  2399. procedure tcg64.a_load64_subsetref_loc(list: TAsmlist; const sref: tsubsetreference; const l: tlocation);
  2400. begin
  2401. case l.loc of
  2402. LOC_REFERENCE, LOC_CREFERENCE:
  2403. a_load64_subsetref_ref(list,sref,l.reference);
  2404. LOC_REGISTER,LOC_CREGISTER:
  2405. a_load64_subsetref_reg(list,sref,l.register64);
  2406. LOC_SUBSETREF,LOC_CSUBSETREF:
  2407. a_load64_subsetref_subsetref(list,sref,l.sref);
  2408. else
  2409. internalerror(2006082211);
  2410. end;
  2411. end;
  2412. {$else cpu64bitalu}
  2413. function joinreg128(reglo, reghi: tregister): tregister128;
  2414. begin
  2415. result.reglo:=reglo;
  2416. result.reghi:=reghi;
  2417. end;
  2418. procedure splitparaloc128(const cgpara:tcgpara;var cgparalo,cgparahi:tcgpara);
  2419. var
  2420. paraloclo,
  2421. paralochi : pcgparalocation;
  2422. begin
  2423. if not(cgpara.size in [OS_128,OS_S128]) then
  2424. internalerror(2012090604);
  2425. if not assigned(cgpara.location) then
  2426. internalerror(2012090605);
  2427. { init lo/hi para }
  2428. cgparahi.reset;
  2429. if cgpara.size=OS_S128 then
  2430. cgparahi.size:=OS_S64
  2431. else
  2432. cgparahi.size:=OS_64;
  2433. cgparahi.intsize:=8;
  2434. cgparahi.alignment:=cgpara.alignment;
  2435. paralochi:=cgparahi.add_location;
  2436. cgparalo.reset;
  2437. cgparalo.size:=OS_64;
  2438. cgparalo.intsize:=8;
  2439. cgparalo.alignment:=cgpara.alignment;
  2440. paraloclo:=cgparalo.add_location;
  2441. { 2 parameter fields? }
  2442. if assigned(cgpara.location^.next) then
  2443. begin
  2444. { Order for multiple locations is always
  2445. paraloc^ -> high
  2446. paraloc^.next -> low }
  2447. if (target_info.endian=ENDIAN_BIG) then
  2448. begin
  2449. { paraloc^ -> high
  2450. paraloc^.next -> low }
  2451. move(cgpara.location^,paralochi^,sizeof(paralochi^));
  2452. move(cgpara.location^.next^,paraloclo^,sizeof(paraloclo^));
  2453. end
  2454. else
  2455. begin
  2456. { paraloc^ -> low
  2457. paraloc^.next -> high }
  2458. move(cgpara.location^,paraloclo^,sizeof(paraloclo^));
  2459. move(cgpara.location^.next^,paralochi^,sizeof(paralochi^));
  2460. end;
  2461. end
  2462. else
  2463. begin
  2464. { single parameter, this can only be in memory }
  2465. if cgpara.location^.loc<>LOC_REFERENCE then
  2466. internalerror(2012090606);
  2467. move(cgpara.location^,paraloclo^,sizeof(paraloclo^));
  2468. move(cgpara.location^,paralochi^,sizeof(paralochi^));
  2469. { for big endian low is at +8, for little endian high }
  2470. if target_info.endian = endian_big then
  2471. begin
  2472. inc(cgparalo.location^.reference.offset,8);
  2473. cgparalo.alignment:=newalignment(cgparalo.alignment,8);
  2474. end
  2475. else
  2476. begin
  2477. inc(cgparahi.location^.reference.offset,8);
  2478. cgparahi.alignment:=newalignment(cgparahi.alignment,8);
  2479. end;
  2480. end;
  2481. { fix size }
  2482. paraloclo^.size:=cgparalo.size;
  2483. paraloclo^.next:=nil;
  2484. paralochi^.size:=cgparahi.size;
  2485. paralochi^.next:=nil;
  2486. end;
  2487. procedure tcg128.a_load128_reg_reg(list: TAsmList; regsrc,
  2488. regdst: tregister128);
  2489. begin
  2490. cg.a_load_reg_reg(list,OS_64,OS_64,regsrc.reglo,regdst.reglo);
  2491. cg.a_load_reg_reg(list,OS_64,OS_64,regsrc.reghi,regdst.reghi);
  2492. end;
  2493. procedure tcg128.a_load128_reg_ref(list: TAsmList; reg: tregister128;
  2494. const ref: treference);
  2495. var
  2496. tmpreg: tregister;
  2497. tmpref: treference;
  2498. begin
  2499. if target_info.endian = endian_big then
  2500. begin
  2501. tmpreg:=reg.reglo;
  2502. reg.reglo:=reg.reghi;
  2503. reg.reghi:=tmpreg;
  2504. end;
  2505. cg.a_load_reg_ref(list,OS_64,OS_64,reg.reglo,ref);
  2506. tmpref := ref;
  2507. inc(tmpref.offset,8);
  2508. cg.a_load_reg_ref(list,OS_64,OS_64,reg.reghi,tmpref);
  2509. end;
  2510. procedure tcg128.a_load128_ref_reg(list: TAsmList; const ref: treference;
  2511. reg: tregister128);
  2512. var
  2513. tmpreg: tregister;
  2514. tmpref: treference;
  2515. begin
  2516. if target_info.endian = endian_big then
  2517. begin
  2518. tmpreg := reg.reglo;
  2519. reg.reglo := reg.reghi;
  2520. reg.reghi := tmpreg;
  2521. end;
  2522. tmpref := ref;
  2523. if (tmpref.base=reg.reglo) then
  2524. begin
  2525. tmpreg:=cg.getaddressregister(list);
  2526. cg.a_load_reg_reg(list,OS_ADDR,OS_ADDR,tmpref.base,tmpreg);
  2527. tmpref.base:=tmpreg;
  2528. end
  2529. else
  2530. { this works only for the i386, thus the i386 needs to override }
  2531. { this method and this method must be replaced by a more generic }
  2532. { implementation FK }
  2533. if (tmpref.index=reg.reglo) then
  2534. begin
  2535. tmpreg:=cg.getaddressregister(list);
  2536. cg.a_load_reg_reg(list,OS_ADDR,OS_ADDR,tmpref.index,tmpreg);
  2537. tmpref.index:=tmpreg;
  2538. end;
  2539. cg.a_load_ref_reg(list,OS_64,OS_64,tmpref,reg.reglo);
  2540. inc(tmpref.offset,8);
  2541. cg.a_load_ref_reg(list,OS_64,OS_64,tmpref,reg.reghi);
  2542. end;
  2543. procedure tcg128.a_load128_loc_ref(list: TAsmList; const l: tlocation;
  2544. const ref: treference);
  2545. begin
  2546. case l.loc of
  2547. LOC_REGISTER,LOC_CREGISTER:
  2548. a_load128_reg_ref(list,l.register128,ref);
  2549. { not yet implemented:
  2550. LOC_CONSTANT :
  2551. a_load128_const_ref(list,l.value128,ref);
  2552. LOC_SUBSETREF, LOC_CSUBSETREF:
  2553. a_load64_subsetref_ref(list,l.sref,ref); }
  2554. else
  2555. internalerror(201209061);
  2556. end;
  2557. end;
  2558. procedure tcg128.a_load128_reg_loc(list: TAsmList; reg: tregister128;
  2559. const l: tlocation);
  2560. begin
  2561. case l.loc of
  2562. LOC_REFERENCE, LOC_CREFERENCE:
  2563. a_load128_reg_ref(list,reg,l.reference);
  2564. LOC_REGISTER,LOC_CREGISTER:
  2565. a_load128_reg_reg(list,reg,l.register128);
  2566. { not yet implemented:
  2567. LOC_SUBSETREF, LOC_CSUBSETREF:
  2568. a_load64_reg_subsetref(list,reg,l.sref);
  2569. LOC_MMREGISTER, LOC_CMMREGISTER:
  2570. a_loadmm_intreg64_reg(list,l.size,reg,l.register); }
  2571. else
  2572. internalerror(201209062);
  2573. end;
  2574. end;
  2575. procedure tcg128.a_load128_const_reg(list: TAsmList; valuelo,
  2576. valuehi: int64; reg: tregister128);
  2577. begin
  2578. cg.a_load_const_reg(list,OS_64,aint(valuelo),reg.reglo);
  2579. cg.a_load_const_reg(list,OS_64,aint(valuehi),reg.reghi);
  2580. end;
  2581. procedure tcg128.a_load128_loc_cgpara(list: TAsmList; const l: tlocation;
  2582. const paraloc: TCGPara);
  2583. begin
  2584. case l.loc of
  2585. LOC_REGISTER,
  2586. LOC_CREGISTER :
  2587. a_load128_reg_cgpara(list,l.register128,paraloc);
  2588. {not yet implemented:
  2589. LOC_CONSTANT :
  2590. a_load128_const_cgpara(list,l.value64,paraloc);
  2591. }
  2592. LOC_CREFERENCE,
  2593. LOC_REFERENCE :
  2594. a_load128_ref_cgpara(list,l.reference,paraloc);
  2595. else
  2596. internalerror(2012090603);
  2597. end;
  2598. end;
  2599. procedure tcg128.a_load128_reg_cgpara(list : TAsmList;reg : tregister128;const paraloc : tcgpara);
  2600. var
  2601. tmplochi,tmploclo: tcgpara;
  2602. begin
  2603. tmploclo.init;
  2604. tmplochi.init;
  2605. splitparaloc128(paraloc,tmploclo,tmplochi);
  2606. cg.a_load_reg_cgpara(list,OS_64,reg.reghi,tmplochi);
  2607. cg.a_load_reg_cgpara(list,OS_64,reg.reglo,tmploclo);
  2608. tmploclo.done;
  2609. tmplochi.done;
  2610. end;
  2611. procedure tcg128.a_load128_ref_cgpara(list : TAsmList;const r : treference;const paraloc : tcgpara);
  2612. var
  2613. tmprefhi,tmpreflo : treference;
  2614. tmploclo,tmplochi : tcgpara;
  2615. begin
  2616. tmploclo.init;
  2617. tmplochi.init;
  2618. splitparaloc128(paraloc,tmploclo,tmplochi);
  2619. tmprefhi:=r;
  2620. tmpreflo:=r;
  2621. if target_info.endian=endian_big then
  2622. inc(tmpreflo.offset,8)
  2623. else
  2624. inc(tmprefhi.offset,8);
  2625. cg.a_load_ref_cgpara(list,OS_64,tmprefhi,tmplochi);
  2626. cg.a_load_ref_cgpara(list,OS_64,tmpreflo,tmploclo);
  2627. tmploclo.done;
  2628. tmplochi.done;
  2629. end;
  2630. {$endif cpu64bitalu}
  2631. function asmsym2indsymflags(sym: TAsmSymbol): tindsymflags;
  2632. begin
  2633. result:=[];
  2634. if sym.typ<>AT_FUNCTION then
  2635. include(result,is_data);
  2636. if sym.bind=AB_WEAK_EXTERNAL then
  2637. include(result,is_weak);
  2638. end;
  2639. procedure destroy_codegen;
  2640. begin
  2641. cg.free;
  2642. cg:=nil;
  2643. {$ifdef cpu64bitalu}
  2644. cg128.free;
  2645. cg128:=nil;
  2646. {$else cpu64bitalu}
  2647. cg64.free;
  2648. cg64:=nil;
  2649. {$endif cpu64bitalu}
  2650. end;
  2651. end.