This PR adds a new option ~~`LIBC_MATH_ALWAYS_ROUND_NEAREST`~~ `LIBC_MATH_ASSUME_ROUND_NEAREST_ONLY` to LLVM libm. There are some UBs that I kept as-is from the original code to keep the changes non-disruptive (which I've marked with TODO comments) Benchmarks (from `files.zip` in the comment https://github.com/llvm/llvm-project/issues/198276#issue-4468816457): - System libm: ``` overflow (>710) 1.55 ns/call (644M ops/sec) underflow to 0 (<-746) 1.34 ns/call (747M ops/sec) normal [-10,10] 4.41 ns/call (227M ops/sec) denormals [-740,-735] 2.25 ns/call (444M ops/sec) near-uflow [-700,-690] 2.25 ns/call (444M ops/sec) ``` - LLVM libm (without the option being set): ``` overflow (>710) 5.21 ns/call (192M ops/sec) underflow to 0 (<-746) 7.20 ns/call (139M ops/sec) normal [-10,10] 4.06 ns/call (246M ops/sec) denormals [-740,-735] 5.85 ns/call (171M ops/sec) near-uflow [-700,-690] 4.06 ns/call (246M ops/sec) ``` - LLVM libm (with the option being **set**, `bench-exp-paths-inc.cc`) ``` overflow (>710) 1.95 ns/call (514M ops/sec) underflow to 0 (<-746) 2.23 ns/call (449M ops/sec) normal [-10,10] 3.43 ns/call (292M ops/sec) denormals [-740,-735] 5.19 ns/call (193M ops/sec) near-uflow [-700,-690] 3.43 ns/call (292M ops/sec) ``` Notice that in the `bench-exp-paths-inc.cc` file, I've changed the option name from `LIBC_MATH_ROUND_NEAREST` to `LIBC_MATH_ASSUME_ROUND_NEAREST_ONLY` Benchmark system: macOS 26.5, Apple M3.
194 lines
7.5 KiB
JSON
194 lines
7.5 KiB
JSON
{
|
|
"errno": {
|
|
"LIBC_CONF_ERRNO_MODE": {
|
|
"value": "LIBC_ERRNO_MODE_DEFAULT",
|
|
"doc": "The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, and LIBC_ERRNO_MODE_SYSTEM_INLINE."
|
|
}
|
|
},
|
|
"threads": {
|
|
"LIBC_CONF_THREAD_MODE": {
|
|
"value": "LIBC_THREAD_MODE_PLATFORM",
|
|
"doc": "The implementation used for Mutex, acceptable values are LIBC_THREAD_MODE_PLATFORM, LIBC_THREAD_MODE_SINGLE, and LIBC_THREAD_MODE_EXTERNAL."
|
|
}
|
|
},
|
|
"printf": {
|
|
"LIBC_CONF_PRINTF_DISABLE_FLOAT": {
|
|
"value": false,
|
|
"doc": "Disable printing floating point values in printf and friends."
|
|
},
|
|
"LIBC_CONF_PRINTF_DISABLE_INDEX_MODE": {
|
|
"value": false,
|
|
"doc": "Disable index mode in the printf format string."
|
|
},
|
|
"LIBC_CONF_PRINTF_DISABLE_WRITE_INT": {
|
|
"value": false,
|
|
"doc": "Disable handling of %n in printf format string."
|
|
},
|
|
"LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE": {
|
|
"value": false,
|
|
"doc": "Use large table for better printf long double performance."
|
|
},
|
|
"LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_DYADIC_FLOAT": {
|
|
"value": false,
|
|
"doc": "Use dyadic float for faster and smaller but less accurate printf doubles."
|
|
},
|
|
"LIBC_CONF_PRINTF_FLOAT_TO_STR_NO_SPECIALIZE_LD": {
|
|
"value": false,
|
|
"doc": "Use the same mode for double and long double in printf."
|
|
},
|
|
"LIBC_CONF_PRINTF_FLOAT_TO_STR_USE_FLOAT320": {
|
|
"value": false,
|
|
"doc": "Use an alternative printf float implementation based on 320-bit floats"
|
|
},
|
|
"LIBC_CONF_PRINTF_DISABLE_FIXED_POINT": {
|
|
"value": false,
|
|
"doc": "Disable printing fixed point values in printf and friends."
|
|
},
|
|
"LIBC_CONF_PRINTF_DISABLE_STRERROR": {
|
|
"value": false,
|
|
"doc": "Disable handling of %m to print strerror in printf and friends."
|
|
},
|
|
"LIBC_CONF_PRINTF_RUNTIME_DISPATCH": {
|
|
"value": true,
|
|
"doc": "Use dynamic dispatch for the output mechanism to reduce code size."
|
|
},
|
|
"LIBC_CONF_PRINTF_DISABLE_WIDE": {
|
|
"value": false,
|
|
"doc": "Disable handling wide characters for printf and friends."
|
|
},
|
|
"LIBC_COPT_PRINTF_DISABLE_BITINT": {
|
|
"value": false,
|
|
"doc": "Disable bitint length modifiers to reduce code size. Specifically the wNUM and wfNUM modifiers."
|
|
},
|
|
"LIBC_CONF_PRINTF_MODULAR": {
|
|
"value": false,
|
|
"doc": "Split printf implementation into modules that can be lazily linked in."
|
|
}
|
|
},
|
|
"scanf": {
|
|
"LIBC_CONF_SCANF_DISABLE_FLOAT": {
|
|
"value": false,
|
|
"doc": "Disable parsing floating point values in scanf and friends."
|
|
},
|
|
"LIBC_CONF_SCANF_DISABLE_INDEX_MODE": {
|
|
"value": false,
|
|
"doc": "Disable index mode in the scanf format string."
|
|
}
|
|
},
|
|
"str_to_float": {
|
|
"LIBC_CONF_STRTOFLOAT_DISABLE_EISEL_LEMIRE": {
|
|
"value": false,
|
|
"doc": "Disable Eisel-Lemire algorithm for string to float conversion."
|
|
},
|
|
"LIBC_CONF_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION": {
|
|
"value": false,
|
|
"doc": "Disable simple decimal conversion for string to float conversion."
|
|
},
|
|
"LIBC_CONF_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH": {
|
|
"value": false,
|
|
"doc": "Disable Clinger's fast path for string to float conversion."
|
|
}
|
|
},
|
|
"string": {
|
|
"LIBC_CONF_STRING_LENGTH_IMPL": {
|
|
"value": "element",
|
|
"doc": "Selects the implementation for string-length: 'element', 'word', 'clang_vector', or 'arch_vector'."
|
|
},
|
|
"LIBC_CONF_FIND_FIRST_CHARACTER_IMPL": {
|
|
"value": "element",
|
|
"doc": "Selects the implementation for find-first-character-related functions: 'element', 'word', 'clang_vector', or 'arch_vector'."
|
|
},
|
|
"LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING": {
|
|
"value": false,
|
|
"doc": "Inserts prefetch for write instructions (PREFETCHW) for memset on x86 to recover performance when hardware prefetcher is disabled."
|
|
},
|
|
"LIBC_CONF_COPT_MEMCPY_X86_USE_NTA_STORES": {
|
|
"value": false,
|
|
"doc": "Use Non-temporal stores in memcpy on x86 to improve performance of large copies."
|
|
},
|
|
"LIBC_CONF_USE_MEM_BUILTINS": {
|
|
"value": false,
|
|
"doc": "Use builtins for memory utility functions."
|
|
}
|
|
},
|
|
"ctype": {
|
|
"LIBC_CONF_CTYPE_SMALLER_ASCII": {
|
|
"value": false,
|
|
"doc": "Shrinks b36_char_to_int by assuming the character encoding is ASCII."
|
|
}
|
|
},
|
|
"codegen": {
|
|
"LIBC_CONF_KEEP_FRAME_POINTER": {
|
|
"value": true,
|
|
"doc": "Keep frame pointer in functions for better debugging experience."
|
|
},
|
|
"LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR": {
|
|
"value": true,
|
|
"doc": "Enable -fstack-protector-strong to defend against stack smashing attack."
|
|
}
|
|
},
|
|
"pthread": {
|
|
"LIBC_CONF_TIMEOUT_ENSURE_MONOTONICITY": {
|
|
"value": true,
|
|
"doc": "Automatically adjust timeout to CLOCK_MONOTONIC (default to true). POSIX API may require CLOCK_REALTIME, which can be unstable and leading to unexpected behavior. This option will convert the real-time timestamp to monotonic timestamp relative to the time of call."
|
|
},
|
|
"LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT": {
|
|
"value": 100,
|
|
"doc": "Default number of spins before blocking if a mutex is in contention (default to 100)."
|
|
},
|
|
"LIBC_CONF_RWLOCK_DEFAULT_SPIN_COUNT": {
|
|
"value": 100,
|
|
"doc": "Default number of spins before blocking if a rwlock is in contention (default to 100)."
|
|
}
|
|
},
|
|
"math": {
|
|
"LIBC_CONF_MATH_OPTIMIZATIONS": {
|
|
"value": 0,
|
|
"doc": "Configure optimizations for math functions. Values accepted are LIBC_MATH_SKIP_ACCURATE_PASS, LIBC_MATH_SMALL_TABLES, LIBC_MATH_NO_ERRNO, LIBC_MATH_NO_EXCEPT, LIBC_MATH_FAST, LIBC_MATH_INTERMEDIATE_COMP_IN_FLOAT, and LIBC_MATH_ASSUME_ROUND_NEAREST_ONLY."
|
|
},
|
|
"LIBC_CONF_FREXP_INF_NAN_EXPONENT": {
|
|
"value": "",
|
|
"doc": "The value written back to the second parameter when calling frexp/frexpf/frexpl` with `+/-Inf`/`NaN` is unspecified. Configure an explicit exp value for Inf/NaN inputs."
|
|
},
|
|
"LIBC_CONF_MATH_USE_SYSTEM_FENV": {
|
|
"value": false,
|
|
"doc": "Use C standard fenv.h calls from the system libc instead our internal fenv implementations."
|
|
}
|
|
},
|
|
"qsort": {
|
|
"LIBC_CONF_QSORT_IMPL": {
|
|
"value": "LIBC_QSORT_QUICK_SORT",
|
|
"doc": "Configures sorting algorithm for qsort and qsort_r. Values accepted are LIBC_QSORT_QUICK_SORT, LIBC_QSORT_HEAP_SORT."
|
|
}
|
|
},
|
|
"setjmp": {
|
|
"LIBC_CONF_SETJMP_AARCH64_RESTORE_PLATFORM_REGISTER": {
|
|
"value": true,
|
|
"doc": "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."
|
|
}
|
|
},
|
|
"general": {
|
|
"LIBC_ADD_NULL_CHECKS": {
|
|
"value": true,
|
|
"doc": "Add nullptr checks in the library's implementations to some functions for which passing nullptr is undefined behavior."
|
|
}
|
|
},
|
|
"wctype": {
|
|
"LIBC_CONF_WCTYPE_MODE": {
|
|
"value": "LIBC_WCTYPE_MODE_ASCII",
|
|
"doc": "The implementation used for wctype, acceptable values are LIBC_WCTYPE_MODE_ASCII and LIBC_WCTYPE_MODE_UTF8."
|
|
}
|
|
},
|
|
"fenv": {
|
|
"LIBC_CONF_TRAP_ON_RAISE_FP_EXCEPT": {
|
|
"value": false,
|
|
"doc": "Trap with SIGFPE when feraiseexcept is called with unmasked floating point exceptions, similar to glibc's behavior. This is currently working only on x86 with SSE."
|
|
}
|
|
},
|
|
"assert": {
|
|
"LIBC_COPT_USE_C_ASSERT": {
|
|
"value": false,
|
|
"doc": "Use the system assert macro for LIBC_ASSERT."
|
|
}
|
|
}
|
|
}
|