ncpuinl.pas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate LoongArch64 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 ncpuinl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cpubase,
  22. node,ninl,ncginl;
  23. type
  24. tloongarch64inlinenode = 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_round_real: tnode; override;
  33. function first_trunc_real: tnode; override;
  34. procedure second_sqrt_real; override;
  35. procedure second_abs_real; override;
  36. procedure second_sqr_real; override;
  37. procedure second_round_real; override;
  38. procedure second_trunc_real; override;
  39. protected
  40. procedure load_fpu_location;
  41. end;
  42. implementation
  43. uses
  44. ncal,
  45. cutils,globals,verbose,globtype,
  46. aasmtai,aasmdata,aasmcpu,
  47. symconst,symdef,
  48. defutil,
  49. cgbase,pass_2,
  50. cpuinfo,ncgutil,
  51. hlcgobj,cgutils,cgobj,rgobj,tgobj;
  52. {*****************************************************************************
  53. tloongarch64inlinenode
  54. *****************************************************************************}
  55. function tloongarch64inlinenode.first_sqrt_real : tnode;
  56. begin
  57. expectloc:=LOC_FPUREGISTER;
  58. first_sqrt_real := nil;
  59. end;
  60. function tloongarch64inlinenode.first_abs_real : tnode;
  61. begin
  62. expectloc:=LOC_FPUREGISTER;
  63. first_abs_real := nil;
  64. end;
  65. function tloongarch64inlinenode.first_sqr_real : tnode;
  66. begin
  67. expectloc:=LOC_FPUREGISTER;
  68. first_sqr_real := nil;
  69. end;
  70. function tloongarch64inlinenode.first_round_real: tnode;
  71. begin
  72. expectloc:=LOC_FPUREGISTER;
  73. first_round_real := nil;
  74. end;
  75. function tloongarch64inlinenode.first_trunc_real: tnode;
  76. begin
  77. expectloc:=LOC_FPUREGISTER;
  78. first_trunc_real := nil;
  79. end;
  80. { load the FPU into the an fpu register }
  81. procedure tloongarch64inlinenode.load_fpu_location;
  82. begin
  83. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  84. secondpass(left);
  85. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  86. location.loc := LOC_FPUREGISTER;
  87. location.register := cg.getfpuregister(current_asmdata.CurrAsmList,def_cgsize(resultdef));
  88. end;
  89. procedure tloongarch64inlinenode.second_sqrt_real;
  90. var
  91. op: TAsmOp;
  92. begin
  93. location.loc:=LOC_FPUREGISTER;
  94. load_fpu_location;
  95. if (left.location.size = OS_F32) then
  96. op := A_FSQRT_S
  97. else
  98. op := A_FSQRT_D;
  99. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,location.register,left.location.register));
  100. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  101. end;
  102. procedure tloongarch64inlinenode.second_abs_real;
  103. var
  104. op: TAsmOp;
  105. begin
  106. location.loc:=LOC_FPUREGISTER;
  107. load_fpu_location;
  108. if (left.location.size = OS_F32) then
  109. op := A_FABS_S
  110. else
  111. op := A_FABS_D;
  112. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,location.register,left.location.register));
  113. end;
  114. procedure tloongarch64inlinenode.second_sqr_real;
  115. var
  116. op: tasmop;
  117. begin
  118. location.loc:=LOC_FPUREGISTER;
  119. load_fpu_location;
  120. if (left.location.size = OS_F32) then
  121. op := A_FMUL_S
  122. else
  123. op := A_FMUL_D;
  124. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,location.register,left.location.register,left.location.register));
  125. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  126. end;
  127. procedure tloongarch64inlinenode.second_round_real;
  128. var
  129. op: TAsmOp;
  130. hreg: tregister;
  131. begin
  132. secondpass(left);
  133. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  134. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  135. location.register:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  136. hreg:= cg.getfpuregister(current_asmdata.CurrAsmList, OS_F64);
  137. if (left.location.size = OS_F32) then
  138. op := A_FTINT_L_S
  139. else
  140. op := A_FTINT_L_D;
  141. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,hreg,left.location.register));
  142. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_MOVFR2GR_D,location.register,hreg));
  143. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  144. end;
  145. procedure tloongarch64inlinenode.second_trunc_real;
  146. var
  147. op,movop: TAsmOp;
  148. hreg: tregister;
  149. begin
  150. secondpass(left);
  151. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  152. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  153. location.register:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  154. hreg:= cg.getfpuregister(current_asmdata.CurrAsmList, OS_F64);
  155. if (left.location.size = OS_F32) then
  156. op := A_FTINTRZ_L_S
  157. else
  158. op := A_FTINTRZ_L_D;
  159. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,hreg,left.location.register));
  160. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_MOVFR2GR_D,location.register,hreg));
  161. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  162. end;
  163. begin
  164. cinlinenode:=tloongarch64inlinenode;
  165. end.