aasmcpu.pas 11 KB

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