cgobj.pas 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088
  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. cclasses,globtype,
  31. cpubase,cgbase,cgutils,parabase,
  32. aasmbase,aasmtai,aasmcpu,
  33. symconst,symbase,symtype,symdef,symtable,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 overriden for all new processors which will be supported
  41. by Free Pascal. For 32-bit processors, the base class
  42. sould be @link(tcg64f32) and not @var(tcg).
  43. }
  44. tcg = class
  45. public
  46. alignment : talignment;
  47. rg : array[tregistertype] of trgobj;
  48. t_times : longint;
  49. {$ifdef flowgraph}
  50. aktflownode:word;
  51. {$endif}
  52. {************************************************}
  53. { basic routines }
  54. constructor create;
  55. {# Initialize the register allocators needed for the codegenerator.}
  56. procedure init_register_allocators;virtual;
  57. {# Clean up the register allocators needed for the codegenerator.}
  58. procedure done_register_allocators;virtual;
  59. {$ifdef flowgraph}
  60. procedure init_flowgraph;
  61. procedure done_flowgraph;
  62. {$endif}
  63. {# Gets a register suitable to do integer operations on.}
  64. function getintregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  65. {# Gets a register suitable to do integer operations on.}
  66. function getaddressregister(list:Taasmoutput):Tregister;virtual;
  67. function getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  68. function getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  69. function getflagregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;abstract;
  70. {Does the generic cg need SIMD registers, like getmmxregister? Or should
  71. the cpu specific child cg object have such a method?}
  72. procedure add_reg_instruction(instr:Tai;r:tregister);virtual;
  73. procedure add_move_instruction(instr:Taicpu);virtual;
  74. function uses_registers(rt:Tregistertype):boolean;virtual;
  75. {# Get a specific register.}
  76. procedure getcpuregister(list:Taasmoutput;r:Tregister);virtual;
  77. procedure ungetcpuregister(list:Taasmoutput;r:Tregister);virtual;
  78. {# Get multiple registers specified.}
  79. procedure alloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;
  80. {# Free multiple registers specified.}
  81. procedure dealloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;
  82. procedure allocallcpuregisters(list:Taasmoutput);virtual;
  83. procedure deallocallcpuregisters(list:Taasmoutput);virtual;
  84. procedure do_register_allocation(list:Taasmoutput;headertai:tai);virtual;
  85. function makeregsize(list:Taasmoutput;reg:Tregister;size:Tcgsize):Tregister;
  86. {# Emit a label to the instruction stream. }
  87. procedure a_label(list : taasmoutput;l : tasmlabel);virtual;
  88. {# Allocates register r by inserting a pai_realloc record }
  89. procedure a_reg_alloc(list : taasmoutput;r : tregister);
  90. {# Deallocates register r by inserting a pa_regdealloc record}
  91. procedure a_reg_dealloc(list : taasmoutput;r : tregister);
  92. { Synchronize register, make sure it is still valid }
  93. procedure a_reg_sync(list : taasmoutput;r : tregister);
  94. {# Pass a parameter, which is located in a register, to a routine.
  95. This routine should push/send the parameter to the routine, as
  96. required by the specific processor ABI and routine modifiers.
  97. This must be overriden for each CPU target.
  98. @param(size size of the operand in the register)
  99. @param(r register source of the operand)
  100. @param(cgpara where the parameter will be stored)
  101. }
  102. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const cgpara : TCGPara);virtual;
  103. {# Pass a parameter, which is a constant, to a routine.
  104. A generic version is provided. This routine should
  105. be overriden for optimization purposes if the cpu
  106. permits directly sending this type of parameter.
  107. @param(size size of the operand in constant)
  108. @param(a value of constant to send)
  109. @param(cgpara where the parameter will be stored)
  110. }
  111. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aint;const cgpara : TCGPara);virtual;
  112. {# Pass the value of a parameter, which is located in memory, to a routine.
  113. A generic version is provided. This routine should
  114. be overriden for optimization purposes if the cpu
  115. permits directly sending this type of parameter.
  116. @param(size size of the operand in constant)
  117. @param(r Memory reference of value to send)
  118. @param(cgpara where the parameter will be stored)
  119. }
  120. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const cgpara : TCGPara);virtual;
  121. {# Pass the value of a parameter, which can be located either in a register or memory location,
  122. to a routine.
  123. A generic version is provided.
  124. @param(l location of the operand to send)
  125. @param(nr parameter number (starting from one) of routine (from left to right))
  126. @param(cgpara where the parameter will be stored)
  127. }
  128. procedure a_param_loc(list : taasmoutput;const l : tlocation;const cgpara : TCGPara);
  129. {# Pass the address of a reference to a routine. This routine
  130. will calculate the address of the reference, and pass this
  131. calculated address as a parameter.
  132. A generic version is provided. This routine should
  133. be overriden for optimization purposes if the cpu
  134. permits directly sending this type of parameter.
  135. @param(r reference to get address from)
  136. @param(nr parameter number (starting from one) of routine (from left to right))
  137. }
  138. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const cgpara : TCGPara);virtual;
  139. { Remarks:
  140. * If a method specifies a size you have only to take care
  141. of that number of bits, i.e. load_const_reg with OP_8 must
  142. only load the lower 8 bit of the specified register
  143. the rest of the register can be undefined
  144. if necessary the compiler will call a method
  145. to zero or sign extend the register
  146. * The a_load_XX_XX with OP_64 needn't to be
  147. implemented for 32 bit
  148. processors, the code generator takes care of that
  149. * the addr size is for work with the natural pointer
  150. size
  151. * the procedures without fpu/mm are only for integer usage
  152. * normally the first location is the source and the
  153. second the destination
  154. }
  155. {# Emits instruction to call the method specified by symbol name.
  156. This routine must be overriden for each new target cpu.
  157. There is no a_call_ref because loading the reference will use
  158. a temp register on most cpu's resulting in conflicts with the
  159. registers used for the parameters (PFV)
  160. }
  161. procedure a_call_name(list : taasmoutput;const s : string);virtual; abstract;
  162. procedure a_call_reg(list : taasmoutput;reg : tregister);virtual; abstract;
  163. procedure a_call_ref(list : taasmoutput;ref : treference);virtual; abstract;
  164. { same as a_call_name, might be overriden on certain architectures to emit
  165. static calls without usage of a got trampoline }
  166. procedure a_call_name_static(list : taasmoutput;const s : string);virtual;
  167. { move instructions }
  168. procedure a_load_const_reg(list : taasmoutput;size : tcgsize;a : aint;register : tregister);virtual; abstract;
  169. procedure a_load_const_ref(list : taasmoutput;size : tcgsize;a : aint;const ref : treference);virtual;
  170. procedure a_load_const_loc(list : taasmoutput;a : aint;const loc : tlocation);
  171. procedure a_load_reg_ref(list : taasmoutput;fromsize,tosize : tcgsize;register : tregister;const ref : treference);virtual; abstract;
  172. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);virtual; abstract;
  173. procedure a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  174. procedure a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref : treference;register : tregister);virtual; abstract;
  175. procedure a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);virtual;
  176. procedure a_load_loc_reg(list : taasmoutput;tosize: tcgsize; const loc: tlocation; reg : tregister);
  177. procedure a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  178. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);virtual; abstract;
  179. { fpu move instructions }
  180. procedure a_loadfpu_reg_reg(list: taasmoutput; size:tcgsize; reg1, reg2: tregister); virtual; abstract;
  181. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); virtual; abstract;
  182. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); virtual; abstract;
  183. procedure a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  184. procedure a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  185. procedure a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const cgpara : TCGPara);virtual;
  186. procedure a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const cgpara : TCGPara);virtual;
  187. { vector register move instructions }
  188. procedure a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); virtual; abstract;
  189. procedure a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual; abstract;
  190. procedure a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); virtual; abstract;
  191. procedure a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  192. procedure a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  193. procedure a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  194. procedure a_parammm_ref(list: taasmoutput; size: tcgsize; const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  195. procedure a_parammm_loc(list: taasmoutput; const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  196. procedure a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle); virtual;abstract;
  197. procedure a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual;
  198. procedure a_opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle); virtual;
  199. procedure a_opmm_reg_ref(list: taasmoutput; Op: TOpCG; size : tcgsize;reg: tregister;const ref: treference; shuffle : pmmshuffle); virtual;
  200. { basic arithmetic operations }
  201. { note: for operators which require only one argument (not, neg), use }
  202. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  203. { that in this case the *second* operand is used as both source and }
  204. { destination (JM) }
  205. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: Aint; reg: TRegister); virtual; abstract;
  206. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: Aint; const ref: TReference); virtual;
  207. procedure a_op_const_loc(list : taasmoutput; Op: TOpCG; a: Aint; const loc: tlocation);
  208. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); virtual; abstract;
  209. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); virtual;
  210. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); virtual;
  211. procedure a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  212. procedure a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  213. { trinary operations for processors that support them, 'emulated' }
  214. { on others. None with "ref" arguments since I don't think there }
  215. { are any processors that support it (JM) }
  216. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister); virtual;
  217. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister); virtual;
  218. procedure a_op_const_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  219. procedure a_op_reg_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  220. { comparison operations }
  221. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  222. l : tasmlabel);virtual; abstract;
  223. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  224. l : tasmlabel); virtual;
  225. procedure a_cmp_const_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; a: aint; const loc: tlocation;
  226. l : tasmlabel);
  227. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  228. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  229. procedure a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); virtual;
  230. procedure a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  231. procedure a_cmp_reg_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; reg: tregister; const loc: tlocation; l : tasmlabel);
  232. procedure a_cmp_ref_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation;
  233. l : tasmlabel);
  234. procedure a_jmp_name(list : taasmoutput;const s : string); virtual; abstract;
  235. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); virtual; abstract;
  236. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); virtual; abstract;
  237. {# Depending on the value to check in the flags, either sets the register reg to one (if the flag is set)
  238. or zero (if the flag is cleared). The size parameter indicates the destination size register.
  239. }
  240. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); virtual; abstract;
  241. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference); virtual;
  242. {
  243. This routine tries to optimize the const_reg opcode, and should be
  244. called at the start of a_op_const_reg. It returns the actual opcode
  245. to emit, and the constant value to emit. If this routine returns
  246. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  247. @param(op The opcode to emit, returns the opcode which must be emitted)
  248. @param(a The constant which should be emitted, returns the constant which must
  249. be emitted)
  250. @param(reg The register to emit the opcode with, returns the register with
  251. which the opcode will be emitted)
  252. }
  253. function optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aint; var reg: tregister): boolean;virtual;
  254. {#
  255. This routine is used in exception management nodes. It should
  256. save the exception reason currently in the FUNCTION_RETURN_REG. The
  257. save should be done either to a temp (pointed to by href).
  258. or on the stack (pushing the value on the stack).
  259. The size of the value to save is OS_S32. The default version
  260. saves the exception reason to a temp. memory area.
  261. }
  262. procedure g_exception_reason_save(list : taasmoutput; const href : treference);virtual;
  263. {#
  264. This routine is used in exception management nodes. It should
  265. save the exception reason constant. The
  266. save should be done either to a temp (pointed to by href).
  267. or on the stack (pushing the value on the stack).
  268. The size of the value to save is OS_S32. The default version
  269. saves the exception reason to a temp. memory area.
  270. }
  271. procedure g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aint);virtual;
  272. {#
  273. This routine is used in exception management nodes. It should
  274. load the exception reason to the FUNCTION_RETURN_REG. The saved value
  275. should either be in the temp. area (pointed to by href , href should
  276. *NOT* be freed) or on the stack (the value should be popped).
  277. The size of the value to save is OS_S32. The default version
  278. saves the exception reason to a temp. memory area.
  279. }
  280. procedure g_exception_reason_load(list : taasmoutput; const href : treference);virtual;
  281. procedure g_maybe_testself(list : taasmoutput;reg:tregister);
  282. procedure g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  283. {# This should emit the opcode to copy len bytes from the source
  284. to destination.
  285. It must be overriden for each new target processor.
  286. @param(source Source reference of copy)
  287. @param(dest Destination reference of copy)
  288. }
  289. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aint);virtual; abstract;
  290. {# This should emit the opcode to copy len bytes from the an unaligned source
  291. to destination.
  292. It must be overriden for each new target processor.
  293. @param(source Source reference of copy)
  294. @param(dest Destination reference of copy)
  295. }
  296. procedure g_concatcopy_unaligned(list : taasmoutput;const source,dest : treference;len : aint);virtual;
  297. {# This should emit the opcode to a shortrstring from the source
  298. to destination.
  299. @param(source Source reference of copy)
  300. @param(dest Destination reference of copy)
  301. }
  302. procedure g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte);
  303. procedure g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  304. procedure g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  305. procedure g_initialize(list : taasmoutput;t : tdef;const ref : treference);
  306. procedure g_finalize(list : taasmoutput;t : tdef;const ref : treference);
  307. {# Generates range checking code. It is to note
  308. that this routine does not need to be overriden,
  309. as it takes care of everything.
  310. @param(p Node which contains the value to check)
  311. @param(todef Type definition of node to range check)
  312. }
  313. procedure g_rangecheck(list: taasmoutput; const l:tlocation; fromdef,todef: tdef); virtual;
  314. {# Generates overflow checking code for a node }
  315. procedure g_overflowcheck(list: taasmoutput; const Loc:tlocation; def:tdef); virtual;abstract;
  316. procedure g_overflowCheck_loc(List:TAasmOutput;const Loc:TLocation;def:TDef;ovloc : tlocation);virtual;
  317. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;const lenloc:tlocation;elesize:aint;destreg:tregister);virtual;
  318. procedure g_releasevaluepara_openarray(list : taasmoutput;const l:tlocation);virtual;
  319. {# Emits instructions when compilation is done in profile
  320. mode (this is set as a command line option). The default
  321. behavior does nothing, should be overriden as required.
  322. }
  323. procedure g_profilecode(list : taasmoutput);virtual;
  324. {# Emits instruction for allocating @var(size) bytes at the stackpointer
  325. @param(size Number of bytes to allocate)
  326. }
  327. procedure g_stackpointer_alloc(list : taasmoutput;size : longint);virtual; abstract;
  328. {# Emits instruction for allocating the locals in entry
  329. code of a routine. This is one of the first
  330. routine called in @var(genentrycode).
  331. @param(localsize Number of bytes to allocate as locals)
  332. }
  333. procedure g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);virtual; abstract;
  334. {# Emits instructions for returning from a subroutine.
  335. Should also restore the framepointer and stack.
  336. @param(parasize Number of bytes of parameters to deallocate from stack)
  337. }
  338. procedure g_proc_exit(list : taasmoutput;parasize:longint;nostackframe:boolean);virtual;abstract;
  339. {# This routine is called when generating the code for the entry point
  340. of a routine. It should save all registers which are not used in this
  341. routine, and which should be declared as saved in the std_saved_registers
  342. set.
  343. This routine is mainly used when linking to code which is generated
  344. by ABI-compliant compilers (like GCC), to make sure that the reserved
  345. registers of that ABI are not clobbered.
  346. @param(usedinproc Registers which are used in the code of this routine)
  347. }
  348. procedure g_save_standard_registers(list:Taasmoutput);virtual;
  349. {# This routine is called when generating the code for the exit point
  350. of a routine. It should restore all registers which were previously
  351. saved in @var(g_save_standard_registers).
  352. @param(usedinproc Registers which are used in the code of this routine)
  353. }
  354. procedure g_restore_standard_registers(list:Taasmoutput);virtual;
  355. procedure g_intf_wrapper(list: TAAsmoutput; procdef: tprocdef; const labelname: string; ioffset: longint);virtual;abstract;
  356. procedure g_adjust_self_value(list:taasmoutput;procdef: tprocdef;ioffset: aint);virtual;
  357. end;
  358. {$ifndef cpu64bit}
  359. {# @abstract(Abstract code generator for 64 Bit operations)
  360. This class implements an abstract code generator class
  361. for 64 Bit operations.
  362. }
  363. tcg64 = class
  364. procedure a_load64_const_ref(list : taasmoutput;value : int64;const ref : treference);virtual;abstract;
  365. procedure a_load64_reg_ref(list : taasmoutput;reg : tregister64;const ref : treference);virtual;abstract;
  366. procedure a_load64_ref_reg(list : taasmoutput;const ref : treference;reg : tregister64);virtual;abstract;
  367. procedure a_load64_reg_reg(list : taasmoutput;regsrc,regdst : tregister64);virtual;abstract;
  368. procedure a_load64_const_reg(list : taasmoutput;value : int64;reg : tregister64);virtual;abstract;
  369. procedure a_load64_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister64);virtual;abstract;
  370. procedure a_load64_loc_ref(list : taasmoutput;const l : tlocation;const ref : treference);virtual;abstract;
  371. procedure a_load64_const_loc(list : taasmoutput;value : int64;const l : tlocation);virtual;abstract;
  372. procedure a_load64_reg_loc(list : taasmoutput;reg : tregister64;const l : tlocation);virtual;abstract;
  373. procedure a_load64high_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  374. procedure a_load64low_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  375. procedure a_load64high_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  376. procedure a_load64low_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  377. procedure a_load64high_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  378. procedure a_load64low_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  379. procedure a_op64_ref_reg(list : taasmoutput;op:TOpCG;size : tcgsize;const ref : treference;reg : tregister64);virtual;abstract;
  380. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);virtual;abstract;
  381. procedure a_op64_reg_ref(list : taasmoutput;op:TOpCG;size : tcgsize;regsrc : tregister64;const ref : treference);virtual;abstract;
  382. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;size : tcgsize;value : int64;regdst : tregister64);virtual;abstract;
  383. procedure a_op64_const_ref(list : taasmoutput;op:TOpCG;size : tcgsize;value : int64;const ref : treference);virtual;abstract;
  384. procedure a_op64_const_loc(list : taasmoutput;op:TOpCG;size : tcgsize;value : int64;const l: tlocation);virtual;abstract;
  385. procedure a_op64_reg_loc(list : taasmoutput;op:TOpCG;size : tcgsize;reg : tregister64;const l : tlocation);virtual;abstract;
  386. procedure a_op64_loc_reg(list : taasmoutput;op:TOpCG;size : tcgsize;const l : tlocation;reg64 : tregister64);virtual;abstract;
  387. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);virtual;
  388. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);virtual;
  389. procedure a_op64_const_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);virtual;
  390. procedure a_op64_reg_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);virtual;
  391. procedure a_param64_reg(list : taasmoutput;reg64 : tregister64;const loc : TCGPara);virtual;abstract;
  392. procedure a_param64_const(list : taasmoutput;value : int64;const loc : TCGPara);virtual;abstract;
  393. procedure a_param64_ref(list : taasmoutput;const r : treference;const loc : TCGPara);virtual;abstract;
  394. procedure a_param64_loc(list : taasmoutput;const l : tlocation;const loc : TCGPara);virtual;abstract;
  395. {
  396. This routine tries to optimize the const_reg opcode, and should be
  397. called at the start of a_op64_const_reg. It returns the actual opcode
  398. to emit, and the constant value to emit. If this routine returns
  399. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  400. @param(op The opcode to emit, returns the opcode which must be emitted)
  401. @param(a The constant which should be emitted, returns the constant which must
  402. be emitted)
  403. @param(reg The register to emit the opcode with, returns the register with
  404. which the opcode will be emitted)
  405. }
  406. function optimize64_op_const_reg(list: taasmoutput; var op: topcg; var a : int64; var reg: tregister64): boolean;virtual;abstract;
  407. { override to catch 64bit rangechecks }
  408. procedure g_rangecheck64(list: taasmoutput; const l:tlocation; fromdef,todef: tdef);virtual;abstract;
  409. end;
  410. {$endif cpu64bit}
  411. var
  412. {# Main code generator class }
  413. cg : tcg;
  414. {$ifndef cpu64bit}
  415. {# Code generator class for all operations working with 64-Bit operands }
  416. cg64 : tcg64;
  417. {$endif cpu64bit}
  418. implementation
  419. uses
  420. globals,options,systems,
  421. verbose,defutil,paramgr,symsym,
  422. tgobj,cutils,procinfo;
  423. const
  424. { Please leave this here, this module should NOT use
  425. exprasmlist, the lists are always passed as arguments.
  426. Declaring it as string here results in an error when compiling (PFV) }
  427. exprasmlist = 'error';
  428. {*****************************************************************************
  429. basic functionallity
  430. ******************************************************************************}
  431. constructor tcg.create;
  432. begin
  433. end;
  434. {*****************************************************************************
  435. register allocation
  436. ******************************************************************************}
  437. procedure tcg.init_register_allocators;
  438. begin
  439. fillchar(rg,sizeof(rg),0);
  440. add_reg_instruction_hook:=@add_reg_instruction;
  441. end;
  442. procedure tcg.done_register_allocators;
  443. begin
  444. { Safety }
  445. fillchar(rg,sizeof(rg),0);
  446. add_reg_instruction_hook:=nil;
  447. end;
  448. {$ifdef flowgraph}
  449. procedure Tcg.init_flowgraph;
  450. begin
  451. aktflownode:=0;
  452. end;
  453. procedure Tcg.done_flowgraph;
  454. begin
  455. end;
  456. {$endif}
  457. function tcg.getintregister(list:Taasmoutput;size:Tcgsize):Tregister;
  458. begin
  459. if not assigned(rg[R_INTREGISTER]) then
  460. internalerror(200312122);
  461. result:=rg[R_INTREGISTER].getregister(list,cgsize2subreg(size));
  462. end;
  463. function tcg.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  464. begin
  465. if not assigned(rg[R_FPUREGISTER]) then
  466. internalerror(200312123);
  467. result:=rg[R_FPUREGISTER].getregister(list,cgsize2subreg(size));
  468. end;
  469. function tcg.getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;
  470. begin
  471. if not assigned(rg[R_MMREGISTER]) then
  472. internalerror(2003121214);
  473. result:=rg[R_MMREGISTER].getregister(list,cgsize2subreg(size));
  474. end;
  475. function tcg.getaddressregister(list:Taasmoutput):Tregister;
  476. begin
  477. if assigned(rg[R_ADDRESSREGISTER]) then
  478. result:=rg[R_ADDRESSREGISTER].getregister(list,R_SUBWHOLE)
  479. else
  480. begin
  481. if not assigned(rg[R_INTREGISTER]) then
  482. internalerror(200312121);
  483. result:=rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  484. end;
  485. end;
  486. function Tcg.makeregsize(list:Taasmoutput;reg:Tregister;size:Tcgsize):Tregister;
  487. var
  488. subreg:Tsubregister;
  489. begin
  490. subreg:=cgsize2subreg(size);
  491. result:=reg;
  492. setsubreg(result,subreg);
  493. { notify RA }
  494. if result<>reg then
  495. list.concat(tai_regalloc.resize(result));
  496. end;
  497. procedure tcg.getcpuregister(list:Taasmoutput;r:Tregister);
  498. begin
  499. if not assigned(rg[getregtype(r)]) then
  500. internalerror(200312125);
  501. rg[getregtype(r)].getcpuregister(list,r);
  502. end;
  503. procedure tcg.ungetcpuregister(list:Taasmoutput;r:Tregister);
  504. begin
  505. if not assigned(rg[getregtype(r)]) then
  506. internalerror(200312126);
  507. rg[getregtype(r)].ungetcpuregister(list,r);
  508. end;
  509. procedure tcg.alloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  510. begin
  511. if assigned(rg[rt]) then
  512. rg[rt].alloccpuregisters(list,r)
  513. else
  514. internalerror(200310092);
  515. end;
  516. procedure tcg.allocallcpuregisters(list:Taasmoutput);
  517. begin
  518. alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  519. {$ifndef i386}
  520. alloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  521. {$ifdef cpumm}
  522. alloccpuregisters(list,R_MMREGISTER,paramanager.get_volatile_registers_mm(pocall_default));
  523. {$endif cpumm}
  524. {$endif i386}
  525. end;
  526. procedure tcg.dealloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  527. begin
  528. if assigned(rg[rt]) then
  529. rg[rt].dealloccpuregisters(list,r)
  530. else
  531. internalerror(200310093);
  532. end;
  533. procedure tcg.deallocallcpuregisters(list:Taasmoutput);
  534. begin
  535. dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  536. {$ifndef i386}
  537. dealloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  538. {$ifdef cpumm}
  539. dealloccpuregisters(list,R_MMREGISTER,paramanager.get_volatile_registers_mm(pocall_default));
  540. {$endif cpumm}
  541. {$endif i386}
  542. end;
  543. function tcg.uses_registers(rt:Tregistertype):boolean;
  544. begin
  545. if assigned(rg[rt]) then
  546. result:=rg[rt].uses_registers
  547. else
  548. result:=false;
  549. end;
  550. procedure tcg.add_reg_instruction(instr:Tai;r:tregister);
  551. var
  552. rt : tregistertype;
  553. begin
  554. rt:=getregtype(r);
  555. { Only add it when a register allocator is configured.
  556. No IE can be generated, because the VMT is written
  557. without a valid rg[] }
  558. if assigned(rg[rt]) then
  559. rg[rt].add_reg_instruction(instr,r);
  560. end;
  561. procedure tcg.add_move_instruction(instr:Taicpu);
  562. var
  563. rt : tregistertype;
  564. begin
  565. rt:=getregtype(instr.oper[O_MOV_SOURCE]^.reg);
  566. if assigned(rg[rt]) then
  567. rg[rt].add_move_instruction(instr)
  568. else
  569. internalerror(200310095);
  570. end;
  571. procedure tcg.do_register_allocation(list:Taasmoutput;headertai:tai);
  572. var
  573. rt : tregistertype;
  574. begin
  575. for rt:=R_FPUREGISTER to R_SPECIALREGISTER do
  576. begin
  577. if assigned(rg[rt]) then
  578. rg[rt].do_register_allocation(list,headertai);
  579. end;
  580. { running the other register allocator passes could require addition int/addr. registers
  581. when spilling so run int/addr register allocation at the end }
  582. if assigned(rg[R_INTREGISTER]) then
  583. rg[R_INTREGISTER].do_register_allocation(list,headertai);
  584. if assigned(rg[R_ADDRESSREGISTER]) then
  585. rg[R_ADDRESSREGISTER].do_register_allocation(list,headertai);
  586. end;
  587. procedure tcg.a_reg_alloc(list : taasmoutput;r : tregister);
  588. begin
  589. list.concat(tai_regalloc.alloc(r,nil));
  590. end;
  591. procedure tcg.a_reg_dealloc(list : taasmoutput;r : tregister);
  592. begin
  593. list.concat(tai_regalloc.dealloc(r,nil));
  594. end;
  595. procedure tcg.a_reg_sync(list : taasmoutput;r : tregister);
  596. var
  597. instr : tai;
  598. begin
  599. instr:=tai_regalloc.sync(r);
  600. list.concat(instr);
  601. add_reg_instruction(instr,r);
  602. end;
  603. procedure tcg.a_label(list : taasmoutput;l : tasmlabel);
  604. begin
  605. list.concat(tai_label.create(l));
  606. end;
  607. {*****************************************************************************
  608. for better code generation these methods should be overridden
  609. ******************************************************************************}
  610. procedure tcg.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const cgpara : TCGPara);
  611. var
  612. ref : treference;
  613. begin
  614. cgpara.check_simple_location;
  615. case cgpara.location^.loc of
  616. LOC_REGISTER,LOC_CREGISTER:
  617. a_load_reg_reg(list,size,cgpara.location^.size,r,cgpara.location^.register);
  618. LOC_REFERENCE,LOC_CREFERENCE:
  619. begin
  620. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  621. a_load_reg_ref(list,size,cgpara.location^.size,r,ref);
  622. end
  623. else
  624. internalerror(2002071004);
  625. end;
  626. end;
  627. procedure tcg.a_param_const(list : taasmoutput;size : tcgsize;a : aint;const cgpara : TCGPara);
  628. var
  629. ref : treference;
  630. begin
  631. cgpara.check_simple_location;
  632. case cgpara.location^.loc of
  633. LOC_REGISTER,LOC_CREGISTER:
  634. a_load_const_reg(list,cgpara.location^.size,a,cgpara.location^.register);
  635. LOC_REFERENCE,LOC_CREFERENCE:
  636. begin
  637. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  638. a_load_const_ref(list,cgpara.location^.size,a,ref);
  639. end
  640. else
  641. internalerror(2002071004);
  642. end;
  643. end;
  644. procedure tcg.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const cgpara : TCGPara);
  645. var
  646. ref : treference;
  647. begin
  648. cgpara.check_simple_location;
  649. case cgpara.location^.loc of
  650. LOC_REGISTER,LOC_CREGISTER:
  651. a_load_ref_reg(list,size,cgpara.location^.size,r,cgpara.location^.register);
  652. LOC_REFERENCE,LOC_CREFERENCE:
  653. begin
  654. reference_reset(ref);
  655. ref.base:=cgpara.location^.reference.index;
  656. ref.offset:=cgpara.location^.reference.offset;
  657. { use concatcopy, because it can also be a float which fails when
  658. load_ref_ref is used }
  659. g_concatcopy(list,r,ref,tcgsize2size[size]);
  660. end
  661. else
  662. internalerror(2002071004);
  663. end;
  664. end;
  665. procedure tcg.a_param_loc(list : taasmoutput;const l:tlocation;const cgpara : TCGPara);
  666. begin
  667. case l.loc of
  668. LOC_REGISTER,
  669. LOC_CREGISTER :
  670. a_param_reg(list,l.size,l.register,cgpara);
  671. LOC_CONSTANT :
  672. a_param_const(list,l.size,l.value,cgpara);
  673. LOC_CREFERENCE,
  674. LOC_REFERENCE :
  675. a_param_ref(list,l.size,l.reference,cgpara);
  676. else
  677. internalerror(2002032211);
  678. end;
  679. end;
  680. procedure tcg.a_paramaddr_ref(list : taasmoutput;const r : treference;const cgpara : TCGPara);
  681. var
  682. hr : tregister;
  683. begin
  684. cgpara.check_simple_location;
  685. hr:=getaddressregister(list);
  686. a_loadaddr_ref_reg(list,r,hr);
  687. a_param_reg(list,OS_ADDR,hr,cgpara);
  688. end;
  689. {****************************************************************************
  690. some generic implementations
  691. ****************************************************************************}
  692. procedure tcg.a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
  693. var
  694. tmpreg: tregister;
  695. begin
  696. { verify if we have the same reference }
  697. if references_equal(sref,dref) then
  698. exit;
  699. tmpreg:=getintregister(list,tosize);
  700. a_load_ref_reg(list,fromsize,tosize,sref,tmpreg);
  701. a_load_reg_ref(list,tosize,tosize,tmpreg,dref);
  702. end;
  703. procedure tcg.a_load_const_ref(list : taasmoutput;size : tcgsize;a : aint;const ref : treference);
  704. var
  705. tmpreg: tregister;
  706. begin
  707. tmpreg:=getintregister(list,size);
  708. a_load_const_reg(list,size,a,tmpreg);
  709. a_load_reg_ref(list,size,size,tmpreg,ref);
  710. end;
  711. procedure tcg.a_load_const_loc(list : taasmoutput;a : aint;const loc: tlocation);
  712. begin
  713. case loc.loc of
  714. LOC_REFERENCE,LOC_CREFERENCE:
  715. a_load_const_ref(list,loc.size,a,loc.reference);
  716. LOC_REGISTER,LOC_CREGISTER:
  717. a_load_const_reg(list,loc.size,a,loc.register);
  718. else
  719. internalerror(200203272);
  720. end;
  721. end;
  722. procedure tcg.a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  723. begin
  724. case loc.loc of
  725. LOC_REFERENCE,LOC_CREFERENCE:
  726. a_load_reg_ref(list,fromsize,loc.size,reg,loc.reference);
  727. LOC_REGISTER,LOC_CREGISTER:
  728. a_load_reg_reg(list,fromsize,loc.size,reg,loc.register);
  729. else
  730. internalerror(200203271);
  731. end;
  732. end;
  733. procedure tcg.a_load_loc_reg(list : taasmoutput; tosize: tcgsize; const loc: tlocation; reg : tregister);
  734. begin
  735. case loc.loc of
  736. LOC_REFERENCE,LOC_CREFERENCE:
  737. a_load_ref_reg(list,loc.size,tosize,loc.reference,reg);
  738. LOC_REGISTER,LOC_CREGISTER:
  739. a_load_reg_reg(list,loc.size,tosize,loc.register,reg);
  740. LOC_CONSTANT:
  741. a_load_const_reg(list,tosize,loc.value,reg);
  742. else
  743. internalerror(200109092);
  744. end;
  745. end;
  746. procedure tcg.a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  747. begin
  748. case loc.loc of
  749. LOC_REFERENCE,LOC_CREFERENCE:
  750. a_load_ref_ref(list,loc.size,tosize,loc.reference,ref);
  751. LOC_REGISTER,LOC_CREGISTER:
  752. a_load_reg_ref(list,loc.size,tosize,loc.register,ref);
  753. LOC_CONSTANT:
  754. a_load_const_ref(list,tosize,loc.value,ref);
  755. else
  756. internalerror(200109302);
  757. end;
  758. end;
  759. function tcg.optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aint; var reg:tregister): boolean;
  760. var
  761. powerval : longint;
  762. begin
  763. optimize_op_const_reg := false;
  764. case op of
  765. { or with zero returns same result }
  766. OP_OR : if a = 0 then optimize_op_const_reg := true;
  767. { and with max returns same result }
  768. OP_AND : if (a = high(a)) then optimize_op_const_reg := true;
  769. { division by 1 returns result }
  770. OP_DIV :
  771. begin
  772. if a = 1 then
  773. optimize_op_const_reg := true
  774. else if ispowerof2(int64(a), powerval) then
  775. begin
  776. a := powerval;
  777. op:= OP_SHR;
  778. end;
  779. exit;
  780. end;
  781. OP_IDIV:
  782. begin
  783. if a = 1 then
  784. optimize_op_const_reg := true
  785. else if ispowerof2(int64(a), powerval) then
  786. begin
  787. a := powerval;
  788. op:= OP_SAR;
  789. end;
  790. exit;
  791. end;
  792. OP_MUL,OP_IMUL:
  793. begin
  794. if a = 1 then
  795. optimize_op_const_reg := true
  796. else if ispowerof2(int64(a), powerval) then
  797. begin
  798. a := powerval;
  799. op:= OP_SHL;
  800. end;
  801. exit;
  802. end;
  803. OP_SAR,OP_SHL,OP_SHR:
  804. begin
  805. if a = 0 then
  806. optimize_op_const_reg := true;
  807. exit;
  808. end;
  809. end;
  810. end;
  811. procedure tcg.a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  812. begin
  813. case loc.loc of
  814. LOC_REFERENCE, LOC_CREFERENCE:
  815. a_loadfpu_ref_reg(list,loc.size,loc.reference,reg);
  816. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  817. a_loadfpu_reg_reg(list,loc.size,loc.register,reg);
  818. else
  819. internalerror(200203301);
  820. end;
  821. end;
  822. procedure tcg.a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  823. begin
  824. case loc.loc of
  825. LOC_REFERENCE, LOC_CREFERENCE:
  826. a_loadfpu_reg_ref(list,size,reg,loc.reference);
  827. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  828. a_loadfpu_reg_reg(list,size,reg,loc.register);
  829. else
  830. internalerror(48991);
  831. end;
  832. end;
  833. procedure tcg.a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const cgpara : TCGPara);
  834. var
  835. ref : treference;
  836. begin
  837. case cgpara.location^.loc of
  838. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  839. begin
  840. cgpara.check_simple_location;
  841. a_loadfpu_reg_reg(list,size,r,cgpara.location^.register);
  842. end;
  843. LOC_REFERENCE,LOC_CREFERENCE:
  844. begin
  845. cgpara.check_simple_location;
  846. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  847. a_loadfpu_reg_ref(list,size,r,ref);
  848. end;
  849. LOC_REGISTER,LOC_CREGISTER:
  850. begin
  851. { paramfpu_ref does the check_simpe_location check here if necessary }
  852. tg.GetTemp(list,TCGSize2Size[size],tt_normal,ref);
  853. a_loadfpu_reg_ref(list,size,r,ref);
  854. a_paramfpu_ref(list,size,ref,cgpara);
  855. tg.Ungettemp(list,ref);
  856. end;
  857. else
  858. internalerror(2002071004);
  859. end;
  860. end;
  861. procedure tcg.a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const cgpara : TCGPara);
  862. var
  863. href : treference;
  864. begin
  865. cgpara.check_simple_location;
  866. case cgpara.location^.loc of
  867. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  868. a_loadfpu_ref_reg(list,size,ref,cgpara.location^.register);
  869. LOC_REFERENCE,LOC_CREFERENCE:
  870. begin
  871. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  872. { concatcopy should choose the best way to copy the data }
  873. g_concatcopy(list,ref,href,tcgsize2size[size]);
  874. end;
  875. else
  876. internalerror(200402201);
  877. end;
  878. end;
  879. procedure tcg.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
  880. var
  881. tmpreg : tregister;
  882. begin
  883. tmpreg:=getintregister(list,size);
  884. a_load_ref_reg(list,size,size,ref,tmpreg);
  885. a_op_const_reg(list,op,size,a,tmpreg);
  886. a_load_reg_ref(list,size,size,tmpreg,ref);
  887. end;
  888. procedure tcg.a_op_const_loc(list : taasmoutput; Op: TOpCG; a: aint; const loc: tlocation);
  889. begin
  890. case loc.loc of
  891. LOC_REGISTER, LOC_CREGISTER:
  892. a_op_const_reg(list,op,loc.size,a,loc.register);
  893. LOC_REFERENCE, LOC_CREFERENCE:
  894. a_op_const_ref(list,op,loc.size,a,loc.reference);
  895. else
  896. internalerror(200109061);
  897. end;
  898. end;
  899. procedure tcg.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  900. var
  901. tmpreg : tregister;
  902. begin
  903. tmpreg:=getintregister(list,size);
  904. a_load_ref_reg(list,size,size,ref,tmpreg);
  905. a_op_reg_reg(list,op,size,reg,tmpreg);
  906. a_load_reg_ref(list,size,size,tmpreg,ref);
  907. end;
  908. procedure tcg.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  909. var
  910. tmpreg: tregister;
  911. begin
  912. case op of
  913. OP_NOT,OP_NEG:
  914. { handle it as "load ref,reg; op reg" }
  915. begin
  916. a_load_ref_reg(list,size,size,ref,reg);
  917. a_op_reg_reg(list,op,size,reg,reg);
  918. end;
  919. else
  920. begin
  921. tmpreg:=getintregister(list,size);
  922. a_load_ref_reg(list,size,size,ref,tmpreg);
  923. a_op_reg_reg(list,op,size,tmpreg,reg);
  924. end;
  925. end;
  926. end;
  927. procedure tcg.a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  928. begin
  929. case loc.loc of
  930. LOC_REGISTER, LOC_CREGISTER:
  931. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  932. LOC_REFERENCE, LOC_CREFERENCE:
  933. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  934. else
  935. internalerror(200109061);
  936. end;
  937. end;
  938. procedure tcg.a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  939. var
  940. tmpreg: tregister;
  941. begin
  942. case loc.loc of
  943. LOC_REGISTER,LOC_CREGISTER:
  944. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  945. LOC_REFERENCE,LOC_CREFERENCE:
  946. begin
  947. tmpreg:=getintregister(list,loc.size);
  948. a_load_ref_reg(list,loc.size,loc.size,ref,tmpreg);
  949. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  950. end;
  951. else
  952. internalerror(200109061);
  953. end;
  954. end;
  955. procedure Tcg.a_op_const_reg_reg(list:Taasmoutput;op:Topcg;size:Tcgsize;
  956. a:aint;src,dst:Tregister);
  957. begin
  958. a_load_reg_reg(list,size,size,src,dst);
  959. a_op_const_reg(list,op,size,a,dst);
  960. end;
  961. procedure tcg.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  962. size: tcgsize; src1, src2, dst: tregister);
  963. var
  964. tmpreg: tregister;
  965. begin
  966. if (dst<>src1) then
  967. begin
  968. a_load_reg_reg(list,size,size,src2,dst);
  969. a_op_reg_reg(list,op,size,src1,dst);
  970. end
  971. else
  972. begin
  973. tmpreg:=getintregister(list,size);
  974. a_load_reg_reg(list,size,size,src2,tmpreg);
  975. a_op_reg_reg(list,op,size,src1,tmpreg);
  976. a_load_reg_reg(list,size,size,tmpreg,dst);
  977. end;
  978. end;
  979. procedure tcg.a_op_const_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation);
  980. begin
  981. a_op_const_reg_reg(list,op,size,a,src,dst);
  982. ovloc.loc:=LOC_VOID;
  983. end;
  984. procedure tcg.a_op_reg_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation);
  985. begin
  986. a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  987. ovloc.loc:=LOC_VOID;
  988. end;
  989. procedure tcg.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  990. l : tasmlabel);
  991. var
  992. tmpreg: tregister;
  993. begin
  994. tmpreg:=getintregister(list,size);
  995. a_load_ref_reg(list,size,size,ref,tmpreg);
  996. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  997. end;
  998. procedure tcg.a_cmp_const_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const loc : tlocation;
  999. l : tasmlabel);
  1000. begin
  1001. case loc.loc of
  1002. LOC_REGISTER,LOC_CREGISTER:
  1003. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1004. LOC_REFERENCE,LOC_CREFERENCE:
  1005. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1006. else
  1007. internalerror(200109061);
  1008. end;
  1009. end;
  1010. procedure tcg.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  1011. var
  1012. tmpreg: tregister;
  1013. begin
  1014. tmpreg:=getintregister(list,size);
  1015. a_load_ref_reg(list,size,size,ref,tmpreg);
  1016. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1017. end;
  1018. procedure tcg.a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; reg : tregister; const ref: treference; l : tasmlabel);
  1019. var
  1020. tmpreg: tregister;
  1021. begin
  1022. tmpreg:=getintregister(list,size);
  1023. a_load_ref_reg(list,size,size,ref,tmpreg);
  1024. a_cmp_reg_reg_label(list,size,cmp_op,reg,tmpreg,l);
  1025. end;
  1026. procedure tcg.a_cmp_reg_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; reg: tregister; const loc: tlocation; l : tasmlabel);
  1027. begin
  1028. a_cmp_loc_reg_label(list,size,swap_opcmp(cmp_op),loc,reg,l);
  1029. end;
  1030. procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  1031. begin
  1032. case loc.loc of
  1033. LOC_REGISTER,
  1034. LOC_CREGISTER:
  1035. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1036. LOC_REFERENCE,
  1037. LOC_CREFERENCE :
  1038. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1039. LOC_CONSTANT:
  1040. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1041. else
  1042. internalerror(200203231);
  1043. end;
  1044. end;
  1045. procedure tcg.a_cmp_ref_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  1046. l : tasmlabel);
  1047. var
  1048. tmpreg: tregister;
  1049. begin
  1050. case loc.loc of
  1051. LOC_REGISTER,LOC_CREGISTER:
  1052. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1053. LOC_REFERENCE,LOC_CREFERENCE:
  1054. begin
  1055. tmpreg:=getintregister(list,size);
  1056. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1057. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1058. end
  1059. else
  1060. internalerror(200109061);
  1061. end;
  1062. end;
  1063. procedure tcg.a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  1064. begin
  1065. case loc.loc of
  1066. LOC_MMREGISTER,LOC_CMMREGISTER:
  1067. a_loadmm_reg_reg(list,loc.size,size,loc.register,reg,shuffle);
  1068. LOC_REFERENCE,LOC_CREFERENCE:
  1069. a_loadmm_ref_reg(list,loc.size,size,loc.reference,reg,shuffle);
  1070. else
  1071. internalerror(200310121);
  1072. end;
  1073. end;
  1074. procedure tcg.a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  1075. begin
  1076. case loc.loc of
  1077. LOC_MMREGISTER,LOC_CMMREGISTER:
  1078. a_loadmm_reg_reg(list,size,loc.size,reg,loc.register,shuffle);
  1079. LOC_REFERENCE,LOC_CREFERENCE:
  1080. a_loadmm_reg_ref(list,size,loc.size,reg,loc.reference,shuffle);
  1081. else
  1082. internalerror(200310122);
  1083. end;
  1084. end;
  1085. procedure tcg.a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle);
  1086. var
  1087. href : treference;
  1088. begin
  1089. cgpara.check_simple_location;
  1090. case cgpara.location^.loc of
  1091. LOC_MMREGISTER,LOC_CMMREGISTER:
  1092. a_loadmm_reg_reg(list,size,cgpara.location^.size,reg,cgpara.location^.register,shuffle);
  1093. LOC_REFERENCE,LOC_CREFERENCE:
  1094. begin
  1095. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  1096. a_loadmm_reg_ref(list,size,cgpara.location^.size,reg,href,shuffle);
  1097. end
  1098. else
  1099. internalerror(200310123);
  1100. end;
  1101. end;
  1102. procedure tcg.a_parammm_ref(list: taasmoutput; size: tcgsize;const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle);
  1103. var
  1104. hr : tregister;
  1105. hs : tmmshuffle;
  1106. begin
  1107. cgpara.check_simple_location;
  1108. hr:=getmmregister(list,cgpara.location^.size);
  1109. a_loadmm_ref_reg(list,size,cgpara.location^.size,ref,hr,shuffle);
  1110. if realshuffle(shuffle) then
  1111. begin
  1112. hs:=shuffle^;
  1113. removeshuffles(hs);
  1114. a_parammm_reg(list,cgpara.location^.size,hr,cgpara,@hs);
  1115. end
  1116. else
  1117. a_parammm_reg(list,cgpara.location^.size,hr,cgpara,shuffle);
  1118. end;
  1119. procedure tcg.a_parammm_loc(list: taasmoutput;const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle);
  1120. begin
  1121. case loc.loc of
  1122. LOC_MMREGISTER,LOC_CMMREGISTER:
  1123. a_parammm_reg(list,loc.size,loc.register,cgpara,shuffle);
  1124. LOC_REFERENCE,LOC_CREFERENCE:
  1125. a_parammm_ref(list,loc.size,loc.reference,cgpara,shuffle);
  1126. else
  1127. internalerror(200310123);
  1128. end;
  1129. end;
  1130. procedure tcg.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  1131. var
  1132. hr : tregister;
  1133. hs : tmmshuffle;
  1134. begin
  1135. hr:=getmmregister(list,size);
  1136. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1137. if realshuffle(shuffle) then
  1138. begin
  1139. hs:=shuffle^;
  1140. removeshuffles(hs);
  1141. a_opmm_reg_reg(list,op,size,hr,reg,@hs);
  1142. end
  1143. else
  1144. a_opmm_reg_reg(list,op,size,hr,reg,shuffle);
  1145. end;
  1146. procedure tcg.a_opmm_reg_ref(list: taasmoutput; Op: TOpCG; size : tcgsize;reg: tregister; const ref: treference; shuffle : pmmshuffle);
  1147. var
  1148. hr : tregister;
  1149. hs : tmmshuffle;
  1150. begin
  1151. hr:=getmmregister(list,size);
  1152. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1153. if realshuffle(shuffle) then
  1154. begin
  1155. hs:=shuffle^;
  1156. removeshuffles(hs);
  1157. a_opmm_reg_reg(list,op,size,reg,hr,@hs);
  1158. a_loadmm_reg_ref(list,size,size,hr,ref,@hs);
  1159. end
  1160. else
  1161. begin
  1162. a_opmm_reg_reg(list,op,size,reg,hr,shuffle);
  1163. a_loadmm_reg_ref(list,size,size,hr,ref,shuffle);
  1164. end;
  1165. end;
  1166. procedure tcg.a_opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle);
  1167. begin
  1168. case loc.loc of
  1169. LOC_CMMREGISTER,LOC_MMREGISTER:
  1170. a_opmm_reg_reg(list,op,size,loc.register,reg,shuffle);
  1171. LOC_CREFERENCE,LOC_REFERENCE:
  1172. a_opmm_ref_reg(list,op,size,loc.reference,reg,shuffle);
  1173. else
  1174. internalerror(200312232);
  1175. end;
  1176. end;
  1177. procedure tcg.g_concatcopy_unaligned(list : taasmoutput;const source,dest : treference;len : aint);
  1178. begin
  1179. g_concatcopy(list,source,dest,len);
  1180. end;
  1181. procedure tcg.g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte);
  1182. var
  1183. cgpara1,cgpara2,cgpara3 : TCGPara;
  1184. begin
  1185. cgpara1.init;
  1186. cgpara2.init;
  1187. cgpara3.init;
  1188. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1189. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1190. paramanager.getintparaloc(pocall_default,3,cgpara3);
  1191. paramanager.allocparaloc(list,cgpara3);
  1192. a_paramaddr_ref(list,dest,cgpara3);
  1193. paramanager.allocparaloc(list,cgpara2);
  1194. a_paramaddr_ref(list,source,cgpara2);
  1195. paramanager.allocparaloc(list,cgpara1);
  1196. a_param_const(list,OS_INT,len,cgpara1);
  1197. paramanager.freeparaloc(list,cgpara3);
  1198. paramanager.freeparaloc(list,cgpara2);
  1199. paramanager.freeparaloc(list,cgpara1);
  1200. allocallcpuregisters(list);
  1201. a_call_name(list,'FPC_SHORTSTR_ASSIGN');
  1202. deallocallcpuregisters(list);
  1203. cgpara3.done;
  1204. cgpara2.done;
  1205. cgpara1.done;
  1206. end;
  1207. procedure tcg.g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  1208. var
  1209. href : treference;
  1210. incrfunc : string;
  1211. cgpara1,cgpara2 : TCGPara;
  1212. begin
  1213. cgpara1.init;
  1214. cgpara2.init;
  1215. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1216. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1217. if is_interfacecom(t) then
  1218. incrfunc:='FPC_INTF_INCR_REF'
  1219. else if is_ansistring(t) then
  1220. incrfunc:='FPC_ANSISTR_INCR_REF'
  1221. else if is_widestring(t) then
  1222. incrfunc:='FPC_WIDESTR_INCR_REF'
  1223. else if is_dynamic_array(t) then
  1224. incrfunc:='FPC_DYNARRAY_INCR_REF'
  1225. else
  1226. incrfunc:='';
  1227. { call the special incr function or the generic addref }
  1228. if incrfunc<>'' then
  1229. begin
  1230. paramanager.allocparaloc(list,cgpara1);
  1231. { these functions get the pointer by value }
  1232. a_param_ref(list,OS_ADDR,ref,cgpara1);
  1233. paramanager.freeparaloc(list,cgpara1);
  1234. allocallcpuregisters(list);
  1235. a_call_name(list,incrfunc);
  1236. deallocallcpuregisters(list);
  1237. end
  1238. else
  1239. begin
  1240. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1241. paramanager.allocparaloc(list,cgpara2);
  1242. a_paramaddr_ref(list,href,cgpara2);
  1243. paramanager.allocparaloc(list,cgpara1);
  1244. a_paramaddr_ref(list,ref,cgpara1);
  1245. paramanager.freeparaloc(list,cgpara1);
  1246. paramanager.freeparaloc(list,cgpara2);
  1247. allocallcpuregisters(list);
  1248. a_call_name(list,'FPC_ADDREF');
  1249. deallocallcpuregisters(list);
  1250. end;
  1251. cgpara2.done;
  1252. cgpara1.done;
  1253. end;
  1254. procedure tcg.g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  1255. var
  1256. href : treference;
  1257. decrfunc : string;
  1258. needrtti : boolean;
  1259. cgpara1,cgpara2 : TCGPara;
  1260. tempreg1,tempreg2 : TRegister;
  1261. begin
  1262. cgpara1.init;
  1263. cgpara2.init;
  1264. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1265. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1266. needrtti:=false;
  1267. if is_interfacecom(t) then
  1268. decrfunc:='FPC_INTF_DECR_REF'
  1269. else if is_ansistring(t) then
  1270. decrfunc:='FPC_ANSISTR_DECR_REF'
  1271. else if is_widestring(t) then
  1272. decrfunc:='FPC_WIDESTR_DECR_REF'
  1273. else if is_dynamic_array(t) then
  1274. begin
  1275. decrfunc:='FPC_DYNARRAY_DECR_REF';
  1276. needrtti:=true;
  1277. end
  1278. else
  1279. decrfunc:='';
  1280. { call the special decr function or the generic decref }
  1281. if decrfunc<>'' then
  1282. begin
  1283. if needrtti then
  1284. begin
  1285. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1286. tempreg2:=getaddressregister(list);
  1287. a_loadaddr_ref_reg(list,href,tempreg2);
  1288. end;
  1289. tempreg1:=getaddressregister(list);
  1290. a_loadaddr_ref_reg(list,ref,tempreg1);
  1291. if needrtti then
  1292. begin
  1293. paramanager.allocparaloc(list,cgpara2);
  1294. a_param_reg(list,OS_ADDR,tempreg2,cgpara2);
  1295. paramanager.freeparaloc(list,cgpara2);
  1296. end;
  1297. paramanager.allocparaloc(list,cgpara1);
  1298. a_param_reg(list,OS_ADDR,tempreg1,cgpara1);
  1299. paramanager.freeparaloc(list,cgpara1);
  1300. allocallcpuregisters(list);
  1301. a_call_name(list,decrfunc);
  1302. deallocallcpuregisters(list);
  1303. end
  1304. else
  1305. begin
  1306. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1307. paramanager.allocparaloc(list,cgpara2);
  1308. a_paramaddr_ref(list,href,cgpara2);
  1309. paramanager.allocparaloc(list,cgpara1);
  1310. a_paramaddr_ref(list,ref,cgpara1);
  1311. paramanager.freeparaloc(list,cgpara1);
  1312. paramanager.freeparaloc(list,cgpara2);
  1313. allocallcpuregisters(list);
  1314. a_call_name(list,'FPC_DECREF');
  1315. deallocallcpuregisters(list);
  1316. end;
  1317. cgpara2.done;
  1318. cgpara1.done;
  1319. end;
  1320. procedure tcg.g_initialize(list : taasmoutput;t : tdef;const ref : treference);
  1321. var
  1322. href : treference;
  1323. cgpara1,cgpara2 : TCGPara;
  1324. begin
  1325. cgpara1.init;
  1326. cgpara2.init;
  1327. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1328. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1329. if is_ansistring(t) or
  1330. is_widestring(t) or
  1331. is_interfacecom(t) or
  1332. is_dynamic_array(t) then
  1333. a_load_const_ref(list,OS_ADDR,0,ref)
  1334. else
  1335. begin
  1336. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1337. paramanager.allocparaloc(list,cgpara2);
  1338. a_paramaddr_ref(list,href,cgpara2);
  1339. paramanager.allocparaloc(list,cgpara1);
  1340. a_paramaddr_ref(list,ref,cgpara1);
  1341. paramanager.freeparaloc(list,cgpara1);
  1342. paramanager.freeparaloc(list,cgpara2);
  1343. allocallcpuregisters(list);
  1344. a_call_name(list,'FPC_INITIALIZE');
  1345. deallocallcpuregisters(list);
  1346. end;
  1347. cgpara1.done;
  1348. cgpara2.done;
  1349. end;
  1350. procedure tcg.g_finalize(list : taasmoutput;t : tdef;const ref : treference);
  1351. var
  1352. href : treference;
  1353. cgpara1,cgpara2 : TCGPara;
  1354. begin
  1355. cgpara1.init;
  1356. cgpara2.init;
  1357. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1358. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1359. if is_ansistring(t) or
  1360. is_widestring(t) or
  1361. is_interfacecom(t) then
  1362. begin
  1363. g_decrrefcount(list,t,ref);
  1364. a_load_const_ref(list,OS_ADDR,0,ref);
  1365. end
  1366. else
  1367. begin
  1368. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1369. paramanager.allocparaloc(list,cgpara2);
  1370. a_paramaddr_ref(list,href,cgpara2);
  1371. paramanager.allocparaloc(list,cgpara1);
  1372. a_paramaddr_ref(list,ref,cgpara1);
  1373. paramanager.freeparaloc(list,cgpara1);
  1374. paramanager.freeparaloc(list,cgpara2);
  1375. allocallcpuregisters(list);
  1376. a_call_name(list,'FPC_FINALIZE');
  1377. deallocallcpuregisters(list);
  1378. end;
  1379. cgpara1.done;
  1380. cgpara2.done;
  1381. end;
  1382. procedure tcg.g_rangecheck(list: taasmoutput; const l:tlocation;fromdef,todef: tdef);
  1383. { generate range checking code for the value at location p. The type }
  1384. { type used is checked against todefs ranges. fromdef (p.resulttype.def) }
  1385. { is the original type used at that location. When both defs are equal }
  1386. { the check is also insert (needed for succ,pref,inc,dec) }
  1387. const
  1388. aintmax=high(aint);
  1389. var
  1390. neglabel : tasmlabel;
  1391. hreg : tregister;
  1392. lto,hto,
  1393. lfrom,hfrom : TConstExprInt;
  1394. from_signed: boolean;
  1395. begin
  1396. { range checking on and range checkable value? }
  1397. if not(cs_check_range in aktlocalswitches) or
  1398. not(fromdef.deftype in [orddef,enumdef,arraydef]) then
  1399. exit;
  1400. {$ifndef cpu64bit}
  1401. { handle 64bit rangechecks separate for 32bit processors }
  1402. if is_64bit(fromdef) or is_64bit(todef) then
  1403. begin
  1404. cg64.g_rangecheck64(list,l,fromdef,todef);
  1405. exit;
  1406. end;
  1407. {$endif cpu64bit}
  1408. { only check when assigning to scalar, subranges are different, }
  1409. { when todef=fromdef then the check is always generated }
  1410. getrange(fromdef,lfrom,hfrom);
  1411. getrange(todef,lto,hto);
  1412. from_signed := is_signed(fromdef);
  1413. { no range check if from and to are equal and are both longint/dword }
  1414. { (if we have a 32bit processor) or int64/qword, since such }
  1415. { operations can at most cause overflows (JM) }
  1416. { Note that these checks are mostly processor independent, they only }
  1417. { have to be changed once we introduce 64bit subrange types }
  1418. {$ifdef cpu64bit}
  1419. if (fromdef = todef) and
  1420. (fromdef.deftype=orddef) and
  1421. (((((torddef(fromdef).typ = s64bit) and
  1422. (lfrom = low(int64)) and
  1423. (hfrom = high(int64))) or
  1424. ((torddef(fromdef).typ = u64bit) and
  1425. (lfrom = low(qword)) and
  1426. (hfrom = high(qword)))))) then
  1427. exit;
  1428. {$else cpu64bit}
  1429. if (fromdef = todef) and
  1430. (fromdef.deftype=orddef) and
  1431. (((((torddef(fromdef).typ = s32bit) and
  1432. (lfrom = low(longint)) and
  1433. (hfrom = high(longint))) or
  1434. ((torddef(fromdef).typ = u32bit) and
  1435. (lfrom = low(cardinal)) and
  1436. (hfrom = high(cardinal)))))) then
  1437. exit;
  1438. {$endif cpu64bit}
  1439. { if the from-range falls completely in the to-range, no check }
  1440. { is necessary. Don't do this conversion for the largest unsigned type }
  1441. if (todef<>fromdef) and
  1442. (from_signed or (hfrom>=0)) and
  1443. (lto<=lfrom) and (hto>=hfrom) then
  1444. exit;
  1445. { generate the rangecheck code for the def where we are going to }
  1446. { store the result }
  1447. { use the trick that }
  1448. { a <= x <= b <=> 0 <= x-a <= b-a <=> unsigned(x-a) <= unsigned(b-a) }
  1449. { To be able to do that, we have to make sure however that either }
  1450. { fromdef and todef are both signed or unsigned, or that we leave }
  1451. { the parts < 0 and > maxlongint out }
  1452. { is_signed now also works for arrays (it checks the rangetype) (JM) }
  1453. if from_signed xor is_signed(todef) then
  1454. begin
  1455. if from_signed then
  1456. { from is signed, to is unsigned }
  1457. begin
  1458. { if high(from) < 0 -> always range error }
  1459. if (hfrom < 0) or
  1460. { if low(to) > maxlongint also range error }
  1461. (lto > aintmax) then
  1462. begin
  1463. a_call_name(list,'FPC_RANGEERROR');
  1464. exit
  1465. end;
  1466. { from is signed and to is unsigned -> when looking at to }
  1467. { as an signed value, it must be < maxaint (otherwise }
  1468. { it will become negative, which is invalid since "to" is unsigned) }
  1469. if hto > aintmax then
  1470. hto := aintmax;
  1471. end
  1472. else
  1473. { from is unsigned, to is signed }
  1474. begin
  1475. if (lfrom > aintmax) or
  1476. (hto < 0) then
  1477. begin
  1478. a_call_name(list,'FPC_RANGEERROR');
  1479. exit
  1480. end;
  1481. { from is unsigned and to is signed -> when looking at to }
  1482. { as an unsigned value, it must be >= 0 (since negative }
  1483. { values are the same as values > maxlongint) }
  1484. if lto < 0 then
  1485. lto := 0;
  1486. end;
  1487. end;
  1488. hreg:=getintregister(list,OS_INT);
  1489. a_load_loc_reg(list,OS_INT,l,hreg);
  1490. a_op_const_reg(list,OP_SUB,OS_INT,aint(lto),hreg);
  1491. objectlibrary.getjumplabel(neglabel);
  1492. {
  1493. if from_signed then
  1494. a_cmp_const_reg_label(list,OS_INT,OC_GTE,aint(hto-lto),hreg,neglabel)
  1495. else
  1496. }
  1497. {$ifdef cpu64bit}
  1498. if qword(hto-lto)>qword(aintmax) then
  1499. a_cmp_const_reg_label(list,OS_INT,OC_BE,aintmax,hreg,neglabel)
  1500. else
  1501. {$endif cpu64bit}
  1502. a_cmp_const_reg_label(list,OS_INT,OC_BE,aint(hto-lto),hreg,neglabel);
  1503. a_call_name(list,'FPC_RANGEERROR');
  1504. a_label(list,neglabel);
  1505. end;
  1506. procedure tcg.g_overflowCheck_loc(List:TAasmOutput;const Loc:TLocation;def:TDef;ovloc : tlocation);
  1507. begin
  1508. g_overflowCheck(list,loc,def);
  1509. end;
  1510. procedure tcg.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference);
  1511. var
  1512. tmpreg : tregister;
  1513. begin
  1514. tmpreg:=getintregister(list,size);
  1515. g_flags2reg(list,size,f,tmpreg);
  1516. a_load_reg_ref(list,size,size,tmpreg,ref);
  1517. end;
  1518. procedure tcg.g_maybe_testself(list : taasmoutput;reg:tregister);
  1519. var
  1520. OKLabel : tasmlabel;
  1521. cgpara1 : TCGPara;
  1522. begin
  1523. if (cs_check_object in aktlocalswitches) or
  1524. (cs_check_range in aktlocalswitches) then
  1525. begin
  1526. objectlibrary.getjumplabel(oklabel);
  1527. a_cmp_const_reg_label(list,OS_ADDR,OC_NE,0,reg,oklabel);
  1528. cgpara1.init;
  1529. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1530. paramanager.allocparaloc(list,cgpara1);
  1531. a_param_const(list,OS_INT,210,cgpara1);
  1532. paramanager.freeparaloc(list,cgpara1);
  1533. a_call_name(list,'FPC_HANDLEERROR');
  1534. a_label(list,oklabel);
  1535. cgpara1.done;
  1536. end;
  1537. end;
  1538. procedure tcg.g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  1539. var
  1540. hrefvmt : treference;
  1541. cgpara1,cgpara2 : TCGPara;
  1542. begin
  1543. cgpara1.init;
  1544. cgpara2.init;
  1545. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1546. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1547. if (cs_check_object in aktlocalswitches) then
  1548. begin
  1549. reference_reset_symbol(hrefvmt,objectlibrary.newasmsymbol(objdef.vmt_mangledname,AB_EXTERNAL,AT_DATA),0);
  1550. paramanager.allocparaloc(list,cgpara2);
  1551. a_paramaddr_ref(list,hrefvmt,cgpara2);
  1552. paramanager.allocparaloc(list,cgpara1);
  1553. a_param_reg(list,OS_ADDR,reg,cgpara1);
  1554. paramanager.freeparaloc(list,cgpara1);
  1555. paramanager.freeparaloc(list,cgpara2);
  1556. allocallcpuregisters(list);
  1557. a_call_name(list,'FPC_CHECK_OBJECT_EXT');
  1558. deallocallcpuregisters(list);
  1559. end
  1560. else
  1561. if (cs_check_range in aktlocalswitches) then
  1562. begin
  1563. paramanager.allocparaloc(list,cgpara1);
  1564. a_param_reg(list,OS_ADDR,reg,cgpara1);
  1565. paramanager.freeparaloc(list,cgpara1);
  1566. allocallcpuregisters(list);
  1567. a_call_name(list,'FPC_CHECK_OBJECT');
  1568. deallocallcpuregisters(list);
  1569. end;
  1570. cgpara1.done;
  1571. cgpara2.done;
  1572. end;
  1573. {*****************************************************************************
  1574. Entry/Exit Code Functions
  1575. *****************************************************************************}
  1576. procedure tcg.g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;const lenloc:tlocation;elesize:aint;destreg:tregister);
  1577. var
  1578. sizereg,sourcereg,lenreg : tregister;
  1579. cgpara1,cgpara2,cgpara3 : TCGPara;
  1580. begin
  1581. { because some abis don't support dynamic stack allocation properly
  1582. open array value parameters are copied onto the heap
  1583. }
  1584. { calculate necessary memory }
  1585. { read/write operations on one register make the life of the register allocator hard }
  1586. if not(lenloc.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  1587. begin
  1588. lenreg:=getintregister(list,OS_INT);
  1589. a_load_loc_reg(list,OS_INT,lenloc,lenreg);
  1590. end
  1591. else
  1592. lenreg:=lenloc.register;
  1593. sizereg:=getintregister(list,OS_INT);
  1594. a_op_const_reg_reg(list,OP_ADD,OS_INT,1,lenreg,sizereg);
  1595. a_op_const_reg(list,OP_IMUL,OS_INT,elesize,sizereg);
  1596. { load source }
  1597. sourcereg:=getaddressregister(list);
  1598. a_loadaddr_ref_reg(list,ref,sourcereg);
  1599. { do getmem call }
  1600. cgpara1.init;
  1601. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1602. paramanager.allocparaloc(list,cgpara1);
  1603. a_param_reg(list,OS_INT,sizereg,cgpara1);
  1604. paramanager.freeparaloc(list,cgpara1);
  1605. allocallcpuregisters(list);
  1606. a_call_name(list,'FPC_GETMEM');
  1607. deallocallcpuregisters(list);
  1608. cgpara1.done;
  1609. { return the new address }
  1610. a_load_reg_reg(list,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,destreg);
  1611. { do move call }
  1612. cgpara1.init;
  1613. cgpara2.init;
  1614. cgpara3.init;
  1615. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1616. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1617. paramanager.getintparaloc(pocall_default,3,cgpara3);
  1618. { load size }
  1619. paramanager.allocparaloc(list,cgpara3);
  1620. a_param_reg(list,OS_INT,sizereg,cgpara3);
  1621. { load destination }
  1622. paramanager.allocparaloc(list,cgpara2);
  1623. a_param_reg(list,OS_ADDR,destreg,cgpara2);
  1624. { load source }
  1625. paramanager.allocparaloc(list,cgpara1);
  1626. a_param_reg(list,OS_ADDR,sourcereg,cgpara1);
  1627. paramanager.freeparaloc(list,cgpara3);
  1628. paramanager.freeparaloc(list,cgpara2);
  1629. paramanager.freeparaloc(list,cgpara1);
  1630. allocallcpuregisters(list);
  1631. a_call_name(list,'FPC_MOVE');
  1632. deallocallcpuregisters(list);
  1633. cgpara3.done;
  1634. cgpara2.done;
  1635. cgpara1.done;
  1636. end;
  1637. procedure tcg.g_releasevaluepara_openarray(list : taasmoutput;const l:tlocation);
  1638. var
  1639. cgpara1 : TCGPara;
  1640. begin
  1641. { do move call }
  1642. cgpara1.init;
  1643. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1644. { load source }
  1645. paramanager.allocparaloc(list,cgpara1);
  1646. a_param_loc(list,l,cgpara1);
  1647. paramanager.freeparaloc(list,cgpara1);
  1648. allocallcpuregisters(list);
  1649. a_call_name(list,'FPC_FREEMEM');
  1650. deallocallcpuregisters(list);
  1651. cgpara1.done;
  1652. end;
  1653. procedure tcg.g_save_standard_registers(list:Taasmoutput);
  1654. var
  1655. href : treference;
  1656. size : longint;
  1657. r : integer;
  1658. begin
  1659. { Get temp }
  1660. size:=0;
  1661. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1662. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1663. inc(size,sizeof(aint));
  1664. if size>0 then
  1665. begin
  1666. tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
  1667. { Copy registers to temp }
  1668. href:=current_procinfo.save_regs_ref;
  1669. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1670. begin
  1671. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1672. begin
  1673. a_load_reg_ref(list,OS_ADDR,OS_ADDR,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE),href);
  1674. inc(href.offset,sizeof(aint));
  1675. end;
  1676. include(rg[R_INTREGISTER].preserved_by_proc,saved_standard_registers[r]);
  1677. end;
  1678. end;
  1679. end;
  1680. procedure tcg.g_restore_standard_registers(list:Taasmoutput);
  1681. var
  1682. href : treference;
  1683. r : integer;
  1684. hreg : tregister;
  1685. begin
  1686. { Copy registers from temp }
  1687. href:=current_procinfo.save_regs_ref;
  1688. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1689. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1690. begin
  1691. hreg:=newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE);
  1692. { Allocate register so the optimizer does remove the load }
  1693. a_reg_alloc(list,hreg);
  1694. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,hreg);
  1695. inc(href.offset,sizeof(aint));
  1696. end;
  1697. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1698. end;
  1699. procedure tcg.g_profilecode(list : taasmoutput);
  1700. begin
  1701. end;
  1702. procedure tcg.g_exception_reason_save(list : taasmoutput; const href : treference);
  1703. begin
  1704. a_load_reg_ref(list, OS_INT, OS_INT, NR_FUNCTION_RESULT_REG, href);
  1705. end;
  1706. procedure tcg.g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aint);
  1707. begin
  1708. a_load_const_ref(list, OS_INT, a, href);
  1709. end;
  1710. procedure tcg.g_exception_reason_load(list : taasmoutput; const href : treference);
  1711. begin
  1712. a_load_ref_reg(list, OS_INT, OS_INT, href, NR_FUNCTION_RESULT_REG);
  1713. end;
  1714. procedure tcg.g_adjust_self_value(list:taasmoutput;procdef: tprocdef;ioffset: aint);
  1715. var
  1716. hsym : tsym;
  1717. href : treference;
  1718. paraloc : tcgparalocation;
  1719. begin
  1720. { calculate the parameter info for the procdef }
  1721. if not procdef.has_paraloc_info then
  1722. begin
  1723. procdef.requiredargarea:=paramanager.create_paraloc_info(procdef,callerside);
  1724. procdef.has_paraloc_info:=true;
  1725. end;
  1726. hsym:=tsym(procdef.parast.search('self'));
  1727. if not(assigned(hsym) and
  1728. (hsym.typ=paravarsym)) then
  1729. internalerror(200305251);
  1730. paraloc:=tparavarsym(hsym).paraloc[callerside].location^;
  1731. case paraloc.loc of
  1732. LOC_REGISTER:
  1733. cg.a_op_const_reg(list,OP_SUB,paraloc.size,ioffset,paraloc.register);
  1734. LOC_REFERENCE:
  1735. begin
  1736. { offset in the wrapper needs to be adjusted for the stored
  1737. return address }
  1738. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset+sizeof(aint));
  1739. cg.a_op_const_ref(list,OP_SUB,paraloc.size,ioffset,href);
  1740. end
  1741. else
  1742. internalerror(200309189);
  1743. end;
  1744. end;
  1745. procedure tcg.a_call_name_static(list : taasmoutput;const s : string);
  1746. begin
  1747. a_call_name(list,s);
  1748. end;
  1749. {*****************************************************************************
  1750. TCG64
  1751. *****************************************************************************}
  1752. {$ifndef cpu64bit}
  1753. procedure tcg64.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64; regsrc,regdst : tregister64);
  1754. begin
  1755. a_load64_reg_reg(list,regsrc,regdst);
  1756. a_op64_const_reg(list,op,size,value,regdst);
  1757. end;
  1758. procedure tcg64.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1759. var
  1760. tmpreg64 : tregister64;
  1761. begin
  1762. { when src1=dst then we need to first create a temp to prevent
  1763. overwriting src1 with src2 }
  1764. if (regsrc1.reghi=regdst.reghi) or
  1765. (regsrc1.reglo=regdst.reghi) or
  1766. (regsrc1.reghi=regdst.reglo) or
  1767. (regsrc1.reglo=regdst.reglo) then
  1768. begin
  1769. tmpreg64.reglo:=cg.getintregister(list,OS_32);
  1770. tmpreg64.reghi:=cg.getintregister(list,OS_32);
  1771. a_load64_reg_reg(list,regsrc2,tmpreg64);
  1772. a_op64_reg_reg(list,op,size,regsrc1,tmpreg64);
  1773. a_load64_reg_reg(list,tmpreg64,regdst);
  1774. end
  1775. else
  1776. begin
  1777. a_load64_reg_reg(list,regsrc2,regdst);
  1778. a_op64_reg_reg(list,op,size,regsrc1,regdst);
  1779. end;
  1780. end;
  1781. procedure tcg64.a_op64_const_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1782. begin
  1783. a_op64_const_reg_reg(list,op,size,value,regsrc,regdst);
  1784. ovloc.loc:=LOC_VOID;
  1785. end;
  1786. procedure tcg64.a_op64_reg_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1787. begin
  1788. a_op64_reg_reg_reg(list,op,size,regsrc1,regsrc2,regdst);
  1789. ovloc.loc:=LOC_VOID;
  1790. end;
  1791. {$endif cpu64bit}
  1792. initialization
  1793. ;
  1794. finalization
  1795. cg.free;
  1796. {$ifndef cpu64bit}
  1797. cg64.free;
  1798. {$endif cpu64bit}
  1799. end.