aasmcpu.pas 10 KB

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