ncpuinl.pas 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. {
  2. Copyright (c) 1998-2017 by Florian Klaempfl
  3. Generates Xtensa 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. node,ninl,ncginl, aasmbase;
  22. type
  23. tcpuinlineNode = class(tcginlinenode)
  24. function first_abs_real: tnode; override;
  25. procedure second_abs_long; override;
  26. procedure second_abs_real; override;
  27. function first_fma: tnode; override;
  28. procedure second_fma; override;
  29. end;
  30. implementation
  31. uses
  32. cpuinfo,
  33. verbose,globals,
  34. compinnr,
  35. aasmdata,
  36. aasmcpu,
  37. symdef,
  38. defutil,
  39. hlcgobj,
  40. pass_2,
  41. cgbase, cgobj, cgutils,
  42. ncal,
  43. cpubase;
  44. procedure tcpuinlinenode.second_abs_long;
  45. begin
  46. secondpass(left);
  47. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  48. location:=left.location;
  49. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  50. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_ABS,location.register,left.location.register));
  51. end;
  52. function tcpuinlinenode.first_abs_real : tnode;
  53. begin
  54. result:=nil;
  55. if is_single(left.resultdef) and (FPUXTENSA_SINGLE in fpu_capabilities[current_settings.fputype]) then
  56. expectloc:=LOC_FPUREGISTER
  57. else
  58. result:=inherited first_abs_real;
  59. end;
  60. procedure tcpuinlinenode.second_abs_real;
  61. begin
  62. if not(is_single(resultdef)) then
  63. InternalError(2020091101);
  64. secondpass(left);
  65. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  66. location_reset(location,LOC_FPUREGISTER,OS_F32);
  67. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  68. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_ABS,location.register,left.location.register),PF_S));
  69. end;
  70. function tcpuinlinenode.first_fma : tnode;
  71. begin
  72. if is_single(resultdef) then
  73. begin
  74. expectloc:=LOC_FPUREGISTER;
  75. Result:=nil;
  76. end
  77. else
  78. Result:=inherited first_fma;
  79. end;
  80. procedure tcpuinlinenode.second_fma;
  81. const
  82. op : array[false..true] of TAsmOp =
  83. (A_MADD,
  84. A_MSUB);
  85. var
  86. paraarray : array[1..3] of tnode;
  87. i : integer;
  88. negproduct : boolean;
  89. oppostfix : TOpPostfix;
  90. ai: taicpu;
  91. begin
  92. if is_single(resultdef)and
  93. (FPUXTENSA_SINGLE in fpu_capabilities[current_settings.fputype]) then
  94. begin
  95. negproduct:=false;
  96. paraarray[1]:=tcallparanode(tcallparanode(tcallparanode(parameters).nextpara).nextpara).paravalue;
  97. paraarray[2]:=tcallparanode(tcallparanode(parameters).nextpara).paravalue;
  98. paraarray[3]:=tcallparanode(parameters).paravalue;
  99. { check if a neg. node can be removed
  100. this is possible because changing the sign of
  101. a floating point number does not affect its absolute
  102. value in any way
  103. }
  104. if paraarray[1].nodetype=unaryminusn then
  105. begin
  106. paraarray[1]:=tunarynode(paraarray[1]).left;
  107. { do not release the unused unary minus node, it is kept and release together with the other nodes,
  108. only no code is generated for it }
  109. negproduct:=not(negproduct);
  110. end;
  111. if paraarray[2].nodetype=unaryminusn then
  112. begin
  113. paraarray[2]:=tunarynode(paraarray[2]).left;
  114. { do not release the unused unary minus node, it is kept and release together with the other nodes,
  115. only no code is generated for it }
  116. negproduct:=not(negproduct);
  117. end;
  118. for i:=1 to 3 do
  119. secondpass(paraarray[i]);
  120. { no memory operand is allowed }
  121. for i:=1 to 3 do
  122. begin
  123. if not(paraarray[i].location.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
  124. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,paraarray[i].location,paraarray[i].resultdef,true);
  125. end;
  126. location_reset(location,LOC_FPUREGISTER,paraarray[1].location.size);
  127. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  128. hlcg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,paraarray[3].resultdef,resultdef,
  129. paraarray[3].location.register,location.register);
  130. ai:=taicpu.op_reg_reg_reg(op[negproduct],
  131. location.register,paraarray[1].location.register,paraarray[2].location.register);
  132. ai.oppostfix:=PF_S;
  133. current_asmdata.CurrAsmList.concat(ai);
  134. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  135. end
  136. else
  137. internalerror(2020112401);
  138. end;
  139. begin
  140. cinlinenode:=tcpuinlinenode;
  141. end.