celt_fft_ne10.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* Copyright (c) 2015 Xiph.Org Foundation
  2. Written by Viswanath Puttagunta */
  3. /**
  4. @file celt_fft_ne10.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_dsp.h>
  34. #include "os_support.h"
  35. #include "kiss_fft.h"
  36. #include "stack_alloc.h"
  37. #if !defined(FIXED_POINT)
  38. # define NE10_FFT_ALLOC_C2C_TYPE_NEON ne10_fft_alloc_c2c_float32_neon
  39. # define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_float32_t
  40. # define NE10_FFT_STATE_TYPE_T ne10_fft_state_float32_t
  41. # define NE10_FFT_DESTROY_C2C_TYPE ne10_fft_destroy_c2c_float32
  42. # define NE10_FFT_CPX_TYPE_T ne10_fft_cpx_float32_t
  43. # define NE10_FFT_C2C_1D_TYPE_NEON ne10_fft_c2c_1d_float32_neon
  44. #else
  45. # define NE10_FFT_ALLOC_C2C_TYPE_NEON(nfft) ne10_fft_alloc_c2c_int32_neon(nfft)
  46. # define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_int32_t
  47. # define NE10_FFT_STATE_TYPE_T ne10_fft_state_int32_t
  48. # define NE10_FFT_DESTROY_C2C_TYPE ne10_fft_destroy_c2c_int32
  49. # define NE10_FFT_DESTROY_C2C_TYPE ne10_fft_destroy_c2c_int32
  50. # define NE10_FFT_CPX_TYPE_T ne10_fft_cpx_int32_t
  51. # define NE10_FFT_C2C_1D_TYPE_NEON ne10_fft_c2c_1d_int32_neon
  52. #endif
  53. #if defined(CUSTOM_MODES)
  54. /* nfft lengths in NE10 that support scaled fft */
  55. # define NE10_FFTSCALED_SUPPORT_MAX 4
  56. static const int ne10_fft_scaled_support[NE10_FFTSCALED_SUPPORT_MAX] = {
  57. 480, 240, 120, 60
  58. };
  59. int opus_fft_alloc_arm_neon(kiss_fft_state *st)
  60. {
  61. int i;
  62. size_t memneeded = sizeof(struct arch_fft_state);
  63. st->arch_fft = (arch_fft_state *)opus_alloc(memneeded);
  64. if (!st->arch_fft)
  65. return -1;
  66. for (i = 0; i < NE10_FFTSCALED_SUPPORT_MAX; i++) {
  67. if(st->nfft == ne10_fft_scaled_support[i])
  68. break;
  69. }
  70. if (i == NE10_FFTSCALED_SUPPORT_MAX) {
  71. /* This nfft length (scaled fft) is not supported in NE10 */
  72. st->arch_fft->is_supported = 0;
  73. st->arch_fft->priv = NULL;
  74. }
  75. else {
  76. st->arch_fft->is_supported = 1;
  77. st->arch_fft->priv = (void *)NE10_FFT_ALLOC_C2C_TYPE_NEON(st->nfft);
  78. if (st->arch_fft->priv == NULL) {
  79. return -1;
  80. }
  81. }
  82. return 0;
  83. }
  84. void opus_fft_free_arm_neon(kiss_fft_state *st)
  85. {
  86. NE10_FFT_CFG_TYPE_T cfg;
  87. if (!st->arch_fft)
  88. return;
  89. cfg = (NE10_FFT_CFG_TYPE_T)st->arch_fft->priv;
  90. if (cfg)
  91. NE10_FFT_DESTROY_C2C_TYPE(cfg);
  92. opus_free(st->arch_fft);
  93. }
  94. #endif
  95. void opus_fft_neon(const kiss_fft_state *st,
  96. const kiss_fft_cpx *fin,
  97. kiss_fft_cpx *fout)
  98. {
  99. NE10_FFT_STATE_TYPE_T state;
  100. NE10_FFT_CFG_TYPE_T cfg = &state;
  101. VARDECL(NE10_FFT_CPX_TYPE_T, buffer);
  102. SAVE_STACK;
  103. ALLOC(buffer, st->nfft, NE10_FFT_CPX_TYPE_T);
  104. if (!st->arch_fft->is_supported) {
  105. /* This nfft length (scaled fft) not supported in NE10 */
  106. opus_fft_c(st, fin, fout);
  107. }
  108. else {
  109. memcpy((void *)cfg, st->arch_fft->priv, sizeof(NE10_FFT_STATE_TYPE_T));
  110. state.buffer = (NE10_FFT_CPX_TYPE_T *)&buffer[0];
  111. #if !defined(FIXED_POINT)
  112. state.is_forward_scaled = 1;
  113. NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout,
  114. (NE10_FFT_CPX_TYPE_T *)fin,
  115. cfg, 0);
  116. #else
  117. NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout,
  118. (NE10_FFT_CPX_TYPE_T *)fin,
  119. cfg, 0, 1);
  120. #endif
  121. }
  122. RESTORE_STACK;
  123. }
  124. void opus_ifft_neon(const kiss_fft_state *st,
  125. const kiss_fft_cpx *fin,
  126. kiss_fft_cpx *fout)
  127. {
  128. NE10_FFT_STATE_TYPE_T state;
  129. NE10_FFT_CFG_TYPE_T cfg = &state;
  130. VARDECL(NE10_FFT_CPX_TYPE_T, buffer);
  131. SAVE_STACK;
  132. ALLOC(buffer, st->nfft, NE10_FFT_CPX_TYPE_T);
  133. if (!st->arch_fft->is_supported) {
  134. /* This nfft length (scaled fft) not supported in NE10 */
  135. opus_ifft_c(st, fin, fout);
  136. }
  137. else {
  138. memcpy((void *)cfg, st->arch_fft->priv, sizeof(NE10_FFT_STATE_TYPE_T));
  139. state.buffer = (NE10_FFT_CPX_TYPE_T *)&buffer[0];
  140. #if !defined(FIXED_POINT)
  141. state.is_backward_scaled = 0;
  142. NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout,
  143. (NE10_FFT_CPX_TYPE_T *)fin,
  144. cfg, 1);
  145. #else
  146. NE10_FFT_C2C_1D_TYPE_NEON((NE10_FFT_CPX_TYPE_T *)fout,
  147. (NE10_FFT_CPX_TYPE_T *)fin,
  148. cfg, 1, 0);
  149. #endif
  150. }
  151. RESTORE_STACK;
  152. }