aasmcpu.pas 10 KB

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