Debian Codegraph @

libcxx/include/experimental/__simd/scalar.h

raw
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_SCALAR_H
11 #define _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H
12
13 #include <__assert>
14 #include <cstddef>
15 #include <experimental/__config>
16 #include <experimental/__simd/declaration.h>
17 #include <experimental/__simd/traits.h>
18
19 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
20
21 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
22 inline namespace parallelism_v2 {
23 namespace simd_abi {
24 struct __scalar {
25 static constexpr size_t __simd_size = 1;
26 };
27 } // namespace simd_abi
28
29 template <>
30 inline constexpr bool is_abi_tag_v<simd_abi::__scalar> = true;
31
32 template <class _Tp>
33 struct __simd_storage<_Tp, simd_abi::__scalar> {
34 _Tp __data;
35
36 _LIBCPP_HIDE_FROM_ABI _Tp __get([[maybe_unused]] size_t __idx) const noexcept {
37 _LIBCPP_ASSERT_UNCATEGORIZED(__idx == 0, "Index is out of bounds");
38 return __data;
39 }
40 _LIBCPP_HIDE_FROM_ABI void __set([[maybe_unused]] size_t __idx, _Tp __v) noexcept {
41 _LIBCPP_ASSERT_UNCATEGORIZED(__idx == 0, "Index is out of bounds");
42 __data = __v;
43 }
44 };
45
46 template <class _Tp>
47 struct __mask_storage<_Tp, simd_abi::__scalar> : __simd_storage<bool, simd_abi::__scalar> {};
48
49 template <class _Tp>
50 struct __simd_operations<_Tp, simd_abi::__scalar> {
51 using _SimdStorage = __simd_storage<_Tp, simd_abi::__scalar>;
52 using _MaskStorage = __mask_storage<_Tp, simd_abi::__scalar>;
53
54 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __broadcast(_Tp __v) noexcept { return {__v}; }
55
56 template <class _Generator>
57 static _LIBCPP_HIDE_FROM_ABI _SimdStorage __generate(_Generator&& __g) noexcept {
58 return {__g(std::integral_constant<size_t, 0>())};
59 }
60
61 template <class _Up>
62 static _LIBCPP_HIDE_FROM_ABI void __load(_SimdStorage& __s, const _Up* __mem) noexcept {
63 __s.__data = static_cast<_Tp>(__mem[0]);
64 }
65
66 template <class _Up>
67 static _LIBCPP_HIDE_FROM_ABI void __store(_SimdStorage __s, _Up* __mem) noexcept {
68 *__mem = static_cast<_Up>(__s.__data);
69 }
70 };
71
72 template <class _Tp>
73 struct __mask_operations<_Tp, simd_abi::__scalar> {
74 using _MaskStorage = __mask_storage<_Tp, simd_abi::__scalar>;
75
76 static _LIBCPP_HIDE_FROM_ABI _MaskStorage __broadcast(bool __v) noexcept { return {__v}; }
77
78 static _LIBCPP_HIDE_FROM_ABI void __load(_MaskStorage& __s, const bool* __mem) noexcept { __s.__data = __mem[0]; }
79
80 static _LIBCPP_HIDE_FROM_ABI void __store(_MaskStorage __s, bool* __mem) noexcept { __mem[0] = __s.__data; }
81 };
82
83 } // namespace parallelism_v2
84 _LIBCPP_END_NAMESPACE_EXPERIMENTAL
85
86 #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
87 #endif // _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H