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.

158 lines
5.0KB

  1. /*
  2. * MMX optimized MP3 decoding functions
  3. * Copyright (c) 2010 Vitor Sessak
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/cpu.h"
  22. #include "libavutil/x86_cpu.h"
  23. #include "libavcodec/dsputil.h"
  24. #include "libavcodec/mpegaudiodsp.h"
  25. #define MACS(rt, ra, rb) rt+=(ra)*(rb)
  26. #define MLSS(rt, ra, rb) rt-=(ra)*(rb)
  27. #define SUM8(op, sum, w, p) \
  28. { \
  29. op(sum, (w)[0 * 64], (p)[0 * 64]); \
  30. op(sum, (w)[1 * 64], (p)[1 * 64]); \
  31. op(sum, (w)[2 * 64], (p)[2 * 64]); \
  32. op(sum, (w)[3 * 64], (p)[3 * 64]); \
  33. op(sum, (w)[4 * 64], (p)[4 * 64]); \
  34. op(sum, (w)[5 * 64], (p)[5 * 64]); \
  35. op(sum, (w)[6 * 64], (p)[6 * 64]); \
  36. op(sum, (w)[7 * 64], (p)[7 * 64]); \
  37. }
  38. static void apply_window(const float *buf, const float *win1,
  39. const float *win2, float *sum1, float *sum2, int len)
  40. {
  41. x86_reg count = - 4*len;
  42. const float *win1a = win1+len;
  43. const float *win2a = win2+len;
  44. const float *bufa = buf+len;
  45. float *sum1a = sum1+len;
  46. float *sum2a = sum2+len;
  47. #define MULT(a, b) \
  48. "movaps " #a "(%1,%0), %%xmm1 \n\t" \
  49. "movaps " #a "(%3,%0), %%xmm2 \n\t" \
  50. "mulps %%xmm2, %%xmm1 \n\t" \
  51. "subps %%xmm1, %%xmm0 \n\t" \
  52. "mulps " #b "(%2,%0), %%xmm2 \n\t" \
  53. "subps %%xmm2, %%xmm4 \n\t" \
  54. __asm__ volatile(
  55. "1: \n\t"
  56. "xorps %%xmm0, %%xmm0 \n\t"
  57. "xorps %%xmm4, %%xmm4 \n\t"
  58. MULT( 0, 0)
  59. MULT( 256, 64)
  60. MULT( 512, 128)
  61. MULT( 768, 192)
  62. MULT(1024, 256)
  63. MULT(1280, 320)
  64. MULT(1536, 384)
  65. MULT(1792, 448)
  66. "movaps %%xmm0, (%4,%0) \n\t"
  67. "movaps %%xmm4, (%5,%0) \n\t"
  68. "add $16, %0 \n\t"
  69. "jl 1b \n\t"
  70. :"+&r"(count)
  71. :"r"(win1a), "r"(win2a), "r"(bufa), "r"(sum1a), "r"(sum2a)
  72. );
  73. #undef MULT
  74. }
  75. static void apply_window_mp3(float *in, float *win, int *unused, float *out,
  76. int incr)
  77. {
  78. LOCAL_ALIGNED_16(float, suma, [17]);
  79. LOCAL_ALIGNED_16(float, sumb, [17]);
  80. LOCAL_ALIGNED_16(float, sumc, [17]);
  81. LOCAL_ALIGNED_16(float, sumd, [17]);
  82. float sum;
  83. /* copy to avoid wrap */
  84. memcpy(in + 512, in, 32 * sizeof(*in));
  85. apply_window(in + 16, win , win + 512, suma, sumc, 16);
  86. apply_window(in + 32, win + 48, win + 640, sumb, sumd, 16);
  87. SUM8(MACS, suma[0], win + 32, in + 48);
  88. sumc[ 0] = 0;
  89. sumb[16] = 0;
  90. sumd[16] = 0;
  91. #define SUMS(suma, sumb, sumc, sumd, out1, out2) \
  92. "movups " #sumd "(%4), %%xmm0 \n\t" \
  93. "shufps $0x1b, %%xmm0, %%xmm0 \n\t" \
  94. "subps " #suma "(%1), %%xmm0 \n\t" \
  95. "movaps %%xmm0," #out1 "(%0) \n\t" \
  96. \
  97. "movups " #sumc "(%3), %%xmm0 \n\t" \
  98. "shufps $0x1b, %%xmm0, %%xmm0 \n\t" \
  99. "addps " #sumb "(%2), %%xmm0 \n\t" \
  100. "movaps %%xmm0," #out2 "(%0) \n\t"
  101. if (incr == 1) {
  102. __asm__ volatile(
  103. SUMS( 0, 48, 4, 52, 0, 112)
  104. SUMS(16, 32, 20, 36, 16, 96)
  105. SUMS(32, 16, 36, 20, 32, 80)
  106. SUMS(48, 0, 52, 4, 48, 64)
  107. :"+&r"(out)
  108. :"r"(&suma[0]), "r"(&sumb[0]), "r"(&sumc[0]), "r"(&sumd[0])
  109. :"memory"
  110. );
  111. out += 16*incr;
  112. } else {
  113. int j;
  114. float *out2 = out + 32 * incr;
  115. out[0 ] = -suma[ 0];
  116. out += incr;
  117. out2 -= incr;
  118. for(j=1;j<16;j++) {
  119. *out = -suma[ j] + sumd[16-j];
  120. *out2 = sumb[16-j] + sumc[ j];
  121. out += incr;
  122. out2 -= incr;
  123. }
  124. }
  125. sum = 0;
  126. SUM8(MLSS, sum, win + 16 + 32, in + 32);
  127. *out = sum;
  128. }
  129. void ff_mpadsp_init_mmx(MPADSPContext *s)
  130. {
  131. int mm_flags = av_get_cpu_flags();
  132. if (mm_flags & AV_CPU_FLAG_SSE2) {
  133. s->apply_window_float = apply_window_mp3;
  134. }
  135. }