cgcpu.pas 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359
  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 : Tsupregset);override;
  70. procedure g_restore_standard_registers(list : taasmoutput; usedinproc : Tsupregset);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,size);
  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 procedure by name }
  193. procedure tcgppc.a_call_name(list : taasmoutput;const s : string);
  194. var
  195. href : treference;
  196. begin
  197. {MacOS: The linker on MacOS (PPCLink) inserts a call to glue code,
  198. if it is a cross-TOC call. If so, it also replaces the NOP
  199. with some restore code.}
  200. list.concat(taicpu.op_sym(A_BL,objectlibrary.newasmsymbol(s)));
  201. if target_info.system=system_powerpc_macos then
  202. list.concat(taicpu.op_none(A_NOP));
  203. procinfo.flags:=procinfo.flags or pi_do_call;
  204. end;
  205. { calling a procedure by address }
  206. procedure tcgppc.a_call_reg(list : taasmoutput;reg: tregister);
  207. var
  208. tmpreg : tregister;
  209. tmpref : treference;
  210. begin
  211. if target_info.system=system_powerpc_macos then
  212. begin
  213. {Generate instruction to load the procedure address from
  214. the transition vector.}
  215. //TODO: Support cross-TOC calls.
  216. tmpreg := get_scratch_reg_int(list,OS_INT);
  217. reference_reset(tmpref);
  218. tmpref.offset := 0;
  219. //tmpref.symaddr := refs_full;
  220. tmpref.base:= reg;
  221. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  222. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  223. free_scratch_reg(list,tmpreg);
  224. end
  225. else
  226. list.concat(taicpu.op_reg(A_MTCTR,reg));
  227. list.concat(taicpu.op_none(A_BCTRL));
  228. //if target_info.system=system_powerpc_macos then
  229. // //NOP is not needed here.
  230. // list.concat(taicpu.op_none(A_NOP));
  231. procinfo.flags:=procinfo.flags or pi_do_call;
  232. //list.concat(tai_comment.create(strpnew('***** a_call_reg')));
  233. end;
  234. { calling a procedure by address }
  235. procedure tcgppc.a_call_ref(list : taasmoutput;const ref : treference);
  236. var
  237. tmpreg : tregister;
  238. tmpref : treference;
  239. begin
  240. tmpreg := get_scratch_reg_int(list,OS_ADDR);
  241. a_load_ref_reg(list,OS_ADDR,ref,tmpreg);
  242. if target_info.system=system_powerpc_macos then
  243. begin
  244. {Generate instruction to load the procedure address from
  245. the transition vector.}
  246. //TODO: Support cross-TOC calls.
  247. reference_reset(tmpref);
  248. tmpref.offset := 0;
  249. //tmpref.symaddr := refs_full;
  250. tmpref.base:= tmpreg;
  251. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  252. end;
  253. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  254. free_scratch_reg(list,tmpreg);
  255. list.concat(taicpu.op_none(A_BCTRL));
  256. //if target_info.system=system_powerpc_macos then
  257. // //NOP is not needed here.
  258. // list.concat(taicpu.op_none(A_NOP));
  259. procinfo.flags:=procinfo.flags or pi_do_call;
  260. //list.concat(tai_comment.create(strpnew('***** a_call_ref')));
  261. end;
  262. {********************** load instructions ********************}
  263. procedure tcgppc.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  264. begin
  265. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  266. internalerror(2002090902);
  267. if (longint(a) >= low(smallint)) and
  268. (longint(a) <= high(smallint)) then
  269. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a)))
  270. else if ((a and $ffff) <> 0) then
  271. begin
  272. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a and $ffff)));
  273. if ((a shr 16) <> 0) or
  274. (smallint(a and $ffff) < 0) then
  275. list.concat(taicpu.op_reg_reg_const(A_ADDIS,reg,reg,
  276. smallint((a shr 16)+ord(smallint(a and $ffff) < 0))))
  277. end
  278. else
  279. list.concat(taicpu.op_reg_const(A_LIS,reg,smallint(a shr 16)));
  280. end;
  281. procedure tcgppc.a_load_reg_ref(list : taasmoutput; size: TCGSize; reg : tregister;const ref : treference);
  282. const
  283. StoreInstr: Array[OS_8..OS_32,boolean, boolean] of TAsmOp =
  284. { indexed? updating?}
  285. (((A_STB,A_STBU),(A_STBX,A_STBUX)),
  286. ((A_STH,A_STHU),(A_STHX,A_STHUX)),
  287. ((A_STW,A_STWU),(A_STWX,A_STWUX)));
  288. var
  289. op: TAsmOp;
  290. ref2: TReference;
  291. freereg: boolean;
  292. begin
  293. ref2 := ref;
  294. freereg := fixref(list,ref2);
  295. if size in [OS_S8..OS_S16] then
  296. { storing is the same for signed and unsigned values }
  297. size := tcgsize(ord(size)-(ord(OS_S8)-ord(OS_8)));
  298. { 64 bit stuff should be handled separately }
  299. if size in [OS_64,OS_S64] then
  300. internalerror(200109236);
  301. op := storeinstr[tcgsize2unsigned[size],ref2.index.number<>NR_NO,false];
  302. a_load_store(list,op,reg,ref2);
  303. if freereg then
  304. cg.free_scratch_reg(list,ref2.base);
  305. End;
  306. procedure tcgppc.a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref: treference;reg : tregister);
  307. const
  308. LoadInstr: Array[OS_8..OS_S32,boolean, boolean] of TAsmOp =
  309. { indexed? updating?}
  310. (((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  311. ((A_LHZ,A_LHZU),(A_LHZX,A_LHZUX)),
  312. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)),
  313. { 64bit stuff should be handled separately }
  314. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  315. { there's no load-byte-with-sign-extend :( }
  316. ((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  317. ((A_LHA,A_LHAU),(A_LHAX,A_LHAUX)),
  318. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)));
  319. var
  320. op: tasmop;
  321. tmpreg: tregister;
  322. ref2, tmpref: treference;
  323. freereg: boolean;
  324. begin
  325. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  326. internalerror(2002090902);
  327. ref2 := ref;
  328. freereg := fixref(list,ref2);
  329. op := loadinstr[size,ref2.index.number<>NR_NO,false];
  330. a_load_store(list,op,reg,ref2);
  331. if freereg then
  332. free_scratch_reg(list,ref2.base);
  333. { sign extend shortint if necessary, since there is no }
  334. { load instruction that does that automatically (JM) }
  335. if size = OS_S8 then
  336. list.concat(taicpu.op_reg_reg(A_EXTSB,reg,reg));
  337. end;
  338. procedure tcgppc.a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  339. begin
  340. if (reg1.enum<>R_INTREGISTER) or (reg1.number = 0) then
  341. internalerror(200303101);
  342. if (reg2.enum<>R_INTREGISTER) or (reg2.number = 0) then
  343. internalerror(200303102);
  344. if (reg1.number<>reg2.number) or
  345. (tcgsize2size[tosize] < tcgsize2size[fromsize]) or
  346. ((tcgsize2size[tosize] = tcgsize2size[fromsize]) and
  347. (tosize <> fromsize) and
  348. not(fromsize in [OS_32,OS_S32])) then
  349. begin
  350. case fromsize of
  351. OS_8:
  352. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  353. reg2,reg1,0,31-8+1,31));
  354. OS_S8:
  355. list.concat(taicpu.op_reg_reg(A_EXTSB,reg2,reg1));
  356. OS_16:
  357. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  358. reg2,reg1,0,31-16+1,31));
  359. OS_S16:
  360. list.concat(taicpu.op_reg_reg(A_EXTSH,reg2,reg1));
  361. OS_32,OS_S32:
  362. list.concat(taicpu.op_reg_reg(A_MR,reg2,reg1));
  363. else internalerror(2002090901);
  364. end;
  365. end;
  366. end;
  367. procedure tcgppc.a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  368. begin
  369. list.concat(taicpu.op_reg_reg(A_FMR,reg2,reg1));
  370. end;
  371. procedure tcgppc.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  372. const
  373. FpuLoadInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  374. { indexed? updating?}
  375. (((A_LFS,A_LFSU),(A_LFSX,A_LFSUX)),
  376. ((A_LFD,A_LFDU),(A_LFDX,A_LFDUX)));
  377. var
  378. op: tasmop;
  379. ref2: treference;
  380. freereg: boolean;
  381. begin
  382. { several functions call this procedure with OS_32 or OS_64 }
  383. { so this makes life easier (FK) }
  384. case size of
  385. OS_32,OS_F32:
  386. size:=OS_F32;
  387. OS_64,OS_F64,OS_C64:
  388. size:=OS_F64;
  389. else
  390. internalerror(200201121);
  391. end;
  392. ref2 := ref;
  393. freereg := fixref(list,ref2);
  394. op := fpuloadinstr[size,ref2.index.number <> NR_NO,false];
  395. a_load_store(list,op,reg,ref2);
  396. if freereg then
  397. cg.free_scratch_reg(list,ref2.base);
  398. end;
  399. procedure tcgppc.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  400. const
  401. FpuStoreInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  402. { indexed? updating?}
  403. (((A_STFS,A_STFSU),(A_STFSX,A_STFSUX)),
  404. ((A_STFD,A_STFDU),(A_STFDX,A_STFDUX)));
  405. var
  406. op: tasmop;
  407. ref2: treference;
  408. freereg: boolean;
  409. begin
  410. if not(size in [OS_F32,OS_F64]) then
  411. internalerror(200201122);
  412. ref2 := ref;
  413. freereg := fixref(list,ref2);
  414. op := fpustoreinstr[size,ref2.index.number <> NR_NO,false];
  415. a_load_store(list,op,reg,ref2);
  416. if freereg then
  417. cg.free_scratch_reg(list,ref2.base);
  418. end;
  419. procedure tcgppc.a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister);
  420. var
  421. scratch_register: TRegister;
  422. begin
  423. a_op_const_reg_reg(list,op,OS_32,a,reg,reg);
  424. end;
  425. procedure tcgppc.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  426. begin
  427. a_op_reg_reg_reg(list,op,OS_32,src,dst,dst);
  428. end;
  429. procedure tcgppc.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  430. size: tcgsize; a: aword; src, dst: tregister);
  431. var
  432. l1,l2: longint;
  433. oplo, ophi: tasmop;
  434. scratchreg: tregister;
  435. useReg, gotrlwi: boolean;
  436. procedure do_lo_hi;
  437. begin
  438. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  439. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  440. end;
  441. begin
  442. if src.enum<>R_INTREGISTER then
  443. internalerror(200303102);
  444. if op = OP_SUB then
  445. begin
  446. {$ifopt q+}
  447. {$q-}
  448. {$define overflowon}
  449. {$endif}
  450. a_op_const_reg_reg(list,OP_ADD,size,aword(-a),src,dst);
  451. {$ifdef overflowon}
  452. {$q+}
  453. {$undef overflowon}
  454. {$endif}
  455. exit;
  456. end;
  457. ophi := TOpCG2AsmOpConstHi[op];
  458. oplo := TOpCG2AsmOpConstLo[op];
  459. gotrlwi := get_rlwi_const(a,l1,l2);
  460. if (op in [OP_AND,OP_OR,OP_XOR]) then
  461. begin
  462. if (a = 0) then
  463. begin
  464. if op = OP_AND then
  465. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  466. exit;
  467. end
  468. else if (a = high(aword)) then
  469. begin
  470. case op of
  471. OP_OR:
  472. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  473. OP_XOR:
  474. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  475. end;
  476. exit;
  477. end
  478. else if (a <= high(word)) and
  479. ((op <> OP_AND) or
  480. not gotrlwi) then
  481. begin
  482. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  483. exit;
  484. end;
  485. { all basic constant instructions also have a shifted form that }
  486. { works only on the highest 16bits, so if lo(a) is 0, we can }
  487. { use that one }
  488. if (word(a) = 0) and
  489. (not(op = OP_AND) or
  490. not gotrlwi) then
  491. begin
  492. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  493. exit;
  494. end;
  495. end
  496. else if (op = OP_ADD) then
  497. if a = 0 then
  498. exit
  499. else if (longint(a) >= low(smallint)) and
  500. (longint(a) <= high(smallint)) then
  501. begin
  502. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  503. exit;
  504. end;
  505. { otherwise, the instructions we can generate depend on the }
  506. { operation }
  507. useReg := false;
  508. case op of
  509. OP_DIV,OP_IDIV:
  510. if (a = 0) then
  511. internalerror(200208103)
  512. else if (a = 1) then
  513. begin
  514. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  515. exit
  516. end
  517. else if ispowerof2(a,l1) then
  518. begin
  519. case op of
  520. OP_DIV:
  521. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  522. OP_IDIV:
  523. begin
  524. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  525. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  526. end;
  527. end;
  528. exit;
  529. end
  530. else
  531. usereg := true;
  532. OP_IMUL, OP_MUL:
  533. if (a = 0) then
  534. begin
  535. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  536. exit
  537. end
  538. else if (a = 1) then
  539. begin
  540. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  541. exit
  542. end
  543. else if ispowerof2(a,l1) then
  544. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  545. else if (longint(a) >= low(smallint)) and
  546. (longint(a) <= high(smallint)) then
  547. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  548. else
  549. usereg := true;
  550. OP_ADD:
  551. begin
  552. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  553. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  554. smallint((a shr 16) + ord(smallint(a) < 0))));
  555. end;
  556. OP_OR:
  557. { try to use rlwimi }
  558. if gotrlwi and
  559. (src.number = dst.number) then
  560. begin
  561. scratchreg := get_scratch_reg_int(list,OS_INT);
  562. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  563. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  564. scratchreg,0,l1,l2));
  565. free_scratch_reg(list,scratchreg);
  566. end
  567. else
  568. do_lo_hi;
  569. OP_AND:
  570. { try to use rlwinm }
  571. if gotrlwi then
  572. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  573. src,0,l1,l2))
  574. else
  575. useReg := true;
  576. OP_XOR:
  577. do_lo_hi;
  578. OP_SHL,OP_SHR,OP_SAR:
  579. begin
  580. if (a and 31) <> 0 Then
  581. list.concat(taicpu.op_reg_reg_const(
  582. TOpCG2AsmOpConstLo[Op],dst,src,a and 31));
  583. if (a shr 5) <> 0 then
  584. internalError(68991);
  585. end
  586. else
  587. internalerror(200109091);
  588. end;
  589. { if all else failed, load the constant in a register and then }
  590. { perform the operation }
  591. if useReg then
  592. begin
  593. scratchreg := get_scratch_reg_int(list,OS_INT);
  594. a_load_const_reg(list,OS_32,a,scratchreg);
  595. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  596. free_scratch_reg(list,scratchreg);
  597. end;
  598. end;
  599. procedure tcgppc.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  600. size: tcgsize; src1, src2, dst: tregister);
  601. const
  602. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  603. (A_NONE,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  604. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  605. begin
  606. case op of
  607. OP_NEG,OP_NOT:
  608. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,dst));
  609. else
  610. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  611. end;
  612. end;
  613. {*************** compare instructructions ****************}
  614. procedure tcgppc.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  615. l : tasmlabel);
  616. var
  617. p: taicpu;
  618. scratch_register: TRegister;
  619. signed: boolean;
  620. r:Tregister;
  621. begin
  622. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE];
  623. { in the following case, we generate more efficient code when }
  624. { signed is true }
  625. if (cmp_op in [OC_EQ,OC_NE]) and
  626. (a > $ffff) then
  627. signed := true;
  628. r.enum:=R_CR0;
  629. if signed then
  630. if (longint(a) >= low(smallint)) and (longint(a) <= high(smallint)) Then
  631. list.concat(taicpu.op_reg_reg_const(A_CMPWI,r,reg,longint(a)))
  632. else
  633. begin
  634. scratch_register := get_scratch_reg_int(list,OS_INT);
  635. a_load_const_reg(list,OS_32,a,scratch_register);
  636. list.concat(taicpu.op_reg_reg_reg(A_CMPW,r,reg,scratch_register));
  637. free_scratch_reg(list,scratch_register);
  638. end
  639. else
  640. if (a <= $ffff) then
  641. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,r,reg,a))
  642. else
  643. begin
  644. scratch_register := get_scratch_reg_int(list,OS_32);
  645. a_load_const_reg(list,OS_32,a,scratch_register);
  646. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,r,reg,scratch_register));
  647. free_scratch_reg(list,scratch_register);
  648. end;
  649. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  650. end;
  651. procedure tcgppc.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  652. reg1,reg2 : tregister;l : tasmlabel);
  653. var
  654. p: taicpu;
  655. op: tasmop;
  656. r:Tregister;
  657. begin
  658. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  659. op := A_CMPW
  660. else op := A_CMPLW;
  661. r.enum:=R_CR0;
  662. list.concat(taicpu.op_reg_reg_reg(op,r,reg1,reg2));
  663. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  664. end;
  665. procedure tcgppc.g_save_standard_registers(list : taasmoutput; usedinproc : Tsupregset);
  666. begin
  667. {$warning FIX ME}
  668. end;
  669. procedure tcgppc.g_restore_standard_registers(list : taasmoutput; usedinproc : Tsupregset);
  670. begin
  671. {$warning FIX ME}
  672. end;
  673. procedure tcgppc.g_save_all_registers(list : taasmoutput);
  674. begin
  675. {$warning FIX ME}
  676. end;
  677. procedure tcgppc.g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);
  678. begin
  679. {$warning FIX ME}
  680. end;
  681. procedure tcgppc.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  682. begin
  683. a_jmp(list,A_BC,TOpCmp2AsmCond[cond],0,l);
  684. end;
  685. procedure tcgppc.a_jmp_always(list : taasmoutput;l: tasmlabel);
  686. begin
  687. a_jmp(list,A_B,C_None,0,l);
  688. end;
  689. procedure tcgppc.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  690. var
  691. c: tasmcond;
  692. r:Tregister;
  693. begin
  694. c := flags_to_cond(f);
  695. r.enum:=R_CR0;
  696. a_jmp(list,A_BC,c.cond,ord(c.cr)-ord(r.enum),l);
  697. end;
  698. procedure tcgppc.g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister);
  699. var
  700. testbit: byte;
  701. bitvalue: boolean;
  702. begin
  703. { get the bit to extract from the conditional register + its }
  704. { requested value (0 or 1) }
  705. testbit := ((ord(f.cr)-ord(R_CR0)) * 4);
  706. case f.flag of
  707. F_EQ,F_NE:
  708. bitvalue := f.flag = F_EQ;
  709. F_LT,F_GE:
  710. begin
  711. inc(testbit);
  712. bitvalue := f.flag = F_LT;
  713. end;
  714. F_GT,F_LE:
  715. begin
  716. inc(testbit,2);
  717. bitvalue := f.flag = F_GT;
  718. end;
  719. else
  720. internalerror(200112261);
  721. end;
  722. { load the conditional register in the destination reg }
  723. list.concat(taicpu.op_reg(A_MFCR,reg));
  724. { we will move the bit that has to be tested to bit 0 by rotating }
  725. { left }
  726. testbit := (32 - testbit) and 31;
  727. { extract bit }
  728. list.concat(taicpu.op_reg_reg_const_const_const(
  729. A_RLWINM,reg,reg,testbit,31,31));
  730. { if we need the inverse, xor with 1 }
  731. if not bitvalue then
  732. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  733. end;
  734. (*
  735. procedure tcgppc.g_cond2reg(list: taasmoutput; const f: TAsmCond; reg: TRegister);
  736. var
  737. testbit: byte;
  738. bitvalue: boolean;
  739. begin
  740. { get the bit to extract from the conditional register + its }
  741. { requested value (0 or 1) }
  742. case f.simple of
  743. false:
  744. begin
  745. { we don't generate this in the compiler }
  746. internalerror(200109062);
  747. end;
  748. true:
  749. case f.cond of
  750. C_None:
  751. internalerror(200109063);
  752. C_LT..C_NU:
  753. begin
  754. testbit := (ord(f.cr) - ord(R_CR0))*4;
  755. inc(testbit,AsmCondFlag2BI[f.cond]);
  756. bitvalue := AsmCondFlagTF[f.cond];
  757. end;
  758. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  759. begin
  760. testbit := f.crbit
  761. bitvalue := AsmCondFlagTF[f.cond];
  762. end;
  763. else
  764. internalerror(200109064);
  765. end;
  766. end;
  767. { load the conditional register in the destination reg }
  768. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  769. { we will move the bit that has to be tested to bit 31 -> rotate }
  770. { left by bitpos+1 (remember, this is big-endian!) }
  771. if bitpos <> 31 then
  772. inc(bitpos)
  773. else
  774. bitpos := 0;
  775. { extract bit }
  776. list.concat(taicpu.op_reg_reg_const_const_const(
  777. A_RLWINM,reg,reg,bitpos,31,31));
  778. { if we need the inverse, xor with 1 }
  779. if not bitvalue then
  780. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  781. end;
  782. *)
  783. { *********** entry/exit code and address loading ************ }
  784. procedure tcgppc.g_stackframe_entry(list : taasmoutput;localsize : longint);
  785. begin
  786. case target_info.system of
  787. system_powerpc_macos:
  788. g_stackframe_entry_mac(list,localsize);
  789. system_powerpc_linux:
  790. g_stackframe_entry_sysv(list,localsize)
  791. else
  792. internalerror(2204001);
  793. end;
  794. end;
  795. procedure tcgppc.g_return_from_proc(list : taasmoutput;parasize : aword);
  796. begin
  797. case target_info.system of
  798. system_powerpc_macos:
  799. g_return_from_proc_mac(list,parasize);
  800. system_powerpc_linux:
  801. g_return_from_proc_sysv(list,parasize)
  802. else
  803. internalerror(2204001);
  804. end;
  805. end;
  806. procedure tcgppc.g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  807. { generated the entry code of a procedure/function. Note: localsize is the }
  808. { sum of the size necessary for local variables and the maximum possible }
  809. { combined size of ALL the parameters of a procedure called by the current }
  810. { one }
  811. var regcounter,firstregfpu,firstreggpr: TRegister;
  812. href : treference;
  813. usesfpr,usesgpr,gotgot : boolean;
  814. parastart : aword;
  815. offset : aword;
  816. r,r2,rsp:Tregister;
  817. regcounter2: Tsuperregister;
  818. begin
  819. { we do our own localsize calculation }
  820. localsize:=0;
  821. { CR and LR only have to be saved in case they are modified by the current }
  822. { procedure, but currently this isn't checked, so save them always }
  823. { following is the entry code as described in "Altivec Programming }
  824. { Interface Manual", bar the saving of AltiVec registers }
  825. rsp.enum:=R_INTREGISTER;
  826. rsp.number:=NR_STACK_POINTER_REG;;
  827. a_reg_alloc(list,rsp);
  828. r.enum:=R_INTREGISTER;
  829. r.number:=NR_R0;
  830. a_reg_alloc(list,r);
  831. { allocate registers containing reg parameters }
  832. r.enum := R_INTREGISTER;
  833. for regcounter2 := RS_R3 to RS_R10 do
  834. begin
  835. r.number:=regcounter2 shl 8;
  836. a_reg_alloc(list,r);
  837. end;
  838. usesfpr:=false;
  839. for regcounter.enum:=R_F14 to R_F31 do
  840. if regcounter.enum in rg.usedbyproc then
  841. begin
  842. usesfpr:=true;
  843. firstregfpu:=regcounter;
  844. break;
  845. end;
  846. usesgpr:=false;
  847. for regcounter2:=RS_R14 to RS_R31 do
  848. begin
  849. if regcounter2 in rg.usedintbyproc then
  850. begin
  851. usesgpr:=true;
  852. firstreggpr.enum := R_INTREGISTER;
  853. firstreggpr.number := regcounter2 shl 8;
  854. break;
  855. end;
  856. end;
  857. { save link register? }
  858. if (procinfo.flags and pi_do_call)<>0 then
  859. begin
  860. { save return address... }
  861. r.enum:=R_INTREGISTER;
  862. r.number:=NR_R0;
  863. list.concat(taicpu.op_reg(A_MFLR,r));
  864. { ... in caller's rframe }
  865. reference_reset_base(href,rsp,4);
  866. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  867. a_reg_dealloc(list,r);
  868. end;
  869. if usesfpr or usesgpr then
  870. begin
  871. r.enum:=R_INTREGISTER;
  872. r.number:=NR_R11;
  873. a_reg_alloc(list,r);
  874. { save end of fpr save area }
  875. list.concat(taicpu.op_reg_reg(A_MR,r,rsp));
  876. end;
  877. { calculate the size of the locals }
  878. if usesgpr then
  879. inc(localsize,((NR_R31-firstreggpr.number) shr 8+1)*4);
  880. if usesfpr then
  881. inc(localsize,(ord(R_F31)-ord(firstregfpu.enum)+1)*8);
  882. { align to 16 bytes }
  883. localsize:=align(localsize,16);
  884. inc(localsize,tg.lasttemp);
  885. localsize:=align(localsize,16);
  886. tppcprocinfo(procinfo).localsize:=localsize;
  887. r.enum:=R_INTREGISTER;
  888. r.number:=NR_STACK_POINTER_REG;
  889. reference_reset_base(href,r,-localsize);
  890. a_load_store(list,A_STWU,r,href);
  891. { no GOT pointer loaded yet }
  892. gotgot:=false;
  893. if usesfpr then
  894. begin
  895. { save floating-point registers
  896. if (cs_create_pic in aktmoduleswitches) and not(usesgpr) then
  897. begin
  898. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g');
  899. gotgot:=true;
  900. end
  901. else
  902. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14));
  903. }
  904. for regcounter.enum:=firstregfpu.enum to R_F31 do
  905. if regcounter.enum in rg.usedbyproc then
  906. begin
  907. { reference_reset_base(href,R_1,-localsize);
  908. a_load_store(list,A_STWU,R_1,href);
  909. }
  910. end;
  911. { compute end of gpr save area }
  912. r.enum:=R_INTREGISTER;
  913. r.number:=NR_R11;
  914. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,-(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  915. end;
  916. { save gprs and fetch GOT pointer }
  917. if usesgpr then
  918. begin
  919. {
  920. if cs_create_pic in aktmoduleswitches then
  921. begin
  922. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g');
  923. gotgot:=true;
  924. end
  925. else
  926. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
  927. }
  928. r.enum:=R_INTREGISTER;
  929. r.number:=NR_R11;
  930. reference_reset_base(href,r,-((NR_R31-firstreggpr.number) shr 8+1)*4);
  931. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  932. end;
  933. r.enum:=R_INTREGISTER;
  934. r.number:=NR_R11;
  935. if usesfpr or usesgpr then
  936. a_reg_dealloc(list,r);
  937. { PIC code support, }
  938. if cs_create_pic in aktmoduleswitches then
  939. begin
  940. { if we didn't get the GOT pointer till now, we've to calculate it now }
  941. if not(gotgot) then
  942. begin
  943. {!!!!!!!!!!!!!}
  944. end;
  945. r.enum:=R_INTREGISTER;
  946. r.number:=NR_R31;
  947. r2.enum:=R_LR;
  948. a_reg_alloc(list,r);
  949. { place GOT ptr in r31 }
  950. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  951. end;
  952. { save the CR if necessary ( !!! always done currently ) }
  953. { still need to find out where this has to be done for SystemV
  954. a_reg_alloc(list,R_0);
  955. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  956. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  957. new_reference(STACK_POINTER_REG,LA_CR)));
  958. a_reg_dealloc(list,R_0); }
  959. { now comes the AltiVec context save, not yet implemented !!! }
  960. end;
  961. procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  962. var
  963. regcounter,firstregfpu,firstreggpr: TRegister;
  964. href : treference;
  965. usesfpr,usesgpr,genret : boolean;
  966. r,r2:Tregister;
  967. regcounter2:Tsuperregister;
  968. begin
  969. { release parameter registers }
  970. r.enum := R_INTREGISTER;
  971. for regcounter2 := RS_R3 to RS_R10 do
  972. begin
  973. r.number:=regcounter2 shl 8;
  974. a_reg_dealloc(list,r);
  975. end;
  976. { AltiVec context restore, not yet implemented !!! }
  977. usesfpr:=false;
  978. for regcounter.enum:=R_F14 to R_F31 do
  979. if regcounter.enum in rg.usedbyproc then
  980. begin
  981. usesfpr:=true;
  982. firstregfpu:=regcounter;
  983. break;
  984. end;
  985. usesgpr:=false;
  986. for regcounter2:=RS_R14 to RS_R30 do
  987. begin
  988. if regcounter2 in rg.usedintbyproc then
  989. begin
  990. usesgpr:=true;
  991. firstreggpr.enum:=R_INTREGISTER;
  992. firstreggpr.number:=regcounter2 shl 8;
  993. break;
  994. end;
  995. end;
  996. { no return (blr) generated yet }
  997. genret:=true;
  998. if usesgpr then
  999. begin
  1000. { address of gpr save area to r11 }
  1001. r.enum:=R_INTREGISTER;
  1002. r.number:=NR_STACK_POINTER_REG;
  1003. r2.enum:=R_INTREGISTER;
  1004. r2.number:=NR_R11;
  1005. if usesfpr then
  1006. list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize-(ord(R_F31)-ord(firstregfpu.enum)+1)*8))
  1007. else
  1008. list.concat(taicpu.op_reg_reg_const(A_ADDI,r2,r,tppcprocinfo(procinfo).localsize));
  1009. { restore gprs }
  1010. { at least for now we use LMW }
  1011. {
  1012. a_call_name(objectlibrary.newasmsymbol('_restgpr_14');
  1013. }
  1014. reference_reset_base(href,r2,-((NR_R31-ord(firstreggpr.number)) shr 8+1)*4);
  1015. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1016. end;
  1017. { restore fprs and return }
  1018. if usesfpr then
  1019. begin
  1020. { address of fpr save area to r11 }
  1021. r.enum:=R_INTREGISTER;
  1022. r.number:=NR_R11;
  1023. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1024. {
  1025. if (procinfo.flags and pi_do_call)<>0 then
  1026. a_call_name(objectlibrary.newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  1027. '_x')
  1028. else
  1029. { leaf node => lr haven't to be restored }
  1030. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+
  1031. '_l');
  1032. genret:=false;
  1033. }
  1034. end;
  1035. { if we didn't generate the return code, we've to do it now }
  1036. if genret then
  1037. begin
  1038. { adjust r1 }
  1039. r.enum:=R_INTREGISTER;
  1040. r.number:=NR_R1;
  1041. a_op_const_reg(list,OP_ADD,tppcprocinfo(procinfo).localsize,r);
  1042. { load link register? }
  1043. if (procinfo.flags and pi_do_call)<>0 then
  1044. begin
  1045. r.enum:=R_INTREGISTER;
  1046. r.number:=NR_STACK_POINTER_REG;
  1047. reference_reset_base(href,r,4);
  1048. r.enum:=R_INTREGISTER;
  1049. r.number:=NR_R0;
  1050. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1051. list.concat(taicpu.op_reg(A_MTLR,r));
  1052. end;
  1053. list.concat(taicpu.op_none(A_BLR));
  1054. end;
  1055. end;
  1056. function save_regs(list : taasmoutput):longint;
  1057. {Generates code which saves used non-volatile registers in
  1058. the save area right below the address the stackpointer point to.
  1059. Returns the actual used save area size.}
  1060. var regcounter,firstregfpu,firstreggpr: TRegister;
  1061. usesfpr,usesgpr: boolean;
  1062. href : treference;
  1063. offset: integer;
  1064. r,r2:Tregister;
  1065. regcounter2: Tsuperregister;
  1066. begin
  1067. usesfpr:=false;
  1068. for regcounter.enum:=R_F14 to R_F31 do
  1069. if regcounter.enum in rg.usedbyproc then
  1070. begin
  1071. usesfpr:=true;
  1072. firstregfpu:=regcounter;
  1073. break;
  1074. end;
  1075. usesgpr:=false;
  1076. for regcounter2:=RS_R13 to RS_R31 do
  1077. begin
  1078. if regcounter2 in rg.usedintbyproc then
  1079. begin
  1080. usesgpr:=true;
  1081. firstreggpr.enum:=R_INTREGISTER;
  1082. firstreggpr.number:=regcounter2 shl 8;
  1083. break;
  1084. end;
  1085. end;
  1086. offset:= 0;
  1087. { save floating-point registers }
  1088. if usesfpr then
  1089. for regcounter.enum := firstregfpu.enum to R_F31 do
  1090. begin
  1091. offset:= offset - 8;
  1092. r.enum:=R_INTREGISTER;
  1093. r.number:=NR_STACK_POINTER_REG;
  1094. reference_reset_base(href, r, offset);
  1095. list.concat(taicpu.op_reg_ref(A_STFD, regcounter, href));
  1096. end;
  1097. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1098. { save gprs in gpr save area }
  1099. if usesgpr then
  1100. if firstreggpr.enum < R_30 then
  1101. begin
  1102. offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
  1103. r.enum:=R_INTREGISTER;
  1104. r.number:=NR_STACK_POINTER_REG;
  1105. reference_reset_base(href,r,offset);
  1106. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  1107. {STMW stores multiple registers}
  1108. end
  1109. else
  1110. begin
  1111. r.enum:=R_INTREGISTER;
  1112. r.number:=NR_STACK_POINTER_REG;
  1113. r2 := firstreggpr;
  1114. convert_register_to_enum(firstreggpr);
  1115. for regcounter.enum := firstreggpr.enum to R_31 do
  1116. begin
  1117. offset:= offset - 4;
  1118. reference_reset_base(href, r, offset);
  1119. list.concat(taicpu.op_reg_ref(A_STW, r2, href));
  1120. inc(r2.number,NR_R1-NR_R0);
  1121. end;
  1122. end;
  1123. { now comes the AltiVec context save, not yet implemented !!! }
  1124. save_regs:= -offset;
  1125. end;
  1126. procedure restore_regs(list : taasmoutput);
  1127. {Generates code which restores used non-volatile registers from
  1128. the save area right below the address the stackpointer point to.}
  1129. var regcounter,firstregfpu,firstreggpr: TRegister;
  1130. usesfpr,usesgpr: boolean;
  1131. href : treference;
  1132. offset: integer;
  1133. r,r2:Tregister;
  1134. regcounter2: Tsuperregister;
  1135. begin
  1136. usesfpr:=false;
  1137. for regcounter.enum:=R_F14 to R_F31 do
  1138. if regcounter.enum in rg.usedbyproc then
  1139. begin
  1140. usesfpr:=true;
  1141. firstregfpu:=regcounter;
  1142. break;
  1143. end;
  1144. usesgpr:=false;
  1145. for regcounter2:=RS_R13 to RS_R31 do
  1146. begin
  1147. if regcounter2 in rg.usedintbyproc then
  1148. begin
  1149. usesgpr:=true;
  1150. firstreggpr.enum:=R_INTREGISTER;
  1151. firstreggpr.number:=regcounter2 shl 8;
  1152. break;
  1153. end;
  1154. inc(r.number,NR_R1-NR_R0);
  1155. end;
  1156. offset:= 0;
  1157. { restore fp registers }
  1158. if usesfpr then
  1159. for regcounter.enum := firstregfpu.enum to R_F31 do
  1160. begin
  1161. offset:= offset - 8;
  1162. r.enum:=R_INTREGISTER;
  1163. r.number:=NR_STACK_POINTER_REG;
  1164. reference_reset_base(href, r, offset);
  1165. list.concat(taicpu.op_reg_ref(A_LFD, regcounter, href));
  1166. end;
  1167. (* Optimiztion in the future: a_call_name(list,'_restfXX'); *)
  1168. { restore gprs }
  1169. if usesgpr then
  1170. if firstreggpr.enum < R_30 then
  1171. begin
  1172. offset:= offset - 4 * (ord(R_31) - ord(firstreggpr.enum) + 1);
  1173. r.enum:=R_INTREGISTER;
  1174. r.number:=NR_STACK_POINTER_REG;
  1175. reference_reset_base(href,r,offset); //-220
  1176. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1177. {LMW loads multiple registers}
  1178. end
  1179. else
  1180. begin
  1181. r.enum:=R_INTREGISTER;
  1182. r.number:=NR_STACK_POINTER_REG;
  1183. r2 := firstreggpr;
  1184. convert_register_to_enum(firstreggpr);
  1185. for regcounter.enum := firstreggpr.enum to R_31 do
  1186. begin
  1187. offset:= offset - 4;
  1188. reference_reset_base(href, r, offset);
  1189. list.concat(taicpu.op_reg_ref(A_LWZ, r2, href));
  1190. inc(r2.number,NR_R1-NR_R0);
  1191. end;
  1192. end;
  1193. { now comes the AltiVec context restore, not yet implemented !!! }
  1194. end;
  1195. procedure tcgppc.g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  1196. { generated the entry code of a procedure/function. Note: localsize is the }
  1197. { sum of the size necessary for local variables and the maximum possible }
  1198. { combined size of ALL the parameters of a procedure called by the current }
  1199. { one }
  1200. const
  1201. macosLinkageAreaSize = 24;
  1202. var regcounter: TRegister;
  1203. href : treference;
  1204. registerSaveAreaSize : longint;
  1205. r,r2,rsp:Tregister;
  1206. regcounter2: Tsuperregister;
  1207. begin
  1208. if (localsize mod 8) <> 0 then internalerror(58991);
  1209. { CR and LR only have to be saved in case they are modified by the current }
  1210. { procedure, but currently this isn't checked, so save them always }
  1211. { following is the entry code as described in "Altivec Programming }
  1212. { Interface Manual", bar the saving of AltiVec registers }
  1213. r.enum:=R_INTREGISTER;
  1214. r.number:=NR_R0;
  1215. rsp.enum:=R_INTREGISTER;
  1216. rsp.number:=NR_STACK_POINTER_REG;
  1217. a_reg_alloc(list,rsp);
  1218. a_reg_alloc(list,r);
  1219. { allocate registers containing reg parameters }
  1220. r.enum := R_INTREGISTER;
  1221. for regcounter2 := RS_R3 to RS_R10 do
  1222. begin
  1223. r.number:=regcounter2 shl 8;
  1224. a_reg_alloc(list,r);
  1225. end;
  1226. {TODO: Allocate fp and altivec parameter registers also}
  1227. { save return address in callers frame}
  1228. r2.enum:=R_LR;
  1229. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  1230. { ... in caller's frame }
  1231. reference_reset_base(href,rsp,8);
  1232. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  1233. a_reg_dealloc(list,r);
  1234. { save non-volatile registers in callers frame}
  1235. registerSaveAreaSize:= save_regs(list);
  1236. { save the CR if necessary in callers frame ( !!! always done currently ) }
  1237. a_reg_alloc(list,r);
  1238. r2.enum:=R_CR;
  1239. list.concat(taicpu.op_reg_reg(A_MFSPR,r,r2));
  1240. reference_reset_base(href,rsp,LA_CR);
  1241. list.concat(taicpu.op_reg_ref(A_STW,r,href));
  1242. a_reg_dealloc(list,r);
  1243. (*
  1244. { save pointer to incoming arguments }
  1245. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  1246. *)
  1247. (*
  1248. a_reg_alloc(list,R_12);
  1249. { 0 or 8 based on SP alignment }
  1250. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  1251. R_12,STACK_POINTER_REG,0,28,28));
  1252. { add in stack length }
  1253. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1254. -localsize));
  1255. { establish new alignment }
  1256. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1257. a_reg_dealloc(list,R_12);
  1258. *)
  1259. { allocate stack frame }
  1260. localsize:= align(localsize + macosLinkageAreaSize + registerSaveAreaSize, 16);
  1261. inc(localsize,tg.lasttemp);
  1262. localsize:=align(localsize,16);
  1263. tppcprocinfo(procinfo).localsize:=localsize;
  1264. r.enum:=R_INTREGISTER;
  1265. r.number:=NR_STACK_POINTER_REG;
  1266. reference_reset_base(href,r,-localsize);
  1267. a_load_store(list,A_STWU,r,href);
  1268. { this also stores the old stack pointer in the new stack frame }
  1269. end;
  1270. procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  1271. var
  1272. regcounter: TRegister;
  1273. href : treference;
  1274. r,r2,rsp:Tregister;
  1275. regcounter2: Tsuperregister;
  1276. begin
  1277. { release parameter registers }
  1278. r.enum := R_INTREGISTER;
  1279. for regcounter2 := RS_R3 to RS_R10 do
  1280. begin
  1281. r.number := regcounter2 shl 8;
  1282. a_reg_dealloc(list,r);
  1283. end;
  1284. {TODO: Release fp and altivec parameter registers also}
  1285. r.enum:=R_INTREGISTER;
  1286. r.number:=NR_R0;
  1287. rsp.enum:=R_INTREGISTER;
  1288. rsp.number:=NR_STACK_POINTER_REG;
  1289. a_reg_alloc(list,r);
  1290. { restore stack pointer }
  1291. reference_reset_base(href,rsp,LA_SP);
  1292. list.concat(taicpu.op_reg_ref(A_LWZ,rsp,href));
  1293. (*
  1294. list.concat(taicpu.op_reg_reg_const(A_ORI,rsp,R_31,0));
  1295. *)
  1296. { restore the CR if necessary from callers frame
  1297. ( !!! always done currently ) }
  1298. reference_reset_base(href,rsp,LA_CR);
  1299. r.enum:=R_INTREGISTER;
  1300. r.number:=NR_R0;
  1301. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1302. r2.enum:=R_CR;
  1303. list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
  1304. a_reg_dealloc(list,r);
  1305. (*
  1306. { restore return address from callers frame }
  1307. reference_reset_base(href,STACK_POINTER_REG,8);
  1308. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1309. *)
  1310. { restore non-volatile registers from callers frame }
  1311. restore_regs(list);
  1312. (*
  1313. { return to caller }
  1314. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1315. list.concat(taicpu.op_none(A_BLR));
  1316. *)
  1317. { restore return address from callers frame }
  1318. r.enum:=R_INTREGISTER;
  1319. r.number:=NR_R0;
  1320. r2.enum:=R_LR;
  1321. reference_reset_base(href,rsp,8);
  1322. list.concat(taicpu.op_reg_ref(A_LWZ,r,href));
  1323. { return to caller }
  1324. list.concat(taicpu.op_reg_reg(A_MTSPR,r,r2));
  1325. list.concat(taicpu.op_none(A_BLR));
  1326. end;
  1327. procedure tcgppc.g_restore_frame_pointer(list : taasmoutput);
  1328. begin
  1329. { no frame pointer on the PowerPC (maybe there is one in the SystemV ABI?)}
  1330. end;
  1331. procedure tcgppc.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  1332. var
  1333. ref2, tmpref: treference;
  1334. freereg: boolean;
  1335. r2,tmpreg:Tregister;
  1336. begin
  1337. ref2 := ref;
  1338. freereg := fixref(list,ref2);
  1339. if assigned(ref2.symbol) then
  1340. begin
  1341. if target_info.system = system_powerpc_macos then
  1342. begin
  1343. if ref2.base.number <> NR_NO then
  1344. internalerror(2002103102); //TODO: Implement this if needed
  1345. if macos_direct_globals then
  1346. begin
  1347. reference_reset(tmpref);
  1348. tmpref.offset := ref2.offset;
  1349. tmpref.symbol := ref2.symbol;
  1350. tmpref.symaddr := refs_full;
  1351. tmpref.base.number := NR_NO;
  1352. r2.enum:=R_INTREGISTER;
  1353. r2.number:=NR_RTOC;
  1354. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r2,tmpref));
  1355. end
  1356. else
  1357. begin
  1358. reference_reset(tmpref);
  1359. tmpref.symbol := ref2.symbol;
  1360. tmpref.offset := 0; //ref2.offset;
  1361. tmpref.symaddr := refs_full;
  1362. tmpref.base.enum := R_INTREGISTER;
  1363. tmpref.base.number := NR_RTOC;
  1364. if ref2.offset = 0 then
  1365. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref))
  1366. else
  1367. begin
  1368. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref));
  1369. reference_reset(tmpref);
  1370. tmpref.offset := ref2.offset;
  1371. tmpref.symaddr := refs_full;
  1372. tmpref.base:= r;
  1373. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1374. (*
  1375. tmpreg := get_scratch_reg_address(list);
  1376. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1377. reference_reset(tmpref);
  1378. tmpref.offset := ref2.offset;
  1379. tmpref.symaddr := refs_full;
  1380. tmpref.base:= tmpreg;
  1381. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1382. free_scratch_reg(list,tmpreg);
  1383. *)
  1384. end;
  1385. end;
  1386. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1387. end
  1388. else
  1389. begin
  1390. { add the symbol's value to the base of the reference, and if the }
  1391. { reference doesn't have a base, create one }
  1392. reference_reset(tmpref);
  1393. tmpref.offset := ref2.offset;
  1394. tmpref.symbol := ref2.symbol;
  1395. tmpref.symaddr := refs_ha;
  1396. if ref2.base .number<> NR_NO then
  1397. begin
  1398. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1399. ref2.base,tmpref));
  1400. if freereg then
  1401. begin
  1402. cg.free_scratch_reg(list,ref2.base);
  1403. freereg := false;
  1404. end;
  1405. end
  1406. else
  1407. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1408. tmpref.base.number := NR_NO;
  1409. tmpref.symaddr := refs_l;
  1410. { can be folded with one of the next instructions by the }
  1411. { optimizer probably }
  1412. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1413. end
  1414. end
  1415. else if ref2.offset <> 0 Then
  1416. if ref2.base.number <> NR_NO then
  1417. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  1418. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1419. { occurs, so now only ref.offset has to be loaded }
  1420. else
  1421. a_load_const_reg(list,OS_32,ref2.offset,r)
  1422. else if ref.index.number <> NR_NO Then
  1423. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1424. else if (ref2.base.number <> NR_NO) and
  1425. (r.number <> ref2.base.number) then
  1426. list.concat(taicpu.op_reg_reg(A_MR,r,ref2.base));
  1427. if freereg then
  1428. cg.free_scratch_reg(list,ref2.base);
  1429. end;
  1430. { ************* concatcopy ************ }
  1431. procedure tcgppc.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  1432. var
  1433. countreg: TRegister;
  1434. src, dst: TReference;
  1435. lab: tasmlabel;
  1436. count, count2: aword;
  1437. orgsrc, orgdst: boolean;
  1438. r:Tregister;
  1439. begin
  1440. {$ifdef extdebug}
  1441. if len > high(longint) then
  1442. internalerror(2002072704);
  1443. {$endif extdebug}
  1444. { make sure short loads are handled as optimally as possible }
  1445. if not loadref then
  1446. if (len <= 8) and
  1447. (byte(len) in [1,2,4,8]) then
  1448. begin
  1449. if len < 8 then
  1450. begin
  1451. a_load_ref_ref(list,int_cgsize(len),source,dest);
  1452. if delsource then
  1453. reference_release(list,source);
  1454. end
  1455. else
  1456. begin
  1457. r.enum:=R_F0;
  1458. a_reg_alloc(list,r);
  1459. a_loadfpu_ref_reg(list,OS_F64,source,r);
  1460. if delsource then
  1461. reference_release(list,source);
  1462. a_loadfpu_reg_ref(list,OS_F64,r,dest);
  1463. a_reg_dealloc(list,r);
  1464. end;
  1465. exit;
  1466. end;
  1467. reference_reset(src);
  1468. reference_reset(dst);
  1469. { load the address of source into src.base }
  1470. if loadref then
  1471. begin
  1472. src.base := get_scratch_reg_address(list);
  1473. a_load_ref_reg(list,OS_32,source,src.base);
  1474. orgsrc := false;
  1475. end
  1476. else if not issimpleref(source) or
  1477. ((source.index.number <> NR_NO) and
  1478. ((source.offset + longint(len)) > high(smallint))) then
  1479. begin
  1480. src.base := get_scratch_reg_address(list);
  1481. a_loadaddr_ref_reg(list,source,src.base);
  1482. orgsrc := false;
  1483. end
  1484. else
  1485. begin
  1486. src := source;
  1487. orgsrc := true;
  1488. end;
  1489. if not orgsrc and delsource then
  1490. reference_release(list,source);
  1491. { load the address of dest into dst.base }
  1492. if not issimpleref(dest) or
  1493. ((dest.index.number <> NR_NO) and
  1494. ((dest.offset + longint(len)) > high(smallint))) then
  1495. begin
  1496. dst.base := get_scratch_reg_address(list);
  1497. a_loadaddr_ref_reg(list,dest,dst.base);
  1498. orgdst := false;
  1499. end
  1500. else
  1501. begin
  1502. dst := dest;
  1503. orgdst := true;
  1504. end;
  1505. count := len div 8;
  1506. if count > 4 then
  1507. { generate a loop }
  1508. begin
  1509. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1510. { have to be set to 8. I put an Inc there so debugging may be }
  1511. { easier (should offset be different from zero here, it will be }
  1512. { easy to notice in the generated assembler }
  1513. inc(dst.offset,8);
  1514. inc(src.offset,8);
  1515. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1516. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1517. countreg := get_scratch_reg_int(list,OS_INT);
  1518. a_load_const_reg(list,OS_32,count,countreg);
  1519. { explicitely allocate R_0 since it can be used safely here }
  1520. { (for holding date that's being copied) }
  1521. r.enum:=R_F0;
  1522. a_reg_alloc(list,r);
  1523. objectlibrary.getlabel(lab);
  1524. a_label(list, lab);
  1525. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1526. r.enum:=R_F0;
  1527. list.concat(taicpu.op_reg_ref(A_LFDU,r,src));
  1528. list.concat(taicpu.op_reg_ref(A_STFDU,r,dst));
  1529. a_jmp(list,A_BC,C_NE,0,lab);
  1530. free_scratch_reg(list,countreg);
  1531. a_reg_dealloc(list,r);
  1532. len := len mod 8;
  1533. end;
  1534. count := len div 8;
  1535. if count > 0 then
  1536. { unrolled loop }
  1537. begin
  1538. r.enum:=R_F0;
  1539. a_reg_alloc(list,r);
  1540. for count2 := 1 to count do
  1541. begin
  1542. a_loadfpu_ref_reg(list,OS_F64,src,r);
  1543. a_loadfpu_reg_ref(list,OS_F64,r,dst);
  1544. inc(src.offset,8);
  1545. inc(dst.offset,8);
  1546. end;
  1547. a_reg_dealloc(list,r);
  1548. len := len mod 8;
  1549. end;
  1550. if (len and 4) <> 0 then
  1551. begin
  1552. r.enum:=R_INTREGISTER;
  1553. r.number:=NR_R0;
  1554. a_reg_alloc(list,r);
  1555. a_load_ref_reg(list,OS_32,src,r);
  1556. a_load_reg_ref(list,OS_32,r,dst);
  1557. inc(src.offset,4);
  1558. inc(dst.offset,4);
  1559. a_reg_dealloc(list,r);
  1560. end;
  1561. { copy the leftovers }
  1562. if (len and 2) <> 0 then
  1563. begin
  1564. r.enum:=R_INTREGISTER;
  1565. r.number:=NR_R0;
  1566. a_reg_alloc(list,r);
  1567. a_load_ref_reg(list,OS_16,src,r);
  1568. a_load_reg_ref(list,OS_16,r,dst);
  1569. inc(src.offset,2);
  1570. inc(dst.offset,2);
  1571. a_reg_dealloc(list,r);
  1572. end;
  1573. if (len and 1) <> 0 then
  1574. begin
  1575. r.enum:=R_INTREGISTER;
  1576. r.number:=NR_R0;
  1577. a_reg_alloc(list,r);
  1578. a_load_ref_reg(list,OS_8,src,r);
  1579. a_load_reg_ref(list,OS_8,r,dst);
  1580. a_reg_dealloc(list,r);
  1581. end;
  1582. if orgsrc then
  1583. begin
  1584. if delsource then
  1585. reference_release(list,source);
  1586. end
  1587. else
  1588. free_scratch_reg(list,src.base);
  1589. if not orgdst then
  1590. free_scratch_reg(list,dst.base);
  1591. end;
  1592. procedure tcgppc.g_overflowcheck(list: taasmoutput; const p: tnode);
  1593. var
  1594. hl : tasmlabel;
  1595. r:Tregister;
  1596. begin
  1597. if not(cs_check_overflow in aktlocalswitches) then
  1598. exit;
  1599. objectlibrary.getlabel(hl);
  1600. if not ((p.resulttype.def.deftype=pointerdef) or
  1601. ((p.resulttype.def.deftype=orddef) and
  1602. (torddef(p.resulttype.def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1603. bool8bit,bool16bit,bool32bit]))) then
  1604. begin
  1605. r.enum:=R_CR7;
  1606. list.concat(taicpu.op_reg(A_MCRXR,r));
  1607. a_jmp(list,A_BC,C_OV,7,hl)
  1608. end
  1609. else
  1610. a_jmp_cond(list,OC_AE,hl);
  1611. a_call_name(list,'FPC_OVERFLOW');
  1612. a_label(list,hl);
  1613. end;
  1614. {***************** This is private property, keep out! :) *****************}
  1615. function tcgppc.issimpleref(const ref: treference): boolean;
  1616. begin
  1617. if (ref.base.number = NR_NO) and
  1618. (ref.index.number <> NR_NO) then
  1619. internalerror(200208101);
  1620. result :=
  1621. not(assigned(ref.symbol)) and
  1622. (((ref.index.number = NR_NO) and
  1623. (ref.offset >= low(smallint)) and
  1624. (ref.offset <= high(smallint))) or
  1625. ((ref.index.number <> NR_NO) and
  1626. (ref.offset = 0)));
  1627. end;
  1628. function tcgppc.fixref(list: taasmoutput; var ref: treference): boolean;
  1629. var
  1630. tmpreg: tregister;
  1631. begin
  1632. result := false;
  1633. if (ref.base.number = NR_NO) then
  1634. ref.base := ref.index;
  1635. if (ref.base.number <> NR_NO) then
  1636. begin
  1637. if (ref.index.number <> NR_NO) and
  1638. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1639. begin
  1640. result := true;
  1641. tmpreg := cg.get_scratch_reg_int(list,OS_INT);
  1642. if not assigned(ref.symbol) and
  1643. (cardinal(ref.offset-low(smallint)) <=
  1644. high(smallint)-low(smallint)) then
  1645. begin
  1646. list.concat(taicpu.op_reg_reg_const(
  1647. A_ADDI,tmpreg,ref.base,ref.offset));
  1648. ref.offset := 0;
  1649. end
  1650. else
  1651. begin
  1652. list.concat(taicpu.op_reg_reg_reg(
  1653. A_ADD,tmpreg,ref.base,ref.index));
  1654. ref.index.number := NR_NO;
  1655. end;
  1656. ref.base := tmpreg;
  1657. end
  1658. end
  1659. else
  1660. if ref.index.number <> NR_NO then
  1661. internalerror(200208102);
  1662. end;
  1663. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1664. { that's the case, we can use rlwinm to do an AND operation }
  1665. function tcgppc.get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  1666. var
  1667. temp : longint;
  1668. testbit : aword;
  1669. compare: boolean;
  1670. begin
  1671. get_rlwi_const := false;
  1672. if (a = 0) or (a = $ffffffff) then
  1673. exit;
  1674. { start with the lowest bit }
  1675. testbit := 1;
  1676. { check its value }
  1677. compare := boolean(a and testbit);
  1678. { find out how long the run of bits with this value is }
  1679. { (it's impossible that all bits are 1 or 0, because in that case }
  1680. { this function wouldn't have been called) }
  1681. l1 := 31;
  1682. while (((a and testbit) <> 0) = compare) do
  1683. begin
  1684. testbit := testbit shl 1;
  1685. dec(l1);
  1686. end;
  1687. { check the length of the run of bits that comes next }
  1688. compare := not compare;
  1689. l2 := l1;
  1690. while (((a and testbit) <> 0) = compare) and
  1691. (l2 >= 0) do
  1692. begin
  1693. testbit := testbit shl 1;
  1694. dec(l2);
  1695. end;
  1696. { and finally the check whether the rest of the bits all have the }
  1697. { same value }
  1698. compare := not compare;
  1699. temp := l2;
  1700. if temp >= 0 then
  1701. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1702. exit;
  1703. { we have done "not(not(compare))", so compare is back to its }
  1704. { initial value. If the lowest bit was 0, a is of the form }
  1705. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1706. { because l2 now contains the position of the last zero of the }
  1707. { first run instead of that of the first 1) so switch l1 and l2 }
  1708. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1709. if not compare then
  1710. begin
  1711. temp := l1;
  1712. l1 := l2+1;
  1713. l2 := temp;
  1714. end
  1715. else
  1716. { otherwise, l1 currently contains the position of the last }
  1717. { zero instead of that of the first 1 of the second run -> +1 }
  1718. inc(l1);
  1719. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1720. l1 := l1 and 31;
  1721. l2 := l2 and 31;
  1722. get_rlwi_const := true;
  1723. end;
  1724. procedure tcgppc.a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  1725. ref: treference);
  1726. var
  1727. tmpreg: tregister;
  1728. tmpref: treference;
  1729. r : Tregister;
  1730. begin
  1731. tmpreg.number := NR_NO;
  1732. if assigned(ref.symbol) or
  1733. (cardinal(ref.offset-low(smallint)) >
  1734. high(smallint)-low(smallint)) then
  1735. begin
  1736. if target_info.system = system_powerpc_macos then
  1737. begin
  1738. if ref.base.number <> NR_NO then
  1739. begin
  1740. if macos_direct_globals then
  1741. begin
  1742. {Generates
  1743. add tempreg, ref.base, RTOC
  1744. op reg, symbolplusoffset, tempreg
  1745. which is eqvivalent to the more comprehensive
  1746. addi tempreg, RTOC, symbolplusoffset
  1747. add tempreg, ref.base, tempreg
  1748. op reg, tempreg
  1749. but which saves one instruction.}
  1750. tmpreg := get_scratch_reg_address(list);
  1751. reference_reset(tmpref);
  1752. tmpref.symbol := ref.symbol;
  1753. tmpref.offset := ref.offset;
  1754. tmpref.symaddr := refs_full;
  1755. tmpref.base:= tmpreg;
  1756. r.enum:=R_INTREGISTER;
  1757. r.number:=NR_RTOC;
  1758. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1759. ref.base,r));
  1760. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1761. end
  1762. else
  1763. begin
  1764. tmpreg := get_scratch_reg_address(list);
  1765. reference_reset(tmpref);
  1766. tmpref.symbol := ref.symbol;
  1767. tmpref.offset := ref.offset;
  1768. tmpref.symaddr := refs_full;
  1769. tmpref.base.enum:= R_INTREGISTER;
  1770. tmpref.base.number:= NR_RTOC;
  1771. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1772. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1773. ref.base,tmpreg));
  1774. reference_reset(tmpref);
  1775. tmpref.offset := 0;
  1776. tmpref.symaddr := refs_full;
  1777. tmpref.base:= tmpreg;
  1778. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1779. end;
  1780. //list.concat(tai_comment.create(strpnew('**** a_load_store 1')));
  1781. end
  1782. else
  1783. begin
  1784. if macos_direct_globals then
  1785. begin
  1786. reference_reset(tmpref);
  1787. tmpref.symbol := ref.symbol;
  1788. tmpref.offset := ref.offset;
  1789. tmpref.symaddr := refs_full;
  1790. tmpref.base.enum:= R_INTREGISTER;
  1791. tmpref.base.number:= NR_RTOC;
  1792. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1793. end
  1794. else
  1795. begin
  1796. tmpreg := get_scratch_reg_address(list);
  1797. reference_reset(tmpref);
  1798. tmpref.symbol := ref.symbol;
  1799. tmpref.offset := ref.offset;
  1800. tmpref.symaddr := refs_full;
  1801. tmpref.base.enum:= R_INTREGISTER;
  1802. tmpref.base.number:= NR_RTOC;
  1803. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1804. reference_reset(tmpref);
  1805. tmpref.offset := 0;
  1806. tmpref.symaddr := refs_full;
  1807. tmpref.base:= tmpreg;
  1808. list.concat(taicpu.op_reg_ref(op,reg,tmpref));
  1809. end;
  1810. //list.concat(tai_comment.create(strpnew('*** a_load_store 2')));
  1811. end;
  1812. end
  1813. else
  1814. begin
  1815. tmpreg := get_scratch_reg_address(list);
  1816. reference_reset(tmpref);
  1817. tmpref.symbol := ref.symbol;
  1818. tmpref.offset := ref.offset;
  1819. tmpref.symaddr := refs_ha;
  1820. if ref.base.number <> NR_NO then
  1821. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1822. ref.base,tmpref))
  1823. else
  1824. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1825. ref.base := tmpreg;
  1826. ref.symaddr := refs_l;
  1827. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1828. end
  1829. end
  1830. else
  1831. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1832. if (tmpreg.number <> NR_NO) then
  1833. free_scratch_reg(list,tmpreg);
  1834. end;
  1835. procedure tcgppc.a_jmp(list: taasmoutput; op: tasmop; c: tasmcondflag;
  1836. crval: longint; l: tasmlabel);
  1837. var
  1838. p: taicpu;
  1839. begin
  1840. p := taicpu.op_sym(op,objectlibrary.newasmsymbol(l.name));
  1841. if op <> A_B then
  1842. create_cond_norm(c,crval,p.condition);
  1843. p.is_jmp := true;
  1844. list.concat(p)
  1845. end;
  1846. procedure tcg64fppc.a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);
  1847. begin
  1848. a_op64_reg_reg_reg(list,op,regsrc,regdst,regdst);
  1849. end;
  1850. procedure tcg64fppc.a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);
  1851. begin
  1852. a_op64_const_reg_reg(list,op,value,reg,reg);
  1853. end;
  1854. procedure tcg64fppc.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1855. begin
  1856. case op of
  1857. OP_AND,OP_OR,OP_XOR:
  1858. begin
  1859. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1860. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1861. end;
  1862. OP_ADD:
  1863. begin
  1864. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1865. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1866. end;
  1867. OP_SUB:
  1868. begin
  1869. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1870. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1871. end;
  1872. else
  1873. internalerror(2002072801);
  1874. end;
  1875. end;
  1876. procedure tcg64fppc.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);
  1877. const
  1878. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1879. (A_SUBIC,A_SUBC,A_ADDME));
  1880. var
  1881. tmpreg: tregister;
  1882. tmpreg64: tregister64;
  1883. issub: boolean;
  1884. begin
  1885. case op of
  1886. OP_AND,OP_OR,OP_XOR:
  1887. begin
  1888. cg.a_op_const_reg_reg(list,op,OS_32,cardinal(value),regsrc.reglo,regdst.reglo);
  1889. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1890. regdst.reghi);
  1891. end;
  1892. OP_ADD, OP_SUB:
  1893. begin
  1894. if (longint(value) <> 0) then
  1895. begin
  1896. issub := op = OP_SUB;
  1897. if (longint(value)-ord(issub) >= -32768) and
  1898. (longint(value)-ord(issub) <= 32767) then
  1899. begin
  1900. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1901. regdst.reglo,regsrc.reglo,longint(value)));
  1902. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1903. regdst.reghi,regsrc.reghi));
  1904. end
  1905. else if ((value shr 32) = 0) then
  1906. begin
  1907. tmpreg := cg.get_scratch_reg_int(list,OS_32);
  1908. cg.a_load_const_reg(list,OS_32,cardinal(value),tmpreg);
  1909. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  1910. regdst.reglo,regsrc.reglo,tmpreg));
  1911. cg.free_scratch_reg(list,tmpreg);
  1912. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1913. regdst.reghi,regsrc.reghi));
  1914. end
  1915. else
  1916. begin
  1917. tmpreg64.reglo := cg.get_scratch_reg_int(list,OS_INT);
  1918. tmpreg64.reghi := cg.get_scratch_reg_int(list,OS_INT);
  1919. a_load64_const_reg(list,value,tmpreg64);
  1920. a_op64_reg_reg_reg(list,op,tmpreg64,regsrc,regdst);
  1921. cg.free_scratch_reg(list,tmpreg64.reghi);
  1922. cg.free_scratch_reg(list,tmpreg64.reglo);
  1923. end
  1924. end
  1925. else
  1926. begin
  1927. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  1928. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1929. regdst.reghi);
  1930. end;
  1931. end;
  1932. else
  1933. internalerror(2002072802);
  1934. end;
  1935. end;
  1936. begin
  1937. cg := tcgppc.create;
  1938. cg64 :=tcg64fppc.create;
  1939. end.
  1940. {
  1941. $Log$
  1942. Revision 1.76 2003-03-22 18:01:13 jonas
  1943. * fixed linux entry/exit code generation
  1944. Revision 1.75 2003/03/19 14:26:26 jonas
  1945. * fixed R_TOC bugs introduced by new register allocator conversion
  1946. Revision 1.74 2003/03/13 22:57:45 olle
  1947. * change in a_loadaddr_ref_reg
  1948. Revision 1.73 2003/03/12 22:43:38 jonas
  1949. * more powerpc and generic fixes related to the new register allocator
  1950. Revision 1.72 2003/03/11 21:46:24 jonas
  1951. * lots of new regallocator fixes, both in generic and ppc-specific code
  1952. (ppc compiler still can't compile the linux system unit though)
  1953. Revision 1.71 2003/02/19 22:00:16 daniel
  1954. * Code generator converted to new register notation
  1955. - Horribily outdated todo.txt removed
  1956. Revision 1.70 2003/01/13 17:17:50 olle
  1957. * changed global var access, TOC now contain pointers to globals
  1958. * fixed handling of function pointers
  1959. Revision 1.69 2003/01/09 22:00:53 florian
  1960. * fixed some PowerPC issues
  1961. Revision 1.68 2003/01/08 18:43:58 daniel
  1962. * Tregister changed into a record
  1963. Revision 1.67 2002/12/15 19:22:01 florian
  1964. * fixed some crashes and a rte 201
  1965. Revision 1.66 2002/11/28 10:55:16 olle
  1966. * macos: changing code gen for references to globals
  1967. Revision 1.65 2002/11/07 15:50:23 jonas
  1968. * fixed bctr(l) problems
  1969. Revision 1.64 2002/11/04 18:24:19 olle
  1970. * macos: globals are located in TOC and relative r2, instead of absolute
  1971. Revision 1.63 2002/10/28 22:24:28 olle
  1972. * macos entry/exit: only used registers are saved
  1973. - macos entry/exit: stackptr not saved in r31 anymore
  1974. * macos entry/exit: misc fixes
  1975. Revision 1.62 2002/10/19 23:51:48 olle
  1976. * macos stack frame size computing updated
  1977. + macos epilogue: control register now restored
  1978. * macos prologue and epilogue: fp reg now saved and restored
  1979. Revision 1.61 2002/10/19 12:50:36 olle
  1980. * reorganized prologue and epilogue routines
  1981. Revision 1.60 2002/10/02 21:49:51 florian
  1982. * all A_BL instructions replaced by calls to a_call_name
  1983. Revision 1.59 2002/10/02 13:24:58 jonas
  1984. * changed a_call_* so that no superfluous code is generated anymore
  1985. Revision 1.58 2002/09/17 18:54:06 jonas
  1986. * a_load_reg_reg() now has two size parameters: source and dest. This
  1987. allows some optimizations on architectures that don't encode the
  1988. register size in the register name.
  1989. Revision 1.57 2002/09/10 21:22:25 jonas
  1990. + added some internal errors
  1991. * fixed bug in sysv exit code
  1992. Revision 1.56 2002/09/08 20:11:56 jonas
  1993. * fixed TOpCmp2AsmCond array (some unsigned equivalents were wrong)
  1994. Revision 1.55 2002/09/08 13:03:26 jonas
  1995. * several large offset-related fixes
  1996. Revision 1.54 2002/09/07 17:54:58 florian
  1997. * first part of PowerPC fixes
  1998. Revision 1.53 2002/09/07 15:25:14 peter
  1999. * old logs removed and tabs fixed
  2000. Revision 1.52 2002/09/02 10:14:51 jonas
  2001. + a_call_reg()
  2002. * small fix in a_call_ref()
  2003. Revision 1.51 2002/09/02 06:09:02 jonas
  2004. * fixed range error
  2005. Revision 1.50 2002/09/01 21:04:49 florian
  2006. * several powerpc related stuff fixed
  2007. Revision 1.49 2002/09/01 12:09:27 peter
  2008. + a_call_reg, a_call_loc added
  2009. * removed exprasmlist references
  2010. Revision 1.48 2002/08/31 21:38:02 jonas
  2011. * fixed a_call_ref (it should load ctr, not lr)
  2012. Revision 1.47 2002/08/31 21:30:45 florian
  2013. * fixed several problems caused by Jonas' commit :)
  2014. Revision 1.46 2002/08/31 19:25:50 jonas
  2015. + implemented a_call_ref()
  2016. Revision 1.45 2002/08/18 22:16:14 florian
  2017. + the ppc gas assembler writer adds now registers aliases
  2018. to the assembler file
  2019. Revision 1.44 2002/08/17 18:23:53 florian
  2020. * some assembler writer bugs fixed
  2021. Revision 1.43 2002/08/17 09:23:49 florian
  2022. * first part of procinfo rewrite
  2023. Revision 1.42 2002/08/16 14:24:59 carl
  2024. * issameref() to test if two references are the same (then emit no opcodes)
  2025. + ret_in_reg to replace ret_in_acc
  2026. (fix some register allocation bugs at the same time)
  2027. + save_std_register now has an extra parameter which is the
  2028. usedinproc registers
  2029. Revision 1.41 2002/08/15 08:13:54 carl
  2030. - a_load_sym_ofs_reg removed
  2031. * loadvmt now calls loadaddr_ref_reg instead
  2032. Revision 1.40 2002/08/11 14:32:32 peter
  2033. * renamed current_library to objectlibrary
  2034. Revision 1.39 2002/08/11 13:24:18 peter
  2035. * saving of asmsymbols in ppu supported
  2036. * asmsymbollist global is removed and moved into a new class
  2037. tasmlibrarydata that will hold the info of a .a file which
  2038. corresponds with a single module. Added librarydata to tmodule
  2039. to keep the library info stored for the module. In the future the
  2040. objectfiles will also be stored to the tasmlibrarydata class
  2041. * all getlabel/newasmsymbol and friends are moved to the new class
  2042. Revision 1.38 2002/08/11 11:39:31 jonas
  2043. + powerpc-specific genlinearlist
  2044. Revision 1.37 2002/08/10 17:15:31 jonas
  2045. * various fixes and optimizations
  2046. Revision 1.36 2002/08/06 20:55:23 florian
  2047. * first part of ppc calling conventions fix
  2048. Revision 1.35 2002/08/06 07:12:05 jonas
  2049. * fixed bug in g_flags2reg()
  2050. * and yet more constant operation fixes :)
  2051. Revision 1.34 2002/08/05 08:58:53 jonas
  2052. * fixed compilation problems
  2053. Revision 1.33 2002/08/04 12:57:55 jonas
  2054. * more misc. fixes, mostly constant-related
  2055. }