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