cgcpu.pas 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the code generator for the PowerPC
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit cgcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,symtype,symdef,
  22. cgbase,cgobj,cgppc,
  23. aasmbase,aasmcpu,aasmtai,aasmdata,
  24. cpubase,cpuinfo,cgutils,cg64f32,rgcpu,
  25. parabase;
  26. type
  27. tcgppc = class(tcgppcgen)
  28. procedure init_register_allocators;override;
  29. procedure done_register_allocators;override;
  30. { passing parameters, per default the parameter is pushed }
  31. { nr gives the number of the parameter (enumerated from }
  32. { left to right), this allows to move the parameter to }
  33. { register, if the cpu supports register calling }
  34. { conventions }
  35. procedure a_param_ref(list : TAsmList;size : tcgsize;const r : treference;const paraloc : tcgpara);override;
  36. procedure a_call_name(list : TAsmList;const s : string);override;
  37. procedure a_call_reg(list : TAsmList;reg: tregister); override;
  38. procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister); override;
  39. procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  40. procedure a_op_const_reg_reg(list: TAsmList; op: TOpCg;
  41. size: tcgsize; a: aint; src, dst: tregister); override;
  42. procedure a_op_reg_reg_reg(list: TAsmList; op: TOpCg;
  43. size: tcgsize; src1, src2, dst: tregister); override;
  44. { move instructions }
  45. procedure a_load_const_reg(list : TAsmList; size: tcgsize; a : aint;reg : tregister);override;
  46. procedure a_load_ref_reg(list : TAsmList; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister);override;
  47. procedure a_load_reg_reg(list : TAsmList; fromsize, tosize : tcgsize;reg1,reg2 : tregister);override;
  48. procedure a_load_subsetreg_reg(list : TAsmList; subsetsize: tcgsize;
  49. tosize: tcgsize; const sreg: tsubsetregister; destreg: tregister); override;
  50. procedure a_load_subsetreg_subsetreg(list: TAsmlist; fromsubsetsize, tosubsetsize: tcgsize; const fromsreg, tosreg: tsubsetregister); override;
  51. { comparison operations }
  52. procedure a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  53. l : tasmlabel);override;
  54. procedure a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  55. procedure a_jmp_name(list : TAsmList;const s : string); override;
  56. procedure a_jmp_always(list : TAsmList;l: tasmlabel); override;
  57. procedure a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel); override;
  58. procedure g_flags2reg(list: TAsmList; size: TCgSize; const f: TResFlags; reg: TRegister); override;
  59. procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);override;
  60. procedure g_proc_exit(list : TAsmList;parasize : longint;nostackframe:boolean); override;
  61. procedure g_save_standard_registers(list:TAsmList); override;
  62. procedure g_restore_standard_registers(list:TAsmList); override;
  63. procedure a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);override;
  64. procedure g_concatcopy(list : TAsmList;const source,dest : treference;len : aint);override;
  65. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  66. { that's the case, we can use rlwinm to do an AND operation }
  67. function get_rlwi_const(a: aint; var l1, l2: longint): boolean;
  68. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  69. protected
  70. procedure a_load_regconst_subsetreg_intern(list : TAsmList; fromsize, subsetsize: tcgsize; fromreg: tregister; const sreg: tsubsetregister; slopt: tsubsetloadopt); override;
  71. private
  72. (* NOT IN USE: *)
  73. procedure g_stackframe_entry_mac(list : TAsmList;localsize : longint);
  74. (* NOT IN USE: *)
  75. procedure g_return_from_proc_mac(list : TAsmList;parasize : aint);
  76. { clear out potential overflow bits from 8 or 16 bit operations }
  77. { the upper 24/16 bits of a register after an operation }
  78. procedure maybeadjustresult(list: TAsmList; op: TOpCg; size: tcgsize; dst: tregister);
  79. { Make sure ref is a valid reference for the PowerPC and sets the }
  80. { base to the value of the index if (base = R_NO). }
  81. { Returns true if the reference contained a base, index and an }
  82. { offset or symbol, in which case the base will have been changed }
  83. { to a tempreg (which has to be freed by the caller) containing }
  84. { the sum of part of the original reference }
  85. function fixref(list: TAsmList; var ref: treference): boolean; override;
  86. { returns whether a reference can be used immediately in a powerpc }
  87. { instruction }
  88. function issimpleref(const ref: treference): boolean;
  89. { contains the common code of a_load_reg_ref and a_load_ref_reg }
  90. procedure a_load_store(list:TAsmList;op: tasmop;reg:tregister;
  91. ref: treference); override;
  92. function save_regs(list : TAsmList):longint;
  93. procedure restore_regs(list : TAsmList);
  94. end;
  95. tcg64fppc = class(tcg64f32)
  96. procedure a_op64_reg_reg(list : TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);override;
  97. procedure a_op64_const_reg(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;reg : tregister64);override;
  98. procedure a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);override;
  99. procedure a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);override;
  100. end;
  101. const
  102. TOpCG2AsmOpConstLo: Array[topcg] of TAsmOp = (A_NONE,A_MR,A_ADDI,A_ANDI_,A_DIVWU,
  103. A_DIVW,A_MULLW, A_MULLW, A_NONE,A_NONE,A_ORI,
  104. A_SRAWI,A_SLWI,A_SRWI,A_SUBI,A_XORI);
  105. TOpCG2AsmOpConstHi: Array[topcg] of TAsmOp = (A_NONE,A_MR,A_ADDIS,A_ANDIS_,
  106. A_DIVWU,A_DIVW, A_MULLW,A_MULLW,A_NONE,A_NONE,
  107. A_ORIS,A_NONE, A_NONE,A_NONE,A_SUBIS,A_XORIS);
  108. implementation
  109. uses
  110. globals,verbose,systems,cutils,
  111. symconst,symsym,fmodule,
  112. rgobj,tgobj,cpupi,procinfo,paramgr;
  113. procedure tcgppc.init_register_allocators;
  114. begin
  115. inherited init_register_allocators;
  116. if target_info.system=system_powerpc_darwin then
  117. begin
  118. {
  119. if pi_needs_got in current_procinfo.flags then
  120. begin
  121. current_procinfo.got:=NR_R31;
  122. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  123. [RS_R2,RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
  124. RS_R9,RS_R10,RS_R11,RS_R12,RS_R30,RS_R29,
  125. RS_R28,RS_R27,RS_R26,RS_R25,RS_R24,RS_R23,RS_R22,
  126. RS_R21,RS_R20,RS_R19,RS_R18,RS_R17,RS_R16,RS_R15,
  127. RS_R14,RS_R13],first_int_imreg,[]);
  128. end
  129. else}
  130. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  131. [RS_R2,RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
  132. RS_R9,RS_R10,RS_R11,RS_R12,RS_R31,RS_R30,RS_R29,
  133. RS_R28,RS_R27,RS_R26,RS_R25,RS_R24,RS_R23,RS_R22,
  134. RS_R21,RS_R20,RS_R19,RS_R18,RS_R17,RS_R16,RS_R15,
  135. RS_R14,RS_R13],first_int_imreg,[]);
  136. end
  137. else
  138. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  139. [RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
  140. RS_R9,RS_R10,RS_R11,RS_R12,RS_R31,RS_R30,RS_R29,
  141. RS_R28,RS_R27,RS_R26,RS_R25,RS_R24,RS_R23,RS_R22,
  142. RS_R21,RS_R20,RS_R19,RS_R18,RS_R17,RS_R16,RS_R15,
  143. RS_R14,RS_R13],first_int_imreg,[]);
  144. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,
  145. [RS_F0,RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7,RS_F8,RS_F9,
  146. RS_F10,RS_F11,RS_F12,RS_F13,RS_F31,RS_F30,RS_F29,RS_F28,RS_F27,
  147. RS_F26,RS_F25,RS_F24,RS_F23,RS_F22,RS_F21,RS_F20,RS_F19,RS_F18,
  148. RS_F17,RS_F16,RS_F15,RS_F14],first_fpu_imreg,[]);
  149. {$warning FIX ME}
  150. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,
  151. [RS_M0,RS_M1,RS_M2],first_mm_imreg,[]);
  152. end;
  153. procedure tcgppc.done_register_allocators;
  154. begin
  155. rg[R_INTREGISTER].free;
  156. rg[R_FPUREGISTER].free;
  157. rg[R_MMREGISTER].free;
  158. inherited done_register_allocators;
  159. end;
  160. procedure tcgppc.a_param_ref(list : TAsmList;size : tcgsize;const r : treference;const paraloc : tcgpara);
  161. var
  162. tmpref, ref: treference;
  163. location: pcgparalocation;
  164. sizeleft: aint;
  165. begin
  166. location := paraloc.location;
  167. tmpref := r;
  168. sizeleft := paraloc.intsize;
  169. while assigned(location) do
  170. begin
  171. case location^.loc of
  172. LOC_REGISTER,LOC_CREGISTER:
  173. begin
  174. {$ifndef cpu64bit}
  175. if (sizeleft <> 3) then
  176. begin
  177. a_load_ref_reg(list,location^.size,location^.size,tmpref,location^.register);
  178. end
  179. else
  180. begin
  181. a_load_ref_reg(list,OS_16,OS_16,tmpref,location^.register);
  182. a_reg_alloc(list,NR_R0);
  183. inc(tmpref.offset,2);
  184. a_load_ref_reg(list,OS_8,OS_8,tmpref,newreg(R_INTREGISTER,RS_R0,R_SUBNONE));
  185. a_op_const_reg(list,OP_SHL,OS_INT,16,location^.register);
  186. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,location^.register,newreg(R_INTREGISTER,RS_R0,R_SUBNONE),8,16,31-8));
  187. a_reg_dealloc(list,NR_R0);
  188. dec(tmpref.offset,2);
  189. end;
  190. {$else not cpu64bit}
  191. {$error add 64 bit support for non power of 2 loads in a_param_ref}
  192. {$endif not cpu64bit}
  193. end;
  194. LOC_REFERENCE:
  195. begin
  196. reference_reset_base(ref,location^.reference.index,location^.reference.offset);
  197. g_concatcopy(list,tmpref,ref,sizeleft);
  198. if assigned(location^.next) then
  199. internalerror(2005010710);
  200. end;
  201. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  202. case location^.size of
  203. OS_F32, OS_F64:
  204. a_loadfpu_ref_reg(list,location^.size,location^.size,tmpref,location^.register);
  205. else
  206. internalerror(2002072801);
  207. end;
  208. LOC_VOID:
  209. begin
  210. // nothing to do
  211. end;
  212. else
  213. internalerror(2002081103);
  214. end;
  215. inc(tmpref.offset,tcgsize2size[location^.size]);
  216. dec(sizeleft,tcgsize2size[location^.size]);
  217. location := location^.next;
  218. end;
  219. end;
  220. { calling a procedure by name }
  221. procedure tcgppc.a_call_name(list : TAsmList;const s : string);
  222. begin
  223. { MacOS: The linker on MacOS (PPCLink) inserts a call to glue code,
  224. if it is a cross-TOC call. If so, it also replaces the NOP
  225. with some restore code.}
  226. if (target_info.system <> system_powerpc_darwin) then
  227. begin
  228. list.concat(taicpu.op_sym(A_BL,current_asmdata.RefAsmSymbol(s)));
  229. if target_info.system=system_powerpc_macos then
  230. list.concat(taicpu.op_none(A_NOP));
  231. end
  232. else
  233. list.concat(taicpu.op_sym(A_BL,get_darwin_call_stub(s)));
  234. {
  235. the compiler does not properly set this flag anymore in pass 1, and
  236. for now we only need it after pass 2 (I hope) (JM)
  237. if not(pi_do_call in current_procinfo.flags) then
  238. internalerror(2003060703);
  239. }
  240. include(current_procinfo.flags,pi_do_call);
  241. end;
  242. { calling a procedure by address }
  243. procedure tcgppc.a_call_reg(list : TAsmList;reg: tregister);
  244. var
  245. tmpreg : tregister;
  246. tmpref : treference;
  247. begin
  248. if target_info.system=system_powerpc_macos then
  249. begin
  250. {Generate instruction to load the procedure address from
  251. the transition vector.}
  252. //TODO: Support cross-TOC calls.
  253. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  254. reference_reset(tmpref);
  255. tmpref.offset := 0;
  256. //tmpref.symaddr := refs_full;
  257. tmpref.base:= reg;
  258. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  259. end
  260. else
  261. tmpreg:=reg;
  262. inherited a_call_reg(list,tmpreg);
  263. end;
  264. {********************** load instructions ********************}
  265. procedure tcgppc.a_load_const_reg(list : TAsmList; size: TCGSize; a : aint; reg : TRegister);
  266. begin
  267. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  268. internalerror(2002090902);
  269. if (a >= low(smallint)) and
  270. (a <= high(smallint)) then
  271. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a)))
  272. else if ((a and $ffff) <> 0) then
  273. begin
  274. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a and $ffff)));
  275. if ((a shr 16) <> 0) or
  276. (smallint(a and $ffff) < 0) then
  277. list.concat(taicpu.op_reg_reg_const(A_ADDIS,reg,reg,
  278. smallint((a shr 16)+ord(smallint(a and $ffff) < 0))))
  279. end
  280. else
  281. list.concat(taicpu.op_reg_const(A_LIS,reg,smallint(a shr 16)));
  282. end;
  283. procedure tcgppc.a_load_ref_reg(list : TAsmList; fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  284. const
  285. LoadInstr: Array[OS_8..OS_S32,boolean, boolean] of TAsmOp =
  286. { indexed? updating?}
  287. (((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  288. ((A_LHZ,A_LHZU),(A_LHZX,A_LHZUX)),
  289. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)),
  290. { 64bit stuff should be handled separately }
  291. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  292. { 128bit stuff too }
  293. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  294. { there's no load-byte-with-sign-extend :( }
  295. ((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  296. ((A_LHA,A_LHAU),(A_LHAX,A_LHAUX)),
  297. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)));
  298. var
  299. op: tasmop;
  300. ref2: treference;
  301. begin
  302. { TODO: optimize/take into consideration fromsize/tosize. Will }
  303. { probably only matter for OS_S8 loads though }
  304. if not(fromsize in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  305. internalerror(2002090902);
  306. ref2 := ref;
  307. fixref(list,ref2);
  308. { the caller is expected to have adjusted the reference already }
  309. { in this case }
  310. if (TCGSize2Size[fromsize] >= TCGSize2Size[tosize]) then
  311. fromsize := tosize;
  312. op := loadinstr[fromsize,ref2.index<>NR_NO,false];
  313. a_load_store(list,op,reg,ref2);
  314. { sign extend shortint if necessary, since there is no }
  315. { load instruction that does that automatically (JM) }
  316. if fromsize = OS_S8 then
  317. list.concat(taicpu.op_reg_reg(A_EXTSB,reg,reg));
  318. end;
  319. procedure tcgppc.a_load_reg_reg(list : TAsmList;fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  320. var
  321. instr: taicpu;
  322. begin
  323. if (tcgsize2size[fromsize] > tcgsize2size[tosize]) or
  324. ((tcgsize2size[fromsize] = tcgsize2size[tosize]) and
  325. (fromsize <> tosize)) or
  326. { needs to mask out the sign in the top 16 bits }
  327. ((fromsize = OS_S8) and
  328. (tosize = OS_16)) then
  329. case tosize of
  330. OS_8:
  331. instr := taicpu.op_reg_reg_const_const_const(A_RLWINM,
  332. reg2,reg1,0,31-8+1,31);
  333. OS_S8:
  334. instr := taicpu.op_reg_reg(A_EXTSB,reg2,reg1);
  335. OS_16:
  336. instr := taicpu.op_reg_reg_const_const_const(A_RLWINM,
  337. reg2,reg1,0,31-16+1,31);
  338. OS_S16:
  339. instr := taicpu.op_reg_reg(A_EXTSH,reg2,reg1);
  340. OS_32,OS_S32:
  341. instr := taicpu.op_reg_reg(A_MR,reg2,reg1);
  342. else internalerror(2002090901);
  343. end
  344. else
  345. instr := taicpu.op_reg_reg(A_MR,reg2,reg1);
  346. list.concat(instr);
  347. rg[R_INTREGISTER].add_move_instruction(instr);
  348. end;
  349. procedure tcgppc.a_load_subsetreg_reg(list : TAsmList; subsetsize, tosize: tcgsize; const sreg: tsubsetregister; destreg: tregister);
  350. begin
  351. if (sreg.bitlen <> sizeof(aint)*8) then
  352. begin
  353. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,destreg,
  354. sreg.subsetreg,(32-sreg.startbit) and 31,32-sreg.bitlen,31));
  355. { types with a negative lower bound are always a base type (8, 16, 32 bits) }
  356. if (subsetsize in [OS_S8..OS_S128]) then
  357. if ((sreg.bitlen mod 8) = 0) then
  358. begin
  359. a_load_reg_reg(list,tcgsize2unsigned[subsetsize],subsetsize,destreg,destreg);
  360. a_load_reg_reg(list,subsetsize,tosize,destreg,destreg);
  361. end
  362. else
  363. begin
  364. a_op_const_reg(list,OP_SHL,OS_INT,32-sreg.bitlen,destreg);
  365. a_op_const_reg(list,OP_SAR,OS_INT,32-sreg.bitlen,destreg);
  366. end;
  367. end
  368. else
  369. a_load_reg_reg(list,subsetsize,tosize,sreg.subsetreg,destreg);
  370. end;
  371. procedure tcgppc.a_load_regconst_subsetreg_intern(list : TAsmList; fromsize, subsetsize: tcgsize; fromreg: tregister; const sreg: tsubsetregister; slopt: tsubsetloadopt);
  372. begin
  373. if (slopt in [SL_SETZERO,SL_SETMAX]) then
  374. inherited a_load_regconst_subsetreg_intern(list,fromsize,subsetsize,fromreg,sreg,slopt)
  375. else if (sreg.bitlen <> sizeof(aint) * 8) then
  376. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,sreg.subsetreg,fromreg,
  377. sreg.startbit,32-sreg.startbit-sreg.bitlen,31-sreg.startbit))
  378. else
  379. a_load_reg_reg(list,fromsize,subsetsize,fromreg,sreg.subsetreg);
  380. end;
  381. procedure tcgppc.a_load_subsetreg_subsetreg(list: TAsmlist; fromsubsetsize, tosubsetsize: tcgsize; const fromsreg, tosreg: tsubsetregister);
  382. begin
  383. if (fromsreg.bitlen >= tosreg.bitlen) then
  384. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,tosreg.subsetreg, fromsreg.subsetreg,
  385. (tosreg.startbit-fromsreg.startbit) and 31,
  386. 32-tosreg.startbit-tosreg.bitlen,31-tosreg.startbit))
  387. else
  388. inherited a_load_subsetreg_subsetreg(list,fromsubsetsize,tosubsetsize,fromsreg,tosreg);
  389. end;
  390. procedure tcgppc.a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister);
  391. begin
  392. a_op_const_reg_reg(list,op,size,a,reg,reg);
  393. end;
  394. procedure tcgppc.a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  395. begin
  396. a_op_reg_reg_reg(list,op,size,src,dst,dst);
  397. end;
  398. procedure tcgppc.maybeadjustresult(list: TAsmList; op: TOpCg; size: tcgsize; dst: tregister);
  399. const
  400. overflowops = [OP_MUL,OP_SHL,OP_ADD,OP_SUB,OP_NOT,OP_NEG];
  401. begin
  402. if (op in overflowops) and
  403. (size in [OS_8,OS_S8,OS_16,OS_S16]) then
  404. a_load_reg_reg(list,OS_32,size,dst,dst);
  405. end;
  406. procedure tcgppc.a_op_const_reg_reg(list: TAsmList; op: TOpCg;
  407. size: tcgsize; a: aint; src, dst: tregister);
  408. var
  409. l1,l2: longint;
  410. oplo, ophi: tasmop;
  411. scratchreg: tregister;
  412. useReg, gotrlwi: boolean;
  413. procedure do_lo_hi;
  414. begin
  415. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  416. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  417. end;
  418. begin
  419. if (op = OP_MOVE) then
  420. internalerror(2006031401);
  421. if op = OP_SUB then
  422. begin
  423. a_op_const_reg_reg(list,OP_ADD,size,-a,src,dst);
  424. exit;
  425. end;
  426. ophi := TOpCG2AsmOpConstHi[op];
  427. oplo := TOpCG2AsmOpConstLo[op];
  428. gotrlwi := get_rlwi_const(a,l1,l2);
  429. if (op in [OP_AND,OP_OR,OP_XOR]) then
  430. begin
  431. if (a = 0) then
  432. begin
  433. if op = OP_AND then
  434. list.concat(taicpu.op_reg_const(A_LI,dst,0))
  435. else
  436. a_load_reg_reg(list,size,size,src,dst);
  437. exit;
  438. end
  439. else if (a = -1) then
  440. begin
  441. case op of
  442. OP_OR:
  443. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  444. OP_XOR:
  445. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  446. OP_AND:
  447. a_load_reg_reg(list,size,size,src,dst);
  448. end;
  449. exit;
  450. end
  451. else if (aword(a) <= high(word)) and
  452. ((op <> OP_AND) or
  453. not gotrlwi) then
  454. begin
  455. if ((size = OS_8) and
  456. (byte(a) <> a)) or
  457. ((size = OS_S8) and
  458. (shortint(a) <> a)) then
  459. internalerror(200604142);
  460. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  461. { and/or/xor -> cannot overflow in high 16 bits }
  462. exit;
  463. end;
  464. { all basic constant instructions also have a shifted form that }
  465. { works only on the highest 16bits, so if lo(a) is 0, we can }
  466. { use that one }
  467. if (word(a) = 0) and
  468. (not(op = OP_AND) or
  469. not gotrlwi) then
  470. begin
  471. if (size in [OS_8,OS_S8,OS_16,OS_S16]) then
  472. internalerror(200604141);
  473. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  474. exit;
  475. end;
  476. end
  477. else if (op = OP_ADD) then
  478. if a = 0 then
  479. begin
  480. a_load_reg_reg(list,size,size,src,dst);
  481. exit
  482. end
  483. else if (a >= low(smallint)) and
  484. (a <= high(smallint)) then
  485. begin
  486. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  487. maybeadjustresult(list,op,size,dst);
  488. exit;
  489. end;
  490. { otherwise, the instructions we can generate depend on the }
  491. { operation }
  492. useReg := false;
  493. case op of
  494. OP_DIV,OP_IDIV:
  495. if (a = 0) then
  496. internalerror(200208103)
  497. else if (a = 1) then
  498. begin
  499. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  500. exit
  501. end
  502. else if ispowerof2(a,l1) then
  503. begin
  504. case op of
  505. OP_DIV:
  506. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  507. OP_IDIV:
  508. begin
  509. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  510. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  511. end;
  512. end;
  513. exit;
  514. end
  515. else
  516. usereg := true;
  517. OP_IMUL, OP_MUL:
  518. if (a = 0) then
  519. begin
  520. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  521. exit
  522. end
  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. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  530. else if (longint(a) >= low(smallint)) and
  531. (longint(a) <= high(smallint)) then
  532. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  533. else
  534. usereg := true;
  535. OP_ADD:
  536. begin
  537. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  538. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  539. smallint((a shr 16) + ord(smallint(a) < 0))));
  540. end;
  541. OP_OR:
  542. { try to use rlwimi }
  543. if gotrlwi and
  544. (src = dst) then
  545. begin
  546. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  547. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  548. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  549. scratchreg,0,l1,l2));
  550. end
  551. else
  552. do_lo_hi;
  553. OP_AND:
  554. { try to use rlwinm }
  555. if gotrlwi then
  556. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  557. src,0,l1,l2))
  558. else
  559. useReg := true;
  560. OP_XOR:
  561. do_lo_hi;
  562. OP_SHL,OP_SHR,OP_SAR:
  563. begin
  564. if (a and 31) <> 0 Then
  565. list.concat(taicpu.op_reg_reg_const(
  566. TOpCG2AsmOpConstLo[Op],dst,src,a and 31))
  567. else
  568. a_load_reg_reg(list,size,size,src,dst);
  569. if (a shr 5) <> 0 then
  570. internalError(68991);
  571. end
  572. else
  573. internalerror(200109091);
  574. end;
  575. { if all else failed, load the constant in a register and then }
  576. { perform the operation }
  577. if useReg then
  578. begin
  579. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  580. a_load_const_reg(list,OS_32,a,scratchreg);
  581. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  582. end;
  583. maybeadjustresult(list,op,size,dst);
  584. end;
  585. procedure tcgppc.a_op_reg_reg_reg(list: TAsmList; op: TOpCg;
  586. size: tcgsize; src1, src2, dst: tregister);
  587. const
  588. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  589. (A_NONE,A_MR,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  590. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  591. begin
  592. if (op = OP_MOVE) then
  593. internalerror(2006031402);
  594. case op of
  595. OP_NEG,OP_NOT:
  596. begin
  597. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,src1));
  598. if (op = OP_NOT) and
  599. not(size in [OS_32,OS_S32]) then
  600. { zero/sign extend result again }
  601. a_load_reg_reg(list,OS_32,size,dst,dst);
  602. end;
  603. else
  604. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  605. end;
  606. maybeadjustresult(list,op,size,dst);
  607. end;
  608. {*************** compare instructructions ****************}
  609. procedure tcgppc.a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  610. l : tasmlabel);
  611. var
  612. scratch_register: TRegister;
  613. signed: boolean;
  614. begin
  615. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE,OC_EQ,OC_NE];
  616. { in the following case, we generate more efficient code when }
  617. { signed is false }
  618. if (cmp_op in [OC_EQ,OC_NE]) and
  619. (aword(a) >= $8000) and
  620. (aword(a) <= $ffff) then
  621. signed := false;
  622. if signed then
  623. if (a >= low(smallint)) and (a <= high(smallint)) Then
  624. list.concat(taicpu.op_reg_reg_const(A_CMPWI,NR_CR0,reg,a))
  625. else
  626. begin
  627. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  628. a_load_const_reg(list,OS_32,a,scratch_register);
  629. list.concat(taicpu.op_reg_reg_reg(A_CMPW,NR_CR0,reg,scratch_register));
  630. end
  631. else
  632. if (aword(a) <= $ffff) then
  633. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,NR_CR0,reg,aword(a)))
  634. else
  635. begin
  636. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  637. a_load_const_reg(list,OS_32,a,scratch_register);
  638. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,NR_CR0,reg,scratch_register));
  639. end;
  640. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  641. end;
  642. procedure tcgppc.a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;
  643. reg1,reg2 : tregister;l : tasmlabel);
  644. var
  645. op: tasmop;
  646. begin
  647. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  648. op := A_CMPW
  649. else
  650. op := A_CMPLW;
  651. list.concat(taicpu.op_reg_reg_reg(op,NR_CR0,reg2,reg1));
  652. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  653. end;
  654. procedure tcgppc.a_jmp_name(list : TAsmList;const s : string);
  655. var
  656. p : taicpu;
  657. begin
  658. if (target_info.system = system_powerpc_darwin) then
  659. p := taicpu.op_sym(A_B,get_darwin_call_stub(s))
  660. else
  661. p := taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(s));
  662. p.is_jmp := true;
  663. list.concat(p)
  664. end;
  665. procedure tcgppc.a_jmp_always(list : TAsmList;l: tasmlabel);
  666. begin
  667. a_jmp(list,A_B,C_None,0,l);
  668. end;
  669. procedure tcgppc.a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel);
  670. var
  671. c: tasmcond;
  672. begin
  673. c := flags_to_cond(f);
  674. a_jmp(list,A_BC,c.cond,c.cr-RS_CR0,l);
  675. end;
  676. procedure tcgppc.g_flags2reg(list: TAsmList; size: TCgSize; const f: TResFlags; reg: TRegister);
  677. var
  678. testbit: byte;
  679. bitvalue: boolean;
  680. begin
  681. { get the bit to extract from the conditional register + its }
  682. { requested value (0 or 1) }
  683. testbit := ((f.cr-RS_CR0) * 4);
  684. case f.flag of
  685. F_EQ,F_NE:
  686. begin
  687. inc(testbit,2);
  688. bitvalue := f.flag = F_EQ;
  689. end;
  690. F_LT,F_GE:
  691. begin
  692. bitvalue := f.flag = F_LT;
  693. end;
  694. F_GT,F_LE:
  695. begin
  696. inc(testbit);
  697. bitvalue := f.flag = F_GT;
  698. end;
  699. else
  700. internalerror(200112261);
  701. end;
  702. { load the conditional register in the destination reg }
  703. list.concat(taicpu.op_reg(A_MFCR,reg));
  704. { we will move the bit that has to be tested to bit 0 by rotating }
  705. { left }
  706. testbit := (testbit + 1) and 31;
  707. { extract bit }
  708. list.concat(taicpu.op_reg_reg_const_const_const(
  709. A_RLWINM,reg,reg,testbit,31,31));
  710. { if we need the inverse, xor with 1 }
  711. if not bitvalue then
  712. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  713. end;
  714. (*
  715. procedure tcgppc.g_cond2reg(list: TAsmList; const f: TAsmCond; reg: TRegister);
  716. var
  717. testbit: byte;
  718. bitvalue: boolean;
  719. begin
  720. { get the bit to extract from the conditional register + its }
  721. { requested value (0 or 1) }
  722. case f.simple of
  723. false:
  724. begin
  725. { we don't generate this in the compiler }
  726. internalerror(200109062);
  727. end;
  728. true:
  729. case f.cond of
  730. C_None:
  731. internalerror(200109063);
  732. C_LT..C_NU:
  733. begin
  734. testbit := (ord(f.cr) - ord(R_CR0))*4;
  735. inc(testbit,AsmCondFlag2BI[f.cond]);
  736. bitvalue := AsmCondFlagTF[f.cond];
  737. end;
  738. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  739. begin
  740. testbit := f.crbit
  741. bitvalue := AsmCondFlagTF[f.cond];
  742. end;
  743. else
  744. internalerror(200109064);
  745. end;
  746. end;
  747. { load the conditional register in the destination reg }
  748. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  749. { we will move the bit that has to be tested to bit 31 -> rotate }
  750. { left by bitpos+1 (remember, this is big-endian!) }
  751. if bitpos <> 31 then
  752. inc(bitpos)
  753. else
  754. bitpos := 0;
  755. { extract bit }
  756. list.concat(taicpu.op_reg_reg_const_const_const(
  757. A_RLWINM,reg,reg,bitpos,31,31));
  758. { if we need the inverse, xor with 1 }
  759. if not bitvalue then
  760. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  761. end;
  762. *)
  763. { *********** entry/exit code and address loading ************ }
  764. procedure tcgppc.g_save_standard_registers(list:TAsmList);
  765. begin
  766. { this work is done in g_proc_entry }
  767. end;
  768. procedure tcgppc.g_restore_standard_registers(list:TAsmList);
  769. begin
  770. { this work is done in g_proc_exit }
  771. end;
  772. procedure tcgppc.g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);
  773. { generated the entry code of a procedure/function. Note: localsize is the }
  774. { sum of the size necessary for local variables and the maximum possible }
  775. { combined size of ALL the parameters of a procedure called by the current }
  776. { one. }
  777. { This procedure may be called before, as well as after g_return_from_proc }
  778. { is called. NOTE registers are not to be allocated through the register }
  779. { allocator here, because the register colouring has already occured !! }
  780. var regcounter,firstregfpu,firstregint: TSuperRegister;
  781. href : treference;
  782. usesfpr,usesgpr,gotgot : boolean;
  783. cond : tasmcond;
  784. instr : taicpu;
  785. begin
  786. { CR and LR only have to be saved in case they are modified by the current }
  787. { procedure, but currently this isn't checked, so save them always }
  788. { following is the entry code as described in "Altivec Programming }
  789. { Interface Manual", bar the saving of AltiVec registers }
  790. a_reg_alloc(list,NR_STACK_POINTER_REG);
  791. usesgpr := false;
  792. usesfpr := false;
  793. if not(po_assembler in current_procinfo.procdef.procoptions) then
  794. begin
  795. { save link register? }
  796. if (pi_do_call in current_procinfo.flags) or
  797. ([cs_lineinfo,cs_debuginfo,cs_profile] * current_settings.moduleswitches <> []) then
  798. begin
  799. a_reg_alloc(list,NR_R0);
  800. { save return address... }
  801. { warning: if this is no longer done via r0, or if r0 is }
  802. { added to the usable registers, adapt tcgppcgen.g_profilecode }
  803. list.concat(taicpu.op_reg(A_MFLR,NR_R0));
  804. { ... in caller's frame }
  805. case target_info.abi of
  806. abi_powerpc_aix:
  807. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  808. abi_powerpc_sysv:
  809. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  810. end;
  811. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  812. if not(cs_profile in current_settings.moduleswitches) then
  813. a_reg_dealloc(list,NR_R0);
  814. end;
  815. (*
  816. { save the CR if necessary in callers frame. }
  817. if target_info.abi = abi_powerpc_aix then
  818. if false then { Not needed at the moment. }
  819. begin
  820. a_reg_alloc(list,NR_R0);
  821. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  822. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  823. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  824. a_reg_dealloc(list,NR_R0);
  825. end;
  826. *)
  827. firstregfpu := tppcprocinfo(current_procinfo).get_first_save_fpu_reg;
  828. firstregint := tppcprocinfo(current_procinfo).get_first_save_int_reg;
  829. usesgpr := firstregint <> 32;
  830. usesfpr := firstregfpu <> 32;
  831. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  832. begin
  833. a_reg_alloc(list,NR_R12);
  834. list.concat(taicpu.op_reg_reg(A_MR,NR_R12,NR_STACK_POINTER_REG));
  835. end;
  836. end;
  837. { no GOT pointer loaded yet }
  838. gotgot:=false;
  839. if usesfpr then
  840. begin
  841. { save floating-point registers
  842. if (cs_create_pic in current_settings.moduleswitches) and not(usesgpr) then
  843. begin
  844. a_call_name(current_asmdata.RefAsmSymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g'));
  845. gotgot:=true;
  846. end
  847. else
  848. a_call_name(current_asmdata.RefAsmSymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)));
  849. }
  850. reference_reset_base(href,NR_R1,-8);
  851. for regcounter:=firstregfpu to RS_F31 do
  852. begin
  853. a_loadfpu_reg_ref(list,OS_F64,OS_F64,newreg(R_FPUREGISTER,regcounter,R_SUBNONE),href);
  854. dec(href.offset,8);
  855. end;
  856. { compute start of gpr save area }
  857. inc(href.offset,4);
  858. end
  859. else
  860. { compute start of gpr save area }
  861. reference_reset_base(href,NR_R1,-4);
  862. { save gprs and fetch GOT pointer }
  863. if usesgpr then
  864. begin
  865. {
  866. if cs_create_pic in current_settings.moduleswitches then
  867. begin
  868. a_call_name(current_asmdata.RefAsmSymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g'));
  869. gotgot:=true;
  870. end
  871. else
  872. a_call_name(current_asmdata.RefAsmSymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)))
  873. }
  874. if (firstregint <= RS_R22) or
  875. ((cs_opt_size in current_settings.optimizerswitches) and
  876. { with RS_R30 it's also already smaller, but too big a speed trade-off to make }
  877. (firstregint <= RS_R29)) then
  878. begin
  879. dec(href.offset,(RS_R31-firstregint)*sizeof(aint));
  880. list.concat(taicpu.op_reg_ref(A_STMW,newreg(R_INTREGISTER,firstregint,R_SUBNONE),href));
  881. end
  882. else
  883. for regcounter:=firstregint to RS_R31 do
  884. begin
  885. a_load_reg_ref(list,OS_INT,OS_INT,newreg(R_INTREGISTER,regcounter,R_SUBNONE),href);
  886. dec(href.offset,4);
  887. end;
  888. end;
  889. { done in ncgutil because it may only be released after the parameters }
  890. { have been moved to their final resting place }
  891. { if (tppcprocinfo(current_procinfo).needs_frame_pointer) then }
  892. { a_reg_dealloc(list,NR_R12); }
  893. { if we didn't get the GOT pointer till now, we've to calculate it now }
  894. (*
  895. if not(gotgot) and (pi_needs_got in current_procinfo.flags) then
  896. case target_info.system of
  897. system_powerpc_darwin:
  898. begin
  899. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_LR));
  900. fillchar(cond,sizeof(cond),0);
  901. cond.simple:=false;
  902. cond.bo:=20;
  903. cond.bi:=31;
  904. instr:=taicpu.op_sym(A_BCL,current_procinfo.CurrGOTLabel);
  905. instr.setcondition(cond);
  906. list.concat(instr);
  907. a_label(list,current_procinfo.CurrGOTLabel);
  908. list.concat(taicpu.op_reg_reg(A_MFSPR,current_procinfo.got,NR_LR));
  909. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_LR,NR_R0));
  910. end;
  911. else
  912. begin
  913. a_reg_alloc(list,NR_R31);
  914. { place GOT ptr in r31 }
  915. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R31,NR_LR));
  916. end;
  917. end;
  918. *)
  919. if (not nostackframe) and
  920. tppcprocinfo(current_procinfo).needstackframe and
  921. (localsize <> 0) then
  922. begin
  923. if (localsize <= high(smallint)) then
  924. begin
  925. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  926. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  927. end
  928. else
  929. begin
  930. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  931. { can't use getregisterint here, the register colouring }
  932. { is already done when we get here }
  933. href.index := NR_R11;
  934. a_reg_alloc(list,href.index);
  935. a_load_const_reg(list,OS_S32,-localsize,href.index);
  936. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  937. a_reg_dealloc(list,href.index);
  938. end;
  939. end;
  940. { save the CR if necessary ( !!! never done currently ) }
  941. { still need to find out where this has to be done for SystemV
  942. a_reg_alloc(list,R_0);
  943. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  944. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  945. new_reference(STACK_POINTER_REG,LA_CR)));
  946. a_reg_dealloc(list,R_0);
  947. }
  948. { now comes the AltiVec context save, not yet implemented !!! }
  949. end;
  950. procedure tcgppc.g_proc_exit(list : TAsmList;parasize : longint;nostackframe:boolean);
  951. { This procedure may be called before, as well as after g_stackframe_entry }
  952. { is called. NOTE registers are not to be allocated through the register }
  953. { allocator here, because the register colouring has already occured !! }
  954. var
  955. regcounter,firstregfpu,firstregint: TsuperRegister;
  956. href : treference;
  957. usesfpr,usesgpr,genret : boolean;
  958. localsize: aint;
  959. begin
  960. { AltiVec context restore, not yet implemented !!! }
  961. usesfpr:=false;
  962. usesgpr:=false;
  963. if not (po_assembler in current_procinfo.procdef.procoptions) then
  964. begin
  965. firstregfpu := tppcprocinfo(current_procinfo).get_first_save_fpu_reg;
  966. firstregint := tppcprocinfo(current_procinfo).get_first_save_int_reg;
  967. usesgpr := firstregint <> 32;
  968. usesfpr := firstregfpu <> 32;
  969. end;
  970. localsize:= tppcprocinfo(current_procinfo).calc_stackframe_size;
  971. { adjust r1 }
  972. { (register allocator is no longer valid at this time and an add of 0 }
  973. { is translated into a move, which is then registered with the register }
  974. { allocator, causing a crash }
  975. if (not nostackframe) and
  976. tppcprocinfo(current_procinfo).needstackframe and
  977. (localsize <> 0) then
  978. a_op_const_reg(list,OP_ADD,OS_ADDR,localsize,NR_R1);
  979. { no return (blr) generated yet }
  980. genret:=true;
  981. if usesfpr then
  982. begin
  983. reference_reset_base(href,NR_R1,-8);
  984. for regcounter := firstregfpu to RS_F31 do
  985. begin
  986. a_loadfpu_ref_reg(list,OS_F64,OS_F64,href,newreg(R_FPUREGISTER,regcounter,R_SUBNONE));
  987. dec(href.offset,8);
  988. end;
  989. inc(href.offset,4);
  990. end
  991. else
  992. reference_reset_base(href,NR_R1,-4);
  993. if (usesgpr) then
  994. begin
  995. if (firstregint <= RS_R22) or
  996. ((cs_opt_size in current_settings.optimizerswitches) and
  997. { with RS_R30 it's also already smaller, but too big a speed trade-off to make }
  998. (firstregint <= RS_R29)) then
  999. begin
  1000. dec(href.offset,(RS_R31-firstregint)*sizeof(aint));
  1001. list.concat(taicpu.op_reg_ref(A_LMW,newreg(R_INTREGISTER,firstregint,R_SUBNONE),href));
  1002. end
  1003. else
  1004. for regcounter:=firstregint to RS_R31 do
  1005. begin
  1006. a_load_ref_reg(list,OS_INT,OS_INT,href,newreg(R_INTREGISTER,regcounter,R_SUBNONE));
  1007. dec(href.offset,4);
  1008. end;
  1009. end;
  1010. (*
  1011. { restore fprs and return }
  1012. if usesfpr then
  1013. begin
  1014. { address of fpr save area to r11 }
  1015. r:=NR_R12;
  1016. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1017. {
  1018. if (pi_do_call in current_procinfo.flags) then
  1019. a_call_name(current_asmdata.RefAsmSymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_x'))
  1020. else
  1021. { leaf node => lr haven't to be restored }
  1022. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+'_l');
  1023. genret:=false;
  1024. }
  1025. end;
  1026. *)
  1027. { if we didn't generate the return code, we've to do it now }
  1028. if genret then
  1029. begin
  1030. { load link register? }
  1031. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1032. begin
  1033. if (pi_do_call in current_procinfo.flags) then
  1034. begin
  1035. case target_info.abi of
  1036. abi_powerpc_aix:
  1037. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  1038. abi_powerpc_sysv:
  1039. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  1040. end;
  1041. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1042. list.concat(taicpu.op_reg(A_MTLR,NR_R0));
  1043. end;
  1044. (*
  1045. { restore the CR if necessary from callers frame}
  1046. if target_info.abi = abi_powerpc_aix then
  1047. if false then { Not needed at the moment. }
  1048. begin
  1049. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1050. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1051. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1052. a_reg_dealloc(list,NR_R0);
  1053. end;
  1054. *)
  1055. end;
  1056. list.concat(taicpu.op_none(A_BLR));
  1057. end;
  1058. end;
  1059. function tcgppc.save_regs(list : TAsmList):longint;
  1060. {Generates code which saves used non-volatile registers in
  1061. the save area right below the address the stackpointer point to.
  1062. Returns the actual used save area size.}
  1063. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1064. usesfpr,usesgpr: boolean;
  1065. href : treference;
  1066. offset: aint;
  1067. regcounter2, firstfpureg: Tsuperregister;
  1068. begin
  1069. usesfpr:=false;
  1070. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1071. begin
  1072. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1073. case target_info.abi of
  1074. abi_powerpc_aix:
  1075. firstfpureg := RS_F14;
  1076. abi_powerpc_sysv:
  1077. firstfpureg := RS_F9;
  1078. else
  1079. internalerror(2003122903);
  1080. end;
  1081. for regcounter:=firstfpureg to RS_F31 do
  1082. begin
  1083. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1084. begin
  1085. usesfpr:=true;
  1086. firstregfpu:=regcounter;
  1087. break;
  1088. end;
  1089. end;
  1090. end;
  1091. usesgpr:=false;
  1092. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1093. for regcounter2:=RS_R13 to RS_R31 do
  1094. begin
  1095. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1096. begin
  1097. usesgpr:=true;
  1098. firstreggpr:=regcounter2;
  1099. break;
  1100. end;
  1101. end;
  1102. offset:= 0;
  1103. { save floating-point registers }
  1104. if usesfpr then
  1105. for regcounter := firstregfpu to RS_F31 do
  1106. begin
  1107. offset:= offset - 8;
  1108. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1109. list.concat(taicpu.op_reg_ref(A_STFD, tregister(regcounter), href));
  1110. end;
  1111. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1112. { save gprs in gpr save area }
  1113. if usesgpr then
  1114. if firstreggpr < RS_R30 then
  1115. begin
  1116. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1117. reference_reset_base(href,NR_STACK_POINTER_REG,offset);
  1118. list.concat(taicpu.op_reg_ref(A_STMW,tregister(firstreggpr),href));
  1119. {STMW stores multiple registers}
  1120. end
  1121. else
  1122. begin
  1123. for regcounter := firstreggpr to RS_R31 do
  1124. begin
  1125. offset:= offset - 4;
  1126. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1127. list.concat(taicpu.op_reg_ref(A_STW, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1128. end;
  1129. end;
  1130. { now comes the AltiVec context save, not yet implemented !!! }
  1131. save_regs:= -offset;
  1132. end;
  1133. procedure tcgppc.restore_regs(list : TAsmList);
  1134. {Generates code which restores used non-volatile registers from
  1135. the save area right below the address the stackpointer point to.}
  1136. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1137. usesfpr,usesgpr: boolean;
  1138. href : treference;
  1139. offset: integer;
  1140. regcounter2, firstfpureg: Tsuperregister;
  1141. begin
  1142. usesfpr:=false;
  1143. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1144. begin
  1145. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1146. case target_info.abi of
  1147. abi_powerpc_aix:
  1148. firstfpureg := RS_F14;
  1149. abi_powerpc_sysv:
  1150. firstfpureg := RS_F9;
  1151. else
  1152. internalerror(2003122903);
  1153. end;
  1154. for regcounter:=firstfpureg to RS_F31 do
  1155. begin
  1156. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1157. begin
  1158. usesfpr:=true;
  1159. firstregfpu:=regcounter;
  1160. break;
  1161. end;
  1162. end;
  1163. end;
  1164. usesgpr:=false;
  1165. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1166. for regcounter2:=RS_R13 to RS_R31 do
  1167. begin
  1168. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1169. begin
  1170. usesgpr:=true;
  1171. firstreggpr:=regcounter2;
  1172. break;
  1173. end;
  1174. end;
  1175. offset:= 0;
  1176. { restore fp registers }
  1177. if usesfpr then
  1178. for regcounter := firstregfpu to RS_F31 do
  1179. begin
  1180. offset:= offset - 8;
  1181. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1182. list.concat(taicpu.op_reg_ref(A_LFD, newreg(R_FPUREGISTER,regcounter,R_SUBWHOLE), href));
  1183. end;
  1184. (* Optimiztion in the future: a_call_name(list,'_restfXX'); *)
  1185. { restore gprs }
  1186. if usesgpr then
  1187. if firstreggpr < RS_R30 then
  1188. begin
  1189. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1190. reference_reset_base(href,NR_STACK_POINTER_REG,offset); //-220
  1191. list.concat(taicpu.op_reg_ref(A_LMW,tregister(firstreggpr),href));
  1192. {LMW loads multiple registers}
  1193. end
  1194. else
  1195. begin
  1196. for regcounter := firstreggpr to RS_R31 do
  1197. begin
  1198. offset:= offset - 4;
  1199. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1200. list.concat(taicpu.op_reg_ref(A_LWZ, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1201. end;
  1202. end;
  1203. { now comes the AltiVec context restore, not yet implemented !!! }
  1204. end;
  1205. procedure tcgppc.g_stackframe_entry_mac(list : TAsmList;localsize : longint);
  1206. (* NOT IN USE *)
  1207. { generated the entry code of a procedure/function. Note: localsize is the }
  1208. { sum of the size necessary for local variables and the maximum possible }
  1209. { combined size of ALL the parameters of a procedure called by the current }
  1210. { one }
  1211. const
  1212. macosLinkageAreaSize = 24;
  1213. var
  1214. href : treference;
  1215. registerSaveAreaSize : longint;
  1216. begin
  1217. if (localsize mod 8) <> 0 then
  1218. internalerror(58991);
  1219. { CR and LR only have to be saved in case they are modified by the current }
  1220. { procedure, but currently this isn't checked, so save them always }
  1221. { following is the entry code as described in "Altivec Programming }
  1222. { Interface Manual", bar the saving of AltiVec registers }
  1223. a_reg_alloc(list,NR_STACK_POINTER_REG);
  1224. a_reg_alloc(list,NR_R0);
  1225. { save return address in callers frame}
  1226. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_LR));
  1227. { ... in caller's frame }
  1228. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1229. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1230. a_reg_dealloc(list,NR_R0);
  1231. { save non-volatile registers in callers frame}
  1232. registerSaveAreaSize:= save_regs(list);
  1233. { save the CR if necessary in callers frame ( !!! always done currently ) }
  1234. a_reg_alloc(list,NR_R0);
  1235. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  1236. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1237. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1238. a_reg_dealloc(list,NR_R0);
  1239. (*
  1240. { save pointer to incoming arguments }
  1241. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  1242. *)
  1243. (*
  1244. a_reg_alloc(list,R_12);
  1245. { 0 or 8 based on SP alignment }
  1246. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  1247. R_12,STACK_POINTER_REG,0,28,28));
  1248. { add in stack length }
  1249. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1250. -localsize));
  1251. { establish new alignment }
  1252. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1253. a_reg_dealloc(list,R_12);
  1254. *)
  1255. { allocate stack frame }
  1256. localsize:= align(localsize + macosLinkageAreaSize + registerSaveAreaSize, 16);
  1257. inc(localsize,tg.lasttemp);
  1258. localsize:=align(localsize,16);
  1259. //tppcprocinfo(current_procinfo).localsize:=localsize;
  1260. if (localsize <> 0) then
  1261. begin
  1262. if (localsize <= high(smallint)) then
  1263. begin
  1264. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  1265. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  1266. end
  1267. else
  1268. begin
  1269. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1270. href.index := NR_R11;
  1271. a_reg_alloc(list,href.index);
  1272. a_load_const_reg(list,OS_S32,-localsize,href.index);
  1273. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  1274. a_reg_dealloc(list,href.index);
  1275. end;
  1276. end;
  1277. end;
  1278. procedure tcgppc.g_return_from_proc_mac(list : TAsmList;parasize : aint);
  1279. (* NOT IN USE *)
  1280. var
  1281. href : treference;
  1282. begin
  1283. a_reg_alloc(list,NR_R0);
  1284. { restore stack pointer }
  1285. reference_reset_base(href,NR_STACK_POINTER_REG,LA_SP);
  1286. list.concat(taicpu.op_reg_ref(A_LWZ,NR_STACK_POINTER_REG,href));
  1287. (*
  1288. list.concat(taicpu.op_reg_reg_const(A_ORI,NR_STACK_POINTER_REG,R_31,0));
  1289. *)
  1290. { restore the CR if necessary from callers frame
  1291. ( !!! always done currently ) }
  1292. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1293. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1294. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1295. a_reg_dealloc(list,NR_R0);
  1296. (*
  1297. { restore return address from callers frame }
  1298. reference_reset_base(href,STACK_POINTER_REG,8);
  1299. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1300. *)
  1301. { restore non-volatile registers from callers frame }
  1302. restore_regs(list);
  1303. (*
  1304. { return to caller }
  1305. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1306. list.concat(taicpu.op_none(A_BLR));
  1307. *)
  1308. { restore return address from callers frame }
  1309. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1310. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1311. { return to caller }
  1312. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_LR));
  1313. list.concat(taicpu.op_none(A_BLR));
  1314. end;
  1315. procedure tcgppc.a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);
  1316. var
  1317. ref2, tmpref: treference;
  1318. begin
  1319. ref2 := ref;
  1320. fixref(list,ref2);
  1321. if assigned(ref2.symbol) then
  1322. begin
  1323. if target_info.system = system_powerpc_macos then
  1324. begin
  1325. if macos_direct_globals then
  1326. begin
  1327. reference_reset(tmpref);
  1328. tmpref.offset := ref2.offset;
  1329. tmpref.symbol := ref2.symbol;
  1330. tmpref.base := NR_NO;
  1331. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,NR_RTOC,tmpref));
  1332. end
  1333. else
  1334. begin
  1335. reference_reset(tmpref);
  1336. tmpref.symbol := ref2.symbol;
  1337. tmpref.offset := 0;
  1338. tmpref.base := NR_RTOC;
  1339. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref));
  1340. if ref2.offset <> 0 then
  1341. begin
  1342. reference_reset(tmpref);
  1343. tmpref.offset := ref2.offset;
  1344. tmpref.base:= r;
  1345. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1346. end;
  1347. end;
  1348. if ref2.base <> NR_NO then
  1349. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,r,ref2.base));
  1350. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1351. end
  1352. else
  1353. begin
  1354. { add the symbol's value to the base of the reference, and if the }
  1355. { reference doesn't have a base, create one }
  1356. reference_reset(tmpref);
  1357. tmpref.offset := ref2.offset;
  1358. tmpref.symbol := ref2.symbol;
  1359. tmpref.relsymbol := ref2.relsymbol;
  1360. tmpref.refaddr := addr_hi;
  1361. if ref2.base<> NR_NO then
  1362. begin
  1363. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1364. ref2.base,tmpref));
  1365. end
  1366. else
  1367. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1368. tmpref.base := NR_NO;
  1369. tmpref.refaddr := addr_lo;
  1370. { can be folded with one of the next instructions by the }
  1371. { optimizer probably }
  1372. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1373. end
  1374. end
  1375. else if ref2.offset <> 0 Then
  1376. if ref2.base <> NR_NO then
  1377. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  1378. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1379. { occurs, so now only ref.offset has to be loaded }
  1380. else
  1381. a_load_const_reg(list,OS_32,ref2.offset,r)
  1382. else if ref2.index <> NR_NO Then
  1383. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1384. else if (ref2.base <> NR_NO) and
  1385. (r <> ref2.base) then
  1386. a_load_reg_reg(list,OS_ADDR,OS_ADDR,ref2.base,r)
  1387. else
  1388. list.concat(taicpu.op_reg_const(A_LI,r,0));
  1389. end;
  1390. { ************* concatcopy ************ }
  1391. {$ifndef ppc603}
  1392. const
  1393. maxmoveunit = 8;
  1394. {$else ppc603}
  1395. const
  1396. maxmoveunit = 4;
  1397. {$endif ppc603}
  1398. procedure tcgppc.g_concatcopy(list : TAsmList;const source,dest : treference;len : aint);
  1399. var
  1400. countreg: TRegister;
  1401. src, dst: TReference;
  1402. lab: tasmlabel;
  1403. count, count2: aint;
  1404. size: tcgsize;
  1405. copyreg: tregister;
  1406. begin
  1407. {$ifdef extdebug}
  1408. if len > high(longint) then
  1409. internalerror(2002072704);
  1410. {$endif extdebug}
  1411. if (references_equal(source,dest)) then
  1412. exit;
  1413. { make sure short loads are handled as optimally as possible }
  1414. if (len <= maxmoveunit) and
  1415. (byte(len) in [1,2,4,8]) then
  1416. begin
  1417. if len < 8 then
  1418. begin
  1419. size := int_cgsize(len);
  1420. a_load_ref_ref(list,size,size,source,dest);
  1421. end
  1422. else
  1423. begin
  1424. copyreg := getfpuregister(list,OS_F64);
  1425. a_loadfpu_ref_reg(list,OS_F64,OS_F64,source,copyreg);
  1426. a_loadfpu_reg_ref(list,OS_F64,OS_F64,copyreg,dest);
  1427. end;
  1428. exit;
  1429. end;
  1430. count := len div maxmoveunit;
  1431. reference_reset(src);
  1432. reference_reset(dst);
  1433. { load the address of source into src.base }
  1434. if (count > 4) or
  1435. not issimpleref(source) or
  1436. ((source.index <> NR_NO) and
  1437. ((source.offset + longint(len)) > high(smallint))) then
  1438. begin
  1439. src.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1440. a_loadaddr_ref_reg(list,source,src.base);
  1441. end
  1442. else
  1443. begin
  1444. src := source;
  1445. end;
  1446. { load the address of dest into dst.base }
  1447. if (count > 4) or
  1448. not issimpleref(dest) or
  1449. ((dest.index <> NR_NO) and
  1450. ((dest.offset + longint(len)) > high(smallint))) then
  1451. begin
  1452. dst.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1453. a_loadaddr_ref_reg(list,dest,dst.base);
  1454. end
  1455. else
  1456. begin
  1457. dst := dest;
  1458. end;
  1459. {$ifndef ppc603}
  1460. if count > 4 then
  1461. { generate a loop }
  1462. begin
  1463. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1464. { have to be set to 8. I put an Inc there so debugging may be }
  1465. { easier (should offset be different from zero here, it will be }
  1466. { easy to notice in the generated assembler }
  1467. inc(dst.offset,8);
  1468. inc(src.offset,8);
  1469. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1470. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1471. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1472. a_load_const_reg(list,OS_32,count,countreg);
  1473. copyreg := getfpuregister(list,OS_F64);
  1474. a_reg_sync(list,copyreg);
  1475. current_asmdata.getjumplabel(lab);
  1476. a_label(list, lab);
  1477. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1478. list.concat(taicpu.op_reg_ref(A_LFDU,copyreg,src));
  1479. list.concat(taicpu.op_reg_ref(A_STFDU,copyreg,dst));
  1480. a_jmp(list,A_BC,C_NE,0,lab);
  1481. a_reg_sync(list,copyreg);
  1482. len := len mod 8;
  1483. end;
  1484. count := len div 8;
  1485. if count > 0 then
  1486. { unrolled loop }
  1487. begin
  1488. copyreg := getfpuregister(list,OS_F64);
  1489. for count2 := 1 to count do
  1490. begin
  1491. a_loadfpu_ref_reg(list,OS_F64,OS_F64,src,copyreg);
  1492. a_loadfpu_reg_ref(list,OS_F64,OS_F64,copyreg,dst);
  1493. inc(src.offset,8);
  1494. inc(dst.offset,8);
  1495. end;
  1496. len := len mod 8;
  1497. end;
  1498. if (len and 4) <> 0 then
  1499. begin
  1500. a_reg_alloc(list,NR_R0);
  1501. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1502. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1503. inc(src.offset,4);
  1504. inc(dst.offset,4);
  1505. a_reg_dealloc(list,NR_R0);
  1506. end;
  1507. {$else not ppc603}
  1508. if count > 4 then
  1509. { generate a loop }
  1510. begin
  1511. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1512. { have to be set to 4. I put an Inc there so debugging may be }
  1513. { easier (should offset be different from zero here, it will be }
  1514. { easy to notice in the generated assembler }
  1515. inc(dst.offset,4);
  1516. inc(src.offset,4);
  1517. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,4));
  1518. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,4));
  1519. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1520. a_load_const_reg(list,OS_32,count,countreg);
  1521. { explicitely allocate R_0 since it can be used safely here }
  1522. { (for holding date that's being copied) }
  1523. a_reg_alloc(list,NR_R0);
  1524. current_asmdata.getjumplabel(lab);
  1525. a_label(list, lab);
  1526. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1527. list.concat(taicpu.op_reg_ref(A_LWZU,NR_R0,src));
  1528. list.concat(taicpu.op_reg_ref(A_STWU,NR_R0,dst));
  1529. a_jmp(list,A_BC,C_NE,0,lab);
  1530. a_reg_dealloc(list,NR_R0);
  1531. len := len mod 4;
  1532. end;
  1533. count := len div 4;
  1534. if count > 0 then
  1535. { unrolled loop }
  1536. begin
  1537. a_reg_alloc(list,NR_R0);
  1538. for count2 := 1 to count do
  1539. begin
  1540. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1541. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1542. inc(src.offset,4);
  1543. inc(dst.offset,4);
  1544. end;
  1545. a_reg_dealloc(list,NR_R0);
  1546. len := len mod 4;
  1547. end;
  1548. {$endif not ppc603}
  1549. { copy the leftovers }
  1550. if (len and 2) <> 0 then
  1551. begin
  1552. a_reg_alloc(list,NR_R0);
  1553. a_load_ref_reg(list,OS_16,OS_16,src,NR_R0);
  1554. a_load_reg_ref(list,OS_16,OS_16,NR_R0,dst);
  1555. inc(src.offset,2);
  1556. inc(dst.offset,2);
  1557. a_reg_dealloc(list,NR_R0);
  1558. end;
  1559. if (len and 1) <> 0 then
  1560. begin
  1561. a_reg_alloc(list,NR_R0);
  1562. a_load_ref_reg(list,OS_8,OS_8,src,NR_R0);
  1563. a_load_reg_ref(list,OS_8,OS_8,NR_R0,dst);
  1564. a_reg_dealloc(list,NR_R0);
  1565. end;
  1566. end;
  1567. procedure tcgppc.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  1568. procedure loadvmttor11;
  1569. var
  1570. href : treference;
  1571. begin
  1572. reference_reset_base(href,NR_R3,0);
  1573. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_R11);
  1574. end;
  1575. procedure op_onr11methodaddr;
  1576. var
  1577. href : treference;
  1578. begin
  1579. if (procdef.extnumber=$ffff) then
  1580. Internalerror(200006139);
  1581. { call/jmp vmtoffs(%eax) ; method offs }
  1582. reference_reset_base(href,NR_R11,procdef._class.vmtmethodoffset(procdef.extnumber));
  1583. if not((longint(href.offset) >= low(smallint)) and
  1584. (longint(href.offset) <= high(smallint))) then
  1585. begin
  1586. list.concat(taicpu.op_reg_reg_const(A_ADDIS,NR_R11,NR_R11,
  1587. smallint((href.offset shr 16)+ord(smallint(href.offset and $ffff) < 0))));
  1588. href.offset := smallint(href.offset and $ffff);
  1589. end;
  1590. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R11,href));
  1591. list.concat(taicpu.op_reg(A_MTCTR,NR_R11));
  1592. list.concat(taicpu.op_none(A_BCTR));
  1593. end;
  1594. var
  1595. make_global : boolean;
  1596. begin
  1597. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  1598. Internalerror(200006137);
  1599. if not assigned(procdef._class) or
  1600. (procdef.procoptions*[po_classmethod, po_staticmethod,
  1601. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  1602. Internalerror(200006138);
  1603. if procdef.owner.symtabletype<>ObjectSymtable then
  1604. Internalerror(200109191);
  1605. make_global:=false;
  1606. if (not current_module.is_unit) or
  1607. (cs_create_smart in current_settings.moduleswitches) or
  1608. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  1609. make_global:=true;
  1610. if make_global then
  1611. List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0))
  1612. else
  1613. List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0));
  1614. { set param1 interface to self }
  1615. g_adjust_self_value(list,procdef,ioffset);
  1616. { case 4 }
  1617. if po_virtualmethod in procdef.procoptions then
  1618. begin
  1619. loadvmttor11;
  1620. op_onr11methodaddr;
  1621. end
  1622. { case 0 }
  1623. else
  1624. if not(target_info.system = system_powerpc_darwin) then
  1625. list.concat(taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(procdef.mangledname)))
  1626. else
  1627. list.concat(taicpu.op_sym(A_B,get_darwin_call_stub(procdef.mangledname)));
  1628. List.concat(Tai_symbol_end.Createname(labelname));
  1629. end;
  1630. {***************** This is private property, keep out! :) *****************}
  1631. function tcgppc.issimpleref(const ref: treference): boolean;
  1632. begin
  1633. if (ref.base = NR_NO) and
  1634. (ref.index <> NR_NO) then
  1635. internalerror(200208101);
  1636. result :=
  1637. not(assigned(ref.symbol)) and
  1638. (((ref.index = NR_NO) and
  1639. (ref.offset >= low(smallint)) and
  1640. (ref.offset <= high(smallint))) or
  1641. ((ref.index <> NR_NO) and
  1642. (ref.offset = 0)));
  1643. end;
  1644. function tcgppc.fixref(list: TAsmList; var ref: treference): boolean;
  1645. var
  1646. tmpreg: tregister;
  1647. begin
  1648. result := false;
  1649. if (target_info.system = system_powerpc_darwin) and
  1650. assigned(ref.symbol) and
  1651. (ref.symbol.bind = AB_EXTERNAL) then
  1652. begin
  1653. tmpreg := g_indirect_sym_load(list,ref.symbol.name);
  1654. if (ref.base = NR_NO) then
  1655. ref.base := tmpreg
  1656. else if (ref.index = NR_NO) then
  1657. ref.index := tmpreg
  1658. else
  1659. begin
  1660. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,ref.base,tmpreg));
  1661. ref.base := tmpreg;
  1662. end;
  1663. ref.symbol := nil;
  1664. end;
  1665. if (ref.base = NR_NO) then
  1666. begin
  1667. ref.base := ref.index;
  1668. ref.index := NR_NO;
  1669. end;
  1670. if (ref.base <> NR_NO) then
  1671. begin
  1672. if (ref.index <> NR_NO) and
  1673. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1674. begin
  1675. result := true;
  1676. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1677. list.concat(taicpu.op_reg_reg_reg(
  1678. A_ADD,tmpreg,ref.base,ref.index));
  1679. ref.index := NR_NO;
  1680. ref.base := tmpreg;
  1681. end
  1682. end
  1683. else
  1684. if ref.index <> NR_NO then
  1685. internalerror(200208102);
  1686. end;
  1687. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1688. { that's the case, we can use rlwinm to do an AND operation }
  1689. function tcgppc.get_rlwi_const(a: aint; var l1, l2: longint): boolean;
  1690. var
  1691. temp : longint;
  1692. testbit : aint;
  1693. compare: boolean;
  1694. begin
  1695. get_rlwi_const := false;
  1696. if (a = 0) or (a = -1) then
  1697. exit;
  1698. { start with the lowest bit }
  1699. testbit := 1;
  1700. { check its value }
  1701. compare := boolean(a and testbit);
  1702. { find out how long the run of bits with this value is }
  1703. { (it's impossible that all bits are 1 or 0, because in that case }
  1704. { this function wouldn't have been called) }
  1705. l1 := 31;
  1706. while (((a and testbit) <> 0) = compare) do
  1707. begin
  1708. testbit := testbit shl 1;
  1709. dec(l1);
  1710. end;
  1711. { check the length of the run of bits that comes next }
  1712. compare := not compare;
  1713. l2 := l1;
  1714. while (((a and testbit) <> 0) = compare) and
  1715. (l2 >= 0) do
  1716. begin
  1717. testbit := testbit shl 1;
  1718. dec(l2);
  1719. end;
  1720. { and finally the check whether the rest of the bits all have the }
  1721. { same value }
  1722. compare := not compare;
  1723. temp := l2;
  1724. if temp >= 0 then
  1725. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1726. exit;
  1727. { we have done "not(not(compare))", so compare is back to its }
  1728. { initial value. If the lowest bit was 0, a is of the form }
  1729. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1730. { because l2 now contains the position of the last zero of the }
  1731. { first run instead of that of the first 1) so switch l1 and l2 }
  1732. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1733. if not compare then
  1734. begin
  1735. temp := l1;
  1736. l1 := l2+1;
  1737. l2 := temp;
  1738. end
  1739. else
  1740. { otherwise, l1 currently contains the position of the last }
  1741. { zero instead of that of the first 1 of the second run -> +1 }
  1742. inc(l1);
  1743. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1744. l1 := l1 and 31;
  1745. l2 := l2 and 31;
  1746. get_rlwi_const := true;
  1747. end;
  1748. procedure tcgppc.a_load_store(list:TAsmList;op: tasmop;reg:tregister;
  1749. ref: treference);
  1750. var
  1751. tmpreg: tregister;
  1752. tmpref: treference;
  1753. largeOffset: Boolean;
  1754. begin
  1755. tmpreg := NR_NO;
  1756. if target_info.system = system_powerpc_macos then
  1757. begin
  1758. largeOffset:= (cardinal(ref.offset-low(smallint)) >
  1759. high(smallint)-low(smallint));
  1760. if assigned(ref.symbol) then
  1761. begin {Load symbol's value}
  1762. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1763. reference_reset(tmpref);
  1764. tmpref.symbol := ref.symbol;
  1765. tmpref.base := NR_RTOC;
  1766. if macos_direct_globals then
  1767. list.concat(taicpu.op_reg_ref(A_LA,tmpreg,tmpref))
  1768. else
  1769. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1770. end;
  1771. if largeOffset then
  1772. begin {Add hi part of offset}
  1773. reference_reset(tmpref);
  1774. if Smallint(Lo(ref.offset)) < 0 then
  1775. tmpref.offset := Hi(ref.offset) + 1 {Compensate when lo part is negative}
  1776. else
  1777. tmpref.offset := Hi(ref.offset);
  1778. if (tmpreg <> NR_NO) then
  1779. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg, tmpreg,tmpref))
  1780. else
  1781. begin
  1782. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1783. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1784. end;
  1785. end;
  1786. if (tmpreg <> NR_NO) then
  1787. begin
  1788. {Add content of base register}
  1789. if ref.base <> NR_NO then
  1790. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1791. ref.base,tmpreg));
  1792. {Make ref ready to be used by op}
  1793. ref.symbol:= nil;
  1794. ref.base:= tmpreg;
  1795. if largeOffset then
  1796. ref.offset := Smallint(Lo(ref.offset));
  1797. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1798. //list.concat(tai_comment.create(strpnew('*** a_load_store indirect global')));
  1799. end
  1800. else
  1801. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1802. end
  1803. else {if target_info.system <> system_powerpc_macos}
  1804. begin
  1805. if assigned(ref.symbol) or
  1806. (cardinal(ref.offset-low(smallint)) >
  1807. high(smallint)-low(smallint)) then
  1808. begin
  1809. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1810. reference_reset(tmpref);
  1811. tmpref.symbol := ref.symbol;
  1812. tmpref.relsymbol := ref.relsymbol;
  1813. tmpref.offset := ref.offset;
  1814. tmpref.refaddr := addr_hi;
  1815. if ref.base <> NR_NO then
  1816. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1817. ref.base,tmpref))
  1818. else
  1819. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1820. ref.base := tmpreg;
  1821. ref.refaddr := addr_lo;
  1822. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1823. end
  1824. else
  1825. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1826. end;
  1827. end;
  1828. procedure tcg64fppc.a_op64_reg_reg(list : TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);
  1829. begin
  1830. a_op64_reg_reg_reg(list,op,size,regsrc,regdst,regdst);
  1831. end;
  1832. procedure tcg64fppc.a_op64_const_reg(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;reg : tregister64);
  1833. begin
  1834. a_op64_const_reg_reg(list,op,size,value,reg,reg);
  1835. end;
  1836. procedure tcg64fppc.a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1837. begin
  1838. case op of
  1839. OP_AND,OP_OR,OP_XOR:
  1840. begin
  1841. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1842. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1843. end;
  1844. OP_ADD:
  1845. begin
  1846. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1847. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1848. end;
  1849. OP_SUB:
  1850. begin
  1851. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1852. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1853. end;
  1854. else
  1855. internalerror(2002072801);
  1856. end;
  1857. end;
  1858. procedure tcg64fppc.a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);
  1859. const
  1860. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1861. (A_SUBIC,A_SUBC,A_ADDME));
  1862. var
  1863. tmpreg: tregister;
  1864. tmpreg64: tregister64;
  1865. issub: boolean;
  1866. begin
  1867. case op of
  1868. OP_AND,OP_OR,OP_XOR:
  1869. begin
  1870. cg.a_op_const_reg_reg(list,op,OS_32,aint(value),regsrc.reglo,regdst.reglo);
  1871. cg.a_op_const_reg_reg(list,op,OS_32,aint(value shr 32),regsrc.reghi,
  1872. regdst.reghi);
  1873. end;
  1874. OP_ADD, OP_SUB:
  1875. begin
  1876. if (value < 0) and
  1877. (value <> low(value)) then
  1878. begin
  1879. if op = OP_ADD then
  1880. op := OP_SUB
  1881. else
  1882. op := OP_ADD;
  1883. value := -value;
  1884. end;
  1885. if (longint(value) <> 0) then
  1886. begin
  1887. issub := op = OP_SUB;
  1888. if (value > 0) and
  1889. (value-ord(issub) <= 32767) then
  1890. begin
  1891. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1892. regdst.reglo,regsrc.reglo,longint(value)));
  1893. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1894. regdst.reghi,regsrc.reghi));
  1895. end
  1896. else if ((value shr 32) = 0) then
  1897. begin
  1898. tmpreg := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1899. cg.a_load_const_reg(list,OS_32,aint(value),tmpreg);
  1900. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  1901. regdst.reglo,regsrc.reglo,tmpreg));
  1902. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1903. regdst.reghi,regsrc.reghi));
  1904. end
  1905. else
  1906. begin
  1907. tmpreg64.reglo := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1908. tmpreg64.reghi := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1909. a_load64_const_reg(list,value,tmpreg64);
  1910. a_op64_reg_reg_reg(list,op,size,tmpreg64,regsrc,regdst);
  1911. end
  1912. end
  1913. else
  1914. begin
  1915. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  1916. cg.a_op_const_reg_reg(list,op,OS_32,aint(value shr 32),regsrc.reghi,
  1917. regdst.reghi);
  1918. end;
  1919. end;
  1920. else
  1921. internalerror(2002072802);
  1922. end;
  1923. end;
  1924. begin
  1925. cg := tcgppc.create;
  1926. cg64 :=tcg64fppc.create;
  1927. end.