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 16 matching lines...) Expand all Loading... |
27 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 27 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
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 "assembler.h" | 35 #include "assembler.h" |
36 | 36 |
37 #include <math.h> // For cos, log, pow, sin, tan, etc. | 37 #include <cmath> |
38 #include "api.h" | 38 #include "api.h" |
39 #include "builtins.h" | 39 #include "builtins.h" |
40 #include "counters.h" | 40 #include "counters.h" |
41 #include "cpu.h" | 41 #include "cpu.h" |
42 #include "debug.h" | 42 #include "debug.h" |
43 #include "deoptimizer.h" | 43 #include "deoptimizer.h" |
44 #include "execution.h" | 44 #include "execution.h" |
45 #include "ic.h" | 45 #include "ic.h" |
46 #include "isolate.h" | 46 #include "isolate.h" |
47 #include "jsregexp.h" | 47 #include "jsregexp.h" |
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 return ExternalReference(entry); | 1452 return ExternalReference(entry); |
1453 } | 1453 } |
1454 | 1454 |
1455 | 1455 |
1456 double power_helper(double x, double y) { | 1456 double power_helper(double x, double y) { |
1457 int y_int = static_cast<int>(y); | 1457 int y_int = static_cast<int>(y); |
1458 if (y == y_int) { | 1458 if (y == y_int) { |
1459 return power_double_int(x, y_int); // Returns 1 if exponent is 0. | 1459 return power_double_int(x, y_int); // Returns 1 if exponent is 0. |
1460 } | 1460 } |
1461 if (y == 0.5) { | 1461 if (y == 0.5) { |
1462 return (isinf(x)) ? V8_INFINITY : fast_sqrt(x + 0.0); // Convert -0 to +0. | 1462 return (std::isinf(x)) ? V8_INFINITY |
| 1463 : fast_sqrt(x + 0.0); // Convert -0 to +0. |
1463 } | 1464 } |
1464 if (y == -0.5) { | 1465 if (y == -0.5) { |
1465 return (isinf(x)) ? 0 : 1.0 / fast_sqrt(x + 0.0); // Convert -0 to +0. | 1466 return (std::isinf(x)) ? 0 : 1.0 / fast_sqrt(x + 0.0); // Convert -0 to +0. |
1466 } | 1467 } |
1467 return power_double_double(x, y); | 1468 return power_double_double(x, y); |
1468 } | 1469 } |
1469 | 1470 |
1470 | 1471 |
1471 // Helper function to compute x^y, where y is known to be an | 1472 // Helper function to compute x^y, where y is known to be an |
1472 // integer. Uses binary decomposition to limit the number of | 1473 // integer. Uses binary decomposition to limit the number of |
1473 // multiplications; see the discussion in "Hacker's Delight" by Henry | 1474 // multiplications; see the discussion in "Hacker's Delight" by Henry |
1474 // S. Warren, Jr., figure 11-6, page 213. | 1475 // S. Warren, Jr., figure 11-6, page 213. |
1475 double power_double_int(double x, int y) { | 1476 double power_double_int(double x, int y) { |
1476 double m = (y < 0) ? 1 / x : x; | 1477 double m = (y < 0) ? 1 / x : x; |
1477 unsigned n = (y < 0) ? -y : y; | 1478 unsigned n = (y < 0) ? -y : y; |
1478 double p = 1; | 1479 double p = 1; |
1479 while (n != 0) { | 1480 while (n != 0) { |
1480 if ((n & 1) != 0) p *= m; | 1481 if ((n & 1) != 0) p *= m; |
1481 m *= m; | 1482 m *= m; |
1482 if ((n & 2) != 0) p *= m; | 1483 if ((n & 2) != 0) p *= m; |
1483 m *= m; | 1484 m *= m; |
1484 n >>= 2; | 1485 n >>= 2; |
1485 } | 1486 } |
1486 return p; | 1487 return p; |
1487 } | 1488 } |
1488 | 1489 |
1489 | 1490 |
1490 double power_double_double(double x, double y) { | 1491 double power_double_double(double x, double y) { |
1491 #if defined(__MINGW64_VERSION_MAJOR) && \ | 1492 #if defined(__MINGW64_VERSION_MAJOR) && \ |
1492 (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1) | 1493 (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1) |
1493 // MinGW64 has a custom implementation for pow. This handles certain | 1494 // MinGW64 has a custom implementation for pow. This handles certain |
1494 // special cases that are different. | 1495 // special cases that are different. |
1495 if ((x == 0.0 || isinf(x)) && isfinite(y)) { | 1496 if ((x == 0.0 || std::isinf(x)) && std::isfinite(y)) { |
1496 double f; | 1497 double f; |
1497 if (modf(y, &f) != 0.0) return ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0; | 1498 if (modf(y, &f) != 0.0) return ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0; |
1498 } | 1499 } |
1499 | 1500 |
1500 if (x == 2.0) { | 1501 if (x == 2.0) { |
1501 int y_int = static_cast<int>(y); | 1502 int y_int = static_cast<int>(y); |
1502 if (y == y_int) return ldexp(1.0, y_int); | 1503 if (y == y_int) return ldexp(1.0, y_int); |
1503 } | 1504 } |
1504 #endif | 1505 #endif |
1505 | 1506 |
1506 // The checks for special cases can be dropped in ia32 because it has already | 1507 // The checks for special cases can be dropped in ia32 because it has already |
1507 // been done in generated code before bailing out here. | 1508 // been done in generated code before bailing out here. |
1508 if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) return OS::nan_value(); | 1509 if (std::isnan(y) || ((x == 1 || x == -1) && std::isinf(y))) { |
| 1510 return OS::nan_value(); |
| 1511 } |
1509 return pow(x, y); | 1512 return pow(x, y); |
1510 } | 1513 } |
1511 | 1514 |
1512 | 1515 |
1513 ExternalReference ExternalReference::power_double_double_function( | 1516 ExternalReference ExternalReference::power_double_double_function( |
1514 Isolate* isolate) { | 1517 Isolate* isolate) { |
1515 return ExternalReference(Redirect(isolate, | 1518 return ExternalReference(Redirect(isolate, |
1516 FUNCTION_ADDR(power_double_double), | 1519 FUNCTION_ADDR(power_double_double), |
1517 BUILTIN_FP_FP_CALL)); | 1520 BUILTIN_FP_FP_CALL)); |
1518 } | 1521 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position); | 1655 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position); |
1653 state_.written_position = state_.current_position; | 1656 state_.written_position = state_.current_position; |
1654 written = true; | 1657 written = true; |
1655 } | 1658 } |
1656 | 1659 |
1657 // Return whether something was written. | 1660 // Return whether something was written. |
1658 return written; | 1661 return written; |
1659 } | 1662 } |
1660 | 1663 |
1661 } } // namespace v8::internal | 1664 } } // namespace v8::internal |
OLD | NEW |