aasmcpu.pas 11 KB

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