diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cee54e8e..2d759056 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/Makefile b/Makefile index a566c7af..3ffd593b 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cli/xsum_arch.c b/cli/xsum_arch.c new file mode 100644 index 00000000..1533f585 --- /dev/null +++ b/cli/xsum_arch.c @@ -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 */ diff --git a/cli/xsum_arch.h b/cli/xsum_arch.h index b3d4f643..aae7eaa8 100644 --- a/cli/xsum_arch.h +++ b/cli/xsum_arch.h @@ -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__) diff --git a/cmake_unofficial/CMakeLists.txt b/cmake_unofficial/CMakeLists.txt index 5c3bc596..5316c6d4 100644 --- a/cmake_unofficial/CMakeLists.txt +++ b/cmake_unofficial/CMakeLists.txt @@ -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" diff --git a/xxh_x86dispatch.c b/xxh_x86dispatch.c index 86512714..430df13e 100644 --- a/xxh_x86dispatch.c +++ b/xxh_x86dispatch.c @@ -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; diff --git a/xxh_x86dispatch.h b/xxh_x86dispatch.h index b87cea95..13679b70 100644 --- a/xxh_x86dispatch.h +++ b/xxh_x86dispatch.h @@ -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);