[libcxx-commits] [libcxx] [libc++] Start implementing std::datapar::simd (PR #139919)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri May 30 08:49:56 PDT 2025
================
@@ -0,0 +1,350 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_BASIC_SIMD_H
+#define _LIBCPP___SIMD_BASIC_SIMD_H
+
+#include <__assert>
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__memory/assume_aligned.h>
+#include <__ranges/concepts.h>
+#include <__simd/abi.h>
+#include <__simd/basic_simd_mask.h>
+#include <__simd/simd_flags.h>
+#include <__type_traits/is_arithmetic.h>
+#include <__type_traits/pack_utils.h>
+#include <__type_traits/remove_const.h>
+#include <__type_traits/remove_cvref.h>
+#include <__utility/integer_sequence.h>
+
+#if _LIBCPP_STD_VER >= 26
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace datapar {
+
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wpsabi")
+template <class _Tp, class _Abi = __native_abi<_Tp>>
+class basic_simd {
+public:
+ using value_type = _Tp;
+ using mask_type = basic_simd_mask<sizeof(_Tp), _Abi>;
+ using abi_type = _Abi;
+
+private:
+ using __data_t = abi_type::_SimdT;
+
+ __data_t __data_;
+
+ _LIBCPP_ALWAYS_INLINE static constexpr __data_t __broadcast(value_type __value) {
+ return [&]<size_t... _Indices>(index_sequence<_Indices...>) _LIBCPP_ALWAYS_INLINE noexcept {
+ return __data_t{((void)_Indices, __value)...};
+ }(make_index_sequence<size()>{});
+ }
+
+ template <class _Up>
+ _LIBCPP_ALWAYS_INLINE static constexpr __data_t __load_from_pointer(const _Up* __ptr) {
----------------
ldionne wrote:
You use `_LIBCPP_ALWAYS_INLINE` in a few places. Based on our discussion just now, this is for the (quite interesting) reason that you want to avoid ABI differences based on compiler flags since these functions traffic in SIMD types. I'd like to introduce a macro like `#define _LIBCPP_SIMD_SENSITIVE_ABI _LIBCPP_ALWAYS_INLINE` (strawman name) that we would use on any function whose ABI is sensitive to SIMD-related compiler flags. This is also where we should document the reason for that function and its mode of operation (i.e. that `_LIBCPP_ALWAYS_INLINE` solves the problem of having mismatched function call ABIs by removing the existence of a function call in the first place).
This should also probably come with a clang-tidy check to ensure that we don't mess up. Otherwise, people could end up with a very very confusing ODR violation.
https://github.com/llvm/llvm-project/pull/139919
More information about the libcxx-commits
mailing list