cgcpu.pas 101 KB

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