DPC++ Runtime
Runtime libraries for oneAPI DPC++
simd_mask_impl.hpp
Go to the documentation of this file.
1 //==------------ - simd_mask_impl.hpp - DPC++ Explicit SIMD API ----------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // Implementation detail of Explicit SIMD mask class.
9 //===----------------------------------------------------------------------===//
10 
11 #pragma once
12 
16 
17 namespace sycl {
18 inline namespace _V1 {
19 namespace ext::intel::esimd::detail {
20 
23 
56 template <typename T, int N>
58  : public simd_obj_impl<
59  T, N, simd_mask_impl<T, N>,
60  std::enable_if_t<std::is_same_v<simd_mask_elem_type, T>>> {
64 
65 public:
67  using raw_element_type = T;
69  using element_type = T;
71  using raw_vector_type = typename base_type::raw_vector_type;
72  static_assert(std::is_same_v<raw_vector_type, simd_mask_storage_t<N>> &&
73  "mask impl type mismatch");
74 
76  simd_mask_impl() = default;
77 
79  simd_mask_impl(const simd_mask_impl &other) : base_type(other) {}
80 
83  template <class T1, class = std::enable_if_t<std::is_integral_v<T1>>>
84  simd_mask_impl(T1 Val) : base_type((T)Val) {}
85 
87  // TODO this should be made inaccessible from user code.
88  simd_mask_impl(const raw_vector_type &Val) : base_type(Val) {}
89 
91  template <int N1, class = std::enable_if_t<N1 == N>>
92  simd_mask_impl(const raw_element_type (&&Arr)[N1]) {
93  base_type::template init_from_array<false>(std::move(Arr));
94  }
95 
97  simd_mask_impl(const simd<T, N> &Val) : base_type(Val.data()) {}
98 
100  template <typename T1>
102  : base_type(convert_vector<T, T1, N>(Val.data())) {}
103 
104 private:
106  static constexpr bool mask_size_ok_for_mem_io() {
107  constexpr unsigned Sz = sizeof(element_type) * N;
108  return (Sz >= OperandSize::OWORD) && (Sz % OperandSize::OWORD == 0) &&
109  isPowerOf2(Sz / OperandSize::OWORD) &&
110  (Sz <= 8 * OperandSize::OWORD);
111  }
113 
114 public:
115  // TODO add accessor-based mask memory operations.
116 
118  // Implementation note: use SFINAE to avoid overload ambiguity:
119  // 1) with 'simd_mask(element_type v)' in 'simd_mask<N> m(0)'
120  // 2) with 'simd_mask(const T1(&&arr)[N])' in simd_mask<N>
121  // m((element_type*)p)'
122  template <typename T1,
123  typename = std::enable_if_t<mask_size_ok_for_mem_io() &&
124  std::is_same_v<T1, element_type>>>
125  explicit simd_mask_impl(const T1 *ptr) {
126  base_type::copy_from(ptr);
127  }
128 
131  base_type::set(val);
132  return *this;
133  }
134 
137  return base_type::operator=(other);
138  }
139 
142  template <class T1 = simd_mask_impl,
143  class = std::enable_if_t<T1::length == 1>>
144  operator bool() const {
145  return base_type::data()[0] != 0;
146  }
147 };
148 
149 #undef __ESIMD_MASK_DEPRECATION_MSG
150 
152 
153 } // namespace ext::intel::esimd::detail
154 } // namespace _V1
155 } // namespace sycl
This class is a simd_obj_impl specialization representing a simd mask, which is basically a simd_obj_...
T raw_element_type
Raw element type actually used for storage.
simd_mask_impl(const simd< T, N > &Val)
Implicit conversion from simd.
typename base_type::raw_vector_type raw_vector_type
Underlying storage type for the entire vector.
simd_mask_impl & operator=(const simd_mask_impl &other) noexcept
Copy assignment operator.
simd_mask_impl(const raw_vector_type &Val)
Implicit conversion constructor from a raw vector object.
simd_mask_impl(const raw_element_type(&&Arr)[N1])
Construct from an array. To allow e.g. simd_mask<N> m({1,0,0,1,...}).
simd_mask_impl & operator=(element_type val) noexcept
Broadcast assignment operator to support simd_mask_impl<N> n = a > b;.
simd_mask_impl()=default
Compiler-generated default constructor.
simd_mask_impl(const simd_mask_impl &other)
Copy constructor.
simd_mask_impl(T1 Val)
Broadcast constructor with conversion.
simd_mask_impl(const ext::oneapi::experimental::simd_mask< T1, N > &Val)
Implicit conversion from std::experimental::simd_mask.
This is a base class for all ESIMD simd classes with real storage (simd, simd_mask_impl).
The main simd vector class.
Definition: simd.hpp:53
constexpr ESIMD_INLINE bool isPowerOf2(unsigned int n)
Check if a given 32 bit positive integer is a power of 2 at compile time.
Definition: common.hpp:95
annotated_arg & operator=(annotated_arg &)=default
std::experimental::simd_mask< T, simd_abi::native_fixed_size< T, N > > simd_mask
Definition: access.hpp:18
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324