Vc  1.0.0-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 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(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(!Traits::is_simd_vector<IT>::value || Traits::simd_vector_size<IT>::value >= Size, \
70  "If you use a SIMD vector for the indexes parameter, the index vector must " \
71  "have at least as many entries as this SIMD vector."); \
72  static_assert(!std::is_array<T>::value || \
73  (std::rank<T>::value == 1 && \
74  (std::extent<T>::value == 0 || std::extent<T>::value >= Size)), \
75  "If you use a simple array for the indexes parameter, the array must have " \
76  "at least as many entries as this SIMD vector.")
77 
89 
92  template <typename MT,
93  typename IT,
94  typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
95  Vc_INTRINSIC void scatter(MT *mem, IT &&indexes) const
96  {
97  Vc_ASSERT_SCATTER_PARAMETER_TYPES__;
98  scatterImplementation(mem, std::forward<IT>(indexes));
99  }
100 
102  template <typename MT,
103  typename IT,
104  typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
105  Vc_INTRINSIC void scatter(MT *mem, IT &&indexes, MaskArgument mask) const
106  {
107  Vc_ASSERT_SCATTER_PARAMETER_TYPES__;
108  scatterImplementation(mem, std::forward<IT>(indexes), mask);
109  }
111 
118  template <typename MT, typename IT>
120  Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args) const
121  {
122  scatter(args.address, args.indexes);
123  }
124 
125  template <typename MT, typename IT>
126  Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args, MaskArgument mask) const
127  {
128  scatter(args.address, args.indexes, mask);
129  }
131 #undef Vc_ASSERT_SCATTER_PARAMETER_TYPES__