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