cgcpu.pas 102 KB

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