Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:31:45

0001 /*  This file is part of the Vc library. {{{
0002 Copyright © 2013-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 #ifndef VC_COMMON_MASKENTRY_H_
0029 #define VC_COMMON_MASKENTRY_H_
0030 
0031 #include "macros.h"
0032 
0033 namespace Vc_VERSIONED_NAMESPACE
0034 {
0035 namespace Common
0036 {
0037 
0038 namespace
0039 {
0040     template<size_t Bytes> struct MaskBoolStorage;
0041     // the following for typedefs must use std::intN_t and NOT! Vc::intN_t. The latter
0042     // segfaults ICC 15.0.3.
0043     template<> struct MaskBoolStorage<1> { typedef std::int8_t  type; };
0044     template<> struct MaskBoolStorage<2> { typedef std::int16_t type; };
0045     template<> struct MaskBoolStorage<4> { typedef std::int32_t type; };
0046     template<> struct MaskBoolStorage<8> { typedef std::int64_t type; };
0047 } // anonymous namespace
0048 
0049 template<size_t Bytes> class MaskBool
0050 {
0051     typedef typename MaskBoolStorage<Bytes>::type storage_type Vc_MAY_ALIAS;
0052     storage_type data;
0053 public:
0054     constexpr MaskBool(bool x) noexcept : data(x ? -1 : 0) {}
0055     Vc_ALWAYS_INLINE MaskBool &operator=(bool x) noexcept { data = x ? -1 : 0; return *this; }
0056     template <typename T, typename = enable_if<(!std::is_same<T, bool>::value &&
0057                                                 std::is_fundamental<T>::value)>>
0058     Vc_ALWAYS_INLINE MaskBool &operator=(T x) noexcept
0059     {
0060         data = reinterpret_cast<const storage_type &>(x);
0061         return *this;
0062     }
0063 
0064     Vc_ALWAYS_INLINE MaskBool(const MaskBool &) noexcept = default;
0065     Vc_ALWAYS_INLINE MaskBool &operator=(const MaskBool &) noexcept = default;
0066 
0067     template <typename T, typename = enable_if<(std::is_same<T, bool>::value ||
0068                                                 (std::is_fundamental<T>::value &&
0069                                                  sizeof(storage_type) == sizeof(T)))>>
0070     constexpr operator T() const noexcept
0071     {
0072         return std::is_same<T, bool>::value ? T((data & 1) != 0) : aliasing_cast<T>(data);
0073     }
0074 } Vc_MAY_ALIAS;
0075 
0076 template <typename A,
0077           typename B,
0078           typename std::enable_if<
0079               std::is_convertible<A, bool>::value &&std::is_convertible<B, bool>::value,
0080               int>::type = 0>
0081 constexpr bool operator==(A &&a, B &&b)
0082 {
0083     return static_cast<bool>(a) == static_cast<bool>(b);
0084 }
0085 template <typename A,
0086           typename B,
0087           typename std::enable_if<
0088               std::is_convertible<A, bool>::value &&std::is_convertible<B, bool>::value,
0089               int>::type = 0>
0090 constexpr bool operator!=(A &&a, B &&b)
0091 {
0092     return static_cast<bool>(a) != static_cast<bool>(b);
0093 }
0094 
0095 }  // namespace Common
0096 }  // namespace Vc
0097 
0098 #endif // VC_COMMON_MASKENTRY_H_