Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:08

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H
0011 #define _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H
0012 
0013 #include <__assert>
0014 #include <__config>
0015 #include <__cstddef/size_t.h>
0016 #include <__type_traits/integral_constant.h>
0017 #include <experimental/__simd/declaration.h>
0018 #include <experimental/__simd/traits.h>
0019 
0020 #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
0021 
0022 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
0023 inline namespace parallelism_v2 {
0024 namespace simd_abi {
0025 struct __scalar {
0026   static constexpr size_t __simd_size = 1;
0027 };
0028 } // namespace simd_abi
0029 
0030 template <>
0031 inline constexpr bool is_abi_tag_v<simd_abi::__scalar> = true;
0032 
0033 template <class _Tp>
0034 struct __simd_storage<_Tp, simd_abi::__scalar> {
0035   _Tp __data;
0036 
0037   _LIBCPP_HIDE_FROM_ABI _Tp __get([[maybe_unused]] size_t __idx) const noexcept {
0038     _LIBCPP_ASSERT_UNCATEGORIZED(__idx == 0, "Index is out of bounds");
0039     return __data;
0040   }
0041   _LIBCPP_HIDE_FROM_ABI void __set([[maybe_unused]] size_t __idx, _Tp __v) noexcept {
0042     _LIBCPP_ASSERT_UNCATEGORIZED(__idx == 0, "Index is out of bounds");
0043     __data = __v;
0044   }
0045 };
0046 
0047 template <class _Tp>
0048 struct __mask_storage<_Tp, simd_abi::__scalar> : __simd_storage<bool, simd_abi::__scalar> {};
0049 
0050 template <class _Tp>
0051 struct __simd_operations<_Tp, simd_abi::__scalar> {
0052   using _SimdStorage _LIBCPP_NODEBUG = __simd_storage<_Tp, simd_abi::__scalar>;
0053   using _MaskStorage _LIBCPP_NODEBUG = __mask_storage<_Tp, simd_abi::__scalar>;
0054 
0055   static _LIBCPP_HIDE_FROM_ABI _SimdStorage __broadcast(_Tp __v) noexcept { return {__v}; }
0056 
0057   template <class _Generator>
0058   static _LIBCPP_HIDE_FROM_ABI _SimdStorage __generate(_Generator&& __g) noexcept {
0059     return {__g(std::integral_constant<size_t, 0>())};
0060   }
0061 
0062   template <class _Up>
0063   static _LIBCPP_HIDE_FROM_ABI void __load(_SimdStorage& __s, const _Up* __mem) noexcept {
0064     __s.__data = static_cast<_Tp>(__mem[0]);
0065   }
0066 
0067   template <class _Up>
0068   static _LIBCPP_HIDE_FROM_ABI void __store(_SimdStorage __s, _Up* __mem) noexcept {
0069     *__mem = static_cast<_Up>(__s.__data);
0070   }
0071 
0072   static _LIBCPP_HIDE_FROM_ABI void __increment(_SimdStorage& __s) noexcept { ++__s.__data; }
0073 
0074   static _LIBCPP_HIDE_FROM_ABI void __decrement(_SimdStorage& __s) noexcept { --__s.__data; }
0075 
0076   static _LIBCPP_HIDE_FROM_ABI _MaskStorage __negate(_SimdStorage __s) noexcept { return {!__s.__data}; }
0077 
0078   static _LIBCPP_HIDE_FROM_ABI _SimdStorage __bitwise_not(_SimdStorage __s) noexcept {
0079     return {static_cast<_Tp>(~__s.__data)};
0080   }
0081 
0082   static _LIBCPP_HIDE_FROM_ABI _SimdStorage __unary_minus(_SimdStorage __s) noexcept {
0083     return {static_cast<_Tp>(-__s.__data)};
0084   }
0085 };
0086 
0087 template <class _Tp>
0088 struct __mask_operations<_Tp, simd_abi::__scalar> {
0089   using _MaskStorage _LIBCPP_NODEBUG = __mask_storage<_Tp, simd_abi::__scalar>;
0090 
0091   static _LIBCPP_HIDE_FROM_ABI _MaskStorage __broadcast(bool __v) noexcept { return {__v}; }
0092 
0093   static _LIBCPP_HIDE_FROM_ABI void __load(_MaskStorage& __s, const bool* __mem) noexcept { __s.__data = __mem[0]; }
0094 
0095   static _LIBCPP_HIDE_FROM_ABI void __store(_MaskStorage __s, bool* __mem) noexcept { __mem[0] = __s.__data; }
0096 };
0097 
0098 } // namespace parallelism_v2
0099 _LIBCPP_END_NAMESPACE_EXPERIMENTAL
0100 
0101 #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
0102 #endif // _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H