cgcpu.pas 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the code generator for the SPARC
  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,
  23. aasmbase,aasmtai,aasmdata,aasmcpu,
  24. cpubase,cpuinfo,
  25. node,symconst,SymType,symdef,
  26. rgcpu;
  27. type
  28. TCgSparc=class(tcg)
  29. protected
  30. function IsSimpleRef(const ref:treference):boolean;
  31. public
  32. procedure init_register_allocators;override;
  33. procedure done_register_allocators;override;
  34. function getfpuregister(list:TAsmList;size:Tcgsize):Tregister;override;
  35. { sparc special, needed by cg64 }
  36. procedure make_simple_ref(list:TAsmList;var ref: treference);
  37. procedure handle_load_store(list:TAsmList;isstore:boolean;op: tasmop;reg:tregister;ref: treference);
  38. procedure handle_reg_const_reg(list:TAsmList;op:Tasmop;src:tregister;a:tcgint;dst:tregister);
  39. { parameter }
  40. procedure a_loadfpu_reg_cgpara(list : TAsmList;size : tcgsize;const r : tregister;const paraloc : TCGPara);override;
  41. procedure a_loadfpu_ref_cgpara(list : TAsmList;size : tcgsize;const ref : treference;const paraloc : TCGPara);override;
  42. procedure a_call_name(list:TAsmList;const s:string; weak: boolean);override;
  43. procedure a_call_reg(list:TAsmList;Reg:TRegister);override;
  44. { General purpose instructions }
  45. procedure maybeadjustresult(list: TAsmList; op: TOpCg; size: tcgsize; dst: tregister);
  46. procedure a_op_const_reg(list:TAsmList;Op:TOpCG;size:tcgsize;a:tcgint;reg:TRegister);override;
  47. procedure a_op_reg_reg(list:TAsmList;Op:TOpCG;size:TCGSize;src, dst:TRegister);override;
  48. procedure a_op_const_reg_reg(list:TAsmList;op:TOpCg;size:tcgsize;a:tcgint;src, dst:tregister);override;
  49. procedure a_op_reg_reg_reg(list:TAsmList;op:TOpCg;size:tcgsize;src1, src2, dst:tregister);override;
  50. procedure a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; a: tcgint; src, dst: tregister;setflags : boolean;var ovloc : tlocation);override;
  51. procedure a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation);override;
  52. { move instructions }
  53. procedure a_load_const_reg(list:TAsmList;size:tcgsize;a:tcgint;reg:tregister);override;
  54. procedure a_load_const_ref(list:TAsmList;size:tcgsize;a:tcgint;const ref:TReference);override;
  55. procedure a_load_reg_ref(list:TAsmList;FromSize,ToSize:TCgSize;reg:TRegister;const ref:TReference);override;
  56. procedure a_load_ref_reg(list:TAsmList;FromSize,ToSize:TCgSize;const ref:TReference;reg:tregister);override;
  57. procedure a_load_reg_reg(list:TAsmList;FromSize,ToSize:TCgSize;reg1,reg2:tregister);override;
  58. procedure a_loadaddr_ref_reg(list:TAsmList;const ref:TReference;r:tregister);override;
  59. { fpu move instructions }
  60. procedure a_loadfpu_reg_reg(list:TAsmList;fromsize,tosize:tcgsize;reg1, reg2:tregister);override;
  61. procedure a_loadfpu_ref_reg(list:TAsmList;fromsize,tosize:tcgsize;const ref:TReference;reg:tregister);override;
  62. procedure a_loadfpu_reg_ref(list:TAsmList;fromsize,tosize:tcgsize;reg:tregister;const ref:TReference);override;
  63. { comparison operations }
  64. procedure a_cmp_const_reg_label(list:TAsmList;size:tcgsize;cmp_op:topcmp;a:tcgint;reg:tregister;l:tasmlabel);override;
  65. procedure a_cmp_reg_reg_label(list:TAsmList;size:tcgsize;cmp_op:topcmp;reg1,reg2:tregister;l:tasmlabel);override;
  66. procedure a_jmp_always(List:TAsmList;l:TAsmLabel);override;
  67. procedure a_jmp_name(list : TAsmList;const s : string);override;
  68. procedure a_jmp_cond(list:TAsmList;cond:TOpCmp;l:tasmlabel);{ override;}
  69. procedure a_jmp_flags(list:TAsmList;const f:TResFlags;l:tasmlabel);override;
  70. procedure g_flags2reg(list:TAsmList;Size:TCgSize;const f:tresflags;reg:TRegister);override;
  71. procedure g_overflowCheck(List:TAsmList;const Loc:TLocation;def:TDef);override;
  72. procedure g_overflowCheck_loc(List:TAsmList;const Loc:TLocation;def:TDef;ovloc : tlocation);override;
  73. procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);override;
  74. procedure g_proc_exit(list : TAsmList;parasize:longint;nostackframe:boolean);override;
  75. procedure g_maybe_got_init(list: TAsmList); override;
  76. procedure g_restore_registers(list:TAsmList);override;
  77. procedure g_save_registers(list : TAsmList);override;
  78. procedure g_concatcopy(list : TAsmList;const source,dest : treference;len : tcgint);override;
  79. procedure g_concatcopy_unaligned(list : TAsmList;const source,dest : treference;len : tcgint);override;
  80. procedure g_concatcopy_move(list : TAsmList;const source,dest : treference;len : tcgint);
  81. procedure g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: tcgint);override;
  82. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  83. procedure g_external_wrapper(list : TAsmList; procdef: tprocdef; const externalname: string);override;
  84. { Transform unsupported methods into Internal errors }
  85. procedure a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; size: TCGSize; src, dst: TRegister); override;
  86. procedure g_stackpointer_alloc(list : TAsmList;localsize : longint);override;
  87. private
  88. use_unlimited_pic_mode : boolean;
  89. end;
  90. TCg64Sparc=class(tcg64f32)
  91. private
  92. procedure get_64bit_ops(op:TOpCG;var op1,op2:TAsmOp;checkoverflow : boolean);
  93. public
  94. procedure a_load64_reg_ref(list : TAsmList;reg : tregister64;const ref : treference);override;
  95. procedure a_load64_ref_reg(list : TAsmList;const ref : treference;reg : tregister64);override;
  96. procedure a_load64_ref_cgpara(list : TAsmList;const r : treference;const paraloc : tcgpara);override;
  97. procedure a_op64_reg_reg(list:TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst:TRegister64);override;
  98. procedure a_op64_const_reg(list:TAsmList;op:TOpCG;size : tcgsize;value:int64;regdst:TRegister64);override;
  99. procedure a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);override;
  100. procedure a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);override;
  101. procedure a_op64_const_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);override;
  102. procedure a_op64_reg_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);override;
  103. end;
  104. procedure create_codegen;
  105. const
  106. TOpCG2AsmOp : array[topcg] of TAsmOp=(
  107. A_NONE,A_MOV,A_ADD,A_AND,A_UDIV,A_SDIV,A_SMUL,A_UMUL,A_NEG,A_NOT,A_OR,A_SRA,A_SLL,A_SRL,A_SUB,A_XOR,A_NONE,A_NONE
  108. );
  109. TOpCG2AsmOpWithFlags : array[topcg] of TAsmOp=(
  110. A_NONE,A_MOV,A_ADDcc,A_ANDcc,A_UDIVcc,A_SDIVcc,A_SMULcc,A_UMULcc,A_NEG,A_NOT,A_ORcc,A_SRA,A_SLL,A_SRL,A_SUBcc,A_XORcc,A_NONE,A_NONE
  111. );
  112. TOpCmp2AsmCond : array[topcmp] of TAsmCond=(C_NONE,
  113. C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A
  114. );
  115. implementation
  116. uses
  117. globals,verbose,systems,cutils,
  118. paramgr,fmodule,
  119. symtable,symsym,
  120. tgobj,
  121. procinfo,cpupi;
  122. function TCgSparc.IsSimpleRef(const ref:treference):boolean;
  123. begin
  124. result :=not(assigned(ref.symbol))and
  125. (((ref.index = NR_NO) and
  126. (ref.offset >= simm13lo) and
  127. (ref.offset <= simm13hi)) or
  128. ((ref.index <> NR_NO) and
  129. (ref.offset = 0)));
  130. end;
  131. procedure tcgsparc.make_simple_ref(list:TAsmList;var ref: treference);
  132. var
  133. href: treference;
  134. hreg,hreg2: tregister;
  135. begin
  136. if (ref.refaddr<>addr_no) then
  137. InternalError(2013022802);
  138. if (ref.base=NR_NO) then
  139. begin
  140. ref.base:=ref.index;
  141. ref.index:=NR_NO;
  142. end;
  143. if IsSimpleRef(ref) then
  144. exit;
  145. if (ref.symbol=nil) then
  146. begin
  147. hreg:=getintregister(list,OS_INT);
  148. if (ref.index=NR_NO) then
  149. a_load_const_reg(list,OS_INT,ref.offset,hreg)
  150. else
  151. begin
  152. if (ref.offset<simm13lo) or (ref.offset>simm13hi-sizeof(pint)) then
  153. begin
  154. a_load_const_reg(list,OS_INT,ref.offset,hreg);
  155. list.concat(taicpu.op_reg_reg_reg(A_ADD,hreg,ref.index,hreg));
  156. end
  157. else
  158. list.concat(taicpu.op_reg_const_reg(A_ADD,ref.index,ref.offset,hreg));
  159. end;
  160. if (ref.base=NR_NO) then
  161. ref.base:=hreg
  162. else
  163. ref.index:=hreg;
  164. ref.offset:=0;
  165. exit;
  166. end;
  167. reference_reset_symbol(href,ref.symbol,ref.offset,ref.alignment);
  168. hreg:=getintregister(list,OS_INT);
  169. if not (cs_create_pic in current_settings.moduleswitches) then
  170. begin
  171. { absolute loads allow any offset to be encoded into relocation }
  172. href.refaddr:=addr_high;
  173. list.concat(taicpu.op_ref_reg(A_SETHI,href,hreg));
  174. if (ref.base=NR_NO) and (ref.index=NR_NO) then
  175. begin
  176. ref.base:=hreg;
  177. ref.refaddr:=addr_low;
  178. exit;
  179. end;
  180. { base present -> load the entire address and use it as index }
  181. href.refaddr:=addr_low;
  182. list.concat(taicpu.op_reg_ref_reg(A_OR,hreg,href,hreg));
  183. ref.symbol:=nil;
  184. ref.offset:=0;
  185. if (ref.index<>NR_NO) then
  186. list.concat(taicpu.op_reg_reg_reg(A_ADD,ref.index,hreg,hreg));
  187. ref.index:=hreg;
  188. end
  189. else
  190. begin
  191. include(current_procinfo.flags,pi_needs_got);
  192. href.offset:=0;
  193. if use_unlimited_pic_mode then
  194. begin
  195. href.refaddr:=addr_high;
  196. list.concat(taicpu.op_ref_reg(A_SETHI,href,hreg));
  197. href.refaddr:=addr_low;
  198. list.concat(taicpu.op_reg_ref_reg(A_OR,hreg,href,hreg));
  199. reference_reset_base(href,hreg,0,sizeof(pint));
  200. href.index:=current_procinfo.got;
  201. end
  202. else
  203. begin
  204. href.base:=current_procinfo.got;
  205. href.refaddr:=addr_pic;
  206. end;
  207. list.concat(taicpu.op_ref_reg(A_LD,href,hreg));
  208. ref.symbol:=nil;
  209. { hreg now holds symbol address. Add remaining members. }
  210. if (ref.offset>=simm13lo) and (ref.offset<=simm13hi-sizeof(pint)) then
  211. begin
  212. if (ref.base=NR_NO) then
  213. ref.base:=hreg
  214. else
  215. begin
  216. if (ref.offset<>0) then
  217. list.concat(taicpu.op_reg_const_reg(A_ADD,hreg,ref.offset,hreg));
  218. if (ref.index<>NR_NO) then
  219. list.concat(taicpu.op_reg_reg_reg(A_ADD,hreg,ref.index,hreg));
  220. ref.index:=hreg;
  221. ref.offset:=0;
  222. end;
  223. end
  224. else { large offset, need another register to deal with it }
  225. begin
  226. hreg2:=getintregister(list,OS_INT);
  227. a_load_const_reg(list,OS_INT,ref.offset,hreg2);
  228. if (ref.index<>NR_NO) then
  229. list.concat(taicpu.op_reg_reg_reg(A_ADD,hreg2,ref.index,hreg2));
  230. if (ref.base<>NR_NO) then
  231. list.concat(taicpu.op_reg_reg_reg(A_ADD,hreg2,ref.base,hreg2));
  232. ref.base:=hreg;
  233. ref.index:=hreg2;
  234. ref.offset:=0;
  235. end;
  236. end;
  237. end;
  238. procedure tcgsparc.handle_load_store(list:TAsmList;isstore:boolean;op: tasmop;reg:tregister;ref: treference);
  239. begin
  240. make_simple_ref(list,ref);
  241. if isstore then
  242. list.concat(taicpu.op_reg_ref(op,reg,ref))
  243. else
  244. list.concat(taicpu.op_ref_reg(op,ref,reg));
  245. end;
  246. procedure tcgsparc.handle_reg_const_reg(list:TAsmList;op:Tasmop;src:tregister;a:tcgint;dst:tregister);
  247. var
  248. tmpreg : tregister;
  249. begin
  250. if (a<simm13lo) or
  251. (a>simm13hi) then
  252. begin
  253. tmpreg:=GetIntRegister(list,OS_INT);
  254. a_load_const_reg(list,OS_INT,a,tmpreg);
  255. list.concat(taicpu.op_reg_reg_reg(op,src,tmpreg,dst));
  256. end
  257. else
  258. list.concat(taicpu.op_reg_const_reg(op,src,a,dst));
  259. end;
  260. {****************************************************************************
  261. Assembler code
  262. ****************************************************************************}
  263. procedure Tcgsparc.init_register_allocators;
  264. begin
  265. inherited init_register_allocators;
  266. rg[R_INTREGISTER]:=Trgcpu.create(R_INTREGISTER,R_SUBD,
  267. [RS_O0,RS_O1,RS_O2,RS_O3,RS_O4,RS_O5,RS_O7,
  268. RS_L0,RS_L1,RS_L2,RS_L3,RS_L4,RS_L5,RS_L6,RS_L7,
  269. RS_I0,RS_I1,RS_I2,RS_I3,RS_I4,RS_I5],
  270. first_int_imreg,[]);
  271. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBFS,
  272. [RS_F0,RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7,
  273. RS_F8,RS_F9,RS_F10,RS_F11,RS_F12,RS_F13,RS_F14,RS_F15,
  274. RS_F16,RS_F17,RS_F18,RS_F19,RS_F20,RS_F21,RS_F22,RS_F23,
  275. RS_F24,RS_F25,RS_F26,RS_F27,RS_F28,RS_F29,RS_F30,RS_F31],
  276. first_fpu_imreg,[]);
  277. { needs at least one element for rgobj not to crash }
  278. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,
  279. [RS_L0],first_mm_imreg,[]);
  280. end;
  281. procedure Tcgsparc.done_register_allocators;
  282. begin
  283. rg[R_INTREGISTER].free;
  284. rg[R_FPUREGISTER].free;
  285. rg[R_MMREGISTER].free;
  286. inherited done_register_allocators;
  287. end;
  288. function tcgsparc.getfpuregister(list:TAsmList;size:Tcgsize):Tregister;
  289. begin
  290. if size=OS_F64 then
  291. result:=rg[R_FPUREGISTER].getregister(list,R_SUBFD)
  292. else
  293. result:=rg[R_FPUREGISTER].getregister(list,R_SUBFS);
  294. end;
  295. procedure tcgsparc.a_loadfpu_ref_cgpara(list : TAsmList;size : tcgsize;const ref : treference;const paraloc : TCGPara);
  296. var
  297. href,href2 : treference;
  298. hloc : pcgparalocation;
  299. begin
  300. href:=ref;
  301. hloc:=paraloc.location;
  302. while assigned(hloc) do
  303. begin
  304. paramanager.allocparaloc(list,hloc);
  305. case hloc^.loc of
  306. LOC_REGISTER,LOC_CREGISTER :
  307. a_load_ref_reg(list,hloc^.size,hloc^.size,href,hloc^.register);
  308. LOC_REFERENCE :
  309. begin
  310. reference_reset_base(href2,hloc^.reference.index,hloc^.reference.offset,paraloc.alignment);
  311. a_load_ref_ref(list,hloc^.size,hloc^.size,href,href2);
  312. end;
  313. LOC_FPUREGISTER,LOC_CFPUREGISTER :
  314. a_loadfpu_ref_reg(list,hloc^.size,hloc^.size,href,hloc^.register);
  315. else
  316. internalerror(200408241);
  317. end;
  318. inc(href.offset,tcgsize2size[hloc^.size]);
  319. hloc:=hloc^.next;
  320. end;
  321. end;
  322. procedure tcgsparc.a_loadfpu_reg_cgpara(list : TAsmList;size : tcgsize;const r : tregister;const paraloc : TCGPara);
  323. var
  324. href : treference;
  325. begin
  326. { happens for function result loc }
  327. if paraloc.location^.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER] then
  328. begin
  329. paraloc.check_simple_location;
  330. paramanager.allocparaloc(list,paraloc.location);
  331. a_loadfpu_reg_reg(list,size,paraloc.location^.size,r,paraloc.location^.register);
  332. end
  333. else
  334. begin
  335. tg.GetTemp(list,TCGSize2Size[size],TCGSize2Size[size],tt_normal,href);
  336. a_loadfpu_reg_ref(list,size,size,r,href);
  337. a_loadfpu_ref_cgpara(list,size,href,paraloc);
  338. tg.Ungettemp(list,href);
  339. end;
  340. end;
  341. procedure TCgSparc.a_call_name(list:TAsmList;const s:string; weak: boolean);
  342. begin
  343. if not weak then
  344. list.concat(taicpu.op_sym(A_CALL,current_asmdata.RefAsmSymbol(s)))
  345. else
  346. list.concat(taicpu.op_sym(A_CALL,current_asmdata.WeakRefAsmSymbol(s)));
  347. { Delay slot }
  348. list.concat(taicpu.op_none(A_NOP));
  349. end;
  350. procedure TCgSparc.a_call_reg(list:TAsmList;Reg:TRegister);
  351. begin
  352. list.concat(taicpu.op_reg(A_CALL,reg));
  353. { Delay slot }
  354. list.concat(taicpu.op_none(A_NOP));
  355. end;
  356. {********************** load instructions ********************}
  357. procedure TCgSparc.a_load_const_reg(list : TAsmList;size : TCGSize;a : tcgint;reg : TRegister);
  358. begin
  359. { we don't use the set instruction here because it could be evalutated to two
  360. instructions which would cause problems with the delay slot (FK) }
  361. if (a=0) then
  362. list.concat(taicpu.op_reg(A_CLR,reg))
  363. else if (a>=simm13lo) and (a<=simm13hi) then
  364. list.concat(taicpu.op_const_reg(A_MOV,a,reg))
  365. else
  366. begin
  367. list.concat(taicpu.op_const_reg(A_SETHI,aint(a) shr 10,reg));
  368. if (aint(a) and aint($3ff))<>0 then
  369. list.concat(taicpu.op_reg_const_reg(A_OR,reg,aint(a) and aint($3ff),reg));
  370. end;
  371. end;
  372. procedure TCgSparc.a_load_const_ref(list : TAsmList;size : tcgsize;a : tcgint;const ref : TReference);
  373. begin
  374. if a=0 then
  375. a_load_reg_ref(list,size,size,NR_G0,ref)
  376. else
  377. inherited a_load_const_ref(list,size,a,ref);
  378. end;
  379. procedure TCgSparc.a_load_reg_ref(list:TAsmList;FromSize,ToSize:TCGSize;reg:tregister;const Ref:TReference);
  380. var
  381. op : tasmop;
  382. begin
  383. if (TCGSize2Size[fromsize] >= TCGSize2Size[tosize]) then
  384. fromsize := tosize;
  385. if (ref.alignment<>0) and
  386. (ref.alignment<tcgsize2size[tosize]) then
  387. begin
  388. a_load_reg_ref_unaligned(list,FromSize,ToSize,reg,ref);
  389. end
  390. else
  391. begin
  392. case tosize of
  393. { signed integer registers }
  394. OS_8,
  395. OS_S8:
  396. Op:=A_STB;
  397. OS_16,
  398. OS_S16:
  399. Op:=A_STH;
  400. OS_32,
  401. OS_S32:
  402. Op:=A_ST;
  403. else
  404. InternalError(2002122100);
  405. end;
  406. handle_load_store(list,true,op,reg,ref);
  407. end;
  408. end;
  409. procedure TCgSparc.a_load_ref_reg(list:TAsmList;FromSize,ToSize:TCgSize;const ref:TReference;reg:tregister);
  410. var
  411. op : tasmop;
  412. begin
  413. if (TCGSize2Size[fromsize] >= TCGSize2Size[tosize]) then
  414. fromsize := tosize;
  415. if (ref.alignment<>0) and
  416. (ref.alignment<tcgsize2size[fromsize]) then
  417. begin
  418. a_load_ref_reg_unaligned(list,FromSize,ToSize,ref,reg);
  419. end
  420. else
  421. begin
  422. case fromsize of
  423. OS_S8:
  424. Op:=A_LDSB;{Load Signed Byte}
  425. OS_8:
  426. Op:=A_LDUB;{Load Unsigned Byte}
  427. OS_S16:
  428. Op:=A_LDSH;{Load Signed Halfword}
  429. OS_16:
  430. Op:=A_LDUH;{Load Unsigned Halfword}
  431. OS_S32,
  432. OS_32:
  433. Op:=A_LD;{Load Word}
  434. OS_S64,
  435. OS_64:
  436. Op:=A_LDD;{Load a Long Word}
  437. else
  438. InternalError(2002122101);
  439. end;
  440. handle_load_store(list,false,op,reg,ref);
  441. if (fromsize=OS_S8) and
  442. (tosize=OS_16) then
  443. a_load_reg_reg(list,fromsize,tosize,reg,reg);
  444. end;
  445. end;
  446. procedure TCgSparc.a_load_reg_reg(list:TAsmList;fromsize,tosize:tcgsize;reg1,reg2:tregister);
  447. var
  448. instr : taicpu;
  449. begin
  450. if (tcgsize2size[fromsize] > tcgsize2size[tosize]) or
  451. ((tcgsize2size[fromsize] = tcgsize2size[tosize]) and
  452. (fromsize <> tosize)) or
  453. { needs to mask out the sign in the top 16 bits }
  454. ((fromsize = OS_S8) and
  455. (tosize = OS_16)) then
  456. case tosize of
  457. OS_8 :
  458. list.concat(taicpu.op_reg_const_reg(A_AND,reg1,$ff,reg2));
  459. OS_16 :
  460. begin
  461. list.concat(taicpu.op_reg_const_reg(A_SLL,reg1,16,reg2));
  462. list.concat(taicpu.op_reg_const_reg(A_SRL,reg2,16,reg2));
  463. end;
  464. OS_32,
  465. OS_S32 :
  466. begin
  467. instr:=taicpu.op_reg_reg(A_MOV,reg1,reg2);
  468. list.Concat(instr);
  469. { Notify the register allocator that we have written a move instruction so
  470. it can try to eliminate it. }
  471. add_move_instruction(instr);
  472. end;
  473. OS_S8 :
  474. begin
  475. list.concat(taicpu.op_reg_const_reg(A_SLL,reg1,24,reg2));
  476. list.concat(taicpu.op_reg_const_reg(A_SRA,reg2,24,reg2));
  477. end;
  478. OS_S16 :
  479. begin
  480. list.concat(taicpu.op_reg_const_reg(A_SLL,reg1,16,reg2));
  481. list.concat(taicpu.op_reg_const_reg(A_SRA,reg2,16,reg2));
  482. end;
  483. else
  484. internalerror(2002090901);
  485. end
  486. else
  487. begin
  488. instr:=taicpu.op_reg_reg(A_MOV,reg1,reg2);
  489. list.Concat(instr);
  490. { Notify the register allocator that we have written a move instruction so
  491. it can try to eliminate it. }
  492. add_move_instruction(instr);
  493. end;
  494. end;
  495. procedure TCgSparc.a_loadaddr_ref_reg(list : TAsmList;const ref : TReference;r : tregister);
  496. var
  497. href: treference;
  498. hreg: tregister;
  499. begin
  500. if (ref.base=NR_NO) and (ref.index<>NR_NO) then
  501. internalerror(200306171);
  502. if (ref.symbol=nil) then
  503. begin
  504. if (ref.base<>NR_NO) then
  505. begin
  506. if (ref.offset<simm13lo) or (ref.offset>simm13hi) then
  507. begin
  508. hreg:=getintregister(list,OS_INT);
  509. a_load_const_reg(list,OS_INT,ref.offset,hreg);
  510. list.concat(taicpu.op_reg_reg_reg(A_ADD,hreg,ref.base,r));
  511. if (ref.index<>NR_NO) then
  512. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref.index,r));
  513. end
  514. else if (ref.offset<>0) then
  515. begin
  516. list.concat(taicpu.op_reg_const_reg(A_ADD,ref.base,ref.offset,r));
  517. if (ref.index<>NR_NO) then
  518. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref.index,r));
  519. end
  520. else if (ref.index<>NR_NO) then
  521. list.concat(taicpu.op_reg_reg_reg(A_ADD,ref.base,ref.index,r))
  522. else
  523. a_load_reg_reg(list,OS_INT,OS_INT,ref.base,r); { (try to) emit optimizable move }
  524. end
  525. else
  526. a_load_const_reg(list,OS_INT,ref.offset,r);
  527. exit;
  528. end;
  529. reference_reset_symbol(href,ref.symbol,ref.offset,ref.alignment);
  530. if (cs_create_pic in current_settings.moduleswitches) then
  531. begin
  532. include(current_procinfo.flags,pi_needs_got);
  533. href.offset:=0;
  534. if use_unlimited_pic_mode then
  535. begin
  536. href.refaddr:=addr_high;
  537. list.concat(taicpu.op_ref_reg(A_SETHI,href,r));
  538. href.refaddr:=addr_low;
  539. list.concat(taicpu.op_reg_ref_reg(A_OR,r,href,r));
  540. reference_reset_base(href,r,0,sizeof(pint));
  541. href.index:=current_procinfo.got;
  542. end
  543. else
  544. begin
  545. href.base:=current_procinfo.got;
  546. href.refaddr:=addr_pic; { should it be done THAT way?? }
  547. end;
  548. { load contents of GOT slot }
  549. list.concat(taicpu.op_ref_reg(A_LD,href,r));
  550. { add original base/index, if any }
  551. if (ref.base<>NR_NO) then
  552. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref.base,r));
  553. if (ref.index<>NR_NO) then
  554. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref.index,r));
  555. { finally, add offset }
  556. if (ref.offset<simm13lo) or (ref.offset>simm13hi) then
  557. begin
  558. hreg:=getintregister(list,OS_INT);
  559. a_load_const_reg(list,OS_INT,ref.offset,hreg);
  560. list.concat(taicpu.op_reg_reg_reg(A_ADD,hreg,r,r));
  561. end
  562. else if (ref.offset<>0) then
  563. list.concat(taicpu.op_reg_const_reg(A_ADD,r,ref.offset,r));
  564. end
  565. else
  566. begin
  567. { load symbol+offset }
  568. href.refaddr:=addr_high;
  569. list.concat(taicpu.op_ref_reg(A_SETHI,href,r));
  570. href.refaddr:=addr_low;
  571. list.concat(taicpu.op_reg_ref_reg(A_OR,r,href,r));
  572. { add original base/index, if any }
  573. if (ref.base<>NR_NO) then
  574. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref.base,r));
  575. if (ref.index<>NR_NO) then
  576. list.concat(taicpu.op_reg_reg_reg(A_ADD,r,ref.index,r));
  577. end;
  578. end;
  579. procedure TCgSparc.a_loadfpu_reg_reg(list:TAsmList;fromsize,tosize:tcgsize;reg1, reg2:tregister);
  580. const
  581. FpuMovInstr : Array[OS_F32..OS_F64,OS_F32..OS_F64] of TAsmOp =
  582. ((A_FMOVS,A_FSTOD),(A_FDTOS,A_FMOVD));
  583. var
  584. op: TAsmOp;
  585. instr : taicpu;
  586. begin
  587. op:=fpumovinstr[fromsize,tosize];
  588. instr:=taicpu.op_reg_reg(op,reg1,reg2);
  589. list.Concat(instr);
  590. { Notify the register allocator that we have written a move instruction so
  591. it can try to eliminate it. }
  592. if (op = A_FMOVS) or
  593. (op = A_FMOVD) then
  594. add_move_instruction(instr);
  595. end;
  596. procedure TCgSparc.a_loadfpu_ref_reg(list:TAsmList;fromsize,tosize:tcgsize;const ref:TReference;reg:tregister);
  597. const
  598. FpuLoadInstr : Array[OS_F32..OS_F64] of TAsmOp =
  599. (A_LDF,A_LDDF);
  600. var
  601. tmpreg: tregister;
  602. begin
  603. tmpreg:=NR_NO;
  604. if (fromsize<>tosize) then
  605. begin
  606. tmpreg:=reg;
  607. reg:=getfpuregister(list,fromsize);
  608. end;
  609. handle_load_store(list,false,fpuloadinstr[fromsize],reg,ref);
  610. if (fromsize<>tosize) then
  611. a_loadfpu_reg_reg(list,fromsize,tosize,reg,tmpreg);
  612. end;
  613. procedure TCgSparc.a_loadfpu_reg_ref(list:TAsmList;fromsize,tosize:tcgsize;reg:tregister;const ref:TReference);
  614. const
  615. FpuLoadInstr : Array[OS_F32..OS_F64] of TAsmOp =
  616. (A_STF,A_STDF);
  617. var
  618. tmpreg: tregister;
  619. begin
  620. if (fromsize<>tosize) then
  621. begin
  622. tmpreg:=getfpuregister(list,tosize);
  623. a_loadfpu_reg_reg(list,fromsize,tosize,reg,tmpreg);
  624. reg:=tmpreg;
  625. end;
  626. handle_load_store(list,true,fpuloadinstr[tosize],reg,ref);
  627. end;
  628. procedure tcgsparc.maybeadjustresult(list: TAsmList; op: TOpCg; size: tcgsize; dst: tregister);
  629. const
  630. overflowops = [OP_MUL,OP_SHL,OP_ADD,OP_SUB,OP_NOT,OP_NEG];
  631. begin
  632. if (op in overflowops) and
  633. (size in [OS_8,OS_S8,OS_16,OS_S16]) then
  634. a_load_reg_reg(list,OS_32,size,dst,dst);
  635. end;
  636. procedure TCgSparc.a_op_const_reg(list:TAsmList;Op:TOpCG;size:tcgsize;a:tcgint;reg:TRegister);
  637. begin
  638. optimize_op_const(size,op,a);
  639. case op of
  640. OP_NONE:
  641. exit;
  642. OP_MOVE:
  643. a_load_const_reg(list,size,a,reg);
  644. OP_NEG,OP_NOT:
  645. internalerror(200306011);
  646. else
  647. a_op_const_reg_reg(list,op,size,a,reg,reg);
  648. end;
  649. end;
  650. procedure TCgSparc.a_op_reg_reg(list:TAsmList;Op:TOpCG;size:TCGSize;src, dst:TRegister);
  651. var
  652. a : aint;
  653. begin
  654. Case Op of
  655. OP_NEG :
  656. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],src,dst));
  657. OP_NOT :
  658. begin
  659. case size of
  660. OS_8 :
  661. a:=aint($ffffff00);
  662. OS_16 :
  663. a:=aint($ffff0000);
  664. else
  665. a:=0;
  666. end;
  667. handle_reg_const_reg(list,A_XNOR,src,a,dst);
  668. end;
  669. else
  670. list.concat(taicpu.op_reg_reg_reg(TOpCG2AsmOp[op],dst,src,dst));
  671. end;
  672. maybeadjustresult(list,op,size,dst);
  673. end;
  674. procedure TCgSparc.a_op_const_reg_reg(list:TAsmList;op:TOpCg;size:tcgsize;a:tcgint;src, dst:tregister);
  675. var
  676. l: TLocation;
  677. begin
  678. a_op_const_reg_reg_checkoverflow(list,op,size,a,src,dst,false,l);
  679. end;
  680. procedure TCgSparc.a_op_reg_reg_reg(list:TAsmList;op:TOpCg;size:tcgsize;src1, src2, dst:tregister);
  681. begin
  682. if (TOpcg2AsmOp[op]=A_NONE) then
  683. InternalError(2013070305);
  684. if (op=OP_SAR) then
  685. begin
  686. if (size in [OS_S8,OS_S16]) then
  687. begin
  688. { Sign-extend before shifting }
  689. list.concat(taicpu.op_reg_const_reg(A_SLL,src2,32-(tcgsize2size[size]*8),dst));
  690. list.concat(taicpu.op_reg_const_reg(A_SRA,dst,32-(tcgsize2size[size]*8),dst));
  691. src2:=dst;
  692. end
  693. else if not (size in [OS_32,OS_S32]) then
  694. InternalError(2013070306);
  695. end;
  696. list.concat(taicpu.op_reg_reg_reg(TOpCG2AsmOp[op],src2,src1,dst));
  697. maybeadjustresult(list,op,size,dst);
  698. end;
  699. procedure tcgsparc.a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; a: tcgint; src, dst: tregister;setflags : boolean;var ovloc : tlocation);
  700. var
  701. tmpreg1,tmpreg2 : tregister;
  702. begin
  703. ovloc.loc:=LOC_VOID;
  704. optimize_op_const(size,op,a);
  705. case op of
  706. OP_NONE:
  707. begin
  708. a_load_reg_reg(list,size,size,src,dst);
  709. exit;
  710. end;
  711. OP_MOVE:
  712. begin
  713. a_load_const_reg(list,size,a,dst);
  714. exit;
  715. end;
  716. OP_SAR:
  717. begin
  718. if (size in [OS_S8,OS_S16]) then
  719. begin
  720. list.concat(taicpu.op_reg_const_reg(A_SLL,src,32-(tcgsize2size[size]*8),dst));
  721. inc(a,32-tcgsize2size[size]*8);
  722. src:=dst;
  723. end
  724. else if not (size in [OS_32,OS_S32]) then
  725. InternalError(2013070303);
  726. end;
  727. end;
  728. if setflags then
  729. begin
  730. handle_reg_const_reg(list,TOpCG2AsmOpWithFlags[op],src,a,dst);
  731. case op of
  732. OP_MUL:
  733. begin
  734. tmpreg1:=GetIntRegister(list,OS_INT);
  735. list.concat(taicpu.op_reg_reg(A_MOV,NR_Y,tmpreg1));
  736. list.concat(taicpu.op_reg_reg(A_CMP,NR_G0,tmpreg1));
  737. ovloc.loc:=LOC_FLAGS;
  738. ovloc.resflags:=F_NE;
  739. end;
  740. OP_IMUL:
  741. begin
  742. tmpreg1:=GetIntRegister(list,OS_INT);
  743. tmpreg2:=GetIntRegister(list,OS_INT);
  744. list.concat(taicpu.op_reg_reg(A_MOV,NR_Y,tmpreg1));
  745. list.concat(taicpu.op_reg_const_reg(A_SRA,dst,31,tmpreg2));
  746. list.concat(taicpu.op_reg_reg(A_CMP,tmpreg1,tmpreg2));
  747. ovloc.loc:=LOC_FLAGS;
  748. ovloc.resflags:=F_NE;
  749. end;
  750. end;
  751. end
  752. else
  753. handle_reg_const_reg(list,TOpCG2AsmOp[op],src,a,dst);
  754. maybeadjustresult(list,op,size,dst);
  755. end;
  756. procedure tcgsparc.a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation);
  757. var
  758. tmpreg1,tmpreg2 : tregister;
  759. begin
  760. ovloc.loc:=LOC_VOID;
  761. if setflags then
  762. begin
  763. list.concat(taicpu.op_reg_reg_reg(TOpCG2AsmOpWithFlags[op],src2,src1,dst));
  764. case op of
  765. OP_MUL:
  766. begin
  767. tmpreg1:=GetIntRegister(list,OS_INT);
  768. list.concat(taicpu.op_reg_reg(A_MOV,NR_Y,tmpreg1));
  769. list.concat(taicpu.op_reg_reg(A_CMP,NR_G0,tmpreg1));
  770. ovloc.loc:=LOC_FLAGS;
  771. ovloc.resflags:=F_NE;
  772. end;
  773. OP_IMUL:
  774. begin
  775. tmpreg1:=GetIntRegister(list,OS_INT);
  776. tmpreg2:=GetIntRegister(list,OS_INT);
  777. list.concat(taicpu.op_reg_reg(A_MOV,NR_Y,tmpreg1));
  778. list.concat(taicpu.op_reg_const_reg(A_SRL,dst,31,tmpreg2));
  779. list.concat(taicpu.op_reg_reg(A_CMP,tmpreg1,tmpreg2));
  780. ovloc.loc:=LOC_FLAGS;
  781. ovloc.resflags:=F_NE;
  782. end;
  783. end;
  784. end
  785. else
  786. list.concat(taicpu.op_reg_reg_reg(TOpCG2AsmOp[op],src2,src1,dst));
  787. maybeadjustresult(list,op,size,dst);
  788. end;
  789. {*************** compare instructructions ****************}
  790. procedure TCgSparc.a_cmp_const_reg_label(list:TAsmList;size:tcgsize;cmp_op:topcmp;a:tcgint;reg:tregister;l:tasmlabel);
  791. begin
  792. if (a=0) then
  793. list.concat(taicpu.op_reg_reg_reg(A_SUBcc,reg,NR_G0,NR_G0))
  794. else
  795. handle_reg_const_reg(list,A_SUBcc,reg,a,NR_G0);
  796. a_jmp_cond(list,cmp_op,l);
  797. end;
  798. procedure TCgSparc.a_cmp_reg_reg_label(list:TAsmList;size:tcgsize;cmp_op:topcmp;reg1,reg2:tregister;l:tasmlabel);
  799. begin
  800. list.concat(taicpu.op_reg_reg_reg(A_SUBcc,reg2,reg1,NR_G0));
  801. a_jmp_cond(list,cmp_op,l);
  802. end;
  803. procedure TCgSparc.a_jmp_always(List:TAsmList;l:TAsmLabel);
  804. begin
  805. List.Concat(TAiCpu.op_sym(A_BA,current_asmdata.RefAsmSymbol(l.name)));
  806. { Delay slot }
  807. list.Concat(TAiCpu.Op_none(A_NOP));
  808. end;
  809. procedure tcgsparc.a_jmp_name(list : TAsmList;const s : string);
  810. begin
  811. List.Concat(TAiCpu.op_sym(A_BA,current_asmdata.RefAsmSymbol(s)));
  812. { Delay slot }
  813. list.Concat(TAiCpu.Op_none(A_NOP));
  814. end;
  815. procedure TCgSparc.a_jmp_cond(list:TAsmList;cond:TOpCmp;l:TAsmLabel);
  816. var
  817. ai:TAiCpu;
  818. begin
  819. ai:=TAiCpu.Op_sym(A_Bxx,l);
  820. ai.SetCondition(TOpCmp2AsmCond[cond]);
  821. list.Concat(ai);
  822. { Delay slot }
  823. list.Concat(TAiCpu.Op_none(A_NOP));
  824. end;
  825. procedure TCgSparc.a_jmp_flags(list:TAsmList;const f:TResFlags;l:tasmlabel);
  826. var
  827. ai : taicpu;
  828. begin
  829. ai:=Taicpu.op_sym(A_Bxx,l);
  830. ai.SetCondition(flags_to_cond(f));
  831. list.Concat(ai);
  832. { Delay slot }
  833. list.Concat(TAiCpu.Op_none(A_NOP));
  834. end;
  835. procedure TCgSparc.g_flags2reg(list:TAsmList;Size:TCgSize;const f:tresflags;reg:TRegister);
  836. var
  837. hl : tasmlabel;
  838. begin
  839. current_asmdata.getjumplabel(hl);
  840. a_load_const_reg(list,size,1,reg);
  841. a_jmp_flags(list,f,hl);
  842. a_load_const_reg(list,size,0,reg);
  843. a_label(list,hl);
  844. end;
  845. procedure tcgsparc.g_overflowCheck(List:TAsmList;const Loc:TLocation;def:TDef);
  846. var
  847. l : tlocation;
  848. begin
  849. l.loc:=LOC_VOID;
  850. g_overflowCheck_loc(list,loc,def,l);
  851. end;
  852. procedure TCgSparc.g_overflowCheck_loc(List:TAsmList;const Loc:TLocation;def:TDef;ovloc : tlocation);
  853. var
  854. hl : tasmlabel;
  855. ai:TAiCpu;
  856. hflags : tresflags;
  857. begin
  858. if not(cs_check_overflow in current_settings.localswitches) then
  859. exit;
  860. current_asmdata.getjumplabel(hl);
  861. case ovloc.loc of
  862. LOC_VOID:
  863. begin
  864. if not((def.typ=pointerdef) or
  865. ((def.typ=orddef) and
  866. (torddef(def).ordtype in [u64bit,u16bit,u32bit,u8bit,uchar,
  867. pasbool8,pasbool16,pasbool32,pasbool64]))) then
  868. begin
  869. ai:=TAiCpu.Op_sym(A_Bxx,hl);
  870. ai.SetCondition(C_NO);
  871. list.Concat(ai);
  872. { Delay slot }
  873. list.Concat(TAiCpu.Op_none(A_NOP));
  874. end
  875. else
  876. a_jmp_cond(list,OC_AE,hl);
  877. end;
  878. LOC_FLAGS:
  879. begin
  880. hflags:=ovloc.resflags;
  881. inverse_flags(hflags);
  882. cg.a_jmp_flags(list,hflags,hl);
  883. end;
  884. else
  885. internalerror(200409281);
  886. end;
  887. a_call_name(list,'FPC_OVERFLOW',false);
  888. a_label(list,hl);
  889. end;
  890. { *********** entry/exit code and address loading ************ }
  891. procedure TCgSparc.g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);
  892. begin
  893. if nostackframe then
  894. exit;
  895. { Althogh the SPARC architecture require only word alignment, software
  896. convention and the operating system require every stack frame to be double word
  897. aligned }
  898. LocalSize:=align(LocalSize,8);
  899. { Execute the SAVE instruction to get a new register window and create a new
  900. stack frame. In the "SAVE %i6,size,%i6" the first %i6 is related to the state
  901. before execution of the SAVE instrucion so it is the caller %i6, when the %i6
  902. after execution of that instruction is the called function stack pointer}
  903. { constant can be 13 bit signed, since it's negative, size can be max. 4096 }
  904. if LocalSize>4096 then
  905. begin
  906. a_load_const_reg(list,OS_ADDR,-LocalSize,NR_G1);
  907. list.concat(Taicpu.Op_reg_reg_reg(A_SAVE,NR_STACK_POINTER_REG,NR_G1,NR_STACK_POINTER_REG));
  908. end
  909. else
  910. list.concat(Taicpu.Op_reg_const_reg(A_SAVE,NR_STACK_POINTER_REG,-LocalSize,NR_STACK_POINTER_REG));
  911. end;
  912. procedure TCgSparc.g_maybe_got_init(list : TAsmList);
  913. var
  914. ref : treference;
  915. hl : tasmlabel;
  916. begin
  917. if (cs_create_pic in current_settings.moduleswitches) and
  918. ((pi_needs_got in current_procinfo.flags) or
  919. (current_procinfo.procdef.proctypeoption=potype_unitfinalize)) then
  920. begin
  921. current_asmdata.getjumplabel(hl);
  922. list.concat(taicpu.op_sym(A_CALL,hl));
  923. { ABI recommends the following sequence:
  924. 1: call 2f
  925. sethi %hi(_GLOBAL_OFFSET_TABLE_+(.-1b)), %l7
  926. 2: or %l7, %lo(_GLOBAL_OFFSET_TABLE_+(.-1b)), %l7
  927. add %l7, %o7, %l7 }
  928. reference_reset_symbol(ref,current_asmdata.RefAsmSymbol('_GLOBAL_OFFSET_TABLE_'),4,sizeof(pint));
  929. ref.refaddr:=addr_high;
  930. list.concat(taicpu.op_ref_reg(A_SETHI,ref,NR_L7));
  931. cg.a_label(list,hl);
  932. ref.refaddr:=addr_low;
  933. ref.offset:=8;
  934. list.concat(Taicpu.Op_reg_ref_reg(A_OR,NR_L7,ref,NR_L7));
  935. list.concat(taicpu.op_reg_reg_reg(A_ADD,NR_L7,NR_O7,NR_L7));
  936. { allocate NR_L7, so reg.allocator does not see it as available }
  937. list.concat(tai_regalloc.alloc(NR_L7,nil));
  938. end;
  939. end;
  940. procedure TCgSparc.g_restore_registers(list:TAsmList);
  941. begin
  942. { The sparc port uses the sparc standard calling convetions so this function has no used }
  943. end;
  944. procedure TCgSparc.g_proc_exit(list : TAsmList;parasize:longint;nostackframe:boolean);
  945. var
  946. hr : treference;
  947. begin
  948. if paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef) then
  949. begin
  950. reference_reset(hr,sizeof(pint));
  951. hr.offset:=12;
  952. hr.refaddr:=addr_full;
  953. if nostackframe then
  954. begin
  955. hr.base:=NR_O7;
  956. list.concat(taicpu.op_ref_reg(A_JMPL,hr,NR_G0));
  957. list.concat(Taicpu.op_none(A_NOP))
  958. end
  959. else
  960. begin
  961. { We use trivial restore in the delay slot of the JMPL instruction, as we
  962. already set result onto %i0 }
  963. hr.base:=NR_I7;
  964. list.concat(taicpu.op_ref_reg(A_JMPL,hr,NR_G0));
  965. list.concat(Taicpu.op_none(A_RESTORE));
  966. end;
  967. end
  968. else
  969. begin
  970. if nostackframe then
  971. begin
  972. { Here we need to use RETL instead of RET so it uses %o7 }
  973. list.concat(Taicpu.op_none(A_RETL));
  974. list.concat(Taicpu.op_none(A_NOP))
  975. end
  976. else
  977. begin
  978. { We use trivial restore in the delay slot of the JMPL instruction, as we
  979. already set result onto %i0 }
  980. list.concat(Taicpu.op_none(A_RET));
  981. list.concat(Taicpu.op_none(A_RESTORE));
  982. end;
  983. end;
  984. end;
  985. procedure TCgSparc.g_save_registers(list : TAsmList);
  986. begin
  987. { The sparc port uses the sparc standard calling convetions so this function has no used }
  988. end;
  989. { ************* concatcopy ************ }
  990. procedure tcgsparc.g_concatcopy_move(list : TAsmList;const source,dest : treference;len : tcgint);
  991. var
  992. paraloc1,paraloc2,paraloc3 : TCGPara;
  993. pd : tprocdef;
  994. begin
  995. pd:=search_system_proc('MOVE');
  996. paraloc1.init;
  997. paraloc2.init;
  998. paraloc3.init;
  999. paramanager.getintparaloc(pd,1,paraloc1);
  1000. paramanager.getintparaloc(pd,2,paraloc2);
  1001. paramanager.getintparaloc(pd,3,paraloc3);
  1002. a_load_const_cgpara(list,OS_SINT,len,paraloc3);
  1003. a_loadaddr_ref_cgpara(list,dest,paraloc2);
  1004. a_loadaddr_ref_cgpara(list,source,paraloc1);
  1005. paramanager.freecgpara(list,paraloc3);
  1006. paramanager.freecgpara(list,paraloc2);
  1007. paramanager.freecgpara(list,paraloc1);
  1008. alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1009. alloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  1010. a_call_name(list,'FPC_MOVE',false);
  1011. dealloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  1012. dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1013. paraloc3.done;
  1014. paraloc2.done;
  1015. paraloc1.done;
  1016. end;
  1017. procedure TCgSparc.g_concatcopy(list:TAsmList;const source,dest:treference;len:tcgint);
  1018. var
  1019. tmpreg1,
  1020. hreg,
  1021. countreg: TRegister;
  1022. src, dst: TReference;
  1023. lab: tasmlabel;
  1024. count, count2: aint;
  1025. function reference_is_reusable(const ref: treference): boolean;
  1026. begin
  1027. result:=(ref.base<>NR_NO) and (ref.index=NR_NO) and
  1028. (ref.symbol=nil) and
  1029. (ref.offset>=simm13lo) and (ref.offset+len<=simm13hi);
  1030. end;
  1031. begin
  1032. if len>high(longint) then
  1033. internalerror(2002072704);
  1034. { anybody wants to determine a good value here :)? }
  1035. if len>100 then
  1036. g_concatcopy_move(list,source,dest,len)
  1037. else
  1038. begin
  1039. count:=len div 4;
  1040. if (count<=4) and reference_is_reusable(source) then
  1041. src:=source
  1042. else
  1043. begin
  1044. reference_reset_base(src,getintregister(list,OS_ADDR),0,sizeof(aint));
  1045. a_loadaddr_ref_reg(list,source,src.base);
  1046. end;
  1047. if (count<=4) and reference_is_reusable(dest) then
  1048. dst:=dest
  1049. else
  1050. begin
  1051. reference_reset_base(dst,getintregister(list,OS_ADDR),0,sizeof(aint));
  1052. a_loadaddr_ref_reg(list,dest,dst.base);
  1053. end;
  1054. { generate a loop }
  1055. if count>4 then
  1056. begin
  1057. countreg:=GetIntRegister(list,OS_INT);
  1058. tmpreg1:=GetIntRegister(list,OS_INT);
  1059. a_load_const_reg(list,OS_INT,count,countreg);
  1060. current_asmdata.getjumplabel(lab);
  1061. a_label(list, lab);
  1062. list.concat(taicpu.op_ref_reg(A_LD,src,tmpreg1));
  1063. list.concat(taicpu.op_reg_ref(A_ST,tmpreg1,dst));
  1064. list.concat(taicpu.op_reg_const_reg(A_ADD,src.base,4,src.base));
  1065. list.concat(taicpu.op_reg_const_reg(A_ADD,dst.base,4,dst.base));
  1066. list.concat(taicpu.op_reg_const_reg(A_SUBcc,countreg,1,countreg));
  1067. a_jmp_cond(list,OC_NE,lab);
  1068. len := len mod 4;
  1069. end;
  1070. { unrolled loop }
  1071. count:=len div 4;
  1072. if count>0 then
  1073. begin
  1074. tmpreg1:=GetIntRegister(list,OS_INT);
  1075. for count2 := 1 to count do
  1076. begin
  1077. list.concat(taicpu.op_ref_reg(A_LD,src,tmpreg1));
  1078. list.concat(taicpu.op_reg_ref(A_ST,tmpreg1,dst));
  1079. inc(src.offset,4);
  1080. inc(dst.offset,4);
  1081. end;
  1082. len := len mod 4;
  1083. end;
  1084. if (len and 4) <> 0 then
  1085. begin
  1086. hreg:=GetIntRegister(list,OS_INT);
  1087. a_load_ref_reg(list,OS_32,OS_32,src,hreg);
  1088. a_load_reg_ref(list,OS_32,OS_32,hreg,dst);
  1089. inc(src.offset,4);
  1090. inc(dst.offset,4);
  1091. end;
  1092. { copy the leftovers }
  1093. if (len and 2) <> 0 then
  1094. begin
  1095. hreg:=GetIntRegister(list,OS_INT);
  1096. a_load_ref_reg(list,OS_16,OS_16,src,hreg);
  1097. a_load_reg_ref(list,OS_16,OS_16,hreg,dst);
  1098. inc(src.offset,2);
  1099. inc(dst.offset,2);
  1100. end;
  1101. if (len and 1) <> 0 then
  1102. begin
  1103. hreg:=GetIntRegister(list,OS_INT);
  1104. a_load_ref_reg(list,OS_8,OS_8,src,hreg);
  1105. a_load_reg_ref(list,OS_8,OS_8,hreg,dst);
  1106. end;
  1107. end;
  1108. end;
  1109. procedure tcgsparc.g_concatcopy_unaligned(list : TAsmList;const source,dest : treference;len : tcgint);
  1110. var
  1111. src, dst: TReference;
  1112. tmpreg1,
  1113. countreg: TRegister;
  1114. i : aint;
  1115. lab: tasmlabel;
  1116. begin
  1117. if len>31 then
  1118. g_concatcopy_move(list,source,dest,len)
  1119. else
  1120. begin
  1121. reference_reset(src,source.alignment);
  1122. reference_reset(dst,dest.alignment);
  1123. { load the address of source into src.base }
  1124. src.base:=GetAddressRegister(list);
  1125. a_loadaddr_ref_reg(list,source,src.base);
  1126. { load the address of dest into dst.base }
  1127. dst.base:=GetAddressRegister(list);
  1128. a_loadaddr_ref_reg(list,dest,dst.base);
  1129. { generate a loop }
  1130. if len>4 then
  1131. begin
  1132. countreg:=GetIntRegister(list,OS_INT);
  1133. tmpreg1:=GetIntRegister(list,OS_INT);
  1134. a_load_const_reg(list,OS_INT,len,countreg);
  1135. current_asmdata.getjumplabel(lab);
  1136. a_label(list, lab);
  1137. list.concat(taicpu.op_ref_reg(A_LDUB,src,tmpreg1));
  1138. list.concat(taicpu.op_reg_ref(A_STB,tmpreg1,dst));
  1139. list.concat(taicpu.op_reg_const_reg(A_ADD,src.base,1,src.base));
  1140. list.concat(taicpu.op_reg_const_reg(A_ADD,dst.base,1,dst.base));
  1141. list.concat(taicpu.op_reg_const_reg(A_SUBcc,countreg,1,countreg));
  1142. a_jmp_cond(list,OC_NE,lab);
  1143. end
  1144. else
  1145. begin
  1146. { unrolled loop }
  1147. tmpreg1:=GetIntRegister(list,OS_INT);
  1148. for i:=1 to len do
  1149. begin
  1150. list.concat(taicpu.op_ref_reg(A_LDUB,src,tmpreg1));
  1151. list.concat(taicpu.op_reg_ref(A_STB,tmpreg1,dst));
  1152. inc(src.offset);
  1153. inc(dst.offset);
  1154. end;
  1155. end;
  1156. end;
  1157. end;
  1158. procedure tcgsparc.g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: tcgint);
  1159. begin
  1160. { This method is integrated into g_intf_wrapper and shouldn't be called separately }
  1161. InternalError(2013020102);
  1162. end;
  1163. procedure tcgsparc.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  1164. var
  1165. make_global : boolean;
  1166. href : treference;
  1167. hsym : tsym;
  1168. paraloc : pcgparalocation;
  1169. begin
  1170. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  1171. Internalerror(200006137);
  1172. if not assigned(procdef.struct) or
  1173. (procdef.procoptions*[po_classmethod, po_staticmethod,
  1174. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  1175. Internalerror(200006138);
  1176. if procdef.owner.symtabletype<>ObjectSymtable then
  1177. Internalerror(200109191);
  1178. make_global:=false;
  1179. if (not current_module.is_unit) or create_smartlink or
  1180. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  1181. make_global:=true;
  1182. if make_global then
  1183. List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0))
  1184. else
  1185. List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0));
  1186. { set param1 interface to self }
  1187. procdef.init_paraloc_info(callerside);
  1188. hsym:=tsym(procdef.parast.Find('self'));
  1189. if not(assigned(hsym) and
  1190. (hsym.typ=paravarsym)) then
  1191. internalerror(2010103101);
  1192. paraloc:=tparavarsym(hsym).paraloc[callerside].location;
  1193. if assigned(paraloc^.next) then
  1194. InternalError(2013020101);
  1195. case paraloc^.loc of
  1196. LOC_REGISTER:
  1197. begin
  1198. if ((ioffset>=simm13lo) and (ioffset<=simm13hi)) then
  1199. a_op_const_reg(list,OP_SUB,paraloc^.size,ioffset,paraloc^.register)
  1200. else
  1201. begin
  1202. a_load_const_reg(list,paraloc^.size,ioffset,NR_G1);
  1203. a_op_reg_reg(list,OP_SUB,paraloc^.size,NR_G1,paraloc^.register);
  1204. end;
  1205. end;
  1206. else
  1207. internalerror(2010103102);
  1208. end;
  1209. if (po_virtualmethod in procdef.procoptions) and
  1210. not is_objectpascal_helper(procdef.struct) then
  1211. begin
  1212. if (procdef.extnumber=$ffff) then
  1213. Internalerror(200006139);
  1214. { mov 0(%rdi),%rax ; load vmt}
  1215. reference_reset_base(href,paraloc^.register,0,sizeof(pint));
  1216. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_G1);
  1217. { jmp *vmtoffs(%eax) ; method offs }
  1218. reference_reset_base(href,NR_G1,tobjectdef(procdef.struct).vmtmethodoffset(procdef.extnumber),sizeof(pint));
  1219. list.concat(taicpu.op_ref_reg(A_LD,href,NR_G1));
  1220. list.concat(taicpu.op_reg(A_JMP,NR_G1));
  1221. { Delay slot }
  1222. list.Concat(TAiCpu.Op_none(A_NOP));
  1223. end
  1224. else
  1225. g_external_wrapper(list,procdef,procdef.mangledname);
  1226. List.concat(Tai_symbol_end.Createname(labelname));
  1227. end;
  1228. procedure tcgsparc.g_external_wrapper(list : TAsmList; procdef: tprocdef; const externalname: string);
  1229. begin
  1230. { CALL overwrites %o7 with its own address, we use delay slot to restore it. }
  1231. list.concat(taicpu.op_reg_reg(A_MOV,NR_O7,NR_G1));
  1232. list.concat(taicpu.op_sym(A_CALL,current_asmdata.RefAsmSymbol(externalname)));
  1233. list.concat(taicpu.op_reg_reg(A_MOV,NR_G1,NR_O7));
  1234. end;
  1235. procedure tcgsparc.g_stackpointer_alloc(list : TAsmList;localsize : longint);
  1236. begin
  1237. Comment(V_Error,'tcgsparc.g_stackpointer_alloc method not implemented');
  1238. end;
  1239. procedure tcgsparc.a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; size: TCGSize; src, dst: TRegister);
  1240. begin
  1241. Comment(V_Error,'tcgsparc.a_bit_scan_reg_reg method not implemented');
  1242. end;
  1243. {****************************************************************************
  1244. TCG64Sparc
  1245. ****************************************************************************}
  1246. procedure tcg64sparc.a_load64_reg_ref(list : TAsmList;reg : tregister64;const ref : treference);
  1247. var
  1248. tmpref: treference;
  1249. begin
  1250. { Override this function to prevent loading the reference twice }
  1251. tmpref:=ref;
  1252. cg.a_load_reg_ref(list,OS_32,OS_32,reg.reghi,tmpref);
  1253. inc(tmpref.offset,4);
  1254. cg.a_load_reg_ref(list,OS_32,OS_32,reg.reglo,tmpref);
  1255. end;
  1256. procedure tcg64sparc.a_load64_ref_reg(list : TAsmList;const ref : treference;reg : tregister64);
  1257. var
  1258. tmpref: treference;
  1259. begin
  1260. { Override this function to prevent loading the reference twice }
  1261. tmpref:=ref;
  1262. cg.a_load_ref_reg(list,OS_32,OS_32,tmpref,reg.reghi);
  1263. inc(tmpref.offset,4);
  1264. cg.a_load_ref_reg(list,OS_32,OS_32,tmpref,reg.reglo);
  1265. end;
  1266. procedure tcg64sparc.a_load64_ref_cgpara(list : TAsmList;const r : treference;const paraloc : tcgpara);
  1267. var
  1268. hreg64 : tregister64;
  1269. begin
  1270. { Override this function to prevent loading the reference twice.
  1271. Use here some extra registers, but those are optimized away by the RA }
  1272. hreg64.reglo:=cg.GetIntRegister(list,OS_32);
  1273. hreg64.reghi:=cg.GetIntRegister(list,OS_32);
  1274. a_load64_ref_reg(list,r,hreg64);
  1275. a_load64_reg_cgpara(list,hreg64,paraloc);
  1276. end;
  1277. procedure TCg64Sparc.get_64bit_ops(op:TOpCG;var op1,op2:TAsmOp;checkoverflow : boolean);
  1278. begin
  1279. case op of
  1280. OP_ADD :
  1281. begin
  1282. op1:=A_ADDCC;
  1283. if checkoverflow then
  1284. op2:=A_ADDXCC
  1285. else
  1286. op2:=A_ADDX;
  1287. end;
  1288. OP_SUB :
  1289. begin
  1290. op1:=A_SUBCC;
  1291. if checkoverflow then
  1292. op2:=A_SUBXCC
  1293. else
  1294. op2:=A_SUBX;
  1295. end;
  1296. OP_XOR :
  1297. begin
  1298. op1:=A_XOR;
  1299. op2:=A_XOR;
  1300. end;
  1301. OP_OR :
  1302. begin
  1303. op1:=A_OR;
  1304. op2:=A_OR;
  1305. end;
  1306. OP_AND :
  1307. begin
  1308. op1:=A_AND;
  1309. op2:=A_AND;
  1310. end;
  1311. else
  1312. internalerror(200203241);
  1313. end;
  1314. end;
  1315. procedure TCg64Sparc.a_op64_reg_reg(list:TAsmList;op:TOpCG;size : tcgsize;regsrc,regdst:TRegister64);
  1316. var
  1317. op1,op2 : TAsmOp;
  1318. begin
  1319. case op of
  1320. OP_NEG :
  1321. begin
  1322. { Use the simple code: y=0-z }
  1323. list.concat(taicpu.op_reg_reg_reg(A_SUBcc,NR_G0,regsrc.reglo,regdst.reglo));
  1324. list.concat(taicpu.op_reg_reg_reg(A_SUBX,NR_G0,regsrc.reghi,regdst.reghi));
  1325. exit;
  1326. end;
  1327. OP_NOT :
  1328. begin
  1329. list.concat(taicpu.op_reg_reg_reg(A_XNOR,regsrc.reglo,NR_G0,regdst.reglo));
  1330. list.concat(taicpu.op_reg_reg_reg(A_XNOR,regsrc.reghi,NR_G0,regdst.reghi));
  1331. exit;
  1332. end;
  1333. end;
  1334. get_64bit_ops(op,op1,op2,false);
  1335. list.concat(taicpu.op_reg_reg_reg(op1,regdst.reglo,regsrc.reglo,regdst.reglo));
  1336. list.concat(taicpu.op_reg_reg_reg(op2,regdst.reghi,regsrc.reghi,regdst.reghi));
  1337. end;
  1338. procedure TCg64Sparc.a_op64_const_reg(list:TAsmList;op:TOpCG;size : tcgsize;value:int64;regdst:TRegister64);
  1339. var
  1340. op1,op2:TAsmOp;
  1341. begin
  1342. case op of
  1343. OP_NEG,
  1344. OP_NOT :
  1345. internalerror(200306017);
  1346. end;
  1347. get_64bit_ops(op,op1,op2,false);
  1348. tcgsparc(cg).handle_reg_const_reg(list,op1,regdst.reglo,tcgint(lo(value)),regdst.reglo);
  1349. tcgsparc(cg).handle_reg_const_reg(list,op2,regdst.reghi,tcgint(hi(value)),regdst.reghi);
  1350. end;
  1351. procedure tcg64sparc.a_op64_const_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;value : int64; regsrc,regdst : tregister64);
  1352. var
  1353. l : tlocation;
  1354. begin
  1355. a_op64_const_reg_reg_checkoverflow(list,op,size,value,regsrc,regdst,false,l);
  1356. end;
  1357. procedure tcg64sparc.a_op64_reg_reg_reg(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1358. var
  1359. l : tlocation;
  1360. begin
  1361. a_op64_reg_reg_reg_checkoverflow(list,op,size,regsrc1,regsrc2,regdst,false,l);
  1362. end;
  1363. procedure tcg64sparc.a_op64_const_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1364. var
  1365. op1,op2:TAsmOp;
  1366. begin
  1367. case op of
  1368. OP_NEG,
  1369. OP_NOT :
  1370. internalerror(200306017);
  1371. end;
  1372. get_64bit_ops(op,op1,op2,setflags);
  1373. tcgsparc(cg).handle_reg_const_reg(list,op1,regsrc.reglo,tcgint(lo(value)),regdst.reglo);
  1374. tcgsparc(cg).handle_reg_const_reg(list,op2,regsrc.reghi,tcgint(hi(value)),regdst.reghi);
  1375. end;
  1376. procedure tcg64sparc.a_op64_reg_reg_reg_checkoverflow(list: TAsmList;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1377. var
  1378. op1,op2:TAsmOp;
  1379. begin
  1380. case op of
  1381. OP_NEG,
  1382. OP_NOT :
  1383. internalerror(200306017);
  1384. end;
  1385. get_64bit_ops(op,op1,op2,setflags);
  1386. list.concat(taicpu.op_reg_reg_reg(op1,regsrc2.reglo,regsrc1.reglo,regdst.reglo));
  1387. list.concat(taicpu.op_reg_reg_reg(op2,regsrc2.reghi,regsrc1.reghi,regdst.reghi));
  1388. end;
  1389. procedure create_codegen;
  1390. begin
  1391. cg:=TCgSparc.Create;
  1392. if target_info.system=system_sparc_linux then
  1393. TCgSparc(cg).use_unlimited_pic_mode:=true
  1394. else
  1395. TCgSparc(cg).use_unlimited_pic_mode:=false;
  1396. cg64:=TCg64Sparc.Create;
  1397. end;
  1398. end.