rgcpu.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the SPARC specific class for the register
  5. allocator
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************}
  18. unit rgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,
  23. cpuinfo,
  24. aasmcpu,
  25. aasmtai,
  26. cclasses,globtype,
  27. cginfo,cgbase,aasmbase,rgobj;
  28. type
  29. trgcpu=class(trgobj)
  30. function GetRegisterFpu(list:TAasmOutput;size:Tcgsize):TRegister;override;
  31. procedure UngetRegisterFpu(list:taasmoutput;reg:tregister;size:TCGsize);override;
  32. procedure ClearTempGen;override;
  33. end;
  34. implementation
  35. uses
  36. cgobj,verbose;
  37. function TRgCpu.GetRegisterFpu(list:TAasmOutput;size:Tcgsize):TRegister;
  38. var
  39. i: Tsuperregister;
  40. r: Tregister;
  41. begin
  42. for i:=firstsavefpureg to lastsavefpureg do
  43. begin
  44. if (i in unusedregsfpu) and
  45. (
  46. (size=OS_F32) or
  47. (not odd(i-RS_F0))
  48. ) then
  49. begin
  50. exclude(unusedregsfpu,i);
  51. dec(countunusedregsfpu);
  52. r:=newreg(R_FPUREGISTER,i,R_SUBNONE);
  53. list.concat(tai_regalloc.alloc(r));
  54. result := r;
  55. { double need 2 FPU registers }
  56. if size=OS_F64 then
  57. begin
  58. r:=newreg(R_FPUREGISTER,i+1,R_SUBNONE);
  59. exclude(unusedregsfpu,i+1);
  60. dec(countunusedregsfpu);
  61. list.concat(tai_regalloc.alloc(r));
  62. end;
  63. exit;
  64. end;
  65. end;
  66. internalerror(10);
  67. end;
  68. procedure trgcpu.UngetRegisterFpu(list:taasmoutput;reg:tregister;size:TCGsize);
  69. var
  70. r : tregister;
  71. supreg : tsuperregister;
  72. begin
  73. supreg:=getsupreg(reg);
  74. { double need 2 FPU registers }
  75. if (size=OS_F64) then
  76. begin
  77. { Only even FP registers are allowed }
  78. if odd(supreg-RS_F0) then
  79. internalerror(200306101);
  80. r:=newreg(R_FPUREGISTER,supreg+1,R_SUBNONE);
  81. inc(countunusedregsfpu);
  82. include(unusedregsfpu,getsupreg(r));
  83. list.concat(tai_regalloc.dealloc(r));
  84. end;
  85. inc(countunusedregsfpu);
  86. include(unusedregsfpu,supreg);
  87. list.concat(tai_regalloc.dealloc(reg));
  88. end;
  89. procedure trgcpu.cleartempgen;
  90. begin
  91. inherited cleartempgen;
  92. end;
  93. begin
  94. { Only use %o and %l }
  95. rg := trgcpu.create(16);
  96. end.
  97. {
  98. $Log$
  99. Revision 1.17 2003-09-03 15:55:01 peter
  100. * NEWRA branch merged
  101. Revision 1.16.2.2 2003/09/02 17:49:17 peter
  102. * newra updates
  103. Revision 1.16.2.1 2003/09/01 21:02:55 peter
  104. * sparc updates for new tregister
  105. Revision 1.16 2003/08/11 21:18:20 peter
  106. * start of sparc support for newra
  107. Revision 1.15 2003/07/02 22:18:04 peter
  108. * paraloc splitted in callerparaloc,calleeparaloc
  109. * sparc calling convention updates
  110. Revision 1.14 2003/06/17 16:36:11 peter
  111. * freeintparaloc added
  112. Revision 1.13 2003/06/12 22:47:52 mazen
  113. - unused temp var r removed in GetExplicitRegisterInt function
  114. * some case added for var and fauncions naming
  115. Revision 1.12 2003/06/12 21:11:44 peter
  116. * updates like the powerpc
  117. Revision 1.11 2003/06/01 21:38:07 peter
  118. * getregisterfpu size parameter added
  119. * op_const_reg size parameter added
  120. * sparc updates
  121. Revision 1.10 2003/05/31 01:00:51 peter
  122. * register fixes
  123. Revision 1.9 2003/04/22 10:09:35 daniel
  124. + Implemented the actual register allocator
  125. + Scratch registers unavailable when new register allocator used
  126. + maybe_save/maybe_restore unavailable when new register allocator used
  127. Revision 1.8 2003/03/15 22:51:58 mazen
  128. * remaking sparc rtl compile
  129. Revision 1.7 2003/03/10 21:59:54 mazen
  130. * fixing index overflow in handling new registers arrays.
  131. Revision 1.6 2003/02/19 22:00:17 daniel
  132. * Code generator converted to new register notation
  133. - Horribily outdated todo.txt removed
  134. Revision 1.5 2003/01/08 18:43:58 daniel
  135. * Tregister changed into a record
  136. Revision 1.4 2002/10/13 21:46:07 mazen
  137. * assembler output format fixed
  138. Revision 1.3 2002/10/12 19:03:23 mazen
  139. * Get/Unget expilit registers to be re-examined
  140. }