annotate src/fftw-3.3.8/kernel/transpose.c @ 168:ceec0dd9ec9c

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