| 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 static LazyMutex modulo_function_mutex = LAZY_MUTEX_INITIALIZER; | 178 V8_DECLARE_ONCE(modulo_function_init_once); |
| 179 // Defined in codegen-x64.cc. | 179 // Defined in codegen-x64.cc. |
| 180 ModuloFunction CreateModuloFunction(); | 180 ModuloFunction CreateModuloFunction(); |
| 181 | 181 |
| 182 void init_modulo_function() { |
| 183 modulo_function = CreateModuloFunction(); |
| 184 MemoryBarrier(); |
| 185 } |
| 186 |
| 182 double modulo(double x, double y) { | 187 double modulo(double x, double y) { |
| 183 if (modulo_function == NULL) { | 188 CallOnce(&modulo_function_init_once, &init_modulo_function); |
| 184 ScopedLock lock(modulo_function_mutex.Pointer()); | |
| 185 if (modulo_function == NULL) { | |
| 186 ModuloFunction temp = CreateModuloFunction(); | |
| 187 MemoryBarrier(); | |
| 188 modulo_function = temp; | |
| 189 } | |
| 190 } | |
| 191 // Note: here we rely on dependent reads being ordered. This is true | 189 // Note: here we rely on dependent reads being ordered. This is true |
| 192 // on all architectures we currently support. | 190 // on all architectures we currently support. |
| 193 return (*modulo_function)(x, y); | 191 return (*modulo_function)(x, y); |
| 194 } | 192 } |
| 195 #else // Win32 | 193 #else // Win32 |
| 196 | 194 |
| 197 double modulo(double x, double y) { | 195 double modulo(double x, double y) { |
| 198 // Workaround MS fmod bugs. ECMA-262 says: | 196 // Workaround MS fmod bugs. ECMA-262 says: |
| 199 // dividend is finite and divisor is an infinity => result equals dividend | 197 // dividend is finite and divisor is an infinity => result equals dividend |
| 200 // dividend is a zero and divisor is nonzero finite => result equals dividend | 198 // dividend is a zero and divisor is nonzero finite => result equals dividend |
| 201 if (!(isfinite(x) && (!isfinite(y) && !isnan(y))) && | 199 if (!(isfinite(x) && (!isfinite(y) && !isnan(y))) && |
| 202 !(x == 0 && (y != 0 && isfinite(y)))) { | 200 !(x == 0 && (y != 0 && isfinite(y)))) { |
| 203 x = fmod(x, y); | 201 x = fmod(x, y); |
| 204 } | 202 } |
| 205 return x; | 203 return x; |
| 206 } | 204 } |
| 207 | 205 |
| 208 #endif // _WIN64 | 206 #endif // _WIN64 |
| 209 | 207 |
| 210 | 208 |
| 211 static Mutex* math_function_mutex = OS::CreateMutex(); | |
| 212 | |
| 213 #define UNARY_MATH_FUNCTION(name, generator) \ | 209 #define UNARY_MATH_FUNCTION(name, generator) \ |
| 214 static UnaryMathFunction fast_##name##_function = NULL; \ | 210 static UnaryMathFunction fast_##name##_function = NULL; \ |
| 211 V8_DECLARE_ONCE(fast_##name##_init_once); \ |
| 212 void init_fast_##name##_function() { \ |
| 213 fast_##name##_function = generator; \ |
| 214 MemoryBarrier(); \ |
| 215 } \ |
| 215 double fast_##name(double x) { \ | 216 double fast_##name(double x) { \ |
| 216 if (fast_##name##_function == NULL) { \ | 217 CallOnce(&fast_##name##_init_once, \ |
| 217 ScopedLock lock(math_function_mutex); \ | 218 &init_fast_##name##_function); \ |
| 218 UnaryMathFunction temp = generator; \ | |
| 219 MemoryBarrier(); \ | |
| 220 fast_##name##_function = temp; \ | |
| 221 } \ | |
| 222 return (*fast_##name##_function)(x); \ | 219 return (*fast_##name##_function)(x); \ |
| 223 } | 220 } |
| 224 | 221 |
| 225 UNARY_MATH_FUNCTION(sin, CreateTranscendentalFunction(TranscendentalCache::SIN)) | 222 UNARY_MATH_FUNCTION(sin, CreateTranscendentalFunction(TranscendentalCache::SIN)) |
| 226 UNARY_MATH_FUNCTION(cos, CreateTranscendentalFunction(TranscendentalCache::COS)) | 223 UNARY_MATH_FUNCTION(cos, CreateTranscendentalFunction(TranscendentalCache::COS)) |
| 227 UNARY_MATH_FUNCTION(tan, CreateTranscendentalFunction(TranscendentalCache::TAN)) | 224 UNARY_MATH_FUNCTION(tan, CreateTranscendentalFunction(TranscendentalCache::TAN)) |
| 228 UNARY_MATH_FUNCTION(log, CreateTranscendentalFunction(TranscendentalCache::LOG)) | 225 UNARY_MATH_FUNCTION(log, CreateTranscendentalFunction(TranscendentalCache::LOG)) |
| 229 UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) | 226 UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) |
| 230 | 227 |
| 231 #undef MATH_FUNCTION | 228 #undef MATH_FUNCTION |
| (...skipping 1862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2094 | 2091 |
| 2095 | 2092 |
| 2096 void Sampler::Stop() { | 2093 void Sampler::Stop() { |
| 2097 ASSERT(IsActive()); | 2094 ASSERT(IsActive()); |
| 2098 SamplerThread::RemoveActiveSampler(this); | 2095 SamplerThread::RemoveActiveSampler(this); |
| 2099 SetActive(false); | 2096 SetActive(false); |
| 2100 } | 2097 } |
| 2101 | 2098 |
| 2102 | 2099 |
| 2103 } } // namespace v8::internal | 2100 } } // namespace v8::internal |
| OLD | NEW |