narminl.pas 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generates ARM 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 narminl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ninl,ncginl;
  22. type
  23. tarminlinenode = class(tcgInlineNode)
  24. function first_abs_real: tnode; override;
  25. function first_sqr_real: tnode; override;
  26. function first_sqrt_real: tnode; override;
  27. { atn,sin,cos,lgn isn't supported by the linux fpe
  28. function first_arctan_real: tnode; override;
  29. function first_ln_real: tnode; override;
  30. function first_cos_real: tnode; override;
  31. function first_sin_real: tnode; override;
  32. }
  33. procedure second_abs_real; override;
  34. procedure second_sqr_real; override;
  35. procedure second_sqrt_real; override;
  36. { atn,sin,cos,lgn isn't supported by the linux fpe
  37. procedure second_arctan_real; override;
  38. procedure second_ln_real; override;
  39. procedure second_cos_real; override;
  40. procedure second_sin_real; override;
  41. }
  42. procedure second_prefetch; override;
  43. private
  44. procedure load_fpu_location;
  45. end;
  46. implementation
  47. uses
  48. globtype,systems,
  49. cutils,verbose,globals,fmodule,
  50. cpuinfo,
  51. symconst,symdef,
  52. aasmbase,aasmtai,aasmdata,aasmcpu,
  53. cgbase,cgutils,
  54. pass_1,pass_2,
  55. cpubase,paramgr,
  56. nbas,ncon,ncal,ncnv,nld,
  57. tgobj,ncgutil,cgobj,cg64f32,rgobj,rgcpu,cgcpu;
  58. {*****************************************************************************
  59. tarminlinenode
  60. *****************************************************************************}
  61. procedure tarminlinenode.load_fpu_location;
  62. begin
  63. secondpass(left);
  64. location_force_fpureg(current_asmdata.CurrAsmList,left.location,true);
  65. location_copy(location,left.location);
  66. if left.location.loc=LOC_CFPUREGISTER then
  67. begin
  68. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  69. location.loc := LOC_FPUREGISTER;
  70. end;
  71. end;
  72. function tarminlinenode.first_abs_real : tnode;
  73. begin
  74. if cs_fp_emulation in current_settings.moduleswitches then
  75. result:=inherited first_abs_real
  76. else
  77. begin
  78. expectloc:=LOC_FPUREGISTER;
  79. registersint:=left.registersint;
  80. registersfpu:=max(left.registersfpu,1);
  81. first_abs_real:=nil;
  82. end;
  83. end;
  84. function tarminlinenode.first_sqr_real : tnode;
  85. begin
  86. if cs_fp_emulation in current_settings.moduleswitches then
  87. result:=inherited first_sqr_real
  88. else
  89. begin
  90. expectloc:=LOC_FPUREGISTER;
  91. registersint:=left.registersint;
  92. registersfpu:=max(left.registersfpu,1);
  93. first_sqr_real:=nil;
  94. end;
  95. end;
  96. function tarminlinenode.first_sqrt_real : tnode;
  97. begin
  98. if cs_fp_emulation in current_settings.moduleswitches then
  99. result:=inherited first_sqrt_real
  100. else
  101. begin
  102. expectloc:=LOC_FPUREGISTER;
  103. registersint:=left.registersint;
  104. registersfpu:=max(left.registersfpu,1);
  105. first_sqrt_real := nil;
  106. end;
  107. end;
  108. { atn,sin,cos,lgn isn't supported by the linux fpe
  109. function tarminlinenode.first_arctan_real: tnode;
  110. begin
  111. expectloc:=LOC_FPUREGISTER;
  112. registersint:=left.registersint;
  113. registersfpu:=max(left.registersfpu,1);
  114. result:=nil;
  115. end;
  116. function tarminlinenode.first_ln_real: tnode;
  117. begin
  118. expectloc:=LOC_FPUREGISTER;
  119. registersint:=left.registersint;
  120. registersfpu:=max(left.registersfpu,1);
  121. result:=nil;
  122. end;
  123. function tarminlinenode.first_cos_real: tnode;
  124. begin
  125. expectloc:=LOC_FPUREGISTER;
  126. registersint:=left.registersint;
  127. registersfpu:=max(left.registersfpu,1);
  128. result:=nil;
  129. end;
  130. function tarminlinenode.first_sin_real: tnode;
  131. begin
  132. expectloc:=LOC_FPUREGISTER;
  133. registersint:=left.registersint;
  134. registersfpu:=max(left.registersfpu,1);
  135. result:=nil;
  136. end;
  137. }
  138. procedure tarminlinenode.second_abs_real;
  139. begin
  140. load_fpu_location;
  141. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_ABS,location.register,left.location.register),get_fpu_postfix(resultdef)));
  142. end;
  143. procedure tarminlinenode.second_sqr_real;
  144. begin
  145. load_fpu_location;
  146. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg_reg(A_MUF,location.register,left.location.register,left.location.register),get_fpu_postfix(resultdef)));
  147. end;
  148. procedure tarminlinenode.second_sqrt_real;
  149. begin
  150. load_fpu_location;
  151. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_SQT,location.register,left.location.register),get_fpu_postfix(resultdef)));
  152. end;
  153. { atn, sin, cos, lgn isn't supported by the linux fpe
  154. procedure tarminlinenode.second_arctan_real;
  155. begin
  156. load_fpu_location;
  157. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_ATN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  158. end;
  159. procedure tarminlinenode.second_ln_real;
  160. begin
  161. load_fpu_location;
  162. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_LGN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  163. end;
  164. procedure tarminlinenode.second_cos_real;
  165. begin
  166. load_fpu_location;
  167. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_COS,location.register,left.location.register),get_fpu_postfix(resultdef)));
  168. end;
  169. procedure tarminlinenode.second_sin_real;
  170. begin
  171. load_fpu_location;
  172. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_SIN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  173. end;
  174. }
  175. procedure tarminlinenode.second_prefetch;
  176. var
  177. ref : treference;
  178. r : tregister;
  179. begin
  180. if current_settings.cputype>=cpu_armv5 then
  181. begin
  182. secondpass(left);
  183. case left.location.loc of
  184. LOC_CREFERENCE,
  185. LOC_REFERENCE:
  186. begin
  187. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  188. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  189. reference_reset_base(ref,r,0);
  190. { since the address might be nil we can't use ldr for older cpus }
  191. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_PLD,ref));
  192. end;
  193. else
  194. internalerror(200402021);
  195. end;
  196. end;
  197. end;
  198. begin
  199. cinlinenode:=tarminlinenode;
  200. end.