Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:25:48

0001 /*  This file is part of the Vc library. {{{
0002 Copyright © 2014-2015 Matthias Kretz <kretz@kde.org>
0003 
0004 Redistribution and use in source and binary forms, with or without
0005 modification, are permitted provided that the following conditions are met:
0006     * Redistributions of source code must retain the above copyright
0007       notice, this list of conditions and the following disclaimer.
0008     * Redistributions in binary form must reproduce the above copyright
0009       notice, this list of conditions and the following disclaimer in the
0010       documentation and/or other materials provided with the distribution.
0011     * Neither the names of contributing organizations nor the
0012       names of its contributors may be used to endorse or promote products
0013       derived from this software without specific prior written permission.
0014 
0015 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
0016 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
0017 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0018 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
0019 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0020 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
0021 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0022 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0023 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
0024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0025 
0026 }}}*/
0027 
0028 ///////////////////////////////////////////////////////////////////////////////////////////
0029 // scatters
0030 // A scatter takes the following arguments:
0031 // 1. A pointer to memory of any type that EntryType can convert to.
0032 // 2. An indexes “vector”. The requirement is that the type implements the subscript operator,
0033 //    stores «Size» valid index values, and each offset to the pointer above yields a valid
0034 //    memory location for reading.
0035 // 3. Optionally the third argument may be a mask. The mask disables several memory stores and
0036 //    thus removes the requirements in (2.) for the disabled entries.
0037 
0038 private:
0039     /**\internal
0040      * This function implements a scatter given a pointer to memory \p mem and some
0041      * container object storing the scatter \p indexes.
0042      *
0043      * \param mem This pointer must be aligned correctly for the type \p MT. This is the
0044      * natural behavior of C++, so this is typically the case.
0045      * \param indexes This object contains at least \VSize{T} indexes that denote the
0046      * offset in \p mem where the components for the current vector should be copied to.
0047      * The offset is not in Bytes, but in multiples of `sizeof(MT)`.
0048      */
0049     // enable_if<std::can_convert<MT, EntryType>::value && has_subscript_operator<IT>::value>
0050     template <typename MT, typename IT>
0051     inline void scatterImplementation(MT *mem, IT &&indexes) const;
0052 
0053     /**\internal
0054      * This overload of the above function adds a \p mask argument to disable memory
0055      * accesses at the \p indexes offsets where \p mask is \c false.
0056      */
0057     template <typename MT, typename IT>
0058     inline void scatterImplementation(MT *mem, IT &&indexes, MaskArgument mask) const;
0059 
0060 public:
0061 #define Vc_ASSERT_SCATTER_PARAMETER_TYPES_                                               \
0062     static_assert(                                                                       \
0063         std::is_convertible<EntryType, MT>::value,                                       \
0064         "The memory pointer needs to point to a type that the EntryType of this "        \
0065         "SIMD vector type can be converted to.");                                        \
0066     static_assert(                                                                       \
0067         Vc::Traits::has_subscript_operator<IT>::value,                                   \
0068         "The indexes argument must be a type that implements the subscript operator.");  \
0069     static_assert(                                                                       \
0070         !Traits::is_simd_vector<IT>::value ||                                            \
0071             Traits::simd_vector_size<IT>::value >= Size,                                 \
0072         "If you use a SIMD vector for the indexes parameter, the index vector must "     \
0073         "have at least as many entries as this SIMD vector.");                           \
0074     static_assert(                                                                       \
0075         !std::is_array<T>::value ||                                                      \
0076             (std::rank<T>::value == 1 &&                                                 \
0077              (std::extent<T>::value == 0 || std::extent<T>::value >= Size)),             \
0078         "If you use a simple array for the indexes parameter, the array must have "      \
0079         "at least as many entries as this SIMD vector.")
0080 
0081     /**
0082      * \name Scatter functions
0083      *
0084      * Stores a vector to the objects at `mem[indexes[0]]`, `mem[indexes[1]]`,
0085      * `mem[indexes[2]]`, ...
0086      *
0087      * \param mem A pointer to memory which contains objects of type \p MT at the offsets
0088      *            given by \p indexes.
0089      * \param indexes
0090      * \param mask
0091      */
0092     ///@{
0093 
0094     /// Scatter function
0095     template <typename MT,
0096               typename IT,
0097               typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
0098     Vc_INTRINSIC void scatter(MT *mem, IT &&indexes) const
0099     {
0100         Vc_ASSERT_SCATTER_PARAMETER_TYPES_;
0101         scatterImplementation(mem, std::forward<IT>(indexes));
0102     }
0103 
0104     /// Masked scatter function
0105     template <typename MT,
0106               typename IT,
0107               typename = enable_if<Vc::Traits::has_subscript_operator<IT>::value>>
0108     Vc_INTRINSIC void scatter(MT *mem, IT &&indexes, MaskArgument mask) const
0109     {
0110         Vc_ASSERT_SCATTER_PARAMETER_TYPES_;
0111         scatterImplementation(mem, std::forward<IT>(indexes), mask);
0112     }
0113     ///@}
0114 
0115 #include "scatterinterface_deprecated.h"
0116 
0117     /**\internal
0118      * \name Scatter function to use from Vc::Common::subscript_operator
0119      *
0120      * \param args
0121      * \param mask
0122      */
0123     ///@{
0124     template <typename MT, typename IT>
0125     Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args) const
0126     {
0127         scatter(args.address, args.indexes);
0128     }
0129 
0130     template <typename MT, typename IT>
0131     Vc_INTRINSIC void scatter(const Common::ScatterArguments<MT, IT> &args, MaskArgument mask) const
0132     {
0133         scatter(args.address, args.indexes, mask);
0134     }
0135     ///@}
0136 #undef Vc_ASSERT_SCATTER_PARAMETER_TYPES_