narminl.pas 11 KB

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