aasmcpu.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. {
  2. $Id$
  3. Copyright (c) 2003 by Florian Klaempfl
  4. Contains the assembler object for the ARM
  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. procedure loadshifterop(opidx:longint;const so:tshifterop);
  33. constructor op_none(op : tasmop);
  34. constructor op_reg(op : tasmop;_op1 : tregister);
  35. constructor op_const(op : tasmop;_op1 : longint);
  36. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  37. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  38. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: longint);
  39. constructor op_const_reg(op:tasmop; _op1: longint; _op2: tregister);
  40. constructor op_const_const(op : tasmop;_op1,_op2 : longint);
  41. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  42. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: Longint);
  43. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  44. constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  45. constructor op_const_reg_reg(op : tasmop;_op1 : longint;_op2, _op3 : tregister);
  46. constructor op_const_reg_const(op : tasmop;_op1 : longint;_op2 : tregister;_op3 : longint);
  47. constructor op_reg_reg_shifterop(op : tasmop;_op1,_op2 : tregister;_op3 : tshifterop);
  48. constructor op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  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. function is_nop: boolean; override;
  59. function is_move:boolean; override;
  60. function spill_registers(list:Taasmoutput;
  61. rgget:Trggetproc;
  62. rgunget:Trgungetproc;
  63. r:Tsupregset;
  64. var unusedregsint:Tsupregset;
  65. const spilltemplist:Tspill_temp_list):boolean; override;
  66. end;
  67. tai_align = class(tai_align_abstract)
  68. { nothing to add }
  69. end;
  70. procedure InitAsm;
  71. procedure DoneAsm;
  72. implementation
  73. uses
  74. cutils,rgobj;
  75. procedure taicpu.loadshifterop(opidx:longint;const so:tshifterop);
  76. begin
  77. if opidx>=ops then
  78. ops:=opidx+1;
  79. with oper[opidx] do
  80. begin
  81. if typ<>top_shifterop then
  82. new(shifterop);
  83. shifterop^:=so;
  84. typ:=top_shifterop;
  85. end;
  86. end;
  87. {*****************************************************************************
  88. taicpu Constructors
  89. *****************************************************************************}
  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_shifterop(op : tasmop;_op1,_op2 : tregister;_op3 : tshifterop);
  226. begin
  227. inherited create(op);
  228. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  229. internalerror(200308233);
  230. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  231. internalerror(200308233);
  232. ops:=3;
  233. loadreg(0,_op1);
  234. loadreg(1,_op2);
  235. loadshifterop(2,_op3);
  236. end;
  237. constructor taicpu.op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  238. begin
  239. inherited create(op);
  240. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  241. internalerror(2003031223);
  242. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  243. internalerror(2003031224);
  244. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  245. internalerror(2003031225);
  246. if (_op4.enum = R_INTREGISTER) and (_op4.number = NR_NO) then
  247. internalerror(2003031226);
  248. ops:=4;
  249. loadreg(0,_op1);
  250. loadreg(1,_op2);
  251. loadreg(2,_op3);
  252. loadreg(3,_op4);
  253. end;
  254. constructor taicpu.op_reg_reg_reg_const_const(op : tasmop;_op1,_op2,_op3 : tregister;_op4,_op5 : Longint);
  255. begin
  256. inherited create(op);
  257. if (_op1.enum = R_INTREGISTER) and (_op1.number = NR_NO) then
  258. internalerror(2003031232);
  259. if (_op2.enum = R_INTREGISTER) and (_op2.number = NR_NO) then
  260. internalerror(2003031233);
  261. if (_op3.enum = R_INTREGISTER) and (_op3.number = NR_NO) then
  262. internalerror(2003031233);
  263. ops:=5;
  264. loadreg(0,_op1);
  265. loadreg(1,_op2);
  266. loadreg(2,_op3);
  267. loadconst(3,cardinal(_op4));
  268. loadconst(4,cardinal(_op5));
  269. end;
  270. constructor taicpu.op_reg_reg_const_const_const(op : tasmop;_op1,_op2 : tregister;_op3,_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. ops:=5;
  278. loadreg(0,_op1);
  279. loadreg(1,_op2);
  280. loadconst(2,aword(_op3));
  281. loadconst(3,cardinal(_op4));
  282. loadconst(4,cardinal(_op5));
  283. end;
  284. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  285. begin
  286. inherited create(op);
  287. condition:=cond;
  288. ops:=1;
  289. loadsymbol(0,_op1,0);
  290. end;
  291. constructor taicpu.op_const_const_sym(op : tasmop;_op1,_op2 : longint; _op3: tasmsymbol);
  292. begin
  293. inherited create(op);
  294. ops:=3;
  295. loadconst(0,aword(_op1));
  296. loadconst(1,aword(_op2));
  297. loadsymbol(2,_op3,0);
  298. end;
  299. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  300. begin
  301. inherited create(op);
  302. ops:=1;
  303. loadsymbol(0,_op1,0);
  304. end;
  305. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  306. begin
  307. inherited create(op);
  308. ops:=1;
  309. loadsymbol(0,_op1,_op1ofs);
  310. end;
  311. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  312. begin
  313. inherited create(op);
  314. ops:=2;
  315. loadreg(0,_op1);
  316. loadsymbol(1,_op2,_op2ofs);
  317. end;
  318. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  319. begin
  320. inherited create(op);
  321. ops:=2;
  322. loadsymbol(0,_op1,_op1ofs);
  323. loadref(1,_op2);
  324. end;
  325. { ****************************** newra stuff *************************** }
  326. function taicpu.is_nop: boolean;
  327. begin
  328. { we don't insert any more nops than necessary }
  329. is_nop := false;
  330. end;
  331. function taicpu.is_move:boolean;
  332. begin
  333. is_move := opcode = A_MOV;
  334. end;
  335. function taicpu.spill_registers(list:Taasmoutput;
  336. rgget:Trggetproc;
  337. rgunget:Trgungetproc;
  338. r:Tsupregset;
  339. var unusedregsint:Tsupregset;
  340. const spilltemplist:Tspill_temp_list): boolean;
  341. {$ifdef dummy}
  342. function get_insert_pos(p:Tai;huntfor1,huntfor2,huntfor3:Tsuperregister):Tai;
  343. var back:Tsupregset;
  344. begin
  345. back:=unusedregsint;
  346. get_insert_pos:=p;
  347. while (p<>nil) and (p.typ=ait_regalloc) do
  348. begin
  349. {Rewind the register allocation.}
  350. if Tai_regalloc(p).allocation then
  351. include(unusedregsint,Tai_regalloc(p).reg.number shr 8)
  352. else
  353. begin
  354. exclude(unusedregsint,Tai_regalloc(p).reg.number shr 8);
  355. if Tai_regalloc(p).reg.number shr 8=huntfor1 then
  356. begin
  357. get_insert_pos:=Tai(p.previous);
  358. back:=unusedregsint;
  359. end;
  360. if Tai_regalloc(p).reg.number shr 8=huntfor2 then
  361. begin
  362. get_insert_pos:=Tai(p.previous);
  363. back:=unusedregsint;
  364. end;
  365. if Tai_regalloc(p).reg.number shr 8=huntfor3 then
  366. begin
  367. get_insert_pos:=Tai(p.previous);
  368. back:=unusedregsint;
  369. end;
  370. end;
  371. p:=Tai(p.previous);
  372. end;
  373. unusedregsint:=back;
  374. end;
  375. procedure forward_allocation(p:Tai);
  376. begin
  377. {Forward the register allocation again.}
  378. while (p<>self) do
  379. begin
  380. if p.typ<>ait_regalloc then
  381. internalerror(200305311);
  382. if Tai_regalloc(p).allocation then
  383. exclude(unusedregsint,Tai_regalloc(p).reg.number shr 8)
  384. else
  385. include(unusedregsint,Tai_regalloc(p).reg.number shr 8);
  386. p:=Tai(p.next);
  387. end;
  388. end;
  389. function decode_loadstore(op: tasmop; var counterpart: tasmop; wasload: boolean): boolean;
  390. begin
  391. result := true;
  392. wasload := true;
  393. case op of
  394. A_LBZ:
  395. begin
  396. counterpart := A_STB;
  397. end;
  398. A_LBZX:
  399. begin
  400. counterpart := A_STBX;
  401. end;
  402. A_LHZ,A_LHA:
  403. begin
  404. counterpart := A_STH;
  405. end;
  406. A_LHZX,A_LHAX:
  407. begin
  408. counterpart := A_STHX;
  409. end;
  410. A_LWZ:
  411. begin
  412. counterpart := A_STW;
  413. end;
  414. A_LWZX:
  415. begin
  416. counterpart := A_STWX;
  417. end;
  418. A_STB:
  419. begin
  420. counterpart := A_LBZ;
  421. wasload := false;
  422. end;
  423. A_STBX:
  424. begin
  425. counterpart := A_LBZX;
  426. wasload := false;
  427. end;
  428. A_STH:
  429. begin
  430. counterpart := A_LHZ;
  431. wasload := false;
  432. end;
  433. A_STHX:
  434. begin
  435. counterpart := A_LHZX;
  436. wasload := false;
  437. end;
  438. A_STW:
  439. begin
  440. counterpart := A_LWZ;
  441. wasload := false;
  442. end;
  443. A_STWX:
  444. begin
  445. counterpart := A_LWZX;
  446. wasload := false;
  447. end;
  448. A_LBZU,A_LBZUX,A_LHZU,A_LHZUX,A_LHAU,A_LHAUX,
  449. A_LWZU,A_LWZUX,A_STBU,A_STBUX,A_STHU,A_STHUX,
  450. A_STWU,A_STWUX:
  451. internalerror(2003070602);
  452. else
  453. result := false;
  454. end;
  455. end;
  456. var i:byte;
  457. supreg, reg1, reg2, reg3: Tsuperregister;
  458. helpreg:Tregister;
  459. helpins:Taicpu;
  460. op:Tasmop;
  461. pos:Tai;
  462. wasload: boolean;
  463. begin
  464. spill_registers:=false;
  465. if (ops = 2) and
  466. (oper[1].typ=top_ref) and
  467. { oper[1] can also be ref in case of "lis r3,symbol@ha" or so }
  468. decode_loadstore(opcode,op,wasload) then
  469. begin
  470. { the register that's being stored/loaded }
  471. supreg:=oper[0].reg.number shr 8;
  472. if supreg in r then
  473. begin
  474. // Example:
  475. // l?? r20d, 8(r1) ; r20d must be spilled into -60(r1)
  476. //
  477. // Change into:
  478. //
  479. // l?? r21d, 8(r1)
  480. // st? r21d, -60(r1)
  481. //
  482. // And:
  483. //
  484. // st? r20d, 8(r1) ; r20d must be spilled into -60(r1)
  485. //
  486. // Change into:
  487. //
  488. // l?? r21d, -60(r1)
  489. // st? r21d, 8(r1)
  490. pos := get_insert_pos(Tai(previous),oper[0].reg.number shr 8,
  491. oper[1].ref^.base.number shr 8,oper[1].ref^.index.number shr 8);
  492. rgget(list,pos,0,helpreg);
  493. spill_registers := true;
  494. if wasload then
  495. begin
  496. helpins := taicpu.op_reg_ref(opcode,helpreg,oper[1].ref^);
  497. loadref(1,spilltemplist[supreg]);
  498. opcode := op;
  499. end
  500. else
  501. helpins := taicpu.op_reg_ref(op,helpreg,spilltemplist[supreg]);
  502. if pos=nil then
  503. list.insertafter(helpins,list.first)
  504. else
  505. list.insertafter(helpins,pos.next);
  506. loadreg(0,helpreg);
  507. rgunget(list,helpins,helpreg);
  508. forward_allocation(tai(helpins.next));
  509. {$ifdef debugra}
  510. writeln('spilling!');
  511. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  512. {$endif debugra}
  513. end;
  514. { now the registers used in the reference }
  515. { a) base }
  516. supreg := oper[1].ref^.base.number shr 8;
  517. if supreg in r then
  518. begin
  519. if wasload then
  520. pos:=get_insert_pos(Tai(previous),oper[1].ref^.index.number shr 8,oper[0].reg.number shr 8,0)
  521. else
  522. pos:=get_insert_pos(Tai(previous),oper[1].ref^.index.number shr 8,0,0);
  523. rgget(list,pos,0,helpreg);
  524. spill_registers:=true;
  525. helpins:=Taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  526. if pos=nil then
  527. list.insertafter(helpins,list.first)
  528. else
  529. list.insertafter(helpins,pos.next);
  530. oper[1].ref^.base:=helpreg;
  531. rgunget(list,helpins,helpreg);
  532. forward_allocation(Tai(helpins.next));
  533. {$ifdef debugra}
  534. writeln('spilling!');
  535. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  536. {$endif debugra}
  537. end;
  538. { b) index }
  539. supreg := oper[1].ref^.index.number shr 8;
  540. if supreg in r then
  541. begin
  542. if wasload then
  543. pos:=get_insert_pos(Tai(previous),oper[1].ref^.base.number shr 8,oper[0].reg.number shr 8,0)
  544. else
  545. pos:=get_insert_pos(Tai(previous),oper[1].ref^.base.number shr 8,0,0);
  546. rgget(list,pos,0,helpreg);
  547. spill_registers:=true;
  548. helpins:=Taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  549. if pos=nil then
  550. list.insertafter(helpins,list.first)
  551. else
  552. list.insertafter(helpins,pos.next);
  553. oper[1].ref^.index:=helpreg;
  554. rgunget(list,helpins,helpreg);
  555. forward_allocation(Tai(helpins.next));
  556. {$ifdef debugra}
  557. writeln('spilling!');
  558. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  559. {$endif debugra}
  560. end;
  561. { load/store is done }
  562. exit;
  563. end;
  564. { all other instructions the compiler generates are the same (I hope): }
  565. { operand 0 is a register and is the destination, the others are sources }
  566. { and can be either registers or constants }
  567. { exception: branches (is_jmp isn't always set for them) }
  568. if oper[0].typ <> top_reg then
  569. exit;
  570. reg1 := oper[0].reg.number shr 8;
  571. if oper[1].typ = top_reg then
  572. reg2 := oper[1].reg.number shr 8
  573. else
  574. reg2 := 0;
  575. if (ops >= 3) and
  576. (oper[2].typ = top_reg) then
  577. reg3 := oper[2].reg.number shr 8
  578. else
  579. reg3 := 0;
  580. supreg:=reg1;
  581. if supreg in r then
  582. begin
  583. // Example:
  584. // add r20d, r21d, r22d ; r20d must be spilled into -60(r1)
  585. //
  586. // Change into:
  587. //
  588. // lwz r23d, -60(r1)
  589. // add r23d, r21d, r22d
  590. // stw r23d, -60(r1)
  591. pos := get_insert_pos(Tai(previous),reg1,reg2,reg3);
  592. rgget(list,pos,0,helpreg);
  593. spill_registers := true;
  594. helpins := taicpu.op_reg_ref(A_STW,helpreg,spilltemplist[supreg]);
  595. list.insertafter(helpins,self);
  596. helpins := taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  597. if pos=nil then
  598. list.insertafter(helpins,list.first)
  599. else
  600. list.insertafter(helpins,pos.next);
  601. loadreg(0,helpreg);
  602. rgunget(list,helpins,helpreg);
  603. forward_allocation(tai(helpins.next));
  604. {$ifdef debugra}
  605. writeln('spilling!');
  606. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  607. {$endif debugra}
  608. end;
  609. for i := 1 to 2 do
  610. if (oper[i].typ = top_reg) then
  611. begin
  612. supreg:=oper[i].reg.number;
  613. if supreg in r then
  614. begin
  615. // Example:
  616. // add r20d, r21d, r22d ; r20d must be spilled into -60(r1)
  617. //
  618. // Change into:
  619. //
  620. // lwz r23d, -60(r1)
  621. // add r23d, r21d, r22d
  622. // stw r23d, -60(r1)
  623. pos := get_insert_pos(Tai(previous),reg1,reg2,reg3);
  624. rgget(list,pos,0,helpreg);
  625. spill_registers := true;
  626. helpins := taicpu.op_reg_ref(A_LWZ,helpreg,spilltemplist[supreg]);
  627. if pos=nil then
  628. list.insertafter(helpins,list.first)
  629. else
  630. list.insertafter(helpins,pos.next);
  631. loadreg(i,helpreg);
  632. rgunget(list,helpins,helpreg);
  633. forward_allocation(tai(helpins.next));
  634. {$ifdef debugra}
  635. writeln('spilling!');
  636. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  637. {$endif debugra}
  638. end;
  639. end;
  640. end;
  641. {$else dummy}
  642. begin
  643. end;
  644. {$endif dummy}
  645. procedure InitAsm;
  646. begin
  647. end;
  648. procedure DoneAsm;
  649. begin
  650. end;
  651. end.
  652. {
  653. $Log$
  654. Revision 1.3 2003-08-24 12:27:26 florian
  655. * continued to work on the arm port
  656. Revision 1.2 2003/08/20 15:50:12 florian
  657. * more arm stuff
  658. Revision 1.1 2003/08/16 13:23:01 florian
  659. * several arm related stuff fixed
  660. }