aasmcpu.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. {
  2. $Id$
  3. Copyright (c) 1999-2002 by Jonas Maebe
  4. Contains the assembler object for the PowerPC
  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,globals,verbose,
  24. cpubase,cpuinfo;
  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(taicpu_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: longint);
  38. constructor op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  39. constructor op_const_const(op : tasmop;_op1,_op2 : longint);
  40. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  41. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  42. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  43. constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  44. constructor op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  45. constructor op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  46. constructor op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  47. constructor op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  48. constructor op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  49. constructor op_reg_reg_reg_const_const(op : tasmop;_op1,_op2,_op3 : tregister;_op4,_op5 : Longint);
  50. constructor op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  51. { this is for Jmp instructions }
  52. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  53. constructor op_const_const_sym(op : tasmop;_op1,_op2 : longint;_op3: tasmsymbol);
  54. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  55. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  56. constructor op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  57. constructor op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  58. procedure loadbool(opidx:longint;_b:boolean);
  59. function is_nop: boolean; override;
  60. function is_move:boolean; override;
  61. function spill_registers(list:Taasmoutput;
  62. rgget:Trggetproc;
  63. rgunget:Trgungetproc;
  64. r:Tsupregset;
  65. var unusedregsint:Tsupregset;
  66. const spilltemplist:Tspill_temp_list):boolean; override;
  67. end;
  68. tai_align = class(tai_align_abstract)
  69. { nothing to add }
  70. end;
  71. procedure InitAsm;
  72. procedure DoneAsm;
  73. implementation
  74. uses cutils,rgobj;
  75. {*****************************************************************************
  76. taicpu Constructors
  77. *****************************************************************************}
  78. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  79. begin
  80. if opidx>=ops then
  81. ops:=opidx+1;
  82. with oper[opidx] do
  83. begin
  84. if typ=top_ref then
  85. dispose(ref);
  86. b:=_b;
  87. typ:=top_bool;
  88. end;
  89. end;
  90. constructor taicpu.op_none(op : tasmop);
  91. begin
  92. inherited create(op);
  93. end;
  94. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  95. begin
  96. inherited create(op);
  97. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  98. internalerror(2003031207);
  99. ops:=1;
  100. loadreg(0,_op1);
  101. end;
  102. constructor taicpu.op_const(op : tasmop;_op1 : longint);
  103. begin
  104. inherited create(op);
  105. ops:=1;
  106. loadconst(0,aword(_op1));
  107. end;
  108. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  109. begin
  110. inherited create(op);
  111. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  112. internalerror(2003031205);
  113. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  114. internalerror(2003031206);
  115. ops:=2;
  116. loadreg(0,_op1);
  117. loadreg(1,_op2);
  118. end;
  119. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  120. begin
  121. inherited create(op);
  122. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  123. internalerror(2003031208);
  124. ops:=2;
  125. loadreg(0,_op1);
  126. loadconst(1,aword(_op2));
  127. end;
  128. constructor taicpu.op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  129. begin
  130. inherited create(op);
  131. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  132. internalerror(2003031209);
  133. ops:=2;
  134. loadconst(0,aword(_op1));
  135. loadreg(1,_op2);
  136. end;
  137. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  138. begin
  139. inherited create(op);
  140. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  141. internalerror(2003031210);
  142. ops:=2;
  143. loadreg(0,_op1);
  144. loadref(1,_op2);
  145. end;
  146. constructor taicpu.op_const_const(op : tasmop;_op1,_op2 : longint);
  147. begin
  148. inherited create(op);
  149. ops:=2;
  150. loadconst(0,aword(_op1));
  151. loadconst(1,aword(_op2));
  152. end;
  153. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  154. begin
  155. inherited create(op);
  156. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  157. internalerror(2003031211);
  158. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  159. internalerror(2003031212);
  160. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  161. internalerror(2003031213);
  162. ops:=3;
  163. loadreg(0,_op1);
  164. loadreg(1,_op2);
  165. loadreg(2,_op3);
  166. end;
  167. constructor taicpu.op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  168. begin
  169. inherited create(op);
  170. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  171. internalerror(2003031214);
  172. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  173. internalerror(2003031215);
  174. ops:=3;
  175. loadreg(0,_op1);
  176. loadreg(1,_op2);
  177. loadconst(2,aword(_op3));
  178. end;
  179. constructor taicpu.op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  180. begin
  181. inherited create(op);
  182. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  183. internalerror(2003031216);
  184. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  185. internalerror(2003031217);
  186. ops:=3;
  187. loadreg(0,_op1);
  188. loadreg(1,_op2);
  189. loadsymbol(0,_op3,_op3ofs);
  190. end;
  191. constructor taicpu.op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  192. begin
  193. inherited create(op);
  194. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  195. internalerror(2003031218);
  196. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  197. internalerror(2003031219);
  198. ops:=3;
  199. loadreg(0,_op1);
  200. loadreg(1,_op2);
  201. loadref(2,_op3);
  202. end;
  203. constructor taicpu.op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  204. begin
  205. inherited create(op);
  206. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  207. internalerror(2003031221);
  208. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  209. internalerror(2003031220);
  210. ops:=3;
  211. loadconst(0,aword(_op1));
  212. loadreg(1,_op2);
  213. loadreg(2,_op3);
  214. end;
  215. constructor taicpu.op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  216. begin
  217. inherited create(op);
  218. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  219. internalerror(2003031222);
  220. ops:=3;
  221. loadconst(0,aword(_op1));
  222. loadreg(1,_op2);
  223. loadconst(2,aword(_op3));
  224. end;
  225. constructor taicpu.op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  226. begin
  227. inherited create(op);
  228. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  229. internalerror(2003031223);
  230. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  231. internalerror(2003031224);
  232. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  233. internalerror(2003031225);
  234. if (_op4.enum = R_INTREGISTER) and (_op4.number = NR_NO) then
  235. internalerror(2003031226);
  236. ops:=4;
  237. loadreg(0,_op1);
  238. loadreg(1,_op2);
  239. loadreg(2,_op3);
  240. loadreg(3,_op4);
  241. end;
  242. constructor taicpu.op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  243. begin
  244. inherited create(op);
  245. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  246. internalerror(2003031227);
  247. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  248. internalerror(2003031228);
  249. if (_op4.enum = R_INTREGISTER) and (_op4.number = NR_NO) then
  250. internalerror(2003031229);
  251. ops:=4;
  252. loadreg(0,_op1);
  253. loadbool(1,_op2);
  254. loadreg(2,_op3);
  255. loadreg(3,_op4);
  256. end;
  257. constructor taicpu.op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  258. begin
  259. inherited create(op);
  260. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  261. internalerror(2003031230);
  262. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  263. internalerror(2003031231);
  264. ops:=4;
  265. loadreg(0,_op1);
  266. loadbool(0,_op2);
  267. loadreg(0,_op3);
  268. loadconst(0,cardinal(_op4));
  269. end;
  270. constructor taicpu.op_reg_reg_reg_const_const(op : tasmop;_op1,_op2,_op3 : tregister;_op4,_op5 : Longint);
  271. begin
  272. inherited create(op);
  273. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  274. internalerror(2003031232);
  275. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  276. internalerror(2003031233);
  277. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  278. internalerror(2003031233);
  279. ops:=5;
  280. loadreg(0,_op1);
  281. loadreg(1,_op2);
  282. loadreg(2,_op3);
  283. loadconst(3,cardinal(_op4));
  284. loadconst(4,cardinal(_op5));
  285. end;
  286. constructor taicpu.op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  287. begin
  288. inherited create(op);
  289. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  290. internalerror(2003031232);
  291. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  292. internalerror(2003031233);
  293. ops:=5;
  294. loadreg(0,_op1);
  295. loadreg(1,_op2);
  296. loadconst(2,aword(_op3));
  297. loadconst(3,cardinal(_op4));
  298. loadconst(4,cardinal(_op5));
  299. end;
  300. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  301. begin
  302. inherited create(op);
  303. condition:=cond;
  304. ops:=1;
  305. loadsymbol(0,_op1,0);
  306. end;
  307. constructor taicpu.op_const_const_sym(op : tasmop;_op1,_op2 : longint; _op3: tasmsymbol);
  308. begin
  309. inherited create(op);
  310. ops:=3;
  311. loadconst(0,aword(_op1));
  312. loadconst(1,aword(_op2));
  313. loadsymbol(2,_op3,0);
  314. end;
  315. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  316. begin
  317. inherited create(op);
  318. ops:=1;
  319. loadsymbol(0,_op1,0);
  320. end;
  321. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  322. begin
  323. inherited create(op);
  324. ops:=1;
  325. loadsymbol(0,_op1,_op1ofs);
  326. end;
  327. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  328. begin
  329. inherited create(op);
  330. ops:=2;
  331. loadreg(0,_op1);
  332. loadsymbol(1,_op2,_op2ofs);
  333. end;
  334. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  335. begin
  336. inherited create(op);
  337. ops:=2;
  338. loadsymbol(0,_op1,_op1ofs);
  339. loadref(1,_op2);
  340. end;
  341. { ****************************** newra stuff *************************** }
  342. function taicpu.is_nop: boolean;
  343. begin
  344. { we don't insert any more nops than necessary }
  345. is_nop :=
  346. ((opcode=A_MR) and (oper[0].typ=top_reg) and (oper[1].typ=top_reg) and (oper[0].reg.number=oper[1].reg.number));
  347. end;
  348. function taicpu.is_move:boolean;
  349. begin
  350. is_move := (opcode = A_MR) or
  351. (opcode = A_EXTSB) or
  352. (opcode = A_EXTSH) or
  353. ((opcode = A_RLWINM) and
  354. (oper[3].val = 0) and
  355. (oper[5].val = 31) and
  356. (oper[4].val in [31-8+1,31-16+1]));
  357. end;
  358. function taicpu.spill_registers(list:Taasmoutput;
  359. rgget:Trggetproc;
  360. rgunget:Trgungetproc;
  361. r:Tsupregset;
  362. var unusedregsint:Tsupregset;
  363. const spilltemplist:Tspill_temp_list): boolean;
  364. function decode_loadstore(op: tasmop; var counterpart: tasmop; var wasload: boolean): boolean;
  365. begin
  366. result := true;
  367. wasload := true;
  368. case op of
  369. A_LBZ:
  370. begin
  371. counterpart := A_STB;
  372. end;
  373. A_LBZX:
  374. begin
  375. counterpart := A_STBX;
  376. end;
  377. A_LHZ,A_LHA:
  378. begin
  379. counterpart := A_STH;
  380. end;
  381. A_LHZX,A_LHAX:
  382. begin
  383. counterpart := A_STHX;
  384. end;
  385. A_LWZ:
  386. begin
  387. counterpart := A_STW;
  388. end;
  389. A_LWZX:
  390. begin
  391. counterpart := A_STWX;
  392. end;
  393. A_STB:
  394. begin
  395. counterpart := A_LBZ;
  396. wasload := false;
  397. end;
  398. A_STBX:
  399. begin
  400. counterpart := A_LBZX;
  401. wasload := false;
  402. end;
  403. A_STH:
  404. begin
  405. counterpart := A_LHZ;
  406. wasload := false;
  407. end;
  408. A_STHX:
  409. begin
  410. counterpart := A_LHZX;
  411. wasload := false;
  412. end;
  413. A_STW:
  414. begin
  415. counterpart := A_LWZ;
  416. wasload := false;
  417. end;
  418. A_STWX:
  419. begin
  420. counterpart := A_LWZX;
  421. wasload := false;
  422. end;
  423. A_LBZU,A_LBZUX,A_LHZU,A_LHZUX,A_LHAU,A_LHAUX,
  424. A_LWZU,A_LWZUX,A_STBU,A_STBUX,A_STHU,A_STHUX,
  425. A_STWU,A_STWUX:
  426. internalerror(2003070602);
  427. else
  428. result := false;
  429. end;
  430. end;
  431. var i:byte;
  432. supreg, reg1, reg2, reg3: Tsuperregister;
  433. helpreg:Tregister;
  434. helpins:Taicpu;
  435. op:Tasmop;
  436. pos:Tai;
  437. wasload: boolean;
  438. begin
  439. spill_registers:=false;
  440. if (ops = 2) and
  441. (oper[1].typ=top_ref) and
  442. { oper[1] can also be ref in case of "lis r3,symbol@ha" or so }
  443. decode_loadstore(opcode,op,wasload) then
  444. begin
  445. { the register that's being stored/loaded }
  446. supreg:=oper[0].reg.number shr 8;
  447. if supreg in r then
  448. begin
  449. // Example:
  450. // l?? r20d, 8(r1) ; r20d must be spilled into -60(r1)
  451. //
  452. // Change into:
  453. //
  454. // l?? r21d, 8(r1)
  455. // st? r21d, -60(r1)
  456. //
  457. // And:
  458. //
  459. // st? r20d, 8(r1) ; r20d must be spilled into -60(r1)
  460. //
  461. // Change into:
  462. //
  463. // l?? r21d, -60(r1)
  464. // st? r21d, 8(r1)
  465. pos := get_insert_pos(Tai(previous),oper[0].reg.number shr 8,
  466. oper[1].ref^.base.number shr 8,oper[1].ref^.index.number shr 8,unusedregsint);
  467. rgget(list,pos,0,helpreg);
  468. spill_registers := true;
  469. if wasload then
  470. begin
  471. helpins := taicpu.op_reg_ref(opcode,helpreg,oper[1].ref^);
  472. loadref(1,spilltemplist[supreg]);
  473. opcode := op;
  474. end
  475. else
  476. helpins := taicpu.op_reg_ref(op,helpreg,spilltemplist[supreg]);
  477. if pos=nil then
  478. list.insertafter(helpins,list.first)
  479. else
  480. list.insertafter(helpins,pos.next);
  481. loadreg(0,helpreg);
  482. rgunget(list,helpins,helpreg);
  483. forward_allocation(tai(helpins.next),unusedregsint);
  484. {
  485. writeln('spilling!');
  486. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  487. }
  488. end;
  489. { now the registers used in the reference }
  490. { a) base }
  491. supreg := oper[1].ref^.base.number shr 8;
  492. if supreg in r then
  493. begin
  494. if wasload then
  495. pos:=get_insert_pos(Tai(previous),oper[1].ref^.index.number shr 8,oper[0].reg.number shr 8,0,unusedregsint)
  496. else
  497. pos:=get_insert_pos(Tai(previous),oper[1].ref^.index.number shr 8,0,0,unusedregsint);
  498. rgget(list,pos,0,helpreg);
  499. spill_registers:=true;
  500. helpins:=Taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  501. if pos=nil then
  502. list.insertafter(helpins,list.first)
  503. else
  504. list.insertafter(helpins,pos.next);
  505. oper[1].ref^.base:=helpreg;
  506. rgunget(list,helpins,helpreg);
  507. forward_allocation(Tai(helpins.next),unusedregsint);
  508. {
  509. writeln('spilling!');
  510. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  511. }
  512. end;
  513. { b) index }
  514. supreg := oper[1].ref^.index.number shr 8;
  515. if supreg in r then
  516. begin
  517. if wasload then
  518. pos:=get_insert_pos(Tai(previous),oper[1].ref^.base.number shr 8,oper[0].reg.number shr 8,0,unusedregsint)
  519. else
  520. pos:=get_insert_pos(Tai(previous),oper[1].ref^.base.number shr 8,0,0,unusedregsint);
  521. rgget(list,pos,0,helpreg);
  522. spill_registers:=true;
  523. helpins:=Taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  524. if pos=nil then
  525. list.insertafter(helpins,list.first)
  526. else
  527. list.insertafter(helpins,pos.next);
  528. oper[1].ref^.index:=helpreg;
  529. rgunget(list,helpins,helpreg);
  530. forward_allocation(Tai(helpins.next),unusedregsint);
  531. {
  532. writeln('spilling!');
  533. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  534. }
  535. end;
  536. { load/store is done }
  537. exit;
  538. end;
  539. { all other instructions the compiler generates are the same (I hope): }
  540. { operand 0 is a register and is the destination, the others are sources }
  541. { and can be either registers or constants }
  542. { exception: branches (is_jmp isn't always set for them) }
  543. if oper[0].typ <> top_reg then
  544. exit;
  545. reg1 := oper[0].reg.number shr 8;
  546. if oper[1].typ = top_reg then
  547. reg2 := oper[1].reg.number shr 8
  548. else
  549. reg2 := 0;
  550. if (ops >= 3) and
  551. (oper[2].typ = top_reg) then
  552. reg3 := oper[2].reg.number shr 8
  553. else
  554. reg3 := 0;
  555. supreg:=reg1;
  556. if supreg in r then
  557. begin
  558. // Example:
  559. // add r20d, r21d, r22d ; r20d must be spilled into -60(r1)
  560. //
  561. // Change into:
  562. //
  563. // lwz r23d, -60(r1)
  564. // add r23d, r21d, r22d
  565. // stw r23d, -60(r1)
  566. pos := get_insert_pos(Tai(previous),reg1,reg2,reg3,unusedregsint);
  567. rgget(list,pos,0,helpreg);
  568. spill_registers := true;
  569. helpins := taicpu.op_reg_ref(A_STW,helpreg,spilltemplist[supreg]);
  570. list.insertafter(helpins,self);
  571. helpins := taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  572. if pos=nil then
  573. list.insertafter(helpins,list.first)
  574. else
  575. list.insertafter(helpins,pos.next);
  576. loadreg(0,helpreg);
  577. rgunget(list,helpins,helpreg);
  578. forward_allocation(tai(helpins.next),unusedregsint);
  579. {
  580. writeln('spilling!');
  581. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  582. }
  583. end;
  584. for i := 1 to 2 do
  585. if (oper[i].typ = top_reg) then
  586. begin
  587. supreg:=oper[i].reg.number shr 8;
  588. if supreg in r then
  589. begin
  590. // Example:
  591. // add r20d, r21d, r22d ; r20d must be spilled into -60(r1)
  592. //
  593. // Change into:
  594. //
  595. // lwz r23d, -60(r1)
  596. // add r23d, r21d, r22d
  597. // stw r23d, -60(r1)
  598. pos := get_insert_pos(Tai(previous),reg1,reg2,reg3,unusedregsint);
  599. rgget(list,pos,0,helpreg);
  600. spill_registers := true;
  601. helpins := taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  602. if pos=nil then
  603. list.insertafter(helpins,list.first)
  604. else
  605. list.insertafter(helpins,pos.next);
  606. loadreg(i,helpreg);
  607. rgunget(list,helpins,helpreg);
  608. forward_allocation(tai(helpins.next),unusedregsint);
  609. {
  610. writeln('spilling!');
  611. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  612. }
  613. end;
  614. end;
  615. end;
  616. procedure InitAsm;
  617. begin
  618. end;
  619. procedure DoneAsm;
  620. begin
  621. end;
  622. end.
  623. {
  624. $Log$
  625. Revision 1.16 2003-09-03 15:55:01 peter
  626. * NEWRA branch merged
  627. Revision 1.15.2.1 2003/08/31 21:08:16 peter
  628. * first batch of sparc fixes
  629. Revision 1.15 2003/08/18 21:27:00 jonas
  630. * some newra optimizations (eliminate lots of moves between registers)
  631. Revision 1.14 2003/08/17 16:53:19 jonas
  632. * fixed compilation of ppc compiler with -dnewra
  633. Revision 1.13 2003/08/11 21:18:20 peter
  634. * start of sparc support for newra
  635. Revision 1.12 2002/09/30 23:16:49 jonas
  636. * is_nop() now identifies "mr rA,rA" instructions for removal
  637. Revision 1.11 2003/07/23 10:58:06 jonas
  638. - disabled some debugging code
  639. Revision 1.10 2003/07/06 21:26:06 jonas
  640. * committed wrong file previously :(
  641. Revision 1.8 2003/06/14 22:32:43 jonas
  642. * ppc compiles with -dnewra, haven't tried to compile anything with it
  643. yet though
  644. Revision 1.7 2003/06/14 14:53:50 jonas
  645. * fixed newra cycle for x86
  646. * added constants for indicating source and destination operands of the
  647. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  648. Revision 1.6 2003/05/11 11:08:25 jonas
  649. + op_reg_reg_reg_const_const (for rlwnm)
  650. Revision 1.5 2003/03/12 22:43:38 jonas
  651. * more powerpc and generic fixes related to the new register allocator
  652. Revision 1.4 2002/12/14 15:02:03 carl
  653. * maxoperands -> max_operands (for portability in rautils.pas)
  654. * fix some range-check errors with loadconst
  655. + add ncgadd unit to m68k
  656. * some bugfix of a_param_reg with LOC_CREFERENCE
  657. Revision 1.3 2002/09/17 18:26:02 jonas
  658. - removed taicpu.destroy, its job is already handled by
  659. taicpu_abstract.destroy() and this caused heap corruption
  660. Revision 1.2 2002/07/26 11:19:57 jonas
  661. * fixed range errors
  662. Revision 1.1 2002/07/07 09:44:31 florian
  663. * powerpc target fixed, very simple units can be compiled
  664. Revision 1.8 2002/05/18 13:34:26 peter
  665. * readded missing revisions
  666. Revision 1.7 2002/05/16 19:46:53 carl
  667. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  668. + try to fix temp allocation (still in ifdef)
  669. + generic constructor calls
  670. + start of tassembler / tmodulebase class cleanup
  671. Revision 1.4 2002/05/13 19:52:46 peter
  672. * a ppcppc can be build again
  673. }