config_cpu.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // config_cpu.h - written and placed in public domain by Jeffrey Walton
  2. // the bits that make up this source file are from the
  3. // library's monolithic config.h.
  4. /// \file config_cpu.h
  5. /// \brief Library configuration file
  6. /// \details <tt>config_cpu.h</tt> provides defines for the cpu and machine
  7. /// architecture.
  8. /// \details <tt>config.h</tt> was split into components in May 2019 to better
  9. /// integrate with Autoconf and its feature tests. The splitting occurred so
  10. /// users could continue to include <tt>config.h</tt> while allowing Autoconf
  11. /// to write new <tt>config_asm.h</tt> and new <tt>config_cxx.h</tt> using
  12. /// its feature tests.
  13. /// \note You should include <tt>config.h</tt> rather than <tt>config_cpu.h</tt>
  14. /// directly.
  15. /// \sa <A HREF="https://github.com/weidai11/cryptopp/issues/835">Issue 835,
  16. /// Make config.h more autoconf friendly</A>,
  17. /// <A HREF="https://www.cryptopp.com/wiki/Configure.sh">Configure.sh script</A>
  18. /// on the Crypto++ wiki,
  19. /// <A HREF="https://sourceforge.net/p/predef/wiki/Architectures/">Sourceforge
  20. /// Pre-defined Compiler Macros</A>
  21. /// \since Crypto++ 8.3
  22. #ifndef CRYPTOPP_CONFIG_CPU_H
  23. #define CRYPTOPP_CONFIG_CPU_H
  24. #include "config_ver.h"
  25. #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
  26. /// \brief 32-bit x32 platform
  27. /// \details CRYPTOPP_BOOL_X32 is defined to 1 when building the library
  28. /// for a 32-bit x32 platform. Otherwise, the macro is not defined.
  29. /// \details x32 is sometimes referred to as x86_32. x32 is the ILP32 data
  30. /// model on a 64-bit cpu. Integers, longs and pointers are 32-bit but the
  31. /// program runs on a 64-bit cpu.
  32. /// \details The significance of x32 is, inline assembly must operate on
  33. /// 64-bit registers, not 32-bit registers. That means, for example,
  34. /// function prologues and epilogues must push and pop RSP, not ESP.
  35. /// \note: Clang defines __ILP32__ on any 32-bit platform. Therefore,
  36. /// CRYPTOPP_BOOL_X32 depends upon both __ILP32__ and __x86_64__.
  37. /// \sa <A HREF="https://wiki.debian.org/X32Port">Debian X32 Port</A>,
  38. /// <A HREF="https://wiki.gentoo.org/wiki/Project:Multilib/Concepts">Gentoo
  39. /// Multilib Concepts</A>
  40. #define CRYPTOPP_BOOL_X32 ...
  41. /// \brief 32-bit x86 platform
  42. /// \details CRYPTOPP_BOOL_X64 is defined to 1 when building the library
  43. /// for a 64-bit x64 platform. Otherwise, the macro is not defined.
  44. #define CRYPTOPP_BOOL_X64 ...
  45. /// \brief 32-bit x86 platform
  46. /// \details CRYPTOPP_BOOL_X86 is defined to 1 when building the library
  47. /// for a 32-bit x86 platform. Otherwise, the macro is not defined.
  48. #define CRYPTOPP_BOOL_X86 ...
  49. #elif (defined(__ILP32__) || defined(_ILP32)) && defined(__x86_64__)
  50. #define CRYPTOPP_BOOL_X32 1
  51. #elif (defined(_M_X64) || defined(__x86_64__))
  52. #define CRYPTOPP_BOOL_X64 1
  53. #elif (defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(_X86_) || defined(__I86__) || defined(__INTEL__))
  54. #define CRYPTOPP_BOOL_X86 1
  55. #endif
  56. #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
  57. /// \brief ARMv8 platform
  58. /// \details CRYPTOPP_BOOL_ARMV8 is defined to 1 when building the library
  59. /// for an ARMv8 platform. Otherwise, the macro is not defined.
  60. /// \details ARMv8 includes both Aarch32 and Aarch64. Aarch32 is a 32-bit
  61. /// execution environment on Aarch64.
  62. #define CRYPTOPP_BOOL_ARMV8 ...
  63. /// \brief 64-bit ARM platform
  64. /// \details CRYPTOPP_BOOL_ARM64 is defined to 1 when building the library
  65. /// for a 64-bit x64 platform. Otherwise, the macro is not defined.
  66. /// \details Currently the macro indicates an ARM 64-bit architecture.
  67. #define CRYPTOPP_BOOL_ARM64 ...
  68. /// \brief 32-bit ARM platform
  69. /// \details CRYPTOPP_BOOL_ARM32 is defined to 1 when building the library
  70. /// for a 32-bit ARM platform. Otherwise, the macro is not defined.
  71. /// \details Currently the macro indicates an ARM A-32 architecture.
  72. #define CRYPTOPP_BOOL_ARM32 ...
  73. #elif defined(__arm64__) || defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
  74. // Microsoft added ARM64 define December 2017.
  75. #define CRYPTOPP_BOOL_ARMV8 1
  76. #endif
  77. #if defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
  78. #define CRYPTOPP_BOOL_ARM64 1
  79. #elif defined(__arm__) || defined(_M_ARM)
  80. #define CRYPTOPP_BOOL_ARM32 1
  81. #endif
  82. #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
  83. /// \brief 64-bit PowerPC platform
  84. /// \details CRYPTOPP_BOOL_PPC64 is defined to 1 when building the library
  85. /// for a 64-bit PowerPC platform. Otherwise, the macro is not defined.
  86. #define CRYPTOPP_BOOL_PPC64 ...
  87. /// \brief 32-bit PowerPC platform
  88. /// \details CRYPTOPP_BOOL_PPC32 is defined to 1 when building the library
  89. /// for a 32-bit PowerPC platform. Otherwise, the macro is not defined.
  90. #define CRYPTOPP_BOOL_PPC32 ...
  91. #elif defined(__ppc64__) || defined(__powerpc64__) || defined(__PPC64__) || defined(_ARCH_PPC64)
  92. #define CRYPTOPP_BOOL_PPC64 1
  93. #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC)
  94. #define CRYPTOPP_BOOL_PPC32 1
  95. #endif
  96. #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
  97. /// \brief 64-bit MIPS platform
  98. /// \details CRYPTOPP_BOOL_MIPS64 is defined to 1 when building the library
  99. /// for a 64-bit MIPS platform. Otherwise, the macro is not defined.
  100. #define CRYPTOPP_BOOL_MIPS64 ...
  101. /// \brief 64-bit MIPS platform
  102. /// \details CRYPTOPP_BOOL_MIPS32 is defined to 1 when building the library
  103. /// for a 32-bit MIPS platform. Otherwise, the macro is not defined.
  104. #define CRYPTOPP_BOOL_MIPS32 ...
  105. #elif defined(__mips64__)
  106. #define CRYPTOPP_BOOL_MIPS64 1
  107. #elif defined(__mips__)
  108. #define CRYPTOPP_BOOL_MIPS32 1
  109. #endif
  110. #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
  111. /// \brief 64-bit SPARC platform
  112. /// \details CRYPTOPP_BOOL_SPARC64 is defined to 1 when building the library
  113. /// for a 64-bit SPARC platform. Otherwise, the macro is not defined.
  114. #define CRYPTOPP_BOOL_SPARC64 ...
  115. /// \brief 32-bit SPARC platform
  116. /// \details CRYPTOPP_BOOL_SPARC32 is defined to 1 when building the library
  117. /// for a 32-bit SPARC platform. Otherwise, the macro is not defined.
  118. #define CRYPTOPP_BOOL_SPARC32 ...
  119. #elif defined(__sparc64__) || defined(__sparc64) || defined(__sparcv9) || defined(__sparc_v9__)
  120. #define CRYPTOPP_BOOL_SPARC64 1
  121. #elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8) || defined(__sparc_v8__)
  122. #define CRYPTOPP_BOOL_SPARC32 1
  123. #endif
  124. #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
  125. /// \brief L1 data cache line size
  126. /// \details CRYPTOPP_L1_CACHE_LINE_SIZE should be a lower bound on the L1
  127. /// data cache line size. It is used for defense against some timing attacks.
  128. /// \details CRYPTOPP_L1_CACHE_LINE_SIZE default value on 32-bit platforms
  129. /// is 32, and the default value on 64-bit platforms is 64. On PowerPC the
  130. /// default value is 128 since all PowerPC cpu's starting at PPC 970 provide
  131. /// it.
  132. /// \note The runtime library on some PowerPC platforms misreport the size
  133. /// of the cache line size. The runtime library reports 64, while the cpu
  134. /// has a cache line size of 128.
  135. /// \sa <A HREF="https://bugs.centos.org/view.php?id=14599">CentOS Issue
  136. /// 14599: sysconf(_SC_LEVEL1_DCACHE_LINESIZE) returns 0 instead of 128</A>
  137. /// \since Crypto++ 5.3
  138. #define CRYPTOPP_L1_CACHE_LINE_SIZE ...
  139. #else
  140. #ifndef CRYPTOPP_L1_CACHE_LINE_SIZE
  141. #if defined(CRYPTOPP_BOOL_X32) || defined(CRYPTOPP_BOOL_X64) || defined(CRYPTOPP_BOOL_ARMV8) || \
  142. defined(CRYPTOPP_BOOL_MIPS64) || defined(CRYPTOPP_BOOL_SPARC64)
  143. #define CRYPTOPP_L1_CACHE_LINE_SIZE 64
  144. #elif defined(CRYPTOPP_BOOL_PPC32) || defined(CRYPTOPP_BOOL_PPC64)
  145. // http://lists.llvm.org/pipermail/llvm-dev/2017-March/110982.html
  146. #define CRYPTOPP_L1_CACHE_LINE_SIZE 128
  147. #else
  148. // L1 cache line size is 32 on Pentium III and earlier
  149. #define CRYPTOPP_L1_CACHE_LINE_SIZE 32
  150. #endif
  151. #endif
  152. #endif
  153. #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
  154. /// \brief Initialized data section
  155. /// \details CRYPTOPP_SECTION_INIT is added to variables to place them in the
  156. /// initialized data section (sometimes denoted <tt>.data</tt>). The placement
  157. /// helps avoid "uninitialized variable" warnings from Valgrind and other tools.
  158. #define CRYPTOPP_SECTION_INIT ...
  159. #else
  160. // The section attribute attempts to initialize CPU flags to avoid Valgrind findings above -O1
  161. #if ((defined(__MACH__) && defined(__APPLE__)) && ((CRYPTOPP_LLVM_CLANG_VERSION >= 30600) || \
  162. (CRYPTOPP_APPLE_CLANG_VERSION >= 70100) || (CRYPTOPP_GCC_VERSION >= 40300)))
  163. #define CRYPTOPP_SECTION_INIT __attribute__((section ("__DATA,__data")))
  164. #elif (defined(__ELF__) && (CRYPTOPP_GCC_VERSION >= 40300))
  165. #define CRYPTOPP_SECTION_INIT __attribute__((section ("nocommon")))
  166. #elif defined(__ELF__) && (defined(__xlC__) || defined(__ibmxl__))
  167. #define CRYPTOPP_SECTION_INIT __attribute__((section ("nocommon")))
  168. #else
  169. #define CRYPTOPP_SECTION_INIT
  170. #endif
  171. #endif
  172. // How to disable CPU feature probing. We determine machine
  173. // capabilities by performing an os/platform *query* first,
  174. // like getauxv(). If the *query* fails, we move onto a
  175. // cpu *probe*. The cpu *probe* tries to exeute an instruction
  176. // and then catches a SIGILL on Linux or the exception
  177. // EXCEPTION_ILLEGAL_INSTRUCTION on Windows. Some OSes
  178. // fail to hangle a SIGILL gracefully, like Apple OSes. Apple
  179. // machines corrupt memory and variables around the probe.
  180. #if defined(__APPLE__)
  181. #define CRYPTOPP_NO_CPU_FEATURE_PROBES 1
  182. #endif
  183. // Flavor of inline assembly language
  184. #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
  185. /// \brief Microsoft style inline assembly
  186. /// \details CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY is defined when either
  187. /// <tt>_MSC_VER</tt> or <tt>__BORLANDC__</tt> are defined.
  188. #define CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY ...
  189. /// \brief GNU style inline assembly
  190. /// \details CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY is defined when neither
  191. /// <tt>_MSC_VER</tt> nor <tt>__BORLANDC__</tt> are defined.
  192. #define CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY ...
  193. #elif defined(_MSC_VER) || defined(__BORLANDC__)
  194. #define CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY 1
  195. #else
  196. #define CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY 1
  197. #endif
  198. #endif // CRYPTOPP_CONFIG_CPU_H