Coverage Report

Created: 2025-07-23 07:03

/src/fftw3/dft/dftw-generic.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2003, 2007-14 Matteo Frigo
3
 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18
 *
19
 */
20
21
/* express a twiddle problem in terms of dft + multiplication by
22
   twiddle factors */
23
24
#include "dft/ct.h"
25
26
typedef ct_solver S;
27
28
typedef struct {
29
     plan_dftw super;
30
31
     INT r, rs, m, mb, me, ms, v, vs;
32
33
     plan *cld;
34
35
     twid *td;
36
37
     const S *slv;
38
     int dec;
39
} P;
40
41
static void mktwiddle(P *ego, enum wakefulness wakefulness)
42
18
{
43
18
     static const tw_instr tw[] = { { TW_FULL, 0, 0 }, { TW_NEXT, 1, 0 } };
44
45
     /* note that R and M are swapped, to allow for sequential
46
  access both to data and twiddles */
47
18
     X(twiddle_awake)(wakefulness, &ego->td, tw,
48
18
          ego->r * ego->m, ego->m, ego->r);
49
18
}
50
51
static void bytwiddle(const P *ego, R *rio, R *iio)
52
11
{
53
11
     INT iv, ir, im;
54
11
     INT r = ego->r, rs = ego->rs;
55
11
     INT m = ego->m, mb = ego->mb, me = ego->me, ms = ego->ms;
56
11
     INT v = ego->v, vs = ego->vs;
57
11
     const R *W = ego->td->W;
58
59
11
     mb += (mb == 0); /* skip m=0 iteration */
60
22
     for (iv = 0; iv < v; ++iv) {
61
127
    for (ir = 1; ir < r; ++ir) {
62
1.54k
         for (im = mb; im < me; ++im) {
63
1.43k
        R *pr = rio + ms * im + rs * ir;
64
1.43k
        R *pi = iio + ms * im + rs * ir;
65
1.43k
        E xr = *pr;
66
1.43k
        E xi = *pi;
67
1.43k
        E wr = W[2 * im + (2 * (m-1)) * ir - 2];
68
1.43k
        E wi = W[2 * im + (2 * (m-1)) * ir - 1];
69
1.43k
        *pr = xr * wr + xi * wi;
70
1.43k
        *pi = xi * wr - xr * wi;
71
1.43k
         }
72
116
    }
73
11
    rio += vs;
74
11
    iio += vs;
75
11
     }
76
11
}
77
78
static int applicable(INT irs, INT ors, INT ivs, INT ovs,
79
          const planner *plnr)
80
202
{
81
202
     return (1
82
202
       && irs == ors
83
202
       && ivs == ovs
84
202
       && !NO_SLOWP(plnr)
85
202
    );
86
202
}
87
88
static void apply_dit(const plan *ego_, R *rio, R *iio)
89
11
{
90
11
     const P *ego = (const P *) ego_;
91
11
     plan_dft *cld;
92
11
     INT dm = ego->ms * ego->mb;
93
94
11
     bytwiddle(ego, rio, iio);
95
96
11
     cld = (plan_dft *) ego->cld;
97
11
     cld->apply(ego->cld, rio + dm, iio + dm, rio + dm, iio + dm);
98
11
}
99
100
static void apply_dif(const plan *ego_, R *rio, R *iio)
101
0
{
102
0
     const P *ego = (const P *) ego_;
103
0
     plan_dft *cld;
104
0
     INT dm = ego->ms * ego->mb;
105
106
0
     cld = (plan_dft *) ego->cld;
107
0
     cld->apply(ego->cld, rio + dm, iio + dm, rio + dm, iio + dm);
108
109
0
     bytwiddle(ego, rio, iio);
110
0
}
111
112
static void awake(plan *ego_, enum wakefulness wakefulness)
113
18
{
114
18
     P *ego = (P *) ego_;
115
18
     X(plan_awake)(ego->cld, wakefulness);
116
18
     mktwiddle(ego, wakefulness);
117
18
}
118
119
static void destroy(plan *ego_)
120
21
{
121
21
     P *ego = (P *) ego_;
122
21
     X(plan_destroy_internal)(ego->cld);
123
21
}
124
125
static void print(const plan *ego_, printer *p)
126
0
{
127
0
     const P *ego = (const P *) ego_;
128
0
     p->print(p, "(dftw-generic-%s-%D-%D%v%(%p%))",
129
0
        ego->dec == DECDIT ? "dit" : "dif",
130
0
        ego->r, ego->m, ego->v, ego->cld);
131
0
}
132
133
static plan *mkcldw(const ct_solver *ego_,
134
        INT r, INT irs, INT ors,
135
        INT m, INT ms,
136
        INT v, INT ivs, INT ovs,
137
        INT mstart, INT mcount,
138
        R *rio, R *iio,
139
        planner *plnr)
140
202
{
141
202
     const S *ego = (const S *)ego_;
142
202
     P *pln;
143
202
     plan *cld = 0;
144
202
     INT dm = ms * mstart;
145
146
202
     static const plan_adt padt = {
147
202
    0, awake, print, destroy
148
202
     };
149
150
202
     A(mstart >= 0 && mstart + mcount <= m);
151
202
     if (!applicable(irs, ors, ivs, ovs, plnr))
152
181
          return (plan *)0;
153
154
21
     cld = X(mkplan_d)(plnr,
155
21
      X(mkproblem_dft_d)(
156
21
           X(mktensor_1d)(r, irs, irs),
157
21
           X(mktensor_2d)(mcount, ms, ms, v, ivs, ivs),
158
21
           rio + dm, iio + dm, rio + dm, iio + dm)
159
21
      );
160
21
     if (!cld) goto nada;
161
162
21
     pln = MKPLAN_DFTW(P, &padt, ego->dec == DECDIT ? apply_dit : apply_dif);
163
21
     pln->slv = ego;
164
21
     pln->cld = cld;
165
21
     pln->r = r;
166
21
     pln->rs = irs;
167
21
     pln->m = m;
168
21
     pln->ms = ms;
169
21
     pln->v = v;
170
21
     pln->vs = ivs;
171
21
     pln->mb = mstart;
172
21
     pln->me = mstart + mcount;
173
21
     pln->dec = ego->dec;
174
21
     pln->td = 0;
175
176
21
     {
177
21
    double n0 = (r - 1) * (mcount - 1) * v;
178
21
    pln->super.super.ops = cld->ops;
179
21
    pln->super.super.ops.mul += 8 * n0;
180
21
    pln->super.super.ops.add += 4 * n0;
181
21
    pln->super.super.ops.other += 8 * n0;
182
21
     }
183
21
     return &(pln->super.super);
184
185
0
 nada:
186
0
     X(plan_destroy_internal)(cld);
187
0
     return (plan *) 0;
188
21
}
189
190
static void regsolver(planner *plnr, INT r, int dec)
191
2
{
192
2
     S *slv = (S *)X(mksolver_ct)(sizeof(S), r, dec, mkcldw, 0);
193
2
     REGISTER_SOLVER(plnr, &(slv->super));
194
2
     if (X(mksolver_ct_hook)) {
195
0
    slv = (S *)X(mksolver_ct_hook)(sizeof(S), r, dec, mkcldw, 0);
196
0
    REGISTER_SOLVER(plnr, &(slv->super));
197
0
     }
198
2
}
199
200
void X(ct_generic_register)(planner *p)
201
1
{
202
1
     regsolver(p, 0, DECDIT);
203
1
     regsolver(p, 0, DECDIF);
204
1
}