Initialize a dense array of 'num_tuples' tuples. TODO: we could do better here if we inlined the tuple and null indicator byte widths with codegen to eliminate all the branches in memcpy()/memset().
| 635 | /// TODO: we could do better here if we inlined the tuple and null indicator byte |
| 636 | /// widths with codegen to eliminate all the branches in memcpy()/memset(). |
| 637 | void InitTupleBuffer( |
| 638 | Tuple* template_tuple, uint8_t* __restrict__ tuple_mem, int64_t num_tuples) { |
| 639 | const TupleDescriptor* desc = scan_node_->tuple_desc(); |
| 640 | const int tuple_byte_size = desc->byte_size(); |
| 641 | // Handle the different template/non-template cases with different loops to avoid |
| 642 | // unnecessary branches inside the loop. |
| 643 | if (template_tuple != nullptr) { |
| 644 | for (int64_t i = 0; i < num_tuples; ++i) { |
| 645 | InitTupleFromTemplate( |
| 646 | template_tuple, reinterpret_cast<Tuple*>(tuple_mem), tuple_byte_size); |
| 647 | tuple_mem += tuple_byte_size; |
| 648 | } |
| 649 | } else if (tuple_byte_size <= CACHELINE_SIZE) { |
| 650 | // If each tuple fits in a cache line, it is quicker to zero the whole memory buffer |
| 651 | // instead of just the null indicators. This is because we are fetching the cache |
| 652 | // line anyway and zeroing a cache line is cheap (a couple of AVX2 instructions) |
| 653 | // compared with the overhead of calling memset() row-by-row. |
| 654 | memset(tuple_mem, 0, num_tuples * tuple_byte_size); |
| 655 | } else { |
| 656 | const int null_bytes_offset = desc->null_bytes_offset(); |
| 657 | const int num_null_bytes = desc->num_null_bytes(); |
| 658 | for (int64_t i = 0; i < num_tuples; ++i) { |
| 659 | reinterpret_cast<Tuple*>(tuple_mem)->ClearNullBits( |
| 660 | null_bytes_offset, num_null_bytes); |
| 661 | tuple_mem += tuple_byte_size; |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | /// Returns true iff 'template_tuple' is non-NULL. |
| 667 | /// Not inlined in IR so it can be replaced with a constant. |
nothing calls this directly
no test coverage detected