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.

129 lines
5.1KB

  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. * 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 "config.h"
  25. #include "libavutil/cpu.h"
  26. #include "libavutil/x86/asm.h"
  27. #include "dsputil_x86.h"
  28. #include "inline_asm.h"
  29. #if HAVE_INLINE_ASM
  30. /* Draw the edges of width 'w' of an image of size width, height
  31. * this MMX version can only handle w == 8 || w == 16. */
  32. void ff_draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
  33. int w, int h, int sides)
  34. {
  35. uint8_t *ptr, *last_line;
  36. int i;
  37. last_line = buf + (height - 1) * wrap;
  38. /* left and right */
  39. ptr = buf;
  40. if (w == 8) {
  41. __asm__ volatile (
  42. "1: \n\t"
  43. "movd (%0), %%mm0 \n\t"
  44. "punpcklbw %%mm0, %%mm0 \n\t"
  45. "punpcklwd %%mm0, %%mm0 \n\t"
  46. "punpckldq %%mm0, %%mm0 \n\t"
  47. "movq %%mm0, -8(%0) \n\t"
  48. "movq -8(%0, %2), %%mm1 \n\t"
  49. "punpckhbw %%mm1, %%mm1 \n\t"
  50. "punpckhwd %%mm1, %%mm1 \n\t"
  51. "punpckhdq %%mm1, %%mm1 \n\t"
  52. "movq %%mm1, (%0, %2) \n\t"
  53. "add %1, %0 \n\t"
  54. "cmp %3, %0 \n\t"
  55. "jb 1b \n\t"
  56. : "+r" (ptr)
  57. : "r" ((x86_reg) wrap), "r" ((x86_reg) width),
  58. "r" (ptr + wrap * height));
  59. } else {
  60. __asm__ volatile (
  61. "1: \n\t"
  62. "movd (%0), %%mm0 \n\t"
  63. "punpcklbw %%mm0, %%mm0 \n\t"
  64. "punpcklwd %%mm0, %%mm0 \n\t"
  65. "punpckldq %%mm0, %%mm0 \n\t"
  66. "movq %%mm0, -8(%0) \n\t"
  67. "movq %%mm0, -16(%0) \n\t"
  68. "movq -8(%0, %2), %%mm1 \n\t"
  69. "punpckhbw %%mm1, %%mm1 \n\t"
  70. "punpckhwd %%mm1, %%mm1 \n\t"
  71. "punpckhdq %%mm1, %%mm1 \n\t"
  72. "movq %%mm1, (%0, %2) \n\t"
  73. "movq %%mm1, 8(%0, %2) \n\t"
  74. "add %1, %0 \n\t"
  75. "cmp %3, %0 \n\t"
  76. "jb 1b \n\t"
  77. : "+r" (ptr)
  78. : "r" ((x86_reg) wrap), "r" ((x86_reg) width),
  79. "r" (ptr + wrap * height));
  80. }
  81. /* top and bottom (and hopefully also the corners) */
  82. if (sides & EDGE_TOP) {
  83. for (i = 0; i < h; i += 4) {
  84. ptr = buf - (i + 1) * wrap - w;
  85. __asm__ volatile (
  86. "1: \n\t"
  87. "movq (%1, %0), %%mm0 \n\t"
  88. "movq %%mm0, (%0) \n\t"
  89. "movq %%mm0, (%0, %2) \n\t"
  90. "movq %%mm0, (%0, %2, 2) \n\t"
  91. "movq %%mm0, (%0, %3) \n\t"
  92. "add $8, %0 \n\t"
  93. "cmp %4, %0 \n\t"
  94. "jb 1b \n\t"
  95. : "+r" (ptr)
  96. : "r" ((x86_reg) buf - (x86_reg) ptr - w),
  97. "r" ((x86_reg) - wrap), "r" ((x86_reg) - wrap * 3),
  98. "r" (ptr + width + 2 * w));
  99. }
  100. }
  101. if (sides & EDGE_BOTTOM) {
  102. for (i = 0; i < h; i += 4) {
  103. ptr = last_line + (i + 1) * wrap - w;
  104. __asm__ volatile (
  105. "1: \n\t"
  106. "movq (%1, %0), %%mm0 \n\t"
  107. "movq %%mm0, (%0) \n\t"
  108. "movq %%mm0, (%0, %2) \n\t"
  109. "movq %%mm0, (%0, %2, 2) \n\t"
  110. "movq %%mm0, (%0, %3) \n\t"
  111. "add $8, %0 \n\t"
  112. "cmp %4, %0 \n\t"
  113. "jb 1b \n\t"
  114. : "+r" (ptr)
  115. : "r" ((x86_reg) last_line - (x86_reg) ptr - w),
  116. "r" ((x86_reg) wrap), "r" ((x86_reg) wrap * 3),
  117. "r" (ptr + width + 2 * w));
  118. }
  119. }
  120. }
  121. #endif /* HAVE_INLINE_ASM */