aasmcpu.pas 11 KB

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