cgcpu.pas 101 KB

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