[libcxx-commits] [libcxx] [libc++] Start implementing std::datapar::simd (PR #139919)
Matthias Kretz via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jun 5 02:03:42 PDT 2025
================
@@ -0,0 +1,165 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___SIMD_ABI_H
+#define _LIBCPP___SIMD_ABI_H
+
+#include <__concepts/convertible_to.h>
+#include <__concepts/equality_comparable.h>
+#include <__config>
+#include <__cstddef/size_t.h>
+#include <__type_traits/standard_types.h>
+#include <__utility/integer_sequence.h>
+#include <cstdint>
+
+#if _LIBCPP_STD_VER >= 26
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+namespace datapar {
+
+template <class _Tp>
+inline constexpr bool __is_vectorizable_type_v = __is_standard_integer_type_v<_Tp> || __is_character_type_v<_Tp>;
+
+template <>
+inline constexpr bool __is_vectorizable_type_v<float> = true;
+
+template <>
+inline constexpr bool __is_vectorizable_type_v<double> = true;
+
+template <class _From, class _To>
+concept __value_preserving_convertible = requires(_From __from) { _To{__from}; };
----------------
mattkretz wrote:
I don't know of any trick. [This is what I implemented](https://github.com/GSI-HPC/simd/blob/af6c41754dd7df0498a2290b6818f37a364b8df7/bits/simd_meta.h#L73-L85):
```cpp
template <typename _From, typename _To>
concept __arithmetic_only_value_preserving_convertible_to
= convertible_to<_From, _To> and __arithmetic<_From> and __arithmetic<_To>
and not (is_signed_v<_From> and is_unsigned_v<_To>)
and numeric_limits<_From>::digits <= numeric_limits<_To>::digits
and numeric_limits<_From>::max() <= numeric_limits<_To>::max()
and numeric_limits<_From>::lowest() >= numeric_limits<_To>::lowest();
template <typename _From, typename _To>
concept __value_preserving_convertible_to
= __arithmetic_only_value_preserving_convertible_to<_From, _To>
or (__complex_like<_To> and __arithmetic_only_value_preserving_convertible_to<
_From, typename _To::value_type>);
```
I think `bfloat16_t` and `float16_t` need another check besides only for `digits`. `bfloat16_t` is not vectorizable yet, but it's arithmetic at least. The `max` and `lowest` compares are mixed-type comparisons but I so far I have convinced myself that even with implicit conversions this concept always gives the right answer.
https://github.com/llvm/llvm-project/pull/139919
More information about the libcxx-commits
mailing list