n68kinl.pas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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:
  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:
  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:
  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. else
  107. internalerror(2015022203);
  108. end;
  109. first_sin_real:=nil;
  110. end;
  111. end;
  112. function t68kinlinenode.first_cos_real : tnode;
  113. begin
  114. if (cs_fp_emulation in current_settings.moduleswitches) then
  115. result:=inherited first_cos_real
  116. else
  117. begin
  118. case current_settings.fputype of
  119. fpu_68881:
  120. expectloc:=LOC_FPUREGISTER;
  121. else
  122. internalerror(2015022203);
  123. end;
  124. first_cos_real:=nil;
  125. end;
  126. end;
  127. procedure t68kinlinenode.second_abs_real;
  128. begin
  129. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_abs_real called!')));
  130. second_do_operation(A_FABS);
  131. end;
  132. procedure t68kinlinenode.second_sqr_real;
  133. begin
  134. secondpass(left);
  135. case current_settings.fputype of
  136. fpu_68881:
  137. begin
  138. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_sqr_real called!')));
  139. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  140. location_copy(location,left.location);
  141. if left.location.loc=LOC_CFPUREGISTER then
  142. begin
  143. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_srq_real called!: left was cfpuregister!')));
  144. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  145. location.loc := LOC_FPUREGISTER;
  146. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmlist,OS_NO,OS_NO,left.location.register,location.register);
  147. end;
  148. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FMUL,S_FX,left.location.register,location.register));
  149. end;
  150. else
  151. internalerror(2015022202);
  152. end;
  153. end;
  154. procedure t68kinlinenode.second_sqrt_real;
  155. begin
  156. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_sqrt_real called!')));
  157. second_do_operation(A_FSQRT);
  158. end;
  159. procedure t68kinlinenode.second_sin_real;
  160. begin
  161. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_sqrt_real called!')));
  162. second_do_operation(A_FSIN);
  163. end;
  164. procedure t68kinlinenode.second_cos_real;
  165. begin
  166. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_sqrt_real called!')));
  167. second_do_operation(A_FCOS);
  168. end;
  169. procedure t68kinlinenode.second_do_operation(op: TAsmOp);
  170. var
  171. href: TReference;
  172. begin
  173. secondpass(left);
  174. case current_settings.fputype of
  175. fpu_68881:
  176. begin
  177. location_reset(location,LOC_FPUREGISTER,left.location.size);
  178. case left.location.loc of
  179. LOC_FPUREGISTER:
  180. begin
  181. location.register:=left.location.register;
  182. current_asmdata.CurrAsmList.concat(taicpu.op_reg(op,S_FX,location.register))
  183. end;
  184. LOC_CFPUREGISTER:
  185. begin
  186. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  187. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,S_FX,left.location.register,location.register));
  188. end;
  189. LOC_REFERENCE,LOC_CREFERENCE:
  190. begin
  191. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  192. href:=left.location.reference;
  193. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href);
  194. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(op,tcgsize2opsize[left.location.size],href,location.register));
  195. end;
  196. else
  197. internalerror(2015022205);
  198. end;
  199. end;
  200. else
  201. internalerror(2015022204);
  202. end;
  203. end;
  204. { ideas for second_abs_long (KB) }
  205. { This is probably faster on 68000 than the generic implementation,
  206. because shifting is slow on the original 68000, maybe also on the 68020?
  207. Also needs to be tested on 040/060. This can also work on a CF.
  208. input - d0, output - d2
  209. move.l d0,d2
  210. btst #31,d2
  211. sne d1
  212. extb.l d1 (or ext.w + ext.l on 68000)
  213. eor.l d1,d2
  214. sub.l d1,d2
  215. }
  216. { Solution using bitfield extraction, we don't support the necessary asm
  217. construct for this yet, probably this is the fastest on 020, slower on
  218. 040/060 than the one above, doesn't work on '000 or CF.
  219. input - d0, output - d2
  220. move.l d0,d2
  221. bfexts d0[0:1],d1
  222. eor.l d1,d2
  223. sub.l d1,d2
  224. }
  225. begin
  226. cinlinenode:=t68kinlinenode;
  227. end.