2
0

cgcpu.pas 103 KB

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