Skip to content

Commit

Permalink
Merge pull request #985 from Cyan4973/autovec_rtdiag
Browse files Browse the repository at this point in the history
xxhsum with auto-dispatch displays the locally detected vector extension
  • Loading branch information
Cyan4973 authored Dec 26, 2024
2 parents 2bf8313 + 4b9ca60 commit 6fe4f19
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ jobs:
PATH=/mingw64/bin:$PATH /mingw32/bin/mingw32-make -C tests/bench
# Abort if result of "file ./xxhsum.exe" doesn't contain 'x86-64'.
# Expected output is "./xxhsum.exe: PE32+ executable (console) x86-64, for MS Windows"
file ./xxhsum.exe
file ./xxhsum.exe | grep -q 'x86-64' || $(exit 1)
./xxhsum.exe --version
Expand All @@ -637,6 +638,7 @@ jobs:
PATH=/mingw32/bin:$PATH /mingw32/bin/mingw32-make.exe clean test MOREFLAGS=-Werror
PATH=/mingw32/bin:$PATH /mingw32/bin/mingw32-make.exe -C tests/bench
# Abort if result of "file ./xxhsum.exe" doesn't contain '80386'.
# Expected output is "./xxhsum.exe: PE32 executable (console) Intel 80386, for MS Windows"
file ./xxhsum.exe | grep -q '80386' || $(exit 1)
# Expected output is "./xxhsum.exe: PE32 executable (console) Intel i386, for MS Windows"
file ./xxhsum.exe
file ./xxhsum.exe | grep -q '386' || $(exit 1)
./xxhsum.exe --version
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ LIBXXH = libxxhash.$(SHARED_EXT_VER)
XXHSUM_SRC_DIR = cli
XXHSUM_SPLIT_SRCS = $(XXHSUM_SRC_DIR)/xxhsum.c \
$(XXHSUM_SRC_DIR)/xsum_os_specific.c \
$(XXHSUM_SRC_DIR)/xsum_arch.c \
$(XXHSUM_SRC_DIR)/xsum_output.c \
$(XXHSUM_SRC_DIR)/xsum_sanity_check.c \
$(XXHSUM_SRC_DIR)/xsum_bench.c
Expand Down
53 changes: 53 additions & 0 deletions cli/xsum_arch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* xxhsum - Command line interface for xxhash algorithms
* Copyright (C) 2013-2021 Yann Collet
*
* GPL v2 License
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* You can contact the author at:
* - xxHash homepage: https://www.xxhash.com
* - xxHash source repository: https://github.com/Cyan4973/xxHash
*/

int g_xsumarch_avoid_empty_unit = 0;

#if ((defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)) && !defined(_M_ARM64EC)) || defined(__i386__) || defined(_M_IX86) || defined(_M_IX86_FP)
#if defined(XXHSUM_DISPATCH)

#include "../xxh_x86dispatch.h"
#define XXH_INLINE_ALL /* XXH_* vector types */
#include "../xxhash.h"

const char* XSUM_autox86(void)
{
int vecVersion = XXH_featureTest();
switch(vecVersion) {
case XXH_SCALAR:
return "x86 autoVec (scalar: no vector extension detected)";
case XXH_SSE2:
return "x86 autoVec (SSE2 detected)";
case XXH_AVX2:
return "x86 autoVec (AVX2 detected)";
case XXH_AVX512:
return "x86 autoVec (AVX512 detected)";
default:;
}
return " autoVec (error detecting vector extension)";
}

#endif /* XXHSUM_DISPATCH */
#endif /* x86 */
3 changes: 2 additions & 1 deletion cli/xsum_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
/* Try to detect the architecture. */
#if defined(XSUM_ARCH_X86)
# if defined(XXHSUM_DISPATCH)
# define XSUM_ARCH XSUM_ARCH_X86 " autoVec"
const char* XSUM_autox86(void);
# define XSUM_ARCH XSUM_autox86()
# elif defined(__AVX512F__)
# define XSUM_ARCH XSUM_ARCH_X86 " + AVX512"
# elif defined(__AVX2__)
Expand Down
1 change: 1 addition & 0 deletions cmake_unofficial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ if(XXHASH_BUILD_XXHSUM)
list(APPEND XXHSUM_SOURCES "${XXHASH_DIR}/xxh_x86dispatch.c")
endif()
list(APPEND XXHSUM_SOURCES "${XXHSUM_DIR}/xxhsum.c"
"${XXHSUM_DIR}/xsum_arch.c"
"${XXHSUM_DIR}/xsum_os_specific.c"
"${XXHSUM_DIR}/xsum_output.c"
"${XXHSUM_DIR}/xsum_sanity_check.c"
Expand Down
2 changes: 1 addition & 1 deletion xxh_x86dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ static xxh_u64 XXH_xgetbv(void)
* @return The best @ref XXH_VECTOR implementation.
* @see XXH_VECTOR_TYPES
*/
static int XXH_featureTest(void)
int XXH_featureTest(void)
{
xxh_u32 abcd[4];
xxh_u32 max_leaves;
Expand Down
8 changes: 8 additions & 0 deletions xxh_x86dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
extern "C" {
#endif

/*!
* @brief Returns the best XXH3 implementation for x86
*
* @return The best @ref XXH_VECTOR implementation.
* @see XXH_VECTOR_TYPES
*/
XXH_PUBLIC_API int XXH_featureTest(void);

XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_dispatch(XXH_NOESCAPE const void* input, size_t len);
XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_withSeed_dispatch(XXH_NOESCAPE const void* input, size_t len, XXH64_hash_t seed);
XXH_PUBLIC_API XXH64_hash_t XXH3_64bits_withSecret_dispatch(XXH_NOESCAPE const void* input, size_t len, XXH_NOESCAPE const void* secret, size_t secretLen);
Expand Down

0 comments on commit 6fe4f19

Please sign in to comment.