annotate src/opus-1.3/celt/arm/celt_mdct_ne10.c @ 81:7029a4916348

Merge build update
author Chris Cannam
date Thu, 31 Oct 2019 13:36:58 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 /* Copyright (c) 2015 Xiph.Org Foundation
Chris@69 2 Written by Viswanath Puttagunta */
Chris@69 3 /**
Chris@69 4 @file celt_mdct_ne10.c
Chris@69 5 @brief ARM Neon optimizations for mdct using NE10 library
Chris@69 6 */
Chris@69 7
Chris@69 8 /*
Chris@69 9 Redistribution and use in source and binary forms, with or without
Chris@69 10 modification, are permitted provided that the following conditions
Chris@69 11 are met:
Chris@69 12
Chris@69 13 - Redistributions of source code must retain the above copyright
Chris@69 14 notice, this list of conditions and the following disclaimer.
Chris@69 15
Chris@69 16 - Redistributions in binary form must reproduce the above copyright
Chris@69 17 notice, this list of conditions and the following disclaimer in the
Chris@69 18 documentation and/or other materials provided with the distribution.
Chris@69 19
Chris@69 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@69 21 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@69 22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@69 23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
Chris@69 24 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Chris@69 25 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Chris@69 26 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Chris@69 27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Chris@69 28 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Chris@69 29 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Chris@69 30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@69 31 */
Chris@69 32
Chris@69 33 #ifndef SKIP_CONFIG_H
Chris@69 34 #ifdef HAVE_CONFIG_H
Chris@69 35 #include "config.h"
Chris@69 36 #endif
Chris@69 37 #endif
Chris@69 38
Chris@69 39 #include "kiss_fft.h"
Chris@69 40 #include "_kiss_fft_guts.h"
Chris@69 41 #include "mdct.h"
Chris@69 42 #include "stack_alloc.h"
Chris@69 43
Chris@69 44 void clt_mdct_forward_neon(const mdct_lookup *l,
Chris@69 45 kiss_fft_scalar *in,
Chris@69 46 kiss_fft_scalar * OPUS_RESTRICT out,
Chris@69 47 const opus_val16 *window,
Chris@69 48 int overlap, int shift, int stride, int arch)
Chris@69 49 {
Chris@69 50 int i;
Chris@69 51 int N, N2, N4;
Chris@69 52 VARDECL(kiss_fft_scalar, f);
Chris@69 53 VARDECL(kiss_fft_cpx, f2);
Chris@69 54 const kiss_fft_state *st = l->kfft[shift];
Chris@69 55 const kiss_twiddle_scalar *trig;
Chris@69 56
Chris@69 57 SAVE_STACK;
Chris@69 58
Chris@69 59 N = l->n;
Chris@69 60 trig = l->trig;
Chris@69 61 for (i=0;i<shift;i++)
Chris@69 62 {
Chris@69 63 N >>= 1;
Chris@69 64 trig += N;
Chris@69 65 }
Chris@69 66 N2 = N>>1;
Chris@69 67 N4 = N>>2;
Chris@69 68
Chris@69 69 ALLOC(f, N2, kiss_fft_scalar);
Chris@69 70 ALLOC(f2, N4, kiss_fft_cpx);
Chris@69 71
Chris@69 72 /* Consider the input to be composed of four blocks: [a, b, c, d] */
Chris@69 73 /* Window, shuffle, fold */
Chris@69 74 {
Chris@69 75 /* Temp pointers to make it really clear to the compiler what we're doing */
Chris@69 76 const kiss_fft_scalar * OPUS_RESTRICT xp1 = in+(overlap>>1);
Chris@69 77 const kiss_fft_scalar * OPUS_RESTRICT xp2 = in+N2-1+(overlap>>1);
Chris@69 78 kiss_fft_scalar * OPUS_RESTRICT yp = f;
Chris@69 79 const opus_val16 * OPUS_RESTRICT wp1 = window+(overlap>>1);
Chris@69 80 const opus_val16 * OPUS_RESTRICT wp2 = window+(overlap>>1)-1;
Chris@69 81 for(i=0;i<((overlap+3)>>2);i++)
Chris@69 82 {
Chris@69 83 /* Real part arranged as -d-cR, Imag part arranged as -b+aR*/
Chris@69 84 *yp++ = MULT16_32_Q15(*wp2, xp1[N2]) + MULT16_32_Q15(*wp1,*xp2);
Chris@69 85 *yp++ = MULT16_32_Q15(*wp1, *xp1) - MULT16_32_Q15(*wp2, xp2[-N2]);
Chris@69 86 xp1+=2;
Chris@69 87 xp2-=2;
Chris@69 88 wp1+=2;
Chris@69 89 wp2-=2;
Chris@69 90 }
Chris@69 91 wp1 = window;
Chris@69 92 wp2 = window+overlap-1;
Chris@69 93 for(;i<N4-((overlap+3)>>2);i++)
Chris@69 94 {
Chris@69 95 /* Real part arranged as a-bR, Imag part arranged as -c-dR */
Chris@69 96 *yp++ = *xp2;
Chris@69 97 *yp++ = *xp1;
Chris@69 98 xp1+=2;
Chris@69 99 xp2-=2;
Chris@69 100 }
Chris@69 101 for(;i<N4;i++)
Chris@69 102 {
Chris@69 103 /* Real part arranged as a-bR, Imag part arranged as -c-dR */
Chris@69 104 *yp++ = -MULT16_32_Q15(*wp1, xp1[-N2]) + MULT16_32_Q15(*wp2, *xp2);
Chris@69 105 *yp++ = MULT16_32_Q15(*wp2, *xp1) + MULT16_32_Q15(*wp1, xp2[N2]);
Chris@69 106 xp1+=2;
Chris@69 107 xp2-=2;
Chris@69 108 wp1+=2;
Chris@69 109 wp2-=2;
Chris@69 110 }
Chris@69 111 }
Chris@69 112 /* Pre-rotation */
Chris@69 113 {
Chris@69 114 kiss_fft_scalar * OPUS_RESTRICT yp = f;
Chris@69 115 const kiss_twiddle_scalar *t = &trig[0];
Chris@69 116 for(i=0;i<N4;i++)
Chris@69 117 {
Chris@69 118 kiss_fft_cpx yc;
Chris@69 119 kiss_twiddle_scalar t0, t1;
Chris@69 120 kiss_fft_scalar re, im, yr, yi;
Chris@69 121 t0 = t[i];
Chris@69 122 t1 = t[N4+i];
Chris@69 123 re = *yp++;
Chris@69 124 im = *yp++;
Chris@69 125 yr = S_MUL(re,t0) - S_MUL(im,t1);
Chris@69 126 yi = S_MUL(im,t0) + S_MUL(re,t1);
Chris@69 127 yc.r = yr;
Chris@69 128 yc.i = yi;
Chris@69 129 f2[i] = yc;
Chris@69 130 }
Chris@69 131 }
Chris@69 132
Chris@69 133 opus_fft(st, f2, (kiss_fft_cpx *)f, arch);
Chris@69 134
Chris@69 135 /* Post-rotate */
Chris@69 136 {
Chris@69 137 /* Temp pointers to make it really clear to the compiler what we're doing */
Chris@69 138 const kiss_fft_cpx * OPUS_RESTRICT fp = (kiss_fft_cpx *)f;
Chris@69 139 kiss_fft_scalar * OPUS_RESTRICT yp1 = out;
Chris@69 140 kiss_fft_scalar * OPUS_RESTRICT yp2 = out+stride*(N2-1);
Chris@69 141 const kiss_twiddle_scalar *t = &trig[0];
Chris@69 142 /* Temp pointers to make it really clear to the compiler what we're doing */
Chris@69 143 for(i=0;i<N4;i++)
Chris@69 144 {
Chris@69 145 kiss_fft_scalar yr, yi;
Chris@69 146 yr = S_MUL(fp->i,t[N4+i]) - S_MUL(fp->r,t[i]);
Chris@69 147 yi = S_MUL(fp->r,t[N4+i]) + S_MUL(fp->i,t[i]);
Chris@69 148 *yp1 = yr;
Chris@69 149 *yp2 = yi;
Chris@69 150 fp++;
Chris@69 151 yp1 += 2*stride;
Chris@69 152 yp2 -= 2*stride;
Chris@69 153 }
Chris@69 154 }
Chris@69 155 RESTORE_STACK;
Chris@69 156 }
Chris@69 157
Chris@69 158 void clt_mdct_backward_neon(const mdct_lookup *l,
Chris@69 159 kiss_fft_scalar *in,
Chris@69 160 kiss_fft_scalar * OPUS_RESTRICT out,
Chris@69 161 const opus_val16 * OPUS_RESTRICT window,
Chris@69 162 int overlap, int shift, int stride, int arch)
Chris@69 163 {
Chris@69 164 int i;
Chris@69 165 int N, N2, N4;
Chris@69 166 VARDECL(kiss_fft_scalar, f);
Chris@69 167 const kiss_twiddle_scalar *trig;
Chris@69 168 const kiss_fft_state *st = l->kfft[shift];
Chris@69 169
Chris@69 170 N = l->n;
Chris@69 171 trig = l->trig;
Chris@69 172 for (i=0;i<shift;i++)
Chris@69 173 {
Chris@69 174 N >>= 1;
Chris@69 175 trig += N;
Chris@69 176 }
Chris@69 177 N2 = N>>1;
Chris@69 178 N4 = N>>2;
Chris@69 179
Chris@69 180 ALLOC(f, N2, kiss_fft_scalar);
Chris@69 181
Chris@69 182 /* Pre-rotate */
Chris@69 183 {
Chris@69 184 /* Temp pointers to make it really clear to the compiler what we're doing */
Chris@69 185 const kiss_fft_scalar * OPUS_RESTRICT xp1 = in;
Chris@69 186 const kiss_fft_scalar * OPUS_RESTRICT xp2 = in+stride*(N2-1);
Chris@69 187 kiss_fft_scalar * OPUS_RESTRICT yp = f;
Chris@69 188 const kiss_twiddle_scalar * OPUS_RESTRICT t = &trig[0];
Chris@69 189 for(i=0;i<N4;i++)
Chris@69 190 {
Chris@69 191 kiss_fft_scalar yr, yi;
Chris@69 192 yr = S_MUL(*xp2, t[i]) + S_MUL(*xp1, t[N4+i]);
Chris@69 193 yi = S_MUL(*xp1, t[i]) - S_MUL(*xp2, t[N4+i]);
Chris@69 194 yp[2*i] = yr;
Chris@69 195 yp[2*i+1] = yi;
Chris@69 196 xp1+=2*stride;
Chris@69 197 xp2-=2*stride;
Chris@69 198 }
Chris@69 199 }
Chris@69 200
Chris@69 201 opus_ifft(st, (kiss_fft_cpx *)f, (kiss_fft_cpx*)(out+(overlap>>1)), arch);
Chris@69 202
Chris@69 203 /* Post-rotate and de-shuffle from both ends of the buffer at once to make
Chris@69 204 it in-place. */
Chris@69 205 {
Chris@69 206 kiss_fft_scalar * yp0 = out+(overlap>>1);
Chris@69 207 kiss_fft_scalar * yp1 = out+(overlap>>1)+N2-2;
Chris@69 208 const kiss_twiddle_scalar *t = &trig[0];
Chris@69 209 /* Loop to (N4+1)>>1 to handle odd N4. When N4 is odd, the
Chris@69 210 middle pair will be computed twice. */
Chris@69 211 for(i=0;i<(N4+1)>>1;i++)
Chris@69 212 {
Chris@69 213 kiss_fft_scalar re, im, yr, yi;
Chris@69 214 kiss_twiddle_scalar t0, t1;
Chris@69 215 re = yp0[0];
Chris@69 216 im = yp0[1];
Chris@69 217 t0 = t[i];
Chris@69 218 t1 = t[N4+i];
Chris@69 219 /* We'd scale up by 2 here, but instead it's done when mixing the windows */
Chris@69 220 yr = S_MUL(re,t0) + S_MUL(im,t1);
Chris@69 221 yi = S_MUL(re,t1) - S_MUL(im,t0);
Chris@69 222 re = yp1[0];
Chris@69 223 im = yp1[1];
Chris@69 224 yp0[0] = yr;
Chris@69 225 yp1[1] = yi;
Chris@69 226
Chris@69 227 t0 = t[(N4-i-1)];
Chris@69 228 t1 = t[(N2-i-1)];
Chris@69 229 /* We'd scale up by 2 here, but instead it's done when mixing the windows */
Chris@69 230 yr = S_MUL(re,t0) + S_MUL(im,t1);
Chris@69 231 yi = S_MUL(re,t1) - S_MUL(im,t0);
Chris@69 232 yp1[0] = yr;
Chris@69 233 yp0[1] = yi;
Chris@69 234 yp0 += 2;
Chris@69 235 yp1 -= 2;
Chris@69 236 }
Chris@69 237 }
Chris@69 238
Chris@69 239 /* Mirror on both sides for TDAC */
Chris@69 240 {
Chris@69 241 kiss_fft_scalar * OPUS_RESTRICT xp1 = out+overlap-1;
Chris@69 242 kiss_fft_scalar * OPUS_RESTRICT yp1 = out;
Chris@69 243 const opus_val16 * OPUS_RESTRICT wp1 = window;
Chris@69 244 const opus_val16 * OPUS_RESTRICT wp2 = window+overlap-1;
Chris@69 245
Chris@69 246 for(i = 0; i < overlap/2; i++)
Chris@69 247 {
Chris@69 248 kiss_fft_scalar x1, x2;
Chris@69 249 x1 = *xp1;
Chris@69 250 x2 = *yp1;
Chris@69 251 *yp1++ = MULT16_32_Q15(*wp2, x2) - MULT16_32_Q15(*wp1, x1);
Chris@69 252 *xp1-- = MULT16_32_Q15(*wp1, x2) + MULT16_32_Q15(*wp2, x1);
Chris@69 253 wp1++;
Chris@69 254 wp2--;
Chris@69 255 }
Chris@69 256 }
Chris@69 257 RESTORE_STACK;
Chris@69 258 }