real XXH3 hash

This commit is contained in:
izzy2lost
2026-03-20 14:36:11 -04:00
parent 093e656756
commit 5d73065d73
3 changed files with 46 additions and 18 deletions
+20 -2
View File
@@ -112,6 +112,24 @@ else()
unset(BUILD_TESTING CACHE)
endif()
# --- xxHash ---
FetchContent_Declare(
xxhash
URL "https://github.com/Cyan4973/xxHash/archive/v0.8.3.tar.gz"
URL_HASH "SHA256=aae608dfe8213dfd05d909a57718ef82f30722c392344583d3f39050c7f29a80"
)
FetchContent_GetProperties(xxhash)
if(NOT xxhash_POPULATED)
if(POLICY CMP0169)
cmake_policy(PUSH)
cmake_policy(SET CMP0169 OLD)
endif()
FetchContent_Populate(xxhash)
if(POLICY CMP0169)
cmake_policy(POP)
endif()
endif()
# --- nv2a_vsh_cpu ---
set(NV2A_VSH_CPU_GIT_REV "1115255708c10c4841b65dcd2223262e7a316598")
set(nv2a_vsh_cpu_UNIT_TEST OFF CACHE BOOL "" FORCE)
@@ -648,7 +666,6 @@ list(FILTER XEMU_CORE_SOURCES EXCLUDE REGEX "util[\\\\/]coroutine-windows\\.c$")
list(FILTER XEMU_CORE_SOURCES EXCLUDE REGEX "util[\\\\/]cpuinfo-loongarch\\.c$")
list(FILTER XEMU_CORE_SOURCES EXCLUDE REGEX "util[\\\\/]cpuinfo-ppc\\.c$")
list(FILTER XEMU_CORE_SOURCES EXCLUDE REGEX "util[\\\\/]cpuinfo-riscv\\.c$")
list(FILTER XEMU_CORE_SOURCES EXCLUDE REGEX "util[\\\\/]fast-hash\\.c$")
list(FILTER XEMU_CORE_SOURCES EXCLUDE REGEX "util[\\\\/]event_notifier-win32\\.c$")
list(FILTER XEMU_CORE_SOURCES EXCLUDE REGEX "util[\\\\/]fdmon-epoll\\.c$")
list(FILTER XEMU_CORE_SOURCES EXCLUDE REGEX "util[\\\\/]fdmon-io_uring\\.c$")
@@ -761,7 +778,6 @@ list(APPEND XEMU_CORE_SOURCES
"${REPO_ROOT}/ui/vnc-stubs.c"
"${REPO_ROOT}/target/i386/kvm/hyperv-stub.c"
"${CMAKE_CURRENT_LIST_DIR}/kvmclock_stub.c"
"${CMAKE_CURRENT_LIST_DIR}/fast_hash_stub.c"
"${CMAKE_CURRENT_LIST_DIR}/libintl_stub.c"
"${CMAKE_CURRENT_LIST_DIR}/qmp_stub.c"
"${CMAKE_CURRENT_LIST_DIR}/monitor_stub.c"
@@ -778,6 +794,7 @@ list(APPEND XEMU_CORE_SOURCES
"${CMAKE_CURRENT_LIST_DIR}/xemu_os_utils_android.c"
"${CMAKE_CURRENT_LIST_DIR}/qcrypto_random_android.c"
"${CMAKE_CURRENT_LIST_DIR}/xemu_settings_android.cc"
"${xxhash_SOURCE_DIR}/xxhash.c"
)
# --- QAPI/Trace generation ---
@@ -1012,6 +1029,7 @@ target_compile_options(xemu_core PRIVATE -g0
target_include_directories(xemu_core PRIVATE
"${nv2a_vsh_cpu_SOURCE_DIR}/src"
"${xxhash_SOURCE_DIR}"
"${REPO_ROOT}"
"${REPO_ROOT}/include"
"${REPO_ROOT}/ui"
-16
View File
@@ -1,16 +0,0 @@
#include "qemu/osdep.h"
#include "qemu/fast-hash.h"
uint64_t fast_hash(const uint8_t *data, size_t len)
{
const uint64_t fnv_offset = 1469598103934665603ULL;
const uint64_t fnv_prime = 1099511628211ULL;
uint64_t hash = fnv_offset;
for (size_t i = 0; i < len; ++i) {
hash ^= (uint64_t)data[i];
hash *= fnv_prime;
}
return hash;
}
+26
View File
@@ -1,7 +1,33 @@
#include "qemu/fast-hash.h"
#include <xxhash.h>
#ifdef __ANDROID__
static uint64_t fast_hash_android_tiny(const uint8_t *data, size_t len)
{
const uint64_t fnv_offset = 1469598103934665603ULL;
const uint64_t fnv_prime = 1099511628211ULL;
uint64_t hash = fnv_offset;
for (size_t i = 0; i < len; i++) {
hash ^= data[i];
hash *= fnv_prime;
}
return hash;
}
#endif
uint64_t fast_hash(const uint8_t *data, size_t len)
{
#ifdef __ANDROID__
/*
* XXH3 is a clear win for the larger shader-state keys Android hashes,
* but very small TCG blocks can spend more time in XXH3 setup than in the
* hash itself. Keep a tiny-input fast path for those cases.
*/
if (len <= 4) {
return fast_hash_android_tiny(data, len);
}
#endif
return XXH3_64bits(data, len);
}