Vc 1.4.5
SIMD Vector Classes for C++
 
Loading...
Searching...
No Matches
gatherinterface.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_CURRENT_CLASS_NAME
29#error "incorrect use of common/gatherinterface.h: Vc_CURRENT_CLASS_NAME must be defined to the current class name for declaring constructors."
30#endif
31
33// gathers
34// A gather takes the following arguments:
35// 1. A const pointer to memory of any type that can convert to EntryType
36// 2. An indexes “vector”. The requirement is that the type implements the subscript operator,
37// stores «Size» valid index values, and each offset to the pointer above yields a valid
38// memory location for reading.
39// 3. Optionally the third argument may be a mask. The mask disables several memory reads and
40// thus removes the requirements in (2.) for the disabled entries.
41
42private:
53 // enable_if<std::can_convert<MT, EntryType>::value &&
54 // has_subscript_operator<IT>::value>
55 template <class MT, class IT, int Scale = 1>
56 inline void gatherImplementation(const Common::GatherArguments<MT, IT, Scale> &);
57
62 template <class MT, class IT, int Scale = 1>
63 inline void gatherImplementation(const Common::GatherArguments<MT, IT, Scale> &,
64 MaskArgument mask);
65
66public:
67#define Vc_ASSERT_GATHER_PARAMETER_TYPES_ \
68 static_assert( \
69 std::is_convertible<MT, EntryType>::value, \
70 "The memory pointer needs to point to a type that can be converted to the " \
71 "EntryType of this SIMD vector type."); \
72 static_assert( \
73 Vc::Traits::has_subscript_operator<IT>::value, \
74 "The indexes argument must be a type that implements the subscript operator."); \
75 static_assert( \
76 !Traits::is_simd_vector<IT>::value || \
77 Traits::simd_vector_size<IT>::value >= Size, \
78 "If you use a SIMD vector for the indexes parameter, the index vector must " \
79 "have at least as many entries as this SIMD vector."); \
80 static_assert( \
81 !std::is_array<T>::value || \
82 (std::rank<T>::value == 1 && \
83 (std::extent<T>::value == 0 || std::extent<T>::value >= Size)), \
84 "If you use a simple array for the indexes parameter, the array must have " \
85 "at least as many entries as this SIMD vector.")
86
138
140 template <typename MT, typename IT,
141 typename = enable_if<Traits::has_subscript_operator<IT>::value>>
142 Vc_INTRINSIC Vc_CURRENT_CLASS_NAME(const MT *mem, const IT &indexes)
143 {
144 Vc_ASSERT_GATHER_PARAMETER_TYPES_;
145 gatherImplementation(
146 Common::make_gather<1>(mem, Common::convertIndexVector(indexes)));
147 }
148
149 template <class MT, class IT, int Scale>
150 Vc_INTRINSIC Vc_CURRENT_CLASS_NAME(const Common::GatherArguments<MT, IT, Scale> &args)
151 {
152 Vc_ASSERT_GATHER_PARAMETER_TYPES_;
153 gatherImplementation(args);
154 }
155
157 template <typename MT, typename IT,
158 typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
159 Vc_INTRINSIC Vc_CURRENT_CLASS_NAME(const MT *mem, const IT &indexes,
160 MaskArgument mask)
161 {
162 Vc_ASSERT_GATHER_PARAMETER_TYPES_;
163 gatherImplementation(
164 Common::make_gather<1>(mem, Common::convertIndexVector(indexes)), mask);
165 }
166
167 template <class MT, class IT, int Scale>
168 Vc_INTRINSIC Vc_CURRENT_CLASS_NAME(const Common::GatherArguments<MT, IT, Scale> &args,
169 MaskArgument mask)
170 {
171 Vc_ASSERT_GATHER_PARAMETER_TYPES_;
172 gatherImplementation(args, mask);
173 }
174
176 template <typename MT, typename IT,
177 typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
178 Vc_INTRINSIC void gather(const MT *mem, const IT &indexes)
179 {
180 Vc_ASSERT_GATHER_PARAMETER_TYPES_;
181 gatherImplementation(
182 Common::make_gather<1>(mem, Common::convertIndexVector(indexes)));
183 }
184
186 template <typename MT, typename IT,
187 typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
188 Vc_INTRINSIC void gather(const MT *mem, const IT &indexes, MaskArgument mask)
189 {
190 Vc_ASSERT_GATHER_PARAMETER_TYPES_;
191 gatherImplementation(
192 Common::make_gather<1>(mem, Common::convertIndexVector(indexes)), mask);
193 }
195
196#include "gatherinterface_deprecated.h"
197
205 template <class MT, class IT, int Scale>
206 Vc_INTRINSIC void gather(const Common::GatherArguments<MT, IT, Scale> &args)
207 {
208 Vc_ASSERT_GATHER_PARAMETER_TYPES_;
209 gatherImplementation(args);
210 }
211
212 template <class MT, class IT, int Scale>
213 Vc_INTRINSIC void gather(const Common::GatherArguments<MT, IT, Scale> &args,
214 MaskArgument mask)
215 {
216 Vc_ASSERT_GATHER_PARAMETER_TYPES_;
217 gatherImplementation(args, mask);
218 }
220
221#undef Vc_ASSERT_GATHER_PARAMETER_TYPES_