cgcpu.pas 47 KB

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