| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 (*memcopy_function)(dest, src, size); | 168 (*memcopy_function)(dest, src, size); |
| 169 #ifdef DEBUG | 169 #ifdef DEBUG |
| 170 CHECK_EQ(0, memcmp(dest, src, size)); | 170 CHECK_EQ(0, memcmp(dest, src, size)); |
| 171 #endif | 171 #endif |
| 172 } | 172 } |
| 173 #endif // V8_TARGET_ARCH_IA32 | 173 #endif // V8_TARGET_ARCH_IA32 |
| 174 | 174 |
| 175 #ifdef _WIN64 | 175 #ifdef _WIN64 |
| 176 typedef double (*ModuloFunction)(double, double); | 176 typedef double (*ModuloFunction)(double, double); |
| 177 static ModuloFunction modulo_function = NULL; | 177 static ModuloFunction modulo_function = NULL; |
| 178 V8_DECLARE_ONCE(modulo_function_init_once); | |
| 179 // Defined in codegen-x64.cc. | 178 // Defined in codegen-x64.cc. |
| 180 ModuloFunction CreateModuloFunction(); | 179 ModuloFunction CreateModuloFunction(); |
| 181 | 180 |
| 182 void init_modulo_function() { | 181 void init_modulo_function() { |
| 183 modulo_function = CreateModuloFunction(); | 182 modulo_function = CreateModuloFunction(); |
| 184 } | 183 } |
| 185 | 184 |
| 186 double modulo(double x, double y) { | 185 double modulo(double x, double y) { |
| 187 CallOnce(&modulo_function_init_once, &init_modulo_function); | |
| 188 // Note: here we rely on dependent reads being ordered. This is true | 186 // Note: here we rely on dependent reads being ordered. This is true |
| 189 // on all architectures we currently support. | 187 // on all architectures we currently support. |
| 190 return (*modulo_function)(x, y); | 188 return (*modulo_function)(x, y); |
| 191 } | 189 } |
| 192 #else // Win32 | 190 #else // Win32 |
| 193 | 191 |
| 194 double modulo(double x, double y) { | 192 double modulo(double x, double y) { |
| 195 // Workaround MS fmod bugs. ECMA-262 says: | 193 // Workaround MS fmod bugs. ECMA-262 says: |
| 196 // dividend is finite and divisor is an infinity => result equals dividend | 194 // dividend is finite and divisor is an infinity => result equals dividend |
| 197 // dividend is a zero and divisor is nonzero finite => result equals dividend | 195 // dividend is a zero and divisor is nonzero finite => result equals dividend |
| 198 if (!(isfinite(x) && (!isfinite(y) && !isnan(y))) && | 196 if (!(isfinite(x) && (!isfinite(y) && !isnan(y))) && |
| 199 !(x == 0 && (y != 0 && isfinite(y)))) { | 197 !(x == 0 && (y != 0 && isfinite(y)))) { |
| 200 x = fmod(x, y); | 198 x = fmod(x, y); |
| 201 } | 199 } |
| 202 return x; | 200 return x; |
| 203 } | 201 } |
| 204 | 202 |
| 205 #endif // _WIN64 | 203 #endif // _WIN64 |
| 206 | 204 |
| 207 | 205 |
| 208 #define UNARY_MATH_FUNCTION(name, generator) \ | 206 #define UNARY_MATH_FUNCTION(name, generator) \ |
| 209 static UnaryMathFunction fast_##name##_function = NULL; \ | 207 static UnaryMathFunction fast_##name##_function = NULL; \ |
| 210 V8_DECLARE_ONCE(fast_##name##_init_once); \ | |
| 211 void init_fast_##name##_function() { \ | 208 void init_fast_##name##_function() { \ |
| 212 fast_##name##_function = generator; \ | 209 fast_##name##_function = generator; \ |
| 213 } \ | 210 } \ |
| 214 double fast_##name(double x) { \ | 211 double fast_##name(double x) { \ |
| 215 CallOnce(&fast_##name##_init_once, \ | |
| 216 &init_fast_##name##_function); \ | |
| 217 return (*fast_##name##_function)(x); \ | 212 return (*fast_##name##_function)(x); \ |
| 218 } | 213 } |
| 219 | 214 |
| 220 UNARY_MATH_FUNCTION(sin, CreateTranscendentalFunction(TranscendentalCache::SIN)) | 215 UNARY_MATH_FUNCTION(sin, CreateTranscendentalFunction(TranscendentalCache::SIN)) |
| 221 UNARY_MATH_FUNCTION(cos, CreateTranscendentalFunction(TranscendentalCache::COS)) | 216 UNARY_MATH_FUNCTION(cos, CreateTranscendentalFunction(TranscendentalCache::COS)) |
| 222 UNARY_MATH_FUNCTION(tan, CreateTranscendentalFunction(TranscendentalCache::TAN)) | 217 UNARY_MATH_FUNCTION(tan, CreateTranscendentalFunction(TranscendentalCache::TAN)) |
| 223 UNARY_MATH_FUNCTION(log, CreateTranscendentalFunction(TranscendentalCache::LOG)) | 218 UNARY_MATH_FUNCTION(log, CreateTranscendentalFunction(TranscendentalCache::LOG)) |
| 224 UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) | 219 UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) |
| 225 | 220 |
| 226 #undef MATH_FUNCTION | 221 #undef MATH_FUNCTION |
| 227 | 222 |
| 228 | 223 |
| 224 void MathSetup() { |
| 225 #ifdef _WIN64 |
| 226 init_modulo_function(); |
| 227 #endif |
| 228 init_fast_sin_function(); |
| 229 init_fast_cos_function(); |
| 230 init_fast_tan_function(); |
| 231 init_fast_log_function(); |
| 232 init_fast_sqrt_function(); |
| 233 } |
| 234 |
| 235 |
| 229 // ---------------------------------------------------------------------------- | 236 // ---------------------------------------------------------------------------- |
| 230 // The Time class represents time on win32. A timestamp is represented as | 237 // The Time class represents time on win32. A timestamp is represented as |
| 231 // a 64-bit integer in 100 nanoseconds since January 1, 1601 (UTC). JavaScript | 238 // a 64-bit integer in 100 nanoseconds since January 1, 1601 (UTC). JavaScript |
| 232 // timestamps are represented as a doubles in milliseconds since 00:00:00 UTC, | 239 // timestamps are represented as a doubles in milliseconds since 00:00:00 UTC, |
| 233 // January 1, 1970. | 240 // January 1, 1970. |
| 234 | 241 |
| 235 class Time { | 242 class Time { |
| 236 public: | 243 public: |
| 237 // Constructors. | 244 // Constructors. |
| 238 Time(); | 245 Time(); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 // Convert the current time to a 64-bit integer first, before converting it | 570 // Convert the current time to a 64-bit integer first, before converting it |
| 564 // to an unsigned. Going directly can cause an overflow and the seed to be | 571 // to an unsigned. Going directly can cause an overflow and the seed to be |
| 565 // set to all ones. The seed will be identical for different instances that | 572 // set to all ones. The seed will be identical for different instances that |
| 566 // call this setup code within the same millisecond. | 573 // call this setup code within the same millisecond. |
| 567 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); | 574 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); |
| 568 srand(static_cast<unsigned int>(seed)); | 575 srand(static_cast<unsigned int>(seed)); |
| 569 limit_mutex = CreateMutex(); | 576 limit_mutex = CreateMutex(); |
| 570 } | 577 } |
| 571 | 578 |
| 572 | 579 |
| 580 void OS::PostSetUp() { |
| 581 // Math functions depend on CPU features therefore they are initialized after |
| 582 // CPU. |
| 583 MathSetup(); |
| 584 } |
| 585 |
| 586 |
| 573 // Returns the accumulated user time for thread. | 587 // Returns the accumulated user time for thread. |
| 574 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { | 588 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { |
| 575 FILETIME dummy; | 589 FILETIME dummy; |
| 576 uint64_t usertime; | 590 uint64_t usertime; |
| 577 | 591 |
| 578 // Get the amount of time that the thread has executed in user mode. | 592 // Get the amount of time that the thread has executed in user mode. |
| 579 if (!GetThreadTimes(GetCurrentThread(), &dummy, &dummy, &dummy, | 593 if (!GetThreadTimes(GetCurrentThread(), &dummy, &dummy, &dummy, |
| 580 reinterpret_cast<FILETIME*>(&usertime))) return -1; | 594 reinterpret_cast<FILETIME*>(&usertime))) return -1; |
| 581 | 595 |
| 582 // Adjust the resolution to micro-seconds. | 596 // Adjust the resolution to micro-seconds. |
| (...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2089 | 2103 |
| 2090 | 2104 |
| 2091 void Sampler::Stop() { | 2105 void Sampler::Stop() { |
| 2092 ASSERT(IsActive()); | 2106 ASSERT(IsActive()); |
| 2093 SamplerThread::RemoveActiveSampler(this); | 2107 SamplerThread::RemoveActiveSampler(this); |
| 2094 SetActive(false); | 2108 SetActive(false); |
| 2095 } | 2109 } |
| 2096 | 2110 |
| 2097 | 2111 |
| 2098 } } // namespace v8::internal | 2112 } } // namespace v8::internal |
| OLD | NEW |