aasmcpu.pas 10 KB

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