aasmcpu.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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_nop:boolean;override;
  50. function is_move:boolean;override;
  51. { register spilling code }
  52. function spilling_decode_loadstore(op: tasmop; var counterpart: tasmop; var wasload: boolean): boolean;override;
  53. function spilling_create_loadstore(op: tasmop; r:tregister; const ref:treference): tai;override;
  54. function spilling_create_load(const ref:treference;r:tregister): tai;override;
  55. function spilling_create_store(r:tregister; const ref:treference): tai;override;
  56. end;
  57. tai_align = class(tai_align_abstract)
  58. { nothing to add }
  59. end;
  60. procedure InitAsm;
  61. procedure DoneAsm;
  62. implementation
  63. {*****************************************************************************
  64. taicpu Constructors
  65. *****************************************************************************}
  66. constructor taicpu.op_none(op : tasmop);
  67. begin
  68. inherited create(op);
  69. end;
  70. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  71. begin
  72. inherited create(op);
  73. ops:=1;
  74. loadreg(0,_op1);
  75. end;
  76. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  77. begin
  78. inherited create(op);
  79. ops:=1;
  80. loadref(0,_op1);
  81. end;
  82. constructor taicpu.op_const(op : tasmop;_op1 : aword);
  83. begin
  84. inherited create(op);
  85. ops:=1;
  86. loadconst(0,_op1);
  87. end;
  88. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  89. begin
  90. inherited create(op);
  91. ops:=2;
  92. loadreg(0,_op1);
  93. loadreg(1,_op2);
  94. end;
  95. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: aword);
  96. begin
  97. inherited create(op);
  98. ops:=2;
  99. loadreg(0,_op1);
  100. loadconst(1,_op2);
  101. end;
  102. constructor taicpu.op_const_reg(op:tasmop; _op1: aword; _op2: tregister);
  103. begin
  104. inherited create(op);
  105. ops:=2;
  106. loadconst(0,_op1);
  107. loadreg(1,_op2);
  108. end;
  109. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  110. begin
  111. inherited create(op);
  112. ops:=2;
  113. loadreg(0,_op1);
  114. loadref(1,_op2);
  115. end;
  116. constructor taicpu.op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  117. begin
  118. inherited create(op);
  119. ops:=2;
  120. loadref(0,_op1);
  121. loadreg(1,_op2);
  122. end;
  123. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  124. begin
  125. inherited create(op);
  126. ops:=3;
  127. loadreg(0,_op1);
  128. loadreg(1,_op2);
  129. loadreg(2,_op3);
  130. end;
  131. constructor taicpu.op_reg_ref_reg(op:tasmop;_op1:TRegister;_op2:TReference;_op3:tregister);
  132. begin
  133. inherited create(op);
  134. { only allowed to load the address }
  135. if not(_op2.symaddr in [refs_lo,refs_hi]) then
  136. internalerror(200305311);
  137. ops:=3;
  138. loadreg(0,_op1);
  139. loadref(1,_op2);
  140. loadreg(2,_op3);
  141. end;
  142. constructor taicpu.op_reg_const_reg(op:tasmop;_op1:TRegister;_op2:aword;_op3:tregister);
  143. begin
  144. inherited create(op);
  145. ops:=3;
  146. loadreg(0,_op1);
  147. loadconst(1,_op2);
  148. loadreg(2,_op3);
  149. end;
  150. constructor taicpu.op_cond_sym(op:tasmop;cond:TAsmCond;_op1:tasmsymbol);
  151. begin
  152. inherited create(op);
  153. condition:=cond;
  154. ops:=1;
  155. loadsymbol(0,_op1,0);
  156. end;
  157. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  158. begin
  159. inherited create(op);
  160. ops:=1;
  161. loadsymbol(0,_op1,0);
  162. end;
  163. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  164. begin
  165. inherited create(op);
  166. ops:=1;
  167. loadsymbol(0,_op1,_op1ofs);
  168. end;
  169. function taicpu.is_nop:boolean;
  170. begin
  171. { Note: This should not check for A_NOP, because that is
  172. used for the delay slots }
  173. result:=(opcode=A_MOV) and
  174. (ops=2) and
  175. (oper[0]^.typ=top_reg) and
  176. (oper[1]^.typ=top_reg) and
  177. (oper[0]^.reg=oper[1]^.reg);
  178. end;
  179. function taicpu.is_move:boolean;
  180. begin
  181. result:=(opcode=A_MOV) and
  182. (oper[0]^.typ=top_reg) and
  183. (oper[1]^.typ=top_reg);
  184. end;
  185. function taicpu.spilling_decode_loadstore(op: tasmop; var counterpart: tasmop; var wasload: boolean): boolean;
  186. begin
  187. result := true;
  188. wasload := true;
  189. case op of
  190. A_LDSB,
  191. A_LDUB :
  192. begin
  193. counterpart := A_STB;
  194. end;
  195. A_LDSH,
  196. A_LDUH:
  197. begin
  198. counterpart := A_STH;
  199. end;
  200. A_LD :
  201. begin
  202. counterpart := A_ST;
  203. wasload := false;
  204. end;
  205. A_LDD:
  206. begin
  207. counterpart := A_STD;
  208. wasload := false;
  209. end;
  210. A_STB:
  211. begin
  212. counterpart := A_LDUB;
  213. end;
  214. A_STH:
  215. begin
  216. counterpart := A_LDUH;
  217. end;
  218. A_ST :
  219. begin
  220. counterpart := A_LD;
  221. wasload := false;
  222. end;
  223. A_STD:
  224. begin
  225. counterpart := A_LDD;
  226. wasload := false;
  227. end;
  228. A_LDF:
  229. begin
  230. counterpart := A_STF;
  231. wasload := false;
  232. end;
  233. A_LDDF:
  234. begin
  235. counterpart := A_STDF;
  236. wasload := false;
  237. end;
  238. A_STF:
  239. begin
  240. counterpart := A_LDF;
  241. wasload := false;
  242. end;
  243. A_STDF:
  244. begin
  245. counterpart := A_LDDF;
  246. wasload := false;
  247. end;
  248. else
  249. result := false;
  250. end;
  251. end;
  252. function taicpu.spilling_create_loadstore(op: tasmop; r:tregister; const ref:treference): tai;
  253. begin
  254. result:=taicpu.op_reg_ref(opcode,r,ref);
  255. end;
  256. function taicpu.spilling_create_load(const ref:treference;r:tregister): tai;
  257. begin
  258. result:=taicpu.op_ref_reg(A_LD,ref,r);
  259. end;
  260. function taicpu.spilling_create_store(r:tregister; const ref:treference): tai;
  261. begin
  262. result:=taicpu.op_reg_ref(A_ST,r,ref);
  263. end;
  264. procedure InitAsm;
  265. begin
  266. end;
  267. procedure DoneAsm;
  268. begin
  269. end;
  270. end.
  271. {
  272. $Log$
  273. Revision 1.36 2003-10-30 15:03:18 mazen
  274. * now uses standard routines in rgHelper unit to search registers by number and by name
  275. Revision 1.35 2003/10/24 07:00:17 mazen
  276. * fixed compil problem when using ObjFpc mode (^ required).
  277. Revision 1.34 2003/10/01 20:34:49 peter
  278. * procinfo unit contains tprocinfo
  279. * cginfo renamed to cgbase
  280. * moved cgmessage to verbose
  281. * fixed ppc and sparc compiles
  282. Revision 1.33 2003/09/14 19:19:04 peter
  283. * updates for new ra
  284. Revision 1.32 2003/09/03 15:55:01 peter
  285. * NEWRA branch merged
  286. Revision 1.31.2.1 2003/08/31 21:08:16 peter
  287. * first batch of sparc fixes
  288. Revision 1.31 2003/08/11 21:18:20 peter
  289. * start of sparc support for newra
  290. Revision 1.30 2003/06/14 14:53:50 jonas
  291. * fixed newra cycle for x86
  292. * added constants for indicating source and destination operands of the
  293. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  294. Revision 1.29 2003/06/12 16:43:07 peter
  295. * newra compiles for sparc
  296. Revision 1.28 2003/06/01 01:03:41 peter
  297. * remove unsupported combinations
  298. * reg_ref_reg only allowed for refs_lo,refs_hi
  299. Revision 1.27 2003/05/30 23:57:08 peter
  300. * more sparc cleanup
  301. * accumulator removed, splitted in function_return_reg (called) and
  302. function_result_reg (caller)
  303. }