nppcinl.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate i386 inline nodes
  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 nppcinl;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,ninl,ncginl;
  23. type
  24. tppcinlinenode = class(tcginlinenode)
  25. { first pass override
  26. so that the code generator will actually generate
  27. these nodes.
  28. }
  29. function first_abs_real: tnode; override;
  30. function first_sqr_real: tnode; override;
  31. function first_sqrt_real: tnode; override;
  32. procedure second_abs_real; override;
  33. procedure second_sqr_real; override;
  34. procedure second_sqrt_real; override;
  35. private
  36. procedure load_fpu_location;
  37. end;
  38. implementation
  39. uses
  40. globtype,systems,
  41. cutils,verbose,globals,fmodule,
  42. symconst,symdef,defutil,
  43. aasmbase,aasmtai,aasmcpu,
  44. cginfo,cgbase,pass_1,pass_2,
  45. cpubase,paramgr,
  46. nbas,ncon,ncal,ncnv,nld,
  47. cga,tgobj,ncgutil,cgobj,cg64f32,rgobj,rgcpu;
  48. {*****************************************************************************
  49. TPPCINLINENODE
  50. *****************************************************************************}
  51. function tppcinlinenode.first_abs_real : tnode;
  52. begin
  53. expectloc:=LOC_FPUREGISTER;
  54. registers32:=left.registers32;
  55. registersfpu:=max(left.registersfpu,1);
  56. {$ifdef SUPPORT_MMX}
  57. registersmmx:=left.registersmmx;
  58. {$endif SUPPORT_MMX}
  59. first_abs_real := nil;
  60. end;
  61. function tppcinlinenode.first_sqr_real : tnode;
  62. begin
  63. expectloc:=LOC_FPUREGISTER;
  64. registers32:=left.registers32;
  65. registersfpu:=max(left.registersfpu,1);
  66. {$ifdef SUPPORT_MMX}
  67. registersmmx:=left.registersmmx;
  68. {$endif SUPPORT_MMX}
  69. first_sqr_real := nil;
  70. end;
  71. function tppcinlinenode.first_sqrt_real : tnode;
  72. begin
  73. expectloc:=LOC_FPUREGISTER;
  74. registers32:=left.registers32;
  75. registersfpu:=max(left.registersfpu,1);
  76. {$ifdef SUPPORT_MMX}
  77. registersmmx:=left.registersmmx;
  78. {$endif SUPPORT_MMX}
  79. first_sqrt_real := nil;
  80. end;
  81. { load the FPU into the an fpu register }
  82. procedure tppcinlinenode.load_fpu_location;
  83. begin
  84. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  85. secondpass(left);
  86. case left.location.loc of
  87. LOC_FPUREGISTER:
  88. location.register := left.location.register;
  89. LOC_CFPUREGISTER:
  90. begin
  91. location.register := rg.getregisterfpu(exprasmlist);
  92. end;
  93. LOC_REFERENCE,LOC_CREFERENCE:
  94. begin
  95. location.register := rg.getregisterfpu(exprasmlist);
  96. cg.a_loadfpu_ref_reg(exprasmlist,
  97. def_cgsize(left.resulttype.def),
  98. left.location.reference,location.register);
  99. location_release(exprasmlist,left.location);
  100. location_reset(left.location,LOC_FPUREGISTER,
  101. left.location.size);
  102. left.location.register := location.register;
  103. end
  104. else
  105. internalerror(309991);
  106. end;
  107. end;
  108. procedure tppcinlinenode.second_abs_real;
  109. begin
  110. location.loc:=LOC_FPUREGISTER;
  111. load_fpu_location;
  112. exprasmlist.concat(taicpu.op_reg_reg(A_FABS,location.register,
  113. left.location.register));
  114. end;
  115. procedure tppcinlinenode.second_sqr_real;
  116. begin
  117. location.loc:=LOC_FPUREGISTER;
  118. load_fpu_location;
  119. exprasmlist.concat(taicpu.op_reg_reg_reg(A_FMUL,location.register,
  120. left.location.register,left.location.register));
  121. end;
  122. procedure tppcinlinenode.second_sqrt_real;
  123. begin
  124. location.loc:=LOC_FPUREGISTER;
  125. load_fpu_location;
  126. exprasmlist.concat(taicpu.op_reg_reg(A_FSQRT,location.register,
  127. left.location.register));
  128. end;
  129. begin
  130. cinlinenode:=tppcinlinenode;
  131. end.
  132. {
  133. $Log$
  134. Revision 1.5 2003-04-23 12:35:35 florian
  135. * fixed several issues with powerpc
  136. + applied a patch from Jonas for nested function calls (PowerPC only)
  137. * ...
  138. Revision 1.4 2002/11/25 17:43:28 peter
  139. * splitted defbase in defutil,symutil,defcmp
  140. * merged isconvertable and is_equal into compare_defs(_ext)
  141. * made operator search faster by walking the list only once
  142. Revision 1.3 2002/09/18 09:19:37 jonas
  143. * fixed LOC_REFERENCE/LOC_CREFERENCE problems
  144. Revision 1.2 2002/08/19 17:35:42 jonas
  145. * fixes
  146. Revision 1.1 2002/08/10 17:15:00 jonas
  147. + abs, sqr, sqrt implementations
  148. }