cgcpu.pas 103 KB

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