cgcpu.pas 48 KB

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