OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_COMPILER_SPECIFIC_H_ | 5 #ifndef BASE_COMPILER_SPECIFIC_H_ |
6 #define BASE_COMPILER_SPECIFIC_H_ | 6 #define BASE_COMPILER_SPECIFIC_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(COMPILER_MSVC) | 10 #if defined(COMPILER_MSVC) |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 // Use like: | 93 // Use like: |
94 // NOINLINE void DoStuff() { ... } | 94 // NOINLINE void DoStuff() { ... } |
95 #if defined(COMPILER_GCC) | 95 #if defined(COMPILER_GCC) |
96 #define NOINLINE __attribute__((noinline)) | 96 #define NOINLINE __attribute__((noinline)) |
97 #elif defined(COMPILER_MSVC) | 97 #elif defined(COMPILER_MSVC) |
98 #define NOINLINE __declspec(noinline) | 98 #define NOINLINE __declspec(noinline) |
99 #else | 99 #else |
100 #define NOINLINE | 100 #define NOINLINE |
101 #endif | 101 #endif |
102 | 102 |
103 // For compatibility with callers in Blink: | |
104 #define NEVER_INLINE NOINLINE | |
dcheng
2016/11/07 20:43:10
Btw, maybe a TODO here for eventual convergence. I
palmer
2016/11/07 21:54:14
Done.
| |
105 | |
106 #if COMPILER_GCC && defined(NDEBUG) | |
107 #define ALWAYS_INLINE inline __attribute__((__always_inline__)) | |
108 #elif COMPILER_MSVC && defined(NDEBUG) | |
109 #define ALWAYS_INLINE __forceinline | |
110 #else | |
111 #define ALWAYS_INLINE inline | |
112 #endif | |
113 | |
103 // Specify memory alignment for structs, classes, etc. | 114 // Specify memory alignment for structs, classes, etc. |
104 // Use like: | 115 // Use like: |
105 // class ALIGNAS(16) MyClass { ... } | 116 // class ALIGNAS(16) MyClass { ... } |
106 // ALIGNAS(16) int array[4]; | 117 // ALIGNAS(16) int array[4]; |
107 #if defined(COMPILER_MSVC) | 118 #if defined(COMPILER_MSVC) |
108 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) | 119 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) |
109 #elif defined(COMPILER_GCC) | 120 #elif defined(COMPILER_GCC) |
110 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) | 121 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) |
111 #endif | 122 #endif |
112 | 123 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 | 200 |
190 // Macro for hinting that an expression is likely to be false. | 201 // Macro for hinting that an expression is likely to be false. |
191 #if !defined(UNLIKELY) | 202 #if !defined(UNLIKELY) |
192 #if defined(COMPILER_GCC) | 203 #if defined(COMPILER_GCC) |
193 #define UNLIKELY(x) __builtin_expect(!!(x), 0) | 204 #define UNLIKELY(x) __builtin_expect(!!(x), 0) |
194 #else | 205 #else |
195 #define UNLIKELY(x) (x) | 206 #define UNLIKELY(x) (x) |
196 #endif // defined(COMPILER_GCC) | 207 #endif // defined(COMPILER_GCC) |
197 #endif // !defined(UNLIKELY) | 208 #endif // !defined(UNLIKELY) |
198 | 209 |
210 #if !defined(LIKELY) | |
211 #if defined(COMPILER_GCC) | |
212 #define LIKELY(x) __builtin_expect((x), 1) | |
213 #else | |
214 #define LIKELY(x) (x) | |
215 #endif // defined(COMPILER_GCC) | |
216 #endif // !defined(LIKELY) | |
217 | |
199 // Compiler feature-detection. | 218 // Compiler feature-detection. |
200 // clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension | 219 // clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension |
201 #if defined(__has_feature) | 220 #if defined(__has_feature) |
202 #define HAS_FEATURE(FEATURE) __has_feature(FEATURE) | 221 #define HAS_FEATURE(FEATURE) __has_feature(FEATURE) |
203 #else | 222 #else |
204 #define HAS_FEATURE(FEATURE) 0 | 223 #define HAS_FEATURE(FEATURE) 0 |
205 #endif | 224 #endif |
206 | 225 |
207 #endif // BASE_COMPILER_SPECIFIC_H_ | 226 #endif // BASE_COMPILER_SPECIFIC_H_ |
OLD | NEW |