aasmcpu.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. {
  2. $Id$
  3. Copyright (c) 1999-2002 by Mazen Neifer
  4. Contains the assembler object 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 aasmcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,
  23. globtype,globals,verbose,
  24. aasmbase,aasmtai,
  25. cgbase,cpubase,cpuinfo;
  26. const
  27. { "mov reg,reg" source operand number }
  28. O_MOV_SOURCE = 0;
  29. { "mov reg,reg" source operand number }
  30. O_MOV_DEST = 1;
  31. type
  32. taicpu = class(tai_cpu_abstract)
  33. delayslot_annulled : boolean; { conditinal opcode with ,a }
  34. constructor op_none(op : tasmop);
  35. constructor op_reg(op : tasmop;_op1 : tregister);
  36. constructor op_const(op : tasmop;_op1 : LongInt);
  37. constructor op_ref(op : tasmop;const _op1 : treference);
  38. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  39. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  40. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  41. constructor op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  42. constructor op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  43. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  44. constructor op_reg_ref_reg(op:tasmop;_op1:TRegister;_op2:TReference;_op3:tregister);
  45. constructor op_reg_const_reg(op:tasmop;_op1:TRegister;_op2:aint;_op3:tregister);
  46. { this is for Jmp instructions }
  47. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  48. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  49. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  50. procedure loadbool(opidx:longint;_b:boolean);
  51. { register allocation }
  52. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  53. { register spilling code }
  54. function spilling_get_operation_type(opnr: longint): topertype;override;
  55. end;
  56. tai_align = class(tai_align_abstract)
  57. { nothing to add }
  58. end;
  59. procedure InitAsm;
  60. procedure DoneAsm;
  61. function spilling_create_load(const ref:treference;r:tregister): tai;
  62. function spilling_create_store(r:tregister; const ref:treference): tai;
  63. implementation
  64. {*****************************************************************************
  65. taicpu Constructors
  66. *****************************************************************************}
  67. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  68. begin
  69. if opidx>=ops then
  70. ops:=opidx+1;
  71. with oper[opidx]^ do
  72. begin
  73. if typ=top_ref then
  74. dispose(ref);
  75. b:=_b;
  76. typ:=top_bool;
  77. end;
  78. end;
  79. constructor taicpu.op_none(op : tasmop);
  80. begin
  81. inherited create(op);
  82. end;
  83. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  84. begin
  85. inherited create(op);
  86. ops:=1;
  87. loadreg(0,_op1);
  88. end;
  89. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  90. begin
  91. inherited create(op);
  92. ops:=1;
  93. loadref(0,_op1);
  94. end;
  95. constructor taicpu.op_const(op : tasmop;_op1 : LongInt);
  96. begin
  97. inherited create(op);
  98. ops:=1;
  99. loadconst(0,_op1);
  100. end;
  101. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  102. begin
  103. inherited create(op);
  104. ops:=2;
  105. loadreg(0,_op1);
  106. loadreg(1,_op2);
  107. end;
  108. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  109. begin
  110. inherited create(op);
  111. ops:=2;
  112. loadreg(0,_op1);
  113. loadconst(1,_op2);
  114. end;
  115. constructor taicpu.op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  116. begin
  117. inherited create(op);
  118. ops:=2;
  119. loadconst(0,_op1);
  120. loadreg(1,_op2);
  121. end;
  122. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  123. begin
  124. inherited create(op);
  125. ops:=2;
  126. loadreg(0,_op1);
  127. loadref(1,_op2);
  128. end;
  129. constructor taicpu.op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  130. begin
  131. inherited create(op);
  132. ops:=2;
  133. loadref(0,_op1);
  134. loadreg(1,_op2);
  135. end;
  136. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  137. begin
  138. inherited create(op);
  139. ops:=3;
  140. loadreg(0,_op1);
  141. loadreg(1,_op2);
  142. loadreg(2,_op3);
  143. end;
  144. constructor taicpu.op_reg_ref_reg(op:tasmop;_op1:TRegister;_op2:TReference;_op3:tregister);
  145. begin
  146. inherited create(op);
  147. { only allowed to load the address }
  148. if not(_op2.refaddr in [addr_lo,addr_hi]) then
  149. internalerror(200305311);
  150. ops:=3;
  151. loadreg(0,_op1);
  152. loadref(1,_op2);
  153. loadreg(2,_op3);
  154. end;
  155. constructor taicpu.op_reg_const_reg(op:tasmop;_op1:TRegister;_op2:aint;_op3:tregister);
  156. begin
  157. inherited create(op);
  158. ops:=3;
  159. loadreg(0,_op1);
  160. loadconst(1,_op2);
  161. loadreg(2,_op3);
  162. end;
  163. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  164. begin
  165. inherited create(op);
  166. condition:=cond;
  167. ops:=1;
  168. loadsymbol(0,_op1,0);
  169. end;
  170. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  171. begin
  172. inherited create(op);
  173. ops:=1;
  174. loadsymbol(0,_op1,0);
  175. end;
  176. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  177. begin
  178. inherited create(op);
  179. ops:=1;
  180. loadsymbol(0,_op1,_op1ofs);
  181. end;
  182. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  183. begin
  184. result:=(
  185. ((opcode=A_MOV) and (regtype = R_INTREGISTER)) or
  186. ((regtype = R_FPUREGISTER) and (opcode in [A_FMOVS,A_FMOVD]))
  187. ) and
  188. (ops=2) and
  189. (oper[0]^.typ=top_reg) and
  190. (oper[1]^.typ=top_reg) and
  191. (oper[0]^.reg=oper[1]^.reg);
  192. end;
  193. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  194. begin
  195. if opnr=ops-1 then
  196. result := operand_write
  197. else
  198. result := operand_read;
  199. end;
  200. function spilling_create_load(const ref:treference;r:tregister): tai;
  201. begin
  202. case getregtype(r) of
  203. R_INTREGISTER :
  204. result:=taicpu.op_ref_reg(A_LD,ref,r);
  205. R_FPUREGISTER :
  206. begin
  207. case getsubreg(r) of
  208. R_SUBFS :
  209. result:=taicpu.op_ref_reg(A_LDF,ref,r);
  210. R_SUBFD :
  211. result:=taicpu.op_ref_reg(A_LDD,ref,r);
  212. else
  213. internalerror(200401042);
  214. end;
  215. end
  216. else
  217. internalerror(200401041);
  218. end;
  219. end;
  220. function spilling_create_store(r:tregister; const ref:treference): tai;
  221. begin
  222. case getregtype(r) of
  223. R_INTREGISTER :
  224. result:=taicpu.op_reg_ref(A_ST,r,ref);
  225. R_FPUREGISTER :
  226. begin
  227. case getsubreg(r) of
  228. R_SUBFS :
  229. result:=taicpu.op_reg_ref(A_STF,r,ref);
  230. R_SUBFD :
  231. result:=taicpu.op_reg_ref(A_STD,r,ref);
  232. else
  233. internalerror(200401042);
  234. end;
  235. end
  236. else
  237. internalerror(200401041);
  238. end;
  239. end;
  240. procedure InitAsm;
  241. begin
  242. end;
  243. procedure DoneAsm;
  244. begin
  245. end;
  246. begin
  247. cai_cpu:=taicpu;
  248. cai_align:=tai_align;
  249. end.
  250. {
  251. $Log$
  252. Revision 1.49 2004-06-20 08:47:33 florian
  253. * spilling of doubles on sparc fixed
  254. Revision 1.48 2004/06/16 20:07:10 florian
  255. * dwarf branch merged
  256. Revision 1.47.2.5 2004/06/03 19:23:41 florian
  257. * fixed some spilling issues
  258. Revision 1.47.2.4 2004/05/30 17:54:14 florian
  259. + implemented cmp64bit
  260. * started to fix spilling
  261. * fixed int64 sub partially
  262. Revision 1.47.2.3 2004/05/28 20:29:49 florian
  263. * fixed currency trouble on x86-64
  264. Revision 1.47.2.2 2004/05/25 21:38:53 peter
  265. * assembler reader/writer updates
  266. Revision 1.47.2.1 2004/05/11 21:06:51 peter
  267. * sparc compiler fixed
  268. Revision 1.47 2004/03/12 08:18:11 mazen
  269. - revert '../' from include path
  270. Revision 1.46 2004/03/11 16:21:27 mazen
  271. + help lazarus analyze the file
  272. Revision 1.45 2004/03/08 16:28:39 mazen
  273. * make it as similar to PPC one ase possible
  274. Revision 1.44 2004/02/27 11:47:32 mazen
  275. * symaddr ==> refaddr to follow the rest of compiler changes
  276. Revision 1.43 2004/02/08 23:10:21 jonas
  277. * taicpu.is_same_reg_move() now gets a regtype parameter so it only
  278. removes moves of that particular register type. This is necessary so
  279. we don't remove the live_start instruction of a register before it
  280. has been processed
  281. Revision 1.42 2004/02/08 20:15:43 jonas
  282. - removed taicpu.is_reg_move because it's not used anymore
  283. + support tracking fpu register moves by rgobj for the ppc
  284. Revision 1.41 2004/01/12 16:39:40 peter
  285. * sparc updates, mostly float related
  286. Revision 1.40 2003/12/28 16:20:09 jonas
  287. - removed unused methods from old generic spilling code
  288. Revision 1.39 2003/12/26 14:02:30 peter
  289. * sparc updates
  290. * use registertype in spill_register
  291. Revision 1.38 2003/12/19 14:38:03 mazen
  292. * new TRegister definition applied
  293. Revision 1.37 2003/12/10 13:16:35 mazen
  294. * improve hadlign %hi and %lo operators
  295. Revision 1.36 2003/10/30 15:03:18 mazen
  296. * now uses standard routines in rgHelper unit to search registers by number and by name
  297. Revision 1.35 2003/10/24 07:00:17 mazen
  298. * fixed compil problem when using ObjFpc mode (^ required).
  299. Revision 1.34 2003/10/01 20:34:49 peter
  300. * procinfo unit contains tprocinfo
  301. * cginfo renamed to cgbase
  302. * moved cgmessage to verbose
  303. * fixed ppc and sparc compiles
  304. Revision 1.33 2003/09/14 19:19:04 peter
  305. * updates for new ra
  306. Revision 1.32 2003/09/03 15:55:01 peter
  307. * NEWRA branch merged
  308. Revision 1.31.2.1 2003/08/31 21:08:16 peter
  309. * first batch of sparc fixes
  310. Revision 1.31 2003/08/11 21:18:20 peter
  311. * start of sparc support for newra
  312. Revision 1.30 2003/06/14 14:53:50 jonas
  313. * fixed newra cycle for x86
  314. * added constants for indicating source and destination operands of the
  315. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  316. Revision 1.29 2003/06/12 16:43:07 peter
  317. * newra compiles for sparc
  318. Revision 1.28 2003/06/01 01:03:41 peter
  319. * remove unsupported combinations
  320. * reg_ref_reg only allowed for refs_lo,refs_hi
  321. Revision 1.27 2003/05/30 23:57:08 peter
  322. * more sparc cleanup
  323. * accumulator removed, splitted in function_return_reg (called) and
  324. function_result_reg (caller)
  325. }