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.

151 lines
6.0KB

  1. /*
  2. * MMX optimized DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
  23. */
  24. #include "config.h"
  25. #include "libavutil/avassert.h"
  26. #include "libavutil/cpu.h"
  27. #include "libavutil/x86/asm.h"
  28. #include "libavcodec/pixels.h"
  29. #include "libavcodec/videodsp.h"
  30. #include "dsputil_x86.h"
  31. #include "inline_asm.h"
  32. #if HAVE_INLINE_ASM
  33. /* Draw the edges of width 'w' of an image of size width, height
  34. * this MMX version can only handle w == 8 || w == 16. */
  35. void ff_draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
  36. int w, int h, int sides)
  37. {
  38. uint8_t *ptr, *last_line;
  39. int i;
  40. last_line = buf + (height - 1) * wrap;
  41. /* left and right */
  42. ptr = buf;
  43. if (w == 8) {
  44. __asm__ volatile (
  45. "1: \n\t"
  46. "movd (%0), %%mm0 \n\t"
  47. "punpcklbw %%mm0, %%mm0 \n\t"
  48. "punpcklwd %%mm0, %%mm0 \n\t"
  49. "punpckldq %%mm0, %%mm0 \n\t"
  50. "movq %%mm0, -8(%0) \n\t"
  51. "movq -8(%0, %2), %%mm1 \n\t"
  52. "punpckhbw %%mm1, %%mm1 \n\t"
  53. "punpckhwd %%mm1, %%mm1 \n\t"
  54. "punpckhdq %%mm1, %%mm1 \n\t"
  55. "movq %%mm1, (%0, %2) \n\t"
  56. "add %1, %0 \n\t"
  57. "cmp %3, %0 \n\t"
  58. "jb 1b \n\t"
  59. : "+r" (ptr)
  60. : "r" ((x86_reg) wrap), "r" ((x86_reg) width),
  61. "r" (ptr + wrap * height));
  62. } else if (w == 16) {
  63. __asm__ volatile (
  64. "1: \n\t"
  65. "movd (%0), %%mm0 \n\t"
  66. "punpcklbw %%mm0, %%mm0 \n\t"
  67. "punpcklwd %%mm0, %%mm0 \n\t"
  68. "punpckldq %%mm0, %%mm0 \n\t"
  69. "movq %%mm0, -8(%0) \n\t"
  70. "movq %%mm0, -16(%0) \n\t"
  71. "movq -8(%0, %2), %%mm1 \n\t"
  72. "punpckhbw %%mm1, %%mm1 \n\t"
  73. "punpckhwd %%mm1, %%mm1 \n\t"
  74. "punpckhdq %%mm1, %%mm1 \n\t"
  75. "movq %%mm1, (%0, %2) \n\t"
  76. "movq %%mm1, 8(%0, %2) \n\t"
  77. "add %1, %0 \n\t"
  78. "cmp %3, %0 \n\t"
  79. "jb 1b \n\t"
  80. : "+r"(ptr)
  81. : "r"((x86_reg)wrap), "r"((x86_reg)width), "r"(ptr + wrap * height)
  82. );
  83. } else {
  84. av_assert1(w == 4);
  85. __asm__ volatile (
  86. "1: \n\t"
  87. "movd (%0), %%mm0 \n\t"
  88. "punpcklbw %%mm0, %%mm0 \n\t"
  89. "punpcklwd %%mm0, %%mm0 \n\t"
  90. "movd %%mm0, -4(%0) \n\t"
  91. "movd -4(%0, %2), %%mm1 \n\t"
  92. "punpcklbw %%mm1, %%mm1 \n\t"
  93. "punpckhwd %%mm1, %%mm1 \n\t"
  94. "punpckhdq %%mm1, %%mm1 \n\t"
  95. "movd %%mm1, (%0, %2) \n\t"
  96. "add %1, %0 \n\t"
  97. "cmp %3, %0 \n\t"
  98. "jb 1b \n\t"
  99. : "+r" (ptr)
  100. : "r" ((x86_reg) wrap), "r" ((x86_reg) width),
  101. "r" (ptr + wrap * height));
  102. }
  103. /* top and bottom (and hopefully also the corners) */
  104. if (sides & EDGE_TOP) {
  105. for (i = 0; i < h; i += 4) {
  106. ptr = buf - (i + 1) * wrap - w;
  107. __asm__ volatile (
  108. "1: \n\t"
  109. "movq (%1, %0), %%mm0 \n\t"
  110. "movq %%mm0, (%0) \n\t"
  111. "movq %%mm0, (%0, %2) \n\t"
  112. "movq %%mm0, (%0, %2, 2) \n\t"
  113. "movq %%mm0, (%0, %3) \n\t"
  114. "add $8, %0 \n\t"
  115. "cmp %4, %0 \n\t"
  116. "jb 1b \n\t"
  117. : "+r" (ptr)
  118. : "r" ((x86_reg) buf - (x86_reg) ptr - w),
  119. "r" ((x86_reg) - wrap), "r" ((x86_reg) - wrap * 3),
  120. "r" (ptr + width + 2 * w));
  121. }
  122. }
  123. if (sides & EDGE_BOTTOM) {
  124. for (i = 0; i < h; i += 4) {
  125. ptr = last_line + (i + 1) * wrap - w;
  126. __asm__ volatile (
  127. "1: \n\t"
  128. "movq (%1, %0), %%mm0 \n\t"
  129. "movq %%mm0, (%0) \n\t"
  130. "movq %%mm0, (%0, %2) \n\t"
  131. "movq %%mm0, (%0, %2, 2) \n\t"
  132. "movq %%mm0, (%0, %3) \n\t"
  133. "add $8, %0 \n\t"
  134. "cmp %4, %0 \n\t"
  135. "jb 1b \n\t"
  136. : "+r" (ptr)
  137. : "r" ((x86_reg) last_line - (x86_reg) ptr - w),
  138. "r" ((x86_reg) wrap), "r" ((x86_reg) wrap * 3),
  139. "r" (ptr + width + 2 * w));
  140. }
  141. }
  142. }
  143. #endif /* HAVE_INLINE_ASM */