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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 double minus_one_half; | 171 double minus_one_half; |
172 double negative_infinity; | 172 double negative_infinity; |
173 double the_hole_nan; | 173 double the_hole_nan; |
174 double uint32_bias; | 174 double uint32_bias; |
175 }; | 175 }; |
176 | 176 |
177 static DoubleConstant double_constants; | 177 static DoubleConstant double_constants; |
178 | 178 |
179 const char* const RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING"; | 179 const char* const RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING"; |
180 | 180 |
| 181 static bool math_exp_data_initialized = false; |
| 182 static base::Mutex* math_exp_data_mutex = NULL; |
| 183 static double* math_exp_constants_array = NULL; |
| 184 static double* math_exp_log_table_array = NULL; |
| 185 |
181 // ----------------------------------------------------------------------------- | 186 // ----------------------------------------------------------------------------- |
182 // Implementation of AssemblerBase | 187 // Implementation of AssemblerBase |
183 | 188 |
184 AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size) | 189 AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size) |
185 : isolate_(isolate), | 190 : isolate_(isolate), |
186 jit_cookie_(0), | 191 jit_cookie_(0), |
187 enabled_cpu_features_(0), | 192 enabled_cpu_features_(0), |
188 emit_debug_code_(FLAG_debug_code), | 193 emit_debug_code_(FLAG_debug_code), |
189 predictable_code_size_(false), | 194 predictable_code_size_(false), |
190 // We may use the assembler without an isolate. | 195 // We may use the assembler without an isolate. |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 | 999 |
995 | 1000 |
996 void ExternalReference::SetUp() { | 1001 void ExternalReference::SetUp() { |
997 double_constants.min_int = kMinInt; | 1002 double_constants.min_int = kMinInt; |
998 double_constants.one_half = 0.5; | 1003 double_constants.one_half = 0.5; |
999 double_constants.minus_one_half = -0.5; | 1004 double_constants.minus_one_half = -0.5; |
1000 double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64); | 1005 double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64); |
1001 double_constants.negative_infinity = -V8_INFINITY; | 1006 double_constants.negative_infinity = -V8_INFINITY; |
1002 double_constants.uint32_bias = | 1007 double_constants.uint32_bias = |
1003 static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1; | 1008 static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1; |
| 1009 |
| 1010 math_exp_data_mutex = new base::Mutex(); |
1004 } | 1011 } |
1005 | 1012 |
1006 | 1013 |
| 1014 void ExternalReference::InitializeMathExpData() { |
| 1015 // Early return? |
| 1016 if (math_exp_data_initialized) return; |
| 1017 |
| 1018 base::LockGuard<base::Mutex> lock_guard(math_exp_data_mutex); |
| 1019 if (!math_exp_data_initialized) { |
| 1020 // If this is changed, generated code must be adapted too. |
| 1021 const int kTableSizeBits = 11; |
| 1022 const int kTableSize = 1 << kTableSizeBits; |
| 1023 const double kTableSizeDouble = static_cast<double>(kTableSize); |
| 1024 |
| 1025 math_exp_constants_array = new double[9]; |
| 1026 // Input values smaller than this always return 0. |
| 1027 math_exp_constants_array[0] = -708.39641853226408; |
| 1028 // Input values larger than this always return +Infinity. |
| 1029 math_exp_constants_array[1] = 709.78271289338397; |
| 1030 math_exp_constants_array[2] = V8_INFINITY; |
| 1031 // The rest is black magic. Do not attempt to understand it. It is |
| 1032 // loosely based on the "expd" function published at: |
| 1033 // http://herumi.blogspot.com/2011/08/fast-double-precision-exponential.html |
| 1034 const double constant3 = (1 << kTableSizeBits) / base::ieee754::log(2.0); |
| 1035 math_exp_constants_array[3] = constant3; |
| 1036 math_exp_constants_array[4] = |
| 1037 static_cast<double>(static_cast<int64_t>(3) << 51); |
| 1038 math_exp_constants_array[5] = 1 / constant3; |
| 1039 math_exp_constants_array[6] = 3.0000000027955394; |
| 1040 math_exp_constants_array[7] = 0.16666666685227835; |
| 1041 math_exp_constants_array[8] = 1; |
| 1042 |
| 1043 math_exp_log_table_array = new double[kTableSize]; |
| 1044 for (int i = 0; i < kTableSize; i++) { |
| 1045 double value = std::pow(2, i / kTableSizeDouble); |
| 1046 uint64_t bits = bit_cast<uint64_t, double>(value); |
| 1047 bits &= (static_cast<uint64_t>(1) << 52) - 1; |
| 1048 double mantissa = bit_cast<double, uint64_t>(bits); |
| 1049 math_exp_log_table_array[i] = mantissa; |
| 1050 } |
| 1051 |
| 1052 math_exp_data_initialized = true; |
| 1053 } |
| 1054 } |
| 1055 |
| 1056 |
| 1057 void ExternalReference::TearDownMathExpData() { |
| 1058 delete[] math_exp_constants_array; |
| 1059 math_exp_constants_array = NULL; |
| 1060 delete[] math_exp_log_table_array; |
| 1061 math_exp_log_table_array = NULL; |
| 1062 delete math_exp_data_mutex; |
| 1063 math_exp_data_mutex = NULL; |
| 1064 } |
| 1065 |
| 1066 |
1007 ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate) | 1067 ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate) |
1008 : address_(Redirect(isolate, Builtins::c_function_address(id))) {} | 1068 : address_(Redirect(isolate, Builtins::c_function_address(id))) {} |
1009 | 1069 |
1010 | 1070 |
1011 ExternalReference::ExternalReference( | 1071 ExternalReference::ExternalReference( |
1012 ApiFunction* fun, | 1072 ApiFunction* fun, |
1013 Type type = ExternalReference::BUILTIN_CALL, | 1073 Type type = ExternalReference::BUILTIN_CALL, |
1014 Isolate* isolate = NULL) | 1074 Isolate* isolate = NULL) |
1015 : address_(Redirect(isolate, fun->address(), type)) {} | 1075 : address_(Redirect(isolate, fun->address(), type)) {} |
1016 | 1076 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 static void f64_tan_wrapper(double* param) { | 1346 static void f64_tan_wrapper(double* param) { |
1287 WriteDoubleValue(param, std::tan(ReadDoubleValue(param))); | 1347 WriteDoubleValue(param, std::tan(ReadDoubleValue(param))); |
1288 } | 1348 } |
1289 | 1349 |
1290 ExternalReference ExternalReference::f64_tan_wrapper_function( | 1350 ExternalReference ExternalReference::f64_tan_wrapper_function( |
1291 Isolate* isolate) { | 1351 Isolate* isolate) { |
1292 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_tan_wrapper))); | 1352 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_tan_wrapper))); |
1293 } | 1353 } |
1294 | 1354 |
1295 static void f64_exp_wrapper(double* param) { | 1355 static void f64_exp_wrapper(double* param) { |
1296 WriteDoubleValue(param, base::ieee754::exp(ReadDoubleValue(param))); | 1356 WriteDoubleValue(param, std::exp(ReadDoubleValue(param))); |
1297 } | 1357 } |
1298 | 1358 |
1299 ExternalReference ExternalReference::f64_exp_wrapper_function( | 1359 ExternalReference ExternalReference::f64_exp_wrapper_function( |
1300 Isolate* isolate) { | 1360 Isolate* isolate) { |
1301 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_exp_wrapper))); | 1361 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_exp_wrapper))); |
1302 } | 1362 } |
1303 | 1363 |
1304 static void f64_pow_wrapper(double* param0, double* param1) { | 1364 static void f64_pow_wrapper(double* param0, double* param1) { |
1305 WriteDoubleValue(param0, power_double_double(ReadDoubleValue(param0), | 1365 WriteDoubleValue(param0, power_double_double(ReadDoubleValue(param0), |
1306 ReadDoubleValue(param1))); | 1366 ReadDoubleValue(param1))); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1561 ExternalReference ExternalReference::ieee754_atan_function(Isolate* isolate) { | 1621 ExternalReference ExternalReference::ieee754_atan_function(Isolate* isolate) { |
1562 return ExternalReference( | 1622 return ExternalReference( |
1563 Redirect(isolate, FUNCTION_ADDR(base::ieee754::atan), BUILTIN_FP_CALL)); | 1623 Redirect(isolate, FUNCTION_ADDR(base::ieee754::atan), BUILTIN_FP_CALL)); |
1564 } | 1624 } |
1565 | 1625 |
1566 ExternalReference ExternalReference::ieee754_atan2_function(Isolate* isolate) { | 1626 ExternalReference ExternalReference::ieee754_atan2_function(Isolate* isolate) { |
1567 return ExternalReference(Redirect( | 1627 return ExternalReference(Redirect( |
1568 isolate, FUNCTION_ADDR(base::ieee754::atan2), BUILTIN_FP_FP_CALL)); | 1628 isolate, FUNCTION_ADDR(base::ieee754::atan2), BUILTIN_FP_FP_CALL)); |
1569 } | 1629 } |
1570 | 1630 |
1571 ExternalReference ExternalReference::ieee754_exp_function(Isolate* isolate) { | |
1572 return ExternalReference( | |
1573 Redirect(isolate, FUNCTION_ADDR(base::ieee754::exp), BUILTIN_FP_CALL)); | |
1574 } | |
1575 | |
1576 ExternalReference ExternalReference::ieee754_log_function(Isolate* isolate) { | 1631 ExternalReference ExternalReference::ieee754_log_function(Isolate* isolate) { |
1577 return ExternalReference( | 1632 return ExternalReference( |
1578 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log), BUILTIN_FP_CALL)); | 1633 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log), BUILTIN_FP_CALL)); |
1579 } | 1634 } |
1580 | 1635 |
1581 ExternalReference ExternalReference::ieee754_log1p_function(Isolate* isolate) { | 1636 ExternalReference ExternalReference::ieee754_log1p_function(Isolate* isolate) { |
1582 return ExternalReference( | 1637 return ExternalReference( |
1583 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log1p), BUILTIN_FP_CALL)); | 1638 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log1p), BUILTIN_FP_CALL)); |
1584 } | 1639 } |
1585 | 1640 |
1586 ExternalReference ExternalReference::ieee754_log2_function(Isolate* isolate) { | 1641 ExternalReference ExternalReference::ieee754_log2_function(Isolate* isolate) { |
1587 return ExternalReference( | 1642 return ExternalReference( |
1588 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log2), BUILTIN_FP_CALL)); | 1643 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log2), BUILTIN_FP_CALL)); |
1589 } | 1644 } |
1590 | 1645 |
1591 ExternalReference ExternalReference::ieee754_log10_function(Isolate* isolate) { | 1646 ExternalReference ExternalReference::ieee754_log10_function(Isolate* isolate) { |
1592 return ExternalReference( | 1647 return ExternalReference( |
1593 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log10), BUILTIN_FP_CALL)); | 1648 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log10), BUILTIN_FP_CALL)); |
1594 } | 1649 } |
1595 | 1650 |
| 1651 ExternalReference ExternalReference::math_exp_constants(int constant_index) { |
| 1652 DCHECK(math_exp_data_initialized); |
| 1653 return ExternalReference( |
| 1654 reinterpret_cast<void*>(math_exp_constants_array + constant_index)); |
| 1655 } |
| 1656 |
| 1657 |
| 1658 ExternalReference ExternalReference::math_exp_log_table() { |
| 1659 DCHECK(math_exp_data_initialized); |
| 1660 return ExternalReference(reinterpret_cast<void*>(math_exp_log_table_array)); |
| 1661 } |
| 1662 |
| 1663 |
1596 ExternalReference ExternalReference::page_flags(Page* page) { | 1664 ExternalReference ExternalReference::page_flags(Page* page) { |
1597 return ExternalReference(reinterpret_cast<Address>(page) + | 1665 return ExternalReference(reinterpret_cast<Address>(page) + |
1598 MemoryChunk::kFlagsOffset); | 1666 MemoryChunk::kFlagsOffset); |
1599 } | 1667 } |
1600 | 1668 |
1601 | 1669 |
1602 ExternalReference ExternalReference::ForDeoptEntry(Address entry) { | 1670 ExternalReference ExternalReference::ForDeoptEntry(Address entry) { |
1603 return ExternalReference(entry); | 1671 return ExternalReference(entry); |
1604 } | 1672 } |
1605 | 1673 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 | 2106 |
2039 | 2107 |
2040 void Assembler::DataAlign(int m) { | 2108 void Assembler::DataAlign(int m) { |
2041 DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m)); | 2109 DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m)); |
2042 while ((pc_offset() & (m - 1)) != 0) { | 2110 while ((pc_offset() & (m - 1)) != 0) { |
2043 db(0); | 2111 db(0); |
2044 } | 2112 } |
2045 } | 2113 } |
2046 } // namespace internal | 2114 } // namespace internal |
2047 } // namespace v8 | 2115 } // namespace v8 |
OLD | NEW |