xsum_arch.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. * Checks for predefined macros by the compiler to try and get both the arch
  27. * and the compiler version.
  28. */
  29. #ifndef XSUM_ARCH_H
  30. #define XSUM_ARCH_H
  31. #include "xsum_config.h"
  32. #define XSUM_LIB_VERSION XXH_VERSION_MAJOR.XXH_VERSION_MINOR.XXH_VERSION_RELEASE
  33. #define XSUM_QUOTE(str) #str
  34. #define XSUM_EXPAND_AND_QUOTE(str) XSUM_QUOTE(str)
  35. #define XSUM_PROGRAM_VERSION XSUM_EXPAND_AND_QUOTE(XSUM_LIB_VERSION)
  36. /* Show compiler versions in WELCOME_MESSAGE. XSUM_CC_VERSION_FMT will return the printf specifiers,
  37. * and VERSION will contain the comma separated list of arguments to the XSUM_CC_VERSION_FMT string. */
  38. #if defined(__clang_version__)
  39. /* Clang does its own thing. */
  40. # ifdef __apple_build_version__
  41. # define XSUM_CC_VERSION_FMT "Apple Clang %s"
  42. # else
  43. # define XSUM_CC_VERSION_FMT "Clang %s"
  44. # endif
  45. # define XSUM_CC_VERSION __clang_version__
  46. #elif defined(__VERSION__)
  47. /* GCC and ICC */
  48. # define XSUM_CC_VERSION_FMT "%s"
  49. # ifdef __INTEL_COMPILER /* icc adds its prefix */
  50. # define XSUM_CC_VERSION __VERSION__
  51. # else /* assume GCC */
  52. # define XSUM_CC_VERSION "GCC " __VERSION__
  53. # endif
  54. #elif defined(_MSC_FULL_VER) && defined(_MSC_BUILD)
  55. /*
  56. * MSVC
  57. * "For example, if the version number of the Visual C++ compiler is
  58. * 15.00.20706.01, the _MSC_FULL_VER macro evaluates to 150020706."
  59. *
  60. * https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017
  61. */
  62. # define XSUM_CC_VERSION_FMT "MSVC %02i.%02i.%05i.%02i"
  63. # define XSUM_CC_VERSION _MSC_FULL_VER / 10000000 % 100, _MSC_FULL_VER / 100000 % 100, _MSC_FULL_VER % 100000, _MSC_BUILD
  64. #elif defined(_MSC_VER) /* old MSVC */
  65. # define XSUM_CC_VERSION_FMT "MSVC %02i.%02i"
  66. # define XSUM_CC_VERSION _MSC_VER / 100, _MSC_VER % 100
  67. #elif defined(__TINYC__)
  68. /* tcc stores its version in the __TINYC__ macro. */
  69. # define XSUM_CC_VERSION_FMT "tcc %i.%i.%i"
  70. # define XSUM_CC_VERSION __TINYC__ / 10000 % 100, __TINYC__ / 100 % 100, __TINYC__ % 100
  71. #else
  72. # define XSUM_CC_VERSION_FMT "%s"
  73. # define XSUM_CC_VERSION "unknown compiler"
  74. #endif
  75. /* makes the next part easier */
  76. #if defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
  77. # define XSUM_ARCH_X64 1
  78. # define XSUM_ARCH_X86 "x86_64"
  79. #elif defined(__i386__) || defined(_M_IX86) || defined(_M_IX86_FP)
  80. # define XSUM_ARCH_X86 "i386"
  81. #endif
  82. /* Try to detect the architecture. */
  83. #if defined(XSUM_ARCH_X86)
  84. # if defined(XXHSUM_DISPATCH)
  85. # define XSUM_ARCH XSUM_ARCH_X86 " autoVec"
  86. # elif defined(__AVX512F__)
  87. # define XSUM_ARCH XSUM_ARCH_X86 " + AVX512"
  88. # elif defined(__AVX2__)
  89. # define XSUM_ARCH XSUM_ARCH_X86 " + AVX2"
  90. # elif defined(__AVX__)
  91. # define XSUM_ARCH XSUM_ARCH_X86 " + AVX"
  92. # elif defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) \
  93. || defined(__SSE2__) || (defined(_M_IX86_FP) && _M_IX86_FP == 2)
  94. # define XSUM_ARCH XSUM_ARCH_X86 " + SSE2"
  95. # else
  96. # define XSUM_ARCH XSUM_ARCH_X86
  97. # endif
  98. #elif defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
  99. # define XSUM_ARCH "aarch64 + NEON"
  100. #elif defined(__arm__) || defined(__thumb__) || defined(__thumb2__) || defined(_M_ARM)
  101. /* ARM has a lot of different features that can change xxHash significantly. */
  102. # if defined(__thumb2__) || (defined(__thumb__) && (__thumb__ == 2 || __ARM_ARCH >= 7))
  103. # define XSUM_ARCH_THUMB " Thumb-2"
  104. # elif defined(__thumb__)
  105. # define XSUM_ARCH_THUMB " Thumb-1"
  106. # else
  107. # define XSUM_ARCH_THUMB ""
  108. # endif
  109. /* ARMv7 has unaligned by default */
  110. # if defined(__ARM_FEATURE_UNALIGNED) || __ARM_ARCH >= 7 || defined(_M_ARMV7VE)
  111. # define XSUM_ARCH_UNALIGNED " + unaligned"
  112. # else
  113. # define XSUM_ARCH_UNALIGNED ""
  114. # endif
  115. # if defined(__ARM_NEON) || defined(__ARM_NEON__)
  116. # define XSUM_ARCH_NEON " + NEON"
  117. # else
  118. # define XSUM_ARCH_NEON ""
  119. # endif
  120. # define XSUM_ARCH "ARMv" XSUM_EXPAND_AND_QUOTE(__ARM_ARCH) XSUM_ARCH_THUMB XSUM_ARCH_NEON XSUM_ARCH_UNALIGNED
  121. #elif defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__)
  122. # if defined(__GNUC__) && defined(__POWER9_VECTOR__)
  123. # define XSUM_ARCH "ppc64 + POWER9 vector"
  124. # elif defined(__GNUC__) && defined(__POWER8_VECTOR__)
  125. # define XSUM_ARCH "ppc64 + POWER8 vector"
  126. # else
  127. # define XSUM_ARCH "ppc64"
  128. # endif
  129. #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)
  130. # define XSUM_ARCH "ppc"
  131. #elif defined(__AVR)
  132. # define XSUM_ARCH "AVR"
  133. #elif defined(__mips64)
  134. # define XSUM_ARCH "mips64"
  135. #elif defined(__mips)
  136. # define XSUM_ARCH "mips"
  137. #elif defined(__s390x__)
  138. # define XSUM_ARCH "s390x"
  139. #elif defined(__s390__)
  140. # define XSUM_ARCH "s390"
  141. #else
  142. # define XSUM_ARCH "unknown"
  143. #endif
  144. #endif /* XSUM_ARCH_H */