Crypto++ 8.2 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.h</tt> was split into components in May 2019 to better
8 /// integrate with Autoconf and its feature tests. The splitting occurred so
9 /// users could continue to include <tt>config.h</tt> while allowing Autoconf
10 /// to write new <tt>config_asm.h</tt> and new <tt>config_cxx.h</tt> using
11 /// its feature tests.
12 /// \sa <A HREF="https://github.com/weidai11/cryptopp/issues/835">Issue 835</A>
13 /// <A HREF="https://sourceforge.net/p/predef/wiki/Architectures/">Sourceforge
14 /// Pre-defined Compiler Macros</A>
15 /// \since Crypto++ 8.3
16
17 #ifndef CRYPTOPP_CONFIG_CPU_H
18 #define CRYPTOPP_CONFIG_CPU_H
19
20 #include "config_ver.h"
21
22 #if (defined(__ILP32__) || defined(_ILP32)) && defined(__x86_64__)
23 #define CRYPTOPP_BOOL_X32 1
24 #elif (defined(_M_X64) || defined(__x86_64__))
25 #define CRYPTOPP_BOOL_X64 1
26 #elif (defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(_X86_) || defined(__I86__) || defined(__INTEL__))
27 #define CRYPTOPP_BOOL_X86 1
28 #endif
29
30 // Microsoft added ARM64 define December 2017.
31 #if defined(__arm64__) || defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
32 #define CRYPTOPP_BOOL_ARMV8 1
33 #endif
34 #if defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
35 #define CRYPTOPP_BOOL_ARM64 1
36 #elif defined(__arm__) || defined(_M_ARM)
37 #define CRYPTOPP_BOOL_ARM32 1
38 #endif
39
40 // And PowerPC.
41 #if defined(__ppc64__) || defined(__powerpc64__) || defined(__PPC64__) || defined(_ARCH_PPC64)
42 #define CRYPTOPP_BOOL_PPC64 1
43 #elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC)
44 #define CRYPTOPP_BOOL_PPC32 1
45 #endif
46
47 // And MIPS. TODO: finish these defines
48 #if defined(__mips64__)
49 #define CRYPTOPP_BOOL_MIPS64 1
50 #elif defined(__mips__)
51 #define CRYPTOPP_BOOL_MIPS32 1
52 #endif
53
54 // And SPARC.
55 #if defined(__sparc64__) || defined(__sparc64) || defined(__sparcv9) || defined(__sparc_v9__)
56 #define CRYPTOPP_BOOL_SPARC64 1
57 #elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8) || defined(__sparc_v8__)
58 #define CRYPTOPP_BOOL_SPARC32 1
59 #endif
60
61 // This should be a lower bound on the L1 cache line size.
62 // It's used for defense against timing attacks.
63 #ifndef CRYPTOPP_L1_CACHE_LINE_SIZE
64 #if defined(CRYPTOPP_BOOL_X32) || defined(CRYPTOPP_BOOL_X64) || defined(CRYPTOPP_BOOL_ARMV8) || \
65 defined(CRYPTOPP_BOOL_PPC64) || defined(CRYPTOPP_BOOL_MIPS64) || defined(CRYPTOPP_BOOL_SPARC64)
66 #define CRYPTOPP_L1_CACHE_LINE_SIZE 64
67 #else
68 // L1 cache line size is 32 on Pentium III and earlier
69 #define CRYPTOPP_L1_CACHE_LINE_SIZE 32
70 #endif
71 #endif
72
73 // The section attribute attempts to initialize CPU flags to avoid Valgrind findings above -O1
74 #if ((defined(__MACH__) && defined(__APPLE__)) && ((CRYPTOPP_LLVM_CLANG_VERSION >= 30600) || (CRYPTOPP_APPLE_CLANG_VERSION >= 70100) || (CRYPTOPP_GCC_VERSION >= 40300)))
75 #define CRYPTOPP_SECTION_INIT __attribute__((section ("__DATA,__data")))
76 #elif (defined(__ELF__) && (CRYPTOPP_GCC_VERSION >= 40300))
77 #define CRYPTOPP_SECTION_INIT __attribute__((section ("nocommon")))
78 #elif defined(__ELF__) && (defined(__xlC__) || defined(__ibmxl__))
79 #define CRYPTOPP_SECTION_INIT __attribute__((section ("nocommon")))
80 #else
81 #define CRYPTOPP_SECTION_INIT
82 #endif
83
84 // How to disable CPU feature probing. We determine machine
85 // capabilities by performing an os/platform *query* first,
86 // like getauxv(). If the *query* fails, we move onto a
87 // cpu *probe*. The cpu *probe* tries to exeute an instruction
88 // and then catches a SIGILL on Linux or the exception
89 // EXCEPTION_ILLEGAL_INSTRUCTION on Windows. Some OSes
90 // fail to hangle a SIGILL gracefully, like Apple OSes. Apple
91 // machines corrupt memory and variables around the probe.
92 #if defined(__APPLE__)
93 #define CRYPTOPP_NO_CPU_FEATURE_PROBES 1
94 #endif
95
96 // Flavor of inline assembly language
97 #if defined(_MSC_VER) || defined(__BORLANDC__)
98 #define CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY 1
99 #else
100 #define CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY 1
101 #endif
102
103 #endif
config_ver.h
Library configuration file.