cgcpu.pas 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  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(list : taasmoutput;localsize : longint);override;
  61. procedure g_return_from_proc(list : taasmoutput;parasize : aword); override;
  62. procedure g_restore_frame_pointer(list : taasmoutput);override;
  63. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  64. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  65. procedure g_overflowcheck(list: taasmoutput; const p: tnode); override;
  66. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  67. { that's the case, we can use rlwinm to do an AND operation }
  68. function get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  69. procedure g_save_standard_registers(list : taasmoutput; usedinproc : tregisterset);override;
  70. procedure g_restore_standard_registers(list : taasmoutput; usedinproc : tregisterset);override;
  71. procedure g_save_all_registers(list : taasmoutput);override;
  72. procedure g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);override;
  73. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  74. private
  75. procedure g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  76. procedure g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  77. procedure g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  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_return_from_proc(list : taasmoutput;parasize : aword);
  746. begin
  747. case target_info.system of
  748. system_powerpc_macos:
  749. g_return_from_proc_mac(list,parasize);
  750. system_powerpc_linux:
  751. g_return_from_proc_sysv(list,parasize)
  752. else
  753. internalerror(2204001);
  754. end;
  755. end;
  756. procedure tcgppc.g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  757. { generated the entry code of a procedure/function. Note: localsize is the }
  758. { sum of the size necessary for local variables and the maximum possible }
  759. { combined size of ALL the parameters of a procedure called by the current }
  760. { one }
  761. var regcounter,firstregfpu,firstreggpr : TRegister;
  762. href : treference;
  763. usesfpr,usesgpr,gotgot : boolean;
  764. parastart : aword;
  765. offset : aword;
  766. begin
  767. { we do our own localsize calculation }
  768. localsize:=0;
  769. { CR and LR only have to be saved in case they are modified by the current }
  770. { procedure, but currently this isn't checked, so save them always }
  771. { following is the entry code as described in "Altivec Programming }
  772. { Interface Manual", bar the saving of AltiVec registers }
  773. a_reg_alloc(list,STACK_POINTER_REG);
  774. a_reg_alloc(list,R_0);
  775. { allocate registers containing reg parameters }
  776. for regcounter := R_3 to R_10 do
  777. a_reg_alloc(list,regcounter);
  778. usesfpr:=false;
  779. for regcounter:=R_F14 to R_F31 do
  780. if regcounter in rg.usedbyproc then
  781. begin
  782. usesfpr:=true;
  783. firstregfpu:=regcounter;
  784. break;
  785. end;
  786. usesgpr:=false;
  787. for regcounter:=R_14 to R_31 do
  788. if regcounter in rg.usedbyproc then
  789. begin
  790. usesgpr:=true;
  791. firstreggpr:=regcounter;
  792. break;
  793. end;
  794. { save link register? }
  795. if (procinfo.flags and pi_do_call)<>0 then
  796. begin
  797. { save return address... }
  798. list.concat(taicpu.op_reg(A_MFLR,R_0));
  799. { ... in caller's rframe }
  800. reference_reset_base(href,STACK_POINTER_REG,4);
  801. list.concat(taicpu.op_reg_ref(A_STW,R_0,href));
  802. a_reg_dealloc(list,R_0);
  803. end;
  804. if usesfpr or usesgpr then
  805. begin
  806. a_reg_alloc(list,R_11);
  807. { save end of fpr save area }
  808. list.concat(taicpu.op_reg_reg_const(A_ORI,R_11,STACK_POINTER_REG,0));
  809. end;
  810. { calculate the size of the locals }
  811. if usesgpr then
  812. inc(localsize,(ord(R_31)-ord(firstreggpr)+1)*4);
  813. if usesfpr then
  814. inc(localsize,(ord(R_F31)-ord(firstregfpu)+1)*8);
  815. { align to 16 bytes }
  816. localsize:=align(localsize,16);
  817. inc(localsize,tg.lasttemp);
  818. localsize:=align(localsize,16);
  819. tppcprocinfo(procinfo).localsize:=localsize;
  820. reference_reset_base(href,R_1,-localsize);
  821. a_load_store(list,A_STWU,R_1,href);
  822. { no GOT pointer loaded yet }
  823. gotgot:=false;
  824. if usesfpr then
  825. begin
  826. { save floating-point registers
  827. if (cs_create_pic in aktmoduleswitches) and not(usesgpr) then
  828. begin
  829. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g');
  830. gotgot:=true;
  831. end
  832. else
  833. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14));
  834. }
  835. for regcounter:=firstregfpu to R_F31 do
  836. if regcounter in rg.usedbyproc then
  837. begin
  838. { reference_reset_base(href,R_1,-localsize);
  839. a_load_store(list,A_STWU,R_1,href);
  840. }
  841. end;
  842. { compute end of gpr save area }
  843. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_11,-(ord(R_F31)-ord(firstregfpu)+1)*8));
  844. end;
  845. { save gprs and fetch GOT pointer }
  846. if usesgpr then
  847. begin
  848. {
  849. if cs_create_pic in aktmoduleswitches then
  850. begin
  851. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g');
  852. gotgot:=true;
  853. end
  854. else
  855. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
  856. }
  857. reference_reset_base(href,R_11,-(ord(R_31)-ord(firstreggpr)+1)*4);
  858. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  859. end;
  860. if usesfpr or usesgpr then
  861. a_reg_dealloc(list,R_11);
  862. { PIC code support, }
  863. if cs_create_pic in aktmoduleswitches then
  864. begin
  865. { if we didn't get the GOT pointer till now, we've to calculate it now }
  866. if not(gotgot) then
  867. begin
  868. {!!!!!!!!!!!!!}
  869. end;
  870. a_reg_alloc(list,R_31);
  871. { place GOT ptr in r31 }
  872. list.concat(taicpu.op_reg_reg(A_MFSPR,R_31,R_LR));
  873. end;
  874. { save the CR if necessary ( !!! always done currently ) }
  875. { still need to find out where this has to be done for SystemV
  876. a_reg_alloc(list,R_0);
  877. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  878. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  879. new_reference(STACK_POINTER_REG,LA_CR)));
  880. a_reg_dealloc(list,R_0); }
  881. { now comes the AltiVec context save, not yet implemented !!! }
  882. end;
  883. procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  884. var
  885. regcounter,firstregfpu,firstreggpr : TRegister;
  886. href : treference;
  887. usesfpr,usesgpr,genret : boolean;
  888. begin
  889. { release parameter registers }
  890. for regcounter := R_3 to R_10 do
  891. a_reg_dealloc(list,regcounter);
  892. { AltiVec context restore, not yet implemented !!! }
  893. usesfpr:=false;
  894. for regcounter:=R_F14 to R_F31 do
  895. if regcounter in rg.usedbyproc then
  896. begin
  897. usesfpr:=true;
  898. firstregfpu:=regcounter;
  899. break;
  900. end;
  901. usesgpr:=false;
  902. for regcounter:=R_14 to R_30 do
  903. if regcounter in rg.usedbyproc then
  904. begin
  905. usesgpr:=true;
  906. firstreggpr:=regcounter;
  907. break;
  908. end;
  909. { no return (blr) generated yet }
  910. genret:=true;
  911. if usesgpr then
  912. begin
  913. { address of gpr save area to r11 }
  914. if usesfpr then
  915. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_1,tppcprocinfo(procinfo).localsize-(ord(R_F31)-ord(firstregfpu)+1)*8))
  916. else
  917. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_1,tppcprocinfo(procinfo).localsize));
  918. { restore gprs }
  919. { at least for now we use LMW }
  920. {
  921. a_call_name(objectlibrary.newasmsymbol('_restgpr_14');
  922. }
  923. reference_reset_base(href,R_11,-(ord(R_31)-ord(firstreggpr)+1)*4);
  924. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  925. end;
  926. { restore fprs and return }
  927. if usesfpr then
  928. begin
  929. { address of fpr save area to r11 }
  930. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_11,(ord(R_F31)-ord(firstregfpu)+1)*8));
  931. {
  932. if (procinfo.flags and pi_do_call)<>0 then
  933. a_call_name(objectlibrary.newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  934. '_x')
  935. else
  936. { leaf node => lr haven't to be restored }
  937. a_call_name('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  938. '_l');
  939. genret:=false;
  940. }
  941. end;
  942. { if we didn't generate the return code, we've to do it now }
  943. if genret then
  944. begin
  945. { adjust r1 }
  946. a_op_const_reg(list,OP_ADD,tppcprocinfo(procinfo).localsize,R_1);
  947. { load link register? }
  948. if (procinfo.flags and pi_do_call)<>0 then
  949. begin
  950. reference_reset_base(href,STACK_POINTER_REG,4);
  951. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  952. list.concat(taicpu.op_reg(A_MTLR,R_0));
  953. end;
  954. list.concat(taicpu.op_none(A_BLR));
  955. end;
  956. end;
  957. procedure tcgppc.g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  958. { generated the entry code of a procedure/function. Note: localsize is the }
  959. { sum of the size necessary for local variables and the maximum possible }
  960. { combined size of ALL the parameters of a procedure called by the current }
  961. { one }
  962. var regcounter: TRegister;
  963. href : treference;
  964. begin
  965. if (localsize mod 8) <> 0 then internalerror(58991);
  966. { CR and LR only have to be saved in case they are modified by the current }
  967. { procedure, but currently this isn't checked, so save them always }
  968. { following is the entry code as described in "Altivec Programming }
  969. { Interface Manual", bar the saving of AltiVec registers }
  970. a_reg_alloc(list,STACK_POINTER_REG);
  971. a_reg_alloc(list,R_0);
  972. { allocate registers containing reg parameters }
  973. for regcounter := R_3 to R_10 do
  974. a_reg_alloc(list,regcounter);
  975. { save return address... }
  976. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_LR));
  977. { ... in caller's frame }
  978. reference_reset_base(href,STACK_POINTER_REG,8);
  979. list.concat(taicpu.op_reg_ref(A_STW,R_0,href));
  980. a_reg_dealloc(list,R_0);
  981. { save floating-point registers }
  982. { !!! has to be optimized: only save registers that are used }
  983. a_call_name(list,'_savef14');
  984. { save gprs in gpr save area }
  985. { !!! has to be optimized: only save registers that are used }
  986. reference_reset_base(href,STACK_POINTER_REG,-220);
  987. list.concat(taicpu.op_reg_ref(A_STMW,R_13,href));
  988. { save the CR if necessary ( !!! always done currently ) }
  989. a_reg_alloc(list,R_0);
  990. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR));
  991. reference_reset_base(href,stack_pointer_reg,LA_CR);
  992. list.concat(taicpu.op_reg_ref(A_STW,R_0,href));
  993. a_reg_dealloc(list,R_0);
  994. { save pointer to incoming arguments }
  995. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  996. a_reg_alloc(list,R_12);
  997. { 0 or 8 based on SP alignment }
  998. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  999. R_12,STACK_POINTER_REG,0,28,28));
  1000. { add in stack length }
  1001. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1002. -localsize));
  1003. { establish new alignment }
  1004. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1005. a_reg_dealloc(list,R_12);
  1006. { now comes the AltiVec context save, not yet implemented !!! }
  1007. end;
  1008. procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  1009. var
  1010. regcounter: TRegister;
  1011. href : treference;
  1012. begin
  1013. { release parameter registers }
  1014. for regcounter := R_3 to R_10 do
  1015. a_reg_dealloc(list,regcounter);
  1016. { AltiVec context restore, not yet implemented !!! }
  1017. { restore SP }
  1018. list.concat(taicpu.op_reg_reg_const(A_ORI,STACK_POINTER_REG,R_31,0));
  1019. { restore gprs }
  1020. reference_reset_base(href,STACK_POINTER_REG,-220);
  1021. list.concat(taicpu.op_reg_ref(A_LMW,R_13,href));
  1022. { restore return address ... }
  1023. reference_reset_base(href,STACK_POINTER_REG,8);
  1024. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1025. { ... and return from _restf14 }
  1026. list.concat(taicpu.op_sym_ofs(A_B,objectlibrary.newasmsymbol('_restf14'),0));
  1027. end;
  1028. procedure tcgppc.g_restore_frame_pointer(list : taasmoutput);
  1029. begin
  1030. { no frame pointer on the PowerPC (maybe there is one in the SystemV ABI?)}
  1031. end;
  1032. procedure tcgppc.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  1033. var
  1034. ref2, tmpref: treference;
  1035. freereg: boolean;
  1036. begin
  1037. ref2 := ref;
  1038. freereg := fixref(list,ref2);
  1039. if assigned(ref2.symbol) then
  1040. { add the symbol's value to the base of the reference, and if the }
  1041. { reference doesn't have a base, create one }
  1042. begin
  1043. reference_reset(tmpref);
  1044. tmpref.offset := ref2.offset;
  1045. tmpref.symbol := ref2.symbol;
  1046. tmpref.symaddr := refs_ha;
  1047. if ref2.base <> R_NO then
  1048. begin
  1049. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1050. ref2.base,tmpref));
  1051. if freereg then
  1052. begin
  1053. cg.free_scratch_reg(list,ref2.base);
  1054. freereg := false;
  1055. end;
  1056. end
  1057. else
  1058. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1059. tmpref.base := R_NO;
  1060. tmpref.symaddr := refs_l;
  1061. { can be folded with one of the next instructions by the }
  1062. { optimizer probably }
  1063. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1064. end
  1065. else if ref2.offset <> 0 Then
  1066. if ref2.base <> R_NO then
  1067. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  1068. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1069. { occurs, so now only ref.offset has to be loaded }
  1070. else a_load_const_reg(list,OS_32,ref2.offset,r)
  1071. else if ref.index <> R_NO Then
  1072. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1073. else if (ref2.base <> R_NO) and
  1074. (r <> ref2.base) then
  1075. list.concat(taicpu.op_reg_reg(A_MR,r,ref2.base));
  1076. if freereg then
  1077. cg.free_scratch_reg(list,ref2.base);
  1078. end;
  1079. { ************* concatcopy ************ }
  1080. procedure tcgppc.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  1081. var
  1082. countreg: TRegister;
  1083. src, dst: TReference;
  1084. lab: tasmlabel;
  1085. count, count2: aword;
  1086. orgsrc, orgdst: boolean;
  1087. begin
  1088. {$ifdef extdebug}
  1089. if len > high(longint) then
  1090. internalerror(2002072704);
  1091. {$endif extdebug}
  1092. { make sure short loads are handled as optimally as possible }
  1093. if not loadref then
  1094. if (len <= 8) and
  1095. (byte(len) in [1,2,4,8]) then
  1096. begin
  1097. if len < 8 then
  1098. begin
  1099. a_load_ref_ref(list,int_cgsize(len),source,dest);
  1100. if delsource then
  1101. reference_release(list,source);
  1102. end
  1103. else
  1104. begin
  1105. a_reg_alloc(list,R_F0);
  1106. a_loadfpu_ref_reg(list,OS_F64,source,R_F0);
  1107. if delsource then
  1108. reference_release(list,source);
  1109. a_loadfpu_reg_ref(list,OS_F64,R_F0,dest);
  1110. a_reg_dealloc(list,R_F0);
  1111. end;
  1112. exit;
  1113. end;
  1114. reference_reset(src);
  1115. reference_reset(dst);
  1116. { load the address of source into src.base }
  1117. if loadref then
  1118. begin
  1119. src.base := get_scratch_reg_address(list);
  1120. a_load_ref_reg(list,OS_32,source,src.base);
  1121. orgsrc := false;
  1122. end
  1123. else if not issimpleref(source) or
  1124. ((source.index <> R_NO) and
  1125. ((source.offset + longint(len)) > high(smallint))) then
  1126. begin
  1127. src.base := get_scratch_reg_address(list);
  1128. a_loadaddr_ref_reg(list,source,src.base);
  1129. orgsrc := false;
  1130. end
  1131. else
  1132. begin
  1133. src := source;
  1134. orgsrc := true;
  1135. end;
  1136. if not orgsrc and delsource then
  1137. reference_release(list,source);
  1138. { load the address of dest into dst.base }
  1139. if not issimpleref(dest) or
  1140. ((dest.index <> R_NO) and
  1141. ((dest.offset + longint(len)) > high(smallint))) then
  1142. begin
  1143. dst.base := get_scratch_reg_address(list);
  1144. a_loadaddr_ref_reg(list,dest,dst.base);
  1145. orgdst := false;
  1146. end
  1147. else
  1148. begin
  1149. dst := dest;
  1150. orgdst := true;
  1151. end;
  1152. count := len div 8;
  1153. if count > 4 then
  1154. { generate a loop }
  1155. begin
  1156. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1157. { have to be set to 8. I put an Inc there so debugging may be }
  1158. { easier (should offset be different from zero here, it will be }
  1159. { easy to notice in the generated assembler }
  1160. inc(dst.offset,8);
  1161. inc(src.offset,8);
  1162. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1163. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1164. countreg := get_scratch_reg_int(list);
  1165. a_load_const_reg(list,OS_32,count,countreg);
  1166. { explicitely allocate R_0 since it can be used safely here }
  1167. { (for holding date that's being copied) }
  1168. a_reg_alloc(list,R_F0);
  1169. objectlibrary.getlabel(lab);
  1170. a_label(list, lab);
  1171. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1172. list.concat(taicpu.op_reg_ref(A_LFDU,R_F0,src));
  1173. list.concat(taicpu.op_reg_ref(A_STFDU,R_F0,dst));
  1174. a_jmp(list,A_BC,C_NE,0,lab);
  1175. free_scratch_reg(list,countreg);
  1176. a_reg_dealloc(list,R_F0);
  1177. len := len mod 8;
  1178. end;
  1179. count := len div 8;
  1180. if count > 0 then
  1181. { unrolled loop }
  1182. begin
  1183. a_reg_alloc(list,R_F0);
  1184. for count2 := 1 to count do
  1185. begin
  1186. a_loadfpu_ref_reg(list,OS_F64,src,R_F0);
  1187. a_loadfpu_reg_ref(list,OS_F64,R_F0,dst);
  1188. inc(src.offset,8);
  1189. inc(dst.offset,8);
  1190. end;
  1191. a_reg_dealloc(list,R_F0);
  1192. len := len mod 8;
  1193. end;
  1194. if (len and 4) <> 0 then
  1195. begin
  1196. a_reg_alloc(list,R_0);
  1197. a_load_ref_reg(list,OS_32,src,R_0);
  1198. a_load_reg_ref(list,OS_32,R_0,dst);
  1199. inc(src.offset,4);
  1200. inc(dst.offset,4);
  1201. a_reg_dealloc(list,R_0);
  1202. end;
  1203. { copy the leftovers }
  1204. if (len and 2) <> 0 then
  1205. begin
  1206. a_reg_alloc(list,R_0);
  1207. a_load_ref_reg(list,OS_16,src,R_0);
  1208. a_load_reg_ref(list,OS_16,R_0,dst);
  1209. inc(src.offset,2);
  1210. inc(dst.offset,2);
  1211. a_reg_dealloc(list,R_0);
  1212. end;
  1213. if (len and 1) <> 0 then
  1214. begin
  1215. a_reg_alloc(list,R_0);
  1216. a_load_ref_reg(list,OS_8,src,R_0);
  1217. a_load_reg_ref(list,OS_8,R_0,dst);
  1218. a_reg_dealloc(list,R_0);
  1219. end;
  1220. if orgsrc then
  1221. begin
  1222. if delsource then
  1223. reference_release(list,source);
  1224. end
  1225. else
  1226. free_scratch_reg(list,src.base);
  1227. if not orgdst then
  1228. free_scratch_reg(list,dst.base);
  1229. end;
  1230. procedure tcgppc.g_overflowcheck(list: taasmoutput; const p: tnode);
  1231. var
  1232. hl : tasmlabel;
  1233. begin
  1234. if not(cs_check_overflow in aktlocalswitches) then
  1235. exit;
  1236. objectlibrary.getlabel(hl);
  1237. if not ((p.resulttype.def.deftype=pointerdef) or
  1238. ((p.resulttype.def.deftype=orddef) and
  1239. (torddef(p.resulttype.def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1240. bool8bit,bool16bit,bool32bit]))) then
  1241. begin
  1242. list.concat(taicpu.op_reg(A_MCRXR,R_CR7));
  1243. a_jmp(list,A_BC,C_OV,7,hl)
  1244. end
  1245. else
  1246. a_jmp_cond(list,OC_AE,hl);
  1247. a_call_name(list,'FPC_OVERFLOW');
  1248. a_label(list,hl);
  1249. end;
  1250. {***************** This is private property, keep out! :) *****************}
  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.61 2002-10-19 12:50:36 olle
  1493. * reorganized prologue and epilogue routines
  1494. Revision 1.60 2002/10/02 21:49:51 florian
  1495. * all A_BL instructions replaced by calls to a_call_name
  1496. Revision 1.59 2002/10/02 13:24:58 jonas
  1497. * changed a_call_* so that no superfluous code is generated anymore
  1498. Revision 1.58 2002/09/17 18:54:06 jonas
  1499. * a_load_reg_reg() now has two size parameters: source and dest. This
  1500. allows some optimizations on architectures that don't encode the
  1501. register size in the register name.
  1502. Revision 1.57 2002/09/10 21:22:25 jonas
  1503. + added some internal errors
  1504. * fixed bug in sysv exit code
  1505. Revision 1.56 2002/09/08 20:11:56 jonas
  1506. * fixed TOpCmp2AsmCond array (some unsigned equivalents were wrong)
  1507. Revision 1.55 2002/09/08 13:03:26 jonas
  1508. * several large offset-related fixes
  1509. Revision 1.54 2002/09/07 17:54:58 florian
  1510. * first part of PowerPC fixes
  1511. Revision 1.53 2002/09/07 15:25:14 peter
  1512. * old logs removed and tabs fixed
  1513. Revision 1.52 2002/09/02 10:14:51 jonas
  1514. + a_call_reg()
  1515. * small fix in a_call_ref()
  1516. Revision 1.51 2002/09/02 06:09:02 jonas
  1517. * fixed range error
  1518. Revision 1.50 2002/09/01 21:04:49 florian
  1519. * several powerpc related stuff fixed
  1520. Revision 1.49 2002/09/01 12:09:27 peter
  1521. + a_call_reg, a_call_loc added
  1522. * removed exprasmlist references
  1523. Revision 1.48 2002/08/31 21:38:02 jonas
  1524. * fixed a_call_ref (it should load ctr, not lr)
  1525. Revision 1.47 2002/08/31 21:30:45 florian
  1526. * fixed several problems caused by Jonas' commit :)
  1527. Revision 1.46 2002/08/31 19:25:50 jonas
  1528. + implemented a_call_ref()
  1529. Revision 1.45 2002/08/18 22:16:14 florian
  1530. + the ppc gas assembler writer adds now registers aliases
  1531. to the assembler file
  1532. Revision 1.44 2002/08/17 18:23:53 florian
  1533. * some assembler writer bugs fixed
  1534. Revision 1.43 2002/08/17 09:23:49 florian
  1535. * first part of procinfo rewrite
  1536. Revision 1.42 2002/08/16 14:24:59 carl
  1537. * issameref() to test if two references are the same (then emit no opcodes)
  1538. + ret_in_reg to replace ret_in_acc
  1539. (fix some register allocation bugs at the same time)
  1540. + save_std_register now has an extra parameter which is the
  1541. usedinproc registers
  1542. Revision 1.41 2002/08/15 08:13:54 carl
  1543. - a_load_sym_ofs_reg removed
  1544. * loadvmt now calls loadaddr_ref_reg instead
  1545. Revision 1.40 2002/08/11 14:32:32 peter
  1546. * renamed current_library to objectlibrary
  1547. Revision 1.39 2002/08/11 13:24:18 peter
  1548. * saving of asmsymbols in ppu supported
  1549. * asmsymbollist global is removed and moved into a new class
  1550. tasmlibrarydata that will hold the info of a .a file which
  1551. corresponds with a single module. Added librarydata to tmodule
  1552. to keep the library info stored for the module. In the future the
  1553. objectfiles will also be stored to the tasmlibrarydata class
  1554. * all getlabel/newasmsymbol and friends are moved to the new class
  1555. Revision 1.38 2002/08/11 11:39:31 jonas
  1556. + powerpc-specific genlinearlist
  1557. Revision 1.37 2002/08/10 17:15:31 jonas
  1558. * various fixes and optimizations
  1559. Revision 1.36 2002/08/06 20:55:23 florian
  1560. * first part of ppc calling conventions fix
  1561. Revision 1.35 2002/08/06 07:12:05 jonas
  1562. * fixed bug in g_flags2reg()
  1563. * and yet more constant operation fixes :)
  1564. Revision 1.34 2002/08/05 08:58:53 jonas
  1565. * fixed compilation problems
  1566. Revision 1.33 2002/08/04 12:57:55 jonas
  1567. * more misc. fixes, mostly constant-related
  1568. }