aasmcpu.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. {
  2. Copyright (c) 1999-2002 by Jonas Maebe
  3. Contains the assembler object for the PowerPC64. Heavily based on code
  4. from the PowerPC platform
  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. globtype, verbose,
  23. aasmbase, aasmtai,
  24. cpubase, 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: aint);
  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_const_reg(op: tasmop; _op1: aint; _op2: tregister);
  39. constructor op_const_const(op: tasmop; _op1, _op2: aint);
  40. constructor op_reg_reg_const_const(op: tasmop; _op1, _op2: tregister; _op3,
  41. _op4: aint);
  42. constructor op_reg_reg_reg(op: tasmop; _op1, _op2, _op3: tregister);
  43. constructor op_reg_reg_const(op: tasmop; _op1, _op2: tregister; _op3: aint);
  44. constructor op_reg_reg_sym_ofs(op: tasmop; _op1, _op2: tregister; _op3:
  45. tasmsymbol; _op3ofs: aint);
  46. constructor op_reg_reg_ref(op: tasmop; _op1, _op2: tregister; const _op3:
  47. treference);
  48. constructor op_const_reg_reg(op: tasmop; _op1: aint; _op2, _op3: tregister);
  49. constructor op_const_reg_const(op: tasmop; _op1: aint; _op2: tregister;
  50. _op3: aint);
  51. constructor op_const_const_const(op: tasmop; _op1: aint; _op2: aint; _op3:
  52. aint);
  53. constructor op_reg_reg_reg_reg(op: tasmop; _op1, _op2, _op3, _op4:
  54. tregister);
  55. constructor op_reg_bool_reg_reg(op: tasmop; _op1: tregister; _op2: boolean;
  56. _op3, _op4: tregister);
  57. constructor op_reg_bool_reg_const(op: tasmop; _op1: tregister; _op2:
  58. boolean; _op3: tregister; _op4: aint);
  59. constructor op_reg_reg_reg_const_const(op: tasmop; _op1, _op2, _op3:
  60. tregister; _op4, _op5: aint);
  61. constructor op_reg_reg_const_const_const(op: tasmop; _op1, _op2: tregister;
  62. _op3, _op4, _op5: aint);
  63. { this is for Jmp instructions }
  64. constructor op_cond_sym(op: tasmop; cond: TAsmCond; _op1: tasmsymbol);
  65. constructor op_const_const_sym(op: tasmop; _op1, _op2: aint; _op3:
  66. tasmsymbol);
  67. constructor op_sym(op: tasmop; _op1: tasmsymbol);
  68. constructor op_sym_ofs(op: tasmop; _op1: tasmsymbol; _op1ofs: aint);
  69. constructor op_reg_sym_ofs(op: tasmop; _op1: tregister; _op2: tasmsymbol;
  70. _op2ofs: aint);
  71. constructor op_sym_ofs_ref(op: tasmop; _op1: tasmsymbol; _op1ofs: aint; const
  72. _op2: treference);
  73. procedure loadbool(opidx: aint; _b: boolean);
  74. function is_same_reg_move(regtype: Tregistertype): boolean; override;
  75. end;
  76. tai_align = class(tai_align_abstract)
  77. { nothing to add }
  78. end;
  79. procedure InitAsm;
  80. procedure DoneAsm;
  81. function spilling_create_load(const ref: treference; r: tregister): tai;
  82. function spilling_create_store(r: tregister; const ref: treference): tai;
  83. implementation
  84. uses cutils;
  85. {*****************************************************************************
  86. taicpu Constructors
  87. *****************************************************************************}
  88. procedure taicpu.loadbool(opidx: aint; _b: boolean);
  89. begin
  90. if opidx >= ops then
  91. ops := opidx + 1;
  92. with oper[opidx]^ do
  93. begin
  94. if typ = top_ref then
  95. dispose(ref);
  96. b := _b;
  97. typ := top_bool;
  98. end;
  99. end;
  100. constructor taicpu.op_none(op: tasmop);
  101. begin
  102. inherited create(op);
  103. end;
  104. constructor taicpu.op_reg(op: tasmop; _op1: tregister);
  105. begin
  106. inherited create(op);
  107. ops := 1;
  108. loadreg(0, _op1);
  109. end;
  110. constructor taicpu.op_const(op: tasmop; _op1: aint);
  111. begin
  112. inherited create(op);
  113. ops := 1;
  114. loadconst(0, _op1);
  115. end;
  116. constructor taicpu.op_reg_reg_const_const(op: tasmop; _op1, _op2: tregister;
  117. _op3, _op4: aint);
  118. begin
  119. inherited create(op);
  120. ops := 4;
  121. loadreg(0, _op1);
  122. loadreg(1, _op2);
  123. loadconst(2, _op3);
  124. loadconst(3, _op4);
  125. end;
  126. constructor taicpu.op_reg_reg(op: tasmop; _op1, _op2: tregister);
  127. begin
  128. inherited create(op);
  129. ops := 2;
  130. loadreg(0, _op1);
  131. loadreg(1, _op2);
  132. end;
  133. constructor taicpu.op_reg_const(op: tasmop; _op1: tregister; _op2: aint);
  134. begin
  135. inherited create(op);
  136. ops := 2;
  137. loadreg(0, _op1);
  138. loadconst(1, _op2);
  139. end;
  140. constructor taicpu.op_const_reg(op: tasmop; _op1: aint; _op2: tregister);
  141. begin
  142. inherited create(op);
  143. ops := 2;
  144. loadconst(0, _op1);
  145. loadreg(1, _op2);
  146. end;
  147. constructor taicpu.op_reg_ref(op: tasmop; _op1: tregister; const _op2:
  148. treference);
  149. begin
  150. inherited create(op);
  151. ops := 2;
  152. loadreg(0, _op1);
  153. loadref(1, _op2);
  154. end;
  155. constructor taicpu.op_const_const(op: tasmop; _op1, _op2: aint);
  156. begin
  157. inherited create(op);
  158. ops := 2;
  159. loadconst(0, _op1);
  160. loadconst(1, _op2);
  161. end;
  162. constructor taicpu.op_reg_reg_reg(op: tasmop; _op1, _op2, _op3: tregister);
  163. begin
  164. inherited create(op);
  165. ops := 3;
  166. loadreg(0, _op1);
  167. loadreg(1, _op2);
  168. loadreg(2, _op3);
  169. end;
  170. constructor taicpu.op_reg_reg_const(op: tasmop; _op1, _op2: tregister; _op3:
  171. aint);
  172. begin
  173. inherited create(op);
  174. ops := 3;
  175. loadreg(0, _op1);
  176. loadreg(1, _op2);
  177. loadconst(2, _op3);
  178. end;
  179. constructor taicpu.op_reg_reg_sym_ofs(op: tasmop; _op1, _op2: tregister; _op3:
  180. tasmsymbol; _op3ofs: aint);
  181. begin
  182. inherited create(op);
  183. ops := 3;
  184. loadreg(0, _op1);
  185. loadreg(1, _op2);
  186. loadsymbol(0, _op3, _op3ofs);
  187. end;
  188. constructor taicpu.op_reg_reg_ref(op: tasmop; _op1, _op2: tregister; const _op3:
  189. treference);
  190. begin
  191. inherited create(op);
  192. ops := 3;
  193. loadreg(0, _op1);
  194. loadreg(1, _op2);
  195. loadref(2, _op3);
  196. end;
  197. constructor taicpu.op_const_reg_reg(op: tasmop; _op1: aint; _op2, _op3:
  198. tregister);
  199. begin
  200. inherited create(op);
  201. ops := 3;
  202. loadconst(0, _op1);
  203. loadreg(1, _op2);
  204. loadreg(2, _op3);
  205. end;
  206. constructor taicpu.op_const_reg_const(op: tasmop; _op1: aint; _op2: tregister;
  207. _op3: aint);
  208. begin
  209. inherited create(op);
  210. ops := 3;
  211. loadconst(0, _op1);
  212. loadreg(1, _op2);
  213. loadconst(2, _op3);
  214. end;
  215. constructor taicpu.op_const_const_const(op: tasmop; _op1: aint; _op2: aint;
  216. _op3: aint);
  217. begin
  218. inherited create(op);
  219. ops := 3;
  220. loadconst(0, _op1);
  221. loadconst(1, _op2);
  222. loadconst(2, _op3);
  223. end;
  224. constructor taicpu.op_reg_reg_reg_reg(op: tasmop; _op1, _op2, _op3, _op4:
  225. tregister);
  226. begin
  227. inherited create(op);
  228. ops := 4;
  229. loadreg(0, _op1);
  230. loadreg(1, _op2);
  231. loadreg(2, _op3);
  232. loadreg(3, _op4);
  233. end;
  234. constructor taicpu.op_reg_bool_reg_reg(op: tasmop; _op1: tregister; _op2:
  235. boolean; _op3, _op4: tregister);
  236. begin
  237. inherited create(op);
  238. ops := 4;
  239. loadreg(0, _op1);
  240. loadbool(1, _op2);
  241. loadreg(2, _op3);
  242. loadreg(3, _op4);
  243. end;
  244. constructor taicpu.op_reg_bool_reg_const(op: tasmop; _op1: tregister; _op2:
  245. boolean; _op3: tregister; _op4: aint);
  246. begin
  247. inherited create(op);
  248. ops := 4;
  249. loadreg(0, _op1);
  250. loadbool(0, _op2);
  251. loadreg(0, _op3);
  252. loadconst(0, cardinal(_op4));
  253. end;
  254. constructor taicpu.op_reg_reg_reg_const_const(op: tasmop; _op1, _op2, _op3:
  255. tregister; _op4, _op5: aint);
  256. begin
  257. inherited create(op);
  258. ops := 5;
  259. loadreg(0, _op1);
  260. loadreg(1, _op2);
  261. loadreg(2, _op3);
  262. loadconst(3, cardinal(_op4));
  263. loadconst(4, cardinal(_op5));
  264. end;
  265. constructor taicpu.op_reg_reg_const_const_const(op: tasmop; _op1, _op2:
  266. tregister; _op3, _op4, _op5: aint);
  267. begin
  268. inherited create(op);
  269. ops := 5;
  270. loadreg(0, _op1);
  271. loadreg(1, _op2);
  272. loadconst(2, _op3);
  273. loadconst(3, _op4);
  274. loadconst(4, _op5);
  275. end;
  276. constructor taicpu.op_cond_sym(op: tasmop; cond: TAsmCond; _op1: tasmsymbol);
  277. begin
  278. inherited create(op);
  279. condition := cond;
  280. ops := 1;
  281. loadsymbol(0, _op1, 0);
  282. end;
  283. constructor taicpu.op_const_const_sym(op: tasmop; _op1, _op2: aint; _op3:
  284. tasmsymbol);
  285. begin
  286. inherited create(op);
  287. ops := 3;
  288. loadconst(0, _op1);
  289. loadconst(1, _op2);
  290. loadsymbol(2, _op3, 0);
  291. end;
  292. constructor taicpu.op_sym(op: tasmop; _op1: tasmsymbol);
  293. begin
  294. inherited create(op);
  295. ops := 1;
  296. loadsymbol(0, _op1, 0);
  297. end;
  298. constructor taicpu.op_sym_ofs(op: tasmop; _op1: tasmsymbol; _op1ofs: aint);
  299. begin
  300. inherited create(op);
  301. ops := 1;
  302. loadsymbol(0, _op1, _op1ofs);
  303. end;
  304. constructor taicpu.op_reg_sym_ofs(op: tasmop; _op1: tregister; _op2: tasmsymbol;
  305. _op2ofs: aint);
  306. begin
  307. inherited create(op);
  308. ops := 2;
  309. loadreg(0, _op1);
  310. loadsymbol(1, _op2, _op2ofs);
  311. end;
  312. constructor taicpu.op_sym_ofs_ref(op: tasmop; _op1: tasmsymbol; _op1ofs: aint;
  313. const _op2: treference);
  314. begin
  315. inherited create(op);
  316. ops := 2;
  317. loadsymbol(0, _op1, _op1ofs);
  318. loadref(1, _op2);
  319. end;
  320. { ****************************** newra stuff *************************** }
  321. function taicpu.is_same_reg_move(regtype: Tregistertype): boolean;
  322. begin
  323. result :=
  324. (((opcode = A_MR) and
  325. (regtype = R_INTREGISTER)) or
  326. ((opcode = A_FMR) and
  327. (regtype = R_FPUREGISTER))) and
  328. { these opcodes can only have registers as operands }
  329. (oper[0]^.reg = oper[1]^.reg);
  330. end;
  331. function spilling_create_load(const ref: treference; r: tregister): tai;
  332. begin
  333. result := taicpu.op_reg_ref(A_LD, r, ref);
  334. end;
  335. function spilling_create_store(r: tregister; const ref: treference): tai;
  336. begin
  337. result := taicpu.op_reg_ref(A_STD, r, ref);
  338. end;
  339. procedure InitAsm;
  340. begin
  341. end;
  342. procedure DoneAsm;
  343. begin
  344. end;
  345. begin
  346. cai_align := tai_align;
  347. cai_cpu := taicpu;
  348. end.