cgcpu.pas 68 KB

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