ngppcinl.pas 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate PowerPC32/64 inline nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ngppcinl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ninl,ncginl;
  22. type
  23. tgppcinlinenode = class(tcginlinenode)
  24. { first pass override
  25. so that the code generator will actually generate
  26. these nodes.
  27. }
  28. function first_sqrt_real: tnode; override;
  29. function first_abs_real: tnode; override;
  30. function first_sqr_real: tnode; override;
  31. procedure second_sqrt_real; override;
  32. procedure second_abs_real; override;
  33. procedure second_sqr_real; override;
  34. procedure second_prefetch;override;
  35. protected
  36. procedure load_fpu_location;
  37. end;
  38. implementation
  39. uses
  40. cutils,globals,verbose,
  41. aasmtai,aasmdata,aasmcpu,
  42. symconst,symdef,
  43. defutil,
  44. cgbase,pass_2,
  45. cpubase,cpuinfo,ncgutil,
  46. cgutils,cgobj,rgobj;
  47. {*****************************************************************************
  48. tgppcinlinenode
  49. *****************************************************************************}
  50. function tgppcinlinenode.first_sqrt_real : tnode;
  51. begin
  52. if (current_settings.cputype >= cpu_PPC970) then
  53. begin
  54. expectloc:=LOC_FPUREGISTER;
  55. registersint:=left.registersint;
  56. registersfpu:=max(left.registersfpu,1);
  57. first_sqrt_real := nil;
  58. end
  59. else
  60. result:=inherited first_sqrt_real;
  61. end;
  62. function tgppcinlinenode.first_abs_real : tnode;
  63. begin
  64. expectloc:=LOC_FPUREGISTER;
  65. registersint:=left.registersint;
  66. registersfpu:=max(left.registersfpu,1);
  67. {$ifdef SUPPORT_MMX}
  68. registersmmx:=left.registersmmx;
  69. {$endif SUPPORT_MMX}
  70. first_abs_real := nil;
  71. end;
  72. function tgppcinlinenode.first_sqr_real : tnode;
  73. begin
  74. expectloc:=LOC_FPUREGISTER;
  75. registersint:=left.registersint;
  76. registersfpu:=max(left.registersfpu,1);
  77. {$ifdef SUPPORT_MMX}
  78. registersmmx:=left.registersmmx;
  79. {$endif SUPPORT_MMX}
  80. first_sqr_real := nil;
  81. end;
  82. { load the FPU into the an fpu register }
  83. procedure tgppcinlinenode.load_fpu_location;
  84. begin
  85. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  86. secondpass(left);
  87. location_force_fpureg(current_asmdata.CurrAsmList,left.location,true);
  88. location.loc := LOC_FPUREGISTER;
  89. location.register := cg.getfpuregister(current_asmdata.CurrAsmList,OS_F64);
  90. end;
  91. procedure tgppcinlinenode.second_sqrt_real;
  92. begin
  93. if (current_settings.cputype < cpu_PPC970) then
  94. internalerror(2007020910);
  95. location.loc:=LOC_FPUREGISTER;
  96. load_fpu_location;
  97. case left.location.size of
  98. OS_F32:
  99. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FSQRTS,location.register,
  100. left.location.register));
  101. OS_F64:
  102. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FSQRT,location.register,
  103. left.location.register));
  104. else
  105. inherited;
  106. end;
  107. end;
  108. procedure tgppcinlinenode.second_abs_real;
  109. begin
  110. location.loc:=LOC_FPUREGISTER;
  111. load_fpu_location;
  112. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FABS,location.register,
  113. left.location.register));
  114. end;
  115. procedure tgppcinlinenode.second_sqr_real;
  116. var
  117. op: tasmop;
  118. begin
  119. location.loc:=LOC_FPUREGISTER;
  120. load_fpu_location;
  121. if (left.location.size = OS_F32) then
  122. op := A_FMULS
  123. else
  124. op := A_FMUL;
  125. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,location.register,
  126. left.location.register,left.location.register));
  127. end;
  128. procedure tgppcinlinenode.second_prefetch;
  129. var
  130. r: tregister;
  131. begin
  132. secondpass(left);
  133. case left.location.loc of
  134. LOC_CREFERENCE,
  135. LOC_REFERENCE:
  136. begin
  137. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  138. if (left.location.reference.offset = 0) and
  139. not assigned(left.location.reference.symbol) then
  140. begin
  141. if (left.location.reference.index = NR_NO) then
  142. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_DCBT,0,left.location.reference.base))
  143. else
  144. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_DCBT,left.location.reference.base,left.location.reference.index));
  145. end
  146. else
  147. begin
  148. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  149. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_DCBT,0,r));
  150. end;
  151. end;
  152. else
  153. internalerror(200402021);
  154. end;
  155. end;
  156. begin
  157. cinlinenode:=tgppcinlinenode;
  158. end.