mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
* additional types cleanup for speedup and reduce cache pressure.
This commit is contained in:
parent
0a18d6b329
commit
17ffdffdd9
@ -17,7 +17,7 @@ namespace fast_float {
|
|||||||
// most significant bits and the low part corresponding to the least significant
|
// most significant bits and the low part corresponding to the least significant
|
||||||
// bits.
|
// bits.
|
||||||
//
|
//
|
||||||
template <uint32_t bit_precision>
|
template <uint8_t bit_precision>
|
||||||
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 value128
|
fastfloat_really_inline FASTFLOAT_CONSTEXPR20 value128
|
||||||
compute_product_approximation(int64_t q, uint64_t w) noexcept {
|
compute_product_approximation(int64_t q, uint64_t w) noexcept {
|
||||||
int const index = 2 * int(q - powers::smallest_power_of_five);
|
int const index = 2 * int(q - powers::smallest_power_of_five);
|
||||||
@ -171,7 +171,7 @@ compute_float(int64_t q, uint64_t w) noexcept {
|
|||||||
// subnormal, but we can only know this after rounding.
|
// subnormal, but we can only know this after rounding.
|
||||||
// So we only declare a subnormal if we are smaller than the threshold.
|
// So we only declare a subnormal if we are smaller than the threshold.
|
||||||
answer.power2 =
|
answer.power2 =
|
||||||
(answer.mantissa < (uint64_t(1) << binary::mantissa_explicit_bits()))
|
(answer.mantissa < (am_mant_t(1) << binary::mantissa_explicit_bits()))
|
||||||
? 0
|
? 0
|
||||||
: 1;
|
: 1;
|
||||||
return answer;
|
return answer;
|
||||||
@ -189,18 +189,18 @@ compute_float(int64_t q, uint64_t w) noexcept {
|
|||||||
// ... we dropped out only zeroes. But if this happened, then we can go
|
// ... we dropped out only zeroes. But if this happened, then we can go
|
||||||
// back!!!
|
// back!!!
|
||||||
if ((answer.mantissa << shift) == product.high) {
|
if ((answer.mantissa << shift) == product.high) {
|
||||||
answer.mantissa &= ~uint64_t(1); // flip it so that we do not round up
|
answer.mantissa &= ~am_mant_t(1); // flip it so that we do not round up
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
answer.mantissa += (answer.mantissa & 1); // round up
|
answer.mantissa += (answer.mantissa & 1); // round up
|
||||||
answer.mantissa >>= 1;
|
answer.mantissa >>= 1;
|
||||||
if (answer.mantissa >= (uint64_t(2) << binary::mantissa_explicit_bits())) {
|
if (answer.mantissa >= (am_mant_t(2) << binary::mantissa_explicit_bits())) {
|
||||||
answer.mantissa = (uint64_t(1) << binary::mantissa_explicit_bits());
|
answer.mantissa = (am_mant_t(1) << binary::mantissa_explicit_bits());
|
||||||
++answer.power2; // undo previous addition
|
++answer.power2; // undo previous addition
|
||||||
}
|
}
|
||||||
|
|
||||||
answer.mantissa &= ~(uint64_t(1) << binary::mantissa_explicit_bits());
|
answer.mantissa &= ~(am_mant_t(1) << binary::mantissa_explicit_bits());
|
||||||
if (answer.power2 >= binary::infinite_power()) { // infinity
|
if (answer.power2 >= binary::infinite_power()) { // infinity
|
||||||
answer.power2 = binary::infinite_power();
|
answer.power2 = binary::infinite_power();
|
||||||
answer.mantissa = 0;
|
answer.mantissa = 0;
|
||||||
|
|||||||
@ -1058,7 +1058,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 void to_float(
|
|||||||
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
|
||||||
|
|
||||||
template <typename = void> struct space_lut {
|
template <typename = void> struct space_lut {
|
||||||
static constexpr bool value[] = {
|
static constexpr uint8_t value[] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
@ -1074,7 +1074,7 @@ template <typename = void> struct space_lut {
|
|||||||
|
|
||||||
#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
|
#if FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE
|
||||||
|
|
||||||
template <typename T> constexpr bool space_lut<T>::value[];
|
template <typename T> constexpr uint8_t space_lut<T>::value[];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user