shun_iwasawa a35b8f
/* this program is in the public domain 
shun_iwasawa a35b8f
   A program that helps the authors of the fine fftw library benchmark kiss 
shun_iwasawa a35b8f
*/
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#include "bench-user.h"
shun_iwasawa a35b8f
#include <math.h></math.h>
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#include "kiss_fft.h"
shun_iwasawa a35b8f
#include "kiss_fftnd.h"
shun_iwasawa a35b8f
#include "kiss_fftr.h"
shun_iwasawa a35b8f
shun_iwasawa a35b8f
BEGIN_BENCH_DOC
shun_iwasawa a35b8f
BENCH_DOC("name", "kissfft")
shun_iwasawa a35b8f
BENCH_DOC("version", "1.0.1")
shun_iwasawa a35b8f
BENCH_DOC("year", "2004")
shun_iwasawa a35b8f
BENCH_DOC("author", "Mark Borgerding")
shun_iwasawa a35b8f
BENCH_DOC("language", "C")
shun_iwasawa a35b8f
BENCH_DOC("url", "http://sourceforge.net/projects/kissfft/")
shun_iwasawa a35b8f
BENCH_DOC("copyright",
shun_iwasawa a35b8f
"Copyright (c) 2003,4 Mark Borgerding\n"
shun_iwasawa a35b8f
"\n"
shun_iwasawa a35b8f
"All rights reserved.\n"
shun_iwasawa a35b8f
"\n"
shun_iwasawa a35b8f
"Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n"
shun_iwasawa a35b8f
"\n"
shun_iwasawa a35b8f
"    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n"
shun_iwasawa a35b8f
"    * 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.\n"
shun_iwasawa a35b8f
"    * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n"
shun_iwasawa a35b8f
"\n"
shun_iwasawa a35b8f
	  "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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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.\n")
shun_iwasawa a35b8f
END_BENCH_DOC
shun_iwasawa a35b8f
shun_iwasawa a35b8f
int can_do(struct problem *p)
shun_iwasawa a35b8f
{
shun_iwasawa a35b8f
    if (p->rank == 1) {
shun_iwasawa a35b8f
        if (p->kind == PROBLEM_REAL) {
shun_iwasawa a35b8f
            return (p->n[0] & 1) == 0;  /* only even real is okay */
shun_iwasawa a35b8f
        } else {
shun_iwasawa a35b8f
            return 1;
shun_iwasawa a35b8f
        }
shun_iwasawa a35b8f
    } else {
shun_iwasawa a35b8f
        return p->kind == PROBLEM_COMPLEX;
shun_iwasawa a35b8f
    }
shun_iwasawa a35b8f
}
shun_iwasawa a35b8f
shun_iwasawa a35b8f
static kiss_fft_cfg cfg=NULL;
shun_iwasawa a35b8f
static kiss_fftr_cfg cfgr=NULL;
shun_iwasawa a35b8f
static kiss_fftnd_cfg cfgnd=NULL;
shun_iwasawa a35b8f
shun_iwasawa a35b8f
#define FAILIF( c ) \
shun_iwasawa a35b8f
    if (  c ) do {\
shun_iwasawa a35b8f
    fprintf(stderr,\
shun_iwasawa a35b8f
    "kissfft: " #c " (file=%s:%d errno=%d %s)\n",\
shun_iwasawa a35b8f
        __FILE__,__LINE__ , errno,strerror( errno ) ) ;\
shun_iwasawa a35b8f
    exit(1);\
shun_iwasawa a35b8f
    }while(0)
shun_iwasawa a35b8f
shun_iwasawa a35b8f
shun_iwasawa a35b8f
shun_iwasawa a35b8f
void setup(struct problem *p)
shun_iwasawa a35b8f
{
shun_iwasawa a35b8f
    size_t i;
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    /*
shun_iwasawa a35b8f
    fprintf(stderr,"%s %s %d-d ",
shun_iwasawa a35b8f
            (p->sign == 1)?"Inverse":"Forward",
shun_iwasawa a35b8f
            p->kind == PROBLEM_COMPLEX?"Complex":"Real",
shun_iwasawa a35b8f
            p->rank);
shun_iwasawa a35b8f
    */
shun_iwasawa a35b8f
    if (p->rank == 1) {
shun_iwasawa a35b8f
        if (p->kind == PROBLEM_COMPLEX) {
shun_iwasawa a35b8f
            cfg = kiss_fft_alloc (p->n[0], (p->sign == 1), 0, 0);
shun_iwasawa a35b8f
            FAILIF(cfg==NULL);
shun_iwasawa a35b8f
        }else{
shun_iwasawa a35b8f
            cfgr = kiss_fftr_alloc (p->n[0], (p->sign == 1), 0, 0);
shun_iwasawa a35b8f
            FAILIF(cfgr==NULL);
shun_iwasawa a35b8f
        }
shun_iwasawa a35b8f
    }else{
shun_iwasawa a35b8f
        int dims[5];
shun_iwasawa a35b8f
        for (i=0;i<p->rank;++i){</p->
shun_iwasawa a35b8f
            dims[i] = p->n[i];
shun_iwasawa a35b8f
        }
shun_iwasawa a35b8f
        /* multi-dimensional */
shun_iwasawa a35b8f
        if (p->kind == PROBLEM_COMPLEX) {
shun_iwasawa a35b8f
            cfgnd = kiss_fftnd_alloc( dims , p->rank, (p->sign == 1), 0, 0 );
shun_iwasawa a35b8f
            FAILIF(cfgnd==NULL);
shun_iwasawa a35b8f
        }
shun_iwasawa a35b8f
    }
shun_iwasawa a35b8f
}
shun_iwasawa a35b8f
shun_iwasawa a35b8f
void doit(int iter, struct problem *p)
shun_iwasawa a35b8f
{
shun_iwasawa a35b8f
    int i;
shun_iwasawa a35b8f
    void *in = p->in;
shun_iwasawa a35b8f
    void *out = p->out;
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    if (p->in_place)
shun_iwasawa a35b8f
        out = p->in;
shun_iwasawa a35b8f
shun_iwasawa a35b8f
    if (p->rank == 1) {
shun_iwasawa a35b8f
        if (p->kind == PROBLEM_COMPLEX){
shun_iwasawa a35b8f
            for (i = 0; i < iter; ++i)
shun_iwasawa a35b8f
                kiss_fft (cfg, in, out);
shun_iwasawa a35b8f
        } else {
shun_iwasawa a35b8f
            /* PROBLEM_REAL */
shun_iwasawa a35b8f
            if (p->sign == -1)   /* FORWARD */
shun_iwasawa a35b8f
                for (i = 0; i < iter; ++i)
shun_iwasawa a35b8f
                    kiss_fftr (cfgr, in, out);
shun_iwasawa a35b8f
            else
shun_iwasawa a35b8f
                for (i = 0; i < iter; ++i)
shun_iwasawa a35b8f
                    kiss_fftri (cfgr, in, out);
shun_iwasawa a35b8f
        }
shun_iwasawa a35b8f
    }else{
shun_iwasawa a35b8f
        /* multi-dimensional */
shun_iwasawa a35b8f
        for (i = 0; i < iter; ++i)
shun_iwasawa a35b8f
            kiss_fftnd(cfgnd,in,out);
shun_iwasawa a35b8f
    }
shun_iwasawa a35b8f
}
shun_iwasawa a35b8f
shun_iwasawa a35b8f
void done(struct problem *p)
shun_iwasawa a35b8f
{
shun_iwasawa a35b8f
     free(cfg);
shun_iwasawa a35b8f
     cfg=NULL;
shun_iwasawa a35b8f
     free(cfgr);
shun_iwasawa a35b8f
     cfgr=NULL;
shun_iwasawa a35b8f
     free(cfgnd);
shun_iwasawa a35b8f
     cfgnd=NULL;
shun_iwasawa a35b8f
     UNUSED(p);
shun_iwasawa a35b8f
}