9prady9 commented on a change in pull request #11674:
URL: https://github.com/apache/arrow/pull/11674#discussion_r748163500



##########
File path: cpp/src/arrow/util/bitmap_ops.cc
##########
@@ -249,59 +249,92 @@ void AlignedBitmapOp(const uint8_t* left, int64_t 
left_offset, const uint8_t* ri
   left += left_offset / 8;
   right += right_offset / 8;
   out += out_offset / 8;
+  uint64_t outPopCount = 0;
   for (int64_t i = 0; i < nbytes; ++i) {
     out[i] = op(left[i], right[i]);
+    if (ComputeNewValidityCount) {
+      outPopCount += BitUtil::kBytePopcount[out[i]];

Review comment:
       > The problem is that v is calculated but never used. So compiler will 
simply delete all the code calculating it.
   > Change the function to let it return v, the generated code will be totally 
different.
   
   Makes sense. After playing with it for few minutes, saving result to 
register and then using that for other two calculations is what letting 
compiler vectorize the loop on all three compilers consistently.
   
   - clang - https://godbolt.org/z/sKvodGzbr
   - gcc - https://godbolt.org/z/Kdc38P7fx
   - msvc - https://godbolt.org/z/n1so9PbG3
   
   In any case, eventually I dropped the above approach. 
   
   I had a version of CountSetBits earlier that was doing popcount on 64-bit 
words. But I removed that in favour of lookup during the bitmap op assuming 
lookup might be faster. It turned out just doing popcount finally on the whole 
array is more efficient than clubbing the pop-count with bitmapOp .
   
   Please check the updated description for new numbers




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to