Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

compiler.h
Go to the documentation of this file.
1 /*
2 * Define useful compiler-specific macros
3 * (C) 2016 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_UTIL_COMPILER_FLAGS_H__
9 #define BOTAN_UTIL_COMPILER_FLAGS_H__
10
11 /* Should we use GCC-style inline assembler? */
12 #if !defined(BOTAN_USE_GCC_INLINE_ASM) && defined(__GNUC__)
13 #define BOTAN_USE_GCC_INLINE_ASM 1
14 #endif
15
16 /*
17 * Define BOTAN_GCC_VERSION
18 */
19 #ifdef __GNUC__
20 #define BOTAN_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__)
21 #else
22 #define BOTAN_GCC_VERSION 0
23 #endif
24
25 /*
26 * Define BOTAN_CLANG_VERSION
27 */
28 #ifdef __clang__
29 #define BOTAN_CLANG_VERSION (__clang_major__ * 10 + __clang_minor__)
30 #else
31 #define BOTAN_CLANG_VERSION 0
32 #endif
33
34 /*
35 * Define special macro when building under MSVC 2013 since there are
36 * many compiler workarounds required for that version.
37 */
38 #if defined(_MSC_VER) && (_MSC_VER < 1900)
39 #define BOTAN_BUILD_COMPILER_IS_MSVC_2013
40 #endif
41
42 /*
43 * Define BOTAN_FUNC_ISA
44 */
45 #if defined(__GNUG__) || (BOTAN_CLANG_VERSION > 38)
46 #define BOTAN_FUNC_ISA(isa) __attribute__ ((target(isa)))
47 #else
48 #define BOTAN_FUNC_ISA(isa)
49 #endif
50
51 /*
52 * Define BOTAN_WARN_UNUSED_RESULT
53 */
54 #if defined(__GNUG__) || defined(__clang__)
55 #define BOTAN_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
56 #else
57 #define BOTAN_WARN_UNUSED_RESULT
58 #endif
59
60 /*
61 * Define BOTAN_DEPRECATED
62 */
63 #if !defined(BOTAN_NO_DEPRECATED_WARNINGS)
64
65 #if defined(__clang__)
66 #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated))
67
68 #elif defined(_MSC_VER)
69 #define BOTAN_DEPRECATED(msg) __declspec(deprecated(msg))
70
71 #elif defined(__GNUG__)
72 // msg supported since GCC 4.5, earliest we support is 4.8
73 #define BOTAN_DEPRECATED(msg) __attribute__ ((deprecated(msg)))
74 #endif
75
76 #endif
77
78 #if !defined(BOTAN_DEPRECATED)
79 #define BOTAN_DEPRECATED(msg)
80 #endif
81
82 /*
83 * Define BOTAN_NORETURN
84 */
85 #if !defined(BOTAN_NORETURN)
86
87 #if defined (__clang__) || defined (__GNUG__)
88 #define BOTAN_NORETURN __attribute__ ((__noreturn__))
89
90 #elif defined (_MSC_VER)
91 #define BOTAN_NORETURN __declspec(noreturn)
92
93 #else
94 #define BOTAN_NORETURN
95 #endif
96
97 #endif
98
99 /*
100 * Define BOTAN_CURRENT_FUNCTION
101 */
102 #if defined(_MSC_VER)
103 #define BOTAN_CURRENT_FUNCTION __FUNCTION__
104 #else
105 #define BOTAN_CURRENT_FUNCTION __func__
106 #endif
107
108 /*
109 * Define BOTAN_NOEXCEPT (for MSVC 2013)
110 */
111 #if defined(BOTAN_BUILD_COMPILER_IS_MSVC_2013)
112 // noexcept is not supported in VS 2013
113 #include <yvals.h>
114 #define BOTAN_NOEXCEPT _NOEXCEPT
115 #else
116 #define BOTAN_NOEXCEPT noexcept
117 #endif
118
119 /*
120 * Define BOTAN_PARALLEL_FOR
121 */
122 #if !defined(BOTAN_PARALLEL_FOR)
123
124 #if defined(BOTAN_TARGET_HAS_CILKPLUS)
125 #define BOTAN_PARALLEL_FOR _Cilk_for
126 #elif defined(BOTAN_TARGET_HAS_OPENMP)
127 #define BOTAN_PARALLEL_FOR _Pragma("omp parallel for") for
128 #else
129 #define BOTAN_PARALLEL_FOR for
130 #endif
131
132 #endif
133
134 /*
135 * Define BOTAN_PARALLEL_SIMD_FOR
136 */
137 #if !defined(BOTAN_PARALLEL_SIMD_FOR)
138
139 #if defined(BOTAN_TARGET_HAS_CILKPLUS)
140 #define BOTAN_PARALLEL_SIMD_FOR _Pragma("simd") for
141 #elif defined(BOTAN_TARGET_HAS_OPENMP)
142 #define BOTAN_PARALLEL_SIMD_FOR _Pragma("omp simd") for
143 #elif defined(BOTAN_BUILD_COMPILER_IS_GCC)
144 #define BOTAN_PARALLEL_SIMD_FOR _Pragma("GCC ivdep") for
145 #else
146 #define BOTAN_PARALLEL_SIMD_FOR for
147 #endif
148
149 #endif
150
151 /*
152 * Define BOTAN_PARALLEL_SPAWN
153 */
154 #if !defined(BOTAN_PARALLEL_SPAWN)
155
156 #if defined(BOTAN_TARGET_HAS_CILKPLUS)
157 #define BOTAN_PARALLEL_SPAWN _Cilk_spawn
158 #else
159 #define BOTAN_PARALLEL_SPAWN
160 #endif
161
162 #endif
163
164 /*
165 * Define BOTAN_PARALLEL_SYNC
166 */
167 #if !defined(BOTAN_PARALLEL_SYNC)
168
169 #if defined(BOTAN_TARGET_HAS_CILKPLUS)
170 #define BOTAN_PARALLEL_SYNC _Cilk_sync
171 #else
172 #define BOTAN_PARALLEL_SYNC BOTAN_FORCE_SEMICOLON
173 #endif
174
175 #endif
176
177 #endif