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.

131 lines
4.5KB

  1. /*
  2. * Copyright (c) 2009 Loren Merritt <lorenm@u.washington.edu>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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/attributes.h"
  22. #include "libavutil/cpu.h"
  23. #include "libavutil/x86/asm.h"
  24. #include "libavutil/x86/cpu.h"
  25. #include "libavcodec/huffyuvdsp.h"
  26. void ff_add_hfyu_median_pred_mmxext(uint8_t *dst, const uint8_t *top,
  27. const uint8_t *diff, int w,
  28. int *left, int *left_top);
  29. int ff_add_hfyu_left_pred_ssse3(uint8_t *dst, const uint8_t *src,
  30. int w, int left);
  31. int ff_add_hfyu_left_pred_sse4(uint8_t *dst, const uint8_t *src,
  32. int w, int left);
  33. #if HAVE_INLINE_ASM
  34. #if HAVE_7REGS
  35. static void add_hfyu_median_pred_cmov(uint8_t *dst, const uint8_t *top,
  36. const uint8_t *diff, int w,
  37. int *left, int *left_top)
  38. {
  39. x86_reg w2 = -w;
  40. x86_reg x;
  41. int l = *left & 0xff;
  42. int tl = *left_top & 0xff;
  43. int t;
  44. __asm__ volatile (
  45. "mov %7, %3 \n"
  46. "1: \n"
  47. "movzbl (%3, %4), %2 \n"
  48. "mov %2, %k3 \n"
  49. "sub %b1, %b3 \n"
  50. "add %b0, %b3 \n"
  51. "mov %2, %1 \n"
  52. "cmp %0, %2 \n"
  53. "cmovg %0, %2 \n"
  54. "cmovg %1, %0 \n"
  55. "cmp %k3, %0 \n"
  56. "cmovg %k3, %0 \n"
  57. "mov %7, %3 \n"
  58. "cmp %2, %0 \n"
  59. "cmovl %2, %0 \n"
  60. "add (%6, %4), %b0 \n"
  61. "mov %b0, (%5, %4) \n"
  62. "inc %4 \n"
  63. "jl 1b \n"
  64. : "+&q"(l), "+&q"(tl), "=&r"(t), "=&q"(x), "+&r"(w2)
  65. : "r"(dst + w), "r"(diff + w), "rm"(top + w)
  66. );
  67. *left = l;
  68. *left_top = tl;
  69. }
  70. #endif /* HAVE_7REGS */
  71. static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w)
  72. {
  73. x86_reg i = 0;
  74. __asm__ volatile (
  75. "jmp 2f \n\t"
  76. "1: \n\t"
  77. "movq (%1, %0), %%mm0 \n\t"
  78. "movq (%2, %0), %%mm1 \n\t"
  79. "paddb %%mm0, %%mm1 \n\t"
  80. "movq %%mm1, (%2, %0) \n\t"
  81. "movq 8(%1, %0), %%mm0 \n\t"
  82. "movq 8(%2, %0), %%mm1 \n\t"
  83. "paddb %%mm0, %%mm1 \n\t"
  84. "movq %%mm1, 8(%2, %0) \n\t"
  85. "add $16, %0 \n\t"
  86. "2: \n\t"
  87. "cmp %3, %0 \n\t"
  88. "js 1b \n\t"
  89. : "+r" (i)
  90. : "r" (src), "r" (dst), "r" ((x86_reg) w - 15));
  91. for (; i < w; i++)
  92. dst[i + 0] += src[i + 0];
  93. }
  94. #endif /* HAVE_INLINE_ASM */
  95. av_cold void ff_huffyuvdsp_init_x86(HuffYUVDSPContext *c)
  96. {
  97. int cpu_flags = av_get_cpu_flags();
  98. #if HAVE_INLINE_ASM
  99. #if HAVE_7REGS
  100. if (cpu_flags & AV_CPU_FLAG_CMOV)
  101. c->add_hfyu_median_pred = add_hfyu_median_pred_cmov;
  102. #endif /* HAVE_7REGS */
  103. if (INLINE_MMX(cpu_flags))
  104. c->add_bytes = add_bytes_mmx;
  105. #endif /* HAVE_INLINE_ASM */
  106. if (EXTERNAL_MMXEXT(cpu_flags)) {
  107. /* slower than cmov version on AMD */
  108. if (!(cpu_flags & AV_CPU_FLAG_3DNOW))
  109. c->add_hfyu_median_pred = ff_add_hfyu_median_pred_mmxext;
  110. }
  111. if (EXTERNAL_SSSE3(cpu_flags)) {
  112. c->add_hfyu_left_pred = ff_add_hfyu_left_pred_ssse3;
  113. if (cpu_flags & AV_CPU_FLAG_SSE4) // not really SSE4, just slow on Conroe
  114. c->add_hfyu_left_pred = ff_add_hfyu_left_pred_sse4;
  115. }
  116. }