narminl.pas 13 KB

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