cgcpu.pas 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the code generator for the SPARC
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,
  23. cgbase,cgobj,cg64f32,
  24. aasmbase,aasmtai,aasmcpu,
  25. cpubase,cpuinfo,
  26. node,symconst,SymType,
  27. rgcpu;
  28. type
  29. TCgSparc=class(tcg)
  30. protected
  31. function IsSimpleRef(const ref:treference):boolean;
  32. public
  33. procedure init_register_allocators;override;
  34. procedure done_register_allocators;override;
  35. function getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;override;
  36. { sparc special, needed by cg64 }
  37. procedure handle_load_store(list:taasmoutput;isstore:boolean;op: tasmop;reg:tregister;ref: treference);
  38. procedure handle_reg_const_reg(list:taasmoutput;op:Tasmop;src:tregister;a:aint;dst:tregister);
  39. { parameter }
  40. procedure a_param_const(list:TAasmOutput;size:tcgsize;a:aint;const LocPara:TParaLocation);override;
  41. procedure a_param_ref(list:TAasmOutput;sz:tcgsize;const r:TReference;const LocPara:TParaLocation);override;
  42. procedure a_paramaddr_ref(list:TAasmOutput;const r:TReference;const LocPara:TParaLocation);override;
  43. procedure a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const locpara : tparalocation);override;
  44. procedure a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const locpara : tparalocation);override;
  45. procedure a_loadany_param_ref(list : taasmoutput;const locpara : tparalocation;const ref:treference;shuffle : pmmshuffle);override;
  46. procedure a_loadany_param_reg(list : taasmoutput;const locpara : tparalocation;const reg:tregister;shuffle : pmmshuffle);override;
  47. procedure a_call_name(list:TAasmOutput;const s:string);override;
  48. procedure a_call_reg(list:TAasmOutput;Reg:TRegister);override;
  49. { General purpose instructions }
  50. procedure a_op_const_reg(list:TAasmOutput;Op:TOpCG;size:tcgsize;a:aint;reg:TRegister);override;
  51. procedure a_op_reg_reg(list:TAasmOutput;Op:TOpCG;size:TCGSize;src, dst:TRegister);override;
  52. procedure a_op_const_reg_reg(list:TAasmOutput;op:TOpCg;size:tcgsize;a:aint;src, dst:tregister);override;
  53. procedure a_op_reg_reg_reg(list:TAasmOutput;op:TOpCg;size:tcgsize;src1, src2, dst:tregister);override;
  54. { move instructions }
  55. procedure a_load_const_reg(list:TAasmOutput;size:tcgsize;a:aint;reg:tregister);override;
  56. procedure a_load_const_ref(list:TAasmOutput;size:tcgsize;a:aint;const ref:TReference);override;
  57. procedure a_load_reg_ref(list:TAasmOutput;FromSize,ToSize:TCgSize;reg:TRegister;const ref:TReference);override;
  58. procedure a_load_ref_reg(list:TAasmOutput;FromSize,ToSize:TCgSize;const ref:TReference;reg:tregister);override;
  59. procedure a_load_reg_reg(list:TAasmOutput;FromSize,ToSize:TCgSize;reg1,reg2:tregister);override;
  60. procedure a_loadaddr_ref_reg(list:TAasmOutput;const ref:TReference;r:tregister);override;
  61. { fpu move instructions }
  62. procedure a_loadfpu_reg_reg(list:TAasmOutput;size:tcgsize;reg1, reg2:tregister);override;
  63. procedure a_loadfpu_ref_reg(list:TAasmOutput;size:tcgsize;const ref:TReference;reg:tregister);override;
  64. procedure a_loadfpu_reg_ref(list:TAasmOutput;size:tcgsize;reg:tregister;const ref:TReference);override;
  65. { comparison operations }
  66. procedure a_cmp_const_reg_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;a:aint;reg:tregister;l:tasmlabel);override;
  67. procedure a_cmp_reg_reg_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;reg1,reg2:tregister;l:tasmlabel);override;
  68. procedure a_jmp_always(List:TAasmOutput;l:TAsmLabel);override;
  69. procedure a_jmp_cond(list:TAasmOutput;cond:TOpCmp;l:tasmlabel);{ override;}
  70. procedure a_jmp_flags(list:TAasmOutput;const f:TResFlags;l:tasmlabel);override;
  71. procedure g_flags2reg(list:TAasmOutput;Size:TCgSize;const f:tresflags;reg:TRegister);override;
  72. procedure g_overflowCheck(List:TAasmOutput;const Loc:TLocation;def:TDef);override;
  73. procedure g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);override;
  74. procedure g_proc_exit(list : taasmoutput;parasize:longint;nostackframe:boolean);override;
  75. procedure g_restore_all_registers(list:TAasmOutput;const funcretparaloc:tparalocation);override;
  76. procedure g_restore_standard_registers(list:taasmoutput);override;
  77. procedure g_save_all_registers(list : taasmoutput);override;
  78. procedure g_save_standard_registers(list : taasmoutput);override;
  79. procedure g_concatcopy(list:TAasmOutput;const source,dest:TReference;len:aint;delsource,loadref:boolean);override;
  80. end;
  81. TCg64Sparc=class(tcg64f32)
  82. private
  83. procedure get_64bit_ops(op:TOpCG;var op1,op2:TAsmOp);
  84. public
  85. procedure a_op64_reg_reg(list:TAasmOutput;op:TOpCG;regsrc,regdst:TRegister64);override;
  86. procedure a_op64_const_reg(list:TAasmOutput;op:TOpCG;value:int64;regdst:TRegister64);override;
  87. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : int64;regsrc,regdst : tregister64);override;
  88. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);override;
  89. end;
  90. const
  91. TOpCG2AsmOp : array[topcg] of TAsmOp=(
  92. A_NONE,A_ADD,A_AND,A_UDIV,A_SDIV,A_UMUL,A_SMUL,A_NEG,A_NOT,A_OR,A_SRA,A_SLL,A_SRL,A_SUB,A_XOR
  93. );
  94. TOpCmp2AsmCond : array[topcmp] of TAsmCond=(C_NONE,
  95. C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A
  96. );
  97. implementation
  98. uses
  99. globals,verbose,systems,cutils,
  100. symdef,paramgr,
  101. tgobj,cpupi,cgutils;
  102. {****************************************************************************
  103. This is private property, keep out! :)
  104. ****************************************************************************}
  105. function TCgSparc.IsSimpleRef(const ref:treference):boolean;
  106. begin
  107. if (ref.base=NR_NO) and (ref.index<>NR_NO) then
  108. InternalError(2002100804);
  109. result :=not(assigned(ref.symbol))and
  110. (((ref.index = NR_NO) and
  111. (ref.offset >= simm13lo) and
  112. (ref.offset <= simm13hi)) or
  113. ((ref.index <> NR_NO) and
  114. (ref.offset = 0)));
  115. end;
  116. procedure tcgsparc.handle_load_store(list:taasmoutput;isstore:boolean;op: tasmop;reg:tregister;ref: treference);
  117. var
  118. tmpreg : tregister;
  119. tmpref : treference;
  120. begin
  121. tmpreg:=NR_NO;
  122. { Be sure to have a base register }
  123. if (ref.base=NR_NO) then
  124. begin
  125. ref.base:=ref.index;
  126. ref.index:=NR_NO;
  127. end;
  128. { When need to use SETHI, do it first }
  129. if assigned(ref.symbol) or
  130. (ref.offset<simm13lo) or
  131. (ref.offset>simm13hi) then
  132. begin
  133. tmpreg:=GetIntRegister(list,OS_INT);
  134. reference_reset(tmpref);
  135. tmpref.symbol:=ref.symbol;
  136. tmpref.offset:=ref.offset;
  137. tmpref.refaddr:=addr_hi;
  138. list.concat(taicpu.op_ref_reg(A_SETHI,tmpref,tmpreg));
  139. { Load the low part is left }
  140. {$warning TODO Maybe not needed to load symbol}
  141. tmpref.refaddr:=addr_lo;
  142. list.concat(taicpu.op_reg_ref_reg(A_OR,tmpreg,tmpref,tmpreg));
  143. { The offset and symbol are loaded, reset in reference }
  144. ref.offset:=0;
  145. ref.symbol:=nil;
  146. { Only an index register or offset is allowed }
  147. if tmpreg<>NR_NO then
  148. begin
  149. if (ref.index<>NR_NO) then
  150. begin
  151. list.concat(taicpu.op_reg_reg_reg(A_ADD,tmpreg,ref.index,tmpreg));
  152. ref.index:=tmpreg;
  153. end
  154. else
  155. begin
  156. if ref.base<>NR_NO then
  157. ref.index:=tmpreg
  158. else
  159. ref.base:=tmpreg;
  160. end;
  161. end;
  162. end;
  163. if (ref.base<>NR_NO) then
  164. begin
  165. if (ref.index<>NR_NO) and
  166. ((ref.offset<>0) or assigned(ref.symbol)) then
  167. begin
  168. if tmpreg=NR_NO then
  169. tmpreg:=GetIntRegister(list,OS_INT);
  170. list.concat(taicpu.op_reg_reg_reg(A_ADD,ref.base,ref.index,tmpreg));
  171. ref.base:=tmpreg;
  172. ref.index:=NR_NO;
  173. end;
  174. end;
  175. if isstore then
  176. list.concat(taicpu.op_reg_ref(op,reg,ref))
  177. else
  178. list.concat(taicpu.op_ref_reg(op,ref,reg));
  179. if (tmpreg<>NR_NO) then
  180. UnGetRegister(list,tmpreg);
  181. end;
  182. procedure tcgsparc.handle_reg_const_reg(list:taasmoutput;op:Tasmop;src:tregister;a:aint;dst:tregister);
  183. var
  184. tmpreg : tregister;
  185. begin
  186. if (a<simm13lo) or
  187. (a>simm13hi) then
  188. begin
  189. tmpreg:=GetIntRegister(list,OS_INT);
  190. a_load_const_reg(list,OS_INT,a,tmpreg);
  191. list.concat(taicpu.op_reg_reg_reg(op,src,tmpreg,dst));
  192. UnGetRegister(list,tmpreg);
  193. end
  194. else
  195. list.concat(taicpu.op_reg_const_reg(op,src,a,dst));
  196. end;
  197. {****************************************************************************
  198. Assembler code
  199. ****************************************************************************}
  200. procedure Tcgsparc.init_register_allocators;
  201. begin
  202. inherited init_register_allocators;
  203. rg[R_INTREGISTER]:=Trgcpu.create(R_INTREGISTER,R_SUBWHOLE,
  204. [RS_O0,RS_O1,RS_O2,RS_O3,RS_O4,RS_O5,
  205. RS_L0,RS_L1,RS_L2,RS_L3,RS_L4,RS_L5,RS_L6,RS_L7],
  206. first_int_imreg,[]);
  207. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBFS,
  208. [RS_F0,RS_F1,RS_F2,RS_F3,RS_F4,RS_F5,RS_F6,RS_F7,
  209. RS_F8,RS_F9,RS_F10,RS_F11,RS_F12,RS_F13,RS_F14,RS_F15,
  210. RS_F16,RS_F17,RS_F18,RS_F19,RS_F20,RS_F21,RS_F22,RS_F23,
  211. RS_F24,RS_F25,RS_F26,RS_F27,RS_F28,RS_F29,RS_F30,RS_F31],
  212. first_fpu_imreg,[]);
  213. end;
  214. procedure Tcgsparc.done_register_allocators;
  215. begin
  216. rg[R_INTREGISTER].free;
  217. rg[R_FPUREGISTER].free;
  218. inherited done_register_allocators;
  219. end;
  220. function tcgsparc.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  221. begin
  222. if size=OS_F64 then
  223. result:=rg[R_FPUREGISTER].getregister(list,R_SUBFD)
  224. else
  225. result:=rg[R_FPUREGISTER].getregister(list,R_SUBFS);
  226. end;
  227. procedure TCgSparc.a_param_const(list:TAasmOutput;size:tcgsize;a:aint;const LocPara:TParaLocation);
  228. var
  229. Ref:TReference;
  230. begin
  231. case locpara.loc of
  232. LOC_REGISTER,LOC_CREGISTER:
  233. a_load_const_reg(list,size,a,locpara.register);
  234. LOC_REFERENCE:
  235. begin
  236. { Code conventions need the parameters being allocated in %o6+92 }
  237. with LocPara.Reference do
  238. if(Index=NR_SP)and(Offset<Target_info.first_parm_offset) then
  239. InternalError(2002081104);
  240. reference_reset_base(ref,locpara.reference.index,locpara.reference.offset);
  241. a_load_const_ref(list,size,a,ref);
  242. end;
  243. else
  244. InternalError(2002122200);
  245. end;
  246. end;
  247. procedure TCgSparc.a_param_ref(list:TAasmOutput;sz:TCgSize;const r:TReference;const LocPara:TParaLocation);
  248. var
  249. ref: treference;
  250. tmpreg:TRegister;
  251. begin
  252. with LocPara do
  253. case loc of
  254. LOC_REGISTER,LOC_CREGISTER :
  255. a_load_ref_reg(list,sz,sz,r,Register);
  256. LOC_REFERENCE:
  257. begin
  258. { Code conventions need the parameters being allocated in %o6+92 }
  259. with LocPara.Reference do
  260. if(Index=NR_SP)and(Offset<Target_info.first_parm_offset) then
  261. InternalError(2002081104);
  262. reference_reset_base(ref,locpara.reference.index,locpara.reference.offset);
  263. tmpreg:=GetIntRegister(list,OS_INT);
  264. a_load_ref_reg(list,sz,sz,r,tmpreg);
  265. a_load_reg_ref(list,sz,sz,tmpreg,ref);
  266. UnGetRegister(list,tmpreg);
  267. end;
  268. else
  269. internalerror(2002081103);
  270. end;
  271. end;
  272. procedure TCgSparc.a_paramaddr_ref(list:TAasmOutput;const r:TReference;const LocPara:TParaLocation);
  273. var
  274. Ref:TReference;
  275. TmpReg:TRegister;
  276. begin
  277. case locpara.loc of
  278. LOC_REGISTER,LOC_CREGISTER:
  279. a_loadaddr_ref_reg(list,r,locpara.register);
  280. LOC_REFERENCE:
  281. begin
  282. reference_reset(ref);
  283. ref.base := locpara.reference.index;
  284. ref.offset := locpara.reference.offset;
  285. tmpreg:=GetAddressRegister(list);
  286. a_loadaddr_ref_reg(list,r,tmpreg);
  287. a_load_reg_ref(list,OS_ADDR,OS_ADDR,tmpreg,ref);
  288. UnGetRegister(list,tmpreg);
  289. end;
  290. else
  291. internalerror(2002080701);
  292. end;
  293. end;
  294. procedure tcgsparc.a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const locpara : tparalocation);
  295. var
  296. href : treference;
  297. begin
  298. tg.GetTemp(list,TCGSize2Size[size],tt_normal,href);
  299. a_loadfpu_reg_ref(list,size,r,href);
  300. a_paramfpu_ref(list,size,href,locpara);
  301. tg.Ungettemp(list,href);
  302. end;
  303. procedure tcgsparc.a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const locpara : tparalocation);
  304. var
  305. templocpara : tparalocation;
  306. begin
  307. { floats are pushed in the int registers }
  308. templocpara:=locpara;
  309. case locpara.size of
  310. OS_F32,OS_32 :
  311. begin
  312. templocpara.size:=OS_32;
  313. a_param_ref(list,OS_32,ref,templocpara);
  314. end;
  315. OS_F64,OS_64 :
  316. begin
  317. templocpara.size:=OS_64;
  318. cg64.a_param64_ref(list,ref,templocpara);
  319. end;
  320. else
  321. internalerror(200307021);
  322. end;
  323. end;
  324. procedure tcgsparc.a_loadany_param_ref(list : taasmoutput;const locpara : tparalocation;const ref:treference;shuffle : pmmshuffle);
  325. var
  326. href,
  327. tempref : treference;
  328. templocpara : tparalocation;
  329. begin
  330. { Load floats like ints }
  331. templocpara:=locpara;
  332. case locpara.size of
  333. OS_F32 :
  334. templocpara.size:=OS_32;
  335. OS_F64 :
  336. templocpara.size:=OS_64;
  337. end;
  338. { Word 0 is in register, word 1 is in reference }
  339. if (templocpara.loc=LOC_REFERENCE) and (templocpara.low_in_reg) then
  340. begin
  341. tempref:=ref;
  342. cg.a_load_reg_ref(list,OS_INT,OS_INT,templocpara.register,tempref);
  343. inc(tempref.offset,4);
  344. reference_reset_base(href,templocpara.reference.index,templocpara.reference.offset);
  345. cg.a_load_ref_ref(list,OS_INT,OS_INT,href,tempref);
  346. end
  347. else
  348. inherited a_loadany_param_ref(list,templocpara,ref,shuffle);
  349. end;
  350. procedure tcgsparc.a_loadany_param_reg(list : taasmoutput;const locpara : tparalocation;const reg:tregister;shuffle : pmmshuffle);
  351. var
  352. href : treference;
  353. begin
  354. { Word 0 is in register, word 1 is in reference, not
  355. possible to load it in 1 register }
  356. if (locpara.loc=LOC_REFERENCE) and (locpara.low_in_reg) then
  357. internalerror(200307011);
  358. { Float load use a temp reference }
  359. if locpara.size in [OS_F32,OS_F64] then
  360. begin
  361. tg.GetTemp(list,TCGSize2Size[locpara.size],tt_normal,href);
  362. a_loadany_param_ref(list,locpara,href,shuffle);
  363. a_loadfpu_ref_reg(list,locpara.size,href,reg);
  364. tg.Ungettemp(list,href);
  365. end
  366. else
  367. inherited a_loadany_param_reg(list,locpara,reg,shuffle);
  368. end;
  369. procedure TCgSparc.a_call_name(list:TAasmOutput;const s:string);
  370. begin
  371. list.concat(taicpu.op_sym(A_CALL,objectlibrary.newasmsymbol(s,AB_EXTERNAL,AT_FUNCTION)));
  372. { Delay slot }
  373. list.concat(taicpu.op_none(A_NOP));
  374. end;
  375. procedure TCgSparc.a_call_reg(list:TAasmOutput;Reg:TRegister);
  376. begin
  377. list.concat(taicpu.op_reg(A_CALL,reg));
  378. { Delay slot }
  379. list.concat(taicpu.op_none(A_NOP));
  380. end;
  381. {********************** load instructions ********************}
  382. procedure TCgSparc.a_load_const_reg(list : TAasmOutput;size : TCGSize;a : aint;reg : TRegister);
  383. begin
  384. { we don't use the set instruction here because it could be evalutated to two
  385. instructions which would cause problems with the delay slot (FK) }
  386. if (a=0) then
  387. list.concat(taicpu.op_reg(A_CLR,reg))
  388. { sethi allows to set the upper 22 bit, so we'll take full advantage of it }
  389. else if (a and aint($1fff))=0 then
  390. list.concat(taicpu.op_const_reg(A_SETHI,a shr 10,reg))
  391. else if (a>=simm13lo) and (a<=simm13hi) then
  392. list.concat(taicpu.op_const_reg(A_MOV,a,reg))
  393. else
  394. begin
  395. list.concat(taicpu.op_const_reg(A_SETHI,a shr 10,reg));
  396. list.concat(taicpu.op_reg_const_reg(A_OR,reg,a and aint($3ff),reg));
  397. end;
  398. end;
  399. procedure TCgSparc.a_load_const_ref(list : TAasmOutput;size : tcgsize;a : aint;const ref : TReference);
  400. begin
  401. if a=0 then
  402. a_load_reg_ref(list,size,size,NR_G0,ref)
  403. else
  404. inherited a_load_const_ref(list,size,a,ref);
  405. end;
  406. procedure TCgSparc.a_load_reg_ref(list:TAasmOutput;FromSize,ToSize:TCGSize;reg:tregister;const Ref:TReference);
  407. var
  408. op:tasmop;
  409. begin
  410. case ToSize of
  411. { signed integer registers }
  412. OS_8,
  413. OS_S8:
  414. Op:=A_STB;
  415. OS_16,
  416. OS_S16:
  417. Op:=A_STH;
  418. OS_32,
  419. OS_S32:
  420. Op:=A_ST;
  421. else
  422. InternalError(2002122100);
  423. end;
  424. handle_load_store(list,true,op,reg,ref);
  425. end;
  426. procedure TCgSparc.a_load_ref_reg(list:TAasmOutput;FromSize,ToSize:TCgSize;const ref:TReference;reg:tregister);
  427. var
  428. op:tasmop;
  429. begin
  430. case Fromsize of
  431. { signed integer registers }
  432. OS_S8:
  433. Op:=A_LDSB;{Load Signed Byte}
  434. OS_8:
  435. Op:=A_LDUB;{Load Unsigned Byte}
  436. OS_S16:
  437. Op:=A_LDSH;{Load Signed Halfword}
  438. OS_16:
  439. Op:=A_LDUH;{Load Unsigned Halfword}
  440. OS_S32,
  441. OS_32:
  442. Op:=A_LD;{Load Word}
  443. OS_S64,
  444. OS_64:
  445. Op:=A_LDD;{Load a Long Word}
  446. else
  447. InternalError(2002122101);
  448. end;
  449. handle_load_store(list,false,op,reg,ref);
  450. end;
  451. procedure TCgSparc.a_load_reg_reg(list:TAasmOutput;fromsize,tosize:tcgsize;reg1,reg2:tregister);
  452. begin
  453. if (tcgsize2size[tosize]<tcgsize2size[fromsize]) or
  454. (
  455. (tcgsize2size[tosize] = tcgsize2size[fromsize]) and
  456. (tosize <> fromsize) and
  457. not(fromsize in [OS_32,OS_S32])
  458. ) then
  459. begin
  460. {$warning TODO Sign extension}
  461. case tosize of
  462. OS_8,OS_S8:
  463. a_op_const_reg_reg(list,OP_AND,tosize,$ff,reg1,reg2);
  464. OS_16,OS_S16:
  465. a_op_const_reg_reg(list,OP_AND,tosize,$ffff,reg1,reg2);
  466. OS_32,OS_S32:
  467. begin
  468. if reg1<>reg2 then
  469. list.Concat(taicpu.op_reg_reg(A_MOV,reg1,reg2));
  470. end;
  471. else
  472. internalerror(2002090901);
  473. end;
  474. end
  475. else
  476. begin
  477. { same size, only a register mov required }
  478. if reg1<>reg2 then
  479. list.Concat(taicpu.op_reg_reg(A_MOV,reg1,reg2));
  480. end;
  481. end;
  482. procedure TCgSparc.a_loadaddr_ref_reg(list : TAasmOutput;const ref : TReference;r : tregister);
  483. var
  484. tmpref : treference;
  485. hreg : tregister;
  486. begin
  487. if (ref.base=NR_NO) and (ref.index<>NR_NO) then
  488. internalerror(200306171);
  489. { At least big offset (need SETHI), maybe base and maybe index }
  490. if assigned(ref.symbol) or
  491. (ref.offset<simm13lo) or
  492. (ref.offset>simm13hi) then
  493. begin
  494. if (ref.base<>r) and (ref.index<>r) then
  495. hreg:=r
  496. else
  497. hreg:=GetAddressRegister(list);
  498. reference_reset(tmpref);
  499. tmpref.symbol := ref.symbol;
  500. tmpref.offset := ref.offset;
  501. tmpref.refaddr := addr_hi;
  502. list.concat(taicpu.op_ref_reg(A_SETHI,tmpref,hreg));
  503. { Only the low part is left }
  504. tmpref.refaddr:=addr_lo;
  505. list.concat(taicpu.op_reg_ref_reg(A_OR,hreg,tmpref,hreg));
  506. if ref.base<>NR_NO then
  507. begin
  508. if ref.index<>NR_NO then
  509. begin
  510. list.concat(taicpu.op_reg_reg_reg(A_ADD,hreg,ref.base,hreg));
  511. list.concat(taicpu.op_reg_reg_reg(A_ADD,hreg,ref.index,r));
  512. end
  513. else
  514. list.concat(taicpu.op_reg_reg_reg(A_ADD,hreg,ref.base,r));
  515. end
  516. else
  517. begin
  518. if hreg<>r then
  519. list.Concat(taicpu.op_reg_reg(A_MOV,hreg,r));
  520. end;
  521. if hreg<>r then
  522. UnGetRegister(list,hreg);
  523. end
  524. else
  525. { At least small offset, maybe base and maybe index }
  526. if ref.offset<>0 then
  527. begin
  528. if ref.base<>NR_NO then
  529. begin
  530. if ref.index<>NR_NO then
  531. begin
  532. if (ref.base<>r) and (ref.index<>r) then
  533. hreg:=r
  534. else
  535. hreg:=GetAddressRegister(list);
  536. list.concat(taicpu.op_reg_const_reg(A_ADD,ref.base,ref.offset,hreg));
  537. list.concat(taicpu.op_reg_reg_reg(A_ADD,hreg,ref.index,r));
  538. if hreg<>r then
  539. UnGetRegister(list,hreg);
  540. end
  541. else
  542. list.concat(taicpu.op_reg_const_reg(A_ADD,ref.base,ref.offset,r));
  543. end
  544. else
  545. list.concat(taicpu.op_const_reg(A_MOV,ref.offset,r));
  546. end
  547. else
  548. { Both base and index }
  549. if ref.index<>NR_NO then
  550. list.concat(taicpu.op_reg_reg_reg(A_ADD,ref.base,ref.index,r))
  551. else
  552. { Only base }
  553. if ref.base<>NR_NO then
  554. a_load_reg_reg(list,OS_INT,OS_INT,ref.base,r)
  555. else
  556. internalerror(200306172);
  557. end;
  558. procedure TCgSparc.a_loadfpu_reg_reg(list:TAasmOutput;size:tcgsize;reg1, reg2:tregister);
  559. const
  560. FpuMovInstr : Array[OS_F32..OS_F64] of TAsmOp =
  561. (A_FMOVS,A_FMOVD);
  562. begin
  563. if reg1<>reg2 then
  564. list.concat(taicpu.op_reg_reg(fpumovinstr[size],reg1,reg2));
  565. end;
  566. procedure TCgSparc.a_loadfpu_ref_reg(list:TAasmOutput;size:tcgsize;const ref:TReference;reg:tregister);
  567. const
  568. FpuLoadInstr : Array[OS_F32..OS_F64] of TAsmOp =
  569. (A_LDF,A_LDDF);
  570. begin
  571. { several functions call this procedure with OS_32 or OS_64 }
  572. { so this makes life easier (FK) }
  573. case size of
  574. OS_32,OS_F32:
  575. size:=OS_F32;
  576. OS_64,OS_F64,OS_C64:
  577. size:=OS_F64;
  578. else
  579. internalerror(200201121);
  580. end;
  581. handle_load_store(list,false,fpuloadinstr[size],reg,ref);
  582. end;
  583. procedure TCgSparc.a_loadfpu_reg_ref(list:TAasmOutput;size:tcgsize;reg:tregister;const ref:TReference);
  584. const
  585. FpuLoadInstr : Array[OS_F32..OS_F64] of TAsmOp =
  586. (A_STF,A_STDF);
  587. begin
  588. { several functions call this procedure with OS_32 or OS_64 }
  589. { so this makes life easier (FK) }
  590. case size of
  591. OS_32,OS_F32:
  592. size:=OS_F32;
  593. OS_64,OS_F64,OS_C64:
  594. size:=OS_F64;
  595. else
  596. internalerror(200201121);
  597. end;
  598. handle_load_store(list,true,fpuloadinstr[size],reg,ref);
  599. end;
  600. procedure TCgSparc.a_op_const_reg(list:TAasmOutput;Op:TOpCG;size:tcgsize;a:aint;reg:TRegister);
  601. begin
  602. if Op in [OP_NEG,OP_NOT] then
  603. internalerror(200306011);
  604. if (a=0) then
  605. list.concat(taicpu.op_reg_reg_reg(TOpCG2AsmOp[op],reg,NR_G0,reg))
  606. else
  607. handle_reg_const_reg(list,TOpCG2AsmOp[op],reg,a,reg);
  608. end;
  609. procedure TCgSparc.a_op_reg_reg(list:TAasmOutput;Op:TOpCG;size:TCGSize;src, dst:TRegister);
  610. begin
  611. Case Op of
  612. OP_NEG,
  613. OP_NOT:
  614. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],src,dst));
  615. else
  616. list.concat(taicpu.op_reg_reg_reg(TOpCG2AsmOp[op],dst,src,dst));
  617. end;
  618. end;
  619. procedure TCgSparc.a_op_const_reg_reg(list:TAasmOutput;op:TOpCg;size:tcgsize;a:aint;src, dst:tregister);
  620. var
  621. power : longInt;
  622. begin
  623. case op of
  624. OP_IMUL :
  625. begin
  626. if not(cs_check_overflow in aktlocalswitches) and
  627. ispowerof2(a,power) then
  628. begin
  629. { can be done with a shift }
  630. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  631. exit;
  632. end;
  633. end;
  634. OP_SUB,
  635. OP_ADD :
  636. begin
  637. if (a=0) then
  638. begin
  639. a_load_reg_reg(list,size,size,src,dst);
  640. exit;
  641. end;
  642. end;
  643. end;
  644. handle_reg_const_reg(list,TOpCG2AsmOp[op],src,a,dst);
  645. end;
  646. procedure TCgSparc.a_op_reg_reg_reg(list:TAasmOutput;op:TOpCg;size:tcgsize;src1, src2, dst:tregister);
  647. begin
  648. list.concat(taicpu.op_reg_reg_reg(TOpCG2AsmOp[op],src2,src1,dst));
  649. end;
  650. {*************** compare instructructions ****************}
  651. procedure TCgSparc.a_cmp_const_reg_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;a:aint;reg:tregister;l:tasmlabel);
  652. begin
  653. if (a=0) then
  654. list.concat(taicpu.op_reg_reg_reg(A_SUBcc,reg,NR_G0,NR_G0))
  655. else
  656. handle_reg_const_reg(list,A_SUBcc,reg,a,NR_G0);
  657. a_jmp_cond(list,cmp_op,l);
  658. end;
  659. procedure TCgSparc.a_cmp_reg_reg_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;reg1,reg2:tregister;l:tasmlabel);
  660. begin
  661. list.concat(taicpu.op_reg_reg_reg(A_SUBcc,reg2,reg1,NR_G0));
  662. a_jmp_cond(list,cmp_op,l);
  663. end;
  664. procedure TCgSparc.a_jmp_always(List:TAasmOutput;l:TAsmLabel);
  665. begin
  666. List.Concat(TAiCpu.op_sym(A_BA,objectlibrary.newasmsymbol(l.name,AB_EXTERNAL,AT_FUNCTION)));
  667. { Delay slot }
  668. list.Concat(TAiCpu.Op_none(A_NOP));
  669. end;
  670. procedure TCgSparc.a_jmp_cond(list:TAasmOutput;cond:TOpCmp;l:TAsmLabel);
  671. var
  672. ai:TAiCpu;
  673. begin
  674. ai:=TAiCpu.Op_sym(A_Bxx,l);
  675. ai.SetCondition(TOpCmp2AsmCond[cond]);
  676. list.Concat(ai);
  677. { Delay slot }
  678. list.Concat(TAiCpu.Op_none(A_NOP));
  679. end;
  680. procedure TCgSparc.a_jmp_flags(list:TAasmOutput;const f:TResFlags;l:tasmlabel);
  681. var
  682. ai : taicpu;
  683. op : tasmop;
  684. begin
  685. if f in [F_FE,F_FNE,F_FG,F_FL,F_FGE,F_FLE] then
  686. op:=A_FBxx
  687. else
  688. op:=A_Bxx;
  689. ai := Taicpu.op_sym(op,l);
  690. ai.SetCondition(flags_to_cond(f));
  691. list.Concat(ai);
  692. { Delay slot }
  693. list.Concat(TAiCpu.Op_none(A_NOP));
  694. end;
  695. procedure TCgSparc.g_flags2reg(list:TAasmOutput;Size:TCgSize;const f:tresflags;reg:TRegister);
  696. var
  697. hl : tasmlabel;
  698. begin
  699. objectlibrary.getlabel(hl);
  700. a_load_const_reg(list,size,1,reg);
  701. a_jmp_flags(list,f,hl);
  702. a_load_const_reg(list,size,0,reg);
  703. a_label(list,hl);
  704. end;
  705. procedure TCgSparc.g_overflowCheck(List:TAasmOutput;const Loc:TLocation;def:TDef);
  706. var
  707. hl : tasmlabel;
  708. begin
  709. if not(cs_check_overflow in aktlocalswitches) then
  710. exit;
  711. objectlibrary.getlabel(hl);
  712. if not((def.deftype=pointerdef)or
  713. ((def.deftype=orddef)and
  714. (torddef(def).typ in [u64bit,u16bit,u32bit,u8bit,uchar,bool8bit,bool16bit,bool32bit]))) then
  715. begin
  716. //r.enum:=R_CR7;
  717. //list.concat(taicpu.op_reg(A_MCRXR,r));
  718. //a_jmp_cond(list,A_Bxx,C_OV,hl)
  719. a_jmp_always(list,hl)
  720. end
  721. else
  722. a_jmp_cond(list,OC_AE,hl);
  723. a_call_name(list,'FPC_OVERFLOW');
  724. a_label(list,hl);
  725. end;
  726. { *********** entry/exit code and address loading ************ }
  727. procedure TCgSparc.g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);
  728. begin
  729. if nostackframe then
  730. exit;
  731. { Althogh the SPARC architecture require only word alignment, software
  732. convention and the operating system require every stack frame to be double word
  733. aligned }
  734. LocalSize:=align(LocalSize,8);
  735. { Execute the SAVE instruction to get a new register window and create a new
  736. stack frame. In the "SAVE %i6,size,%i6" the first %i6 is related to the state
  737. before execution of the SAVE instrucion so it is the caller %i6, when the %i6
  738. after execution of that instruction is the called function stack pointer}
  739. { constant can be 13 bit signed, since it's negative, size can be max. 4096 }
  740. if LocalSize>4096 then
  741. begin
  742. a_load_const_reg(list,OS_ADDR,-LocalSize,NR_G1);
  743. list.concat(Taicpu.Op_reg_reg_reg(A_SAVE,NR_STACK_POINTER_REG,NR_G1,NR_STACK_POINTER_REG));
  744. end
  745. else
  746. list.concat(Taicpu.Op_reg_const_reg(A_SAVE,NR_STACK_POINTER_REG,-LocalSize,NR_STACK_POINTER_REG));
  747. end;
  748. procedure TCgSparc.g_restore_all_registers(list:TaasmOutput;const funcretparaloc:tparalocation);
  749. begin
  750. { The sparc port uses the sparc standard calling convetions so this function has no used }
  751. end;
  752. procedure TCgSparc.g_restore_standard_registers(list:taasmoutput);
  753. begin
  754. { The sparc port uses the sparc standard calling convetions so this function has no used }
  755. end;
  756. procedure TCgSparc.g_proc_exit(list : taasmoutput;parasize:longint;nostackframe:boolean);
  757. begin
  758. if nostackframe then
  759. begin
  760. { Here we need to use RETL instead of RET so it uses %o7 }
  761. list.concat(Taicpu.op_none(A_RETL));
  762. list.concat(Taicpu.op_none(A_NOP))
  763. end
  764. else
  765. begin
  766. { We use trivial restore in the delay slot of the JMPL instruction, as we
  767. already set result onto %i0 }
  768. list.concat(Taicpu.op_none(A_RET));
  769. list.concat(Taicpu.op_none(A_RESTORE));
  770. end;
  771. end;
  772. procedure TCgSparc.g_save_all_registers(list : taasmoutput);
  773. begin
  774. { The sparc port uses the sparc standard calling convetions so this function has no used }
  775. end;
  776. procedure TCgSparc.g_save_standard_registers(list : taasmoutput);
  777. begin
  778. { The sparc port uses the sparc standard calling convetions so this function has no used }
  779. end;
  780. { ************* concatcopy ************ }
  781. procedure TCgSparc.g_concatcopy(list:taasmoutput;const source,dest:treference;len:aint;delsource,loadref:boolean);
  782. var
  783. tmpreg1,
  784. hreg,
  785. countreg: TRegister;
  786. src, dst: TReference;
  787. lab: tasmlabel;
  788. count, count2: aint;
  789. orgsrc, orgdst: boolean;
  790. begin
  791. if len>high(longint) then
  792. internalerror(2002072704);
  793. reference_reset(src);
  794. reference_reset(dst);
  795. { load the address of source into src.base }
  796. if loadref then
  797. begin
  798. src.base:=GetAddressRegister(list);
  799. a_load_ref_reg(list,OS_32,OS_32,source,src.base);
  800. orgsrc := false;
  801. end
  802. else
  803. begin
  804. src.base:=GetAddressRegister(list);
  805. a_loadaddr_ref_reg(list,source,src.base);
  806. orgsrc := false;
  807. end;
  808. if not orgsrc and delsource then
  809. reference_release(list,source);
  810. { load the address of dest into dst.base }
  811. dst.base:=GetAddressRegister(list);
  812. a_loadaddr_ref_reg(list,dest,dst.base);
  813. orgdst := false;
  814. { generate a loop }
  815. count:=len div 4;
  816. if count>4 then
  817. begin
  818. { the offsets are zero after the a_loadaddress_ref_reg and just }
  819. { have to be set to 8. I put an Inc there so debugging may be }
  820. { easier (should offset be different from zero here, it will be }
  821. { easy to notice in the generated assembler }
  822. countreg:=GetIntRegister(list,OS_INT);
  823. tmpreg1:=GetIntRegister(list,OS_INT);
  824. a_load_const_reg(list,OS_INT,count,countreg);
  825. { explicitely allocate R_O0 since it can be used safely here }
  826. { (for holding date that's being copied) }
  827. objectlibrary.getlabel(lab);
  828. a_label(list, lab);
  829. list.concat(taicpu.op_ref_reg(A_LD,src,tmpreg1));
  830. list.concat(taicpu.op_reg_ref(A_ST,tmpreg1,dst));
  831. list.concat(taicpu.op_reg_const_reg(A_ADD,src.base,4,src.base));
  832. list.concat(taicpu.op_reg_const_reg(A_ADD,dst.base,4,dst.base));
  833. list.concat(taicpu.op_reg_const_reg(A_SUBcc,countreg,1,countreg));
  834. a_jmp_cond(list,OC_NE,lab);
  835. list.concat(taicpu.op_none(A_NOP));
  836. { keep the registers alive }
  837. list.concat(taicpu.op_reg_reg(A_MOV,countreg,countreg));
  838. list.concat(taicpu.op_reg_reg(A_MOV,src.base,src.base));
  839. list.concat(taicpu.op_reg_reg(A_MOV,dst.base,dst.base));
  840. UnGetRegister(list,countreg);
  841. len := len mod 4;
  842. end;
  843. { unrolled loop }
  844. count:=len div 4;
  845. if count>0 then
  846. begin
  847. tmpreg1:=GetIntRegister(list,OS_INT);
  848. for count2 := 1 to count do
  849. begin
  850. list.concat(taicpu.op_ref_reg(A_LD,src,tmpreg1));
  851. list.concat(taicpu.op_reg_ref(A_ST,tmpreg1,dst));
  852. inc(src.offset,4);
  853. inc(dst.offset,4);
  854. end;
  855. len := len mod 4;
  856. end;
  857. if (len and 4) <> 0 then
  858. begin
  859. hreg:=GetIntRegister(list,OS_INT);
  860. a_load_ref_reg(list,OS_32,OS_32,src,hreg);
  861. a_load_reg_ref(list,OS_32,OS_32,hreg,dst);
  862. inc(src.offset,4);
  863. inc(dst.offset,4);
  864. UnGetRegister(list,hreg);
  865. end;
  866. { copy the leftovers }
  867. if (len and 2) <> 0 then
  868. begin
  869. hreg:=GetIntRegister(list,OS_INT);
  870. a_load_ref_reg(list,OS_16,OS_16,src,hreg);
  871. a_load_reg_ref(list,OS_16,OS_16,hreg,dst);
  872. inc(src.offset,2);
  873. inc(dst.offset,2);
  874. UnGetRegister(list,hreg);
  875. end;
  876. if (len and 1) <> 0 then
  877. begin
  878. hreg:=GetIntRegister(list,OS_INT);
  879. a_load_ref_reg(list,OS_8,OS_8,src,hreg);
  880. a_load_reg_ref(list,OS_8,OS_8,hreg,dst);
  881. UnGetRegister(list,hreg);
  882. end;
  883. if orgsrc then
  884. begin
  885. if delsource then
  886. reference_release(list,source);
  887. end
  888. else
  889. UnGetRegister(list,src.base);
  890. if not orgdst then
  891. UnGetRegister(list,dst.base);
  892. end;
  893. {****************************************************************************
  894. TCG64Sparc
  895. ****************************************************************************}
  896. procedure TCg64Sparc.get_64bit_ops(op:TOpCG;var op1,op2:TAsmOp);
  897. begin
  898. case op of
  899. OP_ADD :
  900. begin
  901. op1:=A_ADDCC;
  902. op2:=A_ADDX;
  903. end;
  904. OP_SUB :
  905. begin
  906. op1:=A_SUBCC;
  907. op2:=A_SUBX;
  908. end;
  909. OP_XOR :
  910. begin
  911. op1:=A_XOR;
  912. op2:=A_XOR;
  913. end;
  914. OP_OR :
  915. begin
  916. op1:=A_OR;
  917. op2:=A_OR;
  918. end;
  919. OP_AND :
  920. begin
  921. op1:=A_AND;
  922. op2:=A_AND;
  923. end;
  924. else
  925. internalerror(200203241);
  926. end;
  927. end;
  928. procedure TCg64Sparc.a_op64_reg_reg(list:TAasmOutput;op:TOpCG;regsrc,regdst:TRegister64);
  929. var
  930. op1,op2 : TAsmOp;
  931. begin
  932. case op of
  933. OP_NEG :
  934. begin
  935. list.concat(taicpu.op_reg_reg_reg(A_XNOR,NR_G0,regsrc.reghi,regdst.reghi));
  936. list.concat(taicpu.op_reg_reg_reg(A_SUBcc,NR_G0,regsrc.reglo,regdst.reglo));
  937. list.concat(taicpu.op_reg_const_reg(A_ADDX,regdst.reglo,-1,regdst.reglo));
  938. exit;
  939. end;
  940. OP_NOT :
  941. begin
  942. list.concat(taicpu.op_reg_reg_reg(A_XNOR,regsrc.reglo,NR_G0,regdst.reglo));
  943. list.concat(taicpu.op_reg_reg_reg(A_XNOR,regsrc.reghi,NR_G0,regdst.reghi));
  944. exit;
  945. end;
  946. end;
  947. get_64bit_ops(op,op1,op2);
  948. list.concat(taicpu.op_reg_reg_reg(op1,regdst.reglo,regsrc.reglo,regdst.reglo));
  949. list.concat(taicpu.op_reg_reg_reg(op2,regdst.reghi,regsrc.reghi,regdst.reghi));
  950. end;
  951. procedure TCg64Sparc.a_op64_const_reg(list:TAasmOutput;op:TOpCG;value:int64;regdst:TRegister64);
  952. var
  953. op1,op2:TAsmOp;
  954. begin
  955. case op of
  956. OP_NEG,
  957. OP_NOT :
  958. internalerror(200306017);
  959. end;
  960. get_64bit_ops(op,op1,op2);
  961. tcgsparc(cg).handle_reg_const_reg(list,op1,regdst.reglo,aint(lo(value)),regdst.reglo);
  962. tcgsparc(cg).handle_reg_const_reg(list,op1,regdst.reghi,aint(hi(value)),regdst.reghi);
  963. end;
  964. procedure tcg64sparc.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : int64; regsrc,regdst : tregister64);
  965. var
  966. op1,op2:TAsmOp;
  967. begin
  968. case op of
  969. OP_NEG,
  970. OP_NOT :
  971. internalerror(200306017);
  972. end;
  973. get_64bit_ops(op,op1,op2);
  974. tcgsparc(cg).handle_reg_const_reg(list,op1,regsrc.reglo,aint(lo(value)),regdst.reglo);
  975. tcgsparc(cg).handle_reg_const_reg(list,op1,regsrc.reghi,aint(hi(value)),regdst.reghi);
  976. end;
  977. procedure tcg64sparc.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  978. var
  979. op1,op2:TAsmOp;
  980. begin
  981. case op of
  982. OP_NEG,
  983. OP_NOT :
  984. internalerror(200306017);
  985. end;
  986. get_64bit_ops(op,op1,op2);
  987. list.concat(taicpu.op_reg_reg_reg(op1,regsrc2.reglo,regsrc1.reglo,regdst.reglo));
  988. list.concat(taicpu.op_reg_reg_reg(op2,regsrc2.reghi,regsrc1.reghi,regdst.reghi));
  989. end;
  990. begin
  991. cg:=TCgSparc.Create;
  992. cg64:=TCg64Sparc.Create;
  993. end.
  994. {
  995. $Log$
  996. Revision 1.83 2004-06-16 20:07:10 florian
  997. * dwarf branch merged
  998. Revision 1.82.2.9 2004/06/02 19:05:16 peter
  999. * use a_load_const_reg to load const
  1000. Revision 1.82.2.8 2004/06/02 16:07:40 peter
  1001. * implement op64_reg_reg_reg
  1002. Revision 1.82.2.7 2004/05/31 22:07:54 peter
  1003. * don't use float in concatcopy
  1004. Revision 1.82.2.6 2004/05/30 17:54:14 florian
  1005. + implemented cmp64bit
  1006. * started to fix spilling
  1007. * fixed int64 sub partially
  1008. Revision 1.82.2.5 2004/05/30 17:07:07 peter
  1009. * fix shl shr for sparc
  1010. Revision 1.82.2.4 2004/05/30 13:45:35 florian
  1011. * fixed unsigned division
  1012. Revision 1.82.2.3 2004/05/29 21:57:22 florian
  1013. * fixed subroutines which local sizes > 4096
  1014. * fixed concatcopy
  1015. Revision 1.82.2.2 2004/05/27 23:35:30 peter
  1016. * concatcopy can't use floats because of alignment
  1017. Revision 1.82.2.1 2004/05/11 21:06:51 peter
  1018. * sparc compiler fixed
  1019. Revision 1.82 2004/03/12 15:42:18 mazen
  1020. * fixed conditions upon IEs for inlined function call stack frames
  1021. Revision 1.81 2004/03/12 08:18:11 mazen
  1022. - revert '../' from include path
  1023. Revision 1.80 2004/03/02 00:36:33 olle
  1024. * big transformation of Tai_[const_]Symbol.Create[data]name*
  1025. Revision 1.79 2004/02/27 13:28:28 mazen
  1026. * symaddr ==> refaddr to follow the rest of compiler changes
  1027. Revision 1.78 2004/02/04 22:01:13 peter
  1028. * first try to get cpupara working for x86_64
  1029. Revision 1.77 2004/01/12 22:11:38 peter
  1030. * use localalign info for alignment for locals and temps
  1031. * sparc fpu flags branching added
  1032. * moved powerpc copy_valye_openarray to generic
  1033. Revision 1.76 2004/01/12 16:39:40 peter
  1034. * sparc updates, mostly float related
  1035. Revision 1.75 2003/12/26 14:02:30 peter
  1036. * sparc updates
  1037. * use registertype in spill_register
  1038. Revision 1.74 2003/12/19 14:38:03 mazen
  1039. * new TRegister definition applied
  1040. Revision 1.73 2003/12/09 09:44:22 mazen
  1041. + added uses_registers overloaded method for sparc
  1042. Revision 1.72 2003/10/29 15:18:33 mazen
  1043. + added fake MM Registers support because of generic code need it.
  1044. Revision 1.71 2003/10/24 15:20:37 peter
  1045. * added more register functions
  1046. Revision 1.70 2003/10/24 11:14:46 mazen
  1047. * rg.[un]GetRegister* ==> [Un]Get[*]Register
  1048. Revision 1.69 2003/10/01 20:34:49 peter
  1049. * procinfo unit contains tprocinfo
  1050. * cginfo renamed to cgbase
  1051. * moved cgmessage to verbose
  1052. * fixed ppc and sparc compiles
  1053. Revision 1.68 2003/09/14 21:35:52 peter
  1054. * flags2reg fixed
  1055. * fixed 64bit not
  1056. Revision 1.67 2003/09/14 19:19:04 peter
  1057. * updates for new ra
  1058. Revision 1.66 2003/09/03 15:55:01 peter
  1059. * NEWRA branch merged
  1060. Revision 1.65.2.1 2003/09/01 21:02:55 peter
  1061. * sparc updates for new tregister
  1062. Revision 1.65 2003/07/08 21:24:59 peter
  1063. * sparc fixes
  1064. Revision 1.64 2003/07/06 22:10:13 peter
  1065. * operand order of cmp fixed
  1066. Revision 1.63 2003/07/06 17:58:22 peter
  1067. * framepointer fixes for sparc
  1068. * parent framepointer code more generic
  1069. Revision 1.62 2003/07/03 21:09:53 peter
  1070. * delay slot NOPs and comments added
  1071. * a_loadaddr_ref_reg fixed and optimized to reuse passed register
  1072. if it is not used by the ref
  1073. Revision 1.61 2003/07/02 22:18:04 peter
  1074. * paraloc splitted in callerparaloc,calleeparaloc
  1075. * sparc calling convention updates
  1076. Revision 1.60 2003/06/17 16:35:56 peter
  1077. * a_loadaddr_ref_reg fixed
  1078. Revision 1.59 2003/06/13 21:19:32 peter
  1079. * current_procdef removed, use current_procinfo.procdef instead
  1080. Revision 1.58 2003/06/12 16:43:07 peter
  1081. * newra compiles for sparc
  1082. Revision 1.57 2003/06/04 20:59:37 mazen
  1083. + added size of destination in code gen methods
  1084. + making g_overflowcheck declaration same as
  1085. ancestor's method declaration
  1086. Revision 1.56 2003/06/01 21:38:06 peter
  1087. * getregisterfpu size parameter added
  1088. * op_const_reg size parameter added
  1089. * sparc updates
  1090. Revision 1.55 2003/06/01 01:04:35 peter
  1091. * reference fixes
  1092. Revision 1.54 2003/05/31 01:00:51 peter
  1093. * register fixes
  1094. Revision 1.53 2003/05/30 23:57:08 peter
  1095. * more sparc cleanup
  1096. * accumulator removed, splitted in function_return_reg (called) and
  1097. function_result_reg (caller)
  1098. Revision 1.52 2003/05/28 23:18:31 florian
  1099. * started to fix and clean up the sparc port
  1100. Revision 1.51 2003/05/26 22:04:57 mazen
  1101. * added 64 bit value support to fix a problem in RTL
  1102. Revision 1.50 2003/05/23 22:33:48 florian
  1103. * fix some small flaws which prevent sparc linux system unit from compiling
  1104. * some reformatting done
  1105. Revision 1.49 2003/05/22 16:11:22 florian
  1106. * fixed sparc compilation partially
  1107. Revision 1.48 2003/05/07 15:04:30 mazen
  1108. * invalid genrated code for CASE statement fixed
  1109. Revision 1.47 2003/05/06 20:25:20 mazen
  1110. * Invalid genrated code : A_JMPL changed to A_BA
  1111. Revision 1.46 2003/05/06 15:02:40 mazen
  1112. * fixed a bug in a_load_const_reg related to max 13bit value limit
  1113. for immediat value ==> use of A_SETHI for greater values
  1114. Revision 1.45 2003/04/29 11:58:21 mazen
  1115. * fixed bug of output generated assembler for a_cmp_const_ref_label
  1116. Revision 1.44 2003/04/28 09:44:42 mazen
  1117. + NOP after conditional jump instruction to prevent delay slot execution
  1118. Revision 1.43 2003/04/27 11:21:36 peter
  1119. * aktprocdef renamed to current_procinfo.procdef
  1120. * procinfo renamed to current_procinfo
  1121. * procinfo will now be stored in current_module so it can be
  1122. cleaned up properly
  1123. * gen_main_procsym changed to create_main_proc and release_main_proc
  1124. to also generate a tprocinfo structure
  1125. * fixed unit implicit initfinal
  1126. Revision 1.42 2003/03/16 20:45:45 mazen
  1127. * fixing an LD operation without refernce in loading address parameters
  1128. Revision 1.41 2003/03/10 21:59:54 mazen
  1129. * fixing index overflow in handling new registers arrays.
  1130. Revision 1.40 2003/02/25 21:41:44 mazen
  1131. * code re-aligned 2 spaces
  1132. Revision 1.39 2003/02/19 22:00:16 daniel
  1133. * Code generator converted to new register notation
  1134. - Horribily outdated todo.txt removed
  1135. Revision 1.38 2003/02/18 22:00:20 mazen
  1136. * asm condition generation modified by TAiCpu.SetCondition
  1137. Revision 1.37 2003/02/05 21:48:34 mazen
  1138. * fixing run time errors related to unimplemented abstract methods in CG
  1139. + giving empty emplementations for some RTL functions
  1140. Revision 1.36 2003/01/22 22:30:03 mazen
  1141. - internal errors rmoved from a_loar_reg_reg when reg sizes differs from 32
  1142. Revision 1.35 2003/01/20 22:21:36 mazen
  1143. * many stuff related to RTL fixed
  1144. Revision 1.34 2003/01/08 18:43:58 daniel
  1145. * Tregister changed into a record
  1146. Revision 1.33 2003/01/07 22:03:40 mazen
  1147. * adding unequaln node support to sparc compiler
  1148. Revision 1.32 2003/01/06 22:51:47 mazen
  1149. * fixing bugs related to load_reg_ref
  1150. Revision 1.31 2003/01/05 21:32:35 mazen
  1151. * fixing several bugs compiling the RTL
  1152. Revision 1.30 2003/01/05 13:36:53 florian
  1153. * x86-64 compiles
  1154. + very basic support for float128 type (x86-64 only)
  1155. Revision 1.29 2002/12/25 20:59:49 mazen
  1156. - many emitXXX removed from cga.pas in order to remove that file.
  1157. Revision 1.28 2002/12/22 19:26:31 mazen
  1158. * many internal errors related to unimplemented nodes are fixed
  1159. Revision 1.27 2002/12/21 23:21:47 mazen
  1160. + added support for the shift nodes
  1161. + added debug output on screen with -an command line option
  1162. Revision 1.26 2002/11/25 19:21:49 mazen
  1163. * fixed support of nSparcInline
  1164. Revision 1.25 2002/11/25 17:43:28 peter
  1165. * splitted defbase in defutil,symutil,defcmp
  1166. * merged isconvertable and is_equal into compare_defs(_ext)
  1167. * made operator search faster by walking the list only once
  1168. Revision 1.24 2002/11/17 17:49:09 mazen
  1169. + return_result_reg and FUNCTION_RESULT_REG are now used, in all plateforms, to pass functions result between called function and its caller. See the explanation of each one
  1170. Revision 1.23 2002/11/10 19:07:46 mazen
  1171. * SPARC calling mechanism almost OK (as in GCC./mppcsparc )
  1172. Revision 1.22 2002/11/06 11:31:24 mazen
  1173. * op_reg_reg_reg don't need any more a TOpSize parameter
  1174. Revision 1.21 2002/11/05 16:15:00 mazen
  1175. *** empty log message ***
  1176. Revision 1.20 2002/11/03 20:22:40 mazen
  1177. * parameter handling updated
  1178. Revision 1.19 2002/10/28 20:59:17 mazen
  1179. * TOpSize values changed S_L --> S_SW
  1180. Revision 1.18 2002/10/22 13:43:01 mazen
  1181. - cga.pas redueced to an empty unit
  1182. Revision 1.17 2002/10/20 19:01:38 mazen
  1183. + op_raddr_reg and op_caddr_reg added to fix functions prologue
  1184. Revision 1.16 2002/10/13 21:46:07 mazen
  1185. * assembler output format fixed
  1186. Revision 1.15 2002/10/11 13:35:14 mazen
  1187. *** empty log message ***
  1188. Revision 1.14 2002/10/10 19:57:51 mazen
  1189. * Just to update repsitory
  1190. Revision 1.13 2002/10/10 15:10:39 mazen
  1191. * Internal error fixed, but usually i386 parameter model used
  1192. Revision 1.12 2002/10/08 17:17:03 mazen
  1193. *** empty log message ***
  1194. Revision 1.11 2002/10/07 20:33:04 mazen
  1195. word alignement modified in g_stack_frame
  1196. Revision 1.10 2002/10/04 21:57:42 mazen
  1197. * register allocation for parameters now done in cpupara
  1198. Revision 1.9 2002/10/02 22:20:28 mazen
  1199. + out registers allocator for the first 6 scalar parameters which must be passed into %o0..%o5
  1200. Revision 1.8 2002/10/01 21:35:58 mazen
  1201. + procedures exiting prologue added and stack frame now restored in the delay slot of the return (JMPL) instruction
  1202. Revision 1.7 2002/10/01 21:06:29 mazen
  1203. attinst.inc --> strinst.inc
  1204. Revision 1.6 2002/10/01 17:41:50 florian
  1205. * fixed log and id
  1206. }