OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 30 matching lines...) Expand all Loading... |
41 #define V8_WIN32_HEADERS_FULL | 41 #define V8_WIN32_HEADERS_FULL |
42 #include "win32-headers.h" | 42 #include "win32-headers.h" |
43 | 43 |
44 #include "v8.h" | 44 #include "v8.h" |
45 | 45 |
46 #include "codegen.h" | 46 #include "codegen.h" |
47 #include "platform.h" | 47 #include "platform.h" |
48 #include "simulator.h" | 48 #include "simulator.h" |
49 #include "vm-state-inl.h" | 49 #include "vm-state-inl.h" |
50 | 50 |
51 #ifdef _MSC_VER | 51 #if V8_CC_MSVC |
52 | 52 |
53 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually | 53 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually |
54 // defined in strings.h. | 54 // defined in strings.h. |
55 int strncasecmp(const char* s1, const char* s2, int n) { | 55 int strncasecmp(const char* s1, const char* s2, int n) { |
56 return _strnicmp(s1, s2, n); | 56 return _strnicmp(s1, s2, n); |
57 } | 57 } |
58 | 58 |
59 #endif // _MSC_VER | 59 #endif // V8_CC_MSVC |
60 | 60 |
61 | 61 |
62 // Extra functions for MinGW. Most of these are the _s functions which are in | 62 // Extra functions for MinGW. Most of these are the _s functions which are in |
63 // the Microsoft Visual Studio C++ CRT. | 63 // the Microsoft Visual Studio C++ CRT. |
64 #ifdef __MINGW32__ | 64 #ifdef __MINGW32__ |
65 | 65 |
66 | 66 |
67 #ifndef __MINGW64_VERSION_MAJOR | 67 #ifndef __MINGW64_VERSION_MAJOR |
68 | 68 |
69 #define _TRUNCATE 0 | 69 #define _TRUNCATE 0 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // Copy memory area to disjoint memory area. | 162 // Copy memory area to disjoint memory area. |
163 void OS::MemMove(void* dest, const void* src, size_t size) { | 163 void OS::MemMove(void* dest, const void* src, size_t size) { |
164 if (size == 0) return; | 164 if (size == 0) return; |
165 // Note: here we rely on dependent reads being ordered. This is true | 165 // Note: here we rely on dependent reads being ordered. This is true |
166 // on all architectures we currently support. | 166 // on all architectures we currently support. |
167 (*memmove_function)(dest, src, size); | 167 (*memmove_function)(dest, src, size); |
168 } | 168 } |
169 | 169 |
170 #endif // V8_TARGET_ARCH_IA32 | 170 #endif // V8_TARGET_ARCH_IA32 |
171 | 171 |
172 #ifdef _WIN64 | 172 #if V8_OS_WIN64 |
173 typedef double (*ModuloFunction)(double, double); | 173 typedef double (*ModuloFunction)(double, double); |
174 static ModuloFunction modulo_function = NULL; | 174 static ModuloFunction modulo_function = NULL; |
175 // Defined in codegen-x64.cc. | 175 // Defined in codegen-x64.cc. |
176 ModuloFunction CreateModuloFunction(); | 176 ModuloFunction CreateModuloFunction(); |
177 | 177 |
178 void init_modulo_function() { | 178 void init_modulo_function() { |
179 modulo_function = CreateModuloFunction(); | 179 modulo_function = CreateModuloFunction(); |
180 } | 180 } |
181 | 181 |
182 | 182 |
183 double modulo(double x, double y) { | 183 double modulo(double x, double y) { |
184 // Note: here we rely on dependent reads being ordered. This is true | 184 // Note: here we rely on dependent reads being ordered. This is true |
185 // on all architectures we currently support. | 185 // on all architectures we currently support. |
186 return (*modulo_function)(x, y); | 186 return (*modulo_function)(x, y); |
187 } | 187 } |
188 #else // Win32 | 188 #else |
189 | |
190 double modulo(double x, double y) { | 189 double modulo(double x, double y) { |
191 // Workaround MS fmod bugs. ECMA-262 says: | 190 // Workaround MS fmod bugs. ECMA-262 says: |
192 // dividend is finite and divisor is an infinity => result equals dividend | 191 // dividend is finite and divisor is an infinity => result equals dividend |
193 // dividend is a zero and divisor is nonzero finite => result equals dividend | 192 // dividend is a zero and divisor is nonzero finite => result equals dividend |
194 if (!(std::isfinite(x) && (!std::isfinite(y) && !std::isnan(y))) && | 193 if (!(std::isfinite(x) && (!std::isfinite(y) && !std::isnan(y))) && |
195 !(x == 0 && (y != 0 && std::isfinite(y)))) { | 194 !(x == 0 && (y != 0 && std::isfinite(y)))) { |
196 x = fmod(x, y); | 195 x = fmod(x, y); |
197 } | 196 } |
198 return x; | 197 return x; |
199 } | 198 } |
200 | 199 #endif // V8_OS_WIN64 |
201 #endif // _WIN64 | |
202 | 200 |
203 | 201 |
204 #define UNARY_MATH_FUNCTION(name, generator) \ | 202 #define UNARY_MATH_FUNCTION(name, generator) \ |
205 static UnaryMathFunction fast_##name##_function = NULL; \ | 203 static UnaryMathFunction fast_##name##_function = NULL; \ |
206 void init_fast_##name##_function() { \ | 204 void init_fast_##name##_function() { \ |
207 fast_##name##_function = generator; \ | 205 fast_##name##_function = generator; \ |
208 } \ | 206 } \ |
209 double fast_##name(double x) { \ | 207 double fast_##name(double x) { \ |
210 return (*fast_##name##_function)(x); \ | 208 return (*fast_##name##_function)(x); \ |
211 } | 209 } |
212 | 210 |
213 UNARY_MATH_FUNCTION(sin, CreateTranscendentalFunction(TranscendentalCache::SIN)) | 211 UNARY_MATH_FUNCTION(sin, CreateTranscendentalFunction(TranscendentalCache::SIN)) |
214 UNARY_MATH_FUNCTION(cos, CreateTranscendentalFunction(TranscendentalCache::COS)) | 212 UNARY_MATH_FUNCTION(cos, CreateTranscendentalFunction(TranscendentalCache::COS)) |
215 UNARY_MATH_FUNCTION(tan, CreateTranscendentalFunction(TranscendentalCache::TAN)) | 213 UNARY_MATH_FUNCTION(tan, CreateTranscendentalFunction(TranscendentalCache::TAN)) |
216 UNARY_MATH_FUNCTION(log, CreateTranscendentalFunction(TranscendentalCache::LOG)) | 214 UNARY_MATH_FUNCTION(log, CreateTranscendentalFunction(TranscendentalCache::LOG)) |
217 UNARY_MATH_FUNCTION(exp, CreateExpFunction()) | 215 UNARY_MATH_FUNCTION(exp, CreateExpFunction()) |
218 UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) | 216 UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) |
219 | 217 |
220 #undef UNARY_MATH_FUNCTION | 218 #undef UNARY_MATH_FUNCTION |
221 | 219 |
222 | 220 |
223 void lazily_initialize_fast_exp() { | 221 void lazily_initialize_fast_exp() { |
224 if (fast_exp_function == NULL) { | 222 if (fast_exp_function == NULL) { |
225 init_fast_exp_function(); | 223 init_fast_exp_function(); |
226 } | 224 } |
227 } | 225 } |
228 | 226 |
229 | 227 |
230 void MathSetup() { | 228 void MathSetup() { |
231 #ifdef _WIN64 | 229 #if V8_OS_WIN64 |
232 init_modulo_function(); | 230 init_modulo_function(); |
233 #endif | 231 #endif |
234 init_fast_sin_function(); | 232 init_fast_sin_function(); |
235 init_fast_cos_function(); | 233 init_fast_cos_function(); |
236 init_fast_tan_function(); | 234 init_fast_tan_function(); |
237 init_fast_log_function(); | 235 init_fast_log_function(); |
238 // fast_exp is initialized lazily. | 236 // fast_exp is initialized lazily. |
239 init_fast_sqrt_function(); | 237 init_fast_sqrt_function(); |
240 } | 238 } |
241 | 239 |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 if (IsDebuggerPresent() || FLAG_break_on_abort) { | 1000 if (IsDebuggerPresent() || FLAG_break_on_abort) { |
1003 DebugBreak(); | 1001 DebugBreak(); |
1004 } else { | 1002 } else { |
1005 // Make the MSVCRT do a silent abort. | 1003 // Make the MSVCRT do a silent abort. |
1006 raise(SIGABRT); | 1004 raise(SIGABRT); |
1007 } | 1005 } |
1008 } | 1006 } |
1009 | 1007 |
1010 | 1008 |
1011 void OS::DebugBreak() { | 1009 void OS::DebugBreak() { |
1012 #ifdef _MSC_VER | 1010 #if V8_CC_MSVC |
1013 __debugbreak(); | 1011 __debugbreak(); |
1014 #else | 1012 #else |
1015 ::DebugBreak(); | 1013 ::DebugBreak(); |
1016 #endif | 1014 #endif // V8_CC_MSVC |
1017 } | 1015 } |
1018 | 1016 |
1019 | 1017 |
1020 void OS::DumpBacktrace() { | 1018 void OS::DumpBacktrace() { |
1021 // Currently unsupported. | 1019 // Currently unsupported. |
1022 } | 1020 } |
1023 | 1021 |
1024 | 1022 |
1025 class Win32MemoryMappedFile : public OS::MemoryMappedFile { | 1023 class Win32MemoryMappedFile : public OS::MemoryMappedFile { |
1026 public: | 1024 public: |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 // Read the symbols. | 1352 // Read the symbols. |
1355 if (!LoadSymbols(process_handle)) return kStackWalkError; | 1353 if (!LoadSymbols(process_handle)) return kStackWalkError; |
1356 | 1354 |
1357 // Capture current context. | 1355 // Capture current context. |
1358 CONTEXT context; | 1356 CONTEXT context; |
1359 RtlCaptureContext(&context); | 1357 RtlCaptureContext(&context); |
1360 | 1358 |
1361 // Initialize the stack walking | 1359 // Initialize the stack walking |
1362 STACKFRAME64 stack_frame; | 1360 STACKFRAME64 stack_frame; |
1363 memset(&stack_frame, 0, sizeof(stack_frame)); | 1361 memset(&stack_frame, 0, sizeof(stack_frame)); |
1364 #ifdef _WIN64 | 1362 #if V8_OS _WIN64 |
1365 stack_frame.AddrPC.Offset = context.Rip; | 1363 stack_frame.AddrPC.Offset = context.Rip; |
1366 stack_frame.AddrFrame.Offset = context.Rbp; | 1364 stack_frame.AddrFrame.Offset = context.Rbp; |
1367 stack_frame.AddrStack.Offset = context.Rsp; | 1365 stack_frame.AddrStack.Offset = context.Rsp; |
1368 #else | 1366 #else |
1369 stack_frame.AddrPC.Offset = context.Eip; | 1367 stack_frame.AddrPC.Offset = context.Eip; |
1370 stack_frame.AddrFrame.Offset = context.Ebp; | 1368 stack_frame.AddrFrame.Offset = context.Ebp; |
1371 stack_frame.AddrStack.Offset = context.Esp; | 1369 stack_frame.AddrStack.Offset = context.Esp; |
1372 #endif | 1370 #endif |
1373 stack_frame.AddrPC.Mode = AddrModeFlat; | 1371 stack_frame.AddrPC.Mode = AddrModeFlat; |
1374 stack_frame.AddrFrame.Mode = AddrModeFlat; | 1372 stack_frame.AddrFrame.Mode = AddrModeFlat; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 int OS::StackWalk(Vector<OS::StackFrame> frames) { return 0; } | 1461 int OS::StackWalk(Vector<OS::StackFrame> frames) { return 0; } |
1464 #endif // __MINGW32__ | 1462 #endif // __MINGW32__ |
1465 | 1463 |
1466 | 1464 |
1467 uint64_t OS::CpuFeaturesImpliedByPlatform() { | 1465 uint64_t OS::CpuFeaturesImpliedByPlatform() { |
1468 return 0; // Windows runs on anything. | 1466 return 0; // Windows runs on anything. |
1469 } | 1467 } |
1470 | 1468 |
1471 | 1469 |
1472 double OS::nan_value() { | 1470 double OS::nan_value() { |
1473 #ifdef _MSC_VER | 1471 #if V8_CC_MSVC |
1474 // Positive Quiet NaN with no payload (aka. Indeterminate) has all bits | 1472 // Positive Quiet NaN with no payload (aka. Indeterminate) has all bits |
1475 // in mask set, so value equals mask. | 1473 // in mask set, so value equals mask. |
1476 static const __int64 nanval = kQuietNaNMask; | 1474 static const __int64 nanval = kQuietNaNMask; |
1477 return *reinterpret_cast<const double*>(&nanval); | 1475 return *reinterpret_cast<const double*>(&nanval); |
1478 #else // _MSC_VER | 1476 #else // V8_CC_MSVC |
1479 return NAN; | 1477 return NAN; |
1480 #endif // _MSC_VER | 1478 #endif // V8_CC_MSVC |
1481 } | 1479 } |
1482 | 1480 |
1483 | 1481 |
1484 int OS::ActivationFrameAlignment() { | 1482 int OS::ActivationFrameAlignment() { |
1485 #ifdef _WIN64 | 1483 #if V8_OS__WIN64 |
1486 return 16; // Windows 64-bit ABI requires the stack to be 16-byte aligned. | 1484 return 16; // Windows 64-bit ABI requires the stack to be 16-byte aligned. |
1487 #elif defined(__MINGW32__) | 1485 #elif V8_CC_MINGW |
1488 // With gcc 4.4 the tree vectorization optimizer can generate code | 1486 // With gcc 4.4 the tree vectorization optimizer can generate code |
1489 // that requires 16 byte alignment such as movdqa on x86. | 1487 // that requires 16 byte alignment such as movdqa on x86. |
1490 return 16; | 1488 return 16; |
1491 #else | 1489 #else |
1492 return 8; // Floating-point math runs faster with 8-byte alignment. | 1490 return 8; // Floating-point math runs faster with 8-byte alignment. |
1493 #endif | 1491 #endif |
1494 } | 1492 } |
1495 | 1493 |
1496 | 1494 |
1497 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } | 1495 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 limit_mutex = CreateMutex(); | 1988 limit_mutex = CreateMutex(); |
1991 } | 1989 } |
1992 | 1990 |
1993 | 1991 |
1994 void OS::TearDown() { | 1992 void OS::TearDown() { |
1995 delete limit_mutex; | 1993 delete limit_mutex; |
1996 } | 1994 } |
1997 | 1995 |
1998 | 1996 |
1999 } } // namespace v8::internal | 1997 } } // namespace v8::internal |
OLD | NEW |