nppcinl.pas 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate i386 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 nppcinl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ninl,ncginl;
  22. type
  23. tppcinlinenode = class(tcginlinenode)
  24. { first pass override
  25. so that the code generator will actually generate
  26. these nodes.
  27. }
  28. function first_abs_real: tnode; override;
  29. function first_sqr_real: tnode; override;
  30. procedure second_abs_real; override;
  31. procedure second_sqr_real; override;
  32. procedure second_prefetch;override;
  33. private
  34. procedure load_fpu_location;
  35. end;
  36. implementation
  37. uses
  38. cutils,globals,verbose,
  39. aasmtai,aasmdata,aasmcpu,
  40. symconst,symdef,
  41. defutil,
  42. cgbase,pass_2,
  43. cpubase,ncgutil,
  44. cgutils,cgobj,rgobj;
  45. {*****************************************************************************
  46. TPPCINLINENODE
  47. *****************************************************************************}
  48. function tppcinlinenode.first_abs_real : tnode;
  49. begin
  50. expectloc:=LOC_FPUREGISTER;
  51. registersint:=left.registersint;
  52. registersfpu:=max(left.registersfpu,1);
  53. {$ifdef SUPPORT_MMX}
  54. registersmmx:=left.registersmmx;
  55. {$endif SUPPORT_MMX}
  56. first_abs_real := nil;
  57. end;
  58. function tppcinlinenode.first_sqr_real : tnode;
  59. begin
  60. expectloc:=LOC_FPUREGISTER;
  61. registersint:=left.registersint;
  62. registersfpu:=max(left.registersfpu,1);
  63. {$ifdef SUPPORT_MMX}
  64. registersmmx:=left.registersmmx;
  65. {$endif SUPPORT_MMX}
  66. first_sqr_real := nil;
  67. end;
  68. { load the FPU into the an fpu register }
  69. procedure tppcinlinenode.load_fpu_location;
  70. begin
  71. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  72. secondpass(left);
  73. location_force_fpureg(current_asmdata.CurrAsmList,left.location,true);
  74. location_copy(location,left.location);
  75. if (location.loc = LOC_CFPUREGISTER) then
  76. begin
  77. location.loc := LOC_FPUREGISTER;
  78. location.register := cg.getfpuregister(current_asmdata.CurrAsmList,OS_F64);
  79. end;
  80. end;
  81. procedure tppcinlinenode.second_abs_real;
  82. begin
  83. location.loc:=LOC_FPUREGISTER;
  84. load_fpu_location;
  85. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FABS,location.register,
  86. left.location.register));
  87. end;
  88. procedure tppcinlinenode.second_sqr_real;
  89. var
  90. op: tasmop;
  91. begin
  92. location.loc:=LOC_FPUREGISTER;
  93. load_fpu_location;
  94. if (left.location.size = OS_F32) then
  95. op := A_FMULS
  96. else
  97. op := A_FMUL;
  98. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,location.register,
  99. left.location.register,left.location.register));
  100. end;
  101. procedure tppcinlinenode.second_prefetch;
  102. var
  103. r: tregister;
  104. begin
  105. secondpass(left);
  106. case left.location.loc of
  107. LOC_CREFERENCE,
  108. LOC_REFERENCE:
  109. begin
  110. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  111. if (left.location.reference.offset = 0) and
  112. not assigned(left.location.reference.symbol) then
  113. begin
  114. if (left.location.reference.index = NR_NO) then
  115. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_DCBT,0,left.location.reference.base))
  116. else
  117. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_DCBT,left.location.reference.base,left.location.reference.index));
  118. end
  119. else
  120. begin
  121. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  122. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_DCBT,0,r));
  123. end;
  124. end;
  125. else
  126. internalerror(200402021);
  127. end;
  128. end;
  129. begin
  130. cinlinenode:=tppcinlinenode;
  131. end.