]> git.uio.no Git - u/mrichter/AliRoot.git/blame - Vc/include/Vc/common/vectortuple.h
update to Vc 0.7.3-dev
[u/mrichter/AliRoot.git] / Vc / include / Vc / common / vectortuple.h
CommitLineData
c017a39f 1/* This file is part of the Vc library. {{{
2
3 Copyright (C) 2012 Matthias Kretz <kretz@kde.org>
4
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.
9
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.
14
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/>.
17
18}}}*/
19
20#ifndef VC_COMMON_VECTORTUPLE_H
21#define VC_COMMON_VECTORTUPLE_H
22
23#include "macros.h"
24
25namespace AliRoot {
26namespace Vc
27{
28namespace Common
29{
30
31template<size_t StructSize, typename V> struct InterleavedMemoryReadAccess;
32
33template<int Length, typename V> struct VectorTuple;
34template<typename V> struct VectorTuple<2, V>
35{
36 typedef typename V::EntryType T;
37 typedef V &VC_RESTRICT Reference;
38 Reference l, r;
39
40 Vc_ALWAYS_INLINE VectorTuple(Reference a, Reference b)
41 : l(a), r(b)
42 {
43 }
44
45 Vc_ALWAYS_INLINE VectorTuple<3, V> operator,(V &a) const
46 {
47 return VectorTuple<3, V>(*this, a);
48 }
49
50 Vc_ALWAYS_INLINE VectorTuple<3, const V> operator,(const V &a) const
51 {
52 return VectorTuple<3, const V>(*this, a);
53 }
54
55 template<size_t StructSize>
56 Vc_ALWAYS_INLINE void operator=(const InterleavedMemoryReadAccess<StructSize, V> &access) const
57 {
58 VC_STATIC_ASSERT(2 <= StructSize, You_are_trying_to_extract_more_data_from_the_struct_than_it_has);
59 access.deinterleave(l, r);
60 }
61};
62
63template<typename V> struct VectorTuple<2, const V>
64{
65 typedef typename V::EntryType T;
66 typedef const V &VC_RESTRICT Reference;
67 Reference l, r;
68
69 Vc_ALWAYS_INLINE VectorTuple(Reference a, Reference b)
70 : l(a), r(b)
71 {
72 }
73
74 Vc_ALWAYS_INLINE VectorTuple<3, const V> operator,(const V &a) const
75 {
76 return VectorTuple<3, const V>(*this, a);
77 }
78};
79
80#define _VC_VECTORTUPLE_SPECIALIZATION(LENGTH, parameters) \
81template<typename V> struct VectorTuple<LENGTH, V> \
82{ \
83 typedef typename V::EntryType T; \
84 typedef V &VC_RESTRICT Reference; \
85 const VectorTuple<LENGTH - 1, V> &l; \
86 Reference r; \
87 \
88 Vc_ALWAYS_INLINE VectorTuple(const VectorTuple<LENGTH - 1, V> &tuple, Reference a) \
89 : l(tuple), r(a) \
90 { \
91 } \
92 \
93 Vc_ALWAYS_INLINE VectorTuple<LENGTH + 1, V> operator,(V &a) const \
94 { \
95 return VectorTuple<LENGTH + 1, V>(*this, a); \
96 } \
97 \
98 template<size_t StructSize> \
99 Vc_ALWAYS_INLINE void operator=(const InterleavedMemoryReadAccess<StructSize, V> &access) const \
100 { \
101 VC_STATIC_ASSERT(LENGTH <= StructSize, You_are_trying_to_extract_more_data_from_the_struct_than_it_has); \
102 access.deinterleave parameters; \
103 } \
104}; \
105template<typename V> struct VectorTuple<LENGTH, const V> \
106{ \
107 typedef typename V::EntryType T; \
108 typedef const V &VC_RESTRICT Reference; \
109 const VectorTuple<LENGTH - 1, const V> &l; \
110 Reference r; \
111 \
112 Vc_ALWAYS_INLINE VectorTuple(const VectorTuple<LENGTH - 1, const V> &tuple, Reference a) \
113 : l(tuple), r(a) \
114 { \
115 } \
116 \
117 Vc_ALWAYS_INLINE VectorTuple<LENGTH + 1, const V> operator,(const V &a) const \
118 { \
119 return VectorTuple<LENGTH + 1, const V>(*this, a); \
120 } \
121}
122_VC_VECTORTUPLE_SPECIALIZATION(3, (l.l, l.r, r));
123_VC_VECTORTUPLE_SPECIALIZATION(4, (l.l.l, l.l.r, l.r, r));
124_VC_VECTORTUPLE_SPECIALIZATION(5, (l.l.l.l, l.l.l.r, l.l.r, l.r, r));
125_VC_VECTORTUPLE_SPECIALIZATION(6, (l.l.l.l.l, l.l.l.l.r, l.l.l.r, l.l.r, l.r, r));
126_VC_VECTORTUPLE_SPECIALIZATION(7, (l.l.l.l.l.l, l.l.l.l.l.r, l.l.l.l.r, l.l.l.r, l.l.r, l.r, r));
127_VC_VECTORTUPLE_SPECIALIZATION(8, (l.l.l.l.l.l.l, l.l.l.l.l.l.r, l.l.l.l.l.r, l.l.l.l.r, l.l.l.r, l.l.r, l.r, r));
128// VC_STATIC_ASSERT(false, You_are_gathering_too_many_vectors__This_is_not_implemented);
129
130} // namespace Common
131
132#ifdef VC_IMPL_Scalar
133namespace Scalar
134#elif defined VC_IMPL_SSE
135namespace SSE
136#elif defined VC_IMPL_AVX
137namespace AVX
138#endif
139{
140
141template<typename T>
142Vc_ALWAYS_INLINE Common::VectorTuple<2, Vc::Vector<T> > operator,(Vc::Vector<T> &a, Vc::Vector<T> &b)
143{
144 return Common::VectorTuple<2, Vc::Vector<T> >(a, b);
145}
146
147template<typename T>
148Vc_ALWAYS_INLINE Common::VectorTuple<2, const Vc::Vector<T> > operator,(const Vc::Vector<T> &a, const Vc::Vector<T> &b)
149{
150 return Common::VectorTuple<2, const Vc::Vector<T> >(a, b);
151}
152
153} // namespace Scalar/SSE/AVX
154
155} // namespace Vc
156} // namespace AliRoot
157
158#include "undomacros.h"
159
160#endif // VC_COMMON_VECTORTUPLE_H