annotate ext/kissfft/test/doit.c @ 409:1f1999b0f577

Bring in kissfft into this repo (formerly a subrepo, but the remote is not responding)
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 21 Jul 2015 07:34:15 +0100
parents
children
rev   line source
c@409 1 /* this program is in the public domain
c@409 2 A program that helps the authors of the fine fftw library benchmark kiss
c@409 3 */
c@409 4
c@409 5 #include "bench-user.h"
c@409 6 #include <math.h>
c@409 7
c@409 8 #include "kiss_fft.h"
c@409 9 #include "kiss_fftnd.h"
c@409 10 #include "kiss_fftr.h"
c@409 11
c@409 12 BEGIN_BENCH_DOC
c@409 13 BENCH_DOC("name", "kissfft")
c@409 14 BENCH_DOC("version", "1.0.1")
c@409 15 BENCH_DOC("year", "2004")
c@409 16 BENCH_DOC("author", "Mark Borgerding")
c@409 17 BENCH_DOC("language", "C")
c@409 18 BENCH_DOC("url", "http://sourceforge.net/projects/kissfft/")
c@409 19 BENCH_DOC("copyright",
c@409 20 "Copyright (c) 2003,4 Mark Borgerding\n"
c@409 21 "\n"
c@409 22 "All rights reserved.\n"
c@409 23 "\n"
c@409 24 "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n"
c@409 25 "\n"
c@409 26 " * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n"
c@409 27 " * 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"
c@409 28 " * 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"
c@409 29 "\n"
c@409 30 "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")
c@409 31 END_BENCH_DOC
c@409 32
c@409 33 int can_do(struct problem *p)
c@409 34 {
c@409 35 if (p->rank == 1) {
c@409 36 if (p->kind == PROBLEM_REAL) {
c@409 37 return (p->n[0] & 1) == 0; /* only even real is okay */
c@409 38 } else {
c@409 39 return 1;
c@409 40 }
c@409 41 } else {
c@409 42 return p->kind == PROBLEM_COMPLEX;
c@409 43 }
c@409 44 }
c@409 45
c@409 46 static kiss_fft_cfg cfg=NULL;
c@409 47 static kiss_fftr_cfg cfgr=NULL;
c@409 48 static kiss_fftnd_cfg cfgnd=NULL;
c@409 49
c@409 50 #define FAILIF( c ) \
c@409 51 if ( c ) do {\
c@409 52 fprintf(stderr,\
c@409 53 "kissfft: " #c " (file=%s:%d errno=%d %s)\n",\
c@409 54 __FILE__,__LINE__ , errno,strerror( errno ) ) ;\
c@409 55 exit(1);\
c@409 56 }while(0)
c@409 57
c@409 58
c@409 59
c@409 60 void setup(struct problem *p)
c@409 61 {
c@409 62 size_t i;
c@409 63
c@409 64 /*
c@409 65 fprintf(stderr,"%s %s %d-d ",
c@409 66 (p->sign == 1)?"Inverse":"Forward",
c@409 67 p->kind == PROBLEM_COMPLEX?"Complex":"Real",
c@409 68 p->rank);
c@409 69 */
c@409 70 if (p->rank == 1) {
c@409 71 if (p->kind == PROBLEM_COMPLEX) {
c@409 72 cfg = kiss_fft_alloc (p->n[0], (p->sign == 1), 0, 0);
c@409 73 FAILIF(cfg==NULL);
c@409 74 }else{
c@409 75 cfgr = kiss_fftr_alloc (p->n[0], (p->sign == 1), 0, 0);
c@409 76 FAILIF(cfgr==NULL);
c@409 77 }
c@409 78 }else{
c@409 79 int dims[5];
c@409 80 for (i=0;i<p->rank;++i){
c@409 81 dims[i] = p->n[i];
c@409 82 }
c@409 83 /* multi-dimensional */
c@409 84 if (p->kind == PROBLEM_COMPLEX) {
c@409 85 cfgnd = kiss_fftnd_alloc( dims , p->rank, (p->sign == 1), 0, 0 );
c@409 86 FAILIF(cfgnd==NULL);
c@409 87 }
c@409 88 }
c@409 89 }
c@409 90
c@409 91 void doit(int iter, struct problem *p)
c@409 92 {
c@409 93 int i;
c@409 94 void *in = p->in;
c@409 95 void *out = p->out;
c@409 96
c@409 97 if (p->in_place)
c@409 98 out = p->in;
c@409 99
c@409 100 if (p->rank == 1) {
c@409 101 if (p->kind == PROBLEM_COMPLEX){
c@409 102 for (i = 0; i < iter; ++i)
c@409 103 kiss_fft (cfg, in, out);
c@409 104 } else {
c@409 105 /* PROBLEM_REAL */
c@409 106 if (p->sign == -1) /* FORWARD */
c@409 107 for (i = 0; i < iter; ++i)
c@409 108 kiss_fftr (cfgr, in, out);
c@409 109 else
c@409 110 for (i = 0; i < iter; ++i)
c@409 111 kiss_fftri (cfgr, in, out);
c@409 112 }
c@409 113 }else{
c@409 114 /* multi-dimensional */
c@409 115 for (i = 0; i < iter; ++i)
c@409 116 kiss_fftnd(cfgnd,in,out);
c@409 117 }
c@409 118 }
c@409 119
c@409 120 void done(struct problem *p)
c@409 121 {
c@409 122 free(cfg);
c@409 123 cfg=NULL;
c@409 124 free(cfgr);
c@409 125 cfgr=NULL;
c@409 126 free(cfgnd);
c@409 127 cfgnd=NULL;
c@409 128 UNUSED(p);
c@409 129 }