10a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim/* Copyright (c) 2015 Xiph.Org Foundation 20a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim Written by Viswanath Puttagunta */ 30a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim/* 40a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim Redistribution and use in source and binary forms, with or without 50a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim modification, are permitted provided that the following conditions 60a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim are met: 70a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 80a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim - Redistributions of source code must retain the above copyright 90a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim notice, this list of conditions and the following disclaimer. 100a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 110a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim - Redistributions in binary form must reproduce the above copyright 120a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim notice, this list of conditions and the following disclaimer in the 130a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim documentation and/or other materials provided with the distribution. 140a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 150a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 160a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 170a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 180a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 190a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 200a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 210a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 220a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 230a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 240a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 250a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 260a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim*/ 270a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 280a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#if defined(HAVE_CONFIG_H) 290a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim# include "config.h" 300a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#endif 310a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 320a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#include <stdio.h> 330a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#include <stdlib.h> 340a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#include "modes.h" 350a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#include "dump_modes_arch.h" 360a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#include <NE10_dsp.h> 370a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 380a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#if !defined(FIXED_POINT) 390a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim# define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_float32_t 400a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim# define NE10_FFT_CPX_TYPE_T_STR "ne10_fft_cpx_float32_t" 410a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim# define NE10_FFT_STATE_TYPE_T_STR "ne10_fft_state_float32_t" 420a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#else 430a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim# define NE10_FFT_CFG_TYPE_T ne10_fft_cfg_int32_t 440a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim# define NE10_FFT_CPX_TYPE_T_STR "ne10_fft_cpx_int32_t" 450a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim# define NE10_FFT_STATE_TYPE_T_STR "ne10_fft_state_int32_t" 460a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#endif 470a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 480a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Limstatic FILE *file; 490a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 500a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Limvoid dump_modes_arch_init(CELTMode **modes, int nb_modes) 510a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim{ 520a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim int i; 530a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 540a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim file = fopen(ARM_NE10_ARCH_FILE_NAME, "w"); 550a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "/* The contents of this file was automatically generated by\n"); 560a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, " * dump_mode_arm_ne10.c with arguments:"); 570a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim for (i=0;i<nb_modes;i++) 580a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim { 590a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim CELTMode *mode = modes[i]; 600a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, " %d %d",mode->Fs,mode->shortMdctSize*mode->nbShortMdcts); 610a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim } 620a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "\n * It contains static definitions for some pre-defined modes. */\n"); 630c2090c324e4f2ba2a8621c8b083559bab74c7c5Felicia Lim fprintf(file, "#include <NE10_types.h>\n\n"); 640a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim} 650a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 660a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Limvoid dump_modes_arch_finalize() 670a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim{ 680a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fclose(file); 690a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim} 700a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 710a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Limvoid dump_mode_arch(CELTMode *mode) 720a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim{ 730a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim int k, j; 740a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim int mdctSize; 750a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 760a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim mdctSize = mode->shortMdctSize*mode->nbShortMdcts; 770a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 780a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "#ifndef NE10_FFT_PARAMS%d_%d\n", mode->Fs, mdctSize); 790a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "#define NE10_FFT_PARAMS%d_%d\n", mode->Fs, mdctSize); 800a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim /* cfg->factors */ 810a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim for(k=0;k<=mode->mdct.maxshift;k++) { 820a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim NE10_FFT_CFG_TYPE_T cfg; 830a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim cfg = (NE10_FFT_CFG_TYPE_T)mode->mdct.kfft[k]->arch_fft->priv; 840a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim if (!cfg) 850a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim continue; 860a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "static const ne10_int32_t ne10_factors_%d[%d] = {\n", 870a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim mode->mdct.kfft[k]->nfft, (NE10_MAXFACTORS * 2)); 880a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim for(j=0;j<(NE10_MAXFACTORS * 2);j++) { 890a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "%d,%c", cfg->factors[j],(j+16)%15==0?'\n':' '); 900a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim } 910a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf (file, "};\n"); 920a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim } 930a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 940a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim /* cfg->twiddles */ 950a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim for(k=0;k<=mode->mdct.maxshift;k++) { 960a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim NE10_FFT_CFG_TYPE_T cfg; 970a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim cfg = (NE10_FFT_CFG_TYPE_T)mode->mdct.kfft[k]->arch_fft->priv; 980a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim if (!cfg) 990a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim continue; 1000a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "static const %s ne10_twiddles_%d[%d] = {\n", 1010a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim NE10_FFT_CPX_TYPE_T_STR, mode->mdct.kfft[k]->nfft, 1020a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim mode->mdct.kfft[k]->nfft); 1030a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim for(j=0;j<mode->mdct.kfft[k]->nfft;j++) { 1040a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#if !defined(FIXED_POINT) 1050a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "{%#0.8gf,%#0.8gf},%c", 1060a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim cfg->twiddles[j].r, cfg->twiddles[j].i,(j+4)%3==0?'\n':' '); 1070a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#else 1080a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "{%d,%d},%c", 1090a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim cfg->twiddles[j].r, cfg->twiddles[j].i,(j+4)%3==0?'\n':' '); 1100a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#endif 1110a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim } 1120a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf (file, "};\n"); 1130a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim } 1140a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 1150a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim for(k=0;k<=mode->mdct.maxshift;k++) { 1160a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim NE10_FFT_CFG_TYPE_T cfg; 1170a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim cfg = (NE10_FFT_CFG_TYPE_T)mode->mdct.kfft[k]->arch_fft->priv; 1180a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim if (!cfg) { 1190a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "/* Ne10 does not support scaled FFT for length = %d */\n", 1200a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim mode->mdct.kfft[k]->nfft); 1210a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "static const arch_fft_state cfg_arch_%d = {\n", mode->mdct.kfft[k]->nfft); 1220a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "0,\n"); 1230a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "NULL\n"); 1240a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "};\n"); 1250a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim continue; 1260a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim } 1270a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "static const %s %s_%d = {\n", NE10_FFT_STATE_TYPE_T_STR, 1280a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim NE10_FFT_STATE_TYPE_T_STR, mode->mdct.kfft[k]->nfft); 1290a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "%d,\n", cfg->nfft); 1300a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "(ne10_int32_t *)ne10_factors_%d,\n", mode->mdct.kfft[k]->nfft); 1310a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "(%s *)ne10_twiddles_%d,\n", 1320a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim NE10_FFT_CPX_TYPE_T_STR, mode->mdct.kfft[k]->nfft); 1330a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "NULL,\n"); /* buffer */ 1340a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "(%s *)&ne10_twiddles_%d[%d],\n", 1350a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim NE10_FFT_CPX_TYPE_T_STR, mode->mdct.kfft[k]->nfft, cfg->nfft); 1360a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#if !defined(FIXED_POINT) 1370a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "/* is_forward_scaled = true */\n"); 1380a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "(ne10_int32_t) 1,\n"); 1390a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "/* is_backward_scaled = false */\n"); 1400a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "(ne10_int32_t) 0,\n"); 1410a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim#endif 1420a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "};\n"); 1430a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim 1440a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "static const arch_fft_state cfg_arch_%d = {\n", 1450a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim mode->mdct.kfft[k]->nfft); 1460a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "1,\n"); 1470a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "(void *)&%s_%d,\n", 1480a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim NE10_FFT_STATE_TYPE_T_STR, mode->mdct.kfft[k]->nfft); 1490a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "};\n\n"); 1500a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim } 1510a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim fprintf(file, "#endif /* end NE10_FFT_PARAMS%d_%d */\n", mode->Fs, mdctSize); 1520a1406acbe87c63044e9da7e0ab41bcbfa704f3dFelicia Lim} 153