File indexing completed on 2025-12-15 10:31:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
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
0042
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 }
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 }
0096 }
0097
0098 #endif