2
0

lossless_videodsp_init.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Lossless video DSP utils
  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 "config.h"
  21. #include "libavutil/x86/asm.h"
  22. #include "../lossless_videodsp.h"
  23. #include "libavutil/x86/cpu.h"
  24. void ff_add_bytes_mmx(uint8_t *dst, uint8_t *src, ptrdiff_t w);
  25. void ff_add_bytes_sse2(uint8_t *dst, uint8_t *src, ptrdiff_t w);
  26. void ff_add_bytes_avx2(uint8_t *dst, uint8_t *src, ptrdiff_t w);
  27. void ff_add_median_pred_mmxext(uint8_t *dst, const uint8_t *top,
  28. const uint8_t *diff, ptrdiff_t w,
  29. int *left, int *left_top);
  30. void ff_add_median_pred_sse2(uint8_t *dst, const uint8_t *top,
  31. const uint8_t *diff, ptrdiff_t w,
  32. int *left, int *left_top);
  33. int ff_add_left_pred_ssse3(uint8_t *dst, const uint8_t *src,
  34. ptrdiff_t w, int left);
  35. int ff_add_left_pred_unaligned_ssse3(uint8_t *dst, const uint8_t *src,
  36. ptrdiff_t w, int left);
  37. int ff_add_left_pred_unaligned_avx2(uint8_t *dst, const uint8_t *src,
  38. ptrdiff_t w, int left);
  39. int ff_add_left_pred_int16_ssse3(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc);
  40. int ff_add_left_pred_int16_unaligned_ssse3(uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc);
  41. void ff_add_gradient_pred_ssse3(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width);
  42. void ff_add_gradient_pred_avx2(uint8_t *src, const ptrdiff_t stride, const ptrdiff_t width);
  43. #if HAVE_INLINE_ASM && HAVE_7REGS && ARCH_X86_32
  44. static void add_median_pred_cmov(uint8_t *dst, const uint8_t *top,
  45. const uint8_t *diff, ptrdiff_t w,
  46. int *left, int *left_top)
  47. {
  48. x86_reg w2 = -w;
  49. x86_reg x;
  50. int l = *left & 0xff;
  51. int tl = *left_top & 0xff;
  52. int t;
  53. __asm__ volatile (
  54. "mov %7, %3 \n"
  55. "1: \n"
  56. "movzbl (%3, %4), %2 \n"
  57. "mov %2, %k3 \n"
  58. "sub %b1, %b3 \n"
  59. "add %b0, %b3 \n"
  60. "mov %2, %1 \n"
  61. "cmp %0, %2 \n"
  62. "cmovg %0, %2 \n"
  63. "cmovg %1, %0 \n"
  64. "cmp %k3, %0 \n"
  65. "cmovg %k3, %0 \n"
  66. "mov %7, %3 \n"
  67. "cmp %2, %0 \n"
  68. "cmovl %2, %0 \n"
  69. "add (%6, %4), %b0 \n"
  70. "mov %b0, (%5, %4) \n"
  71. "inc %4 \n"
  72. "jl 1b \n"
  73. : "+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
  74. : "r"(dst + w), "r"(diff + w), "rm"(top + w)
  75. );
  76. *left = l;
  77. *left_top = tl;
  78. }
  79. #endif
  80. void ff_llviddsp_init_x86(LLVidDSPContext *c)
  81. {
  82. int cpu_flags = av_get_cpu_flags();
  83. #if HAVE_INLINE_ASM && HAVE_7REGS && ARCH_X86_32
  84. if (cpu_flags & AV_CPU_FLAG_CMOV)
  85. c->add_median_pred = add_median_pred_cmov;
  86. #endif
  87. if (ARCH_X86_32 && EXTERNAL_MMX(cpu_flags)) {
  88. c->add_bytes = ff_add_bytes_mmx;
  89. }
  90. if (ARCH_X86_32 && EXTERNAL_MMXEXT(cpu_flags)) {
  91. /* slower than cmov version on AMD */
  92. if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
  93. c->add_median_pred = ff_add_median_pred_mmxext;
  94. }
  95. if (EXTERNAL_SSE2(cpu_flags)) {
  96. c->add_bytes = ff_add_bytes_sse2;
  97. c->add_median_pred = ff_add_median_pred_sse2;
  98. }
  99. if (EXTERNAL_SSSE3(cpu_flags)) {
  100. c->add_left_pred = ff_add_left_pred_ssse3;
  101. c->add_left_pred_int16 = ff_add_left_pred_int16_ssse3;
  102. c->add_gradient_pred = ff_add_gradient_pred_ssse3;
  103. }
  104. if (EXTERNAL_SSSE3_FAST(cpu_flags)) {
  105. c->add_left_pred = ff_add_left_pred_unaligned_ssse3;
  106. c->add_left_pred_int16 = ff_add_left_pred_int16_unaligned_ssse3;
  107. }
  108. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  109. c->add_bytes = ff_add_bytes_avx2;
  110. c->add_left_pred = ff_add_left_pred_unaligned_avx2;
  111. c->add_gradient_pred = ff_add_gradient_pred_avx2;
  112. }
  113. }