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.

114 lines
3.9KB

  1. /*
  2. * SIMD-optimized HuffYUV 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 Libav.
  9. *
  10. * Libav 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. * Libav 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 Libav; 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/huffyuvencdsp.h"
  29. #include "libavcodec/mathops.h"
  30. #if HAVE_INLINE_ASM
  31. static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w)
  32. {
  33. x86_reg i = 0;
  34. __asm__ volatile (
  35. "1: \n\t"
  36. "movq (%2, %0), %%mm0 \n\t"
  37. "movq (%1, %0), %%mm1 \n\t"
  38. "psubb %%mm0, %%mm1 \n\t"
  39. "movq %%mm1, (%3, %0) \n\t"
  40. "movq 8(%2, %0), %%mm0 \n\t"
  41. "movq 8(%1, %0), %%mm1 \n\t"
  42. "psubb %%mm0, %%mm1 \n\t"
  43. "movq %%mm1, 8(%3, %0) \n\t"
  44. "add $16, %0 \n\t"
  45. "cmp %4, %0 \n\t"
  46. " jb 1b \n\t"
  47. : "+r" (i)
  48. : "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w - 15));
  49. for (; i < w; i++)
  50. dst[i + 0] = src1[i + 0] - src2[i + 0];
  51. }
  52. static void sub_hfyu_median_pred_mmxext(uint8_t *dst, const uint8_t *src1,
  53. const uint8_t *src2, int w,
  54. int *left, int *left_top)
  55. {
  56. x86_reg i = 0;
  57. uint8_t l, lt;
  58. __asm__ volatile (
  59. "movq (%1, %0), %%mm0 \n\t" // LT
  60. "psllq $8, %%mm0 \n\t"
  61. "1: \n\t"
  62. "movq (%1, %0), %%mm1 \n\t" // T
  63. "movq -1(%2, %0), %%mm2 \n\t" // L
  64. "movq (%2, %0), %%mm3 \n\t" // X
  65. "movq %%mm2, %%mm4 \n\t" // L
  66. "psubb %%mm0, %%mm2 \n\t"
  67. "paddb %%mm1, %%mm2 \n\t" // L + T - LT
  68. "movq %%mm4, %%mm5 \n\t" // L
  69. "pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
  70. "pminub %%mm5, %%mm1 \n\t" // min(T, L)
  71. "pminub %%mm2, %%mm4 \n\t"
  72. "pmaxub %%mm1, %%mm4 \n\t"
  73. "psubb %%mm4, %%mm3 \n\t" // dst - pred
  74. "movq %%mm3, (%3, %0) \n\t"
  75. "add $8, %0 \n\t"
  76. "movq -1(%1, %0), %%mm0 \n\t" // LT
  77. "cmp %4, %0 \n\t"
  78. " jb 1b \n\t"
  79. : "+r" (i)
  80. : "r" (src1), "r" (src2), "r" (dst), "r" ((x86_reg) w));
  81. l = *left;
  82. lt = *left_top;
  83. dst[0] = src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt) & 0xFF);
  84. *left_top = src1[w - 1];
  85. *left = src2[w - 1];
  86. }
  87. #endif /* HAVE_INLINE_ASM */
  88. av_cold void ff_huffyuvencdsp_init_x86(HuffYUVEncDSPContext *c)
  89. {
  90. #if HAVE_INLINE_ASM
  91. int cpu_flags = av_get_cpu_flags();
  92. if (INLINE_MMX(cpu_flags)) {
  93. c->diff_bytes = diff_bytes_mmx;
  94. }
  95. if (INLINE_MMXEXT(cpu_flags)) {
  96. c->sub_hfyu_median_pred = sub_hfyu_median_pred_mmxext;
  97. }
  98. #endif /* HAVE_INLINE_ASM */
  99. }