haohuaijin commented on code in PR #10968:
URL: https://github.com/apache/arrow-rs/pull/10968#discussion_r4105566164


##########
arrow-buffer/src/util/bit_util.rs:
##########
@@ -81,6 +81,64 @@ pub fn compress(value: u64, mask: u64) -> u64 {
     }
 }
 
+/// Parallel bit deposit: scatter the lowest `mask.count_ones()` bits of
+/// `value` into the set positions of `mask`, preserving their order.
+/// All other bits in the result are zero; excess input bits are ignored.
+///
+/// This is the inverse of [`compress`] on the selected bits:
+/// `expand(compress(value, mask), mask) == value & mask`.
+///
+/// Equivalent to the x86 BMI2 `PDEP` instruction, implemented with a portable
+/// scalar loop that visits whichever is fewer: unset or set bits in `mask`.
+///
+/// # Functional Example
+///
+/// Using 8 bits for brevity (the function operates on all 64). The low bits
+/// of `value` are scattered into the set positions of `mask`:
+///
+/// ```text
+/// bit:     7 6 5 4 3 2 1 0
+/// value:   0 0 0 b c e f h
+/// mask:    0 1 1 0 1 1 0 1
+/// result:  0 b c 0 e f 0 h
+/// ```
+///
+/// # Code Example
+///
+/// ```
+/// # use arrow_buffer::bit_util::{compress, expand};
+/// assert_eq!(expand(0b0000_1010, 0b0110_1101), 0b0010_0100);
+/// let value = 0b1011_0100;
+/// let mask = 0b0110_1101;
+/// assert_eq!(expand(compress(value, mask), mask), value & mask);
+/// ```
+#[inline]
+pub fn expand(mut value: u64, mask: u64) -> u64 {

Review Comment:
   added in 
[b44dc03](https://github.com/apache/arrow-rs/pull/10968/commits/b44dc03a6342b5e934031970bc8d424ce4cd07d4)



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