forked from timblechmann/nova-simd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simd_pan.hpp
163 lines (130 loc) · 4.67 KB
/
simd_pan.hpp
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
161
162
163
// simd functions for panning
// Copyright (C) 2009, 2010 Tim Blechmann
//
// 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; see the file COPYING. If not, write to
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
#ifndef SIMD_PAN_HPP
#define SIMD_PAN_HPP
#include "vec.hpp"
#if defined(__GNUC__) && defined(NDEBUG)
#define always_inline inline __attribute__((always_inline))
#else
#define always_inline inline
#endif
namespace nova
{
template <typename F>
inline void pan2_vec(F * out0, F * out1, const F * in, F factor0, F factor1, unsigned int n)
{
do
{
F sig = *in++;
*out0++ = sig * factor0;
*out1++ = sig * factor1;
} while(--n);
}
template <typename F>
inline void pan2_vec(F * out0, F * out1, const F * in, F factor0, F slope0, F factor1, F slope1, unsigned int n)
{
do
{
F sig = *in++;
*out0++ = sig * factor0;
*out1++ = sig * factor1;
factor0 += slope0;
factor1 += slope1;
} while(--n);
}
namespace detail
{
template <typename F, unsigned int n>
struct pan2
{
static const int offset = vec<F>::size;
static always_inline void mp_iteration(F * out0, F * out1, const F * in, vec<F> const & factor0, vec<F> const & factor1)
{
vec<F> vin, vout0, vout1;
vin.load_aligned(in);
vout0 = vin * factor0;
vout1 = vin * factor1;
vout0.store_aligned(out0);
vout1.store_aligned(out1);
pan2<F, n-offset>::mp_iteration(out0+offset, out1+offset, in+offset, factor0, factor1);
}
static always_inline void mp_iteration(F * out0, F * out1, const F * in, vec<F> & factor0, vec<F> const & slope0,
vec<F> & factor1, vec<F> const & slope1)
{
vec<F> vin, vout0, vout1;
vin.load_aligned(in);
vout0 = vin * factor0;
vout1 = vin * factor1;
vout0.store_aligned(out0);
vout1.store_aligned(out1);
factor0 += slope0;
factor1 += slope1;
pan2<F, n-offset>::mp_iteration(out0+offset, out1+offset, in+offset, factor0, slope0, factor1, slope1);
}
};
template <typename F>
struct pan2<F, 0>
{
static always_inline void mp_iteration(F * out0, F * out1, const F * in, vec<F> const & factor0, vec<F> const & factor1)
{}
static always_inline void mp_iteration(F * out0, F * out1, const F * in, vec<F> & factor0, vec<F> const & slope0,
vec<F> & factor1, vec<F> const & slope1)
{}
};
} /* namespace detail */
template <typename F>
inline void pan2_vec_simd(F * out0, F * out1, const F * in, F factor0, F factor1, unsigned int n)
{
vec<F> vf0(factor0), vf1(factor1);
const int per_loop = vec<F>::objects_per_cacheline;
n /= per_loop;
do {
detail::pan2<F, per_loop>::mp_iteration(out0, out1, in, vf0, vf1);
out0 += per_loop; out1 += per_loop; in += per_loop;
} while(--n);
}
template <unsigned int n, typename F>
inline void pan2_vec_simd(F * out0, F * out1, const F * in, F factor0, F factor1)
{
vec<F> vf0(factor0), vf1(factor1);
detail::pan2<F, n>::mp_iteration(out0, out1, in, vf0, vf1);
}
template <typename F>
inline void pan2_vec_simd(F * out0, F * out1, const F * in, F factor0, F slope0, F factor1, F slope1, unsigned int n)
{
const int per_loop = vec<F>::objects_per_cacheline;
vec<F> vf0, vf1, vslope0, vslope1;
vslope0.set_vec(vf0.set_slope(factor0, slope0));
vslope1.set_vec(vf1.set_slope(factor1, slope1));
n /= per_loop;
do {
detail::pan2<F, per_loop>::mp_iteration(out0, out1, in, vf0, vslope0, vf1, vslope1);
out0 += per_loop; out1 += per_loop; in += per_loop;
} while(--n);
}
template <unsigned int n, typename F>
inline void pan2_vec_simd(F * out0, F * out1, const F * in, F factor0, F slope0, F factor1, F slope1)
{
vec<F> vf0, vf1, vslope0, vslope1;
vslope0.set_vec(vf0.set_slope(factor0, slope0));
vslope1.set_vec(vf1.set_slope(factor1, slope1));
detail::pan2<F, n>::mp_iteration(out0, out1, in, vf0, vslope0, vf1, vslope1);
}
} /* namespace nova */
#undef always_inline
#endif /* SIMD_PAN_HPP */