aasmcpu.pas 27 KB

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