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 #include "src/codegen.h" | 5 #include "src/codegen.h" |
6 | 6 |
7 #if defined(V8_OS_AIX) | 7 #if defined(V8_OS_AIX) |
8 #include <fenv.h> // NOLINT(build/c++11) | 8 #include <fenv.h> // NOLINT(build/c++11) |
9 #endif | 9 #endif |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
11 #include "src/compiler.h" | 11 #include "src/compiler.h" |
12 #include "src/debug/debug.h" | 12 #include "src/debug/debug.h" |
13 #include "src/parser.h" | 13 #include "src/parser.h" |
14 #include "src/prettyprinter.h" | 14 #include "src/prettyprinter.h" |
15 #include "src/profiler/cpu-profiler.h" | 15 #include "src/profiler/cpu-profiler.h" |
16 #include "src/rewriter.h" | 16 #include "src/rewriter.h" |
17 #include "src/runtime/runtime.h" | 17 #include "src/runtime/runtime.h" |
18 | 18 |
19 namespace v8 { | 19 namespace v8 { |
20 namespace internal { | 20 namespace internal { |
21 | 21 |
22 | 22 |
23 #if defined(_WIN64) | 23 #if defined(V8_OS_WIN) |
24 typedef double (*ModuloFunction)(double, double); | |
25 static ModuloFunction modulo_function = NULL; | |
26 // Defined in codegen-x64.cc. | |
27 ModuloFunction CreateModuloFunction(); | |
28 | |
29 void init_modulo_function() { | |
30 modulo_function = CreateModuloFunction(); | |
31 } | |
32 | |
33 | |
34 double modulo(double x, double y) { | |
35 // Note: here we rely on dependent reads being ordered. This is true | |
36 // on all architectures we currently support. | |
37 return (*modulo_function)(x, y); | |
38 } | |
39 #elif defined(_WIN32) | |
40 | |
41 double modulo(double x, double y) { | 24 double modulo(double x, double y) { |
42 // Workaround MS fmod bugs. ECMA-262 says: | 25 // Workaround MS fmod bugs. ECMA-262 says: |
43 // dividend is finite and divisor is an infinity => result equals dividend | 26 // dividend is finite and divisor is an infinity => result equals dividend |
44 // dividend is a zero and divisor is nonzero finite => result equals dividend | 27 // dividend is a zero and divisor is nonzero finite => result equals dividend |
45 if (!(std::isfinite(x) && (!std::isfinite(y) && !std::isnan(y))) && | 28 if (!(std::isfinite(x) && (!std::isfinite(y) && !std::isnan(y))) && |
46 !(x == 0 && (y != 0 && std::isfinite(y)))) { | 29 !(x == 0 && (y != 0 && std::isfinite(y)))) { |
47 x = fmod(x, y); | 30 x = fmod(x, y); |
48 } | 31 } |
49 return x; | 32 return x; |
50 } | 33 } |
51 #else // POSIX | 34 #else // POSIX |
52 | 35 |
53 double modulo(double x, double y) { | 36 double modulo(double x, double y) { |
54 #if defined(V8_OS_AIX) | 37 #if defined(V8_OS_AIX) |
55 // AIX raises an underflow exception for (Number.MIN_VALUE % Number.MAX_VALUE) | 38 // AIX raises an underflow exception for (Number.MIN_VALUE % Number.MAX_VALUE) |
56 feclearexcept(FE_ALL_EXCEPT); | 39 feclearexcept(FE_ALL_EXCEPT); |
57 double result = std::fmod(x, y); | 40 double result = std::fmod(x, y); |
58 int exception = fetestexcept(FE_UNDERFLOW); | 41 int exception = fetestexcept(FE_UNDERFLOW); |
59 return (exception ? x : result); | 42 return (exception ? x : result); |
60 #else | 43 #else |
61 return std::fmod(x, y); | 44 return std::fmod(x, y); |
62 #endif | 45 #endif |
63 } | 46 } |
64 #endif // defined(_WIN64) | 47 #endif // defined(V8_OS_WIN) |
65 | 48 |
66 | 49 |
67 #define UNARY_MATH_FUNCTION(name, generator) \ | 50 #define UNARY_MATH_FUNCTION(name, generator) \ |
68 static UnaryMathFunctionWithIsolate fast_##name##_function = nullptr; \ | 51 static UnaryMathFunctionWithIsolate fast_##name##_function = nullptr; \ |
69 double std_##name(double x, Isolate* isolate) { return std::name(x); } \ | 52 double std_##name(double x, Isolate* isolate) { return std::name(x); } \ |
70 void init_fast_##name##_function(Isolate* isolate) { \ | 53 void init_fast_##name##_function(Isolate* isolate) { \ |
71 if (FLAG_fast_math) fast_##name##_function = generator(isolate); \ | 54 if (FLAG_fast_math) fast_##name##_function = generator(isolate); \ |
72 if (!fast_##name##_function) fast_##name##_function = std_##name; \ | 55 if (!fast_##name##_function) fast_##name##_function = std_##name; \ |
73 } \ | 56 } \ |
74 void lazily_initialize_fast_##name(Isolate* isolate) { \ | 57 void lazily_initialize_fast_##name(Isolate* isolate) { \ |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 os << "source_position = " << literal->start_position() << "\n"; | 205 os << "source_position = " << literal->start_position() << "\n"; |
223 } | 206 } |
224 code->Disassemble(debug_name.get(), os); | 207 code->Disassemble(debug_name.get(), os); |
225 os << "--- End code ---\n"; | 208 os << "--- End code ---\n"; |
226 } | 209 } |
227 #endif // ENABLE_DISASSEMBLER | 210 #endif // ENABLE_DISASSEMBLER |
228 } | 211 } |
229 | 212 |
230 } // namespace internal | 213 } // namespace internal |
231 } // namespace v8 | 214 } // namespace v8 |
OLD | NEW |