Coverage Report

Created: 2025-10-13 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fftw3/dft/dftw-generic.c
Line
Count
Source
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
22
{
43
22
     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
22
     X(twiddle_awake)(wakefulness, &ego->td, tw,
48
22
          ego->r * ego->m, ego->m, ego->r);
49
22
}
50
51
static void bytwiddle(const P *ego, R *rio, R *iio)
52
13
{
53
13
     INT iv, ir, im;
54
13
     INT r = ego->r, rs = ego->rs;
55
13
     INT m = ego->m, mb = ego->mb, me = ego->me, ms = ego->ms;
56
13
     INT v = ego->v, vs = ego->vs;
57
13
     const R *W = ego->td->W;
58
59
13
     mb += (mb == 0); /* skip m=0 iteration */
60
26
     for (iv = 0; iv < v; ++iv) {
61
153
    for (ir = 1; ir < r; ++ir) {
62
2.00k
         for (im = mb; im < me; ++im) {
63
1.86k
        R *pr = rio + ms * im + rs * ir;
64
1.86k
        R *pi = iio + ms * im + rs * ir;
65
1.86k
        E xr = *pr;
66
1.86k
        E xi = *pi;
67
1.86k
        E wr = W[2 * im + (2 * (m-1)) * ir - 2];
68
1.86k
        E wi = W[2 * im + (2 * (m-1)) * ir - 1];
69
1.86k
        *pr = xr * wr + xi * wi;
70
1.86k
        *pi = xi * wr - xr * wi;
71
1.86k
         }
72
140
    }
73
13
    rio += vs;
74
13
    iio += vs;
75
13
     }
76
13
}
77
78
static int applicable(INT irs, INT ors, INT ivs, INT ovs,
79
          const planner *plnr)
80
203
{
81
203
     return (1
82
203
       && irs == ors
83
203
       && ivs == ovs
84
203
       && !NO_SLOWP(plnr)
85
203
    );
86
203
}
87
88
static void apply_dit(const plan *ego_, R *rio, R *iio)
89
13
{
90
13
     const P *ego = (const P *) ego_;
91
13
     plan_dft *cld;
92
13
     INT dm = ego->ms * ego->mb;
93
94
13
     bytwiddle(ego, rio, iio);
95
96
13
     cld = (plan_dft *) ego->cld;
97
13
     cld->apply(ego->cld, rio + dm, iio + dm, rio + dm, iio + dm);
98
13
}
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
22
{
114
22
     P *ego = (P *) ego_;
115
22
     X(plan_awake)(ego->cld, wakefulness);
116
22
     mktwiddle(ego, wakefulness);
117
22
}
118
119
static void destroy(plan *ego_)
120
25
{
121
25
     P *ego = (P *) ego_;
122
25
     X(plan_destroy_internal)(ego->cld);
123
25
}
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
203
{
141
203
     const S *ego = (const S *)ego_;
142
203
     P *pln;
143
203
     plan *cld = 0;
144
203
     INT dm = ms * mstart;
145
146
203
     static const plan_adt padt = {
147
203
    0, awake, print, destroy
148
203
     };
149
150
203
     A(mstart >= 0 && mstart + mcount <= m);
151
203
     if (!applicable(irs, ors, ivs, ovs, plnr))
152
178
          return (plan *)0;
153
154
25
     cld = X(mkplan_d)(plnr,
155
25
      X(mkproblem_dft_d)(
156
25
           X(mktensor_1d)(r, irs, irs),
157
25
           X(mktensor_2d)(mcount, ms, ms, v, ivs, ivs),
158
25
           rio + dm, iio + dm, rio + dm, iio + dm)
159
25
      );
160
25
     if (!cld) goto nada;
161
162
25
     pln = MKPLAN_DFTW(P, &padt, ego->dec == DECDIT ? apply_dit : apply_dif);
163
25
     pln->slv = ego;
164
25
     pln->cld = cld;
165
25
     pln->r = r;
166
25
     pln->rs = irs;
167
25
     pln->m = m;
168
25
     pln->ms = ms;
169
25
     pln->v = v;
170
25
     pln->vs = ivs;
171
25
     pln->mb = mstart;
172
25
     pln->me = mstart + mcount;
173
25
     pln->dec = ego->dec;
174
25
     pln->td = 0;
175
176
25
     {
177
25
    double n0 = (r - 1) * (mcount - 1) * v;
178
25
    pln->super.super.ops = cld->ops;
179
25
    pln->super.super.ops.mul += 8 * n0;
180
25
    pln->super.super.ops.add += 4 * n0;
181
25
    pln->super.super.ops.other += 8 * n0;
182
25
     }
183
25
     return &(pln->super.super);
184
185
0
 nada:
186
0
     X(plan_destroy_internal)(cld);
187
0
     return (plan *) 0;
188
25
}
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
}