aoptcpu.pas 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. {
  2. Copyright (c) 1998-2004 by Jonas Maebe
  3. This unit calls the optimization procedures to optimize the assembler
  4. code for sparc
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit aoptcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses cpubase, aasmtai, aopt, aoptx86;
  22. type
  23. TCpuAsmOptimizer = class(TX86AsmOptimizer)
  24. function PrePeepHoleOptsCpu(var p: tai): boolean; override;
  25. function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
  26. function PeepHoleOptPass2Cpu(var p: tai): boolean; override;
  27. function PostPeepHoleOptsCpu(var p : tai) : boolean; override;
  28. end;
  29. implementation
  30. uses
  31. globals,
  32. aasmcpu;
  33. function TCpuAsmOptimizer.PrePeepHoleOptsCpu(var p : tai) : boolean;
  34. begin
  35. result := false;
  36. case p.typ of
  37. ait_instruction:
  38. begin
  39. case taicpu(p).opcode of
  40. A_IMUL:
  41. result:=PrePeepholeOptIMUL(p);
  42. A_SAR,A_SHR:
  43. result:=PrePeepholeOptSxx(p);
  44. A_AND:
  45. Result:=PrePeepholeOptAND(p);
  46. else
  47. ;
  48. end;
  49. end;
  50. else
  51. ;
  52. end;
  53. end;
  54. function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p: tai): boolean;
  55. begin
  56. result:=False;
  57. case p.typ of
  58. ait_instruction:
  59. begin
  60. case taicpu(p).opcode of
  61. A_ADD:
  62. Result:=OptPass1ADD(p);
  63. A_AND:
  64. Result:=OptPass1AND(p);
  65. A_IMUL:
  66. Result:=OptPass1Imul(p);
  67. A_MOV:
  68. Result:=OptPass1MOV(p);
  69. A_MOVSX,
  70. A_MOVSXD,
  71. A_MOVZX:
  72. Result:=OptPass1Movx(p);
  73. A_MOVAPD,
  74. A_MOVAPS,
  75. A_MOVUPD,
  76. A_MOVUPS,
  77. A_VMOVAPS,
  78. A_VMOVAPD,
  79. A_VMOVUPS,
  80. A_VMOVUPD:
  81. result:=OptPass1_V_MOVAP(p);
  82. A_VMINSS,
  83. A_VMINSD,
  84. A_VMAXSS,
  85. A_VMAXSD,
  86. A_VSQRTSD,
  87. A_VSQRTSS,
  88. A_VDIVSD,
  89. A_VDIVSS,
  90. A_VSUBSD,
  91. A_VSUBSS,
  92. A_VMULSD,
  93. A_VMULSS,
  94. A_VADDSD,
  95. A_VADDSS,
  96. A_VANDPD,
  97. A_VANDPS,
  98. A_VORPD,
  99. A_VORPS:
  100. result:=OptPass1VOP(p);
  101. A_MULSD,
  102. A_MULSS,
  103. A_ADDSD,
  104. A_ADDSS:
  105. result:=OptPass1OP(p);
  106. A_VMOVSD,
  107. A_VMOVSS,
  108. A_MOVSD,
  109. A_MOVSS:
  110. result:=OptPass1MOVXX(p);
  111. A_LEA:
  112. result:=OptPass1LEA(p);
  113. A_SUB:
  114. result:=OptPass1Sub(p);
  115. A_SHL,A_SAL:
  116. result:=OptPass1SHLSAL(p);
  117. A_FSTP,A_FISTP:
  118. result:=OptPass1FSTP(p);
  119. A_FLD:
  120. result:=OptPass1FLD(p);
  121. A_CMP:
  122. result:=OptPass1Cmp(p);
  123. A_VPXORD,
  124. A_VPXORQ,
  125. A_VXORPS,
  126. A_VXORPD,
  127. A_VPXOR:
  128. Result:=OptPass1VPXor(p);
  129. A_VMOVDQA,
  130. A_VMOVDQU:
  131. Result:=OptPass1VMOVDQ(p);
  132. A_XORPS,
  133. A_XORPD,
  134. A_PXOR:
  135. Result:=OptPass1PXor(p);
  136. A_TEST:
  137. Result:=OptPass1Test(p);
  138. A_Jcc:
  139. Result:=OptPass1Jcc(p);
  140. A_SHRX,
  141. A_SHLX:
  142. Result:=OptPass1SHXX(p);
  143. A_VCVTSS2SD,
  144. A_CVTSS2SD:
  145. Result:=OptPass1_V_Cvtss2sd(p);
  146. else
  147. ;
  148. end;
  149. end;
  150. else
  151. ;
  152. end;
  153. end;
  154. function TCpuAsmOptimizer.PeepHoleOptPass2Cpu(var p : tai) : boolean;
  155. begin
  156. Result := False;
  157. case p.typ of
  158. ait_instruction:
  159. begin
  160. case taicpu(p).opcode of
  161. A_MOV:
  162. Result:=OptPass2MOV(p);
  163. A_MOVZX:
  164. Result:=OptPass2Movx(p);
  165. A_IMUL:
  166. Result:=OptPass2Imul(p);
  167. A_JMP:
  168. Result:=OptPass2Jmp(p);
  169. A_Jcc:
  170. Result:=OptPass2Jcc(p);
  171. A_Lea:
  172. Result:=OptPass2Lea(p);
  173. A_SUB:
  174. Result:=OptPass2SUB(p);
  175. A_ADD:
  176. Result:=OptPass2ADD(p);
  177. A_SETcc:
  178. result:=OptPass2SETcc(p);
  179. else
  180. ;
  181. end;
  182. end;
  183. else
  184. ;
  185. end;
  186. end;
  187. function TCpuAsmOptimizer.PostPeepHoleOptsCpu(var p: tai): boolean;
  188. begin
  189. result := false;
  190. case p.typ of
  191. ait_instruction:
  192. begin
  193. case taicpu(p).opcode of
  194. A_MOV:
  195. Result:=PostPeepholeOptMov(p);
  196. A_AND:
  197. Result:=PostPeepholeOptAnd(p);
  198. A_MOVSX,
  199. A_MOVSXD:
  200. Result:=PostPeepholeOptMOVSX(p);
  201. A_MOVZX:
  202. Result:=PostPeepholeOptMovzx(p);
  203. A_CMP:
  204. Result:=PostPeepholeOptCmp(p);
  205. A_OR,
  206. A_TEST:
  207. Result:=PostPeepholeOptTestOr(p);
  208. A_XOR:
  209. Result:=PostPeepholeOptXor(p);
  210. A_CALL:
  211. Result:=PostPeepholeOptCall(p);
  212. A_LEA:
  213. Result:=PostPeepholeOptLea(p);
  214. A_PUSH:
  215. Result:=PostPeepholeOptPush(p);
  216. A_SHR:
  217. Result:=PostPeepholeOptShr(p);
  218. A_ADD,
  219. A_SUB:
  220. Result:=PostPeepholeOptADDSUB(p);
  221. A_VPXOR:
  222. Result:=PostPeepholeOptVPXOR(p);
  223. else
  224. ;
  225. end;
  226. { Optimise any reference-type operands (if Result is True, the
  227. instruction will be checked on the next iteration) }
  228. if not Result then
  229. OptimizeRefs(taicpu(p));
  230. end;
  231. else
  232. ;
  233. end;
  234. end;
  235. begin
  236. casmoptimizer := TCpuAsmOptimizer;
  237. end.