Vc 1.4.5
SIMD Vector Classes for C++
 
Loading...
Searching...
No Matches
vectortuple.h
1/* This file is part of the Vc library. {{{
2Copyright © 2012-2015 Matthias Kretz <kretz@kde.org>
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
11 * Neither the names of contributing organizations nor the
12 names of its contributors may be used to endorse or promote products
13 derived from this software without specific prior written permission.
14
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26}}}*/
27
28#ifndef VC_COMMON_VECTORTUPLE_H_
29#define VC_COMMON_VECTORTUPLE_H_
30
31#include "transpose.h"
32#include "macros.h"
33
34namespace Vc_VERSIONED_NAMESPACE
35{
36namespace Common
37{
38
39template<size_t StructSize, typename V, typename I, bool Readonly = true> struct InterleavedMemoryReadAccess;
40
41template <int Length, typename V> class VectorReferenceArray
42{
43 typedef typename V::EntryType T;
44 typedef V &Vc_RESTRICT Reference;
45 std::array<V * Vc_RESTRICT, Length> r;
46
47 typedef make_index_sequence<Length> IndexSequence;
48
49 template <typename VV, std::size_t... Indexes>
50 constexpr VectorReferenceArray<Length + 1, VV> appendOneReference(
51 VV &a, index_sequence<Indexes...>) const
52 {
53 return {*r[Indexes]..., a};
54 }
55
56 template <typename A, std::size_t... Indexes>
57 Vc_INTRINSIC void callDeinterleave(const A &access, index_sequence<Indexes...>) const
58 {
59 access.deinterleave(*r[Indexes]...);
60 }
61
62public:
63 template <typename... Us, typename = enable_if<(sizeof...(Us) == Length)>>
64 constexpr VectorReferenceArray(Us &&... args)
65 : r{{std::addressof(std::forward<Us>(args))...}}
66 {
67 }
68
69 template <typename VV, typename = enable_if<!std::is_const<V>::value &&
70 std::is_same<VV, V>::value>>
71 Vc_DEPRECATED("build the tuple with Vc::tie instead") constexpr VectorReferenceArray<
72 Length + 1, V>
73 operator,(VV &a) const &&
74 {
75 return appendOneReference(a, IndexSequence());
76 }
77
78 Vc_DEPRECATED("build the tuple with Vc::tie instead") constexpr VectorReferenceArray<
79 Length + 1, const V>
80 operator,(const V &a) const &&
81 {
82 return appendOneReference(a, IndexSequence());
83 }
84
85 template <size_t StructSize, typename I, bool RO>
86 Vc_ALWAYS_INLINE enable_if<(Length <= StructSize), void> operator=(
87 const InterleavedMemoryReadAccess<StructSize, V, I, RO> &access) &&
88 {
89 callDeinterleave(access, IndexSequence());
90 }
91
92 template <size_t StructSize, typename I, bool RO>
93 enable_if<(Length > StructSize), void> operator=(
94 const InterleavedMemoryReadAccess<StructSize, V, I, RO> &access) && =
95 delete; //("You are trying to extract more data from the struct than it has");
96
97 template <typename... Inputs> void operator=(TransposeProxy<Inputs...> &&proxy) &&
98 {
99 transpose_impl(TransposeTag<Length, sizeof...(Inputs)>(), &r[0], proxy);
100 }
101
102 template <typename T, typename IndexVector, typename Scale, bool Flag>
103 void operator=(SubscriptOperation<T, IndexVector, Scale, Flag> &&sub) &&
104 {
105 const auto &args = std::move(sub).gatherArguments();
106 //const IndexVector args.indexes;
107 //const T *const args.address;
108 Common::InterleavedMemoryReadAccess<1, V, Traits::decay<decltype(args.indexes)>>
109 deinterleaver(args.address, args.indexes);
110 callDeinterleave(deinterleaver, IndexSequence());
111 }
112
113 Vc_ALWAYS_INLINE Reference operator[](std::size_t i) { return *r[i]; }
114};
115
116} // namespace Common
117
118template <typename T, typename Abi>
119Vc_DEPRECATED("build the tuple with Vc::tie instead")
120constexpr Common::VectorReferenceArray<2, Vc::Vector<T, Abi>>
121operator,(Vc::Vector<T, Abi> &a, Vc::Vector<T, Abi> &b)
122{
123 return {a, b};
124}
125
126template <typename T, typename Abi>
127Vc_DEPRECATED("build the tuple with Vc::tie instead")
128constexpr Common::VectorReferenceArray<2, const Vc::Vector<T, Abi>>
129operator,(const Vc::Vector<T, Abi> &a, const Vc::Vector<T, Abi> &b)
130{
131 return {a, b};
132}
133
134template <typename V, typename... Vs>
135constexpr Common::VectorReferenceArray<sizeof...(Vs) + 1,
136 typename std::remove_reference<V>::type>
137 tie(V &&a, Vs &&... b)
138{
139 return {std::forward<V>(a), std::forward<Vs>(b)...};
140}
141
142} // namespace Vc
143
144#endif // VC_COMMON_VECTORTUPLE_H_
Vector Classes Namespace.
Definition dox.h:585