scalar.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifndef _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H
  10. #define _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H
  11. #include <cstddef>
  12. #include <experimental/__simd/internal_declaration.h>
  13. #if _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
  14. _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
  15. inline namespace parallelism_v2 {
  16. namespace simd_abi {
  17. struct __scalar {
  18. static constexpr size_t __simd_size = 1;
  19. };
  20. } // namespace simd_abi
  21. template <class _Tp>
  22. struct __simd_storage<_Tp, simd_abi::__scalar> {
  23. _Tp __data;
  24. _LIBCPP_HIDE_FROM_ABI _Tp __get([[maybe_unused]] size_t __idx) const noexcept {
  25. _LIBCPP_ASSERT_UNCATEGORIZED(__idx == 0, "Index is out of bounds");
  26. return __data;
  27. }
  28. _LIBCPP_HIDE_FROM_ABI void __set([[maybe_unused]] size_t __idx, _Tp __v) noexcept {
  29. _LIBCPP_ASSERT_UNCATEGORIZED(__idx == 0, "Index is out of bounds");
  30. __data = __v;
  31. }
  32. };
  33. template <class _Tp>
  34. struct __mask_storage<_Tp, simd_abi::__scalar> : __simd_storage<bool, simd_abi::__scalar> {};
  35. template <class _Tp>
  36. struct __simd_operations<_Tp, simd_abi::__scalar> {
  37. using _SimdStorage = __simd_storage<_Tp, simd_abi::__scalar>;
  38. using _MaskStorage = __mask_storage<_Tp, simd_abi::__scalar>;
  39. static _LIBCPP_HIDE_FROM_ABI _SimdStorage __broadcast(_Tp __v) noexcept { return {__v}; }
  40. template <class _Generator>
  41. static _LIBCPP_HIDE_FROM_ABI _SimdStorage __generate(_Generator&& __g) noexcept {
  42. return {__g(std::integral_constant<size_t, 0>())};
  43. }
  44. };
  45. template <class _Tp>
  46. struct __mask_operations<_Tp, simd_abi::__scalar> {
  47. using _MaskStorage = __mask_storage<_Tp, simd_abi::__scalar>;
  48. static _LIBCPP_HIDE_FROM_ABI _MaskStorage __broadcast(bool __v) noexcept { return {__v}; }
  49. };
  50. } // namespace parallelism_v2
  51. _LIBCPP_END_NAMESPACE_EXPERIMENTAL
  52. #endif // _LIBCPP_STD_VER >= 17 && defined(_LIBCPP_ENABLE_EXPERIMENTAL)
  53. #endif // _LIBCPP_EXPERIMENTAL___SIMD_SCALAR_H