Chromium Code Reviews| 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 #if COMPILER_GCC && defined(NDEBUG) | |
| 104 #define ALWAYS_INLINE inline __attribute__((__always_inline__)) | |
| 105 #elif COMPILER_MSVC && defined(NDEBUG) | |
| 106 #define ALWAYS_INLINE __forceinline | |
| 107 #else | |
| 108 #define ALWAYS_INLINE inline | |
| 109 #endif | |
| 110 | |
| 103 // Specify memory alignment for structs, classes, etc. | 111 // Specify memory alignment for structs, classes, etc. |
| 104 // Use like: | 112 // Use like: |
| 105 // class ALIGNAS(16) MyClass { ... } | 113 // class ALIGNAS(16) MyClass { ... } |
| 106 // ALIGNAS(16) int array[4]; | 114 // ALIGNAS(16) int array[4]; |
| 107 #if defined(COMPILER_MSVC) | 115 #if defined(COMPILER_MSVC) |
| 108 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) | 116 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) |
| 109 #elif defined(COMPILER_GCC) | 117 #elif defined(COMPILER_GCC) |
| 110 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) | 118 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) |
| 111 #endif | 119 #endif |
| 112 | 120 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 | 197 |
| 190 // Macro for hinting that an expression is likely to be false. | 198 // Macro for hinting that an expression is likely to be false. |
| 191 #if !defined(UNLIKELY) | 199 #if !defined(UNLIKELY) |
| 192 #if defined(COMPILER_GCC) | 200 #if defined(COMPILER_GCC) |
| 193 #define UNLIKELY(x) __builtin_expect(!!(x), 0) | 201 #define UNLIKELY(x) __builtin_expect(!!(x), 0) |
| 194 #else | 202 #else |
| 195 #define UNLIKELY(x) (x) | 203 #define UNLIKELY(x) (x) |
| 196 #endif // defined(COMPILER_GCC) | 204 #endif // defined(COMPILER_GCC) |
| 197 #endif // !defined(UNLIKELY) | 205 #endif // !defined(UNLIKELY) |
| 198 | 206 |
| 207 #if !defined(LIKELY) | |
| 208 #if defined(COMPILER_GCC) | |
| 209 #define LIKELY(x) __builtin_expect((x), 1) | |
|
sdefresne
2016/11/08 08:40:20
Shouldn't this be __builtin_expect(!!(x), 1)? Othe
palmer
2016/11/16 23:45:21
Somehow, I missed this comment. Fix coming right u
| |
| 210 #else | |
| 211 #define LIKELY(x) (x) | |
| 212 #endif // defined(COMPILER_GCC) | |
| 213 #endif // !defined(LIKELY) | |
| 214 | |
| 199 // Compiler feature-detection. | 215 // Compiler feature-detection. |
| 200 // clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension | 216 // clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension |
| 201 #if defined(__has_feature) | 217 #if defined(__has_feature) |
| 202 #define HAS_FEATURE(FEATURE) __has_feature(FEATURE) | 218 #define HAS_FEATURE(FEATURE) __has_feature(FEATURE) |
| 203 #else | 219 #else |
| 204 #define HAS_FEATURE(FEATURE) 0 | 220 #define HAS_FEATURE(FEATURE) 0 |
| 205 #endif | 221 #endif |
| 206 | 222 |
| 207 #endif // BASE_COMPILER_SPECIFIC_H_ | 223 #endif // BASE_COMPILER_SPECIFIC_H_ |
| OLD | NEW |