Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66424a0

Browse files
authored
[libc] provide str to float build configs (#178780)
The str to float code path offers options which can reduce code bloat. Expose them as build config options. Disable Eisel Lemire for avoiding code bloat caused by DETAILED_POWERS_OF_TEN look up table.
1 parent 3dfcd84 commit 66424a0

5 files changed

Lines changed: 37 additions & 2 deletions

File tree

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ endfunction(_get_compile_options_from_flags)
7777
function(_get_compile_options_from_config output_var)
7878
set(config_options "")
7979

80+
if(LIBC_CONF_STRTOFLOAT_DISABLE_EISEL_LEMIRE)
81+
list(APPEND config_options "-DLIBC_COPT_STRTOFLOAT_DISABLE_EISEL_LEMIRE")
82+
endif()
83+
84+
if(LIBC_CONF_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION)
85+
list(APPEND config_options "-DLIBC_COPT_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION")
86+
endif()
87+
88+
if(LIBC_CONF_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH)
89+
list(APPEND config_options "-DLIBC_COPT_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH")
90+
endif()
91+
8092
if(LIBC_CONF_QSORT_IMPL)
8193
list(APPEND config_options "-DLIBC_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}")
8294
endif()

libc/config/baremetal/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
"value": "LIBC_QSORT_HEAP_SORT"
3535
}
3636
},
37+
"str_to_float": {
38+
"LIBC_CONF_STRTOFLOAT_DISABLE_EISEL_LEMIRE": {
39+
"value": true
40+
}
41+
},
3742
"math": {
3843
"LIBC_CONF_MATH_OPTIMIZATIONS": {
3944
"value": "(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_INTERMEDIATE_COMP_IN_FLOAT)"

libc/config/config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@
6868
"doc": "Disable index mode in the scanf format string."
6969
}
7070
},
71+
"str_to_float": {
72+
"LIBC_CONF_STRTOFLOAT_DISABLE_EISEL_LEMIRE": {
73+
"value": false,
74+
"doc": "Disable Eisel-Lemire algorithm for string to float conversion."
75+
},
76+
"LIBC_CONF_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION": {
77+
"value": false,
78+
"doc": "Disable simple decimal conversion for string to float conversion."
79+
},
80+
"LIBC_CONF_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH": {
81+
"value": false,
82+
"doc": "Disable Clinger's fast path for string to float conversion."
83+
}
84+
},
7185
"string": {
7286
"LIBC_CONF_STRING_LENGTH_IMPL": {
7387
"value": "element",

libc/docs/configure.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ to learn about the defaults for your platform and target.
6161
- ``LIBC_CONF_SCANF_DISABLE_INDEX_MODE``: Disable index mode in the scanf format string.
6262
* **"setjmp" options**
6363
- ``LIBC_CONF_SETJMP_AARCH64_RESTORE_PLATFORM_REGISTER``: Make setjmp save the value of x18, and longjmp restore it. The AArch64 ABI delegates this register to platform ABIs, which can choose whether to make it caller-saved.
64+
* **"str_to_float" options**
65+
- ``LIBC_CONF_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH``: Disable Clinger's fast path for string to float conversion.
66+
- ``LIBC_CONF_STRTOFLOAT_DISABLE_EISEL_LEMIRE``: Disable Eisel-Lemire algorithm for string to float conversion.
67+
- ``LIBC_CONF_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION``: Disable simple decimal conversion for string to float conversion.
6468
* **"string" options**
6569
- ``LIBC_CONF_FIND_FIRST_CHARACTER_IMPL``: Selects the implementation for find-first-character-related functions: 'element', 'word', 'clang_vector', or 'arch_vector'.
6670
- ``LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING``: Inserts prefetch for write instructions (PREFETCHW) for memset on x86 to recover performance when hardware prefetcher is disabled.

libc/src/__support/str_to_float.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,7 @@ LIBC_INLINE FloatConvertReturn<T> decimal_exp_to_float(
684684
const CharType *__restrict numStart,
685685
const size_t num_len = cpp::numeric_limits<size_t>::max()) {
686686
using FPBits = typename fputil::FPBits<T>;
687-
using StorageType = typename FPBits::StorageType;
688687

689-
StorageType mantissa = init_num.mantissa;
690688
int32_t exp10 = init_num.exponent;
691689

692690
FloatConvertReturn<T> output;
@@ -725,6 +723,8 @@ LIBC_INLINE FloatConvertReturn<T> decimal_exp_to_float(
725723

726724
#ifndef LIBC_COPT_STRTOFLOAT_DISABLE_EISEL_LEMIRE
727725
// Try Eisel-Lemire
726+
using StorageType = typename FPBits::StorageType;
727+
StorageType mantissa = init_num.mantissa;
728728
opt_output = eisel_lemire<T>(init_num, round);
729729
if (opt_output.has_value()) {
730730
if (!truncated) {

0 commit comments

Comments
 (0)