narminl.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. procedure second_incdec; override;
  44. private
  45. procedure load_fpu_location;
  46. end;
  47. implementation
  48. uses
  49. globtype,systems,
  50. cutils,verbose,globals,fmodule,
  51. cpuinfo,
  52. symconst,symdef,
  53. aasmbase,aasmtai,aasmdata,aasmcpu,
  54. cgbase,cgutils,
  55. pass_1,pass_2,
  56. cpubase,paramgr,
  57. nbas,ncon,ncal,ncnv,nld,
  58. tgobj,ncgutil,cgobj,cg64f32,rgobj,rgcpu,cgcpu;
  59. {*****************************************************************************
  60. tarminlinenode
  61. *****************************************************************************}
  62. procedure tarminlinenode.load_fpu_location;
  63. begin
  64. secondpass(left);
  65. location_force_fpureg(current_asmdata.CurrAsmList,left.location,true);
  66. location_copy(location,left.location);
  67. if left.location.loc=LOC_CFPUREGISTER then
  68. begin
  69. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  70. location.loc := LOC_FPUREGISTER;
  71. end;
  72. end;
  73. function tarminlinenode.first_abs_real : tnode;
  74. begin
  75. if cs_fp_emulation in current_settings.moduleswitches then
  76. result:=inherited first_abs_real
  77. else
  78. begin
  79. expectloc:=LOC_FPUREGISTER;
  80. first_abs_real:=nil;
  81. end;
  82. end;
  83. function tarminlinenode.first_sqr_real : tnode;
  84. begin
  85. if cs_fp_emulation in current_settings.moduleswitches then
  86. result:=inherited first_sqr_real
  87. else
  88. begin
  89. expectloc:=LOC_FPUREGISTER;
  90. first_sqr_real:=nil;
  91. end;
  92. end;
  93. function tarminlinenode.first_sqrt_real : tnode;
  94. begin
  95. if cs_fp_emulation in current_settings.moduleswitches then
  96. result:=inherited first_sqrt_real
  97. else
  98. begin
  99. expectloc:=LOC_FPUREGISTER;
  100. first_sqrt_real := nil;
  101. end;
  102. end;
  103. { atn,sin,cos,lgn isn't supported by the linux fpe
  104. function tarminlinenode.first_arctan_real: tnode;
  105. begin
  106. expectloc:=LOC_FPUREGISTER;
  107. result:=nil;
  108. end;
  109. function tarminlinenode.first_ln_real: tnode;
  110. begin
  111. expectloc:=LOC_FPUREGISTER;
  112. result:=nil;
  113. end;
  114. function tarminlinenode.first_cos_real: tnode;
  115. begin
  116. expectloc:=LOC_FPUREGISTER;
  117. result:=nil;
  118. end;
  119. function tarminlinenode.first_sin_real: tnode;
  120. begin
  121. expectloc:=LOC_FPUREGISTER;
  122. result:=nil;
  123. end;
  124. }
  125. procedure tarminlinenode.second_abs_real;
  126. begin
  127. load_fpu_location;
  128. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_ABS,location.register,left.location.register),get_fpu_postfix(resultdef)));
  129. end;
  130. procedure tarminlinenode.second_sqr_real;
  131. begin
  132. load_fpu_location;
  133. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg_reg(A_MUF,location.register,left.location.register,left.location.register),get_fpu_postfix(resultdef)));
  134. end;
  135. procedure tarminlinenode.second_sqrt_real;
  136. begin
  137. load_fpu_location;
  138. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_SQT,location.register,left.location.register),get_fpu_postfix(resultdef)));
  139. end;
  140. { atn, sin, cos, lgn isn't supported by the linux fpe
  141. procedure tarminlinenode.second_arctan_real;
  142. begin
  143. load_fpu_location;
  144. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_ATN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  145. end;
  146. procedure tarminlinenode.second_ln_real;
  147. begin
  148. load_fpu_location;
  149. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_LGN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  150. end;
  151. procedure tarminlinenode.second_cos_real;
  152. begin
  153. load_fpu_location;
  154. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_COS,location.register,left.location.register),get_fpu_postfix(resultdef)));
  155. end;
  156. procedure tarminlinenode.second_sin_real;
  157. begin
  158. load_fpu_location;
  159. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_SIN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  160. end;
  161. }
  162. procedure tarminlinenode.second_prefetch;
  163. var
  164. ref : treference;
  165. r : tregister;
  166. begin
  167. if current_settings.cputype>=cpu_armv5 then
  168. begin
  169. secondpass(left);
  170. case left.location.loc of
  171. LOC_CREFERENCE,
  172. LOC_REFERENCE:
  173. begin
  174. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  175. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  176. reference_reset_base(ref,r,0);
  177. { since the address might be nil we can't use ldr for older cpus }
  178. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_PLD,ref));
  179. end;
  180. else
  181. internalerror(200402021);
  182. end;
  183. end;
  184. end;
  185. procedure tarminlinenode.second_incdec;
  186. begin
  187. inherited second_incdec;
  188. { Strip result if inc/dec is performed in register on value less than 32-bit }
  189. with tcallparanode(left).left.location do
  190. if (loc in [LOC_REGISTER,LOC_CREGISTER]) and (tcgsize2size[size]<sizeof(aint)) then
  191. cg.a_load_reg_reg(current_asmdata.CurrAsmList, size, OS_32, register, register)
  192. end;
  193. begin
  194. cinlinenode:=tarminlinenode;
  195. end.