зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1745118 - double-conversion: update double-conversion to version 3.1.6 (upstream revision 60e08d0). r=glandium
* Fix update.sh to use macOS-compatible mktemp -d flag. * Rebase use-mozilla-assertions.patch to fix merge conflict. * Rebase debug-only-functions.patch to fix merge conflict. * Rebase to-fixed-dbl-max.patch to fix merge conflict. * Remove to-fixed-digits-after-point.patch because upstream has this fix now. https://github.com/google/double-conversion/releases/tag/v3.1.6 Cleanups and new architectures: * Features some code cleanups. * Adds the following new architectures: loongarch, xtensa, nios2, e2k. Differential Revision: https://phabricator.services.mozilla.com/D133581
This commit is contained in:
Родитель
b36ccf1b42
Коммит
e1a50b756e
|
@ -1,12 +1,5 @@
|
|||
commit bf4607277fa7133825cb7899015374917cd06b8f
|
||||
Author: Mike Hommey <mhommey@mozilla.com>
|
||||
Date: Tue Jan 26 19:46:13 2021 +0900
|
||||
commit bf1c94f675a2e5886e8877913881597c92bd499d
|
||||
Author: Florian Loitsch <florian@loitsch.com>
|
||||
Date: Sat Dec 4 17:56:28 2021 +0100
|
||||
|
||||
Add a flag to make precision mode like printf's %g (#149)
|
||||
|
||||
With this, %g can be emulated with:
|
||||
```
|
||||
DoubleToStringConverter cvt(
|
||||
UNIQUE_ZERO | NO_TRAILING_ZERO | EMIT_POSITIVE_EXPONENT_SIGN,
|
||||
"inf", "nan", 'e', 0, 0, 4, 0, 2)
|
||||
```
|
||||
Add test action (#168)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
diff --git a/mfbt/double-conversion/double-conversion/strtod.cc b/mfbt/double-conversion/double-conversion/strtod.cc
|
||||
index 850bcdaac4ad1..6ed686c8d9bfb 100644
|
||||
--- a/mfbt/double-conversion/double-conversion/strtod.cc
|
||||
+++ b/mfbt/double-conversion/double-conversion/strtod.cc
|
||||
@@ -447,32 +447,34 @@ static bool ComputeGuess(Vector<const char> trimmed, int exponent,
|
||||
@@ -436,16 +436,17 @@ static bool ComputeGuess(Vector<const ch
|
||||
return true;
|
||||
}
|
||||
if (*guess == Double::Infinity()) {
|
||||
|
@ -20,6 +19,7 @@ index 850bcdaac4ad1..6ed686c8d9bfb 100644
|
|||
return ('1' <= d) && (d <= '9');
|
||||
}
|
||||
|
||||
@@ -457,16 +458,17 @@ static bool IsNonZeroDigit(const char d)
|
||||
static bool AssertTrimmedDigits(const Vector<const char>& buffer) {
|
||||
for(int i = 0; i < buffer.length(); ++i) {
|
||||
if(!IsDigit(buffer[i])) {
|
||||
|
|
|
@ -49,7 +49,7 @@ Use `-DBUILD_TESTING=ON` to build the test executable.
|
|||
|
||||
cmake . -DBUILD_TESTING=ON
|
||||
make
|
||||
test/cctest/cctest --list | tr -d '<' | xargs test/cctest/cctest
|
||||
test/cctest/cctest
|
||||
|
||||
[0]: http://www.scons.org/
|
||||
[1]: https://cmake.org/
|
||||
|
|
|
@ -276,7 +276,7 @@ static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
|
|||
|
||||
// Let v = numerator / denominator < 10.
|
||||
// Then we generate 'count' digits of d = x.xxxxx... (without the decimal point)
|
||||
// from left to right. Once 'count' digits have been produced we decide wether
|
||||
// from left to right. Once 'count' digits have been produced we decide whether
|
||||
// to round up or down. Remainders of exactly .5 round upwards. Numbers such
|
||||
// as 9.999999 propagate a carry all the way, and change the
|
||||
// exponent (decimal_point), when rounding upwards.
|
||||
|
|
|
@ -124,7 +124,7 @@ class DoubleToStringConverter {
|
|||
// Example with max_leading_padding_zeroes_in_precision_mode = 6.
|
||||
// ToPrecision(0.0000012345, 2) -> "0.0000012"
|
||||
// ToPrecision(0.00000012345, 2) -> "1.2e-7"
|
||||
// Similarily the converter may add up to
|
||||
// Similarly the converter may add up to
|
||||
// max_trailing_padding_zeroes_in_precision_mode in precision mode to avoid
|
||||
// returning an exponential representation. A zero added by the
|
||||
// EMIT_TRAILING_ZERO_AFTER_POINT flag is counted for this limit.
|
||||
|
@ -182,7 +182,7 @@ class DoubleToStringConverter {
|
|||
// Example with decimal_in_shortest_low = -6,
|
||||
// decimal_in_shortest_high = 21,
|
||||
// EMIT_POSITIVE_EXPONENT_SIGN activated, and
|
||||
// EMIT_TRAILING_DECIMAL_POINT deactived:
|
||||
// EMIT_TRAILING_DECIMAL_POINT deactivated:
|
||||
// ToShortest(0.000001) -> "0.000001"
|
||||
// ToShortest(0.0000001) -> "1e-7"
|
||||
// ToShortest(111111111111111111111.0) -> "111111111111111110000"
|
||||
|
@ -306,7 +306,7 @@ class DoubleToStringConverter {
|
|||
// Example with max_leading_padding_zeroes_in_precision_mode = 6.
|
||||
// ToPrecision(0.0000012345, 2) -> "0.0000012"
|
||||
// ToPrecision(0.00000012345, 2) -> "1.2e-7"
|
||||
// Similarily the converter may add up to
|
||||
// Similarly the converter may add up to
|
||||
// max_trailing_padding_zeroes_in_precision_mode in precision mode to avoid
|
||||
// returning an exponential representation. A zero added by the
|
||||
// EMIT_TRAILING_ZERO_AFTER_POINT flag is counted for this limit.
|
||||
|
|
|
@ -565,7 +565,7 @@ static bool Grisu3(double v,
|
|||
// the difference between w and boundary_minus/plus (a power of 2) and to
|
||||
// compute scaled_boundary_minus/plus by subtracting/adding from
|
||||
// scaled_w. However the code becomes much less readable and the speed
|
||||
// enhancements are not terriffic.
|
||||
// enhancements are not terrific.
|
||||
DiyFp scaled_boundary_minus = DiyFp::Times(boundary_minus, ten_mk);
|
||||
DiyFp scaled_boundary_plus = DiyFp::Times(boundary_plus, ten_mk);
|
||||
|
||||
|
@ -573,7 +573,7 @@ static bool Grisu3(double v,
|
|||
// v == (double) (scaled_w * 10^-mk).
|
||||
// Set decimal_exponent == -mk and pass it to DigitGen. If scaled_w is not an
|
||||
// integer than it will be updated. For instance if scaled_w == 1.23 then
|
||||
// the buffer will be filled with "123" und the decimal_exponent will be
|
||||
// the buffer will be filled with "123" and the decimal_exponent will be
|
||||
// decreased by 2.
|
||||
int kappa;
|
||||
bool result = DigitGen(scaled_boundary_minus, scaled_w, scaled_boundary_plus,
|
||||
|
|
|
@ -395,8 +395,8 @@ bool FastFixedDtoa(double v,
|
|||
TrimZeros(buffer, length, decimal_point);
|
||||
buffer[*length] = '\0';
|
||||
if ((*length) == 0) {
|
||||
// The string is empty and the decimal_point thus has no importance. Mimick
|
||||
// Gay's dtoa and and set it to -fractional_count.
|
||||
// The string is empty and the decimal_point thus has no importance. Mimic
|
||||
// Gay's dtoa and set it to -fractional_count.
|
||||
*decimal_point = -fractional_count;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -729,11 +729,17 @@ double StringToDoubleConverter::StringToIeee(
|
|||
DOUBLE_CONVERSION_ASSERT(buffer_pos < kBufferSize);
|
||||
buffer[buffer_pos] = '\0';
|
||||
|
||||
// Code above ensures there are no leading zeros and the buffer has fewer than
|
||||
// kMaxSignificantDecimalDigits characters. Trim trailing zeros.
|
||||
Vector<const char> chars(buffer, buffer_pos);
|
||||
chars = TrimTrailingZeros(chars);
|
||||
exponent += buffer_pos - chars.length();
|
||||
|
||||
double converted;
|
||||
if (read_as_double) {
|
||||
converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent);
|
||||
converted = StrtodTrimmed(chars, exponent);
|
||||
} else {
|
||||
converted = Strtof(Vector<const char>(buffer, buffer_pos), exponent);
|
||||
converted = StrtofTrimmed(chars, exponent);
|
||||
}
|
||||
*processed_characters_count = static_cast<int>(current - input);
|
||||
return sign? -converted: converted;
|
||||
|
@ -773,4 +779,40 @@ float StringToDoubleConverter::StringToFloat(
|
|||
processed_characters_count));
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
double StringToDoubleConverter::StringTo<double>(
|
||||
const char* buffer,
|
||||
int length,
|
||||
int* processed_characters_count) const {
|
||||
return StringToDouble(buffer, length, processed_characters_count);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
float StringToDoubleConverter::StringTo<float>(
|
||||
const char* buffer,
|
||||
int length,
|
||||
int* processed_characters_count) const {
|
||||
return StringToFloat(buffer, length, processed_characters_count);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
double StringToDoubleConverter::StringTo<double>(
|
||||
const uc16* buffer,
|
||||
int length,
|
||||
int* processed_characters_count) const {
|
||||
return StringToDouble(buffer, length, processed_characters_count);
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
float StringToDoubleConverter::StringTo<float>(
|
||||
const uc16* buffer,
|
||||
int length,
|
||||
int* processed_characters_count) const {
|
||||
return StringToFloat(buffer, length, processed_characters_count);
|
||||
}
|
||||
|
||||
} // namespace double_conversion
|
||||
|
|
|
@ -86,7 +86,7 @@ class StringToDoubleConverter {
|
|||
// This *must* start with "0x" and separate the exponent with "p".
|
||||
// Examples: 0x1.2p3 == 9.0
|
||||
// 0x10.1p0 == 16.0625
|
||||
// ALLOW_HEX and ALLOW_HEX_FLOATS are indendent.
|
||||
// ALLOW_HEX and ALLOW_HEX_FLOATS are indented.
|
||||
//
|
||||
// empty_string_value is returned when an empty string is given as input.
|
||||
// If ALLOW_LEADING_SPACES or ALLOW_TRAILING_SPACES are set, then a string
|
||||
|
@ -204,6 +204,18 @@ class StringToDoubleConverter {
|
|||
int length,
|
||||
int* processed_characters_count) const;
|
||||
|
||||
// Same as StringToDouble for T = double, and StringToFloat for T = float.
|
||||
template <typename T>
|
||||
T StringTo(const char* buffer,
|
||||
int length,
|
||||
int* processed_characters_count) const;
|
||||
|
||||
// Same as StringTo above but for 16 bit characters.
|
||||
template <typename T>
|
||||
T StringTo(const uc16* buffer,
|
||||
int length,
|
||||
int* processed_characters_count) const;
|
||||
|
||||
private:
|
||||
const int flags_;
|
||||
const double empty_string_value_;
|
||||
|
|
|
@ -101,17 +101,6 @@ static Vector<const char> TrimLeadingZeros(Vector<const char> buffer) {
|
|||
return Vector<const char>(buffer.start(), 0);
|
||||
}
|
||||
|
||||
|
||||
static Vector<const char> TrimTrailingZeros(Vector<const char> buffer) {
|
||||
for (int i = buffer.length() - 1; i >= 0; --i) {
|
||||
if (buffer[i] != '0') {
|
||||
return buffer.SubVector(0, i + 1);
|
||||
}
|
||||
}
|
||||
return Vector<const char>(buffer.start(), 0);
|
||||
}
|
||||
|
||||
|
||||
static void CutToMaxSignificantDigits(Vector<const char> buffer,
|
||||
int exponent,
|
||||
char* significant_buffer,
|
||||
|
@ -461,6 +450,11 @@ static bool IsNonZeroDigit(const char d) {
|
|||
return ('1' <= d) && (d <= '9');
|
||||
}
|
||||
|
||||
#ifdef __has_cpp_attribute
|
||||
#if __has_cpp_attribute(maybe_unused)
|
||||
[[maybe_unused]]
|
||||
#endif
|
||||
#endif
|
||||
static bool AssertTrimmedDigits(const Vector<const char>& buffer) {
|
||||
for(int i = 0; i < buffer.length(); ++i) {
|
||||
if(!IsDigit(buffer[i])) {
|
||||
|
@ -533,6 +527,12 @@ float Strtof(Vector<const char> buffer, int exponent) {
|
|||
TrimAndCut(buffer, exponent, copy_buffer, kMaxSignificantDecimalDigits,
|
||||
&trimmed, &updated_exponent);
|
||||
exponent = updated_exponent;
|
||||
return StrtofTrimmed(trimmed, exponent);
|
||||
}
|
||||
|
||||
float StrtofTrimmed(Vector<const char> trimmed, int exponent) {
|
||||
DOUBLE_CONVERSION_ASSERT(trimmed.length() <= kMaxSignificantDecimalDigits);
|
||||
DOUBLE_CONVERSION_ASSERT(AssertTrimmedDigits(trimmed));
|
||||
|
||||
double double_guess;
|
||||
bool is_correct = ComputeGuess(trimmed, exponent, &double_guess);
|
||||
|
@ -552,7 +552,7 @@ float Strtof(Vector<const char> buffer, int exponent) {
|
|||
// low-precision (3 digits):
|
||||
// when read from input: 123
|
||||
// when rounded from high precision: 124.
|
||||
// To do this we simply look at the neigbors of the correct result and see
|
||||
// To do this we simply look at the neighbors of the correct result and see
|
||||
// if they would round to the same float. If the guess is not correct we have
|
||||
// to look at four values (since two different doubles could be the correct
|
||||
// double).
|
||||
|
|
|
@ -40,11 +40,25 @@ double Strtod(Vector<const char> buffer, int exponent);
|
|||
// contain a dot or a sign. It must not start with '0', and must not be empty.
|
||||
float Strtof(Vector<const char> buffer, int exponent);
|
||||
|
||||
// For special use cases, the heart of the Strtod() function is also available
|
||||
// separately, it assumes that 'trimmed' is as produced by TrimAndCut(), i.e.
|
||||
// no leading or trailing zeros, also no lone zero, and not 'too many' digits.
|
||||
// Same as Strtod, but assumes that 'trimmed' is already trimmed, as if run
|
||||
// through TrimAndCut. That is, 'trimmed' must have no leading or trailing
|
||||
// zeros, must not be a lone zero, and must not have 'too many' digits.
|
||||
double StrtodTrimmed(Vector<const char> trimmed, int exponent);
|
||||
|
||||
// Same as Strtof, but assumes that 'trimmed' is already trimmed, as if run
|
||||
// through TrimAndCut. That is, 'trimmed' must have no leading or trailing
|
||||
// zeros, must not be a lone zero, and must not have 'too many' digits.
|
||||
float StrtofTrimmed(Vector<const char> trimmed, int exponent);
|
||||
|
||||
inline Vector<const char> TrimTrailingZeros(Vector<const char> buffer) {
|
||||
for (int i = buffer.length() - 1; i >= 0; --i) {
|
||||
if (buffer[i] != '0') {
|
||||
return buffer.SubVector(0, i + 1);
|
||||
}
|
||||
}
|
||||
return Vector<const char>(buffer.start(), 0);
|
||||
}
|
||||
|
||||
} // namespace double_conversion
|
||||
|
||||
#endif // DOUBLE_CONVERSION_STRTOD_H_
|
||||
|
|
|
@ -108,6 +108,7 @@ int main(int argc, char** argv) {
|
|||
defined(__ARMEL__) || defined(__avr32__) || defined(_M_ARM) || defined(_M_ARM64) || \
|
||||
defined(__hppa__) || defined(__ia64__) || \
|
||||
defined(__mips__) || \
|
||||
defined(__loongarch__) || \
|
||||
defined(__nios2__) || defined(__ghs) || \
|
||||
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
|
||||
defined(_POWER) || defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
diff --git a/mfbt/double-conversion/double-conversion/double-to-string.cc b/mfbt/double-conversion/double-conversion/double-to-string.cc
|
||||
index 9255bce1713e9..30b15a829a25a 100644
|
||||
--- a/mfbt/double-conversion/double-conversion/double-to-string.cc
|
||||
+++ b/mfbt/double-conversion/double-conversion/double-to-string.cc
|
||||
@@ -200,25 +200,21 @@ bool DoubleToStringConverter::ToShortestIeeeNumber(
|
||||
@@ -200,25 +200,21 @@ bool DoubleToStringConverter::ToShortest
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -29,7 +28,6 @@ index 9255bce1713e9..30b15a829a25a 100644
|
|||
kMaxFixedDigitsBeforePoint + kMaxFixedDigitsAfterPoint + 1;
|
||||
char decimal_rep[kDecimalRepCapacity];
|
||||
diff --git a/mfbt/double-conversion/double-conversion/double-to-string.h b/mfbt/double-conversion/double-conversion/double-to-string.h
|
||||
index 52d7986fe9048..5e1c182b6b6a2 100644
|
||||
--- a/mfbt/double-conversion/double-conversion/double-to-string.h
|
||||
+++ b/mfbt/double-conversion/double-conversion/double-to-string.h
|
||||
@@ -33,17 +33,17 @@
|
||||
|
@ -43,7 +41,7 @@ index 52d7986fe9048..5e1c182b6b6a2 100644
|
|||
// function returns false.
|
||||
- static const int kMaxFixedDigitsBeforePoint = 60;
|
||||
+ static const int kMaxFixedDigitsBeforePoint = 308;
|
||||
static const int kMaxFixedDigitsAfterPoint = 60;
|
||||
static const int kMaxFixedDigitsAfterPoint = 100;
|
||||
|
||||
// When calling ToExponential with a requested_digits
|
||||
// parameter > kMaxExponentialDigits then the function returns false.
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
diff --git a/mfbt/double-conversion/double-conversion/double-to-string.h b/mfbt/double-conversion/double-conversion/double-to-string.h
|
||||
--- a/mfbt/double-conversion/double-conversion/double-to-string.h
|
||||
+++ b/mfbt/double-conversion/double-conversion/double-to-string.h
|
||||
@@ -34,17 +34,17 @@
|
||||
namespace double_conversion {
|
||||
|
||||
class DoubleToStringConverter {
|
||||
public:
|
||||
// When calling ToFixed with a double > 10^kMaxFixedDigitsBeforePoint
|
||||
// or a requested_digits parameter > kMaxFixedDigitsAfterPoint then the
|
||||
// function returns false.
|
||||
static const int kMaxFixedDigitsBeforePoint = 308;
|
||||
- static const int kMaxFixedDigitsAfterPoint = 60;
|
||||
+ static const int kMaxFixedDigitsAfterPoint = 100;
|
||||
|
||||
// When calling ToExponential with a requested_digits
|
||||
// parameter > kMaxExponentialDigits then the function returns false.
|
||||
static const int kMaxExponentialDigits = 120;
|
||||
|
||||
// When calling ToPrecision with a requested_digits
|
||||
// parameter < kMinPrecisionDigits or requested_digits > kMaxPrecisionDigits
|
||||
// then the function returns false.
|
|
@ -14,9 +14,8 @@ LOCAL_PATCHES="$LOCAL_PATCHES add-mfbt-api-markers.patch"
|
|||
LOCAL_PATCHES="$LOCAL_PATCHES use-mozilla-assertions.patch"
|
||||
LOCAL_PATCHES="$LOCAL_PATCHES debug-only-functions.patch"
|
||||
LOCAL_PATCHES="$LOCAL_PATCHES to-fixed-dbl-max.patch"
|
||||
LOCAL_PATCHES="$LOCAL_PATCHES to-fixed-digits-after-point.patch"
|
||||
|
||||
TMPDIR=`mktemp --directory`
|
||||
TMPDIR=`mktemp -d`
|
||||
LOCAL_CLONE="$TMPDIR/new-double-conversion"
|
||||
|
||||
git clone https://github.com/google/double-conversion.git "$LOCAL_CLONE"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
diff --git a/mfbt/double-conversion/double-conversion/utils.h b/mfbt/double-conversion/double-conversion/utils.h
|
||||
index c72c333f020a1..6022132e2b495 100644
|
||||
--- a/mfbt/double-conversion/double-conversion/utils.h
|
||||
+++ b/mfbt/double-conversion/double-conversion/utils.h
|
||||
@@ -26,38 +26,38 @@
|
||||
|
@ -15,7 +14,7 @@ index c72c333f020a1..6022132e2b495 100644
|
|||
+#include "mozilla/Assertions.h"
|
||||
#ifndef DOUBLE_CONVERSION_ASSERT
|
||||
#define DOUBLE_CONVERSION_ASSERT(condition) \
|
||||
- assert(condition);
|
||||
- assert(condition)
|
||||
+ MOZ_ASSERT(condition)
|
||||
#endif
|
||||
#ifndef DOUBLE_CONVERSION_UNIMPLEMENTED
|
||||
|
|
Загрузка…
Ссылка в новой задаче