cgobj.pas 83 KB

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