Add experimental XXH3 hash implementation with SIMD acceleration

Memory write speed using the C memset() function:
  memset   57952

Hash used to check the data blocks integrity:
            best murmur3 spooky2 museair    xxh3   xsse2   xavx2
    hash spooky2    6172   17914   32048   14627   23613   44034
This commit is contained in:
Andrea Mazzoleni 2026-09-30 09:13:57 +02:00
parent f0ae584473
commit cea9015933
17 changed files with 5498 additions and 13 deletions

View file

@ -787,6 +787,7 @@ const char* memhashname(unsigned kind)
case HASH_MURMUR3 : return "murmur3";
case HASH_SPOOKY2 : return "spooky2";
case HASH_MUSEAIR : return "museair";
case HASH_XXH3 : return "xxh3";
}
return 0;
@ -810,6 +811,26 @@ unsigned membesthash(void)
#include "murmur3.c"
#include "spooky2.c"
#include "museair.c"
#include "xxh3.c"
static void (*xxh3)(const void* bytes, size_t len, const uint8_t* seed, uint8_t* out) = xxh3_128;
void hash_init(void)
{
xxh3 = xxh3_128;
#if CONFIG_X86
if (raid_cpu_has_avx512f()) {
xxh3 = xxh3_128_avx512;
} else if (raid_cpu_has_avx2()) {
xxh3 = xxh3_128_avx2;
} else if (raid_cpu_has_sse2()) {
xxh3 = xxh3_128_sse2;
}
#endif
#if defined(CONFIG_NEON) || defined(CONFIG_NEON32)
xxh3 = xxh3_128_neon;
#endif
}
void memhash(unsigned kind, const unsigned char* seed, void* digest, const void* src, size_t size)
{
@ -823,6 +844,9 @@ void memhash(unsigned kind, const unsigned char* seed, void* digest, const void*
case HASH_MUSEAIR :
MuseAirLoong(src, size, seed, digest);
break;
case HASH_XXH3 :
xxh3(src, size, seed, digest);
break;
default :
/* LCOV_EXCL_START */
log_fatal(EINTERNAL, "Internal inconsistency in hash function %u\n", kind);
@ -859,6 +883,7 @@ const char* hash_config_name(unsigned kind)
case HASH_MURMUR3 : return "murmur3";
case HASH_SPOOKY2 : return "spooky2";
case HASH_MUSEAIR : return "museair";
case HASH_XXH3 : return "xxh3";
default :
/* LCOV_EXCL_START */
return "unknown";