Vc  1.3.2-dev
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 
4 Redistribution and use in source and binary forms, with or without
5 modification, 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 
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 ON 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
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 }}}*/
27 
29 // scatters
30 // A scatter takes the following arguments:
31 // 1. A pointer to memory of any type that EntryType can convert to.
32 // 2. An indexes “vector”. The requirement is that the type implements the subscript operator,
33 // stores «Size» valid index values, and each offset to the pointer above yields a valid
34 // memory location for reading.
35 // 3. Optionally the third argument may be a mask. The mask disables several memory stores and
36 // thus removes the requirements in (2.) for the disabled entries.
37 
38 private:
49  // enable_if<std::can_convert<MT, EntryType>::value && has_subscript_operator<IT>::value>
50  template <typename MT, typename IT>
51  inline void scatterImplementation(MT *mem, IT &&indexes) const;
52 
57  template <typename MT, typename IT>
58  inline void scatterImplementation(MT *mem, IT &&indexes, MaskArgument mask) const;
59 
60 public:
61 #define Vc_ASSERT_SCATTER_PARAMETER_TYPES_ \
62  static_assert( \
63  std::is_convertible<EntryType, MT>::value, \
64  "The memory pointer needs to point to a type that the EntryType of this " \
65  "SIMD vector type can be converted to."); \
66  static_assert( \
67  Vc::Traits::has_subscript_operator<IT>::value, \
68  "The indexes argument must be a type that implements the subscript operator."); \
69  static_assert( \
70  !Traits::is_simd_vector<IT>::value || \
71  Traits::simd_vector_size<IT>::value >= Size, \
72  "If you use a SIMD vector for the indexes parameter, the index vector must " \
73  "have at least as many entries as this SIMD vector."); \
74  static_assert( \
75  !std::is_array<T>::value || \
76  (std::rank<T>::value == 1 && \
77  (std::extent<T>::value == 0 || std::extent<T>::value >= Size)), \
78  "If you use a simple array for the indexes parameter, the array must have " \
79  "at least as many entries as this SIMD vector.")
80 
92 
95  template <typename MT,
96  typename IT,
97  typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
98  Vc_INTRINSIC void scatter(MT *mem, IT &&indexes) const
99  {
100  Vc_ASSERT_SCATTER_PARAMETER_TYPES_;
101  scatterImplementation(mem, std::forward<IT>(indexes));
102  }
103 
105  template <typename MT,
106  typename IT,
107  typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
108  Vc_INTRINSIC void scatter(MT *mem, IT &&indexes, MaskArgument mask) const
109  {
110  Vc_ASSERT_SCATTER_PARAMETER_TYPES_;
111  scatterImplementation(mem, std::forward<IT>(indexes), mask);
112  }
114 
117 
130  template <typename S1, typename IT>
131  Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
132  "instead.") inline void scatter(S1 *array, EntryType S1::*member1,
133  IT indexes) const
134  {
135  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
136  array, indexes)[member1]
137  .scatterArguments());
138  }
139 
153  template <typename S1, typename IT>
154  Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
155  "instead.") inline void scatter(S1 *array, EntryType S1::*member1,
156  IT indexes, MaskArgument mask) const
157  {
158  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
159  array, indexes)[member1]
160  .scatterArguments(),
161  mask);
162  }
163 
178  template <typename S1, typename S2, typename IT>
179  Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
180  "instead.") inline void scatter(S1 *array, S2 S1::*member1,
181  EntryType S2::*member2,
182  IT indexes) const
183  {
184  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
185  array, indexes)[member1][member2]
186  .scatterArguments());
187  }
188 
204  template <typename S1, typename S2, typename IT>
205  Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
206  "instead.") inline void scatter(S1 *array, S2 S1::*member1,
207  EntryType S2::*member2, IT indexes,
208  MaskArgument mask) const
209  {
210  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
211  array, indexes)[member1][member2]
212  .scatterArguments(),
213  mask);
214  }
215 
227  template <typename S1, typename IT1, typename IT2>
228  Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
229  "instead.") inline void scatter(S1 *array, EntryType *S1::*ptrMember1,
230  IT1 outerIndexes,
231  IT2 innerIndexes) const
232  {
233  scatter(Common::SubscriptOperation<S1, IT1, std::ratio<1, 1>, true>(
234  array, outerIndexes)[ptrMember1][innerIndexes]
235  .scatterArguments());
236  }
237 
250  template <typename S1, typename IT1, typename IT2>
251  Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
252  "instead.") inline void scatter(S1 *array, EntryType *S1::*ptrMember1,
253  IT1 outerIndexes, IT2 innerIndexes,
254  MaskArgument mask) const
255  {
256  scatter(Common::SubscriptOperation<S1, IT1, std::ratio<1, 1>, true>(
257  array, outerIndexes)[ptrMember1][innerIndexes]
258  .scatterArguments(),
259  mask);
260  }
262 
269  template <typename MT, typename IT>
271  Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args) const
272  {
273  scatter(args.address, args.indexes);
274  }
275 
276  template <typename MT, typename IT>
277  Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args, MaskArgument mask) const
278  {
279  scatter(args.address, args.indexes, mask);
280  }
282 #undef Vc_ASSERT_SCATTER_PARAMETER_TYPES_