aasmcpu.pas 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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,
  23. globtype,globals,verbose,
  24. aasmbase,aasmtai,
  25. cgbase,cpubase,cpuinfo;
  26. const
  27. { "mov reg,reg" source operand number }
  28. O_MOV_SOURCE = 0;
  29. { "mov reg,reg" source operand number }
  30. O_MOV_DEST = 1;
  31. type
  32. taicpu = class(tai_cpu_abstract)
  33. delayslot_annulled : boolean; { conditinal opcode with ,a }
  34. constructor op_none(op : tasmop);
  35. constructor op_reg(op : tasmop;_op1 : tregister);
  36. constructor op_const(op : tasmop;_op1 : LongInt);
  37. constructor op_ref(op : tasmop;const _op1 : treference);
  38. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  39. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  40. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  41. constructor op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  42. constructor op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  43. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  44. constructor op_reg_ref_reg(op:tasmop;_op1:TRegister;_op2:TReference;_op3:tregister);
  45. constructor op_reg_const_reg(op:tasmop;_op1:TRegister;_op2:aint;_op3:tregister);
  46. { this is for Jmp instructions }
  47. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  48. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  49. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  50. procedure loadbool(opidx:longint;_b:boolean);
  51. { register allocation }
  52. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  53. { register spilling code }
  54. function spilling_get_operation_type(opnr: longint): topertype;override;
  55. end;
  56. tai_align = class(tai_align_abstract)
  57. { nothing to add }
  58. end;
  59. procedure InitAsm;
  60. procedure DoneAsm;
  61. function spilling_create_load(const ref:treference;r:tregister): tai;
  62. function spilling_create_store(r:tregister; const ref:treference): tai;
  63. implementation
  64. {*****************************************************************************
  65. taicpu Constructors
  66. *****************************************************************************}
  67. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  68. begin
  69. if opidx>=ops then
  70. ops:=opidx+1;
  71. with oper[opidx]^ do
  72. begin
  73. if typ=top_ref then
  74. dispose(ref);
  75. b:=_b;
  76. typ:=top_bool;
  77. end;
  78. end;
  79. constructor taicpu.op_none(op : tasmop);
  80. begin
  81. inherited create(op);
  82. end;
  83. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  84. begin
  85. inherited create(op);
  86. ops:=1;
  87. loadreg(0,_op1);
  88. end;
  89. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  90. begin
  91. inherited create(op);
  92. ops:=1;
  93. loadref(0,_op1);
  94. end;
  95. constructor taicpu.op_const(op : tasmop;_op1 : LongInt);
  96. begin
  97. inherited create(op);
  98. ops:=1;
  99. loadconst(0,_op1);
  100. end;
  101. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  102. begin
  103. inherited create(op);
  104. ops:=2;
  105. loadreg(0,_op1);
  106. loadreg(1,_op2);
  107. end;
  108. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  109. begin
  110. inherited create(op);
  111. ops:=2;
  112. loadreg(0,_op1);
  113. loadconst(1,_op2);
  114. end;
  115. constructor taicpu.op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  116. begin
  117. inherited create(op);
  118. ops:=2;
  119. loadconst(0,_op1);
  120. loadreg(1,_op2);
  121. end;
  122. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  123. begin
  124. inherited create(op);
  125. ops:=2;
  126. loadreg(0,_op1);
  127. loadref(1,_op2);
  128. end;
  129. constructor taicpu.op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  130. begin
  131. inherited create(op);
  132. ops:=2;
  133. loadref(0,_op1);
  134. loadreg(1,_op2);
  135. end;
  136. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  137. begin
  138. inherited create(op);
  139. ops:=3;
  140. loadreg(0,_op1);
  141. loadreg(1,_op2);
  142. loadreg(2,_op3);
  143. end;
  144. constructor taicpu.op_reg_ref_reg(op:tasmop;_op1:TRegister;_op2:TReference;_op3:tregister);
  145. begin
  146. inherited create(op);
  147. { only allowed to load the address }
  148. if not(_op2.refaddr in [addr_lo,addr_hi]) then
  149. internalerror(200305311);
  150. ops:=3;
  151. loadreg(0,_op1);
  152. loadref(1,_op2);
  153. loadreg(2,_op3);
  154. end;
  155. constructor taicpu.op_reg_const_reg(op:tasmop;_op1:TRegister;_op2:aint;_op3:tregister);
  156. begin
  157. inherited create(op);
  158. ops:=3;
  159. loadreg(0,_op1);
  160. loadconst(1,_op2);
  161. loadreg(2,_op3);
  162. end;
  163. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  164. begin
  165. inherited create(op);
  166. condition:=cond;
  167. ops:=1;
  168. loadsymbol(0,_op1,0);
  169. end;
  170. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  171. begin
  172. inherited create(op);
  173. ops:=1;
  174. loadsymbol(0,_op1,0);
  175. end;
  176. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  177. begin
  178. inherited create(op);
  179. ops:=1;
  180. loadsymbol(0,_op1,_op1ofs);
  181. end;
  182. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  183. begin
  184. result:=(
  185. ((opcode=A_MOV) and (regtype = R_INTREGISTER)) or
  186. ((regtype = R_FPUREGISTER) and (opcode in [A_FMOVS,A_FMOVD]))
  187. ) and
  188. (ops=2) and
  189. (oper[0]^.typ=top_reg) and
  190. (oper[1]^.typ=top_reg) and
  191. (oper[0]^.reg=oper[1]^.reg);
  192. end;
  193. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  194. begin
  195. if opnr=ops-1 then
  196. result := operand_write
  197. else
  198. result := operand_read;
  199. end;
  200. function spilling_create_load(const ref:treference;r:tregister): tai;
  201. begin
  202. case getregtype(r) of
  203. R_INTREGISTER :
  204. result:=taicpu.op_ref_reg(A_LD,ref,r);
  205. R_FPUREGISTER :
  206. begin
  207. case getsubreg(r) of
  208. R_SUBFS :
  209. result:=taicpu.op_ref_reg(A_LDF,ref,r);
  210. R_SUBFD :
  211. result:=taicpu.op_ref_reg(A_LDD,ref,r);
  212. else
  213. internalerror(200401042);
  214. end;
  215. end
  216. else
  217. internalerror(200401041);
  218. end;
  219. end;
  220. function spilling_create_store(r:tregister; const ref:treference): tai;
  221. begin
  222. case getregtype(r) of
  223. R_INTREGISTER :
  224. result:=taicpu.op_reg_ref(A_ST,r,ref);
  225. R_FPUREGISTER :
  226. begin
  227. case getsubreg(r) of
  228. R_SUBFS :
  229. result:=taicpu.op_reg_ref(A_STF,r,ref);
  230. R_SUBFD :
  231. result:=taicpu.op_reg_ref(A_STD,r,ref);
  232. else
  233. internalerror(200401042);
  234. end;
  235. end
  236. else
  237. internalerror(200401041);
  238. end;
  239. end;
  240. procedure InitAsm;
  241. begin
  242. end;
  243. procedure DoneAsm;
  244. begin
  245. end;
  246. begin
  247. cai_cpu:=taicpu;
  248. cai_align:=tai_align;
  249. end.
  250. {
  251. $Log$
  252. Revision 1.50 2004-06-20 08:55:32 florian
  253. * logs truncated
  254. Revision 1.49 2004/06/20 08:47:33 florian
  255. * spilling of doubles on sparc fixed
  256. Revision 1.48 2004/06/16 20:07:10 florian
  257. * dwarf branch merged
  258. Revision 1.47.2.5 2004/06/03 19:23:41 florian
  259. * fixed some spilling issues
  260. Revision 1.47.2.4 2004/05/30 17:54:14 florian
  261. + implemented cmp64bit
  262. * started to fix spilling
  263. * fixed int64 sub partially
  264. Revision 1.47.2.3 2004/05/28 20:29:49 florian
  265. * fixed currency trouble on x86-64
  266. }