n68kinl.pas 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. {
  2. Copyright (c) 2015 by the Free Pascal Development team
  3. Generates Motorola 68k 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 n68kinl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ninl,ncginl,cpubase;
  22. type
  23. t68kinlinenode = class(tcgInlineNode)
  24. function first_abs_real: tnode; override;
  25. function first_sqr_real: tnode; override;
  26. function first_sqrt_real: tnode; override;
  27. {function first_arctan_real: tnode; override;
  28. function first_ln_real: tnode; override;}
  29. function first_cos_real: tnode; override;
  30. function first_sin_real: tnode; override;
  31. function first_int_real: tnode; override;
  32. procedure second_abs_real; override;
  33. procedure second_sqr_real; override;
  34. procedure second_sqrt_real; override;
  35. {procedure second_arctan_real; override;
  36. procedure second_ln_real; override;}
  37. procedure second_cos_real; override;
  38. procedure second_sin_real; override;
  39. procedure second_int_real; override;
  40. {procedure second_prefetch; override;
  41. procedure second_abs_long; override;}
  42. private
  43. procedure second_do_operation(op: TAsmOp);
  44. end;
  45. implementation
  46. uses
  47. globtype,verbose,globals,cutils,
  48. cpuinfo,defutil,symdef,aasmdata,aasmcpu,aasmtai,
  49. cgbase,cgutils,pass_1,pass_2,
  50. ncgutil,cgobj,cgcpu,hlcgobj;
  51. {*****************************************************************************
  52. t68kinlinenode
  53. *****************************************************************************}
  54. function t68kinlinenode.first_abs_real : tnode;
  55. begin
  56. if (cs_fp_emulation in current_settings.moduleswitches) then
  57. result:=inherited first_abs_real
  58. else
  59. begin
  60. case current_settings.fputype of
  61. fpu_68881,fpu_coldfire:
  62. expectloc:=LOC_FPUREGISTER;
  63. else
  64. internalerror(2015022206);
  65. end;
  66. first_abs_real:=nil;
  67. end;
  68. end;
  69. function t68kinlinenode.first_sqr_real : tnode;
  70. begin
  71. if (cs_fp_emulation in current_settings.moduleswitches) then
  72. result:=inherited first_sqr_real
  73. else
  74. begin
  75. case current_settings.fputype of
  76. fpu_68881,fpu_coldfire:
  77. expectloc:=LOC_FPUREGISTER;
  78. else
  79. internalerror(2015022201);
  80. end;
  81. first_sqr_real:=nil;
  82. end;
  83. end;
  84. function t68kinlinenode.first_sqrt_real : tnode;
  85. begin
  86. if (cs_fp_emulation in current_settings.moduleswitches) then
  87. result:=inherited first_sqrt_real
  88. else
  89. begin
  90. case current_settings.fputype of
  91. fpu_68881,fpu_coldfire:
  92. expectloc:=LOC_FPUREGISTER;
  93. else
  94. internalerror(2015022203);
  95. end;
  96. first_sqrt_real:=nil;
  97. end;
  98. end;
  99. function t68kinlinenode.first_sin_real : tnode;
  100. begin
  101. if (cs_fp_emulation in current_settings.moduleswitches) then
  102. result:=inherited first_sin_real
  103. else
  104. begin
  105. case current_settings.fputype of
  106. fpu_68881:
  107. expectloc:=LOC_FPUREGISTER;
  108. fpu_soft,fpu_coldfire:
  109. begin
  110. result:=inherited first_sin_real;
  111. exit;
  112. end;
  113. else
  114. internalerror(2015022203);
  115. end;
  116. first_sin_real:=nil;
  117. end;
  118. end;
  119. function t68kinlinenode.first_cos_real : tnode;
  120. begin
  121. if (cs_fp_emulation in current_settings.moduleswitches) then
  122. result:=inherited first_cos_real
  123. else
  124. begin
  125. case current_settings.fputype of
  126. fpu_68881:
  127. expectloc:=LOC_FPUREGISTER;
  128. fpu_soft,fpu_coldfire:
  129. begin
  130. result:=inherited first_cos_real;
  131. exit;
  132. end;
  133. else
  134. internalerror(2015022203);
  135. end;
  136. first_cos_real:=nil;
  137. end;
  138. end;
  139. function t68kinlinenode.first_int_real : tnode;
  140. begin
  141. if (cs_fp_emulation in current_settings.moduleswitches) then
  142. result:=inherited first_int_real
  143. else
  144. begin
  145. case current_settings.fputype of
  146. fpu_68881,fpu_coldfire:
  147. expectloc:=LOC_FPUREGISTER;
  148. else
  149. internalerror(2016112701);
  150. end;
  151. first_int_real:=nil;
  152. end;
  153. end;
  154. procedure t68kinlinenode.second_abs_real;
  155. begin
  156. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_abs_real called!')));
  157. second_do_operation(A_FABS);
  158. end;
  159. procedure t68kinlinenode.second_sqr_real;
  160. begin
  161. secondpass(left);
  162. case current_settings.fputype of
  163. fpu_68881,fpu_coldfire:
  164. begin
  165. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_sqr_real called!')));
  166. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  167. location_copy(location,left.location);
  168. if left.location.loc=LOC_CFPUREGISTER then
  169. begin
  170. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_srq_real called!: left was cfpuregister!')));
  171. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  172. location.loc := LOC_FPUREGISTER;
  173. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmlist,OS_NO,OS_NO,left.location.register,location.register);
  174. end;
  175. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FMUL,fpuregopsize,left.location.register,location.register));
  176. end;
  177. else
  178. internalerror(2015022202);
  179. end;
  180. end;
  181. procedure t68kinlinenode.second_sqrt_real;
  182. begin
  183. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_sqrt_real called!')));
  184. second_do_operation(A_FSQRT);
  185. end;
  186. procedure t68kinlinenode.second_sin_real;
  187. begin
  188. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_sin_real called!')));
  189. second_do_operation(A_FSIN);
  190. end;
  191. procedure t68kinlinenode.second_cos_real;
  192. begin
  193. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_cos_real called!')));
  194. second_do_operation(A_FCOS);
  195. end;
  196. procedure t68kinlinenode.second_int_real;
  197. begin
  198. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_int_real called!')));
  199. second_do_operation(A_FINTRZ);
  200. end;
  201. procedure t68kinlinenode.second_do_operation(op: TAsmOp);
  202. var
  203. href: TReference;
  204. begin
  205. secondpass(left);
  206. case current_settings.fputype of
  207. fpu_68881,fpu_coldfire:
  208. begin
  209. location_reset(location,LOC_FPUREGISTER,left.location.size);
  210. case left.location.loc of
  211. LOC_FPUREGISTER:
  212. begin
  213. location.register:=left.location.register;
  214. current_asmdata.CurrAsmList.concat(taicpu.op_reg(op,fpuregopsize,location.register))
  215. end;
  216. LOC_CFPUREGISTER:
  217. begin
  218. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  219. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,fpuregopsize,left.location.register,location.register));
  220. end;
  221. LOC_REFERENCE,LOC_CREFERENCE:
  222. begin
  223. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  224. href:=left.location.reference;
  225. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,current_settings.fputype = fpu_coldfire);
  226. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(op,tcgsize2opsize[left.location.size],href,location.register));
  227. end;
  228. else
  229. internalerror(2015022205);
  230. end;
  231. end;
  232. else
  233. internalerror(2015022204);
  234. end;
  235. end;
  236. { ideas for second_abs_long (KB) }
  237. { This is probably faster on 68000 than the generic implementation,
  238. because shifting is slow on the original 68000, maybe also on the 68020?
  239. Also needs to be tested on 040/060. This can also work on a CF.
  240. input - d0, output - d2
  241. move.l d0,d2
  242. btst #31,d2
  243. sne d1
  244. extb.l d1 (or ext.w + ext.l on 68000)
  245. eor.l d1,d2
  246. sub.l d1,d2
  247. }
  248. { Solution using bitfield extraction, we don't support the necessary asm
  249. construct for this yet, probably this is the fastest on 020, slower on
  250. 040/060 than the one above, doesn't work on '000 or CF.
  251. input - d0, output - d2
  252. move.l d0,d2
  253. bfexts d0[0:1],d1
  254. eor.l d1,d2
  255. sub.l d1,d2
  256. }
  257. begin
  258. cinlinenode:=t68kinlinenode;
  259. end.