[flang] faster Parse
Original-commit: flang-compiler/f18@ca97439c68 Reviewed-on: https://github.com/flang-compiler/f18/pull/671 Tree-same-pre-rewrite: false
This commit is contained in:
parent
c4696eaf8e
commit
b235c63caf
|
@ -260,12 +260,16 @@ private:
|
|||
}
|
||||
|
||||
template<int N> int MultiplyWithoutNormalization() {
|
||||
int carry{MultiplyByHelper<N>(0)};
|
||||
if (carry > 0 && digits_ < digitLimit_) {
|
||||
digit_[digits_++] = carry;
|
||||
carry = 0;
|
||||
if (int carry{MultiplyByHelper<N>(0)}) {
|
||||
if (digits_ < digitLimit_) {
|
||||
digit_[digits_++] = carry;
|
||||
return 0;
|
||||
} else {
|
||||
return carry;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return carry;
|
||||
}
|
||||
|
||||
void LoseLeastSignificantDigit() {
|
||||
|
|
|
@ -218,7 +218,7 @@ bool BigRadixFloatingPointNumber<PREC, LOG10RADIX>::Mean(
|
|||
carry = 0;
|
||||
}
|
||||
}
|
||||
if (carry > 0) {
|
||||
if (carry != 0) {
|
||||
AddCarry(that.digits_, carry);
|
||||
}
|
||||
return DivideBy<2>() != 0;
|
||||
|
|
|
@ -39,33 +39,63 @@ bool BigRadixFloatingPointNumber<PREC, LOG10RADIX>::ParseNumber(
|
|||
while (*q == '0') {
|
||||
++q;
|
||||
}
|
||||
for (; *q >= '0' && *q <= '9' && !IsFull(); ++q) {
|
||||
MultiplyBy<10>(*q - '0');
|
||||
const char *firstDigit{q};
|
||||
for (; *q >= '0' && *q <= '9'; ++q) {
|
||||
}
|
||||
if (IsFull()) {
|
||||
for (; *q >= '0' && *q <= '9'; ++q) {
|
||||
if (*q != '0') {
|
||||
inexact = true;
|
||||
}
|
||||
++exponent_;
|
||||
}
|
||||
}
|
||||
if (*q == '.') {
|
||||
for (++q; *q >= '0' && *q <= '9' && !IsFull(); ++q) {
|
||||
MultiplyBy<10>(*q - '0');
|
||||
--exponent_;
|
||||
}
|
||||
if (IsFull()) {
|
||||
for (; *q >= '0' && *q <= '9'; ++q) {
|
||||
if (*q != '0') {
|
||||
inexact = true;
|
||||
}
|
||||
}
|
||||
const char *point{*q == '.' ? q : nullptr};
|
||||
if (point) {
|
||||
for (++q; *q >= '0' && *q <= '9'; ++q) {
|
||||
}
|
||||
}
|
||||
if (q == start || (q == start + 1 && *start == '.')) {
|
||||
return false; // require at least one digit
|
||||
}
|
||||
auto times{radix};
|
||||
const char *d{q};
|
||||
if (point != nullptr) {
|
||||
while (d > firstDigit && d[-1] == '0') {
|
||||
--d;
|
||||
}
|
||||
if (d[-1] == '.') {
|
||||
point = nullptr;
|
||||
--d;
|
||||
}
|
||||
}
|
||||
if (point == nullptr) {
|
||||
while (d > firstDigit && d[-1] == '0') {
|
||||
--d;
|
||||
++exponent_;
|
||||
}
|
||||
}
|
||||
if (d == firstDigit) {
|
||||
exponent_ = 0;
|
||||
}
|
||||
if (point != nullptr) {
|
||||
exponent_ -= static_cast<int>(d - point - 1);
|
||||
}
|
||||
const char *limit{firstDigit + maxDigits * log10Radix + (point != nullptr)};
|
||||
if (d > limit) {
|
||||
inexact = true;
|
||||
while (d-- > limit) {
|
||||
if (*d == '.') {
|
||||
point = nullptr;
|
||||
--limit;
|
||||
} else if (point == nullptr) {
|
||||
++exponent_;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (d-- > firstDigit) {
|
||||
if (*d != '.') {
|
||||
if (times == radix) {
|
||||
digit_[digits_++] = *d - '0';
|
||||
times = 10;
|
||||
} else {
|
||||
digit_[digits_ - 1] += times * (*d - '0');
|
||||
times *= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (*q) {
|
||||
case 'e':
|
||||
|
@ -242,7 +272,7 @@ BigRadixFloatingPointNumber<PREC, LOG10RADIX>::ConvertToBinary() {
|
|||
while (exponent_ < log10Radix) {
|
||||
f.AdjustExponent(-9);
|
||||
digitLimit_ = digits_;
|
||||
int carry = MultiplyWithoutNormalization<512>();
|
||||
int carry{MultiplyWithoutNormalization<512>()};
|
||||
RemoveLeastOrderZeroDigits();
|
||||
if (carry != 0) {
|
||||
digit_[digits_++] = carry;
|
||||
|
|
Loading…
Reference in a new issue