zanmato1984 commented on code in PR #45108:
URL: https://github.com/apache/arrow/pull/45108#discussion_r1904836903


##########
cpp/src/arrow/compute/key_map_internal_avx2.cc:
##########
@@ -392,16 +392,32 @@ int SwissTable::extract_group_ids_avx2(const int 
num_keys, const uint32_t* hashe
   } else {
     for (int i = 0; i < num_keys / unroll; ++i) {
       __m256i hash = _mm256_loadu_si256(reinterpret_cast<const 
__m256i*>(hashes) + i);
+      // Extend hash and local_slot to 64-bit to compute 64-bit group id 
offsets to
+      // gather.
+      // This is to prevent index overflow issues in GH-44513.
+      // NB: Use zero-extend conversion for unsigned hash.
+      __m256i hash_lo = _mm256_cvtepu32_epi64(_mm256_castsi256_si128(hash));
+      __m256i hash_hi = _mm256_cvtepu32_epi64(_mm256_extracti128_si256(hash, 
1));
       __m256i local_slot =
           _mm256_set1_epi64x(reinterpret_cast<const 
uint64_t*>(local_slots)[i]);
       local_slot = _mm256_shuffle_epi8(

Review Comment:
   I was thinking that we can save one multiply of `local_offset * byte_size`. 
But yeah, once we shuffled to 64-bit lanes, we can use `_mm256_mul_epi32` (5 
cycles) to replace `_mm256_mullo_epi32` (10 cycles), then we have 2 
`_mm256_shuffle_epi8`s (1 cycle each) + 2 `_mm256_mul_epi32`s = 12 cycles in 
total, VS., 1 `_mm256_shuffle_epi8` + 1 `_mm256_mullo_epi32` + 2 
`_mm256_cvtepi32_epi64` (3 cycles each) = 17 cycles in total, which is still a 
win.
   
   I've updated. Thank you for this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to