OLD | NEW |
1 // Copyright (c) 1994-2006 Sun Microsystems Inc. | 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. |
2 // All Rights Reserved. | 2 // All Rights Reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // - Redistributions of source code must retain the above copyright notice, | 8 // - Redistributions of source code must retain the above copyright notice, |
9 // this list of conditions and the following disclaimer. | 9 // this list of conditions and the following disclaimer. |
10 // | 10 // |
(...skipping 17 matching lines...) Expand all Loading... |
28 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 28 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 // The original source code covered by the above license above has been | 31 // The original source code covered by the above license above has been |
32 // modified significantly by Google Inc. | 32 // modified significantly by Google Inc. |
33 // Copyright 2012 the V8 project authors. All rights reserved. | 33 // Copyright 2012 the V8 project authors. All rights reserved. |
34 | 34 |
35 #include "src/assembler.h" | 35 #include "src/assembler.h" |
36 | 36 |
37 #include <cmath> | 37 #include <cmath> |
| 38 #include <limits> |
| 39 |
38 #include "src/api.h" | 40 #include "src/api.h" |
39 #include "src/base/cpu.h" | 41 #include "src/base/cpu.h" |
40 #include "src/base/functional.h" | 42 #include "src/base/functional.h" |
41 #include "src/base/lazy-instance.h" | 43 #include "src/base/lazy-instance.h" |
42 #include "src/base/platform/platform.h" | 44 #include "src/base/platform/platform.h" |
43 #include "src/builtins.h" | 45 #include "src/builtins.h" |
44 #include "src/codegen.h" | 46 #include "src/codegen.h" |
45 #include "src/counters.h" | 47 #include "src/counters.h" |
46 #include "src/cpu-profiler.h" | 48 #include "src/cpu-profiler.h" |
47 #include "src/debug.h" | 49 #include "src/debug.h" |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 | 881 |
880 // ----------------------------------------------------------------------------- | 882 // ----------------------------------------------------------------------------- |
881 // Implementation of ExternalReference | 883 // Implementation of ExternalReference |
882 | 884 |
883 void ExternalReference::SetUp() { | 885 void ExternalReference::SetUp() { |
884 double_constants.min_int = kMinInt; | 886 double_constants.min_int = kMinInt; |
885 double_constants.one_half = 0.5; | 887 double_constants.one_half = 0.5; |
886 double_constants.minus_one_half = -0.5; | 888 double_constants.minus_one_half = -0.5; |
887 double_constants.canonical_non_hole_nan = base::OS::nan_value(); | 889 double_constants.canonical_non_hole_nan = base::OS::nan_value(); |
888 double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64); | 890 double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64); |
889 double_constants.negative_infinity = -V8_INFINITY; | 891 double_constants.negative_infinity = -std::numeric_limits<double>::infinity(); |
890 double_constants.uint32_bias = | 892 double_constants.uint32_bias = |
891 static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1; | 893 static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1; |
892 | 894 |
893 math_exp_data_mutex = new base::Mutex(); | 895 math_exp_data_mutex = new base::Mutex(); |
894 } | 896 } |
895 | 897 |
896 | 898 |
897 void ExternalReference::InitializeMathExpData() { | 899 void ExternalReference::InitializeMathExpData() { |
898 // Early return? | 900 // Early return? |
899 if (math_exp_data_initialized) return; | 901 if (math_exp_data_initialized) return; |
900 | 902 |
901 base::LockGuard<base::Mutex> lock_guard(math_exp_data_mutex); | 903 base::LockGuard<base::Mutex> lock_guard(math_exp_data_mutex); |
902 if (!math_exp_data_initialized) { | 904 if (!math_exp_data_initialized) { |
903 // If this is changed, generated code must be adapted too. | 905 // If this is changed, generated code must be adapted too. |
904 const int kTableSizeBits = 11; | 906 const int kTableSizeBits = 11; |
905 const int kTableSize = 1 << kTableSizeBits; | 907 const int kTableSize = 1 << kTableSizeBits; |
906 const double kTableSizeDouble = static_cast<double>(kTableSize); | 908 const double kTableSizeDouble = static_cast<double>(kTableSize); |
907 | 909 |
908 math_exp_constants_array = new double[9]; | 910 math_exp_constants_array = new double[9]; |
909 // Input values smaller than this always return 0. | 911 // Input values smaller than this always return 0. |
910 math_exp_constants_array[0] = -708.39641853226408; | 912 math_exp_constants_array[0] = -708.39641853226408; |
911 // Input values larger than this always return +Infinity. | 913 // Input values larger than this always return +Infinity. |
912 math_exp_constants_array[1] = 709.78271289338397; | 914 math_exp_constants_array[1] = 709.78271289338397; |
913 math_exp_constants_array[2] = V8_INFINITY; | 915 math_exp_constants_array[2] = std::numeric_limits<double>::infinity(); |
914 // The rest is black magic. Do not attempt to understand it. It is | 916 // The rest is black magic. Do not attempt to understand it. It is |
915 // loosely based on the "expd" function published at: | 917 // loosely based on the "expd" function published at: |
916 // http://herumi.blogspot.com/2011/08/fast-double-precision-exponential.html | 918 // http://herumi.blogspot.com/2011/08/fast-double-precision-exponential.html |
917 const double constant3 = (1 << kTableSizeBits) / std::log(2.0); | 919 const double constant3 = (1 << kTableSizeBits) / std::log(2.0); |
918 math_exp_constants_array[3] = constant3; | 920 math_exp_constants_array[3] = constant3; |
919 math_exp_constants_array[4] = | 921 math_exp_constants_array[4] = |
920 static_cast<double>(static_cast<int64_t>(3) << 51); | 922 static_cast<double>(static_cast<int64_t>(3) << 51); |
921 math_exp_constants_array[5] = 1 / constant3; | 923 math_exp_constants_array[5] = 1 / constant3; |
922 math_exp_constants_array[6] = 3.0000000027955394; | 924 math_exp_constants_array[6] = 3.0000000027955394; |
923 math_exp_constants_array[7] = 0.16666666685227835; | 925 math_exp_constants_array[7] = 0.16666666685227835; |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 isolate->debug()->restarter_frame_function_pointer_address()); | 1408 isolate->debug()->restarter_frame_function_pointer_address()); |
1407 } | 1409 } |
1408 | 1410 |
1409 | 1411 |
1410 double power_helper(double x, double y) { | 1412 double power_helper(double x, double y) { |
1411 int y_int = static_cast<int>(y); | 1413 int y_int = static_cast<int>(y); |
1412 if (y == y_int) { | 1414 if (y == y_int) { |
1413 return power_double_int(x, y_int); // Returns 1 if exponent is 0. | 1415 return power_double_int(x, y_int); // Returns 1 if exponent is 0. |
1414 } | 1416 } |
1415 if (y == 0.5) { | 1417 if (y == 0.5) { |
1416 return (std::isinf(x)) ? V8_INFINITY | 1418 return (std::isinf(x)) ? std::numeric_limits<double>::infinity() |
1417 : fast_sqrt(x + 0.0); // Convert -0 to +0. | 1419 : fast_sqrt(x + 0.0); // Convert -0 to +0. |
1418 } | 1420 } |
1419 if (y == -0.5) { | 1421 if (y == -0.5) { |
1420 return (std::isinf(x)) ? 0 : 1.0 / fast_sqrt(x + 0.0); // Convert -0 to +0. | 1422 return (std::isinf(x)) ? 0 : 1.0 / fast_sqrt(x + 0.0); // Convert -0 to +0. |
1421 } | 1423 } |
1422 return power_double_double(x, y); | 1424 return power_double_double(x, y); |
1423 } | 1425 } |
1424 | 1426 |
1425 | 1427 |
1426 // Helper function to compute x^y, where y is known to be an | 1428 // Helper function to compute x^y, where y is known to be an |
(...skipping 16 matching lines...) Expand all Loading... |
1443 | 1445 |
1444 | 1446 |
1445 double power_double_double(double x, double y) { | 1447 double power_double_double(double x, double y) { |
1446 #if defined(__MINGW64_VERSION_MAJOR) && \ | 1448 #if defined(__MINGW64_VERSION_MAJOR) && \ |
1447 (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1) | 1449 (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1) |
1448 // MinGW64 has a custom implementation for pow. This handles certain | 1450 // MinGW64 has a custom implementation for pow. This handles certain |
1449 // special cases that are different. | 1451 // special cases that are different. |
1450 if ((x == 0.0 || std::isinf(x)) && std::isfinite(y)) { | 1452 if ((x == 0.0 || std::isinf(x)) && std::isfinite(y)) { |
1451 double f; | 1453 double f; |
1452 if (std::modf(y, &f) != 0.0) { | 1454 if (std::modf(y, &f) != 0.0) { |
1453 return ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0; | 1455 return ((x == 0.0) ^ (y > 0)) ? std::numeric_limits<double>::infinity() |
| 1456 : 0.0; |
1454 } | 1457 } |
1455 } | 1458 } |
1456 | 1459 |
1457 if (x == 2.0) { | 1460 if (x == 2.0) { |
1458 int y_int = static_cast<int>(y); | 1461 int y_int = static_cast<int>(y); |
1459 if (y == y_int) { | 1462 if (y == y_int) { |
1460 return std::ldexp(1.0, y_int); | 1463 return std::ldexp(1.0, y_int); |
1461 } | 1464 } |
1462 } | 1465 } |
1463 #endif | 1466 #endif |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position); | 1593 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position); |
1591 state_.written_position = state_.current_position; | 1594 state_.written_position = state_.current_position; |
1592 written = true; | 1595 written = true; |
1593 } | 1596 } |
1594 | 1597 |
1595 // Return whether something was written. | 1598 // Return whether something was written. |
1596 return written; | 1599 return written; |
1597 } | 1600 } |
1598 | 1601 |
1599 } } // namespace v8::internal | 1602 } } // namespace v8::internal |
OLD | NEW |