1 /* 2 * xxhsum - Command line interface for xxhash algorithms 3 * Copyright (C) 2013-2020 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) 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 # define XSUM_ARCH XSUM_ARCH_X86 " autoVec" 93 # elif defined(__AVX512F__) 94 # define XSUM_ARCH XSUM_ARCH_X86 " + AVX512" 95 # elif defined(__AVX2__) 96 # define XSUM_ARCH XSUM_ARCH_X86 " + AVX2" 97 # elif defined(__AVX__) 98 # define XSUM_ARCH XSUM_ARCH_X86 " + AVX" 99 # elif defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) \ 100 || defined(__SSE2__) || (defined(_M_IX86_FP) && _M_IX86_FP == 2) 101 # define XSUM_ARCH XSUM_ARCH_X86 " + SSE2" 102 # else 103 # define XSUM_ARCH XSUM_ARCH_X86 104 # endif 105 #elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) 106 # define XSUM_ARCH "aarch64 + NEON" 107 #elif defined(__arm__) || defined(__thumb__) || defined(__thumb2__) || defined(_M_ARM) 108 /* ARM has a lot of different features that can change xxHash significantly. */ 109 # if defined(__thumb2__) || (defined(__thumb__) && (__thumb__ == 2 || __ARM_ARCH >= 7)) 110 # define XSUM_ARCH_THUMB " Thumb-2" 111 # elif defined(__thumb__) 112 # define XSUM_ARCH_THUMB " Thumb-1" 113 # else 114 # define XSUM_ARCH_THUMB "" 115 # endif 116 /* ARMv7 has unaligned by default */ 117 # if defined(__ARM_FEATURE_UNALIGNED) || __ARM_ARCH >= 7 || defined(_M_ARMV7VE) 118 # define XSUM_ARCH_UNALIGNED " + unaligned" 119 # else 120 # define XSUM_ARCH_UNALIGNED "" 121 # endif 122 # if defined(__ARM_NEON) || defined(__ARM_NEON__) 123 # define XSUM_ARCH_NEON " + NEON" 124 # else 125 # define XSUM_ARCH_NEON "" 126 # endif 127 # define XSUM_ARCH "ARMv" XSUM_EXPAND_AND_QUOTE(__ARM_ARCH) XSUM_ARCH_THUMB XSUM_ARCH_NEON XSUM_ARCH_UNALIGNED 128 #elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) 129 # if defined(__GNUC__) && defined(__POWER9_VECTOR__) 130 # define XSUM_ARCH "ppc64 + POWER9 vector" 131 # elif defined(__GNUC__) && defined(__POWER8_VECTOR__) 132 # define XSUM_ARCH "ppc64 + POWER8 vector" 133 # else 134 # define XSUM_ARCH "ppc64" 135 # endif 136 #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) 137 # define XSUM_ARCH "ppc" 138 #elif defined(__AVR) 139 # define XSUM_ARCH "AVR" 140 #elif defined(__mips64) 141 # define XSUM_ARCH "mips64" 142 #elif defined(__mips) 143 # define XSUM_ARCH "mips" 144 #elif defined(__s390x__) 145 # define XSUM_ARCH "s390x" 146 #elif defined(__s390__) 147 # define XSUM_ARCH "s390" 148 #else 149 # define XSUM_ARCH "unknown" 150 #endif 151 152 153 #endif /* XSUM_ARCH_H */ 154