~ubuntu-branches/ubuntu/utopic/glame/utopic

« back to all changes in this revision

Viewing changes to src/hash/glsimd.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-09 17:14:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020409171412-jzpnov7mbz2w6zsr
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * glsimd.c
 
3
 * $Id: glsimd.c,v 1.3.2.1 2002/03/04 19:32:59 richi Exp $
 
4
 *
 
5
 * Copyright (C) 2001 Richard Guenther
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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
 
20
 *
 
21
 */
 
22
 
 
23
#ifdef HAVE_CONFIG_H
 
24
#include <config.h>
 
25
#endif
 
26
 
 
27
#include <string.h>
 
28
#include "glsimd.h"
 
29
 
 
30
 
 
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);
 
49
 
 
50
 
 
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
 
61
};
 
62
 
 
63
 
 
64
void glsimd_init(int force_c)
 
65
{
 
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;
 
74
 
 
75
        /* Forced C only operations? */
 
76
        if (force_c)
 
77
                return;
 
78
 
 
79
        /* Also, with SAMPLE == double, optimized versions will
 
80
         * certainly not work. */
 
81
#ifndef SAMPLE_FLOAT
 
82
        return;
 
83
#endif
 
84
 
 
85
        /* FIXME: now we should
 
86
         * 1. detect hardware capabilities
 
87
         * 2. benchmark(!?) alternatives
 
88
         * 3. select the best
 
89
         */
 
90
}
 
91
 
 
92
 
 
93
void c_scalar_product_1d(SAMPLE *result, long cnt,
 
94
                         SAMPLE *c1, SAMPLE f1)
 
95
{
 
96
        while (cnt--)
 
97
                *(result++) = f1 * *(c1++);
 
98
}
 
99
void c_scalar_product_1dI(SAMPLE *result_c1, long cnt, SAMPLE f1)
 
100
{
 
101
        while (cnt--)
 
102
                *(result_c1++) *= f1;
 
103
}
 
104
void c_scalar_product_2d(SAMPLE *result, long cnt,
 
105
                         SAMPLE *c1, SAMPLE f1,
 
106
                         SAMPLE *c2, SAMPLE f2)
 
107
{
 
108
        while (cnt--)
 
109
                *(result++) = f1 * *(c1++)
 
110
                        + f2 * *(c2++);
 
111
}
 
112
void c_scalar_product_2dI(SAMPLE *result_c1, long cnt, SAMPLE f1,
 
113
                          SAMPLE *c2, SAMPLE f2)
 
114
{
 
115
        while (cnt--) {
 
116
                *result_c1 = f1 * *result_c1
 
117
                        + f2 * *(c2++);
 
118
                result_c1++;
 
119
        }
 
120
}
 
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)
 
125
{
 
126
        while (cnt--)
 
127
                *(result++) = f1 * *(c1++)
 
128
                        + f2 * *(c2++)
 
129
                        + f3 * *(c3++);
 
130
}
 
131
void c_scalar_product_3dI(SAMPLE *result_c1, long cnt, SAMPLE f1,
 
132
                          SAMPLE *c2, SAMPLE f2,
 
133
                          SAMPLE *c3, SAMPLE f3)
 
134
{
 
135
        while (cnt--) {
 
136
                *result_c1 = f1 * *result_c1
 
137
                        + f2 * *(c2++)
 
138
                        + f3 * *(c3++);
 
139
                result_c1++;
 
140
        }
 
141
}
 
142
void c_scalar_product_Nd(SAMPLE *result, long cnt,
 
143
                         SAMPLE **c, SAMPLE *f, long dim)
 
144
{
 
145
        int i,j;
 
146
 
 
147
        if (dim == 0) {
 
148
                memset(result, 0, cnt*sizeof(SAMPLE));
 
149
                return;
 
150
        } else if (dim == 1) {
 
151
                glsimd.scalar_product_1d(result, cnt, c[0], f[0]);
 
152
                return;
 
153
        } else if (dim == 2) {
 
154
                glsimd.scalar_product_2d(result, cnt,
 
155
                                         c[0], f[0], c[1], f[1]);
 
156
                return;
 
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]);
 
160
                return;
 
161
        }
 
162
        for (i=0; i<cnt; i++) {
 
163
                /* Minimum is 4d now. */
 
164
                *result = f[0] * c[0][i]
 
165
                        + f[1] * c[1][i]
 
166
                        + f[2] * c[2][i]
 
167
                        + f[3] * c[3][i];
 
168
                for (j=4; j<dim; j++)
 
169
                        *result += f[j] * c[j][i];
 
170
                result++;
 
171
        }
 
172
}