| 1 |
/* |
| 2 |
* xxhsum - Command line interface for xxhash algorithms |
| 3 |
* Copyright (C) 2013-2021 Yann Collet |
| 4 |
* |
| 5 |
* GPL v2 License |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License along |
| 18 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 |
* |
| 21 |
* You can contact the author at: |
| 22 |
* - xxHash homepage: https://www.xxhash.com |
| 23 |
* - xxHash source repository: https://github.com/Cyan4973/xxHash |
| 24 |
*/ |
| 25 |
|
| 26 |
/* |
| 27 |
* Checks for predefined macros by the compiler to try and get both the arch |
| 28 |
* and the compiler version. |
| 29 |
*/ |
| 30 |
#ifndef XSUM_ARCH_H |
| 31 |
#define XSUM_ARCH_H |
| 32 |
|
| 33 |
#include "xsum_config.h" |
| 34 |
|
| 35 |
#define XSUM_LIB_VERSION XXH_VERSION_MAJOR.XXH_VERSION_MINOR.XXH_VERSION_RELEASE |
| 36 |
#define XSUM_QUOTE(str) #str |
| 37 |
#define XSUM_EXPAND_AND_QUOTE(str) XSUM_QUOTE(str) |
| 38 |
#define XSUM_PROGRAM_VERSION XSUM_EXPAND_AND_QUOTE(XSUM_LIB_VERSION) |
| 39 |
|
| 40 |
|
| 41 |
/* Show compiler versions in WELCOME_MESSAGE. XSUM_CC_VERSION_FMT will return the printf specifiers, |
| 42 |
* and VERSION will contain the comma separated list of arguments to the XSUM_CC_VERSION_FMT string. */ |
| 43 |
#if defined(__clang_version__) |
| 44 |
/* Clang does its own thing. */ |
| 45 |
# ifdef __apple_build_version__ |
| 46 |
# define XSUM_CC_VERSION_FMT "Apple Clang %s" |
| 47 |
# else |
| 48 |
# define XSUM_CC_VERSION_FMT "Clang %s" |
| 49 |
# endif |
| 50 |
# define XSUM_CC_VERSION __clang_version__ |
| 51 |
#elif defined(__VERSION__) |
| 52 |
/* GCC and ICC */ |
| 53 |
# define XSUM_CC_VERSION_FMT "%s" |
| 54 |
# ifdef __INTEL_COMPILER /* icc adds its prefix */ |
| 55 |
# define XSUM_CC_VERSION __VERSION__ |
| 56 |
# else /* assume GCC */ |
| 57 |
# define XSUM_CC_VERSION "GCC " __VERSION__ |
| 58 |
# endif |
| 59 |
#elif defined(_MSC_FULL_VER) && defined(_MSC_BUILD) |
| 60 |
/* |
| 61 |
* MSVC |
| 62 |
* "For example, if the version number of the Visual C++ compiler is |
| 63 |
* 15.00.20706.01, the _MSC_FULL_VER macro evaluates to 150020706." |
| 64 |
* |
| 65 |
* https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017 |
| 66 |
*/ |
| 67 |
# define XSUM_CC_VERSION_FMT "MSVC %02i.%02i.%05i.%02i" |
| 68 |
# define XSUM_CC_VERSION _MSC_FULL_VER / 10000000 % 100, _MSC_FULL_VER / 100000 % 100, _MSC_FULL_VER % 100000, _MSC_BUILD |
| 69 |
#elif defined(_MSC_VER) /* old MSVC */ |
| 70 |
# define XSUM_CC_VERSION_FMT "MSVC %02i.%02i" |
| 71 |
# define XSUM_CC_VERSION _MSC_VER / 100, _MSC_VER % 100 |
| 72 |
#elif defined(__TINYC__) |
| 73 |
/* tcc stores its version in the __TINYC__ macro. */ |
| 74 |
# define XSUM_CC_VERSION_FMT "tcc %i.%i.%i" |
| 75 |
# define XSUM_CC_VERSION __TINYC__ / 10000 % 100, __TINYC__ / 100 % 100, __TINYC__ % 100 |
| 76 |
#else |
| 77 |
# define XSUM_CC_VERSION_FMT "%s" |
| 78 |
# define XSUM_CC_VERSION "unknown compiler" |
| 79 |
#endif |
| 80 |
|
| 81 |
/* makes the next part easier */ |
| 82 |
#if (defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)) && !defined(_M_ARM64EC) |
| 83 |
# define XSUM_ARCH_X64 1 |
| 84 |
# define XSUM_ARCH_X86 "x86_64" |
| 85 |
#elif defined(__i386__) || defined(_M_IX86) || defined(_M_IX86_FP) |
| 86 |
# define XSUM_ARCH_X86 "i386" |
| 87 |
#endif |
| 88 |
|
| 89 |
/* Try to detect the architecture. */ |
| 90 |
#if defined(XSUM_ARCH_X86) |
| 91 |
# if defined(XXHSUM_DISPATCH) |
| 92 |
const char* XSUM_autox86(void); |
| 93 |
# define XSUM_ARCH XSUM_autox86() |
| 94 |
# elif defined(__AVX512F__) |
| 95 |
# define XSUM_ARCH XSUM_ARCH_X86 " + AVX512" |
| 96 |
# elif defined(__AVX2__) |
| 97 |
# define XSUM_ARCH XSUM_ARCH_X86 " + AVX2" |
| 98 |
# elif defined(__AVX__) |
| 99 |
# define XSUM_ARCH XSUM_ARCH_X86 " + AVX" |
| 100 |
# elif defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) \ |
| 101 |
|| defined(__SSE2__) || (defined(_M_IX86_FP) && _M_IX86_FP == 2) |
| 102 |
# define XSUM_ARCH XSUM_ARCH_X86 " + SSE2" |
| 103 |
# else |
| 104 |
# define XSUM_ARCH XSUM_ARCH_X86 |
| 105 |
# endif |
| 106 |
#elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) || defined(_M_ARM64EC) |
| 107 |
# if defined(__ARM_FEATURE_SVE) |
| 108 |
# define XSUM_ARCH "aarch64 + SVE" |
| 109 |
# else |
| 110 |
# define XSUM_ARCH "aarch64 + NEON" |
| 111 |
# endif |
| 112 |
#elif defined(__arm__) || defined(__thumb__) || defined(__thumb2__) || defined(_M_ARM) |
| 113 |
/* ARM has a lot of different features that can change xxHash significantly. */ |
| 114 |
# ifdef __ARM_ARCH |
| 115 |
# define XSUM_ARCH_ARM_VER XSUM_EXPAND_AND_QUOTE(__ARM_ARCH) |
| 116 |
# else |
| 117 |
# define XSUM_ARCH_ARM_VER XSUM_EXPAND_AND_QUOTE(_M_ARM) |
| 118 |
# endif |
| 119 |
# if defined(_M_ARM) /* windows arm is always thumb-2 */ \ |
| 120 |
|| defined(__thumb2__) || (defined(__thumb__) && (__thumb__ == 2 || __ARM_ARCH >= 7)) |
| 121 |
# define XSUM_ARCH_THUMB " Thumb-2" |
| 122 |
# elif defined(__thumb__) |
| 123 |
# define XSUM_ARCH_THUMB " Thumb-1" |
| 124 |
# else |
| 125 |
# define XSUM_ARCH_THUMB "" |
| 126 |
# endif |
| 127 |
/* ARMv7 has unaligned by default */ |
| 128 |
# if defined(__ARM_FEATURE_UNALIGNED) || __ARM_ARCH >= 7 || defined(_M_ARM) |
| 129 |
# define XSUM_ARCH_UNALIGNED " + unaligned" |
| 130 |
# else |
| 131 |
# define XSUM_ARCH_UNALIGNED "" |
| 132 |
# endif |
| 133 |
# if defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(_M_ARM) |
| 134 |
# define XSUM_ARCH_NEON " + NEON" |
| 135 |
# else |
| 136 |
# define XSUM_ARCH_NEON "" |
| 137 |
# endif |
| 138 |
# define XSUM_ARCH "ARMv" XSUM_ARCH_ARM_VER XSUM_ARCH_THUMB XSUM_ARCH_NEON XSUM_ARCH_UNALIGNED |
| 139 |
#elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) |
| 140 |
# if defined(__GNUC__) && defined(__POWER9_VECTOR__) |
| 141 |
# define XSUM_ARCH "ppc64 + POWER9 vector" |
| 142 |
# elif defined(__GNUC__) && defined(__POWER8_VECTOR__) |
| 143 |
# define XSUM_ARCH "ppc64 + POWER8 vector" |
| 144 |
# else |
| 145 |
# define XSUM_ARCH "ppc64" |
| 146 |
# endif |
| 147 |
#elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) |
| 148 |
# define XSUM_ARCH "ppc" |
| 149 |
#elif defined(__AVR) |
| 150 |
# define XSUM_ARCH "AVR" |
| 151 |
#elif defined(__mips64) |
| 152 |
# define XSUM_ARCH "mips64" |
| 153 |
#elif defined(__mips) |
| 154 |
# define XSUM_ARCH "mips" |
| 155 |
#elif defined(__s390x__) |
| 156 |
# define XSUM_ARCH "s390x" |
| 157 |
#elif defined(__s390__) |
| 158 |
# define XSUM_ARCH "s390" |
| 159 |
#elif defined(__wasm__) || defined(__asmjs__) || defined(__EMSCRIPTEN__) |
| 160 |
# if defined(__wasm_simd128__) |
| 161 |
# define XSUM_ARCH "wasm/asmjs + simd128" |
| 162 |
# else |
| 163 |
# define XSUM_ARCH "wasm/asmjs" |
| 164 |
# endif |
| 165 |
#elif defined(__loongarch_lp64) |
| 166 |
# define XSUM_ARCH "loongarch" |
| 167 |
#else |
| 168 |
# define XSUM_ARCH "unknown" |
| 169 |
#endif |
| 170 |
|
| 171 |
|
| 172 |
#endif /* XSUM_ARCH_H */ |