1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
* Copyright (c) 2003, 2006 Matteo Frigo
* Copyright (c) 2003, 2006 Massachusetts Institute of Technology
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* out of place 2D copy routines */
#include "ifftw.h"
void X(cpy2d)(R *I, R *O,
INT n0, INT is0, INT os0,
INT n1, INT is1, INT os1,
INT vl)
{
INT i0, i1, v;
switch (vl) {
case 1:
for (i1 = 0; i1 < n1; ++i1)
for (i0 = 0; i0 < n0; ++i0) {
R x0 = I[i0 * is0 + i1 * is1];
O[i0 * os0 + i1 * os1] = x0;
}
break;
case 2:
for (i1 = 0; i1 < n1; ++i1)
for (i0 = 0; i0 < n0; ++i0) {
R x0 = I[i0 * is0 + i1 * is1];
R x1 = I[i0 * is0 + i1 * is1 + 1];
O[i0 * os0 + i1 * os1] = x0;
O[i0 * os0 + i1 * os1 + 1] = x1;
}
break;
default:
for (i1 = 0; i1 < n1; ++i1)
for (i0 = 0; i0 < n0; ++i0)
for (v = 0; v < vl; ++v) {
R x0 = I[i0 * is0 + i1 * is1 + v];
O[i0 * os0 + i1 * os1 + v] = x0;
}
break;
}
}
/* like cpy2d, but read input contiguously if possible */
void X(cpy2d_ci)(R *I, R *O,
INT n0, INT is0, INT os0,
INT n1, INT is1, INT os1,
INT vl)
{
if (IABS(is0) < IABS(is1)) /* inner loop is for n0 */
X(cpy2d) (I, O, n0, is0, os0, n1, is1, os1, vl);
else
X(cpy2d) (I, O, n1, is1, os1, n0, is0, os0, vl);
}
/* like cpy2d, but write output contiguously if possible */
void X(cpy2d_co)(R *I, R *O,
INT n0, INT is0, INT os0,
INT n1, INT is1, INT os1,
INT vl)
{
if (IABS(os0) < IABS(os1)) /* inner loop is for n0 */
X(cpy2d) (I, O, n0, is0, os0, n1, is1, os1, vl);
else
X(cpy2d) (I, O, n1, is1, os1, n0, is0, os0, vl);
}
/* tiled copy routines */
struct cpy2d_closure {
R *I, *O;
INT is0, os0, is1, os1, vl;
R *buf;
};
static void dotile(INT n0l, INT n0u, INT n1l, INT n1u, void *args)
{
struct cpy2d_closure *k = (struct cpy2d_closure *)args;
X(cpy2d)(k->I + n0l * k->is0 + n1l * k->is1,
k->O + n0l * k->os0 + n1l * k->os1,
n0u - n0l, k->is0, k->os0,
n1u - n1l, k->is1, k->os1,
k->vl);
}
static void dotile_buf(INT n0l, INT n0u, INT n1l, INT n1u, void *args)
{
struct cpy2d_closure *k = (struct cpy2d_closure *)args;
/* copy from I to buf */
X(cpy2d_ci)(k->I + n0l * k->is0 + n1l * k->is1,
k->buf,
n0u - n0l, k->is0, k->vl,
n1u - n1l, k->is1, k->vl * (n0u - n0l),
k->vl);
/* copy from buf to O */
X(cpy2d_co)(k->buf,
k->O + n0l * k->os0 + n1l * k->os1,
n0u - n0l, k->vl, k->os0,
n1u - n1l, k->vl * (n0u - n0l), k->os1,
k->vl);
}
void X(cpy2d_tiled)(R *I, R *O,
INT n0, INT is0, INT os0,
INT n1, INT is1, INT os1, INT vl)
{
INT tilesz = X(compute_tilesz)(vl,
1 /* input array */
+ 1 /* ouput array */);
struct cpy2d_closure k;
k.I = I;
k.O = O;
k.is0 = is0;
k.os0 = os0;
k.is1 = is1;
k.os1 = os1;
k.vl = vl;
k.buf = 0; /* unused */
X(tile2d)(0, n0, 0, n1, tilesz, dotile, &k);
}
void X(cpy2d_tiledbuf)(R *I, R *O,
INT n0, INT is0, INT os0,
INT n1, INT is1, INT os1, INT vl)
{
R buf[CACHESIZE / (2 * sizeof(R))];
/* input and buffer in cache, or
output and buffer in cache */
INT tilesz = X(compute_tilesz)(vl, 2);
struct cpy2d_closure k;
k.I = I;
k.O = O;
k.is0 = is0;
k.os0 = os0;
k.is1 = is1;
k.os1 = os1;
k.vl = vl;
k.buf = buf;
A(tilesz * tilesz * vl * sizeof(R) <= sizeof(buf));
X(tile2d)(0, n0, 0, n1, tilesz, dotile_buf, &k);
}
|