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