| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 | 121 |
| 122 // ---------------------------------------------------------------------------- | 122 // ---------------------------------------------------------------------------- |
| 123 // Math functions | 123 // Math functions |
| 124 | 124 |
| 125 double modulo(double x, double y) { | 125 double modulo(double x, double y) { |
| 126 return fmod(x, y); | 126 return fmod(x, y); |
| 127 } | 127 } |
| 128 | 128 |
| 129 | 129 |
| 130 static Mutex* math_function_mutex = OS::CreateMutex(); |
| 131 |
| 130 #define UNARY_MATH_FUNCTION(name, generator) \ | 132 #define UNARY_MATH_FUNCTION(name, generator) \ |
| 131 static UnaryMathFunction fast_##name##_function = NULL; \ | 133 static UnaryMathFunction fast_##name##_function = NULL; \ |
| 132 V8_DECLARE_ONCE(fast_##name##_init_once); \ | |
| 133 void init_fast_##name##_function() { \ | |
| 134 fast_##name##_function = generator; \ | |
| 135 } \ | |
| 136 double fast_##name(double x) { \ | 134 double fast_##name(double x) { \ |
| 137 CallOnce(&fast_##name##_init_once, \ | 135 if (fast_##name##_function == NULL) { \ |
| 138 &init_fast_##name##_function); \ | 136 ScopedLock lock(math_function_mutex); \ |
| 137 UnaryMathFunction temp = generator; \ |
| 138 MemoryBarrier(); \ |
| 139 fast_##name##_function = temp; \ |
| 140 } \ |
| 139 return (*fast_##name##_function)(x); \ | 141 return (*fast_##name##_function)(x); \ |
| 140 } | 142 } |
| 141 | 143 |
| 142 UNARY_MATH_FUNCTION(sin, CreateTranscendentalFunction(TranscendentalCache::SIN)) | 144 UNARY_MATH_FUNCTION(sin, CreateTranscendentalFunction(TranscendentalCache::SIN)) |
| 143 UNARY_MATH_FUNCTION(cos, CreateTranscendentalFunction(TranscendentalCache::COS)) | 145 UNARY_MATH_FUNCTION(cos, CreateTranscendentalFunction(TranscendentalCache::COS)) |
| 144 UNARY_MATH_FUNCTION(tan, CreateTranscendentalFunction(TranscendentalCache::TAN)) | 146 UNARY_MATH_FUNCTION(tan, CreateTranscendentalFunction(TranscendentalCache::TAN)) |
| 145 UNARY_MATH_FUNCTION(log, CreateTranscendentalFunction(TranscendentalCache::LOG)) | 147 UNARY_MATH_FUNCTION(log, CreateTranscendentalFunction(TranscendentalCache::LOG)) |
| 146 UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) | 148 UNARY_MATH_FUNCTION(sqrt, CreateSqrtFunction()) |
| 147 | 149 |
| 148 #undef MATH_FUNCTION | 150 #undef MATH_FUNCTION |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 str[str.length() - 1] = '\0'; | 300 str[str.length() - 1] = '\0'; |
| 299 return -1; | 301 return -1; |
| 300 } else { | 302 } else { |
| 301 return n; | 303 return n; |
| 302 } | 304 } |
| 303 } | 305 } |
| 304 | 306 |
| 305 | 307 |
| 306 #if defined(V8_TARGET_ARCH_IA32) | 308 #if defined(V8_TARGET_ARCH_IA32) |
| 307 static OS::MemCopyFunction memcopy_function = NULL; | 309 static OS::MemCopyFunction memcopy_function = NULL; |
| 308 static LazyMutex memcopy_function_mutex = LAZY_MUTEX_INITIALIZER; | 310 static Mutex* memcopy_function_mutex = OS::CreateMutex(); |
| 309 // Defined in codegen-ia32.cc. | 311 // Defined in codegen-ia32.cc. |
| 310 OS::MemCopyFunction CreateMemCopyFunction(); | 312 OS::MemCopyFunction CreateMemCopyFunction(); |
| 311 | 313 |
| 312 // Copy memory area to disjoint memory area. | 314 // Copy memory area to disjoint memory area. |
| 313 void OS::MemCopy(void* dest, const void* src, size_t size) { | 315 void OS::MemCopy(void* dest, const void* src, size_t size) { |
| 314 if (memcopy_function == NULL) { | 316 if (memcopy_function == NULL) { |
| 315 ScopedLock lock(memcopy_function_mutex.Pointer()); | 317 ScopedLock lock(memcopy_function_mutex); |
| 316 if (memcopy_function == NULL) { | 318 if (memcopy_function == NULL) { |
| 317 OS::MemCopyFunction temp = CreateMemCopyFunction(); | 319 OS::MemCopyFunction temp = CreateMemCopyFunction(); |
| 318 MemoryBarrier(); | 320 MemoryBarrier(); |
| 319 memcopy_function = temp; | 321 memcopy_function = temp; |
| 320 } | 322 } |
| 321 } | 323 } |
| 322 // Note: here we rely on dependent reads being ordered. This is true | 324 // Note: here we rely on dependent reads being ordered. This is true |
| 323 // on all architectures we currently support. | 325 // on all architectures we currently support. |
| 324 (*memcopy_function)(dest, src, size); | 326 (*memcopy_function)(dest, src, size); |
| 325 #ifdef DEBUG | 327 #ifdef DEBUG |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 return ntohl(value); | 515 return ntohl(value); |
| 514 } | 516 } |
| 515 | 517 |
| 516 | 518 |
| 517 Socket* OS::CreateSocket() { | 519 Socket* OS::CreateSocket() { |
| 518 return new POSIXSocket(); | 520 return new POSIXSocket(); |
| 519 } | 521 } |
| 520 | 522 |
| 521 | 523 |
| 522 } } // namespace v8::internal | 524 } } // namespace v8::internal |
| OLD | NEW |