vp3dsp_sse2.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright (C) 2004 the ffmpeg project
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file libavcodec/x86/vp3dsp_sse2.c
  22. * SSE2-optimized functions cribbed from the original VP3 source code.
  23. */
  24. #include "libavcodec/dsputil.h"
  25. #include "dsputil_mmx.h"
  26. DECLARE_ALIGNED_16(const uint16_t, ff_vp3_idct_data[7 * 8]) =
  27. {
  28. 64277,64277,64277,64277,64277,64277,64277,64277,
  29. 60547,60547,60547,60547,60547,60547,60547,60547,
  30. 54491,54491,54491,54491,54491,54491,54491,54491,
  31. 46341,46341,46341,46341,46341,46341,46341,46341,
  32. 36410,36410,36410,36410,36410,36410,36410,36410,
  33. 25080,25080,25080,25080,25080,25080,25080,25080,
  34. 12785,12785,12785,12785,12785,12785,12785,12785
  35. };
  36. #define VP3_1D_IDCT_SSE2(ADD, SHIFT) \
  37. "movdqa "I(3)", %%xmm2 \n\t" /* xmm2 = i3 */ \
  38. "movdqa "C(3)", %%xmm6 \n\t" /* xmm6 = c3 */ \
  39. "movdqa %%xmm2, %%xmm4 \n\t" /* xmm4 = i3 */ \
  40. "movdqa "I(5)", %%xmm7 \n\t" /* xmm7 = i5 */ \
  41. "pmulhw %%xmm6, %%xmm4 \n\t" /* xmm4 = c3 * i3 - i3 */ \
  42. "movdqa "C(5)", %%xmm1 \n\t" /* xmm1 = c5 */ \
  43. "pmulhw %%xmm7, %%xmm6 \n\t" /* xmm6 = c3 * i5 - i5 */ \
  44. "movdqa %%xmm1, %%xmm5 \n\t" /* xmm5 = c5 */ \
  45. "pmulhw %%xmm2, %%xmm1 \n\t" /* xmm1 = c5 * i3 - i3 */ \
  46. "movdqa "I(1)", %%xmm3 \n\t" /* xmm3 = i1 */ \
  47. "pmulhw %%xmm7, %%xmm5 \n\t" /* xmm5 = c5 * i5 - i5 */ \
  48. "movdqa "C(1)", %%xmm0 \n\t" /* xmm0 = c1 */ \
  49. "paddw %%xmm2, %%xmm4 \n\t" /* xmm4 = c3 * i3 */ \
  50. "paddw %%xmm7, %%xmm6 \n\t" /* xmm6 = c3 * i5 */ \
  51. "paddw %%xmm1, %%xmm2 \n\t" /* xmm2 = c5 * i3 */ \
  52. "movdqa "I(7)", %%xmm1 \n\t" /* xmm1 = i7 */ \
  53. "paddw %%xmm5, %%xmm7 \n\t" /* xmm7 = c5 * i5 */ \
  54. "movdqa %%xmm0, %%xmm5 \n\t" /* xmm5 = c1 */ \
  55. "pmulhw %%xmm3, %%xmm0 \n\t" /* xmm0 = c1 * i1 - i1 */ \
  56. "paddsw %%xmm7, %%xmm4 \n\t" /* xmm4 = c3 * i3 + c5 * i5 = C */ \
  57. "pmulhw %%xmm1, %%xmm5 \n\t" /* xmm5 = c1 * i7 - i7 */ \
  58. "movdqa "C(7)", %%xmm7 \n\t" /* xmm7 = c7 */ \
  59. "psubsw %%xmm2, %%xmm6 \n\t" /* xmm6 = c3 * i5 - c5 * i3 = D */ \
  60. "paddw %%xmm3, %%xmm0 \n\t" /* xmm0 = c1 * i1 */ \
  61. "pmulhw %%xmm7, %%xmm3 \n\t" /* xmm3 = c7 * i1 */ \
  62. "movdqa "I(2)", %%xmm2 \n\t" /* xmm2 = i2 */ \
  63. "pmulhw %%xmm1, %%xmm7 \n\t" /* xmm7 = c7 * i7 */ \
  64. "paddw %%xmm1, %%xmm5 \n\t" /* xmm5 = c1 * i7 */ \
  65. "movdqa %%xmm2, %%xmm1 \n\t" /* xmm1 = i2 */ \
  66. "pmulhw "C(2)", %%xmm2 \n\t" /* xmm2 = i2 * c2 -i2 */ \
  67. "psubsw %%xmm5, %%xmm3 \n\t" /* xmm3 = c7 * i1 - c1 * i7 = B */ \
  68. "movdqa "I(6)", %%xmm5 \n\t" /* xmm5 = i6 */ \
  69. "paddsw %%xmm7, %%xmm0 \n\t" /* xmm0 = c1 * i1 + c7 * i7 = A */ \
  70. "movdqa %%xmm5, %%xmm7 \n\t" /* xmm7 = i6 */ \
  71. "psubsw %%xmm4, %%xmm0 \n\t" /* xmm0 = A - C */ \
  72. "pmulhw "C(2)", %%xmm5 \n\t" /* xmm5 = c2 * i6 - i6 */ \
  73. "paddw %%xmm1, %%xmm2 \n\t" /* xmm2 = i2 * c2 */ \
  74. "pmulhw "C(6)", %%xmm1 \n\t" /* xmm1 = c6 * i2 */ \
  75. "paddsw %%xmm4, %%xmm4 \n\t" /* xmm4 = C + C */ \
  76. "paddsw %%xmm0, %%xmm4 \n\t" /* xmm4 = A + C = C. */ \
  77. "psubsw %%xmm6, %%xmm3 \n\t" /* xmm3 = B - D */ \
  78. "paddw %%xmm7, %%xmm5 \n\t" /* xmm5 = c2 * i6 */ \
  79. "paddsw %%xmm6, %%xmm6 \n\t" /* xmm6 = D + D */ \
  80. "pmulhw "C(6)", %%xmm7 \n\t" /* xmm7 = c6 * i6 */ \
  81. "paddsw %%xmm3, %%xmm6 \n\t" /* xmm6 = B + D = D. */ \
  82. "movdqa %%xmm4, "I(1)" \n\t" /* Save C. at I(1) */ \
  83. "psubsw %%xmm5, %%xmm1 \n\t" /* xmm1 = c6 * i2 - c2 * i6 = H */ \
  84. "movdqa "C(4)", %%xmm4 \n\t" /* xmm4 = c4 */ \
  85. "movdqa %%xmm3, %%xmm5 \n\t" /* xmm5 = B - D */ \
  86. "pmulhw %%xmm4, %%xmm3 \n\t" /* xmm3 = ( c4 -1 ) * ( B - D ) */ \
  87. "paddsw %%xmm2, %%xmm7 \n\t" /* xmm7 = c2 * i2 + c6 * i6 = G */ \
  88. "movdqa %%xmm6, "I(2)" \n\t" /* Save D. at I(2) */ \
  89. "movdqa %%xmm0, %%xmm2 \n\t" /* xmm2 = A - C */ \
  90. "movdqa "I(0)", %%xmm6 \n\t" /* xmm6 = i0 */ \
  91. "pmulhw %%xmm4, %%xmm0 \n\t" /* xmm0 = ( c4 - 1 ) * ( A - C ) = A. */ \
  92. "paddw %%xmm3, %%xmm5 \n\t" /* xmm5 = c4 * ( B - D ) = B. */ \
  93. "movdqa "I(4)", %%xmm3 \n\t" /* xmm3 = i4 */ \
  94. "psubsw %%xmm1, %%xmm5 \n\t" /* xmm5 = B. - H = B.. */ \
  95. "paddw %%xmm0, %%xmm2 \n\t" /* xmm2 = c4 * ( A - C) = A. */ \
  96. "psubsw %%xmm3, %%xmm6 \n\t" /* xmm6 = i0 - i4 */ \
  97. "movdqa %%xmm6, %%xmm0 \n\t" /* xmm0 = i0 - i4 */ \
  98. "pmulhw %%xmm4, %%xmm6 \n\t" /* xmm6 = (c4 - 1) * (i0 - i4) = F */ \
  99. "paddsw %%xmm3, %%xmm3 \n\t" /* xmm3 = i4 + i4 */ \
  100. "paddsw %%xmm1, %%xmm1 \n\t" /* xmm1 = H + H */ \
  101. "paddsw %%xmm0, %%xmm3 \n\t" /* xmm3 = i0 + i4 */ \
  102. "paddsw %%xmm5, %%xmm1 \n\t" /* xmm1 = B. + H = H. */ \
  103. "pmulhw %%xmm3, %%xmm4 \n\t" /* xmm4 = ( c4 - 1 ) * ( i0 + i4 ) */ \
  104. "paddw %%xmm0, %%xmm6 \n\t" /* xmm6 = c4 * ( i0 - i4 ) */ \
  105. "psubsw %%xmm2, %%xmm6 \n\t" /* xmm6 = F - A. = F. */ \
  106. "paddsw %%xmm2, %%xmm2 \n\t" /* xmm2 = A. + A. */ \
  107. "movdqa "I(1)", %%xmm0 \n\t" /* Load C. from I(1) */ \
  108. "paddsw %%xmm6, %%xmm2 \n\t" /* xmm2 = F + A. = A.. */ \
  109. "paddw %%xmm3, %%xmm4 \n\t" /* xmm4 = c4 * ( i0 + i4 ) = 3 */ \
  110. "psubsw %%xmm1, %%xmm2 \n\t" /* xmm2 = A.. - H. = R2 */ \
  111. ADD(%%xmm2) /* Adjust R2 and R1 before shifting */ \
  112. "paddsw %%xmm1, %%xmm1 \n\t" /* xmm1 = H. + H. */ \
  113. "paddsw %%xmm2, %%xmm1 \n\t" /* xmm1 = A.. + H. = R1 */ \
  114. SHIFT(%%xmm2) /* xmm2 = op2 */ \
  115. "psubsw %%xmm7, %%xmm4 \n\t" /* xmm4 = E - G = E. */ \
  116. SHIFT(%%xmm1) /* xmm1 = op1 */ \
  117. "movdqa "I(2)", %%xmm3 \n\t" /* Load D. from I(2) */ \
  118. "paddsw %%xmm7, %%xmm7 \n\t" /* xmm7 = G + G */ \
  119. "paddsw %%xmm4, %%xmm7 \n\t" /* xmm7 = E + G = G. */ \
  120. "psubsw %%xmm3, %%xmm4 \n\t" /* xmm4 = E. - D. = R4 */ \
  121. ADD(%%xmm4) /* Adjust R4 and R3 before shifting */ \
  122. "paddsw %%xmm3, %%xmm3 \n\t" /* xmm3 = D. + D. */ \
  123. "paddsw %%xmm4, %%xmm3 \n\t" /* xmm3 = E. + D. = R3 */ \
  124. SHIFT(%%xmm4) /* xmm4 = op4 */ \
  125. "psubsw %%xmm5, %%xmm6 \n\t" /* xmm6 = F. - B..= R6 */ \
  126. SHIFT(%%xmm3) /* xmm3 = op3 */ \
  127. ADD(%%xmm6) /* Adjust R6 and R5 before shifting */ \
  128. "paddsw %%xmm5, %%xmm5 \n\t" /* xmm5 = B.. + B.. */ \
  129. "paddsw %%xmm6, %%xmm5 \n\t" /* xmm5 = F. + B.. = R5 */ \
  130. SHIFT(%%xmm6) /* xmm6 = op6 */ \
  131. SHIFT(%%xmm5) /* xmm5 = op5 */ \
  132. "psubsw %%xmm0, %%xmm7 \n\t" /* xmm7 = G. - C. = R7 */ \
  133. ADD(%%xmm7) /* Adjust R7 and R0 before shifting */ \
  134. "paddsw %%xmm0, %%xmm0 \n\t" /* xmm0 = C. + C. */ \
  135. "paddsw %%xmm7, %%xmm0 \n\t" /* xmm0 = G. + C. */ \
  136. SHIFT(%%xmm7) /* xmm7 = op7 */ \
  137. SHIFT(%%xmm0) /* xmm0 = op0 */
  138. #define PUT_BLOCK(r0, r1, r2, r3, r4, r5, r6, r7) \
  139. "movdqa " #r0 ", " O(0) "\n\t" \
  140. "movdqa " #r1 ", " O(1) "\n\t" \
  141. "movdqa " #r2 ", " O(2) "\n\t" \
  142. "movdqa " #r3 ", " O(3) "\n\t" \
  143. "movdqa " #r4 ", " O(4) "\n\t" \
  144. "movdqa " #r5 ", " O(5) "\n\t" \
  145. "movdqa " #r6 ", " O(6) "\n\t" \
  146. "movdqa " #r7 ", " O(7) "\n\t"
  147. #define NOP(xmm)
  148. #define SHIFT4(xmm) "psraw $4, "#xmm"\n\t"
  149. #define ADD8(xmm) "paddsw %2, "#xmm"\n\t"
  150. void ff_vp3_idct_sse2(int16_t *input_data)
  151. {
  152. #define I(x) AV_STRINGIFY(16*x)"(%0)"
  153. #define O(x) I(x)
  154. #define C(x) AV_STRINGIFY(16*(x-1))"(%1)"
  155. __asm__ volatile (
  156. VP3_1D_IDCT_SSE2(NOP, NOP)
  157. TRANSPOSE8(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm6, %%xmm7, (%0))
  158. PUT_BLOCK(%%xmm0, %%xmm5, %%xmm7, %%xmm3, %%xmm6, %%xmm4, %%xmm2, %%xmm1)
  159. VP3_1D_IDCT_SSE2(ADD8, SHIFT4)
  160. PUT_BLOCK(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm6, %%xmm7)
  161. :: "r"(input_data), "r"(ff_vp3_idct_data), "m"(ff_pw_8)
  162. );
  163. }
  164. void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block)
  165. {
  166. ff_vp3_idct_sse2(block);
  167. put_signed_pixels_clamped_mmx(block, dest, line_size);
  168. }
  169. void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block)
  170. {
  171. ff_vp3_idct_sse2(block);
  172. add_pixels_clamped_mmx(block, dest, line_size);
  173. }