narminl.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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_abs_long; override;
  44. private
  45. procedure load_fpu_location(out singleprec: boolean);
  46. end;
  47. implementation
  48. uses
  49. globtype,verbose,globals,
  50. cpuinfo, defutil,symdef,aasmdata,aasmcpu,
  51. cgbase,cgutils,pass_2,
  52. cpubase,ncgutil,cgobj,cgcpu, hlcgobj;
  53. {*****************************************************************************
  54. tarminlinenode
  55. *****************************************************************************}
  56. procedure tarminlinenode.load_fpu_location(out singleprec: boolean);
  57. begin
  58. secondpass(left);
  59. case current_settings.fputype of
  60. fpu_fpa,
  61. fpu_fpa10,
  62. fpu_fpa11:
  63. begin
  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. fpu_vfpv2,
  73. fpu_vfpv3,
  74. fpu_vfpv3_d16,
  75. fpu_fpv4_s16:
  76. begin
  77. location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,true);
  78. location_copy(location,left.location);
  79. if left.location.loc=LOC_CMMREGISTER then
  80. begin
  81. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  82. location.loc := LOC_MMREGISTER;
  83. end;
  84. end;
  85. else
  86. internalerror(2009111801);
  87. end;
  88. singleprec:=tfloatdef(left.resultdef).floattype=s32real;
  89. end;
  90. function tarminlinenode.first_abs_real : tnode;
  91. begin
  92. if (cs_fp_emulation in current_settings.moduleswitches) then
  93. result:=inherited first_abs_real
  94. else
  95. begin
  96. case current_settings.fputype of
  97. fpu_fpa,
  98. fpu_fpa10,
  99. fpu_fpa11:
  100. expectloc:=LOC_FPUREGISTER;
  101. fpu_vfpv2,
  102. fpu_vfpv3,
  103. fpu_vfpv3_d16:
  104. expectloc:=LOC_MMREGISTER;
  105. fpu_fpv4_s16:
  106. begin
  107. if tfloatdef(left.resultdef).floattype=s32real then
  108. expectloc:=LOC_MMREGISTER
  109. else
  110. exit(inherited first_abs_real);
  111. end;
  112. else
  113. internalerror(2009112401);
  114. end;
  115. first_abs_real:=nil;
  116. end;
  117. end;
  118. function tarminlinenode.first_sqr_real : tnode;
  119. begin
  120. if (cs_fp_emulation in current_settings.moduleswitches) then
  121. result:=inherited first_sqr_real
  122. else
  123. begin
  124. case current_settings.fputype of
  125. fpu_fpa,
  126. fpu_fpa10,
  127. fpu_fpa11:
  128. expectloc:=LOC_FPUREGISTER;
  129. fpu_vfpv2,
  130. fpu_vfpv3,
  131. fpu_vfpv3_d16:
  132. expectloc:=LOC_MMREGISTER;
  133. fpu_fpv4_s16:
  134. begin
  135. if tfloatdef(left.resultdef).floattype=s32real then
  136. expectloc:=LOC_MMREGISTER
  137. else
  138. exit(inherited first_sqr_real);
  139. end;
  140. else
  141. internalerror(2009112402);
  142. end;
  143. first_sqr_real:=nil;
  144. end;
  145. end;
  146. function tarminlinenode.first_sqrt_real : tnode;
  147. begin
  148. if cs_fp_emulation in current_settings.moduleswitches then
  149. result:=inherited first_sqrt_real
  150. else
  151. begin
  152. case current_settings.fputype of
  153. fpu_fpa,
  154. fpu_fpa10,
  155. fpu_fpa11:
  156. expectloc:=LOC_FPUREGISTER;
  157. fpu_vfpv2,
  158. fpu_vfpv3,
  159. fpu_vfpv3_d16:
  160. expectloc:=LOC_MMREGISTER;
  161. fpu_fpv4_s16:
  162. begin
  163. if tfloatdef(left.resultdef).floattype=s32real then
  164. expectloc:=LOC_MMREGISTER
  165. else
  166. exit(inherited first_sqrt_real);
  167. end;
  168. else
  169. internalerror(2009112403);
  170. end;
  171. first_sqrt_real := nil;
  172. end;
  173. end;
  174. { atn,sin,cos,lgn isn't supported by the linux fpe
  175. function tarminlinenode.first_arctan_real: tnode;
  176. begin
  177. expectloc:=LOC_FPUREGISTER;
  178. result:=nil;
  179. end;
  180. function tarminlinenode.first_ln_real: tnode;
  181. begin
  182. expectloc:=LOC_FPUREGISTER;
  183. result:=nil;
  184. end;
  185. function tarminlinenode.first_cos_real: tnode;
  186. begin
  187. expectloc:=LOC_FPUREGISTER;
  188. result:=nil;
  189. end;
  190. function tarminlinenode.first_sin_real: tnode;
  191. begin
  192. expectloc:=LOC_FPUREGISTER;
  193. result:=nil;
  194. end;
  195. }
  196. procedure tarminlinenode.second_abs_real;
  197. var
  198. singleprec: boolean;
  199. op: TAsmOp;
  200. begin
  201. load_fpu_location(singleprec);
  202. case current_settings.fputype of
  203. fpu_fpa,
  204. fpu_fpa10,
  205. fpu_fpa11:
  206. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_ABS,location.register,left.location.register),get_fpu_postfix(resultdef)));
  207. fpu_vfpv2,
  208. fpu_vfpv3,
  209. fpu_vfpv3_d16:
  210. begin
  211. if singleprec then
  212. op:=A_FABSS
  213. else
  214. op:=A_FABSD;
  215. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,location.register,left.location.register));
  216. end;
  217. fpu_fpv4_s16:
  218. current_asmdata.CurrAsmList.Concat(setoppostfix(taicpu.op_reg_reg(A_VABS,location.register,left.location.register), PF_F32));
  219. else
  220. internalerror(2009111402);
  221. end;
  222. end;
  223. procedure tarminlinenode.second_sqr_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_reg(A_MUF,location.register,left.location.register,left.location.register),get_fpu_postfix(resultdef)));
  234. fpu_vfpv2,
  235. fpu_vfpv3,
  236. fpu_vfpv3_d16:
  237. begin
  238. if singleprec then
  239. op:=A_FMULS
  240. else
  241. op:=A_FMULD;
  242. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,location.register,left.location.register,left.location.register));
  243. end;
  244. fpu_fpv4_s16:
  245. current_asmdata.CurrAsmList.Concat(setoppostfix(taicpu.op_reg_reg_reg(A_VMUL,location.register,left.location.register,left.location.register), PF_F32));
  246. else
  247. internalerror(2009111403);
  248. end;
  249. end;
  250. procedure tarminlinenode.second_sqrt_real;
  251. var
  252. singleprec: boolean;
  253. op: TAsmOp;
  254. begin
  255. load_fpu_location(singleprec);
  256. case current_settings.fputype of
  257. fpu_fpa,
  258. fpu_fpa10,
  259. fpu_fpa11:
  260. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_SQT,location.register,left.location.register),get_fpu_postfix(resultdef)));
  261. fpu_vfpv2,
  262. fpu_vfpv3,
  263. fpu_vfpv3_d16:
  264. begin
  265. if singleprec then
  266. op:=A_FSQRTS
  267. else
  268. op:=A_FSQRTD;
  269. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,location.register,left.location.register));
  270. end;
  271. fpu_fpv4_s16:
  272. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_VSQRT,location.register,left.location.register));
  273. else
  274. internalerror(2009111402);
  275. end;
  276. end;
  277. { atn, sin, cos, lgn isn't supported by the linux fpe
  278. procedure tarminlinenode.second_arctan_real;
  279. begin
  280. load_fpu_location;
  281. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_ATN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  282. end;
  283. procedure tarminlinenode.second_ln_real;
  284. begin
  285. load_fpu_location;
  286. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_LGN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  287. end;
  288. procedure tarminlinenode.second_cos_real;
  289. begin
  290. load_fpu_location;
  291. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_COS,location.register,left.location.register),get_fpu_postfix(resultdef)));
  292. end;
  293. procedure tarminlinenode.second_sin_real;
  294. begin
  295. load_fpu_location;
  296. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_SIN,location.register,left.location.register),get_fpu_postfix(resultdef)));
  297. end;
  298. }
  299. procedure tarminlinenode.second_prefetch;
  300. var
  301. ref : treference;
  302. r : tregister;
  303. begin
  304. if CPUARM_HAS_EDSP in cpu_capabilities[current_settings.cputype] then
  305. begin
  306. secondpass(left);
  307. case left.location.loc of
  308. LOC_CREFERENCE,
  309. LOC_REFERENCE:
  310. begin
  311. r:=cg.getintregister(current_asmdata.CurrAsmList,OS_ADDR);
  312. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,r);
  313. reference_reset_base(ref,r,0,left.location.reference.alignment);
  314. { since the address might be nil we can't use ldr for older cpus }
  315. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_PLD,ref));
  316. end;
  317. else
  318. internalerror(200402021);
  319. end;
  320. end;
  321. end;
  322. procedure tarminlinenode.second_abs_long;
  323. var
  324. opsize : tcgsize;
  325. hp : taicpu;
  326. begin
  327. secondpass(left);
  328. opsize:=def_cgsize(left.resultdef);
  329. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  330. location:=left.location;
  331. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  332. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  333. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_MOV,location.register,left.location.register), PF_S));
  334. current_asmdata.CurrAsmList.concat(setcondition(taicpu.op_reg_reg_const(A_RSB,location.register,location.register, 0), C_MI));
  335. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  336. end;
  337. begin
  338. cinlinenode:=tarminlinenode;
  339. end.