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.

141 lines
3.9KB

  1. /*
  2. * Altivec optimized MP3 decoding functions
  3. * Copyright (c) 2010 Vitor Sessak
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "config.h"
  22. #include "libavutil/attributes.h"
  23. #include "libavutil/cpu.h"
  24. #include "libavutil/internal.h"
  25. #include "libavutil/ppc/util_altivec.h"
  26. #include "libavcodec/mpegaudiodsp.h"
  27. #if HAVE_ALTIVEC
  28. #define MACS(rt, ra, rb) rt+=(ra)*(rb)
  29. #define MLSS(rt, ra, rb) rt-=(ra)*(rb)
  30. #define SUM8(op, sum, w, p) \
  31. { \
  32. op(sum, (w)[0 * 64], (p)[0 * 64]); \
  33. op(sum, (w)[1 * 64], (p)[1 * 64]); \
  34. op(sum, (w)[2 * 64], (p)[2 * 64]); \
  35. op(sum, (w)[3 * 64], (p)[3 * 64]); \
  36. op(sum, (w)[4 * 64], (p)[4 * 64]); \
  37. op(sum, (w)[5 * 64], (p)[5 * 64]); \
  38. op(sum, (w)[6 * 64], (p)[6 * 64]); \
  39. op(sum, (w)[7 * 64], (p)[7 * 64]); \
  40. }
  41. static void apply_window(const float *buf, const float *win1,
  42. const float *win2, float *sum1, float *sum2, int len)
  43. {
  44. const vector float *win1a = (const vector float *) win1;
  45. const vector float *win2a = (const vector float *) win2;
  46. const vector float *bufa = (const vector float *) buf;
  47. vector float *sum1a = (vector float *) sum1;
  48. vector float *sum2a = (vector float *) sum2;
  49. vector float av_uninit(v0), av_uninit(v4);
  50. vector float v1, v2, v3;
  51. len = len >> 2;
  52. #define MULT(a, b) \
  53. { \
  54. v1 = vec_ld(a, win1a); \
  55. v2 = vec_ld(b, win2a); \
  56. v3 = vec_ld(a, bufa); \
  57. v0 = vec_madd(v3, v1, v0); \
  58. v4 = vec_madd(v2, v3, v4); \
  59. }
  60. while (len--) {
  61. v0 = vec_xor(v0, v0);
  62. v4 = vec_xor(v4, v4);
  63. MULT( 0, 0);
  64. MULT( 256, 64);
  65. MULT( 512, 128);
  66. MULT( 768, 192);
  67. MULT(1024, 256);
  68. MULT(1280, 320);
  69. MULT(1536, 384);
  70. MULT(1792, 448);
  71. vec_st(v0, 0, sum1a);
  72. vec_st(v4, 0, sum2a);
  73. sum1a++;
  74. sum2a++;
  75. win1a++;
  76. win2a++;
  77. bufa++;
  78. }
  79. }
  80. static void apply_window_mp3(float *in, float *win, int *unused, float *out,
  81. int incr)
  82. {
  83. LOCAL_ALIGNED_16(float, suma, [17]);
  84. LOCAL_ALIGNED_16(float, sumb, [17]);
  85. LOCAL_ALIGNED_16(float, sumc, [17]);
  86. LOCAL_ALIGNED_16(float, sumd, [17]);
  87. float sum;
  88. int j;
  89. float *out2 = out + 32 * incr;
  90. /* copy to avoid wrap */
  91. memcpy(in + 512, in, 32 * sizeof(*in));
  92. apply_window(in + 16, win , win + 512, suma, sumc, 16);
  93. apply_window(in + 32, win + 48, win + 640, sumb, sumd, 16);
  94. SUM8(MLSS, suma[0], win + 32, in + 48);
  95. sumc[ 0] = 0;
  96. sumb[16] = 0;
  97. sumd[16] = 0;
  98. out[0 ] = suma[ 0];
  99. out += incr;
  100. out2 -= incr;
  101. for(j=1;j<16;j++) {
  102. *out = suma[ j] - sumd[16-j];
  103. *out2 = -sumb[16-j] - sumc[ j];
  104. out += incr;
  105. out2 -= incr;
  106. }
  107. sum = 0;
  108. SUM8(MLSS, sum, win + 16 + 32, in + 32);
  109. *out = sum;
  110. }
  111. #endif /* HAVE_ALTIVEC */
  112. av_cold void ff_mpadsp_init_ppc(MPADSPContext *s)
  113. {
  114. #if HAVE_ALTIVEC
  115. if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
  116. return;
  117. s->apply_window_float = apply_window_mp3;
  118. #endif /* HAVE_ALTIVEC */
  119. }