cgcpu.pas 67 KB

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