| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_GLOBALS_H_ | 5 #ifndef V8_GLOBALS_H_ |
| 6 #define V8_GLOBALS_H_ | 6 #define V8_GLOBALS_H_ |
| 7 | 7 |
| 8 #include "../include/v8stdint.h" | 8 #include "../include/v8stdint.h" |
| 9 | 9 |
| 10 #include "base/build_config.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "checks.h" | 12 #include "checks.h" |
| 12 | 13 |
| 13 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic' | 14 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic' |
| 14 // warning flag and certain versions of GCC due to a bug: | 15 // warning flag and certain versions of GCC due to a bug: |
| 15 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931 | 16 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931 |
| 16 // For now, we use the more involved template-based version from <limits>, but | 17 // For now, we use the more involved template-based version from <limits>, but |
| 17 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x) | 18 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x) |
| 18 #if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0) | 19 #if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0) |
| 19 # include <limits> // NOLINT | 20 # include <limits> // NOLINT |
| 20 # define V8_INFINITY std::numeric_limits<double>::infinity() | 21 # define V8_INFINITY std::numeric_limits<double>::infinity() |
| 21 #elif V8_LIBC_MSVCRT | 22 #elif V8_LIBC_MSVCRT |
| 22 # define V8_INFINITY HUGE_VAL | 23 # define V8_INFINITY HUGE_VAL |
| 23 #else | 24 #else |
| 24 # define V8_INFINITY INFINITY | 25 # define V8_INFINITY INFINITY |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 27 namespace v8 { | 28 namespace v8 { |
| 28 namespace internal { | 29 namespace internal { |
| 29 | 30 |
| 30 // Processor architecture detection. For more info on what's defined, see: | |
| 31 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx | |
| 32 // http://www.agner.org/optimize/calling_conventions.pdf | |
| 33 // or with gcc, run: "echo | gcc -E -dM -" | |
| 34 #if defined(_M_X64) || defined(__x86_64__) | |
| 35 #if defined(__native_client__) | |
| 36 // For Native Client builds of V8, use V8_TARGET_ARCH_ARM, so that V8 | |
| 37 // generates ARM machine code, together with a portable ARM simulator | |
| 38 // compiled for the host architecture in question. | |
| 39 // | |
| 40 // Since Native Client is ILP-32 on all architectures we use | |
| 41 // V8_HOST_ARCH_IA32 on both 32- and 64-bit x86. | |
| 42 #define V8_HOST_ARCH_IA32 1 | |
| 43 #define V8_HOST_ARCH_32_BIT 1 | |
| 44 #define V8_HOST_CAN_READ_UNALIGNED 1 | |
| 45 #else | |
| 46 #define V8_HOST_ARCH_X64 1 | |
| 47 #define V8_HOST_ARCH_64_BIT 1 | |
| 48 #define V8_HOST_CAN_READ_UNALIGNED 1 | |
| 49 #endif // __native_client__ | |
| 50 #elif defined(_M_IX86) || defined(__i386__) | |
| 51 #define V8_HOST_ARCH_IA32 1 | |
| 52 #define V8_HOST_ARCH_32_BIT 1 | |
| 53 #define V8_HOST_CAN_READ_UNALIGNED 1 | |
| 54 #elif defined(__AARCH64EL__) | |
| 55 #define V8_HOST_ARCH_ARM64 1 | |
| 56 #define V8_HOST_ARCH_64_BIT 1 | |
| 57 #define V8_HOST_CAN_READ_UNALIGNED 1 | |
| 58 #elif defined(__ARMEL__) | |
| 59 #define V8_HOST_ARCH_ARM 1 | |
| 60 #define V8_HOST_ARCH_32_BIT 1 | |
| 61 #elif defined(__MIPSEB__) || defined(__MIPSEL__) | |
| 62 #define V8_HOST_ARCH_MIPS 1 | |
| 63 #define V8_HOST_ARCH_32_BIT 1 | |
| 64 #else | |
| 65 #error "Host architecture was not detected as supported by v8" | |
| 66 #endif | |
| 67 | |
| 68 #if defined(__ARM_ARCH_7A__) || \ | |
| 69 defined(__ARM_ARCH_7R__) || \ | |
| 70 defined(__ARM_ARCH_7__) | |
| 71 # define CAN_USE_ARMV7_INSTRUCTIONS 1 | |
| 72 # ifndef CAN_USE_VFP3_INSTRUCTIONS | |
| 73 # define CAN_USE_VFP3_INSTRUCTIONS | |
| 74 # endif | |
| 75 #endif | |
| 76 | |
| 77 | |
| 78 // Target architecture detection. This may be set externally. If not, detect | |
| 79 // in the same way as the host architecture, that is, target the native | |
| 80 // environment as presented by the compiler. | |
| 81 #if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_IA32 && !V8_TARGET_ARCH_X87 &&\ | |
| 82 !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64 && !V8_TARGET_ARCH_MIPS | |
| 83 #if defined(_M_X64) || defined(__x86_64__) | |
| 84 #define V8_TARGET_ARCH_X64 1 | |
| 85 #elif defined(_M_IX86) || defined(__i386__) | |
| 86 #define V8_TARGET_ARCH_IA32 1 | |
| 87 #elif defined(__AARCH64EL__) | |
| 88 #define V8_TARGET_ARCH_ARM64 1 | |
| 89 #elif defined(__ARMEL__) | |
| 90 #define V8_TARGET_ARCH_ARM 1 | |
| 91 #elif defined(__MIPSEB__) || defined(__MIPSEL__) | |
| 92 #define V8_TARGET_ARCH_MIPS 1 | |
| 93 #else | |
| 94 #error Target architecture was not detected as supported by v8 | |
| 95 #endif | |
| 96 #endif | |
| 97 | |
| 98 // Check for supported combinations of host and target architectures. | |
| 99 #if V8_TARGET_ARCH_IA32 && !V8_HOST_ARCH_IA32 | |
| 100 #error Target architecture ia32 is only supported on ia32 host | |
| 101 #endif | |
| 102 #if V8_TARGET_ARCH_X64 && !V8_HOST_ARCH_X64 | |
| 103 #error Target architecture x64 is only supported on x64 host | |
| 104 #endif | |
| 105 #if (V8_TARGET_ARCH_ARM && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_ARM)) | |
| 106 #error Target architecture arm is only supported on arm and ia32 host | |
| 107 #endif | |
| 108 #if (V8_TARGET_ARCH_ARM64 && !(V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64)) | |
| 109 #error Target architecture arm64 is only supported on arm64 and x64 host | |
| 110 #endif | |
| 111 #if (V8_TARGET_ARCH_MIPS && !(V8_HOST_ARCH_IA32 || V8_HOST_ARCH_MIPS)) | |
| 112 #error Target architecture mips is only supported on mips and ia32 host | |
| 113 #endif | |
| 114 | |
| 115 // Determine whether we are running in a simulated environment. | 31 // Determine whether we are running in a simulated environment. |
| 116 // Setting USE_SIMULATOR explicitly from the build script will force | 32 // Setting USE_SIMULATOR explicitly from the build script will force |
| 117 // the use of a simulated environment. | 33 // the use of a simulated environment. |
| 118 #if !defined(USE_SIMULATOR) | 34 #if !defined(USE_SIMULATOR) |
| 119 #if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64) | 35 #if (V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64) |
| 120 #define USE_SIMULATOR 1 | 36 #define USE_SIMULATOR 1 |
| 121 #endif | 37 #endif |
| 122 #if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM) | 38 #if (V8_TARGET_ARCH_ARM && !V8_HOST_ARCH_ARM) |
| 123 #define USE_SIMULATOR 1 | 39 #define USE_SIMULATOR 1 |
| 124 #endif | 40 #endif |
| 125 #if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS) | 41 #if (V8_TARGET_ARCH_MIPS && !V8_HOST_ARCH_MIPS) |
| 126 #define USE_SIMULATOR 1 | 42 #define USE_SIMULATOR 1 |
| 127 #endif | 43 #endif |
| 128 #endif | 44 #endif |
| 129 | 45 |
| 130 // Determine architecture endianness. | |
| 131 #if V8_TARGET_ARCH_IA32 | |
| 132 #define V8_TARGET_LITTLE_ENDIAN 1 | |
| 133 #elif V8_TARGET_ARCH_X64 | |
| 134 #define V8_TARGET_LITTLE_ENDIAN 1 | |
| 135 #elif V8_TARGET_ARCH_ARM | |
| 136 #define V8_TARGET_LITTLE_ENDIAN 1 | |
| 137 #elif V8_TARGET_ARCH_ARM64 | |
| 138 #define V8_TARGET_LITTLE_ENDIAN 1 | |
| 139 #elif V8_TARGET_ARCH_MIPS | |
| 140 #if defined(__MIPSEB__) | |
| 141 #define V8_TARGET_BIG_ENDIAN 1 | |
| 142 #else | |
| 143 #define V8_TARGET_LITTLE_ENDIAN 1 | |
| 144 #endif | |
| 145 #elif V8_TARGET_ARCH_X87 | |
| 146 #define V8_TARGET_LITTLE_ENDIAN 1 | |
| 147 #else | |
| 148 #error Unknown target architecture endianness | |
| 149 #endif | |
| 150 | |
| 151 // Determine whether the architecture uses an out-of-line constant pool. | 46 // Determine whether the architecture uses an out-of-line constant pool. |
| 152 #define V8_OOL_CONSTANT_POOL 0 | 47 #define V8_OOL_CONSTANT_POOL 0 |
| 153 | 48 |
| 154 // Support for alternative bool type. This is only enabled if the code is | 49 // Support for alternative bool type. This is only enabled if the code is |
| 155 // compiled with USE_MYBOOL defined. This catches some nasty type bugs. | 50 // compiled with USE_MYBOOL defined. This catches some nasty type bugs. |
| 156 // For instance, 'bool b = "false";' results in b == true! This is a hidden | 51 // For instance, 'bool b = "false";' results in b == true! This is a hidden |
| 157 // source of bugs. | 52 // source of bugs. |
| 158 // However, redefining the bool type does have some negative impact on some | 53 // However, redefining the bool type does have some negative impact on some |
| 159 // platforms. It gives rise to compiler warnings (i.e. with | 54 // platforms. It gives rise to compiler warnings (i.e. with |
| 160 // MSVC) in the API header files when mixing code that uses the standard | 55 // MSVC) in the API header files when mixing code that uses the standard |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 #define V8PRIxPTR V8_PTR_PREFIX "x" | 109 #define V8PRIxPTR V8_PTR_PREFIX "x" |
| 215 #define V8PRIdPTR V8_PTR_PREFIX "d" | 110 #define V8PRIdPTR V8_PTR_PREFIX "d" |
| 216 #define V8PRIuPTR V8_PTR_PREFIX "u" | 111 #define V8PRIuPTR V8_PTR_PREFIX "u" |
| 217 | 112 |
| 218 // Fix for Mac OS X defining uintptr_t as "unsigned long": | 113 // Fix for Mac OS X defining uintptr_t as "unsigned long": |
| 219 #if V8_OS_MACOSX | 114 #if V8_OS_MACOSX |
| 220 #undef V8PRIxPTR | 115 #undef V8PRIxPTR |
| 221 #define V8PRIxPTR "lx" | 116 #define V8PRIxPTR "lx" |
| 222 #endif | 117 #endif |
| 223 | 118 |
| 224 #if V8_OS_MACOSX || defined(__FreeBSD__) || defined(__OpenBSD__) | |
| 225 #define USING_BSD_ABI | |
| 226 #endif | |
| 227 | |
| 228 // ----------------------------------------------------------------------------- | 119 // ----------------------------------------------------------------------------- |
| 229 // Constants | 120 // Constants |
| 230 | 121 |
| 231 const int KB = 1024; | 122 const int KB = 1024; |
| 232 const int MB = KB * KB; | 123 const int MB = KB * KB; |
| 233 const int GB = KB * KB * KB; | 124 const int GB = KB * KB * KB; |
| 234 const int kMaxInt = 0x7FFFFFFF; | 125 const int kMaxInt = 0x7FFFFFFF; |
| 235 const int kMinInt = -kMaxInt - 1; | 126 const int kMinInt = -kMaxInt - 1; |
| 236 const int kMaxInt8 = (1 << 7) - 1; | 127 const int kMaxInt8 = (1 << 7) - 1; |
| 237 const int kMinInt8 = -(1 << 7); | 128 const int kMinInt8 = -(1 << 7); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 typedef uint16_t uc16; | 186 typedef uint16_t uc16; |
| 296 typedef int32_t uc32; | 187 typedef int32_t uc32; |
| 297 const int kOneByteSize = kCharSize; | 188 const int kOneByteSize = kCharSize; |
| 298 const int kUC16Size = sizeof(uc16); // NOLINT | 189 const int kUC16Size = sizeof(uc16); // NOLINT |
| 299 | 190 |
| 300 | 191 |
| 301 // Round up n to be a multiple of sz, where sz is a power of 2. | 192 // Round up n to be a multiple of sz, where sz is a power of 2. |
| 302 #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) | 193 #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) |
| 303 | 194 |
| 304 | 195 |
| 305 // The USE(x) template is used to silence C++ compiler warnings | |
| 306 // issued for (yet) unused variables (typically parameters). | |
| 307 template <typename T> | |
| 308 inline void USE(T) { } | |
| 309 | |
| 310 | |
| 311 // FUNCTION_ADDR(f) gets the address of a C function f. | 196 // FUNCTION_ADDR(f) gets the address of a C function f. |
| 312 #define FUNCTION_ADDR(f) \ | 197 #define FUNCTION_ADDR(f) \ |
| 313 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f))) | 198 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f))) |
| 314 | 199 |
| 315 | 200 |
| 316 // FUNCTION_CAST<F>(addr) casts an address into a function | 201 // FUNCTION_CAST<F>(addr) casts an address into a function |
| 317 // of type F. Used to invoke generated code from within C. | 202 // of type F. Used to invoke generated code from within C. |
| 318 template <typename F> | 203 template <typename F> |
| 319 F FUNCTION_CAST(Address addr) { | 204 F FUNCTION_CAST(Address addr) { |
| 320 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr)); | 205 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr)); |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 enum MinusZeroMode { | 757 enum MinusZeroMode { |
| 873 TREAT_MINUS_ZERO_AS_ZERO, | 758 TREAT_MINUS_ZERO_AS_ZERO, |
| 874 FAIL_ON_MINUS_ZERO | 759 FAIL_ON_MINUS_ZERO |
| 875 }; | 760 }; |
| 876 | 761 |
| 877 } } // namespace v8::internal | 762 } } // namespace v8::internal |
| 878 | 763 |
| 879 namespace i = v8::internal; | 764 namespace i = v8::internal; |
| 880 | 765 |
| 881 #endif // V8_GLOBALS_H_ | 766 #endif // V8_GLOBALS_H_ |
| OLD | NEW |