forked from Xrysnow/lstgx_Math
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeow_fft.h
More file actions
162 lines (133 loc) · 5.56 KB
/
meow_fft.h
File metadata and controls
162 lines (133 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
meow_fft. My Easy Oresome Wonderful Fast Fourier Transform.
Copyright (C) 2017 Richard Maxwell <jodi.the.tigger@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef MEOW_FFT
#define MEOW_FFT
#include <stdlib.h>
// for size_t
#ifdef __cplusplus
extern "C" {
#endif
// C-API -----------------------------------------------------------------------
typedef struct Meow_FFT_Complex
{
float r;
float j;
}
Meow_FFT_Complex;
struct Meow_FFT_Workset;
struct Meow_FFT_Workset_Real;
size_t meow_fft_generate_workset
(
int N
, struct Meow_FFT_Workset* workset
);
// returns the size of the workset if null is passed.
size_t meow_fft_generate_workset_real
(
int N
, struct Meow_FFT_Workset_Real* workset
);
// returns the size of the workset if null is passed.
unsigned meow_fft_is_slow(const struct Meow_FFT_Workset* workset);
unsigned meow_fft_is_slow_real(const struct Meow_FFT_Workset_Real* workset);
// returns non-zero if the fft has a slow dft in any one of its stages.
// C-API (ffts) ----------------------------------------------------------------
// NOTES:
// countof(out) == countof(in).
// In order to do that I have mixed out[0] with out[N/2]. That is:
// out[0].r == out[0].r, out[0].j = out[N/2].r
void meow_fft_real
(
const struct Meow_FFT_Workset_Real* workset
, const float* in
, Meow_FFT_Complex* out
);
void meow_fft_real_i
(
const struct Meow_FFT_Workset_Real* workset
, const Meow_FFT_Complex* in
, Meow_FFT_Complex* temp
, float* out
);
void meow_fft
(
const struct Meow_FFT_Workset* data
, const Meow_FFT_Complex* in
, Meow_FFT_Complex* out
);
void meow_fft_i
(
const struct Meow_FFT_Workset* data
, const Meow_FFT_Complex* in
, Meow_FFT_Complex* out
);
// -----------------------------------------------------------------------------
#ifdef __cplusplus
}
#endif
#endif // MEOW_FFT
// bash script used to generate radix N codelets from fftw that suit this code.
// since my tests run slower with > 8 radix, I hand modified the radix 8
// generated (function signature) instead of updating this code.
#if 0
#!/bin/sh
# <command> N [-1|1] [|_i]
cat << EOF
static void meow_radix_${ 1 }_dit${ 3 }
(
meow_fft_complex* out
, const float* W
, unsigned count
)
{
EOF
#// First loop doesn't use twiddles
. / gen_notw.native - n ${ 1 } -standalone - sign ${ 2 } \
| sed 's/E /float /g' \
| sed '/INT.*/d' \
| sed - r 's/r[io]\[(.+)]/out\[\1\].r/g' \
| sed - r 's/i[io]\[(.+)]/out\[\1\].j/g' \
| sed '/for (.*).*/d' \
| sed - r 's/WS\(.., (.*)\)/count * \1/g' \
| sed - r 's/FMA\((.+), (.+), (.+)\)/\(\1 * \2\) + \(\3\)/g' \
| sed - r 's/FMS\((.+), (.+), (.+)\)/\(\1 * \2\) - \(\3\)/g' \
| sed - r 's/FNMA\((.+), (.+), (.+)\)/-\(\1 * \2\) + \(\3\)/g' \
| sed - r 's/FNMS\((.+), (.+), (.+)\)/\(\3\) - \(\1 * \2\)/g' \
| sed - r 's/DK\((.+), (.+)\);/static const float \1 = \2;/g' \
| head - n - 3 \
| tail - n + 9
echo ""
echo "out = out + 1;"
echo ""
. / gen_twiddle.native - n ${ 1 } -standalone - sign ${ 2 } -dit - with - ms 1 \
| sed 's/E /float /g' \
| sed 's/INT /unsigned /g' \
| sed - r 's/r[io]\[(.+)]/out\[\1\].r/g' \
| sed - r 's/i[io]\[(.+)]/out\[\1\].j/g' \
| sed 's/, MAKE_VOLATILE_STRIDE(.*))/)/g' \
| sed 's/, MAKE_VOLATILE_STRIDE(.*)//g' \
| sed - r 's/WS\(.., (.*)\)/count * \1/g' \
| sed - r 's/FMA\((.+), (.+), (.+)\)/\(\1 * \2\) + \(\3\)/g' \
| sed - r 's/FMS\((.+), (.+), (.+)\)/\(\1 * \2\) - \(\3\)/g' \
| sed - r 's/FNMA\((.+), (.+), (.+)\)/-\(\1 * \2\) + \(\3\)/g' \
| sed - r 's/FNMS\((.+), (.+), (.+)\)/\(\3\) - \(\1 * \2\)/g' \
| sed '/DK(.*);/d' \
| sed 's/ri = ri + 1, ii = ii + 1,/out = out + 1,/g' \
| sed 's/m = mb, W = W + (mb * .*);/m = 1;/g' \
| sed - r 's/(for \(.*\)).*/\1\n{/g' \
| sed 's/me/count/g' \
| head - n - 2 \
| tail - n + 10
echo "}"
#endif