cgcpu.pas 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the code generator for the PowerPC
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cgbase,cgobj,
  23. aasmbase,aasmcpu,aasmtai,
  24. cpubase,cpuinfo,node,cg64f32,cginfo;
  25. type
  26. tcgppc = class(tcg)
  27. { passing parameters, per default the parameter is pushed }
  28. { nr gives the number of the parameter (enumerated from }
  29. { left to right), this allows to move the parameter to }
  30. { register, if the cpu supports register calling }
  31. { conventions }
  32. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);override;
  33. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);override;
  34. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);override;
  35. procedure a_call_name(list : taasmoutput;const s : string);override;
  36. procedure a_call_ref(list : taasmoutput;const ref : treference);override;
  37. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister); override;
  38. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  39. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  40. size: tcgsize; a: aword; src, dst: tregister); override;
  41. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  42. size: tcgsize; src1, src2, dst: tregister); override;
  43. { move instructions }
  44. procedure a_load_const_reg(list : taasmoutput; size: tcgsize; a : aword;reg : tregister);override;
  45. procedure a_load_reg_ref(list : taasmoutput; size: tcgsize; reg : tregister;const ref : treference);override;
  46. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const Ref : treference;reg : tregister);override;
  47. procedure a_load_reg_reg(list : taasmoutput;size : tcgsize;reg1,reg2 : tregister);override;
  48. procedure a_load_sym_ofs_reg(list: taasmoutput; const sym: tasmsymbol; ofs: longint; reg: tregister); override;
  49. { fpu move instructions }
  50. procedure a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister); override;
  51. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); override;
  52. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); override;
  53. { comparison operations }
  54. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  55. l : tasmlabel);override;
  56. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); override;
  57. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); override;
  58. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); override;
  59. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister); override;
  60. procedure g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  61. procedure g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  62. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);override;
  63. procedure g_restore_frame_pointer(list : taasmoutput);override;
  64. procedure g_return_from_proc(list : taasmoutput;parasize : aword); override;
  65. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);override;
  66. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);override;
  67. procedure g_overflowcheck(list: taasmoutput; const p: tnode); override;
  68. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  69. { that's the case, we can use rlwinm to do an AND operation }
  70. function get_rlwi_const(a: longint; var l1, l2: longint): boolean;
  71. procedure g_save_standard_registers(list : taasmoutput);override;
  72. procedure g_restore_standard_registers(list : taasmoutput);override;
  73. procedure g_save_all_registers(list : taasmoutput);override;
  74. procedure g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);override;
  75. private
  76. procedure a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  77. procedure g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  78. procedure g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  79. { Make sure ref is a valid reference for the PowerPC and sets the }
  80. { base to the value of the index if (base = R_NO). }
  81. procedure fixref(list: taasmoutput; var ref: treference);
  82. { contains the common code of a_load_reg_ref and a_load_ref_reg }
  83. procedure a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  84. ref: treference);
  85. { creates the correct branch instruction for a given combination }
  86. { of asmcondflags and destination addressing mode }
  87. procedure a_jmp(list: taasmoutput; op: tasmop;
  88. c: tasmcondflag; crval: longint; l: tasmlabel);
  89. end;
  90. tcg64fppc = class(tcg64f32)
  91. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);override;
  92. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);override;
  93. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);override;
  94. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);override;
  95. end;
  96. const
  97. TOpCG2AsmOpConstLo: Array[topcg] of TAsmOp = (A_NONE,A_ADDI,A_ANDI_,A_DIVWU,
  98. A_DIVW,A_MULLW, A_MULLW, A_NONE,A_NONE,A_ORI,
  99. A_SRAWI,A_SLWI,A_SRWI,A_SUBI,A_XORI);
  100. TOpCG2AsmOpConstHi: Array[topcg] of TAsmOp = (A_NONE,A_ADDIS,A_ANDIS_,
  101. A_DIVWU,A_DIVW, A_MULLW,A_MULLW,A_NONE,A_NONE,
  102. A_ORIS,A_NONE, A_NONE,A_NONE,A_SUBIS,A_XORIS);
  103. TOpCmp2AsmCond: Array[topcmp] of TAsmCondFlag = (C_NONE,C_EQ,C_GT,
  104. C_LT,C_GE,C_LE,C_NE,C_LE,C_NG,C_GE,C_NL);
  105. implementation
  106. uses
  107. globtype,globals,verbose,systems,cutils,symconst,symdef,rgobj;
  108. { parameter passing... Still needs extra support from the processor }
  109. { independent code generator }
  110. procedure tcgppc.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  111. var
  112. ref: treference;
  113. begin
  114. case locpara.loc of
  115. LOC_REGISTER:
  116. a_load_const_reg(list,size,a,locpara.register);
  117. LOC_REFERENCE:
  118. begin
  119. reference_reset(ref);
  120. ref.base:=locpara.reference.index;
  121. ref.offset:=locpara.reference.offset;
  122. a_load_const_ref(list,size,a,ref);
  123. end;
  124. else
  125. internalerror(2002081101);
  126. end;
  127. if locpara.sp_fixup<>0 then
  128. internalerror(2002081102);
  129. end;
  130. procedure tcgppc.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  131. var
  132. ref: treference;
  133. tmpreg: tregister;
  134. begin
  135. case locpara.loc of
  136. LOC_REGISTER:
  137. a_load_ref_reg(list,size,r,locpara.register);
  138. LOC_REFERENCE:
  139. begin
  140. reference_reset(ref);
  141. ref.base:=locpara.reference.index;
  142. ref.offset:=locpara.reference.offset;
  143. tmpreg := get_scratch_reg_int(list);
  144. a_load_ref_reg(list,size,r,tmpreg);
  145. a_load_reg_ref(list,size,tmpreg,ref);
  146. free_scratch_reg(list,tmpreg);
  147. end;
  148. LOC_FPUREGISTER:
  149. case size of
  150. OS_32:
  151. a_loadfpu_ref_reg(list,OS_F32,r,locpara.register);
  152. OS_64:
  153. a_loadfpu_ref_reg(list,OS_F64,r,locpara.register);
  154. else
  155. internalerror(2002072801);
  156. end;
  157. else
  158. internalerror(2002081103);
  159. end;
  160. if locpara.sp_fixup<>0 then
  161. internalerror(2002081104);
  162. end;
  163. procedure tcgppc.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  164. var
  165. ref: treference;
  166. tmpreg: tregister;
  167. begin
  168. case locpara.loc of
  169. LOC_REGISTER:
  170. a_loadaddr_ref_reg(list,r,locpara.register);
  171. LOC_REFERENCE:
  172. begin
  173. reference_reset(ref);
  174. ref.base := locpara.reference.index;
  175. ref.offset := locpara.reference.offset;
  176. tmpreg := get_scratch_reg_address(list);
  177. a_loadaddr_ref_reg(list,r,tmpreg);
  178. a_load_reg_ref(list,OS_ADDR,tmpreg,ref);
  179. free_scratch_reg(list,tmpreg);
  180. end;
  181. else
  182. internalerror(2002080701);
  183. end;
  184. end;
  185. { calling a code fragment by name }
  186. procedure tcgppc.a_call_name(list : taasmoutput;const s : string);
  187. var
  188. href : treference;
  189. begin
  190. { save our RTOC register value. Only necessary when doing pointer based }
  191. { calls or cross TOC calls, but currently done always }
  192. reference_reset_base(href,STACK_POINTER_REG,LA_RTOC);
  193. list.concat(taicpu.op_reg_ref(A_STW,R_TOC,href));
  194. list.concat(taicpu.op_sym(A_BL,newasmsymbol(s)));
  195. reference_reset_base(href,STACK_POINTER_REG,LA_RTOC);
  196. list.concat(taicpu.op_reg_ref(A_LWZ,R_TOC,href));
  197. procinfo^.flags:=procinfo^.flags or pi_do_call;
  198. end;
  199. { calling a code fragment through a reference }
  200. procedure tcgppc.a_call_ref(list : taasmoutput;const ref : treference);
  201. begin
  202. {$warning FIX ME}
  203. procinfo^.flags:=procinfo^.flags or pi_do_call;
  204. end;
  205. {********************** load instructions ********************}
  206. procedure tcgppc.a_load_const_reg(list : taasmoutput; size: TCGSize; a : aword; reg : TRegister);
  207. begin
  208. if (longint(a) >= low(smallint)) and
  209. (longint(a) <= high(smallint)) then
  210. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a)))
  211. else if ((a and $ffff) <> 0) then
  212. begin
  213. list.concat(taicpu.op_reg_const(A_LI,reg,smallint(a and $ffff)));
  214. if ((a shr 16) <> 0) then
  215. list.concat(taicpu.op_reg_const(A_ADDIS,reg,
  216. smallint((a shr 16)+ord(smallint(a and $ffff) < 0))))
  217. end
  218. else
  219. list.concat(taicpu.op_reg_const(A_LIS,reg,smallint(a shr 16)));
  220. end;
  221. procedure tcgppc.a_load_reg_ref(list : taasmoutput; size: TCGSize; reg : tregister;const ref : treference);
  222. const
  223. StoreInstr: Array[OS_8..OS_32,boolean, boolean] of TAsmOp =
  224. { indexed? updating?}
  225. (((A_STB,A_STBU),(A_STBX,A_STBUX)),
  226. ((A_STH,A_STHU),(A_STHX,A_STHUX)),
  227. ((A_STW,A_STWU),(A_STWX,A_STWUX)));
  228. var
  229. op: TAsmOp;
  230. ref2: TReference;
  231. begin
  232. ref2 := ref;
  233. FixRef(list,ref2);
  234. if size in [OS_S8..OS_S16] then
  235. { storing is the same for signed and unsigned values }
  236. size := tcgsize(ord(size)-(ord(OS_S8)-ord(OS_8)));
  237. { 64 bit stuff should be handled separately }
  238. if size in [OS_64,OS_S64] then
  239. internalerror(200109236);
  240. op := storeinstr[tcgsize2unsigned[size],ref2.index<>R_NO,false];
  241. a_load_store(list,op,reg,ref2);
  242. End;
  243. procedure tcgppc.a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref: treference;reg : tregister);
  244. const
  245. LoadInstr: Array[OS_8..OS_S32,boolean, boolean] of TAsmOp =
  246. { indexed? updating?}
  247. (((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  248. ((A_LHZ,A_LHZU),(A_LHZX,A_LHZUX)),
  249. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)),
  250. { 64bit stuff should be handled separately }
  251. ((A_NONE,A_NONE),(A_NONE,A_NONE)),
  252. { there's no load-byte-with-sign-extend :( }
  253. ((A_LBZ,A_LBZU),(A_LBZX,A_LBZUX)),
  254. ((A_LHA,A_LHAU),(A_LHAX,A_LHAUX)),
  255. ((A_LWZ,A_LWZU),(A_LWZX,A_LWZUX)));
  256. var
  257. op: tasmop;
  258. tmpreg: tregister;
  259. ref2, tmpref: treference;
  260. begin
  261. ref2 := ref;
  262. fixref(list,ref2);
  263. op := loadinstr[size,ref2.index<>R_NO,false];
  264. a_load_store(list,op,reg,ref2);
  265. { sign extend shortint if necessary, since there is no }
  266. { load instruction that does that automatically (JM) }
  267. if size = OS_S8 then
  268. list.concat(taicpu.op_reg_reg(A_EXTSB,reg,reg));
  269. end;
  270. procedure tcgppc.a_load_reg_reg(list : taasmoutput;size : tcgsize;reg1,reg2 : tregister);
  271. begin
  272. if (reg1 <> reg2) or
  273. not(size in [OS_32,OS_S32]) then
  274. begin
  275. case size of
  276. OS_8:
  277. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  278. reg2,reg1,0,31-8+1,31));
  279. OS_S8:
  280. list.concat(taicpu.op_reg_reg(A_EXTSB,reg2,reg1));
  281. OS_16:
  282. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  283. reg2,reg1,0,31-16+1,31));
  284. OS_S16:
  285. list.concat(taicpu.op_reg_reg(A_EXTSH,reg2,reg1));
  286. OS_32,OS_S32:
  287. list.concat(taicpu.op_reg_reg(A_MR,reg2,reg1));
  288. end;
  289. end;
  290. end;
  291. procedure tcgppc.a_load_sym_ofs_reg(list: taasmoutput; const sym: tasmsymbol; ofs: longint; reg: tregister);
  292. begin
  293. { can't use op_sym_ofs_reg because sym+ofs can be > 32767!! }
  294. internalerror(200112293);
  295. end;
  296. procedure tcgppc.a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister);
  297. begin
  298. list.concat(taicpu.op_reg_reg(A_FMR,reg1,reg2));
  299. end;
  300. procedure tcgppc.a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister);
  301. const
  302. FpuLoadInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  303. { indexed? updating?}
  304. (((A_LFS,A_LFSU),(A_LFSX,A_LFSUX)),
  305. ((A_LFD,A_LFDU),(A_LFDX,A_LFDUX)));
  306. var
  307. op: tasmop;
  308. ref2: treference;
  309. begin
  310. { several functions call this procedure with OS_32 or OS_64 }
  311. { so this makes life easier (FK) }
  312. case size of
  313. OS_32,OS_F32:
  314. size:=OS_F32;
  315. OS_64,OS_F64:
  316. size:=OS_F64;
  317. else
  318. internalerror(200201121);
  319. end;
  320. ref2 := ref;
  321. fixref(list,ref2);
  322. op := fpuloadinstr[size,ref2.index <> R_NO,false];
  323. a_load_store(list,op,reg,ref2);
  324. end;
  325. procedure tcgppc.a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference);
  326. const
  327. FpuStoreInstr: Array[OS_F32..OS_F64,boolean, boolean] of TAsmOp =
  328. { indexed? updating?}
  329. (((A_STFS,A_STFSU),(A_STFSX,A_STFSUX)),
  330. ((A_STFD,A_STFDU),(A_STFDX,A_STFDUX)));
  331. var
  332. op: tasmop;
  333. ref2: treference;
  334. begin
  335. if not(size in [OS_F32,OS_F64]) then
  336. internalerror(200201122);
  337. ref2 := ref;
  338. fixref(list,ref2);
  339. op := fpustoreinstr[size,ref2.index <> R_NO,false];
  340. a_load_store(list,op,reg,ref2);
  341. end;
  342. procedure tcgppc.a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister);
  343. var
  344. scratch_register: TRegister;
  345. begin
  346. a_op_const_reg_reg(list,op,OS_32,a,reg,reg);
  347. end;
  348. procedure tcgppc.a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  349. begin
  350. a_op_reg_reg_reg(list,op,OS_32,src,dst,dst);
  351. end;
  352. procedure tcgppc.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  353. size: tcgsize; a: aword; src, dst: tregister);
  354. var
  355. l1,l2: longint;
  356. oplo, ophi: tasmop;
  357. scratchreg: tregister;
  358. useReg, gotrlwi: boolean;
  359. procedure do_lo_hi;
  360. begin
  361. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  362. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,word(a shr 16)));
  363. end;
  364. begin
  365. if op = OP_SUB then
  366. begin
  367. {$ifopt q+}
  368. {$q-}
  369. {$define overflowon}
  370. {$endif}
  371. a_op_const_reg_reg(list,OP_ADD,size,aword(-a),src,dst);
  372. {$ifdef overflowon}
  373. {$q+}
  374. {$undef overflowon}
  375. {$endif}
  376. exit;
  377. end;
  378. ophi := TOpCG2AsmOpConstHi[op];
  379. oplo := TOpCG2AsmOpConstLo[op];
  380. gotrlwi := get_rlwi_const(a,l1,l2);
  381. if (op in [OP_ADD,OP_AND,OP_OR,OP_XOR]) then
  382. begin
  383. if (a = 0) then
  384. begin
  385. if op = OP_AND then
  386. list.concat(taicpu.op_reg_const(A_LI,dst,0));
  387. exit;
  388. end
  389. else if (a = high(aword)) and
  390. (op in [OP_AND,OP_OR,OP_XOR]) then
  391. begin
  392. case op of
  393. OP_OR:
  394. list.concat(taicpu.op_reg_const(A_LI,dst,-1));
  395. OP_XOR:
  396. list.concat(taicpu.op_reg_reg(A_NOT,dst,src));
  397. end;
  398. exit;
  399. end
  400. else if (longint(a) >= 0) and
  401. (longint(a) <= high(word)) and
  402. ((op <> OP_AND) or
  403. not gotrlwi) then
  404. begin
  405. if (op = OP_ADD) then
  406. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)))
  407. else
  408. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,word(a)));
  409. exit;
  410. end;
  411. { all basic constant instructions also have a shifted form that }
  412. { works only on the highest 16bits, so if lo(a) is 0, we can }
  413. { use that one }
  414. if (word(a) = 0) and
  415. (not(op = OP_AND) or
  416. not gotrlwi) then
  417. begin
  418. list.concat(taicpu.op_reg_reg_const(ophi,dst,src,word(a shr 16)));
  419. exit;
  420. end;
  421. end;
  422. { otherwise, the instructions we can generate depend on the }
  423. { operation }
  424. useReg := false;
  425. case op of
  426. OP_DIV,OP_IDIV:
  427. useReg := true;
  428. OP_IMUL, OP_MUL:
  429. if (longint(a) >= low(smallint)) and
  430. (longint(a) <= high(smallint)) then
  431. list.concat(taicpu.op_reg_reg_const(A_MULLI,dst,src,smallint(a)))
  432. else
  433. usereg := true;
  434. OP_ADD:
  435. begin
  436. list.concat(taicpu.op_reg_reg_const(oplo,dst,src,smallint(a)));
  437. list.concat(taicpu.op_reg_reg_const(ophi,dst,dst,
  438. smallint((a shr 16) + ord(smallint(a) < 0))));
  439. end;
  440. OP_OR:
  441. { try to use rlwimi }
  442. if gotrlwi and
  443. (src = dst) then
  444. begin
  445. scratchreg := get_scratch_reg_int(list);
  446. list.concat(taicpu.op_reg_const(A_LI,scratchreg,-1));
  447. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWIMI,dst,
  448. scratchreg,0,l1,l2));
  449. free_scratch_reg(list,scratchreg);
  450. end
  451. else
  452. do_lo_hi;
  453. OP_AND:
  454. { try to use rlwinm }
  455. if gotrlwi then
  456. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,dst,
  457. src,0,l1,l2))
  458. else
  459. useReg := true;
  460. OP_XOR:
  461. do_lo_hi;
  462. OP_SHL,OP_SHR,OP_SAR:
  463. begin
  464. if (a and 31) <> 0 Then
  465. list.concat(taicpu.op_reg_reg_const(
  466. TOpCG2AsmOpConstLo[Op],dst,src,a and 31));
  467. if (a shr 5) <> 0 then
  468. internalError(68991);
  469. end
  470. else
  471. internalerror(200109091);
  472. end;
  473. { if all else failed, load the constant in a register and then }
  474. { perform the operation }
  475. if useReg then
  476. begin
  477. scratchreg := get_scratch_reg_int(list);
  478. a_load_const_reg(list,OS_32,a,scratchreg);
  479. a_op_reg_reg_reg(list,op,OS_32,scratchreg,src,dst);
  480. free_scratch_reg(list,scratchreg);
  481. end;
  482. end;
  483. procedure tcgppc.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  484. size: tcgsize; src1, src2, dst: tregister);
  485. const
  486. op_reg_reg_opcg2asmop: array[TOpCG] of tasmop =
  487. (A_NONE,A_ADD,A_AND,A_DIVWU,A_DIVW,A_MULLW,A_MULLW,A_NEG,A_NOT,A_OR,
  488. A_SRAW,A_SLW,A_SRW,A_SUB,A_XOR);
  489. begin
  490. case op of
  491. OP_NEG,OP_NOT:
  492. list.concat(taicpu.op_reg_reg(op_reg_reg_opcg2asmop[op],dst,dst));
  493. else
  494. list.concat(taicpu.op_reg_reg_reg(op_reg_reg_opcg2asmop[op],dst,src2,src1));
  495. end;
  496. end;
  497. {*************** compare instructructions ****************}
  498. procedure tcgppc.a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  499. l : tasmlabel);
  500. var
  501. p: taicpu;
  502. scratch_register: TRegister;
  503. signed: boolean;
  504. begin
  505. signed := cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE];
  506. { in the following case, we generate more efficient code when }
  507. { signed is true }
  508. if (cmp_op in [OC_EQ,OC_NE]) and
  509. (a > $ffff) then
  510. signed := true;
  511. if signed then
  512. if (longint(a) >= low(smallint)) and (longint(a) <= high(smallint)) Then
  513. list.concat(taicpu.op_reg_reg_const(A_CMPWI,R_CR0,reg,longint(a)))
  514. else
  515. begin
  516. scratch_register := get_scratch_reg_int(list);
  517. a_load_const_reg(list,OS_32,a,scratch_register);
  518. list.concat(taicpu.op_reg_reg_reg(A_CMPW,R_CR0,reg,scratch_register));
  519. free_scratch_reg(list,scratch_register);
  520. end
  521. else
  522. if (a <= $ffff) then
  523. list.concat(taicpu.op_reg_reg_const(A_CMPLWI,R_CR0,reg,a))
  524. else
  525. begin
  526. scratch_register := get_scratch_reg_int(list);
  527. a_load_const_reg(list,OS_32,a,scratch_register);
  528. list.concat(taicpu.op_reg_reg_reg(A_CMPLW,R_CR0,reg,scratch_register));
  529. free_scratch_reg(list,scratch_register);
  530. end;
  531. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  532. end;
  533. procedure tcgppc.a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;
  534. reg1,reg2 : tregister;l : tasmlabel);
  535. var
  536. p: taicpu;
  537. op: tasmop;
  538. begin
  539. if cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE] then
  540. op := A_CMPW
  541. else op := A_CMPLW;
  542. list.concat(taicpu.op_reg_reg_reg(op,R_CR0,reg1,reg2));
  543. a_jmp(list,A_BC,TOpCmp2AsmCond[cmp_op],0,l);
  544. end;
  545. procedure tcgppc.g_save_standard_registers(list : taasmoutput);
  546. begin
  547. {$warning FIX ME}
  548. end;
  549. procedure tcgppc.g_restore_standard_registers(list : taasmoutput);
  550. begin
  551. {$warning FIX ME}
  552. end;
  553. procedure tcgppc.g_save_all_registers(list : taasmoutput);
  554. begin
  555. {$warning FIX ME}
  556. end;
  557. procedure tcgppc.g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);
  558. begin
  559. {$warning FIX ME}
  560. end;
  561. procedure tcgppc.a_jmp_cond(list : taasmoutput;cond : TOpCmp;l: tasmlabel);
  562. begin
  563. a_jmp(list,A_BC,TOpCmp2AsmCond[cond],0,l);
  564. end;
  565. procedure tcgppc.a_jmp_always(list : taasmoutput;l: tasmlabel);
  566. begin
  567. a_jmp(list,A_B,C_None,0,l);
  568. end;
  569. procedure tcgppc.a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel);
  570. var
  571. c: tasmcond;
  572. begin
  573. c := flags_to_cond(f);
  574. a_jmp(list,A_BC,c.cond,ord(c.cr)-ord(R_CR0),l);
  575. end;
  576. procedure tcgppc.g_flags2reg(list: taasmoutput; size: TCgSize; const f: TResFlags; reg: TRegister);
  577. var
  578. testbit: byte;
  579. bitvalue: boolean;
  580. begin
  581. { get the bit to extract from the conditional register + its }
  582. { requested value (0 or 1) }
  583. testbit := ((ord(f.cr)-ord(R_CR0)) * 4);
  584. case f.flag of
  585. F_EQ,F_NE:
  586. bitvalue := f.flag = F_EQ;
  587. F_LT,F_GE:
  588. begin
  589. inc(testbit);
  590. bitvalue := f.flag = F_LT;
  591. end;
  592. F_GT,F_LE:
  593. begin
  594. inc(testbit,2);
  595. bitvalue := f.flag = F_GT;
  596. end;
  597. else
  598. internalerror(200112261);
  599. end;
  600. { load the conditional register in the destination reg }
  601. list.concat(taicpu.op_reg(A_MFCR,reg));
  602. { we will move the bit that has to be tested to bit 0 by rotating }
  603. { left }
  604. testbit := (32 - testbit) and 31;
  605. { extract bit }
  606. list.concat(taicpu.op_reg_reg_const_const_const(
  607. A_RLWINM,reg,reg,testbit,31,31));
  608. { if we need the inverse, xor with 1 }
  609. if not bitvalue then
  610. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  611. end;
  612. (*
  613. procedure tcgppc.g_cond2reg(list: taasmoutput; const f: TAsmCond; reg: TRegister);
  614. var
  615. testbit: byte;
  616. bitvalue: boolean;
  617. begin
  618. { get the bit to extract from the conditional register + its }
  619. { requested value (0 or 1) }
  620. case f.simple of
  621. false:
  622. begin
  623. { we don't generate this in the compiler }
  624. internalerror(200109062);
  625. end;
  626. true:
  627. case f.cond of
  628. C_None:
  629. internalerror(200109063);
  630. C_LT..C_NU:
  631. begin
  632. testbit := (ord(f.cr) - ord(R_CR0))*4;
  633. inc(testbit,AsmCondFlag2BI[f.cond]);
  634. bitvalue := AsmCondFlagTF[f.cond];
  635. end;
  636. C_T,C_F,C_DNZT,C_DNZF,C_DZT,C_DZF:
  637. begin
  638. testbit := f.crbit
  639. bitvalue := AsmCondFlagTF[f.cond];
  640. end;
  641. else
  642. internalerror(200109064);
  643. end;
  644. end;
  645. { load the conditional register in the destination reg }
  646. list.concat(taicpu.op_reg_reg(A_MFCR,reg));
  647. { we will move the bit that has to be tested to bit 31 -> rotate }
  648. { left by bitpos+1 (remember, this is big-endian!) }
  649. if bitpos <> 31 then
  650. inc(bitpos)
  651. else
  652. bitpos := 0;
  653. { extract bit }
  654. list.concat(taicpu.op_reg_reg_const_const_const(
  655. A_RLWINM,reg,reg,bitpos,31,31));
  656. { if we need the inverse, xor with 1 }
  657. if not bitvalue then
  658. list.concat(taicpu.op_reg_reg_const(A_XORI,reg,reg,1));
  659. end;
  660. *)
  661. { *********** entry/exit code and address loading ************ }
  662. procedure tcgppc.g_stackframe_entry(list : taasmoutput;localsize : longint);
  663. begin
  664. case target_info.system of
  665. system_powerpc_macos:
  666. g_stackframe_entry_mac(list,localsize);
  667. system_powerpc_linux:
  668. g_stackframe_entry_sysv(list,localsize)
  669. else
  670. internalerror(2204001);
  671. end;
  672. end;
  673. procedure tcgppc.g_stackframe_entry_sysv(list : taasmoutput;localsize : longint);
  674. { generated the entry code of a procedure/function. Note: localsize is the }
  675. { sum of the size necessary for local variables and the maximum possible }
  676. { combined size of ALL the parameters of a procedure called by the current }
  677. { one }
  678. var regcounter,firstregfpu,firstreggpr : TRegister;
  679. href : treference;
  680. usesfpr,usesgpr,gotgot : boolean;
  681. parastart : aword;
  682. begin
  683. { CR and LR only have to be saved in case they are modified by the current }
  684. { procedure, but currently this isn't checked, so save them always }
  685. { following is the entry code as described in "Altivec Programming }
  686. { Interface Manual", bar the saving of AltiVec registers }
  687. a_reg_alloc(list,STACK_POINTER_REG);
  688. a_reg_alloc(list,R_0);
  689. { allocate registers containing reg parameters }
  690. for regcounter := R_3 to R_10 do
  691. a_reg_alloc(list,regcounter);
  692. usesfpr:=false;
  693. for regcounter:=R_F14 to R_F31 do
  694. if regcounter in rg.usedbyproc then
  695. begin
  696. usesfpr:=true;
  697. firstregfpu:=regcounter;
  698. break;
  699. end;
  700. usesgpr:=false;
  701. for regcounter:=R_14 to R_31 do
  702. if regcounter in rg.usedbyproc then
  703. begin
  704. usesgpr:=true;
  705. firstreggpr:=regcounter;
  706. break;
  707. end;
  708. { save link register? }
  709. if (procinfo^.flags and pi_do_call)<>0 then
  710. begin
  711. { save return address... }
  712. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_LR));
  713. { ... in caller's rframe }
  714. reference_reset_base(href,STACK_POINTER_REG,4);
  715. list.concat(taicpu.op_reg_ref(A_STW,R_0,href));
  716. a_reg_dealloc(list,R_0);
  717. end;
  718. if usesfpr or usesgpr then
  719. begin
  720. a_reg_alloc(list,R_11);
  721. { save end of fpr save area }
  722. list.concat(taicpu.op_reg_reg_const(A_ORI,R_11,STACK_POINTER_REG,0));
  723. end;
  724. { calculate the size of the locals }
  725. if usesgpr then
  726. inc(localsize,(ord(R_31)-ord(firstreggpr)+1)*4);
  727. if usesfpr then
  728. inc(localsize,(ord(R_F31)-ord(firstregfpu)+1)*8);
  729. { align to 16 bytes }
  730. if (localsize mod 16)<>0 then
  731. localsize:=(localsize and $fffffff0)+16;
  732. parastart:=localsize;
  733. inc(localsize,procinfo^.maxpushedparasize);
  734. { align to 16 bytes }
  735. if (localsize mod 16)<>0 then
  736. localsize:=(localsize and $fffffff0)+16;
  737. procinfo^.procdef.localst.address_fixup:=localsize-parastart;
  738. procinfo^.localsize:=localsize;
  739. reference_reset_base(href,R_1,-localsize);
  740. list.concat(taicpu.op_reg_ref(A_STWU,R_1,href));
  741. { no GOT pointer loaded yet }
  742. gotgot:=false;
  743. if usesfpr then
  744. begin
  745. { save floating-point registers }
  746. if (cs_create_pic in aktmoduleswitches) and not(usesgpr) then
  747. begin
  748. list.concat(taicpu.op_sym_ofs(A_BL,newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+'_g'),0));
  749. gotgot:=true;
  750. end
  751. else
  752. list.concat(taicpu.op_sym_ofs(A_BL,newasmsymbol('_savefpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)),0));
  753. { compute end of gpr save area }
  754. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_11,-(ord(R_F31)-ord(firstregfpu)+1)*8));
  755. end;
  756. { save gprs and fetch GOT pointer }
  757. if usesgpr then
  758. begin
  759. {
  760. if cs_create_pic in aktmoduleswitches then
  761. begin
  762. list.concat(taicpu.op_sym_ofs(A_BL,newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)+'_g'),0));
  763. gotgot:=true;
  764. end
  765. else
  766. list.concat(taicpu.op_sym_ofs(A_BL,newasmsymbol('_savegpr_'+tostr(ord(firstreggpr)-ord(R_14)+14)),0))
  767. }
  768. reference_reset_base(href,R_11,-(ord(R_31)-ord(firstreggpr)+1)*4);
  769. list.concat(taicpu.op_reg_ref(A_STMW,firstreggpr,href));
  770. end;
  771. if usesfpr or usesgpr then
  772. a_reg_dealloc(list,R_11);
  773. { PIC code support, }
  774. if cs_create_pic in aktmoduleswitches then
  775. begin
  776. { if we didn't get the GOT pointer till now, we've to calculate it now }
  777. if not(gotgot) then
  778. begin
  779. {!!!!!!!!!!!!!}
  780. end;
  781. a_reg_alloc(list,R_31);
  782. { place GOT ptr in r31 }
  783. list.concat(taicpu.op_reg_reg(A_MFSPR,R_31,R_LR));
  784. end;
  785. { save the CR if necessary ( !!! always done currently ) }
  786. { still need to find out where this has to be done for SystemV
  787. a_reg_alloc(list,R_0);
  788. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR);
  789. list.concat(taicpu.op_reg_ref(A_STW,scratch_register,
  790. new_reference(STACK_POINTER_REG,LA_CR)));
  791. a_reg_dealloc(list,R_0); }
  792. { now comes the AltiVec context save, not yet implemented !!! }
  793. end;
  794. procedure tcgppc.g_return_from_proc_sysv(list : taasmoutput;parasize : aword);
  795. var
  796. regcounter,firstregfpu,firstreggpr : TRegister;
  797. href : treference;
  798. usesfpr,usesgpr,genret : boolean;
  799. begin
  800. { release parameter registers }
  801. for regcounter := R_3 to R_10 do
  802. a_reg_dealloc(list,regcounter);
  803. { AltiVec context restore, not yet implemented !!! }
  804. usesfpr:=false;
  805. for regcounter:=R_F14 to R_F31 do
  806. if regcounter in rg.usedbyproc then
  807. begin
  808. usesfpr:=true;
  809. firstregfpu:=regcounter;
  810. break;
  811. end;
  812. usesgpr:=false;
  813. for regcounter:=R_14 to R_30 do
  814. if regcounter in rg.usedbyproc then
  815. begin
  816. usesgpr:=true;
  817. firstreggpr:=regcounter;
  818. break;
  819. end;
  820. { no return (blr) generated yet }
  821. genret:=true;
  822. if usesgpr then
  823. begin
  824. { address of gpr save area to r11 }
  825. if usesfpr then
  826. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_1,procinfo^.localsize-(ord(R_F31)-ord(firstregfpu)+1)*8))
  827. else
  828. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_1,procinfo^.localsize));
  829. { restore gprs }
  830. { at least for now we use LMW }
  831. {
  832. list.concat(taicpu.op_sym_ofs(A_BL,newasmsymbol('_restgpr_14'),0));
  833. }
  834. reference_reset_base(href,R_11,-(ord(R_31)-ord(firstreggpr)+1)*4);
  835. list.concat(taicpu.op_reg_ref(A_LMW,firstreggpr,href));
  836. end;
  837. { restore fprs and return }
  838. if usesfpr then
  839. begin
  840. { address of fpr save area to r11 }
  841. list.concat(taicpu.op_reg_reg_const(A_ADDI,R_11,R_11,(ord(R_F31)-ord(firstregfpu)+1)*8));
  842. if (procinfo^.flags and pi_do_call)<>0 then
  843. list.concat(taicpu.op_sym_ofs(A_BL,newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  844. '_x'),0))
  845. else
  846. { leaf node => lr haven't to be restored }
  847. list.concat(taicpu.op_sym_ofs(A_BL,newasmsymbol('_restfpr_'+tostr(ord(firstregfpu)-ord(R_F14)+14)+
  848. '_l'),0));
  849. genret:=false;
  850. end;
  851. { if we didn't generate the return code, we've to do it now }
  852. if genret then
  853. begin
  854. { adjust r1 }
  855. reference_reset_base(href,R_1,procinfo^.localsize);
  856. list.concat(taicpu.op_reg_ref(A_STWU,R_1,href));
  857. { load link register? }
  858. if (procinfo^.flags and pi_do_call)<>0 then
  859. begin
  860. reference_reset_base(href,STACK_POINTER_REG,4);
  861. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  862. list.concat(taicpu.op_reg_reg(A_MTSPR,R_LR,R_0));
  863. end;
  864. list.concat(taicpu.op_none(A_BLR));
  865. end;
  866. end;
  867. procedure tcgppc.g_stackframe_entry_mac(list : taasmoutput;localsize : longint);
  868. { generated the entry code of a procedure/function. Note: localsize is the }
  869. { sum of the size necessary for local variables and the maximum possible }
  870. { combined size of ALL the parameters of a procedure called by the current }
  871. { one }
  872. var regcounter: TRegister;
  873. href : treference;
  874. begin
  875. if (localsize mod 8) <> 0 then internalerror(58991);
  876. { CR and LR only have to be saved in case they are modified by the current }
  877. { procedure, but currently this isn't checked, so save them always }
  878. { following is the entry code as described in "Altivec Programming }
  879. { Interface Manual", bar the saving of AltiVec registers }
  880. a_reg_alloc(list,STACK_POINTER_REG);
  881. a_reg_alloc(list,R_0);
  882. { allocate registers containing reg parameters }
  883. for regcounter := R_3 to R_10 do
  884. a_reg_alloc(list,regcounter);
  885. { save return address... }
  886. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_LR));
  887. { ... in caller's frame }
  888. reference_reset_base(href,STACK_POINTER_REG,8);
  889. list.concat(taicpu.op_reg_ref(A_STW,R_0,href));
  890. a_reg_dealloc(list,R_0);
  891. { save floating-point registers }
  892. { !!! has to be optimized: only save registers that are used }
  893. list.concat(taicpu.op_sym_ofs(A_BL,newasmsymbol('_savef14'),0));
  894. { save gprs in gpr save area }
  895. { !!! has to be optimized: only save registers that are used }
  896. reference_reset_base(href,STACK_POINTER_REG,-220);
  897. list.concat(taicpu.op_reg_ref(A_STMW,R_13,href));
  898. { save the CR if necessary ( !!! always done currently ) }
  899. a_reg_alloc(list,R_0);
  900. list.concat(taicpu.op_reg_reg(A_MFSPR,R_0,R_CR));
  901. reference_reset_base(href,stack_pointer_reg,LA_CR);
  902. list.concat(taicpu.op_reg_ref(A_STW,R_0,href));
  903. a_reg_dealloc(list,R_0);
  904. { save pointer to incoming arguments }
  905. list.concat(taicpu.op_reg_reg_const(A_ORI,R_31,STACK_POINTER_REG,0));
  906. a_reg_alloc(list,R_12);
  907. { 0 or 8 based on SP alignment }
  908. list.concat(taicpu.op_reg_reg_const_const_const(A_RLWINM,
  909. R_12,STACK_POINTER_REG,0,28,28));
  910. { add in stack length }
  911. list.concat(taicpu.op_reg_reg_const(A_SUBFIC,R_12,R_12,
  912. -localsize));
  913. { establish new alignment }
  914. list.concat(taicpu.op_reg_reg_reg(A_STWUX,STACK_POINTER_REG,STACK_POINTER_REG,R_12));
  915. a_reg_dealloc(list,R_12);
  916. { now comes the AltiVec context save, not yet implemented !!! }
  917. end;
  918. procedure tcgppc.g_restore_frame_pointer(list : taasmoutput);
  919. begin
  920. { no frame pointer on the PowerPC (maybe there is one in the SystemV ABI?)}
  921. end;
  922. procedure tcgppc.g_return_from_proc(list : taasmoutput;parasize : aword);
  923. begin
  924. case target_info.system of
  925. system_powerpc_macos:
  926. g_return_from_proc_mac(list,parasize);
  927. system_powerpc_linux:
  928. g_return_from_proc_sysv(list,parasize)
  929. else
  930. internalerror(2204001);
  931. end;
  932. end;
  933. procedure tcgppc.a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);
  934. var
  935. ref2, tmpref: treference;
  936. begin
  937. ref2 := ref;
  938. FixRef(list,ref2);
  939. if assigned(ref2.symbol) then
  940. { add the symbol's value to the base of the reference, and if the }
  941. { reference doesn't have a base, create one }
  942. begin
  943. reference_reset(tmpref);
  944. tmpref.offset := ref2.offset;
  945. tmpref.symbol := ref2.symbol;
  946. tmpref.symaddr := refs_ha;
  947. if ref2.base <> R_NO then
  948. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,r,
  949. ref2.base,tmpref))
  950. else
  951. list.concat(taicpu.op_reg_ref(A_LIS,r,tmpref));
  952. tmpref.base := R_NO;
  953. tmpref.symaddr := refs_l;
  954. { can be folded with one of the next instructions by the }
  955. { optimizer probably }
  956. list.concat(taicpu.op_reg_reg_ref(A_ADDI,r,r,tmpref));
  957. end
  958. else if ref2.offset <> 0 Then
  959. if ref2.base <> R_NO then
  960. a_op_const_reg_reg(list,OP_ADD,OS_32,ref2.offset,ref2.base,r)
  961. { FixRef makes sure that "(ref.index <> R_NO) and (ref.offset <> 0)" never}
  962. { occurs, so now only ref.offset has to be loaded }
  963. else a_load_const_reg(list,OS_32,ref2.offset,r)
  964. else if ref.index <> R_NO Then
  965. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref2.base,ref2.index))
  966. else if (ref2.base <> R_NO) and
  967. (r <> ref2.base) then
  968. list.concat(taicpu.op_reg_reg(A_MR,r,ref2.base));
  969. end;
  970. { ************* concatcopy ************ }
  971. procedure tcgppc.g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword; delsource,loadref : boolean);
  972. var
  973. countreg: TRegister;
  974. src, dst: TReference;
  975. lab: tasmlabel;
  976. count, count2: aword;
  977. orgsrc, orgdst : boolean;
  978. begin
  979. {$ifdef extdebug}
  980. if len > high(longint) then
  981. internalerror(2002072704);
  982. {$endif extdebug}
  983. { make sure short loads are handled as optimally as possible }
  984. if not loadref then
  985. if (len <= 8) and
  986. (byte(len) in [1,2,4,8]) then
  987. begin
  988. if len < 8 then
  989. begin
  990. a_load_ref_ref(list,int_cgsize(len),source,dest);
  991. if delsource then
  992. reference_release(exprasmlist,source);
  993. end
  994. else
  995. begin
  996. a_reg_alloc(list,R_F0);
  997. a_loadfpu_ref_reg(list,OS_F64,source,R_F0);
  998. if delsource then
  999. reference_release(exprasmlist,source);
  1000. a_loadfpu_reg_ref(list,OS_F64,R_F0,dest);
  1001. a_reg_dealloc(list,R_F0);
  1002. end;
  1003. exit;
  1004. end;
  1005. { make sure source and dest are valid }
  1006. src := source;
  1007. fixref(list,src);
  1008. dst := dest;
  1009. fixref(list,dst);
  1010. reference_reset(src);
  1011. reference_reset(dst);
  1012. { load the address of source into src.base }
  1013. if loadref then
  1014. begin
  1015. src.base := get_scratch_reg_address(list);
  1016. a_load_ref_reg(list,OS_32,source,src.base);
  1017. orgsrc := false;
  1018. end
  1019. else if assigned(source.symbol) or
  1020. ((source.offset + longint(len)) > high(smallint)) then
  1021. begin
  1022. src.base := get_scratch_reg_address(list);
  1023. a_loadaddr_ref_reg(list,source,src.base);
  1024. orgsrc := false;
  1025. end
  1026. else
  1027. begin
  1028. src := source;
  1029. orgsrc := true;
  1030. end;
  1031. if not orgsrc and delsource then
  1032. reference_release(exprasmlist,source);
  1033. { load the address of dest into dst.base }
  1034. if assigned(dest.symbol) or
  1035. ((dest.offset + longint(len)) > high(smallint)) then
  1036. begin
  1037. dst.base := get_scratch_reg_address(list);
  1038. a_loadaddr_ref_reg(list,dest,dst.base);
  1039. orgdst := false;
  1040. end
  1041. else
  1042. begin
  1043. dst := dest;
  1044. orgdst := true;
  1045. end;
  1046. count := len div 8;
  1047. if count > 4 then
  1048. { generate a loop }
  1049. begin
  1050. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1051. { have to be set to 8. I put an Inc there so debugging may be }
  1052. { easier (should offset be different from zero here, it will be }
  1053. { easy to notice in the generated assembler }
  1054. inc(dst.offset,8);
  1055. inc(src.offset,8);
  1056. list.concat(taicpu.op_reg_reg_const(A_SUBI,src.base,src.base,8));
  1057. list.concat(taicpu.op_reg_reg_const(A_SUBI,dst.base,dst.base,8));
  1058. countreg := get_scratch_reg_int(list);
  1059. a_load_const_reg(list,OS_32,count,countreg);
  1060. { explicitely allocate R_0 since it can be used safely here }
  1061. { (for holding date that's being copied) }
  1062. a_reg_alloc(list,R_F0);
  1063. getlabel(lab);
  1064. a_label(list, lab);
  1065. list.concat(taicpu.op_reg_reg_const(A_SUBIC_,countreg,countreg,1));
  1066. list.concat(taicpu.op_reg_ref(A_LFDU,R_F0,src));
  1067. list.concat(taicpu.op_reg_ref(A_STFDU,R_F0,dst));
  1068. a_jmp(list,A_BC,C_NE,0,lab);
  1069. free_scratch_reg(list,countreg);
  1070. a_reg_dealloc(list,R_F0);
  1071. len := len mod 8;
  1072. end;
  1073. count := len div 8;
  1074. if count > 0 then
  1075. { unrolled loop }
  1076. begin
  1077. a_reg_alloc(list,R_F0);
  1078. for count2 := 1 to count do
  1079. begin
  1080. a_loadfpu_ref_reg(list,OS_F64,src,R_F0);
  1081. a_loadfpu_reg_ref(list,OS_F64,R_F0,dst);
  1082. inc(src.offset,8);
  1083. inc(dst.offset,8);
  1084. end;
  1085. a_reg_dealloc(list,R_F0);
  1086. len := len mod 8;
  1087. end;
  1088. if (len and 4) <> 0 then
  1089. begin
  1090. a_reg_alloc(list,R_0);
  1091. a_load_ref_reg(list,OS_32,src,R_0);
  1092. a_load_reg_ref(list,OS_32,R_0,dst);
  1093. inc(src.offset,4);
  1094. inc(dst.offset,4);
  1095. a_reg_dealloc(list,R_0);
  1096. end;
  1097. { copy the leftovers }
  1098. if (len and 2) <> 0 then
  1099. begin
  1100. a_reg_alloc(list,R_0);
  1101. a_load_ref_reg(list,OS_16,src,R_0);
  1102. a_load_reg_ref(list,OS_16,R_0,dst);
  1103. inc(src.offset,2);
  1104. inc(dst.offset,2);
  1105. a_reg_dealloc(list,R_0);
  1106. end;
  1107. if (len and 1) <> 0 then
  1108. begin
  1109. a_reg_alloc(list,R_0);
  1110. a_load_ref_reg(list,OS_8,src,R_0);
  1111. a_load_reg_ref(list,OS_8,R_0,dst);
  1112. a_reg_dealloc(list,R_0);
  1113. end;
  1114. if orgsrc then
  1115. begin
  1116. if delsource then
  1117. reference_release(exprasmlist,source);
  1118. end
  1119. else
  1120. free_scratch_reg(list,src.base);
  1121. if not orgdst then
  1122. free_scratch_reg(list,dst.base);
  1123. end;
  1124. procedure tcgppc.g_overflowcheck(list: taasmoutput; const p: tnode);
  1125. var
  1126. hl : tasmlabel;
  1127. begin
  1128. if not(cs_check_overflow in aktlocalswitches) then
  1129. exit;
  1130. getlabel(hl);
  1131. if not ((p.resulttype.def.deftype=pointerdef) or
  1132. ((p.resulttype.def.deftype=orddef) and
  1133. (torddef(p.resulttype.def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,
  1134. bool8bit,bool16bit,bool32bit]))) then
  1135. begin
  1136. list.concat(taicpu.op_reg(A_MCRXR,R_CR7));
  1137. a_jmp(list,A_BC,C_OV,7,hl)
  1138. end
  1139. else
  1140. a_jmp_cond(list,OC_AE,hl);
  1141. a_call_name(list,'FPC_OVERFLOW');
  1142. a_label(list,hl);
  1143. end;
  1144. {***************** This is private property, keep out! :) *****************}
  1145. procedure tcgppc.g_return_from_proc_mac(list : taasmoutput;parasize : aword);
  1146. var
  1147. regcounter: TRegister;
  1148. href : treference;
  1149. begin
  1150. { release parameter registers }
  1151. for regcounter := R_3 to R_10 do
  1152. a_reg_dealloc(list,regcounter);
  1153. { AltiVec context restore, not yet implemented !!! }
  1154. { restore SP }
  1155. list.concat(taicpu.op_reg_reg_const(A_ORI,STACK_POINTER_REG,R_31,0));
  1156. { restore gprs }
  1157. reference_reset_base(href,STACK_POINTER_REG,-220);
  1158. list.concat(taicpu.op_reg_ref(A_LMW,R_13,href));
  1159. { restore return address ... }
  1160. reference_reset_base(href,STACK_POINTER_REG,8);
  1161. list.concat(taicpu.op_reg_ref(A_LWZ,R_0,href));
  1162. { ... and return from _restf14 }
  1163. list.concat(taicpu.op_sym_ofs(A_B,newasmsymbol('_restf14'),0));
  1164. end;
  1165. procedure tcgppc.fixref(list: taasmoutput; var ref: treference);
  1166. begin
  1167. If (ref.base <> R_NO) then
  1168. begin
  1169. if (ref.index <> R_NO) and
  1170. ((ref.offset <> 0) or assigned(ref.symbol)) then
  1171. begin
  1172. if not assigned(ref.symbol) and
  1173. (cardinal(ref.offset-low(smallint)) <=
  1174. high(smallint)-low(smallint)) then
  1175. begin
  1176. list.concat(taicpu.op_reg_reg_const(
  1177. A_ADDI,ref.base,ref.base,ref.offset));
  1178. ref.offset := 0;
  1179. end
  1180. else
  1181. begin
  1182. list.concat(taicpu.op_reg_reg_reg(
  1183. A_ADD,ref.base,ref.base,ref.index));
  1184. ref.index := R_NO;
  1185. end;
  1186. end
  1187. end
  1188. else
  1189. begin
  1190. ref.base := ref.index;
  1191. ref.index := R_NO
  1192. end
  1193. end;
  1194. { find out whether a is of the form 11..00..11b or 00..11...00. If }
  1195. { that's the case, we can use rlwinm to do an AND operation }
  1196. function tcgppc.get_rlwi_const(a: longint; var l1, l2: longint): boolean;
  1197. var
  1198. temp, testbit: longint;
  1199. compare: boolean;
  1200. begin
  1201. get_rlwi_const := false;
  1202. if (a = 0) or (a = $ffffffff) then
  1203. exit;
  1204. { start with the lowest bit }
  1205. testbit := 1;
  1206. { check its value }
  1207. compare := boolean(a and testbit);
  1208. { find out how long the run of bits with this value is }
  1209. { (it's impossible that all bits are 1 or 0, because in that case }
  1210. { this function wouldn't have been called) }
  1211. l1 := 31;
  1212. while (((a and testbit) <> 0) = compare) do
  1213. begin
  1214. testbit := testbit shl 1;
  1215. dec(l1);
  1216. end;
  1217. { check the length of the run of bits that comes next }
  1218. compare := not compare;
  1219. l2 := l1;
  1220. while (((a and testbit) <> 0) = compare) and
  1221. (l2 >= 0) do
  1222. begin
  1223. testbit := testbit shl 1;
  1224. dec(l2);
  1225. end;
  1226. { and finally the check whether the rest of the bits all have the }
  1227. { same value }
  1228. compare := not compare;
  1229. temp := l2;
  1230. if temp >= 0 then
  1231. if (a shr (31-temp)) <> ((-ord(compare)) shr (31-temp)) then
  1232. exit;
  1233. { we have done "not(not(compare))", so compare is back to its }
  1234. { initial value. If the lowest bit was 0, a is of the form }
  1235. { 00..11..00 and we need "rlwinm reg,reg,0,l2+1,l1", (+1 }
  1236. { because l2 now contains the position of the last zero of the }
  1237. { first run instead of that of the first 1) so switch l1 and l2 }
  1238. { in that case (we will generate "rlwinm reg,reg,0,l1,l2") }
  1239. if not compare then
  1240. begin
  1241. temp := l1;
  1242. l1 := l2+1;
  1243. l2 := temp;
  1244. end
  1245. else
  1246. { otherwise, l1 currently contains the position of the last }
  1247. { zero instead of that of the first 1 of the second run -> +1 }
  1248. inc(l1);
  1249. { the following is the same as "if l1 = -1 then l1 := 31;" }
  1250. l1 := l1 and 31;
  1251. l2 := l2 and 31;
  1252. get_rlwi_const := true;
  1253. end;
  1254. procedure tcgppc.a_load_store(list:taasmoutput;op: tasmop;reg:tregister;
  1255. ref: treference);
  1256. var
  1257. tmpreg: tregister;
  1258. tmpref: treference;
  1259. begin
  1260. if assigned(ref.symbol) then
  1261. begin
  1262. tmpreg := get_scratch_reg_address(list);
  1263. reference_reset(tmpref);
  1264. tmpref.symbol := ref.symbol;
  1265. tmpref.symaddr := refs_ha;
  1266. if ref.base <> R_NO then
  1267. list.concat(taicpu.op_reg_reg_ref(A_ADDIS,tmpreg,
  1268. ref.base,tmpref))
  1269. else
  1270. list.concat(taicpu.op_reg_ref(A_LIS,tmpreg,tmpref));
  1271. ref.base := tmpreg;
  1272. ref.symaddr := refs_l;
  1273. end;
  1274. list.concat(taicpu.op_reg_ref(op,reg,ref));
  1275. if assigned(ref.symbol) then
  1276. free_scratch_reg(list,tmpreg);
  1277. end;
  1278. procedure tcgppc.a_jmp(list: taasmoutput; op: tasmop; c: tasmcondflag;
  1279. crval: longint; l: tasmlabel);
  1280. var
  1281. p: taicpu;
  1282. begin
  1283. p := taicpu.op_sym(op,newasmsymbol(l.name));
  1284. if op <> A_B then
  1285. create_cond_norm(c,crval,p.condition);
  1286. p.is_jmp := true;
  1287. list.concat(p)
  1288. end;
  1289. procedure tcg64fppc.a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);
  1290. begin
  1291. a_op64_reg_reg_reg(list,op,regsrc,regdst,regdst);
  1292. end;
  1293. procedure tcg64fppc.a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;reg : tregister64);
  1294. begin
  1295. a_op64_const_reg_reg(list,op,value,reg,reg);
  1296. end;
  1297. procedure tcg64fppc.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1298. begin
  1299. case op of
  1300. OP_AND,OP_OR,OP_XOR:
  1301. begin
  1302. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reglo,regsrc2.reglo,regdst.reglo);
  1303. cg.a_op_reg_reg_reg(list,op,OS_32,regsrc1.reghi,regsrc2.reghi,regdst.reghi);
  1304. end;
  1305. OP_ADD:
  1306. begin
  1307. list.concat(taicpu.op_reg_reg_reg(A_ADDC,regdst.reglo,regsrc1.reglo,regsrc2.reglo));
  1308. list.concat(taicpu.op_reg_reg_reg(A_ADDE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1309. end;
  1310. OP_SUB:
  1311. begin
  1312. list.concat(taicpu.op_reg_reg_reg(A_SUBC,regdst.reglo,regsrc2.reglo,regsrc1.reglo));
  1313. list.concat(taicpu.op_reg_reg_reg(A_SUBFE,regdst.reghi,regsrc1.reghi,regsrc2.reghi));
  1314. end;
  1315. else
  1316. internalerror(2002072801);
  1317. end;
  1318. end;
  1319. procedure tcg64fppc.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);
  1320. const
  1321. ops: array[boolean,1..3] of tasmop = ((A_ADDIC,A_ADDC,A_ADDZE),
  1322. (A_SUBIC,A_SUBC,A_ADDME));
  1323. var
  1324. tmpreg: tregister;
  1325. tmpreg64: tregister64;
  1326. issub: boolean;
  1327. begin
  1328. case op of
  1329. OP_AND,OP_OR,OP_XOR:
  1330. begin
  1331. cg.a_op_const_reg_reg(list,op,OS_32,cardinal(value),regsrc.reglo,regdst.reglo);
  1332. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1333. regdst.reghi);
  1334. end;
  1335. OP_ADD, OP_SUB:
  1336. begin
  1337. if (longint(value) <> 0) then
  1338. begin
  1339. issub := op = OP_SUB;
  1340. if (longint(value)-ord(issub) >= -32768) and
  1341. (longint(value)-ord(issub) <= 32767) then
  1342. begin
  1343. list.concat(taicpu.op_reg_reg_const(ops[issub,1],
  1344. regdst.reglo,regsrc.reglo,longint(value)));
  1345. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1346. regdst.reghi,regsrc.reghi));
  1347. end
  1348. else if ((value shr 32) = 0) then
  1349. begin
  1350. tmpreg := cg.get_scratch_reg_int(list);
  1351. cg.a_load_const_reg(list,OS_32,cardinal(value),tmpreg);
  1352. list.concat(taicpu.op_reg_reg_reg(ops[issub,2],
  1353. regdst.reglo,regsrc.reglo,tmpreg));
  1354. cg.free_scratch_reg(list,tmpreg);
  1355. list.concat(taicpu.op_reg_reg(ops[issub,3],
  1356. regdst.reghi,regsrc.reghi));
  1357. end
  1358. else
  1359. begin
  1360. tmpreg64.reglo := cg.get_scratch_reg_int(list);
  1361. tmpreg64.reghi := cg.get_scratch_reg_int(list);
  1362. a_load64_const_reg(list,value,tmpreg64);
  1363. a_op64_reg_reg_reg(list,op,tmpreg64,regsrc,regdst);
  1364. cg.free_scratch_reg(list,tmpreg64.reghi);
  1365. cg.free_scratch_reg(list,tmpreg64.reglo);
  1366. end
  1367. end
  1368. else
  1369. begin
  1370. cg.a_load_reg_reg(list,OS_INT,regsrc.reglo,regdst.reglo);
  1371. cg.a_op_const_reg_reg(list,op,OS_32,value shr 32,regsrc.reghi,
  1372. regdst.reghi);
  1373. end;
  1374. end;
  1375. else
  1376. internalerror(2002072802);
  1377. end;
  1378. end;
  1379. begin
  1380. cg := tcgppc.create;
  1381. cg64 :=tcg64fppc.create;
  1382. end.
  1383. {
  1384. $Log$
  1385. Revision 1.36 2002-08-06 20:55:23 florian
  1386. * first part of ppc calling conventions fix
  1387. Revision 1.35 2002/08/06 07:12:05 jonas
  1388. * fixed bug in g_flags2reg()
  1389. * and yet more constant operation fixes :)
  1390. Revision 1.34 2002/08/05 08:58:53 jonas
  1391. * fixed compilation problems
  1392. Revision 1.33 2002/08/04 12:57:55 jonas
  1393. * more misc. fixes, mostly constant-related
  1394. Revision 1.32 2002/08/02 11:10:42 jonas
  1395. * some misc constant fixes
  1396. Revision 1.31 2002/07/30 20:50:44 florian
  1397. * the code generator knows now if parameters are in registers
  1398. Revision 1.30 2002/07/29 21:23:44 florian
  1399. * more fixes for the ppc
  1400. + wrappers for the tcnvnode.first_* stuff introduced
  1401. Revision 1.29 2002/07/28 21:38:30 florian
  1402. - removed debug code which was commited by accident
  1403. Revision 1.28 2002/07/28 21:34:31 florian
  1404. * more powerpc fixes
  1405. + dummy tcgvecnode
  1406. Revision 1.27 2002/07/28 16:01:59 jonas
  1407. + tcg64fppc.a_op64_const_reg_reg() and tcg64fppc.a_op64_reg_reg_reg()
  1408. * several fixes, most notably in a_load_reg_reg(): it didn't do any
  1409. conversion from smaller to larger sizes or vice versa
  1410. * some small optimizations
  1411. Revision 1.26 2002/07/27 19:59:29 jonas
  1412. * fixed a_loadaddr_ref_reg()
  1413. * fixed g_flags2reg()
  1414. * optimized g_concatcopy()
  1415. Revision 1.25 2002/07/26 21:15:45 florian
  1416. * rewrote the system handling
  1417. Revision 1.24 2002/07/21 17:00:23 jonas
  1418. * make sure we use rlwi* when possible instead of andi.
  1419. Revision 1.23 2002/07/11 14:41:34 florian
  1420. * start of the new generic parameter handling
  1421. Revision 1.22 2002/07/11 07:38:28 jonas
  1422. + tcg64fpc implementation (only a_op64_reg_reg and a_op64_const_reg for
  1423. now)
  1424. * fixed and improved tcgppc.a_load_const_reg
  1425. * improved tcgppc.a_op_const_reg, tcgppc.a_cmp_const_reg_label
  1426. * A_CMP* -> A_CMPW* (this means that 32bit compares should be done)
  1427. Revision 1.21 2002/07/09 19:45:01 jonas
  1428. * unarynminus and shlshr node fixed for 32bit and smaller ordinals
  1429. * small fixes in the assembler writer
  1430. * changed scratch registers, because they were used by the linker (r11
  1431. and r12) and by the abi under linux (r31)
  1432. Revision 1.20 2002/07/07 09:44:31 florian
  1433. * powerpc target fixed, very simple units can be compiled
  1434. Revision 1.19 2002/05/20 13:30:41 carl
  1435. * bugfix of hdisponen (base must be set, not index)
  1436. * more portability fixes
  1437. Revision 1.18 2002/05/18 13:34:26 peter
  1438. * readded missing revisions
  1439. Revision 1.17 2002/05/16 19:46:53 carl
  1440. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1441. + try to fix temp allocation (still in ifdef)
  1442. + generic constructor calls
  1443. + start of tassembler / tmodulebase class cleanup
  1444. Revision 1.14 2002/05/13 19:52:46 peter
  1445. * a ppcppc can be build again
  1446. Revision 1.13 2002/04/20 21:41:51 carl
  1447. * renamed some constants
  1448. Revision 1.12 2002/04/06 18:13:01 jonas
  1449. * several powerpc-related additions and fixes
  1450. Revision 1.11 2002/01/02 14:53:04 jonas
  1451. * fixed small bug in a_jmp_flags
  1452. }