dump_modes_arm_ne10.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Copyright (c) 2015 Xiph.Org Foundation
  2. Written by Viswanath Puttagunta */
  3. /*
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. - Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  16. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #if defined(HAVE_CONFIG_H)
  25. # include "config.h"
  26. #endif
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include "modes.h"
  30. #include "dump_modes_arch.h"
  31. #include <NE10_dsp.h>
  32. #if !defined(FIXED_POINT)
  33. # define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_float32_t
  34. # define NE10_FFT_CPX_TYPE_T_STR "ne10_fft_cpx_float32_t"
  35. # define NE10_FFT_STATE_TYPE_T_STR "ne10_fft_state_float32_t"
  36. #else
  37. # define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_int32_t
  38. # define NE10_FFT_CPX_TYPE_T_STR "ne10_fft_cpx_int32_t"
  39. # define NE10_FFT_STATE_TYPE_T_STR "ne10_fft_state_int32_t"
  40. #endif
  41. static FILE *file;
  42. void dump_modes_arch_init(CELTMode **modes, int nb_modes)
  43. {
  44. int i;
  45. file = fopen(ARM_NE10_ARCH_FILE_NAME, "w");
  46. fprintf(file, "/* The contents of this file was automatically generated by\n");
  47. fprintf(file, " * dump_mode_arm_ne10.c with arguments:");
  48. for (i=0;i<nb_modes;i++)
  49. {
  50. CELTMode *mode = modes[i];
  51. fprintf(file, " %d %d",mode->Fs,mode->shortMdctSize*mode->nbShortMdcts);
  52. }
  53. fprintf(file, "\n * It contains static definitions for some pre-defined modes. */\n");
  54. fprintf(file, "#include <NE10_types.h>\n\n");
  55. }
  56. void dump_modes_arch_finalize()
  57. {
  58. fclose(file);
  59. }
  60. void dump_mode_arch(CELTMode *mode)
  61. {
  62. int k, j;
  63. int mdctSize;
  64. mdctSize = mode->shortMdctSize*mode->nbShortMdcts;
  65. fprintf(file, "#ifndef NE10_FFT_PARAMS%d_%d\n", mode->Fs, mdctSize);
  66. fprintf(file, "#define NE10_FFT_PARAMS%d_%d\n", mode->Fs, mdctSize);
  67. /* cfg->factors */
  68. for(k=0;k<=mode->mdct.maxshift;k++) {
  69. NE10_FFT_CFG_TYPE_T cfg;
  70. cfg = (NE10_FFT_CFG_TYPE_T)mode->mdct.kfft[k]->arch_fft->priv;
  71. if (!cfg)
  72. continue;
  73. fprintf(file, "static const ne10_int32_t ne10_factors_%d[%d] = {\n",
  74. mode->mdct.kfft[k]->nfft, (NE10_MAXFACTORS * 2));
  75. for(j=0;j<(NE10_MAXFACTORS * 2);j++) {
  76. fprintf(file, "%d,%c", cfg->factors[j],(j+16)%15==0?'\n':' ');
  77. }
  78. fprintf (file, "};\n");
  79. }
  80. /* cfg->twiddles */
  81. for(k=0;k<=mode->mdct.maxshift;k++) {
  82. NE10_FFT_CFG_TYPE_T cfg;
  83. cfg = (NE10_FFT_CFG_TYPE_T)mode->mdct.kfft[k]->arch_fft->priv;
  84. if (!cfg)
  85. continue;
  86. fprintf(file, "static const %s ne10_twiddles_%d[%d] = {\n",
  87. NE10_FFT_CPX_TYPE_T_STR, mode->mdct.kfft[k]->nfft,
  88. mode->mdct.kfft[k]->nfft);
  89. for(j=0;j<mode->mdct.kfft[k]->nfft;j++) {
  90. #if !defined(FIXED_POINT)
  91. fprintf(file, "{%#0.8gf,%#0.8gf},%c",
  92. cfg->twiddles[j].r, cfg->twiddles[j].i,(j+4)%3==0?'\n':' ');
  93. #else
  94. fprintf(file, "{%d,%d},%c",
  95. cfg->twiddles[j].r, cfg->twiddles[j].i,(j+4)%3==0?'\n':' ');
  96. #endif
  97. }
  98. fprintf (file, "};\n");
  99. }
  100. for(k=0;k<=mode->mdct.maxshift;k++) {
  101. NE10_FFT_CFG_TYPE_T cfg;
  102. cfg = (NE10_FFT_CFG_TYPE_T)mode->mdct.kfft[k]->arch_fft->priv;
  103. if (!cfg) {
  104. fprintf(file, "/* Ne10 does not support scaled FFT for length = %d */\n",
  105. mode->mdct.kfft[k]->nfft);
  106. fprintf(file, "static const arch_fft_state cfg_arch_%d = {\n", mode->mdct.kfft[k]->nfft);
  107. fprintf(file, "0,\n");
  108. fprintf(file, "NULL\n");
  109. fprintf(file, "};\n");
  110. continue;
  111. }
  112. fprintf(file, "static const %s %s_%d = {\n", NE10_FFT_STATE_TYPE_T_STR,
  113. NE10_FFT_STATE_TYPE_T_STR, mode->mdct.kfft[k]->nfft);
  114. fprintf(file, "%d,\n", cfg->nfft);
  115. fprintf(file, "(ne10_int32_t *)ne10_factors_%d,\n", mode->mdct.kfft[k]->nfft);
  116. fprintf(file, "(%s *)ne10_twiddles_%d,\n",
  117. NE10_FFT_CPX_TYPE_T_STR, mode->mdct.kfft[k]->nfft);
  118. fprintf(file, "NULL,\n"); /* buffer */
  119. fprintf(file, "(%s *)&ne10_twiddles_%d[%d],\n",
  120. NE10_FFT_CPX_TYPE_T_STR, mode->mdct.kfft[k]->nfft, cfg->nfft);
  121. #if !defined(FIXED_POINT)
  122. fprintf(file, "/* is_forward_scaled = true */\n");
  123. fprintf(file, "(ne10_int32_t) 1,\n");
  124. fprintf(file, "/* is_backward_scaled = false */\n");
  125. fprintf(file, "(ne10_int32_t) 0,\n");
  126. #endif
  127. fprintf(file, "};\n");
  128. fprintf(file, "static const arch_fft_state cfg_arch_%d = {\n",
  129. mode->mdct.kfft[k]->nfft);
  130. fprintf(file, "1,\n");
  131. fprintf(file, "(void *)&%s_%d,\n",
  132. NE10_FFT_STATE_TYPE_T_STR, mode->mdct.kfft[k]->nfft);
  133. fprintf(file, "};\n\n");
  134. }
  135. fprintf(file, "#endif /* end NE10_FFT_PARAMS%d_%d */\n", mode->Fs, mdctSize);
  136. }