cgcpu.pas 101 KB

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