Vc  1.4.2
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 
115 #include "scatterinterface_deprecated.h"
116 
123  template <typename MT, typename IT>
125  Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args) const
126  {
127  scatter(args.address, args.indexes);
128  }
129 
130  template <typename MT, typename IT>
131  Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args, MaskArgument mask) const
132  {
133  scatter(args.address, args.indexes, mask);
134  }
136 #undef Vc_ASSERT_SCATTER_PARAMETER_TYPES_