annotate fft/fftw/fftw-3.3.4/kernel/transpose.c @ 40:223f770b5341 kissfft-double tip

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