Vc  1.1.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  }
114 
116  template <typename S1, typename IT>
117  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
118  "instead.") void scatter(S1 *array, EntryType S1::*member1,
119  Vc_ALIGNED_PARAMETER(IT) indexes) const
120  {
121  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
122  array, indexes)[member1]
123  .scatterArguments());
124  }
126  template <typename S1, typename IT>
127  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
128  "instead.") void scatter(S1 *array, EntryType S1::*member1,
129  Vc_ALIGNED_PARAMETER(IT) indexes,
130  MaskArgument mask) const
131  {
132  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
133  array, indexes)[member1]
134  .scatterArguments(),
135  mask);
136  }
138  template <typename S1, typename S2, typename IT>
139  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
140  "instead.") void scatter(S1 *array, S2 S1::*member1,
141  EntryType S2::*member2,
142  Vc_ALIGNED_PARAMETER(IT) indexes) const
143  {
144  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
145  array, indexes)[member1][member2]
146  .scatterArguments());
147  }
149  template <typename S1, typename S2, typename IT>
150  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
151  "instead.") void scatter(S1 *array, S2 S1::*member1,
152  EntryType S2::*member2,
153  Vc_ALIGNED_PARAMETER(IT) indexes,
154  MaskArgument mask) const
155  {
156  scatter(Common::SubscriptOperation<S1, IT, std::ratio<1, 1>, true>(
157  array, indexes)[member1][member2]
158  .scatterArguments(),
159  mask);
160  }
162  template <typename S1, typename IT1, typename IT2>
163  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
164  "instead.") void scatter(S1 *array, EntryType *S1::*ptrMember1,
165  Vc_ALIGNED_PARAMETER(IT1) outerIndexes,
166  Vc_ALIGNED_PARAMETER(IT2)
167  innerIndexes) const
168  {
169  scatter(Common::SubscriptOperation<S1, IT1, std::ratio<1, 1>, true>(
170  array, outerIndexes)[ptrMember1][innerIndexes]
171  .scatterArguments());
172  }
174  template <typename S1, typename IT1, typename IT2>
175  inline Vc_DEPRECATED("use the subscript operator to Vc::array or Vc::vector "
176  "instead.") void scatter(S1 *array, EntryType *S1::*ptrMember1,
177  Vc_ALIGNED_PARAMETER(IT1) outerIndexes,
178  Vc_ALIGNED_PARAMETER(IT2) innerIndexes,
179  MaskArgument mask) const
180  {
181  scatter(Common::SubscriptOperation<S1, IT1, std::ratio<1, 1>, true>(
182  array, outerIndexes)[ptrMember1][innerIndexes]
183  .scatterArguments(),
184  mask);
185  }
186 
188 
195  template <typename MT, typename IT>
197  Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args) const
198  {
199  scatter(args.address, args.indexes);
200  }
201 
202  template <typename MT, typename IT>
203  Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args, MaskArgument mask) const
204  {
205  scatter(args.address, args.indexes, mask);
206  }
208 #undef Vc_ASSERT_SCATTER_PARAMETER_TYPES_