Skip to content

Commit

Permalink
Add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
zanmato1984 committed Jun 17, 2024
1 parent c8044b9 commit 95f31f3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cpp/src/arrow/compute/row/compare_internal_avx2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ uint32_t KeyCompare::CompareBinaryColumnToRowHelper_avx2(

namespace {

/// Intrinsics `_mm256_i32gather_epi32/64` treat the `vindex` as signed integer, and we
/// are using `uint32_t` to represent the offset, in range of [0, 4G), within the row
/// table. When the offset is larger than `0x80000000` (2GB), those intrinsics will treat
/// it as negative offset and gather the data from undesired address. To avoid this issue,
/// we normalize the addresses by translating `base` `0x80000000` higher, and `offset`
/// `0x80000000` lower. This way, the offset is always in range of [-2G, 2G) and those
/// intrinsics are safe.

inline __m256i UnsignedOffsetSafeGather32(int const* base, __m256i offset,
const int scale = 1) {
auto normalized_base = base + 0x80000000ull / sizeof(int);
Expand Down

0 comments on commit 95f31f3

Please sign in to comment.