cgcpu.pas 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the code generator for the PowerPC
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit cgcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,symtype,symdef,
  22. cgbase,cgobj,cgppc,
  23. aasmbase,aasmcpu,aasmtai,aasmdata,
  24. cpubase,cpuinfo,cgutils,cg64f32,rgcpu,
  25. parabase;
  26. type
  27. tcgppc = class(tcgppcgen)
  28. procedure init_register_allocators;override;
  29. procedure done_register_allocators;override;
  30. { passing parameters, per default the parameter is pushed }
  31. { nr gives the number of the parameter (enumerated from }
  32. { left to right), this allows to move the parameter to }
  33. { register, if the cpu supports register calling }
  34. { conventions }
  35. procedure a_param_ref(list : TAsmList;size : tcgsize;const r : treference;const paraloc : tcgpara);override;
  36. procedure a_call_name(list : TAsmList;const s : string);override;
  37. procedure a_call_reg(list : TAsmList;reg: tregister); override;
  38. procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister); override;
  39. procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  40. procedure a_op_const_reg_reg(list: TAsmList; op: TOpCg;
  41. size: tcgsize; a: aint; src, dst: tregister); override;
  42. procedure a_op_reg_reg_reg(list: TAsmList; op: TOpCg;
  43. size: tcgsize; src1, src2, dst: tregister); override;
  44. { move instructions }
  45. procedure a_load_const_reg(list : TAsmList; size: tcgsize; a : aint;reg : tregister);override;
  46. procedure a_load_ref_reg(list : TAsmList; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister);override;
  47. procedure a_load_reg_reg(list : TAsmList; fromsize, tosize : tcgsize;reg1,reg2 : tregister);override;
  48. procedure a_load_subsetreg_reg(list : TAsmList; subsetsize: tcgsize;
  49. tosize: tcgsize; const sreg: tsubsetregister; destreg: tregister); override;
  50. procedure a_load_subsetreg_subsetreg(list: TAsmlist; fromsubsetsize, tosubsetsize: tcgsize; const fromsreg, tosreg: tsubsetregister); override;
  51. { comparison operations }
  52. procedure a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  53. l : tasmlabel);override;
  54. procedure a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  55. procedure a_jmp_name(list : TAsmList;const s : string); override;
  56. procedure a_jmp_always(list : TAsmList;l: tasmlabel); override;
  57. procedure a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel); override;
  58. procedure g_flags2reg(list: TAsmList; size: TCgSize; const f: TResFlags; reg: TRegister); override;
  59. procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);override;
  60. procedure g_proc_exit(list : TAsmList;parasize : longint;nostackframe:boolean); override;
  61. procedure g_save_standard_registers(list:TAsmList); override;
  62. procedure g_restore_standard_registers(list:TAsmList); override;
  63. procedure a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);override;
  64. procedure g_concatcopy(list : TAsmList;const source,dest : treference;len : aint);override;
  65. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  66. { that's the case, we can use rlwinm to do an AND operation }
  67. function get_rlwi_const(a: aint; var l1, l2: longint): boolean;
  68. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  69. protected
  70. procedure a_load_regconst_subsetreg_intern(list : TAsmList; fromsize, subsetsize: tcgsize; fromreg: tregister; const sreg: tsubsetregister; slopt: tsubsetloadopt); override;
  71. private
  72. (* NOT IN USE: *)
  73. procedure g_stackframe_entry_mac(list : TAsmList;localsize : longint);
  74. (* NOT IN USE: *)
  75. procedure g_return_from_proc_mac(list : TAsmList;parasize : aint);
  76. { clear out potential overflow bits from 8 or 16 bit operations }
  77. { the upper 24/16 bits of a register after an operation }
  78. procedure maybeadjustresult(list: TAsmList; op: TOpCg; size: tcgsize; dst: tregister);
  79. { Make sure ref is a valid reference for the PowerPC and sets the }
  80. { base to the value of the index if (base = R_NO). }
  81. { Returns true if the reference contained a base, index and an }
  82. { offset or symbol, in which case the base will have been changed }
  83. { to a tempreg (which has to be freed by the caller) containing }
  84. { the sum of part of the original reference }
  85. function fixref(list: TAsmList; var ref: treference): boolean; override;
  86. { returns whether a reference can be used immediately in a powerpc }
  87. { instruction }
  88. function issimpleref(const ref: treference): boolean;
  89. { contains the common code of a_load_reg_ref and a_load_ref_reg }
  90. procedure a_load_store(list:TAsmList;op: tasmop;reg:tregister;
  91. ref: treference); override;
  92. function save_regs(list : TAsmList):longint;
  93. procedure restore_regs(list : TAsmList);
  94. end;
  95. tcg64fppc = class(tcg64f32)
  96. procedure a_op64_reg_reg(list : TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);override;
  97. procedure a_op64_const_reg(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;reg : tregister64);override;
  98. procedure a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);override;
  99. procedure a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);override;
  100. end;
  101. const
  102. TOpCG2AsmOpConstLo: Array[topcg] of TAsmOp = (A_NONE,A_MR,A_ADDI,A_ANDI_,A_DIVWU,
  103. A_DIVW,A_MULLW, A_MULLW, A_NONE,A_NONE,A_ORI,
  104. A_SRAWI,A_SLWI,A_SRWI,A_SUBI,A_XORI);
  105. TOpCG2AsmOpConstHi: Array[topcg] of TAsmOp = (A_NONE,A_MR,A_ADDIS,A_ANDIS_,
  106. A_DIVWU,A_DIVW, A_MULLW,A_MULLW,A_NONE,A_NONE,
  107. A_ORIS,A_NONE, A_NONE,A_NONE,A_SUBIS,A_XORIS);
  108. implementation
  109. uses
  110. globals,verbose,systems,cutils,
  111. symconst,symsym,fmodule,
  112. rgobj,tgobj,cpupi,procinfo,paramgr;
  113. procedure tcgppc.init_register_allocators;
  114. begin
  115. inherited init_register_allocators;
  116. if target_info.system=system_powerpc_darwin then
  117. begin
  118. {
  119. if pi_needs_got in current_procinfo.flags then
  120. begin
  121. current_procinfo.got:=NR_R31;
  122. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  123. [RS_R2,RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
  124. RS_R9,RS_R10,RS_R11,RS_R12,RS_R30,RS_R29,
  125. RS_R28,RS_R27,RS_R26,RS_R25,RS_R24,RS_R23,RS_R22,
  126. RS_R21,RS_R20,RS_R19,RS_R18,RS_R17,RS_R16,RS_R15,
  127. RS_R14,RS_R13],first_int_imreg,[]);
  128. end
  129. else}
  130. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  131. [RS_R2,RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
  132. RS_R9,RS_R10,RS_R11,RS_R12,RS_R31,RS_R30,RS_R29,
  133. RS_R28,RS_R27,RS_R26,RS_R25,RS_R24,RS_R23,RS_R22,
  134. RS_R21,RS_R20,RS_R19,RS_R18,RS_R17,RS_R16,RS_R15,
  135. RS_R14,RS_R13],first_int_imreg,[]);
  136. end
  137. else
  138. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  139. [RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
  140. RS_R9,RS_R10,RS_R11,RS_R12,RS_R31,RS_R30,RS_R29,
  141. RS_R28,RS_R27,RS_R26,RS_R25,RS_R24,RS_R23,RS_R22,
  142. RS_R21,RS_R20,RS_R19,RS_R18,RS_R17,RS_R16,RS_R15,
  143. RS_R14,RS_R13],first_int_imreg,[]);
  144. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,
  145. [RS_F0,RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7,RS_F8,RS_F9,
  146. RS_F10,RS_F11,RS_F12,RS_F13,RS_F31,RS_F30,RS_F29,RS_F28,RS_F27,
  147. RS_F26,RS_F25,RS_F24,RS_F23,RS_F22,RS_F21,RS_F20,RS_F19,RS_F18,
  148. RS_F17,RS_F16,RS_F15,RS_F14],first_fpu_imreg,[]);
  149. {$warning FIX ME}
  150. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,
  151. [RS_M0,RS_M1,RS_M2],first_mm_imreg,[]);
  152. end;
  153. procedure tcgppc.done_register_allocators;
  154. begin
  155. rg[R_INTREGISTER].free;
  156. rg[R_FPUREGISTER].free;
  157. rg[R_MMREGISTER].free;
  158. inherited done_register_allocators;
  159. end;
  160. procedure tcgppc.a_param_ref(list : TAsmList;size : tcgsize;const r : treference;const paraloc : tcgpara);
  161. var
  162. tmpref, ref: treference;
  163. location: pcgparalocation;
  164. sizeleft: aint;
  165. begin
  166. location := paraloc.location;
  167. tmpref := r;
  168. sizeleft := paraloc.intsize;
  169. while assigned(location) do
  170. begin
  171. case location^.loc of
  172. LOC_REGISTER,LOC_CREGISTER:
  173. begin
  174. {$ifndef cpu64bit}
  175. if (sizeleft <> 3) then
  176. begin
  177. a_load_ref_reg(list,location^.size,location^.size,tmpref,location^.register);
  178. end
  179. else
  180. begin
  181. a_load_ref_reg(list,OS_16,OS_16,tmpref,location^.register);
  182. a_reg_alloc(list,NR_R0);
  183. inc(tmpref.offset,2);
  184. a_load_ref_reg(list,OS_8,OS_8,tmpref,newreg(R_INTREGISTER,RS_R0,R_SUBNONE));
  185. a_op_const_reg(list,OP_SHL,OS_INT,16,location^.register);
  186. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,location^.register,newreg(R_INTREGISTER,RS_R0,R_SUBNONE),8,16,31-8));
  187. a_reg_dealloc(list,NR_R0);
  188. dec(tmpref.offset,2);
  189. end;
  190. {$else not cpu64bit}
  191. {$error add 64 bit support for non power of 2 loads in a_param_ref}
  192. {$endif not cpu64bit}
  193. end;
  194. LOC_REFERENCE:
  195. begin
  196. reference_reset_base(ref,location^.reference.index,location^.reference.offset);
  197. g_concatcopy(list,tmpref,ref,sizeleft);
  198. if assigned(location^.next) then
  199. internalerror(2005010710);
  200. end;
  201. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  202. case location^.size of
  203. OS_F32, OS_F64:
  204. a_loadfpu_ref_reg(list,location^.size,location^.size,tmpref,location^.register);
  205. else
  206. internalerror(2002072801);
  207. end;
  208. LOC_VOID:
  209. begin
  210. // nothing to do
  211. end;
  212. else
  213. internalerror(2002081103);
  214. end;
  215. inc(tmpref.offset,tcgsize2size[location^.size]);
  216. dec(sizeleft,tcgsize2size[location^.size]);
  217. location := location^.next;
  218. end;
  219. end;
  220. { calling a procedure by name }
  221. procedure tcgppc.a_call_name(list : TAsmList;const s : string);
  222. begin
  223. { MacOS: The linker on MacOS (PPCLink) inserts a call to glue code,
  224. if it is a cross-TOC call. If so, it also replaces the NOP
  225. with some restore code.}
  226. if (target_info.system <> system_powerpc_darwin) then
  227. begin
  228. list.concat(taicpu.op_sym(A_BL,current_asmdata.RefAsmSymbol(s)));
  229. if target_info.system=system_powerpc_macos then
  230. list.concat(taicpu.op_none(A_NOP));
  231. end
  232. else
  233. list.concat(taicpu.op_sym(A_BL,get_darwin_call_stub(s)));
  234. {
  235. the compiler does not properly set this flag anymore in pass 1, and
  236. for now we only need it after pass 2 (I hope) (JM)
  237. if not(pi_do_call in current_procinfo.flags) then
  238. internalerror(2003060703);
  239. }
  240. include(current_procinfo.flags,pi_do_call);
  241. end;
  242. { calling a procedure by address }
  243. procedure tcgppc.a_call_reg(list : TAsmList;reg: tregister);
  244. var
  245. tmpreg : tregister;
  246. tmpref : treference;
  247. begin
  248. if target_info.system=system_powerpc_macos then
  249. begin
  250. {Generate instruction to load the procedure address from
  251. the transition vector.}
  252. //TODO: Support cross-TOC calls.
  253. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  254. reference_reset(tmpref);
  255. tmpref.offset := 0;
  256. //tmpref.symaddr := refs_full;
  257. tmpref.base:= reg;
  258. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  259. end
  260. else
  261. tmpreg:=reg;
  262. inherited a_call_reg(list,tmpreg);
  263. end;
  264. {********************** load instructions ********************}
  265. procedure tcgppc.a_load_const_reg(list : TAsmList; size: TCGSize; a : aint; reg : TRegister);
  266. begin
  267. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  268. internalerror(2002090902);
  269. if (a >= low(smallint)) and
  270. (a <= high(smallint)) then
  271. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a)))
  272. else if ((a and $ffff) <> 0) then
  273. begin
  274. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a and $ffff)));
  275. if ((a shr 16) <> 0) or
  276. (smallint(a and $ffff) < 0) then
  277. list.concat(taicpu.op_reg_reg_const(A_ADDIS,reg,reg,
  278. smallint((a shr 16)+ord(smallint(a and $ffff) < 0))))
  279. end
  280. else
  281. list.concat(taicpu.op_reg_const(A_LIS,reg,smallint(a shr 16)));
  282. end;
  283. procedure tcgppc.a_load_ref_reg(list : TAsmList; fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  284. const
  285. LoadInstr: Array[OS_8..OS_S32,boolean, boolean] of TAsmOp =
  286. { indexed? updating?}
  287. (((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  288. ((A_LHZ,A_LHZU),(A_LHZX,A_LHZUX)),
  289. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)),
  290. { 64bit stuff should be handled separately }
  291. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  292. { 128bit stuff too }
  293. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  294. { there's no load-byte-with-sign-extend :( }
  295. ((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  296. ((A_LHA,A_LHAU),(A_LHAX,A_LHAUX)),
  297. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)));
  298. var
  299. op: tasmop;
  300. ref2: treference;
  301. begin
  302. { TODO: optimize/take into consideration fromsize/tosize. Will }
  303. { probably only matter for OS_S8 loads though }
  304. if not(fromsize in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  305. internalerror(2002090902);
  306. ref2 := ref;
  307. fixref(list,ref2);
  308. { the caller is expected to have adjusted the reference already }
  309. { in this case }
  310. if (TCGSize2Size[fromsize] >= TCGSize2Size[tosize]) then
  311. fromsize := tosize;
  312. op := loadinstr[fromsize,ref2.index<>NR_NO,false];
  313. a_load_store(list,op,reg,ref2);
  314. { sign extend shortint if necessary, since there is no }
  315. { load instruction that does that automatically (JM) }
  316. if fromsize = OS_S8 then
  317. list.concat(taicpu.op_reg_reg(A_EXTSB,reg,reg));
  318. end;
  319. procedure tcgppc.a_load_reg_reg(list : TAsmList;fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  320. var
  321. instr: taicpu;
  322. begin
  323. if (tcgsize2size[fromsize] > tcgsize2size[tosize]) or
  324. ((tcgsize2size[fromsize] = tcgsize2size[tosize]) and
  325. (fromsize <> tosize)) or
  326. { needs to mask out the sign in the top 16 bits }
  327. ((fromsize = OS_S8) and
  328. (tosize = OS_16)) then
  329. case tosize of
  330. OS_8:
  331. instr := taicpu.op_reg_reg_const_const_const(A_RLWINM,
  332. reg2,reg1,0,31-8+1,31);
  333. OS_S8:
  334. instr := taicpu.op_reg_reg(A_EXTSB,reg2,reg1);
  335. OS_16:
  336. instr := taicpu.op_reg_reg_const_const_const(A_RLWINM,
  337. reg2,reg1,0,31-16+1,31);
  338. OS_S16:
  339. instr := taicpu.op_reg_reg(A_EXTSH,reg2,reg1);
  340. OS_32,OS_S32:
  341. instr := taicpu.op_reg_reg(A_MR,reg2,reg1);
  342. else internalerror(2002090901);
  343. end
  344. else
  345. instr := taicpu.op_reg_reg(A_MR,reg2,reg1);
  346. list.concat(instr);
  347. rg[R_INTREGISTER].add_move_instruction(instr);
  348. end;
  349. procedure tcgppc.a_load_subsetreg_reg(list : TAsmList; subsetsize, tosize: tcgsize; const sreg: tsubsetregister; destreg: tregister);
  350. begin
  351. if (sreg.bitlen <> sizeof(aint)*8) then
  352. begin
  353. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,destreg,
  354. sreg.subsetreg,(32-sreg.startbit) and 31,32-sreg.bitlen,31));
  355. { types with a negative lower bound are always a base type (8, 16, 32 bits) }
  356. if (subsetsize in [OS_S8..OS_S128]) then
  357. if ((sreg.bitlen mod 8) = 0) then
  358. begin
  359. a_load_reg_reg(list,tcgsize2unsigned[subsetsize],subsetsize,destreg,destreg);
  360. a_load_reg_reg(list,subsetsize,tosize,destreg,destreg);
  361. end
  362. else
  363. begin
  364. a_op_const_reg(list,OP_SHL,OS_INT,32-sreg.bitlen,destreg);
  365. a_op_const_reg(list,OP_SAR,OS_INT,32-sreg.bitlen,destreg);
  366. end;
  367. end
  368. else
  369. a_load_reg_reg(list,subsetsize,tosize,sreg.subsetreg,destreg);
  370. end;
  371. procedure tcgppc.a_load_regconst_subsetreg_intern(list : TAsmList; fromsize, subsetsize: tcgsize; fromreg: tregister; const sreg: tsubsetregister; slopt: tsubsetloadopt);
  372. begin
  373. if (slopt in [SL_SETZERO,SL_SETMAX]) then
  374. inherited a_load_regconst_subsetreg_intern(list,fromsize,subsetsize,fromreg,sreg,slopt)
  375. else if (sreg.bitlen <> sizeof(aint) * 8) then
  376. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,sreg.subsetreg,fromreg,
  377. sreg.startbit,32-sreg.startbit-sreg.bitlen,31-sreg.startbit))
  378. else
  379. a_load_reg_reg(list,fromsize,subsetsize,fromreg,sreg.subsetreg);
  380. end;
  381. procedure tcgppc.a_load_subsetreg_subsetreg(list: TAsmlist; fromsubsetsize, tosubsetsize: tcgsize; const fromsreg, tosreg: tsubsetregister);
  382. begin
  383. if (fromsreg.bitlen >= tosreg.bitlen) then
  384. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,tosreg.subsetreg, fromsreg.subsetreg,
  385. (tosreg.startbit-fromsreg.startbit) and 31,
  386. 32-tosreg.startbit-tosreg.bitlen,31-tosreg.startbit))
  387. else
  388. inherited a_load_subsetreg_subsetreg(list,fromsubsetsize,tosubsetsize,fromsreg,tosreg);
  389. end;
  390. procedure tcgppc.a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister);
  391. begin
  392. a_op_const_reg_reg(list,op,size,a,reg,reg);
  393. end;
  394. procedure tcgppc.a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  395. begin
  396. a_op_reg_reg_reg(list,op,size,src,dst,dst);
  397. end;
  398. procedure tcgppc.maybeadjustresult(list: TAsmList; op: TOpCg; size: tcgsize; dst: tregister);
  399. const
  400. overflowops = [OP_MUL,OP_SHL,OP_ADD,OP_SUB,OP_NOT,OP_NEG];
  401. begin
  402. if (op in overflowops) and
  403. (size in [OS_8,OS_S8,OS_16,OS_S16]) then
  404. a_load_reg_reg(list,OS_32,size,dst,dst);
  405. end;
  406. procedure tcgppc.a_op_const_reg_reg(list: TAsmList; op: TOpCg;
  407. size: tcgsize; a: aint; src, dst: tregister);
  408. var
  409. l1,l2: longint;
  410. oplo, ophi: tasmop;
  411. scratchreg: tregister;
  412. useReg, gotrlwi: boolean;
  413. procedure do_lo_hi;
  414. begin
  415. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  416. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  417. end;
  418. begin
  419. if (op = OP_MOVE) then
  420. internalerror(2006031401);
  421. if op = OP_SUB then
  422. begin
  423. a_op_const_reg_reg(list,OP_ADD,size,-a,src,dst);
  424. exit;
  425. end;
  426. ophi := TOpCG2AsmOpConstHi[op];
  427. oplo := TOpCG2AsmOpConstLo[op];
  428. gotrlwi := get_rlwi_const(a,l1,l2);
  429. if (op in [OP_AND,OP_OR,OP_XOR]) then
  430. begin
  431. if (a = 0) then
  432. begin
  433. if op = OP_AND then
  434. list.concat(taicpu.op_reg_const(A_LI,dst,0))
  435. else
  436. a_load_reg_reg(list,size,size,src,dst);
  437. exit;
  438. end
  439. else if (a = -1) then
  440. begin
  441. case op of
  442. OP_OR:
  443. case size of
  444. OS_8, OS_S8:
  445. list.concat(taicpu.op_reg_const(A_LI,dst,255));
  446. OS_16, OS_S16:
  447. a_load_const_reg(list,OS_16,65535,dst);
  448. else
  449. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  450. end;
  451. OP_XOR:
  452. case size of
  453. OS_8, OS_S8:
  454. list.concat(taicpu.op_reg_reg_const(A_XORI,dst,src,255));
  455. OS_16, OS_S16:
  456. list.concat(taicpu.op_reg_reg_const(A_XORI,dst,src,65535));
  457. else
  458. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  459. end;
  460. OP_AND:
  461. a_load_reg_reg(list,size,size,src,dst);
  462. end;
  463. exit;
  464. end
  465. else if (aword(a) <= high(word)) and
  466. ((op <> OP_AND) or
  467. not gotrlwi) then
  468. begin
  469. if ((size = OS_8) and
  470. (byte(a) <> a)) or
  471. ((size = OS_S8) and
  472. (shortint(a) <> a)) then
  473. internalerror(200604142);
  474. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  475. { and/or/xor -> cannot overflow in high 16 bits }
  476. exit;
  477. end;
  478. { all basic constant instructions also have a shifted form that }
  479. { works only on the highest 16bits, so if lo(a) is 0, we can }
  480. { use that one }
  481. if (word(a) = 0) and
  482. (not(op = OP_AND) or
  483. not gotrlwi) then
  484. begin
  485. if (size in [OS_8,OS_S8,OS_16,OS_S16]) then
  486. internalerror(200604141);
  487. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  488. exit;
  489. end;
  490. end
  491. else if (op = OP_ADD) then
  492. if a = 0 then
  493. begin
  494. a_load_reg_reg(list,size,size,src,dst);
  495. exit
  496. end
  497. else if (a >= low(smallint)) and
  498. (a <= high(smallint)) then
  499. begin
  500. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  501. maybeadjustresult(list,op,size,dst);
  502. exit;
  503. end;
  504. { otherwise, the instructions we can generate depend on the }
  505. { operation }
  506. useReg := false;
  507. case op of
  508. OP_DIV,OP_IDIV:
  509. if (a = 0) then
  510. internalerror(200208103)
  511. else if (a = 1) then
  512. begin
  513. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  514. exit
  515. end
  516. else if ispowerof2(a,l1) then
  517. begin
  518. case op of
  519. OP_DIV:
  520. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  521. OP_IDIV:
  522. begin
  523. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  524. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  525. end;
  526. end;
  527. exit;
  528. end
  529. else
  530. usereg := true;
  531. OP_IMUL, OP_MUL:
  532. if (a = 0) then
  533. begin
  534. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  535. exit
  536. end
  537. else if (a = 1) then
  538. begin
  539. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  540. exit
  541. end
  542. else if ispowerof2(a,l1) then
  543. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  544. else if (longint(a) >= low(smallint)) and
  545. (longint(a) <= high(smallint)) then
  546. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  547. else
  548. usereg := true;
  549. OP_ADD:
  550. begin
  551. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  552. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  553. smallint((a shr 16) + ord(smallint(a) < 0))));
  554. end;
  555. OP_OR:
  556. { try to use rlwimi }
  557. if gotrlwi and
  558. (src = dst) then
  559. begin
  560. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  561. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  562. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  563. scratchreg,0,l1,l2));
  564. end
  565. else
  566. do_lo_hi;
  567. OP_AND:
  568. { try to use rlwinm }
  569. if gotrlwi then
  570. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  571. src,0,l1,l2))
  572. else
  573. useReg := true;
  574. OP_XOR:
  575. do_lo_hi;
  576. OP_SHL,OP_SHR,OP_SAR:
  577. begin
  578. if (a and 31) <> 0 Then
  579. list.concat(taicpu.op_reg_reg_const(
  580. TOpCG2AsmOpConstLo[Op],dst,src,a and 31))
  581. else
  582. a_load_reg_reg(list,size,size,src,dst);
  583. if (a shr 5) <> 0 then
  584. internalError(68991);
  585. end
  586. else
  587. internalerror(200109091);
  588. end;
  589. { if all else failed, load the constant in a register and then }
  590. { perform the operation }
  591. if useReg then
  592. begin
  593. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  594. a_load_const_reg(list,OS_32,a,scratchreg);
  595. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  596. end;
  597. maybeadjustresult(list,op,size,dst);
  598. end;
  599. procedure tcgppc.a_op_reg_reg_reg(list: TAsmList; op: TOpCg;
  600. size: tcgsize; src1, src2, dst: tregister);
  601. const
  602. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  603. (A_NONE,A_MR,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  604. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  605. begin
  606. if (op = OP_MOVE) then
  607. internalerror(2006031402);
  608. case op of
  609. OP_NEG,OP_NOT:
  610. begin
  611. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,src1));
  612. if (op = OP_NOT) and
  613. not(size in [OS_32,OS_S32]) then
  614. { zero/sign extend result again }
  615. a_load_reg_reg(list,OS_32,size,dst,dst);
  616. end;
  617. else
  618. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  619. end;
  620. maybeadjustresult(list,op,size,dst);
  621. end;
  622. {*************** compare instructructions ****************}
  623. procedure tcgppc.a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  624. l : tasmlabel);
  625. var
  626. scratch_register: TRegister;
  627. signed: boolean;
  628. begin
  629. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE,OC_EQ,OC_NE];
  630. { in the following case, we generate more efficient code when }
  631. { signed is false }
  632. if (cmp_op in [OC_EQ,OC_NE]) and
  633. (aword(a) >= $8000) and
  634. (aword(a) <= $ffff) then
  635. signed := false;
  636. if signed then
  637. if (a >= low(smallint)) and (a <= high(smallint)) Then
  638. list.concat(taicpu.op_reg_reg_const(A_CMPWI,NR_CR0,reg,a))
  639. else
  640. begin
  641. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  642. a_load_const_reg(list,OS_32,a,scratch_register);
  643. list.concat(taicpu.op_reg_reg_reg(A_CMPW,NR_CR0,reg,scratch_register));
  644. end
  645. else
  646. if (aword(a) <= $ffff) then
  647. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,NR_CR0,reg,aword(a)))
  648. else
  649. begin
  650. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  651. a_load_const_reg(list,OS_32,a,scratch_register);
  652. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,NR_CR0,reg,scratch_register));
  653. end;
  654. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  655. end;
  656. procedure tcgppc.a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;
  657. reg1,reg2 : tregister;l : tasmlabel);
  658. var
  659. op: tasmop;
  660. begin
  661. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  662. op := A_CMPW
  663. else
  664. op := A_CMPLW;
  665. list.concat(taicpu.op_reg_reg_reg(op,NR_CR0,reg2,reg1));
  666. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  667. end;
  668. procedure tcgppc.a_jmp_name(list : TAsmList;const s : string);
  669. var
  670. p : taicpu;
  671. begin
  672. if (target_info.system = system_powerpc_darwin) then
  673. p := taicpu.op_sym(A_B,get_darwin_call_stub(s))
  674. else
  675. p := taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(s));
  676. p.is_jmp := true;
  677. list.concat(p)
  678. end;
  679. procedure tcgppc.a_jmp_always(list : TAsmList;l: tasmlabel);
  680. begin
  681. a_jmp(list,A_B,C_None,0,l);
  682. end;
  683. procedure tcgppc.a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel);
  684. var
  685. c: tasmcond;
  686. begin
  687. c := flags_to_cond(f);
  688. a_jmp(list,A_BC,c.cond,c.cr-RS_CR0,l);
  689. end;
  690. procedure tcgppc.g_flags2reg(list: TAsmList; size: TCgSize; const f: TResFlags; reg: TRegister);
  691. var
  692. testbit: byte;
  693. bitvalue: boolean;
  694. begin
  695. { get the bit to extract from the conditional register + its }
  696. { requested value (0 or 1) }
  697. testbit := ((f.cr-RS_CR0) * 4);
  698. case f.flag of
  699. F_EQ,F_NE:
  700. begin
  701. inc(testbit,2);
  702. bitvalue := f.flag = F_EQ;
  703. end;
  704. F_LT,F_GE:
  705. begin
  706. bitvalue := f.flag = F_LT;
  707. end;
  708. F_GT,F_LE:
  709. begin
  710. inc(testbit);
  711. bitvalue := f.flag = F_GT;
  712. end;
  713. else
  714. internalerror(200112261);
  715. end;
  716. { load the conditional register in the destination reg }
  717. list.concat(taicpu.op_reg(A_MFCR,reg));
  718. { we will move the bit that has to be tested to bit 0 by rotating }
  719. { left }
  720. testbit := (testbit + 1) and 31;
  721. { extract bit }
  722. list.concat(taicpu.op_reg_reg_const_const_const(
  723. A_RLWINM,reg,reg,testbit,31,31));
  724. { if we need the inverse, xor with 1 }
  725. if not bitvalue then
  726. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  727. end;
  728. (*
  729. procedure tcgppc.g_cond2reg(list: TAsmList; const f: TAsmCond; reg: TRegister);
  730. var
  731. testbit: byte;
  732. bitvalue: boolean;
  733. begin
  734. { get the bit to extract from the conditional register + its }
  735. { requested value (0 or 1) }
  736. case f.simple of
  737. false:
  738. begin
  739. { we don't generate this in the compiler }
  740. internalerror(200109062);
  741. end;
  742. true:
  743. case f.cond of
  744. C_None:
  745. internalerror(200109063);
  746. C_LT..C_NU:
  747. begin
  748. testbit := (ord(f.cr) - ord(R_CR0))*4;
  749. inc(testbit,AsmCondFlag2BI[f.cond]);
  750. bitvalue := AsmCondFlagTF[f.cond];
  751. end;
  752. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  753. begin
  754. testbit := f.crbit
  755. bitvalue := AsmCondFlagTF[f.cond];
  756. end;
  757. else
  758. internalerror(200109064);
  759. end;
  760. end;
  761. { load the conditional register in the destination reg }
  762. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  763. { we will move the bit that has to be tested to bit 31 -> rotate }
  764. { left by bitpos+1 (remember, this is big-endian!) }
  765. if bitpos <> 31 then
  766. inc(bitpos)
  767. else
  768. bitpos := 0;
  769. { extract bit }
  770. list.concat(taicpu.op_reg_reg_const_const_const(
  771. A_RLWINM,reg,reg,bitpos,31,31));
  772. { if we need the inverse, xor with 1 }
  773. if not bitvalue then
  774. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  775. end;
  776. *)
  777. { *********** entry/exit code and address loading ************ }
  778. procedure tcgppc.g_save_standard_registers(list:TAsmList);
  779. begin
  780. { this work is done in g_proc_entry }
  781. end;
  782. procedure tcgppc.g_restore_standard_registers(list:TAsmList);
  783. begin
  784. { this work is done in g_proc_exit }
  785. end;
  786. procedure tcgppc.g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);
  787. { generated the entry code of a procedure/function. Note: localsize is the }
  788. { sum of the size necessary for local variables and the maximum possible }
  789. { combined size of ALL the parameters of a procedure called by the current }
  790. { one. }
  791. { This procedure may be called before, as well as after g_return_from_proc }
  792. { is called. NOTE registers are not to be allocated through the register }
  793. { allocator here, because the register colouring has already occured !! }
  794. var regcounter,firstregfpu,firstregint: TSuperRegister;
  795. href : treference;
  796. usesfpr,usesgpr,gotgot : boolean;
  797. cond : tasmcond;
  798. instr : taicpu;
  799. begin
  800. { CR and LR only have to be saved in case they are modified by the current }
  801. { procedure, but currently this isn't checked, so save them always }
  802. { following is the entry code as described in "Altivec Programming }
  803. { Interface Manual", bar the saving of AltiVec registers }
  804. a_reg_alloc(list,NR_STACK_POINTER_REG);
  805. usesgpr := false;
  806. usesfpr := false;
  807. if not(po_assembler in current_procinfo.procdef.procoptions) then
  808. begin
  809. { save link register? }
  810. if (pi_do_call in current_procinfo.flags) or
  811. ([cs_lineinfo,cs_debuginfo,cs_profile] * current_settings.moduleswitches <> []) then
  812. begin
  813. a_reg_alloc(list,NR_R0);
  814. { save return address... }
  815. { warning: if this is no longer done via r0, or if r0 is }
  816. { added to the usable registers, adapt tcgppcgen.g_profilecode }
  817. list.concat(taicpu.op_reg(A_MFLR,NR_R0));
  818. { ... in caller's frame }
  819. case target_info.abi of
  820. abi_powerpc_aix:
  821. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  822. abi_powerpc_sysv:
  823. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  824. end;
  825. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  826. if not(cs_profile in current_settings.moduleswitches) then
  827. a_reg_dealloc(list,NR_R0);
  828. end;
  829. (*
  830. { save the CR if necessary in callers frame. }
  831. if target_info.abi = abi_powerpc_aix then
  832. if false then { Not needed at the moment. }
  833. begin
  834. a_reg_alloc(list,NR_R0);
  835. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  836. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  837. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  838. a_reg_dealloc(list,NR_R0);
  839. end;
  840. *)
  841. firstregfpu := tppcprocinfo(current_procinfo).get_first_save_fpu_reg;
  842. firstregint := tppcprocinfo(current_procinfo).get_first_save_int_reg;
  843. usesgpr := firstregint <> 32;
  844. usesfpr := firstregfpu <> 32;
  845. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  846. begin
  847. a_reg_alloc(list,NR_R12);
  848. list.concat(taicpu.op_reg_reg(A_MR,NR_R12,NR_STACK_POINTER_REG));
  849. end;
  850. end;
  851. { no GOT pointer loaded yet }
  852. gotgot:=false;
  853. if usesfpr then
  854. begin
  855. { save floating-point registers
  856. if (cs_create_pic in current_settings.moduleswitches) and not(usesgpr) then
  857. begin
  858. a_call_name(current_asmdata.RefAsmSymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g'));
  859. gotgot:=true;
  860. end
  861. else
  862. a_call_name(current_asmdata.RefAsmSymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)));
  863. }
  864. reference_reset_base(href,NR_R1,-8);
  865. for regcounter:=firstregfpu to RS_F31 do
  866. begin
  867. a_loadfpu_reg_ref(list,OS_F64,OS_F64,newreg(R_FPUREGISTER,regcounter,R_SUBNONE),href);
  868. dec(href.offset,8);
  869. end;
  870. { compute start of gpr save area }
  871. inc(href.offset,4);
  872. end
  873. else
  874. { compute start of gpr save area }
  875. reference_reset_base(href,NR_R1,-4);
  876. { save gprs and fetch GOT pointer }
  877. if usesgpr then
  878. begin
  879. {
  880. if cs_create_pic in current_settings.moduleswitches then
  881. begin
  882. a_call_name(current_asmdata.RefAsmSymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g'));
  883. gotgot:=true;
  884. end
  885. else
  886. a_call_name(current_asmdata.RefAsmSymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)))
  887. }
  888. if (firstregint <= RS_R22) or
  889. ((cs_opt_size in current_settings.optimizerswitches) and
  890. { with RS_R30 it's also already smaller, but too big a speed trade-off to make }
  891. (firstregint <= RS_R29)) then
  892. begin
  893. dec(href.offset,(RS_R31-firstregint)*sizeof(aint));
  894. list.concat(taicpu.op_reg_ref(A_STMW,newreg(R_INTREGISTER,firstregint,R_SUBNONE),href));
  895. end
  896. else
  897. for regcounter:=firstregint to RS_R31 do
  898. begin
  899. a_load_reg_ref(list,OS_INT,OS_INT,newreg(R_INTREGISTER,regcounter,R_SUBNONE),href);
  900. dec(href.offset,4);
  901. end;
  902. end;
  903. { done in ncgutil because it may only be released after the parameters }
  904. { have been moved to their final resting place }
  905. { if (tppcprocinfo(current_procinfo).needs_frame_pointer) then }
  906. { a_reg_dealloc(list,NR_R12); }
  907. { if we didn't get the GOT pointer till now, we've to calculate it now }
  908. (*
  909. if not(gotgot) and (pi_needs_got in current_procinfo.flags) then
  910. case target_info.system of
  911. system_powerpc_darwin:
  912. begin
  913. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_LR));
  914. fillchar(cond,sizeof(cond),0);
  915. cond.simple:=false;
  916. cond.bo:=20;
  917. cond.bi:=31;
  918. instr:=taicpu.op_sym(A_BCL,current_procinfo.CurrGOTLabel);
  919. instr.setcondition(cond);
  920. list.concat(instr);
  921. a_label(list,current_procinfo.CurrGOTLabel);
  922. list.concat(taicpu.op_reg_reg(A_MFSPR,current_procinfo.got,NR_LR));
  923. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_LR,NR_R0));
  924. end;
  925. else
  926. begin
  927. a_reg_alloc(list,NR_R31);
  928. { place GOT ptr in r31 }
  929. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R31,NR_LR));
  930. end;
  931. end;
  932. *)
  933. if (not nostackframe) and
  934. tppcprocinfo(current_procinfo).needstackframe and
  935. (localsize <> 0) then
  936. begin
  937. if (localsize <= high(smallint)) then
  938. begin
  939. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  940. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  941. end
  942. else
  943. begin
  944. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  945. { can't use getregisterint here, the register colouring }
  946. { is already done when we get here }
  947. href.index := NR_R11;
  948. a_reg_alloc(list,href.index);
  949. a_load_const_reg(list,OS_S32,-localsize,href.index);
  950. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  951. a_reg_dealloc(list,href.index);
  952. end;
  953. end;
  954. { save the CR if necessary ( !!! never done currently ) }
  955. { still need to find out where this has to be done for SystemV
  956. a_reg_alloc(list,R_0);
  957. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  958. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  959. new_reference(STACK_POINTER_REG,LA_CR)));
  960. a_reg_dealloc(list,R_0);
  961. }
  962. { now comes the AltiVec context save, not yet implemented !!! }
  963. end;
  964. procedure tcgppc.g_proc_exit(list : TAsmList;parasize : longint;nostackframe:boolean);
  965. { This procedure may be called before, as well as after g_stackframe_entry }
  966. { is called. NOTE registers are not to be allocated through the register }
  967. { allocator here, because the register colouring has already occured !! }
  968. var
  969. regcounter,firstregfpu,firstregint: TsuperRegister;
  970. href : treference;
  971. usesfpr,usesgpr,genret : boolean;
  972. localsize: aint;
  973. begin
  974. { AltiVec context restore, not yet implemented !!! }
  975. usesfpr:=false;
  976. usesgpr:=false;
  977. if not (po_assembler in current_procinfo.procdef.procoptions) then
  978. begin
  979. firstregfpu := tppcprocinfo(current_procinfo).get_first_save_fpu_reg;
  980. firstregint := tppcprocinfo(current_procinfo).get_first_save_int_reg;
  981. usesgpr := firstregint <> 32;
  982. usesfpr := firstregfpu <> 32;
  983. end;
  984. localsize:= tppcprocinfo(current_procinfo).calc_stackframe_size;
  985. { adjust r1 }
  986. { (register allocator is no longer valid at this time and an add of 0 }
  987. { is translated into a move, which is then registered with the register }
  988. { allocator, causing a crash }
  989. if (not nostackframe) and
  990. tppcprocinfo(current_procinfo).needstackframe and
  991. (localsize <> 0) then
  992. a_op_const_reg(list,OP_ADD,OS_ADDR,localsize,NR_R1);
  993. { no return (blr) generated yet }
  994. genret:=true;
  995. if usesfpr then
  996. begin
  997. reference_reset_base(href,NR_R1,-8);
  998. for regcounter := firstregfpu to RS_F31 do
  999. begin
  1000. a_loadfpu_ref_reg(list,OS_F64,OS_F64,href,newreg(R_FPUREGISTER,regcounter,R_SUBNONE));
  1001. dec(href.offset,8);
  1002. end;
  1003. inc(href.offset,4);
  1004. end
  1005. else
  1006. reference_reset_base(href,NR_R1,-4);
  1007. if (usesgpr) then
  1008. begin
  1009. if (firstregint <= RS_R22) or
  1010. ((cs_opt_size in current_settings.optimizerswitches) and
  1011. { with RS_R30 it's also already smaller, but too big a speed trade-off to make }
  1012. (firstregint <= RS_R29)) then
  1013. begin
  1014. dec(href.offset,(RS_R31-firstregint)*sizeof(aint));
  1015. list.concat(taicpu.op_reg_ref(A_LMW,newreg(R_INTREGISTER,firstregint,R_SUBNONE),href));
  1016. end
  1017. else
  1018. for regcounter:=firstregint to RS_R31 do
  1019. begin
  1020. a_load_ref_reg(list,OS_INT,OS_INT,href,newreg(R_INTREGISTER,regcounter,R_SUBNONE));
  1021. dec(href.offset,4);
  1022. end;
  1023. end;
  1024. (*
  1025. { restore fprs and return }
  1026. if usesfpr then
  1027. begin
  1028. { address of fpr save area to r11 }
  1029. r:=NR_R12;
  1030. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1031. {
  1032. if (pi_do_call in current_procinfo.flags) then
  1033. a_call_name(current_asmdata.RefAsmSymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_x'))
  1034. else
  1035. { leaf node => lr haven't to be restored }
  1036. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+'_l');
  1037. genret:=false;
  1038. }
  1039. end;
  1040. *)
  1041. { if we didn't generate the return code, we've to do it now }
  1042. if genret then
  1043. begin
  1044. { load link register? }
  1045. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1046. begin
  1047. if (pi_do_call in current_procinfo.flags) then
  1048. begin
  1049. case target_info.abi of
  1050. abi_powerpc_aix:
  1051. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  1052. abi_powerpc_sysv:
  1053. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  1054. end;
  1055. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1056. list.concat(taicpu.op_reg(A_MTLR,NR_R0));
  1057. end;
  1058. (*
  1059. { restore the CR if necessary from callers frame}
  1060. if target_info.abi = abi_powerpc_aix then
  1061. if false then { Not needed at the moment. }
  1062. begin
  1063. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1064. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1065. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1066. a_reg_dealloc(list,NR_R0);
  1067. end;
  1068. *)
  1069. end;
  1070. list.concat(taicpu.op_none(A_BLR));
  1071. end;
  1072. end;
  1073. function tcgppc.save_regs(list : TAsmList):longint;
  1074. {Generates code which saves used non-volatile registers in
  1075. the save area right below the address the stackpointer point to.
  1076. Returns the actual used save area size.}
  1077. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1078. usesfpr,usesgpr: boolean;
  1079. href : treference;
  1080. offset: aint;
  1081. regcounter2, firstfpureg: Tsuperregister;
  1082. begin
  1083. usesfpr:=false;
  1084. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1085. begin
  1086. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1087. case target_info.abi of
  1088. abi_powerpc_aix:
  1089. firstfpureg := RS_F14;
  1090. abi_powerpc_sysv:
  1091. firstfpureg := RS_F9;
  1092. else
  1093. internalerror(2003122903);
  1094. end;
  1095. for regcounter:=firstfpureg to RS_F31 do
  1096. begin
  1097. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1098. begin
  1099. usesfpr:=true;
  1100. firstregfpu:=regcounter;
  1101. break;
  1102. end;
  1103. end;
  1104. end;
  1105. usesgpr:=false;
  1106. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1107. for regcounter2:=RS_R13 to RS_R31 do
  1108. begin
  1109. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1110. begin
  1111. usesgpr:=true;
  1112. firstreggpr:=regcounter2;
  1113. break;
  1114. end;
  1115. end;
  1116. offset:= 0;
  1117. { save floating-point registers }
  1118. if usesfpr then
  1119. for regcounter := firstregfpu to RS_F31 do
  1120. begin
  1121. offset:= offset - 8;
  1122. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1123. list.concat(taicpu.op_reg_ref(A_STFD, tregister(regcounter), href));
  1124. end;
  1125. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1126. { save gprs in gpr save area }
  1127. if usesgpr then
  1128. if firstreggpr < RS_R30 then
  1129. begin
  1130. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1131. reference_reset_base(href,NR_STACK_POINTER_REG,offset);
  1132. list.concat(taicpu.op_reg_ref(A_STMW,tregister(firstreggpr),href));
  1133. {STMW stores multiple registers}
  1134. end
  1135. else
  1136. begin
  1137. for regcounter := firstreggpr to RS_R31 do
  1138. begin
  1139. offset:= offset - 4;
  1140. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1141. list.concat(taicpu.op_reg_ref(A_STW, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1142. end;
  1143. end;
  1144. { now comes the AltiVec context save, not yet implemented !!! }
  1145. save_regs:= -offset;
  1146. end;
  1147. procedure tcgppc.restore_regs(list : TAsmList);
  1148. {Generates code which restores used non-volatile registers from
  1149. the save area right below the address the stackpointer point to.}
  1150. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1151. usesfpr,usesgpr: boolean;
  1152. href : treference;
  1153. offset: integer;
  1154. regcounter2, firstfpureg: Tsuperregister;
  1155. begin
  1156. usesfpr:=false;
  1157. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1158. begin
  1159. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1160. case target_info.abi of
  1161. abi_powerpc_aix:
  1162. firstfpureg := RS_F14;
  1163. abi_powerpc_sysv:
  1164. firstfpureg := RS_F9;
  1165. else
  1166. internalerror(2003122903);
  1167. end;
  1168. for regcounter:=firstfpureg to RS_F31 do
  1169. begin
  1170. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1171. begin
  1172. usesfpr:=true;
  1173. firstregfpu:=regcounter;
  1174. break;
  1175. end;
  1176. end;
  1177. end;
  1178. usesgpr:=false;
  1179. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1180. for regcounter2:=RS_R13 to RS_R31 do
  1181. begin
  1182. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1183. begin
  1184. usesgpr:=true;
  1185. firstreggpr:=regcounter2;
  1186. break;
  1187. end;
  1188. end;
  1189. offset:= 0;
  1190. { restore fp registers }
  1191. if usesfpr then
  1192. for regcounter := firstregfpu to RS_F31 do
  1193. begin
  1194. offset:= offset - 8;
  1195. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1196. list.concat(taicpu.op_reg_ref(A_LFD, newreg(R_FPUREGISTER,regcounter,R_SUBWHOLE), href));
  1197. end;
  1198. (* Optimiztion in the future: a_call_name(list,'_restfXX'); *)
  1199. { restore gprs }
  1200. if usesgpr then
  1201. if firstreggpr < RS_R30 then
  1202. begin
  1203. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1204. reference_reset_base(href,NR_STACK_POINTER_REG,offset); //-220
  1205. list.concat(taicpu.op_reg_ref(A_LMW,tregister(firstreggpr),href));
  1206. {LMW loads multiple registers}
  1207. end
  1208. else
  1209. begin
  1210. for regcounter := firstreggpr to RS_R31 do
  1211. begin
  1212. offset:= offset - 4;
  1213. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1214. list.concat(taicpu.op_reg_ref(A_LWZ, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1215. end;
  1216. end;
  1217. { now comes the AltiVec context restore, not yet implemented !!! }
  1218. end;
  1219. procedure tcgppc.g_stackframe_entry_mac(list : TAsmList;localsize : longint);
  1220. (* NOT IN USE *)
  1221. { generated the entry code of a procedure/function. Note: localsize is the }
  1222. { sum of the size necessary for local variables and the maximum possible }
  1223. { combined size of ALL the parameters of a procedure called by the current }
  1224. { one }
  1225. const
  1226. macosLinkageAreaSize = 24;
  1227. var
  1228. href : treference;
  1229. registerSaveAreaSize : longint;
  1230. begin
  1231. if (localsize mod 8) <> 0 then
  1232. internalerror(58991);
  1233. { CR and LR only have to be saved in case they are modified by the current }
  1234. { procedure, but currently this isn't checked, so save them always }
  1235. { following is the entry code as described in "Altivec Programming }
  1236. { Interface Manual", bar the saving of AltiVec registers }
  1237. a_reg_alloc(list,NR_STACK_POINTER_REG);
  1238. a_reg_alloc(list,NR_R0);
  1239. { save return address in callers frame}
  1240. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_LR));
  1241. { ... in caller's frame }
  1242. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1243. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1244. a_reg_dealloc(list,NR_R0);
  1245. { save non-volatile registers in callers frame}
  1246. registerSaveAreaSize:= save_regs(list);
  1247. { save the CR if necessary in callers frame ( !!! always done currently ) }
  1248. a_reg_alloc(list,NR_R0);
  1249. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  1250. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1251. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1252. a_reg_dealloc(list,NR_R0);
  1253. (*
  1254. { save pointer to incoming arguments }
  1255. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  1256. *)
  1257. (*
  1258. a_reg_alloc(list,R_12);
  1259. { 0 or 8 based on SP alignment }
  1260. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  1261. R_12,STACK_POINTER_REG,0,28,28));
  1262. { add in stack length }
  1263. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1264. -localsize));
  1265. { establish new alignment }
  1266. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1267. a_reg_dealloc(list,R_12);
  1268. *)
  1269. { allocate stack frame }
  1270. localsize:= align(localsize + macosLinkageAreaSize + registerSaveAreaSize, 16);
  1271. inc(localsize,tg.lasttemp);
  1272. localsize:=align(localsize,16);
  1273. //tppcprocinfo(current_procinfo).localsize:=localsize;
  1274. if (localsize <> 0) then
  1275. begin
  1276. if (localsize <= high(smallint)) then
  1277. begin
  1278. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  1279. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  1280. end
  1281. else
  1282. begin
  1283. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1284. href.index := NR_R11;
  1285. a_reg_alloc(list,href.index);
  1286. a_load_const_reg(list,OS_S32,-localsize,href.index);
  1287. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  1288. a_reg_dealloc(list,href.index);
  1289. end;
  1290. end;
  1291. end;
  1292. procedure tcgppc.g_return_from_proc_mac(list : TAsmList;parasize : aint);
  1293. (* NOT IN USE *)
  1294. var
  1295. href : treference;
  1296. begin
  1297. a_reg_alloc(list,NR_R0);
  1298. { restore stack pointer }
  1299. reference_reset_base(href,NR_STACK_POINTER_REG,LA_SP);
  1300. list.concat(taicpu.op_reg_ref(A_LWZ,NR_STACK_POINTER_REG,href));
  1301. (*
  1302. list.concat(taicpu.op_reg_reg_const(A_ORI,NR_STACK_POINTER_REG,R_31,0));
  1303. *)
  1304. { restore the CR if necessary from callers frame
  1305. ( !!! always done currently ) }
  1306. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1307. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1308. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1309. a_reg_dealloc(list,NR_R0);
  1310. (*
  1311. { restore return address from callers frame }
  1312. reference_reset_base(href,STACK_POINTER_REG,8);
  1313. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1314. *)
  1315. { restore non-volatile registers from callers frame }
  1316. restore_regs(list);
  1317. (*
  1318. { return to caller }
  1319. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1320. list.concat(taicpu.op_none(A_BLR));
  1321. *)
  1322. { restore return address from callers frame }
  1323. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1324. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1325. { return to caller }
  1326. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_LR));
  1327. list.concat(taicpu.op_none(A_BLR));
  1328. end;
  1329. procedure tcgppc.a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);
  1330. var
  1331. ref2, tmpref: treference;
  1332. begin
  1333. ref2 := ref;
  1334. fixref(list,ref2);
  1335. if assigned(ref2.symbol) then
  1336. begin
  1337. if target_info.system = system_powerpc_macos then
  1338. begin
  1339. if macos_direct_globals then
  1340. begin
  1341. reference_reset(tmpref);
  1342. tmpref.offset := ref2.offset;
  1343. tmpref.symbol := ref2.symbol;
  1344. tmpref.base := NR_NO;
  1345. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,NR_RTOC,tmpref));
  1346. end
  1347. else
  1348. begin
  1349. reference_reset(tmpref);
  1350. tmpref.symbol := ref2.symbol;
  1351. tmpref.offset := 0;
  1352. tmpref.base := NR_RTOC;
  1353. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref));
  1354. if ref2.offset <> 0 then
  1355. begin
  1356. reference_reset(tmpref);
  1357. tmpref.offset := ref2.offset;
  1358. tmpref.base:= r;
  1359. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1360. end;
  1361. end;
  1362. if ref2.base <> NR_NO then
  1363. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,r,ref2.base));
  1364. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1365. end
  1366. else
  1367. begin
  1368. { add the symbol's value to the base of the reference, and if the }
  1369. { reference doesn't have a base, create one }
  1370. reference_reset(tmpref);
  1371. tmpref.offset := ref2.offset;
  1372. tmpref.symbol := ref2.symbol;
  1373. tmpref.relsymbol := ref2.relsymbol;
  1374. tmpref.refaddr := addr_hi;
  1375. if ref2.base<> NR_NO then
  1376. begin
  1377. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1378. ref2.base,tmpref));
  1379. end
  1380. else
  1381. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1382. tmpref.base := NR_NO;
  1383. tmpref.refaddr := addr_lo;
  1384. { can be folded with one of the next instructions by the }
  1385. { optimizer probably }
  1386. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1387. end
  1388. end
  1389. else if ref2.offset <> 0 Then
  1390. if ref2.base <> NR_NO then
  1391. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  1392. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1393. { occurs, so now only ref.offset has to be loaded }
  1394. else
  1395. a_load_const_reg(list,OS_32,ref2.offset,r)
  1396. else if ref2.index <> NR_NO Then
  1397. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1398. else if (ref2.base <> NR_NO) and
  1399. (r <> ref2.base) then
  1400. a_load_reg_reg(list,OS_ADDR,OS_ADDR,ref2.base,r)
  1401. else
  1402. list.concat(taicpu.op_reg_const(A_LI,r,0));
  1403. end;
  1404. { ************* concatcopy ************ }
  1405. {$ifndef ppc603}
  1406. const
  1407. maxmoveunit = 8;
  1408. {$else ppc603}
  1409. const
  1410. maxmoveunit = 4;
  1411. {$endif ppc603}
  1412. procedure tcgppc.g_concatcopy(list : TAsmList;const source,dest : treference;len : aint);
  1413. var
  1414. countreg: TRegister;
  1415. src, dst: TReference;
  1416. lab: tasmlabel;
  1417. count, count2: aint;
  1418. size: tcgsize;
  1419. copyreg: tregister;
  1420. begin
  1421. {$ifdef extdebug}
  1422. if len > high(longint) then
  1423. internalerror(2002072704);
  1424. {$endif extdebug}
  1425. if (references_equal(source,dest)) then
  1426. exit;
  1427. { make sure short loads are handled as optimally as possible }
  1428. if (len <= maxmoveunit) and
  1429. (byte(len) in [1,2,4,8]) then
  1430. begin
  1431. if len < 8 then
  1432. begin
  1433. size := int_cgsize(len);
  1434. a_load_ref_ref(list,size,size,source,dest);
  1435. end
  1436. else
  1437. begin
  1438. copyreg := getfpuregister(list,OS_F64);
  1439. a_loadfpu_ref_reg(list,OS_F64,OS_F64,source,copyreg);
  1440. a_loadfpu_reg_ref(list,OS_F64,OS_F64,copyreg,dest);
  1441. end;
  1442. exit;
  1443. end;
  1444. count := len div maxmoveunit;
  1445. reference_reset(src);
  1446. reference_reset(dst);
  1447. { load the address of source into src.base }
  1448. if (count > 4) or
  1449. not issimpleref(source) or
  1450. ((source.index <> NR_NO) and
  1451. ((source.offset + longint(len)) > high(smallint))) then
  1452. begin
  1453. src.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1454. a_loadaddr_ref_reg(list,source,src.base);
  1455. end
  1456. else
  1457. begin
  1458. src := source;
  1459. end;
  1460. { load the address of dest into dst.base }
  1461. if (count > 4) or
  1462. not issimpleref(dest) or
  1463. ((dest.index <> NR_NO) and
  1464. ((dest.offset + longint(len)) > high(smallint))) then
  1465. begin
  1466. dst.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1467. a_loadaddr_ref_reg(list,dest,dst.base);
  1468. end
  1469. else
  1470. begin
  1471. dst := dest;
  1472. end;
  1473. {$ifndef ppc603}
  1474. if count > 4 then
  1475. { generate a loop }
  1476. begin
  1477. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1478. { have to be set to 8. I put an Inc there so debugging may be }
  1479. { easier (should offset be different from zero here, it will be }
  1480. { easy to notice in the generated assembler }
  1481. inc(dst.offset,8);
  1482. inc(src.offset,8);
  1483. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1484. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1485. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1486. a_load_const_reg(list,OS_32,count,countreg);
  1487. copyreg := getfpuregister(list,OS_F64);
  1488. a_reg_sync(list,copyreg);
  1489. current_asmdata.getjumplabel(lab);
  1490. a_label(list, lab);
  1491. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1492. list.concat(taicpu.op_reg_ref(A_LFDU,copyreg,src));
  1493. list.concat(taicpu.op_reg_ref(A_STFDU,copyreg,dst));
  1494. a_jmp(list,A_BC,C_NE,0,lab);
  1495. a_reg_sync(list,copyreg);
  1496. len := len mod 8;
  1497. end;
  1498. count := len div 8;
  1499. if count > 0 then
  1500. { unrolled loop }
  1501. begin
  1502. copyreg := getfpuregister(list,OS_F64);
  1503. for count2 := 1 to count do
  1504. begin
  1505. a_loadfpu_ref_reg(list,OS_F64,OS_F64,src,copyreg);
  1506. a_loadfpu_reg_ref(list,OS_F64,OS_F64,copyreg,dst);
  1507. inc(src.offset,8);
  1508. inc(dst.offset,8);
  1509. end;
  1510. len := len mod 8;
  1511. end;
  1512. if (len and 4) <> 0 then
  1513. begin
  1514. a_reg_alloc(list,NR_R0);
  1515. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1516. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1517. inc(src.offset,4);
  1518. inc(dst.offset,4);
  1519. a_reg_dealloc(list,NR_R0);
  1520. end;
  1521. {$else not ppc603}
  1522. if count > 4 then
  1523. { generate a loop }
  1524. begin
  1525. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1526. { have to be set to 4. I put an Inc there so debugging may be }
  1527. { easier (should offset be different from zero here, it will be }
  1528. { easy to notice in the generated assembler }
  1529. inc(dst.offset,4);
  1530. inc(src.offset,4);
  1531. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,4));
  1532. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,4));
  1533. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1534. a_load_const_reg(list,OS_32,count,countreg);
  1535. { explicitely allocate R_0 since it can be used safely here }
  1536. { (for holding date that's being copied) }
  1537. a_reg_alloc(list,NR_R0);
  1538. current_asmdata.getjumplabel(lab);
  1539. a_label(list, lab);
  1540. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1541. list.concat(taicpu.op_reg_ref(A_LWZU,NR_R0,src));
  1542. list.concat(taicpu.op_reg_ref(A_STWU,NR_R0,dst));
  1543. a_jmp(list,A_BC,C_NE,0,lab);
  1544. a_reg_dealloc(list,NR_R0);
  1545. len := len mod 4;
  1546. end;
  1547. count := len div 4;
  1548. if count > 0 then
  1549. { unrolled loop }
  1550. begin
  1551. a_reg_alloc(list,NR_R0);
  1552. for count2 := 1 to count do
  1553. begin
  1554. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1555. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1556. inc(src.offset,4);
  1557. inc(dst.offset,4);
  1558. end;
  1559. a_reg_dealloc(list,NR_R0);
  1560. len := len mod 4;
  1561. end;
  1562. {$endif not ppc603}
  1563. { copy the leftovers }
  1564. if (len and 2) <> 0 then
  1565. begin
  1566. a_reg_alloc(list,NR_R0);
  1567. a_load_ref_reg(list,OS_16,OS_16,src,NR_R0);
  1568. a_load_reg_ref(list,OS_16,OS_16,NR_R0,dst);
  1569. inc(src.offset,2);
  1570. inc(dst.offset,2);
  1571. a_reg_dealloc(list,NR_R0);
  1572. end;
  1573. if (len and 1) <> 0 then
  1574. begin
  1575. a_reg_alloc(list,NR_R0);
  1576. a_load_ref_reg(list,OS_8,OS_8,src,NR_R0);
  1577. a_load_reg_ref(list,OS_8,OS_8,NR_R0,dst);
  1578. a_reg_dealloc(list,NR_R0);
  1579. end;
  1580. end;
  1581. procedure tcgppc.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  1582. procedure loadvmttor11;
  1583. var
  1584. href : treference;
  1585. begin
  1586. reference_reset_base(href,NR_R3,0);
  1587. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_R11);
  1588. end;
  1589. procedure op_onr11methodaddr;
  1590. var
  1591. href : treference;
  1592. begin
  1593. if (procdef.extnumber=$ffff) then
  1594. Internalerror(200006139);
  1595. { call/jmp vmtoffs(%eax) ; method offs }
  1596. reference_reset_base(href,NR_R11,procdef._class.vmtmethodoffset(procdef.extnumber));
  1597. if not((longint(href.offset) >= low(smallint)) and
  1598. (longint(href.offset) <= high(smallint))) then
  1599. begin
  1600. list.concat(taicpu.op_reg_reg_const(A_ADDIS,NR_R11,NR_R11,
  1601. smallint((href.offset shr 16)+ord(smallint(href.offset and $ffff) < 0))));
  1602. href.offset := smallint(href.offset and $ffff);
  1603. end;
  1604. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R11,href));
  1605. list.concat(taicpu.op_reg(A_MTCTR,NR_R11));
  1606. list.concat(taicpu.op_none(A_BCTR));
  1607. end;
  1608. var
  1609. make_global : boolean;
  1610. begin
  1611. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  1612. Internalerror(200006137);
  1613. if not assigned(procdef._class) or
  1614. (procdef.procoptions*[po_classmethod, po_staticmethod,
  1615. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  1616. Internalerror(200006138);
  1617. if procdef.owner.symtabletype<>ObjectSymtable then
  1618. Internalerror(200109191);
  1619. make_global:=false;
  1620. if (not current_module.is_unit) or
  1621. (cs_create_smart in current_settings.moduleswitches) or
  1622. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  1623. make_global:=true;
  1624. if make_global then
  1625. List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0))
  1626. else
  1627. List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0));
  1628. { set param1 interface to self }
  1629. g_adjust_self_value(list,procdef,ioffset);
  1630. { case 4 }
  1631. if po_virtualmethod in procdef.procoptions then
  1632. begin
  1633. loadvmttor11;
  1634. op_onr11methodaddr;
  1635. end
  1636. { case 0 }
  1637. else
  1638. if not(target_info.system = system_powerpc_darwin) then
  1639. list.concat(taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(procdef.mangledname)))
  1640. else
  1641. list.concat(taicpu.op_sym(A_B,get_darwin_call_stub(procdef.mangledname)));
  1642. List.concat(Tai_symbol_end.Createname(labelname));
  1643. end;
  1644. {***************** This is private property, keep out! :) *****************}
  1645. function tcgppc.issimpleref(const ref: treference): boolean;
  1646. begin
  1647. if (ref.base = NR_NO) and
  1648. (ref.index <> NR_NO) then
  1649. internalerror(200208101);
  1650. result :=
  1651. not(assigned(ref.symbol)) and
  1652. (((ref.index = NR_NO) and
  1653. (ref.offset >= low(smallint)) and
  1654. (ref.offset <= high(smallint))) or
  1655. ((ref.index <> NR_NO) and
  1656. (ref.offset = 0)));
  1657. end;
  1658. function tcgppc.fixref(list: TAsmList; var ref: treference): boolean;
  1659. var
  1660. tmpreg: tregister;
  1661. begin
  1662. result := false;
  1663. if (target_info.system = system_powerpc_darwin) and
  1664. assigned(ref.symbol) and
  1665. (ref.symbol.bind = AB_EXTERNAL) then
  1666. begin
  1667. tmpreg := g_indirect_sym_load(list,ref.symbol.name);
  1668. if (ref.base = NR_NO) then
  1669. ref.base := tmpreg
  1670. else if (ref.index = NR_NO) then
  1671. ref.index := tmpreg
  1672. else
  1673. begin
  1674. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,ref.base,tmpreg));
  1675. ref.base := tmpreg;
  1676. end;
  1677. ref.symbol := nil;
  1678. end;
  1679. if (ref.base = NR_NO) then
  1680. begin
  1681. ref.base := ref.index;
  1682. ref.index := NR_NO;
  1683. end;
  1684. if (ref.base <> NR_NO) then
  1685. begin
  1686. if (ref.index <> NR_NO) and
  1687. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1688. begin
  1689. result := true;
  1690. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1691. list.concat(taicpu.op_reg_reg_reg(
  1692. A_ADD,tmpreg,ref.base,ref.index));
  1693. ref.index := NR_NO;
  1694. ref.base := tmpreg;
  1695. end
  1696. end
  1697. else
  1698. if ref.index <> NR_NO then
  1699. internalerror(200208102);
  1700. end;
  1701. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1702. { that's the case, we can use rlwinm to do an AND operation }
  1703. function tcgppc.get_rlwi_const(a: aint; var l1, l2: longint): boolean;
  1704. var
  1705. temp : longint;
  1706. testbit : aint;
  1707. compare: boolean;
  1708. begin
  1709. get_rlwi_const := false;
  1710. if (a = 0) or (a = -1) then
  1711. exit;
  1712. { start with the lowest bit }
  1713. testbit := 1;
  1714. { check its value }
  1715. compare := boolean(a and testbit);
  1716. { find out how long the run of bits with this value is }
  1717. { (it's impossible that all bits are 1 or 0, because in that case }
  1718. { this function wouldn't have been called) }
  1719. l1 := 31;
  1720. while (((a and testbit) <> 0) = compare) do
  1721. begin
  1722. testbit := testbit shl 1;
  1723. dec(l1);
  1724. end;
  1725. { check the length of the run of bits that comes next }
  1726. compare := not compare;
  1727. l2 := l1;
  1728. while (((a and testbit) <> 0) = compare) and
  1729. (l2 >= 0) do
  1730. begin
  1731. testbit := testbit shl 1;
  1732. dec(l2);
  1733. end;
  1734. { and finally the check whether the rest of the bits all have the }
  1735. { same value }
  1736. compare := not compare;
  1737. temp := l2;
  1738. if temp >= 0 then
  1739. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1740. exit;
  1741. { we have done "not(not(compare))", so compare is back to its }
  1742. { initial value. If the lowest bit was 0, a is of the form }
  1743. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1744. { because l2 now contains the position of the last zero of the }
  1745. { first run instead of that of the first 1) so switch l1 and l2 }
  1746. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1747. if not compare then
  1748. begin
  1749. temp := l1;
  1750. l1 := l2+1;
  1751. l2 := temp;
  1752. end
  1753. else
  1754. { otherwise, l1 currently contains the position of the last }
  1755. { zero instead of that of the first 1 of the second run -> +1 }
  1756. inc(l1);
  1757. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1758. l1 := l1 and 31;
  1759. l2 := l2 and 31;
  1760. get_rlwi_const := true;
  1761. end;
  1762. procedure tcgppc.a_load_store(list:TAsmList;op: tasmop;reg:tregister;
  1763. ref: treference);
  1764. var
  1765. tmpreg: tregister;
  1766. tmpref: treference;
  1767. largeOffset: Boolean;
  1768. begin
  1769. tmpreg := NR_NO;
  1770. if target_info.system = system_powerpc_macos then
  1771. begin
  1772. largeOffset:= (cardinal(ref.offset-low(smallint)) >
  1773. high(smallint)-low(smallint));
  1774. if assigned(ref.symbol) then
  1775. begin {Load symbol's value}
  1776. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1777. reference_reset(tmpref);
  1778. tmpref.symbol := ref.symbol;
  1779. tmpref.base := NR_RTOC;
  1780. if macos_direct_globals then
  1781. list.concat(taicpu.op_reg_ref(A_LA,tmpreg,tmpref))
  1782. else
  1783. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1784. end;
  1785. if largeOffset then
  1786. begin {Add hi part of offset}
  1787. reference_reset(tmpref);
  1788. if Smallint(Lo(ref.offset)) < 0 then
  1789. tmpref.offset := Hi(ref.offset) + 1 {Compensate when lo part is negative}
  1790. else
  1791. tmpref.offset := Hi(ref.offset);
  1792. if (tmpreg <> NR_NO) then
  1793. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg, tmpreg,tmpref))
  1794. else
  1795. begin
  1796. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1797. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1798. end;
  1799. end;
  1800. if (tmpreg <> NR_NO) then
  1801. begin
  1802. {Add content of base register}
  1803. if ref.base <> NR_NO then
  1804. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1805. ref.base,tmpreg));
  1806. {Make ref ready to be used by op}
  1807. ref.symbol:= nil;
  1808. ref.base:= tmpreg;
  1809. if largeOffset then
  1810. ref.offset := Smallint(Lo(ref.offset));
  1811. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1812. //list.concat(tai_comment.create(strpnew('*** a_load_store indirect global')));
  1813. end
  1814. else
  1815. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1816. end
  1817. else {if target_info.system <> system_powerpc_macos}
  1818. begin
  1819. if assigned(ref.symbol) or
  1820. (cardinal(ref.offset-low(smallint)) >
  1821. high(smallint)-low(smallint)) then
  1822. begin
  1823. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1824. reference_reset(tmpref);
  1825. tmpref.symbol := ref.symbol;
  1826. tmpref.relsymbol := ref.relsymbol;
  1827. tmpref.offset := ref.offset;
  1828. tmpref.refaddr := addr_hi;
  1829. if ref.base <> NR_NO then
  1830. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1831. ref.base,tmpref))
  1832. else
  1833. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1834. ref.base := tmpreg;
  1835. ref.refaddr := addr_lo;
  1836. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1837. end
  1838. else
  1839. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1840. end;
  1841. end;
  1842. procedure tcg64fppc.a_op64_reg_reg(list : TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);
  1843. begin
  1844. a_op64_reg_reg_reg(list,op,size,regsrc,regdst,regdst);
  1845. end;
  1846. procedure tcg64fppc.a_op64_const_reg(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;reg : tregister64);
  1847. begin
  1848. a_op64_const_reg_reg(list,op,size,value,reg,reg);
  1849. end;
  1850. procedure tcg64fppc.a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1851. begin
  1852. case op of
  1853. OP_AND,OP_OR,OP_XOR:
  1854. begin
  1855. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1856. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1857. end;
  1858. OP_ADD:
  1859. begin
  1860. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1861. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1862. end;
  1863. OP_SUB:
  1864. begin
  1865. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1866. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1867. end;
  1868. else
  1869. internalerror(2002072801);
  1870. end;
  1871. end;
  1872. procedure tcg64fppc.a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);
  1873. const
  1874. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1875. (A_SUBIC,A_SUBC,A_ADDME));
  1876. var
  1877. tmpreg: tregister;
  1878. tmpreg64: tregister64;
  1879. issub: boolean;
  1880. begin
  1881. case op of
  1882. OP_AND,OP_OR,OP_XOR:
  1883. begin
  1884. cg.a_op_const_reg_reg(list,op,OS_32,aint(value),regsrc.reglo,regdst.reglo);
  1885. cg.a_op_const_reg_reg(list,op,OS_32,aint(value shr 32),regsrc.reghi,
  1886. regdst.reghi);
  1887. end;
  1888. OP_ADD, OP_SUB:
  1889. begin
  1890. if (value < 0) and
  1891. (value <> low(value)) then
  1892. begin
  1893. if op = OP_ADD then
  1894. op := OP_SUB
  1895. else
  1896. op := OP_ADD;
  1897. value := -value;
  1898. end;
  1899. if (longint(value) <> 0) then
  1900. begin
  1901. issub := op = OP_SUB;
  1902. if (value > 0) and
  1903. (value-ord(issub) <= 32767) then
  1904. begin
  1905. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1906. regdst.reglo,regsrc.reglo,longint(value)));
  1907. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1908. regdst.reghi,regsrc.reghi));
  1909. end
  1910. else if ((value shr 32) = 0) then
  1911. begin
  1912. tmpreg := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1913. cg.a_load_const_reg(list,OS_32,aint(value),tmpreg);
  1914. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  1915. regdst.reglo,regsrc.reglo,tmpreg));
  1916. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1917. regdst.reghi,regsrc.reghi));
  1918. end
  1919. else
  1920. begin
  1921. tmpreg64.reglo := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1922. tmpreg64.reghi := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1923. a_load64_const_reg(list,value,tmpreg64);
  1924. a_op64_reg_reg_reg(list,op,size,tmpreg64,regsrc,regdst);
  1925. end
  1926. end
  1927. else
  1928. begin
  1929. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  1930. cg.a_op_const_reg_reg(list,op,OS_32,aint(value shr 32),regsrc.reghi,
  1931. regdst.reghi);
  1932. end;
  1933. end;
  1934. else
  1935. internalerror(2002072802);
  1936. end;
  1937. end;
  1938. begin
  1939. cg := tcgppc.create;
  1940. cg64 :=tcg64fppc.create;
  1941. end.