n68kinl.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. procedure t68kinlinenode.second_abs_real;
  98. begin
  99. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_abs_real called!')));
  100. second_do_operation(A_FABS);
  101. end;
  102. procedure t68kinlinenode.second_sqr_real;
  103. begin
  104. secondpass(left);
  105. case current_settings.fputype of
  106. fpu_68881:
  107. begin
  108. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_sqr_real called!')));
  109. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  110. location_copy(location,left.location);
  111. if left.location.loc=LOC_CFPUREGISTER then
  112. begin
  113. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_srq_real called!: left was cfpuregister!')));
  114. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  115. location.loc := LOC_FPUREGISTER;
  116. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmlist,OS_NO,OS_NO,left.location.register,location.register);
  117. end;
  118. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FMUL,S_FX,left.location.register,location.register));
  119. end;
  120. else
  121. internalerror(2015022202);
  122. end;
  123. end;
  124. procedure t68kinlinenode.second_sqrt_real;
  125. begin
  126. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_sqrt_real called!')));
  127. second_do_operation(A_FSQRT);
  128. end;
  129. procedure t68kinlinenode.second_do_operation(op: TAsmOp);
  130. var
  131. href: TReference;
  132. begin
  133. secondpass(left);
  134. case current_settings.fputype of
  135. fpu_68881:
  136. begin
  137. location_reset(location,LOC_FPUREGISTER,left.location.size);
  138. case left.location.loc of
  139. LOC_FPUREGISTER:
  140. begin
  141. location.register:=left.location.register;
  142. current_asmdata.CurrAsmList.concat(taicpu.op_reg(op,S_FX,location.register))
  143. end;
  144. LOC_CFPUREGISTER:
  145. begin
  146. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  147. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,S_FX,left.location.register,location.register));
  148. end;
  149. LOC_REFERENCE,LOC_CREFERENCE:
  150. begin
  151. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  152. href:=left.location.reference;
  153. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href);
  154. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(op,tcgsize2opsize[left.location.size],href,location.register));
  155. end;
  156. else
  157. internalerror(2015022205);
  158. end;
  159. end;
  160. else
  161. internalerror(2015022204);
  162. end;
  163. end;
  164. { ideas for second_abs_long (KB) }
  165. { This is probably faster on 68000 than the generic implementation,
  166. because shifting is slow on the original 68000, maybe also on the 68020?
  167. Also needs to be tested on 040/060. This can also work on a CF.
  168. input - d0, output - d2
  169. move.l d0,d2
  170. btst #31,d2
  171. sne d1
  172. extb.l d1 (or ext.w + ext.l on 68000)
  173. eor.l d1,d2
  174. sub.l d1,d2
  175. }
  176. { Solution using bitfield extraction, we don't support the necessary asm
  177. construct for this yet, probably this is the fastest on 020, slower on
  178. 040/060 than the one above, doesn't work on '000 or CF.
  179. input - d0, output - d2
  180. move.l d0,d2
  181. bfexts d0[0:1],d1
  182. eor.l d1,d2
  183. sub.l d1,d2
  184. }
  185. begin
  186. cinlinenode:=t68kinlinenode;
  187. end.