[libcxx-commits] [libcxx] [libc++] Fix endianness for algorithm mismatch (PR #93082)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jun 1 02:52:25 PDT 2024


================
@@ -56,6 +56,112 @@ __mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Pro
 
 #if _LIBCPP_VECTORIZE_ALGORITHMS
 
+template <class _ValueType>
+_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __simd_vector<long long, 2>
+__reverse_vector(__simd_vector<long long, 2>& __cmp_res) {
+#  if defined(_LIBCPP_BIG_ENDIAN)
+  __cmp_res = __builtin_shufflevector(__cmp_res, __cmp_res, 1, 0);
+#  endif
+  return __cmp_res;
+}
----------------
philnik777 wrote:

This seems very ad-hoc to me. These could all be collapsed into a single
```suggestion
template <class _ValueType, size_t _Np>
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI __simd_vector<long long, _Np>
__reverse_vector(__simd_vector<long long, _Np> __cmp_res) {
  return [&]<size_t... _Indices>(index_sequence<_Indices>) {
    return __builtin_shufflevector(__cmp_res, __cmp_res, (_Np - _Indices)...);
  }(make_index_sequence<_Np>{});
}
```
Also note that I removed `_LIBCPP_CONSTEXPR_SINCE_CXX20`, since this is never called in a `constexpr` context. The name of this seems very misleading as well, since this doesn't always reverse the vector.

More generally: Why don't we modify `__find_first_set` to return the first element from left to right on all platforms?

https://github.com/llvm/llvm-project/pull/93082


More information about the libcxx-commits mailing list