Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: src/assembler.cc

Issue 2077533002: [builtins] Introduce proper Float64Exp operator. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: REBASE. Import tests from Raymond. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
186 // ----------------------------------------------------------------------------- 181 // -----------------------------------------------------------------------------
187 // Implementation of AssemblerBase 182 // Implementation of AssemblerBase
188 183
189 AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size) 184 AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size)
190 : isolate_(isolate), 185 : isolate_(isolate),
191 jit_cookie_(0), 186 jit_cookie_(0),
192 enabled_cpu_features_(0), 187 enabled_cpu_features_(0),
193 emit_debug_code_(FLAG_debug_code), 188 emit_debug_code_(FLAG_debug_code),
194 predictable_code_size_(false), 189 predictable_code_size_(false),
195 // We may use the assembler without an isolate. 190 // We may use the assembler without an isolate.
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 994
1000 995
1001 void ExternalReference::SetUp() { 996 void ExternalReference::SetUp() {
1002 double_constants.min_int = kMinInt; 997 double_constants.min_int = kMinInt;
1003 double_constants.one_half = 0.5; 998 double_constants.one_half = 0.5;
1004 double_constants.minus_one_half = -0.5; 999 double_constants.minus_one_half = -0.5;
1005 double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64); 1000 double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64);
1006 double_constants.negative_infinity = -V8_INFINITY; 1001 double_constants.negative_infinity = -V8_INFINITY;
1007 double_constants.uint32_bias = 1002 double_constants.uint32_bias =
1008 static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1; 1003 static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1;
1009
1010 math_exp_data_mutex = new base::Mutex();
1011 } 1004 }
1012 1005
1013 1006
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
1067 ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate) 1007 ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate)
1068 : address_(Redirect(isolate, Builtins::c_function_address(id))) {} 1008 : address_(Redirect(isolate, Builtins::c_function_address(id))) {}
1069 1009
1070 1010
1071 ExternalReference::ExternalReference( 1011 ExternalReference::ExternalReference(
1072 ApiFunction* fun, 1012 ApiFunction* fun,
1073 Type type = ExternalReference::BUILTIN_CALL, 1013 Type type = ExternalReference::BUILTIN_CALL,
1074 Isolate* isolate = NULL) 1014 Isolate* isolate = NULL)
1075 : address_(Redirect(isolate, fun->address(), type)) {} 1015 : address_(Redirect(isolate, fun->address(), type)) {}
1076 1016
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 static void f64_tan_wrapper(double* param) { 1286 static void f64_tan_wrapper(double* param) {
1347 WriteDoubleValue(param, std::tan(ReadDoubleValue(param))); 1287 WriteDoubleValue(param, std::tan(ReadDoubleValue(param)));
1348 } 1288 }
1349 1289
1350 ExternalReference ExternalReference::f64_tan_wrapper_function( 1290 ExternalReference ExternalReference::f64_tan_wrapper_function(
1351 Isolate* isolate) { 1291 Isolate* isolate) {
1352 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_tan_wrapper))); 1292 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_tan_wrapper)));
1353 } 1293 }
1354 1294
1355 static void f64_exp_wrapper(double* param) { 1295 static void f64_exp_wrapper(double* param) {
1356 WriteDoubleValue(param, std::exp(ReadDoubleValue(param))); 1296 WriteDoubleValue(param, base::ieee754::exp(ReadDoubleValue(param)));
1357 } 1297 }
1358 1298
1359 ExternalReference ExternalReference::f64_exp_wrapper_function( 1299 ExternalReference ExternalReference::f64_exp_wrapper_function(
1360 Isolate* isolate) { 1300 Isolate* isolate) {
1361 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_exp_wrapper))); 1301 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_exp_wrapper)));
1362 } 1302 }
1363 1303
1364 static void f64_pow_wrapper(double* param0, double* param1) { 1304 static void f64_pow_wrapper(double* param0, double* param1) {
1365 WriteDoubleValue(param0, power_double_double(ReadDoubleValue(param0), 1305 WriteDoubleValue(param0, power_double_double(ReadDoubleValue(param0),
1366 ReadDoubleValue(param1))); 1306 ReadDoubleValue(param1)));
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 ExternalReference ExternalReference::ieee754_atan_function(Isolate* isolate) { 1561 ExternalReference ExternalReference::ieee754_atan_function(Isolate* isolate) {
1622 return ExternalReference( 1562 return ExternalReference(
1623 Redirect(isolate, FUNCTION_ADDR(base::ieee754::atan), BUILTIN_FP_CALL)); 1563 Redirect(isolate, FUNCTION_ADDR(base::ieee754::atan), BUILTIN_FP_CALL));
1624 } 1564 }
1625 1565
1626 ExternalReference ExternalReference::ieee754_atan2_function(Isolate* isolate) { 1566 ExternalReference ExternalReference::ieee754_atan2_function(Isolate* isolate) {
1627 return ExternalReference(Redirect( 1567 return ExternalReference(Redirect(
1628 isolate, FUNCTION_ADDR(base::ieee754::atan2), BUILTIN_FP_FP_CALL)); 1568 isolate, FUNCTION_ADDR(base::ieee754::atan2), BUILTIN_FP_FP_CALL));
1629 } 1569 }
1630 1570
1571 ExternalReference ExternalReference::ieee754_exp_function(Isolate* isolate) {
1572 return ExternalReference(
1573 Redirect(isolate, FUNCTION_ADDR(base::ieee754::exp), BUILTIN_FP_CALL));
1574 }
1575
1631 ExternalReference ExternalReference::ieee754_log_function(Isolate* isolate) { 1576 ExternalReference ExternalReference::ieee754_log_function(Isolate* isolate) {
1632 return ExternalReference( 1577 return ExternalReference(
1633 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log), BUILTIN_FP_CALL)); 1578 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log), BUILTIN_FP_CALL));
1634 } 1579 }
1635 1580
1636 ExternalReference ExternalReference::ieee754_log1p_function(Isolate* isolate) { 1581 ExternalReference ExternalReference::ieee754_log1p_function(Isolate* isolate) {
1637 return ExternalReference( 1582 return ExternalReference(
1638 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log1p), BUILTIN_FP_CALL)); 1583 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log1p), BUILTIN_FP_CALL));
1639 } 1584 }
1640 1585
1641 ExternalReference ExternalReference::ieee754_log2_function(Isolate* isolate) { 1586 ExternalReference ExternalReference::ieee754_log2_function(Isolate* isolate) {
1642 return ExternalReference( 1587 return ExternalReference(
1643 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log2), BUILTIN_FP_CALL)); 1588 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log2), BUILTIN_FP_CALL));
1644 } 1589 }
1645 1590
1646 ExternalReference ExternalReference::ieee754_log10_function(Isolate* isolate) { 1591 ExternalReference ExternalReference::ieee754_log10_function(Isolate* isolate) {
1647 return ExternalReference( 1592 return ExternalReference(
1648 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log10), BUILTIN_FP_CALL)); 1593 Redirect(isolate, FUNCTION_ADDR(base::ieee754::log10), BUILTIN_FP_CALL));
1649 } 1594 }
1650 1595
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
1664 ExternalReference ExternalReference::page_flags(Page* page) { 1596 ExternalReference ExternalReference::page_flags(Page* page) {
1665 return ExternalReference(reinterpret_cast<Address>(page) + 1597 return ExternalReference(reinterpret_cast<Address>(page) +
1666 MemoryChunk::kFlagsOffset); 1598 MemoryChunk::kFlagsOffset);
1667 } 1599 }
1668 1600
1669 1601
1670 ExternalReference ExternalReference::ForDeoptEntry(Address entry) { 1602 ExternalReference ExternalReference::ForDeoptEntry(Address entry) {
1671 return ExternalReference(entry); 1603 return ExternalReference(entry);
1672 } 1604 }
1673 1605
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 2038
2107 2039
2108 void Assembler::DataAlign(int m) { 2040 void Assembler::DataAlign(int m) {
2109 DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m)); 2041 DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m));
2110 while ((pc_offset() & (m - 1)) != 0) { 2042 while ((pc_offset() & (m - 1)) != 0) {
2111 db(0); 2043 db(0);
2112 } 2044 }
2113 } 2045 }
2114 } // namespace internal 2046 } // namespace internal
2115 } // namespace v8 2047 } // namespace v8
OLDNEW
« no previous file with comments | « src/assembler.h ('k') | src/base/ieee754.h » ('j') | test/unittests/base/ieee754-unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698