celt_ne10_fft.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* Copyright (c) 2015 Xiph.Org Foundation
  2. Written by Viswanath Puttagunta */
  3. /**
  4. @file celt_ne10_fft.c
  5. @brief ARM Neon optimizations for fft using NE10 library
  6. */
  7. /*
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions
  10. are met:
  11. - Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. - Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  20. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  24. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  25. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #ifndef SKIP_CONFIG_H
  29. #ifdef HAVE_CONFIG_H
  30. #include "config.h"
  31. #endif
  32. #endif
  33. #include <NE10_init.h>
  34. #include <NE10_dsp.h>
  35. #include "os_support.h"
  36. #include "kiss_fft.h"
  37. #include "stack_alloc.h"
  38. #if !defined(FIXED_POINT)
  39. # define NE10_FFT_ALLOC_C2C_TYPE_NEON ne10_fft_alloc_c2c_float32_neon
  40. # define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_float32_t
  41. # define NE10_FFT_STATE_TYPE_T ne10_fft_state_float32_t
  42. # define NE10_FFT_DESTROY_C2C_TYPE ne10_fft_destroy_c2c_float32
  43. # define NE10_FFT_CPX_TYPE_T ne10_fft_cpx_float32_t
  44. # define NE10_FFT_C2C_1D_TYPE_NEON ne10_fft_c2c_1d_float32_neon
  45. #else
  46. # define NE10_FFT_ALLOC_C2C_TYPE_NEON(nfft) ne10_fft_alloc_c2c_int32_neon(nfft)
  47. # define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_int32_t
  48. # define NE10_FFT_STATE_TYPE_T ne10_fft_state_int32_t
  49. # define NE10_FFT_DESTROY_C2C_TYPE ne10_fft_destroy_c2c_int32
  50. # define NE10_FFT_DESTROY_C2C_TYPE ne10_fft_destroy_c2c_int32
  51. # define NE10_FFT_CPX_TYPE_T ne10_fft_cpx_int32_t
  52. # define NE10_FFT_C2C_1D_TYPE_NEON ne10_fft_c2c_1d_int32_neon
  53. #endif
  54. #if defined(CUSTOM_MODES)
  55. /* nfft lengths in NE10 that support scaled fft */
  56. # define NE10_FFTSCALED_SUPPORT_MAX 4
  57. static const int ne10_fft_scaled_support[NE10_FFTSCALED_SUPPORT_MAX] = {
  58. 480, 240, 120, 60
  59. };
  60. int opus_fft_alloc_arm_neon(kiss_fft_state *st)
  61. {
  62. int i;
  63. size_t memneeded = sizeof(struct arch_fft_state);
  64. st->arch_fft = (arch_fft_state *)opus_alloc(memneeded);
  65. if (!st->arch_fft)
  66. return -1;
  67. for (i = 0; i < NE10_FFTSCALED_SUPPORT_MAX; i++) {
  68. if(st->nfft == ne10_fft_scaled_support[i])
  69. break;
  70. }
  71. if (i == NE10_FFTSCALED_SUPPORT_MAX) {
  72. /* This nfft length (scaled fft) is not supported in NE10 */
  73. st->arch_fft->is_supported = 0;
  74. st->arch_fft->priv = NULL;
  75. }
  76. else {
  77. st->arch_fft->is_supported = 1;
  78. st->arch_fft->priv = (void *)NE10_FFT_ALLOC_C2C_TYPE_NEON(st->nfft);
  79. if (st->arch_fft->priv == NULL) {
  80. return -1;
  81. }
  82. }
  83. return 0;
  84. }
  85. void opus_fft_free_arm_neon(kiss_fft_state *st)
  86. {
  87. NE10_FFT_CFG_TYPE_T cfg;
  88. if (!st->arch_fft)
  89. return;
  90. cfg = (NE10_FFT_CFG_TYPE_T)st->arch_fft->priv;
  91. if (cfg)
  92. NE10_FFT_DESTROY_C2C_TYPE(cfg);
  93. opus_free(st->arch_fft);
  94. }
  95. #endif
  96. void opus_fft_neon(const kiss_fft_state *st,
  97. const kiss_fft_cpx *fin,
  98. kiss_fft_cpx *fout)
  99. {
  100. NE10_FFT_STATE_TYPE_T state;
  101. NE10_FFT_CFG_TYPE_T cfg = &state;
  102. VARDECL(NE10_FFT_CPX_TYPE_T, buffer);
  103. SAVE_STACK;
  104. ALLOC(buffer, st->nfft, NE10_FFT_CPX_TYPE_T);
  105. if (!st->arch_fft->is_supported) {
  106. /* This nfft length (scaled fft) not supported in NE10 */
  107. opus_fft_c(st, fin, fout);
  108. }
  109. else {
  110. memcpy((void *)cfg, st->arch_fft->priv, sizeof(NE10_FFT_STATE_TYPE_T));
  111. state.buffer = (NE10_FFT_CPX_TYPE_T *)&buffer[0];
  112. #if !defined(FIXED_POINT)
  113. state.is_forward_scaled = 1;
  114. NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout,
  115. (NE10_FFT_CPX_TYPE_T *)fin,
  116. cfg, 0);
  117. #else
  118. NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout,
  119. (NE10_FFT_CPX_TYPE_T *)fin,
  120. cfg, 0, 1);
  121. #endif
  122. }
  123. RESTORE_STACK;
  124. }
  125. void opus_ifft_neon(const kiss_fft_state *st,
  126. const kiss_fft_cpx *fin,
  127. kiss_fft_cpx *fout)
  128. {
  129. NE10_FFT_STATE_TYPE_T state;
  130. NE10_FFT_CFG_TYPE_T cfg = &state;
  131. VARDECL(NE10_FFT_CPX_TYPE_T, buffer);
  132. SAVE_STACK;
  133. ALLOC(buffer, st->nfft, NE10_FFT_CPX_TYPE_T);
  134. if (!st->arch_fft->is_supported) {
  135. /* This nfft length (scaled fft) not supported in NE10 */
  136. opus_ifft_c(st, fin, fout);
  137. }
  138. else {
  139. memcpy((void *)cfg, st->arch_fft->priv, sizeof(NE10_FFT_STATE_TYPE_T));
  140. state.buffer = (NE10_FFT_CPX_TYPE_T *)&buffer[0];
  141. #if !defined(FIXED_POINT)
  142. state.is_backward_scaled = 0;
  143. NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout,
  144. (NE10_FFT_CPX_TYPE_T *)fin,
  145. cfg, 1);
  146. #else
  147. NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout,
  148. (NE10_FFT_CPX_TYPE_T *)fin,
  149. cfg, 1, 0);
  150. #endif
  151. }
  152. RESTORE_STACK;
  153. }