aasmcpu.pas 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. {
  2. Copyright (c) 2003 by Florian Klaempfl
  3. Contains the assembler object for MIPS
  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,aasmtai,aasmdata,
  22. aasmbase,globtype,globals,verbose,
  23. cpubase,cpuinfo,cgbase,cgutils;
  24. const
  25. { "mov reg,reg" source operand number }
  26. O_MOV_SOURCE = 1;
  27. { "mov reg,reg" source operand number }
  28. O_MOV_DEST = 0;
  29. type
  30. taicpu = class(tai_cpu_abstract)
  31. constructor op_none(op : tasmop);
  32. constructor op_reg(op : tasmop;_op1 : tregister);
  33. constructor op_const(op : tasmop;_op1 : longint);
  34. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  35. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  36. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
  37. constructor op_ref_regset(op:tasmop; _op1: treference; _op2: tcpuregisterset);
  38. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  39. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: aint);
  40. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  41. constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  42. { SFM/LFM }
  43. constructor op_reg_const_ref(op : tasmop;_op1 : tregister;_op2 : aint;_op3 : treference);
  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. constructor op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  49. constructor op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  50. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  51. function spilling_get_operation_type(opnr: longint): topertype;override;
  52. end;
  53. tai_align = class(tai_align_abstract)
  54. { nothing to add }
  55. end;
  56. function spilling_create_load(const ref:treference;r:tregister): tai;
  57. function spilling_create_store(r:tregister; const ref:treference): tai;
  58. procedure InitAsm;
  59. procedure DoneAsm;
  60. implementation
  61. uses
  62. cutils,rgobj,itcpugas;
  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_const(op : tasmop;_op1 : longint);
  77. begin
  78. inherited create(op);
  79. ops:=1;
  80. loadconst(0,aint(_op1));
  81. end;
  82. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  83. begin
  84. inherited create(op);
  85. ops:=2;
  86. loadreg(0,_op1);
  87. loadreg(1,_op2);
  88. end;
  89. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
  90. begin
  91. inherited create(op);
  92. ops:=2;
  93. loadreg(0,_op1);
  94. loadconst(1,aint(_op2));
  95. end;
  96. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  97. begin
  98. inherited create(op);
  99. ops:=2;
  100. loadreg(0,_op1);
  101. loadref(1,_op2);
  102. end;
  103. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  104. begin
  105. inherited create(op);
  106. ops:=3;
  107. loadreg(0,_op1);
  108. loadreg(1,_op2);
  109. loadreg(2,_op3);
  110. end;
  111. constructor taicpu.op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: aint);
  112. begin
  113. inherited create(op);
  114. ops:=3;
  115. loadreg(0,_op1);
  116. loadreg(1,_op2);
  117. loadconst(2,aint(_op3));
  118. end;
  119. constructor taicpu.op_reg_const_ref(op : tasmop;_op1 : tregister;_op2 : aint;_op3 : treference);
  120. begin
  121. inherited create(op);
  122. ops:=3;
  123. loadreg(0,_op1);
  124. loadconst(1,_op2);
  125. loadref(2,_op3);
  126. end;
  127. constructor taicpu.op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  128. begin
  129. inherited create(op);
  130. ops:=3;
  131. loadreg(0,_op1);
  132. loadreg(1,_op2);
  133. loadsymbol(0,_op3,_op3ofs);
  134. end;
  135. constructor taicpu.op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  136. begin
  137. inherited create(op);
  138. ops:=3;
  139. loadreg(0,_op1);
  140. loadreg(1,_op2);
  141. loadref(2,_op3);
  142. end;
  143. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  144. begin
  145. inherited create(op);
  146. condition:=cond;
  147. ops:=1;
  148. loadsymbol(0,_op1,0);
  149. end;
  150. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  151. begin
  152. inherited create(op);
  153. ops:=1;
  154. loadsymbol(0,_op1,0);
  155. end;
  156. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  157. begin
  158. inherited create(op);
  159. ops:=1;
  160. loadsymbol(0,_op1,_op1ofs);
  161. end;
  162. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  163. begin
  164. inherited create(op);
  165. ops:=2;
  166. loadreg(0,_op1);
  167. loadsymbol(1,_op2,_op2ofs);
  168. end;
  169. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  170. begin
  171. inherited create(op);
  172. ops:=2;
  173. loadsymbol(0,_op1,_op1ofs);
  174. loadref(1,_op2);
  175. end;
  176. { ****************************** newra stuff *************************** }
  177. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  178. begin
  179. { allow the register allocator to remove unnecessary moves }
  180. result:=(((opcode=A_MOVE) and (regtype = R_INTREGISTER)) or
  181. ((opcode=A_MOVF) and (regtype = R_FPUREGISTER))
  182. ) and
  183. (condition=C_None) and
  184. (ops=2) and
  185. (oper[0]^.typ=top_reg) and
  186. (oper[1]^.typ=top_reg) and
  187. (oper[0]^.reg=oper[1]^.reg);
  188. end;
  189. function spilling_create_load(const ref:treference;r:tregister): tai;
  190. begin
  191. case getregtype(r) of
  192. R_INTREGISTER :
  193. result:=taicpu.op_reg_ref(A_LDR,r,ref);
  194. R_FPUREGISTER :
  195. { use lfm because we don't know the current internal format
  196. and avoid exceptions
  197. }
  198. result:=taicpu.op_reg_const_ref(A_LFM,r,1,ref);
  199. else
  200. internalerror(200401041);
  201. end;
  202. end;
  203. function spilling_create_store(r:tregister; const ref:treference): tai;
  204. begin
  205. case getregtype(r) of
  206. R_INTREGISTER :
  207. result:=taicpu.op_reg_ref(A_STR,r,ref);
  208. R_FPUREGISTER :
  209. { use sfm because we don't know the current internal format
  210. and avoid exceptions
  211. }
  212. result:=taicpu.op_reg_const_ref(A_SFM,r,1,ref);
  213. else
  214. internalerror(200401041);
  215. end;
  216. end;
  217. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  218. begin
  219. case opcode of
  220. A_ADC,A_ADD,A_AND,
  221. A_EOR,A_CLZ,
  222. A_LDR,A_LDRB,A_LDRD,A_LDRBT,A_LDRH,A_LDRSB,
  223. A_LDRSH,A_LDRT,
  224. A_MOV,A_MVN,A_MLA,A_MUL,
  225. A_ORR,A_RSB,A_RSC,A_SBC,A_SUB,
  226. A_SWP,A_SWPB,
  227. A_LDF,A_FLT,A_FIX,
  228. A_ADF,A_DVF,A_FDV,A_FML,
  229. A_RFS,A_RFC,A_RDF,
  230. A_RMF,A_RPW,A_RSF,A_SUF,A_ABS,A_ACS,A_ASN,A_ATN,A_COS,
  231. A_EXP,A_LOG,A_LGN,A_MVF,A_MNF,A_FRD,A_MUF,A_POL,A_RND,A_SIN,A_SQT,A_TAN,
  232. A_LFM:
  233. if opnr=0 then
  234. result:=operand_write
  235. else
  236. result:=operand_read;
  237. A_BIC,A_BKPT,A_B,A_BL,A_BLX,A_BX,
  238. A_CMN,A_CMP,A_TEQ,A_TST,
  239. A_CMF,A_CMFE,A_WFS,A_CNF:
  240. result:=operand_read;
  241. A_SMLAL,A_UMLAL:
  242. if opnr in [0,1] then
  243. result:=operand_readwrite
  244. else
  245. result:=operand_read;
  246. A_SMULL,A_UMULL:
  247. if opnr in [0,1] then
  248. result:=operand_write
  249. else
  250. result:=operand_read;
  251. A_STR,A_STRB,A_STRBT,A_STRD,
  252. A_STRH,A_STRT,A_STF,A_SFM:
  253. { important is what happens with the involved registers }
  254. if opnr=0 then
  255. result := operand_read
  256. else
  257. { check for pre/post indexed }
  258. result := operand_read;
  259. else
  260. internalerror(200403151);
  261. end;
  262. end;
  263. procedure InitAsm;
  264. begin
  265. end;
  266. procedure DoneAsm;
  267. begin
  268. end;
  269. end.