| 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 // Platform-specific code for Win32. | 5 // Platform-specific code for Win32. |
| 6 | 6 |
| 7 // Secure API functions are not available using MinGW with msvcrt.dll | 7 // Secure API functions are not available using MinGW with msvcrt.dll |
| 8 // on Windows XP. Make sure MINGW_HAS_SECURE_API is not defined to | 8 // on Windows XP. Make sure MINGW_HAS_SECURE_API is not defined to |
| 9 // disable definition of secure API functions in standard headers that | 9 // disable definition of secure API functions in standard headers that |
| 10 // would conflict with our own implementation. | 10 // would conflict with our own implementation. |
| 11 #ifdef __MINGW32__ | 11 #ifdef __MINGW32__ |
| 12 #include <_mingw.h> | 12 #include <_mingw.h> |
| 13 #ifdef MINGW_HAS_SECURE_API | 13 #ifdef MINGW_HAS_SECURE_API |
| 14 #undef MINGW_HAS_SECURE_API | 14 #undef MINGW_HAS_SECURE_API |
| 15 #endif // MINGW_HAS_SECURE_API | 15 #endif // MINGW_HAS_SECURE_API |
| 16 #endif // __MINGW32__ | 16 #endif // __MINGW32__ |
| 17 | 17 |
| 18 #include "win32-headers.h" | 18 #include "win32-headers.h" |
| 19 | 19 |
| 20 #include "v8.h" | 20 #include "v8.h" |
| 21 | 21 |
| 22 #include "codegen.h" | |
| 23 #include "isolate-inl.h" | 22 #include "isolate-inl.h" |
| 24 #include "platform.h" | 23 #include "platform.h" |
| 25 | 24 |
| 26 #ifdef _MSC_VER | 25 #ifdef _MSC_VER |
| 27 | 26 |
| 28 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually | 27 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually |
| 29 // defined in strings.h. | 28 // defined in strings.h. |
| 30 int strncasecmp(const char* s1, const char* s2, int n) { | 29 int strncasecmp(const char* s1, const char* s2, int n) { |
| 31 return _strnicmp(s1, s2, n); | 30 return _strnicmp(s1, s2, n); |
| 32 } | 31 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // Copy memory area to disjoint memory area. | 122 // Copy memory area to disjoint memory area. |
| 124 void OS::MemMove(void* dest, const void* src, size_t size) { | 123 void OS::MemMove(void* dest, const void* src, size_t size) { |
| 125 if (size == 0) return; | 124 if (size == 0) return; |
| 126 // Note: here we rely on dependent reads being ordered. This is true | 125 // Note: here we rely on dependent reads being ordered. This is true |
| 127 // on all architectures we currently support. | 126 // on all architectures we currently support. |
| 128 (*memmove_function)(dest, src, size); | 127 (*memmove_function)(dest, src, size); |
| 129 } | 128 } |
| 130 | 129 |
| 131 #endif // V8_TARGET_ARCH_IA32 | 130 #endif // V8_TARGET_ARCH_IA32 |
| 132 | 131 |
| 133 #ifdef _WIN64 | |
| 134 typedef double (*ModuloFunction)(double, double); | |
| 135 static ModuloFunction modulo_function = NULL; | |
| 136 // Defined in codegen-x64.cc. | |
| 137 ModuloFunction CreateModuloFunction(); | |
| 138 | |
| 139 void init_modulo_function() { | |
| 140 modulo_function = CreateModuloFunction(); | |
| 141 } | |
| 142 | |
| 143 | |
| 144 double modulo(double x, double y) { | |
| 145 // Note: here we rely on dependent reads being ordered. This is true | |
| 146 // on all architectures we currently support. | |
| 147 return (*modulo_function)(x, y); | |
| 148 } | |
| 149 #else // Win32 | |
| 150 | |
| 151 double modulo(double x, double y) { | |
| 152 // Workaround MS fmod bugs. ECMA-262 says: | |
| 153 // dividend is finite and divisor is an infinity => result equals dividend | |
| 154 // dividend is a zero and divisor is nonzero finite => result equals dividend | |
| 155 if (!(std::isfinite(x) && (!std::isfinite(y) && !std::isnan(y))) && | |
| 156 !(x == 0 && (y != 0 && std::isfinite(y)))) { | |
| 157 x = fmod(x, y); | |
| 158 } | |
| 159 return x; | |
| 160 } | |
| 161 | |
| 162 #endif // _WIN64 | |
| 163 | |
| 164 | |
| 165 #define UNARY_MATH_FUNCTION(name, generator) \ | |
| 166 static UnaryMathFunction fast_##name##_function = NULL; \ | |
| 167 void init_fast_##name##_function() { \ | |
| 168 fast_##name##_function = generator; \ | |
| 169 } \ | |
| 170 double fast_##name(double x) { \ | |
| 171 return (*fast_##name##_function)(x); \ | |
| 172 } | |
| 173 | |
| 174 UNARY_MATH_FUNCTION(exp, CreateExpFunction()) | |
| 175 UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) | |
| 176 | |
| 177 #undef UNARY_MATH_FUNCTION | |
| 178 | |
| 179 | |
| 180 void lazily_initialize_fast_exp() { | |
| 181 if (fast_exp_function == NULL) { | |
| 182 init_fast_exp_function(); | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 | |
| 187 void MathSetup() { | |
| 188 #ifdef _WIN64 | |
| 189 init_modulo_function(); | |
| 190 #endif | |
| 191 // fast_exp is initialized lazily. | |
| 192 init_fast_sqrt_function(); | |
| 193 } | |
| 194 | |
| 195 | 132 |
| 196 class TimezoneCache { | 133 class TimezoneCache { |
| 197 public: | 134 public: |
| 198 TimezoneCache() : initialized_(false) { } | 135 TimezoneCache() : initialized_(false) { } |
| 199 | 136 |
| 200 void Clear() { | 137 void Clear() { |
| 201 initialized_ = false; | 138 initialized_ = false; |
| 202 } | 139 } |
| 203 | 140 |
| 204 // Initialize timezone information. The timezone information is obtained from | 141 // Initialize timezone information. The timezone information is obtained from |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 // Returns a string identifying the current timezone for the | 446 // Returns a string identifying the current timezone for the |
| 510 // timestamp taking into account daylight saving. | 447 // timestamp taking into account daylight saving. |
| 511 char* Win32Time::LocalTimezone(TimezoneCache* cache) { | 448 char* Win32Time::LocalTimezone(TimezoneCache* cache) { |
| 512 // Return the standard or DST time zone name based on whether daylight | 449 // Return the standard or DST time zone name based on whether daylight |
| 513 // saving is in effect at the given time. | 450 // saving is in effect at the given time. |
| 514 return InDST(cache) ? cache->dst_tz_name_ : cache->std_tz_name_; | 451 return InDST(cache) ? cache->dst_tz_name_ : cache->std_tz_name_; |
| 515 } | 452 } |
| 516 | 453 |
| 517 | 454 |
| 518 void OS::PostSetUp() { | 455 void OS::PostSetUp() { |
| 519 // Math functions depend on CPU features therefore they are initialized after | |
| 520 // CPU. | |
| 521 MathSetup(); | |
| 522 #if V8_TARGET_ARCH_IA32 | 456 #if V8_TARGET_ARCH_IA32 |
| 523 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); | 457 OS::MemMoveFunction generated_memmove = CreateMemMoveFunction(); |
| 524 if (generated_memmove != NULL) { | 458 if (generated_memmove != NULL) { |
| 525 memmove_function = generated_memmove; | 459 memmove_function = generated_memmove; |
| 526 } | 460 } |
| 527 #endif | 461 #endif |
| 528 } | 462 } |
| 529 | 463 |
| 530 | 464 |
| 531 // Returns the accumulated user time for thread. | 465 // Returns the accumulated user time for thread. |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1488 ASSERT(result); | 1422 ASSERT(result); |
| 1489 } | 1423 } |
| 1490 | 1424 |
| 1491 | 1425 |
| 1492 | 1426 |
| 1493 void Thread::YieldCPU() { | 1427 void Thread::YieldCPU() { |
| 1494 Sleep(0); | 1428 Sleep(0); |
| 1495 } | 1429 } |
| 1496 | 1430 |
| 1497 } } // namespace v8::internal | 1431 } } // namespace v8::internal |
| OLD | NEW |