diff --git a/common_components/objects/base_string.cpp b/common_components/objects/base_string.cpp index 6ec3ada819b297d382b7cdc0a1bd3bce8883bbb3..b299519d8af258576dea0dcf14eb2bbcafcd836d 100644 --- a/common_components/objects/base_string.cpp +++ b/common_components/objects/base_string.cpp @@ -78,6 +78,7 @@ namespace common { template uint32_t ComputeHashForDataInternal(const T *data, size_t size, uint32_t hashSeed) { + /* if (size <= static_cast(StringHash::MIN_SIZE_FOR_UNROLLING)) { uint32_t hash = hashSeed; for (uint32_t i = 0; i < size; i++) { @@ -85,6 +86,37 @@ namespace common { } return hash; } + */ + constexpr uint32_t c1=31; + constexpr uint32_t c2=c1*c1; + constexpr uint32_t c3=c2*c1; + constexpr uint32_t c4=c3*c1; + constexpr uint32_t c5=c4*c1; + constexpr uint32_t c6=c5*c1; + constexpr uint32_t c7=c6*c1; + constexpr uint32_t c8=c7*c1; + + if(size<16) { + uint32_t hash=hashSeed; + T* ptr = (T*) data; + if (size&1) { + hash=hash*c1+*(ptr++); + } + if (size&2) { + hash=hash*c2+ptr[0]*c1+ptr[1]; + ptr+=2; + } + if (size&4) { + hash=hash*c4+ptr[0]*c3+ptr[1]*c2+ptr[2]*c1+ptr[3]; + ptr+=4; + } + if (size&8) { + hash=hash*c8+ptr[0]*c7+ptr[1]*c6+ptr[2]*c5+ptr[3]*c4+ptr[4]*c3+ptr[5]*c2+ptr[6]*c1+ptr[7]; + //ptr+=8 + } + return hash; + } + return StringHashHelper::ComputeHashForDataPlatform(data, size, hashSeed); } diff --git a/common_components/platform/arm64/string_hash_internal.h b/common_components/platform/arm64/string_hash_internal.h index 3f1c9e4266605ac0cccca0af292318c727ee233e..dc0fd6ab8a0283d0013368210df911606f77ade3 100644 --- a/common_components/platform/arm64/string_hash_internal.h +++ b/common_components/platform/arm64/string_hash_internal.h @@ -96,10 +96,40 @@ private: hash = hash * multiplierHash + vaddvq_u32(dataVec32_4); } + /* for (; p < dataEnd; p++) { hash = (hash << static_cast(StringHash::HASH_SHIFT)) - hash + *p; } return hash; + */ + + constexpr uint32_t c1=31; + constexpr uint32_t c2=c1*c1; + constexpr uint32_t c3=c2*c1; + constexpr uint32_t c4=c3*c1; + constexpr uint32_t c5=c4*c1; + constexpr uint32_t c6=c5*c1; + constexpr uint32_t c7=c6*c1; + constexpr uint32_t c8=c7*c1; + + size_t remainder=dataEnd-p; + const uint8_t* ptr = p; + if (remainder&1) { + hash=hash*c1+*(ptr++); + } + if (remainder&2) { + hash=hash*c2+ptr[0]*c1+ptr[1]; + ptr+=2; + } + if (remainder&4) { + hash=hash*c4+ptr[0]*c3+ptr[1]*c2+ptr[2]*c1+ptr[3]; + ptr+=4; + } + if (remainder&8) { + hash=hash*c8+ptr[0]*c7+ptr[1]*c6+ptr[2]*c5+ptr[3]*c4+ptr[4]*c3+ptr[5]*c2+ptr[6]*c1+ptr[7]; + //ptr+=8 + } + return hash; } template <> @@ -125,11 +155,40 @@ private: hash = hash * multiplierHash + vaddvq_u32(dataVec32_2); } + /* for (; p < dataEnd; p++) { hash = (hash << static_cast(StringHash::HASH_SHIFT)) - hash + *p; } return hash; + */ + constexpr uint32_t c1=31; + constexpr uint32_t c2=c1*c1; + constexpr uint32_t c3=c2*c1; + constexpr uint32_t c4=c3*c1; + constexpr uint32_t c5=c4*c1; + constexpr uint32_t c6=c5*c1; + constexpr uint32_t c7=c6*c1; + constexpr uint32_t c8=c7*c1; + + size_t remainder=dataEnd-p; + const uint16_t* ptr = p; + if (remainder&1) { + hash=hash*c1+*(ptr++); + } + if (remainder&2) { + hash=hash*c2+ptr[0]*c1+ptr[1]; + ptr+=2; + } + if (remainder&4) { + hash=hash*c4+ptr[0]*c3+ptr[1]*c2+ptr[2]*c1+ptr[3]; + ptr+=4; + } + if (remainder&8) { + hash=hash*c8+ptr[0]*c7+ptr[1]*c6+ptr[2]*c5+ptr[3]*c4+ptr[4]*c3+ptr[5]*c2+ptr[6]*c1+ptr[7]; + //ptr+=8 + } + return hash; } }; } // namespace common -#endif // COMMON_COMPONENTS_PLATFORM_STRING_HASH_ARM64_H \ No newline at end of file +#endif // COMMON_COMPONENTS_PLATFORM_STRING_HASH_ARM64_H