tgcpu.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. {
  2. $Id$
  3. Copyright (C) 1998-2000 by Florian Klaempfl
  4. This unit handles the temporary variables stuff for i386
  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 tgcpu;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. globals,
  23. cgbase,verbose,aasm,
  24. node,
  25. cpubase,cpuasm
  26. ;
  27. type
  28. tregisterset = set of tregister;
  29. tpushed = array[R_EAX..R_MM6] of boolean;
  30. tsaved = array[R_EAX..R_MM6] of longint;
  31. const
  32. usablereg32 : byte = 4;
  33. { this value is used in tsaved, if the register isn't saved }
  34. reg_not_saved = $7fffffff;
  35. {$ifdef SUPPORT_MMX}
  36. usableregmmx : byte = 8;
  37. {$endif SUPPORT_MMX}
  38. var
  39. { tries to hold the amount of times which the current tree is processed }
  40. t_times : longint;
  41. {$ifdef TEMPREGDEBUG}
  42. procedure testregisters32;
  43. {$endif TEMPREGDEBUG}
  44. function getregisterint : tregister;
  45. function getaddressregister: tregister;
  46. procedure ungetregister32(r : tregister);
  47. { tries to allocate the passed register, if possible }
  48. function getexplicitregister32(r : tregister) : tregister;
  49. {$ifdef SUPPORT_MMX}
  50. function getregistermmx : tregister;
  51. procedure ungetregistermmx(r : tregister);
  52. {$endif SUPPORT_MMX}
  53. function isaddressregister(reg: tregister): boolean;
  54. procedure ungetregister(r : tregister);
  55. procedure cleartempgen;
  56. procedure del_reference(const ref : treference);
  57. procedure del_locref(const location : tlocation);
  58. procedure del_location(const l : tlocation);
  59. { pushs and restores registers }
  60. procedure pushusedregisters(var pushed : tpushed;b : tregisterset);
  61. procedure popusedregisters(const pushed : tpushed);
  62. { saves register variables (restoring happens automatically (JM) }
  63. procedure saveregvars(b : tregisterset);
  64. { saves and restores used registers to temp. values }
  65. procedure saveusedregisters(var saved : tsaved;b : tregisterset);
  66. procedure restoreusedregisters(const saved : tsaved);
  67. { increments the push count of all registers in b}
  68. procedure incrementregisterpushed(b : tregisterset);
  69. procedure clearregistercount;
  70. procedure resetusableregisters;
  71. { corrects the fpu stack register by ofs }
  72. function correct_fpuregister(r : tregister;ofs : byte) : tregister;
  73. type
  74. {$ifdef SUPPORT_MMX}
  75. regvar_longintarray = array[R_EAX..R_MM6] of longint;
  76. regvar_booleanarray = array[R_EAX..R_MM6] of boolean;
  77. regvar_ptreearray = array[R_EAX..R_MM6] of tnode;
  78. {$else SUPPORT_MMX}
  79. regvar_longintarray = array[R_EAX..R_EDI] of longint;
  80. regvar_booleanarray = array[R_EAX..R_EDI] of boolean;
  81. regvar_ptreearray = array[R_EAX..R_EDI] of tnode;
  82. {$endif SUPPORT_MMX}
  83. var
  84. unused,usableregs : tregisterset;
  85. c_usableregs : longint;
  86. { uses only 1 byte while a set uses in FPC 32 bytes }
  87. usedinproc : tregisterset;
  88. fpuvaroffset : byte;
  89. { count, how much a register must be pushed if it is used as register }
  90. { variable }
  91. reg_pushes : regvar_longintarray;
  92. is_reg_var : regvar_booleanarray;
  93. regvar_loaded: regvar_booleanarray;
  94. {$ifdef TEMPREGDEBUG}
  95. reg_user : regvar_ptreearray;
  96. reg_releaser : regvar_ptreearray;
  97. {$endif TEMPREGDEBUG}
  98. implementation
  99. uses
  100. globtype,temp_gen,tainst,regvars;
  101. procedure incrementregisterpushed(b : tregisterset);
  102. var
  103. regi : tregister;
  104. begin
  105. for regi:=R_EAX to R_EDI do
  106. begin
  107. if regi in b then
  108. inc(reg_pushes[regi],t_times*2);
  109. end;
  110. end;
  111. procedure pushusedregisters(var pushed : tpushed;b : tregisterset);
  112. var
  113. r : tregister;
  114. {$ifdef SUPPORT_MMX}
  115. hr : preference;
  116. {$endif}
  117. begin
  118. usedinproc:=usedinproc+b;
  119. for r:=R_EAX to R_EBX do
  120. begin
  121. pushed[r]:=false;
  122. { if the register is used by the calling subroutine }
  123. if r in b then
  124. begin
  125. { and is present in use }
  126. if not is_reg_var[r] then
  127. if not(r in unused) then
  128. begin
  129. { then save it }
  130. exprasmlist.concat(Taicpu.Op_reg(A_PUSH,S_L,r));
  131. { here was a big problem !!!!!}
  132. { you cannot do that for a register that is
  133. globally assigned to a var
  134. this also means that you must push it much more
  135. often, but there must be a better way
  136. maybe by putting the value back to the stack !! }
  137. if not(is_reg_var[r]) then
  138. begin
  139. unused:=unused+[r];
  140. {$ifdef TEMPREGDEBUG}
  141. inc(usablereg32);
  142. {$endif TEMPREGDEBUG}
  143. end;
  144. pushed[r]:=true;
  145. end;
  146. end;
  147. end;
  148. {$ifdef SUPPORT_MMX}
  149. for r:=R_MM0 to R_MM6 do
  150. begin
  151. pushed[r]:=false;
  152. { if the mmx register is in use, save it }
  153. if not(r in unused) then
  154. begin
  155. exprasmList.concat(Taicpu.Op_const_reg(A_SUB,S_L,8,R_ESP));
  156. new(hr);
  157. reset_reference(hr^);
  158. hr^.base:=R_ESP;
  159. exprasmList.concat(Taicpu.Op_reg_ref(A_MOVQ,S_NO,r,hr));
  160. if not(is_reg_var[r]) then
  161. begin
  162. unused:=unused+[r];
  163. {$ifdef TEMPREGDEBUG}
  164. inc(usableregmmx);
  165. {$endif TEMPREGDEBUG}
  166. end;
  167. pushed[r]:=true;
  168. end;
  169. end;
  170. {$endif SUPPORT_MMX}
  171. {$ifdef TEMPREGDEBUG}
  172. testregisters32;
  173. {$endif TEMPREGDEBUG}
  174. end;
  175. procedure saveregvars(b : tregisterset);
  176. var
  177. r : tregister;
  178. begin
  179. if not(cs_regalloc in aktglobalswitches) then
  180. exit;
  181. for r:=R_EAX to R_EBX do
  182. { if the register is used by the calling subroutine }
  183. if (r in b) and is_reg_var[r] then
  184. store_regvar(exprasmlist,r)
  185. end;
  186. procedure saveusedregisters(var saved : tsaved;b : tregisterset);
  187. var
  188. r : tregister;
  189. hr : treference;
  190. begin
  191. usedinproc:=usedinproc+b;
  192. for r:=R_EAX to R_EBX do
  193. begin
  194. saved[r]:=reg_not_saved;
  195. { if the register is used by the calling subroutine }
  196. if r in b then
  197. begin
  198. { and is present in use }
  199. if not(r in unused) then
  200. begin
  201. { then save it }
  202. gettempofsizereference(4,hr);
  203. saved[r]:=hr.offset;
  204. exprasmList.concat(Taicpu.Op_reg_ref(A_MOV,S_L,r,newreference(hr)));
  205. { here was a big problem !!!!!}
  206. { you cannot do that for a register that is
  207. globally assigned to a var
  208. this also means that you must push it much more
  209. often, but there must be a better way
  210. maybe by putting the value back to the stack !! }
  211. if not(is_reg_var[r]) then
  212. begin
  213. unused:=unused+[r];
  214. {$ifdef TEMPREGDEBUG}
  215. inc(usablereg32);
  216. {$endif TEMPREGDEBUG}
  217. end;
  218. end;
  219. end;
  220. end;
  221. {$ifdef SUPPORT_MMX}
  222. for r:=R_MM0 to R_MM6 do
  223. begin
  224. saved[r]:=reg_not_saved;
  225. { if the mmx register is in use, save it }
  226. if not(r in unused) then
  227. begin
  228. gettempofsizereference(8,hr);
  229. exprasmList.concat(Taicpu.Op_reg_ref(A_MOVQ,S_NO,r,newreference(hr)));
  230. if not(is_reg_var[r]) then
  231. begin
  232. unused:=unused+[r];
  233. {$ifdef TEMPREGDEBUG}
  234. inc(usableregmmx);
  235. {$endif TEMPREGDEBUG}
  236. end;
  237. saved[r]:=hr.offset;
  238. end;
  239. end;
  240. {$endif SUPPORT_MMX}
  241. {$ifdef TEMPREGDEBUG}
  242. testregisters32;
  243. {$endif TEMPREGDEBUG}
  244. end;
  245. procedure popusedregisters(const pushed : tpushed);
  246. var
  247. r : tregister;
  248. {$ifdef SUPPORT_MMX}
  249. hr : preference;
  250. {$endif SUPPORT_MMX}
  251. begin
  252. { restore in reverse order: }
  253. {$ifdef SUPPORT_MMX}
  254. for r:=R_MM6 downto R_MM0 do
  255. begin
  256. if pushed[r] then
  257. begin
  258. new(hr);
  259. reset_reference(hr^);
  260. hr^.base:=R_ESP;
  261. exprasmList.concat(Taicpu.Op_ref_reg(
  262. A_MOVQ,S_NO,hr,r));
  263. exprasmList.concat(Taicpu.Op_const_reg(
  264. A_ADD,S_L,8,R_ESP));
  265. unused:=unused-[r];
  266. {$ifdef TEMPREGDEBUG}
  267. dec(usableregmmx);
  268. {$endif TEMPREGDEBUG}
  269. end;
  270. end;
  271. {$endif SUPPORT_MMX}
  272. for r:=R_EBX downto R_EAX do
  273. if pushed[r] then
  274. begin
  275. exprasmList.concat(Taicpu.Op_reg(A_POP,S_L,r));
  276. {$ifdef TEMPREGDEBUG}
  277. if not (r in unused) then
  278. { internalerror(10)
  279. in cg386cal we always restore regs
  280. that appear as used
  281. due to a unused tmep storage PM }
  282. else
  283. dec(usablereg32);
  284. {$endif TEMPREGDEBUG}
  285. unused:=unused-[r];
  286. end;
  287. {$ifdef TEMPREGDEBUG}
  288. testregisters32;
  289. {$endif TEMPREGDEBUG}
  290. end;
  291. procedure restoreusedregisters(const saved : tsaved);
  292. var
  293. r : tregister;
  294. hr : treference;
  295. begin
  296. { restore in reverse order: }
  297. {$ifdef SUPPORT_MMX}
  298. for r:=R_MM6 downto R_MM0 do
  299. begin
  300. if saved[r]<>reg_not_saved then
  301. begin
  302. reset_reference(hr);
  303. hr.base:=frame_pointer;
  304. hr.offset:=saved[r];
  305. exprasmList.concat(Taicpu.Op_ref_reg(
  306. A_MOVQ,S_NO,newreference(hr),r));
  307. unused:=unused-[r];
  308. {$ifdef TEMPREGDEBUG}
  309. dec(usableregmmx);
  310. {$endif TEMPREGDEBUG}
  311. ungetiftemp(hr);
  312. end;
  313. end;
  314. {$endif SUPPORT_MMX}
  315. for r:=R_EBX downto R_EAX do
  316. if saved[r]<>reg_not_saved then
  317. begin
  318. reset_reference(hr);
  319. hr.base:=frame_pointer;
  320. hr.offset:=saved[r];
  321. exprasmList.concat(Taicpu.Op_ref_reg(A_MOV,S_L,newreference(hr),r));
  322. {$ifdef TEMPREGDEBUG}
  323. if not (r in unused) then
  324. internalerror(10)
  325. else
  326. dec(usablereg32);
  327. {$endif TEMPREGDEBUG}
  328. unused:=unused-[r];
  329. ungetiftemp(hr);
  330. end;
  331. {$ifdef TEMPREGDEBUG}
  332. testregisters32;
  333. {$endif TEMPREGDEBUG}
  334. end;
  335. procedure ungetregister(r : tregister);
  336. begin
  337. if r in [R_EAX,R_ECX,R_EDX,R_EBX,R_ESP,R_EBP,R_ESI,R_EDI] then
  338. ungetregister32(r)
  339. else if r in [R_AX,R_CX,R_DX,R_BX,R_SP,R_BP,R_SI,R_DI] then
  340. ungetregister32(reg16toreg32(r))
  341. else if r in [R_AL,R_BL,R_CL,R_DL] then
  342. ungetregister32(reg8toreg32(r))
  343. {$ifdef SUPPORT_MMX}
  344. else if r in [R_MM0..R_MM6] then
  345. ungetregistermmx(r)
  346. {$endif SUPPORT_MMX}
  347. else internalerror(200112021);
  348. end;
  349. procedure ungetregister32(r : tregister);
  350. begin
  351. if (r = R_EDI) or
  352. ((not assigned(procinfo^._class)) and (r = R_ESI)) then
  353. begin
  354. exprasmList.concat(Tairegalloc.DeAlloc(r));
  355. exit;
  356. end;
  357. if cs_regalloc in aktglobalswitches then
  358. begin
  359. { takes much time }
  360. if not(r in usableregs) then
  361. exit;
  362. unused:=unused+[r];
  363. inc(usablereg32);
  364. end
  365. else
  366. begin
  367. if not(r in [R_EAX,R_EBX,R_ECX,R_EDX]) then
  368. exit;
  369. {$ifdef TEMPREGDEBUG}
  370. if (r in unused) then
  371. {$ifdef EXTTEMPREGDEBUG}
  372. begin
  373. Comment(V_Debug,'register freed twice '+reg2str(r));
  374. testregisters32;
  375. exit;
  376. end
  377. {$else EXTTEMPREGDEBUG}
  378. exit
  379. {$endif EXTTEMPREGDEBUG}
  380. else
  381. {$endif TEMPREGDEBUG}
  382. inc(usablereg32);
  383. unused:=unused+[r];
  384. {$ifdef TEMPREGDEBUG}
  385. reg_releaser[r]:=curptree^;
  386. {$endif TEMPREGDEBUG}
  387. end;
  388. exprasmList.concat(Tairegalloc.DeAlloc(r));
  389. {$ifdef TEMPREGDEBUG}
  390. testregisters32;
  391. {$endif TEMPREGDEBUG}
  392. end;
  393. {$ifdef SUPPORT_MMX}
  394. function getregistermmx : tregister;
  395. var
  396. r : tregister;
  397. begin
  398. dec(usableregmmx);
  399. for r:=R_MM0 to R_MM6 do
  400. if r in unused then
  401. begin
  402. unused:=unused-[r];
  403. usedinproc:=usedinproc or ($80 shr byte(R_EAX));
  404. getregistermmx:=r;
  405. exit;
  406. end;
  407. internalerror(10);
  408. end;
  409. procedure ungetregistermmx(r : tregister);
  410. begin
  411. if cs_regalloc in aktglobalswitches then
  412. begin
  413. { takes much time }
  414. if not(r in usableregs) then
  415. exit;
  416. unused:=unused+[r];
  417. inc(usableregmmx);
  418. end
  419. else
  420. begin
  421. unused:=unused+[r];
  422. inc(usableregmmx);
  423. end;
  424. end;
  425. {$endif SUPPORT_MMX}
  426. function isaddressregister(reg: tregister): boolean;
  427. begin
  428. isaddressregister := true;
  429. end;
  430. procedure del_reference(const ref : treference);
  431. begin
  432. if ref.is_immediate then
  433. exit;
  434. ungetregister32(ref.base);
  435. ungetregister32(ref.index);
  436. end;
  437. procedure del_locref(const location : tlocation);
  438. begin
  439. if (location.loc<>loc_mem) and (location.loc<>loc_reference) then
  440. exit;
  441. if location.reference.is_immediate then
  442. exit;
  443. ungetregister32(location.reference.base);
  444. ungetregister32(location.reference.index);
  445. end;
  446. procedure del_location(const l : tlocation);
  447. begin
  448. case l.loc of
  449. LOC_REGISTER :
  450. ungetregister(l.register);
  451. LOC_MEM,LOC_REFERENCE :
  452. del_reference(l.reference);
  453. end;
  454. end;
  455. {$ifdef TEMPREGDEBUG}
  456. procedure testregisters32;
  457. var test : byte;
  458. begin
  459. test:=0;
  460. if R_EAX in unused then
  461. inc(test);
  462. if R_EBX in unused then
  463. inc(test);
  464. if R_ECX in unused then
  465. inc(test);
  466. if R_EDX in unused then
  467. inc(test);
  468. if test<>usablereg32 then
  469. internalerror(10);
  470. end;
  471. {$endif TEMPREGDEBUG}
  472. <<<<<<< tgcpu.pas
  473. function getregister32 : tregister;
  474. var
  475. r : tregister;
  476. =======
  477. function getregisterint : tregister;
  478. >>>>>>> 1.8
  479. begin
  480. if usablereg32=0 then
  481. internalerror(10);
  482. {$ifdef TEMPREGDEBUG}
  483. if curptree^^.usableregs-usablereg32>curptree^^.registers32 then
  484. internalerror(10);
  485. {$endif TEMPREGDEBUG}
  486. {$ifdef EXTTEMPREGDEBUG}
  487. if curptree^^.usableregs-usablereg32>curptree^^.reallyusedregs then
  488. curptree^^.reallyusedregs:=curptree^^.usableregs-usablereg32;
  489. {$endif EXTTEMPREGDEBUG}
  490. dec(usablereg32);
  491. if R_EAX in unused then
  492. begin
  493. <<<<<<< tgcpu.pas
  494. r:=R_EAX;
  495. =======
  496. unused:=unused-[R_EAX];
  497. usedinproc:=usedinproc or ($80 shr byte(R_EAX));
  498. getregisterint:=R_EAX;
  499. >>>>>>> 1.8
  500. {$ifdef TEMPREGDEBUG}
  501. reg_user[R_EAX]:=curptree^;
  502. {$endif TEMPREGDEBUG}
  503. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  504. end
  505. else if R_EDX in unused then
  506. begin
  507. <<<<<<< tgcpu.pas
  508. r:=R_EDX;
  509. =======
  510. unused:=unused-[R_EDX];
  511. usedinproc:=usedinproc or ($80 shr byte(R_EDX));
  512. getregisterint:=R_EDX;
  513. >>>>>>> 1.8
  514. {$ifdef TEMPREGDEBUG}
  515. reg_user[R_EDX]:=curptree^;
  516. {$endif TEMPREGDEBUG}
  517. exprasmList.concat(Tairegalloc.Alloc(R_EDX));
  518. end
  519. else if R_EBX in unused then
  520. begin
  521. <<<<<<< tgcpu.pas
  522. r:=R_EBX;
  523. =======
  524. unused:=unused-[R_EBX];
  525. usedinproc:=usedinproc or ($80 shr byte(R_EBX));
  526. getregisterint:=R_EBX;
  527. >>>>>>> 1.8
  528. {$ifdef TEMPREGDEBUG}
  529. reg_user[R_EBX]:=curptree^;
  530. {$endif TEMPREGDEBUG}
  531. exprasmList.concat(Tairegalloc.Alloc(R_EBX));
  532. end
  533. else if R_ECX in unused then
  534. begin
  535. <<<<<<< tgcpu.pas
  536. r:=R_ECX;
  537. =======
  538. unused:=unused-[R_ECX];
  539. usedinproc:=usedinproc or ($80 shr byte(R_ECX));
  540. getregisterint:=R_ECX;
  541. >>>>>>> 1.8
  542. {$ifdef TEMPREGDEBUG}
  543. reg_user[R_ECX]:=curptree^;
  544. {$endif TEMPREGDEBUG}
  545. exprasmList.concat(Tairegalloc.Alloc(R_ECX));
  546. end
  547. else internalerror(10);
  548. {$ifdef TEMPREGDEBUG}
  549. testregisters32;
  550. {$endif TEMPREGDEBUG}
  551. exclude(unused,r);
  552. include(usedinproc,r);
  553. getregister32:=r;
  554. end;
  555. function getaddressregister: tregister;
  556. begin
  557. getaddressregister := getregisterint;
  558. end;
  559. function getexplicitregister32(r : tregister) : tregister;
  560. begin
  561. if r in [R_ESI,R_EDI] then
  562. begin
  563. exprasmList.concat(Tairegalloc.Alloc(r));
  564. getexplicitregister32 := r;
  565. exit;
  566. end;
  567. if r in unused then
  568. begin
  569. dec(usablereg32);
  570. {$ifdef TEMPREGDEBUG}
  571. if curptree^^.usableregs-usablereg32>curptree^^.registers32 then
  572. internalerror(10);
  573. reg_user[r]:=curptree^;
  574. {$endif TEMPREGDEBUG}
  575. include(unused,r);
  576. include(usedinproc,r);
  577. exprasmList.concat(Tairegalloc.Alloc(r));
  578. getexplicitregister32:=r;
  579. {$ifdef TEMPREGDEBUG}
  580. testregisters32;
  581. {$endif TEMPREGDEBUG}
  582. end
  583. else
  584. getexplicitregister32:=getregisterint;
  585. end;
  586. procedure cleartempgen;
  587. begin
  588. unused:=usableregs;
  589. usablereg32:=c_usableregs;
  590. {fpuvaroffset:=0;
  591. this must only be resetted at each procedure
  592. compilation start PM }
  593. end;
  594. procedure clearregistercount;
  595. var
  596. regi : tregister;
  597. begin
  598. {$ifdef SUPPORT_MMX}
  599. for regi:=R_EAX to R_MM6 do
  600. begin
  601. reg_pushes[regi]:=0;
  602. is_reg_var[regi]:=false;
  603. end;
  604. {$else SUPPORT_MMX}
  605. for regi:=R_EAX to R_EDI do
  606. begin
  607. reg_pushes[regi]:=0;
  608. is_reg_var[regi]:=false;
  609. end;
  610. {$endif SUPPORT_MMX}
  611. end;
  612. function correct_fpuregister(r : tregister;ofs : byte) : tregister;
  613. begin
  614. correct_fpuregister:=tregister(longint(r)+ofs);
  615. end;
  616. procedure resetusableregisters;
  617. begin
  618. {$ifdef SUPPORT_MMX}
  619. usableregs:=[R_EAX,R_EBX,R_ECX,R_EDX,R_MM0..R_MM6];
  620. c_usableregs:=4;
  621. usableregmmx:=8;
  622. {$else}
  623. usableregs:=[R_EAX,R_EBX,R_ECX,R_EDX];
  624. c_usableregs:=4;
  625. {$endif SUPPORT_MMX}
  626. fillchar(regvar_loaded,sizeof(regvar_loaded),false);
  627. fillchar(is_reg_var,sizeof(is_reg_var),false);
  628. fpuvaroffset:=0;
  629. end;
  630. begin
  631. resetusableregisters;
  632. end.
  633. {
  634. $Log$
  635. Revision 1.10 2002-07-04 20:43:02 florian
  636. * first x86-64 patches
  637. Revision 1.9 2002/03/31 20:26:42 jonas
  638. + a_loadfpu_* and a_loadmm_* methods in tcg
  639. * register allocation is now handled by a class and is mostly processor
  640. independent (+rgobj.pas and i386/rgcpu.pas)
  641. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  642. * some small improvements and fixes to the optimizer
  643. * some register allocation fixes
  644. * some fpuvaroffset fixes in the unary minus node
  645. * push/popusedregisters is now called rg.save/restoreusedregisters and
  646. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  647. also better optimizable)
  648. * fixed and optimized register saving/restoring for new/dispose nodes
  649. * LOC_FPU locations now also require their "register" field to be set to
  650. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  651. - list field removed of the tnode class because it's not used currently
  652. and can cause hard-to-find bugs
  653. Revision 1.8 2001/12/31 09:53:16 jonas
  654. * changed remaining "getregister32" calls to "getregisterint"
  655. Revision 1.7 2001/12/29 15:29:59 jonas
  656. * powerpc/cgcpu.pas compiles :)
  657. * several powerpc-related fixes
  658. * cpuasm unit is now based on common tainst unit
  659. + nppcmat unit for powerpc (almost complete)
  660. Revision 1.5 2001/08/26 13:37:03 florian
  661. * some cg reorganisation
  662. * some PPC updates
  663. Revision 1.4 2001/04/13 01:22:21 peter
  664. * symtable change to classes
  665. * range check generation and errors fixed, make cycle DEBUG=1 works
  666. * memory leaks fixed
  667. Revision 1.3 2000/12/25 00:07:34 peter
  668. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  669. tlinkedlist objects)
  670. Revision 1.2 2000/12/05 11:44:34 jonas
  671. + new integer regvar handling, should be much more efficient
  672. Revision 1.1 2000/11/29 00:30:51 florian
  673. * unused units removed from uses clause
  674. * some changes for widestrings
  675. Revision 1.9 2000/10/31 22:30:13 peter
  676. * merged asm result patch part 2
  677. Revision 1.8 2000/10/14 10:14:56 peter
  678. * moehrendorf oct 2000 rewrite
  679. Revision 1.7 2000/09/30 16:08:46 peter
  680. * more cg11 updates
  681. Revision 1.6 2000/09/24 15:06:32 peter
  682. * use defines.inc
  683. Revision 1.5 2000/08/27 16:11:55 peter
  684. * moved some util functions from globals,cobjects to cutils
  685. * splitted files into finput,fmodule
  686. Revision 1.4 2000/08/05 13:32:39 peter
  687. * fixed build prob without support_mmx
  688. Revision 1.3 2000/08/04 05:09:49 jonas
  689. * forgot to commit :( (part of regvar changes)
  690. Revision 1.2 2000/07/13 11:32:52 michael
  691. + removed logs
  692. }