Vc  1.2.0
SIMD Vector Classes for C++
scatterinterface.h
1 /* This file is part of the Vc library. {{{
2 Copyright © 2014-2015 Matthias Kretz <kretz@kde.org>
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the names of contributing organizations nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 }}}*/
28 
30 // scatters
31 // A scatter takes the following arguments:
32 // 1. A pointer to memory of any type that EntryType can convert to.
33 // 2. An indexes “vector”. The requirement is that the type implements the subscript operator,
34 // stores «Size» valid index values, and each offset to the pointer above yields a valid
35 // memory location for reading.
36 // 3. Optionally the third argument may be a mask. The mask disables several memory stores and
37 // thus removes the requirements in (2.) for the disabled entries.
38 
39 private:
50  // enable_if<std::can_convert<MT, EntryType>::value && has_subscript_operator<IT>::value>
51  template <typename MT, typename IT>
52  inline void scatterImplementation(MT *mem, IT &&indexes) const;
53 
58  template <typename MT, typename IT>
59  inline void scatterImplementation(MT *mem, IT &&indexes, MaskArgument mask) const;
60 
61 public:
62 #define Vc_ASSERT_SCATTER_PARAMETER_TYPES_ \
63  static_assert( \
64  std::is_convertible<EntryType, MT>::value, \
65  "The memory pointer needs to point to a type that the EntryType of this " \
66  "SIMD vector type can be converted to."); \
67  static_assert( \
68  Vc::Traits::has_subscript_operator<IT>::value, \
69  "The indexes argument must be a type that implements the subscript operator."); \
70  static_assert( \
71  !Traits::is_simd_vector<IT>::value || \
72  Traits::simd_vector_size<IT>::value >= Size, \
73  "If you use a SIMD vector for the indexes parameter, the index vector must " \
74  "have at least as many entries as this SIMD vector."); \
75  static_assert( \
76  !std::is_array<T>::value || \
77  (std::rank<T>::value == 1 && \
78  (std::extent<T>::value == 0 || std::extent<T>::value >= Size)), \
79  "If you use a simple array for the indexes parameter, the array must have " \
80  "at least as many entries as this SIMD vector.")
81 
93 
96  template <typename MT,
97  typename IT,
98  typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
99  Vc_INTRINSIC void scatter(MT *mem, IT &&indexes) const
100  {
101  Vc_ASSERT_SCATTER_PARAMETER_TYPES_;
102  scatterImplementation(mem, std::forward<IT>(indexes));
103  }
104 
106  template <typename MT,
107  typename IT,
108  typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
109  Vc_INTRINSIC void scatter(MT *mem, IT &&indexes, MaskArgument mask) const
110  {
111  Vc_ASSERT_SCATTER_PARAMETER_TYPES_;
112  scatterImplementation(mem, std::forward<IT>(indexes), mask);
113  }
115 
118 
131  template <typename S1, typename IT>
132  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
133  "instead.") void scatter(S1 *array, EntryType S1::*member1,
134  Vc_ALIGNED_PARAMETER(IT) indexes) const
135  {
136  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
137  array, indexes)[member1]
138  .scatterArguments());
139  }
140 
154  template <typename S1, typename IT>
155  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
156  "instead.") void scatter(S1 *array, EntryType S1::*member1,
157  Vc_ALIGNED_PARAMETER(IT) indexes,
158  MaskArgument mask) const
159  {
160  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
161  array, indexes)[member1]
162  .scatterArguments(),
163  mask);
164  }
165 
180  template <typename S1, typename S2, typename IT>
181  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
182  "instead.") void scatter(S1 *array, S2 S1::*member1,
183  EntryType S2::*member2,
184  Vc_ALIGNED_PARAMETER(IT) indexes) const
185  {
186  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
187  array, indexes)[member1][member2]
188  .scatterArguments());
189  }
190 
206  template <typename S1, typename S2, typename IT>
207  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
208  "instead.") void scatter(S1 *array, S2 S1::*member1,
209  EntryType S2::*member2,
210  Vc_ALIGNED_PARAMETER(IT) indexes,
211  MaskArgument mask) const
212  {
213  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
214  array, indexes)[member1][member2]
215  .scatterArguments(),
216  mask);
217  }
218 
230  template <typename S1, typename IT1, typename IT2>
231  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
232  "instead.") void scatter(S1 *array, EntryType *S1::*ptrMember1,
233  Vc_ALIGNED_PARAMETER(IT1) outerIndexes,
234  Vc_ALIGNED_PARAMETER(IT2)
235  innerIndexes) const
236  {
237  scatter(Common::SubscriptOperation<S1, IT1, std::ratio<1, 1>, true>(
238  array, outerIndexes)[ptrMember1][innerIndexes]
239  .scatterArguments());
240  }
241 
254  template <typename S1, typename IT1, typename IT2>
255  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
256  "instead.") void scatter(S1 *array, EntryType *S1::*ptrMember1,
257  Vc_ALIGNED_PARAMETER(IT1) outerIndexes,
258  Vc_ALIGNED_PARAMETER(IT2) innerIndexes,
259  MaskArgument mask) const
260  {
261  scatter(Common::SubscriptOperation<S1, IT1, std::ratio<1, 1>, true>(
262  array, outerIndexes)[ptrMember1][innerIndexes]
263  .scatterArguments(),
264  mask);
265  }
267 
274  template <typename MT, typename IT>
276  Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args) const
277  {
278  scatter(args.address, args.indexes);
279  }
280 
281  template <typename MT, typename IT>
282  Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args, MaskArgument mask) const
283  {
284  scatter(args.address, args.indexes, mask);
285  }
287 #undef Vc_ASSERT_SCATTER_PARAMETER_TYPES_