n68kinl.pas 9.1 KB

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