Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:55

0001 // config_cpu.h - written and placed in public domain by Jeffrey Walton

0002 //                the bits that make up this source file are from the

0003 //                library's monolithic config.h.

0004 
0005 /// \file config_cpu.h

0006 /// \brief Library configuration file

0007 /// \details <tt>config_cpu.h</tt> provides defines for the cpu and machine

0008 ///  architecture.

0009 /// \details <tt>config.h</tt> was split into components in May 2019 to better

0010 ///  integrate with Autoconf and its feature tests. The splitting occurred so

0011 ///  users could continue to include <tt>config.h</tt> while allowing Autoconf

0012 ///  to write new <tt>config_asm.h</tt> and new <tt>config_cxx.h</tt> using

0013 ///  its feature tests.

0014 /// \note You should include <tt>config.h</tt> rather than <tt>config_cpu.h</tt>

0015 ///  directly.

0016 /// \sa <A HREF="https://github.com/weidai11/cryptopp/issues/835">Issue 835,

0017 ///  Make config.h more autoconf friendly</A>,

0018 ///  <A HREF="https://www.cryptopp.com/wiki/Configure.sh">Configure.sh script</A>

0019 ///  on the Crypto++ wiki,

0020 ///  <A HREF="https://sourceforge.net/p/predef/wiki/Architectures/">Sourceforge

0021 ///  Pre-defined Compiler Macros</A>

0022 /// \since Crypto++ 8.3

0023 
0024 #ifndef CRYPTOPP_CONFIG_CPU_H
0025 #define CRYPTOPP_CONFIG_CPU_H
0026 
0027 #include "config_ver.h"
0028 
0029 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
0030     /// \brief 32-bit x32 platform

0031     /// \details CRYPTOPP_BOOL_X32 is defined to 1 when building the library

0032     ///  for a 32-bit x32 platform. Otherwise, the macro is not defined.

0033     /// \details x32 is sometimes referred to as x86_32. x32 is the ILP32 data

0034     ///  model on a 64-bit cpu. Integers, longs and pointers are 32-bit but the

0035     ///  program runs on a 64-bit cpu.

0036     /// \details The significance of x32 is, inline assembly must operate on

0037     ///  64-bit registers, not 32-bit registers. That means, for example,

0038     ///  function prologues and epilogues must push and pop RSP, not ESP.

0039     /// \note: Clang defines __ILP32__ on any 32-bit platform. Therefore,

0040     ///  CRYPTOPP_BOOL_X32 depends upon both __ILP32__ and __x86_64__.

0041     /// \sa <A HREF="https://wiki.debian.org/X32Port">Debian X32 Port</A>,

0042     ///  <A HREF="https://wiki.gentoo.org/wiki/Project:Multilib/Concepts">Gentoo

0043     ///  Multilib Concepts</A>

0044     #define CRYPTOPP_BOOL_X32 ...
0045     /// \brief 32-bit x86 platform

0046     /// \details CRYPTOPP_BOOL_X64 is defined to 1 when building the library

0047     ///  for a 64-bit x64 platform. Otherwise, the macro is not defined.

0048     #define CRYPTOPP_BOOL_X64 ...
0049     /// \brief 32-bit x86 platform

0050     /// \details CRYPTOPP_BOOL_X86 is defined to 1 when building the library

0051     ///  for a 32-bit x86 platform. Otherwise, the macro is not defined.

0052     #define CRYPTOPP_BOOL_X86 ...
0053 #elif (defined(__ILP32__) || defined(_ILP32)) && defined(__x86_64__)
0054     #define CRYPTOPP_BOOL_X32 1
0055 #elif (defined(_M_X64) || defined(__x86_64__))
0056     #define CRYPTOPP_BOOL_X64 1
0057 #elif (defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(_X86_) || defined(__I86__) || defined(__INTEL__))
0058     #define CRYPTOPP_BOOL_X86 1
0059 #endif
0060 
0061 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
0062     /// \brief ARMv8 platform

0063     /// \details CRYPTOPP_BOOL_ARMV8 is defined to 1 when building the library

0064     ///  for an ARMv8 platform. Otherwise, the macro is not defined.

0065     /// \details ARMv8 includes both Aarch32 and Aarch64. Aarch32 is a 32-bit

0066     ///  execution environment on Aarch64.

0067     #define CRYPTOPP_BOOL_ARMV8 ...
0068     /// \brief 64-bit ARM platform

0069     /// \details CRYPTOPP_BOOL_ARM64 is defined to 1 when building the library

0070     ///  for a 64-bit x64 platform. Otherwise, the macro is not defined.

0071     /// \details Currently the macro indicates an ARM 64-bit architecture.

0072     #define CRYPTOPP_BOOL_ARM64 ...
0073     /// \brief 32-bit ARM platform

0074     /// \details CRYPTOPP_BOOL_ARM32 is defined to 1 when building the library

0075     ///  for a 32-bit ARM platform. Otherwise, the macro is not defined.

0076     /// \details Currently the macro indicates an ARM A-32 architecture.

0077     #define CRYPTOPP_BOOL_ARM32 ...
0078 #elif defined(__arm64__) || defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
0079     // Microsoft added ARM64 define December 2017.

0080     #define CRYPTOPP_BOOL_ARMV8 1
0081 #endif
0082 #if defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
0083     #define CRYPTOPP_BOOL_ARM64 1
0084 #elif defined(__arm__) || defined(_M_ARM)
0085     #define CRYPTOPP_BOOL_ARM32 1
0086 #endif
0087 
0088 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
0089     /// \brief 64-bit PowerPC platform

0090     /// \details CRYPTOPP_BOOL_PPC64 is defined to 1 when building the library

0091     ///  for a 64-bit PowerPC platform. Otherwise, the macro is not defined.

0092     #define CRYPTOPP_BOOL_PPC64 ...
0093     /// \brief 32-bit PowerPC platform

0094     /// \details CRYPTOPP_BOOL_PPC32 is defined to 1 when building the library

0095     ///  for a 32-bit PowerPC platform. Otherwise, the macro is not defined.

0096     #define CRYPTOPP_BOOL_PPC32 ...
0097 #elif defined(__ppc64__) || defined(__powerpc64__) || defined(__PPC64__) || defined(_ARCH_PPC64)
0098     #define CRYPTOPP_BOOL_PPC64 1
0099 #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC)
0100     #define CRYPTOPP_BOOL_PPC32 1
0101 #endif
0102 
0103 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
0104     /// \brief 64-bit MIPS platform

0105     /// \details CRYPTOPP_BOOL_MIPS64 is defined to 1 when building the library

0106     ///  for a 64-bit MIPS platform. Otherwise, the macro is not defined.

0107     #define CRYPTOPP_BOOL_MIPS64 ...
0108     /// \brief 64-bit MIPS platform

0109     /// \details CRYPTOPP_BOOL_MIPS32 is defined to 1 when building the library

0110     ///  for a 32-bit MIPS platform. Otherwise, the macro is not defined.

0111     #define CRYPTOPP_BOOL_MIPS32 ...
0112 #elif defined(__mips64__)
0113     #define CRYPTOPP_BOOL_MIPS64 1
0114 #elif defined(__mips__)
0115     #define CRYPTOPP_BOOL_MIPS32 1
0116 #endif
0117 
0118 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
0119     /// \brief 64-bit SPARC platform

0120     /// \details CRYPTOPP_BOOL_SPARC64 is defined to 1 when building the library

0121     ///  for a 64-bit SPARC platform. Otherwise, the macro is not defined.

0122     #define CRYPTOPP_BOOL_SPARC64 ...
0123     /// \brief 32-bit SPARC platform

0124     /// \details CRYPTOPP_BOOL_SPARC32 is defined to 1 when building the library

0125     ///  for a 32-bit SPARC platform. Otherwise, the macro is not defined.

0126     #define CRYPTOPP_BOOL_SPARC32 ...
0127 #elif defined(__sparc64__) || defined(__sparc64) || defined(__sparcv9) || defined(__sparc_v9__)
0128     #define CRYPTOPP_BOOL_SPARC64 1
0129 #elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8) || defined(__sparc_v8__)
0130     #define CRYPTOPP_BOOL_SPARC32 1
0131 #endif
0132 
0133 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
0134     /// \brief L1 data cache line size

0135     /// \details CRYPTOPP_L1_CACHE_LINE_SIZE should be a lower bound on the L1

0136     ///  data cache line size. It is used for defense against some timing attacks.

0137     /// \details CRYPTOPP_L1_CACHE_LINE_SIZE default value on 32-bit platforms

0138     ///  is 32, and the default value on 64-bit platforms is 64. On PowerPC the

0139     ///  default value is 128 since all PowerPC cpu's starting at PPC 970 provide

0140     ///  it.

0141     /// \note The runtime library on some PowerPC platforms misreport the size

0142     ///  of the cache line size. The runtime library reports 64, while the cpu

0143     ///  has a cache line size of 128.

0144     /// \sa <A HREF="https://bugs.centos.org/view.php?id=14599">CentOS Issue

0145     ///  14599: sysconf(_SC_LEVEL1_DCACHE_LINESIZE) returns 0 instead of 128</A>

0146     /// \since Crypto++ 5.3

0147     #define CRYPTOPP_L1_CACHE_LINE_SIZE ...
0148 #else
0149     #ifndef CRYPTOPP_L1_CACHE_LINE_SIZE
0150         #if defined(CRYPTOPP_BOOL_X32) || defined(CRYPTOPP_BOOL_X64) || defined(CRYPTOPP_BOOL_ARMV8) || \
0151             defined(CRYPTOPP_BOOL_MIPS64) || defined(CRYPTOPP_BOOL_SPARC64)
0152             #define CRYPTOPP_L1_CACHE_LINE_SIZE 64
0153         #elif defined(CRYPTOPP_BOOL_PPC32) || defined(CRYPTOPP_BOOL_PPC64)
0154             // http://lists.llvm.org/pipermail/llvm-dev/2017-March/110982.html

0155             #define CRYPTOPP_L1_CACHE_LINE_SIZE 128
0156         #else
0157             // L1 cache line size is 32 on Pentium III and earlier

0158             #define CRYPTOPP_L1_CACHE_LINE_SIZE 32
0159         #endif
0160     #endif
0161 #endif
0162 
0163 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
0164     /// \brief Initialized data section

0165     /// \details CRYPTOPP_SECTION_INIT is added to variables to place them in the

0166     ///  initialized data section (sometimes denoted <tt>.data</tt>). The placement

0167     ///  helps avoid "uninitialized variable" warnings from Valgrind and other tools.

0168     #define CRYPTOPP_SECTION_INIT ...
0169 #else
0170     // The section attribute attempts to initialize CPU flags to avoid Valgrind findings above -O1

0171     #if ((defined(__MACH__) && defined(__APPLE__)) && ((CRYPTOPP_LLVM_CLANG_VERSION >= 30600) || \
0172         (CRYPTOPP_APPLE_CLANG_VERSION >= 70100) || (CRYPTOPP_GCC_VERSION >= 40300)))
0173         #define CRYPTOPP_SECTION_INIT __attribute__((section ("__DATA,__data")))
0174     #elif (defined(__ELF__) && (CRYPTOPP_GCC_VERSION >= 40300))
0175         #define CRYPTOPP_SECTION_INIT __attribute__((section ("nocommon")))
0176     #elif defined(__ELF__) && (defined(__xlC__) || defined(__ibmxl__))
0177         #define CRYPTOPP_SECTION_INIT __attribute__((section ("nocommon")))
0178     #else
0179         #define CRYPTOPP_SECTION_INIT
0180     #endif
0181 #endif
0182 
0183 // How to disable CPU feature probing. We determine machine

0184 // capabilities by performing an os/platform *query* first,

0185 // like getauxv(). If the *query* fails, we move onto a

0186 // cpu *probe*. The cpu *probe* tries to exeute an instruction

0187 // and then catches a SIGILL on Linux or the exception

0188 // EXCEPTION_ILLEGAL_INSTRUCTION on Windows. Some OSes

0189 // fail to hangle a SIGILL gracefully, like Apple OSes. Apple

0190 // machines corrupt memory and variables around the probe.

0191 #if defined(__APPLE__)
0192     #define CRYPTOPP_NO_CPU_FEATURE_PROBES 1
0193 #endif
0194 
0195 // Flavor of inline assembly language

0196 #if defined(CRYPTOPP_DOXYGEN_PROCESSING)
0197     /// \brief Microsoft style inline assembly

0198     /// \details CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY is defined when either

0199     ///  <tt>_MSC_VER</tt> or <tt>__BORLANDC__</tt> are defined.

0200     #define CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY ...
0201     /// \brief GNU style inline assembly

0202     /// \details CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY is defined when neither

0203     ///  <tt>_MSC_VER</tt> nor <tt>__BORLANDC__</tt> are defined.

0204     #define CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY ...
0205 #elif defined(CRYPTOPP_MSC_VERSION) || defined(__BORLANDC__) || \
0206     (defined(CRYPTOPP_WIN32_AVAILABLE) && defined(CRYPTOPP_LLVM_CLANG_VERSION))
0207     #define CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY 1
0208 #else
0209     #define CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY 1
0210 #endif
0211 
0212 #endif  // CRYPTOPP_CONFIG_CPU_H