Chris@69: /* Copyright (c) 2015 Xiph.Org Foundation Chris@69: Written by Viswanath Puttagunta */ Chris@69: /** Chris@69: @file celt_mdct_ne10.c Chris@69: @brief ARM Neon optimizations for mdct using NE10 library Chris@69: */ Chris@69: Chris@69: /* Chris@69: Redistribution and use in source and binary forms, with or without Chris@69: modification, are permitted provided that the following conditions Chris@69: are met: Chris@69: Chris@69: - Redistributions of source code must retain the above copyright Chris@69: notice, this list of conditions and the following disclaimer. Chris@69: Chris@69: - Redistributions in binary form must reproduce the above copyright Chris@69: notice, this list of conditions and the following disclaimer in the Chris@69: documentation and/or other materials provided with the distribution. Chris@69: Chris@69: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@69: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT Chris@69: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR Chris@69: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER Chris@69: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@69: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@69: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR Chris@69: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF Chris@69: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING Chris@69: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS Chris@69: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@69: */ Chris@69: Chris@69: #ifndef SKIP_CONFIG_H Chris@69: #ifdef HAVE_CONFIG_H Chris@69: #include "config.h" Chris@69: #endif Chris@69: #endif Chris@69: Chris@69: #include "kiss_fft.h" Chris@69: #include "_kiss_fft_guts.h" Chris@69: #include "mdct.h" Chris@69: #include "stack_alloc.h" Chris@69: Chris@69: void clt_mdct_forward_neon(const mdct_lookup *l, Chris@69: kiss_fft_scalar *in, Chris@69: kiss_fft_scalar * OPUS_RESTRICT out, Chris@69: const opus_val16 *window, Chris@69: int overlap, int shift, int stride, int arch) Chris@69: { Chris@69: int i; Chris@69: int N, N2, N4; Chris@69: VARDECL(kiss_fft_scalar, f); Chris@69: VARDECL(kiss_fft_cpx, f2); Chris@69: const kiss_fft_state *st = l->kfft[shift]; Chris@69: const kiss_twiddle_scalar *trig; Chris@69: Chris@69: SAVE_STACK; Chris@69: Chris@69: N = l->n; Chris@69: trig = l->trig; Chris@69: for (i=0;i>= 1; Chris@69: trig += N; Chris@69: } Chris@69: N2 = N>>1; Chris@69: N4 = N>>2; Chris@69: Chris@69: ALLOC(f, N2, kiss_fft_scalar); Chris@69: ALLOC(f2, N4, kiss_fft_cpx); Chris@69: Chris@69: /* Consider the input to be composed of four blocks: [a, b, c, d] */ Chris@69: /* Window, shuffle, fold */ Chris@69: { Chris@69: /* Temp pointers to make it really clear to the compiler what we're doing */ Chris@69: const kiss_fft_scalar * OPUS_RESTRICT xp1 = in+(overlap>>1); Chris@69: const kiss_fft_scalar * OPUS_RESTRICT xp2 = in+N2-1+(overlap>>1); Chris@69: kiss_fft_scalar * OPUS_RESTRICT yp = f; Chris@69: const opus_val16 * OPUS_RESTRICT wp1 = window+(overlap>>1); Chris@69: const opus_val16 * OPUS_RESTRICT wp2 = window+(overlap>>1)-1; Chris@69: for(i=0;i<((overlap+3)>>2);i++) Chris@69: { Chris@69: /* Real part arranged as -d-cR, Imag part arranged as -b+aR*/ Chris@69: *yp++ = MULT16_32_Q15(*wp2, xp1[N2]) + MULT16_32_Q15(*wp1,*xp2); Chris@69: *yp++ = MULT16_32_Q15(*wp1, *xp1) - MULT16_32_Q15(*wp2, xp2[-N2]); Chris@69: xp1+=2; Chris@69: xp2-=2; Chris@69: wp1+=2; Chris@69: wp2-=2; Chris@69: } Chris@69: wp1 = window; Chris@69: wp2 = window+overlap-1; Chris@69: for(;i>2);i++) Chris@69: { Chris@69: /* Real part arranged as a-bR, Imag part arranged as -c-dR */ Chris@69: *yp++ = *xp2; Chris@69: *yp++ = *xp1; Chris@69: xp1+=2; Chris@69: xp2-=2; Chris@69: } Chris@69: for(;ii,t[N4+i]) - S_MUL(fp->r,t[i]); Chris@69: yi = S_MUL(fp->r,t[N4+i]) + S_MUL(fp->i,t[i]); Chris@69: *yp1 = yr; Chris@69: *yp2 = yi; Chris@69: fp++; Chris@69: yp1 += 2*stride; Chris@69: yp2 -= 2*stride; Chris@69: } Chris@69: } Chris@69: RESTORE_STACK; Chris@69: } Chris@69: Chris@69: void clt_mdct_backward_neon(const mdct_lookup *l, Chris@69: kiss_fft_scalar *in, Chris@69: kiss_fft_scalar * OPUS_RESTRICT out, Chris@69: const opus_val16 * OPUS_RESTRICT window, Chris@69: int overlap, int shift, int stride, int arch) Chris@69: { Chris@69: int i; Chris@69: int N, N2, N4; Chris@69: VARDECL(kiss_fft_scalar, f); Chris@69: const kiss_twiddle_scalar *trig; Chris@69: const kiss_fft_state *st = l->kfft[shift]; Chris@69: Chris@69: N = l->n; Chris@69: trig = l->trig; Chris@69: for (i=0;i>= 1; Chris@69: trig += N; Chris@69: } Chris@69: N2 = N>>1; Chris@69: N4 = N>>2; Chris@69: Chris@69: ALLOC(f, N2, kiss_fft_scalar); Chris@69: Chris@69: /* Pre-rotate */ Chris@69: { Chris@69: /* Temp pointers to make it really clear to the compiler what we're doing */ Chris@69: const kiss_fft_scalar * OPUS_RESTRICT xp1 = in; Chris@69: const kiss_fft_scalar * OPUS_RESTRICT xp2 = in+stride*(N2-1); Chris@69: kiss_fft_scalar * OPUS_RESTRICT yp = f; Chris@69: const kiss_twiddle_scalar * OPUS_RESTRICT t = &trig[0]; Chris@69: for(i=0;i>1)), arch); Chris@69: Chris@69: /* Post-rotate and de-shuffle from both ends of the buffer at once to make Chris@69: it in-place. */ Chris@69: { Chris@69: kiss_fft_scalar * yp0 = out+(overlap>>1); Chris@69: kiss_fft_scalar * yp1 = out+(overlap>>1)+N2-2; Chris@69: const kiss_twiddle_scalar *t = &trig[0]; Chris@69: /* Loop to (N4+1)>>1 to handle odd N4. When N4 is odd, the Chris@69: middle pair will be computed twice. */ Chris@69: for(i=0;i<(N4+1)>>1;i++) Chris@69: { Chris@69: kiss_fft_scalar re, im, yr, yi; Chris@69: kiss_twiddle_scalar t0, t1; Chris@69: re = yp0[0]; Chris@69: im = yp0[1]; Chris@69: t0 = t[i]; Chris@69: t1 = t[N4+i]; Chris@69: /* We'd scale up by 2 here, but instead it's done when mixing the windows */ Chris@69: yr = S_MUL(re,t0) + S_MUL(im,t1); Chris@69: yi = S_MUL(re,t1) - S_MUL(im,t0); Chris@69: re = yp1[0]; Chris@69: im = yp1[1]; Chris@69: yp0[0] = yr; Chris@69: yp1[1] = yi; Chris@69: Chris@69: t0 = t[(N4-i-1)]; Chris@69: t1 = t[(N2-i-1)]; Chris@69: /* We'd scale up by 2 here, but instead it's done when mixing the windows */ Chris@69: yr = S_MUL(re,t0) + S_MUL(im,t1); Chris@69: yi = S_MUL(re,t1) - S_MUL(im,t0); Chris@69: yp1[0] = yr; Chris@69: yp0[1] = yi; Chris@69: yp0 += 2; Chris@69: yp1 -= 2; Chris@69: } Chris@69: } Chris@69: Chris@69: /* Mirror on both sides for TDAC */ Chris@69: { Chris@69: kiss_fft_scalar * OPUS_RESTRICT xp1 = out+overlap-1; Chris@69: kiss_fft_scalar * OPUS_RESTRICT yp1 = out; Chris@69: const opus_val16 * OPUS_RESTRICT wp1 = window; Chris@69: const opus_val16 * OPUS_RESTRICT wp2 = window+overlap-1; Chris@69: Chris@69: for(i = 0; i < overlap/2; i++) Chris@69: { Chris@69: kiss_fft_scalar x1, x2; Chris@69: x1 = *xp1; Chris@69: x2 = *yp1; Chris@69: *yp1++ = MULT16_32_Q15(*wp2, x2) - MULT16_32_Q15(*wp1, x1); Chris@69: *xp1-- = MULT16_32_Q15(*wp1, x2) + MULT16_32_Q15(*wp2, x1); Chris@69: wp1++; Chris@69: wp2--; Chris@69: } Chris@69: } Chris@69: RESTORE_STACK; Chris@69: }