cgcpu.pas 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797
  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. symtype,
  23. cgbase,cgobj,
  24. aasmbase,aasmcpu,aasmtai,
  25. cpubase,cpuinfo,node,cg64f32,rgcpu;
  26. type
  27. tcgppc = class(tcg)
  28. procedure init_register_allocators;override;
  29. procedure done_register_allocators;override;
  30. procedure ungetreference(list:Taasmoutput;const r:Treference);override;
  31. { passing parameters, per default the parameter is pushed }
  32. { nr gives the number of the parameter (enumerated from }
  33. { left to right), this allows to move the parameter to }
  34. { register, if the cpu supports register calling }
  35. { conventions }
  36. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);override;
  37. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);override;
  38. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);override;
  39. procedure a_call_name(list : taasmoutput;const s : string);override;
  40. procedure a_call_reg(list : taasmoutput;reg: tregister); override;
  41. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister); override;
  42. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  43. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  44. size: tcgsize; a: aword; src, dst: tregister); override;
  45. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  46. size: tcgsize; src1, src2, dst: tregister); override;
  47. { move instructions }
  48. procedure a_load_const_reg(list : taasmoutput; size: tcgsize; a : aword;reg : tregister);override;
  49. procedure a_load_reg_ref(list : taasmoutput; fromsize, tosize: tcgsize; reg : tregister;const ref : treference);override;
  50. procedure a_load_ref_reg(list : taasmoutput; fromsize, tosize : tcgsize;const Ref : treference;reg : tregister);override;
  51. procedure a_load_reg_reg(list : taasmoutput; fromsize, tosize : tcgsize;reg1,reg2 : tregister);override;
  52. { fpu move instructions }
  53. procedure a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister); override;
  54. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  55. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  56. { comparison operations }
  57. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  58. l : tasmlabel);override;
  59. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  60. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  61. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  62. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister); override;
  63. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  64. procedure g_return_from_proc(list : taasmoutput;parasize : aword); override;
  65. procedure g_restore_frame_pointer(list : taasmoutput);override;
  66. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  67. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  68. procedure g_overflowcheck(list: taasmoutput; const l: tlocation; def: tdef); override;
  69. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  70. { that's the case, we can use rlwinm to do an AND operation }
  71. function get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  72. procedure g_save_standard_registers(list:Taasmoutput);override;
  73. procedure g_restore_standard_registers(list:Taasmoutput);override;
  74. procedure g_save_all_registers(list : taasmoutput);override;
  75. procedure g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);override;
  76. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  77. private
  78. (* NOT IN USE: *)
  79. procedure g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  80. (* NOT IN USE: *)
  81. procedure g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  82. { Make sure ref is a valid reference for the PowerPC and sets the }
  83. { base to the value of the index if (base = R_NO). }
  84. { Returns true if the reference contained a base, index and an }
  85. { offset or symbol, in which case the base will have been changed }
  86. { to a tempreg (which has to be freed by the caller) containing }
  87. { the sum of part of the original reference }
  88. function fixref(list: taasmoutput; var ref: treference): boolean;
  89. { returns whether a reference can be used immediately in a powerpc }
  90. { instruction }
  91. function issimpleref(const ref: treference): boolean;
  92. { contains the common code of a_load_reg_ref and a_load_ref_reg }
  93. procedure a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  94. ref: treference);
  95. { creates the correct branch instruction for a given combination }
  96. { of asmcondflags and destination addressing mode }
  97. procedure a_jmp(list: taasmoutput; op: tasmop;
  98. c: tasmcondflag; crval: longint; l: tasmlabel);
  99. function save_regs(list : taasmoutput):longint;
  100. procedure restore_regs(list : taasmoutput);
  101. end;
  102. tcg64fppc = class(tcg64f32)
  103. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);override;
  104. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);override;
  105. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);override;
  106. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);override;
  107. end;
  108. const
  109. TOpCG2AsmOpConstLo: Array[topcg] of TAsmOp = (A_NONE,A_ADDI,A_ANDI_,A_DIVWU,
  110. A_DIVW,A_MULLW, A_MULLW, A_NONE,A_NONE,A_ORI,
  111. A_SRAWI,A_SLWI,A_SRWI,A_SUBI,A_XORI);
  112. TOpCG2AsmOpConstHi: Array[topcg] of TAsmOp = (A_NONE,A_ADDIS,A_ANDIS_,
  113. A_DIVWU,A_DIVW, A_MULLW,A_MULLW,A_NONE,A_NONE,
  114. A_ORIS,A_NONE, A_NONE,A_NONE,A_SUBIS,A_XORIS);
  115. TOpCmp2AsmCond: Array[topcmp] of TAsmCondFlag = (C_NONE,C_EQ,C_GT,
  116. C_LT,C_GE,C_LE,C_NE,C_LE,C_LT,C_GE,C_GT);
  117. implementation
  118. uses
  119. globtype,globals,verbose,systems,cutils,
  120. symconst,symdef,symsym,
  121. rgobj,tgobj,cpupi,procinfo,paramgr;
  122. procedure tcgppc.init_register_allocators;
  123. begin
  124. inherited init_register_allocators;
  125. rg[R_INTREGISTER]:=trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  126. [RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
  127. RS_R9,RS_R10,RS_R11,RS_R12,RS_R31,RS_R30,RS_R29,
  128. RS_R28,RS_R27,RS_R26,RS_R25,RS_R24,RS_R23,RS_R22,
  129. RS_R21,RS_R20,RS_R19,RS_R18,RS_R17,RS_R16,RS_R15,
  130. RS_R14,RS_R13],first_int_imreg,[]);
  131. case target_info.abi of
  132. abi_powerpc_aix:
  133. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,
  134. [RS_F0,RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7,RS_F8,RS_F9,
  135. RS_F10,RS_F11,RS_F12,RS_F13,RS_F31,RS_F30,RS_F29,RS_F28,RS_F27,
  136. RS_F26,RS_F25,RS_F24,RS_F23,RS_F22,RS_F21,RS_F20,RS_F19,RS_F18,
  137. RS_F17,RS_F16,RS_F15,RS_F14],first_fpu_imreg,[]);
  138. abi_powerpc_sysv:
  139. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,
  140. [RS_F0,RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7,RS_F8,RS_F9,
  141. RS_F31,RS_F30,RS_F29,RS_F28,RS_F27,RS_F26,RS_F25,RS_F24,RS_F23,
  142. RS_F22,RS_F21,RS_F20,RS_F19,RS_F18,RS_F17,RS_F16,RS_F15,RS_F14,
  143. RS_F13,RS_F12,RS_F11,RS_F10],first_fpu_imreg,[]);
  144. else
  145. internalerror(2003122903);
  146. end;
  147. {$warning FIX ME}
  148. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,
  149. [RS_M0,RS_M1,RS_M2],first_mm_imreg,[]);
  150. end;
  151. procedure tcgppc.done_register_allocators;
  152. begin
  153. rg[R_INTREGISTER].free;
  154. rg[R_FPUREGISTER].free;
  155. rg[R_MMREGISTER].free;
  156. inherited done_register_allocators;
  157. end;
  158. procedure tcgppc.ungetreference(list:Taasmoutput;const r:Treference);
  159. begin
  160. if r.base<>NR_NO then
  161. ungetregister(list,r.base);
  162. if r.index<>NR_NO then
  163. ungetregister(list,r.index);
  164. end;
  165. procedure tcgppc.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  166. var
  167. ref: treference;
  168. begin
  169. case locpara.loc of
  170. LOC_REGISTER,LOC_CREGISTER:
  171. a_load_const_reg(list,size,a,locpara.register);
  172. LOC_REFERENCE:
  173. begin
  174. reference_reset(ref);
  175. ref.base:=locpara.reference.index;
  176. ref.offset:=locpara.reference.offset;
  177. a_load_const_ref(list,size,a,ref);
  178. end;
  179. else
  180. internalerror(2002081101);
  181. end;
  182. end;
  183. procedure tcgppc.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  184. var
  185. ref: treference;
  186. tmpreg: tregister;
  187. begin
  188. case locpara.loc of
  189. LOC_REGISTER,LOC_CREGISTER:
  190. a_load_ref_reg(list,size,size,r,locpara.register);
  191. LOC_REFERENCE:
  192. begin
  193. reference_reset(ref);
  194. ref.base:=locpara.reference.index;
  195. ref.offset:=locpara.reference.offset;
  196. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  197. a_load_ref_reg(list,size,size,r,tmpreg);
  198. a_load_reg_ref(list,size,size,tmpreg,ref);
  199. rg[R_INTREGISTER].ungetregister(list,tmpreg);
  200. end;
  201. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  202. case size of
  203. OS_F32, OS_F64:
  204. a_loadfpu_ref_reg(list,size,r,locpara.register);
  205. else
  206. internalerror(2002072801);
  207. end;
  208. else
  209. internalerror(2002081103);
  210. end;
  211. end;
  212. procedure tcgppc.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  213. var
  214. ref: treference;
  215. tmpreg: tregister;
  216. begin
  217. case locpara.loc of
  218. LOC_REGISTER,LOC_CREGISTER:
  219. a_loadaddr_ref_reg(list,r,locpara.register);
  220. LOC_REFERENCE:
  221. begin
  222. reference_reset(ref);
  223. ref.base := locpara.reference.index;
  224. ref.offset := locpara.reference.offset;
  225. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  226. a_loadaddr_ref_reg(list,r,tmpreg);
  227. a_load_reg_ref(list,OS_ADDR,OS_ADDR,tmpreg,ref);
  228. rg[R_INTREGISTER].ungetregister(list,tmpreg);
  229. end;
  230. else
  231. internalerror(2002080701);
  232. end;
  233. end;
  234. { calling a procedure by name }
  235. procedure tcgppc.a_call_name(list : taasmoutput;const s : string);
  236. var
  237. href : treference;
  238. begin
  239. { MacOS: The linker on MacOS (PPCLink) inserts a call to glue code,
  240. if it is a cross-TOC call. If so, it also replaces the NOP
  241. with some restore code.}
  242. list.concat(taicpu.op_sym(A_BL,objectlibrary.newasmsymbol(s)));
  243. if target_info.system=system_powerpc_macos then
  244. list.concat(taicpu.op_none(A_NOP));
  245. if not(pi_do_call in current_procinfo.flags) then
  246. internalerror(2003060703);
  247. end;
  248. { calling a procedure by address }
  249. procedure tcgppc.a_call_reg(list : taasmoutput;reg: tregister);
  250. var
  251. tmpreg : tregister;
  252. tmpref : treference;
  253. begin
  254. if target_info.system=system_powerpc_macos then
  255. begin
  256. {Generate instruction to load the procedure address from
  257. the transition vector.}
  258. //TODO: Support cross-TOC calls.
  259. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  260. reference_reset(tmpref);
  261. tmpref.offset := 0;
  262. //tmpref.symaddr := refs_full;
  263. tmpref.base:= reg;
  264. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  265. list.concat(taicpu.op_reg(A_MTCTR,tmpreg));
  266. rg[R_INTREGISTER].ungetregister(list,tmpreg);
  267. end
  268. else
  269. list.concat(taicpu.op_reg(A_MTCTR,reg));
  270. list.concat(taicpu.op_none(A_BCTRL));
  271. //if target_info.system=system_powerpc_macos then
  272. // //NOP is not needed here.
  273. // list.concat(taicpu.op_none(A_NOP));
  274. if not(pi_do_call in current_procinfo.flags) then
  275. internalerror(2003060704);
  276. //list.concat(tai_comment.create(strpnew('***** a_call_reg')));
  277. end;
  278. {********************** load instructions ********************}
  279. procedure tcgppc.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  280. begin
  281. if not(size in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  282. internalerror(2002090902);
  283. if (longint(a) >= low(smallint)) and
  284. (longint(a) <= high(smallint)) then
  285. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a)))
  286. else if ((a and $ffff) <> 0) then
  287. begin
  288. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a and $ffff)));
  289. if ((a shr 16) <> 0) or
  290. (smallint(a and $ffff) < 0) then
  291. list.concat(taicpu.op_reg_reg_const(A_ADDIS,reg,reg,
  292. smallint((a shr 16)+ord(smallint(a and $ffff) < 0))))
  293. end
  294. else
  295. list.concat(taicpu.op_reg_const(A_LIS,reg,smallint(a shr 16)));
  296. end;
  297. procedure tcgppc.a_load_reg_ref(list : taasmoutput; fromsize, tosize: TCGSize; reg : tregister;const ref : treference);
  298. const
  299. StoreInstr: Array[OS_8..OS_32,boolean, boolean] of TAsmOp =
  300. { indexed? updating?}
  301. (((A_STB,A_STBU),(A_STBX,A_STBUX)),
  302. ((A_STH,A_STHU),(A_STHX,A_STHUX)),
  303. ((A_STW,A_STWU),(A_STWX,A_STWUX)));
  304. var
  305. op: TAsmOp;
  306. ref2: TReference;
  307. freereg: boolean;
  308. begin
  309. ref2 := ref;
  310. freereg := fixref(list,ref2);
  311. if tosize in [OS_S8..OS_S16] then
  312. { storing is the same for signed and unsigned values }
  313. tosize := tcgsize(ord(tosize)-(ord(OS_S8)-ord(OS_8)));
  314. { 64 bit stuff should be handled separately }
  315. if tosize in [OS_64,OS_S64] then
  316. internalerror(200109236);
  317. op := storeinstr[tcgsize2unsigned[tosize],ref2.index<>NR_NO,false];
  318. a_load_store(list,op,reg,ref2);
  319. if freereg then
  320. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  321. End;
  322. procedure tcgppc.a_load_ref_reg(list : taasmoutput; fromsize,tosize : tcgsize;const ref: treference;reg : tregister);
  323. const
  324. LoadInstr: Array[OS_8..OS_S32,boolean, boolean] of TAsmOp =
  325. { indexed? updating?}
  326. (((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  327. ((A_LHZ,A_LHZU),(A_LHZX,A_LHZUX)),
  328. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)),
  329. { 64bit stuff should be handled separately }
  330. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  331. { 128bit stuff too }
  332. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  333. { there's no load-byte-with-sign-extend :( }
  334. ((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  335. ((A_LHA,A_LHAU),(A_LHAX,A_LHAUX)),
  336. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)));
  337. var
  338. op: tasmop;
  339. tmpreg: tregister;
  340. ref2, tmpref: treference;
  341. freereg: boolean;
  342. begin
  343. { TODO: optimize/take into consideration fromsize/tosize. Will }
  344. { probably only matter for OS_S8 loads though }
  345. if not(fromsize in [OS_8,OS_S8,OS_16,OS_S16,OS_32,OS_S32]) then
  346. internalerror(2002090902);
  347. ref2 := ref;
  348. freereg := fixref(list,ref2);
  349. { the caller is expected to have adjusted the reference already }
  350. { in this case }
  351. if (TCGSize2Size[fromsize] >= TCGSize2Size[tosize]) then
  352. fromsize := tosize;
  353. op := loadinstr[fromsize,ref2.index<>NR_NO,false];
  354. a_load_store(list,op,reg,ref2);
  355. if freereg then
  356. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  357. { sign extend shortint if necessary, since there is no }
  358. { load instruction that does that automatically (JM) }
  359. if fromsize = OS_S8 then
  360. list.concat(taicpu.op_reg_reg(A_EXTSB,reg,reg));
  361. end;
  362. procedure tcgppc.a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);
  363. var
  364. instr: taicpu;
  365. begin
  366. case tosize of
  367. OS_8:
  368. instr := taicpu.op_reg_reg_const_const_const(A_RLWINM,
  369. reg2,reg1,0,31-8+1,31);
  370. OS_S8:
  371. instr := taicpu.op_reg_reg(A_EXTSB,reg2,reg1);
  372. OS_16:
  373. instr := taicpu.op_reg_reg_const_const_const(A_RLWINM,
  374. reg2,reg1,0,31-16+1,31);
  375. OS_S16:
  376. instr := taicpu.op_reg_reg(A_EXTSH,reg2,reg1);
  377. OS_32,OS_S32:
  378. instr := taicpu.op_reg_reg(A_MR,reg2,reg1);
  379. else internalerror(2002090901);
  380. end;
  381. list.concat(instr);
  382. rg[R_INTREGISTER].add_move_instruction(instr);
  383. end;
  384. procedure tcgppc.a_loadfpu_reg_reg(list: taasmoutput; size: tcgsize; reg1, reg2: tregister);
  385. var
  386. instr: taicpu;
  387. begin
  388. instr := taicpu.op_reg_reg(A_FMR,reg2,reg1);
  389. list.concat(instr);
  390. rg[R_FPUREGISTER].add_move_instruction(instr);
  391. end;
  392. procedure tcgppc.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  393. const
  394. FpuLoadInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  395. { indexed? updating?}
  396. (((A_LFS,A_LFSU),(A_LFSX,A_LFSUX)),
  397. ((A_LFD,A_LFDU),(A_LFDX,A_LFDUX)));
  398. var
  399. op: tasmop;
  400. ref2: treference;
  401. freereg: boolean;
  402. begin
  403. { several functions call this procedure with OS_32 or OS_64 }
  404. { so this makes life easier (FK) }
  405. case size of
  406. OS_32,OS_F32:
  407. size:=OS_F32;
  408. OS_64,OS_F64,OS_C64:
  409. size:=OS_F64;
  410. else
  411. internalerror(200201121);
  412. end;
  413. ref2 := ref;
  414. freereg := fixref(list,ref2);
  415. op := fpuloadinstr[size,ref2.index <> NR_NO,false];
  416. a_load_store(list,op,reg,ref2);
  417. if freereg then
  418. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  419. end;
  420. procedure tcgppc.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  421. const
  422. FpuStoreInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  423. { indexed? updating?}
  424. (((A_STFS,A_STFSU),(A_STFSX,A_STFSUX)),
  425. ((A_STFD,A_STFDU),(A_STFDX,A_STFDUX)));
  426. var
  427. op: tasmop;
  428. ref2: treference;
  429. freereg: boolean;
  430. begin
  431. if not(size in [OS_F32,OS_F64]) then
  432. internalerror(200201122);
  433. ref2 := ref;
  434. freereg := fixref(list,ref2);
  435. op := fpustoreinstr[size,ref2.index <> NR_NO,false];
  436. a_load_store(list,op,reg,ref2);
  437. if freereg then
  438. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  439. end;
  440. procedure tcgppc.a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister);
  441. begin
  442. a_op_const_reg_reg(list,op,size,a,reg,reg);
  443. end;
  444. procedure tcgppc.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  445. begin
  446. a_op_reg_reg_reg(list,op,size,src,dst,dst);
  447. end;
  448. procedure tcgppc.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  449. size: tcgsize; a: aword; src, dst: tregister);
  450. var
  451. l1,l2: longint;
  452. oplo, ophi: tasmop;
  453. scratchreg: tregister;
  454. useReg, gotrlwi: boolean;
  455. procedure do_lo_hi;
  456. begin
  457. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  458. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  459. end;
  460. begin
  461. if op = OP_SUB then
  462. begin
  463. {$ifopt q+}
  464. {$q-}
  465. {$define overflowon}
  466. {$endif}
  467. a_op_const_reg_reg(list,OP_ADD,size,aword(-longint(a)),src,dst);
  468. {$ifdef overflowon}
  469. {$q+}
  470. {$undef overflowon}
  471. {$endif}
  472. exit;
  473. end;
  474. ophi := TOpCG2AsmOpConstHi[op];
  475. oplo := TOpCG2AsmOpConstLo[op];
  476. gotrlwi := get_rlwi_const(a,l1,l2);
  477. if (op in [OP_AND,OP_OR,OP_XOR]) then
  478. begin
  479. if (a = 0) then
  480. begin
  481. if op = OP_AND then
  482. list.concat(taicpu.op_reg_const(A_LI,dst,0))
  483. else
  484. a_load_reg_reg(list,size,size,src,dst);
  485. exit;
  486. end
  487. else if (a = high(aword)) then
  488. begin
  489. case op of
  490. OP_OR:
  491. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  492. OP_XOR:
  493. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  494. OP_AND:
  495. a_load_reg_reg(list,size,size,src,dst);
  496. end;
  497. exit;
  498. end
  499. else if (a <= high(word)) and
  500. ((op <> OP_AND) or
  501. not gotrlwi) then
  502. begin
  503. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  504. exit;
  505. end;
  506. { all basic constant instructions also have a shifted form that }
  507. { works only on the highest 16bits, so if lo(a) is 0, we can }
  508. { use that one }
  509. if (word(a) = 0) and
  510. (not(op = OP_AND) or
  511. not gotrlwi) then
  512. begin
  513. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  514. exit;
  515. end;
  516. end
  517. else if (op = OP_ADD) then
  518. if a = 0 then
  519. exit
  520. else if (longint(a) >= low(smallint)) and
  521. (longint(a) <= high(smallint)) then
  522. begin
  523. list.concat(taicpu.op_reg_reg_const(A_ADDI,dst,src,smallint(a)));
  524. exit;
  525. end;
  526. { otherwise, the instructions we can generate depend on the }
  527. { operation }
  528. useReg := false;
  529. case op of
  530. OP_DIV,OP_IDIV:
  531. if (a = 0) then
  532. internalerror(200208103)
  533. else if (a = 1) then
  534. begin
  535. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  536. exit
  537. end
  538. else if ispowerof2(a,l1) then
  539. begin
  540. case op of
  541. OP_DIV:
  542. list.concat(taicpu.op_reg_reg_const(A_SRWI,dst,src,l1));
  543. OP_IDIV:
  544. begin
  545. list.concat(taicpu.op_reg_reg_const(A_SRAWI,dst,src,l1));
  546. list.concat(taicpu.op_reg_reg(A_ADDZE,dst,dst));
  547. end;
  548. end;
  549. exit;
  550. end
  551. else
  552. usereg := true;
  553. OP_IMUL, OP_MUL:
  554. if (a = 0) then
  555. begin
  556. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  557. exit
  558. end
  559. else if (a = 1) then
  560. begin
  561. a_load_reg_reg(list,OS_INT,OS_INT,src,dst);
  562. exit
  563. end
  564. else if ispowerof2(a,l1) then
  565. list.concat(taicpu.op_reg_reg_const(A_SLWI,dst,src,l1))
  566. else if (longint(a) >= low(smallint)) and
  567. (longint(a) <= high(smallint)) then
  568. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  569. else
  570. usereg := true;
  571. OP_ADD:
  572. begin
  573. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  574. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  575. smallint((a shr 16) + ord(smallint(a) < 0))));
  576. end;
  577. OP_OR:
  578. { try to use rlwimi }
  579. if gotrlwi and
  580. (src = dst) then
  581. begin
  582. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  583. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  584. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  585. scratchreg,0,l1,l2));
  586. rg[R_INTREGISTER].ungetregister(list,scratchreg);
  587. end
  588. else
  589. do_lo_hi;
  590. OP_AND:
  591. { try to use rlwinm }
  592. if gotrlwi then
  593. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  594. src,0,l1,l2))
  595. else
  596. useReg := true;
  597. OP_XOR:
  598. do_lo_hi;
  599. OP_SHL,OP_SHR,OP_SAR:
  600. begin
  601. if (a and 31) <> 0 Then
  602. list.concat(taicpu.op_reg_reg_const(
  603. TOpCG2AsmOpConstLo[Op],dst,src,a and 31))
  604. else
  605. a_load_reg_reg(list,size,size,src,dst);
  606. if (a shr 5) <> 0 then
  607. internalError(68991);
  608. end
  609. else
  610. internalerror(200109091);
  611. end;
  612. { if all else failed, load the constant in a register and then }
  613. { perform the operation }
  614. if useReg then
  615. begin
  616. scratchreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  617. a_load_const_reg(list,OS_32,a,scratchreg);
  618. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  619. rg[R_INTREGISTER].ungetregister(list,scratchreg);
  620. end;
  621. end;
  622. procedure tcgppc.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  623. size: tcgsize; src1, src2, dst: tregister);
  624. const
  625. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  626. (A_NONE,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  627. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  628. begin
  629. case op of
  630. OP_NEG,OP_NOT:
  631. begin
  632. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,src1));
  633. if (op = OP_NOT) and
  634. not(size in [OS_32,OS_S32]) then
  635. { zero/sign extend result again }
  636. a_load_reg_reg(list,OS_32,size,dst,dst);
  637. end;
  638. else
  639. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  640. end;
  641. end;
  642. {*************** compare instructructions ****************}
  643. procedure tcgppc.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  644. l : tasmlabel);
  645. var
  646. p: taicpu;
  647. scratch_register: TRegister;
  648. signed: boolean;
  649. begin
  650. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE];
  651. { in the following case, we generate more efficient code when }
  652. { signed is true }
  653. if (cmp_op in [OC_EQ,OC_NE]) and
  654. (a > $ffff) then
  655. signed := true;
  656. if signed then
  657. if (longint(a) >= low(smallint)) and (longint(a) <= high(smallint)) Then
  658. list.concat(taicpu.op_reg_reg_const(A_CMPWI,NR_CR0,reg,longint(a)))
  659. else
  660. begin
  661. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  662. a_load_const_reg(list,OS_32,a,scratch_register);
  663. list.concat(taicpu.op_reg_reg_reg(A_CMPW,NR_CR0,reg,scratch_register));
  664. rg[R_INTREGISTER].ungetregister(list,scratch_register);
  665. end
  666. else
  667. if (a <= $ffff) then
  668. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,NR_CR0,reg,a))
  669. else
  670. begin
  671. scratch_register := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  672. a_load_const_reg(list,OS_32,a,scratch_register);
  673. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,NR_CR0,reg,scratch_register));
  674. rg[R_INTREGISTER].ungetregister(list,scratch_register);
  675. end;
  676. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  677. end;
  678. procedure tcgppc.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  679. reg1,reg2 : tregister;l : tasmlabel);
  680. var
  681. p: taicpu;
  682. op: tasmop;
  683. begin
  684. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  685. op := A_CMPW
  686. else
  687. op := A_CMPLW;
  688. list.concat(taicpu.op_reg_reg_reg(op,NR_CR0,reg2,reg1));
  689. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  690. end;
  691. procedure tcgppc.g_save_standard_registers(list:Taasmoutput);
  692. begin
  693. {$warning FIX ME}
  694. end;
  695. procedure tcgppc.g_restore_standard_registers(list:Taasmoutput);
  696. begin
  697. {$warning FIX ME}
  698. end;
  699. procedure tcgppc.g_save_all_registers(list : taasmoutput);
  700. begin
  701. {$warning FIX ME}
  702. end;
  703. procedure tcgppc.g_restore_all_registers(list : taasmoutput;const funcretparaloc:tparalocation);
  704. begin
  705. {$warning FIX ME}
  706. end;
  707. procedure tcgppc.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  708. begin
  709. a_jmp(list,A_BC,TOpCmp2AsmCond[cond],0,l);
  710. end;
  711. procedure tcgppc.a_jmp_always(list : taasmoutput;l: tasmlabel);
  712. begin
  713. a_jmp(list,A_B,C_None,0,l);
  714. end;
  715. procedure tcgppc.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  716. var
  717. c: tasmcond;
  718. begin
  719. c := flags_to_cond(f);
  720. a_jmp(list,A_BC,c.cond,c.cr-RS_CR0,l);
  721. end;
  722. procedure tcgppc.g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister);
  723. var
  724. testbit: byte;
  725. bitvalue: boolean;
  726. begin
  727. { get the bit to extract from the conditional register + its }
  728. { requested value (0 or 1) }
  729. testbit := ((f.cr-RS_CR0) * 4);
  730. case f.flag of
  731. F_EQ,F_NE:
  732. begin
  733. inc(testbit,2);
  734. bitvalue := f.flag = F_EQ;
  735. end;
  736. F_LT,F_GE:
  737. begin
  738. bitvalue := f.flag = F_LT;
  739. end;
  740. F_GT,F_LE:
  741. begin
  742. inc(testbit);
  743. bitvalue := f.flag = F_GT;
  744. end;
  745. else
  746. internalerror(200112261);
  747. end;
  748. { load the conditional register in the destination reg }
  749. list.concat(taicpu.op_reg(A_MFCR,reg));
  750. { we will move the bit that has to be tested to bit 0 by rotating }
  751. { left }
  752. testbit := (testbit + 1) and 31;
  753. { extract bit }
  754. list.concat(taicpu.op_reg_reg_const_const_const(
  755. A_RLWINM,reg,reg,testbit,31,31));
  756. { if we need the inverse, xor with 1 }
  757. if not bitvalue then
  758. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  759. end;
  760. (*
  761. procedure tcgppc.g_cond2reg(list: taasmoutput; const f: TAsmCond; reg: TRegister);
  762. var
  763. testbit: byte;
  764. bitvalue: boolean;
  765. begin
  766. { get the bit to extract from the conditional register + its }
  767. { requested value (0 or 1) }
  768. case f.simple of
  769. false:
  770. begin
  771. { we don't generate this in the compiler }
  772. internalerror(200109062);
  773. end;
  774. true:
  775. case f.cond of
  776. C_None:
  777. internalerror(200109063);
  778. C_LT..C_NU:
  779. begin
  780. testbit := (ord(f.cr) - ord(R_CR0))*4;
  781. inc(testbit,AsmCondFlag2BI[f.cond]);
  782. bitvalue := AsmCondFlagTF[f.cond];
  783. end;
  784. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  785. begin
  786. testbit := f.crbit
  787. bitvalue := AsmCondFlagTF[f.cond];
  788. end;
  789. else
  790. internalerror(200109064);
  791. end;
  792. end;
  793. { load the conditional register in the destination reg }
  794. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  795. { we will move the bit that has to be tested to bit 31 -> rotate }
  796. { left by bitpos+1 (remember, this is big-endian!) }
  797. if bitpos <> 31 then
  798. inc(bitpos)
  799. else
  800. bitpos := 0;
  801. { extract bit }
  802. list.concat(taicpu.op_reg_reg_const_const_const(
  803. A_RLWINM,reg,reg,bitpos,31,31));
  804. { if we need the inverse, xor with 1 }
  805. if not bitvalue then
  806. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  807. end;
  808. *)
  809. { *********** entry/exit code and address loading ************ }
  810. procedure tcgppc.g_stackframe_entry(list : taasmoutput;localsize : longint);
  811. { generated the entry code of a procedure/function. Note: localsize is the }
  812. { sum of the size necessary for local variables and the maximum possible }
  813. { combined size of ALL the parameters of a procedure called by the current }
  814. { one. }
  815. { This procedure may be called before, as well as after g_return_from_proc }
  816. { is called. NOTE registers are not to be allocated through the register }
  817. { allocator here, because the register colouring has already occured !! }
  818. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  819. href,href2 : treference;
  820. usesfpr,usesgpr,gotgot : boolean;
  821. parastart : aword;
  822. // r,r2,rsp:Tregister;
  823. regcounter2, firstfpureg: Tsuperregister;
  824. hp: tparaitem;
  825. begin
  826. { CR and LR only have to be saved in case they are modified by the current }
  827. { procedure, but currently this isn't checked, so save them always }
  828. { following is the entry code as described in "Altivec Programming }
  829. { Interface Manual", bar the saving of AltiVec registers }
  830. a_reg_alloc(list,NR_STACK_POINTER_REG);
  831. a_reg_alloc(list,NR_R0);
  832. if current_procinfo.procdef.parast.symtablelevel>1 then
  833. a_reg_alloc(list,NR_R11);
  834. usesfpr:=false;
  835. if not (po_assembler in current_procinfo.procdef.procoptions) then
  836. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  837. case target_info.abi of
  838. abi_powerpc_aix:
  839. firstfpureg := RS_F14;
  840. abi_powerpc_sysv:
  841. firstfpureg := RS_F9;
  842. else
  843. internalerror(2003122903);
  844. end;
  845. for regcounter:=firstfpureg to RS_F31 do
  846. begin
  847. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  848. begin
  849. usesfpr:= true;
  850. firstregfpu:=regcounter;
  851. break;
  852. end;
  853. end;
  854. usesgpr:=false;
  855. if not (po_assembler in current_procinfo.procdef.procoptions) then
  856. for regcounter2:=RS_R13 to RS_R31 do
  857. begin
  858. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  859. begin
  860. usesgpr:=true;
  861. firstreggpr:=regcounter2;
  862. break;
  863. end;
  864. end;
  865. { save link register? }
  866. if not (po_assembler in current_procinfo.procdef.procoptions) then
  867. if (pi_do_call in current_procinfo.flags) then
  868. begin
  869. { save return address... }
  870. list.concat(taicpu.op_reg(A_MFLR,NR_R0));
  871. { ... in caller's frame }
  872. case target_info.abi of
  873. abi_powerpc_aix:
  874. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  875. abi_powerpc_sysv:
  876. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  877. end;
  878. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  879. a_reg_dealloc(list,NR_R0);
  880. end;
  881. { save the CR if necessary in callers frame. }
  882. if not (po_assembler in current_procinfo.procdef.procoptions) then
  883. if target_info.abi = abi_powerpc_aix then
  884. if false then { Not needed at the moment. }
  885. begin
  886. a_reg_alloc(list,NR_R0);
  887. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  888. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  889. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  890. a_reg_dealloc(list,NR_R0);
  891. end;
  892. { !!! always allocate space for all registers for now !!! }
  893. if not (po_assembler in current_procinfo.procdef.procoptions) then
  894. { if usesfpr or usesgpr then }
  895. begin
  896. a_reg_alloc(list,NR_R12);
  897. { save end of fpr save area }
  898. list.concat(taicpu.op_reg_reg(A_MR,NR_R12,NR_STACK_POINTER_REG));
  899. end;
  900. if (localsize <> 0) then
  901. begin
  902. if (localsize <= high(smallint)) then
  903. begin
  904. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  905. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  906. end
  907. else
  908. begin
  909. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  910. { can't use getregisterint here, the register colouring }
  911. { is already done when we get here }
  912. href.index := NR_R11;
  913. a_reg_alloc(list,href.index);
  914. a_load_const_reg(list,OS_S32,-localsize,href.index);
  915. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  916. a_reg_dealloc(list,href.index);
  917. end;
  918. end;
  919. { no GOT pointer loaded yet }
  920. gotgot:=false;
  921. if usesfpr then
  922. begin
  923. { save floating-point registers
  924. if (cs_create_pic in aktmoduleswitches) and not(usesgpr) then
  925. begin
  926. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g');
  927. gotgot:=true;
  928. end
  929. else
  930. a_call_name(objectlibrary.newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14));
  931. }
  932. reference_reset_base(href,NR_R12,-8);
  933. for regcounter:=firstregfpu to RS_F31 do
  934. begin
  935. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  936. begin
  937. a_loadfpu_reg_ref(list,OS_F64,newreg(R_FPUREGISTER,regcounter,R_SUBNONE),href);
  938. dec(href.offset,8);
  939. end;
  940. end;
  941. { compute end of gpr save area }
  942. a_op_const_reg(list,OP_ADD,OS_ADDR,aword(href.offset+8),NR_R12);
  943. end;
  944. { save gprs and fetch GOT pointer }
  945. if usesgpr then
  946. begin
  947. {
  948. if cs_create_pic in aktmoduleswitches then
  949. begin
  950. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g');
  951. gotgot:=true;
  952. end
  953. else
  954. a_call_name(objectlibrary.newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14))
  955. }
  956. reference_reset_base(href,NR_R12,-4);
  957. for regcounter2:=RS_R13 to RS_R31 do
  958. begin
  959. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  960. begin
  961. usesgpr:=true;
  962. a_load_reg_ref(list,OS_INT,OS_INT,newreg(R_INTREGISTER,regcounter2,R_SUBNONE),href);
  963. dec(href.offset,4);
  964. end;
  965. end;
  966. {
  967. r.enum:=R_INTREGISTER;
  968. r.:=;
  969. reference_reset_base(href,NR_R12,-((NR_R31-firstreggpr) shr 8+1)*4);
  970. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  971. }
  972. end;
  973. if assigned(current_procinfo.procdef.parast) then
  974. begin
  975. if not (po_assembler in current_procinfo.procdef.procoptions) then
  976. begin
  977. { copy memory parameters to local parast }
  978. hp:=tparaitem(current_procinfo.procdef.para.first);
  979. while assigned(hp) do
  980. begin
  981. if (hp.paraloc[calleeside].loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  982. begin
  983. if tvarsym(hp.parasym).localloc.loc<>LOC_REFERENCE then
  984. internalerror(200310011);
  985. reference_reset_base(href,tvarsym(hp.parasym).localloc.reference.index,tvarsym(hp.parasym).localloc.reference.offset);
  986. reference_reset_base(href2,NR_R12,hp.paraloc[callerside].reference.offset);
  987. { we can't use functions here which allocate registers (FK)
  988. cg.a_load_ref_ref(list,hp.paraloc[calleeside].size,hp.paraloc[calleeside].size,href2,href);
  989. }
  990. cg.a_load_ref_reg(list,hp.paraloc[calleeside].size,hp.paraloc[calleeside].size,href2,NR_R0);
  991. cg.a_load_reg_ref(list,hp.paraloc[calleeside].size,hp.paraloc[calleeside].size,NR_R0,href);
  992. end
  993. {$ifdef dummy}
  994. else if (hp.calleeparaloc.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  995. begin
  996. rg.getexplicitregisterint(list,hp.calleeparaloc.register);
  997. end
  998. {$endif dummy}
  999. ;
  1000. hp := tparaitem(hp.next);
  1001. end;
  1002. end;
  1003. end;
  1004. if usesfpr or usesgpr then
  1005. a_reg_dealloc(list,NR_R12);
  1006. { PIC code support, }
  1007. if cs_create_pic in aktmoduleswitches then
  1008. begin
  1009. { if we didn't get the GOT pointer till now, we've to calculate it now }
  1010. if not(gotgot) then
  1011. begin
  1012. {!!!!!!!!!!!!!}
  1013. end;
  1014. a_reg_alloc(list,NR_R31);
  1015. { place GOT ptr in r31 }
  1016. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R31,NR_LR));
  1017. end;
  1018. { save the CR if necessary ( !!! always done currently ) }
  1019. { still need to find out where this has to be done for SystemV
  1020. a_reg_alloc(list,R_0);
  1021. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  1022. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  1023. new_reference(STACK_POINTER_REG,LA_CR)));
  1024. a_reg_dealloc(list,R_0); }
  1025. { now comes the AltiVec context save, not yet implemented !!! }
  1026. { if we're in a nested procedure, we've to save R11 }
  1027. if current_procinfo.procdef.parast.symtablelevel>2 then
  1028. begin
  1029. reference_reset_base(href,NR_STACK_POINTER_REG,PARENT_FRAMEPOINTER_OFFSET);
  1030. list.concat(taicpu.op_reg_ref(A_STW,NR_R11,href));
  1031. end;
  1032. end;
  1033. procedure tcgppc.g_return_from_proc(list : taasmoutput;parasize : aword);
  1034. { This procedure may be called before, as well as after g_stackframe_entry }
  1035. { is called. NOTE registers are not to be allocated through the register }
  1036. { allocator here, because the register colouring has already occured !! }
  1037. var
  1038. regcounter,firstregfpu,firstreggpr: TsuperRegister;
  1039. href : treference;
  1040. usesfpr,usesgpr,genret : boolean;
  1041. regcounter2, firstfpureg:Tsuperregister;
  1042. localsize: aword;
  1043. begin
  1044. { AltiVec context restore, not yet implemented !!! }
  1045. usesfpr:=false;
  1046. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1047. begin
  1048. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1049. case target_info.abi of
  1050. abi_powerpc_aix:
  1051. firstfpureg := RS_F14;
  1052. abi_powerpc_sysv:
  1053. firstfpureg := RS_F9;
  1054. else
  1055. internalerror(2003122903);
  1056. end;
  1057. for regcounter:=firstfpureg to RS_F31 do
  1058. begin
  1059. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1060. begin
  1061. usesfpr:=true;
  1062. firstregfpu:=regcounter;
  1063. break;
  1064. end;
  1065. end;
  1066. end;
  1067. usesgpr:=false;
  1068. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1069. for regcounter2:=RS_R13 to RS_R31 do
  1070. begin
  1071. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1072. begin
  1073. usesgpr:=true;
  1074. firstreggpr:=regcounter2;
  1075. break;
  1076. end;
  1077. end;
  1078. localsize:= tppcprocinfo(current_procinfo).calc_stackframe_size;
  1079. { no return (blr) generated yet }
  1080. genret:=true;
  1081. if usesgpr or usesfpr then
  1082. begin
  1083. { address of gpr save area to r11 }
  1084. a_op_const_reg_reg(list,OP_ADD,OS_ADDR,localsize,NR_STACK_POINTER_REG,NR_R12);
  1085. if usesfpr then
  1086. begin
  1087. reference_reset_base(href,NR_R12,-8);
  1088. for regcounter := firstregfpu to RS_F31 do
  1089. begin
  1090. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1091. begin
  1092. a_loadfpu_ref_reg(list,OS_F64,href,newreg(R_FPUREGISTER,regcounter,R_SUBNONE));
  1093. dec(href.offset,8);
  1094. end;
  1095. end;
  1096. inc(href.offset,4);
  1097. end
  1098. else
  1099. reference_reset_base(href,NR_R12,-4);
  1100. for regcounter2:=RS_R13 to RS_R31 do
  1101. begin
  1102. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1103. begin
  1104. usesgpr:=true;
  1105. a_load_ref_reg(list,OS_INT,OS_INT,href,newreg(R_INTREGISTER,regcounter2,R_SUBNONE));
  1106. dec(href.offset,4);
  1107. end;
  1108. end;
  1109. (*
  1110. reference_reset_base(href,r2,-((NR_R31-ord(firstreggpr)) shr 8+1)*4);
  1111. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  1112. *)
  1113. end;
  1114. (*
  1115. { restore fprs and return }
  1116. if usesfpr then
  1117. begin
  1118. { address of fpr save area to r11 }
  1119. r:=NR_R12;
  1120. list.concat(taicpu.op_reg_reg_const(A_ADDI,r,r,(ord(R_F31)-ord(firstregfpu.enum)+1)*8));
  1121. {
  1122. if (pi_do_call in current_procinfo.flags) then
  1123. a_call_name(objectlibrary.newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  1124. '_x')
  1125. else
  1126. { leaf node => lr haven't to be restored }
  1127. a_call_name('_restfpr_'+tostr(ord(firstregfpu.enum)-ord(R_F14)+14)+
  1128. '_l');
  1129. genret:=false;
  1130. }
  1131. end;
  1132. *)
  1133. { if we didn't generate the return code, we've to do it now }
  1134. if genret then
  1135. begin
  1136. { adjust r1 }
  1137. a_op_const_reg(list,OP_ADD,OS_ADDR,localsize,NR_R1);
  1138. { load link register? }
  1139. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1140. begin
  1141. if (pi_do_call in current_procinfo.flags) then
  1142. begin
  1143. case target_info.abi of
  1144. abi_powerpc_aix:
  1145. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_AIX);
  1146. abi_powerpc_sysv:
  1147. reference_reset_base(href,NR_STACK_POINTER_REG,LA_LR_SYSV);
  1148. end;
  1149. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1150. list.concat(taicpu.op_reg(A_MTLR,NR_R0));
  1151. end;
  1152. { restore the CR if necessary from callers frame}
  1153. if target_info.abi = abi_powerpc_aix then
  1154. if false then { Not needed at the moment. }
  1155. begin
  1156. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1157. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1158. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1159. a_reg_dealloc(list,NR_R0);
  1160. end;
  1161. end;
  1162. list.concat(taicpu.op_none(A_BLR));
  1163. end;
  1164. end;
  1165. function tcgppc.save_regs(list : taasmoutput):longint;
  1166. {Generates code which saves used non-volatile registers in
  1167. the save area right below the address the stackpointer point to.
  1168. Returns the actual used save area size.}
  1169. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1170. usesfpr,usesgpr: boolean;
  1171. href : treference;
  1172. offset: integer;
  1173. regcounter2, firstfpureg: Tsuperregister;
  1174. begin
  1175. usesfpr:=false;
  1176. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1177. begin
  1178. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1179. case target_info.abi of
  1180. abi_powerpc_aix:
  1181. firstfpureg := RS_F14;
  1182. abi_powerpc_sysv:
  1183. firstfpureg := RS_F9;
  1184. else
  1185. internalerror(2003122903);
  1186. end;
  1187. for regcounter:=firstfpureg to RS_F31 do
  1188. begin
  1189. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1190. begin
  1191. usesfpr:=true;
  1192. firstregfpu:=regcounter;
  1193. break;
  1194. end;
  1195. end;
  1196. end;
  1197. usesgpr:=false;
  1198. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1199. for regcounter2:=RS_R13 to RS_R31 do
  1200. begin
  1201. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1202. begin
  1203. usesgpr:=true;
  1204. firstreggpr:=regcounter2;
  1205. break;
  1206. end;
  1207. end;
  1208. offset:= 0;
  1209. { save floating-point registers }
  1210. if usesfpr then
  1211. for regcounter := firstregfpu to RS_F31 do
  1212. begin
  1213. offset:= offset - 8;
  1214. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1215. list.concat(taicpu.op_reg_ref(A_STFD, tregister(regcounter), href));
  1216. end;
  1217. (* Optimiztion in the future: a_call_name(list,'_savefXX'); *)
  1218. { save gprs in gpr save area }
  1219. if usesgpr then
  1220. if firstreggpr < RS_R30 then
  1221. begin
  1222. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1223. reference_reset_base(href,NR_STACK_POINTER_REG,offset);
  1224. list.concat(taicpu.op_reg_ref(A_STMW,tregister(firstreggpr),href));
  1225. {STMW stores multiple registers}
  1226. end
  1227. else
  1228. begin
  1229. for regcounter := firstreggpr to RS_R31 do
  1230. begin
  1231. offset:= offset - 4;
  1232. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1233. list.concat(taicpu.op_reg_ref(A_STW, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1234. end;
  1235. end;
  1236. { now comes the AltiVec context save, not yet implemented !!! }
  1237. save_regs:= -offset;
  1238. end;
  1239. procedure tcgppc.restore_regs(list : taasmoutput);
  1240. {Generates code which restores used non-volatile registers from
  1241. the save area right below the address the stackpointer point to.}
  1242. var regcounter,firstregfpu,firstreggpr: TSuperRegister;
  1243. usesfpr,usesgpr: boolean;
  1244. href : treference;
  1245. offset: integer;
  1246. regcounter2, firstfpureg: Tsuperregister;
  1247. begin
  1248. usesfpr:=false;
  1249. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1250. begin
  1251. { FIXME: has to be R_F14 instad of R_F8 for SYSV-64bit }
  1252. case target_info.abi of
  1253. abi_powerpc_aix:
  1254. firstfpureg := RS_F14;
  1255. abi_powerpc_sysv:
  1256. firstfpureg := RS_F9;
  1257. else
  1258. internalerror(2003122903);
  1259. end;
  1260. for regcounter:=firstfpureg to RS_F31 do
  1261. begin
  1262. if regcounter in rg[R_FPUREGISTER].used_in_proc then
  1263. begin
  1264. usesfpr:=true;
  1265. firstregfpu:=regcounter;
  1266. break;
  1267. end;
  1268. end;
  1269. end;
  1270. usesgpr:=false;
  1271. if not (po_assembler in current_procinfo.procdef.procoptions) then
  1272. for regcounter2:=RS_R13 to RS_R31 do
  1273. begin
  1274. if regcounter2 in rg[R_INTREGISTER].used_in_proc then
  1275. begin
  1276. usesgpr:=true;
  1277. firstreggpr:=regcounter2;
  1278. break;
  1279. end;
  1280. end;
  1281. offset:= 0;
  1282. { restore fp registers }
  1283. if usesfpr then
  1284. for regcounter := firstregfpu to RS_F31 do
  1285. begin
  1286. offset:= offset - 8;
  1287. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1288. list.concat(taicpu.op_reg_ref(A_LFD, newreg(R_FPUREGISTER,regcounter,R_SUBWHOLE), href));
  1289. end;
  1290. (* Optimiztion in the future: a_call_name(list,'_restfXX'); *)
  1291. { restore gprs }
  1292. if usesgpr then
  1293. if firstreggpr < RS_R30 then
  1294. begin
  1295. offset:= offset - 4 * (RS_R31 - firstreggpr + 1);
  1296. reference_reset_base(href,NR_STACK_POINTER_REG,offset); //-220
  1297. list.concat(taicpu.op_reg_ref(A_LMW,tregister(firstreggpr),href));
  1298. {LMW loads multiple registers}
  1299. end
  1300. else
  1301. begin
  1302. for regcounter := firstreggpr to RS_R31 do
  1303. begin
  1304. offset:= offset - 4;
  1305. reference_reset_base(href, NR_STACK_POINTER_REG, offset);
  1306. list.concat(taicpu.op_reg_ref(A_LWZ, newreg(R_INTREGISTER,regcounter,R_SUBWHOLE), href));
  1307. end;
  1308. end;
  1309. { now comes the AltiVec context restore, not yet implemented !!! }
  1310. end;
  1311. procedure tcgppc.g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  1312. (* NOT IN USE *)
  1313. { generated the entry code of a procedure/function. Note: localsize is the }
  1314. { sum of the size necessary for local variables and the maximum possible }
  1315. { combined size of ALL the parameters of a procedure called by the current }
  1316. { one }
  1317. const
  1318. macosLinkageAreaSize = 24;
  1319. var regcounter: TRegister;
  1320. href : treference;
  1321. registerSaveAreaSize : longint;
  1322. begin
  1323. if (localsize mod 8) <> 0 then
  1324. internalerror(58991);
  1325. { CR and LR only have to be saved in case they are modified by the current }
  1326. { procedure, but currently this isn't checked, so save them always }
  1327. { following is the entry code as described in "Altivec Programming }
  1328. { Interface Manual", bar the saving of AltiVec registers }
  1329. a_reg_alloc(list,NR_STACK_POINTER_REG);
  1330. a_reg_alloc(list,NR_R0);
  1331. { save return address in callers frame}
  1332. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_LR));
  1333. { ... in caller's frame }
  1334. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1335. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1336. a_reg_dealloc(list,NR_R0);
  1337. { save non-volatile registers in callers frame}
  1338. registerSaveAreaSize:= save_regs(list);
  1339. { save the CR if necessary in callers frame ( !!! always done currently ) }
  1340. a_reg_alloc(list,NR_R0);
  1341. list.concat(taicpu.op_reg_reg(A_MFSPR,NR_R0,NR_CR));
  1342. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1343. list.concat(taicpu.op_reg_ref(A_STW,NR_R0,href));
  1344. a_reg_dealloc(list,NR_R0);
  1345. (*
  1346. { save pointer to incoming arguments }
  1347. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  1348. *)
  1349. (*
  1350. a_reg_alloc(list,R_12);
  1351. { 0 or 8 based on SP alignment }
  1352. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  1353. R_12,STACK_POINTER_REG,0,28,28));
  1354. { add in stack length }
  1355. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  1356. -localsize));
  1357. { establish new alignment }
  1358. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  1359. a_reg_dealloc(list,R_12);
  1360. *)
  1361. { allocate stack frame }
  1362. localsize:= align(localsize + macosLinkageAreaSize + registerSaveAreaSize, 16);
  1363. inc(localsize,tg.lasttemp);
  1364. localsize:=align(localsize,16);
  1365. //tppcprocinfo(current_procinfo).localsize:=localsize;
  1366. if (localsize <> 0) then
  1367. begin
  1368. if (localsize <= high(smallint)) then
  1369. begin
  1370. reference_reset_base(href,NR_STACK_POINTER_REG,-localsize);
  1371. a_load_store(list,A_STWU,NR_STACK_POINTER_REG,href);
  1372. end
  1373. else
  1374. begin
  1375. reference_reset_base(href,NR_STACK_POINTER_REG,0);
  1376. href.index := NR_R11;
  1377. a_reg_alloc(list,href.index);
  1378. a_load_const_reg(list,OS_S32,-localsize,href.index);
  1379. a_load_store(list,A_STWUX,NR_STACK_POINTER_REG,href);
  1380. a_reg_dealloc(list,href.index);
  1381. end;
  1382. end;
  1383. end;
  1384. procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  1385. (* NOT IN USE *)
  1386. var
  1387. href : treference;
  1388. begin
  1389. a_reg_alloc(list,NR_R0);
  1390. { restore stack pointer }
  1391. reference_reset_base(href,NR_STACK_POINTER_REG,LA_SP);
  1392. list.concat(taicpu.op_reg_ref(A_LWZ,NR_STACK_POINTER_REG,href));
  1393. (*
  1394. list.concat(taicpu.op_reg_reg_const(A_ORI,NR_STACK_POINTER_REG,R_31,0));
  1395. *)
  1396. { restore the CR if necessary from callers frame
  1397. ( !!! always done currently ) }
  1398. reference_reset_base(href,NR_STACK_POINTER_REG,LA_CR_AIX);
  1399. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1400. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_CR));
  1401. a_reg_dealloc(list,NR_R0);
  1402. (*
  1403. { restore return address from callers frame }
  1404. reference_reset_base(href,STACK_POINTER_REG,8);
  1405. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1406. *)
  1407. { restore non-volatile registers from callers frame }
  1408. restore_regs(list);
  1409. (*
  1410. { return to caller }
  1411. list.concat(taicpu.op_reg_reg(A_MTSPR,R_0,R_LR));
  1412. list.concat(taicpu.op_none(A_BLR));
  1413. *)
  1414. { restore return address from callers frame }
  1415. reference_reset_base(href,NR_STACK_POINTER_REG,8);
  1416. list.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,href));
  1417. { return to caller }
  1418. list.concat(taicpu.op_reg_reg(A_MTSPR,NR_R0,NR_LR));
  1419. list.concat(taicpu.op_none(A_BLR));
  1420. end;
  1421. procedure tcgppc.g_restore_frame_pointer(list : taasmoutput);
  1422. begin
  1423. { no frame pointer on the PowerPC (maybe there is one in the SystemV ABI?)}
  1424. end;
  1425. procedure tcgppc.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  1426. var
  1427. ref2, tmpref: treference;
  1428. freereg: boolean;
  1429. tmpreg:Tregister;
  1430. begin
  1431. ref2 := ref;
  1432. freereg := fixref(list,ref2);
  1433. if assigned(ref2.symbol) then
  1434. begin
  1435. if target_info.system = system_powerpc_macos then
  1436. begin
  1437. if macos_direct_globals then
  1438. begin
  1439. reference_reset(tmpref);
  1440. tmpref.offset := ref2.offset;
  1441. tmpref.symbol := ref2.symbol;
  1442. tmpref.base := NR_NO;
  1443. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,NR_RTOC,tmpref));
  1444. end
  1445. else
  1446. begin
  1447. reference_reset(tmpref);
  1448. tmpref.symbol := ref2.symbol;
  1449. tmpref.offset := 0;
  1450. tmpref.base := NR_RTOC;
  1451. list.concat(taicpu.op_reg_ref(A_LWZ,r,tmpref));
  1452. if ref2.offset <> 0 then
  1453. begin
  1454. reference_reset(tmpref);
  1455. tmpref.offset := ref2.offset;
  1456. tmpref.base:= r;
  1457. list.concat(taicpu.op_reg_ref(A_LA,r,tmpref));
  1458. end;
  1459. end;
  1460. if ref2.base <> NR_NO then
  1461. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,r,ref2.base));
  1462. //list.concat(tai_comment.create(strpnew('*** a_loadaddr_ref_reg')));
  1463. end
  1464. else
  1465. begin
  1466. { add the symbol's value to the base of the reference, and if the }
  1467. { reference doesn't have a base, create one }
  1468. reference_reset(tmpref);
  1469. tmpref.offset := ref2.offset;
  1470. tmpref.symbol := ref2.symbol;
  1471. tmpref.symaddr := refs_ha;
  1472. if ref2.base<> NR_NO then
  1473. begin
  1474. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  1475. ref2.base,tmpref));
  1476. if freereg then
  1477. begin
  1478. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  1479. freereg := false;
  1480. end;
  1481. end
  1482. else
  1483. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  1484. tmpref.base := NR_NO;
  1485. tmpref.symaddr := refs_l;
  1486. { can be folded with one of the next instructions by the }
  1487. { optimizer probably }
  1488. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  1489. end
  1490. end
  1491. else if ref2.offset <> 0 Then
  1492. if ref2.base <> NR_NO then
  1493. a_op_const_reg_reg(list,OP_ADD,OS_32,aword(ref2.offset),ref2.base,r)
  1494. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  1495. { occurs, so now only ref.offset has to be loaded }
  1496. else
  1497. a_load_const_reg(list,OS_32,ref2.offset,r)
  1498. else if ref.index <> NR_NO Then
  1499. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  1500. else if (ref2.base <> NR_NO) and
  1501. (r <> ref2.base) then
  1502. a_load_reg_reg(list,OS_ADDR,OS_ADDR,ref2.base,r)
  1503. else
  1504. list.concat(taicpu.op_reg_const(A_LI,r,0));
  1505. if freereg then
  1506. rg[R_INTREGISTER].ungetregister(list,ref2.base);
  1507. end;
  1508. { ************* concatcopy ************ }
  1509. {$ifndef ppc603}
  1510. const
  1511. maxmoveunit = 8;
  1512. {$else ppc603}
  1513. const
  1514. maxmoveunit = 4;
  1515. {$endif ppc603}
  1516. procedure tcgppc.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  1517. var
  1518. countreg: TRegister;
  1519. src, dst: TReference;
  1520. lab: tasmlabel;
  1521. count, count2: aword;
  1522. orgsrc, orgdst: boolean;
  1523. size: tcgsize;
  1524. begin
  1525. {$ifdef extdebug}
  1526. if len > high(longint) then
  1527. internalerror(2002072704);
  1528. {$endif extdebug}
  1529. { make sure short loads are handled as optimally as possible }
  1530. if not loadref then
  1531. if (len <= maxmoveunit) and
  1532. (byte(len) in [1,2,4,8]) then
  1533. begin
  1534. if len < 8 then
  1535. begin
  1536. size := int_cgsize(len);
  1537. a_load_ref_ref(list,size,size,source,dest);
  1538. if delsource then
  1539. begin
  1540. reference_release(list,source);
  1541. tg.ungetiftemp(list,source);
  1542. end;
  1543. end
  1544. else
  1545. begin
  1546. a_reg_alloc(list,NR_F0);
  1547. a_loadfpu_ref_reg(list,OS_F64,source,NR_F0);
  1548. if delsource then
  1549. begin
  1550. reference_release(list,source);
  1551. tg.ungetiftemp(list,source);
  1552. end;
  1553. a_loadfpu_reg_ref(list,OS_F64,NR_F0,dest);
  1554. a_reg_dealloc(list,NR_F0);
  1555. end;
  1556. exit;
  1557. end;
  1558. count := len div maxmoveunit;
  1559. reference_reset(src);
  1560. reference_reset(dst);
  1561. { load the address of source into src.base }
  1562. if loadref then
  1563. begin
  1564. src.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1565. a_load_ref_reg(list,OS_32,OS_32,source,src.base);
  1566. orgsrc := false;
  1567. end
  1568. else if (count > 4) or
  1569. not issimpleref(source) or
  1570. ((source.index <> NR_NO) and
  1571. ((source.offset + longint(len)) > high(smallint))) then
  1572. begin
  1573. src.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1574. a_loadaddr_ref_reg(list,source,src.base);
  1575. orgsrc := false;
  1576. end
  1577. else
  1578. begin
  1579. src := source;
  1580. orgsrc := true;
  1581. end;
  1582. if not orgsrc and delsource then
  1583. reference_release(list,source);
  1584. { load the address of dest into dst.base }
  1585. if (count > 4) or
  1586. not issimpleref(dest) or
  1587. ((dest.index <> NR_NO) and
  1588. ((dest.offset + longint(len)) > high(smallint))) then
  1589. begin
  1590. dst.base := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1591. a_loadaddr_ref_reg(list,dest,dst.base);
  1592. orgdst := false;
  1593. end
  1594. else
  1595. begin
  1596. dst := dest;
  1597. orgdst := true;
  1598. end;
  1599. {$ifndef ppc603}
  1600. if count > 4 then
  1601. { generate a loop }
  1602. begin
  1603. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1604. { have to be set to 8. I put an Inc there so debugging may be }
  1605. { easier (should offset be different from zero here, it will be }
  1606. { easy to notice in the generated assembler }
  1607. inc(dst.offset,8);
  1608. inc(src.offset,8);
  1609. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1610. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1611. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1612. a_load_const_reg(list,OS_32,count,countreg);
  1613. { explicitely allocate R_0 since it can be used safely here }
  1614. { (for holding date that's being copied) }
  1615. a_reg_alloc(list,NR_F0);
  1616. objectlibrary.getlabel(lab);
  1617. a_label(list, lab);
  1618. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1619. list.concat(taicpu.op_reg_ref(A_LFDU,NR_F0,src));
  1620. list.concat(taicpu.op_reg_ref(A_STFDU,NR_F0,dst));
  1621. a_jmp(list,A_BC,C_NE,0,lab);
  1622. rg[R_INTREGISTER].ungetregister(list,countreg);
  1623. a_reg_dealloc(list,NR_F0);
  1624. len := len mod 8;
  1625. end;
  1626. count := len div 8;
  1627. if count > 0 then
  1628. { unrolled loop }
  1629. begin
  1630. a_reg_alloc(list,NR_F0);
  1631. for count2 := 1 to count do
  1632. begin
  1633. a_loadfpu_ref_reg(list,OS_F64,src,NR_F0);
  1634. a_loadfpu_reg_ref(list,OS_F64,NR_F0,dst);
  1635. inc(src.offset,8);
  1636. inc(dst.offset,8);
  1637. end;
  1638. a_reg_dealloc(list,NR_F0);
  1639. len := len mod 8;
  1640. end;
  1641. if (len and 4) <> 0 then
  1642. begin
  1643. a_reg_alloc(list,NR_R0);
  1644. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1645. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1646. inc(src.offset,4);
  1647. inc(dst.offset,4);
  1648. a_reg_dealloc(list,NR_R0);
  1649. end;
  1650. {$else not ppc603}
  1651. if count > 4 then
  1652. { generate a loop }
  1653. begin
  1654. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1655. { have to be set to 4. I put an Inc there so debugging may be }
  1656. { easier (should offset be different from zero here, it will be }
  1657. { easy to notice in the generated assembler }
  1658. inc(dst.offset,4);
  1659. inc(src.offset,4);
  1660. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,4));
  1661. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,4));
  1662. countreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1663. a_load_const_reg(list,OS_32,count,countreg);
  1664. { explicitely allocate R_0 since it can be used safely here }
  1665. { (for holding date that's being copied) }
  1666. a_reg_alloc(list,NR_R0);
  1667. objectlibrary.getlabel(lab);
  1668. a_label(list, lab);
  1669. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1670. list.concat(taicpu.op_reg_ref(A_LWZU,NR_R0,src));
  1671. list.concat(taicpu.op_reg_ref(A_STWU,NR_R0,dst));
  1672. a_jmp(list,A_BC,C_NE,0,lab);
  1673. rg[R_INTREGISTER].ungetregister(list,countreg);
  1674. a_reg_dealloc(list,NR_R0);
  1675. len := len mod 4;
  1676. end;
  1677. count := len div 4;
  1678. if count > 0 then
  1679. { unrolled loop }
  1680. begin
  1681. a_reg_alloc(list,NR_R0);
  1682. for count2 := 1 to count do
  1683. begin
  1684. a_load_ref_reg(list,OS_32,OS_32,src,NR_R0);
  1685. a_load_reg_ref(list,OS_32,OS_32,NR_R0,dst);
  1686. inc(src.offset,4);
  1687. inc(dst.offset,4);
  1688. end;
  1689. a_reg_dealloc(list,NR_R0);
  1690. len := len mod 4;
  1691. end;
  1692. {$endif not ppc603}
  1693. { copy the leftovers }
  1694. if (len and 2) <> 0 then
  1695. begin
  1696. a_reg_alloc(list,NR_R0);
  1697. a_load_ref_reg(list,OS_16,OS_16,src,NR_R0);
  1698. a_load_reg_ref(list,OS_16,OS_16,NR_R0,dst);
  1699. inc(src.offset,2);
  1700. inc(dst.offset,2);
  1701. a_reg_dealloc(list,NR_R0);
  1702. end;
  1703. if (len and 1) <> 0 then
  1704. begin
  1705. a_reg_alloc(list,NR_R0);
  1706. a_load_ref_reg(list,OS_8,OS_8,src,NR_R0);
  1707. a_load_reg_ref(list,OS_8,OS_8,NR_R0,dst);
  1708. a_reg_dealloc(list,NR_R0);
  1709. end;
  1710. if orgsrc then
  1711. begin
  1712. if delsource then
  1713. reference_release(list,source);
  1714. end
  1715. else
  1716. rg[R_INTREGISTER].ungetregister(list,src.base);
  1717. if not orgdst then
  1718. rg[R_INTREGISTER].ungetregister(list,dst.base);
  1719. if delsource then
  1720. tg.ungetiftemp(list,source);
  1721. end;
  1722. procedure tcgppc.g_overflowcheck(list: taasmoutput; const l: tlocation; def: tdef);
  1723. var
  1724. hl : tasmlabel;
  1725. begin
  1726. if not(cs_check_overflow in aktlocalswitches) then
  1727. exit;
  1728. objectlibrary.getlabel(hl);
  1729. if not ((def.deftype=pointerdef) or
  1730. ((def.deftype=orddef) and
  1731. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1732. bool8bit,bool16bit,bool32bit]))) then
  1733. begin
  1734. list.concat(taicpu.op_reg(A_MCRXR,NR_CR7));
  1735. a_jmp(list,A_BC,C_NO,7,hl)
  1736. end
  1737. else
  1738. a_jmp_cond(list,OC_AE,hl);
  1739. a_call_name(list,'FPC_OVERFLOW');
  1740. a_label(list,hl);
  1741. end;
  1742. {***************** This is private property, keep out! :) *****************}
  1743. function tcgppc.issimpleref(const ref: treference): boolean;
  1744. begin
  1745. if (ref.base = NR_NO) and
  1746. (ref.index <> NR_NO) then
  1747. internalerror(200208101);
  1748. result :=
  1749. not(assigned(ref.symbol)) and
  1750. (((ref.index = NR_NO) and
  1751. (ref.offset >= low(smallint)) and
  1752. (ref.offset <= high(smallint))) or
  1753. ((ref.index <> NR_NO) and
  1754. (ref.offset = 0)));
  1755. end;
  1756. function tcgppc.fixref(list: taasmoutput; var ref: treference): boolean;
  1757. var
  1758. tmpreg: tregister;
  1759. orgindex: tregister;
  1760. begin
  1761. result := false;
  1762. if (ref.base = NR_NO) then
  1763. begin
  1764. ref.base := ref.index;
  1765. ref.base := NR_NO;
  1766. end;
  1767. if (ref.base <> NR_NO) then
  1768. begin
  1769. if (ref.index <> NR_NO) and
  1770. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1771. begin
  1772. result := true;
  1773. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1774. list.concat(taicpu.op_reg_reg_reg(
  1775. A_ADD,tmpreg,ref.base,ref.index));
  1776. ref.index := NR_NO;
  1777. ref.base := tmpreg;
  1778. end
  1779. end
  1780. else
  1781. if ref.index <> NR_NO then
  1782. internalerror(200208102);
  1783. end;
  1784. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1785. { that's the case, we can use rlwinm to do an AND operation }
  1786. function tcgppc.get_rlwi_const(a: aword; var l1, l2: longint): boolean;
  1787. var
  1788. temp : longint;
  1789. testbit : aword;
  1790. compare: boolean;
  1791. begin
  1792. get_rlwi_const := false;
  1793. if (a = 0) or (a = $ffffffff) then
  1794. exit;
  1795. { start with the lowest bit }
  1796. testbit := 1;
  1797. { check its value }
  1798. compare := boolean(a and testbit);
  1799. { find out how long the run of bits with this value is }
  1800. { (it's impossible that all bits are 1 or 0, because in that case }
  1801. { this function wouldn't have been called) }
  1802. l1 := 31;
  1803. while (((a and testbit) <> 0) = compare) do
  1804. begin
  1805. testbit := testbit shl 1;
  1806. dec(l1);
  1807. end;
  1808. { check the length of the run of bits that comes next }
  1809. compare := not compare;
  1810. l2 := l1;
  1811. while (((a and testbit) <> 0) = compare) and
  1812. (l2 >= 0) do
  1813. begin
  1814. testbit := testbit shl 1;
  1815. dec(l2);
  1816. end;
  1817. { and finally the check whether the rest of the bits all have the }
  1818. { same value }
  1819. compare := not compare;
  1820. temp := l2;
  1821. if temp >= 0 then
  1822. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1823. exit;
  1824. { we have done "not(not(compare))", so compare is back to its }
  1825. { initial value. If the lowest bit was 0, a is of the form }
  1826. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1827. { because l2 now contains the position of the last zero of the }
  1828. { first run instead of that of the first 1) so switch l1 and l2 }
  1829. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1830. if not compare then
  1831. begin
  1832. temp := l1;
  1833. l1 := l2+1;
  1834. l2 := temp;
  1835. end
  1836. else
  1837. { otherwise, l1 currently contains the position of the last }
  1838. { zero instead of that of the first 1 of the second run -> +1 }
  1839. inc(l1);
  1840. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1841. l1 := l1 and 31;
  1842. l2 := l2 and 31;
  1843. get_rlwi_const := true;
  1844. end;
  1845. procedure tcgppc.a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  1846. ref: treference);
  1847. var
  1848. tmpreg: tregister;
  1849. tmpref: treference;
  1850. largeOffset: Boolean;
  1851. begin
  1852. tmpreg := NR_NO;
  1853. if target_info.system = system_powerpc_macos then
  1854. begin
  1855. largeOffset:= (cardinal(ref.offset-low(smallint)) >
  1856. high(smallint)-low(smallint));
  1857. if assigned(ref.symbol) then
  1858. begin {Load symbol's value}
  1859. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1860. reference_reset(tmpref);
  1861. tmpref.symbol := ref.symbol;
  1862. tmpref.base := NR_RTOC;
  1863. if macos_direct_globals then
  1864. list.concat(taicpu.op_reg_ref(A_LA,tmpreg,tmpref))
  1865. else
  1866. list.concat(taicpu.op_reg_ref(A_LWZ,tmpreg,tmpref));
  1867. end;
  1868. if largeOffset then
  1869. begin {Add hi part of offset}
  1870. reference_reset(tmpref);
  1871. tmpref.offset := Hi(ref.offset);
  1872. if (tmpreg <> NR_NO) then
  1873. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg, tmpreg,tmpref))
  1874. else
  1875. begin
  1876. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1877. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1878. end;
  1879. end;
  1880. if (tmpreg <> NR_NO) then
  1881. begin
  1882. {Add content of base register}
  1883. if ref.base <> NR_NO then
  1884. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,
  1885. ref.base,tmpreg));
  1886. {Make ref ready to be used by op}
  1887. ref.symbol:= nil;
  1888. ref.base:= tmpreg;
  1889. if largeOffset then
  1890. ref.offset := Lo(ref.offset);
  1891. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1892. //list.concat(tai_comment.create(strpnew('*** a_load_store indirect global')));
  1893. end
  1894. else
  1895. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1896. end
  1897. else {if target_info.system <> system_powerpc_macos}
  1898. begin
  1899. if assigned(ref.symbol) or
  1900. (cardinal(ref.offset-low(smallint)) >
  1901. high(smallint)-low(smallint)) then
  1902. begin
  1903. tmpreg := rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  1904. reference_reset(tmpref);
  1905. tmpref.symbol := ref.symbol;
  1906. tmpref.offset := ref.offset;
  1907. tmpref.symaddr := refs_ha;
  1908. if ref.base <> NR_NO then
  1909. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1910. ref.base,tmpref))
  1911. else
  1912. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1913. ref.base := tmpreg;
  1914. ref.symaddr := refs_l;
  1915. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1916. end
  1917. else
  1918. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1919. end;
  1920. if (tmpreg <> NR_NO) then
  1921. rg[R_INTREGISTER].ungetregister(list,tmpreg);
  1922. end;
  1923. procedure tcgppc.a_jmp(list: taasmoutput; op: tasmop; c: tasmcondflag;
  1924. crval: longint; l: tasmlabel);
  1925. var
  1926. p: taicpu;
  1927. begin
  1928. p := taicpu.op_sym(op,objectlibrary.newasmsymbol(l.name));
  1929. if op <> A_B then
  1930. create_cond_norm(c,crval,p.condition);
  1931. p.is_jmp := true;
  1932. list.concat(p)
  1933. end;
  1934. procedure tcg64fppc.a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);
  1935. begin
  1936. a_op64_reg_reg_reg(list,op,regsrc,regdst,regdst);
  1937. end;
  1938. procedure tcg64fppc.a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);
  1939. begin
  1940. a_op64_const_reg_reg(list,op,value,reg,reg);
  1941. end;
  1942. procedure tcg64fppc.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1943. begin
  1944. case op of
  1945. OP_AND,OP_OR,OP_XOR:
  1946. begin
  1947. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1948. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1949. end;
  1950. OP_ADD:
  1951. begin
  1952. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1953. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1954. end;
  1955. OP_SUB:
  1956. begin
  1957. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1958. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1959. end;
  1960. else
  1961. internalerror(2002072801);
  1962. end;
  1963. end;
  1964. procedure tcg64fppc.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);
  1965. const
  1966. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1967. (A_SUBIC,A_SUBC,A_ADDME));
  1968. var
  1969. tmpreg: tregister;
  1970. tmpreg64: tregister64;
  1971. issub: boolean;
  1972. begin
  1973. case op of
  1974. OP_AND,OP_OR,OP_XOR:
  1975. begin
  1976. cg.a_op_const_reg_reg(list,op,OS_32,aword(value),regsrc.reglo,regdst.reglo);
  1977. cg.a_op_const_reg_reg(list,op,OS_32,aword(value shr 32),regsrc.reghi,
  1978. regdst.reghi);
  1979. end;
  1980. OP_ADD, OP_SUB:
  1981. begin
  1982. if (int64(value) < 0) then
  1983. begin
  1984. if op = OP_ADD then
  1985. op := OP_SUB
  1986. else
  1987. op := OP_ADD;
  1988. int64(value) := -int64(value);
  1989. end;
  1990. if (longint(value) <> 0) then
  1991. begin
  1992. issub := op = OP_SUB;
  1993. if (int64(value) > 0) and
  1994. (int64(value)-ord(issub) <= 32767) then
  1995. begin
  1996. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1997. regdst.reglo,regsrc.reglo,longint(value)));
  1998. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1999. regdst.reghi,regsrc.reghi));
  2000. end
  2001. else if ((value shr 32) = 0) then
  2002. begin
  2003. tmpreg := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  2004. cg.a_load_const_reg(list,OS_32,cardinal(value),tmpreg);
  2005. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  2006. regdst.reglo,regsrc.reglo,tmpreg));
  2007. tcgppc(cg).rg[R_INTREGISTER].ungetregister(list,tmpreg);
  2008. list.concat(taicpu.op_reg_reg(ops[issub,3],
  2009. regdst.reghi,regsrc.reghi));
  2010. end
  2011. else
  2012. begin
  2013. tmpreg64.reglo := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  2014. tmpreg64.reghi := tcgppc(cg).rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  2015. a_load64_const_reg(list,value,tmpreg64);
  2016. a_op64_reg_reg_reg(list,op,tmpreg64,regsrc,regdst);
  2017. tcgppc(cg).rg[R_INTREGISTER].ungetregister(list,tmpreg64.reglo);
  2018. tcgppc(cg).rg[R_INTREGISTER].ungetregister(list,tmpreg64.reghi);
  2019. end
  2020. end
  2021. else
  2022. begin
  2023. cg.a_load_reg_reg(list,OS_INT,OS_INT,regsrc.reglo,regdst.reglo);
  2024. cg.a_op_const_reg_reg(list,op,OS_32,aword(value shr 32),regsrc.reghi,
  2025. regdst.reghi);
  2026. end;
  2027. end;
  2028. else
  2029. internalerror(2002072802);
  2030. end;
  2031. end;
  2032. begin
  2033. cg := tcgppc.create;
  2034. cg64 :=tcg64fppc.create;
  2035. end.
  2036. {
  2037. $Log$
  2038. Revision 1.163 2004-02-09 22:45:49 florian
  2039. * compilation fixed
  2040. Revision 1.162 2004/02/09 20:44:40 olle
  2041. * macos: a_load_store fixed to only allocat temp reg if needed, side effect is compiler work for macos again.
  2042. Revision 1.161 2004/02/08 20:15:42 jonas
  2043. - removed taicpu.is_reg_move because it's not used anymore
  2044. + support tracking fpu register moves by rgobj for the ppc
  2045. Revision 1.160 2004/02/08 14:50:13 jonas
  2046. * fixed previous commit
  2047. Revision 1.159 2004/02/07 15:01:05 jonas
  2048. * changed an explicit mr to a_load_reg_reg so it's registered with the
  2049. register allocator as move
  2050. Revision 1.158 2004/02/04 22:01:13 peter
  2051. * first try to get cpupara working for x86_64
  2052. Revision 1.157 2004/02/03 19:49:24 jonas
  2053. - removed mov "reg, reg" optimizations, as they are removed by the
  2054. register allocator and may be necessary to indicate a register may not
  2055. be reused before some point
  2056. Revision 1.156 2004/01/25 16:36:34 jonas
  2057. - removed double construction of fpu register allocator
  2058. Revision 1.155 2004/01/12 22:11:38 peter
  2059. * use localalign info for alignment for locals and temps
  2060. * sparc fpu flags branching added
  2061. * moved powerpc copy_valye_openarray to generic
  2062. Revision 1.154 2003/12/29 14:17:50 jonas
  2063. * fixed saving/restoring of volatile fpu registers under sysv
  2064. + better provisions for abi differences regarding fpu registers that have
  2065. to be saved
  2066. Revision 1.153 2003/12/29 11:13:53 jonas
  2067. * fixed tb0350 (support loading address of reference containing the
  2068. address 0)
  2069. Revision 1.152 2003/12/28 23:49:30 jonas
  2070. * fixed tnotnode for < 32 bit quantities
  2071. Revision 1.151 2003/12/28 19:22:27 florian
  2072. * handling of open array value parameters fixed
  2073. Revision 1.150 2003/12/26 14:02:30 peter
  2074. * sparc updates
  2075. * use registertype in spill_register
  2076. Revision 1.149 2003/12/18 01:03:52 florian
  2077. + register allocators are set to nil now after they are freed
  2078. Revision 1.148 2003/12/16 21:49:47 florian
  2079. * fixed ppc compilation
  2080. Revision 1.147 2003/12/15 21:37:09 jonas
  2081. * fixed compilation and simplified fixref, so it never has to reallocate
  2082. already freed registers anymore
  2083. Revision 1.146 2003/12/12 17:16:18 peter
  2084. * rg[tregistertype] added in tcg
  2085. Revision 1.145 2003/12/10 00:09:57 karoly
  2086. * fixed compilation with -dppc603
  2087. Revision 1.144 2003/12/09 20:39:43 jonas
  2088. * forgot call to cg.g_overflowcheck() in nppcadd
  2089. * fixed overflow flag definition
  2090. * fixed cg.g_overflowcheck() for signed numbers (jump over call to
  2091. FPC_OVERFLOW if *no* overflow instead of if overflow :)
  2092. Revision 1.143 2003/12/07 21:59:21 florian
  2093. * a_load_ref_ref isn't allowed to be used in g_stackframe_entry
  2094. Revision 1.142 2003/12/06 22:13:53 jonas
  2095. * another fix to a_load_ref_reg()
  2096. + implemented uses_registers() method
  2097. Revision 1.141 2003/12/05 22:53:28 jonas
  2098. * fixed load_ref_reg for source > dest size
  2099. Revision 1.140 2003/12/04 20:37:02 jonas
  2100. * fixed some int<->boolean type conversion issues
  2101. Revision 1.139 2003/11/30 11:32:12 jonas
  2102. * fixded fixref() regarding the reallocation of already freed registers
  2103. used in references
  2104. Revision 1.138 2003/11/30 10:16:05 jonas
  2105. * fixed fpu regallocator initialisation
  2106. Revision 1.137 2003/11/21 16:29:26 florian
  2107. * fixed reading of reg. sets in the arm assembler reader
  2108. Revision 1.136 2003/11/02 17:19:33 florian
  2109. + copying of open array value parameters to the heap implemented
  2110. Revision 1.135 2003/11/02 15:20:06 jonas
  2111. * fixed releasing of references (ppc also has a base and an index, not
  2112. just a base)
  2113. Revision 1.134 2003/10/19 01:34:30 florian
  2114. * some ppc stuff fixed
  2115. * memory leak fixed
  2116. Revision 1.133 2003/10/17 15:25:18 florian
  2117. * fixed more ppc stuff
  2118. Revision 1.132 2003/10/17 15:08:34 peter
  2119. * commented out more obsolete constants
  2120. Revision 1.131 2003/10/17 14:52:07 peter
  2121. * fixed ppc build
  2122. Revision 1.130 2003/10/17 01:22:08 florian
  2123. * compilation of the powerpc compiler fixed
  2124. Revision 1.129 2003/10/13 01:58:04 florian
  2125. * some ideas for mm support implemented
  2126. Revision 1.128 2003/10/11 16:06:42 florian
  2127. * fixed some MMX<->SSE
  2128. * started to fix ppc, needs an overhaul
  2129. + stabs info improve for spilling, not sure if it works correctly/completly
  2130. - MMX_SUPPORT removed from Makefile.fpc
  2131. Revision 1.127 2003/10/01 20:34:49 peter
  2132. * procinfo unit contains tprocinfo
  2133. * cginfo renamed to cgbase
  2134. * moved cgmessage to verbose
  2135. * fixed ppc and sparc compiles
  2136. Revision 1.126 2003/09/14 16:37:20 jonas
  2137. * fixed some ppc problems
  2138. Revision 1.125 2003/09/03 21:04:14 peter
  2139. * some fixes for ppc
  2140. Revision 1.124 2003/09/03 19:35:24 peter
  2141. * powerpc compiles again
  2142. Revision 1.123 2003/09/03 15:55:01 peter
  2143. * NEWRA branch merged
  2144. Revision 1.122.2.1 2003/08/31 21:08:16 peter
  2145. * first batch of sparc fixes
  2146. Revision 1.122 2003/08/18 21:27:00 jonas
  2147. * some newra optimizations (eliminate lots of moves between registers)
  2148. Revision 1.121 2003/08/18 11:50:55 olle
  2149. + cleaning up in proc entry and exit, now calc_stack_frame always is used.
  2150. Revision 1.120 2003/08/17 16:59:20 jonas
  2151. * fixed regvars so they work with newra (at least for ppc)
  2152. * fixed some volatile register bugs
  2153. + -dnotranslation option for -dnewra, which causes the registers not to
  2154. be translated from virtual to normal registers. Requires support in
  2155. the assembler writer as well, which is only implemented in aggas/
  2156. agppcgas currently
  2157. Revision 1.119 2003/08/11 21:18:20 peter
  2158. * start of sparc support for newra
  2159. Revision 1.118 2003/08/08 15:50:45 olle
  2160. * merged macos entry/exit code generation into the general one.
  2161. Revision 1.117 2002/10/01 05:24:28 olle
  2162. * made a_load_store more robust and to accept large offsets and cleaned up code
  2163. Revision 1.116 2003/07/23 11:02:23 jonas
  2164. * don't use rg.getregisterint() anymore in g_stackframe_entry_*, because
  2165. the register colouring has already occurred then, use a hard-coded
  2166. register instead
  2167. Revision 1.115 2003/07/20 20:39:20 jonas
  2168. * fixed newra bug due to the fact that we sometimes need a temp reg
  2169. when loading/storing to memory (base+index+offset is not possible)
  2170. and because a reference is often freed before it is last used, this
  2171. temp register was soemtimes the same as one of the reference regs
  2172. Revision 1.114 2003/07/20 16:15:58 jonas
  2173. * fixed bug in g_concatcopy with -dnewra
  2174. Revision 1.113 2003/07/06 20:25:03 jonas
  2175. * fixed ppc compiler
  2176. Revision 1.112 2003/07/05 20:11:42 jonas
  2177. * create_paraloc_info() is now called separately for the caller and
  2178. callee info
  2179. * fixed ppc cycle
  2180. Revision 1.111 2003/07/02 22:18:04 peter
  2181. * paraloc splitted in callerparaloc,calleeparaloc
  2182. * sparc calling convention updates
  2183. Revision 1.110 2003/06/18 10:12:36 olle
  2184. * macos: fixes of loading-code
  2185. Revision 1.109 2003/06/14 22:32:43 jonas
  2186. * ppc compiles with -dnewra, haven't tried to compile anything with it
  2187. yet though
  2188. Revision 1.108 2003/06/13 21:19:31 peter
  2189. * current_procdef removed, use current_procinfo.procdef instead
  2190. Revision 1.107 2003/06/09 14:54:26 jonas
  2191. * (de)allocation of registers for parameters is now performed properly
  2192. (and checked on the ppc)
  2193. - removed obsolete allocation of all parameter registers at the start
  2194. of a procedure (and deallocation at the end)
  2195. Revision 1.106 2003/06/08 18:19:27 jonas
  2196. - removed duplicate identifier
  2197. Revision 1.105 2003/06/07 18:57:04 jonas
  2198. + added freeintparaloc
  2199. * ppc get/freeintparaloc now check whether the parameter regs are
  2200. properly allocated/deallocated (and get an extra list para)
  2201. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  2202. * fixed lot of missing pi_do_call's
  2203. Revision 1.104 2003/06/04 11:58:58 jonas
  2204. * calculate localsize also in g_return_from_proc since it's now called
  2205. before g_stackframe_entry (still have to fix macos)
  2206. * compilation fixes (cycle doesn't work yet though)
  2207. Revision 1.103 2003/06/01 21:38:06 peter
  2208. * getregisterfpu size parameter added
  2209. * op_const_reg size parameter added
  2210. * sparc updates
  2211. Revision 1.102 2003/06/01 13:42:18 jonas
  2212. * fix for bug in fixref that Peter found during the Sparc conversion
  2213. Revision 1.101 2003/05/30 18:52:10 jonas
  2214. * fixed bug with intregvars
  2215. * locapara.loc can also be LOC_CFPUREGISTER -> also fixed
  2216. rcgppc.a_param_ref, which previously got bogus size values
  2217. Revision 1.100 2003/05/29 21:17:27 jonas
  2218. * compile with -dppc603 to not use unaligned float loads in move() and
  2219. g_concatcopy, because the 603 and 604 take an exception for those
  2220. (and netbsd doesn't even handle those in the kernel). There are
  2221. still some of those left that could cause problems though (e.g.
  2222. in the set helpers)
  2223. Revision 1.99 2003/05/29 10:06:09 jonas
  2224. * also free temps in g_concatcopy if delsource is true
  2225. Revision 1.98 2003/05/28 23:58:18 jonas
  2226. * added missing initialization of rg.usedintin,byproc
  2227. * ppc now also saves/restores used fpu registers
  2228. * ncgcal doesn't add used registers to usedby/inproc anymore, except for
  2229. i386
  2230. Revision 1.97 2003/05/28 23:18:31 florian
  2231. * started to fix and clean up the sparc port
  2232. Revision 1.96 2003/05/24 11:59:42 jonas
  2233. * fixed integer typeconversion problems
  2234. Revision 1.95 2003/05/23 18:51:26 jonas
  2235. * fixed support for nested procedures and more parameters than those
  2236. which fit in registers (untested/probably not working: calling a
  2237. nested procedure from a deeper nested procedure)
  2238. Revision 1.94 2003/05/20 23:54:00 florian
  2239. + basic darwin support added
  2240. Revision 1.93 2003/05/15 22:14:42 florian
  2241. * fixed last commit, changing lastsaveintreg to r31 caused some strange problems
  2242. Revision 1.92 2003/05/15 21:37:00 florian
  2243. * sysv entry code saves r13 now as well
  2244. Revision 1.91 2003/05/15 19:39:09 florian
  2245. * fixed ppc compiler which was broken by Peter's changes
  2246. Revision 1.90 2003/05/12 18:43:50 jonas
  2247. * fixed g_concatcopy
  2248. Revision 1.89 2003/05/11 20:59:23 jonas
  2249. * fixed bug with large offsets in entrycode
  2250. Revision 1.88 2003/05/11 11:45:08 jonas
  2251. * fixed shifts
  2252. Revision 1.87 2003/05/11 11:07:33 jonas
  2253. * fixed optimizations in a_op_const_reg_reg()
  2254. Revision 1.86 2003/04/27 11:21:36 peter
  2255. * aktprocdef renamed to current_procinfo.procdef
  2256. * procinfo renamed to current_procinfo
  2257. * procinfo will now be stored in current_module so it can be
  2258. cleaned up properly
  2259. * gen_main_procsym changed to create_main_proc and release_main_proc
  2260. to also generate a tprocinfo structure
  2261. * fixed unit implicit initfinal
  2262. Revision 1.85 2003/04/26 22:56:11 jonas
  2263. * fix to a_op64_const_reg_reg
  2264. Revision 1.84 2003/04/26 16:08:41 jonas
  2265. * fixed g_flags2reg
  2266. Revision 1.83 2003/04/26 15:25:29 florian
  2267. * fixed cmp_reg_reg_reg, cmp operands were emitted in the wrong order
  2268. Revision 1.82 2003/04/25 20:55:34 florian
  2269. * stack frame calculations are now completly done using the code generator
  2270. routines instead of generating directly assembler so also large stack frames
  2271. are handle properly
  2272. Revision 1.81 2003/04/24 11:24:00 florian
  2273. * fixed several issues with nested procedures
  2274. Revision 1.80 2003/04/23 22:18:01 peter
  2275. * fixes to get rtl compiled
  2276. Revision 1.79 2003/04/23 12:35:35 florian
  2277. * fixed several issues with powerpc
  2278. + applied a patch from Jonas for nested function calls (PowerPC only)
  2279. * ...
  2280. Revision 1.78 2003/04/16 09:26:55 jonas
  2281. * assembler procedures now again get a stackframe if they have local
  2282. variables. No space is reserved for a function result however.
  2283. Also, the register parameters aren't automatically saved on the stack
  2284. anymore in assembler procedures.
  2285. Revision 1.77 2003/04/06 16:39:11 jonas
  2286. * don't generate entry/exit code for assembler procedures
  2287. Revision 1.76 2003/03/22 18:01:13 jonas
  2288. * fixed linux entry/exit code generation
  2289. Revision 1.75 2003/03/19 14:26:26 jonas
  2290. * fixed R_TOC bugs introduced by new register allocator conversion
  2291. Revision 1.74 2003/03/13 22:57:45 olle
  2292. * change in a_loadaddr_ref_reg
  2293. Revision 1.73 2003/03/12 22:43:38 jonas
  2294. * more powerpc and generic fixes related to the new register allocator
  2295. Revision 1.72 2003/03/11 21:46:24 jonas
  2296. * lots of new regallocator fixes, both in generic and ppc-specific code
  2297. (ppc compiler still can't compile the linux system unit though)
  2298. Revision 1.71 2003/02/19 22:00:16 daniel
  2299. * Code generator converted to new register notation
  2300. - Horribily outdated todo.txt removed
  2301. Revision 1.70 2003/01/13 17:17:50 olle
  2302. * changed global var access, TOC now contain pointers to globals
  2303. * fixed handling of function pointers
  2304. Revision 1.69 2003/01/09 22:00:53 florian
  2305. * fixed some PowerPC issues
  2306. Revision 1.68 2003/01/08 18:43:58 daniel
  2307. * Tregister changed into a record
  2308. Revision 1.67 2002/12/15 19:22:01 florian
  2309. * fixed some crashes and a rte 201
  2310. Revision 1.66 2002/11/28 10:55:16 olle
  2311. * macos: changing code gen for references to globals
  2312. Revision 1.65 2002/11/07 15:50:23 jonas
  2313. * fixed bctr(l) problems
  2314. Revision 1.64 2002/11/04 18:24:19 olle
  2315. * macos: globals are located in TOC and relative r2, instead of absolute
  2316. Revision 1.63 2002/10/28 22:24:28 olle
  2317. * macos entry/exit: only used registers are saved
  2318. - macos entry/exit: stackptr not saved in r31 anymore
  2319. * macos entry/exit: misc fixes
  2320. Revision 1.62 2002/10/19 23:51:48 olle
  2321. * macos stack frame size computing updated
  2322. + macos epilogue: control register now restored
  2323. * macos prologue and epilogue: fp reg now saved and restored
  2324. Revision 1.61 2002/10/19 12:50:36 olle
  2325. * reorganized prologue and epilogue routines
  2326. Revision 1.60 2002/10/02 21:49:51 florian
  2327. * all A_BL instructions replaced by calls to a_call_name
  2328. Revision 1.59 2002/10/02 13:24:58 jonas
  2329. * changed a_call_* so that no superfluous code is generated anymore
  2330. Revision 1.58 2002/09/17 18:54:06 jonas
  2331. * a_load_reg_reg() now has two size parameters: source and dest. This
  2332. allows some optimizations on architectures that don't encode the
  2333. register size in the register name.
  2334. Revision 1.57 2002/09/10 21:22:25 jonas
  2335. + added some internal errors
  2336. * fixed bug in sysv exit code
  2337. Revision 1.56 2002/09/08 20:11:56 jonas
  2338. * fixed TOpCmp2AsmCond array (some unsigned equivalents were wrong)
  2339. Revision 1.55 2002/09/08 13:03:26 jonas
  2340. * several large offset-related fixes
  2341. Revision 1.54 2002/09/07 17:54:58 florian
  2342. * first part of PowerPC fixes
  2343. Revision 1.53 2002/09/07 15:25:14 peter
  2344. * old logs removed and tabs fixed
  2345. Revision 1.52 2002/09/02 10:14:51 jonas
  2346. + a_call_reg()
  2347. * small fix in a_call_ref()
  2348. Revision 1.51 2002/09/02 06:09:02 jonas
  2349. * fixed range error
  2350. Revision 1.50 2002/09/01 21:04:49 florian
  2351. * several powerpc related stuff fixed
  2352. Revision 1.49 2002/09/01 12:09:27 peter
  2353. + a_call_reg, a_call_loc added
  2354. * removed exprasmlist references
  2355. Revision 1.48 2002/08/31 21:38:02 jonas
  2356. * fixed a_call_ref (it should load ctr, not lr)
  2357. Revision 1.47 2002/08/31 21:30:45 florian
  2358. * fixed several problems caused by Jonas' commit :)
  2359. Revision 1.46 2002/08/31 19:25:50 jonas
  2360. + implemented a_call_ref()
  2361. Revision 1.45 2002/08/18 22:16:14 florian
  2362. + the ppc gas assembler writer adds now registers aliases
  2363. to the assembler file
  2364. Revision 1.44 2002/08/17 18:23:53 florian
  2365. * some assembler writer bugs fixed
  2366. Revision 1.43 2002/08/17 09:23:49 florian
  2367. * first part of procinfo rewrite
  2368. Revision 1.42 2002/08/16 14:24:59 carl
  2369. * issameref() to test if two references are the same (then emit no opcodes)
  2370. + ret_in_reg to replace ret_in_acc
  2371. (fix some register allocation bugs at the same time)
  2372. + save_std_register now has an extra parameter which is the
  2373. usedinproc registers
  2374. Revision 1.41 2002/08/15 08:13:54 carl
  2375. - a_load_sym_ofs_reg removed
  2376. * loadvmt now calls loadaddr_ref_reg instead
  2377. Revision 1.40 2002/08/11 14:32:32 peter
  2378. * renamed current_library to objectlibrary
  2379. Revision 1.39 2002/08/11 13:24:18 peter
  2380. * saving of asmsymbols in ppu supported
  2381. * asmsymbollist global is removed and moved into a new class
  2382. tasmlibrarydata that will hold the info of a .a file which
  2383. corresponds with a single module. Added librarydata to tmodule
  2384. to keep the library info stored for the module. In the future the
  2385. objectfiles will also be stored to the tasmlibrarydata class
  2386. * all getlabel/newasmsymbol and friends are moved to the new class
  2387. Revision 1.38 2002/08/11 11:39:31 jonas
  2388. + powerpc-specific genlinearlist
  2389. Revision 1.37 2002/08/10 17:15:31 jonas
  2390. * various fixes and optimizations
  2391. Revision 1.36 2002/08/06 20:55:23 florian
  2392. * first part of ppc calling conventions fix
  2393. Revision 1.35 2002/08/06 07:12:05 jonas
  2394. * fixed bug in g_flags2reg()
  2395. * and yet more constant operation fixes :)
  2396. Revision 1.34 2002/08/05 08:58:53 jonas
  2397. * fixed compilation problems
  2398. Revision 1.33 2002/08/04 12:57:55 jonas
  2399. * more misc. fixes, mostly constant-related
  2400. }