Vc 1.4.5
SIMD Vector Classes for C++
 
Loading...
Searching...
No Matches
simdarrayfwd.h
1/* This file is part of the Vc library. {{{
2Copyright © 2014-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_SIMDARRAYFWD_H_
29#define VC_COMMON_SIMDARRAYFWD_H_
30
31#include "../scalar/types.h"
32#include "../sse/types.h"
33#include "../avx/types.h"
34
35#include "utility.h"
36#include "macros.h"
37
38namespace Vc_VERSIONED_NAMESPACE
39{
40// specialization of Vector for fixed_size<N> {{{
41template <class T, int N>
42class Vector<T, simd_abi::fixed_size<N>> : public SimdArray<T, N>
43{
44 using SimdArray<T, N>::SimdArray;
45
46public:
47 // overload copy to force argument passing via the stack. This makes the type more
48 // usable on ABI boundaries
49 Vc_INTRINSIC Vector(const Vector &x) : SimdArray<T, N>(x) {}
50 Vc_INTRINSIC Vector &operator=(const Vector &x)
51 {
52 SimdArray<T, N>::operator=(x);
53 return *this;
54 }
55 Vector() = default;
56
57 using abi_type = simd_abi::fixed_size<N>;
58 using abi = abi_type;
59
60 Vc_DEPRECATED("use Vector([](int n) { return n; }) instead of "
61 "Vector::IndexesFromZero()") static Vector IndexesFromZero()
62 {
63 return Vector([](size_t i) -> T { return i; });
64 }
65 Vc_DEPRECATED("use 0 instead of Vector::Zero()") static Vector Zero() { return 0; }
66 Vc_DEPRECATED("use 1 instead of Vector::One()") static Vector One() { return 1; }
67};
68
69template <class T, int N>
70class Mask<T, simd_abi::fixed_size<N>> : public SimdMaskArray<T, N>
71{
72 using SimdMaskArray<T, N>::SimdMaskArray;
73
74public:
75 // overload copy to force argument passing via the stack. This makes the type more
76 // usable on ABI boundaries
77 Vc_INTRINSIC Mask(const Mask &x) : SimdMaskArray<T, N>(x) {}
78 Vc_INTRINSIC Mask &operator=(const Mask &x)
79 {
80 SimdMaskArray<T, N>::operator=(x);
81 return *this;
82 }
83 Mask() = default;
84
85 using abi_type = simd_abi::fixed_size<N>;
86 using abi = abi_type;
87};
88// }}}
89
94template <typename T, std::size_t N> struct SimdArrayTraits {
95 static constexpr std::size_t N0 = Common::left_size<N>();
96 static constexpr std::size_t N1 = Common::right_size<N>();
97
98 using storage_type0 = fixed_size_simd<T, N0>;
99 using storage_type1 = fixed_size_simd<T, N1>;
100};
101
102template <typename T, std::size_t N, typename VectorType, std::size_t VectorSize>
103Vc_INTRINSIC_L typename SimdArrayTraits<T, N>::storage_type0 &internal_data0(
104 SimdArray<T, N, VectorType, VectorSize> &x) Vc_INTRINSIC_R;
105template <typename T, std::size_t N, typename VectorType, std::size_t VectorSize>
106Vc_INTRINSIC_L typename SimdArrayTraits<T, N>::storage_type1 &internal_data1(
107 SimdArray<T, N, VectorType, VectorSize> &x) Vc_INTRINSIC_R;
108template <typename T, std::size_t N, typename VectorType, std::size_t VectorSize>
109Vc_INTRINSIC_L const typename SimdArrayTraits<T, N>::storage_type0 &internal_data0(
110 const SimdArray<T, N, VectorType, VectorSize> &x) Vc_INTRINSIC_R;
111template <typename T, std::size_t N, typename VectorType, std::size_t VectorSize>
112Vc_INTRINSIC_L const typename SimdArrayTraits<T, N>::storage_type1 &internal_data1(
113 const SimdArray<T, N, VectorType, VectorSize> &x) Vc_INTRINSIC_R;
114
115template <typename T, std::size_t N, typename V>
116Vc_INTRINSIC_L V &internal_data(SimdArray<T, N, V, N> &x) Vc_INTRINSIC_R;
117template <typename T, std::size_t N, typename V>
118Vc_INTRINSIC_L const V &internal_data(const SimdArray<T, N, V, N> &x) Vc_INTRINSIC_R;
119
120namespace Traits
121{
122// is_fixed_size_simd {{{1
123template <class T> struct is_fixed_size_simd : std::false_type {
124};
125template <class T, int N>
126struct is_fixed_size_simd<fixed_size_simd<T, N>> : std::true_type {
127};
128template <class T, int N>
129struct is_fixed_size_simd<fixed_size_simd_mask<T, N>> : std::true_type {
130};
131
132// is_simd_vector_internal {{{1
133template <class T, int N>
134struct is_simd_vector_internal<fixed_size_simd<T, N>> : is_valid_vector_argument<T> {};
135
136// is_simd_mask_internal {{{1
137template <class T, int N>
138struct is_simd_mask_internal<fixed_size_simd_mask<T, N>> : is_valid_vector_argument<T> {};
139
140// is_atomic_simdarray_internal {{{1
141template <typename T, std::size_t N, typename V>
142struct is_atomic_simdarray_internal<SimdArray<T, N, V, N>> : is_valid_vector_argument<T> {};
143template <typename T, int N>
144struct is_atomic_simdarray_internal<fixed_size_simd<T, N>>
145 : is_atomic_simdarray_internal<SimdArray<T, N>> {
146};
147
148// is_atomic_simd_mask_array_internal {{{1
149template <typename T, std::size_t N, typename V>
150struct is_atomic_simd_mask_array_internal<SimdMaskArray<T, N, V, N>>
151 : is_valid_vector_argument<T> {
152};
153template <typename T, int N>
154struct is_atomic_simd_mask_array_internal<fixed_size_simd_mask<T, N>>
155 : is_atomic_simd_mask_array_internal<SimdMaskArray<T, N>> {
156};
157
158// is_simdarray_internal {{{1
159template <typename T, std::size_t N, typename VectorType, std::size_t M>
160struct is_simdarray_internal<SimdArray<T, N, VectorType, M>>
161 : is_valid_vector_argument<T> {
162};
163template <typename T, int N>
164struct is_simdarray_internal<fixed_size_simd<T, N>> : is_valid_vector_argument<T> {
165};
166
167// is_simd_mask_array_internal {{{1
168template <typename T, std::size_t N, typename VectorType, std::size_t M>
169struct is_simd_mask_array_internal<SimdMaskArray<T, N, VectorType, M>>
170 : is_valid_vector_argument<T> {
171};
172template <typename T, int N>
173struct is_simd_mask_array_internal<fixed_size_simd_mask<T, N>>
174 : is_valid_vector_argument<T> {
175};
176
177// is_integral_internal {{{1
178template <typename T, std::size_t N, typename V, std::size_t M>
179struct is_integral_internal<SimdArray<T, N, V, M>, false> : std::is_integral<T> {
180};
181
182// is_floating_point_internal {{{1
183template <typename T, std::size_t N, typename V, std::size_t M>
184struct is_floating_point_internal<SimdArray<T, N, V, M>, false>
185 : std::is_floating_point<T> {
186};
187
188// is_signed_internal {{{1
189template <typename T, std::size_t N, typename V, std::size_t M>
190struct is_signed_internal<SimdArray<T, N, V, M>, false> : std::is_signed<T> {
191};
192
193// is_unsigned_internal {{{1
194template <typename T, std::size_t N, typename V, std::size_t M>
195struct is_unsigned_internal<SimdArray<T, N, V, M>, false> : std::is_unsigned<T> {
196};
197
198// has_no_allocated_data_impl {{{1
199template <typename T, std::size_t N>
200struct has_no_allocated_data_impl<Vc::SimdArray<T, N>> : std::true_type {
201};
202
203// }}}1
204} // namespace Traits
205
206} // namespace Vc
207
208#endif // VC_COMMON_SIMDARRAYFWD_H_
209
210// vim: foldmethod=marker
Vector Classes Namespace.
Definition dox.h:585