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.

258 lines
9.8KB

  1. /*
  2. * MMX optimized DSP utils
  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/cpu.h"
  25. #include "libavutil/x86/asm.h"
  26. #include "libavcodec/hpeldsp.h"
  27. #include "dsputil_mmx.h"
  28. void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  29. ptrdiff_t line_size, int h);
  30. void ff_put_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  31. ptrdiff_t line_size, int h);
  32. void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  33. ptrdiff_t line_size, int h);
  34. void ff_put_pixels16_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  35. ptrdiff_t line_size, int h);
  36. void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  37. ptrdiff_t line_size, int h);
  38. void ff_put_no_rnd_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  39. ptrdiff_t line_size, int h);
  40. void ff_put_no_rnd_pixels8_x2_exact_mmxext(uint8_t *block,
  41. const uint8_t *pixels,
  42. ptrdiff_t line_size, int h);
  43. void ff_put_no_rnd_pixels8_x2_exact_3dnow(uint8_t *block,
  44. const uint8_t *pixels,
  45. ptrdiff_t line_size, int h);
  46. void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  47. ptrdiff_t line_size, int h);
  48. void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  49. ptrdiff_t line_size, int h);
  50. void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  51. ptrdiff_t line_size, int h);
  52. void ff_put_no_rnd_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_exact_mmxext(uint8_t *block,
  55. const uint8_t *pixels,
  56. ptrdiff_t line_size, int h);
  57. void ff_put_no_rnd_pixels8_y2_exact_3dnow(uint8_t *block,
  58. const uint8_t *pixels,
  59. ptrdiff_t line_size, int h);
  60. void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
  61. ptrdiff_t line_size, int h);
  62. void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
  63. ptrdiff_t line_size, int h);
  64. void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
  65. ptrdiff_t line_size, int h);
  66. void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
  67. ptrdiff_t line_size, int h);
  68. void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
  69. ptrdiff_t line_size, int h);
  70. void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
  71. ptrdiff_t line_size, int h);
  72. void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
  73. ptrdiff_t line_size, int h);
  74. #define avg_pixels8_mmx ff_avg_pixels8_mmx
  75. #define put_pixels8_mmx ff_put_pixels8_mmx
  76. #define put_pixels16_mmx ff_put_pixels16_mmx
  77. #define put_no_rnd_pixels8_mmx ff_put_pixels8_mmx
  78. #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
  79. #if HAVE_INLINE_ASM
  80. /***********************************/
  81. /* MMX no rounding */
  82. #define NO_RND 1
  83. #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
  84. #define SET_RND MOVQ_WONE
  85. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
  86. #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
  87. #define OP_AVG(a, b, c, e) PAVGB_MMX(a, b, c, e)
  88. #include "hpeldsp_rnd_template.c"
  89. #undef DEF
  90. #undef SET_RND
  91. #undef PAVGBP
  92. #undef PAVGB
  93. #undef NO_RND
  94. /***********************************/
  95. /* MMX rounding */
  96. #define DEF(x, y) x ## _ ## y ## _mmx
  97. #define SET_RND MOVQ_WTWO
  98. #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
  99. #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
  100. #include "hpeldsp_rnd_template.c"
  101. #undef DEF
  102. #undef SET_RND
  103. #undef PAVGBP
  104. #undef PAVGB
  105. #undef OP_AVG
  106. #endif /* HAVE_INLINE_ASM */
  107. #if HAVE_YASM
  108. /***********************************/
  109. /* 3Dnow specific */
  110. #define DEF(x) x ## _3dnow
  111. #include "hpeldsp_avg_template.c"
  112. #undef DEF
  113. /***********************************/
  114. /* MMXEXT specific */
  115. #define DEF(x) x ## _mmxext
  116. #include "hpeldsp_avg_template.c"
  117. #undef DEF
  118. #endif /* HAVE_YASM */
  119. #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
  120. do { \
  121. c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
  122. c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
  123. c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
  124. c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
  125. } while (0)
  126. static void hpeldsp_init_mmx(HpelDSPContext *c, int flags, int mm_flags)
  127. {
  128. #if HAVE_INLINE_ASM
  129. SET_HPEL_FUNCS(put, [0], 16, mmx);
  130. SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
  131. SET_HPEL_FUNCS(avg, [0], 16, mmx);
  132. SET_HPEL_FUNCS(avg_no_rnd, , 16, mmx);
  133. SET_HPEL_FUNCS(put, [1], 8, mmx);
  134. SET_HPEL_FUNCS(put_no_rnd, [1], 8, mmx);
  135. SET_HPEL_FUNCS(avg, [1], 8, mmx);
  136. #endif /* HAVE_INLINE_ASM */
  137. }
  138. static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags, int mm_flags)
  139. {
  140. #if HAVE_YASM
  141. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_mmxext;
  142. c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
  143. c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
  144. c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
  145. c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
  146. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_mmxext;
  147. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_mmxext;
  148. c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmxext;
  149. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmxext;
  150. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_mmxext;
  151. if (!(flags & CODEC_FLAG_BITEXACT)) {
  152. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
  153. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
  154. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_mmxext;
  155. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_mmxext;
  156. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
  157. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmxext;
  158. }
  159. if (flags & CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
  160. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_mmxext;
  161. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_mmxext;
  162. }
  163. #endif /* HAVE_YASM */
  164. }
  165. static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags, int mm_flags)
  166. {
  167. #if HAVE_YASM
  168. c->put_pixels_tab[0][1] = ff_put_pixels16_x2_3dnow;
  169. c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
  170. c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
  171. c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
  172. c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
  173. c->put_pixels_tab[1][1] = ff_put_pixels8_x2_3dnow;
  174. c->put_pixels_tab[1][2] = ff_put_pixels8_y2_3dnow;
  175. c->avg_pixels_tab[1][0] = ff_avg_pixels8_3dnow;
  176. c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_3dnow;
  177. c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_3dnow;
  178. if (!(flags & CODEC_FLAG_BITEXACT)){
  179. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
  180. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
  181. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_3dnow;
  182. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_3dnow;
  183. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
  184. c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_3dnow;
  185. }
  186. if (flags & CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
  187. c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_3dnow;
  188. c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_3dnow;
  189. }
  190. #endif /* HAVE_YASM */
  191. }
  192. static void hpeldsp_init_sse2(HpelDSPContext *c, int flags, int mm_flags)
  193. {
  194. #if HAVE_YASM
  195. if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
  196. // these functions are slower than mmx on AMD, but faster on Intel
  197. c->put_pixels_tab[0][0] = ff_put_pixels16_sse2;
  198. c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
  199. c->avg_pixels_tab[0][0] = ff_avg_pixels16_sse2;
  200. }
  201. #endif /* HAVE_YASM */
  202. }
  203. void ff_hpeldsp_init_x86(HpelDSPContext *c, int flags)
  204. {
  205. int mm_flags = av_get_cpu_flags();
  206. if (mm_flags & AV_CPU_FLAG_MMX)
  207. hpeldsp_init_mmx(c, flags, mm_flags);
  208. if (mm_flags & AV_CPU_FLAG_MMXEXT)
  209. hpeldsp_init_mmxext(c, flags, mm_flags);
  210. if (mm_flags & AV_CPU_FLAG_3DNOW)
  211. hpeldsp_init_3dnow(c, flags, mm_flags);
  212. if (mm_flags & AV_CPU_FLAG_SSE2)
  213. hpeldsp_init_sse2(c, flags, mm_flags);
  214. }