ngppcinl.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. first_sqrt_real := nil;
  56. end
  57. else
  58. result:=inherited first_sqrt_real;
  59. end;
  60. function tgppcinlinenode.first_abs_real : tnode;
  61. begin
  62. expectloc:=LOC_FPUREGISTER;
  63. first_abs_real := nil;
  64. end;
  65. function tgppcinlinenode.first_sqr_real : tnode;
  66. begin
  67. expectloc:=LOC_FPUREGISTER;
  68. first_sqr_real := nil;
  69. end;
  70. { load the FPU into the an fpu register }
  71. procedure tgppcinlinenode.load_fpu_location;
  72. begin
  73. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  74. secondpass(left);
  75. location_force_fpureg(current_asmdata.CurrAsmList,left.location,true);
  76. location.loc := LOC_FPUREGISTER;
  77. location.register := cg.getfpuregister(current_asmdata.CurrAsmList,OS_F64);
  78. end;
  79. procedure tgppcinlinenode.second_sqrt_real;
  80. begin
  81. if (current_settings.cputype < cpu_PPC970) then
  82. internalerror(2007020910);
  83. location.loc:=LOC_FPUREGISTER;
  84. load_fpu_location;
  85. case left.location.size of
  86. OS_F32:
  87. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FSQRTS,location.register,
  88. left.location.register));
  89. OS_F64:
  90. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FSQRT,location.register,
  91. left.location.register));
  92. else
  93. inherited;
  94. end;
  95. end;
  96. procedure tgppcinlinenode.second_abs_real;
  97. begin
  98. location.loc:=LOC_FPUREGISTER;
  99. load_fpu_location;
  100. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FABS,location.register,
  101. left.location.register));
  102. end;
  103. procedure tgppcinlinenode.second_sqr_real;
  104. var
  105. op: tasmop;
  106. begin
  107. location.loc:=LOC_FPUREGISTER;
  108. load_fpu_location;
  109. if (left.location.size = OS_F32) then
  110. op := A_FMULS
  111. else
  112. op := A_FMUL;
  113. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,location.register,
  114. left.location.register,left.location.register));
  115. end;
  116. procedure tgppcinlinenode.second_prefetch;
  117. var
  118. r: tregister;
  119. begin
  120. secondpass(left);
  121. case left.location.loc of
  122. LOC_CREFERENCE,
  123. LOC_REFERENCE:
  124. begin
  125. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  126. if (left.location.reference.offset = 0) and
  127. not assigned(left.location.reference.symbol) then
  128. begin
  129. if (left.location.reference.index = NR_NO) then
  130. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_DCBT,0,left.location.reference.base))
  131. else
  132. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_DCBT,left.location.reference.base,left.location.reference.index));
  133. end
  134. else
  135. begin
  136. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  137. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_DCBT,0,r));
  138. end;
  139. end;
  140. else
  141. internalerror(200402021);
  142. end;
  143. end;
  144. begin
  145. cinlinenode:=tgppcinlinenode;
  146. end.