cgcpu.pas 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the code generator for the PowerPC
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. symtype,
  23. cgbase,cgobj,
  24. aasmbase,aasmcpu,aasmtai,
  25. cpubase,cpuinfo,node,cg64f32,rgcpu;
  26. type
  27. tcgppc = class(tcg)
  28. procedure init_register_allocators;override;
  29. procedure done_register_allocators;override;
  30. procedure ungetreference(list:Taasmoutput;const r:Treference);override;
  31. { passing parameters, per default the parameter is pushed }
  32. { nr gives the number of the parameter (enumerated from }
  33. { left to right), this allows to move the parameter to }
  34. { register, if the cpu supports register calling }
  35. { conventions }
  36. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);override;
  37. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);override;
  38. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);override;
  39. procedure a_call_name(list : taasmoutput;const s : string);override;
  40. procedure a_call_reg(list : taasmoutput;reg: tregister); override;
  41. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister); override;
  42. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  43. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  44. size: tcgsize; a: aword; src, dst: tregister); override;
  45. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  46. size: tcgsize; src1, src2, dst: tregister); override;
  47. { move instructions }
  48. procedure a_load_const_reg(list : taasmoutput; size: tcgsize; a : aword;reg : tregister);override;
  49. procedure a_load_reg_ref(list : taasmoutput; fromsize, tosize: tcgsize; reg : tregister;const ref : treference);override;
  50. procedure a_load_ref_reg(list : taasmoutput; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister);override;
  51. procedure a_load_reg_reg(list : taasmoutput; fromsize, tosize : tcgsize;reg1,reg2 : tregister);override;
  52. { fpu move instructions }
  53. procedure a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister); override;
  54. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  55. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  56. { comparison operations }
  57. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  58. l : tasmlabel);override;
  59. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  60. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  61. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  62. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister); override;
  63. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:aword);override;
  64. procedure g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);override;
  65. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  66. procedure g_return_from_proc(list : taasmoutput;parasize : aword); override;
  67. procedure g_restore_frame_pointer(list : taasmoutput);override;
  68. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  69. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  70. procedure g_overflowcheck(list: taasmoutput; const l: tlocation; def: tdef); override;
  71. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  72. { that's the case, we can use rlwinm to do an AND operation }
  73. function get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  74. procedure g_save_standard_registers(list:Taasmoutput);override;
  75. procedure g_restore_standard_registers(list:Taasmoutput);override;
  76. procedure g_save_all_registers(list : taasmoutput);override;
  77. procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);override;
  78. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  79. private
  80. (* NOT IN USE: *)
  81. procedure g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  82. (* NOT IN USE: *)
  83. procedure g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  84. { Make sure ref is a valid reference for the PowerPC and sets the }
  85. { base to the value of the index if (base = R_NO). }
  86. { Returns true if the reference contained a base, index and an }
  87. { offset or symbol, in which case the base will have been changed }
  88. { to a tempreg (which has to be freed by the caller) containing }
  89. { the sum of part of the original reference }
  90. function fixref(list: taasmoutput; var ref: treference): boolean;
  91. { returns whether a reference can be used immediately in a powerpc }
  92. { instruction }
  93. function issimpleref(const ref: treference): boolean;
  94. { contains the common code of a_load_reg_ref and a_load_ref_reg }
  95. procedure a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  96. ref: treference);
  97. { creates the correct branch instruction for a given combination }
  98. { of asmcondflags and destination addressing mode }
  99. procedure a_jmp(list: taasmoutput; op: tasmop;
  100. c: tasmcondflag; crval: longint; l: tasmlabel);
  101. function save_regs(list : taasmoutput):longint;
  102. procedure restore_regs(list : taasmoutput);
  103. end;
  104. tcg64fppc = class(tcg64f32)
  105. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);override;
  106. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);override;
  107. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);override;
  108. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);override;
  109. end;
  110. const
  111. TOpCG2AsmOpConstLo: Array[topcg] of TAsmOp = (A_NONE,A_ADDI,A_ANDI_,A_DIVWU,
  112. A_DIVW,A_MULLW, A_MULLW, A_NONE,A_NONE,A_ORI,
  113. A_SRAWI,A_SLWI,A_SRWI,A_SUBI,A_XORI);
  114. TOpCG2AsmOpConstHi: Array[topcg] of TAsmOp = (A_NONE,A_ADDIS,A_ANDIS_,
  115. A_DIVWU,A_DIVW, A_MULLW,A_MULLW,A_NONE,A_NONE,
  116. A_ORIS,A_NONE, A_NONE,A_NONE,A_SUBIS,A_XORIS);
  117. TOpCmp2AsmCond: Array[topcmp] of TAsmCondFlag = (C_NONE,C_EQ,C_GT,
  118. C_LT,C_GE,C_LE,C_NE,C_LE,C_LT,C_GE,C_GT);
  119. implementation
  120. uses
  121. globtype,globals,verbose,systems,cutils,
  122. symconst,symdef,symsym,
  123. rgobj,tgobj,cpupi,procinfo,paramgr;
  124. procedure tcgppc.init_register_allocators;
  125. begin
  126. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  127. [RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
  128. RS_R9,RS_R10,RS_R11,RS_R12,RS_R31,RS_R30,RS_R29,
  129. RS_R28,RS_R27,RS_R26,RS_R25,RS_R24,RS_R23,RS_R22,
  130. RS_R21,RS_R20,RS_R19,RS_R18,RS_R17,RS_R16,RS_R15,
  131. RS_R14,RS_R13],first_int_imreg,[]);
  132. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,
  133. [RS_F0,RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7,RS_F8,RS_F9,
  134. RS_F10,RS_F11,RS_F12,RS_F13,RS_F31,RS_F30,RS_F29,RS_F28,RS_F27,
  135. RS_F26,RS_F25,RS_F24,RS_F23,RS_F22,RS_F21,RS_F20,RS_F19,RS_F18,
  136. RS_F17,RS_F16,RS_F15,RS_F14],first_fpu_imreg,[]);
  137. {$warning FIX ME}
  138. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,
  139. [RS_M0,RS_M1,RS_M2],first_mm_imreg,[]);
  140. end;
  141. procedure tcgppc.done_register_allocators;
  142. begin
  143. rg[R_INTREGISTER].free;
  144. rg[R_FPUREGISTER].free;
  145. rg[R_MMREGISTER].free;
  146. end;
  147. procedure tcgppc.ungetreference(list:Taasmoutput;const r:Treference);
  148. begin
  149. if r.base<>NR_NO then
  150. ungetregister(list,r.base);
  151. if r.index<>NR_NO then
  152. ungetregister(list,r.index);
  153. end;
  154. procedure tcgppc.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  155. var
  156. ref: treference;
  157. begin
  158. case locpara.loc of
  159. LOC_REGISTER,LOC_CREGISTER:
  160. a_load_const_reg(list,size,a,locpara.register);
  161. LOC_REFERENCE:
  162. begin
  163. reference_reset(ref);
  164. ref.base:=locpara.reference.index;
  165. ref.offset:=locpara.reference.offset;
  166. a_load_const_ref(list,size,a,ref);
  167. end;
  168. else
  169. internalerror(2002081101);
  170. end;
  171. end;
  172. procedure tcgppc.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  173. var
  174. ref: treference;
  175. tmpreg: tregister;
  176. begin
  177. case locpara.loc of
  178. LOC_REGISTER,LOC_CREGISTER:
  179. a_load_ref_reg(list,size,size,r,locpara.register);
  180. LOC_REFERENCE:
  181. begin
  182. reference_reset(ref);
  183. ref.base:=locpara.reference.index;
  184. ref.offset:=locpara.reference.offset;
  185. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  186. a_load_ref_reg(list,size,size,r,tmpreg);
  187. a_load_reg_ref(list,size,size,tmpreg,ref);
  188. rg[R_INTREGISTER].ungetregister(list,tmpreg);
  189. end;
  190. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  191. case size of
  192. OS_F32, OS_F64:
  193. a_loadfpu_ref_reg(list,size,r,locpara.register);
  194. else
  195. internalerror(2002072801);
  196. end;
  197. else
  198. internalerror(2002081103);
  199. end;
  200. end;
  201. procedure tcgppc.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  202. var
  203. ref: treference;
  204. tmpreg: tregister;
  205. begin
  206. case locpara.loc of
  207. LOC_REGISTER,LOC_CREGISTER:
  208. a_loadaddr_ref_reg(list,r,locpara.register);
  209. LOC_REFERENCE:
  210. begin
  211. reference_reset(ref);
  212. ref.base := locpara.reference.index;
  213. ref.offset := locpara.reference.offset;
  214. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  215. a_loadaddr_ref_reg(list,r,tmpreg);
  216. a_load_reg_ref(list,OS_ADDR,OS_ADDR,tmpreg,ref);
  217. rg[R_INTREGISTER].ungetregister(list,tmpreg);
  218. end;
  219. else
  220. internalerror(2002080701);
  221. end;
  222. end;
  223. { calling a procedure by name }
  224. procedure tcgppc.a_call_name(list : taasmoutput;const s : string);
  225. var
  226. href : treference;
  227. begin
  228. { MacOS: The linker on MacOS (PPCLink) inserts a call to glue code,
  229. if it is a cross-TOC call. If so, it also replaces the NOP
  230. with some restore code.}
  231. list.concat(taicpu.op_sym(A_BL,objectlibrary.newasmsymbol(s)));
  232. if target_info.system=system_powerpc_macos then
  233. list.concat(taicpu.op_none(A_NOP));
  234. if not(pi_do_call in current_procinfo.flags) then
  235. internalerror(2003060703);
  236. end;
  237. { calling a procedure by address }
  238. procedure tcgppc.a_call_reg(list : taasmoutput;reg: tregister);
  239. var
  240. tmpreg : tregister;
  241. tmpref : treference;
  242. begin
  243. if target_info.system=system_powerpc_macos then
  244. begin
  245. {Generate instruction to load the procedure address from
  246. the transition vector.}
  247. //TODO: Support cross-TOC calls.
  248. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  249. reference_reset(tmpref);
  250. tmpref.offset := 0;
  251. //tmpref.symaddr := refs_full;
  252. tmpref.base:= reg;
  253. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  254. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  255. rg[R_INTREGISTER].ungetregister(list,tmpreg);
  256. end
  257. else
  258. list.concat(taicpu.op_reg(A_MTCTR,reg));
  259. list.concat(taicpu.op_none(A_BCTRL));
  260. //if target_info.system=system_powerpc_macos then
  261. // //NOP is not needed here.
  262. // list.concat(taicpu.op_none(A_NOP));
  263. if not(pi_do_call in current_procinfo.flags) then
  264. internalerror(2003060704);
  265. //list.concat(tai_comment.create(strpnew('***** a_call_reg')));
  266. end;
  267. {********************** load instructions ********************}
  268. procedure tcgppc.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  269. begin
  270. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  271. internalerror(2002090902);
  272. if (longint(a) >= low(smallint)) and
  273. (longint(a) <= high(smallint)) then
  274. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a)))
  275. else if ((a and $ffff) <> 0) then
  276. begin
  277. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a and $ffff)));
  278. if ((a shr 16) <> 0) or
  279. (smallint(a and $ffff) < 0) then
  280. list.concat(taicpu.op_reg_reg_const(A_ADDIS,reg,reg,
  281. smallint((a shr 16)+ord(smallint(a and $ffff) < 0))))
  282. end
  283. else
  284. list.concat(taicpu.op_reg_const(A_LIS,reg,smallint(a shr 16)));
  285. end;
  286. procedure tcgppc.a_load_reg_ref(list : taasmoutput; fromsize, tosize: TCGSize; reg : tregister;const ref : treference);
  287. const
  288. StoreInstr: Array[OS_8..OS_32,boolean, boolean] of TAsmOp =
  289. { indexed? updating?}
  290. (((A_STB,A_STBU),(A_STBX,A_STBUX)),
  291. ((A_STH,A_STHU),(A_STHX,A_STHUX)),
  292. ((A_STW,A_STWU),(A_STWX,A_STWUX)));
  293. var
  294. op: TAsmOp;
  295. ref2: TReference;
  296. freereg: boolean;
  297. begin
  298. ref2 := ref;
  299. freereg := fixref(list,ref2);
  300. if tosize in [OS_S8..OS_S16] then
  301. { storing is the same for signed and unsigned values }
  302. tosize := tcgsize(ord(tosize)-(ord(OS_S8)-ord(OS_8)));
  303. { 64 bit stuff should be handled separately }
  304. if tosize in [OS_64,OS_S64] then
  305. internalerror(200109236);
  306. op := storeinstr[tcgsize2unsigned[tosize],ref2.index<>NR_NO,false];
  307. a_load_store(list,op,reg,ref2);
  308. if freereg then
  309. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  310. End;
  311. procedure tcgppc.a_load_ref_reg(list : taasmoutput; fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  312. const
  313. LoadInstr: Array[OS_8..OS_S32,boolean, boolean] of TAsmOp =
  314. { indexed? updating?}
  315. (((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  316. ((A_LHZ,A_LHZU),(A_LHZX,A_LHZUX)),
  317. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)),
  318. { 64bit stuff should be handled separately }
  319. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  320. { there's no load-byte-with-sign-extend :( }
  321. ((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  322. ((A_LHA,A_LHAU),(A_LHAX,A_LHAUX)),
  323. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)));
  324. var
  325. op: tasmop;
  326. tmpreg: tregister;
  327. ref2, tmpref: treference;
  328. freereg: boolean;
  329. begin
  330. { TODO: optimize/take into consideration fromsize/tosize. Will }
  331. { probably only matter for OS_S8 loads though }
  332. if not(fromsize in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  333. internalerror(2002090902);
  334. ref2 := ref;
  335. freereg := fixref(list,ref2);
  336. { the caller is expected to have adjusted the reference already }
  337. { in this case }
  338. if (TCGSize2Size[fromsize] >= TCGSize2Size[tosize]) then
  339. fromsize := tosize;
  340. op := loadinstr[fromsize,ref2.index<>NR_NO,false];
  341. a_load_store(list,op,reg,ref2);
  342. if freereg then
  343. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  344. { sign extend shortint if necessary, since there is no }
  345. { load instruction that does that automatically (JM) }
  346. if fromsize = OS_S8 then
  347. list.concat(taicpu.op_reg_reg(A_EXTSB,reg,reg));
  348. end;
  349. procedure tcgppc.a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  350. var
  351. instr: taicpu;
  352. begin
  353. if (reg1<>reg2) or
  354. (tcgsize2size[tosize] < tcgsize2size[fromsize]) or
  355. ((tcgsize2size[tosize] = tcgsize2size[fromsize]) and
  356. (tosize <> fromsize) and
  357. not(fromsize in [OS_32,OS_S32])) then
  358. begin
  359. case tosize of
  360. OS_8:
  361. instr := taicpu.op_reg_reg_const_const_const(A_RLWINM,
  362. reg2,reg1,0,31-8+1,31);
  363. OS_S8:
  364. instr := taicpu.op_reg_reg(A_EXTSB,reg2,reg1);
  365. OS_16:
  366. instr := taicpu.op_reg_reg_const_const_const(A_RLWINM,
  367. reg2,reg1,0,31-16+1,31);
  368. OS_S16:
  369. instr := taicpu.op_reg_reg(A_EXTSH,reg2,reg1);
  370. OS_32,OS_S32:
  371. instr := taicpu.op_reg_reg(A_MR,reg2,reg1);
  372. else internalerror(2002090901);
  373. end;
  374. list.concat(instr);
  375. rg[R_INTREGISTER].add_move_instruction(instr);
  376. end;
  377. end;
  378. procedure tcgppc.a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister);
  379. begin
  380. list.concat(taicpu.op_reg_reg(A_FMR,reg2,reg1));
  381. end;
  382. procedure tcgppc.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  383. const
  384. FpuLoadInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  385. { indexed? updating?}
  386. (((A_LFS,A_LFSU),(A_LFSX,A_LFSUX)),
  387. ((A_LFD,A_LFDU),(A_LFDX,A_LFDUX)));
  388. var
  389. op: tasmop;
  390. ref2: treference;
  391. freereg: boolean;
  392. begin
  393. { several functions call this procedure with OS_32 or OS_64 }
  394. { so this makes life easier (FK) }
  395. case size of
  396. OS_32,OS_F32:
  397. size:=OS_F32;
  398. OS_64,OS_F64,OS_C64:
  399. size:=OS_F64;
  400. else
  401. internalerror(200201121);
  402. end;
  403. ref2 := ref;
  404. freereg := fixref(list,ref2);
  405. op := fpuloadinstr[size,ref2.index <> NR_NO,false];
  406. a_load_store(list,op,reg,ref2);
  407. if freereg then
  408. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  409. end;
  410. procedure tcgppc.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  411. const
  412. FpuStoreInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  413. { indexed? updating?}
  414. (((A_STFS,A_STFSU),(A_STFSX,A_STFSUX)),
  415. ((A_STFD,A_STFDU),(A_STFDX,A_STFDUX)));
  416. var
  417. op: tasmop;
  418. ref2: treference;
  419. freereg: boolean;
  420. begin
  421. if not(size in [OS_F32,OS_F64]) then
  422. internalerror(200201122);
  423. ref2 := ref;
  424. freereg := fixref(list,ref2);
  425. op := fpustoreinstr[size,ref2.index <> NR_NO,false];
  426. a_load_store(list,op,reg,ref2);
  427. if freereg then
  428. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  429. end;
  430. procedure tcgppc.a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister);
  431. begin
  432. a_op_const_reg_reg(list,op,OS_32,a,reg,reg);
  433. end;
  434. procedure tcgppc.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  435. begin
  436. a_op_reg_reg_reg(list,op,OS_32,src,dst,dst);
  437. end;
  438. procedure tcgppc.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  439. size: tcgsize; a: aword; src, dst: tregister);
  440. var
  441. l1,l2: longint;
  442. oplo, ophi: tasmop;
  443. scratchreg: tregister;
  444. useReg, gotrlwi: boolean;
  445. procedure do_lo_hi;
  446. begin
  447. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  448. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  449. end;
  450. begin
  451. if op = OP_SUB then
  452. begin
  453. {$ifopt q+}
  454. {$q-}
  455. {$define overflowon}
  456. {$endif}
  457. a_op_const_reg_reg(list,OP_ADD,size,aword(-longint(a)),src,dst);
  458. {$ifdef overflowon}
  459. {$q+}
  460. {$undef overflowon}
  461. {$endif}
  462. exit;
  463. end;
  464. ophi := TOpCG2AsmOpConstHi[op];
  465. oplo := TOpCG2AsmOpConstLo[op];
  466. gotrlwi := get_rlwi_const(a,l1,l2);
  467. if (op in [OP_AND,OP_OR,OP_XOR]) then
  468. begin
  469. if (a = 0) then
  470. begin
  471. if op = OP_AND then
  472. list.concat(taicpu.op_reg_const(A_LI,dst,0))
  473. else
  474. a_load_reg_reg(list,size,size,src,dst);
  475. exit;
  476. end
  477. else if (a = high(aword)) then
  478. begin
  479. case op of
  480. OP_OR:
  481. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  482. OP_XOR:
  483. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  484. OP_AND:
  485. a_load_reg_reg(list,size,size,src,dst);
  486. end;
  487. exit;
  488. end
  489. else if (a <= high(word)) and
  490. ((op <> OP_AND) or
  491. not gotrlwi) then
  492. begin
  493. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  494. exit;
  495. end;
  496. { all basic constant instructions also have a shifted form that }
  497. { works only on the highest 16bits, so if lo(a) is 0, we can }
  498. { use that one }
  499. if (word(a) = 0) and
  500. (not(op = OP_AND) or
  501. not gotrlwi) then
  502. begin
  503. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  504. exit;
  505. end;
  506. end
  507. else if (op = OP_ADD) then
  508. if a = 0 then
  509. exit
  510. else if (longint(a) >= low(smallint)) and
  511. (longint(a) <= high(smallint)) then
  512. begin
  513. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  514. exit;
  515. end;
  516. { otherwise, the instructions we can generate depend on the }
  517. { operation }
  518. useReg := false;
  519. case op of
  520. OP_DIV,OP_IDIV:
  521. if (a = 0) then
  522. internalerror(200208103)
  523. else if (a = 1) then
  524. begin
  525. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  526. exit
  527. end
  528. else if ispowerof2(a,l1) then
  529. begin
  530. case op of
  531. OP_DIV:
  532. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  533. OP_IDIV:
  534. begin
  535. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  536. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  537. end;
  538. end;
  539. exit;
  540. end
  541. else
  542. usereg := true;
  543. OP_IMUL, OP_MUL:
  544. if (a = 0) then
  545. begin
  546. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  547. exit
  548. end
  549. else if (a = 1) then
  550. begin
  551. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  552. exit
  553. end
  554. else if ispowerof2(a,l1) then
  555. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  556. else if (longint(a) >= low(smallint)) and
  557. (longint(a) <= high(smallint)) then
  558. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  559. else
  560. usereg := true;
  561. OP_ADD:
  562. begin
  563. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  564. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  565. smallint((a shr 16) + ord(smallint(a) < 0))));
  566. end;
  567. OP_OR:
  568. { try to use rlwimi }
  569. if gotrlwi and
  570. (src = dst) then
  571. begin
  572. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  573. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  574. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  575. scratchreg,0,l1,l2));
  576. rg[R_INTREGISTER].ungetregister(list,scratchreg);
  577. end
  578. else
  579. do_lo_hi;
  580. OP_AND:
  581. { try to use rlwinm }
  582. if gotrlwi then
  583. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  584. src,0,l1,l2))
  585. else
  586. useReg := true;
  587. OP_XOR:
  588. do_lo_hi;
  589. OP_SHL,OP_SHR,OP_SAR:
  590. begin
  591. if (a and 31) <> 0 Then
  592. list.concat(taicpu.op_reg_reg_const(
  593. TOpCG2AsmOpConstLo[Op],dst,src,a and 31))
  594. else
  595. a_load_reg_reg(list,size,size,src,dst);
  596. if (a shr 5) <> 0 then
  597. internalError(68991);
  598. end
  599. else
  600. internalerror(200109091);
  601. end;
  602. { if all else failed, load the constant in a register and then }
  603. { perform the operation }
  604. if useReg then
  605. begin
  606. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  607. a_load_const_reg(list,OS_32,a,scratchreg);
  608. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  609. rg[R_INTREGISTER].ungetregister(list,scratchreg);
  610. end;
  611. end;
  612. procedure tcgppc.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  613. size: tcgsize; src1, src2, dst: tregister);
  614. const
  615. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  616. (A_NONE,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  617. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  618. begin
  619. case op of
  620. OP_NEG,OP_NOT:
  621. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,dst));
  622. else
  623. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  624. end;
  625. end;
  626. {*************** compare instructructions ****************}
  627. procedure tcgppc.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  628. l : tasmlabel);
  629. var
  630. p: taicpu;
  631. scratch_register: TRegister;
  632. signed: boolean;
  633. begin
  634. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE];
  635. { in the following case, we generate more efficient code when }
  636. { signed is true }
  637. if (cmp_op in [OC_EQ,OC_NE]) and
  638. (a > $ffff) then
  639. signed := true;
  640. if signed then
  641. if (longint(a) >= low(smallint)) and (longint(a) <= high(smallint)) Then
  642. list.concat(taicpu.op_reg_reg_const(A_CMPWI,NR_CR0,reg,longint(a)))
  643. else
  644. begin
  645. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  646. a_load_const_reg(list,OS_32,a,scratch_register);
  647. list.concat(taicpu.op_reg_reg_reg(A_CMPW,NR_CR0,reg,scratch_register));
  648. rg[R_INTREGISTER].ungetregister(list,scratch_register);
  649. end
  650. else
  651. if (a <= $ffff) then
  652. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,NR_CR0,reg,a))
  653. else
  654. begin
  655. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  656. a_load_const_reg(list,OS_32,a,scratch_register);
  657. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,NR_CR0,reg,scratch_register));
  658. rg[R_INTREGISTER].ungetregister(list,scratch_register);
  659. end;
  660. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  661. end;
  662. procedure tcgppc.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  663. reg1,reg2 : tregister;l : tasmlabel);
  664. var
  665. p: taicpu;
  666. op: tasmop;
  667. begin
  668. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  669. op := A_CMPW
  670. else
  671. op := A_CMPLW;
  672. list.concat(taicpu.op_reg_reg_reg(op,NR_CR0,reg2,reg1));
  673. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  674. end;
  675. procedure tcgppc.g_save_standard_registers(list:Taasmoutput);
  676. begin
  677. {$warning FIX ME}
  678. end;
  679. procedure tcgppc.g_restore_standard_registers(list:Taasmoutput);
  680. begin
  681. {$warning FIX ME}
  682. end;
  683. procedure tcgppc.g_save_all_registers(list : taasmoutput);
  684. begin
  685. {$warning FIX ME}
  686. end;
  687. procedure tcgppc.g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);
  688. begin
  689. {$warning FIX ME}
  690. end;
  691. procedure tcgppc.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  692. begin
  693. a_jmp(list,A_BC,TOpCmp2AsmCond[cond],0,l);
  694. end;
  695. procedure tcgppc.a_jmp_always(list : taasmoutput;l: tasmlabel);
  696. begin
  697. a_jmp(list,A_B,C_None,0,l);
  698. end;
  699. procedure tcgppc.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  700. var
  701. c: tasmcond;
  702. begin
  703. c := flags_to_cond(f);
  704. a_jmp(list,A_BC,c.cond,c.cr-RS_CR0,l);
  705. end;
  706. procedure tcgppc.g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister);
  707. var
  708. testbit: byte;
  709. bitvalue: boolean;
  710. begin
  711. { get the bit to extract from the conditional register + its }
  712. { requested value (0 or 1) }
  713. testbit := ((f.cr-RS_CR0) * 4);
  714. case f.flag of
  715. F_EQ,F_NE:
  716. begin
  717. inc(testbit,2);
  718. bitvalue := f.flag = F_EQ;
  719. end;
  720. F_LT,F_GE:
  721. begin
  722. bitvalue := f.flag = F_LT;
  723. end;
  724. F_GT,F_LE:
  725. begin
  726. inc(testbit);
  727. bitvalue := f.flag = F_GT;
  728. end;
  729. else
  730. internalerror(200112261);
  731. end;
  732. { load the conditional register in the destination reg }
  733. list.concat(taicpu.op_reg(A_MFCR,reg));
  734. { we will move the bit that has to be tested to bit 0 by rotating }
  735. { left }
  736. testbit := (testbit + 1) and 31;
  737. { extract bit }
  738. list.concat(taicpu.op_reg_reg_const_const_const(
  739. A_RLWINM,reg,reg,testbit,31,31));
  740. { if we need the inverse, xor with 1 }
  741. if not bitvalue then
  742. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  743. end;
  744. (*
  745. procedure tcgppc.g_cond2reg(list: taasmoutput; const f: TAsmCond; reg: TRegister);
  746. var
  747. testbit: byte;
  748. bitvalue: boolean;
  749. begin
  750. { get the bit to extract from the conditional register + its }
  751. { requested value (0 or 1) }
  752. case f.simple of
  753. false:
  754. begin
  755. { we don't generate this in the compiler }
  756. internalerror(200109062);
  757. end;
  758. true:
  759. case f.cond of
  760. C_None:
  761. internalerror(200109063);
  762. C_LT..C_NU:
  763. begin
  764. testbit := (ord(f.cr) - ord(R_CR0))*4;
  765. inc(testbit,AsmCondFlag2BI[f.cond]);
  766. bitvalue := AsmCondFlagTF[f.cond];
  767. end;
  768. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  769. begin
  770. testbit := f.crbit
  771. bitvalue := AsmCondFlagTF[f.cond];
  772. end;
  773. else
  774. internalerror(200109064);
  775. end;
  776. end;
  777. { load the conditional register in the destination reg }
  778. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  779. { we will move the bit that has to be tested to bit 31 -> rotate }
  780. { left by bitpos+1 (remember, this is big-endian!) }
  781. if bitpos <> 31 then
  782. inc(bitpos)
  783. else
  784. bitpos := 0;
  785. { extract bit }
  786. list.concat(taicpu.op_reg_reg_const_const_const(
  787. A_RLWINM,reg,reg,bitpos,31,31));
  788. { if we need the inverse, xor with 1 }
  789. if not bitvalue then
  790. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  791. end;
  792. *)
  793. { *********** entry/exit code and address loading ************ }
  794. procedure tcgppc.g_stackframe_entry(list : taasmoutput;localsize : longint);
  795. { generated the entry code of a procedure/function. Note: localsize is the }
  796. { sum of the size necessary for local variables and the maximum possible }
  797. { combined size of ALL the parameters of a procedure called by the current }
  798. { one. }
  799. { This procedure may be called before, as well as after
  800. g_return_from_proc is called.}
  801. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  802. href,href2 : treference;
  803. usesfpr,usesgpr,gotgot : boolean;
  804. parastart : aword;
  805. offset : aword;
  806. // r,r2,rsp:Tregister;
  807. regcounter2: Tsuperregister;
  808. hp: tparaitem;
  809. begin
  810. { CR and LR only have to be saved in case they are modified by the current }
  811. { procedure, but currently this isn't checked, so save them always }
  812. { following is the entry code as described in "Altivec Programming }
  813. { Interface Manual", bar the saving of AltiVec registers }
  814. a_reg_alloc(list,NR_STACK_POINTER_REG);
  815. a_reg_alloc(list,NR_R0);
  816. if current_procinfo.procdef.parast.symtablelevel>1 then
  817. a_reg_alloc(list,NR_R11);
  818. usesfpr:=false;
  819. if not (po_assembler in current_procinfo.procdef.procoptions) then
  820. {$warning FIXME!!}
  821. { FIXME: has to be R_F8 instad of R_F14 for SYSV abi }
  822. for regcounter:=RS_F14 to RS_F31 do
  823. begin
  824. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  825. begin
  826. usesfpr:= true;
  827. firstregfpu:=regcounter;
  828. break;
  829. end;
  830. end;
  831. usesgpr:=false;
  832. if not (po_assembler in current_procinfo.procdef.procoptions) then
  833. for regcounter2:=RS_R13 to RS_R31 do
  834. begin
  835. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  836. begin
  837. usesgpr:=true;
  838. firstreggpr:=regcounter2;
  839. break;
  840. end;
  841. end;
  842. { save link register? }
  843. if not (po_assembler in current_procinfo.procdef.procoptions) then
  844. if (pi_do_call in current_procinfo.flags) then
  845. begin
  846. { save return address... }
  847. list.concat(taicpu.op_reg(A_MFLR,NR_R0));
  848. { ... in caller's frame }
  849. case target_info.abi of
  850. abi_powerpc_aix:
  851. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  852. abi_powerpc_sysv:
  853. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  854. end;
  855. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  856. a_reg_dealloc(list,NR_R0);
  857. end;
  858. { save the CR if necessary in callers frame. }
  859. if not (po_assembler in current_procinfo.procdef.procoptions) then
  860. if target_info.abi = abi_powerpc_aix then
  861. if false then { Not needed at the moment. }
  862. begin
  863. a_reg_alloc(list,NR_R0);
  864. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  865. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  866. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  867. a_reg_dealloc(list,NR_R0);
  868. end;
  869. { !!! always allocate space for all registers for now !!! }
  870. if not (po_assembler in current_procinfo.procdef.procoptions) then
  871. { if usesfpr or usesgpr then }
  872. begin
  873. a_reg_alloc(list,NR_R12);
  874. { save end of fpr save area }
  875. list.concat(taicpu.op_reg_reg(A_MR,NR_R12,NR_STACK_POINTER_REG));
  876. end;
  877. if (localsize <> 0) then
  878. begin
  879. if (localsize <= high(smallint)) then
  880. begin
  881. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  882. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  883. end
  884. else
  885. begin
  886. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  887. { can't use getregisterint here, the register colouring }
  888. { is already done when we get here }
  889. href.index := NR_R11;
  890. a_reg_alloc(list,href.index);
  891. a_load_const_reg(list,OS_S32,-localsize,href.index);
  892. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  893. a_reg_dealloc(list,href.index);
  894. end;
  895. end;
  896. { no GOT pointer loaded yet }
  897. gotgot:=false;
  898. if usesfpr then
  899. begin
  900. { save floating-point registers
  901. if (cs_create_pic in aktmoduleswitches) and not(usesgpr) then
  902. begin
  903. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g');
  904. gotgot:=true;
  905. end
  906. else
  907. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14));
  908. }
  909. reference_reset_base(href,NR_R12,-8);
  910. for regcounter:=firstregfpu to RS_F31 do
  911. begin
  912. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  913. begin
  914. a_loadfpu_reg_ref(list,OS_F64,newreg(R_FPUREGISTER,regcounter,R_SUBNONE),href);
  915. dec(href.offset,8);
  916. end;
  917. end;
  918. { compute end of gpr save area }
  919. a_op_const_reg(list,OP_ADD,OS_ADDR,aword(href.offset+8),NR_R12);
  920. end;
  921. { save gprs and fetch GOT pointer }
  922. if usesgpr then
  923. begin
  924. {
  925. if cs_create_pic in aktmoduleswitches then
  926. begin
  927. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g');
  928. gotgot:=true;
  929. end
  930. else
  931. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
  932. }
  933. reference_reset_base(href,NR_R12,-4);
  934. for regcounter2:=RS_R13 to RS_R31 do
  935. begin
  936. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  937. begin
  938. usesgpr:=true;
  939. a_load_reg_ref(list,OS_INT,OS_INT,newreg(R_INTREGISTER,regcounter2,R_SUBNONE),href);
  940. dec(href.offset,4);
  941. end;
  942. end;
  943. {
  944. r.enum:=R_INTREGISTER;
  945. r.:=;
  946. reference_reset_base(href,NR_R12,-((NR_R31-firstreggpr) shr 8+1)*4);
  947. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  948. }
  949. end;
  950. if assigned(current_procinfo.procdef.parast) then
  951. begin
  952. if not (po_assembler in current_procinfo.procdef.procoptions) then
  953. begin
  954. { copy memory parameters to local parast }
  955. hp:=tparaitem(current_procinfo.procdef.para.first);
  956. while assigned(hp) do
  957. begin
  958. if (hp.paraloc[calleeside].loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  959. begin
  960. if tvarsym(hp.parasym).localloc.loc<>LOC_REFERENCE then
  961. internalerror(200310011);
  962. reference_reset_base(href,tvarsym(hp.parasym).localloc.reference.index,tvarsym(hp.parasym).localloc.reference.offset);
  963. reference_reset_base(href2,NR_R12,hp.paraloc[callerside].reference.offset);
  964. { we can't use functions here which allocate registers (FK)
  965. cg.a_load_ref_ref(list,hp.paraloc[calleeside].size,hp.paraloc[calleeside].size,href2,href);
  966. }
  967. cg.a_load_ref_reg(list,hp.paraloc[calleeside].size,hp.paraloc[calleeside].size,href2,NR_R0);
  968. cg.a_load_reg_ref(list,hp.paraloc[calleeside].size,hp.paraloc[calleeside].size,NR_R0,href);
  969. end
  970. {$ifdef dummy}
  971. else if (hp.calleeparaloc.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  972. begin
  973. rg.getexplicitregisterint(list,hp.calleeparaloc.register);
  974. end
  975. {$endif dummy}
  976. ;
  977. hp := tparaitem(hp.next);
  978. end;
  979. end;
  980. end;
  981. if usesfpr or usesgpr then
  982. a_reg_dealloc(list,NR_R12);
  983. { PIC code support, }
  984. if cs_create_pic in aktmoduleswitches then
  985. begin
  986. { if we didn't get the GOT pointer till now, we've to calculate it now }
  987. if not(gotgot) then
  988. begin
  989. {!!!!!!!!!!!!!}
  990. end;
  991. a_reg_alloc(list,NR_R31);
  992. { place GOT ptr in r31 }
  993. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R31,NR_LR));
  994. end;
  995. { save the CR if necessary ( !!! always done currently ) }
  996. { still need to find out where this has to be done for SystemV
  997. a_reg_alloc(list,R_0);
  998. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  999. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  1000. new_reference(STACK_POINTER_REG,LA_CR)));
  1001. a_reg_dealloc(list,R_0); }
  1002. { now comes the AltiVec context save, not yet implemented !!! }
  1003. { if we're in a nested procedure, we've to save R11 }
  1004. if current_procinfo.procdef.parast.symtablelevel>2 then
  1005. begin
  1006. reference_reset_base(href,NR_STACK_POINTER_REG,PARENT_FRAMEPOINTER_OFFSET);
  1007. list.concat(taicpu.op_reg_ref(A_STW,NR_R11,href));
  1008. end;
  1009. end;
  1010. procedure tcgppc.g_return_from_proc(list : taasmoutput;parasize : aword);
  1011. { This procedure may be called before, as well as after
  1012. g_stackframe_entry is called.}
  1013. var
  1014. regcounter,firstregfpu,firstreggpr: TsuperRegister;
  1015. href : treference;
  1016. usesfpr,usesgpr,genret : boolean;
  1017. regcounter2:Tsuperregister;
  1018. localsize: aword;
  1019. begin
  1020. { AltiVec context restore, not yet implemented !!! }
  1021. usesfpr:=false;
  1022. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1023. for regcounter:=RS_F14 to RS_F31 do
  1024. begin
  1025. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1026. begin
  1027. usesfpr:=true;
  1028. firstregfpu:=regcounter;
  1029. break;
  1030. end;
  1031. end;
  1032. usesgpr:=false;
  1033. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1034. for regcounter2:=RS_R13 to RS_R31 do
  1035. begin
  1036. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1037. begin
  1038. usesgpr:=true;
  1039. firstreggpr:=regcounter2;
  1040. break;
  1041. end;
  1042. end;
  1043. localsize:= tppcprocinfo(current_procinfo).calc_stackframe_size;
  1044. { no return (blr) generated yet }
  1045. genret:=true;
  1046. if usesgpr or usesfpr then
  1047. begin
  1048. { address of gpr save area to r11 }
  1049. a_op_const_reg_reg(list,OP_ADD,OS_ADDR,localsize,NR_STACK_POINTER_REG,NR_R12);
  1050. if usesfpr then
  1051. begin
  1052. reference_reset_base(href,NR_R12,-8);
  1053. for regcounter := firstregfpu to RS_F31 do
  1054. begin
  1055. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1056. begin
  1057. a_loadfpu_ref_reg(list,OS_F64,href,newreg(R_FPUREGISTER,regcounter,R_SUBNONE));
  1058. dec(href.offset,8);
  1059. end;
  1060. end;
  1061. inc(href.offset,4);
  1062. end
  1063. else
  1064. reference_reset_base(href,NR_R12,-4);
  1065. for regcounter2:=RS_R13 to RS_R31 do
  1066. begin
  1067. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1068. begin
  1069. usesgpr:=true;
  1070. a_load_ref_reg(list,OS_INT,OS_INT,href,newreg(R_INTREGISTER,regcounter2,R_SUBNONE));
  1071. dec(href.offset,4);
  1072. end;
  1073. end;
  1074. (*
  1075. reference_reset_base(href,r2,-((NR_R31-ord(firstreggpr)) shr 8+1)*4);
  1076. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1077. *)
  1078. end;
  1079. (*
  1080. { restore fprs and return }
  1081. if usesfpr then
  1082. begin
  1083. { address of fpr save area to r11 }
  1084. r:=NR_R12;
  1085. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1086. {
  1087. if (pi_do_call in current_procinfo.flags) then
  1088. a_call_name(objectlibrary.newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  1089. '_x')
  1090. else
  1091. { leaf node => lr haven't to be restored }
  1092. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+
  1093. '_l');
  1094. genret:=false;
  1095. }
  1096. end;
  1097. *)
  1098. { if we didn't generate the return code, we've to do it now }
  1099. if genret then
  1100. begin
  1101. { adjust r1 }
  1102. a_op_const_reg(list,OP_ADD,OS_ADDR,localsize,NR_R1);
  1103. { load link register? }
  1104. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1105. begin
  1106. if (pi_do_call in current_procinfo.flags) then
  1107. begin
  1108. case target_info.abi of
  1109. abi_powerpc_aix:
  1110. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  1111. abi_powerpc_sysv:
  1112. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  1113. end;
  1114. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1115. list.concat(taicpu.op_reg(A_MTLR,NR_R0));
  1116. end;
  1117. { restore the CR if necessary from callers frame}
  1118. if target_info.abi = abi_powerpc_aix then
  1119. if false then { Not needed at the moment. }
  1120. begin
  1121. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1122. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1123. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1124. a_reg_dealloc(list,NR_R0);
  1125. end;
  1126. end;
  1127. list.concat(taicpu.op_none(A_BLR));
  1128. end;
  1129. end;
  1130. function tcgppc.save_regs(list : taasmoutput):longint;
  1131. {Generates code which saves used non-volatile registers in
  1132. the save area right below the address the stackpointer point to.
  1133. Returns the actual used save area size.}
  1134. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1135. usesfpr,usesgpr: boolean;
  1136. href : treference;
  1137. offset: integer;
  1138. regcounter2: Tsuperregister;
  1139. begin
  1140. usesfpr:=false;
  1141. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1142. for regcounter:=RS_F14 to RS_F31 do
  1143. begin
  1144. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1145. begin
  1146. usesfpr:=true;
  1147. firstregfpu:=regcounter;
  1148. break;
  1149. end;
  1150. end;
  1151. usesgpr:=false;
  1152. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1153. for regcounter2:=RS_R13 to RS_R31 do
  1154. begin
  1155. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1156. begin
  1157. usesgpr:=true;
  1158. firstreggpr:=regcounter2;
  1159. break;
  1160. end;
  1161. end;
  1162. offset:= 0;
  1163. { save floating-point registers }
  1164. if usesfpr then
  1165. for regcounter := firstregfpu to RS_F31 do
  1166. begin
  1167. offset:= offset - 8;
  1168. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1169. list.concat(taicpu.op_reg_ref(A_STFD, regcounter, href));
  1170. end;
  1171. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1172. { save gprs in gpr save area }
  1173. if usesgpr then
  1174. if firstreggpr < RS_R30 then
  1175. begin
  1176. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1177. reference_reset_base(href,NR_STACK_POINTER_REG,offset);
  1178. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  1179. {STMW stores multiple registers}
  1180. end
  1181. else
  1182. begin
  1183. for regcounter := firstreggpr to RS_R31 do
  1184. begin
  1185. offset:= offset - 4;
  1186. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1187. list.concat(taicpu.op_reg_ref(A_STW, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1188. end;
  1189. end;
  1190. { now comes the AltiVec context save, not yet implemented !!! }
  1191. save_regs:= -offset;
  1192. end;
  1193. procedure tcgppc.restore_regs(list : taasmoutput);
  1194. {Generates code which restores used non-volatile registers from
  1195. the save area right below the address the stackpointer point to.}
  1196. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1197. usesfpr,usesgpr: boolean;
  1198. href : treference;
  1199. offset: integer;
  1200. regcounter2: Tsuperregister;
  1201. begin
  1202. usesfpr:=false;
  1203. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1204. for regcounter:=RS_F14 to RS_F31 do
  1205. begin
  1206. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1207. begin
  1208. usesfpr:=true;
  1209. firstregfpu:=regcounter;
  1210. break;
  1211. end;
  1212. end;
  1213. usesgpr:=false;
  1214. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1215. for regcounter2:=RS_R13 to RS_R31 do
  1216. begin
  1217. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1218. begin
  1219. usesgpr:=true;
  1220. firstreggpr:=regcounter2;
  1221. break;
  1222. end;
  1223. end;
  1224. offset:= 0;
  1225. { restore fp registers }
  1226. if usesfpr then
  1227. for regcounter := firstregfpu to RS_F31 do
  1228. begin
  1229. offset:= offset - 8;
  1230. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1231. list.concat(taicpu.op_reg_ref(A_LFD, newreg(R_FPUREGISTER,regcounter,R_SUBWHOLE), href));
  1232. end;
  1233. (* Optimiztion in the future: a_call_name(list,'_restfXX'); *)
  1234. { restore gprs }
  1235. if usesgpr then
  1236. if firstreggpr < RS_R30 then
  1237. begin
  1238. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1239. reference_reset_base(href,NR_STACK_POINTER_REG,offset); //-220
  1240. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1241. {LMW loads multiple registers}
  1242. end
  1243. else
  1244. begin
  1245. for regcounter := firstreggpr to RS_R31 do
  1246. begin
  1247. offset:= offset - 4;
  1248. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1249. list.concat(taicpu.op_reg_ref(A_LWZ, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1250. end;
  1251. end;
  1252. { now comes the AltiVec context restore, not yet implemented !!! }
  1253. end;
  1254. procedure tcgppc.g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  1255. (* NOT IN USE *)
  1256. { generated the entry code of a procedure/function. Note: localsize is the }
  1257. { sum of the size necessary for local variables and the maximum possible }
  1258. { combined size of ALL the parameters of a procedure called by the current }
  1259. { one }
  1260. const
  1261. macosLinkageAreaSize = 24;
  1262. var regcounter: TRegister;
  1263. href : treference;
  1264. registerSaveAreaSize : longint;
  1265. begin
  1266. if (localsize mod 8) <> 0 then
  1267. internalerror(58991);
  1268. { CR and LR only have to be saved in case they are modified by the current }
  1269. { procedure, but currently this isn't checked, so save them always }
  1270. { following is the entry code as described in "Altivec Programming }
  1271. { Interface Manual", bar the saving of AltiVec registers }
  1272. a_reg_alloc(list,NR_STACK_POINTER_REG);
  1273. a_reg_alloc(list,NR_R0);
  1274. { save return address in callers frame}
  1275. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_LR));
  1276. { ... in caller's frame }
  1277. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1278. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1279. a_reg_dealloc(list,NR_R0);
  1280. { save non-volatile registers in callers frame}
  1281. registerSaveAreaSize:= save_regs(list);
  1282. { save the CR if necessary in callers frame ( !!! always done currently ) }
  1283. a_reg_alloc(list,NR_R0);
  1284. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  1285. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1286. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1287. a_reg_dealloc(list,NR_R0);
  1288. (*
  1289. { save pointer to incoming arguments }
  1290. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  1291. *)
  1292. (*
  1293. a_reg_alloc(list,R_12);
  1294. { 0 or 8 based on SP alignment }
  1295. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  1296. R_12,STACK_POINTER_REG,0,28,28));
  1297. { add in stack length }
  1298. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1299. -localsize));
  1300. { establish new alignment }
  1301. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1302. a_reg_dealloc(list,R_12);
  1303. *)
  1304. { allocate stack frame }
  1305. localsize:= align(localsize + macosLinkageAreaSize + registerSaveAreaSize, 16);
  1306. inc(localsize,tg.lasttemp);
  1307. localsize:=align(localsize,16);
  1308. //tppcprocinfo(current_procinfo).localsize:=localsize;
  1309. if (localsize <> 0) then
  1310. begin
  1311. if (localsize <= high(smallint)) then
  1312. begin
  1313. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  1314. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  1315. end
  1316. else
  1317. begin
  1318. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1319. href.index := NR_R11;
  1320. a_reg_alloc(list,href.index);
  1321. a_load_const_reg(list,OS_S32,-localsize,href.index);
  1322. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  1323. a_reg_dealloc(list,href.index);
  1324. end;
  1325. end;
  1326. end;
  1327. procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  1328. (* NOT IN USE *)
  1329. var
  1330. href : treference;
  1331. begin
  1332. a_reg_alloc(list,NR_R0);
  1333. { restore stack pointer }
  1334. reference_reset_base(href,NR_STACK_POINTER_REG,LA_SP);
  1335. list.concat(taicpu.op_reg_ref(A_LWZ,NR_STACK_POINTER_REG,href));
  1336. (*
  1337. list.concat(taicpu.op_reg_reg_const(A_ORI,NR_STACK_POINTER_REG,R_31,0));
  1338. *)
  1339. { restore the CR if necessary from callers frame
  1340. ( !!! always done currently ) }
  1341. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1342. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1343. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1344. a_reg_dealloc(list,NR_R0);
  1345. (*
  1346. { restore return address from callers frame }
  1347. reference_reset_base(href,STACK_POINTER_REG,8);
  1348. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1349. *)
  1350. { restore non-volatile registers from callers frame }
  1351. restore_regs(list);
  1352. (*
  1353. { return to caller }
  1354. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1355. list.concat(taicpu.op_none(A_BLR));
  1356. *)
  1357. { restore return address from callers frame }
  1358. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1359. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1360. { return to caller }
  1361. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_LR));
  1362. list.concat(taicpu.op_none(A_BLR));
  1363. end;
  1364. procedure tcgppc.g_restore_frame_pointer(list : taasmoutput);
  1365. begin
  1366. { no frame pointer on the PowerPC (maybe there is one in the SystemV ABI?)}
  1367. end;
  1368. procedure tcgppc.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  1369. var
  1370. ref2, tmpref: treference;
  1371. freereg: boolean;
  1372. tmpreg:Tregister;
  1373. begin
  1374. ref2 := ref;
  1375. freereg := fixref(list,ref2);
  1376. if assigned(ref2.symbol) then
  1377. begin
  1378. if target_info.system = system_powerpc_macos then
  1379. begin
  1380. if macos_direct_globals then
  1381. begin
  1382. reference_reset(tmpref);
  1383. tmpref.offset := ref2.offset;
  1384. tmpref.symbol := ref2.symbol;
  1385. tmpref.base := NR_NO;
  1386. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,NR_RTOC,tmpref));
  1387. end
  1388. else
  1389. begin
  1390. reference_reset(tmpref);
  1391. tmpref.symbol := ref2.symbol;
  1392. tmpref.offset := 0;
  1393. tmpref.base := NR_RTOC;
  1394. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref));
  1395. if ref2.offset <> 0 then
  1396. begin
  1397. reference_reset(tmpref);
  1398. tmpref.offset := ref2.offset;
  1399. tmpref.base:= r;
  1400. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1401. end;
  1402. end;
  1403. if ref2.base <> NR_NO then
  1404. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,r,ref2.base));
  1405. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1406. end
  1407. else
  1408. begin
  1409. { add the symbol's value to the base of the reference, and if the }
  1410. { reference doesn't have a base, create one }
  1411. reference_reset(tmpref);
  1412. tmpref.offset := ref2.offset;
  1413. tmpref.symbol := ref2.symbol;
  1414. tmpref.symaddr := refs_ha;
  1415. if ref2.base<> NR_NO then
  1416. begin
  1417. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1418. ref2.base,tmpref));
  1419. if freereg then
  1420. begin
  1421. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  1422. freereg := false;
  1423. end;
  1424. end
  1425. else
  1426. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1427. tmpref.base := NR_NO;
  1428. tmpref.symaddr := refs_l;
  1429. { can be folded with one of the next instructions by the }
  1430. { optimizer probably }
  1431. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1432. end
  1433. end
  1434. else if ref2.offset <> 0 Then
  1435. if ref2.base <> NR_NO then
  1436. a_op_const_reg_reg(list,OP_ADD,OS_32,aword(ref2.offset),ref2.base,r)
  1437. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1438. { occurs, so now only ref.offset has to be loaded }
  1439. else
  1440. a_load_const_reg(list,OS_32,ref2.offset,r)
  1441. else if ref.index <> NR_NO Then
  1442. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1443. else if (ref2.base <> NR_NO) and
  1444. (r <> ref2.base) then
  1445. list.concat(taicpu.op_reg_reg(A_MR,r,ref2.base));
  1446. if freereg then
  1447. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  1448. end;
  1449. { ************* concatcopy ************ }
  1450. {$ifndef ppc603}
  1451. const
  1452. maxmoveunit = 8;
  1453. {$else ppc603}
  1454. const
  1455. maxmoveunit = 4;
  1456. {$endif ppc603}
  1457. procedure tcgppc.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  1458. var
  1459. countreg: TRegister;
  1460. src, dst: TReference;
  1461. lab: tasmlabel;
  1462. count, count2: aword;
  1463. orgsrc, orgdst: boolean;
  1464. size: tcgsize;
  1465. begin
  1466. {$ifdef extdebug}
  1467. if len > high(longint) then
  1468. internalerror(2002072704);
  1469. {$endif extdebug}
  1470. { make sure short loads are handled as optimally as possible }
  1471. if not loadref then
  1472. if (len <= maxmoveunit) and
  1473. (byte(len) in [1,2,4,8]) then
  1474. begin
  1475. if len < 8 then
  1476. begin
  1477. size := int_cgsize(len);
  1478. a_load_ref_ref(list,size,size,source,dest);
  1479. if delsource then
  1480. begin
  1481. reference_release(list,source);
  1482. tg.ungetiftemp(list,source);
  1483. end;
  1484. end
  1485. else
  1486. begin
  1487. a_reg_alloc(list,NR_F0);
  1488. a_loadfpu_ref_reg(list,OS_F64,source,NR_F0);
  1489. if delsource then
  1490. begin
  1491. reference_release(list,source);
  1492. tg.ungetiftemp(list,source);
  1493. end;
  1494. a_loadfpu_reg_ref(list,OS_F64,NR_F0,dest);
  1495. a_reg_dealloc(list,NR_F0);
  1496. end;
  1497. exit;
  1498. end;
  1499. count := len div maxmoveunit;
  1500. reference_reset(src);
  1501. reference_reset(dst);
  1502. { load the address of source into src.base }
  1503. if loadref then
  1504. begin
  1505. src.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1506. a_load_ref_reg(list,OS_32,OS_32,source,src.base);
  1507. orgsrc := false;
  1508. end
  1509. else if (count > 4) or
  1510. not issimpleref(source) or
  1511. ((source.index <> NR_NO) and
  1512. ((source.offset + longint(len)) > high(smallint))) then
  1513. begin
  1514. src.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1515. a_loadaddr_ref_reg(list,source,src.base);
  1516. orgsrc := false;
  1517. end
  1518. else
  1519. begin
  1520. src := source;
  1521. orgsrc := true;
  1522. end;
  1523. if not orgsrc and delsource then
  1524. reference_release(list,source);
  1525. { load the address of dest into dst.base }
  1526. if (count > 4) or
  1527. not issimpleref(dest) or
  1528. ((dest.index <> NR_NO) and
  1529. ((dest.offset + longint(len)) > high(smallint))) then
  1530. begin
  1531. dst.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1532. a_loadaddr_ref_reg(list,dest,dst.base);
  1533. orgdst := false;
  1534. end
  1535. else
  1536. begin
  1537. dst := dest;
  1538. orgdst := true;
  1539. end;
  1540. {$ifndef ppc603}
  1541. if count > 4 then
  1542. { generate a loop }
  1543. begin
  1544. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1545. { have to be set to 8. I put an Inc there so debugging may be }
  1546. { easier (should offset be different from zero here, it will be }
  1547. { easy to notice in the generated assembler }
  1548. inc(dst.offset,8);
  1549. inc(src.offset,8);
  1550. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1551. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1552. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1553. a_load_const_reg(list,OS_32,count,countreg);
  1554. { explicitely allocate R_0 since it can be used safely here }
  1555. { (for holding date that's being copied) }
  1556. a_reg_alloc(list,NR_F0);
  1557. objectlibrary.getlabel(lab);
  1558. a_label(list, lab);
  1559. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1560. list.concat(taicpu.op_reg_ref(A_LFDU,NR_F0,src));
  1561. list.concat(taicpu.op_reg_ref(A_STFDU,NR_F0,dst));
  1562. a_jmp(list,A_BC,C_NE,0,lab);
  1563. rg[R_INTREGISTER].ungetregister(list,countreg);
  1564. a_reg_dealloc(list,NR_F0);
  1565. len := len mod 8;
  1566. end;
  1567. count := len div 8;
  1568. if count > 0 then
  1569. { unrolled loop }
  1570. begin
  1571. a_reg_alloc(list,NR_F0);
  1572. for count2 := 1 to count do
  1573. begin
  1574. a_loadfpu_ref_reg(list,OS_F64,src,NR_F0);
  1575. a_loadfpu_reg_ref(list,OS_F64,NR_F0,dst);
  1576. inc(src.offset,8);
  1577. inc(dst.offset,8);
  1578. end;
  1579. a_reg_dealloc(list,NR_F0);
  1580. len := len mod 8;
  1581. end;
  1582. if (len and 4) <> 0 then
  1583. begin
  1584. a_reg_alloc(list,NR_R0);
  1585. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1586. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1587. inc(src.offset,4);
  1588. inc(dst.offset,4);
  1589. a_reg_dealloc(list,NR_R0);
  1590. end;
  1591. {$else not ppc603}
  1592. if count > 4 then
  1593. { generate a loop }
  1594. begin
  1595. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1596. { have to be set to 4. I put an Inc there so debugging may be }
  1597. { easier (should offset be different from zero here, it will be }
  1598. { easy to notice in the generated assembler }
  1599. inc(dst.offset,4);
  1600. inc(src.offset,4);
  1601. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,4));
  1602. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,4));
  1603. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1604. a_load_const_reg(list,OS_32,count,countreg);
  1605. { explicitely allocate R_0 since it can be used safely here }
  1606. { (for holding date that's being copied) }
  1607. a_reg_alloc(list,NR_R0);
  1608. objectlibrary.getlabel(lab);
  1609. a_label(list, lab);
  1610. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1611. list.concat(taicpu.op_reg_ref(A_LWZU,NR_R0,src));
  1612. list.concat(taicpu.op_reg_ref(A_STWU,NR_R0,dst));
  1613. a_jmp(list,A_BC,C_NE,0,lab);
  1614. rg[R_INTREGISTER].ungetregister(list,countreg);
  1615. a_reg_dealloc(list,NR_R0);
  1616. len := len mod 4;
  1617. end;
  1618. count := len div 4;
  1619. if count > 0 then
  1620. { unrolled loop }
  1621. begin
  1622. a_reg_alloc(list,NR_R0);
  1623. for count2 := 1 to count do
  1624. begin
  1625. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1626. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1627. inc(src.offset,4);
  1628. inc(dst.offset,4);
  1629. end;
  1630. a_reg_dealloc(list,NR_R0);
  1631. len := len mod 4;
  1632. end;
  1633. {$endif not ppc603}
  1634. { copy the leftovers }
  1635. if (len and 2) <> 0 then
  1636. begin
  1637. a_reg_alloc(list,NR_R0);
  1638. a_load_ref_reg(list,OS_16,OS_16,src,NR_R0);
  1639. a_load_reg_ref(list,OS_16,OS_16,NR_R0,dst);
  1640. inc(src.offset,2);
  1641. inc(dst.offset,2);
  1642. a_reg_dealloc(list,NR_R0);
  1643. end;
  1644. if (len and 1) <> 0 then
  1645. begin
  1646. a_reg_alloc(list,NR_R0);
  1647. a_load_ref_reg(list,OS_8,OS_8,src,NR_R0);
  1648. a_load_reg_ref(list,OS_8,OS_8,NR_R0,dst);
  1649. a_reg_dealloc(list,NR_R0);
  1650. end;
  1651. if orgsrc then
  1652. begin
  1653. if delsource then
  1654. reference_release(list,source);
  1655. end
  1656. else
  1657. rg[R_INTREGISTER].ungetregister(list,src.base);
  1658. if not orgdst then
  1659. rg[R_INTREGISTER].ungetregister(list,dst.base);
  1660. if delsource then
  1661. tg.ungetiftemp(list,source);
  1662. end;
  1663. procedure tcgppc.g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:aword);
  1664. var
  1665. sizereg,sourcereg : tregister;
  1666. paraloc1,paraloc2,paraloc3 : tparalocation;
  1667. begin
  1668. { because ppc abi doesn't support dynamic stack allocation properly
  1669. open array value parameters are copied onto the heap
  1670. }
  1671. { allocate two registers for len and source }
  1672. sizereg:=getintregister(list,OS_INT);
  1673. sourcereg:=getintregister(list,OS_INT);
  1674. { calculate necessary memory }
  1675. a_load_ref_reg(list,OS_INT,OS_INT,lenref,sizereg);
  1676. a_op_const_reg_reg(list,OP_MUL,OS_INT,elesize,sizereg,sizereg);
  1677. { load source }
  1678. a_load_ref_reg(list,OS_ADDR,OS_ADDR,ref,sourcereg);
  1679. { do getmem call }
  1680. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1681. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1682. paramanager.allocparaloc(list,paraloc2);
  1683. a_param_reg(list,OS_INT,sizereg,paraloc2);
  1684. paramanager.allocparaloc(list,paraloc1);
  1685. a_paramaddr_ref(list,ref,paraloc1);
  1686. paramanager.freeparaloc(list,paraloc2);
  1687. paramanager.freeparaloc(list,paraloc1);
  1688. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1689. a_call_name(list,'FPC_GETMEM');
  1690. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1691. { do move call }
  1692. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1693. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1694. paraloc3:=paramanager.getintparaloc(pocall_default,3);
  1695. { load size }
  1696. paramanager.allocparaloc(list,paraloc3);
  1697. a_param_reg(list,OS_INT,sizereg,paraloc3);
  1698. { load destination }
  1699. paramanager.allocparaloc(list,paraloc2);
  1700. a_param_ref(list,OS_ADDR,ref,paraloc2);
  1701. { load source }
  1702. paramanager.allocparaloc(list,paraloc1);
  1703. a_param_reg(list,OS_ADDR,sourcereg,paraloc1);
  1704. paramanager.freeparaloc(list,paraloc3);
  1705. paramanager.freeparaloc(list,paraloc2);
  1706. paramanager.freeparaloc(list,paraloc1);
  1707. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1708. a_call_name(list,'FPC_MOVE');
  1709. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1710. { release used registers }
  1711. ungetregister(list,sizereg);
  1712. ungetregister(list,sourcereg);
  1713. end;
  1714. procedure tcgppc.g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);
  1715. var
  1716. paraloc : tparalocation;
  1717. begin
  1718. { do move call }
  1719. paraloc:=paramanager.getintparaloc(pocall_default,1);
  1720. { load source }
  1721. paramanager.allocparaloc(list,paraloc);
  1722. a_param_ref(list,OS_ADDR,ref,paraloc);
  1723. paramanager.freeparaloc(list,paraloc);
  1724. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1725. a_call_name(list,'FPC_FREEMEM');
  1726. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1727. end;
  1728. procedure tcgppc.g_overflowcheck(list: taasmoutput; const l: tlocation; def: tdef);
  1729. var
  1730. hl : tasmlabel;
  1731. begin
  1732. if not(cs_check_overflow in aktlocalswitches) then
  1733. exit;
  1734. objectlibrary.getlabel(hl);
  1735. if not ((def.deftype=pointerdef) or
  1736. ((def.deftype=orddef) and
  1737. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1738. bool8bit,bool16bit,bool32bit]))) then
  1739. begin
  1740. list.concat(taicpu.op_reg(A_MCRXR,NR_CR7));
  1741. a_jmp(list,A_BC,C_NO,7,hl)
  1742. end
  1743. else
  1744. a_jmp_cond(list,OC_AE,hl);
  1745. a_call_name(list,'FPC_OVERFLOW');
  1746. a_label(list,hl);
  1747. end;
  1748. {***************** This is private property, keep out! :) *****************}
  1749. function tcgppc.issimpleref(const ref: treference): boolean;
  1750. begin
  1751. if (ref.base = NR_NO) and
  1752. (ref.index <> NR_NO) then
  1753. internalerror(200208101);
  1754. result :=
  1755. not(assigned(ref.symbol)) and
  1756. (((ref.index = NR_NO) and
  1757. (ref.offset >= low(smallint)) and
  1758. (ref.offset <= high(smallint))) or
  1759. ((ref.index <> NR_NO) and
  1760. (ref.offset = 0)));
  1761. end;
  1762. function tcgppc.fixref(list: taasmoutput; var ref: treference): boolean;
  1763. var
  1764. tmpreg: tregister;
  1765. orgindex: tregister;
  1766. freeindex: boolean;
  1767. begin
  1768. result := false;
  1769. if (ref.base = NR_NO) then
  1770. begin
  1771. ref.base := ref.index;
  1772. ref.base := NR_NO;
  1773. end;
  1774. if (ref.base <> NR_NO) then
  1775. begin
  1776. if (ref.index <> NR_NO) and
  1777. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1778. begin
  1779. result := true;
  1780. { references are often freed before they are used. Since we allocate }
  1781. { a register here, we must first reallocate the index register, since }
  1782. { otherwise it may be overwritten (and it's still used afterwards) }
  1783. freeindex := false;
  1784. if (ref.index >= first_int_imreg) and
  1785. (supregset_in(rg[R_INTREGISTER].unusedregs,getsupreg(ref.index))) then
  1786. begin
  1787. rg[R_INTREGISTER].getexplicitregister(list,ref.index);
  1788. orgindex := ref.index;
  1789. freeindex := true;
  1790. end;
  1791. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1792. if not assigned(ref.symbol) and
  1793. (cardinal(ref.offset-low(smallint)) <=
  1794. high(smallint)-low(smallint)) then
  1795. begin
  1796. list.concat(taicpu.op_reg_reg_const(
  1797. A_ADDI,tmpreg,ref.base,ref.offset));
  1798. ref.offset := 0;
  1799. end
  1800. else
  1801. begin
  1802. list.concat(taicpu.op_reg_reg_reg(
  1803. A_ADD,tmpreg,ref.base,ref.index));
  1804. ref.index := NR_NO;
  1805. end;
  1806. ref.base := tmpreg;
  1807. if freeindex then
  1808. rg[R_INTREGISTER].ungetregister(list,orgindex);
  1809. end
  1810. end
  1811. else
  1812. if ref.index <> NR_NO then
  1813. internalerror(200208102);
  1814. end;
  1815. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1816. { that's the case, we can use rlwinm to do an AND operation }
  1817. function tcgppc.get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  1818. var
  1819. temp : longint;
  1820. testbit : aword;
  1821. compare: boolean;
  1822. begin
  1823. get_rlwi_const := false;
  1824. if (a = 0) or (a = $ffffffff) then
  1825. exit;
  1826. { start with the lowest bit }
  1827. testbit := 1;
  1828. { check its value }
  1829. compare := boolean(a and testbit);
  1830. { find out how long the run of bits with this value is }
  1831. { (it's impossible that all bits are 1 or 0, because in that case }
  1832. { this function wouldn't have been called) }
  1833. l1 := 31;
  1834. while (((a and testbit) <> 0) = compare) do
  1835. begin
  1836. testbit := testbit shl 1;
  1837. dec(l1);
  1838. end;
  1839. { check the length of the run of bits that comes next }
  1840. compare := not compare;
  1841. l2 := l1;
  1842. while (((a and testbit) <> 0) = compare) and
  1843. (l2 >= 0) do
  1844. begin
  1845. testbit := testbit shl 1;
  1846. dec(l2);
  1847. end;
  1848. { and finally the check whether the rest of the bits all have the }
  1849. { same value }
  1850. compare := not compare;
  1851. temp := l2;
  1852. if temp >= 0 then
  1853. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1854. exit;
  1855. { we have done "not(not(compare))", so compare is back to its }
  1856. { initial value. If the lowest bit was 0, a is of the form }
  1857. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1858. { because l2 now contains the position of the last zero of the }
  1859. { first run instead of that of the first 1) so switch l1 and l2 }
  1860. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1861. if not compare then
  1862. begin
  1863. temp := l1;
  1864. l1 := l2+1;
  1865. l2 := temp;
  1866. end
  1867. else
  1868. { otherwise, l1 currently contains the position of the last }
  1869. { zero instead of that of the first 1 of the second run -> +1 }
  1870. inc(l1);
  1871. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1872. l1 := l1 and 31;
  1873. l2 := l2 and 31;
  1874. get_rlwi_const := true;
  1875. end;
  1876. procedure tcgppc.a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  1877. ref: treference);
  1878. var
  1879. tmpreg: tregister;
  1880. tmpregUsed: Boolean;
  1881. tmpref: treference;
  1882. largeOffset: Boolean;
  1883. begin
  1884. tmpreg := NR_NO;
  1885. if target_info.system = system_powerpc_macos then
  1886. begin
  1887. largeOffset:= (cardinal(ref.offset-low(smallint)) >
  1888. high(smallint)-low(smallint));
  1889. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1890. tmpregUsed:= false;
  1891. if assigned(ref.symbol) then
  1892. begin //Load symbol's value
  1893. reference_reset(tmpref);
  1894. tmpref.symbol := ref.symbol;
  1895. tmpref.base := NR_RTOC;
  1896. if macos_direct_globals then
  1897. list.concat(taicpu.op_reg_ref(A_LA,tmpreg,tmpref))
  1898. else
  1899. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1900. tmpregUsed:= true;
  1901. end;
  1902. if largeOffset then
  1903. begin //Add hi part of offset
  1904. reference_reset(tmpref);
  1905. tmpref.offset := Hi(ref.offset);
  1906. if tmpregUsed then
  1907. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1908. tmpreg,tmpref))
  1909. else
  1910. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1911. tmpregUsed:= true;
  1912. end;
  1913. if tmpregUsed then
  1914. begin
  1915. //Add content of base register
  1916. if ref.base <> NR_NO then
  1917. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1918. ref.base,tmpreg));
  1919. //Make ref ready to be used by op
  1920. ref.symbol:= nil;
  1921. ref.base:= tmpreg;
  1922. if largeOffset then
  1923. ref.offset := Lo(ref.offset);
  1924. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1925. //list.concat(tai_comment.create(strpnew('*** a_load_store indirect global')));
  1926. end
  1927. else
  1928. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1929. end
  1930. else {if target_info.system <> system_powerpc_macos}
  1931. begin
  1932. if assigned(ref.symbol) or
  1933. (cardinal(ref.offset-low(smallint)) >
  1934. high(smallint)-low(smallint)) then
  1935. begin
  1936. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1937. reference_reset(tmpref);
  1938. tmpref.symbol := ref.symbol;
  1939. tmpref.offset := ref.offset;
  1940. tmpref.symaddr := refs_ha;
  1941. if ref.base <> NR_NO then
  1942. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1943. ref.base,tmpref))
  1944. else
  1945. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1946. ref.base := tmpreg;
  1947. ref.symaddr := refs_l;
  1948. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1949. end
  1950. else
  1951. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1952. end;
  1953. if (tmpreg <> NR_NO) then
  1954. rg[R_INTREGISTER].ungetregister(list,tmpreg);
  1955. end;
  1956. procedure tcgppc.a_jmp(list: taasmoutput; op: tasmop; c: tasmcondflag;
  1957. crval: longint; l: tasmlabel);
  1958. var
  1959. p: taicpu;
  1960. begin
  1961. p := taicpu.op_sym(op,objectlibrary.newasmsymbol(l.name));
  1962. if op <> A_B then
  1963. create_cond_norm(c,crval,p.condition);
  1964. p.is_jmp := true;
  1965. list.concat(p)
  1966. end;
  1967. procedure tcg64fppc.a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);
  1968. begin
  1969. a_op64_reg_reg_reg(list,op,regsrc,regdst,regdst);
  1970. end;
  1971. procedure tcg64fppc.a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);
  1972. begin
  1973. a_op64_const_reg_reg(list,op,value,reg,reg);
  1974. end;
  1975. procedure tcg64fppc.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1976. begin
  1977. case op of
  1978. OP_AND,OP_OR,OP_XOR:
  1979. begin
  1980. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1981. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1982. end;
  1983. OP_ADD:
  1984. begin
  1985. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1986. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1987. end;
  1988. OP_SUB:
  1989. begin
  1990. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1991. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1992. end;
  1993. else
  1994. internalerror(2002072801);
  1995. end;
  1996. end;
  1997. procedure tcg64fppc.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);
  1998. const
  1999. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  2000. (A_SUBIC,A_SUBC,A_ADDME));
  2001. var
  2002. tmpreg: tregister;
  2003. tmpreg64: tregister64;
  2004. issub: boolean;
  2005. begin
  2006. case op of
  2007. OP_AND,OP_OR,OP_XOR:
  2008. begin
  2009. cg.a_op_const_reg_reg(list,op,OS_32,aword(value),regsrc.reglo,regdst.reglo);
  2010. cg.a_op_const_reg_reg(list,op,OS_32,aword(value shr 32),regsrc.reghi,
  2011. regdst.reghi);
  2012. end;
  2013. OP_ADD, OP_SUB:
  2014. begin
  2015. if (int64(value) < 0) then
  2016. begin
  2017. if op = OP_ADD then
  2018. op := OP_SUB
  2019. else
  2020. op := OP_ADD;
  2021. int64(value) := -int64(value);
  2022. end;
  2023. if (longint(value) <> 0) then
  2024. begin
  2025. issub := op = OP_SUB;
  2026. if (int64(value) > 0) and
  2027. (int64(value)-ord(issub) <= 32767) then
  2028. begin
  2029. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  2030. regdst.reglo,regsrc.reglo,longint(value)));
  2031. list.concat(taicpu.op_reg_reg(ops[issub,3],
  2032. regdst.reghi,regsrc.reghi));
  2033. end
  2034. else if ((value shr 32) = 0) then
  2035. begin
  2036. tmpreg := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  2037. cg.a_load_const_reg(list,OS_32,cardinal(value),tmpreg);
  2038. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  2039. regdst.reglo,regsrc.reglo,tmpreg));
  2040. tcgppc(cg).rg[R_INTREGISTER].ungetregister(list,tmpreg);
  2041. list.concat(taicpu.op_reg_reg(ops[issub,3],
  2042. regdst.reghi,regsrc.reghi));
  2043. end
  2044. else
  2045. begin
  2046. tmpreg64.reglo := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  2047. tmpreg64.reghi := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  2048. a_load64_const_reg(list,value,tmpreg64);
  2049. a_op64_reg_reg_reg(list,op,tmpreg64,regsrc,regdst);
  2050. tcgppc(cg).rg[R_INTREGISTER].ungetregister(list,tmpreg64.reglo);
  2051. tcgppc(cg).rg[R_INTREGISTER].ungetregister(list,tmpreg64.reghi);
  2052. end
  2053. end
  2054. else
  2055. begin
  2056. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  2057. cg.a_op_const_reg_reg(list,op,OS_32,aword(value shr 32),regsrc.reghi,
  2058. regdst.reghi);
  2059. end;
  2060. end;
  2061. else
  2062. internalerror(2002072802);
  2063. end;
  2064. end;
  2065. begin
  2066. cg := tcgppc.create;
  2067. cg64 :=tcg64fppc.create;
  2068. end.
  2069. {
  2070. $Log$
  2071. Revision 1.146 2003-12-12 17:16:18 peter
  2072. * rg[tregistertype] added in tcg
  2073. Revision 1.145 2003/12/10 00:09:57 karoly
  2074. * fixed compilation with -dppc603
  2075. Revision 1.144 2003/12/09 20:39:43 jonas
  2076. * forgot call to cg.g_overflowcheck() in nppcadd
  2077. * fixed overflow flag definition
  2078. * fixed cg.g_overflowcheck() for signed numbers (jump over call to
  2079. FPC_OVERFLOW if *no* overflow instead of if overflow :)
  2080. Revision 1.143 2003/12/07 21:59:21 florian
  2081. * a_load_ref_ref isn't allowed to be used in g_stackframe_entry
  2082. Revision 1.142 2003/12/06 22:13:53 jonas
  2083. * another fix to a_load_ref_reg()
  2084. + implemented uses_registers() method
  2085. Revision 1.141 2003/12/05 22:53:28 jonas
  2086. * fixed load_ref_reg for source > dest size
  2087. Revision 1.140 2003/12/04 20:37:02 jonas
  2088. * fixed some int<->boolean type conversion issues
  2089. Revision 1.139 2003/11/30 11:32:12 jonas
  2090. * fixded fixref() regarding the reallocation of already freed registers
  2091. used in references
  2092. Revision 1.138 2003/11/30 10:16:05 jonas
  2093. * fixed fpu regallocator initialisation
  2094. Revision 1.137 2003/11/21 16:29:26 florian
  2095. * fixed reading of reg. sets in the arm assembler reader
  2096. Revision 1.136 2003/11/02 17:19:33 florian
  2097. + copying of open array value parameters to the heap implemented
  2098. Revision 1.135 2003/11/02 15:20:06 jonas
  2099. * fixed releasing of references (ppc also has a base and an index, not
  2100. just a base)
  2101. Revision 1.134 2003/10/19 01:34:30 florian
  2102. * some ppc stuff fixed
  2103. * memory leak fixed
  2104. Revision 1.133 2003/10/17 15:25:18 florian
  2105. * fixed more ppc stuff
  2106. Revision 1.132 2003/10/17 15:08:34 peter
  2107. * commented out more obsolete constants
  2108. Revision 1.131 2003/10/17 14:52:07 peter
  2109. * fixed ppc build
  2110. Revision 1.130 2003/10/17 01:22:08 florian
  2111. * compilation of the powerpc compiler fixed
  2112. Revision 1.129 2003/10/13 01:58:04 florian
  2113. * some ideas for mm support implemented
  2114. Revision 1.128 2003/10/11 16:06:42 florian
  2115. * fixed some MMX<->SSE
  2116. * started to fix ppc, needs an overhaul
  2117. + stabs info improve for spilling, not sure if it works correctly/completly
  2118. - MMX_SUPPORT removed from Makefile.fpc
  2119. Revision 1.127 2003/10/01 20:34:49 peter
  2120. * procinfo unit contains tprocinfo
  2121. * cginfo renamed to cgbase
  2122. * moved cgmessage to verbose
  2123. * fixed ppc and sparc compiles
  2124. Revision 1.126 2003/09/14 16:37:20 jonas
  2125. * fixed some ppc problems
  2126. Revision 1.125 2003/09/03 21:04:14 peter
  2127. * some fixes for ppc
  2128. Revision 1.124 2003/09/03 19:35:24 peter
  2129. * powerpc compiles again
  2130. Revision 1.123 2003/09/03 15:55:01 peter
  2131. * NEWRA branch merged
  2132. Revision 1.122.2.1 2003/08/31 21:08:16 peter
  2133. * first batch of sparc fixes
  2134. Revision 1.122 2003/08/18 21:27:00 jonas
  2135. * some newra optimizations (eliminate lots of moves between registers)
  2136. Revision 1.121 2003/08/18 11:50:55 olle
  2137. + cleaning up in proc entry and exit, now calc_stack_frame always is used.
  2138. Revision 1.120 2003/08/17 16:59:20 jonas
  2139. * fixed regvars so they work with newra (at least for ppc)
  2140. * fixed some volatile register bugs
  2141. + -dnotranslation option for -dnewra, which causes the registers not to
  2142. be translated from virtual to normal registers. Requires support in
  2143. the assembler writer as well, which is only implemented in aggas/
  2144. agppcgas currently
  2145. Revision 1.119 2003/08/11 21:18:20 peter
  2146. * start of sparc support for newra
  2147. Revision 1.118 2003/08/08 15:50:45 olle
  2148. * merged macos entry/exit code generation into the general one.
  2149. Revision 1.117 2002/10/01 05:24:28 olle
  2150. * made a_load_store more robust and to accept large offsets and cleaned up code
  2151. Revision 1.116 2003/07/23 11:02:23 jonas
  2152. * don't use rg.getregisterint() anymore in g_stackframe_entry_*, because
  2153. the register colouring has already occurred then, use a hard-coded
  2154. register instead
  2155. Revision 1.115 2003/07/20 20:39:20 jonas
  2156. * fixed newra bug due to the fact that we sometimes need a temp reg
  2157. when loading/storing to memory (base+index+offset is not possible)
  2158. and because a reference is often freed before it is last used, this
  2159. temp register was soemtimes the same as one of the reference regs
  2160. Revision 1.114 2003/07/20 16:15:58 jonas
  2161. * fixed bug in g_concatcopy with -dnewra
  2162. Revision 1.113 2003/07/06 20:25:03 jonas
  2163. * fixed ppc compiler
  2164. Revision 1.112 2003/07/05 20:11:42 jonas
  2165. * create_paraloc_info() is now called separately for the caller and
  2166. callee info
  2167. * fixed ppc cycle
  2168. Revision 1.111 2003/07/02 22:18:04 peter
  2169. * paraloc splitted in callerparaloc,calleeparaloc
  2170. * sparc calling convention updates
  2171. Revision 1.110 2003/06/18 10:12:36 olle
  2172. * macos: fixes of loading-code
  2173. Revision 1.109 2003/06/14 22:32:43 jonas
  2174. * ppc compiles with -dnewra, haven't tried to compile anything with it
  2175. yet though
  2176. Revision 1.108 2003/06/13 21:19:31 peter
  2177. * current_procdef removed, use current_procinfo.procdef instead
  2178. Revision 1.107 2003/06/09 14:54:26 jonas
  2179. * (de)allocation of registers for parameters is now performed properly
  2180. (and checked on the ppc)
  2181. - removed obsolete allocation of all parameter registers at the start
  2182. of a procedure (and deallocation at the end)
  2183. Revision 1.106 2003/06/08 18:19:27 jonas
  2184. - removed duplicate identifier
  2185. Revision 1.105 2003/06/07 18:57:04 jonas
  2186. + added freeintparaloc
  2187. * ppc get/freeintparaloc now check whether the parameter regs are
  2188. properly allocated/deallocated (and get an extra list para)
  2189. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  2190. * fixed lot of missing pi_do_call's
  2191. Revision 1.104 2003/06/04 11:58:58 jonas
  2192. * calculate localsize also in g_return_from_proc since it's now called
  2193. before g_stackframe_entry (still have to fix macos)
  2194. * compilation fixes (cycle doesn't work yet though)
  2195. Revision 1.103 2003/06/01 21:38:06 peter
  2196. * getregisterfpu size parameter added
  2197. * op_const_reg size parameter added
  2198. * sparc updates
  2199. Revision 1.102 2003/06/01 13:42:18 jonas
  2200. * fix for bug in fixref that Peter found during the Sparc conversion
  2201. Revision 1.101 2003/05/30 18:52:10 jonas
  2202. * fixed bug with intregvars
  2203. * locapara.loc can also be LOC_CFPUREGISTER -> also fixed
  2204. rcgppc.a_param_ref, which previously got bogus size values
  2205. Revision 1.100 2003/05/29 21:17:27 jonas
  2206. * compile with -dppc603 to not use unaligned float loads in move() and
  2207. g_concatcopy, because the 603 and 604 take an exception for those
  2208. (and netbsd doesn't even handle those in the kernel). There are
  2209. still some of those left that could cause problems though (e.g.
  2210. in the set helpers)
  2211. Revision 1.99 2003/05/29 10:06:09 jonas
  2212. * also free temps in g_concatcopy if delsource is true
  2213. Revision 1.98 2003/05/28 23:58:18 jonas
  2214. * added missing initialization of rg.usedintin,byproc
  2215. * ppc now also saves/restores used fpu registers
  2216. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  2217. i386
  2218. Revision 1.97 2003/05/28 23:18:31 florian
  2219. * started to fix and clean up the sparc port
  2220. Revision 1.96 2003/05/24 11:59:42 jonas
  2221. * fixed integer typeconversion problems
  2222. Revision 1.95 2003/05/23 18:51:26 jonas
  2223. * fixed support for nested procedures and more parameters than those
  2224. which fit in registers (untested/probably not working: calling a
  2225. nested procedure from a deeper nested procedure)
  2226. Revision 1.94 2003/05/20 23:54:00 florian
  2227. + basic darwin support added
  2228. Revision 1.93 2003/05/15 22:14:42 florian
  2229. * fixed last commit, changing lastsaveintreg to r31 caused some strange problems
  2230. Revision 1.92 2003/05/15 21:37:00 florian
  2231. * sysv entry code saves r13 now as well
  2232. Revision 1.91 2003/05/15 19:39:09 florian
  2233. * fixed ppc compiler which was broken by Peter's changes
  2234. Revision 1.90 2003/05/12 18:43:50 jonas
  2235. * fixed g_concatcopy
  2236. Revision 1.89 2003/05/11 20:59:23 jonas
  2237. * fixed bug with large offsets in entrycode
  2238. Revision 1.88 2003/05/11 11:45:08 jonas
  2239. * fixed shifts
  2240. Revision 1.87 2003/05/11 11:07:33 jonas
  2241. * fixed optimizations in a_op_const_reg_reg()
  2242. Revision 1.86 2003/04/27 11:21:36 peter
  2243. * aktprocdef renamed to current_procinfo.procdef
  2244. * procinfo renamed to current_procinfo
  2245. * procinfo will now be stored in current_module so it can be
  2246. cleaned up properly
  2247. * gen_main_procsym changed to create_main_proc and release_main_proc
  2248. to also generate a tprocinfo structure
  2249. * fixed unit implicit initfinal
  2250. Revision 1.85 2003/04/26 22:56:11 jonas
  2251. * fix to a_op64_const_reg_reg
  2252. Revision 1.84 2003/04/26 16:08:41 jonas
  2253. * fixed g_flags2reg
  2254. Revision 1.83 2003/04/26 15:25:29 florian
  2255. * fixed cmp_reg_reg_reg, cmp operands were emitted in the wrong order
  2256. Revision 1.82 2003/04/25 20:55:34 florian
  2257. * stack frame calculations are now completly done using the code generator
  2258. routines instead of generating directly assembler so also large stack frames
  2259. are handle properly
  2260. Revision 1.81 2003/04/24 11:24:00 florian
  2261. * fixed several issues with nested procedures
  2262. Revision 1.80 2003/04/23 22:18:01 peter
  2263. * fixes to get rtl compiled
  2264. Revision 1.79 2003/04/23 12:35:35 florian
  2265. * fixed several issues with powerpc
  2266. + applied a patch from Jonas for nested function calls (PowerPC only)
  2267. * ...
  2268. Revision 1.78 2003/04/16 09:26:55 jonas
  2269. * assembler procedures now again get a stackframe if they have local
  2270. variables. No space is reserved for a function result however.
  2271. Also, the register parameters aren't automatically saved on the stack
  2272. anymore in assembler procedures.
  2273. Revision 1.77 2003/04/06 16:39:11 jonas
  2274. * don't generate entry/exit code for assembler procedures
  2275. Revision 1.76 2003/03/22 18:01:13 jonas
  2276. * fixed linux entry/exit code generation
  2277. Revision 1.75 2003/03/19 14:26:26 jonas
  2278. * fixed R_TOC bugs introduced by new register allocator conversion
  2279. Revision 1.74 2003/03/13 22:57:45 olle
  2280. * change in a_loadaddr_ref_reg
  2281. Revision 1.73 2003/03/12 22:43:38 jonas
  2282. * more powerpc and generic fixes related to the new register allocator
  2283. Revision 1.72 2003/03/11 21:46:24 jonas
  2284. * lots of new regallocator fixes, both in generic and ppc-specific code
  2285. (ppc compiler still can't compile the linux system unit though)
  2286. Revision 1.71 2003/02/19 22:00:16 daniel
  2287. * Code generator converted to new register notation
  2288. - Horribily outdated todo.txt removed
  2289. Revision 1.70 2003/01/13 17:17:50 olle
  2290. * changed global var access, TOC now contain pointers to globals
  2291. * fixed handling of function pointers
  2292. Revision 1.69 2003/01/09 22:00:53 florian
  2293. * fixed some PowerPC issues
  2294. Revision 1.68 2003/01/08 18:43:58 daniel
  2295. * Tregister changed into a record
  2296. Revision 1.67 2002/12/15 19:22:01 florian
  2297. * fixed some crashes and a rte 201
  2298. Revision 1.66 2002/11/28 10:55:16 olle
  2299. * macos: changing code gen for references to globals
  2300. Revision 1.65 2002/11/07 15:50:23 jonas
  2301. * fixed bctr(l) problems
  2302. Revision 1.64 2002/11/04 18:24:19 olle
  2303. * macos: globals are located in TOC and relative r2, instead of absolute
  2304. Revision 1.63 2002/10/28 22:24:28 olle
  2305. * macos entry/exit: only used registers are saved
  2306. - macos entry/exit: stackptr not saved in r31 anymore
  2307. * macos entry/exit: misc fixes
  2308. Revision 1.62 2002/10/19 23:51:48 olle
  2309. * macos stack frame size computing updated
  2310. + macos epilogue: control register now restored
  2311. * macos prologue and epilogue: fp reg now saved and restored
  2312. Revision 1.61 2002/10/19 12:50:36 olle
  2313. * reorganized prologue and epilogue routines
  2314. Revision 1.60 2002/10/02 21:49:51 florian
  2315. * all A_BL instructions replaced by calls to a_call_name
  2316. Revision 1.59 2002/10/02 13:24:58 jonas
  2317. * changed a_call_* so that no superfluous code is generated anymore
  2318. Revision 1.58 2002/09/17 18:54:06 jonas
  2319. * a_load_reg_reg() now has two size parameters: source and dest. This
  2320. allows some optimizations on architectures that don't encode the
  2321. register size in the register name.
  2322. Revision 1.57 2002/09/10 21:22:25 jonas
  2323. + added some internal errors
  2324. * fixed bug in sysv exit code
  2325. Revision 1.56 2002/09/08 20:11:56 jonas
  2326. * fixed TOpCmp2AsmCond array (some unsigned equivalents were wrong)
  2327. Revision 1.55 2002/09/08 13:03:26 jonas
  2328. * several large offset-related fixes
  2329. Revision 1.54 2002/09/07 17:54:58 florian
  2330. * first part of PowerPC fixes
  2331. Revision 1.53 2002/09/07 15:25:14 peter
  2332. * old logs removed and tabs fixed
  2333. Revision 1.52 2002/09/02 10:14:51 jonas
  2334. + a_call_reg()
  2335. * small fix in a_call_ref()
  2336. Revision 1.51 2002/09/02 06:09:02 jonas
  2337. * fixed range error
  2338. Revision 1.50 2002/09/01 21:04:49 florian
  2339. * several powerpc related stuff fixed
  2340. Revision 1.49 2002/09/01 12:09:27 peter
  2341. + a_call_reg, a_call_loc added
  2342. * removed exprasmlist references
  2343. Revision 1.48 2002/08/31 21:38:02 jonas
  2344. * fixed a_call_ref (it should load ctr, not lr)
  2345. Revision 1.47 2002/08/31 21:30:45 florian
  2346. * fixed several problems caused by Jonas' commit :)
  2347. Revision 1.46 2002/08/31 19:25:50 jonas
  2348. + implemented a_call_ref()
  2349. Revision 1.45 2002/08/18 22:16:14 florian
  2350. + the ppc gas assembler writer adds now registers aliases
  2351. to the assembler file
  2352. Revision 1.44 2002/08/17 18:23:53 florian
  2353. * some assembler writer bugs fixed
  2354. Revision 1.43 2002/08/17 09:23:49 florian
  2355. * first part of procinfo rewrite
  2356. Revision 1.42 2002/08/16 14:24:59 carl
  2357. * issameref() to test if two references are the same (then emit no opcodes)
  2358. + ret_in_reg to replace ret_in_acc
  2359. (fix some register allocation bugs at the same time)
  2360. + save_std_register now has an extra parameter which is the
  2361. usedinproc registers
  2362. Revision 1.41 2002/08/15 08:13:54 carl
  2363. - a_load_sym_ofs_reg removed
  2364. * loadvmt now calls loadaddr_ref_reg instead
  2365. Revision 1.40 2002/08/11 14:32:32 peter
  2366. * renamed current_library to objectlibrary
  2367. Revision 1.39 2002/08/11 13:24:18 peter
  2368. * saving of asmsymbols in ppu supported
  2369. * asmsymbollist global is removed and moved into a new class
  2370. tasmlibrarydata that will hold the info of a .a file which
  2371. corresponds with a single module. Added librarydata to tmodule
  2372. to keep the library info stored for the module. In the future the
  2373. objectfiles will also be stored to the tasmlibrarydata class
  2374. * all getlabel/newasmsymbol and friends are moved to the new class
  2375. Revision 1.38 2002/08/11 11:39:31 jonas
  2376. + powerpc-specific genlinearlist
  2377. Revision 1.37 2002/08/10 17:15:31 jonas
  2378. * various fixes and optimizations
  2379. Revision 1.36 2002/08/06 20:55:23 florian
  2380. * first part of ppc calling conventions fix
  2381. Revision 1.35 2002/08/06 07:12:05 jonas
  2382. * fixed bug in g_flags2reg()
  2383. * and yet more constant operation fixes :)
  2384. Revision 1.34 2002/08/05 08:58:53 jonas
  2385. * fixed compilation problems
  2386. Revision 1.33 2002/08/04 12:57:55 jonas
  2387. * more misc. fixes, mostly constant-related
  2388. }