cgcpu.pas 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998
  1. {
  2. Copyright (c) 1998-2012 by Florian Klaempfl and David Zhang
  3. This unit implements the code generator for MIPS
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit cgcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype, parabase,
  22. cgbase, cgutils, cgobj, cg64f32, cpupara,
  23. aasmbase, aasmtai, aasmcpu, aasmdata,
  24. cpubase, cpuinfo,
  25. node, symconst, SymType, symdef,
  26. rgcpu;
  27. type
  28. TCGMIPS = class(tcg)
  29. public
  30. procedure init_register_allocators; override;
  31. procedure done_register_allocators; override;
  32. function getfpuregister(list: tasmlist; size: Tcgsize): Tregister; override;
  33. /// { needed by cg64 }
  34. procedure make_simple_ref(list: tasmlist; var ref: treference);
  35. procedure handle_reg_const_reg(list: tasmlist; op: Tasmop; src: tregister; a: tcgint; dst: tregister);
  36. procedure maybeadjustresult(list: TAsmList; op: TOpCg; size: tcgsize; dst: tregister);
  37. { parameter }
  38. procedure a_loadfpu_reg_cgpara(list: tasmlist; size: tcgsize; const r: tregister; const paraloc: TCGPara); override;
  39. procedure a_loadfpu_ref_cgpara(list: tasmlist; size: tcgsize; const ref: treference; const paraloc: TCGPara); override;
  40. procedure a_call_name(list: tasmlist; const s: string; weak : boolean); override;
  41. procedure a_call_reg(list: tasmlist; Reg: TRegister); override;
  42. procedure a_call_sym_pic(list: tasmlist; sym: tasmsymbol);
  43. { General purpose instructions }
  44. procedure a_op_const_reg(list: tasmlist; Op: TOpCG; size: tcgsize; a: tcgint; reg: TRegister); override;
  45. procedure a_op_reg_reg(list: tasmlist; Op: TOpCG; size: TCGSize; src, dst: TRegister); override;
  46. procedure a_op_const_reg_reg(list: tasmlist; op: TOpCg; size: tcgsize; a: tcgint; src, dst: tregister); override;
  47. procedure a_op_reg_reg_reg(list: tasmlist; op: TOpCg; size: tcgsize; src1, src2, dst: tregister); override;
  48. procedure a_op_const_reg_reg_checkoverflow(list: tasmlist; op: TOpCg; size: tcgsize; a: tcgint; src, dst: tregister; setflags: boolean; var ovloc: tlocation); override;
  49. procedure a_op_reg_reg_reg_checkoverflow(list: tasmlist; op: TOpCg; size: tcgsize; src1, src2, dst: tregister; setflags: boolean; var ovloc: tlocation); override;
  50. { move instructions }
  51. procedure a_load_const_reg(list: tasmlist; size: tcgsize; a: tcgint; reg: tregister); override;
  52. procedure a_load_const_ref(list: tasmlist; size: tcgsize; a: tcgint; const ref: TReference); override;
  53. procedure a_load_reg_ref(list: tasmlist; FromSize, ToSize: TCgSize; reg: TRegister; const ref: TReference); override;
  54. procedure a_load_ref_reg(list: tasmlist; FromSize, ToSize: TCgSize; const ref: TReference; reg: tregister); override;
  55. procedure a_load_reg_reg(list: tasmlist; FromSize, ToSize: TCgSize; reg1, reg2: tregister); override;
  56. procedure a_loadaddr_ref_reg(list: tasmlist; const ref: TReference; r: tregister); override;
  57. { fpu move instructions }
  58. procedure a_loadfpu_reg_reg(list: tasmlist; fromsize, tosize: tcgsize; reg1, reg2: tregister); override;
  59. procedure a_loadfpu_ref_reg(list: tasmlist; fromsize, tosize: tcgsize; const ref: TReference; reg: tregister); override;
  60. procedure a_loadfpu_reg_ref(list: tasmlist; fromsize, tosize: tcgsize; reg: tregister; const ref: TReference); override;
  61. { comparison operations }
  62. procedure a_cmp_const_reg_label(list: tasmlist; size: tcgsize; cmp_op: topcmp; a: tcgint; reg: tregister; l: tasmlabel); override;
  63. procedure a_cmp_reg_reg_label(list: tasmlist; size: tcgsize; cmp_op: topcmp; reg1, reg2: tregister; l: tasmlabel); override;
  64. procedure a_jmp_always(List: tasmlist; l: TAsmLabel); override;
  65. procedure a_jmp_name(list: tasmlist; const s: string); override;
  66. procedure g_overflowCheck(List: tasmlist; const Loc: TLocation; def: TDef); override;
  67. procedure g_overflowCheck_loc(List: tasmlist; const Loc: TLocation; def: TDef; ovloc: tlocation); override;
  68. procedure g_proc_entry(list: tasmlist; localsize: longint; nostackframe: boolean); override;
  69. procedure g_proc_exit(list: tasmlist; parasize: longint; nostackframe: boolean); override;
  70. procedure g_concatcopy(list: tasmlist; const Source, dest: treference; len: tcgint); override;
  71. procedure g_concatcopy_unaligned(list: tasmlist; const Source, dest: treference; len: tcgint); override;
  72. procedure g_concatcopy_move(list: tasmlist; const Source, dest: treference; len: tcgint);
  73. procedure g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: tcgint); override;
  74. procedure g_intf_wrapper(list: tasmlist; procdef: tprocdef; const labelname: string; ioffset: longint); override;
  75. procedure g_external_wrapper(list : TAsmList; procdef: tprocdef; const externalname: string);override;
  76. procedure g_profilecode(list: TAsmList);override;
  77. { Transform unsupported methods into Internal errors }
  78. procedure a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; size: TCGSize; src, dst: TRegister); override;
  79. procedure g_stackpointer_alloc(list : TAsmList;localsize : longint);override;
  80. end;
  81. TCg64MPSel = class(tcg64f32)
  82. public
  83. procedure a_load64_reg_ref(list: tasmlist; reg: tregister64; const ref: treference); override;
  84. procedure a_load64_ref_reg(list: tasmlist; const ref: treference; reg: tregister64); override;
  85. procedure a_load64_ref_cgpara(list: tasmlist; const r: treference; const paraloc: tcgpara); override;
  86. procedure a_op64_reg_reg(list: tasmlist; op: TOpCG; size: tcgsize; regsrc, regdst: TRegister64); override;
  87. procedure a_op64_const_reg(list: tasmlist; op: TOpCG; size: tcgsize; Value: int64; regdst: TRegister64); override;
  88. procedure a_op64_const_reg_reg(list: tasmlist; op: TOpCG; size: tcgsize; Value: int64; regsrc, regdst: tregister64); override;
  89. procedure a_op64_reg_reg_reg(list: tasmlist; op: TOpCG; size: tcgsize; regsrc1, regsrc2, regdst: tregister64); override;
  90. procedure a_op64_const_reg_reg_checkoverflow(list: tasmlist; op: TOpCG; size: tcgsize; Value: int64; regsrc, regdst: tregister64; setflags: boolean; var ovloc: tlocation); override;
  91. procedure a_op64_reg_reg_reg_checkoverflow(list: tasmlist; op: TOpCG; size: tcgsize; regsrc1, regsrc2, regdst: tregister64; setflags: boolean; var ovloc: tlocation); override;
  92. end;
  93. procedure create_codegen;
  94. const
  95. TOpCmp2AsmCond : array[topcmp] of TAsmCond=(C_NONE,
  96. C_EQ,C_GT,C_LT,C_GE,C_LE,C_NE,C_LEU,C_LTU,C_GEU,C_GTU
  97. );
  98. implementation
  99. uses
  100. globals, verbose, systems, cutils,
  101. paramgr, fmodule,
  102. symtable, symsym,
  103. tgobj,
  104. procinfo, cpupi;
  105. function f_TOpCG2AsmOp(op: TOpCG; size: tcgsize): TAsmOp;
  106. begin
  107. if size = OS_32 then
  108. case op of
  109. OP_ADD: { simple addition }
  110. f_TOpCG2AsmOp := A_ADDU;
  111. OP_AND: { simple logical and }
  112. f_TOpCG2AsmOp := A_AND;
  113. OP_DIV: { simple unsigned division }
  114. f_TOpCG2AsmOp := A_DIVU;
  115. OP_IDIV: { simple signed division }
  116. f_TOpCG2AsmOp := A_DIV;
  117. OP_IMUL: { simple signed multiply }
  118. f_TOpCG2AsmOp := A_MULT;
  119. OP_MUL: { simple unsigned multiply }
  120. f_TOpCG2AsmOp := A_MULTU;
  121. OP_NEG: { simple negate }
  122. f_TOpCG2AsmOp := A_NEGU;
  123. OP_NOT: { simple logical not }
  124. f_TOpCG2AsmOp := A_NOT;
  125. OP_OR: { simple logical or }
  126. f_TOpCG2AsmOp := A_OR;
  127. OP_SAR: { arithmetic shift-right }
  128. f_TOpCG2AsmOp := A_SRA;
  129. OP_SHL: { logical shift left }
  130. f_TOpCG2AsmOp := A_SLL;
  131. OP_SHR: { logical shift right }
  132. f_TOpCG2AsmOp := A_SRL;
  133. OP_SUB: { simple subtraction }
  134. f_TOpCG2AsmOp := A_SUBU;
  135. OP_XOR: { simple exclusive or }
  136. f_TOpCG2AsmOp := A_XOR;
  137. else
  138. InternalError(2007070401);
  139. end{ case }
  140. else
  141. case op of
  142. OP_ADD: { simple addition }
  143. f_TOpCG2AsmOp := A_ADDU;
  144. OP_AND: { simple logical and }
  145. f_TOpCG2AsmOp := A_AND;
  146. OP_DIV: { simple unsigned division }
  147. f_TOpCG2AsmOp := A_DIVU;
  148. OP_IDIV: { simple signed division }
  149. f_TOpCG2AsmOp := A_DIV;
  150. OP_IMUL: { simple signed multiply }
  151. f_TOpCG2AsmOp := A_MULT;
  152. OP_MUL: { simple unsigned multiply }
  153. f_TOpCG2AsmOp := A_MULTU;
  154. OP_NEG: { simple negate }
  155. f_TOpCG2AsmOp := A_NEGU;
  156. OP_NOT: { simple logical not }
  157. f_TOpCG2AsmOp := A_NOT;
  158. OP_OR: { simple logical or }
  159. f_TOpCG2AsmOp := A_OR;
  160. OP_SAR: { arithmetic shift-right }
  161. f_TOpCG2AsmOp := A_SRA;
  162. OP_SHL: { logical shift left }
  163. f_TOpCG2AsmOp := A_SLL;
  164. OP_SHR: { logical shift right }
  165. f_TOpCG2AsmOp := A_SRL;
  166. OP_SUB: { simple subtraction }
  167. f_TOpCG2AsmOp := A_SUBU;
  168. OP_XOR: { simple exclusive or }
  169. f_TOpCG2AsmOp := A_XOR;
  170. else
  171. InternalError(2007010701);
  172. end;{ case }
  173. end;
  174. function f_TOpCG2AsmOp_ovf(op: TOpCG; size: tcgsize): TAsmOp;
  175. begin
  176. if size = OS_32 then
  177. case op of
  178. OP_ADD: { simple addition }
  179. f_TOpCG2AsmOp_ovf := A_ADD;
  180. OP_AND: { simple logical and }
  181. f_TOpCG2AsmOp_ovf := A_AND;
  182. OP_DIV: { simple unsigned division }
  183. f_TOpCG2AsmOp_ovf := A_DIVU;
  184. OP_IDIV: { simple signed division }
  185. f_TOpCG2AsmOp_ovf := A_DIV;
  186. OP_IMUL: { simple signed multiply }
  187. f_TOpCG2AsmOp_ovf := A_MULO;
  188. OP_MUL: { simple unsigned multiply }
  189. f_TOpCG2AsmOp_ovf := A_MULOU;
  190. OP_NEG: { simple negate }
  191. f_TOpCG2AsmOp_ovf := A_NEG;
  192. OP_NOT: { simple logical not }
  193. f_TOpCG2AsmOp_ovf := A_NOT;
  194. OP_OR: { simple logical or }
  195. f_TOpCG2AsmOp_ovf := A_OR;
  196. OP_SAR: { arithmetic shift-right }
  197. f_TOpCG2AsmOp_ovf := A_SRA;
  198. OP_SHL: { logical shift left }
  199. f_TOpCG2AsmOp_ovf := A_SLL;
  200. OP_SHR: { logical shift right }
  201. f_TOpCG2AsmOp_ovf := A_SRL;
  202. OP_SUB: { simple subtraction }
  203. f_TOpCG2AsmOp_ovf := A_SUB;
  204. OP_XOR: { simple exclusive or }
  205. f_TOpCG2AsmOp_ovf := A_XOR;
  206. else
  207. InternalError(2007070403);
  208. end{ case }
  209. else
  210. case op of
  211. OP_ADD: { simple addition }
  212. f_TOpCG2AsmOp_ovf := A_ADD;
  213. OP_AND: { simple logical and }
  214. f_TOpCG2AsmOp_ovf := A_AND;
  215. OP_DIV: { simple unsigned division }
  216. f_TOpCG2AsmOp_ovf := A_DIVU;
  217. OP_IDIV: { simple signed division }
  218. f_TOpCG2AsmOp_ovf := A_DIV;
  219. OP_IMUL: { simple signed multiply }
  220. f_TOpCG2AsmOp_ovf := A_MULO;
  221. OP_MUL: { simple unsigned multiply }
  222. f_TOpCG2AsmOp_ovf := A_MULOU;
  223. OP_NEG: { simple negate }
  224. f_TOpCG2AsmOp_ovf := A_NEG;
  225. OP_NOT: { simple logical not }
  226. f_TOpCG2AsmOp_ovf := A_NOT;
  227. OP_OR: { simple logical or }
  228. f_TOpCG2AsmOp_ovf := A_OR;
  229. OP_SAR: { arithmetic shift-right }
  230. f_TOpCG2AsmOp_ovf := A_SRA;
  231. OP_SHL: { logical shift left }
  232. f_TOpCG2AsmOp_ovf := A_SLL;
  233. OP_SHR: { logical shift right }
  234. f_TOpCG2AsmOp_ovf := A_SRL;
  235. OP_SUB: { simple subtraction }
  236. f_TOpCG2AsmOp_ovf := A_SUB;
  237. OP_XOR: { simple exclusive or }
  238. f_TOpCG2AsmOp_ovf := A_XOR;
  239. else
  240. InternalError(2007010703);
  241. end;{ case }
  242. end;
  243. procedure TCGMIPS.make_simple_ref(list: tasmlist; var ref: treference);
  244. var
  245. tmpreg, tmpreg1: tregister;
  246. tmpref: treference;
  247. base_replaced: boolean;
  248. begin
  249. { Enforce some discipline for callers:
  250. - gp is always implicit
  251. - reference is processed only once }
  252. if (ref.base=NR_GP) or (ref.index=NR_GP) then
  253. InternalError(2013022801);
  254. if (ref.refaddr<>addr_no) then
  255. InternalError(2013022802);
  256. { fixup base/index, if both are present then add them together }
  257. base_replaced:=false;
  258. tmpreg:=ref.base;
  259. if (tmpreg=NR_NO) then
  260. tmpreg:=ref.index
  261. else if (ref.index<>NR_NO) then
  262. begin
  263. tmpreg:=getintregister(list,OS_ADDR);
  264. list.concat(taicpu.op_reg_reg_reg(A_ADDU,tmpreg,ref.base,ref.index));
  265. base_replaced:=true;
  266. end;
  267. ref.base:=tmpreg;
  268. ref.index:=NR_NO;
  269. if (ref.symbol=nil) and
  270. (ref.offset>=simm16lo) and
  271. (ref.offset<=simm16hi-sizeof(pint)) then
  272. exit;
  273. { Symbol present or offset > 16bits }
  274. if assigned(ref.symbol) then
  275. begin
  276. ref.base:=getintregister(list,OS_ADDR);
  277. reference_reset_symbol(tmpref,ref.symbol,ref.offset,ref.alignment);
  278. if (cs_create_pic in current_settings.moduleswitches) then
  279. begin
  280. { For PIC global symbols offset must be handled separately.
  281. Otherwise (non-PIC or local symbols) offset can be encoded
  282. into relocation even if exceeds 16 bits. }
  283. if (ref.symbol.bind<>AB_LOCAL) then
  284. tmpref.offset:=0;
  285. tmpref.refaddr:=addr_pic;
  286. tmpref.base:=NR_GP;
  287. list.concat(taicpu.op_reg_ref(A_LW,ref.base,tmpref));
  288. end
  289. else
  290. begin
  291. tmpref.refaddr:=addr_high;
  292. list.concat(taicpu.op_reg_ref(A_LUI,ref.base,tmpref));
  293. end;
  294. { Add original base/index, if any. }
  295. if (tmpreg<>NR_NO) then
  296. list.concat(taicpu.op_reg_reg_reg(A_ADDU,ref.base,tmpreg,ref.base));
  297. if (ref.symbol.bind=AB_LOCAL) or
  298. not (cs_create_pic in current_settings.moduleswitches) then
  299. begin
  300. ref.refaddr:=addr_low;
  301. exit;
  302. end;
  303. { PIC global symbol }
  304. ref.symbol:=nil;
  305. if (ref.offset=0) then
  306. exit;
  307. if (ref.offset>=simm16lo) and
  308. (ref.offset<=simm16hi-sizeof(pint)) then
  309. begin
  310. list.concat(taicpu.op_reg_reg_const(A_ADDIU,ref.base,ref.base,ref.offset));
  311. ref.offset:=0;
  312. exit;
  313. end;
  314. { fallthrough to the case of large offset }
  315. end;
  316. tmpreg1:=getintregister(list,OS_INT);
  317. a_load_const_reg(list,OS_INT,ref.offset,tmpreg1);
  318. if (ref.base=NR_NO) then
  319. ref.base:=tmpreg1 { offset alone, weird but possible }
  320. else
  321. begin
  322. if (not base_replaced) then
  323. ref.base:=getintregister(list,OS_ADDR);
  324. list.concat(taicpu.op_reg_reg_reg(A_ADDU,ref.base,tmpreg,tmpreg1))
  325. end;
  326. ref.offset:=0;
  327. end;
  328. procedure TCGMIPS.handle_reg_const_reg(list: tasmlist; op: Tasmop; src: tregister; a: tcgint; dst: tregister);
  329. var
  330. tmpreg: tregister;
  331. begin
  332. if (a < simm16lo) or
  333. (a > simm16hi) then
  334. begin
  335. tmpreg := GetIntRegister(list, OS_INT);
  336. a_load_const_reg(list, OS_INT, a, tmpreg);
  337. list.concat(taicpu.op_reg_reg_reg(op, dst, src, tmpreg));
  338. end
  339. else
  340. list.concat(taicpu.op_reg_reg_const(op, dst, src, a));
  341. end;
  342. {****************************************************************************
  343. Assembler code
  344. ****************************************************************************}
  345. procedure TCGMIPS.init_register_allocators;
  346. begin
  347. inherited init_register_allocators;
  348. { Keep RS_R25, i.e. $t9 for PIC call }
  349. if (cs_create_pic in current_settings.moduleswitches) and assigned(current_procinfo) and
  350. (pi_needs_got in current_procinfo.flags) then
  351. begin
  352. current_procinfo.got := NR_GP;
  353. rg[R_INTREGISTER] := Trgcpu.Create(R_INTREGISTER, R_SUBD,
  354. [RS_R2,RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,RS_R9,
  355. RS_R10,RS_R11,RS_R12,RS_R13,RS_R14,RS_R15,RS_R16,RS_R17,RS_R18,RS_R19,
  356. RS_R20,RS_R21,RS_R22,RS_R23,RS_R24{,RS_R25}],
  357. first_int_imreg, []);
  358. end
  359. else
  360. rg[R_INTREGISTER] := trgcpu.Create(R_INTREGISTER, R_SUBD,
  361. [RS_R2,RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,RS_R9,
  362. RS_R10,RS_R11,RS_R12,RS_R13,RS_R14,RS_R15,RS_R16,RS_R17,RS_R18,RS_R19,
  363. RS_R20,RS_R21,RS_R22,RS_R23,RS_R24{,RS_R25}],
  364. first_int_imreg, []);
  365. {
  366. rg[R_FPUREGISTER] := trgcpu.Create(R_FPUREGISTER, R_SUBFS,
  367. [RS_F0,RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7,
  368. RS_F8,RS_F9,RS_F10,RS_F11,RS_F12,RS_F13,RS_F14,RS_F15,
  369. RS_F16,RS_F17,RS_F18,RS_F19,RS_F20,RS_F21,RS_F22,RS_F23,
  370. RS_F24,RS_F25,RS_F26,RS_F27,RS_F28,RS_F29,RS_F30,RS_F31],
  371. first_fpu_imreg, []);
  372. }
  373. rg[R_FPUREGISTER] := trgcpu.Create(R_FPUREGISTER, R_SUBFS,
  374. [RS_F0,RS_F2,RS_F4,RS_F6, RS_F8,RS_F10,RS_F12,RS_F14,
  375. RS_F16,RS_F18,RS_F20,RS_F22, RS_F24,RS_F26,RS_F28,RS_F30],
  376. first_fpu_imreg, []);
  377. { needs at least one element for rgobj not to crash }
  378. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,
  379. [RS_R0],first_mm_imreg,[]);
  380. end;
  381. procedure TCGMIPS.done_register_allocators;
  382. begin
  383. rg[R_INTREGISTER].Free;
  384. rg[R_FPUREGISTER].Free;
  385. rg[R_MMREGISTER].Free;
  386. inherited done_register_allocators;
  387. end;
  388. function TCGMIPS.getfpuregister(list: tasmlist; size: Tcgsize): Tregister;
  389. begin
  390. if size = OS_F64 then
  391. Result := rg[R_FPUREGISTER].getregister(list, R_SUBFD)
  392. else
  393. Result := rg[R_FPUREGISTER].getregister(list, R_SUBFS);
  394. end;
  395. procedure TCGMIPS.a_loadfpu_ref_cgpara(list: tasmlist; size: tcgsize; const ref: treference; const paraloc: TCGPara);
  396. var
  397. href, href2: treference;
  398. hloc: pcgparalocation;
  399. begin
  400. { TODO: inherited cannot deal with individual locations for each of OS_32 registers.
  401. Must change parameter management to allocate a single 64-bit register pair,
  402. then this method can be removed. }
  403. href := ref;
  404. hloc := paraloc.location;
  405. while assigned(hloc) do
  406. begin
  407. paramanager.allocparaloc(list,hloc);
  408. case hloc^.loc of
  409. LOC_REGISTER:
  410. a_load_ref_reg(list, hloc^.size, hloc^.size, href, hloc^.Register);
  411. LOC_FPUREGISTER,LOC_CFPUREGISTER :
  412. a_loadfpu_ref_reg(list,hloc^.size,hloc^.size,href,hloc^.register);
  413. LOC_REFERENCE:
  414. begin
  415. paraloc.check_simple_location;
  416. reference_reset_base(href2,paraloc.location^.reference.index,paraloc.location^.reference.offset,paraloc.alignment);
  417. { concatcopy should choose the best way to copy the data }
  418. g_concatcopy(list,ref,href2,tcgsize2size[size]);
  419. end;
  420. else
  421. internalerror(200408241);
  422. end;
  423. Inc(href.offset, tcgsize2size[hloc^.size]);
  424. hloc := hloc^.Next;
  425. end;
  426. end;
  427. procedure TCGMIPS.a_loadfpu_reg_cgpara(list: tasmlist; size: tcgsize; const r: tregister; const paraloc: TCGPara);
  428. var
  429. href: treference;
  430. begin
  431. if paraloc.Location^.next=nil then
  432. begin
  433. inherited a_loadfpu_reg_cgpara(list,size,r,paraloc);
  434. exit;
  435. end;
  436. tg.GetTemp(list, TCGSize2Size[size], TCGSize2Size[size], tt_normal, href);
  437. a_loadfpu_reg_ref(list, size, size, r, href);
  438. a_loadfpu_ref_cgpara(list, size, href, paraloc);
  439. tg.Ungettemp(list, href);
  440. end;
  441. procedure TCGMIPS.a_call_sym_pic(list: tasmlist; sym: tasmsymbol);
  442. var
  443. href: treference;
  444. begin
  445. reference_reset_symbol(href,sym,0,sizeof(aint));
  446. if (sym.bind=AB_LOCAL) then
  447. href.refaddr:=addr_pic
  448. else
  449. href.refaddr:=addr_pic_call16;
  450. href.base:=NR_GP;
  451. list.concat(taicpu.op_reg_ref(A_LW,NR_PIC_FUNC,href));
  452. if (sym.bind=AB_LOCAL) then
  453. begin
  454. href.refaddr:=addr_low;
  455. list.concat(taicpu.op_reg_ref(A_ADDIU,NR_PIC_FUNC,href));
  456. end;
  457. { JAL handled as macro provides delay slot and correct restoring of GP. }
  458. { Doing it ourselves requires a fixup pass, because GP restore location
  459. becomes known only in g_proc_entry, when all code is already generated. }
  460. { GAS <2.21 is buggy, it doesn't add delay slot in noreorder mode. As a result,
  461. the code will crash if dealing with stack frame size >32767 or if calling
  462. into shared library.
  463. This can be remedied by enabling instruction reordering, but then we also
  464. have to emit .set macro/.set nomacro pair and exclude JAL from the
  465. list of macro instructions (because noreorder is not allowed after nomacro) }
  466. list.concat(taicpu.op_none(A_P_SET_MACRO));
  467. list.concat(taicpu.op_none(A_P_SET_REORDER));
  468. list.concat(taicpu.op_reg(A_JAL,NR_PIC_FUNC));
  469. list.concat(taicpu.op_none(A_P_SET_NOREORDER));
  470. list.concat(taicpu.op_none(A_P_SET_NOMACRO));
  471. end;
  472. procedure TCGMIPS.a_call_name(list: tasmlist; const s: string; weak: boolean);
  473. var
  474. sym: tasmsymbol;
  475. begin
  476. if assigned(current_procinfo) and
  477. not (pi_do_call in current_procinfo.flags) then
  478. InternalError(2013022101);
  479. if weak then
  480. sym:=current_asmdata.WeakRefAsmSymbol(s)
  481. else
  482. sym:=current_asmdata.RefAsmSymbol(s);
  483. if (cs_create_pic in current_settings.moduleswitches) then
  484. a_call_sym_pic(list,sym)
  485. else
  486. begin
  487. list.concat(taicpu.op_sym(A_JAL,sym));
  488. { Delay slot }
  489. list.concat(taicpu.op_none(A_NOP));
  490. end;
  491. end;
  492. procedure TCGMIPS.a_call_reg(list: tasmlist; Reg: TRegister);
  493. begin
  494. if assigned(current_procinfo) and
  495. not (pi_do_call in current_procinfo.flags) then
  496. InternalError(2013022102);
  497. // if (cs_create_pic in current_settings.moduleswitches) then
  498. begin
  499. if (Reg <> NR_PIC_FUNC) then
  500. list.concat(taicpu.op_reg_reg(A_MOVE,NR_PIC_FUNC,reg));
  501. { See comments in a_call_name }
  502. list.concat(taicpu.op_none(A_P_SET_MACRO));
  503. list.concat(taicpu.op_none(A_P_SET_REORDER));
  504. list.concat(taicpu.op_reg(A_JAL,NR_PIC_FUNC));
  505. list.concat(taicpu.op_none(A_P_SET_NOREORDER));
  506. list.concat(taicpu.op_none(A_P_SET_NOMACRO));
  507. (* end
  508. else
  509. begin
  510. list.concat(taicpu.op_reg(A_JALR, reg));
  511. { Delay slot }
  512. list.concat(taicpu.op_none(A_NOP)); *)
  513. end;
  514. end;
  515. {********************** load instructions ********************}
  516. procedure TCGMIPS.a_load_const_reg(list: tasmlist; size: TCGSize; a: tcgint; reg: TRegister);
  517. begin
  518. if (a = 0) then
  519. list.concat(taicpu.op_reg_reg(A_MOVE, reg, NR_R0))
  520. { LUI allows to set the upper 16 bits, so we'll take full advantage of it }
  521. else if (a and aint($ffff)) = 0 then
  522. list.concat(taicpu.op_reg_const(A_LUI, reg, aint(a) shr 16))
  523. else if (a >= simm16lo) and (a <= simm16hi) then
  524. list.concat(taicpu.op_reg_reg_const(A_ADDIU, reg, NR_R0, a))
  525. else if (a>=0) and (a <= 65535) then
  526. list.concat(taicpu.op_reg_reg_const(A_ORI, reg, NR_R0, a))
  527. else
  528. begin
  529. list.concat(taicpu.op_reg_const(A_LI, reg, aint(a) ));
  530. end;
  531. end;
  532. procedure TCGMIPS.a_load_const_ref(list: tasmlist; size: tcgsize; a: tcgint; const ref: TReference);
  533. begin
  534. if a = 0 then
  535. a_load_reg_ref(list, size, size, NR_R0, ref)
  536. else
  537. inherited a_load_const_ref(list, size, a, ref);
  538. end;
  539. procedure TCGMIPS.a_load_reg_ref(list: tasmlist; FromSize, ToSize: TCGSize; reg: tregister; const Ref: TReference);
  540. var
  541. op: tasmop;
  542. href: treference;
  543. begin
  544. if (TCGSize2Size[fromsize] < TCGSize2Size[tosize]) then
  545. a_load_reg_reg(list,fromsize,tosize,reg,reg);
  546. case tosize of
  547. OS_8,
  548. OS_S8:
  549. Op := A_SB;
  550. OS_16,
  551. OS_S16:
  552. Op := A_SH;
  553. OS_32,
  554. OS_S32:
  555. Op := A_SW;
  556. else
  557. InternalError(2002122100);
  558. end;
  559. href:=ref;
  560. make_simple_ref(list,href);
  561. list.concat(taicpu.op_reg_ref(op,reg,href));
  562. end;
  563. procedure TCGMIPS.a_load_ref_reg(list: tasmlist; FromSize, ToSize: TCgSize; const ref: TReference; reg: tregister);
  564. var
  565. op: tasmop;
  566. href: treference;
  567. begin
  568. if (TCGSize2Size[fromsize] >= TCGSize2Size[tosize]) then
  569. fromsize := tosize;
  570. case fromsize of
  571. OS_S8:
  572. Op := A_LB;{Load Signed Byte}
  573. OS_8:
  574. Op := A_LBU;{Load Unsigned Byte}
  575. OS_S16:
  576. Op := A_LH;{Load Signed Halfword}
  577. OS_16:
  578. Op := A_LHU;{Load Unsigned Halfword}
  579. OS_S32:
  580. Op := A_LW;{Load Word}
  581. OS_32:
  582. Op := A_LW;//A_LWU;{Load Unsigned Word}
  583. OS_S64,
  584. OS_64:
  585. Op := A_LD;{Load a Long Word}
  586. else
  587. InternalError(2002122101);
  588. end;
  589. href:=ref;
  590. make_simple_ref(list,href);
  591. list.concat(taicpu.op_reg_ref(op,reg,href));
  592. if (fromsize=OS_S8) and (tosize=OS_16) then
  593. a_load_reg_reg(list,fromsize,tosize,reg,reg);
  594. end;
  595. procedure TCGMIPS.a_load_reg_reg(list: tasmlist; fromsize, tosize: tcgsize; reg1, reg2: tregister);
  596. var
  597. instr: taicpu;
  598. begin
  599. if (tcgsize2size[tosize] < tcgsize2size[fromsize]) or
  600. (
  601. (tcgsize2size[tosize] = tcgsize2size[fromsize]) and (tosize <> fromsize)
  602. ) or ((fromsize = OS_S8) and
  603. (tosize = OS_16)) then
  604. begin
  605. case tosize of
  606. OS_8:
  607. list.concat(taicpu.op_reg_reg_const(A_ANDI, reg2, reg1, $ff));
  608. OS_16:
  609. list.concat(taicpu.op_reg_reg_const(A_ANDI, reg2, reg1, $ffff));
  610. OS_32,
  611. OS_S32:
  612. begin
  613. instr := taicpu.op_reg_reg(A_MOVE, reg2, reg1);
  614. list.Concat(instr);
  615. { Notify the register allocator that we have written a move instruction so
  616. it can try to eliminate it. }
  617. add_move_instruction(instr);
  618. end;
  619. OS_S8:
  620. begin
  621. list.concat(taicpu.op_reg_reg_const(A_SLL, reg2, reg1, 24));
  622. list.concat(taicpu.op_reg_reg_const(A_SRA, reg2, reg2, 24));
  623. end;
  624. OS_S16:
  625. begin
  626. list.concat(taicpu.op_reg_reg_const(A_SLL, reg2, reg1, 16));
  627. list.concat(taicpu.op_reg_reg_const(A_SRA, reg2, reg2, 16));
  628. end;
  629. else
  630. internalerror(2002090901);
  631. end;
  632. end
  633. else
  634. begin
  635. if reg1 <> reg2 then
  636. begin
  637. { same size, only a register mov required }
  638. instr := taicpu.op_reg_reg(A_MOVE, reg2, reg1);
  639. list.Concat(instr);
  640. // { Notify the register allocator that we have written a move instruction so
  641. // it can try to eliminate it. }
  642. add_move_instruction(instr);
  643. end;
  644. end;
  645. end;
  646. procedure TCGMIPS.a_loadaddr_ref_reg(list: tasmlist; const ref: TReference; r: tregister);
  647. var
  648. href: treference;
  649. hreg: tregister;
  650. begin
  651. { Enforce some discipline for callers:
  652. - reference must be a "raw" one and not use gp }
  653. if (ref.base=NR_GP) or (ref.index=NR_GP) then
  654. InternalError(2013022803);
  655. if (ref.refaddr<>addr_no) then
  656. InternalError(2013022804);
  657. if (ref.base=NR_NO) and (ref.index<>NR_NO) then
  658. InternalError(200306171);
  659. if (ref.symbol=nil) then
  660. begin
  661. if (ref.base<>NR_NO) then
  662. begin
  663. if (ref.offset<simm16lo) or (ref.offset>simm16hi) then
  664. begin
  665. hreg:=getintregister(list,OS_INT);
  666. a_load_const_reg(list,OS_INT,ref.offset,hreg);
  667. list.concat(taicpu.op_reg_reg_reg(A_ADDU,r,ref.base,hreg));
  668. end
  669. else if (ref.offset<>0) then
  670. list.concat(taicpu.op_reg_reg_const(A_ADDIU,r,ref.base,ref.offset))
  671. else
  672. a_load_reg_reg(list,OS_INT,OS_INT,ref.base,r); { emit optimizable move }
  673. if (ref.index<>NR_NO) then
  674. list.concat(taicpu.op_reg_reg_reg(A_ADDU,r,r,ref.index));
  675. end
  676. else
  677. a_load_const_reg(list,OS_INT,ref.offset,r);
  678. exit;
  679. end;
  680. reference_reset_symbol(href,ref.symbol,ref.offset,ref.alignment);
  681. if (cs_create_pic in current_settings.moduleswitches) then
  682. begin
  683. { For PIC global symbols offset must be handled separately.
  684. Otherwise (non-PIC or local symbols) offset can be encoded
  685. into relocation even if exceeds 16 bits. }
  686. if (href.symbol.bind<>AB_LOCAL) then
  687. href.offset:=0;
  688. href.refaddr:=addr_pic;
  689. href.base:=NR_GP;
  690. list.concat(taicpu.op_reg_ref(A_LW,r,href));
  691. end
  692. else
  693. begin
  694. href.refaddr:=addr_high;
  695. list.concat(taicpu.op_reg_ref(A_LUI,r,href));
  696. end;
  697. { Add original base/index, if any. }
  698. if (ref.base<>NR_NO) then
  699. list.concat(taicpu.op_reg_reg_reg(A_ADDU,r,r,ref.base));
  700. if (ref.index<>NR_NO) then
  701. list.concat(taicpu.op_reg_reg_reg(A_ADDU,r,r,ref.index));
  702. { add low part if necessary }
  703. if (ref.symbol.bind=AB_LOCAL) or
  704. not (cs_create_pic in current_settings.moduleswitches) then
  705. begin
  706. href.refaddr:=addr_low;
  707. href.base:=NR_NO;
  708. list.concat(taicpu.op_reg_reg_ref(A_ADDIU,r,r,href));
  709. exit;
  710. end;
  711. if (ref.offset<simm16lo) or (ref.offset>simm16hi) then
  712. begin
  713. hreg:=getintregister(list,OS_INT);
  714. a_load_const_reg(list,OS_INT,ref.offset,hreg);
  715. list.concat(taicpu.op_reg_reg_reg(A_ADDU,r,r,hreg));
  716. end
  717. else if (ref.offset<>0) then
  718. list.concat(taicpu.op_reg_reg_const(A_ADDIU,r,r,ref.offset));
  719. end;
  720. procedure TCGMIPS.a_loadfpu_reg_reg(list: tasmlist; fromsize, tosize: tcgsize; reg1, reg2: tregister);
  721. const
  722. FpuMovInstr: array[OS_F32..OS_F64,OS_F32..OS_F64] of TAsmOp =
  723. ((A_MOV_S, A_CVT_D_S),(A_CVT_S_D,A_MOV_D));
  724. var
  725. instr: taicpu;
  726. begin
  727. if (reg1 <> reg2) or (fromsize<>tosize) then
  728. begin
  729. instr := taicpu.op_reg_reg(fpumovinstr[fromsize,tosize], reg2, reg1);
  730. list.Concat(instr);
  731. { Notify the register allocator that we have written a move instruction so
  732. it can try to eliminate it. }
  733. if (fromsize=tosize) then
  734. add_move_instruction(instr);
  735. end;
  736. end;
  737. procedure TCGMIPS.a_loadfpu_ref_reg(list: tasmlist; fromsize, tosize: tcgsize; const ref: TReference; reg: tregister);
  738. var
  739. href: TReference;
  740. begin
  741. href:=ref;
  742. make_simple_ref(list,href);
  743. case fromsize of
  744. OS_F32:
  745. list.concat(taicpu.op_reg_ref(A_LWC1,reg,href));
  746. OS_F64:
  747. list.concat(taicpu.op_reg_ref(A_LDC1,reg,href));
  748. else
  749. InternalError(2007042701);
  750. end;
  751. if tosize<>fromsize then
  752. a_loadfpu_reg_reg(list,fromsize,tosize,reg,reg);
  753. end;
  754. procedure TCGMIPS.a_loadfpu_reg_ref(list: tasmlist; fromsize, tosize: tcgsize; reg: tregister; const ref: TReference);
  755. var
  756. href: TReference;
  757. begin
  758. if tosize<>fromsize then
  759. a_loadfpu_reg_reg(list,fromsize,tosize,reg,reg);
  760. href:=ref;
  761. make_simple_ref(list,href);
  762. case tosize of
  763. OS_F32:
  764. list.concat(taicpu.op_reg_ref(A_SWC1,reg,href));
  765. OS_F64:
  766. list.concat(taicpu.op_reg_ref(A_SDC1,reg,href));
  767. else
  768. InternalError(2007042702);
  769. end;
  770. end;
  771. procedure TCGMIPS.maybeadjustresult(list: TAsmList; op: TOpCg; size: tcgsize; dst: tregister);
  772. const
  773. overflowops = [OP_MUL,OP_SHL,OP_ADD,OP_SUB,OP_NOT,OP_NEG];
  774. begin
  775. if (op in overflowops) and
  776. (size in [OS_8,OS_S8,OS_16,OS_S16]) then
  777. a_load_reg_reg(list,OS_32,size,dst,dst);
  778. end;
  779. procedure TCGMIPS.a_op_const_reg(list: tasmlist; Op: TOpCG; size: tcgsize; a: tcgint; reg: TRegister);
  780. var
  781. power: longint;
  782. tmpreg1: tregister;
  783. begin
  784. if ((op = OP_MUL) or (op = OP_IMUL)) then
  785. begin
  786. if ispowerof2(a, power) then
  787. begin
  788. { can be done with a shift }
  789. if power < 32 then
  790. begin
  791. list.concat(taicpu.op_reg_reg_const(A_SLL, reg, reg, power));
  792. exit;
  793. end;
  794. end;
  795. end;
  796. if ((op = OP_SUB) or (op = OP_ADD)) then
  797. begin
  798. if (a = 0) then
  799. exit;
  800. end;
  801. if Op in [OP_NEG, OP_NOT] then
  802. internalerror(200306011);
  803. if (a = 0) then
  804. begin
  805. if (Op = OP_IMUL) or (Op = OP_MUL) then
  806. list.concat(taicpu.op_reg_reg(A_MOVE, reg, NR_R0))
  807. else
  808. list.concat(taicpu.op_reg_reg_reg(f_TOpCG2AsmOp(op, size), reg, reg, NR_R0))
  809. end
  810. else
  811. begin
  812. if op = OP_IMUL then
  813. begin
  814. tmpreg1 := GetIntRegister(list, OS_INT);
  815. a_load_const_reg(list, OS_INT, a, tmpreg1);
  816. list.concat(taicpu.op_reg_reg(A_MULT, reg, tmpreg1));
  817. list.concat(taicpu.op_reg(A_MFLO, reg));
  818. end
  819. else if op = OP_MUL then
  820. begin
  821. tmpreg1 := GetIntRegister(list, OS_INT);
  822. a_load_const_reg(list, OS_INT, a, tmpreg1);
  823. list.concat(taicpu.op_reg_reg(A_MULTU, reg, tmpreg1));
  824. list.concat(taicpu.op_reg(A_MFLO, reg));
  825. end
  826. else
  827. handle_reg_const_reg(list, f_TOpCG2AsmOp(op, size), reg, a, reg);
  828. end;
  829. maybeadjustresult(list,op,size,reg);
  830. end;
  831. procedure TCGMIPS.a_op_reg_reg(list: tasmlist; Op: TOpCG; size: TCGSize; src, dst: TRegister);
  832. begin
  833. case Op of
  834. OP_NEG:
  835. { discard overflow checking }
  836. list.concat(taicpu.op_reg_reg(A_NEGU{A_NEG}, dst, src));
  837. OP_NOT:
  838. begin
  839. list.concat(taicpu.op_reg_reg(A_NOT, dst, src));
  840. end;
  841. else
  842. begin
  843. if op = OP_IMUL then
  844. begin
  845. list.concat(taicpu.op_reg_reg(A_MULT, dst, src));
  846. list.concat(taicpu.op_reg(A_MFLO, dst));
  847. end
  848. else if op = OP_MUL then
  849. begin
  850. list.concat(taicpu.op_reg_reg(A_MULTU, dst, src));
  851. list.concat(taicpu.op_reg(A_MFLO, dst));
  852. end
  853. else
  854. begin
  855. list.concat(taicpu.op_reg_reg_reg(f_TOpCG2AsmOp(op, size), dst, dst, src));
  856. end;
  857. end;
  858. end;
  859. maybeadjustresult(list,op,size,dst);
  860. end;
  861. procedure TCGMIPS.a_op_const_reg_reg(list: tasmlist; op: TOpCg; size: tcgsize; a: tcgint; src, dst: tregister);
  862. var
  863. power: longint;
  864. tmpreg1: tregister;
  865. begin
  866. case op of
  867. OP_MUL,
  868. OP_IMUL:
  869. begin
  870. if ispowerof2(a, power) then
  871. begin
  872. { can be done with a shift }
  873. if power < 32 then
  874. list.concat(taicpu.op_reg_reg_const(A_SLL, dst, src, power))
  875. else
  876. inherited a_op_const_reg_reg(list, op, size, a, src, dst);
  877. exit;
  878. end;
  879. end;
  880. OP_SUB,
  881. OP_ADD:
  882. begin
  883. if (a = 0) then
  884. begin
  885. a_load_reg_reg(list, size, size, src, dst);
  886. exit;
  887. end;
  888. end;
  889. end;
  890. if op = OP_IMUL then
  891. begin
  892. tmpreg1 := GetIntRegister(list, OS_INT);
  893. a_load_const_reg(list, OS_INT, a, tmpreg1);
  894. list.concat(taicpu.op_reg_reg(A_MULT, src, tmpreg1));
  895. list.concat(taicpu.op_reg(A_MFLO, dst));
  896. end
  897. else if op = OP_MUL then
  898. begin
  899. tmpreg1 := GetIntRegister(list, OS_INT);
  900. a_load_const_reg(list, OS_INT, a, tmpreg1);
  901. list.concat(taicpu.op_reg_reg(A_MULTU, src, tmpreg1));
  902. list.concat(taicpu.op_reg(A_MFLO, dst));
  903. end
  904. else
  905. handle_reg_const_reg(list, f_TOpCG2AsmOp(op, size), src, a, dst);
  906. maybeadjustresult(list,op,size,dst);
  907. end;
  908. procedure TCGMIPS.a_op_reg_reg_reg(list: tasmlist; op: TOpCg; size: tcgsize; src1, src2, dst: tregister);
  909. begin
  910. list.concat(taicpu.op_reg_reg_reg(f_TOpCG2AsmOp(op, size), dst, src2, src1));
  911. maybeadjustresult(list,op,size,dst);
  912. end;
  913. procedure TCGMIPS.a_op_const_reg_reg_checkoverflow(list: tasmlist; op: TOpCg; size: tcgsize; a: tcgint; src, dst: tregister; setflags: boolean; var ovloc: tlocation);
  914. var
  915. tmpreg1: tregister;
  916. begin
  917. ovloc.loc := LOC_VOID;
  918. case op of
  919. OP_SUB,
  920. OP_ADD:
  921. begin
  922. if (a = 0) then
  923. begin
  924. a_load_reg_reg(list, size, size, src, dst);
  925. exit;
  926. end;
  927. end;
  928. end;{case}
  929. case op of
  930. OP_ADD:
  931. begin
  932. if setflags then
  933. handle_reg_const_reg(list, f_TOpCG2AsmOp_ovf(op, size), src, a, dst)
  934. else
  935. handle_reg_const_reg(list, f_TOpCG2AsmOp(op, size), src, a, dst);
  936. end;
  937. OP_SUB:
  938. begin
  939. if setflags then
  940. handle_reg_const_reg(list, f_TOpCG2AsmOp_ovf(op, size), src, a, dst)
  941. else
  942. handle_reg_const_reg(list, f_TOpCG2AsmOp(op, size), src, a, dst);
  943. end;
  944. OP_MUL:
  945. begin
  946. if setflags then
  947. handle_reg_const_reg(list, f_TOpCG2AsmOp_ovf(op, size), src, a, dst)
  948. else
  949. begin
  950. tmpreg1 := GetIntRegister(list, OS_INT);
  951. a_load_const_reg(list, OS_INT, a, tmpreg1);
  952. list.concat(taicpu.op_reg_reg(f_TOpCG2AsmOp(op, size),src, tmpreg1));
  953. list.concat(taicpu.op_reg(A_MFLO, dst));
  954. end;
  955. end;
  956. OP_IMUL:
  957. begin
  958. if setflags then
  959. handle_reg_const_reg(list, f_TOpCG2AsmOp_ovf(op, size), src, a, dst)
  960. else
  961. begin
  962. tmpreg1 := GetIntRegister(list, OS_INT);
  963. a_load_const_reg(list, OS_INT, a, tmpreg1);
  964. list.concat(taicpu.op_reg_reg(f_TOpCG2AsmOp(op, size),src, tmpreg1));
  965. list.concat(taicpu.op_reg(A_MFLO, dst));
  966. end;
  967. end;
  968. OP_XOR, OP_OR, OP_AND:
  969. begin
  970. handle_reg_const_reg(list, f_TOpCG2AsmOp_ovf(op, size), src, a, dst);
  971. end;
  972. else
  973. internalerror(2007012601);
  974. end;
  975. maybeadjustresult(list,op,size,dst);
  976. end;
  977. procedure TCGMIPS.a_op_reg_reg_reg_checkoverflow(list: tasmlist; op: TOpCg; size: tcgsize; src1, src2, dst: tregister; setflags: boolean; var ovloc: tlocation);
  978. begin
  979. ovloc.loc := LOC_VOID;
  980. case op of
  981. OP_ADD:
  982. begin
  983. if setflags then
  984. list.concat(taicpu.op_reg_reg_reg(f_TOpCG2AsmOp_ovf(op, size), dst, src2, src1))
  985. else
  986. list.concat(taicpu.op_reg_reg_reg(f_TOpCG2AsmOp(op, size), dst, src2, src1));
  987. end;
  988. OP_SUB:
  989. begin
  990. if setflags then
  991. list.concat(taicpu.op_reg_reg_reg(f_TOpCG2AsmOp_ovf(op, size), dst, src2, src1))
  992. else
  993. list.concat(taicpu.op_reg_reg_reg(f_TOpCG2AsmOp(op, size), dst, src2, src1));
  994. end;
  995. OP_MUL:
  996. begin
  997. if setflags then
  998. list.concat(taicpu.op_reg_reg_reg(f_TOpCG2AsmOp_ovf(op, size), dst, src2, src1))
  999. else
  1000. begin
  1001. list.concat(taicpu.op_reg_reg(f_TOpCG2AsmOp(op, size), src2, src1));
  1002. list.concat(taicpu.op_reg(A_MFLO, dst));
  1003. end;
  1004. end;
  1005. OP_IMUL:
  1006. begin
  1007. if setflags then
  1008. list.concat(taicpu.op_reg_reg_reg(f_TOpCG2AsmOp_ovf(op, size), dst, src2, src1))
  1009. else
  1010. begin
  1011. list.concat(taicpu.op_reg_reg(f_TOpCG2AsmOp(op, size), src2, src1));
  1012. list.concat(taicpu.op_reg(A_MFLO, dst));
  1013. end;
  1014. end;
  1015. OP_XOR, OP_OR, OP_AND:
  1016. begin
  1017. list.concat(taicpu.op_reg_reg_reg(f_TOpCG2AsmOp_ovf(op, size), dst, src2, src1));
  1018. end;
  1019. else
  1020. internalerror(2007012602);
  1021. end;
  1022. maybeadjustresult(list,op,size,dst);
  1023. end;
  1024. {*************** compare instructructions ****************}
  1025. procedure TCGMIPS.a_cmp_const_reg_label(list: tasmlist; size: tcgsize; cmp_op: topcmp; a: tcgint; reg: tregister; l: tasmlabel);
  1026. var
  1027. tmpreg: tregister;
  1028. ai : Taicpu;
  1029. begin
  1030. if a = 0 then
  1031. tmpreg := NR_R0
  1032. else
  1033. begin
  1034. tmpreg := GetIntRegister(list, OS_INT);
  1035. a_load_const_reg(list,OS_INT,a,tmpreg);
  1036. end;
  1037. ai := taicpu.op_reg_reg_sym(A_BC, reg, tmpreg, l);
  1038. ai.SetCondition(TOpCmp2AsmCond[cmp_op]);
  1039. list.concat(ai);
  1040. { Delay slot }
  1041. list.Concat(TAiCpu.Op_none(A_NOP));
  1042. end;
  1043. procedure TCGMIPS.a_cmp_reg_reg_label(list: tasmlist; size: tcgsize; cmp_op: topcmp; reg1, reg2: tregister; l: tasmlabel);
  1044. var
  1045. ai : Taicpu;
  1046. begin
  1047. ai := taicpu.op_reg_reg_sym(A_BC, reg2, reg1, l);
  1048. ai.SetCondition(TOpCmp2AsmCond[cmp_op]);
  1049. list.concat(ai);
  1050. { Delay slot }
  1051. list.Concat(TAiCpu.Op_none(A_NOP));
  1052. end;
  1053. procedure TCGMIPS.a_jmp_always(List: tasmlist; l: TAsmLabel);
  1054. var
  1055. ai : Taicpu;
  1056. begin
  1057. ai := taicpu.op_sym(A_BA, l);
  1058. list.concat(ai);
  1059. { Delay slot }
  1060. list.Concat(TAiCpu.Op_none(A_NOP));
  1061. end;
  1062. procedure TCGMIPS.a_jmp_name(list: tasmlist; const s: string);
  1063. begin
  1064. List.Concat(TAiCpu.op_sym(A_BA, current_asmdata.RefAsmSymbol(s)));
  1065. { Delay slot }
  1066. list.Concat(TAiCpu.Op_none(A_NOP));
  1067. end;
  1068. procedure TCGMIPS.g_overflowCheck(List: tasmlist; const Loc: TLocation; def: TDef);
  1069. begin
  1070. // this is an empty procedure
  1071. end;
  1072. procedure TCGMIPS.g_overflowCheck_loc(List: tasmlist; const Loc: TLocation; def: TDef; ovloc: tlocation);
  1073. begin
  1074. // this is an empty procedure
  1075. end;
  1076. { *********** entry/exit code and address loading ************ }
  1077. procedure TCGMIPS.g_proc_entry(list: tasmlist; localsize: longint; nostackframe: boolean);
  1078. var
  1079. lastintoffset,lastfpuoffset,
  1080. nextoffset : aint;
  1081. i : longint;
  1082. ra_save,framesave : taicpu;
  1083. fmask,mask : dword;
  1084. saveregs : tcpuregisterset;
  1085. href: treference;
  1086. reg : Tsuperregister;
  1087. helplist : TAsmList;
  1088. begin
  1089. a_reg_alloc(list,NR_STACK_POINTER_REG);
  1090. if nostackframe then
  1091. exit;
  1092. if (pi_needs_stackframe in current_procinfo.flags) then
  1093. a_reg_alloc(list,NR_FRAME_POINTER_REG);
  1094. helplist:=TAsmList.Create;
  1095. reference_reset(href,0);
  1096. href.base:=NR_STACK_POINTER_REG;
  1097. fmask:=0;
  1098. nextoffset:=TMIPSProcInfo(current_procinfo).floatregstart;
  1099. lastfpuoffset:=LocalSize;
  1100. for reg := RS_F0 to RS_F31 do { to check: what if F30 is double? }
  1101. begin
  1102. if reg in (rg[R_FPUREGISTER].used_in_proc-paramanager.get_volatile_registers_fpu(pocall_stdcall)) then
  1103. begin
  1104. fmask:=fmask or (1 shl ord(reg));
  1105. href.offset:=nextoffset;
  1106. lastfpuoffset:=nextoffset;
  1107. helplist.concat(taicpu.op_reg_ref(A_SWC1,newreg(R_FPUREGISTER,reg,R_SUBFS),href));
  1108. inc(nextoffset,4);
  1109. { IEEE Double values are stored in floating point
  1110. register pairs f2X/f2X+1,
  1111. as the f2X+1 register is not correctly marked as used for now,
  1112. we simply assume it is also used if f2X is used
  1113. Should be fixed by a proper inclusion of f2X+1 into used_in_proc }
  1114. if (ord(reg)-ord(RS_F0)) mod 2 = 0 then
  1115. include(rg[R_FPUREGISTER].used_in_proc,succ(reg));
  1116. end;
  1117. end;
  1118. mask:=0;
  1119. nextoffset:=TMIPSProcInfo(current_procinfo).intregstart;
  1120. saveregs:=rg[R_INTREGISTER].used_in_proc-paramanager.get_volatile_registers_int(pocall_stdcall);
  1121. if (current_procinfo.flags*[pi_do_call,pi_is_assembler]<>[]) then
  1122. include(saveregs,RS_R31);
  1123. if (pi_needs_stackframe in current_procinfo.flags) then
  1124. include(saveregs,RS_FRAME_POINTER_REG);
  1125. lastintoffset:=LocalSize;
  1126. framesave:=nil;
  1127. ra_save:=nil;
  1128. for reg:=RS_R1 to RS_R31 do
  1129. begin
  1130. if reg in saveregs then
  1131. begin
  1132. mask:=mask or (1 shl ord(reg));
  1133. href.offset:=nextoffset;
  1134. lastintoffset:=nextoffset;
  1135. if (reg=RS_FRAME_POINTER_REG) then
  1136. framesave:=taicpu.op_reg_ref(A_SW,newreg(R_INTREGISTER,reg,R_SUBWHOLE),href)
  1137. else if (reg=RS_R31) then
  1138. ra_save:=taicpu.op_reg_ref(A_SW,newreg(R_INTREGISTER,reg,R_SUBWHOLE),href)
  1139. else
  1140. helplist.concat(taicpu.op_reg_ref(A_SW,newreg(R_INTREGISTER,reg,R_SUBWHOLE),href));
  1141. inc(nextoffset,4);
  1142. end;
  1143. end;
  1144. //list.concat(Taicpu.Op_reg_reg_const(A_ADDIU,NR_FRAME_POINTER_REG,NR_STACK_POINTER_REG,current_procinfo.para_stack_size));
  1145. list.concat(Taicpu.op_none(A_P_SET_NOMIPS16));
  1146. list.concat(Taicpu.op_reg_const_reg(A_P_FRAME,current_procinfo.framepointer,LocalSize,NR_R31));
  1147. list.concat(Taicpu.op_const_const(A_P_MASK,mask,-(LocalSize-lastintoffset)));
  1148. list.concat(Taicpu.op_const_const(A_P_FMASK,Fmask,-(LocalSize-lastfpuoffset)));
  1149. list.concat(Taicpu.op_none(A_P_SET_NOREORDER));
  1150. if (cs_create_pic in current_settings.moduleswitches) and
  1151. (pi_needs_got in current_procinfo.flags) then
  1152. begin
  1153. list.concat(Taicpu.op_reg(A_P_CPLOAD,NR_PIC_FUNC));
  1154. end;
  1155. if (-LocalSize >= simm16lo) and (-LocalSize <= simm16hi) then
  1156. begin
  1157. list.concat(Taicpu.op_none(A_P_SET_NOMACRO));
  1158. list.concat(Taicpu.Op_reg_reg_const(A_ADDIU,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,-LocalSize));
  1159. if assigned(ra_save) then
  1160. list.concat(ra_save);
  1161. if assigned(framesave) then
  1162. begin
  1163. list.concat(framesave);
  1164. list.concat(Taicpu.op_reg_reg_const(A_ADDIU,NR_FRAME_POINTER_REG,
  1165. NR_STACK_POINTER_REG,LocalSize));
  1166. end;
  1167. end
  1168. else
  1169. begin
  1170. list.concat(Taicpu.Op_reg_const(A_LI,NR_R9,-LocalSize));
  1171. list.concat(Taicpu.Op_reg_reg_reg(A_ADD,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,NR_R9));
  1172. if assigned(ra_save) then
  1173. list.concat(ra_save);
  1174. if assigned(framesave) then
  1175. begin
  1176. list.concat(framesave);
  1177. list.concat(Taicpu.op_reg_reg_reg(A_SUBU,NR_FRAME_POINTER_REG,
  1178. NR_STACK_POINTER_REG,NR_R9));
  1179. end;
  1180. { The instructions before are macros that can extend to multiple instructions,
  1181. the settings of R9 to -LocalSize surely does,
  1182. but the saving of RA and FP also might, and might
  1183. even use AT register, which is why we use R9 instead of AT here for -LocalSize }
  1184. list.concat(Taicpu.op_none(A_P_SET_NOMACRO));
  1185. end;
  1186. if (cs_create_pic in current_settings.moduleswitches) and
  1187. (pi_needs_got in current_procinfo.flags) then
  1188. begin
  1189. list.concat(Taicpu.op_none(A_P_SET_MACRO));
  1190. list.concat(Taicpu.op_const(A_P_CPRESTORE,TMIPSProcinfo(current_procinfo).save_gp_ref.offset));
  1191. list.concat(Taicpu.op_none(A_P_SET_NOMACRO));
  1192. end;
  1193. with TMIPSProcInfo(current_procinfo) do
  1194. begin
  1195. href.offset:=0;
  1196. //if current_procinfo.framepointer<>NR_STACK_POINTER_REG then
  1197. href.base:=NR_FRAME_POINTER_REG;
  1198. for i:=0 to MIPS_MAX_REGISTERS_USED_IN_CALL-1 do
  1199. if (register_used[i]) then
  1200. begin
  1201. reg:=parasupregs[i];
  1202. if register_offset[i]=-1 then
  1203. comment(V_warning,'Register parameter has offset -1 in TCGMIPS.g_proc_entry');
  1204. //if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  1205. // href.offset:=register_offset[i]+Localsize
  1206. //else
  1207. href.offset:=register_offset[i];
  1208. list.concat(taicpu.op_reg_ref(A_SW, newreg(R_INTREGISTER,reg,R_SUBWHOLE), href));
  1209. end;
  1210. end;
  1211. list.concatList(helplist);
  1212. helplist.Free;
  1213. end;
  1214. procedure TCGMIPS.g_proc_exit(list: tasmlist; parasize: longint; nostackframe: boolean);
  1215. var
  1216. href : treference;
  1217. stacksize : aint;
  1218. saveregs : tcpuregisterset;
  1219. nextoffset : aint;
  1220. reg : Tsuperregister;
  1221. begin
  1222. stacksize:=current_procinfo.calc_stackframe_size;
  1223. if nostackframe then
  1224. begin
  1225. list.concat(taicpu.op_reg(A_JR, NR_R31));
  1226. list.concat(Taicpu.op_none(A_NOP));
  1227. list.concat(Taicpu.op_none(A_P_SET_MACRO));
  1228. list.concat(Taicpu.op_none(A_P_SET_REORDER));
  1229. end
  1230. else
  1231. begin
  1232. reference_reset(href,0);
  1233. href.base:=NR_STACK_POINTER_REG;
  1234. nextoffset:=TMIPSProcInfo(current_procinfo).floatregstart;
  1235. for reg := RS_F0 to RS_F31 do
  1236. begin
  1237. if reg in (rg[R_FPUREGISTER].used_in_proc-paramanager.get_volatile_registers_fpu(pocall_stdcall)) then
  1238. begin
  1239. href.offset:=nextoffset;
  1240. list.concat(taicpu.op_reg_ref(A_LWC1,newreg(R_FPUREGISTER,reg,R_SUBFS),href));
  1241. inc(nextoffset,4);
  1242. end;
  1243. end;
  1244. nextoffset:=TMIPSProcInfo(current_procinfo).intregstart;
  1245. saveregs:=rg[R_INTREGISTER].used_in_proc-paramanager.get_volatile_registers_int(pocall_stdcall);
  1246. if (current_procinfo.flags*[pi_do_call,pi_is_assembler]<>[]) then
  1247. include(saveregs,RS_R31);
  1248. if (pi_needs_stackframe in current_procinfo.flags) then
  1249. include(saveregs,RS_FRAME_POINTER_REG);
  1250. // GP does not need to be restored on exit
  1251. for reg:=RS_R1 to RS_R31 do
  1252. begin
  1253. if reg in saveregs then
  1254. begin
  1255. href.offset:=nextoffset;
  1256. list.concat(taicpu.op_reg_ref(A_LW,newreg(R_INTREGISTER,reg,R_SUBWHOLE),href));
  1257. inc(nextoffset,sizeof(aint));
  1258. end;
  1259. end;
  1260. if (-stacksize >= simm16lo) and (-stacksize <= simm16hi) then
  1261. begin
  1262. list.concat(taicpu.op_reg(A_JR, NR_R31));
  1263. { correct stack pointer in the delay slot }
  1264. list.concat(Taicpu.Op_reg_reg_const(A_ADDIU, NR_STACK_POINTER_REG, NR_STACK_POINTER_REG, stacksize));
  1265. end
  1266. else
  1267. begin
  1268. a_load_const_reg(list,OS_32,stacksize,NR_R1);
  1269. list.concat(taicpu.op_reg(A_JR, NR_R31));
  1270. { correct stack pointer in the delay slot }
  1271. list.concat(taicpu.op_reg_reg_reg(A_ADD,NR_STACK_POINTER_REG,NR_STACK_POINTER_REG,NR_R1));
  1272. end;
  1273. list.concat(Taicpu.op_none(A_P_SET_MACRO));
  1274. list.concat(Taicpu.op_none(A_P_SET_REORDER));
  1275. end;
  1276. end;
  1277. { ************* concatcopy ************ }
  1278. procedure TCGMIPS.g_concatcopy_move(list: tasmlist; const Source, dest: treference; len: tcgint);
  1279. var
  1280. paraloc1, paraloc2, paraloc3: TCGPara;
  1281. pd: tprocdef;
  1282. begin
  1283. pd:=search_system_proc('MOVE');
  1284. paraloc1.init;
  1285. paraloc2.init;
  1286. paraloc3.init;
  1287. paramanager.getintparaloc(pd, 1, paraloc1);
  1288. paramanager.getintparaloc(pd, 2, paraloc2);
  1289. paramanager.getintparaloc(pd, 3, paraloc3);
  1290. a_load_const_cgpara(list, OS_SINT, len, paraloc3);
  1291. a_loadaddr_ref_cgpara(list, dest, paraloc2);
  1292. a_loadaddr_ref_cgpara(list, Source, paraloc1);
  1293. paramanager.freecgpara(list, paraloc3);
  1294. paramanager.freecgpara(list, paraloc2);
  1295. paramanager.freecgpara(list, paraloc1);
  1296. alloccpuregisters(list, R_INTREGISTER, paramanager.get_volatile_registers_int(pocall_default));
  1297. alloccpuregisters(list, R_FPUREGISTER, paramanager.get_volatile_registers_fpu(pocall_default));
  1298. a_call_name(list, 'FPC_MOVE', false);
  1299. dealloccpuregisters(list, R_FPUREGISTER, paramanager.get_volatile_registers_fpu(pocall_default));
  1300. dealloccpuregisters(list, R_INTREGISTER, paramanager.get_volatile_registers_int(pocall_default));
  1301. paraloc3.done;
  1302. paraloc2.done;
  1303. paraloc1.done;
  1304. end;
  1305. procedure TCGMIPS.g_concatcopy(list: tasmlist; const Source, dest: treference; len: tcgint);
  1306. var
  1307. tmpreg1, hreg, countreg: TRegister;
  1308. src, dst: TReference;
  1309. lab: tasmlabel;
  1310. Count, count2: aint;
  1311. ai : TaiCpu;
  1312. function reference_is_reusable(const ref: treference): boolean;
  1313. begin
  1314. result:=(ref.base<>NR_NO) and (ref.index=NR_NO) and
  1315. (ref.symbol=nil) and
  1316. (ref.alignment>=sizeof(aint)) and
  1317. (ref.offset>=simm16lo) and (ref.offset+len<=simm16hi);
  1318. end;
  1319. begin
  1320. if len > high(longint) then
  1321. internalerror(2002072704);
  1322. { A call (to FPC_MOVE) requires the outgoing parameter area to be properly
  1323. allocated on stack. This can only be done before tmipsprocinfo.set_first_temp_offset,
  1324. i.e. before secondpass. Other internal procedures request correct stack frame
  1325. by setting pi_do_call during firstpass, but for this particular one it is impossible.
  1326. Therefore, if the current procedure is a leaf one, we have to leave it that way. }
  1327. { anybody wants to determine a good value here :)? }
  1328. if (len > 100) and
  1329. assigned(current_procinfo) and
  1330. (pi_do_call in current_procinfo.flags) then
  1331. g_concatcopy_move(list, Source, dest, len)
  1332. else
  1333. begin
  1334. Count := len div 4;
  1335. if (count<=4) and reference_is_reusable(source) then
  1336. src:=source
  1337. else
  1338. begin
  1339. reference_reset(src,sizeof(aint));
  1340. { load the address of source into src.base }
  1341. src.base := GetAddressRegister(list);
  1342. a_loadaddr_ref_reg(list, Source, src.base);
  1343. end;
  1344. if (count<=4) and reference_is_reusable(dest) then
  1345. dst:=dest
  1346. else
  1347. begin
  1348. reference_reset(dst,sizeof(aint));
  1349. { load the address of dest into dst.base }
  1350. dst.base := GetAddressRegister(list);
  1351. a_loadaddr_ref_reg(list, dest, dst.base);
  1352. end;
  1353. { generate a loop }
  1354. if Count > 4 then
  1355. begin
  1356. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1357. { have to be set to 8. I put an Inc there so debugging may be }
  1358. { easier (should offset be different from zero here, it will be }
  1359. { easy to notice in the generated assembler }
  1360. countreg := GetIntRegister(list, OS_INT);
  1361. tmpreg1 := GetIntRegister(list, OS_INT);
  1362. a_load_const_reg(list, OS_INT, Count, countreg);
  1363. { explicitely allocate R_O0 since it can be used safely here }
  1364. { (for holding date that's being copied) }
  1365. current_asmdata.getjumplabel(lab);
  1366. a_label(list, lab);
  1367. list.concat(taicpu.op_reg_ref(A_LW, tmpreg1, src));
  1368. list.concat(taicpu.op_reg_ref(A_SW, tmpreg1, dst));
  1369. list.concat(taicpu.op_reg_reg_const(A_ADDIU, src.base, src.base, 4));
  1370. list.concat(taicpu.op_reg_reg_const(A_ADDIU, dst.base, dst.base, 4));
  1371. list.concat(taicpu.op_reg_reg_const(A_ADDIU, countreg, countreg, -1));
  1372. //list.concat(taicpu.op_reg_sym(A_BGTZ, countreg, lab));
  1373. ai := taicpu.op_reg_reg_sym(A_BC,countreg, NR_R0, lab);
  1374. ai.setcondition(C_GT);
  1375. list.concat(ai);
  1376. list.concat(taicpu.op_none(A_NOP));
  1377. len := len mod 4;
  1378. end;
  1379. { unrolled loop }
  1380. Count := len div 4;
  1381. if Count > 0 then
  1382. begin
  1383. tmpreg1 := GetIntRegister(list, OS_INT);
  1384. for count2 := 1 to Count do
  1385. begin
  1386. list.concat(taicpu.op_reg_ref(A_LW, tmpreg1, src));
  1387. list.concat(taicpu.op_reg_ref(A_SW, tmpreg1, dst));
  1388. Inc(src.offset, 4);
  1389. Inc(dst.offset, 4);
  1390. end;
  1391. len := len mod 4;
  1392. end;
  1393. if (len and 4) <> 0 then
  1394. begin
  1395. hreg := GetIntRegister(list, OS_INT);
  1396. a_load_ref_reg(list, OS_32, OS_32, src, hreg);
  1397. a_load_reg_ref(list, OS_32, OS_32, hreg, dst);
  1398. Inc(src.offset, 4);
  1399. Inc(dst.offset, 4);
  1400. end;
  1401. { copy the leftovers }
  1402. if (len and 2) <> 0 then
  1403. begin
  1404. hreg := GetIntRegister(list, OS_INT);
  1405. a_load_ref_reg(list, OS_16, OS_16, src, hreg);
  1406. a_load_reg_ref(list, OS_16, OS_16, hreg, dst);
  1407. Inc(src.offset, 2);
  1408. Inc(dst.offset, 2);
  1409. end;
  1410. if (len and 1) <> 0 then
  1411. begin
  1412. hreg := GetIntRegister(list, OS_INT);
  1413. a_load_ref_reg(list, OS_8, OS_8, src, hreg);
  1414. a_load_reg_ref(list, OS_8, OS_8, hreg, dst);
  1415. end;
  1416. end;
  1417. end;
  1418. procedure TCGMIPS.g_concatcopy_unaligned(list: tasmlist; const Source, dest: treference; len: tcgint);
  1419. var
  1420. src, dst: TReference;
  1421. tmpreg1, countreg: TRegister;
  1422. i: aint;
  1423. lab: tasmlabel;
  1424. ai : TaiCpu;
  1425. begin
  1426. if (len > 31) and
  1427. { see comment in g_concatcopy }
  1428. assigned(current_procinfo) and
  1429. (pi_do_call in current_procinfo.flags) then
  1430. g_concatcopy_move(list, Source, dest, len)
  1431. else
  1432. begin
  1433. reference_reset(src,sizeof(aint));
  1434. reference_reset(dst,sizeof(aint));
  1435. { load the address of source into src.base }
  1436. src.base := GetAddressRegister(list);
  1437. a_loadaddr_ref_reg(list, Source, src.base);
  1438. { load the address of dest into dst.base }
  1439. dst.base := GetAddressRegister(list);
  1440. a_loadaddr_ref_reg(list, dest, dst.base);
  1441. { generate a loop }
  1442. if len > 4 then
  1443. begin
  1444. { the offsets are zero after the a_loadaddress_ref_reg and just }
  1445. { have to be set to 8. I put an Inc there so debugging may be }
  1446. { easier (should offset be different from zero here, it will be }
  1447. { easy to notice in the generated assembler }
  1448. countreg := cg.GetIntRegister(list, OS_INT);
  1449. tmpreg1 := cg.GetIntRegister(list, OS_INT);
  1450. a_load_const_reg(list, OS_INT, len, countreg);
  1451. { explicitely allocate R_O0 since it can be used safely here }
  1452. { (for holding date that's being copied) }
  1453. current_asmdata.getjumplabel(lab);
  1454. a_label(list, lab);
  1455. list.concat(taicpu.op_reg_ref(A_LBU, tmpreg1, src));
  1456. list.concat(taicpu.op_reg_ref(A_SB, tmpreg1, dst));
  1457. list.concat(taicpu.op_reg_reg_const(A_ADDIU, src.base, src.base, 1));
  1458. list.concat(taicpu.op_reg_reg_const(A_ADDIU, dst.base, dst.base, 1));
  1459. list.concat(taicpu.op_reg_reg_const(A_ADDIU, countreg, countreg, -1));
  1460. //list.concat(taicpu.op_reg_sym(A_BGTZ, countreg, lab));
  1461. ai := taicpu.op_reg_reg_sym(A_BC,countreg, NR_R0, lab);
  1462. ai.setcondition(C_GT);
  1463. list.concat(ai);
  1464. list.concat(taicpu.op_none(A_NOP));
  1465. end
  1466. else
  1467. begin
  1468. { unrolled loop }
  1469. tmpreg1 := cg.GetIntRegister(list, OS_INT);
  1470. for i := 1 to len do
  1471. begin
  1472. list.concat(taicpu.op_reg_ref(A_LBU, tmpreg1, src));
  1473. list.concat(taicpu.op_reg_ref(A_SB, tmpreg1, dst));
  1474. Inc(src.offset);
  1475. Inc(dst.offset);
  1476. end;
  1477. end;
  1478. end;
  1479. end;
  1480. procedure TCGMIPS.g_intf_wrapper(list: tasmlist; procdef: tprocdef; const labelname: string; ioffset: longint);
  1481. var
  1482. make_global: boolean;
  1483. hsym: tsym;
  1484. href: treference;
  1485. paraloc: Pcgparalocation;
  1486. IsVirtual: boolean;
  1487. begin
  1488. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  1489. Internalerror(200006137);
  1490. if not assigned(procdef.struct) or
  1491. (procdef.procoptions * [po_classmethod, po_staticmethod,
  1492. po_methodpointer, po_interrupt, po_iocheck] <> []) then
  1493. Internalerror(200006138);
  1494. if procdef.owner.symtabletype <> objectsymtable then
  1495. Internalerror(200109191);
  1496. make_global := False;
  1497. if (not current_module.is_unit) or create_smartlink or
  1498. (procdef.owner.defowner.owner.symtabletype = globalsymtable) then
  1499. make_global := True;
  1500. if make_global then
  1501. List.concat(Tai_symbol.Createname_global(labelname, AT_FUNCTION, 0))
  1502. else
  1503. List.concat(Tai_symbol.Createname(labelname, AT_FUNCTION, 0));
  1504. IsVirtual:=(po_virtualmethod in procdef.procoptions) and
  1505. not is_objectpascal_helper(procdef.struct);
  1506. if (cs_create_pic in current_settings.moduleswitches) and
  1507. (not IsVirtual) then
  1508. begin
  1509. list.concat(Taicpu.op_none(A_P_SET_NOREORDER));
  1510. list.concat(Taicpu.op_reg(A_P_CPLOAD,NR_PIC_FUNC));
  1511. list.concat(Taicpu.op_none(A_P_SET_REORDER));
  1512. end;
  1513. { set param1 interface to self }
  1514. procdef.init_paraloc_info(callerside);
  1515. hsym:=tsym(procdef.parast.Find('self'));
  1516. if not(assigned(hsym) and
  1517. (hsym.typ=paravarsym)) then
  1518. internalerror(2010103101);
  1519. paraloc:=tparavarsym(hsym).paraloc[callerside].location;
  1520. if assigned(paraloc^.next) then
  1521. InternalError(2013020101);
  1522. case paraloc^.loc of
  1523. LOC_REGISTER:
  1524. begin
  1525. if ((ioffset>=simm16lo) and (ioffset<=simm16hi)) then
  1526. a_op_const_reg(list,OP_SUB, paraloc^.size,ioffset,paraloc^.register)
  1527. else
  1528. begin
  1529. a_load_const_reg(list, paraloc^.size, ioffset, NR_R1);
  1530. a_op_reg_reg(list, OP_SUB, paraloc^.size, NR_R1, paraloc^.register);
  1531. end;
  1532. end;
  1533. else
  1534. internalerror(2010103102);
  1535. end;
  1536. if IsVirtual then
  1537. begin
  1538. { load VMT pointer }
  1539. reference_reset_base(href,paraloc^.register,0,sizeof(aint));
  1540. list.concat(taicpu.op_reg_ref(A_LW,NR_VMT,href));
  1541. if (procdef.extnumber=$ffff) then
  1542. Internalerror(200006139);
  1543. { TODO: case of large VMT is not handled }
  1544. { We have no reason not to use $t9 even in non-PIC mode. }
  1545. reference_reset_base(href, NR_VMT, tobjectdef(procdef.struct).vmtmethodoffset(procdef.extnumber), sizeof(aint));
  1546. list.concat(taicpu.op_reg_ref(A_LW,NR_PIC_FUNC,href));
  1547. list.concat(taicpu.op_reg(A_JR, NR_PIC_FUNC));
  1548. end
  1549. else if not (cs_create_pic in current_settings.moduleswitches) then
  1550. list.concat(taicpu.op_sym(A_J,current_asmdata.RefAsmSymbol(procdef.mangledname)))
  1551. else
  1552. begin
  1553. { GAS does not expand "J symbol" into PIC sequence }
  1554. reference_reset_symbol(href,current_asmdata.RefAsmSymbol(procdef.mangledname),0,sizeof(pint));
  1555. href.base:=NR_GP;
  1556. href.refaddr:=addr_pic_call16;
  1557. list.concat(taicpu.op_reg_ref(A_LW,NR_PIC_FUNC,href));
  1558. list.concat(taicpu.op_reg(A_JR,NR_PIC_FUNC));
  1559. end;
  1560. { Delay slot }
  1561. list.Concat(TAiCpu.Op_none(A_NOP));
  1562. List.concat(Tai_symbol_end.Createname(labelname));
  1563. end;
  1564. procedure TCGMIPS.g_external_wrapper(list: TAsmList; procdef: tprocdef; const externalname: string);
  1565. var
  1566. href: treference;
  1567. begin
  1568. reference_reset_symbol(href,current_asmdata.RefAsmSymbol(externalname),0,sizeof(aint));
  1569. { Always do indirect jump using $t9, it won't harm in non-PIC mode }
  1570. if (cs_create_pic in current_settings.moduleswitches) then
  1571. begin
  1572. list.concat(taicpu.op_none(A_P_SET_NOREORDER));
  1573. list.concat(taicpu.op_reg(A_P_CPLOAD,NR_PIC_FUNC));
  1574. href.base:=NR_GP;
  1575. href.refaddr:=addr_pic_call16;
  1576. list.concat(taicpu.op_reg_ref(A_LW,NR_PIC_FUNC,href));
  1577. list.concat(taicpu.op_reg(A_JR,NR_PIC_FUNC));
  1578. { Delay slot }
  1579. list.Concat(taicpu.op_none(A_NOP));
  1580. list.Concat(taicpu.op_none(A_P_SET_REORDER));
  1581. end
  1582. else
  1583. begin
  1584. href.refaddr:=addr_high;
  1585. list.concat(taicpu.op_reg_ref(A_LUI,NR_PIC_FUNC,href));
  1586. href.refaddr:=addr_low;
  1587. list.concat(taicpu.op_reg_ref(A_ADDIU,NR_PIC_FUNC,href));
  1588. list.concat(taicpu.op_reg(A_JR,NR_PIC_FUNC));
  1589. { Delay slot }
  1590. list.Concat(taicpu.op_none(A_NOP));
  1591. end;
  1592. end;
  1593. procedure TCGMIPS.g_profilecode(list:TAsmList);
  1594. var
  1595. href: treference;
  1596. begin
  1597. if not (cs_create_pic in current_settings.moduleswitches) then
  1598. begin
  1599. reference_reset_symbol(href,current_asmdata.RefAsmSymbol('_gp'),0,sizeof(pint));
  1600. a_loadaddr_ref_reg(list,href,NR_GP);
  1601. end;
  1602. list.concat(taicpu.op_reg_reg(A_MOVE,NR_R1,NR_RA));
  1603. list.concat(taicpu.op_reg_reg_const(A_ADDIU,NR_SP,NR_SP,-8));
  1604. a_call_sym_pic(list,current_asmdata.RefAsmSymbol('_mcount'));
  1605. end;
  1606. procedure TCGMIPS.g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: tcgint);
  1607. begin
  1608. { This method is integrated into g_intf_wrapper and shouldn't be called separately }
  1609. InternalError(2013020102);
  1610. end;
  1611. procedure TCGMIPS.g_stackpointer_alloc(list : TAsmList;localsize : longint);
  1612. begin
  1613. Comment(V_Error,'TCgMPSel.g_stackpointer_alloc method not implemented');
  1614. end;
  1615. procedure TCGMIPS.a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; size: TCGSize; src, dst: TRegister);
  1616. begin
  1617. Comment(V_Error,'TCgMPSel.a_bit_scan_reg_reg method not implemented');
  1618. end;
  1619. {****************************************************************************
  1620. TCG64_MIPSel
  1621. ****************************************************************************}
  1622. procedure TCg64MPSel.a_load64_reg_ref(list: tasmlist; reg: tregister64; const ref: treference);
  1623. var
  1624. tmpref: treference;
  1625. tmpreg: tregister;
  1626. begin
  1627. { Override this function to prevent loading the reference twice }
  1628. if target_info.endian = endian_big then
  1629. begin
  1630. tmpreg := reg.reglo;
  1631. reg.reglo := reg.reghi;
  1632. reg.reghi := tmpreg;
  1633. end;
  1634. tmpref := ref;
  1635. cg.a_load_reg_ref(list, OS_S32, OS_S32, reg.reglo, tmpref);
  1636. Inc(tmpref.offset, 4);
  1637. cg.a_load_reg_ref(list, OS_S32, OS_S32, reg.reghi, tmpref);
  1638. end;
  1639. procedure TCg64MPSel.a_load64_ref_reg(list: tasmlist; const ref: treference; reg: tregister64);
  1640. var
  1641. tmpref: treference;
  1642. tmpreg: tregister;
  1643. begin
  1644. { Override this function to prevent loading the reference twice }
  1645. if target_info.endian = endian_big then
  1646. begin
  1647. tmpreg := reg.reglo;
  1648. reg.reglo := reg.reghi;
  1649. reg.reghi := tmpreg;
  1650. end;
  1651. tmpref := ref;
  1652. cg.a_load_ref_reg(list, OS_S32, OS_S32, tmpref, reg.reglo);
  1653. Inc(tmpref.offset, 4);
  1654. cg.a_load_ref_reg(list, OS_S32, OS_S32, tmpref, reg.reghi);
  1655. end;
  1656. procedure TCg64MPSel.a_load64_ref_cgpara(list: tasmlist; const r: treference; const paraloc: tcgpara);
  1657. var
  1658. hreg64: tregister64;
  1659. begin
  1660. { Override this function to prevent loading the reference twice.
  1661. Use here some extra registers, but those are optimized away by the RA }
  1662. hreg64.reglo := cg.GetIntRegister(list, OS_S32);
  1663. hreg64.reghi := cg.GetIntRegister(list, OS_S32);
  1664. a_load64_ref_reg(list, r, hreg64);
  1665. a_load64_reg_cgpara(list, hreg64, paraloc);
  1666. end;
  1667. procedure TCg64MPSel.a_op64_reg_reg(list: tasmlist; op: TOpCG; size: tcgsize; regsrc, regdst: TRegister64);
  1668. var
  1669. tmpreg1, tmpreg2: TRegister;
  1670. begin
  1671. tmpreg1 := cg.GetIntRegister(list, OS_INT);
  1672. tmpreg2 := cg.GetIntRegister(list, OS_INT);
  1673. case op of
  1674. OP_ADD:
  1675. begin
  1676. list.concat(taicpu.op_reg_reg_reg(A_ADDU, regdst.reglo, regsrc.reglo, regdst.reglo));
  1677. list.concat(taicpu.op_reg_reg_reg(A_SLTU, tmpreg1, regdst.reglo, regsrc.reglo));
  1678. list.concat(taicpu.op_reg_reg_reg(A_ADDU, tmpreg2, regsrc.reghi, regdst.reghi));
  1679. list.concat(taicpu.op_reg_reg_reg(A_ADDU, regdst.reghi, tmpreg1, tmpreg2));
  1680. exit;
  1681. end;
  1682. OP_AND:
  1683. begin
  1684. list.concat(taicpu.op_reg_reg_reg(A_AND, regdst.reglo, regsrc.reglo, regdst.reglo));
  1685. list.concat(taicpu.op_reg_reg_reg(A_AND, regdst.reghi, regsrc.reghi, regdst.reghi));
  1686. exit;
  1687. end;
  1688. OP_NEG:
  1689. begin
  1690. list.concat(taicpu.op_reg_reg_reg(A_SUBU, regdst.reglo, NR_R0, regsrc.reglo));
  1691. list.concat(taicpu.op_reg_reg_reg(A_SLTU, tmpreg1, NR_R0, regdst.reglo));
  1692. list.concat(taicpu.op_reg_reg_reg(A_SUBU, regdst.reghi, NR_R0, regsrc.reghi));
  1693. list.concat(taicpu.op_reg_reg_reg(A_SUBU, regdst.reghi, regdst.reghi, tmpreg1));
  1694. exit;
  1695. end;
  1696. OP_NOT:
  1697. begin
  1698. list.concat(taicpu.op_reg_reg_reg(A_NOR, regdst.reglo, NR_R0, regsrc.reglo));
  1699. list.concat(taicpu.op_reg_reg_reg(A_NOR, regdst.reghi, NR_R0, regsrc.reghi));
  1700. exit;
  1701. end;
  1702. OP_OR:
  1703. begin
  1704. list.concat(taicpu.op_reg_reg_reg(A_OR, regdst.reglo, regsrc.reglo, regdst.reglo));
  1705. list.concat(taicpu.op_reg_reg_reg(A_OR, regdst.reghi, regsrc.reghi, regdst.reghi));
  1706. exit;
  1707. end;
  1708. OP_SUB:
  1709. begin
  1710. list.concat(taicpu.op_reg_reg_reg(A_SUBU, tmpreg1, regdst.reglo, regsrc.reglo));
  1711. list.concat(taicpu.op_reg_reg_reg(A_SLTU, tmpreg2, regdst.reglo, tmpreg1));
  1712. list.concat(taicpu.op_reg_reg_reg(A_SUBU, regdst.reghi, regdst.reghi, regsrc.reghi));
  1713. list.concat(taicpu.op_reg_reg_reg(A_SUBU, regdst.reghi, regdst.reghi, tmpreg2));
  1714. list.concat(Taicpu.Op_reg_reg(A_MOVE, regdst.reglo, tmpreg1));
  1715. exit;
  1716. end;
  1717. OP_XOR:
  1718. begin
  1719. list.concat(taicpu.op_reg_reg_reg(A_XOR, regdst.reglo, regdst.reglo, regsrc.reglo));
  1720. list.concat(taicpu.op_reg_reg_reg(A_XOR, regdst.reghi, regsrc.reghi, regdst.reghi));
  1721. exit;
  1722. end;
  1723. else
  1724. internalerror(200306017);
  1725. end; {case}
  1726. end;
  1727. procedure TCg64MPSel.a_op64_const_reg(list: tasmlist; op: TOpCG; size: tcgsize; Value: int64; regdst: TRegister64);
  1728. begin
  1729. a_op64_const_reg_reg(list, op, size, value, regdst, regdst);
  1730. end;
  1731. procedure TCg64MPSel.a_op64_const_reg_reg(list: tasmlist; op: TOpCG; size: tcgsize; Value: int64; regsrc, regdst: tregister64);
  1732. var
  1733. l: tlocation;
  1734. begin
  1735. a_op64_const_reg_reg_checkoverflow(list, op, size, Value, regsrc, regdst, False, l);
  1736. end;
  1737. procedure TCg64MPSel.a_op64_reg_reg_reg(list: tasmlist; op: TOpCG; size: tcgsize; regsrc1, regsrc2, regdst: tregister64);
  1738. var
  1739. l: tlocation;
  1740. begin
  1741. a_op64_reg_reg_reg_checkoverflow(list, op, size, regsrc1, regsrc2, regdst, False, l);
  1742. end;
  1743. procedure TCg64MPSel.a_op64_const_reg_reg_checkoverflow(list: tasmlist; op: TOpCG; size: tcgsize; Value: int64; regsrc, regdst: tregister64; setflags: boolean; var ovloc: tlocation);
  1744. var
  1745. tmpreg64: TRegister64;
  1746. begin
  1747. tmpreg64.reglo := cg.GetIntRegister(list, OS_S32);
  1748. tmpreg64.reghi := cg.GetIntRegister(list, OS_S32);
  1749. list.concat(taicpu.op_reg_const(A_LI, tmpreg64.reglo, aint(lo(Value))));
  1750. list.concat(taicpu.op_reg_const(A_LI, tmpreg64.reghi, aint(hi(Value))));
  1751. a_op64_reg_reg_reg_checkoverflow(list, op, size, tmpreg64, regsrc, regdst, False, ovloc);
  1752. end;
  1753. procedure TCg64MPSel.a_op64_reg_reg_reg_checkoverflow(list: tasmlist; op: TOpCG; size: tcgsize; regsrc1, regsrc2, regdst: tregister64; setflags: boolean; var ovloc: tlocation);
  1754. var
  1755. tmpreg1, tmpreg2: TRegister;
  1756. begin
  1757. case op of
  1758. OP_ADD:
  1759. begin
  1760. tmpreg1 := cg.GetIntRegister(list,OS_S32);
  1761. tmpreg2 := cg.GetIntRegister(list,OS_S32);
  1762. // destreg.reglo could be regsrc1.reglo or regsrc2.reglo
  1763. list.concat(taicpu.op_reg_reg_reg(A_ADDU, tmpreg1, regsrc2.reglo, regsrc1.reglo));
  1764. list.concat(taicpu.op_reg_reg_reg(A_SLTU, tmpreg2, tmpreg1, regsrc2.reglo));
  1765. list.concat(taicpu.op_reg_reg(A_MOVE, regdst.reglo, tmpreg1));
  1766. list.concat(taicpu.op_reg_reg_reg(A_ADDU, regdst.reghi, regsrc2.reghi, regsrc1.reghi));
  1767. list.concat(taicpu.op_reg_reg_reg(A_ADDU, regdst.reghi, regdst.reghi, tmpreg2));
  1768. exit;
  1769. end;
  1770. OP_AND:
  1771. begin
  1772. list.concat(taicpu.op_reg_reg_reg(A_AND, regdst.reglo, regsrc2.reglo, regsrc1.reglo));
  1773. list.concat(taicpu.op_reg_reg_reg(A_AND, regdst.reghi, regsrc2.reghi, regsrc1.reghi));
  1774. exit;
  1775. end;
  1776. OP_OR:
  1777. begin
  1778. list.concat(taicpu.op_reg_reg_reg(A_OR, regdst.reglo, regsrc2.reglo, regsrc1.reglo));
  1779. list.concat(taicpu.op_reg_reg_reg(A_OR, regdst.reghi, regsrc2.reghi, regsrc1.reghi));
  1780. exit;
  1781. end;
  1782. OP_SUB:
  1783. begin
  1784. tmpreg1 := cg.GetIntRegister(list,OS_S32);
  1785. tmpreg2 := cg.GetIntRegister(list,OS_S32);
  1786. // destreg.reglo could be regsrc1.reglo or regsrc2.reglo
  1787. list.concat(taicpu.op_reg_reg_reg(A_SUBU,tmpreg1, regsrc2.reglo, regsrc1.reglo));
  1788. list.concat(taicpu.op_reg_reg_reg(A_SLTU, tmpreg2, regsrc2.reglo,tmpreg1));
  1789. list.concat(taicpu.op_reg_reg_reg(A_SUBU, regdst.reghi, regsrc2.reghi, regsrc1.reghi));
  1790. list.concat(taicpu.op_reg_reg_reg(A_SUBU, regdst.reghi, regdst.reghi, tmpreg2));
  1791. list.concat(taicpu.op_reg_reg(A_MOVE, regdst.reglo, tmpreg1));
  1792. exit;
  1793. end;
  1794. OP_XOR:
  1795. begin
  1796. list.concat(taicpu.op_reg_reg_reg(A_XOR, regdst.reglo, regsrc2.reglo, regsrc1.reglo));
  1797. list.concat(taicpu.op_reg_reg_reg(A_XOR, regdst.reghi, regsrc2.reghi, regsrc1.reghi));
  1798. exit;
  1799. end;
  1800. else
  1801. internalerror(200306017);
  1802. end; {case}
  1803. end;
  1804. procedure create_codegen;
  1805. begin
  1806. cg:=TCGMIPS.Create;
  1807. cg64:=TCg64MPSel.Create;
  1808. end;
  1809. end.