Add xxHash submodule and CMake integration for fast hashing

This commit is contained in:
2025-09-30 20:04:45 +01:00
parent f34215f33c
commit 88816c37fd
4 changed files with 65 additions and 1 deletions

3
.gitmodules vendored
View File

@@ -10,3 +10,6 @@
[submodule "3rdparty/slog"]
path = 3rdparty/slog
url = https://github.com/kala13x/slog
[submodule "3rdparty/xxHash"]
path = 3rdparty/xxHash
url = https://github.com/Cyan4973/xxHash

1
3rdparty/xxHash vendored Submodule

Submodule 3rdparty/xxHash added at c961fbe61a

57
3rdparty/xxhash.cmake vendored Normal file
View File

@@ -0,0 +1,57 @@
# xxHash - Extremely Fast Hash algorithm
# Copyright (C) 2012-2023 Yann Collet
# BSD 2-Clause License
set("XXHASH_C_DIRECTORY" "3rdparty/xxHash")
message(STATUS "xxHash: Building static library")
# Create static library target for xxHash
add_library(xxhash STATIC)
# Add the main xxhash source file
target_sources(xxhash PRIVATE ${XXHASH_C_DIRECTORY}/xxhash.c)
# Set include directories for xxhash
target_include_directories(xxhash PUBLIC ${XXHASH_C_DIRECTORY})
# Enable x86/x64 dispatch for better performance on supported platforms
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR
${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64" OR
${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386" OR
${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686")
message(STATUS "xxHash: Enabling x86 dispatch optimization")
target_sources(xxhash PRIVATE ${XXHASH_C_DIRECTORY}/xxh_x86dispatch.c)
target_compile_definitions(xxhash PRIVATE XXHSUM_DISPATCH=1)
endif()
# Set compile definitions for xxhash
target_compile_definitions(xxhash PRIVATE XXH_STATIC_LINKING_ONLY)
# Optimization flags
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(MSVC)
target_compile_options(xxhash PRIVATE /O2)
else()
target_compile_options(xxhash PRIVATE -O3 -ffast-math)
# Enable specific optimizations for x86/x64
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR
${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64" OR
${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386" OR
${CMAKE_SYSTEM_PROCESSOR} MATCHES "i686")
if(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "AppleClang")
target_compile_options(xxhash PRIVATE -march=core2 -mtune=westmere)
endif()
endif()
endif()
endif()
# Set position independent code for shared library compatibility
set_property(TARGET xxhash PROPERTY POSITION_INDEPENDENT_CODE TRUE)
# Link xxhash to the main aaruformat target
target_link_libraries(aaruformat xxhash)
# Add include directory to main target so it can find xxhash headers
target_include_directories(aaruformat PRIVATE ${XXHASH_C_DIRECTORY})

View File

@@ -123,12 +123,15 @@ add_library(aaruformat SHARED include/aaruformat/consts.h include/aaruformat/enu
src/create.c
src/time.c
src/write.c
include/log.h)
include/log.h
src/ddt/hash_map.c
include/aaruformat/hash_map.h)
include_directories(include include/aaruformat)
include(3rdparty/flac.cmake)
include(3rdparty/lzma.cmake)
include(3rdparty/xxhash.cmake)
macro(TARGET_LINK_LIBRARIES_WHOLE_ARCHIVE target)
if(MSVC)