Chris@69: /* Copyright (c) 2015 Xiph.Org Foundation Chris@69: Written by Viswanath Puttagunta */ Chris@69: /** Chris@69: @file celt_fft_ne10.c Chris@69: @brief ARM Neon optimizations for fft 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 Chris@69: #include "os_support.h" Chris@69: #include "kiss_fft.h" Chris@69: #include "stack_alloc.h" Chris@69: Chris@69: #if !defined(FIXED_POINT) Chris@69: # define NE10_FFT_ALLOC_C2C_TYPE_NEON ne10_fft_alloc_c2c_float32_neon Chris@69: # define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_float32_t Chris@69: # define NE10_FFT_STATE_TYPE_T ne10_fft_state_float32_t Chris@69: # define NE10_FFT_DESTROY_C2C_TYPE ne10_fft_destroy_c2c_float32 Chris@69: # define NE10_FFT_CPX_TYPE_T ne10_fft_cpx_float32_t Chris@69: # define NE10_FFT_C2C_1D_TYPE_NEON ne10_fft_c2c_1d_float32_neon Chris@69: #else Chris@69: # define NE10_FFT_ALLOC_C2C_TYPE_NEON(nfft) ne10_fft_alloc_c2c_int32_neon(nfft) Chris@69: # define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_int32_t Chris@69: # define NE10_FFT_STATE_TYPE_T ne10_fft_state_int32_t Chris@69: # define NE10_FFT_DESTROY_C2C_TYPE ne10_fft_destroy_c2c_int32 Chris@69: # define NE10_FFT_DESTROY_C2C_TYPE ne10_fft_destroy_c2c_int32 Chris@69: # define NE10_FFT_CPX_TYPE_T ne10_fft_cpx_int32_t Chris@69: # define NE10_FFT_C2C_1D_TYPE_NEON ne10_fft_c2c_1d_int32_neon Chris@69: #endif Chris@69: Chris@69: #if defined(CUSTOM_MODES) Chris@69: Chris@69: /* nfft lengths in NE10 that support scaled fft */ Chris@69: # define NE10_FFTSCALED_SUPPORT_MAX 4 Chris@69: static const int ne10_fft_scaled_support[NE10_FFTSCALED_SUPPORT_MAX] = { Chris@69: 480, 240, 120, 60 Chris@69: }; Chris@69: Chris@69: int opus_fft_alloc_arm_neon(kiss_fft_state *st) Chris@69: { Chris@69: int i; Chris@69: size_t memneeded = sizeof(struct arch_fft_state); Chris@69: Chris@69: st->arch_fft = (arch_fft_state *)opus_alloc(memneeded); Chris@69: if (!st->arch_fft) Chris@69: return -1; Chris@69: Chris@69: for (i = 0; i < NE10_FFTSCALED_SUPPORT_MAX; i++) { Chris@69: if(st->nfft == ne10_fft_scaled_support[i]) Chris@69: break; Chris@69: } Chris@69: if (i == NE10_FFTSCALED_SUPPORT_MAX) { Chris@69: /* This nfft length (scaled fft) is not supported in NE10 */ Chris@69: st->arch_fft->is_supported = 0; Chris@69: st->arch_fft->priv = NULL; Chris@69: } Chris@69: else { Chris@69: st->arch_fft->is_supported = 1; Chris@69: st->arch_fft->priv = (void *)NE10_FFT_ALLOC_C2C_TYPE_NEON(st->nfft); Chris@69: if (st->arch_fft->priv == NULL) { Chris@69: return -1; Chris@69: } Chris@69: } Chris@69: return 0; Chris@69: } Chris@69: Chris@69: void opus_fft_free_arm_neon(kiss_fft_state *st) Chris@69: { Chris@69: NE10_FFT_CFG_TYPE_T cfg; Chris@69: Chris@69: if (!st->arch_fft) Chris@69: return; Chris@69: Chris@69: cfg = (NE10_FFT_CFG_TYPE_T)st->arch_fft->priv; Chris@69: if (cfg) Chris@69: NE10_FFT_DESTROY_C2C_TYPE(cfg); Chris@69: opus_free(st->arch_fft); Chris@69: } Chris@69: #endif Chris@69: Chris@69: void opus_fft_neon(const kiss_fft_state *st, Chris@69: const kiss_fft_cpx *fin, Chris@69: kiss_fft_cpx *fout) Chris@69: { Chris@69: NE10_FFT_STATE_TYPE_T state; Chris@69: NE10_FFT_CFG_TYPE_T cfg = &state; Chris@69: VARDECL(NE10_FFT_CPX_TYPE_T, buffer); Chris@69: SAVE_STACK; Chris@69: ALLOC(buffer, st->nfft, NE10_FFT_CPX_TYPE_T); Chris@69: Chris@69: if (!st->arch_fft->is_supported) { Chris@69: /* This nfft length (scaled fft) not supported in NE10 */ Chris@69: opus_fft_c(st, fin, fout); Chris@69: } Chris@69: else { Chris@69: memcpy((void *)cfg, st->arch_fft->priv, sizeof(NE10_FFT_STATE_TYPE_T)); Chris@69: state.buffer = (NE10_FFT_CPX_TYPE_T *)&buffer[0]; Chris@69: #if !defined(FIXED_POINT) Chris@69: state.is_forward_scaled = 1; Chris@69: Chris@69: NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout, Chris@69: (NE10_FFT_CPX_TYPE_T *)fin, Chris@69: cfg, 0); Chris@69: #else Chris@69: NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout, Chris@69: (NE10_FFT_CPX_TYPE_T *)fin, Chris@69: cfg, 0, 1); Chris@69: #endif Chris@69: } Chris@69: RESTORE_STACK; Chris@69: } Chris@69: Chris@69: void opus_ifft_neon(const kiss_fft_state *st, Chris@69: const kiss_fft_cpx *fin, Chris@69: kiss_fft_cpx *fout) Chris@69: { Chris@69: NE10_FFT_STATE_TYPE_T state; Chris@69: NE10_FFT_CFG_TYPE_T cfg = &state; Chris@69: VARDECL(NE10_FFT_CPX_TYPE_T, buffer); Chris@69: SAVE_STACK; Chris@69: ALLOC(buffer, st->nfft, NE10_FFT_CPX_TYPE_T); Chris@69: Chris@69: if (!st->arch_fft->is_supported) { Chris@69: /* This nfft length (scaled fft) not supported in NE10 */ Chris@69: opus_ifft_c(st, fin, fout); Chris@69: } Chris@69: else { Chris@69: memcpy((void *)cfg, st->arch_fft->priv, sizeof(NE10_FFT_STATE_TYPE_T)); Chris@69: state.buffer = (NE10_FFT_CPX_TYPE_T *)&buffer[0]; Chris@69: #if !defined(FIXED_POINT) Chris@69: state.is_backward_scaled = 0; Chris@69: Chris@69: NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout, Chris@69: (NE10_FFT_CPX_TYPE_T *)fin, Chris@69: cfg, 1); Chris@69: #else Chris@69: NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout, Chris@69: (NE10_FFT_CPX_TYPE_T *)fin, Chris@69: cfg, 1, 0); Chris@69: #endif Chris@69: } Chris@69: RESTORE_STACK; Chris@69: }