1
/* This file is part of the Vc library.
3
Copyright (C) 2010-2012 Matthias Kretz <kretz@kde.org>
5
Vc is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as
7
published by the Free Software Foundation, either version 3 of
8
the License, or (at your option) any later version.
10
Vc is distributed in the hope that it will be useful, but
11
WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU Lesser General Public License for more details.
15
You should have received a copy of the GNU Lesser General Public
16
License along with Vc. If not, see <http://www.gnu.org/licenses/>.
25
template<typename V> void reads()
27
typedef typename V::EntryType T;
28
typedef typename V::IndexType I;
32
for (int i = 0; i < V::Size; ++i) {
36
a = static_cast<V>(I::IndexesFromZero());
37
for (int i = 0; i < V::Size; ++i) {
44
template<typename V, size_t Index>
45
inline void readsConstantIndexTest(VC_ALIGNED_PARAMETER(V) a, VC_ALIGNED_PARAMETER(V) b)
47
typedef typename V::EntryType T;
51
COMPARE(x, zero) << Index;
55
COMPARE(x, y) << Index;
59
template<typename V, size_t Index>
60
struct ReadsConstantIndex
62
ReadsConstantIndex(VC_ALIGNED_PARAMETER(V) a, VC_ALIGNED_PARAMETER(V) b)
64
readsConstantIndexTest<V, Index>(a, b);
65
ReadsConstantIndex<V, Index - 1>(a, b);
71
struct ReadsConstantIndex<V, 0>
73
ReadsConstantIndex(VC_ALIGNED_PARAMETER(V) a, VC_ALIGNED_PARAMETER(V) b)
75
readsConstantIndexTest<V, 0>(a, b);
79
template<typename V> void readsConstantIndex()
81
typedef typename V::IndexType I;
84
V b = static_cast<V>(I::IndexesFromZero());
85
ReadsConstantIndex<V, V::Size - 1>(a, b);
88
template<typename V> void writes()
90
typedef typename V::EntryType T;
91
typedef typename V::IndexType I;
94
for (int i = 0; i < V::Size; ++i) {
95
a[i] = static_cast<T>(i);
97
V b = static_cast<V>(I::IndexesFromZero());
108
} else if (V::Size == 4) {
116
} else if (V::Size == 8 || V::Size == 16) {
124
} else if (V::Size == 2) { // a = [0, 1]; b = [0, 1]
125
a(a == 0) += two; // a = [2, 1]
126
a[1] += one; // a = [2, 2]
127
a(a == 2) += one; // a = [3, 3]
128
b(b == 0) += one; // b = [1, 1]
129
b(b == 1) += one; // b = [2, 2]
130
b(b == 2) += one; // b = [3, 3]
133
FAIL() << "unsupported Vector::Size";
137
int main(int argc, char **argv)
139
initTest(argc, argv);
142
testAllTypes(writes);
143
testAllTypes(readsConstantIndex);
144
//testAllTypes(writesConstantIndex);