annotate src/fftw-3.3.3/kernel/transpose.c @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents 37bf6b4a2645
children
rev   line source
Chris@10 1 /*
Chris@10 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
Chris@10 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
Chris@10 4 *
Chris@10 5 * This program is free software; you can redistribute it and/or modify
Chris@10 6 * it under the terms of the GNU General Public License as published by
Chris@10 7 * the Free Software Foundation; either version 2 of the License, or
Chris@10 8 * (at your option) any later version.
Chris@10 9 *
Chris@10 10 * This program is distributed in the hope that it will be useful,
Chris@10 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@10 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@10 13 * GNU General Public License for more details.
Chris@10 14 *
Chris@10 15 * You should have received a copy of the GNU General Public License
Chris@10 16 * along with this program; if not, write to the Free Software
Chris@10 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@10 18 *
Chris@10 19 */
Chris@10 20
Chris@10 21 #include "ifftw.h"
Chris@10 22
Chris@10 23 /* in place square transposition, iterative */
Chris@10 24 void X(transpose)(R *I, INT n, INT s0, INT s1, INT vl)
Chris@10 25 {
Chris@10 26 INT i0, i1, v;
Chris@10 27
Chris@10 28 switch (vl) {
Chris@10 29 case 1:
Chris@10 30 for (i1 = 1; i1 < n; ++i1) {
Chris@10 31 for (i0 = 0; i0 < i1; ++i0) {
Chris@10 32 R x0 = I[i1 * s0 + i0 * s1];
Chris@10 33 R y0 = I[i1 * s1 + i0 * s0];
Chris@10 34 I[i1 * s1 + i0 * s0] = x0;
Chris@10 35 I[i1 * s0 + i0 * s1] = y0;
Chris@10 36 }
Chris@10 37 }
Chris@10 38 break;
Chris@10 39 case 2:
Chris@10 40 for (i1 = 1; i1 < n; ++i1) {
Chris@10 41 for (i0 = 0; i0 < i1; ++i0) {
Chris@10 42 R x0 = I[i1 * s0 + i0 * s1];
Chris@10 43 R x1 = I[i1 * s0 + i0 * s1 + 1];
Chris@10 44 R y0 = I[i1 * s1 + i0 * s0];
Chris@10 45 R y1 = I[i1 * s1 + i0 * s0 + 1];
Chris@10 46 I[i1 * s1 + i0 * s0] = x0;
Chris@10 47 I[i1 * s1 + i0 * s0 + 1] = x1;
Chris@10 48 I[i1 * s0 + i0 * s1] = y0;
Chris@10 49 I[i1 * s0 + i0 * s1 + 1] = y1;
Chris@10 50 }
Chris@10 51 }
Chris@10 52 break;
Chris@10 53 default:
Chris@10 54 for (i1 = 1; i1 < n; ++i1) {
Chris@10 55 for (i0 = 0; i0 < i1; ++i0) {
Chris@10 56 for (v = 0; v < vl; ++v) {
Chris@10 57 R x0 = I[i1 * s0 + i0 * s1 + v];
Chris@10 58 R y0 = I[i1 * s1 + i0 * s0 + v];
Chris@10 59 I[i1 * s1 + i0 * s0 + v] = x0;
Chris@10 60 I[i1 * s0 + i0 * s1 + v] = y0;
Chris@10 61 }
Chris@10 62 }
Chris@10 63 }
Chris@10 64 break;
Chris@10 65 }
Chris@10 66 }
Chris@10 67
Chris@10 68 struct transpose_closure {
Chris@10 69 R *I;
Chris@10 70 INT s0, s1, vl, tilesz;
Chris@10 71 R *buf0, *buf1;
Chris@10 72 };
Chris@10 73
Chris@10 74 static void dotile(INT n0l, INT n0u, INT n1l, INT n1u, void *args)
Chris@10 75 {
Chris@10 76 struct transpose_closure *k = (struct transpose_closure *)args;
Chris@10 77 R *I = k->I;
Chris@10 78 INT s0 = k->s0, s1 = k->s1, vl = k->vl;
Chris@10 79 INT i0, i1, v;
Chris@10 80
Chris@10 81 switch (vl) {
Chris@10 82 case 1:
Chris@10 83 for (i1 = n1l; i1 < n1u; ++i1) {
Chris@10 84 for (i0 = n0l; i0 < n0u; ++i0) {
Chris@10 85 R x0 = I[i1 * s0 + i0 * s1];
Chris@10 86 R y0 = I[i1 * s1 + i0 * s0];
Chris@10 87 I[i1 * s1 + i0 * s0] = x0;
Chris@10 88 I[i1 * s0 + i0 * s1] = y0;
Chris@10 89 }
Chris@10 90 }
Chris@10 91 break;
Chris@10 92 case 2:
Chris@10 93 for (i1 = n1l; i1 < n1u; ++i1) {
Chris@10 94 for (i0 = n0l; i0 < n0u; ++i0) {
Chris@10 95 R x0 = I[i1 * s0 + i0 * s1];
Chris@10 96 R x1 = I[i1 * s0 + i0 * s1 + 1];
Chris@10 97 R y0 = I[i1 * s1 + i0 * s0];
Chris@10 98 R y1 = I[i1 * s1 + i0 * s0 + 1];
Chris@10 99 I[i1 * s1 + i0 * s0] = x0;
Chris@10 100 I[i1 * s1 + i0 * s0 + 1] = x1;
Chris@10 101 I[i1 * s0 + i0 * s1] = y0;
Chris@10 102 I[i1 * s0 + i0 * s1 + 1] = y1;
Chris@10 103 }
Chris@10 104 }
Chris@10 105 break;
Chris@10 106 default:
Chris@10 107 for (i1 = n1l; i1 < n1u; ++i1) {
Chris@10 108 for (i0 = n0l; i0 < n0u; ++i0) {
Chris@10 109 for (v = 0; v < vl; ++v) {
Chris@10 110 R x0 = I[i1 * s0 + i0 * s1 + v];
Chris@10 111 R y0 = I[i1 * s1 + i0 * s0 + v];
Chris@10 112 I[i1 * s1 + i0 * s0 + v] = x0;
Chris@10 113 I[i1 * s0 + i0 * s1 + v] = y0;
Chris@10 114 }
Chris@10 115 }
Chris@10 116 }
Chris@10 117 }
Chris@10 118 }
Chris@10 119
Chris@10 120 static void dotile_buf(INT n0l, INT n0u, INT n1l, INT n1u, void *args)
Chris@10 121 {
Chris@10 122 struct transpose_closure *k = (struct transpose_closure *)args;
Chris@10 123 X(cpy2d_ci)(k->I + n0l * k->s0 + n1l * k->s1,
Chris@10 124 k->buf0,
Chris@10 125 n0u - n0l, k->s0, k->vl,
Chris@10 126 n1u - n1l, k->s1, k->vl * (n0u - n0l),
Chris@10 127 k->vl);
Chris@10 128 X(cpy2d_ci)(k->I + n0l * k->s1 + n1l * k->s0,
Chris@10 129 k->buf1,
Chris@10 130 n0u - n0l, k->s1, k->vl,
Chris@10 131 n1u - n1l, k->s0, k->vl * (n0u - n0l),
Chris@10 132 k->vl);
Chris@10 133 X(cpy2d_co)(k->buf1,
Chris@10 134 k->I + n0l * k->s0 + n1l * k->s1,
Chris@10 135 n0u - n0l, k->vl, k->s0,
Chris@10 136 n1u - n1l, k->vl * (n0u - n0l), k->s1,
Chris@10 137 k->vl);
Chris@10 138 X(cpy2d_co)(k->buf0,
Chris@10 139 k->I + n0l * k->s1 + n1l * k->s0,
Chris@10 140 n0u - n0l, k->vl, k->s1,
Chris@10 141 n1u - n1l, k->vl * (n0u - n0l), k->s0,
Chris@10 142 k->vl);
Chris@10 143 }
Chris@10 144
Chris@10 145 static void transpose_rec(R *I, INT n,
Chris@10 146 void (*f)(INT n0l, INT n0u, INT n1l, INT n1u,
Chris@10 147 void *args),
Chris@10 148 struct transpose_closure *k)
Chris@10 149 {
Chris@10 150 tail:
Chris@10 151 if (n > 1) {
Chris@10 152 INT n2 = n / 2;
Chris@10 153 k->I = I;
Chris@10 154 X(tile2d)(0, n2, n2, n, k->tilesz, f, k);
Chris@10 155 transpose_rec(I, n2, f, k);
Chris@10 156 I += n2 * (k->s0 + k->s1); n -= n2; goto tail;
Chris@10 157 }
Chris@10 158 }
Chris@10 159
Chris@10 160 void X(transpose_tiled)(R *I, INT n, INT s0, INT s1, INT vl)
Chris@10 161 {
Chris@10 162 struct transpose_closure k;
Chris@10 163 k.s0 = s0;
Chris@10 164 k.s1 = s1;
Chris@10 165 k.vl = vl;
Chris@10 166 /* two blocks must be in cache, to be swapped */
Chris@10 167 k.tilesz = X(compute_tilesz)(vl, 2);
Chris@10 168 k.buf0 = k.buf1 = 0; /* unused */
Chris@10 169 transpose_rec(I, n, dotile, &k);
Chris@10 170 }
Chris@10 171
Chris@10 172 void X(transpose_tiledbuf)(R *I, INT n, INT s0, INT s1, INT vl)
Chris@10 173 {
Chris@10 174 struct transpose_closure k;
Chris@10 175 /* Assume that the the rows of I conflict into the same cache
Chris@10 176 lines, and therefore we don't need to reserve cache space for
Chris@10 177 the input. If the rows don't conflict, there is no reason
Chris@10 178 to use tiledbuf at all.*/
Chris@10 179 R buf0[CACHESIZE / (2 * sizeof(R))];
Chris@10 180 R buf1[CACHESIZE / (2 * sizeof(R))];
Chris@10 181 k.s0 = s0;
Chris@10 182 k.s1 = s1;
Chris@10 183 k.vl = vl;
Chris@10 184 k.tilesz = X(compute_tilesz)(vl, 2);
Chris@10 185 k.buf0 = buf0;
Chris@10 186 k.buf1 = buf1;
Chris@10 187 A(k.tilesz * k.tilesz * vl * sizeof(R) <= sizeof(buf0));
Chris@10 188 A(k.tilesz * k.tilesz * vl * sizeof(R) <= sizeof(buf1));
Chris@10 189 transpose_rec(I, n, dotile_buf, &k);
Chris@10 190 }
Chris@10 191