Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Side by Side Diff: include/v8config.h

Issue 22888008: Add V8_ALIGNOF() and use that in lazy-instance.h. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Improve detection of __alignof__ in clang. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/lazy-instance.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 # define V8_OS_POSIX 1 79 # define V8_OS_POSIX 1
80 #elif defined(__OpenBSD__) 80 #elif defined(__OpenBSD__)
81 # define V8_OS_BSD 1 81 # define V8_OS_BSD 1
82 # define V8_OS_OPENBSD 1 82 # define V8_OS_OPENBSD 1
83 # define V8_OS_POSIX 1 83 # define V8_OS_POSIX 1
84 #elif defined(_WIN32) 84 #elif defined(_WIN32)
85 # define V8_OS_WIN 1 85 # define V8_OS_WIN 1
86 #endif 86 #endif
87 87
88 88
89 // This macro checks for a required GCC version. It also works with compilers
90 // that pretend to be GCC, i.e. Clang, ICC or the ARM compiler with the --gnu
91 // flag.
92 // Use like this if you want to check for a GCC compatible version:
93 // #if V8_GNUC_PREREQ(x, y, z)
94 // ...
95 // #endif
96 //
97 // Use like ths if you want to check for a specific GCC version:
98 // #if V8_CC_GNU && V8_GNUC_PREREQ(x, y, z)
99 // ...
100 // #endif
101 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
102 # define V8_GNUC_PREREQ(major, minor, patchlevel) \
103 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \
104 ((major) * 10000 + (minor) * 100 + (patchlevel)))
105 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
106 # define V8_GNUC_PREREQ(major, minor, patchlevel) \
107 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= \
108 ((major) * 10000 + (minor) * 100 + (patchlevel)))
109 #else
110 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0
111 #endif
112
113
89 // ----------------------------------------------------------------------------- 114 // -----------------------------------------------------------------------------
90 // Compiler detection 115 // Compiler detection
91 // 116 //
92 // V8_CC_CLANG - Clang 117 // V8_CC_CLANG - Clang
93 // V8_CC_GNU - GNU C++ 118 // V8_CC_GNU - GNU C++
94 // V8_CC_MINGW - Minimalist GNU for Windows 119 // V8_CC_MINGW - Minimalist GNU for Windows
95 // V8_CC_MSVC - Microsoft Visual C/C++ 120 // V8_CC_MSVC - Microsoft Visual C/C++
96 // 121 //
97 // C++11 feature detection 122 // C++11 feature detection
98 // 123 //
99 // V8_HAS_CXX11_ALIGNAS - alignas specifier supported 124 // V8_HAS_CXX11_ALIGNAS - alignas specifier supported
125 // V8_HAS_CXX11_ALIGNOF - alignas operator supported
100 // V8_HAS_CXX11_STATIC_ASSERT - static_assert() supported 126 // V8_HAS_CXX11_STATIC_ASSERT - static_assert() supported
101 // V8_HAS_CXX11_DELETE - deleted functions supported 127 // V8_HAS_CXX11_DELETE - deleted functions supported
102 // V8_HAS_CXX11_FINAL - final marker supported 128 // V8_HAS_CXX11_FINAL - final marker supported
103 // V8_HAS_CXX11_OVERRIDE - override marker supported 129 // V8_HAS_CXX11_OVERRIDE - override marker supported
104 // 130 //
105 // Compiler-specific feature detection 131 // Compiler-specific feature detection
106 // 132 //
107 // V8_HAS_ATTRIBUTE___ALIGNED__ - __attribute__((__aligned__(n))) supported 133 // V8_HAS___ALIGNOF - __alignof(t) operator supported
134 // V8_HAS___ALIGNOF__ - __alignof__(t) operator supported
135 // V8_HAS_ATTRIBUTE_ALIGNED - __attribute__((aligned(n))) supported
108 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) supported 136 // V8_HAS_ATTRIBUTE_ALWAYS_INLINE - __attribute__((always_inline)) supported
109 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported 137 // V8_HAS_ATTRIBUTE_DEPRECATED - __attribute__((deprecated)) supported
110 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported 138 // V8_HAS_ATTRIBUTE_VISIBILITY - __attribute__((visibility)) supported
111 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported 139 // V8_HAS_BUILTIN_EXPECT - __builtin_expect() supported
112 // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported 140 // V8_HAS_DECLSPEC_ALIGN - __declspec(align(n)) supported
113 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported 141 // V8_HAS_DECLSPEC_DEPRECATED - __declspec(deprecated) supported
114 // V8_HAS___FINAL - __final supported in non-C++11 mode 142 // V8_HAS___FINAL - __final supported in non-C++11 mode
115 // V8_HAS___FORCEINLINE - __forceinline supported 143 // V8_HAS___FORCEINLINE - __forceinline supported
116 // V8_HAS_SEALED - MSVC style sealed marker supported 144 // V8_HAS_SEALED - MSVC style sealed marker supported
117 145
118 #if defined(__clang__) 146 #if defined(__clang__)
119 147
120 // Don't treat clang as GCC.
121 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0
122
123 # define V8_CC_CLANG 1 148 # define V8_CC_CLANG 1
124 149
125 # define V8_HAS_ATTRIBUTE___ALIGNED__ (__has_attribute(__aligned__)) 150 # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(2, 95, 0))
151
152 # define V8_HAS_ATTRIBUTE_ALIGNED (__has_attribute(aligned))
126 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) 153 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
127 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated)) 154 # define V8_HAS_ATTRIBUTE_DEPRECATED (__has_attribute(deprecated))
128 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility)) 155 # define V8_HAS_ATTRIBUTE_VISIBILITY (__has_attribute(visibility))
129 156
130 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect)) 157 # define V8_HAS_BUILTIN_EXPECT (__has_builtin(__builtin_expect))
131 158
132 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas)) 159 # define V8_HAS_CXX11_ALIGNAS (__has_feature(cxx_alignas))
133 # define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert)) 160 # define V8_HAS_CXX11_STATIC_ASSERT (__has_feature(cxx_static_assert))
134 # define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions)) 161 # define V8_HAS_CXX11_DELETE (__has_feature(cxx_deleted_functions))
135 # define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control)) 162 # define V8_HAS_CXX11_FINAL (__has_feature(cxx_override_control))
136 # define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control)) 163 # define V8_HAS_CXX11_OVERRIDE (__has_feature(cxx_override_control))
137 164
138 #elif defined(__GNUC__) 165 #elif defined(__GNUC__)
139 166
140 # define V8_GNUC_PREREQ(major, minor, patchlevel) \
141 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= \
142 ((major) * 10000 + (minor) * 100 + (patchlevel)))
143
144 # define V8_CC_GNU 1 167 # define V8_CC_GNU 1
145 # if defined(__MINGW32__) 168 # if defined(__MINGW32__)
146 # define V8_CC_MINGW 1 169 # define V8_CC_MINGW 1
147 # endif 170 # endif
148 171
149 # define V8_HAS_ATTRIBUTE___ALIGNED__ (V8_GNUC_PREREQ(2, 95, 0)) 172 # define V8_HAS___ALIGNOF__ (V8_GNUC_PREREQ(2, 95, 0))
173
174 # define V8_HAS_ATTRIBUTE_ALIGNED (V8_GNUC_PREREQ(2, 95, 0))
150 // always_inline is available in gcc 4.0 but not very reliable until 4.4. 175 // always_inline is available in gcc 4.0 but not very reliable until 4.4.
151 // Works around "sorry, unimplemented: inlining failed" build errors with 176 // Works around "sorry, unimplemented: inlining failed" build errors with
152 // older compilers. 177 // older compilers.
153 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0)) 178 # define V8_HAS_ATTRIBUTE_ALWAYS_INLINE (V8_GNUC_PREREQ(4, 4, 0))
154 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0)) 179 # define V8_HAS_ATTRIBUTE_DEPRECATED (V8_GNUC_PREREQ(3, 4, 0))
155 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0)) 180 # define V8_HAS_ATTRIBUTE_VISIBILITY (V8_GNUC_PREREQ(4, 3, 0))
156 181
157 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0)) 182 # define V8_HAS_BUILTIN_EXPECT (V8_GNUC_PREREQ(2, 96, 0))
158 183
159 // g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality 184 // g++ requires -std=c++0x or -std=gnu++0x to support C++11 functionality
160 // without warnings (functionality used by the macros below). These modes 185 // without warnings (functionality used by the macros below). These modes
161 // are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or, 186 // are detectable by checking whether __GXX_EXPERIMENTAL_CXX0X__ is defined or,
162 // more standardly, by checking whether __cplusplus has a C++11 or greater 187 // more standardly, by checking whether __cplusplus has a C++11 or greater
163 // value. Current versions of g++ do not correctly set __cplusplus, so we check 188 // value. Current versions of g++ do not correctly set __cplusplus, so we check
164 // both for forward compatibility. 189 // both for forward compatibility.
165 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L 190 # if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
166 # define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0)) 191 # define V8_HAS_CXX11_ALIGNAS (V8_GNUC_PREREQ(4, 8, 0))
192 # define V8_HAS_CXX11_ALIGNOF (V8_GNUC_PREREQ(4, 5, 0))
167 # define V8_HAS_CXX11_STATIC_ASSERT (V8_GNUC_PREREQ(4, 3, 0)) 193 # define V8_HAS_CXX11_STATIC_ASSERT (V8_GNUC_PREREQ(4, 3, 0))
168 # define V8_HAS_CXX11_DELETE (V8_GNUC_PREREQ(4, 4, 0)) 194 # define V8_HAS_CXX11_DELETE (V8_GNUC_PREREQ(4, 4, 0))
169 # define V8_HAS_CXX11_OVERRIDE (V8_GNUC_PREREQ(4, 7, 0)) 195 # define V8_HAS_CXX11_OVERRIDE (V8_GNUC_PREREQ(4, 7, 0))
170 # define V8_HAS_CXX11_FINAL (V8_GNUC_PREREQ(4, 7, 0)) 196 # define V8_HAS_CXX11_FINAL (V8_GNUC_PREREQ(4, 7, 0))
171 # else 197 # else
172 // '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655. 198 // '__final' is a non-C++11 GCC synonym for 'final', per GCC r176655.
173 # define V8_HAS___FINAL (V8_GNUC_PREREQ(4, 7, 0)) 199 # define V8_HAS___FINAL (V8_GNUC_PREREQ(4, 7, 0))
174 # endif 200 # endif
175 201
176 #elif defined(_MSC_VER) 202 #elif defined(_MSC_VER)
177 203
178 # define V8_GNUC_PREREQ(major, minor, patchlevel) 0
179
180 # define V8_CC_MSVC 1 204 # define V8_CC_MSVC 1
181 205
182 // Override control was added with Visual Studio 2005, but 206 // Override control was added with Visual Studio 2005, but
183 // Visual Studio 2010 and earlier spell "final" as "sealed". 207 // Visual Studio 2010 and earlier spell "final" as "sealed".
184 # define V8_HAS_CXX11_FINAL (_MSC_VER >= 1700) 208 # define V8_HAS_CXX11_FINAL (_MSC_VER >= 1700)
185 # define V8_HAS_CXX11_OVERRIDE (_MSC_VER >= 1400) 209 # define V8_HAS_CXX11_OVERRIDE (_MSC_VER >= 1400)
186 # define V8_HAS_SEALED (_MSC_VER >= 1400) 210 # define V8_HAS_SEALED (_MSC_VER >= 1400)
187 211
188 # define V8_HAS_DECLSPEC_ALIGN 1 212 # define V8_HAS_DECLSPEC_ALIGN 1
189 # define V8_HAS_DECLSPEC_DEPRECATED (_MSC_VER >= 1300) 213 # define V8_HAS_DECLSPEC_DEPRECATED (_MSC_VER >= 1300)
190 214
215 # define V8_HAS___ALIGNOF 1
191 # define V8_HAS___FORCEINLINE 1 216 # define V8_HAS___FORCEINLINE 1
192 217
193 #endif 218 #endif
194 219
195 220
196 // ----------------------------------------------------------------------------- 221 // -----------------------------------------------------------------------------
197 // Helper macros 222 // Helper macros
198 223
199 // A macro used to make better inlining. Don't bother for debug builds. 224 // A macro used to make better inlining. Don't bother for debug builds.
200 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE 225 #if !defined(DEBUG) && V8_HAS_ATTRIBUTE_ALWAYS_INLINE
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 # define V8_FINAL /* NOT SUPPORTED */ 297 # define V8_FINAL /* NOT SUPPORTED */
273 #endif 298 #endif
274 299
275 300
276 // This macro allows to specify memory alignment for structs, classes, etc. 301 // This macro allows to specify memory alignment for structs, classes, etc.
277 // Use like: 302 // Use like:
278 // class V8_ALIGNAS(16) MyClass { ... }; 303 // class V8_ALIGNAS(16) MyClass { ... };
279 // V8_ALIGNAS(32) int array[42]; 304 // V8_ALIGNAS(32) int array[42];
280 #if V8_HAS_CXX11_ALIGNAS 305 #if V8_HAS_CXX11_ALIGNAS
281 # define V8_ALIGNAS(n) alignas(n) 306 # define V8_ALIGNAS(n) alignas(n)
282 #elif V8_HAS_ATTRIBUTE___ALIGNED__ 307 #elif V8_HAS_ATTRIBUTE_ALIGNED
283 # define V8_ALIGNAS(n) __attribute__((__aligned__(n))) 308 # define V8_ALIGNAS(n) __attribute__((aligned(n)))
284 #elif V8_HAS_DECLSPEC_ALIGN 309 #elif V8_HAS_DECLSPEC_ALIGN
285 # define V8_ALIGNAS(n) __declspec(align(n)) 310 # define V8_ALIGNAS(n) __declspec(align(n))
286 #else 311 #else
287 # define V8_ALIGNAS(n) /* NOT SUPPORTED */ 312 # define V8_ALIGNAS(n) /* NOT SUPPORTED */
288 #endif 313 #endif
289 314
315 // This macro takes a type and returns the power of 2 byte boundary on which
316 // the type instances must be allocated.
317 // Use like:
318 // size_t alignment = V8_ALIGNOF(double);
319 // V8_ALIGNAS(V8_ALIGNOF(void*)) int x;
320 #if V8_HAS_CXX11_ALIGNOF
321 # define V8_ALIGNOF(t) alignof(t)
322 #elif V8_HAS___ALIGNOF
323 # define V8_ALIGNOF(t) __alignof(t)
324 #elif V8_HAS___ALIGNOF__
325 # define V8_ALIGNOF(t) __alignof__(t)
326 #else
327 namespace v8 { template <typename T> struct AlignOfHelper { char x; T t; }; }
328 # define V8_ALIGNOF(t) (sizeof(::v8::AlignOfHelper<t>) - sizeof(t))
329 #endif
330
290 #endif // V8CONFIG_H_ 331 #endif // V8CONFIG_H_
OLDNEW
« no previous file with comments | « no previous file | src/lazy-instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698