aasmcpu.pas 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. {
  2. Copyright (c) 1999-2002 by Mazen Neifer
  3. Contains the assembler object for the SPARC
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit aasmcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. globtype,globals,verbose,
  23. aasmbase,aasmtai,aasmdata,aasmsym,
  24. cgbase,cgutils,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(tai_cpu_abstract_sym)
  32. delayslot_annulled : boolean; { conditinal opcode with ,a }
  33. constructor op_none(op : tasmop);
  34. constructor op_reg(op : tasmop;_op1 : tregister);
  35. constructor op_const(op : tasmop;_op1 : aint);
  36. constructor op_ref(op : tasmop;const _op1 : treference);
  37. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  38. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  39. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
  40. constructor op_const_reg(op:tasmop; _op1: aint; _op2: tregister);
  41. constructor op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  42. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  43. constructor op_reg_ref_reg(op:tasmop;_op1:TRegister;_op2:TReference;_op3:tregister);
  44. constructor op_reg_const_reg(op:tasmop;_op1:TRegister;_op2:aint;_op3:tregister);
  45. { this is for Jmp instructions }
  46. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  47. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  48. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:aint);
  49. constructor op_reg_sym(op : tasmop;_op1 : Tregister;_op2 : tasmsymbol);
  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):Taicpu;
  62. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  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 : aint);
  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: aint);
  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: aint; _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_low,addr_high]) 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. is_jmp:=op in [A_BA,A_Bxx];
  167. condition:=cond;
  168. ops:=1;
  169. loadsymbol(0,_op1,0);
  170. end;
  171. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  172. begin
  173. inherited create(op);
  174. is_jmp:=op in [A_BA,A_Bxx];
  175. ops:=1;
  176. loadsymbol(0,_op1,0);
  177. end;
  178. constructor taicpu.op_reg_sym(op : tasmop;_op1:Tregister;_op2 : tasmsymbol);
  179. begin
  180. inherited create(op);
  181. is_jmp:=op in [A_BA,A_Bxx];
  182. ops:=2;
  183. loadreg(0,_op1);
  184. loadsymbol(1,_op2,0);
  185. end;
  186. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:aint);
  187. begin
  188. inherited create(op);
  189. ops:=1;
  190. loadsymbol(0,_op1,_op1ofs);
  191. end;
  192. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  193. begin
  194. result:=(
  195. ((opcode=A_MOV) and (regtype = R_INTREGISTER)) or
  196. ((regtype = R_FPUREGISTER) and (opcode in [A_FMOVS,A_FMOVD]))
  197. ) and
  198. (ops=2) and
  199. (oper[0]^.typ=top_reg) and
  200. (oper[1]^.typ=top_reg) and
  201. (oper[0]^.reg=oper[1]^.reg);
  202. end;
  203. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  204. begin
  205. result := operand_read;
  206. case opcode of
  207. A_FCMPs,A_FCMPd,A_FCMPq :
  208. ;
  209. else
  210. begin
  211. if opnr=ops-1 then
  212. result := operand_write;
  213. end;
  214. end;
  215. end;
  216. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  217. begin
  218. case getregtype(r) of
  219. R_INTREGISTER :
  220. result:=taicpu.op_ref_reg(A_LD_R,ref,r);
  221. R_FPUREGISTER :
  222. begin
  223. case getsubreg(r) of
  224. R_SUBFS :
  225. result:=taicpu.op_ref_reg(A_LDF,ref,r);
  226. R_SUBFD :
  227. result:=taicpu.op_ref_reg(A_LDD,ref,r);
  228. else
  229. internalerror(200401042);
  230. end;
  231. end
  232. else
  233. internalerror(200401041);
  234. end;
  235. end;
  236. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  237. begin
  238. case getregtype(r) of
  239. R_INTREGISTER :
  240. result:=taicpu.op_reg_ref(A_ST_R,r,ref);
  241. R_FPUREGISTER :
  242. begin
  243. case getsubreg(r) of
  244. R_SUBFS :
  245. result:=taicpu.op_reg_ref(A_STF,r,ref);
  246. R_SUBFD :
  247. result:=taicpu.op_reg_ref(A_STD,r,ref);
  248. else
  249. internalerror(200401042);
  250. end;
  251. end
  252. else
  253. internalerror(200401041);
  254. end;
  255. end;
  256. procedure InitAsm;
  257. begin
  258. end;
  259. procedure DoneAsm;
  260. begin
  261. end;
  262. begin
  263. cai_cpu:=taicpu;
  264. cai_align:=tai_align;
  265. end.