Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::BitpackingPrimitives Class Reference

Static Public Member Functions

template<class T, bool ASSUME_INPUT_ALIGNED = false>
static void PackBuffer (data_ptr_t dst, T *src, idx_t count, bitpacking_width_t width)
template<class T>
static void UnPackBuffer (data_ptr_t dst, data_ptr_t src, idx_t count, bitpacking_width_t width, bool skip_sign_extension=false)
template<class T>
static void PackBlock (data_ptr_t dst, T *src, bitpacking_width_t width)
template<class T>
static void UnPackBlock (data_ptr_t dst, data_ptr_t src, bitpacking_width_t width, bool skip_sign_extension=false)
template<class T, bool is_signed = NumericLimits<T>::IsSigned()>
static bitpacking_width_t MinimumBitWidth (T value)
template<class T, bool is_signed = NumericLimits<T>::IsSigned()>
static bitpacking_width_t MinimumBitWidth (T *values, idx_t count)
template<class T, bool is_signed = NumericLimits<T>::IsSigned()>
static bitpacking_width_t MinimumBitWidth (T minimum, T maximum)
static idx_t GetRequiredSize (idx_t count, bitpacking_width_t width)
template<class T>
static T RoundUpToAlgorithmGroupSize (T num_to_round)

Static Public Attributes

static constexpr const idx_t BITPACKING_ALGORITHM_GROUP_SIZE = 32
static constexpr const idx_t BITPACKING_HEADER_SIZE = sizeof(uint64_t)
static constexpr const bool BYTE_ALIGNED = false

Static Private Member Functions

template<class T, bool is_signed, bool round_to_next_byte = false>
static bitpacking_width_t FindMinimumBitWidth (T *values, idx_t count)
template<class T, bool is_signed, bool round_to_next_byte = false>
static bitpacking_width_t FindMinimumBitWidth (T min_value, T max_value)
template<class T, class T_U = typename MakeUnsigned<T>::type>
static void SignExtend (data_ptr_t dst, bitpacking_width_t width)
template<class T>
static bitpacking_width_t GetEffectiveWidth (bitpacking_width_t width)
template<class T>
static void PackGroup (data_ptr_t dst, T *values, bitpacking_width_t width)
template<class T>
static void UnPackGroup (data_ptr_t dst, data_ptr_t src, bitpacking_width_t width, bool skip_sign_extension=false)

Member Function Documentation

◆ PackBuffer()

template<class T, bool ASSUME_INPUT_ALIGNED = false>
void duckdb::BitpackingPrimitives::PackBuffer ( data_ptr_t dst,
T * src,
idx_t count,
bitpacking_width_t width )
inlinestatic
391581 {
391582 if (ASSUME_INPUT_ALIGNED) {
391583 for (idx_t i = 0; i < count; i += BITPACKING_ALGORITHM_GROUP_SIZE) {
391584 PackGroup<T>(dst + (i * width) / 8, src + i, width);
391585 }
391586 } else {
391587 idx_t misaligned_count = count % BITPACKING_ALGORITHM_GROUP_SIZE;
391588 count -= misaligned_count;
391589 for (idx_t i = 0; i < count; i += BITPACKING_ALGORITHM_GROUP_SIZE) {
391590 PackGroup<T>(dst + (i * width) / 8, src + i, width);
391591 }
391592
391593 // The input is not aligned to BITPACKING_ALGORITHM_GROUP_SIZE.
391594 // Copy the unaligned count into a zero-initialized temporary group, and pack it.
391595 if (misaligned_count) {
391596 T tmp_buffer[BITPACKING_ALGORITHM_GROUP_SIZE] = {0};
391597 memcpy(tmp_buffer, src + count, misaligned_count * sizeof(T));
391598 PackGroup<T>(dst + (count * width) / 8, tmp_buffer, width);
391599 }
391600 }
391601 }
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ UnPackBuffer()

template<class T>
void duckdb::BitpackingPrimitives::UnPackBuffer ( data_ptr_t dst,
data_ptr_t src,
idx_t count,
bitpacking_width_t width,
bool skip_sign_extension = false )
inlinestatic
391607 {
391608 for (idx_t i = 0; i < count; i += BITPACKING_ALGORITHM_GROUP_SIZE) {
391609 UnPackGroup<T>(dst + i * sizeof(T), src + (i * width) / 8, width, skip_sign_extension);
391610 }
391611 }

◆ PackBlock()

template<class T>
void duckdb::BitpackingPrimitives::PackBlock ( data_ptr_t dst,
T * src,
bitpacking_width_t width )
inlinestatic
391615 {
391616 return PackGroup<T>(dst, src, width);
391617 }

◆ UnPackBlock()

template<class T>
void duckdb::BitpackingPrimitives::UnPackBlock ( data_ptr_t dst,
data_ptr_t src,
bitpacking_width_t width,
bool skip_sign_extension = false )
inlinestatic
391622 {
391623 return UnPackGroup<T>(dst, src, width, skip_sign_extension);
391624 }

◆ MinimumBitWidth() [1/3]

template<class T, bool is_signed = NumericLimits<T>::IsSigned()>
bitpacking_width_t duckdb::BitpackingPrimitives::MinimumBitWidth ( T value)
inlinestatic
391628 {
391629 return FindMinimumBitWidth<T, is_signed, BYTE_ALIGNED>(value, value);
391630 }

◆ MinimumBitWidth() [2/3]

template<class T, bool is_signed = NumericLimits<T>::IsSigned()>
bitpacking_width_t duckdb::BitpackingPrimitives::MinimumBitWidth ( T * values,
idx_t count )
inlinestatic
391634 {
391635 return FindMinimumBitWidth<T, is_signed, BYTE_ALIGNED>(values, count);
391636 }

◆ MinimumBitWidth() [3/3]

template<class T, bool is_signed = NumericLimits<T>::IsSigned()>
bitpacking_width_t duckdb::BitpackingPrimitives::MinimumBitWidth ( T minimum,
T maximum )
inlinestatic
391641 {
391642 return FindMinimumBitWidth<T, is_signed, BYTE_ALIGNED>(minimum, maximum);
391643 }

◆ GetRequiredSize()

idx_t duckdb::BitpackingPrimitives::GetRequiredSize ( idx_t count,
bitpacking_width_t width )
inlinestatic
391645 {
391646 count = RoundUpToAlgorithmGroupSize(count);
391647 return ((count * width) / 8);
391648 }

◆ RoundUpToAlgorithmGroupSize()

template<class T>
T duckdb::BitpackingPrimitives::RoundUpToAlgorithmGroupSize ( T num_to_round)
inlinestatic
391651 {
391652 int remainder = num_to_round % BITPACKING_ALGORITHM_GROUP_SIZE;
391653 if (remainder == 0) {
391654 return num_to_round;
391655 }
391656
391657 return num_to_round + BITPACKING_ALGORITHM_GROUP_SIZE - NumericCast<idx_t>(remainder);
391658 }

◆ FindMinimumBitWidth() [1/2]

template<class T, bool is_signed, bool round_to_next_byte = false>
bitpacking_width_t duckdb::BitpackingPrimitives::FindMinimumBitWidth ( T * values,
idx_t count )
inlinestaticprivate
391662 {
391663 T min_value = values[0];
391664 T max_value = values[0];
391665
391666 for (idx_t i = 1; i < count; i++) {
391667 if (values[i] > max_value) {
391668 max_value = values[i];
391669 }
391670
391671 if (is_signed) {
391672 if (values[i] < min_value) {
391673 min_value = values[i];
391674 }
391675 }
391676 }
391677
391678 return FindMinimumBitWidth<T, is_signed, round_to_next_byte>(min_value, max_value);
391679 }

◆ FindMinimumBitWidth() [2/2]

template<class T, bool is_signed, bool round_to_next_byte = false>
bitpacking_width_t duckdb::BitpackingPrimitives::FindMinimumBitWidth ( T min_value,
T max_value )
inlinestaticprivate
391682 {
391683 bitpacking_width_t bitwidth;
391684 T value;
391685
391686 if (is_signed) {
391687 if (min_value == NumericLimits<T>::Minimum()) {
391688 // handle special case of the minimal value, as it cannot be negated like all other values.
391689 return sizeof(T) * 8;
391690 } else {
391691 value = MaxValue((T)-min_value, max_value);
391692 }
391693 } else {
391694 value = max_value;
391695 }
391696
391697 if (value == 0) {
391698 return 0;
391699 }
391700
391701 if (is_signed) {
391702 bitwidth = 1;
391703 } else {
391704 bitwidth = 0;
391705 }
391706
391707 while (value) {
391708 bitwidth++;
391709 value >>= 1;
391710 }
391711
391712 bitwidth = GetEffectiveWidth<T>(bitwidth);
391713
391714 // Assert results are correct
391715#ifdef DEBUG
391716 if (bitwidth < sizeof(T) * 8 && bitwidth != 0) {
391717 if (is_signed) {
391718 D_ASSERT(max_value <= (T(1) << (bitwidth - 1)) - 1);
391719 // D_ASSERT(min_value >= (T(-1) * ((T(1) << (bitwidth - 1)) - 1) - 1));
391720 } else {
391721 D_ASSERT(max_value <= (T(1) << (bitwidth)) - 1);
391722 }
391723 }
391724#endif
391725 if (round_to_next_byte) {
391726 return (bitwidth / 8 + (bitwidth % 8 != 0)) * 8;
391727 }
391728 return bitwidth;
391729 }

◆ SignExtend()

template<class T, class T_U = typename MakeUnsigned<T>::type>
void duckdb::BitpackingPrimitives::SignExtend ( data_ptr_t dst,
bitpacking_width_t width )
inlinestaticprivate
391733 {
391734 T const mask = UnsafeNumericCast<T>(T_U(1) << (width - 1));
391735 for (idx_t i = 0; i < BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE; ++i) {
391736 T value = Load<T>(dst + i * sizeof(T));
391737 value = UnsafeNumericCast<T>(T_U(value) & ((T_U(1) << width) - T_U(1)));
391738 T result = (value ^ mask) - mask;
391739 Store(result, dst + i * sizeof(T));
391740 }
391741 }
GMat mask(const GMat &src, const GMat &mask)

◆ GetEffectiveWidth()

template<class T>
bitpacking_width_t duckdb::BitpackingPrimitives::GetEffectiveWidth ( bitpacking_width_t width)
inlinestaticprivate
391745 {
391746 bitpacking_width_t bits_of_type = sizeof(T) * 8;
391747 bitpacking_width_t type_size = sizeof(T);
391748 if (width + type_size > bits_of_type) {
391749 return bits_of_type;
391750 }
391751 return width;
391752 }

◆ PackGroup()

template<class T>
void duckdb::BitpackingPrimitives::PackGroup ( data_ptr_t dst,
T * values,
bitpacking_width_t width )
inlinestaticprivate
391755 {
391756 if (std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value) {
391757 duckdb_fastpforlib::fastpack(reinterpret_cast<const uint8_t *>(values), reinterpret_cast<uint8_t *>(dst),
391758 static_cast<uint32_t>(width));
391759 } else if (std::is_same<T, int16_t>::value || std::is_same<T, uint16_t>::value) {
391760 duckdb_fastpforlib::fastpack(reinterpret_cast<const uint16_t *>(values), reinterpret_cast<uint16_t *>(dst),
391761 static_cast<uint32_t>(width));
391762 } else if (std::is_same<T, int32_t>::value || std::is_same<T, uint32_t>::value) {
391763 duckdb_fastpforlib::fastpack(reinterpret_cast<const uint32_t *>(values), reinterpret_cast<uint32_t *>(dst),
391764 static_cast<uint32_t>(width));
391765 } else if (std::is_same<T, int64_t>::value || std::is_same<T, uint64_t>::value) {
391766 duckdb_fastpforlib::fastpack(reinterpret_cast<const uint64_t *>(values), reinterpret_cast<uint32_t *>(dst),
391767 static_cast<uint32_t>(width));
391768 } else if (std::is_same<T, hugeint_t>::value || std::is_same<T, uhugeint_t>::value) {
391769 HugeIntPacker::Pack(reinterpret_cast<const uhugeint_t *>(values), reinterpret_cast<uint32_t *>(dst), width);
391770 } else {
391771 throw InternalException("Unsupported type for bitpacking");
391772 }
391773 }
::uint32_t uint32_t
::uint8_t uint8_t
::uint64_t uint64_t
::uint16_t uint16_t

◆ UnPackGroup()

template<class T>
void duckdb::BitpackingPrimitives::UnPackGroup ( data_ptr_t dst,
data_ptr_t src,
bitpacking_width_t width,
bool skip_sign_extension = false )
inlinestaticprivate
391777 {
391778 if (std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value) {
391779 duckdb_fastpforlib::fastunpack(reinterpret_cast<const uint8_t *>(src), reinterpret_cast<uint8_t *>(dst),
391780 static_cast<uint32_t>(width));
391781 } else if (std::is_same<T, int16_t>::value || std::is_same<T, uint16_t>::value) {
391782 duckdb_fastpforlib::fastunpack(reinterpret_cast<const uint16_t *>(src), reinterpret_cast<uint16_t *>(dst),
391783 static_cast<uint32_t>(width));
391784 } else if (std::is_same<T, int32_t>::value || std::is_same<T, uint32_t>::value) {
391785 duckdb_fastpforlib::fastunpack(reinterpret_cast<const uint32_t *>(src), reinterpret_cast<uint32_t *>(dst),
391786 static_cast<uint32_t>(width));
391787 } else if (std::is_same<T, int64_t>::value || std::is_same<T, uint64_t>::value) {
391788 duckdb_fastpforlib::fastunpack(reinterpret_cast<const uint32_t *>(src), reinterpret_cast<uint64_t *>(dst),
391789 static_cast<uint32_t>(width));
391790 } else if (std::is_same<T, hugeint_t>::value || std::is_same<T, uhugeint_t>::value) {
391791 HugeIntPacker::Unpack(reinterpret_cast<const uint32_t *>(src), reinterpret_cast<uhugeint_t *>(dst), width);
391792 } else {
391793 throw InternalException("Unsupported type for bitpacking");
391794 }
391795
391796 if (NumericLimits<T>::IsSigned() && !skip_sign_extension && width > 0 && width < sizeof(T) * 8) {
391797 SignExtend<T>(dst, width);
391798 }
391799 }

The documentation for this class was generated from the following file: