[libcxx-commits] [libcxx] [libc++] Optimize the std::mismatch tail (PR #83440)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 29 08:05:09 PST 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 1a0986f0f7a18cef78852e91e73ec577ea05d8c4 e1c9ff33e89ef62f322e73469aab5e9e7fa52b8e -- libcxx/benchmarks/algorithms/mismatch.bench.cpp libcxx/include/__algorithm/simd_utils.h libcxx/include/__algorithm/mismatch.h libcxx/include/__bit/bit_cast.h libcxx/include/__bit/countr.h libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp
``````````

</details>

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

``````````diff
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp
index 7e508834e8..790c2880ad 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp
@@ -116,61 +116,60 @@ int main(int, char**) {
   static_assert(test());
 #endif
 
-  { // check with a lot of elements to test the vectorization optimization
+  {// check with a lot of elements to test the vectorization optimization
+   {std::vector<char> lhs(256);
+  std::vector<char> rhs(256);
+  for (size_t i = 0; i != lhs.size(); ++i) {
+    lhs[i] = 1;
+    check<char*>(lhs, rhs, i);
+    lhs[i] = 0;
+    rhs[i] = 1;
+    check<char*>(lhs, rhs, i);
+    rhs[i] = 0;
+  }
+}
+
+{
+  std::vector<int> lhs(256);
+  std::vector<int> rhs(256);
+  for (size_t i = 0; i != lhs.size(); ++i) {
+    lhs[i] = 1;
+    check<int*>(lhs, rhs, i);
+    lhs[i] = 0;
+    rhs[i] = 1;
+    check<int*>(lhs, rhs, i);
+    rhs[i] = 0;
+  }
+}
+}
+
+{ // check the tail of the vectorized loop
+  for (size_t vec_size = 1; vec_size != 256; ++vec_size) {
     {
       std::vector<char> lhs(256);
       std::vector<char> rhs(256);
-      for (size_t i = 0; i != lhs.size(); ++i) {
-        lhs[i] = 1;
-        check<char*>(lhs, rhs, i);
-        lhs[i] = 0;
-        rhs[i] = 1;
-        check<char*>(lhs, rhs, i);
-        rhs[i] = 0;
-      }
-    }
 
+      check<char*>(lhs, rhs, lhs.size());
+      lhs.back() = 1;
+      check<char*>(lhs, rhs, lhs.size() - 1);
+      lhs.back() = 0;
+      rhs.back() = 1;
+      check<char*>(lhs, rhs, lhs.size() - 1);
+      rhs.back() = 0;
+    }
     {
       std::vector<int> lhs(256);
       std::vector<int> rhs(256);
-      for (size_t i = 0; i != lhs.size(); ++i) {
-        lhs[i] = 1;
-        check<int*>(lhs, rhs, i);
-        lhs[i] = 0;
-        rhs[i] = 1;
-        check<int*>(lhs, rhs, i);
-        rhs[i] = 0;
-      }
-    }
-  }
 
-  { // check the tail of the vectorized loop
-    for (size_t vec_size = 1; vec_size != 256; ++vec_size) {
-      {
-        std::vector<char> lhs(256);
-        std::vector<char> rhs(256);
-
-        check<char*>(lhs, rhs, lhs.size());
-        lhs.back() = 1;
-        check<char*>(lhs, rhs, lhs.size() - 1);
-        lhs.back() = 0;
-        rhs.back() = 1;
-        check<char*>(lhs, rhs, lhs.size() - 1);
-        rhs.back() = 0;
-      }
-      {
-        std::vector<int> lhs(256);
-        std::vector<int> rhs(256);
-
-        check<int*>(lhs, rhs, lhs.size());
-        lhs.back() = 1;
-        check<int*>(lhs, rhs, lhs.size() - 1);
-        lhs.back() = 0;
-        rhs.back() = 1;
-        check<int*>(lhs, rhs, lhs.size() - 1);
-        rhs.back() = 0;
-      }
+      check<int*>(lhs, rhs, lhs.size());
+      lhs.back() = 1;
+      check<int*>(lhs, rhs, lhs.size() - 1);
+      lhs.back() = 0;
+      rhs.back() = 1;
+      check<int*>(lhs, rhs, lhs.size() - 1);
+      rhs.back() = 0;
     }
   }
+}
   return 0;
 }

``````````

</details>


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


More information about the libcxx-commits mailing list