vf_idet_init.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg 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 GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "libavutil/attributes.h"
  19. #include "libavutil/cpu.h"
  20. #include "libavutil/mem.h"
  21. #include "libavutil/x86/asm.h"
  22. #include "libavutil/x86/cpu.h"
  23. #include "libavfilter/vf_idet.h"
  24. #if HAVE_YASM
  25. /* declares main callable idet_filter_line_{mmx,mmxext,sse2}() */
  26. #define FUNC_MAIN_DECL(KIND, SPAN) \
  27. int ff_idet_filter_line_##KIND(const uint8_t *a, const uint8_t *b, \
  28. const uint8_t *c, int w); \
  29. static int idet_filter_line_##KIND(const uint8_t *a, const uint8_t *b, \
  30. const uint8_t *c, int w) { \
  31. int sum = 0; \
  32. const int left_over = w & (SPAN - 1); \
  33. w -= left_over; \
  34. if (w > 0) \
  35. sum += ff_idet_filter_line_##KIND(a, b, c, w); \
  36. if (left_over > 0) \
  37. sum += ff_idet_filter_line_c(a + w, b + w, c + w, left_over); \
  38. return sum; \
  39. }
  40. #define FUNC_MAIN_DECL_16bit(KIND, SPAN) \
  41. int ff_idet_filter_line_16bit_##KIND(const uint16_t *a, const uint16_t *b, \
  42. const uint16_t *c, int w); \
  43. static int idet_filter_line_16bit_##KIND(const uint16_t *a, const uint16_t *b, \
  44. const uint16_t *c, int w) { \
  45. int sum = 0; \
  46. const int left_over = w & (SPAN - 1); \
  47. w -= left_over; \
  48. if (w > 0) \
  49. sum += ff_idet_filter_line_16bit_##KIND(a, b, c, w); \
  50. if (left_over > 0) \
  51. sum += ff_idet_filter_line_c_16bit(a + w, b + w, c + w, left_over); \
  52. return sum; \
  53. }
  54. FUNC_MAIN_DECL(sse2, 16)
  55. FUNC_MAIN_DECL_16bit(sse2, 8)
  56. #if ARCH_X86_32
  57. FUNC_MAIN_DECL(mmx, 8)
  58. FUNC_MAIN_DECL(mmxext, 8)
  59. FUNC_MAIN_DECL_16bit(mmx, 4)
  60. #endif
  61. #endif
  62. av_cold void ff_idet_init_x86(IDETContext *idet, int for_16b)
  63. {
  64. #if HAVE_YASM
  65. const int cpu_flags = av_get_cpu_flags();
  66. #if ARCH_X86_32
  67. if (EXTERNAL_MMX(cpu_flags)) {
  68. idet->filter_line = for_16b ? (ff_idet_filter_func)idet_filter_line_16bit_mmx : idet_filter_line_mmx;
  69. }
  70. if (EXTERNAL_MMXEXT(cpu_flags)) {
  71. idet->filter_line = for_16b ? (ff_idet_filter_func)idet_filter_line_16bit_mmx : idet_filter_line_mmxext;
  72. }
  73. #endif // ARCH_x86_32
  74. if (EXTERNAL_SSE2(cpu_flags)) {
  75. idet->filter_line = for_16b ? (ff_idet_filter_func)idet_filter_line_16bit_sse2 : idet_filter_line_sse2;
  76. }
  77. #endif // HAVE_YASM
  78. }