cgcpu.pas 103 KB

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