BiteTheDDDDt commented on code in PR #10472:
URL: https://github.com/apache/doris/pull/10472#discussion_r908740012


##########
be/src/util/simd/bits.h:
##########
@@ -59,10 +59,28 @@ inline uint32_t bytes32_mask_to_bits32_mask(const bool* 
data) {
     return bytes32_mask_to_bits32_mask(reinterpret_cast<const uint8_t*>(data));
 }
 
-// compiler will make this SIMD automatically
 inline size_t count_zero_num(const int8_t* __restrict data, size_t size) {
     size_t num = 0;
     const int8_t* end = data + size;
+#if defined(__SSE2__) && defined(__POPCNT__)
+    const __m128i zero16 = _mm_setzero_si128();
+    const int8_t* end64 = data + (size / 64 * 64);
+
+    for (; data < end64; data += 64) {
+        num += __builtin_popcountll(
+                static_cast<uint64_t>(_mm_movemask_epi8(_mm_cmpeq_epi8(

Review Comment:
   we can shift lowest bit to highest, then movemask can get result.
   ```cpp
   __builtin_popcountll(static_cast<uint64_t>(_mm_movemask_epi8(_mm_slli_epi16(
                                               *reinterpret_cast<const 
__m128i*>(data), 15))) |
                                       
(static_cast<uint64_t>(_mm_movemask_epi8(_mm_slli_epi16(
                                                *reinterpret_cast<const 
__m128i*>(data + 16), 15)))
                                        << 16u) |
                                       
(static_cast<uint64_t>(_mm_movemask_epi8(_mm_slli_epi16(
                                                *reinterpret_cast<const 
__m128i*>(data + 32), 15)))
                                        << 32u) |
                                       
(static_cast<uint64_t>(_mm_movemask_epi8(_mm_slli_epi16(
                                                *reinterpret_cast<const 
__m128i*>(data + 48), 15)))
                                        << 48u));
   ```



-- 
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.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to