[all-commits] [llvm/llvm-project] b53da7: [libc] Alternative algorithm for decimal FP printf...

Simon Tatham via All-commits all-commits at lists.llvm.org
Tue Feb 4 00:58:16 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b53da77c505a2d35452e161c844712afbc11f6a7
      https://github.com/llvm/llvm-project/commit/b53da77c505a2d35452e161c844712afbc11f6a7
  Author: Simon Tatham <simon.tatham at arm.com>
  Date:   2025-02-04 (Tue, 04 Feb 2025)

  Changed paths:
    M libc/config/config.json
    M libc/docs/configure.rst
    M libc/src/__support/CPP/algorithm.h
    M libc/src/__support/FPUtil/dyadic_float.h
    M libc/src/__support/big_int.h
    M libc/src/__support/sign.h
    M libc/src/stdio/printf_core/CMakeLists.txt
    M libc/src/stdio/printf_core/converter_atlas.h
    A libc/src/stdio/printf_core/float_dec_converter_limited.h
    M libc/test/src/stdio/CMakeLists.txt
    M libc/test/src/stdio/sprintf_test.cpp
    M libc/test/src/stdlib/CMakeLists.txt

  Log Message:
  -----------
  [libc] Alternative algorithm for decimal FP printf (#123643)

The existing options for bin→dec float conversion are all based on the
Ryū algorithm, which generates 9 output digits at a time using a table
lookup. For users who can't afford the space cost of the table, the
table-lookup subroutine is replaced with one that computes the needed
table entry on demand, but the algorithm is otherwise unmodified.

The performance problem with computing table entries on demand is that
now you need to calculate a power of 10 for each 9 digits you output.
But if you're calculating a custom power of 10 anyway, it's easier to
just compute one, and multiply the _whole_ mantissa by it.

This patch adds a header file alongside `float_dec_converter.h`, which
replaces the whole Ryū system instead of just the table-lookup routine,
implementing this alternative simpler algorithm. The result is accurate
enough to satisfy (minimally) the accuracy demands of IEEE 754-2019 even
in 128-bit long double. The new float128 test cases demonstrate this by
testing the cases closest to the 39-digit rounding boundary.

In my tests of generating 39 output digits (the maximum number supported
by this algorithm) this code is also both faster and smaller than the
USE_DYADIC_FLOAT version of the existing Ryū code.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list