annotate ext/kissfft/test/doit.c @ 184:76ec2365b250

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