aasmcpu.pas 25 KB

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