cgcpu.pas 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the code generator for the PowerPC
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cgbase,cgobj,
  23. aasmbase,aasmcpu,aasmtai,
  24. cpubase,cpuinfo,node,cg64f32,cginfo;
  25. type
  26. tcgppc = class(tcg)
  27. { passing parameters, per default the parameter is pushed }
  28. { nr gives the number of the parameter (enumerated from }
  29. { left to right), this allows to move the parameter to }
  30. { register, if the cpu supports register calling }
  31. { conventions }
  32. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);override;
  33. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);override;
  34. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);override;
  35. procedure a_call_name(list : taasmoutput;const s : string);override;
  36. procedure a_call_reg(list : taasmoutput;reg: tregister); override;
  37. procedure a_call_ref(list : taasmoutput;const ref : treference);override;
  38. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister); override;
  39. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  40. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  41. size: tcgsize; a: aword; src, dst: tregister); override;
  42. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  43. size: tcgsize; src1, src2, dst: tregister); override;
  44. { move instructions }
  45. procedure a_load_const_reg(list : taasmoutput; size: tcgsize; a : aword;reg : tregister);override;
  46. procedure a_load_reg_ref(list : taasmoutput; size: tcgsize; reg : tregister;const ref : treference);override;
  47. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const Ref : treference;reg : tregister);override;
  48. procedure a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);override;
  49. { fpu move instructions }
  50. procedure a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister); override;
  51. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  52. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  53. { comparison operations }
  54. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  55. l : tasmlabel);override;
  56. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  57. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  58. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  59. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister); override;
  60. procedure g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  61. procedure g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  62. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  63. procedure g_restore_frame_pointer(list : taasmoutput);override;
  64. procedure g_return_from_proc(list : taasmoutput;parasize : aword); override;
  65. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  66. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  67. procedure g_overflowcheck(list: taasmoutput; const p: tnode); override;
  68. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  69. { that's the case, we can use rlwinm to do an AND operation }
  70. function get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  71. procedure g_save_standard_registers(list : taasmoutput; usedinproc : tregisterset);override;
  72. procedure g_restore_standard_registers(list : taasmoutput; usedinproc : tregisterset);override;
  73. procedure g_save_all_registers(list : taasmoutput);override;
  74. procedure g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);override;
  75. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  76. private
  77. procedure g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  78. procedure g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  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: taasmoutput; var ref: treference): boolean;
  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:taasmoutput;op: tasmop;reg:tregister;
  91. ref: treference);
  92. { creates the correct branch instruction for a given combination }
  93. { of asmcondflags and destination addressing mode }
  94. procedure a_jmp(list: taasmoutput; op: tasmop;
  95. c: tasmcondflag; crval: longint; l: tasmlabel);
  96. end;
  97. tcg64fppc = class(tcg64f32)
  98. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);override;
  99. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);override;
  100. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);override;
  101. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);override;
  102. end;
  103. const
  104. TOpCG2AsmOpConstLo: Array[topcg] of TAsmOp = (A_NONE,A_ADDI,A_ANDI_,A_DIVWU,
  105. A_DIVW,A_MULLW, A_MULLW, A_NONE,A_NONE,A_ORI,
  106. A_SRAWI,A_SLWI,A_SRWI,A_SUBI,A_XORI);
  107. TOpCG2AsmOpConstHi: Array[topcg] of TAsmOp = (A_NONE,A_ADDIS,A_ANDIS_,
  108. A_DIVWU,A_DIVW, A_MULLW,A_MULLW,A_NONE,A_NONE,
  109. A_ORIS,A_NONE, A_NONE,A_NONE,A_SUBIS,A_XORIS);
  110. TOpCmp2AsmCond: Array[topcmp] of TAsmCondFlag = (C_NONE,C_EQ,C_GT,
  111. C_LT,C_GE,C_LE,C_NE,C_LE,C_LT,C_GE,C_GT);
  112. implementation
  113. uses
  114. globtype,globals,verbose,systems,cutils,symconst,symdef,rgobj,tgobj,cpupi;
  115. { parameter passing... Still needs extra support from the processor }
  116. { independent code generator }
  117. procedure tcgppc.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  118. var
  119. ref: treference;
  120. begin
  121. case locpara.loc of
  122. LOC_REGISTER,LOC_CREGISTER:
  123. a_load_const_reg(list,size,a,locpara.register);
  124. LOC_REFERENCE:
  125. begin
  126. reference_reset(ref);
  127. ref.base:=locpara.reference.index;
  128. ref.offset:=locpara.reference.offset;
  129. a_load_const_ref(list,size,a,ref);
  130. end;
  131. else
  132. internalerror(2002081101);
  133. end;
  134. if locpara.sp_fixup<>0 then
  135. internalerror(2002081102);
  136. end;
  137. procedure tcgppc.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  138. var
  139. ref: treference;
  140. tmpreg: tregister;
  141. begin
  142. case locpara.loc of
  143. LOC_REGISTER,LOC_CREGISTER:
  144. a_load_ref_reg(list,size,r,locpara.register);
  145. LOC_REFERENCE:
  146. begin
  147. reference_reset(ref);
  148. ref.base:=locpara.reference.index;
  149. ref.offset:=locpara.reference.offset;
  150. tmpreg := get_scratch_reg_int(list);
  151. a_load_ref_reg(list,size,r,tmpreg);
  152. a_load_reg_ref(list,size,tmpreg,ref);
  153. free_scratch_reg(list,tmpreg);
  154. end;
  155. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  156. case size of
  157. OS_32:
  158. a_loadfpu_ref_reg(list,OS_F32,r,locpara.register);
  159. OS_64:
  160. a_loadfpu_ref_reg(list,OS_F64,r,locpara.register);
  161. else
  162. internalerror(2002072801);
  163. end;
  164. else
  165. internalerror(2002081103);
  166. end;
  167. if locpara.sp_fixup<>0 then
  168. internalerror(2002081104);
  169. end;
  170. procedure tcgppc.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  171. var
  172. ref: treference;
  173. tmpreg: tregister;
  174. begin
  175. case locpara.loc of
  176. LOC_REGISTER,LOC_CREGISTER:
  177. a_loadaddr_ref_reg(list,r,locpara.register);
  178. LOC_REFERENCE:
  179. begin
  180. reference_reset(ref);
  181. ref.base := locpara.reference.index;
  182. ref.offset := locpara.reference.offset;
  183. tmpreg := get_scratch_reg_address(list);
  184. a_loadaddr_ref_reg(list,r,tmpreg);
  185. a_load_reg_ref(list,OS_ADDR,tmpreg,ref);
  186. free_scratch_reg(list,tmpreg);
  187. end;
  188. else
  189. internalerror(2002080701);
  190. end;
  191. end;
  192. { calling a code fragment by name }
  193. procedure tcgppc.a_call_name(list : taasmoutput;const s : string);
  194. var
  195. href : treference;
  196. begin
  197. list.concat(taicpu.op_sym(A_BL,objectlibrary.newasmsymbol(s)));
  198. if target_info.system=system_powerpc_macos then
  199. list.concat(taicpu.op_none(A_NOP));
  200. procinfo.flags:=procinfo.flags or pi_do_call;
  201. end;
  202. procedure tcgppc.a_call_reg(list : taasmoutput;reg: tregister);
  203. begin
  204. list.concat(taicpu.op_reg(A_MTCTR,reg));
  205. list.concat(taicpu.op_none(A_BCCTRL));
  206. if target_info.system=system_powerpc_macos then
  207. list.concat(taicpu.op_none(A_NOP));
  208. procinfo.flags:=procinfo.flags or pi_do_call;
  209. end;
  210. { calling a code fragment through a reference }
  211. procedure tcgppc.a_call_ref(list : taasmoutput;const ref : treference);
  212. var
  213. tmpreg : tregister;
  214. begin
  215. tmpreg := get_scratch_reg_int(list);
  216. a_load_ref_reg(list,OS_ADDR,ref,tmpreg);
  217. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  218. free_scratch_reg(list,tmpreg);
  219. list.concat(taicpu.op_none(A_BCCTRL));
  220. if target_info.system=system_powerpc_macos then
  221. list.concat(taicpu.op_none(A_NOP));
  222. procinfo.flags:=procinfo.flags or pi_do_call;
  223. end;
  224. {********************** load instructions ********************}
  225. procedure tcgppc.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  226. begin
  227. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  228. internalerror(2002090902);
  229. if (longint(a) >= low(smallint)) and
  230. (longint(a) <= high(smallint)) then
  231. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a)))
  232. else if ((a and $ffff) <> 0) then
  233. begin
  234. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a and $ffff)));
  235. if ((a shr 16) <> 0) or
  236. (smallint(a and $ffff) < 0) then
  237. list.concat(taicpu.op_reg_reg_const(A_ADDIS,reg,reg,
  238. smallint((a shr 16)+ord(smallint(a and $ffff) < 0))))
  239. end
  240. else
  241. list.concat(taicpu.op_reg_const(A_LIS,reg,smallint(a shr 16)));
  242. end;
  243. procedure tcgppc.a_load_reg_ref(list : taasmoutput; size: TCGSize; reg : tregister;const ref : treference);
  244. const
  245. StoreInstr: Array[OS_8..OS_32,boolean, boolean] of TAsmOp =
  246. { indexed? updating?}
  247. (((A_STB,A_STBU),(A_STBX,A_STBUX)),
  248. ((A_STH,A_STHU),(A_STHX,A_STHUX)),
  249. ((A_STW,A_STWU),(A_STWX,A_STWUX)));
  250. var
  251. op: TAsmOp;
  252. ref2: TReference;
  253. freereg: boolean;
  254. begin
  255. ref2 := ref;
  256. freereg := fixref(list,ref2);
  257. if size in [OS_S8..OS_S16] then
  258. { storing is the same for signed and unsigned values }
  259. size := tcgsize(ord(size)-(ord(OS_S8)-ord(OS_8)));
  260. { 64 bit stuff should be handled separately }
  261. if size in [OS_64,OS_S64] then
  262. internalerror(200109236);
  263. op := storeinstr[tcgsize2unsigned[size],ref2.index<>R_NO,false];
  264. a_load_store(list,op,reg,ref2);
  265. if freereg then
  266. cg.free_scratch_reg(list,ref2.base);
  267. End;
  268. procedure tcgppc.a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref: treference;reg : tregister);
  269. const
  270. LoadInstr: Array[OS_8..OS_S32,boolean, boolean] of TAsmOp =
  271. { indexed? updating?}
  272. (((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  273. ((A_LHZ,A_LHZU),(A_LHZX,A_LHZUX)),
  274. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)),
  275. { 64bit stuff should be handled separately }
  276. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  277. { there's no load-byte-with-sign-extend :( }
  278. ((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  279. ((A_LHA,A_LHAU),(A_LHAX,A_LHAUX)),
  280. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)));
  281. var
  282. op: tasmop;
  283. tmpreg: tregister;
  284. ref2, tmpref: treference;
  285. freereg: boolean;
  286. begin
  287. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  288. internalerror(2002090902);
  289. ref2 := ref;
  290. freereg := fixref(list,ref2);
  291. op := loadinstr[size,ref2.index<>R_NO,false];
  292. a_load_store(list,op,reg,ref2);
  293. if freereg then
  294. free_scratch_reg(list,ref2.base);
  295. { sign extend shortint if necessary, since there is no }
  296. { load instruction that does that automatically (JM) }
  297. if size = OS_S8 then
  298. list.concat(taicpu.op_reg_reg(A_EXTSB,reg,reg));
  299. end;
  300. procedure tcgppc.a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  301. begin
  302. if (reg1 <> reg2) or
  303. (tcgsize2size[tosize] < tcgsize2size[fromsize]) or
  304. ((tcgsize2size[tosize] = tcgsize2size[fromsize]) and
  305. (tosize <> fromsize) and
  306. not(fromsize in [OS_32,OS_S32])) then
  307. begin
  308. case fromsize of
  309. OS_8:
  310. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  311. reg2,reg1,0,31-8+1,31));
  312. OS_S8:
  313. list.concat(taicpu.op_reg_reg(A_EXTSB,reg2,reg1));
  314. OS_16:
  315. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  316. reg2,reg1,0,31-16+1,31));
  317. OS_S16:
  318. list.concat(taicpu.op_reg_reg(A_EXTSH,reg2,reg1));
  319. OS_32,OS_S32:
  320. list.concat(taicpu.op_reg_reg(A_MR,reg2,reg1));
  321. else internalerror(2002090901);
  322. end;
  323. end;
  324. end;
  325. procedure tcgppc.a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  326. begin
  327. list.concat(taicpu.op_reg_reg(A_FMR,reg2,reg1));
  328. end;
  329. procedure tcgppc.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  330. const
  331. FpuLoadInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  332. { indexed? updating?}
  333. (((A_LFS,A_LFSU),(A_LFSX,A_LFSUX)),
  334. ((A_LFD,A_LFDU),(A_LFDX,A_LFDUX)));
  335. var
  336. op: tasmop;
  337. ref2: treference;
  338. freereg: boolean;
  339. begin
  340. { several functions call this procedure with OS_32 or OS_64 }
  341. { so this makes life easier (FK) }
  342. case size of
  343. OS_32,OS_F32:
  344. size:=OS_F32;
  345. OS_64,OS_F64:
  346. size:=OS_F64;
  347. else
  348. internalerror(200201121);
  349. end;
  350. ref2 := ref;
  351. freereg := fixref(list,ref2);
  352. op := fpuloadinstr[size,ref2.index <> R_NO,false];
  353. a_load_store(list,op,reg,ref2);
  354. if freereg then
  355. cg.free_scratch_reg(list,ref2.base);
  356. end;
  357. procedure tcgppc.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  358. const
  359. FpuStoreInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  360. { indexed? updating?}
  361. (((A_STFS,A_STFSU),(A_STFSX,A_STFSUX)),
  362. ((A_STFD,A_STFDU),(A_STFDX,A_STFDUX)));
  363. var
  364. op: tasmop;
  365. ref2: treference;
  366. freereg: boolean;
  367. begin
  368. if not(size in [OS_F32,OS_F64]) then
  369. internalerror(200201122);
  370. ref2 := ref;
  371. freereg := fixref(list,ref2);
  372. op := fpustoreinstr[size,ref2.index <> R_NO,false];
  373. a_load_store(list,op,reg,ref2);
  374. if freereg then
  375. cg.free_scratch_reg(list,ref2.base);
  376. end;
  377. procedure tcgppc.a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister);
  378. var
  379. scratch_register: TRegister;
  380. begin
  381. a_op_const_reg_reg(list,op,OS_32,a,reg,reg);
  382. end;
  383. procedure tcgppc.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  384. begin
  385. a_op_reg_reg_reg(list,op,OS_32,src,dst,dst);
  386. end;
  387. procedure tcgppc.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  388. size: tcgsize; a: aword; src, dst: tregister);
  389. var
  390. l1,l2: longint;
  391. oplo, ophi: tasmop;
  392. scratchreg: tregister;
  393. useReg, gotrlwi: boolean;
  394. procedure do_lo_hi;
  395. begin
  396. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  397. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  398. end;
  399. begin
  400. if op = OP_SUB then
  401. begin
  402. {$ifopt q+}
  403. {$q-}
  404. {$define overflowon}
  405. {$endif}
  406. a_op_const_reg_reg(list,OP_ADD,size,aword(-a),src,dst);
  407. {$ifdef overflowon}
  408. {$q+}
  409. {$undef overflowon}
  410. {$endif}
  411. exit;
  412. end;
  413. ophi := TOpCG2AsmOpConstHi[op];
  414. oplo := TOpCG2AsmOpConstLo[op];
  415. gotrlwi := get_rlwi_const(a,l1,l2);
  416. if (op in [OP_AND,OP_OR,OP_XOR]) then
  417. begin
  418. if (a = 0) then
  419. begin
  420. if op = OP_AND then
  421. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  422. exit;
  423. end
  424. else if (a = high(aword)) then
  425. begin
  426. case op of
  427. OP_OR:
  428. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  429. OP_XOR:
  430. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  431. end;
  432. exit;
  433. end
  434. else if (a <= high(word)) and
  435. ((op <> OP_AND) or
  436. not gotrlwi) then
  437. begin
  438. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  439. exit;
  440. end;
  441. { all basic constant instructions also have a shifted form that }
  442. { works only on the highest 16bits, so if lo(a) is 0, we can }
  443. { use that one }
  444. if (word(a) = 0) and
  445. (not(op = OP_AND) or
  446. not gotrlwi) then
  447. begin
  448. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  449. exit;
  450. end;
  451. end
  452. else if (op = OP_ADD) then
  453. if a = 0 then
  454. exit
  455. else if (longint(a) >= low(smallint)) and
  456. (longint(a) <= high(smallint)) then
  457. begin
  458. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  459. exit;
  460. end;
  461. { otherwise, the instructions we can generate depend on the }
  462. { operation }
  463. useReg := false;
  464. case op of
  465. OP_DIV,OP_IDIV:
  466. if (a = 0) then
  467. internalerror(200208103)
  468. else if (a = 1) then
  469. begin
  470. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  471. exit
  472. end
  473. else if ispowerof2(a,l1) then
  474. begin
  475. case op of
  476. OP_DIV:
  477. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  478. OP_IDIV:
  479. begin
  480. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  481. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  482. end;
  483. end;
  484. exit;
  485. end
  486. else
  487. usereg := true;
  488. OP_IMUL, OP_MUL:
  489. if (a = 0) then
  490. begin
  491. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  492. exit
  493. end
  494. else if (a = 1) then
  495. begin
  496. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  497. exit
  498. end
  499. else if ispowerof2(a,l1) then
  500. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  501. else if (longint(a) >= low(smallint)) and
  502. (longint(a) <= high(smallint)) then
  503. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  504. else
  505. usereg := true;
  506. OP_ADD:
  507. begin
  508. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  509. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  510. smallint((a shr 16) + ord(smallint(a) < 0))));
  511. end;
  512. OP_OR:
  513. { try to use rlwimi }
  514. if gotrlwi and
  515. (src = dst) then
  516. begin
  517. scratchreg := get_scratch_reg_int(list);
  518. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  519. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  520. scratchreg,0,l1,l2));
  521. free_scratch_reg(list,scratchreg);
  522. end
  523. else
  524. do_lo_hi;
  525. OP_AND:
  526. { try to use rlwinm }
  527. if gotrlwi then
  528. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  529. src,0,l1,l2))
  530. else
  531. useReg := true;
  532. OP_XOR:
  533. do_lo_hi;
  534. OP_SHL,OP_SHR,OP_SAR:
  535. begin
  536. if (a and 31) <> 0 Then
  537. list.concat(taicpu.op_reg_reg_const(
  538. TOpCG2AsmOpConstLo[Op],dst,src,a and 31));
  539. if (a shr 5) <> 0 then
  540. internalError(68991);
  541. end
  542. else
  543. internalerror(200109091);
  544. end;
  545. { if all else failed, load the constant in a register and then }
  546. { perform the operation }
  547. if useReg then
  548. begin
  549. scratchreg := get_scratch_reg_int(list);
  550. a_load_const_reg(list,OS_32,a,scratchreg);
  551. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  552. free_scratch_reg(list,scratchreg);
  553. end;
  554. end;
  555. procedure tcgppc.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  556. size: tcgsize; src1, src2, dst: tregister);
  557. const
  558. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  559. (A_NONE,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  560. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  561. begin
  562. case op of
  563. OP_NEG,OP_NOT:
  564. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,dst));
  565. else
  566. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  567. end;
  568. end;
  569. {*************** compare instructructions ****************}
  570. procedure tcgppc.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  571. l : tasmlabel);
  572. var
  573. p: taicpu;
  574. scratch_register: TRegister;
  575. signed: boolean;
  576. begin
  577. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE];
  578. { in the following case, we generate more efficient code when }
  579. { signed is true }
  580. if (cmp_op in [OC_EQ,OC_NE]) and
  581. (a > $ffff) then
  582. signed := true;
  583. if signed then
  584. if (longint(a) >= low(smallint)) and (longint(a) <= high(smallint)) Then
  585. list.concat(taicpu.op_reg_reg_const(A_CMPWI,R_CR0,reg,longint(a)))
  586. else
  587. begin
  588. scratch_register := get_scratch_reg_int(list);
  589. a_load_const_reg(list,OS_32,a,scratch_register);
  590. list.concat(taicpu.op_reg_reg_reg(A_CMPW,R_CR0,reg,scratch_register));
  591. free_scratch_reg(list,scratch_register);
  592. end
  593. else
  594. if (a <= $ffff) then
  595. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,R_CR0,reg,a))
  596. else
  597. begin
  598. scratch_register := get_scratch_reg_int(list);
  599. a_load_const_reg(list,OS_32,a,scratch_register);
  600. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,R_CR0,reg,scratch_register));
  601. free_scratch_reg(list,scratch_register);
  602. end;
  603. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  604. end;
  605. procedure tcgppc.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  606. reg1,reg2 : tregister;l : tasmlabel);
  607. var
  608. p: taicpu;
  609. op: tasmop;
  610. begin
  611. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  612. op := A_CMPW
  613. else op := A_CMPLW;
  614. list.concat(taicpu.op_reg_reg_reg(op,R_CR0,reg1,reg2));
  615. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  616. end;
  617. procedure tcgppc.g_save_standard_registers(list : taasmoutput; usedinproc : tregisterset);
  618. begin
  619. {$warning FIX ME}
  620. end;
  621. procedure tcgppc.g_restore_standard_registers(list : taasmoutput; usedinproc : tregisterset);
  622. begin
  623. {$warning FIX ME}
  624. end;
  625. procedure tcgppc.g_save_all_registers(list : taasmoutput);
  626. begin
  627. {$warning FIX ME}
  628. end;
  629. procedure tcgppc.g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);
  630. begin
  631. {$warning FIX ME}
  632. end;
  633. procedure tcgppc.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  634. begin
  635. a_jmp(list,A_BC,TOpCmp2AsmCond[cond],0,l);
  636. end;
  637. procedure tcgppc.a_jmp_always(list : taasmoutput;l: tasmlabel);
  638. begin
  639. a_jmp(list,A_B,C_None,0,l);
  640. end;
  641. procedure tcgppc.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  642. var
  643. c: tasmcond;
  644. begin
  645. c := flags_to_cond(f);
  646. a_jmp(list,A_BC,c.cond,ord(c.cr)-ord(R_CR0),l);
  647. end;
  648. procedure tcgppc.g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister);
  649. var
  650. testbit: byte;
  651. bitvalue: boolean;
  652. begin
  653. { get the bit to extract from the conditional register + its }
  654. { requested value (0 or 1) }
  655. testbit := ((ord(f.cr)-ord(R_CR0)) * 4);
  656. case f.flag of
  657. F_EQ,F_NE:
  658. bitvalue := f.flag = F_EQ;
  659. F_LT,F_GE:
  660. begin
  661. inc(testbit);
  662. bitvalue := f.flag = F_LT;
  663. end;
  664. F_GT,F_LE:
  665. begin
  666. inc(testbit,2);
  667. bitvalue := f.flag = F_GT;
  668. end;
  669. else
  670. internalerror(200112261);
  671. end;
  672. { load the conditional register in the destination reg }
  673. list.concat(taicpu.op_reg(A_MFCR,reg));
  674. { we will move the bit that has to be tested to bit 0 by rotating }
  675. { left }
  676. testbit := (32 - testbit) and 31;
  677. { extract bit }
  678. list.concat(taicpu.op_reg_reg_const_const_const(
  679. A_RLWINM,reg,reg,testbit,31,31));
  680. { if we need the inverse, xor with 1 }
  681. if not bitvalue then
  682. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  683. end;
  684. (*
  685. procedure tcgppc.g_cond2reg(list: taasmoutput; const f: TAsmCond; reg: TRegister);
  686. var
  687. testbit: byte;
  688. bitvalue: boolean;
  689. begin
  690. { get the bit to extract from the conditional register + its }
  691. { requested value (0 or 1) }
  692. case f.simple of
  693. false:
  694. begin
  695. { we don't generate this in the compiler }
  696. internalerror(200109062);
  697. end;
  698. true:
  699. case f.cond of
  700. C_None:
  701. internalerror(200109063);
  702. C_LT..C_NU:
  703. begin
  704. testbit := (ord(f.cr) - ord(R_CR0))*4;
  705. inc(testbit,AsmCondFlag2BI[f.cond]);
  706. bitvalue := AsmCondFlagTF[f.cond];
  707. end;
  708. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  709. begin
  710. testbit := f.crbit
  711. bitvalue := AsmCondFlagTF[f.cond];
  712. end;
  713. else
  714. internalerror(200109064);
  715. end;
  716. end;
  717. { load the conditional register in the destination reg }
  718. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  719. { we will move the bit that has to be tested to bit 31 -> rotate }
  720. { left by bitpos+1 (remember, this is big-endian!) }
  721. if bitpos <> 31 then
  722. inc(bitpos)
  723. else
  724. bitpos := 0;
  725. { extract bit }
  726. list.concat(taicpu.op_reg_reg_const_const_const(
  727. A_RLWINM,reg,reg,bitpos,31,31));
  728. { if we need the inverse, xor with 1 }
  729. if not bitvalue then
  730. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  731. end;
  732. *)
  733. { *********** entry/exit code and address loading ************ }
  734. procedure tcgppc.g_stackframe_entry(list : taasmoutput;localsize : longint);
  735. begin
  736. case target_info.system of
  737. system_powerpc_macos:
  738. g_stackframe_entry_mac(list,localsize);
  739. system_powerpc_linux:
  740. g_stackframe_entry_sysv(list,localsize)
  741. else
  742. internalerror(2204001);
  743. end;
  744. end;
  745. procedure tcgppc.g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  746. { generated the entry code of a procedure/function. Note: localsize is the }
  747. { sum of the size necessary for local variables and the maximum possible }
  748. { combined size of ALL the parameters of a procedure called by the current }
  749. { one }
  750. var regcounter,firstregfpu,firstreggpr : TRegister;
  751. href : treference;
  752. usesfpr,usesgpr,gotgot : boolean;
  753. parastart : aword;
  754. offset : aword;
  755. begin
  756. { we do our own localsize calculation }
  757. localsize:=0;
  758. { CR and LR only have to be saved in case they are modified by the current }
  759. { procedure, but currently this isn't checked, so save them always }
  760. { following is the entry code as described in "Altivec Programming }
  761. { Interface Manual", bar the saving of AltiVec registers }
  762. a_reg_alloc(list,STACK_POINTER_REG);
  763. a_reg_alloc(list,R_0);
  764. { allocate registers containing reg parameters }
  765. for regcounter := R_3 to R_10 do
  766. a_reg_alloc(list,regcounter);
  767. usesfpr:=false;
  768. for regcounter:=R_F14 to R_F31 do
  769. if regcounter in rg.usedbyproc then
  770. begin
  771. usesfpr:=true;
  772. firstregfpu:=regcounter;
  773. break;
  774. end;
  775. usesgpr:=false;
  776. for regcounter:=R_14 to R_31 do
  777. if regcounter in rg.usedbyproc then
  778. begin
  779. usesgpr:=true;
  780. firstreggpr:=regcounter;
  781. break;
  782. end;
  783. { save link register? }
  784. if (procinfo.flags and pi_do_call)<>0 then
  785. begin
  786. { save return address... }
  787. list.concat(taicpu.op_reg(A_MFLR,R_0));
  788. { ... in caller's rframe }
  789. reference_reset_base(href,STACK_POINTER_REG,4);
  790. list.concat(taicpu.op_reg_ref(A_STW,R_0,href));
  791. a_reg_dealloc(list,R_0);
  792. end;
  793. if usesfpr or usesgpr then
  794. begin
  795. a_reg_alloc(list,R_11);
  796. { save end of fpr save area }
  797. list.concat(taicpu.op_reg_reg_const(A_ORI,R_11,STACK_POINTER_REG,0));
  798. end;
  799. { calculate the size of the locals }
  800. if usesgpr then
  801. inc(localsize,(ord(R_31)-ord(firstreggpr)+1)*4);
  802. if usesfpr then
  803. inc(localsize,(ord(R_F31)-ord(firstregfpu)+1)*8);
  804. { align to 16 bytes }
  805. localsize:=align(localsize,16);
  806. inc(localsize,tg.lasttemp);
  807. localsize:=align(localsize,16);
  808. tppcprocinfo(procinfo).localsize:=localsize;
  809. reference_reset_base(href,R_1,-localsize);
  810. a_load_store(list,A_STWU,R_1,href);
  811. { no GOT pointer loaded yet }
  812. gotgot:=false;
  813. if usesfpr then
  814. begin
  815. { save floating-point registers
  816. if (cs_create_pic in aktmoduleswitches) and not(usesgpr) then
  817. begin
  818. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g');
  819. gotgot:=true;
  820. end
  821. else
  822. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14));
  823. }
  824. for regcounter:=firstregfpu to R_F31 do
  825. if regcounter in rg.usedbyproc then
  826. begin
  827. { reference_reset_base(href,R_1,-localsize);
  828. a_load_store(list,A_STWU,R_1,href);
  829. }
  830. end;
  831. { compute end of gpr save area }
  832. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_11,-(ord(R_F31)-ord(firstregfpu)+1)*8));
  833. end;
  834. { save gprs and fetch GOT pointer }
  835. if usesgpr then
  836. begin
  837. {
  838. if cs_create_pic in aktmoduleswitches then
  839. begin
  840. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g');
  841. gotgot:=true;
  842. end
  843. else
  844. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
  845. }
  846. reference_reset_base(href,R_11,-(ord(R_31)-ord(firstreggpr)+1)*4);
  847. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  848. end;
  849. if usesfpr or usesgpr then
  850. a_reg_dealloc(list,R_11);
  851. { PIC code support, }
  852. if cs_create_pic in aktmoduleswitches then
  853. begin
  854. { if we didn't get the GOT pointer till now, we've to calculate it now }
  855. if not(gotgot) then
  856. begin
  857. {!!!!!!!!!!!!!}
  858. end;
  859. a_reg_alloc(list,R_31);
  860. { place GOT ptr in r31 }
  861. list.concat(taicpu.op_reg_reg(A_MFSPR,R_31,R_LR));
  862. end;
  863. { save the CR if necessary ( !!! always done currently ) }
  864. { still need to find out where this has to be done for SystemV
  865. a_reg_alloc(list,R_0);
  866. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  867. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  868. new_reference(STACK_POINTER_REG,LA_CR)));
  869. a_reg_dealloc(list,R_0); }
  870. { now comes the AltiVec context save, not yet implemented !!! }
  871. end;
  872. procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  873. var
  874. regcounter,firstregfpu,firstreggpr : TRegister;
  875. href : treference;
  876. usesfpr,usesgpr,genret : boolean;
  877. begin
  878. { release parameter registers }
  879. for regcounter := R_3 to R_10 do
  880. a_reg_dealloc(list,regcounter);
  881. { AltiVec context restore, not yet implemented !!! }
  882. usesfpr:=false;
  883. for regcounter:=R_F14 to R_F31 do
  884. if regcounter in rg.usedbyproc then
  885. begin
  886. usesfpr:=true;
  887. firstregfpu:=regcounter;
  888. break;
  889. end;
  890. usesgpr:=false;
  891. for regcounter:=R_14 to R_30 do
  892. if regcounter in rg.usedbyproc then
  893. begin
  894. usesgpr:=true;
  895. firstreggpr:=regcounter;
  896. break;
  897. end;
  898. { no return (blr) generated yet }
  899. genret:=true;
  900. if usesgpr then
  901. begin
  902. { address of gpr save area to r11 }
  903. if usesfpr then
  904. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_1,tppcprocinfo(procinfo).localsize-(ord(R_F31)-ord(firstregfpu)+1)*8))
  905. else
  906. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_1,tppcprocinfo(procinfo).localsize));
  907. { restore gprs }
  908. { at least for now we use LMW }
  909. {
  910. a_call_name(objectlibrary.newasmsymbol('_restgpr_14');
  911. }
  912. reference_reset_base(href,R_11,-(ord(R_31)-ord(firstreggpr)+1)*4);
  913. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  914. end;
  915. { restore fprs and return }
  916. if usesfpr then
  917. begin
  918. { address of fpr save area to r11 }
  919. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_11,(ord(R_F31)-ord(firstregfpu)+1)*8));
  920. {
  921. if (procinfo.flags and pi_do_call)<>0 then
  922. a_call_name(objectlibrary.newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  923. '_x')
  924. else
  925. { leaf node => lr haven't to be restored }
  926. a_call_name('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  927. '_l');
  928. genret:=false;
  929. }
  930. end;
  931. { if we didn't generate the return code, we've to do it now }
  932. if genret then
  933. begin
  934. { adjust r1 }
  935. a_op_const_reg(list,OP_ADD,tppcprocinfo(procinfo).localsize,R_1);
  936. { load link register? }
  937. if (procinfo.flags and pi_do_call)<>0 then
  938. begin
  939. reference_reset_base(href,STACK_POINTER_REG,4);
  940. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  941. list.concat(taicpu.op_reg(A_MTLR,R_0));
  942. end;
  943. list.concat(taicpu.op_none(A_BLR));
  944. end;
  945. end;
  946. procedure tcgppc.g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  947. { generated the entry code of a procedure/function. Note: localsize is the }
  948. { sum of the size necessary for local variables and the maximum possible }
  949. { combined size of ALL the parameters of a procedure called by the current }
  950. { one }
  951. var regcounter: TRegister;
  952. href : treference;
  953. begin
  954. if (localsize mod 8) <> 0 then internalerror(58991);
  955. { CR and LR only have to be saved in case they are modified by the current }
  956. { procedure, but currently this isn't checked, so save them always }
  957. { following is the entry code as described in "Altivec Programming }
  958. { Interface Manual", bar the saving of AltiVec registers }
  959. a_reg_alloc(list,STACK_POINTER_REG);
  960. a_reg_alloc(list,R_0);
  961. { allocate registers containing reg parameters }
  962. for regcounter := R_3 to R_10 do
  963. a_reg_alloc(list,regcounter);
  964. { save return address... }
  965. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_LR));
  966. { ... in caller's frame }
  967. reference_reset_base(href,STACK_POINTER_REG,8);
  968. list.concat(taicpu.op_reg_ref(A_STW,R_0,href));
  969. a_reg_dealloc(list,R_0);
  970. { save floating-point registers }
  971. { !!! has to be optimized: only save registers that are used }
  972. a_call_name(list,'_savef14');
  973. { save gprs in gpr save area }
  974. { !!! has to be optimized: only save registers that are used }
  975. reference_reset_base(href,STACK_POINTER_REG,-220);
  976. list.concat(taicpu.op_reg_ref(A_STMW,R_13,href));
  977. { save the CR if necessary ( !!! always done currently ) }
  978. a_reg_alloc(list,R_0);
  979. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR));
  980. reference_reset_base(href,stack_pointer_reg,LA_CR);
  981. list.concat(taicpu.op_reg_ref(A_STW,R_0,href));
  982. a_reg_dealloc(list,R_0);
  983. { save pointer to incoming arguments }
  984. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  985. a_reg_alloc(list,R_12);
  986. { 0 or 8 based on SP alignment }
  987. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  988. R_12,STACK_POINTER_REG,0,28,28));
  989. { add in stack length }
  990. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  991. -localsize));
  992. { establish new alignment }
  993. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  994. a_reg_dealloc(list,R_12);
  995. { now comes the AltiVec context save, not yet implemented !!! }
  996. end;
  997. procedure tcgppc.g_restore_frame_pointer(list : taasmoutput);
  998. begin
  999. { no frame pointer on the PowerPC (maybe there is one in the SystemV ABI?)}
  1000. end;
  1001. procedure tcgppc.g_return_from_proc(list : taasmoutput;parasize : aword);
  1002. begin
  1003. case target_info.system of
  1004. system_powerpc_macos:
  1005. g_return_from_proc_mac(list,parasize);
  1006. system_powerpc_linux:
  1007. g_return_from_proc_sysv(list,parasize)
  1008. else
  1009. internalerror(2204001);
  1010. end;
  1011. end;
  1012. procedure tcgppc.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  1013. var
  1014. ref2, tmpref: treference;
  1015. freereg: boolean;
  1016. begin
  1017. ref2 := ref;
  1018. freereg := fixref(list,ref2);
  1019. if assigned(ref2.symbol) then
  1020. { add the symbol's value to the base of the reference, and if the }
  1021. { reference doesn't have a base, create one }
  1022. begin
  1023. reference_reset(tmpref);
  1024. tmpref.offset := ref2.offset;
  1025. tmpref.symbol := ref2.symbol;
  1026. tmpref.symaddr := refs_ha;
  1027. if ref2.base <> R_NO then
  1028. begin
  1029. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1030. ref2.base,tmpref));
  1031. if freereg then
  1032. begin
  1033. cg.free_scratch_reg(list,ref2.base);
  1034. freereg := false;
  1035. end;
  1036. end
  1037. else
  1038. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1039. tmpref.base := R_NO;
  1040. tmpref.symaddr := refs_l;
  1041. { can be folded with one of the next instructions by the }
  1042. { optimizer probably }
  1043. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1044. end
  1045. else if ref2.offset <> 0 Then
  1046. if ref2.base <> R_NO then
  1047. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  1048. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1049. { occurs, so now only ref.offset has to be loaded }
  1050. else a_load_const_reg(list,OS_32,ref2.offset,r)
  1051. else if ref.index <> R_NO Then
  1052. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1053. else if (ref2.base <> R_NO) and
  1054. (r <> ref2.base) then
  1055. list.concat(taicpu.op_reg_reg(A_MR,r,ref2.base));
  1056. if freereg then
  1057. cg.free_scratch_reg(list,ref2.base);
  1058. end;
  1059. { ************* concatcopy ************ }
  1060. procedure tcgppc.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  1061. var
  1062. countreg: TRegister;
  1063. src, dst: TReference;
  1064. lab: tasmlabel;
  1065. count, count2: aword;
  1066. orgsrc, orgdst: boolean;
  1067. begin
  1068. {$ifdef extdebug}
  1069. if len > high(longint) then
  1070. internalerror(2002072704);
  1071. {$endif extdebug}
  1072. { make sure short loads are handled as optimally as possible }
  1073. if not loadref then
  1074. if (len <= 8) and
  1075. (byte(len) in [1,2,4,8]) then
  1076. begin
  1077. if len < 8 then
  1078. begin
  1079. a_load_ref_ref(list,int_cgsize(len),source,dest);
  1080. if delsource then
  1081. reference_release(list,source);
  1082. end
  1083. else
  1084. begin
  1085. a_reg_alloc(list,R_F0);
  1086. a_loadfpu_ref_reg(list,OS_F64,source,R_F0);
  1087. if delsource then
  1088. reference_release(list,source);
  1089. a_loadfpu_reg_ref(list,OS_F64,R_F0,dest);
  1090. a_reg_dealloc(list,R_F0);
  1091. end;
  1092. exit;
  1093. end;
  1094. reference_reset(src);
  1095. reference_reset(dst);
  1096. { load the address of source into src.base }
  1097. if loadref then
  1098. begin
  1099. src.base := get_scratch_reg_address(list);
  1100. a_load_ref_reg(list,OS_32,source,src.base);
  1101. orgsrc := false;
  1102. end
  1103. else if not issimpleref(source) or
  1104. ((source.index <> R_NO) and
  1105. ((source.offset + longint(len)) > high(smallint))) then
  1106. begin
  1107. src.base := get_scratch_reg_address(list);
  1108. a_loadaddr_ref_reg(list,source,src.base);
  1109. orgsrc := false;
  1110. end
  1111. else
  1112. begin
  1113. src := source;
  1114. orgsrc := true;
  1115. end;
  1116. if not orgsrc and delsource then
  1117. reference_release(list,source);
  1118. { load the address of dest into dst.base }
  1119. if not issimpleref(dest) or
  1120. ((dest.index <> R_NO) and
  1121. ((dest.offset + longint(len)) > high(smallint))) then
  1122. begin
  1123. dst.base := get_scratch_reg_address(list);
  1124. a_loadaddr_ref_reg(list,dest,dst.base);
  1125. orgdst := false;
  1126. end
  1127. else
  1128. begin
  1129. dst := dest;
  1130. orgdst := true;
  1131. end;
  1132. count := len div 8;
  1133. if count > 4 then
  1134. { generate a loop }
  1135. begin
  1136. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1137. { have to be set to 8. I put an Inc there so debugging may be }
  1138. { easier (should offset be different from zero here, it will be }
  1139. { easy to notice in the generated assembler }
  1140. inc(dst.offset,8);
  1141. inc(src.offset,8);
  1142. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1143. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1144. countreg := get_scratch_reg_int(list);
  1145. a_load_const_reg(list,OS_32,count,countreg);
  1146. { explicitely allocate R_0 since it can be used safely here }
  1147. { (for holding date that's being copied) }
  1148. a_reg_alloc(list,R_F0);
  1149. objectlibrary.getlabel(lab);
  1150. a_label(list, lab);
  1151. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1152. list.concat(taicpu.op_reg_ref(A_LFDU,R_F0,src));
  1153. list.concat(taicpu.op_reg_ref(A_STFDU,R_F0,dst));
  1154. a_jmp(list,A_BC,C_NE,0,lab);
  1155. free_scratch_reg(list,countreg);
  1156. a_reg_dealloc(list,R_F0);
  1157. len := len mod 8;
  1158. end;
  1159. count := len div 8;
  1160. if count > 0 then
  1161. { unrolled loop }
  1162. begin
  1163. a_reg_alloc(list,R_F0);
  1164. for count2 := 1 to count do
  1165. begin
  1166. a_loadfpu_ref_reg(list,OS_F64,src,R_F0);
  1167. a_loadfpu_reg_ref(list,OS_F64,R_F0,dst);
  1168. inc(src.offset,8);
  1169. inc(dst.offset,8);
  1170. end;
  1171. a_reg_dealloc(list,R_F0);
  1172. len := len mod 8;
  1173. end;
  1174. if (len and 4) <> 0 then
  1175. begin
  1176. a_reg_alloc(list,R_0);
  1177. a_load_ref_reg(list,OS_32,src,R_0);
  1178. a_load_reg_ref(list,OS_32,R_0,dst);
  1179. inc(src.offset,4);
  1180. inc(dst.offset,4);
  1181. a_reg_dealloc(list,R_0);
  1182. end;
  1183. { copy the leftovers }
  1184. if (len and 2) <> 0 then
  1185. begin
  1186. a_reg_alloc(list,R_0);
  1187. a_load_ref_reg(list,OS_16,src,R_0);
  1188. a_load_reg_ref(list,OS_16,R_0,dst);
  1189. inc(src.offset,2);
  1190. inc(dst.offset,2);
  1191. a_reg_dealloc(list,R_0);
  1192. end;
  1193. if (len and 1) <> 0 then
  1194. begin
  1195. a_reg_alloc(list,R_0);
  1196. a_load_ref_reg(list,OS_8,src,R_0);
  1197. a_load_reg_ref(list,OS_8,R_0,dst);
  1198. a_reg_dealloc(list,R_0);
  1199. end;
  1200. if orgsrc then
  1201. begin
  1202. if delsource then
  1203. reference_release(list,source);
  1204. end
  1205. else
  1206. free_scratch_reg(list,src.base);
  1207. if not orgdst then
  1208. free_scratch_reg(list,dst.base);
  1209. end;
  1210. procedure tcgppc.g_overflowcheck(list: taasmoutput; const p: tnode);
  1211. var
  1212. hl : tasmlabel;
  1213. begin
  1214. if not(cs_check_overflow in aktlocalswitches) then
  1215. exit;
  1216. objectlibrary.getlabel(hl);
  1217. if not ((p.resulttype.def.deftype=pointerdef) or
  1218. ((p.resulttype.def.deftype=orddef) and
  1219. (torddef(p.resulttype.def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1220. bool8bit,bool16bit,bool32bit]))) then
  1221. begin
  1222. list.concat(taicpu.op_reg(A_MCRXR,R_CR7));
  1223. a_jmp(list,A_BC,C_OV,7,hl)
  1224. end
  1225. else
  1226. a_jmp_cond(list,OC_AE,hl);
  1227. a_call_name(list,'FPC_OVERFLOW');
  1228. a_label(list,hl);
  1229. end;
  1230. {***************** This is private property, keep out! :) *****************}
  1231. procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  1232. var
  1233. regcounter: TRegister;
  1234. href : treference;
  1235. begin
  1236. { release parameter registers }
  1237. for regcounter := R_3 to R_10 do
  1238. a_reg_dealloc(list,regcounter);
  1239. { AltiVec context restore, not yet implemented !!! }
  1240. { restore SP }
  1241. list.concat(taicpu.op_reg_reg_const(A_ORI,STACK_POINTER_REG,R_31,0));
  1242. { restore gprs }
  1243. reference_reset_base(href,STACK_POINTER_REG,-220);
  1244. list.concat(taicpu.op_reg_ref(A_LMW,R_13,href));
  1245. { restore return address ... }
  1246. reference_reset_base(href,STACK_POINTER_REG,8);
  1247. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1248. { ... and return from _restf14 }
  1249. list.concat(taicpu.op_sym_ofs(A_B,objectlibrary.newasmsymbol('_restf14'),0));
  1250. end;
  1251. function tcgppc.issimpleref(const ref: treference): boolean;
  1252. begin
  1253. if (ref.base = R_NO) and
  1254. (ref.index <> R_NO) then
  1255. internalerror(200208101);
  1256. result :=
  1257. not(assigned(ref.symbol)) and
  1258. (((ref.index = R_NO) and
  1259. (ref.offset >= low(smallint)) and
  1260. (ref.offset <= high(smallint))) or
  1261. ((ref.index <> R_NO) and
  1262. (ref.offset = 0)));
  1263. end;
  1264. function tcgppc.fixref(list: taasmoutput; var ref: treference): boolean;
  1265. var
  1266. tmpreg: tregister;
  1267. begin
  1268. result := false;
  1269. if (ref.base <> R_NO) then
  1270. begin
  1271. if (ref.index <> R_NO) and
  1272. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1273. begin
  1274. result := true;
  1275. tmpreg := cg.get_scratch_reg_int(list);
  1276. if not assigned(ref.symbol) and
  1277. (cardinal(ref.offset-low(smallint)) <=
  1278. high(smallint)-low(smallint)) then
  1279. begin
  1280. list.concat(taicpu.op_reg_reg_const(
  1281. A_ADDI,tmpreg,ref.base,ref.offset));
  1282. ref.offset := 0;
  1283. end
  1284. else
  1285. begin
  1286. list.concat(taicpu.op_reg_reg_reg(
  1287. A_ADD,tmpreg,ref.base,ref.index));
  1288. ref.index := R_NO;
  1289. end;
  1290. ref.base := tmpreg;
  1291. end
  1292. end
  1293. else
  1294. if ref.index <> R_NO then
  1295. internalerror(200208102);
  1296. end;
  1297. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1298. { that's the case, we can use rlwinm to do an AND operation }
  1299. function tcgppc.get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  1300. var
  1301. temp, testbit: longint;
  1302. compare: boolean;
  1303. begin
  1304. get_rlwi_const := false;
  1305. if (a = 0) or (a = $ffffffff) then
  1306. exit;
  1307. { start with the lowest bit }
  1308. testbit := 1;
  1309. { check its value }
  1310. compare := boolean(a and testbit);
  1311. { find out how long the run of bits with this value is }
  1312. { (it's impossible that all bits are 1 or 0, because in that case }
  1313. { this function wouldn't have been called) }
  1314. l1 := 31;
  1315. while (((a and testbit) <> 0) = compare) do
  1316. begin
  1317. testbit := testbit shl 1;
  1318. dec(l1);
  1319. end;
  1320. { check the length of the run of bits that comes next }
  1321. compare := not compare;
  1322. l2 := l1;
  1323. while (((a and testbit) <> 0) = compare) and
  1324. (l2 >= 0) do
  1325. begin
  1326. testbit := testbit shl 1;
  1327. dec(l2);
  1328. end;
  1329. { and finally the check whether the rest of the bits all have the }
  1330. { same value }
  1331. compare := not compare;
  1332. temp := l2;
  1333. if temp >= 0 then
  1334. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1335. exit;
  1336. { we have done "not(not(compare))", so compare is back to its }
  1337. { initial value. If the lowest bit was 0, a is of the form }
  1338. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1339. { because l2 now contains the position of the last zero of the }
  1340. { first run instead of that of the first 1) so switch l1 and l2 }
  1341. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1342. if not compare then
  1343. begin
  1344. temp := l1;
  1345. l1 := l2+1;
  1346. l2 := temp;
  1347. end
  1348. else
  1349. { otherwise, l1 currently contains the position of the last }
  1350. { zero instead of that of the first 1 of the second run -> +1 }
  1351. inc(l1);
  1352. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1353. l1 := l1 and 31;
  1354. l2 := l2 and 31;
  1355. get_rlwi_const := true;
  1356. end;
  1357. procedure tcgppc.a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  1358. ref: treference);
  1359. var
  1360. tmpreg: tregister;
  1361. tmpref: treference;
  1362. begin
  1363. tmpreg := R_NO;
  1364. if assigned(ref.symbol) or
  1365. (cardinal(ref.offset-low(smallint)) >
  1366. high(smallint)-low(smallint)) then
  1367. begin
  1368. tmpreg := get_scratch_reg_address(list);
  1369. reference_reset(tmpref);
  1370. tmpref.symbol := ref.symbol;
  1371. tmpref.offset := ref.offset;
  1372. tmpref.symaddr := refs_ha;
  1373. if ref.base <> R_NO then
  1374. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1375. ref.base,tmpref))
  1376. else
  1377. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1378. ref.base := tmpreg;
  1379. ref.symaddr := refs_l;
  1380. end;
  1381. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1382. if (tmpreg <> R_NO) then
  1383. free_scratch_reg(list,tmpreg);
  1384. end;
  1385. procedure tcgppc.a_jmp(list: taasmoutput; op: tasmop; c: tasmcondflag;
  1386. crval: longint; l: tasmlabel);
  1387. var
  1388. p: taicpu;
  1389. begin
  1390. p := taicpu.op_sym(op,objectlibrary.newasmsymbol(l.name));
  1391. if op <> A_B then
  1392. create_cond_norm(c,crval,p.condition);
  1393. p.is_jmp := true;
  1394. list.concat(p)
  1395. end;
  1396. procedure tcg64fppc.a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);
  1397. begin
  1398. a_op64_reg_reg_reg(list,op,regsrc,regdst,regdst);
  1399. end;
  1400. procedure tcg64fppc.a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);
  1401. begin
  1402. a_op64_const_reg_reg(list,op,value,reg,reg);
  1403. end;
  1404. procedure tcg64fppc.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1405. begin
  1406. case op of
  1407. OP_AND,OP_OR,OP_XOR:
  1408. begin
  1409. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1410. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1411. end;
  1412. OP_ADD:
  1413. begin
  1414. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1415. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1416. end;
  1417. OP_SUB:
  1418. begin
  1419. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1420. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1421. end;
  1422. else
  1423. internalerror(2002072801);
  1424. end;
  1425. end;
  1426. procedure tcg64fppc.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);
  1427. const
  1428. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1429. (A_SUBIC,A_SUBC,A_ADDME));
  1430. var
  1431. tmpreg: tregister;
  1432. tmpreg64: tregister64;
  1433. issub: boolean;
  1434. begin
  1435. case op of
  1436. OP_AND,OP_OR,OP_XOR:
  1437. begin
  1438. cg.a_op_const_reg_reg(list,op,OS_32,cardinal(value),regsrc.reglo,regdst.reglo);
  1439. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1440. regdst.reghi);
  1441. end;
  1442. OP_ADD, OP_SUB:
  1443. begin
  1444. if (longint(value) <> 0) then
  1445. begin
  1446. issub := op = OP_SUB;
  1447. if (longint(value)-ord(issub) >= -32768) and
  1448. (longint(value)-ord(issub) <= 32767) then
  1449. begin
  1450. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1451. regdst.reglo,regsrc.reglo,longint(value)));
  1452. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1453. regdst.reghi,regsrc.reghi));
  1454. end
  1455. else if ((value shr 32) = 0) then
  1456. begin
  1457. tmpreg := cg.get_scratch_reg_int(list);
  1458. cg.a_load_const_reg(list,OS_32,cardinal(value),tmpreg);
  1459. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  1460. regdst.reglo,regsrc.reglo,tmpreg));
  1461. cg.free_scratch_reg(list,tmpreg);
  1462. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1463. regdst.reghi,regsrc.reghi));
  1464. end
  1465. else
  1466. begin
  1467. tmpreg64.reglo := cg.get_scratch_reg_int(list);
  1468. tmpreg64.reghi := cg.get_scratch_reg_int(list);
  1469. a_load64_const_reg(list,value,tmpreg64);
  1470. a_op64_reg_reg_reg(list,op,tmpreg64,regsrc,regdst);
  1471. cg.free_scratch_reg(list,tmpreg64.reghi);
  1472. cg.free_scratch_reg(list,tmpreg64.reglo);
  1473. end
  1474. end
  1475. else
  1476. begin
  1477. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  1478. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1479. regdst.reghi);
  1480. end;
  1481. end;
  1482. else
  1483. internalerror(2002072802);
  1484. end;
  1485. end;
  1486. begin
  1487. cg := tcgppc.create;
  1488. cg64 :=tcg64fppc.create;
  1489. end.
  1490. {
  1491. $Log$
  1492. Revision 1.60 2002-10-02 21:49:51 florian
  1493. * all A_BL instructions replaced by calls to a_call_name
  1494. Revision 1.59 2002/10/02 13:24:58 jonas
  1495. * changed a_call_* so that no superfluous code is generated anymore
  1496. Revision 1.58 2002/09/17 18:54:06 jonas
  1497. * a_load_reg_reg() now has two size parameters: source and dest. This
  1498. allows some optimizations on architectures that don't encode the
  1499. register size in the register name.
  1500. Revision 1.57 2002/09/10 21:22:25 jonas
  1501. + added some internal errors
  1502. * fixed bug in sysv exit code
  1503. Revision 1.56 2002/09/08 20:11:56 jonas
  1504. * fixed TOpCmp2AsmCond array (some unsigned equivalents were wrong)
  1505. Revision 1.55 2002/09/08 13:03:26 jonas
  1506. * several large offset-related fixes
  1507. Revision 1.54 2002/09/07 17:54:58 florian
  1508. * first part of PowerPC fixes
  1509. Revision 1.53 2002/09/07 15:25:14 peter
  1510. * old logs removed and tabs fixed
  1511. Revision 1.52 2002/09/02 10:14:51 jonas
  1512. + a_call_reg()
  1513. * small fix in a_call_ref()
  1514. Revision 1.51 2002/09/02 06:09:02 jonas
  1515. * fixed range error
  1516. Revision 1.50 2002/09/01 21:04:49 florian
  1517. * several powerpc related stuff fixed
  1518. Revision 1.49 2002/09/01 12:09:27 peter
  1519. + a_call_reg, a_call_loc added
  1520. * removed exprasmlist references
  1521. Revision 1.48 2002/08/31 21:38:02 jonas
  1522. * fixed a_call_ref (it should load ctr, not lr)
  1523. Revision 1.47 2002/08/31 21:30:45 florian
  1524. * fixed several problems caused by Jonas' commit :)
  1525. Revision 1.46 2002/08/31 19:25:50 jonas
  1526. + implemented a_call_ref()
  1527. Revision 1.45 2002/08/18 22:16:14 florian
  1528. + the ppc gas assembler writer adds now registers aliases
  1529. to the assembler file
  1530. Revision 1.44 2002/08/17 18:23:53 florian
  1531. * some assembler writer bugs fixed
  1532. Revision 1.43 2002/08/17 09:23:49 florian
  1533. * first part of procinfo rewrite
  1534. Revision 1.42 2002/08/16 14:24:59 carl
  1535. * issameref() to test if two references are the same (then emit no opcodes)
  1536. + ret_in_reg to replace ret_in_acc
  1537. (fix some register allocation bugs at the same time)
  1538. + save_std_register now has an extra parameter which is the
  1539. usedinproc registers
  1540. Revision 1.41 2002/08/15 08:13:54 carl
  1541. - a_load_sym_ofs_reg removed
  1542. * loadvmt now calls loadaddr_ref_reg instead
  1543. Revision 1.40 2002/08/11 14:32:32 peter
  1544. * renamed current_library to objectlibrary
  1545. Revision 1.39 2002/08/11 13:24:18 peter
  1546. * saving of asmsymbols in ppu supported
  1547. * asmsymbollist global is removed and moved into a new class
  1548. tasmlibrarydata that will hold the info of a .a file which
  1549. corresponds with a single module. Added librarydata to tmodule
  1550. to keep the library info stored for the module. In the future the
  1551. objectfiles will also be stored to the tasmlibrarydata class
  1552. * all getlabel/newasmsymbol and friends are moved to the new class
  1553. Revision 1.38 2002/08/11 11:39:31 jonas
  1554. + powerpc-specific genlinearlist
  1555. Revision 1.37 2002/08/10 17:15:31 jonas
  1556. * various fixes and optimizations
  1557. Revision 1.36 2002/08/06 20:55:23 florian
  1558. * first part of ppc calling conventions fix
  1559. Revision 1.35 2002/08/06 07:12:05 jonas
  1560. * fixed bug in g_flags2reg()
  1561. * and yet more constant operation fixes :)
  1562. Revision 1.34 2002/08/05 08:58:53 jonas
  1563. * fixed compilation problems
  1564. Revision 1.33 2002/08/04 12:57:55 jonas
  1565. * more misc. fixes, mostly constant-related
  1566. }