nppcinl.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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,defbase,
  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. location.loc:=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. location.loc:=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. location.loc:=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. end
  101. else
  102. internalerror(309991);
  103. end;
  104. end;
  105. procedure tppcinlinenode.second_abs_real;
  106. begin
  107. load_fpu_location;
  108. exprasmlist.concat(taicpu.op_none(A_FABS));
  109. end;
  110. procedure tppcinlinenode.second_sqr_real;
  111. begin
  112. load_fpu_location;
  113. exprasmlist.concat(taicpu.op_reg_reg_reg(A_FMUL,location.register,
  114. left.location.register,left.location.register));
  115. end;
  116. procedure tppcinlinenode.second_sqrt_real;
  117. begin
  118. load_fpu_location;
  119. exprasmlist.concat(taicpu.op_reg_reg(A_FMUL,location.register,
  120. left.location.register));
  121. end;
  122. begin
  123. cinlinenode:=tppcinlinenode;
  124. end.
  125. {
  126. $Log$
  127. Revision 1.1 2002-08-10 17:15:00 jonas
  128. + abs, sqr, sqrt implementations
  129. }