aasmcpu.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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_ref(op : tasmop;const _op1 : treference);
  35. constructor op_const(op : tasmop;_op1 : aword);
  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: aword);
  39. constructor op_const_reg(op:tasmop; _op1: aword; _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. { register allocation }
  49. function is_reg_move:boolean;override;
  50. function is_same_reg_move: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. constructor taicpu.op_none(op : tasmop);
  66. begin
  67. inherited create(op);
  68. end;
  69. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  70. begin
  71. inherited create(op);
  72. ops:=1;
  73. loadreg(0,_op1);
  74. end;
  75. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  76. begin
  77. inherited create(op);
  78. ops:=1;
  79. loadref(0,_op1);
  80. end;
  81. constructor taicpu.op_const(op : tasmop;_op1 : aword);
  82. begin
  83. inherited create(op);
  84. ops:=1;
  85. loadconst(0,_op1);
  86. end;
  87. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  88. begin
  89. inherited create(op);
  90. ops:=2;
  91. loadreg(0,_op1);
  92. loadreg(1,_op2);
  93. end;
  94. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: aword);
  95. begin
  96. inherited create(op);
  97. ops:=2;
  98. loadreg(0,_op1);
  99. loadconst(1,_op2);
  100. end;
  101. constructor taicpu.op_const_reg(op:tasmop; _op1: aword; _op2: tregister);
  102. begin
  103. inherited create(op);
  104. ops:=2;
  105. loadconst(0,_op1);
  106. loadreg(1,_op2);
  107. end;
  108. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  109. begin
  110. inherited create(op);
  111. ops:=2;
  112. loadreg(0,_op1);
  113. loadref(1,_op2);
  114. end;
  115. constructor taicpu.op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  116. begin
  117. inherited create(op);
  118. ops:=2;
  119. loadref(0,_op1);
  120. loadreg(1,_op2);
  121. end;
  122. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  123. begin
  124. inherited create(op);
  125. ops:=3;
  126. loadreg(0,_op1);
  127. loadreg(1,_op2);
  128. loadreg(2,_op3);
  129. end;
  130. constructor taicpu.op_reg_ref_reg(op:tasmop;_op1:TRegister;_op2:TReference;_op3:tregister);
  131. begin
  132. inherited create(op);
  133. { only allowed to load the address }
  134. if not(_op2.symaddr in [refs_lo,refs_hi]) then
  135. internalerror(200305311);
  136. ops:=3;
  137. loadreg(0,_op1);
  138. loadref(1,_op2);
  139. loadreg(2,_op3);
  140. end;
  141. constructor taicpu.op_reg_const_reg(op:tasmop;_op1:TRegister;_op2:aword;_op3:tregister);
  142. begin
  143. inherited create(op);
  144. ops:=3;
  145. loadreg(0,_op1);
  146. loadconst(1,_op2);
  147. loadreg(2,_op3);
  148. end;
  149. constructor taicpu.op_cond_sym(op:tasmop;cond:TAsmCond;_op1:tasmsymbol);
  150. begin
  151. inherited create(op);
  152. condition:=cond;
  153. ops:=1;
  154. loadsymbol(0,_op1,0);
  155. end;
  156. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  157. begin
  158. inherited create(op);
  159. ops:=1;
  160. loadsymbol(0,_op1,0);
  161. end;
  162. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  163. begin
  164. inherited create(op);
  165. ops:=1;
  166. loadsymbol(0,_op1,_op1ofs);
  167. end;
  168. function taicpu.is_reg_move:boolean;
  169. begin
  170. result:=((opcode=A_MOV) or (opcode=A_FMOVS)) and
  171. (ops=2) and
  172. (oper[0]^.typ=top_reg) and
  173. (oper[1]^.typ=top_reg);
  174. end;
  175. function taicpu.is_same_reg_move:boolean;
  176. begin
  177. result:=((opcode=A_MOV) or (opcode=A_FMOVS)) and
  178. (ops=2) and
  179. (oper[0]^.typ=top_reg) and
  180. (oper[1]^.typ=top_reg) and
  181. (oper[0]^.reg=oper[1]^.reg);
  182. end;
  183. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  184. begin
  185. result := operand_read;
  186. case opcode of
  187. A_STB..A_STDA:
  188. begin
  189. if opnr = 1 then
  190. result := operand_write;
  191. end;
  192. else
  193. if opnr = 0 then
  194. result := operand_write;
  195. end;
  196. end;
  197. function taicpu.spilling_create_load(const ref:treference;r:tregister): tai;
  198. begin
  199. case getregtype(r) of
  200. R_INTREGISTER :
  201. result:=taicpu.op_ref_reg(A_LD,ref,r);
  202. R_FPUREGISTER :
  203. begin
  204. case getsubreg(r) of
  205. R_SUBFS :
  206. result:=taicpu.op_ref_reg(A_LDF,ref,r);
  207. R_SUBFD :
  208. result:=taicpu.op_ref_reg(A_LDD,ref,r);
  209. else
  210. internalerror(200401042);
  211. end;
  212. end
  213. else
  214. internalerror(200401041);
  215. end;
  216. end;
  217. function taicpu.spilling_create_store(r:tregister; const ref:treference): tai;
  218. begin
  219. case getregtype(r) of
  220. R_INTREGISTER :
  221. result:=taicpu.op_reg_ref(A_ST,r,ref);
  222. R_FPUREGISTER :
  223. begin
  224. case getsubreg(r) of
  225. R_SUBFS :
  226. result:=taicpu.op_reg_ref(A_STF,r,ref);
  227. R_SUBFD :
  228. result:=taicpu.op_reg_ref(A_STD,r,ref);
  229. else
  230. internalerror(200401042);
  231. end;
  232. end
  233. else
  234. internalerror(200401041);
  235. end;
  236. end;
  237. procedure InitAsm;
  238. begin
  239. end;
  240. procedure DoneAsm;
  241. begin
  242. end;
  243. end.
  244. {
  245. $Log$
  246. Revision 1.41 2004-01-12 16:39:40 peter
  247. * sparc updates, mostly float related
  248. Revision 1.40 2003/12/28 16:20:09 jonas
  249. - removed unused methods from old generic spilling code
  250. Revision 1.39 2003/12/26 14:02:30 peter
  251. * sparc updates
  252. * use registertype in spill_register
  253. Revision 1.38 2003/12/19 14:38:03 mazen
  254. * new TRegister definition applied
  255. Revision 1.37 2003/12/10 13:16:35 mazen
  256. * improve hadlign %hi and %lo operators
  257. Revision 1.36 2003/10/30 15:03:18 mazen
  258. * now uses standard routines in rgHelper unit to search registers by number and by name
  259. Revision 1.35 2003/10/24 07:00:17 mazen
  260. * fixed compil problem when using ObjFpc mode (^ required).
  261. Revision 1.34 2003/10/01 20:34:49 peter
  262. * procinfo unit contains tprocinfo
  263. * cginfo renamed to cgbase
  264. * moved cgmessage to verbose
  265. * fixed ppc and sparc compiles
  266. Revision 1.33 2003/09/14 19:19:04 peter
  267. * updates for new ra
  268. Revision 1.32 2003/09/03 15:55:01 peter
  269. * NEWRA branch merged
  270. Revision 1.31.2.1 2003/08/31 21:08:16 peter
  271. * first batch of sparc fixes
  272. Revision 1.31 2003/08/11 21:18:20 peter
  273. * start of sparc support for newra
  274. Revision 1.30 2003/06/14 14:53:50 jonas
  275. * fixed newra cycle for x86
  276. * added constants for indicating source and destination operands of the
  277. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  278. Revision 1.29 2003/06/12 16:43:07 peter
  279. * newra compiles for sparc
  280. Revision 1.28 2003/06/01 01:03:41 peter
  281. * remove unsupported combinations
  282. * reg_ref_reg only allowed for refs_lo,refs_hi
  283. Revision 1.27 2003/05/30 23:57:08 peter
  284. * more sparc cleanup
  285. * accumulator removed, splitted in function_return_reg (called) and
  286. function_result_reg (caller)
  287. }