google / highwayhash

Fast strong hash functions: SipHash/HighwayHash
Apache License 2.0
1.52k stars 185 forks source link

Question: SSSE3 #79

Open easyaspi314 opened 5 years ago

easyaspi314 commented 5 years ago

HighwayHash can easily be adapted to SSSE3 with only a few changes:

  1. Remove the min, max, and stream functions in vector128.h. We don't use them.
  2. Change V128<uint64_t>::operator== to this:
    // There are no greater-than comparison instructions for unsigned T.
    HH_INLINE V128 operator==(const V128& other) const {
    #ifdef __SSE4_1__
    return V128(_mm_cmpeq_epi64(v_, other.v_));
    #else 
    // Do a 32-bit equality comparison, then AND the high bits and the low bits. If the
    // vectors are equal, the result will be
    //    0xFFFFFFFFFFFFFFFF & 0xFFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFF
    // and if not, it will be
    //    0xFFFFFFFF00000000 & 0x00000000FFFFFFFF = 0x0000000000000000
    __m128i cmp = _mm_cmpeq_epi32(v_, other.v_);
    return V128(_mm_and_si128(cmp, _mm_shuffle_epi32(cmp, _MM_SHUFFLE(2, 3, 0, 1))));
    #endif
    }
  3. Change the _mm_insert_epi32 in HHStateSSE41::UpdateRemainder to this:
      packetH = V2x64U(_mm_insert_epi16(_mm_insert_epi16(packetH, last4 & 0xFFFF, 6), last4 >> 16, 7));
  4. Change the second _mm_insert_epi32 in HHStateSSE41::XorByShift128Left12 to this:
    const V2x64U sign_bit128(_mm_insert_epi16(zero, 0x8000u, 7));

    Done.

If we add it, the only issue I see is what do we name it, and what do we do with the SSE41 target?

jan-wassenberg commented 4 years ago

@easyaspi314 These look like reasonable workarounds, we could rely on #if inside the same file, but generally we are targeting SSE4.1 as a minimum baseline (Penryn was launched in 2008). Can you help me understand if/why SSSE3 support is required?

johnplatts commented 4 months ago

simdhwyhash, which is an implementation of the HighwayHash algorithm that uses the Google Highway library, supports some additional SIMD targets such as SSE2, SSSE3, AVX3 (AVX512F+AVX512CD+AVX512VL+AVX512BW+AVX512DQ), RVV, SVE, and Z14.

The simdhwyhash implementation can be found at https://github.com/johnplatts/simdhwyhash.

jan-wassenberg commented 4 months ago

I warmly endorse @johnplatts's simdhwyhash implementation :)