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/abi_tag.h> 17 #include <experimental/__simd/declaration.h> 18 #include <experimental/__simd/internal_declaration.h> 19 #include <experimental/__simd/reference.h> 20 #include <experimental/__simd/traits.h> 21 22 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL) 23 24 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL 25 inline namespace parallelism_v2 { 26 27 // class template simd_mask [simd.mask.class] 28 // TODO: implement simd_mask class 29 template <class _Tp, class _Abi> 30 class simd_mask { 31 using _Impl = __mask_operations<_Tp, _Abi>; 32 using _Storage = typename _Impl::_MaskStorage; 33 34 _Storage __s_; 35 36 public: 37 using value_type = bool; 38 using reference = __simd_reference<_Tp, _Storage, value_type>; 39 using simd_type = simd<_Tp, _Abi>; 40 using abi_type = _Abi; 41 size()42 static _LIBCPP_HIDE_FROM_ABI constexpr size_t size() noexcept { return simd_type::size(); } 43 44 _LIBCPP_HIDE_FROM_ABI simd_mask() noexcept = default; 45 46 // broadcast constructor simd_mask(value_type __v)47 _LIBCPP_HIDE_FROM_ABI explicit simd_mask(value_type __v) noexcept : __s_(_Impl::__broadcast(__v)) {} 48 49 // implicit type conversion constructor 50 template <class _Up, enable_if_t<!is_same_v<_Up, _Tp> && is_same_v<abi_type, simd_abi::fixed_size<size()>>, int> = 0> simd_mask(const simd_mask<_Up,simd_abi::fixed_size<size ()>> & __v)51 _LIBCPP_HIDE_FROM_ABI simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>& __v) noexcept { 52 for (size_t __i = 0; __i < size(); __i++) { 53 (*this)[__i] = __v[__i]; 54 } 55 } 56 57 // scalar access [simd.mask.subscr] 58 _LIBCPP_HIDE_FROM_ABI reference operator[](size_t __i) noexcept { return reference(__s_, __i); } 59 _LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); } 60 }; 61 62 template <class _Tp, class _Abi> 63 inline constexpr bool is_simd_mask_v<simd_mask<_Tp, _Abi>> = true; 64 65 template <class _Tp> 66 using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>; 67 68 template <class _Tp, int _Np> 69 using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>; 70 71 } // namespace parallelism_v2 72 _LIBCPP_END_NAMESPACE_EXPERIMENTAL 73 74 #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL) 75 #endif // _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H 76