3
* $Id: glsimd.c,v 1.3.2.1 2002/03/04 19:32:59 richi Exp $
5
* Copyright (C) 2001 Richard Guenther
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
/* Forward declarations. */
32
void c_scalar_product_1d(SAMPLE *result, long cnt,
33
SAMPLE *c1, SAMPLE f1);
34
void c_scalar_product_1dI(SAMPLE *result_c1, long cnt, SAMPLE f1);
35
void c_scalar_product_2d(SAMPLE *result, long cnt,
36
SAMPLE *c1, SAMPLE f1,
37
SAMPLE *c2, SAMPLE f2);
38
void c_scalar_product_2dI(SAMPLE *result_c1, long cnt, SAMPLE f1,
39
SAMPLE *c2, SAMPLE f2);
40
void c_scalar_product_3d(SAMPLE *result, long cnt,
41
SAMPLE *c1, SAMPLE f1,
42
SAMPLE *c2, SAMPLE f2,
43
SAMPLE *c3, SAMPLE f3);
44
void c_scalar_product_3dI(SAMPLE *result_c1, long cnt, SAMPLE f1,
45
SAMPLE *c2, SAMPLE f2,
46
SAMPLE *c3, SAMPLE f3);
47
void c_scalar_product_Nd(SAMPLE *result, long cnt,
48
SAMPLE **c, SAMPLE *f, long dim);
51
/* The simd operations table. Statically initialized to the C variants
52
* to allow use without glsimd_init(). */
53
struct glsimd_ops_table glsimd = {
54
scalar_product_1d: c_scalar_product_1d,
55
scalar_product_1dI: c_scalar_product_1dI,
56
scalar_product_2d: c_scalar_product_2d,
57
scalar_product_2dI: c_scalar_product_2dI,
58
scalar_product_3d: c_scalar_product_3d,
59
scalar_product_3dI: c_scalar_product_3dI,
60
scalar_product_Nd: c_scalar_product_Nd
64
void glsimd_init(int force_c)
66
/* Init with C only operations, i.e. safe default. */
67
glsimd.scalar_product_1d = c_scalar_product_1d;
68
glsimd.scalar_product_1dI = c_scalar_product_1dI;
69
glsimd.scalar_product_2d = c_scalar_product_2d;
70
glsimd.scalar_product_2dI = c_scalar_product_2dI;
71
glsimd.scalar_product_3d = c_scalar_product_3d;
72
glsimd.scalar_product_3dI = c_scalar_product_3dI;
73
glsimd.scalar_product_Nd = c_scalar_product_Nd;
75
/* Forced C only operations? */
79
/* Also, with SAMPLE == double, optimized versions will
80
* certainly not work. */
85
/* FIXME: now we should
86
* 1. detect hardware capabilities
87
* 2. benchmark(!?) alternatives
93
void c_scalar_product_1d(SAMPLE *result, long cnt,
94
SAMPLE *c1, SAMPLE f1)
97
*(result++) = f1 * *(c1++);
99
void c_scalar_product_1dI(SAMPLE *result_c1, long cnt, SAMPLE f1)
102
*(result_c1++) *= f1;
104
void c_scalar_product_2d(SAMPLE *result, long cnt,
105
SAMPLE *c1, SAMPLE f1,
106
SAMPLE *c2, SAMPLE f2)
109
*(result++) = f1 * *(c1++)
112
void c_scalar_product_2dI(SAMPLE *result_c1, long cnt, SAMPLE f1,
113
SAMPLE *c2, SAMPLE f2)
116
*result_c1 = f1 * *result_c1
121
void c_scalar_product_3d(SAMPLE *result, long cnt,
122
SAMPLE *c1, SAMPLE f1,
123
SAMPLE *c2, SAMPLE f2,
124
SAMPLE *c3, SAMPLE f3)
127
*(result++) = f1 * *(c1++)
131
void c_scalar_product_3dI(SAMPLE *result_c1, long cnt, SAMPLE f1,
132
SAMPLE *c2, SAMPLE f2,
133
SAMPLE *c3, SAMPLE f3)
136
*result_c1 = f1 * *result_c1
142
void c_scalar_product_Nd(SAMPLE *result, long cnt,
143
SAMPLE **c, SAMPLE *f, long dim)
148
memset(result, 0, cnt*sizeof(SAMPLE));
150
} else if (dim == 1) {
151
glsimd.scalar_product_1d(result, cnt, c[0], f[0]);
153
} else if (dim == 2) {
154
glsimd.scalar_product_2d(result, cnt,
155
c[0], f[0], c[1], f[1]);
157
} else if (dim == 3) {
158
glsimd.scalar_product_3d(result, cnt, c[0], f[0],
159
c[1], f[1], c[2], f[2]);
162
for (i=0; i<cnt; i++) {
163
/* Minimum is 4d now. */
164
*result = f[0] * c[0][i]
168
for (j=4; j<dim; j++)
169
*result += f[j] * c[j][i];