cgcpu.pas 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187
  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 ((sreg.bitlen mod 8) = 0) then
  357. begin
  358. a_load_reg_reg(list,tcgsize2unsigned[subsetsize],subsetsize,destreg,destreg);
  359. a_load_reg_reg(list,subsetsize,tosize,destreg,destreg);
  360. end;
  361. end
  362. else
  363. a_load_reg_reg(list,subsetsize,tosize,sreg.subsetreg,destreg);
  364. end;
  365. procedure tcgppc.a_load_regconst_subsetreg_intern(list : TAsmList; fromsize, subsetsize: tcgsize; fromreg: tregister; const sreg: tsubsetregister; slopt: tsubsetloadopt);
  366. begin
  367. if (slopt in [SL_SETZERO,SL_SETMAX]) then
  368. inherited a_load_regconst_subsetreg_intern(list,fromsize,subsetsize,fromreg,sreg,slopt)
  369. else if (sreg.bitlen <> sizeof(aint) * 8) then
  370. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,sreg.subsetreg,fromreg,
  371. sreg.startbit,32-sreg.startbit-sreg.bitlen,31-sreg.startbit))
  372. else
  373. a_load_reg_reg(list,fromsize,subsetsize,fromreg,sreg.subsetreg);
  374. end;
  375. procedure tcgppc.a_load_subsetreg_subsetreg(list: TAsmlist; fromsubsetsize, tosubsetsize: tcgsize; const fromsreg, tosreg: tsubsetregister);
  376. begin
  377. if (fromsreg.bitlen >= tosreg.bitlen) then
  378. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,tosreg.subsetreg, fromsreg.subsetreg,
  379. (tosreg.startbit-fromsreg.startbit) and 31,
  380. 32-tosreg.startbit-tosreg.bitlen,31-tosreg.startbit))
  381. else
  382. inherited a_load_subsetreg_subsetreg(list,fromsubsetsize,tosubsetsize,fromsreg,tosreg);
  383. end;
  384. procedure tcgppc.a_op_const_reg(list : TAsmList; Op: TOpCG; size: TCGSize; a: aint; reg: TRegister);
  385. begin
  386. a_op_const_reg_reg(list,op,size,a,reg,reg);
  387. end;
  388. procedure tcgppc.a_op_reg_reg(list : TAsmList; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  389. begin
  390. a_op_reg_reg_reg(list,op,size,src,dst,dst);
  391. end;
  392. procedure tcgppc.maybeadjustresult(list: TAsmList; op: TOpCg; size: tcgsize; dst: tregister);
  393. const
  394. overflowops = [OP_MUL,OP_SHL,OP_ADD,OP_SUB,OP_NOT,OP_NEG];
  395. begin
  396. if (op in overflowops) and
  397. (size in [OS_8,OS_S8,OS_16,OS_S16]) then
  398. a_load_reg_reg(list,OS_32,size,dst,dst);
  399. end;
  400. procedure tcgppc.a_op_const_reg_reg(list: TAsmList; op: TOpCg;
  401. size: tcgsize; a: aint; src, dst: tregister);
  402. var
  403. l1,l2: longint;
  404. oplo, ophi: tasmop;
  405. scratchreg: tregister;
  406. useReg, gotrlwi: boolean;
  407. procedure do_lo_hi;
  408. begin
  409. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  410. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  411. end;
  412. begin
  413. if (op = OP_MOVE) then
  414. internalerror(2006031401);
  415. if op = OP_SUB then
  416. begin
  417. a_op_const_reg_reg(list,OP_ADD,size,-a,src,dst);
  418. exit;
  419. end;
  420. ophi := TOpCG2AsmOpConstHi[op];
  421. oplo := TOpCG2AsmOpConstLo[op];
  422. gotrlwi := get_rlwi_const(a,l1,l2);
  423. if (op in [OP_AND,OP_OR,OP_XOR]) then
  424. begin
  425. if (a = 0) then
  426. begin
  427. if op = OP_AND then
  428. list.concat(taicpu.op_reg_const(A_LI,dst,0))
  429. else
  430. a_load_reg_reg(list,size,size,src,dst);
  431. exit;
  432. end
  433. else if (a = -1) then
  434. begin
  435. case op of
  436. OP_OR:
  437. case size of
  438. OS_8, OS_S8:
  439. list.concat(taicpu.op_reg_const(A_LI,dst,255));
  440. OS_16, OS_S16:
  441. a_load_const_reg(list,OS_16,65535,dst);
  442. else
  443. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  444. end;
  445. OP_XOR:
  446. case size of
  447. OS_8, OS_S8:
  448. list.concat(taicpu.op_reg_reg_const(A_XORI,dst,src,255));
  449. OS_16, OS_S16:
  450. list.concat(taicpu.op_reg_reg_const(A_XORI,dst,src,65535));
  451. else
  452. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  453. end;
  454. OP_AND:
  455. a_load_reg_reg(list,size,size,src,dst);
  456. end;
  457. exit;
  458. end
  459. else if (aword(a) <= high(word)) and
  460. ((op <> OP_AND) or
  461. not gotrlwi) then
  462. begin
  463. if ((size = OS_8) and
  464. (byte(a) <> a)) or
  465. ((size = OS_S8) and
  466. (shortint(a) <> a)) then
  467. internalerror(200604142);
  468. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  469. { and/or/xor -> cannot overflow in high 16 bits }
  470. exit;
  471. end;
  472. { all basic constant instructions also have a shifted form that }
  473. { works only on the highest 16bits, so if lo(a) is 0, we can }
  474. { use that one }
  475. if (word(a) = 0) and
  476. (not(op = OP_AND) or
  477. not gotrlwi) then
  478. begin
  479. if (size in [OS_8,OS_S8,OS_16,OS_S16]) then
  480. internalerror(200604141);
  481. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  482. exit;
  483. end;
  484. end
  485. else if (op = OP_ADD) then
  486. if a = 0 then
  487. begin
  488. a_load_reg_reg(list,size,size,src,dst);
  489. exit
  490. end
  491. else if (a >= low(smallint)) and
  492. (a <= high(smallint)) then
  493. begin
  494. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  495. maybeadjustresult(list,op,size,dst);
  496. exit;
  497. end;
  498. { otherwise, the instructions we can generate depend on the }
  499. { operation }
  500. useReg := false;
  501. case op of
  502. OP_DIV,OP_IDIV:
  503. if (a = 0) then
  504. internalerror(200208103)
  505. else if (a = 1) then
  506. begin
  507. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  508. exit
  509. end
  510. else if ispowerof2(a,l1) then
  511. begin
  512. case op of
  513. OP_DIV:
  514. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  515. OP_IDIV:
  516. begin
  517. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  518. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  519. end;
  520. end;
  521. exit;
  522. end
  523. else
  524. usereg := true;
  525. OP_IMUL, OP_MUL:
  526. if (a = 0) then
  527. begin
  528. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  529. exit
  530. end
  531. else if (a = 1) then
  532. begin
  533. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  534. exit
  535. end
  536. else if ispowerof2(a,l1) then
  537. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  538. else if (longint(a) >= low(smallint)) and
  539. (longint(a) <= high(smallint)) then
  540. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  541. else
  542. usereg := true;
  543. OP_ADD:
  544. begin
  545. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  546. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  547. smallint((a shr 16) + ord(smallint(a) < 0))));
  548. end;
  549. OP_OR:
  550. { try to use rlwimi }
  551. if gotrlwi and
  552. (src = dst) then
  553. begin
  554. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  555. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  556. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  557. scratchreg,0,l1,l2));
  558. end
  559. else
  560. do_lo_hi;
  561. OP_AND:
  562. { try to use rlwinm }
  563. if gotrlwi then
  564. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  565. src,0,l1,l2))
  566. else
  567. useReg := true;
  568. OP_XOR:
  569. do_lo_hi;
  570. OP_SHL,OP_SHR,OP_SAR:
  571. begin
  572. if (a and 31) <> 0 Then
  573. list.concat(taicpu.op_reg_reg_const(
  574. TOpCG2AsmOpConstLo[Op],dst,src,a and 31))
  575. else
  576. a_load_reg_reg(list,size,size,src,dst);
  577. if (a shr 5) <> 0 then
  578. internalError(68991);
  579. end
  580. else
  581. internalerror(200109091);
  582. end;
  583. { if all else failed, load the constant in a register and then }
  584. { perform the operation }
  585. if useReg then
  586. begin
  587. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  588. a_load_const_reg(list,OS_32,a,scratchreg);
  589. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  590. end;
  591. maybeadjustresult(list,op,size,dst);
  592. end;
  593. procedure tcgppc.a_op_reg_reg_reg(list: TAsmList; op: TOpCg;
  594. size: tcgsize; src1, src2, dst: tregister);
  595. const
  596. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  597. (A_NONE,A_MR,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  598. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  599. begin
  600. if (op = OP_MOVE) then
  601. internalerror(2006031402);
  602. case op of
  603. OP_NEG,OP_NOT:
  604. begin
  605. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,src1));
  606. if (op = OP_NOT) and
  607. not(size in [OS_32,OS_S32]) then
  608. { zero/sign extend result again }
  609. a_load_reg_reg(list,OS_32,size,dst,dst);
  610. end;
  611. else
  612. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  613. end;
  614. maybeadjustresult(list,op,size,dst);
  615. end;
  616. {*************** compare instructructions ****************}
  617. procedure tcgppc.a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  618. l : tasmlabel);
  619. var
  620. scratch_register: TRegister;
  621. signed: boolean;
  622. begin
  623. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE,OC_EQ,OC_NE];
  624. { in the following case, we generate more efficient code when }
  625. { signed is false }
  626. if (cmp_op in [OC_EQ,OC_NE]) and
  627. (aword(a) >= $8000) and
  628. (aword(a) <= $ffff) then
  629. signed := false;
  630. if signed then
  631. if (a >= low(smallint)) and (a <= high(smallint)) Then
  632. list.concat(taicpu.op_reg_reg_const(A_CMPWI,NR_CR0,reg,a))
  633. else
  634. begin
  635. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  636. a_load_const_reg(list,OS_32,a,scratch_register);
  637. list.concat(taicpu.op_reg_reg_reg(A_CMPW,NR_CR0,reg,scratch_register));
  638. end
  639. else
  640. if (aword(a) <= $ffff) then
  641. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,NR_CR0,reg,aword(a)))
  642. else
  643. begin
  644. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  645. a_load_const_reg(list,OS_32,a,scratch_register);
  646. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,NR_CR0,reg,scratch_register));
  647. end;
  648. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  649. end;
  650. procedure tcgppc.a_cmp_reg_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;
  651. reg1,reg2 : tregister;l : tasmlabel);
  652. var
  653. op: tasmop;
  654. begin
  655. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  656. op := A_CMPW
  657. else
  658. op := A_CMPLW;
  659. list.concat(taicpu.op_reg_reg_reg(op,NR_CR0,reg2,reg1));
  660. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  661. end;
  662. procedure tcgppc.a_jmp_name(list : TAsmList;const s : string);
  663. var
  664. p : taicpu;
  665. begin
  666. if (target_info.system = system_powerpc_darwin) then
  667. p := taicpu.op_sym(A_B,get_darwin_call_stub(s))
  668. else
  669. p := taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(s));
  670. p.is_jmp := true;
  671. list.concat(p)
  672. end;
  673. procedure tcgppc.a_jmp_always(list : TAsmList;l: tasmlabel);
  674. begin
  675. a_jmp(list,A_B,C_None,0,l);
  676. end;
  677. procedure tcgppc.a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel);
  678. var
  679. c: tasmcond;
  680. begin
  681. c := flags_to_cond(f);
  682. a_jmp(list,A_BC,c.cond,c.cr-RS_CR0,l);
  683. end;
  684. procedure tcgppc.g_flags2reg(list: TAsmList; size: TCgSize; const f: TResFlags; reg: TRegister);
  685. var
  686. testbit: byte;
  687. bitvalue: boolean;
  688. begin
  689. { get the bit to extract from the conditional register + its }
  690. { requested value (0 or 1) }
  691. testbit := ((f.cr-RS_CR0) * 4);
  692. case f.flag of
  693. F_EQ,F_NE:
  694. begin
  695. inc(testbit,2);
  696. bitvalue := f.flag = F_EQ;
  697. end;
  698. F_LT,F_GE:
  699. begin
  700. bitvalue := f.flag = F_LT;
  701. end;
  702. F_GT,F_LE:
  703. begin
  704. inc(testbit);
  705. bitvalue := f.flag = F_GT;
  706. end;
  707. else
  708. internalerror(200112261);
  709. end;
  710. { load the conditional register in the destination reg }
  711. list.concat(taicpu.op_reg(A_MFCR,reg));
  712. { we will move the bit that has to be tested to bit 0 by rotating }
  713. { left }
  714. testbit := (testbit + 1) and 31;
  715. { extract bit }
  716. list.concat(taicpu.op_reg_reg_const_const_const(
  717. A_RLWINM,reg,reg,testbit,31,31));
  718. { if we need the inverse, xor with 1 }
  719. if not bitvalue then
  720. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  721. end;
  722. (*
  723. procedure tcgppc.g_cond2reg(list: TAsmList; const f: TAsmCond; reg: TRegister);
  724. var
  725. testbit: byte;
  726. bitvalue: boolean;
  727. begin
  728. { get the bit to extract from the conditional register + its }
  729. { requested value (0 or 1) }
  730. case f.simple of
  731. false:
  732. begin
  733. { we don't generate this in the compiler }
  734. internalerror(200109062);
  735. end;
  736. true:
  737. case f.cond of
  738. C_None:
  739. internalerror(200109063);
  740. C_LT..C_NU:
  741. begin
  742. testbit := (ord(f.cr) - ord(R_CR0))*4;
  743. inc(testbit,AsmCondFlag2BI[f.cond]);
  744. bitvalue := AsmCondFlagTF[f.cond];
  745. end;
  746. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  747. begin
  748. testbit := f.crbit
  749. bitvalue := AsmCondFlagTF[f.cond];
  750. end;
  751. else
  752. internalerror(200109064);
  753. end;
  754. end;
  755. { load the conditional register in the destination reg }
  756. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  757. { we will move the bit that has to be tested to bit 31 -> rotate }
  758. { left by bitpos+1 (remember, this is big-endian!) }
  759. if bitpos <> 31 then
  760. inc(bitpos)
  761. else
  762. bitpos := 0;
  763. { extract bit }
  764. list.concat(taicpu.op_reg_reg_const_const_const(
  765. A_RLWINM,reg,reg,bitpos,31,31));
  766. { if we need the inverse, xor with 1 }
  767. if not bitvalue then
  768. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  769. end;
  770. *)
  771. { *********** entry/exit code and address loading ************ }
  772. procedure tcgppc.g_save_standard_registers(list:TAsmList);
  773. begin
  774. { this work is done in g_proc_entry }
  775. end;
  776. procedure tcgppc.g_restore_standard_registers(list:TAsmList);
  777. begin
  778. { this work is done in g_proc_exit }
  779. end;
  780. procedure tcgppc.g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);
  781. { generated the entry code of a procedure/function. Note: localsize is the }
  782. { sum of the size necessary for local variables and the maximum possible }
  783. { combined size of ALL the parameters of a procedure called by the current }
  784. { one. }
  785. { This procedure may be called before, as well as after g_return_from_proc }
  786. { is called. NOTE registers are not to be allocated through the register }
  787. { allocator here, because the register colouring has already occured !! }
  788. var regcounter,firstregfpu,firstregint: TSuperRegister;
  789. href : treference;
  790. usesfpr,usesgpr,gotgot : boolean;
  791. cond : tasmcond;
  792. instr : taicpu;
  793. begin
  794. { CR and LR only have to be saved in case they are modified by the current }
  795. { procedure, but currently this isn't checked, so save them always }
  796. { following is the entry code as described in "Altivec Programming }
  797. { Interface Manual", bar the saving of AltiVec registers }
  798. a_reg_alloc(list,NR_STACK_POINTER_REG);
  799. usesgpr := false;
  800. usesfpr := false;
  801. if not(po_assembler in current_procinfo.procdef.procoptions) then
  802. begin
  803. { save link register? }
  804. if (pi_do_call in current_procinfo.flags) or
  805. ([cs_lineinfo,cs_debuginfo,cs_profile] * current_settings.moduleswitches <> []) then
  806. begin
  807. a_reg_alloc(list,NR_R0);
  808. { save return address... }
  809. { warning: if this is no longer done via r0, or if r0 is }
  810. { added to the usable registers, adapt tcgppcgen.g_profilecode }
  811. list.concat(taicpu.op_reg(A_MFLR,NR_R0));
  812. { ... in caller's frame }
  813. case target_info.abi of
  814. abi_powerpc_aix:
  815. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  816. abi_powerpc_sysv:
  817. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  818. end;
  819. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  820. if not(cs_profile in current_settings.moduleswitches) then
  821. a_reg_dealloc(list,NR_R0);
  822. end;
  823. (*
  824. { save the CR if necessary in callers frame. }
  825. if target_info.abi = abi_powerpc_aix then
  826. if false then { Not needed at the moment. }
  827. begin
  828. a_reg_alloc(list,NR_R0);
  829. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  830. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  831. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  832. a_reg_dealloc(list,NR_R0);
  833. end;
  834. *)
  835. firstregfpu := tppcprocinfo(current_procinfo).get_first_save_fpu_reg;
  836. firstregint := tppcprocinfo(current_procinfo).get_first_save_int_reg;
  837. usesgpr := firstregint <> 32;
  838. usesfpr := firstregfpu <> 32;
  839. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  840. begin
  841. a_reg_alloc(list,NR_R12);
  842. list.concat(taicpu.op_reg_reg(A_MR,NR_R12,NR_STACK_POINTER_REG));
  843. end;
  844. end;
  845. { no GOT pointer loaded yet }
  846. gotgot:=false;
  847. if usesfpr then
  848. begin
  849. { save floating-point registers
  850. if (cs_create_pic in current_settings.moduleswitches) and not(usesgpr) then
  851. begin
  852. a_call_name(current_asmdata.RefAsmSymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g'));
  853. gotgot:=true;
  854. end
  855. else
  856. a_call_name(current_asmdata.RefAsmSymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)));
  857. }
  858. reference_reset_base(href,NR_R1,-8);
  859. for regcounter:=firstregfpu to RS_F31 do
  860. begin
  861. a_loadfpu_reg_ref(list,OS_F64,OS_F64,newreg(R_FPUREGISTER,regcounter,R_SUBNONE),href);
  862. dec(href.offset,8);
  863. end;
  864. { compute start of gpr save area }
  865. inc(href.offset,4);
  866. end
  867. else
  868. { compute start of gpr save area }
  869. reference_reset_base(href,NR_R1,-4);
  870. { save gprs and fetch GOT pointer }
  871. if usesgpr then
  872. begin
  873. {
  874. if cs_create_pic in current_settings.moduleswitches then
  875. begin
  876. a_call_name(current_asmdata.RefAsmSymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g'));
  877. gotgot:=true;
  878. end
  879. else
  880. a_call_name(current_asmdata.RefAsmSymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)))
  881. }
  882. if (firstregint <= RS_R22) or
  883. ((cs_opt_size in current_settings.optimizerswitches) and
  884. { with RS_R30 it's also already smaller, but too big a speed trade-off to make }
  885. (firstregint <= RS_R29)) then
  886. begin
  887. dec(href.offset,(RS_R31-firstregint)*sizeof(aint));
  888. list.concat(taicpu.op_reg_ref(A_STMW,newreg(R_INTREGISTER,firstregint,R_SUBNONE),href));
  889. end
  890. else
  891. for regcounter:=firstregint to RS_R31 do
  892. begin
  893. a_load_reg_ref(list,OS_INT,OS_INT,newreg(R_INTREGISTER,regcounter,R_SUBNONE),href);
  894. dec(href.offset,4);
  895. end;
  896. end;
  897. { done in ncgutil because it may only be released after the parameters }
  898. { have been moved to their final resting place }
  899. { if (tppcprocinfo(current_procinfo).needs_frame_pointer) then }
  900. { a_reg_dealloc(list,NR_R12); }
  901. { if we didn't get the GOT pointer till now, we've to calculate it now }
  902. (*
  903. if not(gotgot) and (pi_needs_got in current_procinfo.flags) then
  904. case target_info.system of
  905. system_powerpc_darwin:
  906. begin
  907. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_LR));
  908. fillchar(cond,sizeof(cond),0);
  909. cond.simple:=false;
  910. cond.bo:=20;
  911. cond.bi:=31;
  912. instr:=taicpu.op_sym(A_BCL,current_procinfo.CurrGOTLabel);
  913. instr.setcondition(cond);
  914. list.concat(instr);
  915. a_label(list,current_procinfo.CurrGOTLabel);
  916. list.concat(taicpu.op_reg_reg(A_MFSPR,current_procinfo.got,NR_LR));
  917. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_LR,NR_R0));
  918. end;
  919. else
  920. begin
  921. a_reg_alloc(list,NR_R31);
  922. { place GOT ptr in r31 }
  923. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R31,NR_LR));
  924. end;
  925. end;
  926. *)
  927. if (not nostackframe) and
  928. (localsize <> 0) then
  929. begin
  930. if (localsize <= high(smallint)) then
  931. begin
  932. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  933. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  934. end
  935. else
  936. begin
  937. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  938. { can't use getregisterint here, the register colouring }
  939. { is already done when we get here }
  940. href.index := NR_R11;
  941. a_reg_alloc(list,href.index);
  942. a_load_const_reg(list,OS_S32,-localsize,href.index);
  943. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  944. a_reg_dealloc(list,href.index);
  945. end;
  946. end;
  947. { save the CR if necessary ( !!! never done currently ) }
  948. { still need to find out where this has to be done for SystemV
  949. a_reg_alloc(list,R_0);
  950. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  951. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  952. new_reference(STACK_POINTER_REG,LA_CR)));
  953. a_reg_dealloc(list,R_0);
  954. }
  955. { now comes the AltiVec context save, not yet implemented !!! }
  956. end;
  957. procedure tcgppc.g_proc_exit(list : TAsmList;parasize : longint;nostackframe:boolean);
  958. { This procedure may be called before, as well as after g_stackframe_entry }
  959. { is called. NOTE registers are not to be allocated through the register }
  960. { allocator here, because the register colouring has already occured !! }
  961. var
  962. regcounter,firstregfpu,firstregint: TsuperRegister;
  963. href : treference;
  964. usesfpr,usesgpr,genret : boolean;
  965. localsize: aint;
  966. begin
  967. { AltiVec context restore, not yet implemented !!! }
  968. usesfpr:=false;
  969. usesgpr:=false;
  970. if not (po_assembler in current_procinfo.procdef.procoptions) then
  971. begin
  972. firstregfpu := tppcprocinfo(current_procinfo).get_first_save_fpu_reg;
  973. firstregint := tppcprocinfo(current_procinfo).get_first_save_int_reg;
  974. usesgpr := firstregint <> 32;
  975. usesfpr := firstregfpu <> 32;
  976. end;
  977. localsize:= tppcprocinfo(current_procinfo).calc_stackframe_size;
  978. { adjust r1 }
  979. { (register allocator is no longer valid at this time and an add of 0 }
  980. { is translated into a move, which is then registered with the register }
  981. { allocator, causing a crash }
  982. if (not nostackframe) and
  983. (localsize <> 0) then
  984. a_op_const_reg(list,OP_ADD,OS_ADDR,localsize,NR_R1);
  985. { no return (blr) generated yet }
  986. genret:=true;
  987. if usesfpr then
  988. begin
  989. reference_reset_base(href,NR_R1,-8);
  990. for regcounter := firstregfpu to RS_F31 do
  991. begin
  992. a_loadfpu_ref_reg(list,OS_F64,OS_F64,href,newreg(R_FPUREGISTER,regcounter,R_SUBNONE));
  993. dec(href.offset,8);
  994. end;
  995. inc(href.offset,4);
  996. end
  997. else
  998. reference_reset_base(href,NR_R1,-4);
  999. if (usesgpr) then
  1000. begin
  1001. if (firstregint <= RS_R22) or
  1002. ((cs_opt_size in current_settings.optimizerswitches) and
  1003. { with RS_R30 it's also already smaller, but too big a speed trade-off to make }
  1004. (firstregint <= RS_R29)) then
  1005. begin
  1006. dec(href.offset,(RS_R31-firstregint)*sizeof(aint));
  1007. list.concat(taicpu.op_reg_ref(A_LMW,newreg(R_INTREGISTER,firstregint,R_SUBNONE),href));
  1008. end
  1009. else
  1010. for regcounter:=firstregint to RS_R31 do
  1011. begin
  1012. a_load_ref_reg(list,OS_INT,OS_INT,href,newreg(R_INTREGISTER,regcounter,R_SUBNONE));
  1013. dec(href.offset,4);
  1014. end;
  1015. end;
  1016. (*
  1017. { restore fprs and return }
  1018. if usesfpr then
  1019. begin
  1020. { address of fpr save area to r11 }
  1021. r:=NR_R12;
  1022. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1023. {
  1024. if (pi_do_call in current_procinfo.flags) then
  1025. a_call_name(current_asmdata.RefAsmSymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_x'))
  1026. else
  1027. { leaf node => lr haven't to be restored }
  1028. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+'_l');
  1029. genret:=false;
  1030. }
  1031. end;
  1032. *)
  1033. { if we didn't generate the return code, we've to do it now }
  1034. if genret then
  1035. begin
  1036. { load link register? }
  1037. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1038. begin
  1039. if (pi_do_call in current_procinfo.flags) then
  1040. begin
  1041. case target_info.abi of
  1042. abi_powerpc_aix:
  1043. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  1044. abi_powerpc_sysv:
  1045. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  1046. end;
  1047. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1048. list.concat(taicpu.op_reg(A_MTLR,NR_R0));
  1049. end;
  1050. (*
  1051. { restore the CR if necessary from callers frame}
  1052. if target_info.abi = abi_powerpc_aix then
  1053. if false then { Not needed at the moment. }
  1054. begin
  1055. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1056. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1057. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1058. a_reg_dealloc(list,NR_R0);
  1059. end;
  1060. *)
  1061. end;
  1062. list.concat(taicpu.op_none(A_BLR));
  1063. end;
  1064. end;
  1065. function tcgppc.save_regs(list : TAsmList):longint;
  1066. {Generates code which saves used non-volatile registers in
  1067. the save area right below the address the stackpointer point to.
  1068. Returns the actual used save area size.}
  1069. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1070. usesfpr,usesgpr: boolean;
  1071. href : treference;
  1072. offset: aint;
  1073. regcounter2, firstfpureg: Tsuperregister;
  1074. begin
  1075. usesfpr:=false;
  1076. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1077. begin
  1078. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1079. case target_info.abi of
  1080. abi_powerpc_aix:
  1081. firstfpureg := RS_F14;
  1082. abi_powerpc_sysv:
  1083. firstfpureg := RS_F9;
  1084. else
  1085. internalerror(2003122903);
  1086. end;
  1087. for regcounter:=firstfpureg to RS_F31 do
  1088. begin
  1089. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1090. begin
  1091. usesfpr:=true;
  1092. firstregfpu:=regcounter;
  1093. break;
  1094. end;
  1095. end;
  1096. end;
  1097. usesgpr:=false;
  1098. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1099. for regcounter2:=RS_R13 to RS_R31 do
  1100. begin
  1101. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1102. begin
  1103. usesgpr:=true;
  1104. firstreggpr:=regcounter2;
  1105. break;
  1106. end;
  1107. end;
  1108. offset:= 0;
  1109. { save floating-point registers }
  1110. if usesfpr then
  1111. for regcounter := firstregfpu to RS_F31 do
  1112. begin
  1113. offset:= offset - 8;
  1114. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1115. list.concat(taicpu.op_reg_ref(A_STFD, tregister(regcounter), href));
  1116. end;
  1117. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1118. { save gprs in gpr save area }
  1119. if usesgpr then
  1120. if firstreggpr < RS_R30 then
  1121. begin
  1122. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1123. reference_reset_base(href,NR_STACK_POINTER_REG,offset);
  1124. list.concat(taicpu.op_reg_ref(A_STMW,tregister(firstreggpr),href));
  1125. {STMW stores multiple registers}
  1126. end
  1127. else
  1128. begin
  1129. for regcounter := firstreggpr to RS_R31 do
  1130. begin
  1131. offset:= offset - 4;
  1132. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1133. list.concat(taicpu.op_reg_ref(A_STW, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1134. end;
  1135. end;
  1136. { now comes the AltiVec context save, not yet implemented !!! }
  1137. save_regs:= -offset;
  1138. end;
  1139. procedure tcgppc.restore_regs(list : TAsmList);
  1140. {Generates code which restores used non-volatile registers from
  1141. the save area right below the address the stackpointer point to.}
  1142. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1143. usesfpr,usesgpr: boolean;
  1144. href : treference;
  1145. offset: integer;
  1146. regcounter2, firstfpureg: Tsuperregister;
  1147. begin
  1148. usesfpr:=false;
  1149. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1150. begin
  1151. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1152. case target_info.abi of
  1153. abi_powerpc_aix:
  1154. firstfpureg := RS_F14;
  1155. abi_powerpc_sysv:
  1156. firstfpureg := RS_F9;
  1157. else
  1158. internalerror(2003122903);
  1159. end;
  1160. for regcounter:=firstfpureg to RS_F31 do
  1161. begin
  1162. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1163. begin
  1164. usesfpr:=true;
  1165. firstregfpu:=regcounter;
  1166. break;
  1167. end;
  1168. end;
  1169. end;
  1170. usesgpr:=false;
  1171. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1172. for regcounter2:=RS_R13 to RS_R31 do
  1173. begin
  1174. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1175. begin
  1176. usesgpr:=true;
  1177. firstreggpr:=regcounter2;
  1178. break;
  1179. end;
  1180. end;
  1181. offset:= 0;
  1182. { restore fp registers }
  1183. if usesfpr then
  1184. for regcounter := firstregfpu to RS_F31 do
  1185. begin
  1186. offset:= offset - 8;
  1187. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1188. list.concat(taicpu.op_reg_ref(A_LFD, newreg(R_FPUREGISTER,regcounter,R_SUBWHOLE), href));
  1189. end;
  1190. (* Optimiztion in the future: a_call_name(list,'_restfXX'); *)
  1191. { restore gprs }
  1192. if usesgpr then
  1193. if firstreggpr < RS_R30 then
  1194. begin
  1195. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1196. reference_reset_base(href,NR_STACK_POINTER_REG,offset); //-220
  1197. list.concat(taicpu.op_reg_ref(A_LMW,tregister(firstreggpr),href));
  1198. {LMW loads multiple registers}
  1199. end
  1200. else
  1201. begin
  1202. for regcounter := firstreggpr to RS_R31 do
  1203. begin
  1204. offset:= offset - 4;
  1205. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1206. list.concat(taicpu.op_reg_ref(A_LWZ, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1207. end;
  1208. end;
  1209. { now comes the AltiVec context restore, not yet implemented !!! }
  1210. end;
  1211. procedure tcgppc.g_stackframe_entry_mac(list : TAsmList;localsize : longint);
  1212. (* NOT IN USE *)
  1213. { generated the entry code of a procedure/function. Note: localsize is the }
  1214. { sum of the size necessary for local variables and the maximum possible }
  1215. { combined size of ALL the parameters of a procedure called by the current }
  1216. { one }
  1217. const
  1218. macosLinkageAreaSize = 24;
  1219. var
  1220. href : treference;
  1221. registerSaveAreaSize : longint;
  1222. begin
  1223. if (localsize mod 8) <> 0 then
  1224. internalerror(58991);
  1225. { CR and LR only have to be saved in case they are modified by the current }
  1226. { procedure, but currently this isn't checked, so save them always }
  1227. { following is the entry code as described in "Altivec Programming }
  1228. { Interface Manual", bar the saving of AltiVec registers }
  1229. a_reg_alloc(list,NR_STACK_POINTER_REG);
  1230. a_reg_alloc(list,NR_R0);
  1231. { save return address in callers frame}
  1232. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_LR));
  1233. { ... in caller's frame }
  1234. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1235. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1236. a_reg_dealloc(list,NR_R0);
  1237. { save non-volatile registers in callers frame}
  1238. registerSaveAreaSize:= save_regs(list);
  1239. { save the CR if necessary in callers frame ( !!! always done currently ) }
  1240. a_reg_alloc(list,NR_R0);
  1241. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  1242. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1243. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1244. a_reg_dealloc(list,NR_R0);
  1245. (*
  1246. { save pointer to incoming arguments }
  1247. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  1248. *)
  1249. (*
  1250. a_reg_alloc(list,R_12);
  1251. { 0 or 8 based on SP alignment }
  1252. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  1253. R_12,STACK_POINTER_REG,0,28,28));
  1254. { add in stack length }
  1255. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1256. -localsize));
  1257. { establish new alignment }
  1258. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1259. a_reg_dealloc(list,R_12);
  1260. *)
  1261. { allocate stack frame }
  1262. localsize:= align(localsize + macosLinkageAreaSize + registerSaveAreaSize, 16);
  1263. inc(localsize,tg.lasttemp);
  1264. localsize:=align(localsize,16);
  1265. //tppcprocinfo(current_procinfo).localsize:=localsize;
  1266. if (localsize <> 0) then
  1267. begin
  1268. if (localsize <= high(smallint)) then
  1269. begin
  1270. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  1271. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  1272. end
  1273. else
  1274. begin
  1275. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1276. href.index := NR_R11;
  1277. a_reg_alloc(list,href.index);
  1278. a_load_const_reg(list,OS_S32,-localsize,href.index);
  1279. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  1280. a_reg_dealloc(list,href.index);
  1281. end;
  1282. end;
  1283. end;
  1284. procedure tcgppc.g_return_from_proc_mac(list : TAsmList;parasize : aint);
  1285. (* NOT IN USE *)
  1286. var
  1287. href : treference;
  1288. begin
  1289. a_reg_alloc(list,NR_R0);
  1290. { restore stack pointer }
  1291. reference_reset_base(href,NR_STACK_POINTER_REG,LA_SP);
  1292. list.concat(taicpu.op_reg_ref(A_LWZ,NR_STACK_POINTER_REG,href));
  1293. (*
  1294. list.concat(taicpu.op_reg_reg_const(A_ORI,NR_STACK_POINTER_REG,R_31,0));
  1295. *)
  1296. { restore the CR if necessary from callers frame
  1297. ( !!! always done currently ) }
  1298. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1299. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1300. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1301. a_reg_dealloc(list,NR_R0);
  1302. (*
  1303. { restore return address from callers frame }
  1304. reference_reset_base(href,STACK_POINTER_REG,8);
  1305. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1306. *)
  1307. { restore non-volatile registers from callers frame }
  1308. restore_regs(list);
  1309. (*
  1310. { return to caller }
  1311. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1312. list.concat(taicpu.op_none(A_BLR));
  1313. *)
  1314. { restore return address from callers frame }
  1315. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1316. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1317. { return to caller }
  1318. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_LR));
  1319. list.concat(taicpu.op_none(A_BLR));
  1320. end;
  1321. procedure tcgppc.a_loadaddr_ref_reg(list : TAsmList;const ref : treference;r : tregister);
  1322. var
  1323. ref2, tmpref: treference;
  1324. begin
  1325. ref2 := ref;
  1326. fixref(list,ref2);
  1327. if assigned(ref2.symbol) then
  1328. begin
  1329. if target_info.system = system_powerpc_macos then
  1330. begin
  1331. if macos_direct_globals then
  1332. begin
  1333. reference_reset(tmpref);
  1334. tmpref.offset := ref2.offset;
  1335. tmpref.symbol := ref2.symbol;
  1336. tmpref.base := NR_NO;
  1337. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,NR_RTOC,tmpref));
  1338. end
  1339. else
  1340. begin
  1341. reference_reset(tmpref);
  1342. tmpref.symbol := ref2.symbol;
  1343. tmpref.offset := 0;
  1344. tmpref.base := NR_RTOC;
  1345. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref));
  1346. if ref2.offset <> 0 then
  1347. begin
  1348. reference_reset(tmpref);
  1349. tmpref.offset := ref2.offset;
  1350. tmpref.base:= r;
  1351. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1352. end;
  1353. end;
  1354. if ref2.base <> NR_NO then
  1355. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,r,ref2.base));
  1356. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1357. end
  1358. else
  1359. begin
  1360. { add the symbol's value to the base of the reference, and if the }
  1361. { reference doesn't have a base, create one }
  1362. reference_reset(tmpref);
  1363. tmpref.offset := ref2.offset;
  1364. tmpref.symbol := ref2.symbol;
  1365. tmpref.relsymbol := ref2.relsymbol;
  1366. tmpref.refaddr := addr_hi;
  1367. if ref2.base<> NR_NO then
  1368. begin
  1369. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1370. ref2.base,tmpref));
  1371. end
  1372. else
  1373. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1374. tmpref.base := NR_NO;
  1375. tmpref.refaddr := addr_lo;
  1376. { can be folded with one of the next instructions by the }
  1377. { optimizer probably }
  1378. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1379. end
  1380. end
  1381. else if ref2.offset <> 0 Then
  1382. if ref2.base <> NR_NO then
  1383. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  1384. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1385. { occurs, so now only ref.offset has to be loaded }
  1386. else
  1387. a_load_const_reg(list,OS_32,ref2.offset,r)
  1388. else if ref2.index <> NR_NO Then
  1389. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1390. else if (ref2.base <> NR_NO) and
  1391. (r <> ref2.base) then
  1392. a_load_reg_reg(list,OS_ADDR,OS_ADDR,ref2.base,r)
  1393. else
  1394. list.concat(taicpu.op_reg_const(A_LI,r,0));
  1395. end;
  1396. { ************* concatcopy ************ }
  1397. {$ifndef ppc603}
  1398. const
  1399. maxmoveunit = 8;
  1400. {$else ppc603}
  1401. const
  1402. maxmoveunit = 4;
  1403. {$endif ppc603}
  1404. procedure tcgppc.g_concatcopy(list : TAsmList;const source,dest : treference;len : aint);
  1405. var
  1406. countreg: TRegister;
  1407. src, dst: TReference;
  1408. lab: tasmlabel;
  1409. count, count2: aint;
  1410. size: tcgsize;
  1411. copyreg: tregister;
  1412. begin
  1413. {$ifdef extdebug}
  1414. if len > high(longint) then
  1415. internalerror(2002072704);
  1416. {$endif extdebug}
  1417. if (references_equal(source,dest)) then
  1418. exit;
  1419. { make sure short loads are handled as optimally as possible }
  1420. if (len <= maxmoveunit) and
  1421. (byte(len) in [1,2,4,8]) then
  1422. begin
  1423. if len < 8 then
  1424. begin
  1425. size := int_cgsize(len);
  1426. a_load_ref_ref(list,size,size,source,dest);
  1427. end
  1428. else
  1429. begin
  1430. copyreg := getfpuregister(list,OS_F64);
  1431. a_loadfpu_ref_reg(list,OS_F64,OS_F64,source,copyreg);
  1432. a_loadfpu_reg_ref(list,OS_F64,OS_F64,copyreg,dest);
  1433. end;
  1434. exit;
  1435. end;
  1436. count := len div maxmoveunit;
  1437. reference_reset(src);
  1438. reference_reset(dst);
  1439. { load the address of source into src.base }
  1440. if (count > 4) or
  1441. not issimpleref(source) or
  1442. ((source.index <> NR_NO) and
  1443. ((source.offset + longint(len)) > high(smallint))) then
  1444. begin
  1445. src.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1446. a_loadaddr_ref_reg(list,source,src.base);
  1447. end
  1448. else
  1449. begin
  1450. src := source;
  1451. end;
  1452. { load the address of dest into dst.base }
  1453. if (count > 4) or
  1454. not issimpleref(dest) or
  1455. ((dest.index <> NR_NO) and
  1456. ((dest.offset + longint(len)) > high(smallint))) then
  1457. begin
  1458. dst.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1459. a_loadaddr_ref_reg(list,dest,dst.base);
  1460. end
  1461. else
  1462. begin
  1463. dst := dest;
  1464. end;
  1465. {$ifndef ppc603}
  1466. if count > 4 then
  1467. { generate a loop }
  1468. begin
  1469. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1470. { have to be set to 8. I put an Inc there so debugging may be }
  1471. { easier (should offset be different from zero here, it will be }
  1472. { easy to notice in the generated assembler }
  1473. inc(dst.offset,8);
  1474. inc(src.offset,8);
  1475. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1476. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1477. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1478. a_load_const_reg(list,OS_32,count,countreg);
  1479. copyreg := getfpuregister(list,OS_F64);
  1480. a_reg_sync(list,copyreg);
  1481. current_asmdata.getjumplabel(lab);
  1482. a_label(list, lab);
  1483. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1484. list.concat(taicpu.op_reg_ref(A_LFDU,copyreg,src));
  1485. list.concat(taicpu.op_reg_ref(A_STFDU,copyreg,dst));
  1486. a_jmp(list,A_BC,C_NE,0,lab);
  1487. a_reg_sync(list,copyreg);
  1488. len := len mod 8;
  1489. end;
  1490. count := len div 8;
  1491. if count > 0 then
  1492. { unrolled loop }
  1493. begin
  1494. copyreg := getfpuregister(list,OS_F64);
  1495. for count2 := 1 to count do
  1496. begin
  1497. a_loadfpu_ref_reg(list,OS_F64,OS_F64,src,copyreg);
  1498. a_loadfpu_reg_ref(list,OS_F64,OS_F64,copyreg,dst);
  1499. inc(src.offset,8);
  1500. inc(dst.offset,8);
  1501. end;
  1502. len := len mod 8;
  1503. end;
  1504. if (len and 4) <> 0 then
  1505. begin
  1506. a_reg_alloc(list,NR_R0);
  1507. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1508. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1509. inc(src.offset,4);
  1510. inc(dst.offset,4);
  1511. a_reg_dealloc(list,NR_R0);
  1512. end;
  1513. {$else not ppc603}
  1514. if count > 4 then
  1515. { generate a loop }
  1516. begin
  1517. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1518. { have to be set to 4. I put an Inc there so debugging may be }
  1519. { easier (should offset be different from zero here, it will be }
  1520. { easy to notice in the generated assembler }
  1521. inc(dst.offset,4);
  1522. inc(src.offset,4);
  1523. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,4));
  1524. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,4));
  1525. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1526. a_load_const_reg(list,OS_32,count,countreg);
  1527. { explicitely allocate R_0 since it can be used safely here }
  1528. { (for holding date that's being copied) }
  1529. a_reg_alloc(list,NR_R0);
  1530. current_asmdata.getjumplabel(lab);
  1531. a_label(list, lab);
  1532. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1533. list.concat(taicpu.op_reg_ref(A_LWZU,NR_R0,src));
  1534. list.concat(taicpu.op_reg_ref(A_STWU,NR_R0,dst));
  1535. a_jmp(list,A_BC,C_NE,0,lab);
  1536. a_reg_dealloc(list,NR_R0);
  1537. len := len mod 4;
  1538. end;
  1539. count := len div 4;
  1540. if count > 0 then
  1541. { unrolled loop }
  1542. begin
  1543. a_reg_alloc(list,NR_R0);
  1544. for count2 := 1 to count do
  1545. begin
  1546. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1547. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1548. inc(src.offset,4);
  1549. inc(dst.offset,4);
  1550. end;
  1551. a_reg_dealloc(list,NR_R0);
  1552. len := len mod 4;
  1553. end;
  1554. {$endif not ppc603}
  1555. { copy the leftovers }
  1556. if (len and 2) <> 0 then
  1557. begin
  1558. a_reg_alloc(list,NR_R0);
  1559. a_load_ref_reg(list,OS_16,OS_16,src,NR_R0);
  1560. a_load_reg_ref(list,OS_16,OS_16,NR_R0,dst);
  1561. inc(src.offset,2);
  1562. inc(dst.offset,2);
  1563. a_reg_dealloc(list,NR_R0);
  1564. end;
  1565. if (len and 1) <> 0 then
  1566. begin
  1567. a_reg_alloc(list,NR_R0);
  1568. a_load_ref_reg(list,OS_8,OS_8,src,NR_R0);
  1569. a_load_reg_ref(list,OS_8,OS_8,NR_R0,dst);
  1570. a_reg_dealloc(list,NR_R0);
  1571. end;
  1572. end;
  1573. procedure tcgppc.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  1574. procedure loadvmttor11;
  1575. var
  1576. href : treference;
  1577. begin
  1578. reference_reset_base(href,NR_R3,0);
  1579. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_R11);
  1580. end;
  1581. procedure op_onr11methodaddr;
  1582. var
  1583. href : treference;
  1584. begin
  1585. if (procdef.extnumber=$ffff) then
  1586. Internalerror(200006139);
  1587. { call/jmp vmtoffs(%eax) ; method offs }
  1588. reference_reset_base(href,NR_R11,procdef._class.vmtmethodoffset(procdef.extnumber));
  1589. if not((longint(href.offset) >= low(smallint)) and
  1590. (longint(href.offset) <= high(smallint))) then
  1591. begin
  1592. list.concat(taicpu.op_reg_reg_const(A_ADDIS,NR_R11,NR_R11,
  1593. smallint((href.offset shr 16)+ord(smallint(href.offset and $ffff) < 0))));
  1594. href.offset := smallint(href.offset and $ffff);
  1595. end;
  1596. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R11,href));
  1597. list.concat(taicpu.op_reg(A_MTCTR,NR_R11));
  1598. list.concat(taicpu.op_none(A_BCTR));
  1599. end;
  1600. var
  1601. make_global : boolean;
  1602. begin
  1603. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  1604. Internalerror(200006137);
  1605. if not assigned(procdef._class) or
  1606. (procdef.procoptions*[po_classmethod, po_staticmethod,
  1607. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  1608. Internalerror(200006138);
  1609. if procdef.owner.symtabletype<>ObjectSymtable then
  1610. Internalerror(200109191);
  1611. make_global:=false;
  1612. if (not current_module.is_unit) or
  1613. (cs_create_smart in current_settings.moduleswitches) or
  1614. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  1615. make_global:=true;
  1616. if make_global then
  1617. List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0))
  1618. else
  1619. List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0));
  1620. { set param1 interface to self }
  1621. g_adjust_self_value(list,procdef,ioffset);
  1622. { case 4 }
  1623. if po_virtualmethod in procdef.procoptions then
  1624. begin
  1625. loadvmttor11;
  1626. op_onr11methodaddr;
  1627. end
  1628. { case 0 }
  1629. else
  1630. if not(target_info.system = system_powerpc_darwin) then
  1631. list.concat(taicpu.op_sym(A_B,current_asmdata.RefAsmSymbol(procdef.mangledname)))
  1632. else
  1633. list.concat(taicpu.op_sym(A_B,get_darwin_call_stub(procdef.mangledname)));
  1634. List.concat(Tai_symbol_end.Createname(labelname));
  1635. end;
  1636. {***************** This is private property, keep out! :) *****************}
  1637. function tcgppc.issimpleref(const ref: treference): boolean;
  1638. begin
  1639. if (ref.base = NR_NO) and
  1640. (ref.index <> NR_NO) then
  1641. internalerror(200208101);
  1642. result :=
  1643. not(assigned(ref.symbol)) and
  1644. (((ref.index = NR_NO) and
  1645. (ref.offset >= low(smallint)) and
  1646. (ref.offset <= high(smallint))) or
  1647. ((ref.index <> NR_NO) and
  1648. (ref.offset = 0)));
  1649. end;
  1650. function tcgppc.fixref(list: TAsmList; var ref: treference): boolean;
  1651. var
  1652. tmpreg: tregister;
  1653. begin
  1654. result := false;
  1655. if (target_info.system = system_powerpc_darwin) and
  1656. assigned(ref.symbol) and
  1657. (ref.symbol.bind = AB_EXTERNAL) then
  1658. begin
  1659. tmpreg := g_indirect_sym_load(list,ref.symbol.name);
  1660. if (ref.base = NR_NO) then
  1661. ref.base := tmpreg
  1662. else if (ref.index = NR_NO) then
  1663. ref.index := tmpreg
  1664. else
  1665. begin
  1666. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,ref.base,tmpreg));
  1667. ref.base := tmpreg;
  1668. end;
  1669. ref.symbol := nil;
  1670. end;
  1671. if (ref.base = NR_NO) then
  1672. begin
  1673. ref.base := ref.index;
  1674. ref.index := NR_NO;
  1675. end;
  1676. if (ref.base <> NR_NO) then
  1677. begin
  1678. if (ref.index <> NR_NO) and
  1679. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1680. begin
  1681. result := true;
  1682. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1683. list.concat(taicpu.op_reg_reg_reg(
  1684. A_ADD,tmpreg,ref.base,ref.index));
  1685. ref.index := NR_NO;
  1686. ref.base := tmpreg;
  1687. end
  1688. end
  1689. else
  1690. if ref.index <> NR_NO then
  1691. internalerror(200208102);
  1692. end;
  1693. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1694. { that's the case, we can use rlwinm to do an AND operation }
  1695. function tcgppc.get_rlwi_const(a: aint; var l1, l2: longint): boolean;
  1696. var
  1697. temp : longint;
  1698. testbit : aint;
  1699. compare: boolean;
  1700. begin
  1701. get_rlwi_const := false;
  1702. if (a = 0) or (a = -1) then
  1703. exit;
  1704. { start with the lowest bit }
  1705. testbit := 1;
  1706. { check its value }
  1707. compare := boolean(a and testbit);
  1708. { find out how long the run of bits with this value is }
  1709. { (it's impossible that all bits are 1 or 0, because in that case }
  1710. { this function wouldn't have been called) }
  1711. l1 := 31;
  1712. while (((a and testbit) <> 0) = compare) do
  1713. begin
  1714. testbit := testbit shl 1;
  1715. dec(l1);
  1716. end;
  1717. { check the length of the run of bits that comes next }
  1718. compare := not compare;
  1719. l2 := l1;
  1720. while (((a and testbit) <> 0) = compare) and
  1721. (l2 >= 0) do
  1722. begin
  1723. testbit := testbit shl 1;
  1724. dec(l2);
  1725. end;
  1726. { and finally the check whether the rest of the bits all have the }
  1727. { same value }
  1728. compare := not compare;
  1729. temp := l2;
  1730. if temp >= 0 then
  1731. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1732. exit;
  1733. { we have done "not(not(compare))", so compare is back to its }
  1734. { initial value. If the lowest bit was 0, a is of the form }
  1735. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1736. { because l2 now contains the position of the last zero of the }
  1737. { first run instead of that of the first 1) so switch l1 and l2 }
  1738. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1739. if not compare then
  1740. begin
  1741. temp := l1;
  1742. l1 := l2+1;
  1743. l2 := temp;
  1744. end
  1745. else
  1746. { otherwise, l1 currently contains the position of the last }
  1747. { zero instead of that of the first 1 of the second run -> +1 }
  1748. inc(l1);
  1749. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1750. l1 := l1 and 31;
  1751. l2 := l2 and 31;
  1752. get_rlwi_const := true;
  1753. end;
  1754. procedure tcgppc.a_load_store(list:TAsmList;op: tasmop;reg:tregister;
  1755. ref: treference);
  1756. var
  1757. tmpreg: tregister;
  1758. tmpref: treference;
  1759. largeOffset: Boolean;
  1760. begin
  1761. tmpreg := NR_NO;
  1762. if target_info.system = system_powerpc_macos then
  1763. begin
  1764. largeOffset:= (cardinal(ref.offset-low(smallint)) >
  1765. high(smallint)-low(smallint));
  1766. if assigned(ref.symbol) then
  1767. begin {Load symbol's value}
  1768. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1769. reference_reset(tmpref);
  1770. tmpref.symbol := ref.symbol;
  1771. tmpref.base := NR_RTOC;
  1772. if macos_direct_globals then
  1773. list.concat(taicpu.op_reg_ref(A_LA,tmpreg,tmpref))
  1774. else
  1775. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1776. end;
  1777. if largeOffset then
  1778. begin {Add hi part of offset}
  1779. reference_reset(tmpref);
  1780. if Smallint(Lo(ref.offset)) < 0 then
  1781. tmpref.offset := Hi(ref.offset) + 1 {Compensate when lo part is negative}
  1782. else
  1783. tmpref.offset := Hi(ref.offset);
  1784. if (tmpreg <> NR_NO) then
  1785. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg, tmpreg,tmpref))
  1786. else
  1787. begin
  1788. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1789. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1790. end;
  1791. end;
  1792. if (tmpreg <> NR_NO) then
  1793. begin
  1794. {Add content of base register}
  1795. if ref.base <> NR_NO then
  1796. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1797. ref.base,tmpreg));
  1798. {Make ref ready to be used by op}
  1799. ref.symbol:= nil;
  1800. ref.base:= tmpreg;
  1801. if largeOffset then
  1802. ref.offset := Smallint(Lo(ref.offset));
  1803. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1804. //list.concat(tai_comment.create(strpnew('*** a_load_store indirect global')));
  1805. end
  1806. else
  1807. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1808. end
  1809. else {if target_info.system <> system_powerpc_macos}
  1810. begin
  1811. if assigned(ref.symbol) or
  1812. (cardinal(ref.offset-low(smallint)) >
  1813. high(smallint)-low(smallint)) then
  1814. begin
  1815. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1816. reference_reset(tmpref);
  1817. tmpref.symbol := ref.symbol;
  1818. tmpref.relsymbol := ref.relsymbol;
  1819. tmpref.offset := ref.offset;
  1820. tmpref.refaddr := addr_hi;
  1821. if ref.base <> NR_NO then
  1822. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1823. ref.base,tmpref))
  1824. else
  1825. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1826. ref.base := tmpreg;
  1827. ref.refaddr := addr_lo;
  1828. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1829. end
  1830. else
  1831. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1832. end;
  1833. end;
  1834. procedure tcg64fppc.a_op64_reg_reg(list : TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);
  1835. begin
  1836. a_op64_reg_reg_reg(list,op,size,regsrc,regdst,regdst);
  1837. end;
  1838. procedure tcg64fppc.a_op64_const_reg(list : TAsmList;op:TOpCG;size : tcgsize;value : int64;reg : tregister64);
  1839. begin
  1840. a_op64_const_reg_reg(list,op,size,value,reg,reg);
  1841. end;
  1842. procedure tcg64fppc.a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1843. begin
  1844. case op of
  1845. OP_AND,OP_OR,OP_XOR:
  1846. begin
  1847. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1848. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1849. end;
  1850. OP_ADD:
  1851. begin
  1852. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1853. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1854. end;
  1855. OP_SUB:
  1856. begin
  1857. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1858. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1859. end;
  1860. else
  1861. internalerror(2002072801);
  1862. end;
  1863. end;
  1864. procedure tcg64fppc.a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);
  1865. const
  1866. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1867. (A_SUBIC,A_SUBC,A_ADDME));
  1868. var
  1869. tmpreg: tregister;
  1870. tmpreg64: tregister64;
  1871. issub: boolean;
  1872. begin
  1873. case op of
  1874. OP_AND,OP_OR,OP_XOR:
  1875. begin
  1876. cg.a_op_const_reg_reg(list,op,OS_32,aint(value),regsrc.reglo,regdst.reglo);
  1877. cg.a_op_const_reg_reg(list,op,OS_32,aint(value shr 32),regsrc.reghi,
  1878. regdst.reghi);
  1879. end;
  1880. OP_ADD, OP_SUB:
  1881. begin
  1882. if (value < 0) and
  1883. (value <> low(value)) then
  1884. begin
  1885. if op = OP_ADD then
  1886. op := OP_SUB
  1887. else
  1888. op := OP_ADD;
  1889. value := -value;
  1890. end;
  1891. if (longint(value) <> 0) then
  1892. begin
  1893. issub := op = OP_SUB;
  1894. if (value > 0) and
  1895. (value-ord(issub) <= 32767) then
  1896. begin
  1897. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1898. regdst.reglo,regsrc.reglo,longint(value)));
  1899. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1900. regdst.reghi,regsrc.reghi));
  1901. end
  1902. else if ((value shr 32) = 0) then
  1903. begin
  1904. tmpreg := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1905. cg.a_load_const_reg(list,OS_32,aint(value),tmpreg);
  1906. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  1907. regdst.reglo,regsrc.reglo,tmpreg));
  1908. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1909. regdst.reghi,regsrc.reghi));
  1910. end
  1911. else
  1912. begin
  1913. tmpreg64.reglo := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1914. tmpreg64.reghi := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1915. a_load64_const_reg(list,value,tmpreg64);
  1916. a_op64_reg_reg_reg(list,op,size,tmpreg64,regsrc,regdst);
  1917. end
  1918. end
  1919. else
  1920. begin
  1921. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  1922. cg.a_op_const_reg_reg(list,op,OS_32,aint(value shr 32),regsrc.reghi,
  1923. regdst.reghi);
  1924. end;
  1925. end;
  1926. else
  1927. internalerror(2002072802);
  1928. end;
  1929. end;
  1930. begin
  1931. cg := tcgppc.create;
  1932. cg64 :=tcg64fppc.create;
  1933. end.