annotate src/fftw-3.3.5/kernel/cpy2d.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
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 /* out of place 2D copy routines */
cannam@127 22 #include "ifftw.h"
cannam@127 23
cannam@127 24 #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64)
cannam@127 25 # ifdef HAVE_XMMINTRIN_H
cannam@127 26 # include <xmmintrin.h>
cannam@127 27 # define WIDE_TYPE __m128
cannam@127 28 # endif
cannam@127 29 #endif
cannam@127 30
cannam@127 31 #ifndef WIDE_TYPE
cannam@127 32 /* fall back to double, which means that WIDE_TYPE will be unused */
cannam@127 33 # define WIDE_TYPE double
cannam@127 34 #endif
cannam@127 35
cannam@127 36 void X(cpy2d)(R *I, R *O,
cannam@127 37 INT n0, INT is0, INT os0,
cannam@127 38 INT n1, INT is1, INT os1,
cannam@127 39 INT vl)
cannam@127 40 {
cannam@127 41 INT i0, i1, v;
cannam@127 42
cannam@127 43 switch (vl) {
cannam@127 44 case 1:
cannam@127 45 for (i1 = 0; i1 < n1; ++i1)
cannam@127 46 for (i0 = 0; i0 < n0; ++i0) {
cannam@127 47 R x0 = I[i0 * is0 + i1 * is1];
cannam@127 48 O[i0 * os0 + i1 * os1] = x0;
cannam@127 49 }
cannam@127 50 break;
cannam@127 51 case 2:
cannam@127 52 if (1
cannam@127 53 && (2 * sizeof(R) == sizeof(WIDE_TYPE))
cannam@127 54 && (sizeof(WIDE_TYPE) > sizeof(double))
cannam@127 55 && (((size_t)I) % sizeof(WIDE_TYPE) == 0)
cannam@127 56 && (((size_t)O) % sizeof(WIDE_TYPE) == 0)
cannam@127 57 && ((is0 & 1) == 0)
cannam@127 58 && ((is1 & 1) == 0)
cannam@127 59 && ((os0 & 1) == 0)
cannam@127 60 && ((os1 & 1) == 0)) {
cannam@127 61 /* copy R[2] as WIDE_TYPE if WIDE_TYPE is large
cannam@127 62 enough to hold R[2], and if the input is
cannam@127 63 properly aligned. This is a win when R==double
cannam@127 64 and WIDE_TYPE is 128 bits. */
cannam@127 65 for (i1 = 0; i1 < n1; ++i1)
cannam@127 66 for (i0 = 0; i0 < n0; ++i0) {
cannam@127 67 *(WIDE_TYPE *)&O[i0 * os0 + i1 * os1] =
cannam@127 68 *(WIDE_TYPE *)&I[i0 * is0 + i1 * is1];
cannam@127 69 }
cannam@127 70 } else if (1
cannam@127 71 && (2 * sizeof(R) == sizeof(double))
cannam@127 72 && (((size_t)I) % sizeof(double) == 0)
cannam@127 73 && (((size_t)O) % sizeof(double) == 0)
cannam@127 74 && ((is0 & 1) == 0)
cannam@127 75 && ((is1 & 1) == 0)
cannam@127 76 && ((os0 & 1) == 0)
cannam@127 77 && ((os1 & 1) == 0)) {
cannam@127 78 /* copy R[2] as double if double is large enough to
cannam@127 79 hold R[2], and if the input is properly aligned.
cannam@127 80 This case applies when R==float */
cannam@127 81 for (i1 = 0; i1 < n1; ++i1)
cannam@127 82 for (i0 = 0; i0 < n0; ++i0) {
cannam@127 83 *(double *)&O[i0 * os0 + i1 * os1] =
cannam@127 84 *(double *)&I[i0 * is0 + i1 * is1];
cannam@127 85 }
cannam@127 86 } else {
cannam@127 87 for (i1 = 0; i1 < n1; ++i1)
cannam@127 88 for (i0 = 0; i0 < n0; ++i0) {
cannam@127 89 R x0 = I[i0 * is0 + i1 * is1];
cannam@127 90 R x1 = I[i0 * is0 + i1 * is1 + 1];
cannam@127 91 O[i0 * os0 + i1 * os1] = x0;
cannam@127 92 O[i0 * os0 + i1 * os1 + 1] = x1;
cannam@127 93 }
cannam@127 94 }
cannam@127 95 break;
cannam@127 96 default:
cannam@127 97 for (i1 = 0; i1 < n1; ++i1)
cannam@127 98 for (i0 = 0; i0 < n0; ++i0)
cannam@127 99 for (v = 0; v < vl; ++v) {
cannam@127 100 R x0 = I[i0 * is0 + i1 * is1 + v];
cannam@127 101 O[i0 * os0 + i1 * os1 + v] = x0;
cannam@127 102 }
cannam@127 103 break;
cannam@127 104 }
cannam@127 105 }
cannam@127 106
cannam@127 107 /* like cpy2d, but read input contiguously if possible */
cannam@127 108 void X(cpy2d_ci)(R *I, R *O,
cannam@127 109 INT n0, INT is0, INT os0,
cannam@127 110 INT n1, INT is1, INT os1,
cannam@127 111 INT vl)
cannam@127 112 {
cannam@127 113 if (IABS(is0) < IABS(is1)) /* inner loop is for n0 */
cannam@127 114 X(cpy2d) (I, O, n0, is0, os0, n1, is1, os1, vl);
cannam@127 115 else
cannam@127 116 X(cpy2d) (I, O, n1, is1, os1, n0, is0, os0, vl);
cannam@127 117 }
cannam@127 118
cannam@127 119 /* like cpy2d, but write output contiguously if possible */
cannam@127 120 void X(cpy2d_co)(R *I, R *O,
cannam@127 121 INT n0, INT is0, INT os0,
cannam@127 122 INT n1, INT is1, INT os1,
cannam@127 123 INT vl)
cannam@127 124 {
cannam@127 125 if (IABS(os0) < IABS(os1)) /* inner loop is for n0 */
cannam@127 126 X(cpy2d) (I, O, n0, is0, os0, n1, is1, os1, vl);
cannam@127 127 else
cannam@127 128 X(cpy2d) (I, O, n1, is1, os1, n0, is0, os0, vl);
cannam@127 129 }
cannam@127 130
cannam@127 131
cannam@127 132 /* tiled copy routines */
cannam@127 133 struct cpy2d_closure {
cannam@127 134 R *I, *O;
cannam@127 135 INT is0, os0, is1, os1, vl;
cannam@127 136 R *buf;
cannam@127 137 };
cannam@127 138
cannam@127 139 static void dotile(INT n0l, INT n0u, INT n1l, INT n1u, void *args)
cannam@127 140 {
cannam@127 141 struct cpy2d_closure *k = (struct cpy2d_closure *)args;
cannam@127 142 X(cpy2d)(k->I + n0l * k->is0 + n1l * k->is1,
cannam@127 143 k->O + n0l * k->os0 + n1l * k->os1,
cannam@127 144 n0u - n0l, k->is0, k->os0,
cannam@127 145 n1u - n1l, k->is1, k->os1,
cannam@127 146 k->vl);
cannam@127 147 }
cannam@127 148
cannam@127 149 static void dotile_buf(INT n0l, INT n0u, INT n1l, INT n1u, void *args)
cannam@127 150 {
cannam@127 151 struct cpy2d_closure *k = (struct cpy2d_closure *)args;
cannam@127 152
cannam@127 153 /* copy from I to buf */
cannam@127 154 X(cpy2d_ci)(k->I + n0l * k->is0 + n1l * k->is1,
cannam@127 155 k->buf,
cannam@127 156 n0u - n0l, k->is0, k->vl,
cannam@127 157 n1u - n1l, k->is1, k->vl * (n0u - n0l),
cannam@127 158 k->vl);
cannam@127 159
cannam@127 160 /* copy from buf to O */
cannam@127 161 X(cpy2d_co)(k->buf,
cannam@127 162 k->O + n0l * k->os0 + n1l * k->os1,
cannam@127 163 n0u - n0l, k->vl, k->os0,
cannam@127 164 n1u - n1l, k->vl * (n0u - n0l), k->os1,
cannam@127 165 k->vl);
cannam@127 166 }
cannam@127 167
cannam@127 168
cannam@127 169 void X(cpy2d_tiled)(R *I, R *O,
cannam@127 170 INT n0, INT is0, INT os0,
cannam@127 171 INT n1, INT is1, INT os1, INT vl)
cannam@127 172 {
cannam@127 173 INT tilesz = X(compute_tilesz)(vl,
cannam@127 174 1 /* input array */
cannam@127 175 + 1 /* ouput array */);
cannam@127 176 struct cpy2d_closure k;
cannam@127 177 k.I = I;
cannam@127 178 k.O = O;
cannam@127 179 k.is0 = is0;
cannam@127 180 k.os0 = os0;
cannam@127 181 k.is1 = is1;
cannam@127 182 k.os1 = os1;
cannam@127 183 k.vl = vl;
cannam@127 184 k.buf = 0; /* unused */
cannam@127 185 X(tile2d)(0, n0, 0, n1, tilesz, dotile, &k);
cannam@127 186 }
cannam@127 187
cannam@127 188 void X(cpy2d_tiledbuf)(R *I, R *O,
cannam@127 189 INT n0, INT is0, INT os0,
cannam@127 190 INT n1, INT is1, INT os1, INT vl)
cannam@127 191 {
cannam@127 192 R buf[CACHESIZE / (2 * sizeof(R))];
cannam@127 193 /* input and buffer in cache, or
cannam@127 194 output and buffer in cache */
cannam@127 195 INT tilesz = X(compute_tilesz)(vl, 2);
cannam@127 196 struct cpy2d_closure k;
cannam@127 197 k.I = I;
cannam@127 198 k.O = O;
cannam@127 199 k.is0 = is0;
cannam@127 200 k.os0 = os0;
cannam@127 201 k.is1 = is1;
cannam@127 202 k.os1 = os1;
cannam@127 203 k.vl = vl;
cannam@127 204 k.buf = buf;
cannam@127 205 A(tilesz * tilesz * vl * sizeof(R) <= sizeof(buf));
cannam@127 206 X(tile2d)(0, n0, 0, n1, tilesz, dotile_buf, &k);
cannam@127 207 }