You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
11KB

  1. /*
  2. * SIMD-optimized halfpel functions
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * Libav is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with Libav; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
  23. */
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/cpu.h"
  26. #include "libavutil/x86/cpu.h"
  27. #include "libavcodec/avcodec.h"
  28. #include "libavcodec/hpeldsp.h"
  29. #include "libavcodec/pixels.h"
  30. #include "fpel.h"
  31. #include "hpeldsp.h"
  32. void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  33. ptrdiff_t line_size, int h);
  34. void ff_put_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  35. ptrdiff_t line_size, int h);
  36. void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  37. ptrdiff_t line_size, int h);
  38. void ff_put_pixels16_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  39. ptrdiff_t line_size, int h);
  40. void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  41. ptrdiff_t line_size, int h);
  42. void ff_put_no_rnd_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  43. ptrdiff_t line_size, int h);
  44. void ff_put_no_rnd_pixels8_x2_exact_mmxext(uint8_t *block,
  45. const uint8_t *pixels,
  46. ptrdiff_t line_size, int h);
  47. void ff_put_no_rnd_pixels8_x2_exact_3dnow(uint8_t *block,
  48. const uint8_t *pixels,
  49. ptrdiff_t line_size, int h);
  50. void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  51. ptrdiff_t line_size, int h);
  52. void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  53. ptrdiff_t line_size, int h);
  54. void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  55. ptrdiff_t line_size, int h);
  56. void ff_put_no_rnd_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  57. ptrdiff_t line_size, int h);
  58. void ff_put_no_rnd_pixels8_y2_exact_mmxext(uint8_t *block,
  59. const uint8_t *pixels,
  60. ptrdiff_t line_size, int h);
  61. void ff_put_no_rnd_pixels8_y2_exact_3dnow(uint8_t *block,
  62. const uint8_t *pixels,
  63. ptrdiff_t line_size, int h);
  64. void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
  65. ptrdiff_t line_size, int h);
  66. void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  67. ptrdiff_t line_size, int h);
  68. void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  69. ptrdiff_t line_size, int h);
  70. void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  71. ptrdiff_t line_size, int h);
  72. void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  73. ptrdiff_t line_size, int h);
  74. void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
  75. ptrdiff_t line_size, int h);
  76. void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
  77. ptrdiff_t line_size, int h);
  78. #define avg_pixels8_mmx ff_avg_pixels8_mmx
  79. #define avg_pixels8_x2_mmx ff_avg_pixels8_x2_mmx
  80. #define avg_pixels16_mmx ff_avg_pixels16_mmx
  81. #define avg_pixels8_xy2_mmx ff_avg_pixels8_xy2_mmx
  82. #define avg_pixels16_xy2_mmx ff_avg_pixels16_xy2_mmx
  83. #define put_pixels8_mmx ff_put_pixels8_mmx
  84. #define put_pixels16_mmx ff_put_pixels16_mmx
  85. #define put_pixels8_xy2_mmx ff_put_pixels8_xy2_mmx
  86. #define put_pixels16_xy2_mmx ff_put_pixels16_xy2_mmx
  87. #define avg_no_rnd_pixels16_mmx ff_avg_pixels16_mmx
  88. #define put_no_rnd_pixels8_mmx ff_put_pixels8_mmx
  89. #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
  90. #if HAVE_INLINE_ASM
  91. /***********************************/
  92. /* MMX no rounding */
  93. #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
  94. #define SET_RND MOVQ_WONE
  95. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
  96. #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
  97. #define STATIC static
  98. #include "rnd_template.c"
  99. #include "hpeldsp_rnd_template.c"
  100. #undef DEF
  101. #undef SET_RND
  102. #undef PAVGBP
  103. #undef PAVGB
  104. #undef STATIC
  105. CALL_2X_PIXELS(avg_no_rnd_pixels16_y2_mmx, avg_no_rnd_pixels8_y2_mmx, 8)
  106. CALL_2X_PIXELS(put_no_rnd_pixels16_y2_mmx, put_no_rnd_pixels8_y2_mmx, 8)
  107. CALL_2X_PIXELS(avg_no_rnd_pixels16_xy2_mmx, avg_no_rnd_pixels8_xy2_mmx, 8)
  108. CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_mmx, put_no_rnd_pixels8_xy2_mmx, 8)
  109. /***********************************/
  110. /* MMX rounding */
  111. #define DEF(x, y) x ## _ ## y ## _mmx
  112. #define SET_RND MOVQ_WTWO
  113. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
  114. #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
  115. #include "hpeldsp_rnd_template.c"
  116. #undef DEF
  117. #define DEF(x, y) ff_ ## x ## _ ## y ## _mmx
  118. #define STATIC
  119. #include "rnd_template.c"
  120. #undef DEF
  121. #undef SET_RND
  122. #undef PAVGBP
  123. #undef PAVGB
  124. CALL_2X_PIXELS(avg_pixels16_y2_mmx, avg_pixels8_y2_mmx, 8)
  125. CALL_2X_PIXELS(put_pixels16_y2_mmx, put_pixels8_y2_mmx, 8)
  126. CALL_2X_PIXELS_EXPORT(ff_avg_pixels16_xy2_mmx, ff_avg_pixels8_xy2_mmx, 8)
  127. CALL_2X_PIXELS_EXPORT(ff_put_pixels16_xy2_mmx, ff_put_pixels8_xy2_mmx, 8)
  128. #endif /* HAVE_INLINE_ASM */
  129. #if HAVE_YASM
  130. #define HPELDSP_AVG_PIXELS16(CPUEXT) \
  131. CALL_2X_PIXELS(put_no_rnd_pixels16_x2 ## CPUEXT, ff_put_no_rnd_pixels8_x2 ## CPUEXT, 8) \
  132. CALL_2X_PIXELS(put_pixels16_y2 ## CPUEXT, ff_put_pixels8_y2 ## CPUEXT, 8) \
  133. CALL_2X_PIXELS(put_no_rnd_pixels16_y2 ## CPUEXT, ff_put_no_rnd_pixels8_y2 ## CPUEXT, 8) \
  134. CALL_2X_PIXELS(avg_pixels16 ## CPUEXT, ff_avg_pixels8 ## CPUEXT, 8) \
  135. CALL_2X_PIXELS(avg_pixels16_x2 ## CPUEXT, ff_avg_pixels8_x2 ## CPUEXT, 8) \
  136. CALL_2X_PIXELS(avg_pixels16_y2 ## CPUEXT, ff_avg_pixels8_y2 ## CPUEXT, 8) \
  137. CALL_2X_PIXELS(avg_pixels16_xy2 ## CPUEXT, ff_avg_pixels8_xy2 ## CPUEXT, 8)
  138. HPELDSP_AVG_PIXELS16(_3dnow)
  139. HPELDSP_AVG_PIXELS16(_mmxext)
  140. #endif /* HAVE_YASM */
  141. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  142. do { \
  143. c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
  144. c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
  145. c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
  146. c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
  147. } while (0)
  148. static void hpeldsp_init_mmx(HpelDSPContext *c, int flags, int cpu_flags)
  149. {
  150. #if HAVE_MMX_INLINE
  151. SET_HPEL_FUNCS(put, [0], 16, mmx);
  152. SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
  153. SET_HPEL_FUNCS(avg, [0], 16, mmx);
  154. SET_HPEL_FUNCS(avg_no_rnd, , 16, mmx);
  155. SET_HPEL_FUNCS(put, [1], 8, mmx);
  156. SET_HPEL_FUNCS(put_no_rnd, [1], 8, mmx);
  157. SET_HPEL_FUNCS(avg, [1], 8, mmx);
  158. #endif /* HAVE_MMX_INLINE */
  159. }
  160. static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags, int cpu_flags)
  161. {
  162. #if HAVE_MMXEXT_EXTERNAL
  163. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_mmxext;
  164. c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
  165. c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
  166. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
  167. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
  168. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_mmxext;
  169. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_mmxext;
  170. c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmxext;
  171. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmxext;
  172. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_mmxext;
  173. if (!(flags & AV_CODEC_FLAG_BITEXACT)) {
  174. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
  175. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
  176. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_mmxext;
  177. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_mmxext;
  178. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
  179. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmxext;
  180. }
  181. if (flags & AV_CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
  182. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_mmxext;
  183. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_mmxext;
  184. }
  185. #endif /* HAVE_MMXEXT_EXTERNAL */
  186. }
  187. static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags, int cpu_flags)
  188. {
  189. #if HAVE_AMD3DNOW_EXTERNAL
  190. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_3dnow;
  191. c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
  192. c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
  193. c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
  194. c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
  195. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_3dnow;
  196. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_3dnow;
  197. c->avg_pixels_tab[1][0] = ff_avg_pixels8_3dnow;
  198. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_3dnow;
  199. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_3dnow;
  200. if (!(flags & AV_CODEC_FLAG_BITEXACT)){
  201. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
  202. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
  203. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_3dnow;
  204. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_3dnow;
  205. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
  206. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_3dnow;
  207. }
  208. if (flags & AV_CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
  209. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_3dnow;
  210. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_3dnow;
  211. }
  212. #endif /* HAVE_AMD3DNOW_EXTERNAL */
  213. }
  214. static void hpeldsp_init_sse2(HpelDSPContext *c, int flags, int cpu_flags)
  215. {
  216. #if HAVE_SSE2_EXTERNAL
  217. if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
  218. // these functions are slower than mmx on AMD, but faster on Intel
  219. c->put_pixels_tab[0][0] = ff_put_pixels16_sse2;
  220. c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
  221. c->avg_pixels_tab[0][0] = ff_avg_pixels16_sse2;
  222. }
  223. #endif /* HAVE_SSE2_EXTERNAL */
  224. }
  225. av_cold void ff_hpeldsp_init_x86(HpelDSPContext *c, int flags)
  226. {
  227. int cpu_flags = av_get_cpu_flags();
  228. if (INLINE_MMX(cpu_flags))
  229. hpeldsp_init_mmx(c, flags, cpu_flags);
  230. if (EXTERNAL_AMD3DNOW(cpu_flags))
  231. hpeldsp_init_3dnow(c, flags, cpu_flags);
  232. if (EXTERNAL_MMXEXT(cpu_flags))
  233. hpeldsp_init_mmxext(c, flags, cpu_flags);
  234. if (EXTERNAL_SSE2(cpu_flags))
  235. hpeldsp_init_sse2(c, flags, cpu_flags);
  236. }