ncpuinl.pas 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. procinfo,
  50. cgbase,pass_2,
  51. cpuinfo,ncgutil,
  52. hlcgobj,cgutils,cgobj,rgobj,tgobj;
  53. {*****************************************************************************
  54. tloongarch64inlinenode
  55. *****************************************************************************}
  56. function tloongarch64inlinenode.first_sqrt_real : tnode;
  57. begin
  58. expectloc:=LOC_FPUREGISTER;
  59. first_sqrt_real := nil;
  60. if needs_check_for_fpu_exceptions then
  61. Include(current_procinfo.flags,pi_do_call);
  62. end;
  63. function tloongarch64inlinenode.first_abs_real : tnode;
  64. begin
  65. expectloc:=LOC_FPUREGISTER;
  66. first_abs_real := nil;
  67. end;
  68. function tloongarch64inlinenode.first_sqr_real : tnode;
  69. begin
  70. expectloc:=LOC_FPUREGISTER;
  71. first_sqr_real := nil;
  72. if needs_check_for_fpu_exceptions then
  73. Include(current_procinfo.flags,pi_do_call);
  74. end;
  75. function tloongarch64inlinenode.first_round_real: tnode;
  76. begin
  77. expectloc:=LOC_FPUREGISTER;
  78. first_round_real := nil;
  79. if needs_check_for_fpu_exceptions then
  80. Include(current_procinfo.flags,pi_do_call);
  81. end;
  82. function tloongarch64inlinenode.first_trunc_real: tnode;
  83. begin
  84. expectloc:=LOC_FPUREGISTER;
  85. first_trunc_real := nil;
  86. if needs_check_for_fpu_exceptions then
  87. Include(current_procinfo.flags,pi_do_call);
  88. end;
  89. { load the FPU into the an fpu register }
  90. procedure tloongarch64inlinenode.load_fpu_location;
  91. begin
  92. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  93. secondpass(left);
  94. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  95. location.loc := LOC_FPUREGISTER;
  96. location.register := cg.getfpuregister(current_asmdata.CurrAsmList,def_cgsize(resultdef));
  97. end;
  98. procedure tloongarch64inlinenode.second_sqrt_real;
  99. var
  100. op: TAsmOp;
  101. begin
  102. location.loc:=LOC_FPUREGISTER;
  103. load_fpu_location;
  104. if (left.location.size = OS_F32) then
  105. op := A_FSQRT_S
  106. else
  107. op := A_FSQRT_D;
  108. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,location.register,left.location.register));
  109. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  110. end;
  111. procedure tloongarch64inlinenode.second_abs_real;
  112. var
  113. op: TAsmOp;
  114. begin
  115. location.loc:=LOC_FPUREGISTER;
  116. load_fpu_location;
  117. if (left.location.size = OS_F32) then
  118. op := A_FABS_S
  119. else
  120. op := A_FABS_D;
  121. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,location.register,left.location.register));
  122. end;
  123. procedure tloongarch64inlinenode.second_sqr_real;
  124. var
  125. op: tasmop;
  126. begin
  127. location.loc:=LOC_FPUREGISTER;
  128. load_fpu_location;
  129. if (left.location.size = OS_F32) then
  130. op := A_FMUL_S
  131. else
  132. op := A_FMUL_D;
  133. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,location.register,left.location.register,left.location.register));
  134. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  135. end;
  136. procedure tloongarch64inlinenode.second_round_real;
  137. var
  138. op: TAsmOp;
  139. hreg: tregister;
  140. begin
  141. secondpass(left);
  142. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  143. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  144. location.register:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  145. hreg:= cg.getfpuregister(current_asmdata.CurrAsmList, OS_F64);
  146. if (left.location.size = OS_F32) then
  147. op := A_FTINT_L_S
  148. else
  149. op := A_FTINT_L_D;
  150. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,hreg,left.location.register));
  151. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_MOVFR2GR_D,location.register,hreg));
  152. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  153. end;
  154. procedure tloongarch64inlinenode.second_trunc_real;
  155. var
  156. op,movop: TAsmOp;
  157. hreg: tregister;
  158. begin
  159. secondpass(left);
  160. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  161. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  162. location.register:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  163. hreg:= cg.getfpuregister(current_asmdata.CurrAsmList, OS_F64);
  164. if (left.location.size = OS_F32) then
  165. op := A_FTINTRZ_L_S
  166. else
  167. op := A_FTINTRZ_L_D;
  168. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,hreg,left.location.register));
  169. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_MOVFR2GR_D,location.register,hreg));
  170. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  171. end;
  172. begin
  173. cinlinenode:=tloongarch64inlinenode;
  174. end.