narminl.pas 11 KB

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