aasmcpu.pas 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. {
  2. Copyright (c) 1999-2009 by Mazen Neifer and David Zhang
  3. Contains the assembler object for the MIPSEL
  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,
  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)
  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: longint);
  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: longint);
  40. constructor op_reg_reg_reg(op: tasmop; _op1, _op2, _op3: tregister);
  41. constructor op_reg_reg_ref(op: tasmop; _op1, _op2: tregister; const _op3: treference);
  42. constructor op_reg_reg_const(op: tasmop; _op1, _op2: tregister; _op3: aint);
  43. { this is for Jmp instructions }
  44. constructor op_sym(op: tasmop; _op1: tasmsymbol);
  45. constructor op_reg_reg_sym(op: tasmop; _op1, _op2: tregister; _op3: tasmsymbol);
  46. constructor op_reg_sym(op: tasmop; _op1: tregister; _op2: tasmsymbol);
  47. constructor op_sym_ofs(op: tasmop; _op1: tasmsymbol; _op1ofs: longint);
  48. { register allocation }
  49. function is_same_reg_move(regtype: Tregistertype): boolean; override;
  50. { register spilling code }
  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. procedure InitAsm;
  57. procedure DoneAsm;
  58. function spilling_create_load(const ref: treference; r: tregister): taicpu;
  59. function spilling_create_store(r: tregister; const ref: treference): taicpu;
  60. implementation
  61. {*****************************************************************************
  62. taicpu Constructors
  63. *****************************************************************************}
  64. constructor taicpu.op_none(op: tasmop);
  65. begin
  66. inherited Create(op);
  67. end;
  68. constructor taicpu.op_reg(op: tasmop; _op1: tregister);
  69. begin
  70. inherited Create(op);
  71. ops := 1;
  72. loadreg(0, _op1);
  73. end;
  74. constructor taicpu.op_ref(op: tasmop; const _op1: treference);
  75. begin
  76. inherited Create(op);
  77. ops := 1;
  78. loadref(0, _op1);
  79. end;
  80. constructor taicpu.op_const(op: tasmop; _op1: longint);
  81. begin
  82. inherited Create(op);
  83. ops := 1;
  84. loadconst(0, _op1);
  85. end;
  86. constructor taicpu.op_reg_reg(op: tasmop; _op1, _op2: tregister);
  87. begin
  88. inherited Create(op);
  89. ops := 2;
  90. loadreg(0, _op1);
  91. loadreg(1, _op2);
  92. end;
  93. constructor taicpu.op_reg_const(op: tasmop; _op1: tregister; _op2: longint);
  94. begin
  95. inherited Create(op);
  96. ops := 2;
  97. loadreg(0, _op1);
  98. loadconst(1, _op2);
  99. end;
  100. constructor taicpu.op_reg_ref(op: tasmop; _op1: tregister; const _op2: treference);
  101. begin
  102. inherited Create(op);
  103. ops := 2;
  104. loadreg(0, _op1);
  105. loadref(1, _op2);
  106. end;
  107. constructor taicpu.op_reg_reg_reg(op: tasmop; _op1, _op2, _op3: tregister);
  108. begin
  109. inherited Create(op);
  110. ops := 3;
  111. loadreg(0, _op1);
  112. loadreg(1, _op2);
  113. loadreg(2, _op3);
  114. end;
  115. constructor taicpu.op_reg_reg_ref(op: tasmop; _op1, _op2: tregister; const _op3: treference);
  116. begin
  117. inherited create(op);
  118. ops := 3;
  119. loadreg(0, _op1);
  120. loadreg(1, _op2);
  121. loadref(2, _op3);
  122. end;
  123. constructor taicpu.op_reg_reg_const(op: tasmop; _op1, _op2: tregister; _op3: aint);
  124. begin
  125. inherited create(op);
  126. ops := 3;
  127. loadreg(0, _op1);
  128. loadreg(1, _op2);
  129. loadconst(2, _op3);
  130. end;
  131. constructor taicpu.op_sym(op: tasmop; _op1: tasmsymbol);
  132. begin
  133. inherited Create(op);
  134. is_jmp := op in [A_J, A_BEQI, A_BNEI, A_BLTI, A_BLEI, A_BGTI, A_BGEI,
  135. A_BLTUI, A_BLEUI, A_BGTUI, A_BGEUI,
  136. A_BEQ, A_BNE, A_BLT, A_BLE, A_BGT, A_BGE,
  137. A_BLTU, A_BLEU, A_BGTU, A_BGEU
  138. ];
  139. ops := 1;
  140. loadsymbol(0, _op1, 0);
  141. end;
  142. constructor taicpu.op_reg_reg_sym(op: tasmop; _op1, _op2: tregister; _op3: tasmsymbol);
  143. begin
  144. inherited create(op);
  145. is_jmp := op in [A_J,
  146. A_BEQI, A_BNEI, A_BLTI, A_BLEI, A_BGTI, A_BGEI, A_BLTUI, A_BLEUI,
  147. A_BGTUI, A_BGEUI,
  148. A_BEQ, A_BNE, A_BLT, A_BLE, A_BGT, A_BGE, A_BLTU, A_BLEU, A_BGTU, A_BGEU];
  149. ops := 3;
  150. loadreg(0, _op1);
  151. loadreg(1, _op2);
  152. loadsymbol(2, _op3, 0);
  153. end;
  154. constructor taicpu.op_reg_sym(op: tasmop; _op1: tregister; _op2: tasmsymbol);
  155. begin
  156. inherited create(op);
  157. is_jmp := op in [A_J,
  158. A_BEQI, A_BNEI, A_BLTI, A_BLEI, A_BGTI, A_BGEI, A_BLTUI, A_BLEUI,
  159. A_BGTUI, A_BGEUI,
  160. A_BEQ, A_BNE, A_BLT, A_BLE, A_BGT, A_BGE, A_BLTU, A_BLEU, A_BGTU, A_BGEU, A_BGTZ];
  161. ops := 2;
  162. loadreg(0, _op1);
  163. loadsymbol(1, _op2, 0);
  164. end;
  165. constructor taicpu.op_sym_ofs(op: tasmop; _op1: tasmsymbol; _op1ofs: longint);
  166. begin
  167. inherited Create(op);
  168. ops := 1;
  169. loadsymbol(0, _op1, _op1ofs);
  170. end;
  171. function taicpu.is_same_reg_move(regtype: Tregistertype): boolean;
  172. begin
  173. Result := (
  174. ((opcode = A_MOVE) and (regtype = R_INTREGISTER)) or
  175. ((regtype = R_FPUREGISTER) and (opcode in [A_MOV_S, A_MOV_D]))
  176. ) and
  177. (oper[0]^.reg = oper[1]^.reg);
  178. end;
  179. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  180. type
  181. op_write_set_type = set of TAsmOp;
  182. const
  183. op_write_set: op_write_set_type =
  184. [A_NEG,
  185. A_NEGU,
  186. A_LI,
  187. A_DLI,
  188. A_LA,
  189. A_MOVE,
  190. A_LB,
  191. A_LBU,
  192. A_LH,
  193. A_LHU,
  194. A_LW,
  195. A_LWU,
  196. A_LWL,
  197. A_LWR,
  198. A_LD,
  199. A_LDL,
  200. A_LDR,
  201. A_LL,
  202. A_LLD,
  203. A_ADDI,
  204. A_DADDI,
  205. A_ADDIU,
  206. A_DADDIU,
  207. A_SLTI,
  208. A_SLTIU,
  209. A_ANDI,
  210. A_ORI,
  211. A_XORI,
  212. A_LUI,
  213. A_DNEG,
  214. A_DNEGU,
  215. A_ADD,
  216. A_DADD,
  217. A_ADDU,
  218. A_DADDU,
  219. A_SUB,
  220. A_DSUB,
  221. A_SUBU,
  222. A_DSUBU,
  223. A_SLT,
  224. A_SLTU,
  225. A_AND,
  226. A_OR,
  227. A_XOR,
  228. A_NOR,
  229. A_MUL,
  230. A_MULO,
  231. A_MULOU,
  232. A_DMUL,
  233. A_DMULO,
  234. A_DMULOU,
  235. A_DIV,
  236. A_DIVU,
  237. A_DDIV,
  238. A_DDIVU,
  239. A_REM,
  240. A_REMU,
  241. A_DREM,
  242. A_DREMU,
  243. A_MULT,
  244. A_DMULT,
  245. A_MULTU,
  246. A_DMULTU,
  247. A_MFHI,
  248. A_MFLO,
  249. A_MULTG,
  250. A_DMULTG,
  251. A_MULTUG,
  252. A_DMULTUG,
  253. A_DIVG,
  254. A_DDIVG,
  255. A_DIVUG,
  256. A_DDIVUG,
  257. A_MODG,
  258. A_DMODG,
  259. A_MODUG,
  260. A_DMODUG,
  261. A_SLL,
  262. A_SRL,
  263. A_SRA,
  264. A_SLLV,
  265. A_SRLV,
  266. A_SRAV,
  267. A_DSLL,
  268. A_DSRL,
  269. A_DSRA,
  270. A_DSLLV,
  271. A_DSRLV,
  272. A_DSRAV,
  273. A_DSLL32,
  274. A_DSRL32,
  275. A_DSRA32,
  276. A_LWC1,
  277. A_LDC1,
  278. A_ADD_S,
  279. A_ADD_D,
  280. A_SUB_S,
  281. A_SUB_D,
  282. A_MUL_S,
  283. A_MUL_D,
  284. A_DIV_S,
  285. A_DIV_D,
  286. A_ABS_S,
  287. A_ABS_D,
  288. A_NEG_S,
  289. A_NEG_D,
  290. A_SQRT_S,
  291. A_SQRT_D,
  292. A_MOV_S,
  293. A_MOV_D,
  294. A_CVT_S_D,
  295. A_CVT_S_W,
  296. A_CVT_S_L,
  297. A_CVT_D_S,
  298. A_CVT_D_W,
  299. A_CVT_D_L,
  300. A_CVT_W_S,
  301. A_CVT_W_D,
  302. A_CVT_L_S,
  303. A_CVT_L_D,
  304. A_ROUND_W_S,
  305. A_ROUND_W_D,
  306. A_ROUND_L_S,
  307. A_ROUND_L_D,
  308. A_TRUNC_W_S,
  309. A_TRUNC_W_D,
  310. A_TRUNC_L_S,
  311. A_TRUNC_L_D,
  312. A_CEIL_W_S,
  313. A_CEIL_W_D,
  314. A_CEIL_L_S,
  315. A_CEIL_L_D,
  316. A_FLOOR_W_S,
  317. A_FLOOR_W_D,
  318. A_FLOOR_L_S,
  319. A_FLOOR_L_D,
  320. A_SEQ,
  321. A_SGE,
  322. A_SGEU,
  323. A_SGT,
  324. A_SGTU,
  325. A_SLE,
  326. A_SLEU,
  327. A_SNE];
  328. begin
  329. result := operand_read;
  330. if opcode in op_write_set then
  331. if opnr = 0 then
  332. result := operand_write;
  333. end;
  334. function spilling_create_load(const ref: treference; r: tregister): taicpu;
  335. begin
  336. case getregtype(r) of
  337. R_INTREGISTER :
  338. result:=taicpu.op_reg_ref(A_LW,r,ref);
  339. R_FPUREGISTER :
  340. begin
  341. case getsubreg(r) of
  342. R_SUBFS :
  343. result:=taicpu.op_reg_ref(A_LWC1,r,ref);
  344. R_SUBFD :
  345. result:=taicpu.op_reg_ref(A_LDC1,r,ref);
  346. else
  347. internalerror(200401042);
  348. end;
  349. end
  350. else
  351. internalerror(200401041);
  352. end;
  353. end;
  354. function spilling_create_store(r: tregister; const ref: treference): taicpu;
  355. begin
  356. case getregtype(r) of
  357. R_INTREGISTER :
  358. result:=taicpu.op_reg_ref(A_SW,r,ref);
  359. R_FPUREGISTER :
  360. begin
  361. case getsubreg(r) of
  362. R_SUBFS :
  363. result:=taicpu.op_reg_ref(A_SWC1,r,ref);
  364. R_SUBFD :
  365. result:=taicpu.op_reg_ref(A_SDC1,r,ref);
  366. else
  367. internalerror(200401042);
  368. end;
  369. end
  370. else
  371. internalerror(200401041);
  372. end;
  373. end;
  374. procedure InitAsm;
  375. begin
  376. end;
  377. procedure DoneAsm;
  378. begin
  379. end;
  380. begin
  381. cai_cpu := taicpu;
  382. cai_align := tai_align;
  383. end.