aasmcpu.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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. {$ifdef newra}
  62. function spill_registers(list:Taasmoutput;
  63. rgget:Trggetproc;
  64. rgunget:Trgungetproc;
  65. r:Tsupregset;
  66. var unusedregsint:Tsupregset;
  67. const spilltemplist:Tspill_temp_list):boolean; override;
  68. {$endif}
  69. end;
  70. tai_align = class(tai_align_abstract)
  71. { nothing to add }
  72. end;
  73. procedure InitAsm;
  74. procedure DoneAsm;
  75. implementation
  76. uses cutils,rgobj;
  77. {*****************************************************************************
  78. taicpu Constructors
  79. *****************************************************************************}
  80. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  81. begin
  82. if opidx>=ops then
  83. ops:=opidx+1;
  84. with oper[opidx] do
  85. begin
  86. if typ=top_ref then
  87. dispose(ref);
  88. b:=_b;
  89. typ:=top_bool;
  90. end;
  91. end;
  92. constructor taicpu.op_none(op : tasmop);
  93. begin
  94. inherited create(op);
  95. end;
  96. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  97. begin
  98. inherited create(op);
  99. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  100. internalerror(2003031207);
  101. ops:=1;
  102. loadreg(0,_op1);
  103. end;
  104. constructor taicpu.op_const(op : tasmop;_op1 : longint);
  105. begin
  106. inherited create(op);
  107. ops:=1;
  108. loadconst(0,aword(_op1));
  109. end;
  110. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  111. begin
  112. inherited create(op);
  113. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  114. internalerror(2003031205);
  115. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  116. internalerror(2003031206);
  117. ops:=2;
  118. loadreg(0,_op1);
  119. loadreg(1,_op2);
  120. end;
  121. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  122. begin
  123. inherited create(op);
  124. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  125. internalerror(2003031208);
  126. ops:=2;
  127. loadreg(0,_op1);
  128. loadconst(1,aword(_op2));
  129. end;
  130. constructor taicpu.op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  131. begin
  132. inherited create(op);
  133. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  134. internalerror(2003031209);
  135. ops:=2;
  136. loadconst(0,aword(_op1));
  137. loadreg(1,_op2);
  138. end;
  139. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  140. begin
  141. inherited create(op);
  142. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  143. internalerror(2003031210);
  144. ops:=2;
  145. loadreg(0,_op1);
  146. loadref(1,_op2);
  147. end;
  148. constructor taicpu.op_const_const(op : tasmop;_op1,_op2 : longint);
  149. begin
  150. inherited create(op);
  151. ops:=2;
  152. loadconst(0,aword(_op1));
  153. loadconst(1,aword(_op2));
  154. end;
  155. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  156. begin
  157. inherited create(op);
  158. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  159. internalerror(2003031211);
  160. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  161. internalerror(2003031212);
  162. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  163. internalerror(2003031213);
  164. ops:=3;
  165. loadreg(0,_op1);
  166. loadreg(1,_op2);
  167. loadreg(2,_op3);
  168. end;
  169. constructor taicpu.op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  170. begin
  171. inherited create(op);
  172. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  173. internalerror(2003031214);
  174. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  175. internalerror(2003031215);
  176. ops:=3;
  177. loadreg(0,_op1);
  178. loadreg(1,_op2);
  179. loadconst(2,aword(_op3));
  180. end;
  181. constructor taicpu.op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  182. begin
  183. inherited create(op);
  184. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  185. internalerror(2003031216);
  186. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  187. internalerror(2003031217);
  188. ops:=3;
  189. loadreg(0,_op1);
  190. loadreg(1,_op2);
  191. loadsymbol(0,_op3,_op3ofs);
  192. end;
  193. constructor taicpu.op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  194. begin
  195. inherited create(op);
  196. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  197. internalerror(2003031218);
  198. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  199. internalerror(2003031219);
  200. ops:=3;
  201. loadreg(0,_op1);
  202. loadreg(1,_op2);
  203. loadref(2,_op3);
  204. end;
  205. constructor taicpu.op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  206. begin
  207. inherited create(op);
  208. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  209. internalerror(2003031221);
  210. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  211. internalerror(2003031220);
  212. ops:=3;
  213. loadconst(0,aword(_op1));
  214. loadreg(1,_op2);
  215. loadreg(2,_op3);
  216. end;
  217. constructor taicpu.op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  218. begin
  219. inherited create(op);
  220. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  221. internalerror(2003031222);
  222. ops:=3;
  223. loadconst(0,aword(_op1));
  224. loadreg(1,_op2);
  225. loadconst(2,aword(_op3));
  226. end;
  227. constructor taicpu.op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  228. begin
  229. inherited create(op);
  230. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  231. internalerror(2003031223);
  232. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  233. internalerror(2003031224);
  234. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  235. internalerror(2003031225);
  236. if (_op4.enum = R_INTREGISTER) and (_op4.number = NR_NO) then
  237. internalerror(2003031226);
  238. ops:=4;
  239. loadreg(0,_op1);
  240. loadreg(1,_op2);
  241. loadreg(2,_op3);
  242. loadreg(3,_op4);
  243. end;
  244. constructor taicpu.op_reg_bool_reg_reg(op : tasmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  245. begin
  246. inherited create(op);
  247. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  248. internalerror(2003031227);
  249. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  250. internalerror(2003031228);
  251. if (_op4.enum = R_INTREGISTER) and (_op4.number = NR_NO) then
  252. internalerror(2003031229);
  253. ops:=4;
  254. loadreg(0,_op1);
  255. loadbool(1,_op2);
  256. loadreg(2,_op3);
  257. loadreg(3,_op4);
  258. end;
  259. constructor taicpu.op_reg_bool_reg_const(op : tasmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: longint);
  260. begin
  261. inherited create(op);
  262. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  263. internalerror(2003031230);
  264. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  265. internalerror(2003031231);
  266. ops:=4;
  267. loadreg(0,_op1);
  268. loadbool(0,_op2);
  269. loadreg(0,_op3);
  270. loadconst(0,cardinal(_op4));
  271. end;
  272. constructor taicpu.op_reg_reg_reg_const_const(op : tasmop;_op1,_op2,_op3 : tregister;_op4,_op5 : Longint);
  273. begin
  274. inherited create(op);
  275. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  276. internalerror(2003031232);
  277. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  278. internalerror(2003031233);
  279. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  280. internalerror(2003031233);
  281. ops:=5;
  282. loadreg(0,_op1);
  283. loadreg(1,_op2);
  284. loadreg(2,_op3);
  285. loadconst(3,cardinal(_op4));
  286. loadconst(4,cardinal(_op5));
  287. end;
  288. constructor taicpu.op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_op4,_op5 : Longint);
  289. begin
  290. inherited create(op);
  291. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  292. internalerror(2003031232);
  293. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  294. internalerror(2003031233);
  295. ops:=5;
  296. loadreg(0,_op1);
  297. loadreg(1,_op2);
  298. loadconst(2,aword(_op3));
  299. loadconst(3,cardinal(_op4));
  300. loadconst(4,cardinal(_op5));
  301. end;
  302. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  303. begin
  304. inherited create(op);
  305. condition:=cond;
  306. ops:=1;
  307. loadsymbol(0,_op1,0);
  308. end;
  309. constructor taicpu.op_const_const_sym(op : tasmop;_op1,_op2 : longint; _op3: tasmsymbol);
  310. begin
  311. inherited create(op);
  312. ops:=3;
  313. loadconst(0,aword(_op1));
  314. loadconst(1,aword(_op2));
  315. loadsymbol(2,_op3,0);
  316. end;
  317. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  318. begin
  319. inherited create(op);
  320. ops:=1;
  321. loadsymbol(0,_op1,0);
  322. end;
  323. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  324. begin
  325. inherited create(op);
  326. ops:=1;
  327. loadsymbol(0,_op1,_op1ofs);
  328. end;
  329. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  330. begin
  331. inherited create(op);
  332. ops:=2;
  333. loadreg(0,_op1);
  334. loadsymbol(1,_op2,_op2ofs);
  335. end;
  336. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  337. begin
  338. inherited create(op);
  339. ops:=2;
  340. loadsymbol(0,_op1,_op1ofs);
  341. loadref(1,_op2);
  342. end;
  343. { ****************************** newra stuff *************************** }
  344. function taicpu.is_nop: boolean;
  345. begin
  346. { we don't insert any more nops than necessary }
  347. is_nop :=
  348. ((opcode=A_MR) and (oper[0].typ=top_reg) and (oper[1].typ=top_reg) and (oper[0].reg.number=oper[1].reg.number));
  349. end;
  350. function taicpu.is_move:boolean;
  351. begin
  352. is_move := (opcode = A_MR) or
  353. (opcode = A_EXTSB) or
  354. (opcode = A_EXTSH) or
  355. ((opcode = A_RLWINM) and
  356. (oper[3].val = 0) and
  357. (oper[5].val = 31) and
  358. (oper[4].val in [31-8+1,31-16+1]));
  359. end;
  360. {$ifdef newra}
  361. function taicpu.spill_registers(list:Taasmoutput;
  362. rgget:Trggetproc;
  363. rgunget:Trgungetproc;
  364. r:Tsupregset;
  365. var unusedregsint:Tsupregset;
  366. const spilltemplist:Tspill_temp_list): boolean;
  367. function decode_loadstore(op: tasmop; var counterpart: tasmop; var wasload: boolean): boolean;
  368. begin
  369. result := true;
  370. wasload := true;
  371. case op of
  372. A_LBZ:
  373. begin
  374. counterpart := A_STB;
  375. end;
  376. A_LBZX:
  377. begin
  378. counterpart := A_STBX;
  379. end;
  380. A_LHZ,A_LHA:
  381. begin
  382. counterpart := A_STH;
  383. end;
  384. A_LHZX,A_LHAX:
  385. begin
  386. counterpart := A_STHX;
  387. end;
  388. A_LWZ:
  389. begin
  390. counterpart := A_STW;
  391. end;
  392. A_LWZX:
  393. begin
  394. counterpart := A_STWX;
  395. end;
  396. A_STB:
  397. begin
  398. counterpart := A_LBZ;
  399. wasload := false;
  400. end;
  401. A_STBX:
  402. begin
  403. counterpart := A_LBZX;
  404. wasload := false;
  405. end;
  406. A_STH:
  407. begin
  408. counterpart := A_LHZ;
  409. wasload := false;
  410. end;
  411. A_STHX:
  412. begin
  413. counterpart := A_LHZX;
  414. wasload := false;
  415. end;
  416. A_STW:
  417. begin
  418. counterpart := A_LWZ;
  419. wasload := false;
  420. end;
  421. A_STWX:
  422. begin
  423. counterpart := A_LWZX;
  424. wasload := false;
  425. end;
  426. A_LBZU,A_LBZUX,A_LHZU,A_LHZUX,A_LHAU,A_LHAUX,
  427. A_LWZU,A_LWZUX,A_STBU,A_STBUX,A_STHU,A_STHUX,
  428. A_STWU,A_STWUX:
  429. internalerror(2003070602);
  430. else
  431. result := false;
  432. end;
  433. end;
  434. var i:byte;
  435. supreg, reg1, reg2, reg3: Tsuperregister;
  436. helpreg:Tregister;
  437. helpins:Taicpu;
  438. op:Tasmop;
  439. pos:Tai;
  440. wasload: boolean;
  441. begin
  442. spill_registers:=false;
  443. if (ops = 2) and
  444. (oper[1].typ=top_ref) and
  445. { oper[1] can also be ref in case of "lis r3,symbol@ha" or so }
  446. decode_loadstore(opcode,op,wasload) then
  447. begin
  448. { the register that's being stored/loaded }
  449. supreg:=oper[0].reg.number shr 8;
  450. if supreg in r then
  451. begin
  452. // Example:
  453. // l?? r20d, 8(r1) ; r20d must be spilled into -60(r1)
  454. //
  455. // Change into:
  456. //
  457. // l?? r21d, 8(r1)
  458. // st? r21d, -60(r1)
  459. //
  460. // And:
  461. //
  462. // st? r20d, 8(r1) ; r20d must be spilled into -60(r1)
  463. //
  464. // Change into:
  465. //
  466. // l?? r21d, -60(r1)
  467. // st? r21d, 8(r1)
  468. pos := get_insert_pos(Tai(previous),oper[0].reg.number shr 8,
  469. oper[1].ref^.base.number shr 8,oper[1].ref^.index.number shr 8,unusedregsint);
  470. rgget(list,pos,0,helpreg);
  471. spill_registers := true;
  472. if wasload then
  473. begin
  474. helpins := taicpu.op_reg_ref(opcode,helpreg,oper[1].ref^);
  475. loadref(1,spilltemplist[supreg]);
  476. opcode := op;
  477. end
  478. else
  479. helpins := taicpu.op_reg_ref(op,helpreg,spilltemplist[supreg]);
  480. if pos=nil then
  481. list.insertafter(helpins,list.first)
  482. else
  483. list.insertafter(helpins,pos.next);
  484. loadreg(0,helpreg);
  485. rgunget(list,helpins,helpreg);
  486. forward_allocation(tai(helpins.next),unusedregsint);
  487. {
  488. writeln('spilling!');
  489. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  490. }
  491. end;
  492. { now the registers used in the reference }
  493. { a) base }
  494. supreg := oper[1].ref^.base.number shr 8;
  495. if supreg in r then
  496. begin
  497. if wasload then
  498. pos:=get_insert_pos(Tai(previous),oper[1].ref^.index.number shr 8,oper[0].reg.number shr 8,0,unusedregsint)
  499. else
  500. pos:=get_insert_pos(Tai(previous),oper[1].ref^.index.number shr 8,0,0,unusedregsint);
  501. rgget(list,pos,0,helpreg);
  502. spill_registers:=true;
  503. helpins:=Taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  504. if pos=nil then
  505. list.insertafter(helpins,list.first)
  506. else
  507. list.insertafter(helpins,pos.next);
  508. oper[1].ref^.base:=helpreg;
  509. rgunget(list,helpins,helpreg);
  510. forward_allocation(Tai(helpins.next),unusedregsint);
  511. {
  512. writeln('spilling!');
  513. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  514. }
  515. end;
  516. { b) index }
  517. supreg := oper[1].ref^.index.number shr 8;
  518. if supreg in r then
  519. begin
  520. if wasload then
  521. pos:=get_insert_pos(Tai(previous),oper[1].ref^.base.number shr 8,oper[0].reg.number shr 8,0,unusedregsint)
  522. else
  523. pos:=get_insert_pos(Tai(previous),oper[1].ref^.base.number shr 8,0,0,unusedregsint);
  524. rgget(list,pos,0,helpreg);
  525. spill_registers:=true;
  526. helpins:=Taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  527. if pos=nil then
  528. list.insertafter(helpins,list.first)
  529. else
  530. list.insertafter(helpins,pos.next);
  531. oper[1].ref^.index:=helpreg;
  532. rgunget(list,helpins,helpreg);
  533. forward_allocation(Tai(helpins.next),unusedregsint);
  534. {
  535. writeln('spilling!');
  536. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  537. }
  538. end;
  539. { load/store is done }
  540. exit;
  541. end;
  542. { all other instructions the compiler generates are the same (I hope): }
  543. { operand 0 is a register and is the destination, the others are sources }
  544. { and can be either registers or constants }
  545. { exception: branches (is_jmp isn't always set for them) }
  546. if oper[0].typ <> top_reg then
  547. exit;
  548. reg1 := oper[0].reg.number shr 8;
  549. if oper[1].typ = top_reg then
  550. reg2 := oper[1].reg.number shr 8
  551. else
  552. reg2 := 0;
  553. if (ops >= 3) and
  554. (oper[2].typ = top_reg) then
  555. reg3 := oper[2].reg.number shr 8
  556. else
  557. reg3 := 0;
  558. supreg:=reg1;
  559. if supreg in r then
  560. begin
  561. // Example:
  562. // add r20d, r21d, r22d ; r20d must be spilled into -60(r1)
  563. //
  564. // Change into:
  565. //
  566. // lwz r23d, -60(r1)
  567. // add r23d, r21d, r22d
  568. // stw r23d, -60(r1)
  569. pos := get_insert_pos(Tai(previous),reg1,reg2,reg3,unusedregsint);
  570. rgget(list,pos,0,helpreg);
  571. spill_registers := true;
  572. helpins := taicpu.op_reg_ref(A_STW,helpreg,spilltemplist[supreg]);
  573. list.insertafter(helpins,self);
  574. helpins := taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  575. if pos=nil then
  576. list.insertafter(helpins,list.first)
  577. else
  578. list.insertafter(helpins,pos.next);
  579. loadreg(0,helpreg);
  580. rgunget(list,helpins,helpreg);
  581. forward_allocation(tai(helpins.next),unusedregsint);
  582. {
  583. writeln('spilling!');
  584. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  585. }
  586. end;
  587. for i := 1 to 2 do
  588. if (oper[i].typ = top_reg) then
  589. begin
  590. supreg:=oper[i].reg.number shr 8;
  591. if supreg in r then
  592. begin
  593. // Example:
  594. // add r20d, r21d, r22d ; r20d must be spilled into -60(r1)
  595. //
  596. // Change into:
  597. //
  598. // lwz r23d, -60(r1)
  599. // add r23d, r21d, r22d
  600. // stw r23d, -60(r1)
  601. pos := get_insert_pos(Tai(previous),reg1,reg2,reg3,unusedregsint);
  602. rgget(list,pos,0,helpreg);
  603. spill_registers := true;
  604. helpins := taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  605. if pos=nil then
  606. list.insertafter(helpins,list.first)
  607. else
  608. list.insertafter(helpins,pos.next);
  609. loadreg(i,helpreg);
  610. rgunget(list,helpins,helpreg);
  611. forward_allocation(tai(helpins.next),unusedregsint);
  612. {
  613. writeln('spilling!');
  614. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  615. }
  616. end;
  617. end;
  618. end;
  619. {$endif newra}
  620. procedure InitAsm;
  621. begin
  622. end;
  623. procedure DoneAsm;
  624. begin
  625. end;
  626. end.
  627. {
  628. $Log$
  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. }