| 384 | } |
| 385 | |
| 386 | inline void DoMergeStreams(const uint8_t** src_streams, int width, int64_t nvalues, |
| 387 | uint8_t* dest) { |
| 388 | // Value empirically chosen to provide the best performance on the author's machine |
| 389 | constexpr int kBlockSize = 128; |
| 390 | |
| 391 | while (nvalues >= kBlockSize) { |
| 392 | for (int stream = 0; stream < width; ++stream) { |
| 393 | // Take kBlockSize bytes from the given stream and spread them |
| 394 | // to their logical places in destination. |
| 395 | const uint8_t* src = src_streams[stream]; |
| 396 | for (int i = 0; i < kBlockSize; i += 8) { |
| 397 | uint64_t v = arrow::util::SafeLoadAs<uint64_t>(&src[i]); |
| 398 | #if ARROW_LITTLE_ENDIAN |
| 399 | dest[stream + i * width] = static_cast<uint8_t>(v); |
| 400 | dest[stream + (i + 1) * width] = static_cast<uint8_t>(v >> 8); |
| 401 | dest[stream + (i + 2) * width] = static_cast<uint8_t>(v >> 16); |
| 402 | dest[stream + (i + 3) * width] = static_cast<uint8_t>(v >> 24); |
| 403 | dest[stream + (i + 4) * width] = static_cast<uint8_t>(v >> 32); |
| 404 | dest[stream + (i + 5) * width] = static_cast<uint8_t>(v >> 40); |
| 405 | dest[stream + (i + 6) * width] = static_cast<uint8_t>(v >> 48); |
| 406 | dest[stream + (i + 7) * width] = static_cast<uint8_t>(v >> 56); |
| 407 | #else |
| 408 | dest[stream + i * width] = static_cast<uint8_t>(v >> 56); |
| 409 | dest[stream + (i + 1) * width] = static_cast<uint8_t>(v >> 48); |
| 410 | dest[stream + (i + 2) * width] = static_cast<uint8_t>(v >> 40); |
| 411 | dest[stream + (i + 3) * width] = static_cast<uint8_t>(v >> 32); |
| 412 | dest[stream + (i + 4) * width] = static_cast<uint8_t>(v >> 24); |
| 413 | dest[stream + (i + 5) * width] = static_cast<uint8_t>(v >> 16); |
| 414 | dest[stream + (i + 6) * width] = static_cast<uint8_t>(v >> 8); |
| 415 | dest[stream + (i + 7) * width] = static_cast<uint8_t>(v); |
| 416 | #endif |
| 417 | } |
| 418 | src_streams[stream] += kBlockSize; |
| 419 | } |
| 420 | dest += width * kBlockSize; |
| 421 | nvalues -= kBlockSize; |
| 422 | } |
| 423 | |
| 424 | // Epilog |
| 425 | for (int stream = 0; stream < width; ++stream) { |
| 426 | const uint8_t* src = src_streams[stream]; |
| 427 | for (int64_t i = 0; i < nvalues; ++i) { |
| 428 | dest[stream + i * width] = src[i]; |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | template <int kNumStreams> |
| 434 | void ByteStreamSplitEncodeScalar(const uint8_t* raw_values, int width, |
no outgoing calls
no test coverage detected