1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H 11 #define _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H 12 13 #include <__type_traits/is_same.h> 14 #include <cstddef> 15 #include <experimental/__config> 16 #include <experimental/__simd/declaration.h> 17 #include <experimental/__simd/reference.h> 18 #include <experimental/__simd/traits.h> 19 20 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL) 21 22 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL 23 inline namespace parallelism_v2 { 24 25 // class template simd_mask [simd.mask.class] 26 // TODO: implement simd_mask class 27 template <class _Tp, class _Abi> 28 class simd_mask { 29 using _Impl = __mask_operations<_Tp, _Abi>; 30 using _Storage = typename _Impl::_MaskStorage; 31 32 _Storage __s_; 33 34 public: 35 using value_type = bool; 36 using reference = __simd_reference<_Tp, _Storage, value_type>; 37 using simd_type = simd<_Tp, _Abi>; 38 using abi_type = _Abi; 39 40 static _LIBCPP_HIDE_FROM_ABI constexpr size_t size() noexcept { return simd_type::size(); } 41 42 _LIBCPP_HIDE_FROM_ABI simd_mask() noexcept = default; 43 44 // broadcast constructor 45 _LIBCPP_HIDE_FROM_ABI explicit simd_mask(value_type __v) noexcept : __s_(_Impl::__broadcast(__v)) {} 46 47 // implicit type conversion constructor 48 template <class _Up, enable_if_t<!is_same_v<_Up, _Tp> && is_same_v<abi_type, simd_abi::fixed_size<size()>>, int> = 0> 49 _LIBCPP_HIDE_FROM_ABI simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>& __v) noexcept { 50 for (size_t __i = 0; __i < size(); __i++) { 51 (*this)[__i] = __v[__i]; 52 } 53 } 54 55 // scalar access [simd.mask.subscr] 56 _LIBCPP_HIDE_FROM_ABI reference operator[](size_t __i) noexcept { return reference(__s_, __i); } 57 _LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); } 58 }; 59 60 template <class _Tp, class _Abi> 61 inline constexpr bool is_simd_mask_v<simd_mask<_Tp, _Abi>> = true; 62 63 template <class _Tp> 64 using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>; 65 66 template <class _Tp, int _Np> 67 using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>; 68 69 } // namespace parallelism_v2 70 _LIBCPP_END_NAMESPACE_EXPERIMENTAL 71 72 #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL) 73 #endif // _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H 74