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



##########
File path: cpp/src/arrow/util/bit_util.cc
##########
@@ -273,28 +274,115 @@ void AlignedBitmapOp(const uint8_t* left, int64_t 
left_offset, const uint8_t* ri
   }
 }
 
-template <typename Op>
+template <template <typename> class BitOp, typename LogicalOp>
 void UnalignedBitmapOp(const uint8_t* left, int64_t left_offset, const 
uint8_t* right,
                        int64_t right_offset, uint8_t* out, int64_t out_offset,
                        int64_t length) {
-  Op op;
-  auto left_reader = internal::BitmapReader(left, left_offset, length);
-  auto right_reader = internal::BitmapReader(right, right_offset, length);
-  auto writer = internal::BitmapWriter(out, out_offset, length);
-  for (int64_t i = 0; i < length; ++i) {
-    if (op(left_reader.IsSet(), right_reader.IsSet())) {
-      writer.Set();
-    } else {
-      writer.Clear();
+  using Word = uint64_t;
+
+  left += left_offset / 8;
+  right += right_offset / 8;
+  out += out_offset / 8;
+
+  left_offset %= 8;
+  right_offset %= 8;
+  out_offset %= 8;
+
+  const int64_t min_offset = std::min({left_offset, right_offset, out_offset});
+  const int64_t min_nbytes = BitUtil::BytesForBits(length + min_offset);
+  int64_t nwords = min_nbytes / sizeof(Word);
+
+  // process in words, we may touch two words in each iteration

Review comment:
       I'm not using Bitmap::VisitWords() as the first word returned may be not 
full (e.g, only 63 bits are valid), and there's no easy way to get that valid 
bit count in visitor callback. It also causes special handling of first (and 
last) word.
   So I'm handling the raw data here. In each iteration, pick 64 bits from 
`left` and `right`, and/or/xor them, then write to `out`. Remaining bits are 
treated bit by bit.




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


Reply via email to