cgcpu.pas 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. {*****************************************************************************}
  2. { File : cgcpu.pas }
  3. { Author : Mazen NEIFER }
  4. { Project : Free Pascal Compiler (FPC) }
  5. { Creation date : 2002\04\26 }
  6. { Last modification date : 2002\08\20 }
  7. { Licence : GPL }
  8. { Bug report : [email protected] }
  9. {*****************************************************************************}
  10. {
  11. $Id$
  12. Copyright (c) 1998-2000 by Florian Klaempfl
  13. This program is free software;you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation;either version 2 of the License, or
  16. (at your option) any later version.
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY;without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. You should have received a copy of the GNU General Public License
  22. along with this program;if not, write to the Free Software
  23. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. ****************************************************************************}
  25. UNIT cgcpu;
  26. {This unit implements the code generator for the SPARC architecture}
  27. {$INCLUDE fpcdefs.inc}
  28. INTERFACE
  29. USES
  30. cginfo,cgbase,cgobj,cg64f32,
  31. aasmbase,aasmtai,aasmcpu,
  32. cpubase,cpuinfo,cpupara,
  33. node,symconst;
  34. TYPE
  35. tcgSPARC=CLASS(tcg)
  36. FreeParamRegSet:TRegisterSet;
  37. {This method is used to pass a parameter, which is located in a register, to a
  38. routine. It should give the parameter to the routine, as required by the
  39. specific processor ABI. It is overriden for each CPU target.
  40. Size : is the size of the operand in the register
  41. r : is the register source of the operand
  42. nr : is number of that parameter in the routine parameters list starting
  43. from one from left to right}
  44. procedure a_param_reg(list:TAasmOutput;size:tcgsize;r:tregister;const LocPara:TParaLocation);override;
  45. PROCEDURE a_param_const(list:TAasmOutput;size:tcgsize;a:aword;CONST LocPara:TParaLocation);override;
  46. procedure a_param_ref(list:TAasmOutput;size:tcgsize;CONST r:TReference;CONST LocPara:TParaLocation);override;
  47. PROCEDURE a_paramaddr_ref(list:TAasmOutput;CONST r:TReference;CONST LocPara:TParaLocation);override;
  48. PROCEDURE a_call_name(list:TAasmOutput;CONST s:string);override;
  49. PROCEDURE a_call_ref(list:TAasmOutput;CONST ref:TReference);override;
  50. PROCEDURE a_op_const_reg(list:TAasmOutput;Op:TOpCG;a:AWord;reg:TRegister);override;
  51. PROCEDURE a_op_const_ref(list:TAasmOutput;Op:TOpCG;size:TCGSize;a:AWord;CONST ref:TReference);override;
  52. PROCEDURE a_op_reg_reg(list:TAasmOutput;Op:TOpCG;size:TCGSize;src, dst:TRegister);override;
  53. PROCEDURE a_op_ref_reg(list:TAasmOutput;Op:TOpCG;size:TCGSize;CONST ref:TReference;reg:TRegister);override;
  54. PROCEDURE a_op_reg_ref(list:TAasmOutput;Op:TOpCG;size:TCGSize;reg:TRegister;CONST ref:TReference);override;
  55. PROCEDURE a_op_const_reg_reg(list:TAasmOutput;op:TOpCg;size:tcgsize;a:aword;src, dst:tregister);override;
  56. PROCEDURE a_op_reg_reg_reg(list:TAasmOutput;op:TOpCg;size:tcgsize;src1, src2, dst:tregister);override;
  57. { move instructions }
  58. PROCEDURE a_load_const_reg(list:TAasmOutput;size:tcgsize;a:aword;reg:tregister);override;
  59. PROCEDURE a_load_const_ref(list:TAasmOutput;size:tcgsize;a:aword;CONST ref:TReference);override;
  60. PROCEDURE a_load_reg_ref(list:TAasmOutput;size:tcgsize;reg:tregister;CONST ref:TReference);override;
  61. PROCEDURE a_load_ref_reg(list:TAasmOutput;size:tcgsize;CONST ref:TReference;reg:tregister);override;
  62. PROCEDURE a_load_reg_reg(list:TAasmOutput;fromsize,size:tcgsize;reg1,reg2:tregister);override;
  63. PROCEDURE a_loadaddr_ref_reg(list:TAasmOutput;CONST ref:TReference;r:tregister);override;
  64. { fpu move instructions }
  65. PROCEDURE a_loadfpu_reg_reg(list:TAasmOutput;reg1, reg2:tregister);override;
  66. PROCEDURE a_loadfpu_ref_reg(list:TAasmOutput;size:tcgsize;CONST ref:TReference;reg:tregister);override;
  67. PROCEDURE a_loadfpu_reg_ref(list:TAasmOutput;size:tcgsize;reg:tregister;CONST ref:TReference);override;
  68. { vector register move instructions }
  69. PROCEDURE a_loadmm_reg_reg(list:TAasmOutput;reg1, reg2:tregister);override;
  70. PROCEDURE a_loadmm_ref_reg(list:TAasmOutput;CONST ref:TReference;reg:tregister);override;
  71. PROCEDURE a_loadmm_reg_ref(list:TAasmOutput;reg:tregister;CONST ref:TReference);override;
  72. PROCEDURE a_parammm_reg(list:TAasmOutput;reg:tregister);override;
  73. { comparison operations }
  74. PROCEDURE a_cmp_const_reg_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;a:aword;reg:tregister;l:tasmlabel);override;
  75. PROCEDURE a_cmp_const_ref_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;a:aword;CONST ref:TReference;l:tasmlabel);override;
  76. PROCEDURE a_cmp_reg_reg_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;reg1,reg2:tregister;l:tasmlabel);override;
  77. PROCEDURE a_cmp_ref_reg_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;CONST ref:TReference;reg:tregister;l:tasmlabel);override;
  78. PROCEDURE a_jmp_cond(list:TAasmOutput;cond:TOpCmp;l:tasmlabel);{ override;}
  79. PROCEDURE a_jmp_flags(list:TAasmOutput;CONST f:TResFlags;l:tasmlabel);override;
  80. PROCEDURE g_flags2reg(list:TAasmOutput;Size:TCgSize;CONST f:tresflags;reg:TRegister);override;
  81. procedure g_stackframe_entry(list:TAasmOutput;localsize:LongInt);override;
  82. procedure g_restore_frame_pointer(list:TAasmOutput);override;
  83. procedure g_return_from_proc(list:TAasmOutput;parasize:aword);override;
  84. PROCEDURE g_concatcopy(list:TAasmOutput;CONST source,dest:TReference;len:aword;delsource,loadref:boolean);override;
  85. class function reg_cgsize(CONST reg:tregister):tcgsize;override;
  86. PRIVATE
  87. PROCEDURE sizes2load(s1:tcgsize;s2:topsize;var op:tasmop;var s3:topsize);
  88. PROCEDURE floatload(list:TAasmOutput;t:tcgsize;CONST ref:TReference);
  89. PROCEDURE floatstore(list:TAasmOutput;t:tcgsize;CONST ref:TReference);
  90. PROCEDURE floatloadops(t:tcgsize;var op:tasmop;var s:topsize);
  91. PROCEDURE floatstoreops(t:tcgsize;var op:tasmop;var s:topsize);
  92. END;
  93. TCg64fSPARC=class(tcg64f32)
  94. PROCEDURE a_op64_ref_reg(list:TAasmOutput;op:TOpCG;CONST ref:TReference;reg:TRegister64);override;
  95. PROCEDURE a_op64_reg_reg(list:TAasmOutput;op:TOpCG;regsrc,regdst:TRegister64);override;
  96. PROCEDURE a_op64_const_reg(list:TAasmOutput;op:TOpCG;value:qWord;regdst:TRegister64);override;
  97. PROCEDURE a_op64_const_ref(list:TAasmOutput;op:TOpCG;value:qWord;CONST ref:TReference);override;
  98. PROCEDURE get_64bit_ops(op:TOpCG;var op1,op2:TAsmOp);
  99. END;
  100. CONST
  101. TOpCG2AsmOp:ARRAY[topcg]OF TAsmOp=(A_NONE,A_ADD,A_AND,A_UDIV,A_SDIV,A_UMUL, A_SMUL, A_NEG,A_NOT,A_OR,A_not,A_not,A_not,A_SUB,A_XOR);
  102. TOpCmp2AsmCond:ARRAY[topcmp]OF TAsmCond=(C_NONE,C_E,C_G,C_L,C_GE,C_LE,C_NE,C_BE,C_B,C_AE,C_A);
  103. TCGSize2OpSize:ARRAY[tcgsize]OF TOpSize=(S_NO,S_B,S_W,S_L,S_L,S_B,S_W,S_L,S_L,S_FS,S_FL,S_FX,S_IQ,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_NO);
  104. IMPLEMENTATION
  105. USES
  106. globtype,globals,verbose,systems,cutils,
  107. symdef,symsym,defbase,paramgr,
  108. rgobj,tgobj,rgcpu;
  109. {function GetFreeParamReg(var FreeParamRegSet:TRegisterSet):TRegister;
  110. begin
  111. if FreeParamRegSet=[]
  112. then
  113. exit(R_NONE);
  114. GetFreeParamReg:=R_O0;
  115. repeat
  116. GetFreeParamReg:=Succ(GetFreeParamReg);
  117. until GetFreeParamReg in FreeParamRegSet;
  118. Exclude(FreeParamRegSet,GetFreeParamReg);
  119. end;
  120. constructor tcgSPARC.Create;
  121. begin
  122. inherited Create;
  123. FreeParamRegSet:=[R_O0..R_O5];
  124. end;}
  125. { we implement the following routines because otherwise we can't }
  126. { instantiate the class since it's abstract }
  127. PROCEDURE tcgSPARC.a_param_reg(list:TAasmOutput;size:tcgsize;r:tregister;CONST LocPara:TParaLocation);
  128. BEGIN
  129. IF(Size<>OS_32)AND(Size<>OS_S32)
  130. THEN
  131. InternalError(2002032212);
  132. List.Concat(taicpu.op_reg(A_LD,S_L,r));
  133. END;
  134. PROCEDURE tcgSPARC.a_param_const(list:TAasmOutput;size:tcgsize;a:aword;CONST LocPara:TParaLocation);
  135. BEGIN
  136. IF(Size<>OS_32)AND(Size<>OS_S32)
  137. THEN
  138. InternalError(2002032213);
  139. List.Concat(taicpu.op_const(A_LD,S_L,a));
  140. END;
  141. procedure tcgSPARC.a_param_ref(list:TAasmOutput;size:tcgsize;const r:TReference;const LocPara:TParaLocation);
  142. var
  143. ref: treference;
  144. tmpreg:TRegister;
  145. begin
  146. if Size<>OS_32
  147. then
  148. InternalError(2002100400);
  149. case locpara.loc of
  150. LOC_REGISTER,LOC_CREGISTER:
  151. a_load_ref_reg(list,size,r,locpara.register);
  152. LOC_REFERENCE:
  153. begin
  154. reference_reset(ref);
  155. ref.base:=locpara.reference.index;
  156. ref.offset:=locpara.reference.offset;
  157. tmpreg := get_scratch_reg_int(list);
  158. a_load_ref_reg(list,size,r,tmpreg);
  159. a_load_reg_ref(list,size,tmpreg,ref);
  160. free_scratch_reg(list,tmpreg);
  161. end;
  162. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  163. case size of
  164. OS_32:
  165. a_loadfpu_ref_reg(list,OS_F32,r,locpara.register);
  166. OS_64:
  167. a_loadfpu_ref_reg(list,OS_F64,r,locpara.register);
  168. else
  169. internalerror(2002072801);
  170. end;
  171. else
  172. internalerror(2002081103);
  173. end;
  174. if locpara.sp_fixup<>0
  175. then
  176. internalerror(2002081104);
  177. end;
  178. PROCEDURE tcgSPARC.a_paramaddr_ref(list:TAasmOutput;CONST r:TReference;CONST LocPara:TParaLocation);
  179. VAR
  180. tmpreg:TRegister;
  181. BEGIN
  182. IF r.segment<>R_NO
  183. THEN
  184. CGMessage(cg_e_cant_use_far_pointer_there);
  185. IF(r.base=R_NO)AND(r.index=R_NO)
  186. THEN
  187. list.concat(Taicpu.Op_sym_ofs(A_LD,S_L,r.symbol,r.offset))
  188. ELSE IF(r.base=R_NO)AND(r.index<>R_NO)AND
  189. (r.offset=0)AND(r.scalefactor=0)AND(r.symbol=nil)
  190. THEN
  191. list.concat(Taicpu.Op_reg(A_LD,S_L,r.index))
  192. ELSE IF(r.base<>R_NO)AND(r.index=R_NO)AND
  193. (r.offset=0)AND(r.symbol=nil)
  194. THEN
  195. list.concat(Taicpu.Op_reg(A_LD,S_L,r.base))
  196. ELSE
  197. BEGIN
  198. tmpreg:=get_scratch_reg_address(list);
  199. a_loadaddr_ref_reg(list,r,tmpreg);
  200. list.concat(taicpu.op_reg(A_LD,S_L,tmpreg));
  201. free_scratch_reg(list,tmpreg);
  202. END;
  203. END;
  204. PROCEDURE tcgSPARC.a_call_name(list:TAasmOutput;CONST s:string);
  205. BEGIN
  206. WITH List,objectlibrary DO
  207. BEGIN
  208. concat(taicpu.op_sym(A_CALL,S_NO,newasmsymbol(s)));
  209. concat(taicpu.op_none(A_NOP,S_NO));
  210. END;
  211. END;
  212. PROCEDURE tcgSPARC.a_call_ref(list:TAasmOutput;CONST ref:TReference);
  213. BEGIN
  214. list.concat(taicpu.op_ref(A_CALL,S_NO,ref));
  215. list.concat(taicpu.op_none(A_NOP,S_NO));
  216. END;
  217. {********************** load instructions ********************}
  218. PROCEDURE tcgSPARC.a_load_const_reg(list:TAasmOutput;size:TCGSize;a:aword;reg:TRegister);
  219. BEGIN
  220. WITH List DO
  221. IF a<>0
  222. THEN{R_G0 is usually set to zero, so we use it}
  223. Concat(taicpu.op_reg_const_reg(A_OR,TCGSize2OpSize[size],R_G0,a,reg))
  224. ELSE{The is no A_MOV in sparc, that's why we use A_OR with help of R_G0}
  225. Concat(taicpu.op_reg_reg_reg(A_OR,TCGSize2OpSize[size],R_G0,R_G0,reg));
  226. END;
  227. PROCEDURE tcgSPARC.a_load_const_ref(list:TAasmOutput;size:tcgsize;a:aword;CONST ref:TReference);
  228. BEGIN
  229. WITH List DO
  230. IF a=0
  231. THEN
  232. Concat(taicpu.op_reg_ref(A_ST,TCGSize2OpSize[size],R_G0,ref))
  233. ELSE
  234. BEGIN
  235. a_load_const_reg(list,size,a,R_G1);
  236. list.concat(taicpu.op_reg_ref(A_ST,TCGSize2OpSize[size],R_G1,ref));
  237. END;
  238. END;
  239. PROCEDURE tcgSPARC.a_load_reg_ref(list:TAasmOutput;size:TCGSize;reg:tregister;CONST ref:TReference);
  240. BEGIN
  241. list.concat(taicpu.op_reg_ref(A_LD,TCGSize2OpSize[size],reg,ref));
  242. END;
  243. procedure tcgSPARC.a_load_ref_reg(list:TAasmOutput;size:tcgsize;const ref:TReference;reg:tregister);
  244. var
  245. op:tasmop;
  246. s:topsize;
  247. begin
  248. sizes2load(size,S_L,op,s);
  249. list.concat(taicpu.op_ref_reg(op,s,ref,reg));
  250. end;
  251. PROCEDURE tcgSPARC.a_load_reg_reg(list:TAasmOutput;fromsize,size:tcgsize;reg1,reg2:tregister);
  252. var
  253. op:tasmop;
  254. s:topsize;
  255. begin
  256. sizes2load(size,S_L,op,s);
  257. if ((reg1) = (reg2)) then
  258. begin
  259. { "mov reg1, reg1" doesn't make sense }
  260. if op = A_NONE then
  261. exit;
  262. { optimize movzx with "and ffff,<reg>" operation }
  263. //if (op = A_NONEZX) then
  264. begin
  265. case size of
  266. OS_8:
  267. begin
  268. list.concat(taicpu.op_const_reg(A_AND,S_L,255,reg2));
  269. exit;
  270. end;
  271. OS_16:
  272. begin
  273. list.concat(taicpu.op_const_reg(A_AND,S_L,65535,reg2));
  274. exit;
  275. end;
  276. end;
  277. end;
  278. end;
  279. list.concat(taicpu.op_reg_reg(op,s,reg1,reg2));
  280. end;
  281. { all fpu load routines expect that R_ST[0-7] means an fpu regvar and }
  282. { R_ST means "the current value at the top of the fpu stack" (JM) }
  283. PROCEDURE tcgSPARC.a_loadfpu_reg_reg(list:TAasmOutput;reg1, reg2:tregister);
  284. begin
  285. if NOT (reg1 IN [R_F0..R_F31]) then
  286. begin
  287. list.concat(taicpu.op_reg(A_NONE,S_NO,
  288. trgcpu(rg).correct_fpuregister(reg1,trgcpu(rg).fpuvaroffset)));
  289. inc(trgcpu(rg).fpuvaroffset);
  290. end;
  291. if NOT (reg2 IN [R_F0..R_F31]) then
  292. begin
  293. list.concat(taicpu.op_reg(A_JMPL,S_NO,
  294. trgcpu(rg).correct_fpuregister(reg2,trgcpu(rg).fpuvaroffset)));
  295. dec(trgcpu(rg).fpuvaroffset);
  296. end;
  297. end;
  298. PROCEDURE tcgSPARC.a_loadfpu_ref_reg(list:TAasmOutput;size:tcgsize;CONST ref:TReference;reg:tregister);
  299. begin
  300. floatload(list,size,ref);
  301. { if (reg <> R_ST) then
  302. a_loadfpu_reg_reg(list,R_ST,reg);}
  303. end;
  304. PROCEDURE tcgSPARC.a_loadfpu_reg_ref(list:TAasmOutput;size:tcgsize;reg:tregister;CONST ref:TReference);
  305. begin
  306. { if reg <> R_ST then
  307. a_loadfpu_reg_reg(list,reg,R_ST);}
  308. floatstore(list,size,ref);
  309. end;
  310. PROCEDURE tcgSPARC.a_loadmm_reg_reg(list:TAasmOutput;reg1, reg2:tregister);
  311. begin
  312. // list.concat(taicpu.op_reg_reg(A_NONEQ,S_NO,reg1,reg2));
  313. end;
  314. PROCEDURE tcgSPARC.a_loadmm_ref_reg(list:TAasmOutput;CONST ref:TReference;reg:tregister);
  315. begin
  316. // list.concat(taicpu.op_ref_reg(A_NONEQ,S_NO,ref,reg));
  317. end;
  318. PROCEDURE tcgSPARC.a_loadmm_reg_ref(list:TAasmOutput;reg:tregister;CONST ref:TReference);
  319. begin
  320. // list.concat(taicpu.op_reg_ref(A_NONEQ,S_NO,reg,ref));
  321. end;
  322. PROCEDURE tcgSPARC.a_parammm_reg(list:TAasmOutput;reg:tregister);
  323. VAR
  324. href:TReference;
  325. BEGIN
  326. // list.concat(taicpu.op_const_reg(A_SUB,S_L,8,R_RSP));
  327. // reference_reset_base(href,R_ESP,0);
  328. // list.concat(taicpu.op_reg_ref(A_NONEQ,S_NO,reg,href));
  329. END;
  330. PROCEDURE tcgSPARC.a_op_const_reg(list:TAasmOutput;Op:TOpCG;a:AWord;reg:TRegister);
  331. var
  332. opcode:tasmop;
  333. power:LongInt;
  334. begin
  335. (* Case Op of
  336. OP_DIV, OP_IDIV:
  337. Begin
  338. if ispowerof2(a,power) then
  339. begin
  340. case op of
  341. OP_DIV:
  342. opcode := A_SHR;
  343. OP_IDIV:
  344. opcode := A_SAR;
  345. end;
  346. list.concat(taicpu.op_const_reg(opcode,S_L,power,
  347. reg));
  348. exit;
  349. end;
  350. { the rest should be handled specifically in the code }
  351. { generator because of the silly register usage restraints }
  352. internalerror(200109224);
  353. End;
  354. OP_MUL,OP_IMUL:
  355. begin
  356. if not(cs_check_overflow in aktlocalswitches) and
  357. ispowerof2(a,power) then
  358. begin
  359. list.concat(taicpu.op_const_reg(A_SHL,S_L,power,
  360. reg));
  361. exit;
  362. end;
  363. if op = OP_IMUL then
  364. list.concat(taicpu.op_const_reg(A_IMUL,S_L,
  365. a,reg))
  366. else
  367. { OP_MUL should be handled specifically in the code }
  368. { generator because of the silly register usage restraints }
  369. internalerror(200109225);
  370. end;
  371. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  372. if not(cs_check_overflow in aktlocalswitches) and
  373. (a = 1) and
  374. (op in [OP_ADD,OP_SUB]) then
  375. if op = OP_ADD then
  376. list.concat(taicpu.op_reg(A_INC,S_L,reg))
  377. else
  378. list.concat(taicpu.op_reg(A_DEC,S_L,reg))
  379. else if (a = 0) then
  380. if (op <> OP_AND) then
  381. exit
  382. else
  383. list.concat(taicpu.op_const_reg(A_NONE,S_L,0,reg))
  384. else if (a = high(aword)) and
  385. (op in [OP_AND,OP_OR,OP_XOR]) then
  386. begin
  387. case op of
  388. OP_AND:
  389. exit;
  390. OP_OR:
  391. list.concat(taicpu.op_const_reg(A_NONE,S_L,high(aword),reg));
  392. OP_XOR:
  393. list.concat(taicpu.op_reg(A_NOT,S_L,reg));
  394. end
  395. end
  396. else
  397. list.concat(taicpu.op_const_reg(TOpCG2AsmOp[op],S_L,
  398. a,reg));
  399. OP_SHL,OP_SHR,OP_SAR:
  400. begin
  401. if (a and 31) <> 0 Then
  402. list.concat(taicpu.op_const_reg(
  403. TOpCG2AsmOp[op],S_L,a and 31,reg));
  404. if (a shr 5) <> 0 Then
  405. internalerror(68991);
  406. end
  407. else internalerror(68992);
  408. end;*)
  409. end;
  410. PROCEDURE tcgSPARC.a_op_const_ref(list:TAasmOutput;Op:TOpCG;size:TCGSize;a:AWord;CONST ref:TReference);
  411. var
  412. opcode:tasmop;
  413. power:LongInt;
  414. begin
  415. (* Case Op of
  416. OP_DIV, OP_IDIV:
  417. Begin
  418. if ispowerof2(a,power) then
  419. begin
  420. case op of
  421. OP_DIV:
  422. opcode := A_SHR;
  423. OP_IDIV:
  424. opcode := A_SAR;
  425. end;
  426. list.concat(taicpu.op_const_ref(opcode,
  427. TCgSize2OpSize[size],power,ref));
  428. exit;
  429. end;
  430. { the rest should be handled specifically in the code }
  431. { generator because of the silly register usage restraints }
  432. internalerror(200109231);
  433. End;
  434. OP_MUL,OP_IMUL:
  435. begin
  436. if not(cs_check_overflow in aktlocalswitches) and
  437. ispowerof2(a,power) then
  438. begin
  439. list.concat(taicpu.op_const_ref(A_SHL,TCgSize2OpSize[size],
  440. power,ref));
  441. exit;
  442. end;
  443. { can't multiply a memory location directly with a CONSTant }
  444. if op = OP_IMUL then
  445. inherited a_op_const_ref(list,op,size,a,ref)
  446. else
  447. { OP_MUL should be handled specifically in the code }
  448. { generator because of the silly register usage restraints }
  449. internalerror(200109232);
  450. end;
  451. OP_ADD, OP_AND, OP_OR, OP_SUB, OP_XOR:
  452. if not(cs_check_overflow in aktlocalswitches) and
  453. (a = 1) and
  454. (op in [OP_ADD,OP_SUB]) then
  455. if op = OP_ADD then
  456. list.concat(taicpu.op_ref(A_INC,TCgSize2OpSize[size],ref))
  457. else
  458. list.concat(taicpu.op_ref(A_DEC,TCgSize2OpSize[size],ref))
  459. else if (a = 0) then
  460. if (op <> OP_AND) then
  461. exit
  462. else
  463. a_load_const_ref(list,size,0,ref)
  464. else if (a = high(aword)) and
  465. (op in [OP_AND,OP_OR,OP_XOR]) then
  466. begin
  467. case op of
  468. OP_AND:
  469. exit;
  470. OP_OR:
  471. list.concat(taicpu.op_const_ref(A_NONE,TCgSize2OpSize[size],high(aword),ref));
  472. OP_XOR:
  473. list.concat(taicpu.op_ref(A_NOT,TCgSize2OpSize[size],ref));
  474. end
  475. end
  476. else
  477. list.concat(taicpu.op_const_ref(TOpCG2AsmOp[op],
  478. TCgSize2OpSize[size],a,ref));
  479. OP_SHL,OP_SHR,OP_SAR:
  480. begin
  481. if (a and 31) <> 0 Then
  482. list.concat(taicpu.op_const_ref(
  483. TOpCG2AsmOp[op],TCgSize2OpSize[size],a and 31,ref));
  484. if (a shr 5) <> 0 Then
  485. internalerror(68991);
  486. end
  487. else internalerror(68992);
  488. end;*)
  489. end;
  490. PROCEDURE tcgSPARC.a_op_reg_reg(list:TAasmOutput;Op:TOpCG;size:TCGSize;src, dst:TRegister);
  491. var
  492. regloadsize:tcgsize;
  493. dstsize:topsize;
  494. tmpreg:tregister;
  495. popecx:boolean;
  496. begin
  497. (* dstsize := S_Q{makeregsize(dst,size)};
  498. case op of
  499. OP_NEG,OP_NOT:
  500. begin
  501. if src <> R_NO then
  502. internalerror(200112291);
  503. list.concat(taicpu.op_reg(TOpCG2AsmOp[op],dstsize,dst));
  504. end;
  505. OP_MUL,OP_DIV,OP_IDIV:
  506. { special stuff, needs separate handling inside code }
  507. { generator }
  508. internalerror(200109233);
  509. OP_SHR,OP_SHL,OP_SAR:
  510. begin
  511. tmpreg := R_NO;
  512. { we need cl to hold the shift count, so if the destination }
  513. { is ecx, save it to a temp for now }
  514. if dst in [R_ECX,R_CX,R_CL] then
  515. begin
  516. case S_L of
  517. S_B:regloadsize := OS_8;
  518. S_W:regloadsize := OS_16;
  519. else regloadsize := OS_32;
  520. end;
  521. tmpreg := get_scratch_reg(list);
  522. a_load_reg_reg(list,regloadsize,OS_32,src,tmpreg);
  523. end;
  524. if not(src in [R_ECX,R_CX,R_CL]) then
  525. begin
  526. { is ecx still free (it's also free if it was allocated }
  527. { to dst, since we've moved dst somewhere else already) }
  528. if not((dst = R_ECX) or
  529. ((R_ECX in rg.unusedregsint) and
  530. { this will always be true, it's just here to }
  531. { allocate ecx }
  532. (rg.getexplicitregisterint(list,R_ECX) = R_ECX))) then
  533. begin
  534. list.concat(taicpu.op_reg(A_NONE,S_L,R_ECX));
  535. popecx := true;
  536. end;
  537. a_load_reg_reg(list,OS_8,OS_8,(src),R_CL);
  538. end
  539. else
  540. src := R_CL;
  541. { do the shift }
  542. if tmpreg = R_NO then
  543. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,
  544. R_CL,dst))
  545. else
  546. begin
  547. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],S_L,
  548. R_CL,tmpreg));
  549. { move result back to the destination }
  550. a_load_reg_reg(list,OS_32,OS_32,tmpreg,R_ECX);
  551. free_scratch_reg(list,tmpreg);
  552. end;
  553. if popecx then
  554. list.concat(taicpu.op_reg(A_POP,S_L,R_ECX))
  555. else if not (dst in [R_ECX,R_CX,R_CL]) then
  556. rg.ungetregisterint(list,R_ECX);
  557. end;
  558. else
  559. begin
  560. if S_L <> dstsize then
  561. internalerror(200109226);
  562. list.concat(taicpu.op_reg_reg(TOpCG2AsmOp[op],dstsize,
  563. src,dst));
  564. end;
  565. end;*)
  566. end;
  567. PROCEDURE tcgSPARC.a_op_ref_reg(list:TAasmOutput;Op:TOpCG;size:TCGSize;CONST ref:TReference;reg:TRegister);
  568. var
  569. opsize:topsize;
  570. begin
  571. (* case op of
  572. OP_NEG,OP_NOT,OP_IMUL:
  573. begin
  574. inherited a_op_ref_reg(list,op,size,ref,reg);
  575. end;
  576. OP_MUL,OP_DIV,OP_IDIV:
  577. { special stuff, needs separate handling inside code }
  578. { generator }
  579. internalerror(200109239);
  580. else
  581. begin
  582. opsize := S_Q{makeregsize(reg,size)};
  583. list.concat(taicpu.op_ref_reg(TOpCG2AsmOp[op],opsize,ref,reg));
  584. end;
  585. end;*)
  586. end;
  587. PROCEDURE tcgSPARC.a_op_reg_ref(list:TAasmOutput;Op:TOpCG;size:TCGSize;reg:TRegister;CONST ref:TReference);
  588. var
  589. opsize:topsize;
  590. begin
  591. (* case op of
  592. OP_NEG,OP_NOT:
  593. begin
  594. if reg <> R_NO then
  595. internalerror(200109237);
  596. list.concat(taicpu.op_ref(TOpCG2AsmOp[op],tcgsize2opsize[size],ref));
  597. end;
  598. OP_IMUL:
  599. begin
  600. { this one needs a load/imul/store, which is the default }
  601. inherited a_op_ref_reg(list,op,size,ref,reg);
  602. end;
  603. OP_MUL,OP_DIV,OP_IDIV:
  604. { special stuff, needs separate handling inside code }
  605. { generator }
  606. internalerror(200109238);
  607. else
  608. begin
  609. opsize := tcgsize2opsize[size];
  610. list.concat(taicpu.op_reg_ref(TOpCG2AsmOp[op],opsize,reg,ref));
  611. end;
  612. end;*)
  613. end;
  614. PROCEDURE tcgSPARC.a_op_const_reg_reg(list:TAasmOutput;op:TOpCg;
  615. size:tcgsize;a:aword;src, dst:tregister);
  616. var
  617. tmpref:TReference;
  618. power:LongInt;
  619. opsize:topsize;
  620. begin
  621. opsize := S_L;
  622. if (opsize <> S_L) or
  623. not (size in [OS_32,OS_S32]) then
  624. begin
  625. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  626. exit;
  627. end;
  628. { if we get here, we have to do a 32 bit calculation, guaranteed }
  629. Case Op of
  630. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  631. OP_SAR:
  632. { can't do anything special for these }
  633. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  634. OP_IMUL:
  635. begin
  636. if not(cs_check_overflow in aktlocalswitches) and
  637. ispowerof2(a,power) then
  638. { can be done with a shift }
  639. inherited a_op_const_reg_reg(list,op,size,a,src,dst);
  640. list.concat(taicpu.op_reg_const_reg(A_SMUL,S_L,src,a,dst));
  641. end;
  642. OP_ADD, OP_SUB:
  643. if (a = 0) then
  644. a_load_reg_reg(list,size,size,src,dst)
  645. else
  646. begin
  647. reference_reset(tmpref);
  648. tmpref.base := src;
  649. tmpref.offset := LongInt(a);
  650. if op = OP_SUB then
  651. tmpref.offset := -tmpref.offset;
  652. list.concat(taicpu.op_ref_reg(A_NONE,S_L,tmpref,dst));
  653. end
  654. else internalerror(200112302);
  655. end;
  656. end;
  657. PROCEDURE tcgSPARC.a_op_reg_reg_reg(list:TAasmOutput;op:TOpCg;
  658. size:tcgsize;src1, src2, dst:tregister);
  659. var
  660. tmpref:TReference;
  661. opsize:topsize;
  662. begin
  663. opsize := S_L;
  664. if (opsize <> S_L) or
  665. (S_L <> S_L) or
  666. not (size in [OS_32,OS_S32]) then
  667. begin
  668. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  669. exit;
  670. end;
  671. { if we get here, we have to do a 32 bit calculation, guaranteed }
  672. Case Op of
  673. OP_DIV, OP_IDIV, OP_MUL, OP_AND, OP_OR, OP_XOR, OP_SHL, OP_SHR,
  674. OP_SAR,OP_SUB,OP_NOT,OP_NEG:
  675. { can't do anything special for these }
  676. inherited a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  677. OP_IMUL:
  678. list.concat(taicpu.op_reg_reg_reg(A_SMUL,S_L,src1,src2,dst));
  679. OP_ADD:
  680. begin
  681. reference_reset(tmpref);
  682. tmpref.base := src1;
  683. tmpref.index := src2;
  684. tmpref.scalefactor := 1;
  685. list.concat(taicpu.op_ref_reg(A_NONE,S_L,tmpref,dst));
  686. end
  687. else internalerror(200112303);
  688. end;
  689. end;
  690. {*************** compare instructructions ****************}
  691. PROCEDURE tcgSPARC.a_cmp_const_reg_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;a:aword;reg:tregister;
  692. l:tasmlabel);
  693. begin
  694. if (a = 0) then
  695. list.concat(taicpu.op_reg_reg(A_CMP,S_L,reg,reg))
  696. else
  697. list.concat(taicpu.op_const_reg(A_CMP,S_L,a,reg));
  698. a_jmp_cond(list,cmp_op,l);
  699. end;
  700. PROCEDURE tcgSPARC.a_cmp_const_ref_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;a:aword;CONST ref:TReference;
  701. l:tasmlabel);
  702. begin
  703. list.concat(taicpu.op_const_ref(A_CMP,TCgSize2OpSize[size],a,ref));
  704. a_jmp_cond(list,cmp_op,l);
  705. end;
  706. PROCEDURE tcgSPARC.a_cmp_reg_reg_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;
  707. reg1,reg2:tregister;l:tasmlabel);
  708. begin
  709. { if regsize(reg1) <> S_L then
  710. internalerror(200109226);
  711. list.concat(taicpu.op_reg_reg(A_CMP,regsize(reg1),reg1,reg2));
  712. a_jmp_cond(list,cmp_op,l);}
  713. end;
  714. PROCEDURE tcgSPARC.a_cmp_ref_reg_label(list:TAasmOutput;size:tcgsize;cmp_op:topcmp;CONST ref:TReference;reg:tregister;l:tasmlabel);
  715. var
  716. opsize:topsize;
  717. begin
  718. opsize := S_Q{makeregsize(reg,size)};
  719. list.concat(taicpu.op_ref_reg(A_CMP,opsize,ref,reg));
  720. a_jmp_cond(list,cmp_op,l);
  721. end;
  722. PROCEDURE tcgSPARC.a_jmp_cond(list:TAasmOutput;cond:TOpCmp;l:tasmlabel);
  723. var
  724. ai:taicpu;
  725. begin
  726. if cond=OC_None then
  727. ai := Taicpu.Op_sym(A_JMPL,S_NO,l)
  728. else
  729. begin
  730. ai:=Taicpu.Op_sym(A_JMPL,S_NO,l);
  731. ai.SetCondition(TOpCmp2AsmCond[cond]);
  732. end;
  733. ai.is_jmp:=true;
  734. list.concat(ai);
  735. end;
  736. PROCEDURE tcgSPARC.a_jmp_flags(list:TAasmOutput;CONST f:TResFlags;l:tasmlabel);
  737. var
  738. ai:taicpu;
  739. begin
  740. ai := Taicpu.op_sym(A_JMPL,S_NO,l);
  741. ai.SetCondition(flags_to_cond(f));
  742. ai.is_jmp := true;
  743. list.concat(ai);
  744. end;
  745. PROCEDURE tcgSPARC.g_flags2reg(list:TAasmOutput;Size:TCgSize;CONST f:tresflags;reg:TRegister);
  746. VAR
  747. ai:taicpu;
  748. hreg:tregister;
  749. BEGIN
  750. hreg := rg.makeregsize(reg,OS_8);
  751. // ai:=Taicpu.Op_reg(A_Setcc,S_B,hreg);
  752. ai.SetCondition(flags_to_cond(f));
  753. list.concat(ai);
  754. IF hreg<>reg
  755. THEN
  756. a_load_reg_reg(list,OS_8,OS_8,hreg,reg);
  757. END;
  758. { *********** entry/exit code and address loading ************ }
  759. procedure tcgSPARC.g_stackframe_entry(list:TAasmOutput;localsize:LongInt);
  760. var
  761. href:TReference;
  762. i:integer;
  763. again:tasmlabel;
  764. begin
  765. {According the the SPARC ABI the standard stack frame must include :
  766. * 16 word save for the in and local registers in case of overflow/underflow.
  767. this save area always must exist at the %o6+0,
  768. * software conventions requires space for the aggregate return value pointer, even if the word is not used,
  769. * althogh the first six words of arguments reside in registers, the standard
  770. stack frame reserves space for them. Arguments beond the sixth reside on the
  771. stack as in the Intel architecture,
  772. * other areas depend on the compiler and the code being compiled. The
  773. standard calling sequence does not define a maximum stack frame size, nor does
  774. it restrict how a language system uses the "unspecified" areas of the standard
  775. stack frame.}
  776. Dec(LocalSize,(16+1+5)*4);
  777. {Althogh the SPARC architecture require only word alignment, software
  778. convention and the operating system require every stack frame to be double word
  779. aligned}
  780. if(LocalSize and $00000003)<>0
  781. then
  782. LocalSize:=(LocalSize and $FFFFFFFC)+4;
  783. {Execute the SAVE instruction to get a new register window and get a new stack
  784. frame. In the "SAVE %i6,size,%i6" the first %i6 is related to the state before
  785. execution of the SAVE instrucion so it is the caller %i6, when the %i6 after
  786. execution of that instrucion is the called function stack pointer}
  787. with list do
  788. concat(Taicpu.Op_reg_const_reg(A_SAVE,S_L,Stack_Pointer_Reg,localsize,Stack_Pointer_Reg));
  789. end;
  790. procedure tcgSPARC.g_restore_frame_pointer(list:TAasmOutput);
  791. begin
  792. {This function intontionally does nothing as frame pointer is restored in the
  793. delay slot of the return instrucion done in g_return_from_proc}
  794. end;
  795. procedure tcgSPARC.g_return_from_proc(list:TAasmOutput;parasize:aword);
  796. var
  797. RetReference:TReference;
  798. begin
  799. {According to the SPARC ABI, the stack is cleared using the RESTORE instruction
  800. which is genereted in the g_restore_frame_pointer. Notice that SPARC has no
  801. RETURN instruction and that JMPL is used instead. The JMPL instrucion have one
  802. delay slot, so an inversion is possible such as
  803. JMPL %i6+8,%g0
  804. RESTORE %g0,0,%g0
  805. If no inversion we can use just
  806. RESTORE %g0,0,%g0
  807. JMPL %i6+8,%g0
  808. NOP}
  809. with list do
  810. begin
  811. {Return address is computed by adding 8 to the CALL address saved onto %i6}
  812. reference_reset_base(RetReference,R_I7,8);
  813. concat(Taicpu.Op_ref_reg(A_JMPL,S_L,RetReference,R_G0));
  814. {We use trivial restore in the delay slot of the JMPL instruction, as we
  815. already set result onto %i0}
  816. concat(Taicpu.Op_reg_const_reg(A_RESTORE,S_L,R_G0,0,R_G0));
  817. end
  818. end;
  819. PROCEDURE tcgSPARC.a_loadaddr_ref_reg(list:TAasmOutput;CONST ref:TReference;r:tregister);
  820. begin
  821. // list.concat(taicpu.op_ref_reg(A_LEA,S_L,ref,r));
  822. end;
  823. { ************* 64bit operations ************ }
  824. PROCEDURE TCg64fSPARC.get_64bit_ops(op:TOpCG;var op1,op2:TAsmOp);
  825. begin
  826. case op of
  827. OP_ADD :
  828. begin
  829. op1:=A_ADD;
  830. op2:=A_ADD;
  831. end;
  832. OP_SUB :
  833. begin
  834. op1:=A_SUB;
  835. op2:=A_SUB;
  836. end;
  837. OP_XOR :
  838. begin
  839. op1:=A_XOR;
  840. op2:=A_XOR;
  841. end;
  842. OP_OR :
  843. begin
  844. op1:=A_OR;
  845. op2:=A_OR;
  846. end;
  847. OP_AND :
  848. begin
  849. op1:=A_AND;
  850. op2:=A_AND;
  851. end;
  852. else
  853. internalerror(200203241);
  854. end;
  855. end;
  856. PROCEDURE TCg64fSPARC.a_op64_ref_reg(list:TAasmOutput;op:TOpCG;CONST ref:TReference;reg:TRegister64);
  857. var
  858. op1,op2:TAsmOp;
  859. tempref:TReference;
  860. begin
  861. get_64bit_ops(op,op1,op2);
  862. list.concat(taicpu.op_ref_reg(op1,S_L,ref,reg.reglo));
  863. tempref:=ref;
  864. inc(tempref.offset,4);
  865. list.concat(taicpu.op_ref_reg(op2,S_L,tempref,reg.reghi));
  866. end;
  867. PROCEDURE TCg64fSPARC.a_op64_reg_reg(list:TAasmOutput;op:TOpCG;regsrc,regdst:TRegister64);
  868. var
  869. op1,op2:TAsmOp;
  870. begin
  871. get_64bit_ops(op,op1,op2);
  872. list.concat(taicpu.op_reg_reg(op1,S_L,regsrc.reglo,regdst.reglo));
  873. list.concat(taicpu.op_reg_reg(op2,S_L,regsrc.reghi,regdst.reghi));
  874. end;
  875. PROCEDURE TCg64fSPARC.a_op64_const_reg(list:TAasmOutput;op:TOpCG;value:qWord;regdst:TRegister64);
  876. var
  877. op1,op2:TAsmOp;
  878. begin
  879. case op of
  880. OP_AND,OP_OR,OP_XOR:
  881. WITH cg DO
  882. begin
  883. a_op_const_reg(list,op,Lo(Value),regdst.reglo);
  884. a_op_const_reg(list,op,Hi(Value),regdst.reghi);
  885. end;
  886. OP_ADD, OP_SUB:
  887. begin
  888. // can't use a_op_const_ref because this may use dec/inc
  889. get_64bit_ops(op,op1,op2);
  890. list.concat(taicpu.op_const_reg(op1,S_L,Lo(Value),regdst.reglo));
  891. list.concat(taicpu.op_const_reg(op2,S_L,Hi(Value),regdst.reghi));
  892. end;
  893. else
  894. internalerror(200204021);
  895. end;
  896. end;
  897. PROCEDURE TCg64fSPARC.a_op64_const_ref(list:TAasmOutput;op:TOpCG;value:qWord;CONST ref:TReference);
  898. var
  899. op1,op2:TAsmOp;
  900. tempref:TReference;
  901. begin
  902. case op of
  903. OP_AND,OP_OR,OP_XOR:
  904. WITH cg DO
  905. begin
  906. a_op_const_ref(list,op,OS_32,Lo(Value),ref);
  907. tempref:=ref;
  908. inc(tempref.offset,4);
  909. a_op_const_ref(list,op,OS_32,Hi(Value),tempref);
  910. end;
  911. OP_ADD, OP_SUB:
  912. begin
  913. get_64bit_ops(op,op1,op2);
  914. // can't use a_op_const_ref because this may use dec/inc
  915. list.concat(taicpu.op_const_ref(op1,S_L,Lo(Value),ref));
  916. tempref:=ref;
  917. inc(tempref.offset,4);
  918. list.concat(taicpu.op_const_ref(op2,S_L,Hi(Value),tempref));
  919. end;
  920. else
  921. internalerror(200204022);
  922. end;
  923. end;
  924. { ************* concatcopy ************ }
  925. PROCEDURE tcgSPARC.g_concatcopy(list:TAasmOutput;CONST source,dest:TReference;len:aword;delsource,loadref:boolean);
  926. { temp implementation, until it's permanenty moved here from cga.pas }
  927. var
  928. oldlist:TAasmOutput;
  929. begin
  930. if list <> exprasmlist then
  931. begin
  932. oldlist := exprasmlist;
  933. exprasmlist := list;
  934. end;
  935. // cga.concatcopy(source,dest,len,delsource,loadref);
  936. if list <> exprasmlist then
  937. list := oldlist;
  938. end;
  939. function tcgSPARC.reg_cgsize(CONST reg:tregister):tcgsize;
  940. // CONST
  941. // regsize_2_cgsize:array[S_B..S_L] of tcgsize = (OS_8,OS_16,OS_32);
  942. begin
  943. //result := regsize_2_cgsize[S_L];
  944. end;
  945. {***************** This is private property, keep out! :) *****************}
  946. procedure tcgSPARC.sizes2load(s1:tcgsize;s2:topsize;var op:tasmop;var s3:topsize);
  947. begin
  948. case s2 of
  949. S_B:
  950. if S1 in [OS_8,OS_S8]
  951. then
  952. s3 := S_B
  953. else
  954. internalerror(200109221);
  955. S_W:
  956. case s1 of
  957. OS_8,OS_S8:
  958. s3 := S_BW;
  959. OS_16,OS_S16:
  960. s3 := S_W;
  961. else
  962. internalerror(200109222);
  963. end;
  964. S_L:
  965. case s1 of
  966. OS_8,OS_S8:
  967. s3 := S_BL;
  968. OS_16,OS_S16:
  969. s3 := S_WL;
  970. OS_32,OS_S32:
  971. s3 := S_L;
  972. else
  973. internalerror(200109223);
  974. end;
  975. else internalerror(200109227);
  976. end;
  977. if s3 in [S_B,S_W,S_L]
  978. then
  979. op := A_LD
  980. { else if s3=S_DW
  981. then
  982. op:=A_LDD
  983. else if s3 in [OS_8,OS_16,OS_32]
  984. then
  985. op := A_NONE}
  986. else
  987. op := A_NONE;
  988. end;
  989. PROCEDURE tcgSPARC.floatloadops(t:tcgsize;VAR op:tasmop;VAR s:topsize);
  990. BEGIN
  991. (* case t of
  992. OS_F32:begin
  993. op:=A_FLD;
  994. s:=S_FS;
  995. end;
  996. OS_F64:begin
  997. op:=A_FLD;
  998. { ???? }
  999. s:=S_FL;
  1000. end;
  1001. OS_F80:begin
  1002. op:=A_FLD;
  1003. s:=S_FX;
  1004. end;
  1005. OS_C64:begin
  1006. op:=A_FILD;
  1007. s:=S_IQ;
  1008. end;
  1009. else internalerror(17);
  1010. end;*)
  1011. END;
  1012. PROCEDURE tcgSPARC.floatload(list:TAasmOutput;t:tcgsize;CONST ref:TReference);
  1013. VAR
  1014. op:tasmop;
  1015. s:topsize;
  1016. BEGIN
  1017. floatloadops(t,op,s);
  1018. list.concat(Taicpu.Op_ref(op,s,ref));
  1019. inc(trgcpu(rg).fpuvaroffset);
  1020. END;
  1021. PROCEDURE tcgSPARC.floatstoreops(t:tcgsize;var op:tasmop;var s:topsize);
  1022. BEGIN
  1023. { case t of
  1024. OS_F32:begin
  1025. op:=A_FSTP;
  1026. s:=S_FS;
  1027. end;
  1028. OS_F64:begin
  1029. op:=A_FSTP;
  1030. s:=S_FL;
  1031. end;
  1032. OS_F80:begin
  1033. op:=A_FSTP;
  1034. s:=S_FX;
  1035. end;
  1036. OS_C64:begin
  1037. op:=A_FISTP;
  1038. s:=S_IQ;
  1039. end;
  1040. else
  1041. internalerror(17);
  1042. end;}
  1043. end;
  1044. PROCEDURE tcgSPARC.floatstore(list:TAasmOutput;t:tcgsize;CONST ref:TReference);
  1045. VAR
  1046. op:tasmop;
  1047. s:topsize;
  1048. BEGIN
  1049. floatstoreops(t,op,s);
  1050. list.concat(Taicpu.Op_ref(op,s,ref));
  1051. dec(trgcpu(rg).fpuvaroffset);
  1052. END;
  1053. BEGIN
  1054. cg:=tcgSPARC.create;
  1055. END.
  1056. {
  1057. $Log$
  1058. Revision 1.10 2002-10-04 21:57:42 mazen
  1059. * register allocation for parameters now done in cpupara, but InternalError(200109223) in cgcpu.pas:1053 is still not fixed du to location_force problem in ncgutils.pas:419
  1060. Revision 1.9 2002/10/02 22:20:28 mazen
  1061. + out registers allocator for the first 6 scalar parameters which must be passed into %o0..%o5
  1062. Revision 1.8 2002/10/01 21:35:58 mazen
  1063. + procedures exiting prologue added and stack frame now restored in the delay slot of the return (JMPL) instruction
  1064. Revision 1.7 2002/10/01 21:06:29 mazen
  1065. attinst.inc --> strinst.inc
  1066. Revision 1.6 2002/10/01 17:41:50 florian
  1067. * fixed log and id
  1068. }