narminl.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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(out singleprec: boolean);
  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(out singleprec: boolean);
  62. begin
  63. secondpass(left);
  64. case current_settings.fputype of
  65. fpu_fpa,
  66. fpu_fpa10,
  67. fpu_fpa11:
  68. begin
  69. location_force_fpureg(current_asmdata.CurrAsmList,left.location,true);
  70. location_copy(location,left.location);
  71. if left.location.loc=LOC_CFPUREGISTER then
  72. begin
  73. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  74. location.loc := LOC_FPUREGISTER;
  75. end;
  76. end;
  77. fpu_vfpv2,
  78. fpu_vfpv3,
  79. fpu_vfpv3_d16:
  80. begin
  81. location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,true);
  82. location_copy(location,left.location);
  83. if left.location.loc=LOC_CMMREGISTER then
  84. begin
  85. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  86. location.loc := LOC_MMREGISTER;
  87. end;
  88. end;
  89. else
  90. internalerror(2009111801);
  91. end;
  92. singleprec:=tfloatdef(left.resultdef).floattype=s32real;
  93. end;
  94. function tarminlinenode.first_abs_real : tnode;
  95. begin
  96. if (cs_fp_emulation in current_settings.moduleswitches) then
  97. result:=inherited first_abs_real
  98. else
  99. begin
  100. case current_settings.fputype of
  101. fpu_fpa,
  102. fpu_fpa10,
  103. fpu_fpa11:
  104. expectloc:=LOC_FPUREGISTER;
  105. fpu_vfpv2,
  106. fpu_vfpv3,
  107. fpu_vfpv3_d16:
  108. expectloc:=LOC_MMREGISTER;
  109. else
  110. internalerror(2009112401);
  111. end;
  112. first_abs_real:=nil;
  113. end;
  114. end;
  115. function tarminlinenode.first_sqr_real : tnode;
  116. begin
  117. if (cs_fp_emulation in current_settings.moduleswitches) then
  118. result:=inherited first_sqr_real
  119. else
  120. begin
  121. case current_settings.fputype of
  122. fpu_fpa,
  123. fpu_fpa10,
  124. fpu_fpa11:
  125. expectloc:=LOC_FPUREGISTER;
  126. fpu_vfpv2,
  127. fpu_vfpv3,
  128. fpu_vfpv3_d16:
  129. expectloc:=LOC_MMREGISTER;
  130. else
  131. internalerror(2009112402);
  132. end;
  133. first_sqr_real:=nil;
  134. end;
  135. end;
  136. function tarminlinenode.first_sqrt_real : tnode;
  137. begin
  138. if cs_fp_emulation in current_settings.moduleswitches then
  139. result:=inherited first_sqrt_real
  140. else
  141. begin
  142. case current_settings.fputype of
  143. fpu_fpa,
  144. fpu_fpa10,
  145. fpu_fpa11:
  146. expectloc:=LOC_FPUREGISTER;
  147. fpu_vfpv2,
  148. fpu_vfpv3,
  149. fpu_vfpv3_d16:
  150. expectloc:=LOC_MMREGISTER;
  151. else
  152. internalerror(2009112403);
  153. end;
  154. first_sqrt_real := nil;
  155. end;
  156. end;
  157. { atn,sin,cos,lgn isn't supported by the linux fpe
  158. function tarminlinenode.first_arctan_real: tnode;
  159. begin
  160. expectloc:=LOC_FPUREGISTER;
  161. result:=nil;
  162. end;
  163. function tarminlinenode.first_ln_real: tnode;
  164. begin
  165. expectloc:=LOC_FPUREGISTER;
  166. result:=nil;
  167. end;
  168. function tarminlinenode.first_cos_real: tnode;
  169. begin
  170. expectloc:=LOC_FPUREGISTER;
  171. result:=nil;
  172. end;
  173. function tarminlinenode.first_sin_real: tnode;
  174. begin
  175. expectloc:=LOC_FPUREGISTER;
  176. result:=nil;
  177. end;
  178. }
  179. procedure tarminlinenode.second_abs_real;
  180. var
  181. singleprec: boolean;
  182. op: TAsmOp;
  183. begin
  184. load_fpu_location(singleprec);
  185. case current_settings.fputype of
  186. fpu_fpa,
  187. fpu_fpa10,
  188. fpu_fpa11:
  189. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_ABS,location.register,left.location.register),get_fpu_postfix(resultdef)));
  190. fpu_vfpv2,
  191. fpu_vfpv3,
  192. fpu_vfpv3_d16:
  193. begin
  194. if singleprec then
  195. op:=A_FABSS
  196. else
  197. op:=A_FABSD;
  198. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,location.register,left.location.register));
  199. end;
  200. else
  201. internalerror(2009111402);
  202. end;
  203. end;
  204. procedure tarminlinenode.second_sqr_real;
  205. var
  206. singleprec: boolean;
  207. op: TAsmOp;
  208. begin
  209. load_fpu_location(singleprec);
  210. case current_settings.fputype of
  211. fpu_fpa,
  212. fpu_fpa10,
  213. fpu_fpa11:
  214. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg_reg(A_MUF,location.register,left.location.register,left.location.register),get_fpu_postfix(resultdef)));
  215. fpu_vfpv2,
  216. fpu_vfpv3,
  217. fpu_vfpv3_d16:
  218. begin
  219. if singleprec then
  220. op:=A_FMULS
  221. else
  222. op:=A_FMULD;
  223. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,location.register,left.location.register,left.location.register));
  224. end;
  225. else
  226. internalerror(2009111403);
  227. end;
  228. end;
  229. procedure tarminlinenode.second_sqrt_real;
  230. var
  231. singleprec: boolean;
  232. op: TAsmOp;
  233. begin
  234. load_fpu_location(singleprec);
  235. case current_settings.fputype of
  236. fpu_fpa,
  237. fpu_fpa10,
  238. fpu_fpa11:
  239. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_SQT,location.register,left.location.register),get_fpu_postfix(resultdef)));
  240. fpu_vfpv2,
  241. fpu_vfpv3,
  242. fpu_vfpv3_d16:
  243. begin
  244. if singleprec then
  245. op:=A_FSQRTS
  246. else
  247. op:=A_FSQRTD;
  248. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,location.register,left.location.register));
  249. end;
  250. else
  251. internalerror(2009111402);
  252. end;
  253. end;
  254. { atn, sin, cos, lgn isn't supported by the linux fpe
  255. procedure tarminlinenode.second_arctan_real;
  256. begin
  257. load_fpu_location;
  258. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_ATN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  259. end;
  260. procedure tarminlinenode.second_ln_real;
  261. begin
  262. load_fpu_location;
  263. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_LGN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  264. end;
  265. procedure tarminlinenode.second_cos_real;
  266. begin
  267. load_fpu_location;
  268. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_COS,location.register,left.location.register),get_fpu_postfix(resultdef)));
  269. end;
  270. procedure tarminlinenode.second_sin_real;
  271. begin
  272. load_fpu_location;
  273. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_SIN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  274. end;
  275. }
  276. procedure tarminlinenode.second_prefetch;
  277. var
  278. ref : treference;
  279. r : tregister;
  280. begin
  281. if current_settings.cputype>=cpu_armv5 then
  282. begin
  283. secondpass(left);
  284. case left.location.loc of
  285. LOC_CREFERENCE,
  286. LOC_REFERENCE:
  287. begin
  288. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  289. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  290. reference_reset_base(ref,r,0,left.location.reference.alignment);
  291. { since the address might be nil we can't use ldr for older cpus }
  292. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_PLD,ref));
  293. end;
  294. else
  295. internalerror(200402021);
  296. end;
  297. end;
  298. end;
  299. begin
  300. cinlinenode:=tarminlinenode;
  301. end.