From 88816c37fd2e8e46873070892d6f8f5b4e162f7d Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 30 Sep 2025 20:04:45 +0100 Subject: [PATCH] Add xxHash submodule and CMake integration for fast hashing --- .gitmodules | 3 +++ 3rdparty/xxHash | 1 + 3rdparty/xxhash.cmake | 57 +++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 5 +++- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 160000 3rdparty/xxHash create mode 100644 3rdparty/xxhash.cmake diff --git a/.gitmodules b/.gitmodules index 6b05097..f70241f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/3rdparty/xxHash b/3rdparty/xxHash new file mode 160000 index 0000000..c961fbe --- /dev/null +++ b/3rdparty/xxHash @@ -0,0 +1 @@ +Subproject commit c961fbe61ad1ee1e430b9c304735a0534fda1c6d diff --git a/3rdparty/xxhash.cmake b/3rdparty/xxhash.cmake new file mode 100644 index 0000000..fa4590d --- /dev/null +++ b/3rdparty/xxhash.cmake @@ -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}) diff --git a/CMakeLists.txt b/CMakeLists.txt index 028c64b..1ddfcc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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)