[libcxx-commits] [libcxx] Fix endianess for algorithm mismatch (PR #93082)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 22 11:11:13 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff cc3b6c3ba9c0dd7df0fd7ac23c8609c4675dd62a fa56dba875e527e7ecc21dae5805cdafec238acf -- libcxx/include/__algorithm/mismatch.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/include/__algorithm/mismatch.h b/libcxx/include/__algorithm/mismatch.h
index a8219f0817..acffc133d2 100644
--- a/libcxx/include/__algorithm/mismatch.h
+++ b/libcxx/include/__algorithm/mismatch.h
@@ -56,36 +56,67 @@ __mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Pro
 
 #if _LIBCPP_VECTORIZE_ALGORITHMS
 
-template <class _Tp,
-          __enable_if_t<is_integral<_Tp>::value, int> = 0>
+template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0>
 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __simd_vector<_Tp, 8>
 __reverse_vector(__simd_vector<_Tp, 8>& __cmp_res) {
-#if defined(_LIBCPP_BIG_ENDIAN)
+#  if defined(_LIBCPP_BIG_ENDIAN)
   static_assert(__native_vector_size<_Tp> == 8, "The __native_vector_size has to be 8");
   __cmp_res = __builtin_shufflevector(__cmp_res, __cmp_res, 7, 6, 5, 4, 3, 2, 1, 0);
-#endif
+#  endif
   return __cmp_res;
 }
 
-template <class _Tp,
-          __enable_if_t<is_integral<_Tp>::value, int> = 0>
+template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0>
 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __simd_vector<_Tp, 16>
 __reverse_vector(__simd_vector<_Tp, 16> __cmp_res) {
-#if defined(_LIBCPP_BIG_ENDIAN)
+#  if defined(_LIBCPP_BIG_ENDIAN)
   static_assert(__native_vector_size<_Tp> == 16, "The __native_vector_size has to be 16");
   __cmp_res = __builtin_shufflevector(__cmp_res, __cmp_res, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
-#endif
+#  endif
   return __cmp_res;
 }
 
-template <class _Tp,
-          __enable_if_t<is_integral<_Tp>::value, int> = 0>
+template <class _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0>
 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __simd_vector<_Tp, 32>
 __reverse_vector(__simd_vector<_Tp, 32> __cmp_res) {
-#if defined(_LIBCPP_BIG_ENDIAN)
+#  if defined(_LIBCPP_BIG_ENDIAN)
   static_assert(__native_vector_size<_Tp> == 32, "The __native_vector_size has to be 32");
-  __cmp_res = __builtin_shufflevector(__cmp_res, __cmp_res, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
-#endif
+  __cmp_res = __builtin_shufflevector(
+      __cmp_res,
+      __cmp_res,
+      31,
+      30,
+      29,
+      28,
+      27,
+      26,
+      25,
+      24,
+      23,
+      22,
+      21,
+      20,
+      19,
+      18,
+      17,
+      16,
+      15,
+      14,
+      13,
+      12,
+      11,
+      10,
+      9,
+      8,
+      7,
+      6,
+      5,
+      4,
+      3,
+      2,
+      1,
+      0);
+#  endif
   return __cmp_res;
 }
 
@@ -111,7 +142,7 @@ __mismatch_vectorized(_Iter __first1, _Iter __last1, _Iter __first2) {
 
       for (size_t __i = 0; __i != __unroll_count; ++__i) {
         auto __cmp_res = __lhs[__i] == __rhs[__i];
-        __cmp_res = __reverse_vector<_Tp>(__cmp_res);
+        __cmp_res      = __reverse_vector<_Tp>(__cmp_res);
         if (!std::__all_of(__cmp_res)) {
           auto __offset = __i * __vec_size + std::__find_first_not_set(__cmp_res);
           return {__first1 + __offset, __first2 + __offset};
@@ -125,7 +156,7 @@ __mismatch_vectorized(_Iter __first1, _Iter __last1, _Iter __first2) {
     // check the remaining 0-3 vectors
     while (static_cast<size_t>(__last1 - __first1) >= __vec_size) {
       auto __cmp_res = std::__load_vector<__vec>(__first1) == std::__load_vector<__vec>(__first2);
-      __cmp_res = __reverse_vector<_Tp>(__cmp_res);
+      __cmp_res      = __reverse_vector<_Tp>(__cmp_res);
       if (!std::__all_of(__cmp_res)) {
         auto __offset = std::__find_first_not_set(__cmp_res);
         return {__first1 + __offset, __first2 + __offset};
@@ -143,8 +174,8 @@ __mismatch_vectorized(_Iter __first1, _Iter __last1, _Iter __first2) {
       __first1 = __last1 - __vec_size;
       __first2 = __last2 - __vec_size;
       auto __cmp_res = std::__load_vector<__vec>(__first1) == std::__load_vector<__vec>(__first2);
-      __cmp_res = __reverse_vector<_Tp>(__cmp_res);
-      auto __offset = std::__find_first_not_set(__cmp_res);
+      __cmp_res      = __reverse_vector<_Tp>(__cmp_res);
+      auto __offset  = std::__find_first_not_set(__cmp_res);
       return {__first1 + __offset, __first2 + __offset};
     } // else loop over the elements individually
   }

``````````

</details>


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


More information about the libcxx-commits mailing list