annotate src/fftw-3.3.3/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 89f5e221ed7b
children
rev   line source
cannam@95 1 /*
cannam@95 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
cannam@95 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
cannam@95 4 *
cannam@95 5 * This program is free software; you can redistribute it and/or modify
cannam@95 6 * it under the terms of the GNU General Public License as published by
cannam@95 7 * the Free Software Foundation; either version 2 of the License, or
cannam@95 8 * (at your option) any later version.
cannam@95 9 *
cannam@95 10 * This program is distributed in the hope that it will be useful,
cannam@95 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@95 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@95 13 * GNU General Public License for more details.
cannam@95 14 *
cannam@95 15 * You should have received a copy of the GNU General Public License
cannam@95 16 * along with this program; if not, write to the Free Software
cannam@95 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@95 18 *
cannam@95 19 */
cannam@95 20
cannam@95 21 /* out of place 2D copy routines */
cannam@95 22 #include "ifftw.h"
cannam@95 23
cannam@95 24 #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64)
cannam@95 25 # ifdef HAVE_XMMINTRIN_H
cannam@95 26 # include <xmmintrin.h>
cannam@95 27 # define WIDE_TYPE __m128
cannam@95 28 # endif
cannam@95 29 #endif
cannam@95 30
cannam@95 31 #ifndef WIDE_TYPE
cannam@95 32 /* fall back to double, which means that WIDE_TYPE will be unused */
cannam@95 33 # define WIDE_TYPE double
cannam@95 34 #endif
cannam@95 35
cannam@95 36 void X(cpy2d)(R *I, R *O,
cannam@95 37 INT n0, INT is0, INT os0,
cannam@95 38 INT n1, INT is1, INT os1,
cannam@95 39 INT vl)
cannam@95 40 {
cannam@95 41 INT i0, i1, v;
cannam@95 42
cannam@95 43 switch (vl) {
cannam@95 44 case 1:
cannam@95 45 for (i1 = 0; i1 < n1; ++i1)
cannam@95 46 for (i0 = 0; i0 < n0; ++i0) {
cannam@95 47 R x0 = I[i0 * is0 + i1 * is1];
cannam@95 48 O[i0 * os0 + i1 * os1] = x0;
cannam@95 49 }
cannam@95 50 break;
cannam@95 51 case 2:
cannam@95 52 if (1
cannam@95 53 && (2 * sizeof(R) == sizeof(WIDE_TYPE))
cannam@95 54 && (sizeof(WIDE_TYPE) > sizeof(double))
cannam@95 55 && (((size_t)I) % sizeof(WIDE_TYPE) == 0)
cannam@95 56 && (((size_t)O) % sizeof(WIDE_TYPE) == 0)
cannam@95 57 && ((is0 & 1) == 0)
cannam@95 58 && ((is1 & 1) == 0)
cannam@95 59 && ((os0 & 1) == 0)
cannam@95 60 && ((os1 & 1) == 0)) {
cannam@95 61 /* copy R[2] as WIDE_TYPE if WIDE_TYPE is large
cannam@95 62 enough to hold R[2], and if the input is
cannam@95 63 properly aligned. This is a win when R==double
cannam@95 64 and WIDE_TYPE is 128 bits. */
cannam@95 65 for (i1 = 0; i1 < n1; ++i1)
cannam@95 66 for (i0 = 0; i0 < n0; ++i0) {
cannam@95 67 *(WIDE_TYPE *)&O[i0 * os0 + i1 * os1] =
cannam@95 68 *(WIDE_TYPE *)&I[i0 * is0 + i1 * is1];
cannam@95 69 }
cannam@95 70 } else if (1
cannam@95 71 && (2 * sizeof(R) == sizeof(double))
cannam@95 72 && (((size_t)I) % sizeof(double) == 0)
cannam@95 73 && (((size_t)O) % sizeof(double) == 0)
cannam@95 74 && ((is0 & 1) == 0)
cannam@95 75 && ((is1 & 1) == 0)
cannam@95 76 && ((os0 & 1) == 0)
cannam@95 77 && ((os1 & 1) == 0)) {
cannam@95 78 /* copy R[2] as double if double is large enough to
cannam@95 79 hold R[2], and if the input is properly aligned.
cannam@95 80 This case applies when R==float */
cannam@95 81 for (i1 = 0; i1 < n1; ++i1)
cannam@95 82 for (i0 = 0; i0 < n0; ++i0) {
cannam@95 83 *(double *)&O[i0 * os0 + i1 * os1] =
cannam@95 84 *(double *)&I[i0 * is0 + i1 * is1];
cannam@95 85 }
cannam@95 86 } else {
cannam@95 87 for (i1 = 0; i1 < n1; ++i1)
cannam@95 88 for (i0 = 0; i0 < n0; ++i0) {
cannam@95 89 R x0 = I[i0 * is0 + i1 * is1];
cannam@95 90 R x1 = I[i0 * is0 + i1 * is1 + 1];
cannam@95 91 O[i0 * os0 + i1 * os1] = x0;
cannam@95 92 O[i0 * os0 + i1 * os1 + 1] = x1;
cannam@95 93 }
cannam@95 94 }
cannam@95 95 break;
cannam@95 96 default:
cannam@95 97 for (i1 = 0; i1 < n1; ++i1)
cannam@95 98 for (i0 = 0; i0 < n0; ++i0)
cannam@95 99 for (v = 0; v < vl; ++v) {
cannam@95 100 R x0 = I[i0 * is0 + i1 * is1 + v];
cannam@95 101 O[i0 * os0 + i1 * os1 + v] = x0;
cannam@95 102 }
cannam@95 103 break;
cannam@95 104 }
cannam@95 105 }
cannam@95 106
cannam@95 107 /* like cpy2d, but read input contiguously if possible */
cannam@95 108 void X(cpy2d_ci)(R *I, R *O,
cannam@95 109 INT n0, INT is0, INT os0,
cannam@95 110 INT n1, INT is1, INT os1,
cannam@95 111 INT vl)
cannam@95 112 {
cannam@95 113 if (IABS(is0) < IABS(is1)) /* inner loop is for n0 */
cannam@95 114 X(cpy2d) (I, O, n0, is0, os0, n1, is1, os1, vl);
cannam@95 115 else
cannam@95 116 X(cpy2d) (I, O, n1, is1, os1, n0, is0, os0, vl);
cannam@95 117 }
cannam@95 118
cannam@95 119 /* like cpy2d, but write output contiguously if possible */
cannam@95 120 void X(cpy2d_co)(R *I, R *O,
cannam@95 121 INT n0, INT is0, INT os0,
cannam@95 122 INT n1, INT is1, INT os1,
cannam@95 123 INT vl)
cannam@95 124 {
cannam@95 125 if (IABS(os0) < IABS(os1)) /* inner loop is for n0 */
cannam@95 126 X(cpy2d) (I, O, n0, is0, os0, n1, is1, os1, vl);
cannam@95 127 else
cannam@95 128 X(cpy2d) (I, O, n1, is1, os1, n0, is0, os0, vl);
cannam@95 129 }
cannam@95 130
cannam@95 131
cannam@95 132 /* tiled copy routines */
cannam@95 133 struct cpy2d_closure {
cannam@95 134 R *I, *O;
cannam@95 135 INT is0, os0, is1, os1, vl;
cannam@95 136 R *buf;
cannam@95 137 };
cannam@95 138
cannam@95 139 static void dotile(INT n0l, INT n0u, INT n1l, INT n1u, void *args)
cannam@95 140 {
cannam@95 141 struct cpy2d_closure *k = (struct cpy2d_closure *)args;
cannam@95 142 X(cpy2d)(k->I + n0l * k->is0 + n1l * k->is1,
cannam@95 143 k->O + n0l * k->os0 + n1l * k->os1,
cannam@95 144 n0u - n0l, k->is0, k->os0,
cannam@95 145 n1u - n1l, k->is1, k->os1,
cannam@95 146 k->vl);
cannam@95 147 }
cannam@95 148
cannam@95 149 static void dotile_buf(INT n0l, INT n0u, INT n1l, INT n1u, void *args)
cannam@95 150 {
cannam@95 151 struct cpy2d_closure *k = (struct cpy2d_closure *)args;
cannam@95 152
cannam@95 153 /* copy from I to buf */
cannam@95 154 X(cpy2d_ci)(k->I + n0l * k->is0 + n1l * k->is1,
cannam@95 155 k->buf,
cannam@95 156 n0u - n0l, k->is0, k->vl,
cannam@95 157 n1u - n1l, k->is1, k->vl * (n0u - n0l),
cannam@95 158 k->vl);
cannam@95 159
cannam@95 160 /* copy from buf to O */
cannam@95 161 X(cpy2d_co)(k->buf,
cannam@95 162 k->O + n0l * k->os0 + n1l * k->os1,
cannam@95 163 n0u - n0l, k->vl, k->os0,
cannam@95 164 n1u - n1l, k->vl * (n0u - n0l), k->os1,
cannam@95 165 k->vl);
cannam@95 166 }
cannam@95 167
cannam@95 168
cannam@95 169 void X(cpy2d_tiled)(R *I, R *O,
cannam@95 170 INT n0, INT is0, INT os0,
cannam@95 171 INT n1, INT is1, INT os1, INT vl)
cannam@95 172 {
cannam@95 173 INT tilesz = X(compute_tilesz)(vl,
cannam@95 174 1 /* input array */
cannam@95 175 + 1 /* ouput array */);
cannam@95 176 struct cpy2d_closure k;
cannam@95 177 k.I = I;
cannam@95 178 k.O = O;
cannam@95 179 k.is0 = is0;
cannam@95 180 k.os0 = os0;
cannam@95 181 k.is1 = is1;
cannam@95 182 k.os1 = os1;
cannam@95 183 k.vl = vl;
cannam@95 184 k.buf = 0; /* unused */
cannam@95 185 X(tile2d)(0, n0, 0, n1, tilesz, dotile, &k);
cannam@95 186 }
cannam@95 187
cannam@95 188 void X(cpy2d_tiledbuf)(R *I, R *O,
cannam@95 189 INT n0, INT is0, INT os0,
cannam@95 190 INT n1, INT is1, INT os1, INT vl)
cannam@95 191 {
cannam@95 192 R buf[CACHESIZE / (2 * sizeof(R))];
cannam@95 193 /* input and buffer in cache, or
cannam@95 194 output and buffer in cache */
cannam@95 195 INT tilesz = X(compute_tilesz)(vl, 2);
cannam@95 196 struct cpy2d_closure k;
cannam@95 197 k.I = I;
cannam@95 198 k.O = O;
cannam@95 199 k.is0 = is0;
cannam@95 200 k.os0 = os0;
cannam@95 201 k.is1 = is1;
cannam@95 202 k.os1 = os1;
cannam@95 203 k.vl = vl;
cannam@95 204 k.buf = buf;
cannam@95 205 A(tilesz * tilesz * vl * sizeof(R) <= sizeof(buf));
cannam@95 206 X(tile2d)(0, n0, 0, n1, tilesz, dotile_buf, &k);
cannam@95 207 }