cgcpu.pas 47 KB

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