~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to extern/fftw/rdft/vrank-geq1.c

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2003, 2006 Matteo Frigo
 
3
 * Copyright (c) 2003, 2006 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
/* $Id: vrank-geq1.c,v 1.40 2006-01-27 02:10:50 athena Exp $ */
 
22
 
 
23
 
 
24
/* Plans for handling vector transform loops.  These are *just* the
 
25
   loops, and rely on child plans for the actual RDFTs.
 
26
 
 
27
   They form a wrapper around solvers that don't have apply functions
 
28
   for non-null vectors.
 
29
 
 
30
   vrank-geq1 plans also recursively handle the case of multi-dimensional
 
31
   vectors, obviating the need for most solvers to deal with this.  We
 
32
   can also play games here, such as reordering the vector loops.
 
33
 
 
34
   Each vrank-geq1 plan reduces the vector rank by 1, picking out a
 
35
   dimension determined by the vecloop_dim field of the solver. */
 
36
 
 
37
#include "rdft.h"
 
38
 
 
39
typedef struct {
 
40
     solver super;
 
41
     int vecloop_dim;
 
42
     const int *buddies;
 
43
     int nbuddies;
 
44
} S;
 
45
 
 
46
typedef struct {
 
47
     plan_rdft super;
 
48
 
 
49
     plan *cld;
 
50
     INT vl;
 
51
     INT ivs, ovs;
 
52
     const S *solver;
 
53
} P;
 
54
 
 
55
static void apply(const plan *ego_, R *I, R *O)
 
56
{
 
57
     const P *ego = (const P *) ego_;
 
58
     INT i, vl = ego->vl;
 
59
     INT ivs = ego->ivs, ovs = ego->ovs;
 
60
     rdftapply cldapply = ((plan_rdft *) ego->cld)->apply;
 
61
 
 
62
     for (i = 0; i < vl; ++i) {
 
63
          cldapply(ego->cld, I + i * ivs, O + i * ovs);
 
64
     }
 
65
}
 
66
 
 
67
static void awake(plan *ego_, enum wakefulness wakefulness)
 
68
{
 
69
     P *ego = (P *) ego_;
 
70
     X(plan_awake)(ego->cld, wakefulness);
 
71
}
 
72
 
 
73
static void destroy(plan *ego_)
 
74
{
 
75
     P *ego = (P *) ego_;
 
76
     X(plan_destroy_internal)(ego->cld);
 
77
}
 
78
 
 
79
static void print(const plan *ego_, printer *p)
 
80
{
 
81
     const P *ego = (const P *) ego_;
 
82
     const S *s = ego->solver;
 
83
     p->print(p, "(rdft-vrank>=1-x%D/%d%(%p%))",
 
84
              ego->vl, s->vecloop_dim, ego->cld);
 
85
}
 
86
 
 
87
static int pickdim(const S *ego, const tensor *vecsz, int oop, int *dp)
 
88
{
 
89
     return X(pickdim)(ego->vecloop_dim, ego->buddies, ego->nbuddies,
 
90
                       vecsz, oop, dp);
 
91
}
 
92
 
 
93
static int applicable0(const solver *ego_, const problem *p_, int *dp)
 
94
{
 
95
     const S *ego = (const S *) ego_;
 
96
     const problem_rdft *p = (const problem_rdft *) p_;
 
97
 
 
98
     return (1
 
99
             && FINITE_RNK(p->vecsz->rnk)
 
100
             && p->vecsz->rnk > 0
 
101
 
 
102
             /* the rank-0 solver deals with the general case */
 
103
             && p->sz->rnk > 0
 
104
 
 
105
             && pickdim(ego, p->vecsz, p->I != p->O, dp)
 
106
          );
 
107
}
 
108
 
 
109
static int applicable(const solver *ego_, const problem *p_, 
 
110
                      const planner *plnr, int *dp)
 
111
{
 
112
     const S *ego = (const S *)ego_;
 
113
     const problem_rdft *p;
 
114
 
 
115
     if (!applicable0(ego_, p_, dp)) return 0;
 
116
 
 
117
     /* fftw2 behavior */
 
118
     if (NO_VRANK_SPLITSP(plnr) && (ego->vecloop_dim != ego->buddies[0]))
 
119
          return 0;
 
120
 
 
121
     if (NO_UGLYP(plnr)) {
 
122
          p = (const problem_rdft *) p_;
 
123
 
 
124
          /* Heuristic: if the transform is multi-dimensional, and the
 
125
             vector stride is less than the transform size, then we
 
126
             probably want to use a rank>=2 plan first in order to combine
 
127
             this vector with the transform-dimension vectors. */
 
128
          {
 
129
               iodim *d = p->vecsz->dims + *dp;
 
130
               if (1
 
131
                   && p->sz->rnk > 1 
 
132
                   && X(imin)(X(iabs)(d->is), X(iabs)(d->os))
 
133
                   < X(tensor_max_index)(p->sz)
 
134
                    )
 
135
                    return 0;
 
136
          }
 
137
 
 
138
          /* prefer threaded version */
 
139
          if (NO_NONTHREADEDP(plnr)) return 0;
 
140
 
 
141
          /* exploit built-in vecloops of (ugly) r{e,o}dft solvers */
 
142
          if (p->vecsz->rnk == 1 && p->sz->rnk == 1 
 
143
              && REODFT_KINDP(p->kind[0]))
 
144
               return 0;
 
145
     }
 
146
 
 
147
     return 1;
 
148
}
 
149
 
 
150
static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
 
151
{
 
152
     const S *ego = (const S *) ego_;
 
153
     const problem_rdft *p;
 
154
     P *pln;
 
155
     plan *cld;
 
156
     int vdim;
 
157
     iodim *d;
 
158
 
 
159
     static const plan_adt padt = {
 
160
          X(rdft_solve), awake, print, destroy
 
161
     };
 
162
 
 
163
     if (!applicable(ego_, p_, plnr, &vdim))
 
164
          return (plan *) 0;
 
165
     p = (const problem_rdft *) p_;
 
166
 
 
167
     d = p->vecsz->dims + vdim;
 
168
 
 
169
     A(d->n > 1); 
 
170
 
 
171
     cld = X(mkplan_d)(plnr, 
 
172
                       X(mkproblem_rdft_d)(
 
173
                            X(tensor_copy)(p->sz),
 
174
                            X(tensor_copy_except)(p->vecsz, vdim),
 
175
                            TAINT(p->I, d->is), TAINT(p->O, d->os),
 
176
                            p->kind));
 
177
     if (!cld) return (plan *) 0;
 
178
 
 
179
     pln = MKPLAN_RDFT(P, &padt, apply);
 
180
 
 
181
     pln->cld = cld;
 
182
     pln->vl = d->n;
 
183
     pln->ivs = d->is;
 
184
     pln->ovs = d->os;
 
185
 
 
186
     pln->solver = ego;
 
187
     X(ops_zero)(&pln->super.super.ops);
 
188
     pln->super.super.ops.other = 3.14159; /* magic to prefer codelet loops */
 
189
     X(ops_madd2)(pln->vl, &cld->ops, &pln->super.super.ops);
 
190
 
 
191
     if (p->sz->rnk != 1 || (p->sz->dims[0].n > 128))
 
192
          pln->super.super.pcost = pln->vl * cld->pcost;
 
193
 
 
194
     return &(pln->super.super);
 
195
}
 
196
 
 
197
static solver *mksolver(int vecloop_dim, const int *buddies, int nbuddies)
 
198
{
 
199
     static const solver_adt sadt = { PROBLEM_RDFT, mkplan };
 
200
     S *slv = MKSOLVER(S, &sadt);
 
201
     slv->vecloop_dim = vecloop_dim;
 
202
     slv->buddies = buddies;
 
203
     slv->nbuddies = nbuddies;
 
204
     return &(slv->super);
 
205
}
 
206
 
 
207
void X(rdft_vrank_geq1_register)(planner *p)
 
208
{
 
209
     int i;
 
210
 
 
211
     /* FIXME: Should we try other vecloop_dim values? */
 
212
     static const int buddies[] = { 1, -1 };
 
213
 
 
214
     const int nbuddies = (int)(sizeof(buddies) / sizeof(buddies[0]));
 
215
 
 
216
     for (i = 0; i < nbuddies; ++i)
 
217
          REGISTER_SOLVER(p, mksolver(buddies[i], buddies, nbuddies));
 
218
}