You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/02/24 03:05:50 UTC

[GitHub] [arrow] cyb70289 commented on a change in pull request #9556: ARROW-11744: [C++] Add xsimd dependency

cyb70289 commented on a change in pull request #9556:
URL: https://github.com/apache/arrow/pull/9556#discussion_r581583765



##########
File path: cpp/src/arrow/util/utf8.h
##########
@@ -240,54 +244,26 @@ inline bool ValidateAsciiSw(const uint8_t* data, int64_t len) {
   }
 }
 
-#ifdef ARROW_HAVE_NEON
+#if defined(ARROW_HAVE_NEON) || defined(ARROW_HAVE_SSE4_2)
 inline bool ValidateAsciiSimd(const uint8_t* data, int64_t len) {
-  if (len >= 32) {
-    const uint8_t* data2 = data + 16;
-    uint8x16_t or1 = vdupq_n_u8(0), or2 = or1;
-
-    while (len >= 32) {
-      const uint8x16_t input1 = vld1q_u8(data);
-      const uint8x16_t input2 = vld1q_u8(data2);
-
-      or1 = vorrq_u8(or1, input1);
-      or2 = vorrq_u8(or2, input2);
-
-      data += 32;
-      data2 += 32;
-      len -= 32;
-    }
-
-    or1 = vorrq_u8(or1, or2);
-    if (vmaxvq_u8(or1) >= 0x80) {
-      return false;
-    }
-  }
+  using simd_batch = xsimd::batch<int8_t, 16>;
 
-  return ValidateAsciiSw(data, len);
-}
-#endif  // ARROW_HAVE_NEON
-
-#if defined(ARROW_HAVE_SSE4_2)
-inline bool ValidateAsciiSimd(const uint8_t* data, int64_t len) {
   if (len >= 32) {
+    const simd_batch zero(static_cast<int8_t>(0));
     const uint8_t* data2 = data + 16;
-    __m128i or1 = _mm_set1_epi8(0), or2 = or1;
+    simd_batch or1 = zero, or2 = zero;
 
     while (len >= 32) {
-      __m128i input1 = _mm_lddqu_si128((const __m128i*)data);
-      __m128i input2 = _mm_lddqu_si128((const __m128i*)data2);
-
-      or1 = _mm_or_si128(or1, input1);
-      or2 = _mm_or_si128(or2, input2);
-
+      or1 |= simd_batch(reinterpret_cast<const int8_t*>(data), xsimd::unaligned_mode{});
+      or2 |= simd_batch(reinterpret_cast<const int8_t*>(data2), xsimd::unaligned_mode{});
       data += 32;
       data2 += 32;
       len -= 32;
     }
 
-    or1 = _mm_or_si128(or1, or2);
-    if (_mm_movemask_epi8(_mm_cmplt_epi8(or1, _mm_set1_epi8(0)))) {
+    // To test for upper bit in all bytes, test whether any of them is negative
+    or1 |= or2;
+    if (xsimd::any(or1 < zero)) {

Review comment:
       Compared with current Neon code, this line introduces an additional vector comparison instruction. No trouble as it's not in the hot loop.
   Look simd lib does make the code easier to read and maintain.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org