cgobj.pas 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090
  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. case cgpara.location^.loc of
  833. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  834. begin
  835. cgpara.check_simple_location;
  836. a_loadfpu_reg_reg(list,size,r,cgpara.location^.register);
  837. end;
  838. LOC_REFERENCE,LOC_CREFERENCE:
  839. begin
  840. cgpara.check_simple_location;
  841. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  842. a_loadfpu_reg_ref(list,size,r,ref);
  843. end;
  844. LOC_REGISTER,LOC_CREGISTER:
  845. begin
  846. { paramfpu_ref does the check_simpe_location check here if necessary }
  847. tg.GetTemp(list,TCGSize2Size[size],tt_normal,ref);
  848. a_loadfpu_reg_ref(list,size,r,ref);
  849. a_paramfpu_ref(list,size,ref,cgpara);
  850. tg.Ungettemp(list,ref);
  851. end;
  852. else
  853. internalerror(2002071004);
  854. end;
  855. end;
  856. procedure tcg.a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const cgpara : TCGPara);
  857. var
  858. href : treference;
  859. begin
  860. cgpara.check_simple_location;
  861. case cgpara.location^.loc of
  862. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  863. a_loadfpu_ref_reg(list,size,ref,cgpara.location^.register);
  864. LOC_REFERENCE,LOC_CREFERENCE:
  865. begin
  866. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  867. { concatcopy should choose the best way to copy the data }
  868. g_concatcopy(list,ref,href,tcgsize2size[size]);
  869. end;
  870. else
  871. internalerror(200402201);
  872. end;
  873. end;
  874. procedure tcg.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
  875. var
  876. tmpreg : tregister;
  877. begin
  878. tmpreg:=getintregister(list,size);
  879. a_load_ref_reg(list,size,size,ref,tmpreg);
  880. a_op_const_reg(list,op,size,a,tmpreg);
  881. a_load_reg_ref(list,size,size,tmpreg,ref);
  882. end;
  883. procedure tcg.a_op_const_loc(list : taasmoutput; Op: TOpCG; a: aint; const loc: tlocation);
  884. begin
  885. case loc.loc of
  886. LOC_REGISTER, LOC_CREGISTER:
  887. a_op_const_reg(list,op,loc.size,a,loc.register);
  888. LOC_REFERENCE, LOC_CREFERENCE:
  889. a_op_const_ref(list,op,loc.size,a,loc.reference);
  890. else
  891. internalerror(200109061);
  892. end;
  893. end;
  894. procedure tcg.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  895. var
  896. tmpreg : tregister;
  897. begin
  898. tmpreg:=getintregister(list,size);
  899. a_load_ref_reg(list,size,size,ref,tmpreg);
  900. a_op_reg_reg(list,op,size,reg,tmpreg);
  901. a_load_reg_ref(list,size,size,tmpreg,ref);
  902. end;
  903. procedure tcg.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  904. var
  905. tmpreg: tregister;
  906. begin
  907. case op of
  908. OP_NOT,OP_NEG:
  909. { handle it as "load ref,reg; op reg" }
  910. begin
  911. a_load_ref_reg(list,size,size,ref,reg);
  912. a_op_reg_reg(list,op,size,reg,reg);
  913. end;
  914. else
  915. begin
  916. tmpreg:=getintregister(list,size);
  917. a_load_ref_reg(list,size,size,ref,tmpreg);
  918. a_op_reg_reg(list,op,size,tmpreg,reg);
  919. end;
  920. end;
  921. end;
  922. procedure tcg.a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  923. begin
  924. case loc.loc of
  925. LOC_REGISTER, LOC_CREGISTER:
  926. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  927. LOC_REFERENCE, LOC_CREFERENCE:
  928. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  929. else
  930. internalerror(200109061);
  931. end;
  932. end;
  933. procedure tcg.a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  934. var
  935. tmpreg: tregister;
  936. begin
  937. case loc.loc of
  938. LOC_REGISTER,LOC_CREGISTER:
  939. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  940. LOC_REFERENCE,LOC_CREFERENCE:
  941. begin
  942. tmpreg:=getintregister(list,loc.size);
  943. a_load_ref_reg(list,loc.size,loc.size,ref,tmpreg);
  944. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  945. end;
  946. else
  947. internalerror(200109061);
  948. end;
  949. end;
  950. procedure Tcg.a_op_const_reg_reg(list:Taasmoutput;op:Topcg;size:Tcgsize;
  951. a:aint;src,dst:Tregister);
  952. begin
  953. a_load_reg_reg(list,size,size,src,dst);
  954. a_op_const_reg(list,op,size,a,dst);
  955. end;
  956. procedure tcg.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  957. size: tcgsize; src1, src2, dst: tregister);
  958. var
  959. tmpreg: tregister;
  960. begin
  961. if (dst<>src1) then
  962. begin
  963. a_load_reg_reg(list,size,size,src2,dst);
  964. a_op_reg_reg(list,op,size,src1,dst);
  965. end
  966. else
  967. begin
  968. tmpreg:=getintregister(list,size);
  969. a_load_reg_reg(list,size,size,src2,tmpreg);
  970. a_op_reg_reg(list,op,size,src1,tmpreg);
  971. a_load_reg_reg(list,size,size,tmpreg,dst);
  972. end;
  973. end;
  974. procedure tcg.a_op_const_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation);
  975. begin
  976. a_op_const_reg_reg(list,op,size,a,src,dst);
  977. ovloc.loc:=LOC_VOID;
  978. end;
  979. procedure tcg.a_op_reg_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation);
  980. begin
  981. a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  982. ovloc.loc:=LOC_VOID;
  983. end;
  984. procedure tcg.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  985. l : tasmlabel);
  986. var
  987. tmpreg: tregister;
  988. begin
  989. tmpreg:=getintregister(list,size);
  990. a_load_ref_reg(list,size,size,ref,tmpreg);
  991. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  992. end;
  993. procedure tcg.a_cmp_const_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const loc : tlocation;
  994. l : tasmlabel);
  995. begin
  996. case loc.loc of
  997. LOC_REGISTER,LOC_CREGISTER:
  998. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  999. LOC_REFERENCE,LOC_CREFERENCE:
  1000. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1001. else
  1002. internalerror(200109061);
  1003. end;
  1004. end;
  1005. procedure tcg.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  1006. var
  1007. tmpreg: tregister;
  1008. begin
  1009. tmpreg:=getintregister(list,size);
  1010. a_load_ref_reg(list,size,size,ref,tmpreg);
  1011. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1012. end;
  1013. procedure tcg.a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; reg : tregister; const ref: treference; l : tasmlabel);
  1014. var
  1015. tmpreg: tregister;
  1016. begin
  1017. tmpreg:=getintregister(list,size);
  1018. a_load_ref_reg(list,size,size,ref,tmpreg);
  1019. a_cmp_reg_reg_label(list,size,cmp_op,reg,tmpreg,l);
  1020. end;
  1021. procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  1022. begin
  1023. case loc.loc of
  1024. LOC_REGISTER,
  1025. LOC_CREGISTER:
  1026. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1027. LOC_REFERENCE,
  1028. LOC_CREFERENCE :
  1029. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1030. LOC_CONSTANT:
  1031. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1032. else
  1033. internalerror(200203231);
  1034. end;
  1035. end;
  1036. procedure tcg.a_cmp_ref_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  1037. l : tasmlabel);
  1038. var
  1039. tmpreg: tregister;
  1040. begin
  1041. case loc.loc of
  1042. LOC_REGISTER,LOC_CREGISTER:
  1043. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1044. LOC_REFERENCE,LOC_CREFERENCE:
  1045. begin
  1046. tmpreg:=getintregister(list,size);
  1047. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1048. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1049. end
  1050. else
  1051. internalerror(200109061);
  1052. end;
  1053. end;
  1054. procedure tcg.a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  1055. begin
  1056. case loc.loc of
  1057. LOC_MMREGISTER,LOC_CMMREGISTER:
  1058. a_loadmm_reg_reg(list,loc.size,size,loc.register,reg,shuffle);
  1059. LOC_REFERENCE,LOC_CREFERENCE:
  1060. a_loadmm_ref_reg(list,loc.size,size,loc.reference,reg,shuffle);
  1061. else
  1062. internalerror(200310121);
  1063. end;
  1064. end;
  1065. procedure tcg.a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  1066. begin
  1067. case loc.loc of
  1068. LOC_MMREGISTER,LOC_CMMREGISTER:
  1069. a_loadmm_reg_reg(list,size,loc.size,reg,loc.register,shuffle);
  1070. LOC_REFERENCE,LOC_CREFERENCE:
  1071. a_loadmm_reg_ref(list,size,loc.size,reg,loc.reference,shuffle);
  1072. else
  1073. internalerror(200310122);
  1074. end;
  1075. end;
  1076. procedure tcg.a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle);
  1077. var
  1078. href : treference;
  1079. begin
  1080. cgpara.check_simple_location;
  1081. case cgpara.location^.loc of
  1082. LOC_MMREGISTER,LOC_CMMREGISTER:
  1083. a_loadmm_reg_reg(list,size,cgpara.location^.size,reg,cgpara.location^.register,shuffle);
  1084. LOC_REFERENCE,LOC_CREFERENCE:
  1085. begin
  1086. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  1087. a_loadmm_reg_ref(list,size,cgpara.location^.size,reg,href,shuffle);
  1088. end
  1089. else
  1090. internalerror(200310123);
  1091. end;
  1092. end;
  1093. procedure tcg.a_parammm_ref(list: taasmoutput; size: tcgsize;const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle);
  1094. var
  1095. hr : tregister;
  1096. hs : tmmshuffle;
  1097. begin
  1098. cgpara.check_simple_location;
  1099. hr:=getmmregister(list,cgpara.location^.size);
  1100. a_loadmm_ref_reg(list,size,cgpara.location^.size,ref,hr,shuffle);
  1101. if realshuffle(shuffle) then
  1102. begin
  1103. hs:=shuffle^;
  1104. removeshuffles(hs);
  1105. a_parammm_reg(list,cgpara.location^.size,hr,cgpara,@hs);
  1106. end
  1107. else
  1108. a_parammm_reg(list,cgpara.location^.size,hr,cgpara,shuffle);
  1109. end;
  1110. procedure tcg.a_parammm_loc(list: taasmoutput;const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle);
  1111. begin
  1112. case loc.loc of
  1113. LOC_MMREGISTER,LOC_CMMREGISTER:
  1114. a_parammm_reg(list,loc.size,loc.register,cgpara,shuffle);
  1115. LOC_REFERENCE,LOC_CREFERENCE:
  1116. a_parammm_ref(list,loc.size,loc.reference,cgpara,shuffle);
  1117. else
  1118. internalerror(200310123);
  1119. end;
  1120. end;
  1121. procedure tcg.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  1122. var
  1123. hr : tregister;
  1124. hs : tmmshuffle;
  1125. begin
  1126. hr:=getmmregister(list,size);
  1127. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1128. if realshuffle(shuffle) then
  1129. begin
  1130. hs:=shuffle^;
  1131. removeshuffles(hs);
  1132. a_opmm_reg_reg(list,op,size,hr,reg,@hs);
  1133. end
  1134. else
  1135. a_opmm_reg_reg(list,op,size,hr,reg,shuffle);
  1136. end;
  1137. procedure tcg.a_opmm_reg_ref(list: taasmoutput; Op: TOpCG; size : tcgsize;reg: tregister; const ref: treference; shuffle : pmmshuffle);
  1138. var
  1139. hr : tregister;
  1140. hs : tmmshuffle;
  1141. begin
  1142. hr:=getmmregister(list,size);
  1143. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1144. if realshuffle(shuffle) then
  1145. begin
  1146. hs:=shuffle^;
  1147. removeshuffles(hs);
  1148. a_opmm_reg_reg(list,op,size,reg,hr,@hs);
  1149. a_loadmm_reg_ref(list,size,size,hr,ref,@hs);
  1150. end
  1151. else
  1152. begin
  1153. a_opmm_reg_reg(list,op,size,reg,hr,shuffle);
  1154. a_loadmm_reg_ref(list,size,size,hr,ref,shuffle);
  1155. end;
  1156. end;
  1157. procedure tcg.a_opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle);
  1158. begin
  1159. case loc.loc of
  1160. LOC_CMMREGISTER,LOC_MMREGISTER:
  1161. a_opmm_reg_reg(list,op,size,loc.register,reg,shuffle);
  1162. LOC_CREFERENCE,LOC_REFERENCE:
  1163. a_opmm_ref_reg(list,op,size,loc.reference,reg,shuffle);
  1164. else
  1165. internalerror(200312232);
  1166. end;
  1167. end;
  1168. procedure tcg.g_concatcopy_unaligned(list : taasmoutput;const source,dest : treference;len : aint);
  1169. begin
  1170. g_concatcopy(list,source,dest,len);
  1171. end;
  1172. procedure tcg.g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte);
  1173. var
  1174. cgpara1,cgpara2,cgpara3 : TCGPara;
  1175. begin
  1176. cgpara1.init;
  1177. cgpara2.init;
  1178. cgpara3.init;
  1179. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1180. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1181. paramanager.getintparaloc(pocall_default,3,cgpara3);
  1182. paramanager.allocparaloc(list,cgpara3);
  1183. a_paramaddr_ref(list,dest,cgpara3);
  1184. paramanager.allocparaloc(list,cgpara2);
  1185. a_paramaddr_ref(list,source,cgpara2);
  1186. paramanager.allocparaloc(list,cgpara1);
  1187. a_param_const(list,OS_INT,len,cgpara1);
  1188. paramanager.freeparaloc(list,cgpara3);
  1189. paramanager.freeparaloc(list,cgpara2);
  1190. paramanager.freeparaloc(list,cgpara1);
  1191. allocallcpuregisters(list);
  1192. a_call_name(list,'FPC_SHORTSTR_ASSIGN');
  1193. deallocallcpuregisters(list);
  1194. cgpara3.done;
  1195. cgpara2.done;
  1196. cgpara1.done;
  1197. end;
  1198. procedure tcg.g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  1199. var
  1200. href : treference;
  1201. incrfunc : string;
  1202. cgpara1,cgpara2 : TCGPara;
  1203. begin
  1204. cgpara1.init;
  1205. cgpara2.init;
  1206. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1207. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1208. if is_interfacecom(t) then
  1209. incrfunc:='FPC_INTF_INCR_REF'
  1210. else if is_ansistring(t) then
  1211. {$ifdef ansistring_bits}
  1212. begin
  1213. case Tstringdef(t).string_typ of
  1214. st_ansistring16:
  1215. incrfunc:='FPC_ANSISTR16_INCR_REF';
  1216. st_ansistring32:
  1217. incrfunc:='FPC_ANSISTR32_INCR_REF';
  1218. st_ansistring64:
  1219. incrfunc:='FPC_ANSISTR64_INCR_REF';
  1220. end;
  1221. end
  1222. {$else}
  1223. incrfunc:='FPC_ANSISTR_INCR_REF'
  1224. {$endif}
  1225. else if is_widestring(t) then
  1226. incrfunc:='FPC_WIDESTR_INCR_REF'
  1227. else if is_dynamic_array(t) then
  1228. incrfunc:='FPC_DYNARRAY_INCR_REF'
  1229. else
  1230. incrfunc:='';
  1231. { call the special incr function or the generic addref }
  1232. if incrfunc<>'' then
  1233. begin
  1234. paramanager.allocparaloc(list,cgpara1);
  1235. { these functions get the pointer by value }
  1236. a_param_ref(list,OS_ADDR,ref,cgpara1);
  1237. paramanager.freeparaloc(list,cgpara1);
  1238. allocallcpuregisters(list);
  1239. a_call_name(list,incrfunc);
  1240. deallocallcpuregisters(list);
  1241. end
  1242. else
  1243. begin
  1244. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1245. paramanager.allocparaloc(list,cgpara2);
  1246. a_paramaddr_ref(list,href,cgpara2);
  1247. paramanager.allocparaloc(list,cgpara1);
  1248. a_paramaddr_ref(list,ref,cgpara1);
  1249. paramanager.freeparaloc(list,cgpara1);
  1250. paramanager.freeparaloc(list,cgpara2);
  1251. allocallcpuregisters(list);
  1252. a_call_name(list,'FPC_ADDREF');
  1253. deallocallcpuregisters(list);
  1254. end;
  1255. cgpara2.done;
  1256. cgpara1.done;
  1257. end;
  1258. procedure tcg.g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  1259. var
  1260. href : treference;
  1261. decrfunc : string;
  1262. needrtti : boolean;
  1263. cgpara1,cgpara2 : TCGPara;
  1264. begin
  1265. cgpara1.init;
  1266. cgpara2.init;
  1267. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1268. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1269. needrtti:=false;
  1270. if is_interfacecom(t) then
  1271. decrfunc:='FPC_INTF_DECR_REF'
  1272. else if is_ansistring(t) then
  1273. {$ifdef ansistring_bits}
  1274. begin
  1275. case Tstringdef(t).string_typ of
  1276. st_ansistring16:
  1277. decrfunc:='FPC_ANSISTR16_DECR_REF';
  1278. st_ansistring32:
  1279. decrfunc:='FPC_ANSISTR32_DECR_REF';
  1280. st_ansistring64:
  1281. decrfunc:='FPC_ANSISTR64_DECR_REF';
  1282. end;
  1283. end
  1284. {$else}
  1285. decrfunc:='FPC_ANSISTR_DECR_REF'
  1286. {$endif}
  1287. else if is_widestring(t) then
  1288. decrfunc:='FPC_WIDESTR_DECR_REF'
  1289. else if is_dynamic_array(t) then
  1290. begin
  1291. decrfunc:='FPC_DYNARRAY_DECR_REF';
  1292. needrtti:=true;
  1293. end
  1294. else
  1295. decrfunc:='';
  1296. { call the special decr function or the generic decref }
  1297. if decrfunc<>'' then
  1298. begin
  1299. if needrtti then
  1300. begin
  1301. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1302. paramanager.allocparaloc(list,cgpara2);
  1303. a_paramaddr_ref(list,href,cgpara2);
  1304. end;
  1305. paramanager.allocparaloc(list,cgpara1);
  1306. a_paramaddr_ref(list,ref,cgpara1);
  1307. paramanager.freeparaloc(list,cgpara1);
  1308. if needrtti then
  1309. paramanager.freeparaloc(list,cgpara2);
  1310. allocallcpuregisters(list);
  1311. a_call_name(list,decrfunc);
  1312. deallocallcpuregisters(list);
  1313. end
  1314. else
  1315. begin
  1316. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1317. paramanager.allocparaloc(list,cgpara2);
  1318. a_paramaddr_ref(list,href,cgpara2);
  1319. paramanager.allocparaloc(list,cgpara1);
  1320. a_paramaddr_ref(list,ref,cgpara1);
  1321. paramanager.freeparaloc(list,cgpara1);
  1322. paramanager.freeparaloc(list,cgpara2);
  1323. allocallcpuregisters(list);
  1324. a_call_name(list,'FPC_DECREF');
  1325. deallocallcpuregisters(list);
  1326. end;
  1327. cgpara2.done;
  1328. cgpara1.done;
  1329. end;
  1330. procedure tcg.g_initialize(list : taasmoutput;t : tdef;const ref : treference);
  1331. var
  1332. href : treference;
  1333. cgpara1,cgpara2 : TCGPara;
  1334. begin
  1335. cgpara1.init;
  1336. cgpara2.init;
  1337. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1338. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1339. if is_ansistring(t) or
  1340. is_widestring(t) or
  1341. is_interfacecom(t) or
  1342. is_dynamic_array(t) then
  1343. a_load_const_ref(list,OS_ADDR,0,ref)
  1344. else
  1345. begin
  1346. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1347. paramanager.allocparaloc(list,cgpara2);
  1348. a_paramaddr_ref(list,href,cgpara2);
  1349. paramanager.allocparaloc(list,cgpara1);
  1350. a_paramaddr_ref(list,ref,cgpara1);
  1351. paramanager.freeparaloc(list,cgpara1);
  1352. paramanager.freeparaloc(list,cgpara2);
  1353. allocallcpuregisters(list);
  1354. a_call_name(list,'FPC_INITIALIZE');
  1355. deallocallcpuregisters(list);
  1356. end;
  1357. cgpara1.done;
  1358. cgpara2.done;
  1359. end;
  1360. procedure tcg.g_finalize(list : taasmoutput;t : tdef;const ref : treference);
  1361. var
  1362. href : treference;
  1363. cgpara1,cgpara2 : TCGPara;
  1364. begin
  1365. cgpara1.init;
  1366. cgpara2.init;
  1367. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1368. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1369. if is_ansistring(t) or
  1370. is_widestring(t) or
  1371. is_interfacecom(t) then
  1372. begin
  1373. g_decrrefcount(list,t,ref);
  1374. a_load_const_ref(list,OS_ADDR,0,ref);
  1375. end
  1376. else
  1377. begin
  1378. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1379. paramanager.allocparaloc(list,cgpara2);
  1380. a_paramaddr_ref(list,href,cgpara2);
  1381. paramanager.allocparaloc(list,cgpara1);
  1382. a_paramaddr_ref(list,ref,cgpara1);
  1383. paramanager.freeparaloc(list,cgpara1);
  1384. paramanager.freeparaloc(list,cgpara2);
  1385. allocallcpuregisters(list);
  1386. a_call_name(list,'FPC_FINALIZE');
  1387. deallocallcpuregisters(list);
  1388. end;
  1389. cgpara1.done;
  1390. cgpara2.done;
  1391. end;
  1392. procedure tcg.g_rangecheck(list: taasmoutput; const l:tlocation;fromdef,todef: tdef);
  1393. { generate range checking code for the value at location p. The type }
  1394. { type used is checked against todefs ranges. fromdef (p.resulttype.def) }
  1395. { is the original type used at that location. When both defs are equal }
  1396. { the check is also insert (needed for succ,pref,inc,dec) }
  1397. const
  1398. aintmax=high(aint);
  1399. var
  1400. neglabel : tasmlabel;
  1401. hreg : tregister;
  1402. lto,hto,
  1403. lfrom,hfrom : TConstExprInt;
  1404. from_signed: boolean;
  1405. begin
  1406. { range checking on and range checkable value? }
  1407. if not(cs_check_range in aktlocalswitches) or
  1408. not(fromdef.deftype in [orddef,enumdef,arraydef]) then
  1409. exit;
  1410. {$ifndef cpu64bit}
  1411. { handle 64bit rangechecks separate for 32bit processors }
  1412. if is_64bit(fromdef) or is_64bit(todef) then
  1413. begin
  1414. cg64.g_rangecheck64(list,l,fromdef,todef);
  1415. exit;
  1416. end;
  1417. {$endif cpu64bit}
  1418. { only check when assigning to scalar, subranges are different, }
  1419. { when todef=fromdef then the check is always generated }
  1420. getrange(fromdef,lfrom,hfrom);
  1421. getrange(todef,lto,hto);
  1422. from_signed := is_signed(fromdef);
  1423. { no range check if from and to are equal and are both longint/dword }
  1424. { (if we have a 32bit processor) or int64/qword, since such }
  1425. { operations can at most cause overflows (JM) }
  1426. { Note that these checks are mostly processor independent, they only }
  1427. { have to be changed once we introduce 64bit subrange types }
  1428. {$ifdef cpu64bit}
  1429. if (fromdef = todef) and
  1430. (fromdef.deftype=orddef) and
  1431. (((((torddef(fromdef).typ = s64bit) and
  1432. (lfrom = low(int64)) and
  1433. (hfrom = high(int64))) or
  1434. ((torddef(fromdef).typ = u64bit) and
  1435. (lfrom = low(qword)) and
  1436. (hfrom = high(qword)))))) then
  1437. exit;
  1438. {$else cpu64bit}
  1439. if (fromdef = todef) and
  1440. (fromdef.deftype=orddef) and
  1441. (((((torddef(fromdef).typ = s32bit) and
  1442. (lfrom = low(longint)) and
  1443. (hfrom = high(longint))) or
  1444. ((torddef(fromdef).typ = u32bit) and
  1445. (lfrom = low(cardinal)) and
  1446. (hfrom = high(cardinal)))))) then
  1447. exit;
  1448. {$endif cpu64bit}
  1449. { if the from-range falls completely in the to-range, no check }
  1450. { is necessary. Don't do this conversion for the largest unsigned type }
  1451. if (todef<>fromdef) and
  1452. (from_signed or (hfrom>=0)) and
  1453. (lto<=lfrom) and (hto>=hfrom) then
  1454. exit;
  1455. { generate the rangecheck code for the def where we are going to }
  1456. { store the result }
  1457. { use the trick that }
  1458. { a <= x <= b <=> 0 <= x-a <= b-a <=> unsigned(x-a) <= unsigned(b-a) }
  1459. { To be able to do that, we have to make sure however that either }
  1460. { fromdef and todef are both signed or unsigned, or that we leave }
  1461. { the parts < 0 and > maxlongint out }
  1462. { is_signed now also works for arrays (it checks the rangetype) (JM) }
  1463. if from_signed xor is_signed(todef) then
  1464. begin
  1465. if from_signed then
  1466. { from is signed, to is unsigned }
  1467. begin
  1468. { if high(from) < 0 -> always range error }
  1469. if (hfrom < 0) or
  1470. { if low(to) > maxlongint also range error }
  1471. (lto > aintmax) then
  1472. begin
  1473. a_call_name(list,'FPC_RANGEERROR');
  1474. exit
  1475. end;
  1476. { from is signed and to is unsigned -> when looking at to }
  1477. { as an signed value, it must be < maxaint (otherwise }
  1478. { it will become negative, which is invalid since "to" is unsigned) }
  1479. if hto > aintmax then
  1480. hto := aintmax;
  1481. end
  1482. else
  1483. { from is unsigned, to is signed }
  1484. begin
  1485. if (lfrom > aintmax) or
  1486. (hto < 0) then
  1487. begin
  1488. a_call_name(list,'FPC_RANGEERROR');
  1489. exit
  1490. end;
  1491. { from is unsigned and to is signed -> when looking at to }
  1492. { as an unsigned value, it must be >= 0 (since negative }
  1493. { values are the same as values > maxlongint) }
  1494. if lto < 0 then
  1495. lto := 0;
  1496. end;
  1497. end;
  1498. hreg:=getintregister(list,OS_INT);
  1499. a_load_loc_reg(list,OS_INT,l,hreg);
  1500. a_op_const_reg(list,OP_SUB,OS_INT,aint(lto),hreg);
  1501. objectlibrary.getlabel(neglabel);
  1502. {
  1503. if from_signed then
  1504. a_cmp_const_reg_label(list,OS_INT,OC_GTE,aint(hto-lto),hreg,neglabel)
  1505. else
  1506. }
  1507. {$ifdef cpu64bit}
  1508. if qword(hto-lto)>qword(aintmax) then
  1509. a_cmp_const_reg_label(list,OS_INT,OC_BE,aintmax,hreg,neglabel)
  1510. else
  1511. {$endif cpu64bit}
  1512. a_cmp_const_reg_label(list,OS_INT,OC_BE,aint(hto-lto),hreg,neglabel);
  1513. a_call_name(list,'FPC_RANGEERROR');
  1514. a_label(list,neglabel);
  1515. end;
  1516. procedure tcg.g_overflowCheck_loc(List:TAasmOutput;const Loc:TLocation;def:TDef;ovloc : tlocation);
  1517. begin
  1518. g_overflowCheck(list,loc,def);
  1519. end;
  1520. procedure tcg.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference);
  1521. var
  1522. tmpreg : tregister;
  1523. begin
  1524. tmpreg:=getintregister(list,size);
  1525. g_flags2reg(list,size,f,tmpreg);
  1526. a_load_reg_ref(list,size,size,tmpreg,ref);
  1527. end;
  1528. procedure tcg.g_maybe_testself(list : taasmoutput;reg:tregister);
  1529. var
  1530. OKLabel : tasmlabel;
  1531. cgpara1 : TCGPara;
  1532. begin
  1533. if (cs_check_object in aktlocalswitches) or
  1534. (cs_check_range in aktlocalswitches) then
  1535. begin
  1536. objectlibrary.getlabel(oklabel);
  1537. a_cmp_const_reg_label(list,OS_ADDR,OC_NE,0,reg,oklabel);
  1538. cgpara1.init;
  1539. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1540. paramanager.allocparaloc(list,cgpara1);
  1541. a_param_const(list,OS_INT,210,cgpara1);
  1542. paramanager.freeparaloc(list,cgpara1);
  1543. a_call_name(list,'FPC_HANDLEERROR');
  1544. a_label(list,oklabel);
  1545. cgpara1.done;
  1546. end;
  1547. end;
  1548. procedure tcg.g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  1549. var
  1550. hrefvmt : treference;
  1551. cgpara1,cgpara2 : TCGPara;
  1552. begin
  1553. cgpara1.init;
  1554. cgpara2.init;
  1555. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1556. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1557. if (cs_check_object in aktlocalswitches) then
  1558. begin
  1559. reference_reset_symbol(hrefvmt,objectlibrary.newasmsymbol(objdef.vmt_mangledname,AB_EXTERNAL,AT_DATA),0);
  1560. paramanager.allocparaloc(list,cgpara2);
  1561. a_paramaddr_ref(list,hrefvmt,cgpara2);
  1562. paramanager.allocparaloc(list,cgpara1);
  1563. a_param_reg(list,OS_ADDR,reg,cgpara1);
  1564. paramanager.freeparaloc(list,cgpara1);
  1565. paramanager.freeparaloc(list,cgpara2);
  1566. allocallcpuregisters(list);
  1567. a_call_name(list,'FPC_CHECK_OBJECT_EXT');
  1568. deallocallcpuregisters(list);
  1569. end
  1570. else
  1571. if (cs_check_range in aktlocalswitches) then
  1572. begin
  1573. paramanager.allocparaloc(list,cgpara1);
  1574. a_param_reg(list,OS_ADDR,reg,cgpara1);
  1575. paramanager.freeparaloc(list,cgpara1);
  1576. allocallcpuregisters(list);
  1577. a_call_name(list,'FPC_CHECK_OBJECT');
  1578. deallocallcpuregisters(list);
  1579. end;
  1580. cgpara1.done;
  1581. cgpara2.done;
  1582. end;
  1583. {*****************************************************************************
  1584. Entry/Exit Code Functions
  1585. *****************************************************************************}
  1586. procedure tcg.g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;const lenloc:tlocation;elesize:aint;destreg:tregister);
  1587. var
  1588. sizereg,sourcereg,lenreg : tregister;
  1589. cgpara1,cgpara2,cgpara3 : TCGPara;
  1590. begin
  1591. { because some abis don't support dynamic stack allocation properly
  1592. open array value parameters are copied onto the heap
  1593. }
  1594. { calculate necessary memory }
  1595. { read/write operations on one register make the life of the register allocator hard }
  1596. if not(lenloc.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  1597. begin
  1598. lenreg:=getintregister(list,OS_INT);
  1599. a_load_loc_reg(list,OS_INT,lenloc,lenreg);
  1600. end
  1601. else
  1602. lenreg:=lenloc.register;
  1603. sizereg:=getintregister(list,OS_INT);
  1604. a_op_const_reg_reg(list,OP_ADD,OS_INT,1,lenreg,sizereg);
  1605. a_op_const_reg(list,OP_IMUL,OS_INT,elesize,sizereg);
  1606. { load source }
  1607. sourcereg:=getaddressregister(list);
  1608. a_loadaddr_ref_reg(list,ref,sourcereg);
  1609. { do getmem call }
  1610. cgpara1.init;
  1611. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1612. paramanager.allocparaloc(list,cgpara1);
  1613. a_param_reg(list,OS_INT,sizereg,cgpara1);
  1614. paramanager.freeparaloc(list,cgpara1);
  1615. allocallcpuregisters(list);
  1616. a_call_name(list,'FPC_GETMEM');
  1617. deallocallcpuregisters(list);
  1618. cgpara1.done;
  1619. { return the new address }
  1620. a_load_reg_reg(list,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,destreg);
  1621. { do move call }
  1622. cgpara1.init;
  1623. cgpara2.init;
  1624. cgpara3.init;
  1625. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1626. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1627. paramanager.getintparaloc(pocall_default,3,cgpara3);
  1628. { load size }
  1629. paramanager.allocparaloc(list,cgpara3);
  1630. a_param_reg(list,OS_INT,sizereg,cgpara3);
  1631. { load destination }
  1632. paramanager.allocparaloc(list,cgpara2);
  1633. a_param_reg(list,OS_ADDR,destreg,cgpara2);
  1634. { load source }
  1635. paramanager.allocparaloc(list,cgpara1);
  1636. a_param_reg(list,OS_ADDR,sourcereg,cgpara1);
  1637. paramanager.freeparaloc(list,cgpara3);
  1638. paramanager.freeparaloc(list,cgpara2);
  1639. paramanager.freeparaloc(list,cgpara1);
  1640. allocallcpuregisters(list);
  1641. a_call_name(list,'FPC_MOVE');
  1642. deallocallcpuregisters(list);
  1643. cgpara3.done;
  1644. cgpara2.done;
  1645. cgpara1.done;
  1646. end;
  1647. procedure tcg.g_releasevaluepara_openarray(list : taasmoutput;const l:tlocation);
  1648. var
  1649. cgpara1 : TCGPara;
  1650. begin
  1651. { do move call }
  1652. cgpara1.init;
  1653. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1654. { load source }
  1655. paramanager.allocparaloc(list,cgpara1);
  1656. a_param_loc(list,l,cgpara1);
  1657. paramanager.freeparaloc(list,cgpara1);
  1658. allocallcpuregisters(list);
  1659. a_call_name(list,'FPC_FREEMEM');
  1660. deallocallcpuregisters(list);
  1661. cgpara1.done;
  1662. end;
  1663. procedure tcg.g_save_standard_registers(list:Taasmoutput);
  1664. var
  1665. href : treference;
  1666. size : longint;
  1667. r : integer;
  1668. begin
  1669. { Get temp }
  1670. size:=0;
  1671. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1672. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1673. inc(size,sizeof(aint));
  1674. if size>0 then
  1675. begin
  1676. tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
  1677. { Copy registers to temp }
  1678. href:=current_procinfo.save_regs_ref;
  1679. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1680. begin
  1681. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1682. begin
  1683. a_load_reg_ref(list,OS_ADDR,OS_ADDR,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE),href);
  1684. inc(href.offset,sizeof(aint));
  1685. end;
  1686. include(rg[R_INTREGISTER].preserved_by_proc,saved_standard_registers[r]);
  1687. end;
  1688. end;
  1689. end;
  1690. procedure tcg.g_restore_standard_registers(list:Taasmoutput);
  1691. var
  1692. href : treference;
  1693. r : integer;
  1694. hreg : tregister;
  1695. begin
  1696. { Copy registers from temp }
  1697. href:=current_procinfo.save_regs_ref;
  1698. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1699. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1700. begin
  1701. hreg:=newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE);
  1702. { Allocate register so the optimizer does remove the load }
  1703. a_reg_alloc(list,hreg);
  1704. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,hreg);
  1705. inc(href.offset,sizeof(aint));
  1706. end;
  1707. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1708. end;
  1709. procedure tcg.g_profilecode(list : taasmoutput);
  1710. begin
  1711. end;
  1712. procedure tcg.g_exception_reason_save(list : taasmoutput; const href : treference);
  1713. begin
  1714. a_load_reg_ref(list, OS_INT, OS_INT, NR_FUNCTION_RESULT_REG, href);
  1715. end;
  1716. procedure tcg.g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aint);
  1717. begin
  1718. a_load_const_ref(list, OS_INT, a, href);
  1719. end;
  1720. procedure tcg.g_exception_reason_load(list : taasmoutput; const href : treference);
  1721. begin
  1722. a_load_ref_reg(list, OS_INT, OS_INT, href, NR_FUNCTION_RESULT_REG);
  1723. end;
  1724. procedure tcg.g_adjust_self_value(list:taasmoutput;procdef: tprocdef;ioffset: aint);
  1725. var
  1726. hsym : tsym;
  1727. href : treference;
  1728. paraloc : tcgparalocation;
  1729. begin
  1730. { calculate the parameter info for the procdef }
  1731. if not procdef.has_paraloc_info then
  1732. begin
  1733. procdef.requiredargarea:=paramanager.create_paraloc_info(procdef,callerside);
  1734. procdef.has_paraloc_info:=true;
  1735. end;
  1736. hsym:=tsym(procdef.parast.search('self'));
  1737. if not(assigned(hsym) and
  1738. (hsym.typ=paravarsym)) then
  1739. internalerror(200305251);
  1740. paraloc:=tparavarsym(hsym).paraloc[callerside].location^;
  1741. case paraloc.loc of
  1742. LOC_REGISTER:
  1743. cg.a_op_const_reg(list,OP_SUB,paraloc.size,ioffset,paraloc.register);
  1744. LOC_REFERENCE:
  1745. begin
  1746. { offset in the wrapper needs to be adjusted for the stored
  1747. return address }
  1748. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset+sizeof(aint));
  1749. cg.a_op_const_ref(list,OP_SUB,paraloc.size,ioffset,href);
  1750. end
  1751. else
  1752. internalerror(200309189);
  1753. end;
  1754. end;
  1755. {*****************************************************************************
  1756. TCG64
  1757. *****************************************************************************}
  1758. {$ifndef cpu64bit}
  1759. procedure tcg64.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64; regsrc,regdst : tregister64);
  1760. begin
  1761. a_load64_reg_reg(list,regsrc,regdst);
  1762. a_op64_const_reg(list,op,size,value,regdst);
  1763. end;
  1764. procedure tcg64.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1765. var
  1766. tmpreg64 : tregister64;
  1767. begin
  1768. { when src1=dst then we need to first create a temp to prevent
  1769. overwriting src1 with src2 }
  1770. if (regsrc1.reghi=regdst.reghi) or
  1771. (regsrc1.reglo=regdst.reghi) or
  1772. (regsrc1.reghi=regdst.reglo) or
  1773. (regsrc1.reglo=regdst.reglo) then
  1774. begin
  1775. tmpreg64.reglo:=cg.getintregister(list,OS_32);
  1776. tmpreg64.reghi:=cg.getintregister(list,OS_32);
  1777. a_load64_reg_reg(list,regsrc2,tmpreg64);
  1778. a_op64_reg_reg(list,op,size,regsrc1,tmpreg64);
  1779. a_load64_reg_reg(list,tmpreg64,regdst);
  1780. end
  1781. else
  1782. begin
  1783. a_load64_reg_reg(list,regsrc2,regdst);
  1784. a_op64_reg_reg(list,op,size,regsrc1,regdst);
  1785. end;
  1786. end;
  1787. procedure tcg64.a_op64_const_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1788. begin
  1789. a_op64_const_reg_reg(list,op,size,value,regsrc,regdst);
  1790. ovloc.loc:=LOC_VOID;
  1791. end;
  1792. procedure tcg64.a_op64_reg_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1793. begin
  1794. a_op64_reg_reg_reg(list,op,size,regsrc1,regsrc2,regdst);
  1795. ovloc.loc:=LOC_VOID;
  1796. end;
  1797. {$endif cpu64bit}
  1798. initialization
  1799. ;
  1800. finalization
  1801. cg.free;
  1802. {$ifndef cpu64bit}
  1803. cg64.free;
  1804. {$endif cpu64bit}
  1805. end.