diracdsp_init.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (C) 2010 David Conrad
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/x86/cpu.h"
  21. #include "libavcodec/diracdsp.h"
  22. #include "fpel.h"
  23. DECL_DIRAC_PIXOP(put, mmx);
  24. DECL_DIRAC_PIXOP(avg, mmx);
  25. DECL_DIRAC_PIXOP(avg, mmxext);
  26. void ff_put_dirac_pixels16_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h);
  27. void ff_avg_dirac_pixels16_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h);
  28. void ff_put_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h);
  29. void ff_avg_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h);
  30. void ff_add_rect_clamped_mmx(uint8_t *, const uint16_t *, int, const int16_t *, int, int, int);
  31. void ff_add_rect_clamped_sse2(uint8_t *, const uint16_t *, int, const int16_t *, int, int, int);
  32. void ff_add_dirac_obmc8_mmx(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen);
  33. void ff_add_dirac_obmc16_mmx(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen);
  34. void ff_add_dirac_obmc32_mmx(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen);
  35. void ff_add_dirac_obmc16_sse2(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen);
  36. void ff_add_dirac_obmc32_sse2(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen);
  37. void ff_put_rect_clamped_mmx(uint8_t *dst, int dst_stride, const int16_t *src, int src_stride, int width, int height);
  38. void ff_put_rect_clamped_sse2(uint8_t *dst, int dst_stride, const int16_t *src, int src_stride, int width, int height);
  39. void ff_put_signed_rect_clamped_mmx(uint8_t *dst, int dst_stride, const int16_t *src, int src_stride, int width, int height);
  40. void ff_put_signed_rect_clamped_sse2(uint8_t *dst, int dst_stride, const int16_t *src, int src_stride, int width, int height);
  41. void ff_put_signed_rect_clamped_10_sse4(uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int width, int height);
  42. void ff_dequant_subband_32_sse4(uint8_t *src, uint8_t *dst, ptrdiff_t stride, const int qf, const int qs, int tot_v, int tot_h);
  43. #if HAVE_X86ASM
  44. #define HPEL_FILTER(MMSIZE, EXT) \
  45. void ff_dirac_hpel_filter_v_ ## EXT(uint8_t *, const uint8_t *, int, int); \
  46. void ff_dirac_hpel_filter_h_ ## EXT(uint8_t *, const uint8_t *, int); \
  47. \
  48. static void dirac_hpel_filter_ ## EXT(uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, \
  49. const uint8_t *src, int stride, int width, int height) \
  50. { \
  51. while( height-- ) \
  52. { \
  53. ff_dirac_hpel_filter_v_ ## EXT(dstv-MMSIZE, src-MMSIZE, stride, width+MMSIZE+5); \
  54. ff_dirac_hpel_filter_h_ ## EXT(dsth, src, width); \
  55. ff_dirac_hpel_filter_h_ ## EXT(dstc, dstv, width); \
  56. \
  57. dsth += stride; \
  58. dstv += stride; \
  59. dstc += stride; \
  60. src += stride; \
  61. } \
  62. }
  63. #define PIXFUNC(PFX, IDX, EXT) \
  64. /*MMXDISABLEDc->PFX ## _dirac_pixels_tab[0][IDX] = ff_ ## PFX ## _dirac_pixels8_ ## EXT;*/ \
  65. c->PFX ## _dirac_pixels_tab[1][IDX] = ff_ ## PFX ## _dirac_pixels16_ ## EXT; \
  66. c->PFX ## _dirac_pixels_tab[2][IDX] = ff_ ## PFX ## _dirac_pixels32_ ## EXT
  67. #define DIRAC_PIXOP(OPNAME2, OPNAME, EXT)\
  68. void ff_ ## OPNAME2 ## _dirac_pixels8_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  69. {\
  70. if (h&3)\
  71. ff_ ## OPNAME2 ## _dirac_pixels8_c(dst, src, stride, h);\
  72. else\
  73. OPNAME ## _pixels8_ ## EXT(dst, src[0], stride, h);\
  74. }\
  75. void ff_ ## OPNAME2 ## _dirac_pixels16_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  76. {\
  77. if (h&3)\
  78. ff_ ## OPNAME2 ## _dirac_pixels16_c(dst, src, stride, h);\
  79. else\
  80. OPNAME ## _pixels16_ ## EXT(dst, src[0], stride, h);\
  81. }\
  82. void ff_ ## OPNAME2 ## _dirac_pixels32_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h)\
  83. {\
  84. if (h&3) {\
  85. ff_ ## OPNAME2 ## _dirac_pixels32_c(dst, src, stride, h);\
  86. } else {\
  87. OPNAME ## _pixels16_ ## EXT(dst , src[0] , stride, h);\
  88. OPNAME ## _pixels16_ ## EXT(dst+16, src[0]+16, stride, h);\
  89. }\
  90. }
  91. DIRAC_PIXOP(put, ff_put, mmx)
  92. DIRAC_PIXOP(avg, ff_avg, mmx)
  93. DIRAC_PIXOP(avg, ff_avg, mmxext)
  94. void ff_put_dirac_pixels16_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
  95. {
  96. if (h&3)
  97. ff_put_dirac_pixels16_c(dst, src, stride, h);
  98. else
  99. ff_put_pixels16_sse2(dst, src[0], stride, h);
  100. }
  101. void ff_avg_dirac_pixels16_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
  102. {
  103. if (h&3)
  104. ff_avg_dirac_pixels16_c(dst, src, stride, h);
  105. else
  106. ff_avg_pixels16_sse2(dst, src[0], stride, h);
  107. }
  108. void ff_put_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
  109. {
  110. if (h&3) {
  111. ff_put_dirac_pixels32_c(dst, src, stride, h);
  112. } else {
  113. ff_put_pixels16_sse2(dst , src[0] , stride, h);
  114. ff_put_pixels16_sse2(dst+16, src[0]+16, stride, h);
  115. }
  116. }
  117. void ff_avg_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h)
  118. {
  119. if (h&3) {
  120. ff_avg_dirac_pixels32_c(dst, src, stride, h);
  121. } else {
  122. ff_avg_pixels16_sse2(dst , src[0] , stride, h);
  123. ff_avg_pixels16_sse2(dst+16, src[0]+16, stride, h);
  124. }
  125. }
  126. #else // HAVE_X86ASM
  127. #define HPEL_FILTER(MMSIZE, EXT) \
  128. void dirac_hpel_filter_ ## EXT(uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, \
  129. const uint8_t *src, int stride, int width, int height);
  130. #define PIXFUNC(PFX, IDX, EXT) do {} while (0)
  131. #endif // HAVE_X86ASM
  132. #if !ARCH_X86_64
  133. HPEL_FILTER(8, mmx)
  134. #endif
  135. HPEL_FILTER(16, sse2)
  136. void ff_diracdsp_init_x86(DiracDSPContext* c)
  137. {
  138. int mm_flags = av_get_cpu_flags();
  139. if (EXTERNAL_MMX(mm_flags)) {
  140. c->add_dirac_obmc[0] = ff_add_dirac_obmc8_mmx;
  141. #if !ARCH_X86_64
  142. c->add_dirac_obmc[1] = ff_add_dirac_obmc16_mmx;
  143. c->add_dirac_obmc[2] = ff_add_dirac_obmc32_mmx;
  144. c->dirac_hpel_filter = dirac_hpel_filter_mmx;
  145. c->add_rect_clamped = ff_add_rect_clamped_mmx;
  146. c->put_signed_rect_clamped[0] = (void *)ff_put_signed_rect_clamped_mmx;
  147. #endif
  148. PIXFUNC(put, 0, mmx);
  149. PIXFUNC(avg, 0, mmx);
  150. }
  151. if (EXTERNAL_MMXEXT(mm_flags)) {
  152. PIXFUNC(avg, 0, mmxext);
  153. }
  154. if (EXTERNAL_SSE2(mm_flags)) {
  155. c->dirac_hpel_filter = dirac_hpel_filter_sse2;
  156. c->add_rect_clamped = ff_add_rect_clamped_sse2;
  157. c->put_signed_rect_clamped[0] = (void *)ff_put_signed_rect_clamped_sse2;
  158. c->add_dirac_obmc[1] = ff_add_dirac_obmc16_sse2;
  159. c->add_dirac_obmc[2] = ff_add_dirac_obmc32_sse2;
  160. c->put_dirac_pixels_tab[1][0] = ff_put_dirac_pixels16_sse2;
  161. c->avg_dirac_pixels_tab[1][0] = ff_avg_dirac_pixels16_sse2;
  162. c->put_dirac_pixels_tab[2][0] = ff_put_dirac_pixels32_sse2;
  163. c->avg_dirac_pixels_tab[2][0] = ff_avg_dirac_pixels32_sse2;
  164. }
  165. if (EXTERNAL_SSE4(mm_flags)) {
  166. c->dequant_subband[1] = ff_dequant_subband_32_sse4;
  167. c->put_signed_rect_clamped[1] = ff_put_signed_rect_clamped_10_sse4;
  168. }
  169. }