aasmcpu.pas 24 KB

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