cgcpu.pas 108 KB

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