pitrou commented on code in PR #50217:
URL: https://github.com/apache/arrow/pull/50217#discussion_r3452895999
##########
cpp/src/arrow/util/bit_util.h:
##########
@@ -176,6 +179,54 @@ static constexpr bool GetBitFromByte(uint8_t byte, uint8_t
i) {
return byte & kBitmask[i];
}
+/// Read 32 bits starting at bit `offset` into a uint32.
+///
+/// The return value in in-memory byte layout matches the source bit-stream
+/// identically on little- and big-endian platforms.
+///
+/// The caller must guarantee that many bytes are readable.
+static inline uint32_t Get32Bits(const uint8_t* bits, uint64_t offset) {
+ uint64_t buffer = {};
+ std::memcpy(&buffer, bits + (offset / 8), BytesForBits(offset % 8 + 32));
+ // Interpret the loaded bytes as little-endian, drop the low `offset % 8`
bits
+ // to align LSB-first, then store back in little-endian byte order so the
+ // result's memory representation matches the bit-stream.
+ buffer = FromLittleEndian(buffer);
+ return ToLittleEndian(static_cast<uint32_t>(buffer >> (offset % 8)));
+}
+
+template <typename Uint>
+struct CopyBitsParams {
+ Uint src = {};
+ Uint dst = {};
+ Uint start = {};
+ Uint end = {};
Review Comment:
Not sure why `start` and `end` are templated as well?
--
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]