cgcpu.pas 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189
  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 ((sreg.bitlen mod 8) = 0) then
  357. begin
  358. a_load_reg_reg(list,tcgsize2unsigned[subsetsize],subsetsize,destreg,destreg);
  359. a_load_reg_reg(list,subsetsize,tosize,destreg,destreg);
  360. end;
  361. end
  362. else
  363. a_load_reg_reg(list,subsetsize,tosize,sreg.subsetreg,destreg);
  364. end;
  365. procedure tcgppc.a_load_regconst_subsetreg_intern(list : TAsmList; fromsize, subsetsize: tcgsize; fromreg: tregister; const sreg: tsubsetregister; slopt: tsubsetloadopt);
  366. begin
  367. if (slopt in [SL_SETZERO,SL_SETMAX]) then
  368. inherited a_load_regconst_subsetreg_intern(list,fromsize,subsetsize,fromreg,sreg,slopt)
  369. else if (sreg.bitlen <> sizeof(aint) * 8) then
  370. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,sreg.subsetreg,fromreg,
  371. sreg.startbit,32-sreg.startbit-sreg.bitlen,31-sreg.startbit))
  372. else
  373. a_load_reg_reg(list,fromsize,subsetsize,fromreg,sreg.subsetreg);
  374. end;
  375. procedure tcgppc.a_load_subsetreg_subsetreg(list: TAsmlist; fromsubsetsize, tosubsetsize: tcgsize; const fromsreg, tosreg: tsubsetregister);
  376. begin
  377. if (fromsreg.bitlen >= tosreg.bitlen) then
  378. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,tosreg.subsetreg, fromsreg.subsetreg,
  379. (tosreg.startbit-fromsreg.startbit) and 31,
  380. 32-tosreg.startbit-tosreg.bitlen,31-tosreg.startbit))
  381. else
  382. inherited a_load_subsetreg_subsetreg(list,fromsubsetsize,tosubsetsize,fromsreg,tosreg);
  383. end;
  384. procedure tcgppc.a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister);
  385. begin
  386. a_op_const_reg_reg(list,op,size,a,reg,reg);
  387. end;
  388. procedure tcgppc.a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  389. begin
  390. a_op_reg_reg_reg(list,op,size,src,dst,dst);
  391. end;
  392. procedure tcgppc.maybeadjustresult(list: TAsmList; op: TOpCg; size: tcgsize; dst: tregister);
  393. const
  394. overflowops = [OP_MUL,OP_SHL,OP_ADD,OP_SUB,OP_NOT,OP_NEG];
  395. begin
  396. if (op in overflowops) and
  397. (size in [OS_8,OS_S8,OS_16,OS_S16]) then
  398. a_load_reg_reg(list,OS_32,size,dst,dst);
  399. end;
  400. procedure tcgppc.a_op_const_reg_reg(list: TAsmList; op: TOpCg;
  401. size: tcgsize; a: aint; src, dst: tregister);
  402. var
  403. l1,l2: longint;
  404. oplo, ophi: tasmop;
  405. scratchreg: tregister;
  406. useReg, gotrlwi: boolean;
  407. procedure do_lo_hi;
  408. begin
  409. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  410. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  411. end;
  412. begin
  413. if (op = OP_MOVE) then
  414. internalerror(2006031401);
  415. if op = OP_SUB then
  416. begin
  417. a_op_const_reg_reg(list,OP_ADD,size,-a,src,dst);
  418. exit;
  419. end;
  420. ophi := TOpCG2AsmOpConstHi[op];
  421. oplo := TOpCG2AsmOpConstLo[op];
  422. gotrlwi := get_rlwi_const(a,l1,l2);
  423. if (op in [OP_AND,OP_OR,OP_XOR]) then
  424. begin
  425. if (a = 0) then
  426. begin
  427. if op = OP_AND then
  428. list.concat(taicpu.op_reg_const(A_LI,dst,0))
  429. else
  430. a_load_reg_reg(list,size,size,src,dst);
  431. exit;
  432. end
  433. else if (a = -1) then
  434. begin
  435. case op of
  436. OP_OR:
  437. case size of
  438. OS_8, OS_S8:
  439. list.concat(taicpu.op_reg_const(A_LI,dst,255));
  440. OS_16, OS_S16:
  441. a_load_const_reg(list,OS_16,65535,dst);
  442. else
  443. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  444. end;
  445. OP_XOR:
  446. case size of
  447. OS_8, OS_S8:
  448. list.concat(taicpu.op_reg_reg_const(A_XORI,dst,src,255));
  449. OS_16, OS_S16:
  450. list.concat(taicpu.op_reg_reg_const(A_XORI,dst,src,65535));
  451. else
  452. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  453. end;
  454. OP_AND:
  455. a_load_reg_reg(list,size,size,src,dst);
  456. end;
  457. exit;
  458. end
  459. else if (aword(a) <= high(word)) and
  460. ((op <> OP_AND) or
  461. not gotrlwi) then
  462. begin
  463. if ((size = OS_8) and
  464. (byte(a) <> a)) or
  465. ((size = OS_S8) and
  466. (shortint(a) <> a)) then
  467. internalerror(200604142);
  468. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  469. { and/or/xor -> cannot overflow in high 16 bits }
  470. exit;
  471. end;
  472. { all basic constant instructions also have a shifted form that }
  473. { works only on the highest 16bits, so if lo(a) is 0, we can }
  474. { use that one }
  475. if (word(a) = 0) and
  476. (not(op = OP_AND) or
  477. not gotrlwi) then
  478. begin
  479. if (size in [OS_8,OS_S8,OS_16,OS_S16]) then
  480. internalerror(200604141);
  481. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  482. exit;
  483. end;
  484. end
  485. else if (op = OP_ADD) then
  486. if a = 0 then
  487. begin
  488. a_load_reg_reg(list,size,size,src,dst);
  489. exit
  490. end
  491. else if (a >= low(smallint)) and
  492. (a <= high(smallint)) then
  493. begin
  494. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  495. maybeadjustresult(list,op,size,dst);
  496. exit;
  497. end;
  498. { otherwise, the instructions we can generate depend on the }
  499. { operation }
  500. useReg := false;
  501. case op of
  502. OP_DIV,OP_IDIV:
  503. if (a = 0) then
  504. internalerror(200208103)
  505. else if (a = 1) then
  506. begin
  507. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  508. exit
  509. end
  510. else if ispowerof2(a,l1) then
  511. begin
  512. case op of
  513. OP_DIV:
  514. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  515. OP_IDIV:
  516. begin
  517. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  518. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  519. end;
  520. end;
  521. exit;
  522. end
  523. else
  524. usereg := true;
  525. OP_IMUL, OP_MUL:
  526. if (a = 0) then
  527. begin
  528. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  529. exit
  530. end
  531. else if (a = 1) then
  532. begin
  533. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  534. exit
  535. end
  536. else if ispowerof2(a,l1) then
  537. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  538. else if (longint(a) >= low(smallint)) and
  539. (longint(a) <= high(smallint)) then
  540. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  541. else
  542. usereg := true;
  543. OP_ADD:
  544. begin
  545. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  546. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  547. smallint((a shr 16) + ord(smallint(a) < 0))));
  548. end;
  549. OP_OR:
  550. { try to use rlwimi }
  551. if gotrlwi and
  552. (src = dst) then
  553. begin
  554. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  555. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  556. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  557. scratchreg,0,l1,l2));
  558. end
  559. else
  560. do_lo_hi;
  561. OP_AND:
  562. { try to use rlwinm }
  563. if gotrlwi then
  564. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  565. src,0,l1,l2))
  566. else
  567. useReg := true;
  568. OP_XOR:
  569. do_lo_hi;
  570. OP_SHL,OP_SHR,OP_SAR:
  571. begin
  572. if (a and 31) <> 0 Then
  573. list.concat(taicpu.op_reg_reg_const(
  574. TOpCG2AsmOpConstLo[Op],dst,src,a and 31))
  575. else
  576. a_load_reg_reg(list,size,size,src,dst);
  577. if (a shr 5) <> 0 then
  578. internalError(68991);
  579. end
  580. else
  581. internalerror(200109091);
  582. end;
  583. { if all else failed, load the constant in a register and then }
  584. { perform the operation }
  585. if useReg then
  586. begin
  587. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  588. a_load_const_reg(list,OS_32,a,scratchreg);
  589. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  590. end;
  591. maybeadjustresult(list,op,size,dst);
  592. end;
  593. procedure tcgppc.a_op_reg_reg_reg(list: TAsmList; op: TOpCg;
  594. size: tcgsize; src1, src2, dst: tregister);
  595. const
  596. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  597. (A_NONE,A_MR,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  598. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  599. begin
  600. if (op = OP_MOVE) then
  601. internalerror(2006031402);
  602. case op of
  603. OP_NEG,OP_NOT:
  604. begin
  605. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,src1));
  606. if (op = OP_NOT) and
  607. not(size in [OS_32,OS_S32]) then
  608. { zero/sign extend result again }
  609. a_load_reg_reg(list,OS_32,size,dst,dst);
  610. end;
  611. else
  612. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  613. end;
  614. maybeadjustresult(list,op,size,dst);
  615. end;
  616. {*************** compare instructructions ****************}
  617. procedure tcgppc.a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  618. l : tasmlabel);
  619. var
  620. scratch_register: TRegister;
  621. signed: boolean;
  622. begin
  623. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE,OC_EQ,OC_NE];
  624. { in the following case, we generate more efficient code when }
  625. { signed is false }
  626. if (cmp_op in [OC_EQ,OC_NE]) and
  627. (aword(a) >= $8000) and
  628. (aword(a) <= $ffff) then
  629. signed := false;
  630. if signed then
  631. if (a >= low(smallint)) and (a <= high(smallint)) Then
  632. list.concat(taicpu.op_reg_reg_const(A_CMPWI,NR_CR0,reg,a))
  633. else
  634. begin
  635. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  636. a_load_const_reg(list,OS_32,a,scratch_register);
  637. list.concat(taicpu.op_reg_reg_reg(A_CMPW,NR_CR0,reg,scratch_register));
  638. end
  639. else
  640. if (aword(a) <= $ffff) then
  641. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,NR_CR0,reg,aword(a)))
  642. else
  643. begin
  644. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  645. a_load_const_reg(list,OS_32,a,scratch_register);
  646. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,NR_CR0,reg,scratch_register));
  647. end;
  648. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  649. end;
  650. procedure tcgppc.a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;
  651. reg1,reg2 : tregister;l : tasmlabel);
  652. var
  653. op: tasmop;
  654. begin
  655. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  656. op := A_CMPW
  657. else
  658. op := A_CMPLW;
  659. list.concat(taicpu.op_reg_reg_reg(op,NR_CR0,reg2,reg1));
  660. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  661. end;
  662. procedure tcgppc.a_jmp_name(list : TAsmList;const s : string);
  663. var
  664. p : taicpu;
  665. begin
  666. if (target_info.system = system_powerpc_darwin) then
  667. p := taicpu.op_sym(A_B,get_darwin_call_stub(s))
  668. else
  669. p := taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(s));
  670. p.is_jmp := true;
  671. list.concat(p)
  672. end;
  673. procedure tcgppc.a_jmp_always(list : TAsmList;l: tasmlabel);
  674. begin
  675. a_jmp(list,A_B,C_None,0,l);
  676. end;
  677. procedure tcgppc.a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel);
  678. var
  679. c: tasmcond;
  680. begin
  681. c := flags_to_cond(f);
  682. a_jmp(list,A_BC,c.cond,c.cr-RS_CR0,l);
  683. end;
  684. procedure tcgppc.g_flags2reg(list: TAsmList; size: TCgSize; const f: TResFlags; reg: TRegister);
  685. var
  686. testbit: byte;
  687. bitvalue: boolean;
  688. begin
  689. { get the bit to extract from the conditional register + its }
  690. { requested value (0 or 1) }
  691. testbit := ((f.cr-RS_CR0) * 4);
  692. case f.flag of
  693. F_EQ,F_NE:
  694. begin
  695. inc(testbit,2);
  696. bitvalue := f.flag = F_EQ;
  697. end;
  698. F_LT,F_GE:
  699. begin
  700. bitvalue := f.flag = F_LT;
  701. end;
  702. F_GT,F_LE:
  703. begin
  704. inc(testbit);
  705. bitvalue := f.flag = F_GT;
  706. end;
  707. else
  708. internalerror(200112261);
  709. end;
  710. { load the conditional register in the destination reg }
  711. list.concat(taicpu.op_reg(A_MFCR,reg));
  712. { we will move the bit that has to be tested to bit 0 by rotating }
  713. { left }
  714. testbit := (testbit + 1) and 31;
  715. { extract bit }
  716. list.concat(taicpu.op_reg_reg_const_const_const(
  717. A_RLWINM,reg,reg,testbit,31,31));
  718. { if we need the inverse, xor with 1 }
  719. if not bitvalue then
  720. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  721. end;
  722. (*
  723. procedure tcgppc.g_cond2reg(list: TAsmList; const f: TAsmCond; reg: TRegister);
  724. var
  725. testbit: byte;
  726. bitvalue: boolean;
  727. begin
  728. { get the bit to extract from the conditional register + its }
  729. { requested value (0 or 1) }
  730. case f.simple of
  731. false:
  732. begin
  733. { we don't generate this in the compiler }
  734. internalerror(200109062);
  735. end;
  736. true:
  737. case f.cond of
  738. C_None:
  739. internalerror(200109063);
  740. C_LT..C_NU:
  741. begin
  742. testbit := (ord(f.cr) - ord(R_CR0))*4;
  743. inc(testbit,AsmCondFlag2BI[f.cond]);
  744. bitvalue := AsmCondFlagTF[f.cond];
  745. end;
  746. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  747. begin
  748. testbit := f.crbit
  749. bitvalue := AsmCondFlagTF[f.cond];
  750. end;
  751. else
  752. internalerror(200109064);
  753. end;
  754. end;
  755. { load the conditional register in the destination reg }
  756. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  757. { we will move the bit that has to be tested to bit 31 -> rotate }
  758. { left by bitpos+1 (remember, this is big-endian!) }
  759. if bitpos <> 31 then
  760. inc(bitpos)
  761. else
  762. bitpos := 0;
  763. { extract bit }
  764. list.concat(taicpu.op_reg_reg_const_const_const(
  765. A_RLWINM,reg,reg,bitpos,31,31));
  766. { if we need the inverse, xor with 1 }
  767. if not bitvalue then
  768. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  769. end;
  770. *)
  771. { *********** entry/exit code and address loading ************ }
  772. procedure tcgppc.g_save_standard_registers(list:TAsmList);
  773. begin
  774. { this work is done in g_proc_entry }
  775. end;
  776. procedure tcgppc.g_restore_standard_registers(list:TAsmList);
  777. begin
  778. { this work is done in g_proc_exit }
  779. end;
  780. procedure tcgppc.g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);
  781. { generated the entry code of a procedure/function. Note: localsize is the }
  782. { sum of the size necessary for local variables and the maximum possible }
  783. { combined size of ALL the parameters of a procedure called by the current }
  784. { one. }
  785. { This procedure may be called before, as well as after g_return_from_proc }
  786. { is called. NOTE registers are not to be allocated through the register }
  787. { allocator here, because the register colouring has already occured !! }
  788. var regcounter,firstregfpu,firstregint: TSuperRegister;
  789. href : treference;
  790. usesfpr,usesgpr,gotgot : boolean;
  791. cond : tasmcond;
  792. instr : taicpu;
  793. begin
  794. { CR and LR only have to be saved in case they are modified by the current }
  795. { procedure, but currently this isn't checked, so save them always }
  796. { following is the entry code as described in "Altivec Programming }
  797. { Interface Manual", bar the saving of AltiVec registers }
  798. a_reg_alloc(list,NR_STACK_POINTER_REG);
  799. usesgpr := false;
  800. usesfpr := false;
  801. if not(po_assembler in current_procinfo.procdef.procoptions) then
  802. begin
  803. { save link register? }
  804. if (pi_do_call in current_procinfo.flags) or
  805. ([cs_lineinfo,cs_debuginfo,cs_profile] * current_settings.moduleswitches <> []) then
  806. begin
  807. a_reg_alloc(list,NR_R0);
  808. { save return address... }
  809. { warning: if this is no longer done via r0, or if r0 is }
  810. { added to the usable registers, adapt tcgppcgen.g_profilecode }
  811. list.concat(taicpu.op_reg(A_MFLR,NR_R0));
  812. { ... in caller's frame }
  813. case target_info.abi of
  814. abi_powerpc_aix:
  815. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  816. abi_powerpc_sysv:
  817. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  818. end;
  819. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  820. if not(cs_profile in current_settings.moduleswitches) then
  821. a_reg_dealloc(list,NR_R0);
  822. end;
  823. (*
  824. { save the CR if necessary in callers frame. }
  825. if target_info.abi = abi_powerpc_aix then
  826. if false then { Not needed at the moment. }
  827. begin
  828. a_reg_alloc(list,NR_R0);
  829. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  830. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  831. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  832. a_reg_dealloc(list,NR_R0);
  833. end;
  834. *)
  835. firstregfpu := tppcprocinfo(current_procinfo).get_first_save_fpu_reg;
  836. firstregint := tppcprocinfo(current_procinfo).get_first_save_int_reg;
  837. usesgpr := firstregint <> 32;
  838. usesfpr := firstregfpu <> 32;
  839. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  840. begin
  841. a_reg_alloc(list,NR_R12);
  842. list.concat(taicpu.op_reg_reg(A_MR,NR_R12,NR_STACK_POINTER_REG));
  843. end;
  844. end;
  845. { no GOT pointer loaded yet }
  846. gotgot:=false;
  847. if usesfpr then
  848. begin
  849. { save floating-point registers
  850. if (cs_create_pic in current_settings.moduleswitches) and not(usesgpr) then
  851. begin
  852. a_call_name(current_asmdata.RefAsmSymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g'));
  853. gotgot:=true;
  854. end
  855. else
  856. a_call_name(current_asmdata.RefAsmSymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)));
  857. }
  858. reference_reset_base(href,NR_R1,-8);
  859. for regcounter:=firstregfpu to RS_F31 do
  860. begin
  861. a_loadfpu_reg_ref(list,OS_F64,OS_F64,newreg(R_FPUREGISTER,regcounter,R_SUBNONE),href);
  862. dec(href.offset,8);
  863. end;
  864. { compute start of gpr save area }
  865. inc(href.offset,4);
  866. end
  867. else
  868. { compute start of gpr save area }
  869. reference_reset_base(href,NR_R1,-4);
  870. { save gprs and fetch GOT pointer }
  871. if usesgpr then
  872. begin
  873. {
  874. if cs_create_pic in current_settings.moduleswitches then
  875. begin
  876. a_call_name(current_asmdata.RefAsmSymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g'));
  877. gotgot:=true;
  878. end
  879. else
  880. a_call_name(current_asmdata.RefAsmSymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)))
  881. }
  882. if (firstregint <= RS_R22) or
  883. ((cs_opt_size in current_settings.optimizerswitches) and
  884. { with RS_R30 it's also already smaller, but too big a speed trade-off to make }
  885. (firstregint <= RS_R29)) then
  886. begin
  887. dec(href.offset,(RS_R31-firstregint)*sizeof(aint));
  888. list.concat(taicpu.op_reg_ref(A_STMW,newreg(R_INTREGISTER,firstregint,R_SUBNONE),href));
  889. end
  890. else
  891. for regcounter:=firstregint to RS_R31 do
  892. begin
  893. a_load_reg_ref(list,OS_INT,OS_INT,newreg(R_INTREGISTER,regcounter,R_SUBNONE),href);
  894. dec(href.offset,4);
  895. end;
  896. end;
  897. { done in ncgutil because it may only be released after the parameters }
  898. { have been moved to their final resting place }
  899. { if (tppcprocinfo(current_procinfo).needs_frame_pointer) then }
  900. { a_reg_dealloc(list,NR_R12); }
  901. { if we didn't get the GOT pointer till now, we've to calculate it now }
  902. (*
  903. if not(gotgot) and (pi_needs_got in current_procinfo.flags) then
  904. case target_info.system of
  905. system_powerpc_darwin:
  906. begin
  907. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_LR));
  908. fillchar(cond,sizeof(cond),0);
  909. cond.simple:=false;
  910. cond.bo:=20;
  911. cond.bi:=31;
  912. instr:=taicpu.op_sym(A_BCL,current_procinfo.CurrGOTLabel);
  913. instr.setcondition(cond);
  914. list.concat(instr);
  915. a_label(list,current_procinfo.CurrGOTLabel);
  916. list.concat(taicpu.op_reg_reg(A_MFSPR,current_procinfo.got,NR_LR));
  917. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_LR,NR_R0));
  918. end;
  919. else
  920. begin
  921. a_reg_alloc(list,NR_R31);
  922. { place GOT ptr in r31 }
  923. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R31,NR_LR));
  924. end;
  925. end;
  926. *)
  927. if (not nostackframe) and
  928. tppcprocinfo(current_procinfo).needstackframe and
  929. (localsize <> 0) then
  930. begin
  931. if (localsize <= high(smallint)) then
  932. begin
  933. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  934. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  935. end
  936. else
  937. begin
  938. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  939. { can't use getregisterint here, the register colouring }
  940. { is already done when we get here }
  941. href.index := NR_R11;
  942. a_reg_alloc(list,href.index);
  943. a_load_const_reg(list,OS_S32,-localsize,href.index);
  944. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  945. a_reg_dealloc(list,href.index);
  946. end;
  947. end;
  948. { save the CR if necessary ( !!! never done currently ) }
  949. { still need to find out where this has to be done for SystemV
  950. a_reg_alloc(list,R_0);
  951. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  952. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  953. new_reference(STACK_POINTER_REG,LA_CR)));
  954. a_reg_dealloc(list,R_0);
  955. }
  956. { now comes the AltiVec context save, not yet implemented !!! }
  957. end;
  958. procedure tcgppc.g_proc_exit(list : TAsmList;parasize : longint;nostackframe:boolean);
  959. { This procedure may be called before, as well as after g_stackframe_entry }
  960. { is called. NOTE registers are not to be allocated through the register }
  961. { allocator here, because the register colouring has already occured !! }
  962. var
  963. regcounter,firstregfpu,firstregint: TsuperRegister;
  964. href : treference;
  965. usesfpr,usesgpr,genret : boolean;
  966. localsize: aint;
  967. begin
  968. { AltiVec context restore, not yet implemented !!! }
  969. usesfpr:=false;
  970. usesgpr:=false;
  971. if not (po_assembler in current_procinfo.procdef.procoptions) then
  972. begin
  973. firstregfpu := tppcprocinfo(current_procinfo).get_first_save_fpu_reg;
  974. firstregint := tppcprocinfo(current_procinfo).get_first_save_int_reg;
  975. usesgpr := firstregint <> 32;
  976. usesfpr := firstregfpu <> 32;
  977. end;
  978. localsize:= tppcprocinfo(current_procinfo).calc_stackframe_size;
  979. { adjust r1 }
  980. { (register allocator is no longer valid at this time and an add of 0 }
  981. { is translated into a move, which is then registered with the register }
  982. { allocator, causing a crash }
  983. if (not nostackframe) and
  984. tppcprocinfo(current_procinfo).needstackframe and
  985. (localsize <> 0) then
  986. a_op_const_reg(list,OP_ADD,OS_ADDR,localsize,NR_R1);
  987. { no return (blr) generated yet }
  988. genret:=true;
  989. if usesfpr then
  990. begin
  991. reference_reset_base(href,NR_R1,-8);
  992. for regcounter := firstregfpu to RS_F31 do
  993. begin
  994. a_loadfpu_ref_reg(list,OS_F64,OS_F64,href,newreg(R_FPUREGISTER,regcounter,R_SUBNONE));
  995. dec(href.offset,8);
  996. end;
  997. inc(href.offset,4);
  998. end
  999. else
  1000. reference_reset_base(href,NR_R1,-4);
  1001. if (usesgpr) then
  1002. begin
  1003. if (firstregint <= RS_R22) or
  1004. ((cs_opt_size in current_settings.optimizerswitches) and
  1005. { with RS_R30 it's also already smaller, but too big a speed trade-off to make }
  1006. (firstregint <= RS_R29)) then
  1007. begin
  1008. dec(href.offset,(RS_R31-firstregint)*sizeof(aint));
  1009. list.concat(taicpu.op_reg_ref(A_LMW,newreg(R_INTREGISTER,firstregint,R_SUBNONE),href));
  1010. end
  1011. else
  1012. for regcounter:=firstregint to RS_R31 do
  1013. begin
  1014. a_load_ref_reg(list,OS_INT,OS_INT,href,newreg(R_INTREGISTER,regcounter,R_SUBNONE));
  1015. dec(href.offset,4);
  1016. end;
  1017. end;
  1018. (*
  1019. { restore fprs and return }
  1020. if usesfpr then
  1021. begin
  1022. { address of fpr save area to r11 }
  1023. r:=NR_R12;
  1024. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1025. {
  1026. if (pi_do_call in current_procinfo.flags) then
  1027. a_call_name(current_asmdata.RefAsmSymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_x'))
  1028. else
  1029. { leaf node => lr haven't to be restored }
  1030. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+'_l');
  1031. genret:=false;
  1032. }
  1033. end;
  1034. *)
  1035. { if we didn't generate the return code, we've to do it now }
  1036. if genret then
  1037. begin
  1038. { load link register? }
  1039. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1040. begin
  1041. if (pi_do_call in current_procinfo.flags) then
  1042. begin
  1043. case target_info.abi of
  1044. abi_powerpc_aix:
  1045. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  1046. abi_powerpc_sysv:
  1047. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  1048. end;
  1049. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1050. list.concat(taicpu.op_reg(A_MTLR,NR_R0));
  1051. end;
  1052. (*
  1053. { restore the CR if necessary from callers frame}
  1054. if target_info.abi = abi_powerpc_aix then
  1055. if false then { Not needed at the moment. }
  1056. begin
  1057. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1058. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1059. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1060. a_reg_dealloc(list,NR_R0);
  1061. end;
  1062. *)
  1063. end;
  1064. list.concat(taicpu.op_none(A_BLR));
  1065. end;
  1066. end;
  1067. function tcgppc.save_regs(list : TAsmList):longint;
  1068. {Generates code which saves used non-volatile registers in
  1069. the save area right below the address the stackpointer point to.
  1070. Returns the actual used save area size.}
  1071. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1072. usesfpr,usesgpr: boolean;
  1073. href : treference;
  1074. offset: aint;
  1075. regcounter2, firstfpureg: Tsuperregister;
  1076. begin
  1077. usesfpr:=false;
  1078. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1079. begin
  1080. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1081. case target_info.abi of
  1082. abi_powerpc_aix:
  1083. firstfpureg := RS_F14;
  1084. abi_powerpc_sysv:
  1085. firstfpureg := RS_F9;
  1086. else
  1087. internalerror(2003122903);
  1088. end;
  1089. for regcounter:=firstfpureg to RS_F31 do
  1090. begin
  1091. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1092. begin
  1093. usesfpr:=true;
  1094. firstregfpu:=regcounter;
  1095. break;
  1096. end;
  1097. end;
  1098. end;
  1099. usesgpr:=false;
  1100. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1101. for regcounter2:=RS_R13 to RS_R31 do
  1102. begin
  1103. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1104. begin
  1105. usesgpr:=true;
  1106. firstreggpr:=regcounter2;
  1107. break;
  1108. end;
  1109. end;
  1110. offset:= 0;
  1111. { save floating-point registers }
  1112. if usesfpr then
  1113. for regcounter := firstregfpu to RS_F31 do
  1114. begin
  1115. offset:= offset - 8;
  1116. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1117. list.concat(taicpu.op_reg_ref(A_STFD, tregister(regcounter), href));
  1118. end;
  1119. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1120. { save gprs in gpr save area }
  1121. if usesgpr then
  1122. if firstreggpr < RS_R30 then
  1123. begin
  1124. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1125. reference_reset_base(href,NR_STACK_POINTER_REG,offset);
  1126. list.concat(taicpu.op_reg_ref(A_STMW,tregister(firstreggpr),href));
  1127. {STMW stores multiple registers}
  1128. end
  1129. else
  1130. begin
  1131. for regcounter := firstreggpr to RS_R31 do
  1132. begin
  1133. offset:= offset - 4;
  1134. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1135. list.concat(taicpu.op_reg_ref(A_STW, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1136. end;
  1137. end;
  1138. { now comes the AltiVec context save, not yet implemented !!! }
  1139. save_regs:= -offset;
  1140. end;
  1141. procedure tcgppc.restore_regs(list : TAsmList);
  1142. {Generates code which restores used non-volatile registers from
  1143. the save area right below the address the stackpointer point to.}
  1144. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1145. usesfpr,usesgpr: boolean;
  1146. href : treference;
  1147. offset: integer;
  1148. regcounter2, firstfpureg: Tsuperregister;
  1149. begin
  1150. usesfpr:=false;
  1151. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1152. begin
  1153. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1154. case target_info.abi of
  1155. abi_powerpc_aix:
  1156. firstfpureg := RS_F14;
  1157. abi_powerpc_sysv:
  1158. firstfpureg := RS_F9;
  1159. else
  1160. internalerror(2003122903);
  1161. end;
  1162. for regcounter:=firstfpureg to RS_F31 do
  1163. begin
  1164. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1165. begin
  1166. usesfpr:=true;
  1167. firstregfpu:=regcounter;
  1168. break;
  1169. end;
  1170. end;
  1171. end;
  1172. usesgpr:=false;
  1173. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1174. for regcounter2:=RS_R13 to RS_R31 do
  1175. begin
  1176. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1177. begin
  1178. usesgpr:=true;
  1179. firstreggpr:=regcounter2;
  1180. break;
  1181. end;
  1182. end;
  1183. offset:= 0;
  1184. { restore fp registers }
  1185. if usesfpr then
  1186. for regcounter := firstregfpu to RS_F31 do
  1187. begin
  1188. offset:= offset - 8;
  1189. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1190. list.concat(taicpu.op_reg_ref(A_LFD, newreg(R_FPUREGISTER,regcounter,R_SUBWHOLE), href));
  1191. end;
  1192. (* Optimiztion in the future: a_call_name(list,'_restfXX'); *)
  1193. { restore gprs }
  1194. if usesgpr then
  1195. if firstreggpr < RS_R30 then
  1196. begin
  1197. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1198. reference_reset_base(href,NR_STACK_POINTER_REG,offset); //-220
  1199. list.concat(taicpu.op_reg_ref(A_LMW,tregister(firstreggpr),href));
  1200. {LMW loads multiple registers}
  1201. end
  1202. else
  1203. begin
  1204. for regcounter := firstreggpr to RS_R31 do
  1205. begin
  1206. offset:= offset - 4;
  1207. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1208. list.concat(taicpu.op_reg_ref(A_LWZ, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1209. end;
  1210. end;
  1211. { now comes the AltiVec context restore, not yet implemented !!! }
  1212. end;
  1213. procedure tcgppc.g_stackframe_entry_mac(list : TAsmList;localsize : longint);
  1214. (* NOT IN USE *)
  1215. { generated the entry code of a procedure/function. Note: localsize is the }
  1216. { sum of the size necessary for local variables and the maximum possible }
  1217. { combined size of ALL the parameters of a procedure called by the current }
  1218. { one }
  1219. const
  1220. macosLinkageAreaSize = 24;
  1221. var
  1222. href : treference;
  1223. registerSaveAreaSize : longint;
  1224. begin
  1225. if (localsize mod 8) <> 0 then
  1226. internalerror(58991);
  1227. { CR and LR only have to be saved in case they are modified by the current }
  1228. { procedure, but currently this isn't checked, so save them always }
  1229. { following is the entry code as described in "Altivec Programming }
  1230. { Interface Manual", bar the saving of AltiVec registers }
  1231. a_reg_alloc(list,NR_STACK_POINTER_REG);
  1232. a_reg_alloc(list,NR_R0);
  1233. { save return address in callers frame}
  1234. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_LR));
  1235. { ... in caller's frame }
  1236. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1237. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1238. a_reg_dealloc(list,NR_R0);
  1239. { save non-volatile registers in callers frame}
  1240. registerSaveAreaSize:= save_regs(list);
  1241. { save the CR if necessary in callers frame ( !!! always done currently ) }
  1242. a_reg_alloc(list,NR_R0);
  1243. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  1244. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1245. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1246. a_reg_dealloc(list,NR_R0);
  1247. (*
  1248. { save pointer to incoming arguments }
  1249. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  1250. *)
  1251. (*
  1252. a_reg_alloc(list,R_12);
  1253. { 0 or 8 based on SP alignment }
  1254. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  1255. R_12,STACK_POINTER_REG,0,28,28));
  1256. { add in stack length }
  1257. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1258. -localsize));
  1259. { establish new alignment }
  1260. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1261. a_reg_dealloc(list,R_12);
  1262. *)
  1263. { allocate stack frame }
  1264. localsize:= align(localsize + macosLinkageAreaSize + registerSaveAreaSize, 16);
  1265. inc(localsize,tg.lasttemp);
  1266. localsize:=align(localsize,16);
  1267. //tppcprocinfo(current_procinfo).localsize:=localsize;
  1268. if (localsize <> 0) then
  1269. begin
  1270. if (localsize <= high(smallint)) then
  1271. begin
  1272. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  1273. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  1274. end
  1275. else
  1276. begin
  1277. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1278. href.index := NR_R11;
  1279. a_reg_alloc(list,href.index);
  1280. a_load_const_reg(list,OS_S32,-localsize,href.index);
  1281. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  1282. a_reg_dealloc(list,href.index);
  1283. end;
  1284. end;
  1285. end;
  1286. procedure tcgppc.g_return_from_proc_mac(list : TAsmList;parasize : aint);
  1287. (* NOT IN USE *)
  1288. var
  1289. href : treference;
  1290. begin
  1291. a_reg_alloc(list,NR_R0);
  1292. { restore stack pointer }
  1293. reference_reset_base(href,NR_STACK_POINTER_REG,LA_SP);
  1294. list.concat(taicpu.op_reg_ref(A_LWZ,NR_STACK_POINTER_REG,href));
  1295. (*
  1296. list.concat(taicpu.op_reg_reg_const(A_ORI,NR_STACK_POINTER_REG,R_31,0));
  1297. *)
  1298. { restore the CR if necessary from callers frame
  1299. ( !!! always done currently ) }
  1300. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1301. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1302. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1303. a_reg_dealloc(list,NR_R0);
  1304. (*
  1305. { restore return address from callers frame }
  1306. reference_reset_base(href,STACK_POINTER_REG,8);
  1307. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1308. *)
  1309. { restore non-volatile registers from callers frame }
  1310. restore_regs(list);
  1311. (*
  1312. { return to caller }
  1313. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1314. list.concat(taicpu.op_none(A_BLR));
  1315. *)
  1316. { restore return address from callers frame }
  1317. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1318. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1319. { return to caller }
  1320. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_LR));
  1321. list.concat(taicpu.op_none(A_BLR));
  1322. end;
  1323. procedure tcgppc.a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);
  1324. var
  1325. ref2, tmpref: treference;
  1326. begin
  1327. ref2 := ref;
  1328. fixref(list,ref2);
  1329. if assigned(ref2.symbol) then
  1330. begin
  1331. if target_info.system = system_powerpc_macos then
  1332. begin
  1333. if macos_direct_globals then
  1334. begin
  1335. reference_reset(tmpref);
  1336. tmpref.offset := ref2.offset;
  1337. tmpref.symbol := ref2.symbol;
  1338. tmpref.base := NR_NO;
  1339. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,NR_RTOC,tmpref));
  1340. end
  1341. else
  1342. begin
  1343. reference_reset(tmpref);
  1344. tmpref.symbol := ref2.symbol;
  1345. tmpref.offset := 0;
  1346. tmpref.base := NR_RTOC;
  1347. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref));
  1348. if ref2.offset <> 0 then
  1349. begin
  1350. reference_reset(tmpref);
  1351. tmpref.offset := ref2.offset;
  1352. tmpref.base:= r;
  1353. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1354. end;
  1355. end;
  1356. if ref2.base <> NR_NO then
  1357. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,r,ref2.base));
  1358. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1359. end
  1360. else
  1361. begin
  1362. { add the symbol's value to the base of the reference, and if the }
  1363. { reference doesn't have a base, create one }
  1364. reference_reset(tmpref);
  1365. tmpref.offset := ref2.offset;
  1366. tmpref.symbol := ref2.symbol;
  1367. tmpref.relsymbol := ref2.relsymbol;
  1368. tmpref.refaddr := addr_hi;
  1369. if ref2.base<> NR_NO then
  1370. begin
  1371. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1372. ref2.base,tmpref));
  1373. end
  1374. else
  1375. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1376. tmpref.base := NR_NO;
  1377. tmpref.refaddr := addr_lo;
  1378. { can be folded with one of the next instructions by the }
  1379. { optimizer probably }
  1380. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1381. end
  1382. end
  1383. else if ref2.offset <> 0 Then
  1384. if ref2.base <> NR_NO then
  1385. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  1386. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1387. { occurs, so now only ref.offset has to be loaded }
  1388. else
  1389. a_load_const_reg(list,OS_32,ref2.offset,r)
  1390. else if ref2.index <> NR_NO Then
  1391. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1392. else if (ref2.base <> NR_NO) and
  1393. (r <> ref2.base) then
  1394. a_load_reg_reg(list,OS_ADDR,OS_ADDR,ref2.base,r)
  1395. else
  1396. list.concat(taicpu.op_reg_const(A_LI,r,0));
  1397. end;
  1398. { ************* concatcopy ************ }
  1399. {$ifndef ppc603}
  1400. const
  1401. maxmoveunit = 8;
  1402. {$else ppc603}
  1403. const
  1404. maxmoveunit = 4;
  1405. {$endif ppc603}
  1406. procedure tcgppc.g_concatcopy(list : TAsmList;const source,dest : treference;len : aint);
  1407. var
  1408. countreg: TRegister;
  1409. src, dst: TReference;
  1410. lab: tasmlabel;
  1411. count, count2: aint;
  1412. size: tcgsize;
  1413. copyreg: tregister;
  1414. begin
  1415. {$ifdef extdebug}
  1416. if len > high(longint) then
  1417. internalerror(2002072704);
  1418. {$endif extdebug}
  1419. if (references_equal(source,dest)) then
  1420. exit;
  1421. { make sure short loads are handled as optimally as possible }
  1422. if (len <= maxmoveunit) and
  1423. (byte(len) in [1,2,4,8]) then
  1424. begin
  1425. if len < 8 then
  1426. begin
  1427. size := int_cgsize(len);
  1428. a_load_ref_ref(list,size,size,source,dest);
  1429. end
  1430. else
  1431. begin
  1432. copyreg := getfpuregister(list,OS_F64);
  1433. a_loadfpu_ref_reg(list,OS_F64,OS_F64,source,copyreg);
  1434. a_loadfpu_reg_ref(list,OS_F64,OS_F64,copyreg,dest);
  1435. end;
  1436. exit;
  1437. end;
  1438. count := len div maxmoveunit;
  1439. reference_reset(src);
  1440. reference_reset(dst);
  1441. { load the address of source into src.base }
  1442. if (count > 4) or
  1443. not issimpleref(source) or
  1444. ((source.index <> NR_NO) and
  1445. ((source.offset + longint(len)) > high(smallint))) then
  1446. begin
  1447. src.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1448. a_loadaddr_ref_reg(list,source,src.base);
  1449. end
  1450. else
  1451. begin
  1452. src := source;
  1453. end;
  1454. { load the address of dest into dst.base }
  1455. if (count > 4) or
  1456. not issimpleref(dest) or
  1457. ((dest.index <> NR_NO) and
  1458. ((dest.offset + longint(len)) > high(smallint))) then
  1459. begin
  1460. dst.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1461. a_loadaddr_ref_reg(list,dest,dst.base);
  1462. end
  1463. else
  1464. begin
  1465. dst := dest;
  1466. end;
  1467. {$ifndef ppc603}
  1468. if count > 4 then
  1469. { generate a loop }
  1470. begin
  1471. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1472. { have to be set to 8. I put an Inc there so debugging may be }
  1473. { easier (should offset be different from zero here, it will be }
  1474. { easy to notice in the generated assembler }
  1475. inc(dst.offset,8);
  1476. inc(src.offset,8);
  1477. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1478. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1479. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1480. a_load_const_reg(list,OS_32,count,countreg);
  1481. copyreg := getfpuregister(list,OS_F64);
  1482. a_reg_sync(list,copyreg);
  1483. current_asmdata.getjumplabel(lab);
  1484. a_label(list, lab);
  1485. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1486. list.concat(taicpu.op_reg_ref(A_LFDU,copyreg,src));
  1487. list.concat(taicpu.op_reg_ref(A_STFDU,copyreg,dst));
  1488. a_jmp(list,A_BC,C_NE,0,lab);
  1489. a_reg_sync(list,copyreg);
  1490. len := len mod 8;
  1491. end;
  1492. count := len div 8;
  1493. if count > 0 then
  1494. { unrolled loop }
  1495. begin
  1496. copyreg := getfpuregister(list,OS_F64);
  1497. for count2 := 1 to count do
  1498. begin
  1499. a_loadfpu_ref_reg(list,OS_F64,OS_F64,src,copyreg);
  1500. a_loadfpu_reg_ref(list,OS_F64,OS_F64,copyreg,dst);
  1501. inc(src.offset,8);
  1502. inc(dst.offset,8);
  1503. end;
  1504. len := len mod 8;
  1505. end;
  1506. if (len and 4) <> 0 then
  1507. begin
  1508. a_reg_alloc(list,NR_R0);
  1509. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1510. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1511. inc(src.offset,4);
  1512. inc(dst.offset,4);
  1513. a_reg_dealloc(list,NR_R0);
  1514. end;
  1515. {$else not ppc603}
  1516. if count > 4 then
  1517. { generate a loop }
  1518. begin
  1519. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1520. { have to be set to 4. I put an Inc there so debugging may be }
  1521. { easier (should offset be different from zero here, it will be }
  1522. { easy to notice in the generated assembler }
  1523. inc(dst.offset,4);
  1524. inc(src.offset,4);
  1525. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,4));
  1526. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,4));
  1527. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1528. a_load_const_reg(list,OS_32,count,countreg);
  1529. { explicitely allocate R_0 since it can be used safely here }
  1530. { (for holding date that's being copied) }
  1531. a_reg_alloc(list,NR_R0);
  1532. current_asmdata.getjumplabel(lab);
  1533. a_label(list, lab);
  1534. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1535. list.concat(taicpu.op_reg_ref(A_LWZU,NR_R0,src));
  1536. list.concat(taicpu.op_reg_ref(A_STWU,NR_R0,dst));
  1537. a_jmp(list,A_BC,C_NE,0,lab);
  1538. a_reg_dealloc(list,NR_R0);
  1539. len := len mod 4;
  1540. end;
  1541. count := len div 4;
  1542. if count > 0 then
  1543. { unrolled loop }
  1544. begin
  1545. a_reg_alloc(list,NR_R0);
  1546. for count2 := 1 to count do
  1547. begin
  1548. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1549. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1550. inc(src.offset,4);
  1551. inc(dst.offset,4);
  1552. end;
  1553. a_reg_dealloc(list,NR_R0);
  1554. len := len mod 4;
  1555. end;
  1556. {$endif not ppc603}
  1557. { copy the leftovers }
  1558. if (len and 2) <> 0 then
  1559. begin
  1560. a_reg_alloc(list,NR_R0);
  1561. a_load_ref_reg(list,OS_16,OS_16,src,NR_R0);
  1562. a_load_reg_ref(list,OS_16,OS_16,NR_R0,dst);
  1563. inc(src.offset,2);
  1564. inc(dst.offset,2);
  1565. a_reg_dealloc(list,NR_R0);
  1566. end;
  1567. if (len and 1) <> 0 then
  1568. begin
  1569. a_reg_alloc(list,NR_R0);
  1570. a_load_ref_reg(list,OS_8,OS_8,src,NR_R0);
  1571. a_load_reg_ref(list,OS_8,OS_8,NR_R0,dst);
  1572. a_reg_dealloc(list,NR_R0);
  1573. end;
  1574. end;
  1575. procedure tcgppc.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  1576. procedure loadvmttor11;
  1577. var
  1578. href : treference;
  1579. begin
  1580. reference_reset_base(href,NR_R3,0);
  1581. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_R11);
  1582. end;
  1583. procedure op_onr11methodaddr;
  1584. var
  1585. href : treference;
  1586. begin
  1587. if (procdef.extnumber=$ffff) then
  1588. Internalerror(200006139);
  1589. { call/jmp vmtoffs(%eax) ; method offs }
  1590. reference_reset_base(href,NR_R11,procdef._class.vmtmethodoffset(procdef.extnumber));
  1591. if not((longint(href.offset) >= low(smallint)) and
  1592. (longint(href.offset) <= high(smallint))) then
  1593. begin
  1594. list.concat(taicpu.op_reg_reg_const(A_ADDIS,NR_R11,NR_R11,
  1595. smallint((href.offset shr 16)+ord(smallint(href.offset and $ffff) < 0))));
  1596. href.offset := smallint(href.offset and $ffff);
  1597. end;
  1598. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R11,href));
  1599. list.concat(taicpu.op_reg(A_MTCTR,NR_R11));
  1600. list.concat(taicpu.op_none(A_BCTR));
  1601. end;
  1602. var
  1603. make_global : boolean;
  1604. begin
  1605. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  1606. Internalerror(200006137);
  1607. if not assigned(procdef._class) or
  1608. (procdef.procoptions*[po_classmethod, po_staticmethod,
  1609. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  1610. Internalerror(200006138);
  1611. if procdef.owner.symtabletype<>ObjectSymtable then
  1612. Internalerror(200109191);
  1613. make_global:=false;
  1614. if (not current_module.is_unit) or
  1615. (cs_create_smart in current_settings.moduleswitches) or
  1616. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  1617. make_global:=true;
  1618. if make_global then
  1619. List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0))
  1620. else
  1621. List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0));
  1622. { set param1 interface to self }
  1623. g_adjust_self_value(list,procdef,ioffset);
  1624. { case 4 }
  1625. if po_virtualmethod in procdef.procoptions then
  1626. begin
  1627. loadvmttor11;
  1628. op_onr11methodaddr;
  1629. end
  1630. { case 0 }
  1631. else
  1632. if not(target_info.system = system_powerpc_darwin) then
  1633. list.concat(taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(procdef.mangledname)))
  1634. else
  1635. list.concat(taicpu.op_sym(A_B,get_darwin_call_stub(procdef.mangledname)));
  1636. List.concat(Tai_symbol_end.Createname(labelname));
  1637. end;
  1638. {***************** This is private property, keep out! :) *****************}
  1639. function tcgppc.issimpleref(const ref: treference): boolean;
  1640. begin
  1641. if (ref.base = NR_NO) and
  1642. (ref.index <> NR_NO) then
  1643. internalerror(200208101);
  1644. result :=
  1645. not(assigned(ref.symbol)) and
  1646. (((ref.index = NR_NO) and
  1647. (ref.offset >= low(smallint)) and
  1648. (ref.offset <= high(smallint))) or
  1649. ((ref.index <> NR_NO) and
  1650. (ref.offset = 0)));
  1651. end;
  1652. function tcgppc.fixref(list: TAsmList; var ref: treference): boolean;
  1653. var
  1654. tmpreg: tregister;
  1655. begin
  1656. result := false;
  1657. if (target_info.system = system_powerpc_darwin) and
  1658. assigned(ref.symbol) and
  1659. (ref.symbol.bind = AB_EXTERNAL) then
  1660. begin
  1661. tmpreg := g_indirect_sym_load(list,ref.symbol.name);
  1662. if (ref.base = NR_NO) then
  1663. ref.base := tmpreg
  1664. else if (ref.index = NR_NO) then
  1665. ref.index := tmpreg
  1666. else
  1667. begin
  1668. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,ref.base,tmpreg));
  1669. ref.base := tmpreg;
  1670. end;
  1671. ref.symbol := nil;
  1672. end;
  1673. if (ref.base = NR_NO) then
  1674. begin
  1675. ref.base := ref.index;
  1676. ref.index := NR_NO;
  1677. end;
  1678. if (ref.base <> NR_NO) then
  1679. begin
  1680. if (ref.index <> NR_NO) and
  1681. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1682. begin
  1683. result := true;
  1684. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1685. list.concat(taicpu.op_reg_reg_reg(
  1686. A_ADD,tmpreg,ref.base,ref.index));
  1687. ref.index := NR_NO;
  1688. ref.base := tmpreg;
  1689. end
  1690. end
  1691. else
  1692. if ref.index <> NR_NO then
  1693. internalerror(200208102);
  1694. end;
  1695. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1696. { that's the case, we can use rlwinm to do an AND operation }
  1697. function tcgppc.get_rlwi_const(a: aint; var l1, l2: longint): boolean;
  1698. var
  1699. temp : longint;
  1700. testbit : aint;
  1701. compare: boolean;
  1702. begin
  1703. get_rlwi_const := false;
  1704. if (a = 0) or (a = -1) then
  1705. exit;
  1706. { start with the lowest bit }
  1707. testbit := 1;
  1708. { check its value }
  1709. compare := boolean(a and testbit);
  1710. { find out how long the run of bits with this value is }
  1711. { (it's impossible that all bits are 1 or 0, because in that case }
  1712. { this function wouldn't have been called) }
  1713. l1 := 31;
  1714. while (((a and testbit) <> 0) = compare) do
  1715. begin
  1716. testbit := testbit shl 1;
  1717. dec(l1);
  1718. end;
  1719. { check the length of the run of bits that comes next }
  1720. compare := not compare;
  1721. l2 := l1;
  1722. while (((a and testbit) <> 0) = compare) and
  1723. (l2 >= 0) do
  1724. begin
  1725. testbit := testbit shl 1;
  1726. dec(l2);
  1727. end;
  1728. { and finally the check whether the rest of the bits all have the }
  1729. { same value }
  1730. compare := not compare;
  1731. temp := l2;
  1732. if temp >= 0 then
  1733. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1734. exit;
  1735. { we have done "not(not(compare))", so compare is back to its }
  1736. { initial value. If the lowest bit was 0, a is of the form }
  1737. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1738. { because l2 now contains the position of the last zero of the }
  1739. { first run instead of that of the first 1) so switch l1 and l2 }
  1740. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1741. if not compare then
  1742. begin
  1743. temp := l1;
  1744. l1 := l2+1;
  1745. l2 := temp;
  1746. end
  1747. else
  1748. { otherwise, l1 currently contains the position of the last }
  1749. { zero instead of that of the first 1 of the second run -> +1 }
  1750. inc(l1);
  1751. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1752. l1 := l1 and 31;
  1753. l2 := l2 and 31;
  1754. get_rlwi_const := true;
  1755. end;
  1756. procedure tcgppc.a_load_store(list:TAsmList;op: tasmop;reg:tregister;
  1757. ref: treference);
  1758. var
  1759. tmpreg: tregister;
  1760. tmpref: treference;
  1761. largeOffset: Boolean;
  1762. begin
  1763. tmpreg := NR_NO;
  1764. if target_info.system = system_powerpc_macos then
  1765. begin
  1766. largeOffset:= (cardinal(ref.offset-low(smallint)) >
  1767. high(smallint)-low(smallint));
  1768. if assigned(ref.symbol) then
  1769. begin {Load symbol's value}
  1770. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1771. reference_reset(tmpref);
  1772. tmpref.symbol := ref.symbol;
  1773. tmpref.base := NR_RTOC;
  1774. if macos_direct_globals then
  1775. list.concat(taicpu.op_reg_ref(A_LA,tmpreg,tmpref))
  1776. else
  1777. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1778. end;
  1779. if largeOffset then
  1780. begin {Add hi part of offset}
  1781. reference_reset(tmpref);
  1782. if Smallint(Lo(ref.offset)) < 0 then
  1783. tmpref.offset := Hi(ref.offset) + 1 {Compensate when lo part is negative}
  1784. else
  1785. tmpref.offset := Hi(ref.offset);
  1786. if (tmpreg <> NR_NO) then
  1787. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg, tmpreg,tmpref))
  1788. else
  1789. begin
  1790. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1791. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1792. end;
  1793. end;
  1794. if (tmpreg <> NR_NO) then
  1795. begin
  1796. {Add content of base register}
  1797. if ref.base <> NR_NO then
  1798. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1799. ref.base,tmpreg));
  1800. {Make ref ready to be used by op}
  1801. ref.symbol:= nil;
  1802. ref.base:= tmpreg;
  1803. if largeOffset then
  1804. ref.offset := Smallint(Lo(ref.offset));
  1805. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1806. //list.concat(tai_comment.create(strpnew('*** a_load_store indirect global')));
  1807. end
  1808. else
  1809. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1810. end
  1811. else {if target_info.system <> system_powerpc_macos}
  1812. begin
  1813. if assigned(ref.symbol) or
  1814. (cardinal(ref.offset-low(smallint)) >
  1815. high(smallint)-low(smallint)) then
  1816. begin
  1817. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1818. reference_reset(tmpref);
  1819. tmpref.symbol := ref.symbol;
  1820. tmpref.relsymbol := ref.relsymbol;
  1821. tmpref.offset := ref.offset;
  1822. tmpref.refaddr := addr_hi;
  1823. if ref.base <> NR_NO then
  1824. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1825. ref.base,tmpref))
  1826. else
  1827. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1828. ref.base := tmpreg;
  1829. ref.refaddr := addr_lo;
  1830. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1831. end
  1832. else
  1833. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1834. end;
  1835. end;
  1836. procedure tcg64fppc.a_op64_reg_reg(list : TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);
  1837. begin
  1838. a_op64_reg_reg_reg(list,op,size,regsrc,regdst,regdst);
  1839. end;
  1840. procedure tcg64fppc.a_op64_const_reg(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;reg : tregister64);
  1841. begin
  1842. a_op64_const_reg_reg(list,op,size,value,reg,reg);
  1843. end;
  1844. procedure tcg64fppc.a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1845. begin
  1846. case op of
  1847. OP_AND,OP_OR,OP_XOR:
  1848. begin
  1849. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1850. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1851. end;
  1852. OP_ADD:
  1853. begin
  1854. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1855. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1856. end;
  1857. OP_SUB:
  1858. begin
  1859. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1860. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1861. end;
  1862. else
  1863. internalerror(2002072801);
  1864. end;
  1865. end;
  1866. procedure tcg64fppc.a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);
  1867. const
  1868. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1869. (A_SUBIC,A_SUBC,A_ADDME));
  1870. var
  1871. tmpreg: tregister;
  1872. tmpreg64: tregister64;
  1873. issub: boolean;
  1874. begin
  1875. case op of
  1876. OP_AND,OP_OR,OP_XOR:
  1877. begin
  1878. cg.a_op_const_reg_reg(list,op,OS_32,aint(value),regsrc.reglo,regdst.reglo);
  1879. cg.a_op_const_reg_reg(list,op,OS_32,aint(value shr 32),regsrc.reghi,
  1880. regdst.reghi);
  1881. end;
  1882. OP_ADD, OP_SUB:
  1883. begin
  1884. if (value < 0) and
  1885. (value <> low(value)) then
  1886. begin
  1887. if op = OP_ADD then
  1888. op := OP_SUB
  1889. else
  1890. op := OP_ADD;
  1891. value := -value;
  1892. end;
  1893. if (longint(value) <> 0) then
  1894. begin
  1895. issub := op = OP_SUB;
  1896. if (value > 0) and
  1897. (value-ord(issub) <= 32767) then
  1898. begin
  1899. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1900. regdst.reglo,regsrc.reglo,longint(value)));
  1901. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1902. regdst.reghi,regsrc.reghi));
  1903. end
  1904. else if ((value shr 32) = 0) then
  1905. begin
  1906. tmpreg := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1907. cg.a_load_const_reg(list,OS_32,aint(value),tmpreg);
  1908. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  1909. regdst.reglo,regsrc.reglo,tmpreg));
  1910. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1911. regdst.reghi,regsrc.reghi));
  1912. end
  1913. else
  1914. begin
  1915. tmpreg64.reglo := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1916. tmpreg64.reghi := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1917. a_load64_const_reg(list,value,tmpreg64);
  1918. a_op64_reg_reg_reg(list,op,size,tmpreg64,regsrc,regdst);
  1919. end
  1920. end
  1921. else
  1922. begin
  1923. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  1924. cg.a_op_const_reg_reg(list,op,OS_32,aint(value shr 32),regsrc.reghi,
  1925. regdst.reghi);
  1926. end;
  1927. end;
  1928. else
  1929. internalerror(2002072802);
  1930. end;
  1931. end;
  1932. begin
  1933. cg := tcgppc.create;
  1934. cg64 :=tcg64fppc.create;
  1935. end.