| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Specify memory alignment for structs, classes, etc. | 121 // Specify memory alignment for structs, classes, etc. |
| 122 // Use like: | 122 // Use like: |
| 123 // class ALIGNAS(16) MyClass { ... } | 123 // class ALIGNAS(16) MyClass { ... } |
| 124 // ALIGNAS(16) int array[4]; | 124 // ALIGNAS(16) int array[4]; |
| 125 #if defined(COMPILER_MSVC) | 125 #if defined(COMPILER_MSVC) |
| 126 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) | 126 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) |
| 127 #elif defined(COMPILER_GCC) | 127 #elif defined(COMPILER_GCC) |
| 128 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) | 128 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) |
| 129 #endif | 129 #endif |
| 130 | 130 |
| 131 // Return the byte alignment of the given type (available at compile time). Use | 131 // Return the byte alignment of the given type (available at compile time). |
| 132 // sizeof(type) prior to checking __alignof to workaround Visual C++ bug: | |
| 133 // http://goo.gl/isH0C | |
| 134 // Use like: | 132 // Use like: |
| 135 // ALIGNOF(int32) // this would be 4 | 133 // ALIGNOF(int32) // this would be 4 |
| 136 #if defined(COMPILER_MSVC) | 134 #if defined(COMPILER_MSVC) |
| 137 #define ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type)) | 135 #define ALIGNOF(type) __alignof(type) |
| 138 #elif defined(COMPILER_GCC) | 136 #elif defined(COMPILER_GCC) |
| 139 #define ALIGNOF(type) __alignof__(type) | 137 #define ALIGNOF(type) __alignof__(type) |
| 140 #endif | 138 #endif |
| 141 | 139 |
| 142 // Annotate a function indicating the caller must examine the return value. | 140 // Annotate a function indicating the caller must examine the return value. |
| 143 // Use like: | 141 // Use like: |
| 144 // int foo() WARN_UNUSED_RESULT; | 142 // int foo() WARN_UNUSED_RESULT; |
| 145 // To explicitly ignore a result, see |ignore_result()| in <base/basictypes.h>. | 143 // To explicitly ignore a result, see |ignore_result()| in <base/basictypes.h>. |
| 146 #if defined(COMPILER_GCC) | 144 #if defined(COMPILER_GCC) |
| 147 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) | 145 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // Macro for hinting that an expression is likely to be false. | 198 // Macro for hinting that an expression is likely to be false. |
| 201 #if !defined(UNLIKELY) | 199 #if !defined(UNLIKELY) |
| 202 #if defined(COMPILER_GCC) | 200 #if defined(COMPILER_GCC) |
| 203 #define UNLIKELY(x) __builtin_expect(!!(x), 0) | 201 #define UNLIKELY(x) __builtin_expect(!!(x), 0) |
| 204 #else | 202 #else |
| 205 #define UNLIKELY(x) (x) | 203 #define UNLIKELY(x) (x) |
| 206 #endif // defined(COMPILER_GCC) | 204 #endif // defined(COMPILER_GCC) |
| 207 #endif // !defined(UNLIKELY) | 205 #endif // !defined(UNLIKELY) |
| 208 | 206 |
| 209 #endif // BASE_COMPILER_SPECIFIC_H_ | 207 #endif // BASE_COMPILER_SPECIFIC_H_ |
| OLD | NEW |