Warning: This file is not a C or C++ file. It does not have highlighting.
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 <__config> |
14 | #include <__cstddef/size_t.h> |
15 | #include <__type_traits/enable_if.h> |
16 | #include <__type_traits/is_same.h> |
17 | #include <experimental/__simd/declaration.h> |
18 | #include <experimental/__simd/reference.h> |
19 | #include <experimental/__simd/traits.h> |
20 | |
21 | #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL) |
22 | |
23 | _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL |
24 | inline namespace parallelism_v2 { |
25 | |
26 | // class template simd_mask [simd.mask.class] |
27 | // TODO: implement simd_mask class |
28 | template <class _Tp, class _Abi> |
29 | class simd_mask { |
30 | using _Impl _LIBCPP_NODEBUG = __mask_operations<_Tp, _Abi>; |
31 | using _Storage _LIBCPP_NODEBUG = typename _Impl::_MaskStorage; |
32 | |
33 | _Storage __s_; |
34 | |
35 | public: |
36 | using value_type = bool; |
37 | using reference = __simd_reference<_Tp, _Storage, value_type>; |
38 | using simd_type = simd<_Tp, _Abi>; |
39 | using abi_type = _Abi; |
40 | |
41 | static _LIBCPP_HIDE_FROM_ABI constexpr size_t size() noexcept { return simd_type::size(); } |
42 | |
43 | _LIBCPP_HIDE_FROM_ABI simd_mask() noexcept = default; |
44 | |
45 | // explicit conversion from and to implementation-defined types |
46 | struct __storage_tag_t {}; |
47 | static constexpr __storage_tag_t __storage_tag{}; |
48 | explicit _LIBCPP_HIDE_FROM_ABI operator _Storage() const { return __s_; } |
49 | explicit _LIBCPP_HIDE_FROM_ABI simd_mask(const _Storage& __s, __storage_tag_t) : __s_(__s) {} |
50 | |
51 | // broadcast constructor |
52 | _LIBCPP_HIDE_FROM_ABI explicit simd_mask(value_type __v) noexcept : __s_(_Impl::__broadcast(__v)) {} |
53 | |
54 | // implicit type conversion constructor |
55 | template <class _Up, enable_if_t<!is_same_v<_Up, _Tp> && is_same_v<abi_type, simd_abi::fixed_size<size()>>, int> = 0> |
56 | _LIBCPP_HIDE_FROM_ABI simd_mask(const simd_mask<_Up, simd_abi::fixed_size<size()>>& __v) noexcept { |
57 | for (size_t __i = 0; __i < size(); __i++) { |
58 | (*this)[__i] = __v[__i]; |
59 | } |
60 | } |
61 | |
62 | // load constructor |
63 | template <class _Flags, enable_if_t<is_simd_flag_type_v<_Flags>, int> = 0> |
64 | _LIBCPP_HIDE_FROM_ABI simd_mask(const value_type* __mem, _Flags) { |
65 | _Impl::__load(__s_, _Flags::template __apply<simd_mask>(__mem)); |
66 | } |
67 | |
68 | // copy functions |
69 | template <class _Flags, enable_if_t<is_simd_flag_type_v<_Flags>, int> = 0> |
70 | _LIBCPP_HIDE_FROM_ABI void copy_from(const value_type* __mem, _Flags) { |
71 | _Impl::__load(__s_, _Flags::template __apply<simd_mask>(__mem)); |
72 | } |
73 | |
74 | template <class _Flags, enable_if_t<is_simd_flag_type_v<_Flags>, int> = 0> |
75 | _LIBCPP_HIDE_FROM_ABI void copy_to(value_type* __mem, _Flags) const { |
76 | _Impl::__store(__s_, _Flags::template __apply<simd_mask>(__mem)); |
77 | } |
78 | |
79 | // scalar access [simd.mask.subscr] |
80 | _LIBCPP_HIDE_FROM_ABI reference operator[](size_t __i) noexcept { return reference(__s_, __i); } |
81 | _LIBCPP_HIDE_FROM_ABI value_type operator[](size_t __i) const noexcept { return __s_.__get(__i); } |
82 | }; |
83 | |
84 | template <class _Tp, class _Abi> |
85 | inline constexpr bool is_simd_mask_v<simd_mask<_Tp, _Abi>> = true; |
86 | |
87 | template <class _Tp> |
88 | using native_simd_mask = simd_mask<_Tp, simd_abi::native<_Tp>>; |
89 | |
90 | template <class _Tp, int _Np> |
91 | using fixed_size_simd_mask = simd_mask<_Tp, simd_abi::fixed_size<_Np>>; |
92 | |
93 | } // namespace parallelism_v2 |
94 | _LIBCPP_END_NAMESPACE_EXPERIMENTAL |
95 | |
96 | #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL) |
97 | #endif // _LIBCPP_EXPERIMENTAL___SIMD_SIMD_MASK_H |
98 |
Warning: This file is not a C or C++ file. It does not have highlighting.