lossless_videoencdsp_init.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * SIMD-optimized lossless video encoding functions
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/cpu.h"
  26. #include "libavutil/x86/asm.h"
  27. #include "libavutil/x86/cpu.h"
  28. #include "libavcodec/lossless_videoencdsp.h"
  29. #include "libavcodec/mathops.h"
  30. void ff_diff_bytes_mmx(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
  31. intptr_t w);
  32. void ff_diff_bytes_sse2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
  33. intptr_t w);
  34. void ff_diff_bytes_avx2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
  35. intptr_t w);
  36. void ff_sub_left_predict_avx(uint8_t *dst, uint8_t *src,
  37. ptrdiff_t stride, ptrdiff_t width, int height);
  38. #if HAVE_INLINE_ASM
  39. static void sub_median_pred_mmxext(uint8_t *dst, const uint8_t *src1,
  40. const uint8_t *src2, intptr_t w,
  41. int *left, int *left_top)
  42. {
  43. x86_reg i = 0;
  44. uint8_t l, lt;
  45. __asm__ volatile (
  46. "movq (%1, %0), %%mm0 \n\t" // LT
  47. "psllq $8, %%mm0 \n\t"
  48. "1: \n\t"
  49. "movq (%1, %0), %%mm1 \n\t" // T
  50. "movq -1(%2, %0), %%mm2 \n\t" // L
  51. "movq (%2, %0), %%mm3 \n\t" // X
  52. "movq %%mm2, %%mm4 \n\t" // L
  53. "psubb %%mm0, %%mm2 \n\t"
  54. "paddb %%mm1, %%mm2 \n\t" // L + T - LT
  55. "movq %%mm4, %%mm5 \n\t" // L
  56. "pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
  57. "pminub %%mm5, %%mm1 \n\t" // min(T, L)
  58. "pminub %%mm2, %%mm4 \n\t"
  59. "pmaxub %%mm1, %%mm4 \n\t"
  60. "psubb %%mm4, %%mm3 \n\t" // dst - pred
  61. "movq %%mm3, (%3, %0) \n\t"
  62. "add $8, %0 \n\t"
  63. "movq -1(%1, %0), %%mm0 \n\t" // LT
  64. "cmp %4, %0 \n\t"
  65. " jb 1b \n\t"
  66. : "+r" (i)
  67. : "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w));
  68. l = *left;
  69. lt = *left_top;
  70. dst[0] = src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt) & 0xFF);
  71. *left_top = src1[w - 1];
  72. *left = src2[w - 1];
  73. }
  74. #endif /* HAVE_INLINE_ASM */
  75. av_cold void ff_llvidencdsp_init_x86(LLVidEncDSPContext *c)
  76. {
  77. av_unused int cpu_flags = av_get_cpu_flags();
  78. if (ARCH_X86_32 && EXTERNAL_MMX(cpu_flags)) {
  79. c->diff_bytes = ff_diff_bytes_mmx;
  80. }
  81. #if HAVE_INLINE_ASM
  82. if (INLINE_MMXEXT(cpu_flags)) {
  83. c->sub_median_pred = sub_median_pred_mmxext;
  84. }
  85. #endif /* HAVE_INLINE_ASM */
  86. if (EXTERNAL_SSE2(cpu_flags)) {
  87. c->diff_bytes = ff_diff_bytes_sse2;
  88. }
  89. if (EXTERNAL_AVX(cpu_flags)) {
  90. c->sub_left_predict = ff_sub_left_predict_avx;
  91. }
  92. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  93. c->diff_bytes = ff_diff_bytes_avx2;
  94. }
  95. }