2
0

narminl.pas 10 KB

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