cgcpu.pas 101 KB

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