ncpuinl.pas 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. function first_minmax: tnode; override;
  30. procedure second_minmax; override;
  31. procedure second_prefetch; override;
  32. end;
  33. implementation
  34. uses
  35. cpuinfo,
  36. verbose,globals,globtype,
  37. compinnr,
  38. aasmdata,
  39. aasmcpu,
  40. symdef,
  41. defutil,
  42. hlcgobj,
  43. pass_2,
  44. cgbase, cgobj, cgutils,
  45. ncal,nutils,
  46. cpubase;
  47. procedure tcpuinlinenode.second_abs_long;
  48. begin
  49. secondpass(left);
  50. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  51. location:=left.location;
  52. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  53. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_ABS,location.register,left.location.register));
  54. end;
  55. function tcpuinlinenode.first_abs_real : tnode;
  56. begin
  57. result:=nil;
  58. if is_single(left.resultdef) and (FPUXTENSA_SINGLE in fpu_capabilities[current_settings.fputype]) then
  59. expectloc:=LOC_FPUREGISTER
  60. else
  61. result:=inherited first_abs_real;
  62. end;
  63. procedure tcpuinlinenode.second_abs_real;
  64. begin
  65. if not(is_single(resultdef)) then
  66. InternalError(2020091101);
  67. secondpass(left);
  68. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  69. location_reset(location,LOC_FPUREGISTER,OS_F32);
  70. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  71. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_ABS,location.register,left.location.register),PF_S));
  72. end;
  73. function tcpuinlinenode.first_fma : tnode;
  74. begin
  75. if is_single(resultdef) then
  76. begin
  77. expectloc:=LOC_FPUREGISTER;
  78. Result:=nil;
  79. end
  80. else
  81. Result:=inherited first_fma;
  82. end;
  83. procedure tcpuinlinenode.second_fma;
  84. const
  85. op : array[false..true] of TAsmOp =
  86. (A_MADD,
  87. A_MSUB);
  88. var
  89. paraarray : array[1..3] of tnode;
  90. i : integer;
  91. negproduct : boolean;
  92. oppostfix : TOpPostfix;
  93. ai: taicpu;
  94. begin
  95. if is_single(resultdef)and
  96. (FPUXTENSA_SINGLE in fpu_capabilities[current_settings.fputype]) then
  97. begin
  98. negproduct:=false;
  99. paraarray[1]:=tcallparanode(tcallparanode(tcallparanode(parameters).nextpara).nextpara).paravalue;
  100. paraarray[2]:=tcallparanode(tcallparanode(parameters).nextpara).paravalue;
  101. paraarray[3]:=tcallparanode(parameters).paravalue;
  102. { check if a neg. node can be removed
  103. this is possible because changing the sign of
  104. a floating point number does not affect its absolute
  105. value in any way
  106. }
  107. if paraarray[1].nodetype=unaryminusn then
  108. begin
  109. paraarray[1]:=tunarynode(paraarray[1]).left;
  110. { do not release the unused unary minus node, it is kept and release together with the other nodes,
  111. only no code is generated for it }
  112. negproduct:=not(negproduct);
  113. end;
  114. if paraarray[2].nodetype=unaryminusn then
  115. begin
  116. paraarray[2]:=tunarynode(paraarray[2]).left;
  117. { do not release the unused unary minus node, it is kept and release together with the other nodes,
  118. only no code is generated for it }
  119. negproduct:=not(negproduct);
  120. end;
  121. for i:=1 to 3 do
  122. secondpass(paraarray[i]);
  123. { no memory operand is allowed }
  124. for i:=1 to 3 do
  125. begin
  126. if not(paraarray[i].location.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
  127. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,paraarray[i].location,paraarray[i].resultdef,true);
  128. end;
  129. location_reset(location,LOC_FPUREGISTER,paraarray[1].location.size);
  130. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  131. hlcg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,paraarray[3].resultdef,resultdef,
  132. paraarray[3].location.register,location.register);
  133. ai:=taicpu.op_reg_reg_reg(op[negproduct],
  134. location.register,paraarray[1].location.register,paraarray[2].location.register);
  135. ai.oppostfix:=PF_S;
  136. current_asmdata.CurrAsmList.concat(ai);
  137. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  138. end
  139. else
  140. internalerror(2020112401);
  141. end;
  142. function tcpuinlinenode.first_minmax : tnode;
  143. begin
  144. if is_32bitint(resultdef) then
  145. begin
  146. expectloc:=LOC_REGISTER;
  147. Result:=nil;
  148. end
  149. else
  150. Result:=inherited first_minmax;
  151. end;
  152. procedure tcpuinlinenode.second_minmax;
  153. var
  154. paraarray : array[1..2] of tnode;
  155. i: Integer;
  156. ai: taicpu;
  157. op: TAsmOp;
  158. begin
  159. if is_32bitint(resultdef) then
  160. begin
  161. paraarray[1]:=tcallparanode(tcallparanode(parameters).nextpara).paravalue;
  162. paraarray[2]:=tcallparanode(parameters).paravalue;
  163. for i:=low(paraarray) to high(paraarray) do
  164. secondpass(paraarray[i]);
  165. { no memory operand is allowed }
  166. for i:=low(paraarray) to high(paraarray) do
  167. begin
  168. if not(paraarray[i].location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  169. hlcg.location_force_reg(current_asmdata.CurrAsmList,paraarray[i].location,
  170. paraarray[i].resultdef,resultdef,true);
  171. end;
  172. location_reset(location,LOC_REGISTER,paraarray[1].location.size);
  173. location.register:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  174. case inlinenumber of
  175. in_min_dword:
  176. op:=A_MINU;
  177. in_max_dword:
  178. op:=A_MAXU;
  179. in_min_longint:
  180. op:=A_MIN;
  181. in_max_longint:
  182. op:=A_MAX;
  183. else
  184. Internalerror(2020120505);
  185. end;
  186. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,
  187. location.register,paraarray[1].location.register,paraarray[2].location.register));
  188. cg.maybe_check_for_fpu_exception(current_asmdata.CurrAsmList);
  189. end
  190. else
  191. internalerror(2020120502);
  192. end;
  193. procedure tcpuinlinenode.second_prefetch;
  194. var
  195. ref : treference;
  196. r : tregister;
  197. checkpointer_used : boolean;
  198. begin
  199. { do not call Checkpointer for left node }
  200. checkpointer_used:=(cs_checkpointer in current_settings.localswitches);
  201. if checkpointer_used then
  202. node_change_local_switch(left,cs_checkpointer,false);
  203. secondpass(left);
  204. if checkpointer_used then
  205. node_change_local_switch(left,cs_checkpointer,false);
  206. case left.location.loc of
  207. LOC_CREFERENCE,
  208. LOC_REFERENCE:
  209. begin
  210. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  211. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  212. reference_reset_base(ref,r,0,location.reference.temppos,left.location.reference.alignment,location.reference.volatility);
  213. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_DPFR,ref.base,ref.offset));
  214. end;
  215. else
  216. { nothing to prefetch };
  217. end;
  218. end;
  219. begin
  220. cinlinenode:=tcpuinlinenode;
  221. end.