[libc-commits] [llvm] [libc] [libc] Move printf long double to simple calc (PR #75414)

via libc-commits libc-commits at lists.llvm.org
Thu Dec 21 13:29:41 PST 2023


================
@@ -87,14 +87,25 @@ are not recommended to be adjusted except by persons familiar with the Printf
 Ryu Algorithm. Additionally they have no effect when float conversions are
 disabled.
 
+LIBC_COPT_FLOAT_TO_STR_NO_SPECIALIZE_LD
+---------------------------------------
+This flag disables the separate long double conversion implementation. It is
+not based on the Ryu algorithm, instead generating the digits by
+multiplying/dividing the written-out number by 10^9 to get blocks. It's
+significantly faster than INT_CALC, only about 10x slower than MEGA_TABLE,
----------------
michaelrj-google wrote:

10 times. It a lot, but only sort of. I separated out the decimal (%f) long double tests and ran them both with the new specialization and with the mega table with `-O3` in release mode. On my workstation the mega table version took ~400 microseconds and the new version took ~8000 microseconds.

The reason I think this is a worthwhile tradeoff is because the mega table takes up a lot of space. Just the converter (found in `build/libc/src/stdio/printf_core/CMakeFiles/libc.src.stdio.printf_core.converter.dir/`) takes up  ~5 megabytes with the mega table, but only ~150 kilobytes with the specialization.

The other option I was considering for saving space was using integer calculation (`INT_CALC`) which takes up more space (~200 Kb) and time (~7,500,000 microseconds) so in comparison the new version looks quite good.

https://github.com/llvm/llvm-project/pull/75414


More information about the libc-commits mailing list