From 551c7aed70ad9aac77e9287b7b6f014f90f1e1b4 Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Fri, 21 Oct 2022 13:57:01 -0700 Subject: [PATCH] [libc] add performance options for string to float This allows the client to set compile flags to disable the passes that the string to float function uses. A client may be willing to trade off performance for a reduction in code size, and this allows for that fine-tuning. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D136495 --- libc/src/__support/str_to_float.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h index bc0d574..26ef2e9 100644 --- a/libc/src/__support/str_to_float.h +++ b/libc/src/__support/str_to_float.h @@ -108,8 +108,9 @@ eisel_lemire(typename fputil::FPBits::UIntType mantissa, int32_t exp10, uint32_t clz = leading_zeroes(mantissa); mantissa <<= clz; - uint32_t exp2 = static_cast(exp10_to_exp2(exp10)) + BITS_IN_MANTISSA + - fputil::FloatProperties::EXPONENT_BIAS - clz; + uint32_t exp2 = static_cast(exp10_to_exp2(exp10)) + + BITS_IN_MANTISSA + fputil::FloatProperties::EXPONENT_BIAS - + clz; // Multiplication const uint64_t *power_of_ten = @@ -147,8 +148,10 @@ eisel_lemire(typename fputil::FPBits::UIntType mantissa, int32_t exp10, } // Shifting to 54 bits for doubles and 25 bits for floats - BitsType msb = static_cast(high64(final_approx) >> (BITS_IN_MANTISSA - 1)); - BitsType final_mantissa = static_cast(high64(final_approx) >> + BitsType msb = + static_cast(high64(final_approx) >> (BITS_IN_MANTISSA - 1)); + BitsType final_mantissa = + static_cast(high64(final_approx) >> (msb + BITS_IN_MANTISSA - (fputil::FloatProperties::MANTISSA_WIDTH + 3))); exp2 -= static_cast(1 ^ msb); // same as !msb @@ -208,7 +211,8 @@ inline bool eisel_lemire( uint32_t clz = leading_zeroes(mantissa); mantissa <<= clz; - uint32_t exp2 = static_cast(exp10_to_exp2(exp10)) + BITS_IN_MANTISSA + + uint32_t exp2 = static_cast(exp10_to_exp2(exp10)) + + BITS_IN_MANTISSA + fputil::FloatProperties::EXPONENT_BIAS - clz; // Multiplication @@ -576,12 +580,15 @@ decimal_exp_to_float(typename fputil::FPBits::UIntType mantissa, return; } +#ifndef LLVM_LIBC_DISABLE_CLINGER_FAST_PATH if (!truncated) { if (clinger_fast_path(mantissa, exp10, outputMantissa, outputExp2)) { return; } } +#endif // LLVM_LIBC_DISABLE_CLINGER_FAST_PATH +#ifndef LLVM_LIBC_DISABLE_EISEL_LEMIRE // Try Eisel-Lemire if (eisel_lemire(mantissa, exp10, outputMantissa, outputExp2)) { if (!truncated) { @@ -598,8 +605,11 @@ decimal_exp_to_float(typename fputil::FPBits::UIntType mantissa, } } } +#endif // LLVM_LIBC_DISABLE_EISEL_LEMIRE +#ifndef LLVM_LIBC_DISABLE_SIMPLE_DECIMAL_CONVERSION simple_decimal_conversion(numStart, outputMantissa, outputExp2); +#endif // LLVM_LIBC_DISABLE_SIMPLE_DECIMAL_CONVERSION return; } -- 2.7.4