annotate src/fftw-3.3.5/kernel/transpose.c @ 148:b4bfdf10c4b3

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