From 14d918151bd447d854c3d0b34a9d542a5dff38ff Mon Sep 17 00:00:00 2001 From: Anthony Blake Date: Sat, 6 Sep 2014 01:35:32 -0500 Subject: Add FFTS v0.7 --- lib/ffts/src/ffts.c | 398 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 398 insertions(+) create mode 100644 lib/ffts/src/ffts.c (limited to 'lib/ffts/src/ffts.c') diff --git a/lib/ffts/src/ffts.c b/lib/ffts/src/ffts.c new file mode 100644 index 0000000..bec2177 --- /dev/null +++ b/lib/ffts/src/ffts.c @@ -0,0 +1,398 @@ +/* + + This file is part of FFTS -- The Fastest Fourier Transform in the South + + Copyright (c) 2012, Anthony M. Blake + Copyright (c) 2012, The University of Waikato + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the organization nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL ANTHONY M. BLAKE BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ +#include "ffts.h" +#include "macros.h" +//#include "mini_macros.h" +#include "patterns.h" +#include "ffts_small.h" + +#ifdef DYNAMIC_DISABLED + #include "ffts_static.h" +#else + #include "codegen.h" +#endif + +#include + #include + #include + #include /* for PAGESIZE */ + +#if __APPLE__ + #include +#else +#endif + +void ffts_execute(ffts_plan_t *p, const void * in, void * out) { + p->transform(p, (const float *)in, (float *)out); +} + +void ffts_free(ffts_plan_t *p) { + p->destroy(p); +} + +void ffts_free_1d(ffts_plan_t *p) { + + size_t i; + + if(p->ws) { + FFTS_FREE(p->ws); + } + if(p->is) free(p->is); + if(p->ws_is) free(p->ws_is); + if(p->offsets) free(p->offsets); + //free(p->transforms); + if(p->transforms) free(p->transforms); + + if(p->transform_base) { + if (mprotect(p->transform_base, p->transform_size, PROT_READ | PROT_WRITE)) { + perror("Couldn't mprotect"); + exit(errno); + } + munmap(p->transform_base, p->transform_size); + //free(p->transform_base); + } + free(p); +} + +ffts_plan_t *ffts_init_1d(size_t N, int sign) { + ffts_plan_t *p = malloc(sizeof(ffts_plan_t)); + size_t leafN = 8; + size_t i; + +#ifdef __arm__ +//#ifdef HAVE_NEON + V MULI_SIGN; + + if(sign < 0) MULI_SIGN = VLIT4(-0.0f, 0.0f, -0.0f, 0.0f); + else MULI_SIGN = VLIT4(0.0f, -0.0f, 0.0f, -0.0f); +//#endif +#else + V MULI_SIGN; + + if(sign < 0) MULI_SIGN = VLIT4(-0.0f, 0.0f, -0.0f, 0.0f); + else MULI_SIGN = VLIT4(0.0f, -0.0f, 0.0f, -0.0f); +#endif + + p->transform = NULL; + p->transform_base = NULL; + p->transforms = NULL; + p->is = NULL; + p->ws_is = NULL; + p->ws = NULL; + p->offsets = NULL; + p->destroy = ffts_free_1d; + + if(N >= 32) { + ffts_init_offsets(p, N, leafN); +#ifdef __arm__ +#ifdef HAVE_NEON + ffts_init_is(p, N, leafN, 1); +#else + ffts_init_is(p, N, leafN, 1); +#endif +#else + ffts_init_is(p, N, leafN, 1); +#endif + + p->i0 = N/leafN/3+1; + p->i1 = N/leafN/3; + if((N/leafN) % 3 > 1) p->i1++; + p->i2 = N/leafN/3; + + #ifdef __arm__ + #ifdef HAVE_NEON + p->i0/=2; + p->i1/=2; + #endif + #else + p->i0/=2; + p->i1/=2; + #endif + + }else{ + p->transforms = malloc(2 * sizeof(transform_index_t)); + p->transforms[0] = 0; + p->transforms[1] = 1; + if(N == 2) p->transform = &firstpass_2; + else if(N == 4 && sign == -1) p->transform = &firstpass_4_f; + else if(N == 4 && sign == 1) p->transform = &firstpass_4_b; + else if(N == 8 && sign == -1) p->transform = &firstpass_8_f; + else if(N == 8 && sign == 1) p->transform = &firstpass_8_b; + else if(N == 16 && sign == -1) p->transform = &firstpass_16_f; + else if(N == 16 && sign == 1) p->transform = &firstpass_16_b; + + p->is = NULL; + p->offsets = NULL; + } + + int hardcoded = 0; + + /* LUTS */ + size_t n_luts = __builtin_ctzl(N/leafN); + if(N < 32) { n_luts = __builtin_ctzl(N/4); hardcoded = 1; } + + if(n_luts >= 32) n_luts = 0; + +// fprintf(stderr, "n_luts = %zu\n", n_luts); + + cdata_t *w; + + int n = leafN*2; + if(hardcoded) n = 8; + + size_t lut_size = 0; + + for(i=0;iws = FFTS_MALLOC(lut_size,32); + p->ws_is = malloc(n_luts * sizeof(size_t)); + }else{ + p->ws = NULL; + p->ws_is = NULL; + } + w = p->ws; + + n = leafN*2; + if(hardcoded) n = 8; + + #ifdef HAVE_NEON + V neg = (sign < 0) ? VLIT4(0.0f, 0.0f, 0.0f, 0.0f) : VLIT4(-0.0f, -0.0f, -0.0f, -0.0f); + #endif + + for(i=0;iws_is[i] = w - (cdata_t *)p->ws; + //fprintf(stderr, "LUT[%zu] = %d @ %08x - %zu\n", i, n, w, p->ws_is[i]); + + if(!i || hardcoded) { + cdata_t *w0 = FFTS_MALLOC(n/4 * sizeof(cdata_t), 32); + + size_t j; + for(j=0;j0, im); + #else + im = MULI(sign>0, im); + #endif + VST(fw + j*4 , re); + VST(fw + j*4+4, im); + // #endif + } + w += n/4 * 2; + }else{ + //w = FFTS_MALLOC(n/4 * sizeof(cdata_t), 32); + float *fw = (float *)w; + #ifdef HAVE_NEON + VS temp0, temp1, temp2; + for(j=0;jws[i] = w; + + n *= 2; + } + + float *tmp = (float *)p->ws; + + if(sign < 0) { + p->oe_ws = (void *)(&w_data[4]); + p->ee_ws = (void *)(w_data); + p->eo_ws = (void *)(&w_data[4]); + }else{ + p->oe_ws = (void *)(w_data + 12); + p->ee_ws = (void *)(w_data + 8); + p->eo_ws = (void *)(w_data + 12); + } + + p->N = N; + p->lastlut = w; + p->n_luts = n_luts; +#ifdef DYNAMIC_DISABLED + if(sign < 0) { + if(N >= 32) p->transform = ffts_static_transform_f; + }else{ + if(N >= 32) p->transform = ffts_static_transform_i; + } + +#else + if(N>=32) ffts_generate_func_code(p, N, leafN, sign); +#endif + + return p; +} + -- cgit v1.2.1