OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 V8_BASE_MACROS_H_ | 5 #ifndef V8_BASE_MACROS_H_ |
6 #define V8_BASE_MACROS_H_ | 6 #define V8_BASE_MACROS_H_ |
7 | 7 |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "include/v8stdint.h" | 10 #include "include/v8stdint.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // constant size, gcc 2.95.3, gcc 4.0.1, and msvc 7.1 produce inline | 223 // constant size, gcc 2.95.3, gcc 4.0.1, and msvc 7.1 produce inline |
224 // code with the minimal amount of data movement. On a 32-bit system, | 224 // code with the minimal amount of data movement. On a 32-bit system, |
225 // memcpy(d,s,4) compiles to one load and one store, and memcpy(d,s,8) | 225 // memcpy(d,s,4) compiles to one load and one store, and memcpy(d,s,8) |
226 // compiles to two loads and two stores. | 226 // compiles to two loads and two stores. |
227 // | 227 // |
228 // I tested this code with gcc 2.95.3, gcc 4.0.1, icc 8.1, and msvc 7.1. | 228 // I tested this code with gcc 2.95.3, gcc 4.0.1, icc 8.1, and msvc 7.1. |
229 // | 229 // |
230 // WARNING: if Dest or Source is a non-POD type, the result of the memcpy | 230 // WARNING: if Dest or Source is a non-POD type, the result of the memcpy |
231 // is likely to surprise you. | 231 // is likely to surprise you. |
232 template <class Dest, class Source> | 232 template <class Dest, class Source> |
233 inline Dest bit_cast(const Source& source) { | 233 V8_INLINE Dest bit_cast(Source const& source) { |
234 COMPILE_ASSERT(sizeof(Dest) == sizeof(Source), VerifySizesAreEqual); | 234 COMPILE_ASSERT(sizeof(Dest) == sizeof(Source), VerifySizesAreEqual); |
235 | 235 |
236 Dest dest; | 236 Dest dest; |
237 memcpy(&dest, &source, sizeof(dest)); | 237 memcpy(&dest, &source, sizeof(dest)); |
238 return dest; | 238 return dest; |
239 } | 239 } |
240 | 240 |
241 | 241 |
242 // A macro to disallow the evil copy constructor and operator= functions | 242 // A macro to disallow the evil copy constructor and operator= functions |
243 // This should be used in the private: declarations for a class | 243 // This should be used in the private: declarations for a class |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 402 } |
403 | 403 |
404 | 404 |
405 // Return the smallest multiple of m which is >= x. | 405 // Return the smallest multiple of m which is >= x. |
406 template <typename T> | 406 template <typename T> |
407 inline T RoundUp(T x, intptr_t m) { | 407 inline T RoundUp(T x, intptr_t m) { |
408 return RoundDown<T>(static_cast<T>(x + m - 1), m); | 408 return RoundDown<T>(static_cast<T>(x + m - 1), m); |
409 } | 409 } |
410 | 410 |
411 #endif // V8_BASE_MACROS_H_ | 411 #endif // V8_BASE_MACROS_H_ |
OLD | NEW |