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