ngppcinl.pas 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. cpubase,
  22. node,ninl,ncginl;
  23. type
  24. tgppcinlinenode = class(tcginlinenode)
  25. { first pass override
  26. so that the code generator will actually generate
  27. these nodes.
  28. }
  29. function first_sqrt_real: tnode; override;
  30. function first_abs_real: tnode; override;
  31. function first_sqr_real: tnode; override;
  32. function first_trunc_real: tnode; override;
  33. function first_round_real: tnode; override;
  34. procedure second_sqrt_real; override;
  35. procedure second_abs_real; override;
  36. procedure second_sqr_real; override;
  37. procedure second_trunc_real; override;
  38. procedure second_round_real; override;
  39. procedure second_prefetch;override;
  40. protected
  41. procedure load_fpu_location;
  42. procedure second_trunc_round_real(op: tasmop);
  43. end;
  44. implementation
  45. uses
  46. cutils,globals,verbose,globtype,
  47. aasmtai,aasmdata,aasmcpu,
  48. symconst,symdef,
  49. defutil,
  50. cgbase,pass_2,
  51. cpuinfo,ncgutil,
  52. cgutils,cgobj,rgobj,tgobj;
  53. {*****************************************************************************
  54. tgppcinlinenode
  55. *****************************************************************************}
  56. function tgppcinlinenode.first_sqrt_real : tnode;
  57. begin
  58. if (current_settings.cputype >= cpu_PPC970) then
  59. begin
  60. expectloc:=LOC_FPUREGISTER;
  61. first_sqrt_real := nil;
  62. end
  63. else
  64. result:=inherited first_sqrt_real;
  65. end;
  66. function tgppcinlinenode.first_abs_real : tnode;
  67. begin
  68. expectloc:=LOC_FPUREGISTER;
  69. first_abs_real := nil;
  70. end;
  71. function tgppcinlinenode.first_sqr_real : tnode;
  72. begin
  73. expectloc:=LOC_FPUREGISTER;
  74. first_sqr_real := nil;
  75. end;
  76. function tgppcinlinenode.first_trunc_real : tnode;
  77. begin
  78. if (current_settings.cputype >= cpu_PPC970) then
  79. begin
  80. expectloc:=LOC_REFERENCE;
  81. first_trunc_real := nil;
  82. end
  83. else
  84. result:=inherited first_trunc_real;
  85. end;
  86. function tgppcinlinenode.first_round_real : tnode;
  87. begin
  88. if (current_settings.cputype >= cpu_PPC970) then
  89. begin
  90. expectloc:=LOC_REFERENCE;
  91. first_round_real := nil;
  92. end
  93. else
  94. result:=inherited first_round_real;
  95. end;
  96. { load the FPU into the an fpu register }
  97. procedure tgppcinlinenode.load_fpu_location;
  98. begin
  99. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  100. secondpass(left);
  101. location_force_fpureg(current_asmdata.CurrAsmList,left.location,true);
  102. location.loc := LOC_FPUREGISTER;
  103. location.register := cg.getfpuregister(current_asmdata.CurrAsmList,OS_F64);
  104. end;
  105. procedure tgppcinlinenode.second_sqrt_real;
  106. begin
  107. if (current_settings.cputype < cpu_PPC970) then
  108. internalerror(2007020910);
  109. location.loc:=LOC_FPUREGISTER;
  110. load_fpu_location;
  111. case left.location.size of
  112. OS_F32:
  113. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FSQRTS,location.register,
  114. left.location.register));
  115. OS_F64:
  116. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FSQRT,location.register,
  117. left.location.register));
  118. else
  119. inherited;
  120. end;
  121. end;
  122. procedure tgppcinlinenode.second_abs_real;
  123. begin
  124. location.loc:=LOC_FPUREGISTER;
  125. load_fpu_location;
  126. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FABS,location.register,
  127. left.location.register));
  128. end;
  129. procedure tgppcinlinenode.second_sqr_real;
  130. var
  131. op: tasmop;
  132. begin
  133. location.loc:=LOC_FPUREGISTER;
  134. load_fpu_location;
  135. if (left.location.size = OS_F32) then
  136. op := A_FMULS
  137. else
  138. op := A_FMUL;
  139. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,location.register,
  140. left.location.register,left.location.register));
  141. end;
  142. procedure tgppcinlinenode.second_trunc_round_real(op: tasmop);
  143. var
  144. tmpreg: tregister;
  145. begin
  146. if (current_settings.cputype < cpu_PPC970) then
  147. internalerror(2007020910);
  148. secondpass(left);
  149. location_force_fpureg(current_asmdata.CurrAsmList,left.location,true);
  150. tmpreg:=cg.getfpuregister(current_asmdata.CurrAsmList,OS_F64);
  151. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,tmpreg,
  152. left.location.register));
  153. location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),0);
  154. tg.gettemptyped(current_asmdata.CurrAsmList,resultdef,tt_normal,
  155. location.reference);
  156. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,OS_F64,OS_F64,tmpreg,
  157. location.reference);
  158. end;
  159. procedure tgppcinlinenode.second_trunc_real;
  160. begin
  161. second_trunc_round_real(A_FCTIDZ);
  162. end;
  163. procedure tgppcinlinenode.second_round_real;
  164. begin
  165. second_trunc_round_real(A_FCTID);
  166. end;
  167. procedure tgppcinlinenode.second_prefetch;
  168. var
  169. r: tregister;
  170. begin
  171. secondpass(left);
  172. case left.location.loc of
  173. LOC_CREFERENCE,
  174. LOC_REFERENCE:
  175. begin
  176. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  177. if (left.location.reference.offset = 0) and
  178. not assigned(left.location.reference.symbol) then
  179. begin
  180. if (left.location.reference.index = NR_NO) then
  181. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_DCBT,0,left.location.reference.base))
  182. else
  183. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_DCBT,left.location.reference.base,left.location.reference.index));
  184. end
  185. else
  186. begin
  187. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  188. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_DCBT,0,r));
  189. end;
  190. end;
  191. else
  192. internalerror(200402021);
  193. end;
  194. end;
  195. begin
  196. cinlinenode:=tgppcinlinenode;
  197. end.