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.

105 lines
3.4KB

  1. /*
  2. * SIMD optimized non-power-of-two MDCT functions
  3. *
  4. * Copyright (C) 2017 Rostislav Pehlivanov <atomnuker@gmail.com>
  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. #include "config.h"
  23. #include "libavutil/x86/cpu.h"
  24. #include "libavcodec/mdct15.h"
  25. void ff_mdct15_postreindex_sse3(FFTComplex *out, FFTComplex *in, FFTComplex *exp, int *lut, ptrdiff_t len8);
  26. void ff_mdct15_postreindex_avx2(FFTComplex *out, FFTComplex *in, FFTComplex *exp, int *lut, ptrdiff_t len8);
  27. void ff_fft15_avx(FFTComplex *out, FFTComplex *in, FFTComplex *exptab, ptrdiff_t stride);
  28. static void perm_twiddles(MDCT15Context *s)
  29. {
  30. int k;
  31. FFTComplex exp_5point[4];
  32. FFTComplex tmp[21], tmp2[30];
  33. memcpy(tmp, s->exptab, sizeof(FFTComplex)*21);
  34. /* 15-point FFT twiddles */
  35. for (k = 0; k < 5; k++) {
  36. tmp2[6*k + 0] = tmp[k + 0];
  37. tmp2[6*k + 2] = tmp[k + 5];
  38. tmp2[6*k + 4] = tmp[k + 10];
  39. tmp2[6*k + 1] = tmp[2 * (k + 0)];
  40. tmp2[6*k + 3] = tmp[2 * (k + 5)];
  41. tmp2[6*k + 5] = tmp[2 * k + 5 ];
  42. }
  43. for (k = 0; k < 6; k++) {
  44. FFTComplex ac_exp[] = {
  45. { tmp2[6*1 + k].re, tmp2[6*1 + k].re },
  46. { tmp2[6*2 + k].re, tmp2[6*2 + k].re },
  47. { tmp2[6*3 + k].re, tmp2[6*3 + k].re },
  48. { tmp2[6*4 + k].re, tmp2[6*4 + k].re },
  49. { tmp2[6*1 + k].im, -tmp2[6*1 + k].im },
  50. { tmp2[6*2 + k].im, -tmp2[6*2 + k].im },
  51. { tmp2[6*3 + k].im, -tmp2[6*3 + k].im },
  52. { tmp2[6*4 + k].im, -tmp2[6*4 + k].im },
  53. };
  54. memcpy(s->exptab + 8*k, ac_exp, 8*sizeof(FFTComplex));
  55. }
  56. /* Specialcase when k = 0 */
  57. for (k = 0; k < 3; k++) {
  58. FFTComplex dc_exp[] = {
  59. { tmp2[2*k + 0].re, -tmp2[2*k + 0].im },
  60. { tmp2[2*k + 0].im, tmp2[2*k + 0].re },
  61. { tmp2[2*k + 1].re, -tmp2[2*k + 1].im },
  62. { tmp2[2*k + 1].im, tmp2[2*k + 1].re },
  63. };
  64. memcpy(s->exptab + 8*6 + 4*k, dc_exp, 4*sizeof(FFTComplex));
  65. }
  66. /* 5-point FFT twiddles */
  67. exp_5point[0].re = exp_5point[0].im = tmp[19].re;
  68. exp_5point[1].re = exp_5point[1].im = tmp[19].im;
  69. exp_5point[2].re = exp_5point[2].im = tmp[20].re;
  70. exp_5point[3].re = exp_5point[3].im = tmp[20].im;
  71. memcpy(s->exptab + 8*6 + 4*3, exp_5point, 4*sizeof(FFTComplex));
  72. }
  73. av_cold void ff_mdct15_init_x86(MDCT15Context *s)
  74. {
  75. int adjust_twiddles = 0;
  76. int cpu_flags = av_get_cpu_flags();
  77. if (EXTERNAL_SSE3(cpu_flags))
  78. s->postreindex = ff_mdct15_postreindex_sse3;
  79. if (ARCH_X86_64 && EXTERNAL_AVX(cpu_flags)) {
  80. s->fft15 = ff_fft15_avx;
  81. adjust_twiddles = 1;
  82. }
  83. if (ARCH_X86_64 && EXTERNAL_AVX2_FAST(cpu_flags))
  84. s->postreindex = ff_mdct15_postreindex_avx2;
  85. if (adjust_twiddles)
  86. perm_twiddles(s);
  87. }