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::ValidityUncompressed Struct Reference

Static Public Member Functions

static CompressionFunction GetFunction (PhysicalType data_type)
static void AlignedScan (data_ptr_t input, idx_t input_start, Vector &result, idx_t scan_count)
static void UnalignedScan (data_ptr_t input, idx_t input_size, idx_t input_start, Vector &result, idx_t result_offset, idx_t scan_count)

Static Public Attributes

static const validity_t LOWER_MASKS [65]
static const validity_t UPPER_MASKS [65]

Member Function Documentation

◆ GetFunction()

CompressionFunction duckdb::ValidityUncompressed::GetFunction ( PhysicalType data_type)
static
406741 {
406742 D_ASSERT(data_type == PhysicalType::BIT);
406743 return CompressionFunction(CompressionType::COMPRESSION_UNCOMPRESSED, data_type, ValidityInitAnalyze,
406744 ValidityAnalyze, ValidityFinalAnalyze, UncompressedFunctions::InitCompression,
406745 UncompressedFunctions::Compress, UncompressedFunctions::FinalizeCompress,
406746 ValidityInitScan, ValidityScan, ValidityScanPartial, ValidityFetchRow,
406747 UncompressedFunctions::EmptySkip, ValidityInitSegment, ValidityInitAppend,
406748 ValidityAppend, ValidityFinalizeAppend, ValidityRevertAppend);
406749}
@ BIT
Boolean as 1 bit, LSB bit-packed ordering.
Definition duckdb.hpp:2852

◆ AlignedScan()

void duckdb::ValidityUncompressed::AlignedScan ( data_ptr_t input,
idx_t input_start,
Vector & result,
idx_t scan_count )
static
406576 {
406577 D_ASSERT(input_start % ValidityMask::BITS_PER_VALUE == 0);
406578
406579 // aligned scan: no need to do anything fancy
406580 // note: this is only an optimization which avoids having to do messy bitshifting in the common case
406581 // it is not required for correctness
406582 auto &result_mask = FlatVector::Validity(result);
406583 auto input_data = reinterpret_cast<validity_t *>(input);
406584 auto result_data = result_mask.GetData();
406585 idx_t start_offset = input_start / ValidityMask::BITS_PER_VALUE;
406586 idx_t entry_scan_count = (scan_count + ValidityMask::BITS_PER_VALUE - 1) / ValidityMask::BITS_PER_VALUE;
406587 for (idx_t i = 0; i < entry_scan_count; i++) {
406588 auto input_entry = input_data[start_offset + i];
406589 if (!result_data && input_entry == ValidityMask::ValidityBuffer::MAX_ENTRY) {
406590 continue;
406591 }
406592 if (!result_data) {
406593 result_mask.Initialize();
406594 result_data = result_mask.GetData();
406595 }
406596 result_data[i] = input_entry;
406597 }
406598}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ UnalignedScan()

void duckdb::ValidityUncompressed::UnalignedScan ( data_ptr_t input,
idx_t input_size,
idx_t input_start,
Vector & result,
idx_t result_offset,
idx_t scan_count )
static

ANDs scan_count validity bits from input (starting at input_start) into the result validity mask (starting at result_offset). If a bit in the result is already invalid (0), it remains invalid regardless of the input bit value - i.e., the operation is result[i] &= input[i]. This function should be used, as the name suggests, if the starting points are unaligned relative to ValidityMask::BITS_PER_VALUE, otherwise AlignedScan should be used (however this function will still work).

406363 {
406364 D_ASSERT(input_start < input_size);
406365 auto &result_mask = FlatVector::Validity(result);
406366 auto input_data = reinterpret_cast<validity_t *>(input);
406367
406368#ifdef DEBUG
406369 // save boundary entries to verify we don't corrupt surrounding bits later.
406370 idx_t debug_first_entry = result_offset / ValidityMask::BITS_PER_VALUE;
406371 idx_t debug_last_entry = (result_offset + scan_count - 1) / ValidityMask::BITS_PER_VALUE;
406372 auto debug_result_data = (validity_t *)result_mask.GetData();
406373 validity_t debug_original_first_entry =
406374 debug_result_data ? debug_result_data[debug_first_entry] : ValidityMask::ValidityBuffer::MAX_ENTRY;
406375 validity_t debug_original_last_entry =
406376 debug_result_data ? debug_result_data[debug_last_entry] : ValidityMask::ValidityBuffer::MAX_ENTRY;
406377
406378 // save original result validity for in-range verification (usually this function is meant to be called
406379 // with all result bits set to valid, but in some instances, the result bits may be invalid, in which case,
406380 // the result bits should remain invalid, i.e. we do not copy over the input bit.
406381 ValidityMask debug_original_result(scan_count);
406382 if (debug_result_data) {
406383 for (idx_t i = 0; i < scan_count; i++) {
406384 if (!result_mask.RowIsValid(result_offset + i)) {
406385 debug_original_result.SetInvalid(i);
406386 }
406387 }
406388 }
406389#endif
406390
406391#if STANDARD_VECTOR_SIZE < 128
406392 // fallback for tiny vector sizes
406393 // the bitwise ops we use below don't work if the vector size is too small
406394 ValidityMask source_mask128(input_data, input_size);
406395 for (idx_t i = 0; i < scan_count; i++) {
406396 if (!source_mask128.RowIsValid(input_start + i)) {
406397 if (result_mask.AllValid()) {
406398 result_mask.Initialize();
406399 }
406400 result_mask.SetInvalid(result_offset + i);
406401 }
406402 }
406403#else
406404 // the code below does what the fallback code above states, but using bitwise ops:
406405 auto result_data = (validity_t *)result_mask.GetData();
406406
406407 // set up the initial positions
406408 // we need to find the validity_entry to modify, together with the bit-index WITHIN the validity entry
406409 idx_t result_entry = result_offset / ValidityMask::BITS_PER_VALUE;
406410 idx_t result_idx = result_offset - result_entry * ValidityMask::BITS_PER_VALUE;
406411
406412 // same for the input: find the validity_entry we are pulling from, together with the bit-index WITHIN that entry
406413 idx_t input_entry = input_start / ValidityMask::BITS_PER_VALUE;
406414 idx_t input_idx = input_start - input_entry * ValidityMask::BITS_PER_VALUE;
406415
406416 // Window scanning algorithm -- the goal is to copy a contiguous sequence of bits from input into result,
406417 // and to do this using bit operations on 64 bit fields.
406418 //
406419 // The algorithm is simply explained with the diagram below: each loop iteration is numbered, and within each
406420 // iteration we are copying the numbered window from the input to the corresponding window in the result.
406421 //
406422 // input_entry and result_entry are the 64 bit entries, i.e. on any given loop iteration we only want to be
406423 // performing bit operations on 64 bit entries.
406424 //
406425 // input_index and result_index are the current offset within each entry. We can calculate the current window size
406426 // as the minimum between the remaining bits to process in each entry.
406427 //
406428 // INPUT:
406429 // 0 63| 127| 191
406430 // +-------------------------------+--------------------------------+--------------------------------+
406431 // | [ 1 ]|[ 2 ][ 3 ]|[ 4 ][ 5 ]|
406432 // +-------------------------------+--------------------------------+--------------------------------+
406433 //
406434 // RESULT:
406435 // 0 63| 127| 191
406436 // +-------------------------------+--------------------------------+--------------------------------+
406437 // [ 1 ][ 2 ]|[ 3 ][ 4 ]|[ 5 ] |
406438 // +-------------------------------+--------------------------------+--------------------------------+
406439 //
406440 // Note: in case this ever becomes a bottleneck, it should be possible to make each loop iteration branchless.
406441 // The idea would be to do an odd iteration before the loop, then have two loops depending on the layout of the
406442 // windows that will either shift left then right on each iteration, or the other loop will always shift right
406443 // then left. For example, in the diagram above, we would first apply the first window outside of the loop
406444 // beforehand, then we can see that each loop iteration requires us to shift right, fetch a new result entry,
406445 // shift left, fetch a new input entry. This would have to be generalized to two possible branchless loops,
406446 // depending on the input.
406447
406448 // now start the bit games
406449 idx_t pos = 0;
406450 while (pos < scan_count) {
406451 validity_t input_mask = input_data[input_entry];
406452 idx_t bits_left = scan_count - pos;
406453
406454 // these are bits left within the current entries (possibly extra than what we need).
406455 idx_t input_bits_left = ValidityMask::BITS_PER_VALUE - input_idx;
406456 idx_t result_bits_left = ValidityMask::BITS_PER_VALUE - result_idx;
406457
406458 // these are the bits left within the current entries that need to be processed.
406459 idx_t input_window_size = MinValue(bits_left, input_bits_left);
406460 idx_t result_window_size = MinValue(bits_left, result_bits_left);
406461
406462 // the smaller of the two is our next window to copy from input to result.
406463 idx_t window_size = MinValue(input_window_size, result_window_size);
406464
406465 // Within each loop iteration, copy the window from the starting index in input over to the starting index
406466 // of result, without corrupting surrounding bits in the result entry.
406467
406468 // First, line up the windows:
406469 if (result_idx < input_idx) {
406470 // X is arbitrary bits, P is arbitrary protected bits.
406471 // INPUT ENTRY:
406472 // 63 0
406473 // +--------------------------------------------------------------------------------------------------+
406474 // |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX[=============WINDOW=============]XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|
406475 // +--------------------------------------------------------------------------------------------------+
406476 // ^
406477 // input_idx
406478 //
406479 // RESULT ENTRY:
406480 // 63 0
406481 // +--------------------------------------------------------------------------------------------------+
406482 // |PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP[=============WINDOW=============]PPPPPPPPPPPPPPPPPPPPPP|
406483 // +--------------------------------------------------------------------------------------------------+
406484 // ^
406485 // result_idx
406486 //
406487 idx_t shift_amount = input_idx - result_idx;
406488 input_mask = input_mask >> shift_amount;
406489 } else {
406490 // current_result_idx >= current_input_idx
406491 idx_t shift_amount = result_idx - input_idx;
406492 input_mask = (input_mask & ~UPPER_MASKS[shift_amount]);
406493
406494 // X is arbitrary bits, P is arbitrary protected bits.
406495 // Note the zeroed out bits in INPUT_ENTRY - these have to be zeroed before shifting left to align with
406496 // result window, to prevent overflow.
406497 //
406498 // INPUT ENTRY:
406499 // 63 0
406500 // +--------------------------------------------------------------------------------------------------+
406501 // |000000000000XXXXXXXXXXXXXXXXXXXX[=============WINDOW=============]XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|
406502 // +--------------------------------------------------------------------------------------------------+
406503 // ^
406504 // input_idx
406505 //
406506 // RESULT ENTRY:
406507 // 63 0
406508 // +--------------------------------------------------------------------------------------------------+
406509 // |PPPPPPPPPPPPPPPPPPPP[=============WINDOW=============]PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP|
406510 // +--------------------------------------------------------------------------------------------------+
406511 // ^
406512 // result_idx
406513 input_mask = input_mask << shift_amount;
406514 }
406515
406516 // Once the windows are aligned, mask the input to prevent overwriting protected bits in the result_mask.
406517 auto protected_upper_bits = UPPER_MASKS[ValidityMask::BITS_PER_VALUE - result_idx - window_size];
406518 auto protected_lower_bits = LOWER_MASKS[result_idx];
406519 input_mask |= protected_upper_bits;
406520 input_mask |= protected_lower_bits;
406521
406522 if (input_mask != ValidityMask::ValidityBuffer::MAX_ENTRY) {
406523 if (!result_data) {
406524 result_mask.Initialize();
406525 result_data = (validity_t *)result_mask.GetData();
406526 }
406527 result_data[result_entry] &= input_mask;
406528 }
406529 // Now update pos, entries, and indexes for the next iteration.
406530 pos += window_size;
406531
406532 // Windows can only go until the end of the current entry, so the mod can only wrap to 0 here.
406533 input_idx = (input_idx + window_size) % ValidityMask::BITS_PER_VALUE;
406534 result_idx = (result_idx + window_size) % ValidityMask::BITS_PER_VALUE;
406535
406536 // Advance entries if the mod was 0.
406537 if (input_idx == 0) {
406538 input_entry++;
406539 }
406540 if (result_idx == 0) {
406541 result_entry++;
406542 }
406543 }
406544#endif
406545
406546#ifdef DEBUG
406547 // verify in-range bits.
406548 ValidityMask source_mask(input_data, input_size);
406549 for (idx_t i = 0; i < scan_count; i++) {
406550 bool original_valid = debug_original_result.RowIsValid(i);
406551 bool input_valid = source_mask.RowIsValid(input_start + i);
406552 bool result_valid = result_mask.RowIsValid(result_offset + i);
406553 D_ASSERT(result_valid == (original_valid && input_valid));
406554 }
406555
406556 // verify surrounding bits weren't modified
406557 auto debug_final_result_data = (validity_t *)result_mask.GetData();
406558 validity_t debug_final_first_entry =
406559 debug_final_result_data ? debug_final_result_data[debug_first_entry] : ValidityMask::ValidityBuffer::MAX_ENTRY;
406560 validity_t debug_final_last_entry =
406561 debug_final_result_data ? debug_final_result_data[debug_last_entry] : ValidityMask::ValidityBuffer::MAX_ENTRY;
406562
406563 idx_t first_bit_in_first_entry = result_offset % ValidityMask::BITS_PER_VALUE;
406564 idx_t last_bit_in_last_entry = (result_offset + scan_count - 1) % ValidityMask::BITS_PER_VALUE;
406565
406566 // lower bits of first entry should be unchanged
406567 validity_t lower_mask = LOWER_MASKS[first_bit_in_first_entry];
406568 D_ASSERT((debug_original_first_entry & lower_mask) == (debug_final_first_entry & lower_mask));
406569
406570 // upper bits of last entry should be unchanged
406571 validity_t upper_mask = UPPER_MASKS[ValidityMask::BITS_PER_VALUE - last_bit_in_last_entry - 1];
406572 D_ASSERT((debug_original_last_entry & upper_mask) == (debug_final_last_entry & upper_mask));
406573#endif
406574}
Here is the call graph for this function:

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