aasmcpu.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  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 := false;
  346. end;
  347. function taicpu.is_move:boolean;
  348. begin
  349. is_move := opcode = A_MR;
  350. end;
  351. function taicpu.spill_registers(list:Taasmoutput;
  352. rgget:Trggetproc;
  353. rgunget:Trgungetproc;
  354. r:Tsupregset;
  355. var unusedregsint:Tsupregset;
  356. const spilltemplist:Tspill_temp_list): boolean;
  357. function get_insert_pos(p:Tai;huntfor1,huntfor2,huntfor3:Tsuperregister):Tai;
  358. var back:Tsupregset;
  359. begin
  360. back:=unusedregsint;
  361. get_insert_pos:=p;
  362. while (p<>nil) and (p.typ=ait_regalloc) do
  363. begin
  364. {Rewind the register allocation.}
  365. if Tai_regalloc(p).allocation then
  366. include(unusedregsint,Tai_regalloc(p).reg.number shr 8)
  367. else
  368. begin
  369. exclude(unusedregsint,Tai_regalloc(p).reg.number shr 8);
  370. if Tai_regalloc(p).reg.number shr 8=huntfor1 then
  371. begin
  372. get_insert_pos:=Tai(p.previous);
  373. back:=unusedregsint;
  374. end;
  375. if Tai_regalloc(p).reg.number shr 8=huntfor2 then
  376. begin
  377. get_insert_pos:=Tai(p.previous);
  378. back:=unusedregsint;
  379. end;
  380. if Tai_regalloc(p).reg.number shr 8=huntfor3 then
  381. begin
  382. get_insert_pos:=Tai(p.previous);
  383. back:=unusedregsint;
  384. end;
  385. end;
  386. p:=Tai(p.previous);
  387. end;
  388. unusedregsint:=back;
  389. end;
  390. procedure forward_allocation(p:Tai);
  391. begin
  392. {Forward the register allocation again.}
  393. while (p<>self) do
  394. begin
  395. if p.typ<>ait_regalloc then
  396. internalerror(200305311);
  397. if Tai_regalloc(p).allocation then
  398. exclude(unusedregsint,Tai_regalloc(p).reg.number shr 8)
  399. else
  400. include(unusedregsint,Tai_regalloc(p).reg.number shr 8);
  401. p:=Tai(p.next);
  402. end;
  403. end;
  404. function decode_loadstore(op: tasmop; var counterpart: tasmop; wasload: boolean): boolean;
  405. begin
  406. result := true;
  407. wasload := true;
  408. case op of
  409. A_LBZ:
  410. begin
  411. counterpart := A_STB;
  412. end;
  413. A_LBZX:
  414. begin
  415. counterpart := A_STBX;
  416. end;
  417. A_LHZ,A_LHA:
  418. begin
  419. counterpart := A_STH;
  420. end;
  421. A_LHZX,A_LHAX:
  422. begin
  423. counterpart := A_STHX;
  424. end;
  425. A_LWZ:
  426. begin
  427. counterpart := A_STW;
  428. end;
  429. A_LWZX:
  430. begin
  431. counterpart := A_STWX;
  432. end;
  433. A_STB:
  434. begin
  435. counterpart := A_LBZ;
  436. wasload := false;
  437. end;
  438. A_STBX:
  439. begin
  440. counterpart := A_LBZX;
  441. wasload := false;
  442. end;
  443. A_STH:
  444. begin
  445. counterpart := A_LHZ;
  446. wasload := false;
  447. end;
  448. A_STHX:
  449. begin
  450. counterpart := A_LHZX;
  451. wasload := false;
  452. end;
  453. A_STW:
  454. begin
  455. counterpart := A_LWZ;
  456. wasload := false;
  457. end;
  458. A_STWX:
  459. begin
  460. counterpart := A_LWZX;
  461. wasload := false;
  462. end;
  463. A_LBZU,A_LBZUX,A_LHZU,A_LHZUX,A_LHAU,A_LHAUX,
  464. A_LWZU,A_LWZUX,A_STBU,A_STBUX,A_STHU,A_STHUX,
  465. A_STWU,A_STWUX:
  466. internalerror(2003070602);
  467. else
  468. result := false;
  469. end;
  470. end;
  471. var i:byte;
  472. supreg, reg1, reg2, reg3: Tsuperregister;
  473. helpreg:Tregister;
  474. helpins:Taicpu;
  475. op:Tasmop;
  476. pos:Tai;
  477. wasload: boolean;
  478. begin
  479. spill_registers:=false;
  480. if (ops = 2) and
  481. (oper[1].typ=top_ref) and
  482. { oper[1] can also be ref in case of "lis r3,symbol@ha" or so }
  483. decode_loadstore(opcode,op,wasload) then
  484. begin
  485. { the register that's being stored/loaded }
  486. supreg:=oper[0].reg.number shr 8;
  487. if supreg in r then
  488. begin
  489. // Example:
  490. // l?? r20d, 8(r1) ; r20d must be spilled into -60(r1)
  491. //
  492. // Change into:
  493. //
  494. // l?? r21d, 8(r1)
  495. // st? r21d, -60(r1)
  496. //
  497. // And:
  498. //
  499. // st? r20d, 8(r1) ; r20d must be spilled into -60(r1)
  500. //
  501. // Change into:
  502. //
  503. // l?? r21d, -60(r1)
  504. // st? r21d, 8(r1)
  505. pos := get_insert_pos(Tai(previous),oper[0].reg.number shr 8,
  506. oper[1].ref^.base.number shr 8,oper[1].ref^.index.number shr 8);
  507. rgget(list,pos,0,helpreg);
  508. spill_registers := true;
  509. if wasload then
  510. begin
  511. helpins := taicpu.op_reg_ref(opcode,helpreg,oper[1].ref^);
  512. loadref(1,spilltemplist[supreg]);
  513. opcode := op;
  514. end
  515. else
  516. helpins := taicpu.op_reg_ref(op,helpreg,spilltemplist[supreg]);
  517. if pos=nil then
  518. list.insertafter(helpins,list.first)
  519. else
  520. list.insertafter(helpins,pos.next);
  521. loadreg(0,helpreg);
  522. rgunget(list,helpins,helpreg);
  523. forward_allocation(tai(helpins.next));
  524. {
  525. writeln('spilling!');
  526. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  527. }
  528. end;
  529. { now the registers used in the reference }
  530. { a) base }
  531. supreg := oper[1].ref^.base.number shr 8;
  532. if supreg in r then
  533. begin
  534. if wasload then
  535. pos:=get_insert_pos(Tai(previous),oper[1].ref^.index.number shr 8,oper[0].reg.number shr 8,0)
  536. else
  537. pos:=get_insert_pos(Tai(previous),oper[1].ref^.index.number shr 8,0,0);
  538. rgget(list,pos,0,helpreg);
  539. spill_registers:=true;
  540. helpins:=Taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  541. if pos=nil then
  542. list.insertafter(helpins,list.first)
  543. else
  544. list.insertafter(helpins,pos.next);
  545. oper[1].ref^.base:=helpreg;
  546. rgunget(list,helpins,helpreg);
  547. forward_allocation(Tai(helpins.next));
  548. {
  549. writeln('spilling!');
  550. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  551. }
  552. end;
  553. { b) index }
  554. supreg := oper[1].ref^.index.number shr 8;
  555. if supreg in r then
  556. begin
  557. if wasload then
  558. pos:=get_insert_pos(Tai(previous),oper[1].ref^.base.number shr 8,oper[0].reg.number shr 8,0)
  559. else
  560. pos:=get_insert_pos(Tai(previous),oper[1].ref^.base.number shr 8,0,0);
  561. rgget(list,pos,0,helpreg);
  562. spill_registers:=true;
  563. helpins:=Taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  564. if pos=nil then
  565. list.insertafter(helpins,list.first)
  566. else
  567. list.insertafter(helpins,pos.next);
  568. oper[1].ref^.index:=helpreg;
  569. rgunget(list,helpins,helpreg);
  570. forward_allocation(Tai(helpins.next));
  571. {
  572. writeln('spilling!');
  573. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  574. }
  575. end;
  576. { load/store is done }
  577. exit;
  578. end;
  579. { all other instructions the compiler generates are the same (I hope): }
  580. { operand 0 is a register and is the destination, the others are sources }
  581. { and can be either registers or constants }
  582. { exception: branches (is_jmp isn't always set for them) }
  583. if oper[0].typ <> top_reg then
  584. exit;
  585. reg1 := oper[0].reg.number shr 8;
  586. if oper[1].typ = top_reg then
  587. reg2 := oper[1].reg.number shr 8
  588. else
  589. reg2 := 0;
  590. if (ops >= 3) and
  591. (oper[2].typ = top_reg) then
  592. reg3 := oper[2].reg.number shr 8
  593. else
  594. reg3 := 0;
  595. supreg:=reg1;
  596. if supreg in r then
  597. begin
  598. // Example:
  599. // add r20d, r21d, r22d ; r20d must be spilled into -60(r1)
  600. //
  601. // Change into:
  602. //
  603. // lwz r23d, -60(r1)
  604. // add r23d, r21d, r22d
  605. // stw r23d, -60(r1)
  606. pos := get_insert_pos(Tai(previous),reg1,reg2,reg3);
  607. rgget(list,pos,0,helpreg);
  608. spill_registers := true;
  609. helpins := taicpu.op_reg_ref(A_STW,helpreg,spilltemplist[supreg]);
  610. list.insertafter(helpins,self);
  611. helpins := taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  612. if pos=nil then
  613. list.insertafter(helpins,list.first)
  614. else
  615. list.insertafter(helpins,pos.next);
  616. loadreg(0,helpreg);
  617. rgunget(list,helpins,helpreg);
  618. forward_allocation(tai(helpins.next));
  619. {
  620. writeln('spilling!');
  621. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  622. }
  623. end;
  624. for i := 1 to 2 do
  625. if (oper[i].typ = top_reg) then
  626. begin
  627. supreg:=oper[i].reg.number;
  628. if supreg in r then
  629. begin
  630. // Example:
  631. // add r20d, r21d, r22d ; r20d must be spilled into -60(r1)
  632. //
  633. // Change into:
  634. //
  635. // lwz r23d, -60(r1)
  636. // add r23d, r21d, r22d
  637. // stw r23d, -60(r1)
  638. pos := get_insert_pos(Tai(previous),reg1,reg2,reg3);
  639. rgget(list,pos,0,helpreg);
  640. spill_registers := true;
  641. helpins := taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  642. if pos=nil then
  643. list.insertafter(helpins,list.first)
  644. else
  645. list.insertafter(helpins,pos.next);
  646. loadreg(i,helpreg);
  647. rgunget(list,helpins,helpreg);
  648. forward_allocation(tai(helpins.next));
  649. {
  650. writeln('spilling!');
  651. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  652. }
  653. end;
  654. end;
  655. end;
  656. procedure InitAsm;
  657. begin
  658. end;
  659. procedure DoneAsm;
  660. begin
  661. end;
  662. end.
  663. {
  664. $Log$
  665. Revision 1.11 2003-07-23 10:58:06 jonas
  666. - disabled some debugging code
  667. Revision 1.10 2003/07/06 21:26:06 jonas
  668. * committed wrong file previously :(
  669. Revision 1.8 2003/06/14 22:32:43 jonas
  670. * ppc compiles with -dnewra, haven't tried to compile anything with it
  671. yet though
  672. Revision 1.7 2003/06/14 14:53:50 jonas
  673. * fixed newra cycle for x86
  674. * added constants for indicating source and destination operands of the
  675. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  676. Revision 1.6 2003/05/11 11:08:25 jonas
  677. + op_reg_reg_reg_const_const (for rlwnm)
  678. Revision 1.5 2003/03/12 22:43:38 jonas
  679. * more powerpc and generic fixes related to the new register allocator
  680. Revision 1.4 2002/12/14 15:02:03 carl
  681. * maxoperands -> max_operands (for portability in rautils.pas)
  682. * fix some range-check errors with loadconst
  683. + add ncgadd unit to m68k
  684. * some bugfix of a_param_reg with LOC_CREFERENCE
  685. Revision 1.3 2002/09/17 18:26:02 jonas
  686. - removed taicpu.destroy, its job is already handled by
  687. taicpu_abstract.destroy() and this caused heap corruption
  688. Revision 1.2 2002/07/26 11:19:57 jonas
  689. * fixed range errors
  690. Revision 1.1 2002/07/07 09:44:31 florian
  691. * powerpc target fixed, very simple units can be compiled
  692. Revision 1.8 2002/05/18 13:34:26 peter
  693. * readded missing revisions
  694. Revision 1.7 2002/05/16 19:46:53 carl
  695. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  696. + try to fix temp allocation (still in ifdef)
  697. + generic constructor calls
  698. + start of tassembler / tmodulebase class cleanup
  699. Revision 1.4 2002/05/13 19:52:46 peter
  700. * a ppcppc can be build again
  701. }