204 changes: 102 additions & 102 deletions libc/docs/gpu/rpc.rst

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions libc/docs/gpu/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Testing Infrastructure
======================

The testing support in LLVM's libc implementation for GPUs is designed to mimic
the standard unit tests as much as possible. We use the :ref:`libc_gpu_rpc`
support to provide the necessary utilities like printing from the GPU. Execution
the standard unit tests as much as possible. We use the :ref:`libc_gpu_rpc`
support to provide the necessary utilities like printing from the GPU. Execution
is performed by emitting a ``_start`` kernel from the GPU
that is then called by an external loader utility. This is an example of how
this can be done manually:
Expand Down
18 changes: 9 additions & 9 deletions libc/docs/gpu/using.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Building the GPU library

LLVM's libc GPU support *must* be built with an up-to-date ``clang`` compiler
due to heavy reliance on ``clang``'s GPU support. This can be done automatically
using the LLVM runtimes support. The GPU build is done using cross-compilation
to the GPU architecture. This project currently supports AMD and NVIDIA GPUs
which can be targeted using the appropriate target name. The following
invocation will enable a cross-compiling build for the GPU architecture and
enable the ``libc`` project only for them.
using the LLVM runtimes support. The GPU build is done using cross-compilation
to the GPU architecture. This project currently supports AMD and NVIDIA GPUs
which can be targeted using the appropriate target name. The following
invocation will enable a cross-compiling build for the GPU architecture and
enable the ``libc`` project only for them.

.. code-block:: sh
Expand All @@ -29,8 +29,8 @@ enable the ``libc`` project only for them.
-DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" \
-DLLVM_ENABLE_RUNTIMES="openmp" \
-DCMAKE_BUILD_TYPE=<Debug|Release> \ # Select build type
-DCMAKE_INSTALL_PREFIX=<PATH> \ # Where 'libcgpu.a' will live
-DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=libc \
-DCMAKE_INSTALL_PREFIX=<PATH> \ # Where 'libcgpu.a' will live
-DRUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES=libc \
-DRUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES=libc \
-DLLVM_RUNTIME_TARGETS=default;amdgcn-amd-amdhsa;nvptx64-nvidia-cuda
$> ninja install
Expand All @@ -40,8 +40,8 @@ toolchain, we list them in ``LLVM_ENABLE_PROJECTS``. To ensure ``libc`` is built
using a compatible compiler and to support ``openmp`` offloading, we list them
in ``LLVM_ENABLE_RUNTIMES`` to build them after the enabled projects using the
newly built compiler. ``CMAKE_INSTALL_PREFIX`` specifies the installation
directory in which to install the ``libcgpu-nvptx.a`` and ``libcgpu-amdgpu.a``
libraries and headers along with LLVM. The generated headers will be placed in
directory in which to install the ``libcgpu-nvptx.a`` and ``libcgpu-amdgpu.a``
libraries and headers along with LLVM. The generated headers will be placed in
``include/<gpu-triple>``.

Usage
Expand Down
6 changes: 3 additions & 3 deletions libc/docs/libc_search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Type Name Available
============================ =========
ACTION |check|
ENTRY |check|
VISIT
VISIT
============================ =========

POSIX Standard Functions
Expand All @@ -42,8 +42,8 @@ hcreate |check|
hdestroy |check|
hsearch |check|
insque |check|
lfind
lsearch
lfind
lsearch
remque |check|
tdelete
tfind
Expand Down
6 changes: 3 additions & 3 deletions libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Implementation Status

* To check math functions enabled for Windows:

- `windows-x86_64 <https://github.com/llvm/llvm-project/tree/main/libc/config/windows/entrypoints.txt>`_
- `windows-x86_64 <https://github.com/llvm/llvm-project/tree/main/libc/config/windows/entrypoints.txt>`_

- windows-aarch64 - to be added

Expand All @@ -93,11 +93,11 @@ Implementation Status

* To check math functions enabled for GPU:

- `gpu-entrypoints <https://github.com/llvm/llvm-project/tree/main/libc/config/gpu/entrypoints.txt>`_
- `gpu-entrypoints <https://github.com/llvm/llvm-project/tree/main/libc/config/gpu/entrypoints.txt>`_

* To check math functions enabled for embedded system:

- `baremetal-aarch32 <https://github.com/llvm/llvm-project/tree/main/libc/config/baremetal/arm/entrypoints.txt>`_
- `baremetal-aarch32 <https://github.com/llvm/llvm-project/tree/main/libc/config/baremetal/arm/entrypoints.txt>`_

- baremetal-riscv32 - to be added

Expand Down
6 changes: 3 additions & 3 deletions libc/docs/math/log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Hence we have the following bound on `s`:
In order for `s` to exist, we need that:

.. math::
\frac{C - (k + 1) 2^{-M}}{1 + (k + 1) 2^{-M}} >
\frac{C - (k + 1) 2^{-M}}{1 + (k + 1) 2^{-M}} >
\frac{-C - k 2^{-M}}{1 + k 2^{-M}}
which is equivalent to:
Expand All @@ -135,7 +135,7 @@ side of `\text{(C1)}` is bounded by:

.. math::
2^{-M - 1} > \frac{2^{-M - 1}}{1 + (2k + 1) 2^{-M - 1}} \geq
\frac{2^{-M - 1}}{1 + (2^{M + 1} - 1) 2^{-M - 1}} > 2^{-M - 2}.
\frac{2^{-M - 1}}{1 + (2^{M + 1} - 1) 2^{-M - 1}} > 2^{-M - 2}.
Hence, from `\text{(C1)}`, being an exact power of 2, `C = 2^{-N}` is bounded below
by:
Expand Down Expand Up @@ -427,7 +427,7 @@ to look-up for the reduction constant `s_{i, k}`. In other word, `k` is given
by the formula:

.. math::
k = \left\lfloor 2^{N_i + M_i} u_i \right\rfloor
k = \left\lfloor 2^{N_i + M_i} u_i \right\rfloor
Notice that our reduction constant `s_{i, k}` must work for all `u_i` in the
interval `I = \{ v: k 2^{-N_i - M_i} \leq v < (k + 1) 2^{-N_i - M_i} \}`,
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/porting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ If you are starting to bring up LLVM's libc on a new operating system, the first
step is to add a directory for that OS in the ``libc/config`` directory. Both
`Linux <https://github.com/llvm/llvm-project/tree/main/libc/config/linux>`_ and
`Windows <https://github.com/llvm/llvm-project/tree/main/libc/config/windows>`_,
the two operating systems on which LLVM's libc is being actively developed,
the two operating systems on which LLVM's libc is being actively developed,
have their own config directory.

.. note:: Windows development is not as active as the development on Linux.
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/stdio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ funlockfile |check|
Operations on system files
==========================

These functions operate on files on the host's system, without using the
These functions operate on files on the host's system, without using the
``FILE`` object type. They only take the name of the file being operated on.

============= =========
Expand Down
14 changes: 7 additions & 7 deletions libc/docs/strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Function Name Available
============= =========
bzero |check|
bcmp |check|
bcopy |check|
bcopy |check|
memcpy |check|
memset |check|
memcmp |check|
Expand Down Expand Up @@ -99,14 +99,14 @@ These functions are not in strings.h, but are still primarily string
functions, and are therefore tracked along with the rest of the string
functions.

The String to float functions were implemented using the Eisel-Lemire algorithm
The String to float functions were implemented using the Eisel-Lemire algorithm
(read more about the algorithm here: `The Eisel-Lemire ParseNumberF64 Algorithm
<https://nigeltao.github.io/blog/2020/eisel-lemire.html>`_). This improved
the performance of string to float and double, and allowed it to complete this
comprehensive test 15% faster than glibc: `Parse Number FXX Test Data
<https://github.com/nigeltao/parse-number-fxx-test-data>`_. The test was done
<https://github.com/nigeltao/parse-number-fxx-test-data>`_. The test was done
with LLVM-libc built on 2022-04-14 and Debian GLibc version 2.33-6. The targets
``libc_str_to_float_comparison_test`` and
``libc_str_to_float_comparison_test`` and
``libc_system_str_to_float_comparison_test`` were built and run on the test data
10 times each, skipping the first run since it was an outlier.

Expand Down Expand Up @@ -142,7 +142,7 @@ strerror_r |check|
Localized String Functions
==========================

These functions require locale.h, and will be finished when locale support is
These functions require locale.h, and will be finished when locale support is
implemented in LLVM-libc.

============= =========
Expand All @@ -160,7 +160,7 @@ Many String functions have an equivalent _s version, which is intended to be
more secure and safe than the previous standard. These functions add runtime
error detection and overflow protection. While they can be seen as an
improvement, adoption remains relatively low among users. In addition, they are
being considered for removal, see
being considered for removal, see
`Field Experience With Annex K — Bounds Checking Interfaces
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm>`_. For these reasons,
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm>`_. For these reasons,
there is no ongoing work to implement them.
2 changes: 1 addition & 1 deletion libc/include/fcntl.h.def
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

%%public_api()

#endif // LLVM_LIBC_FCNTL_H
#endif // LLVM_LIBC_FCNTL_H
2 changes: 1 addition & 1 deletion libc/include/sched.h.def
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

%%public_api()

#endif // LLVM_LIBC_SCHED_H
#endif // LLVM_LIBC_SCHED_H
2 changes: 1 addition & 1 deletion libc/include/spawn.h.def
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

%%public_api()

#endif // LLVM_LIBC_SPAWN_H
#endif // LLVM_LIBC_SPAWN_H
2 changes: 1 addition & 1 deletion libc/spec/bsd_ext.td
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def BsdExtensions : StandardSpec<"BSDExtensions"> {
[], // Macros
[], // Types
[], // Enumerations
[
[
FunctionSpec<
"strlcat",
RetValSpec<SizeTType>,
Expand Down
10 changes: 5 additions & 5 deletions libc/spec/gnu_ext.td
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
FunctionSpec<
"hcreate_r",
RetValSpec<IntType>,
[
ArgSpec<SizeTType>,
[
ArgSpec<SizeTType>,
ArgSpec<StructHsearchDataPtr>
]
>,
Expand All @@ -117,7 +117,7 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
"hsearch_r",
RetValSpec<IntType>,
[
ArgSpec<EntryType>,
ArgSpec<EntryType>,
ArgSpec<ActionType>,
ArgSpec<EntryTypePtrPtr>,
ArgSpec<StructHsearchDataPtr>
Expand Down Expand Up @@ -207,8 +207,8 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
[], // Enumerations
[
FunctionSpec<
"qsort_r",
RetValSpec<VoidType>,
"qsort_r",
RetValSpec<VoidType>,
[ArgSpec<VoidPtr>, ArgSpec<SizeTType>, ArgSpec<SizeTType>, ArgSpec<QSortRCompareT>, ArgSpec<VoidPtr>]
>,
]
Expand Down
2 changes: 1 addition & 1 deletion libc/spec/llvm_libc_ext.td
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> {
>,
]
>;

HeaderSpec Sched = HeaderSpec<
"sched.h",
[], // Macros
Expand Down
4 changes: 2 additions & 2 deletions libc/spec/posix.td
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ def POSIX : StandardSpec<"POSIX"> {
"hsearch",
RetValSpec<EntryTypePtr>,
[
ArgSpec<EntryType>,
ArgSpec<EntryType>,
ArgSpec<ActionType>
]
>,
Expand All @@ -1339,7 +1339,7 @@ def POSIX : StandardSpec<"POSIX"> {
]
>,
]
>;
>;

HeaderSpec Termios = HeaderSpec<
"termios.h",
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/HashTable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ list(FIND TARGET_ENTRYPOINT_NAME_LIST getrandom getrandom_index)
if (NOT ${getrandom_index} EQUAL -1)
message(STATUS "Using getrandom for hashtable randomness")
set(randomness_compile_flags -DLIBC_HASHTABLE_USE_GETRANDOM)
set(randomness_extra_depends
set(randomness_extra_depends
libc.src.sys.random.getrandom libc.src.errno.errno)
endif()

Expand Down
2 changes: 1 addition & 1 deletion libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ add_entrypoint_object(
../sqrtf128.h
DEPENDS
libc.src.__support.macros.properties.float
libc.src.__support.FPUtil.sqrt
libc.src.__support.FPUtil.sqrt
COMPILE_OPTIONS
-O3
)
Expand Down
2 changes: 1 addition & 1 deletion libc/src/search/hsearch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
add_object_library(
global
SRCS
global.cpp
global.cpp
HDRS
global.h
)
2 changes: 1 addition & 1 deletion libc/src/stdio/printf_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ add_object_library(
)

if(NOT (TARGET libc.src.__support.File.file) AND LLVM_LIBC_FULL_BUILD)
# Not all platforms have a file implementation. If file is unvailable, and a
# Not all platforms have a file implementation. If file is unvailable, and a
# full build is requested, then we must skip all file based printf sections.
return()
endif()
Expand Down
2 changes: 1 addition & 1 deletion libc/src/stdio/scanf_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ add_object_library(
)

if(NOT (TARGET libc.src.__support.File.file) AND LLVM_LIBC_FULL_BUILD)
# Not all platforms have a file implementation. If file is unvailable, and a
# Not all platforms have a file implementation. If file is unvailable, and a
# full build is requested, then we must skip all file based printf sections.
return()
endif()
Expand Down
6 changes: 3 additions & 3 deletions libc/src/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
set(SCUDO_DEPS "")

include(${LIBC_SOURCE_DIR}/../compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake)

# scudo distinguishes riscv32 and riscv64, so we need to translate the architecture
set(LIBC_TARGET_ARCHITECTURE_FOR_SCUDO ${LIBC_TARGET_ARCHITECTURE})
if(LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
Expand All @@ -278,7 +278,7 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
endif()

if(NOT (LIBC_TARGET_ARCHITECTURE_FOR_SCUDO IN_LIST ALL_SCUDO_STANDALONE_SUPPORTED_ARCH))
message(FATAL_ERROR "Architecture ${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO} is not supported by SCUDO.
message(FATAL_ERROR "Architecture ${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO} is not supported by SCUDO.
Either disable LLVM_LIBC_INCLUDE_SCUDO or change your target architecture.")
endif()

Expand All @@ -290,7 +290,7 @@ if(LLVM_LIBC_INCLUDE_SCUDO)
RTGwpAsanBacktraceLibc.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
RTGwpAsanSegvHandler.${LIBC_TARGET_ARCHITECTURE_FOR_SCUDO}
)

add_entrypoint_external(
malloc
DEPENDS
Expand Down
2 changes: 1 addition & 1 deletion libc/src/wchar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_entrypoint_object(
wctob.cpp
HDRS
wctob.h
DEPENDS
DEPENDS
libc.include.stdio
libc.include.wchar
libc.src.__support.wctype_utils
Expand Down
6 changes: 3 additions & 3 deletions libc/startup/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ function(merge_relocatable_object name)
add_dependencies(${fq_name} ${relocatable_target})
target_link_libraries(${fq_name} INTERFACE ${fq_link_libraries})
set_target_properties(
${fq_name}
${fq_name}
PROPERTIES
LINKER_LANGUAGE CXX
IMPORTED_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/${name}.o
TARGET_TYPE ${OBJECT_LIBRARY_TARGET_TYPE}
DEPS "${fq_link_libraries}"
)
)
endfunction()

function(add_startup_object name)
Expand All @@ -56,7 +56,7 @@ function(add_startup_object name)
)

get_fq_target_name(${name} fq_target_name)

add_object_library(
${name}
SRCS ${ADD_STARTUP_OBJECT_SRC}
Expand Down
2 changes: 1 addition & 1 deletion libc/test/integration/scudo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ target_link_libraries(libc-gwp-asan-uaf-should-crash
add_custom_command(TARGET libc-scudo-integration-test
POST_BUILD
COMMAND $<TARGET_FILE:libc-scudo-integration-test>
COMMENT "Run the test after it is built."
COMMENT "Run the test after it is built."
VERBATIM)
2 changes: 1 addition & 1 deletion libc/test/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ if(NOT LIBC_TARGET_OS_IS_GPU)
POST_BUILD
COMMAND $<TARGET_FILE:libc_str_to_float_comparison_test> ${float_test_file}
DEPENDS ${float_test_file}
COMMENT "Test the strtof and strtod implementations against precomputed results."
COMMENT "Test the strtof and strtod implementations against precomputed results."
VERBATIM)
endif()

Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/fenv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ add_libc_unittest(

if (NOT (LLVM_USE_SANITIZER OR (${LIBC_TARGET_OS} STREQUAL "windows")
OR (${LIBC_TARGET_OS} STREQUAL "darwin")))
# Sanitizers don't like SIGFPE. So, we will run the
# Sanitizers don't like SIGFPE. So, we will run the
# tests which raise SIGFPE only in non-sanitizer builds.
# The tests are also disabled for Windows and MacOS as they fail currently.
# TODO: Investigate and fix the windows failures and enable them for Windows
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/differential_testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function(add_diff_binary target_name)

set_target_properties(${fq_target_name}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

if(DIFF_CXX_STANDARD)
set_target_properties(
${fq_target_name}
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ if(NOT LIBC_TARGET_OS_IS_GPU)
libc.src.math.fmaxl
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
fmaxf128_test
SUITE
Expand Down
4 changes: 2 additions & 2 deletions libc/test/utils/UnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_libc_unittest(
SRCS
testfilter_test.cpp
DEPENDS
# TODO(michaelrj): Remove this dependancy. It's only here because all unit
# TODO(michaelrj): Remove this dependancy. It's only here because all unit
# tests must have at least one dependancy.
libc.src.__support.CPP.bit
libc.src.__support.CPP.bit
)
8 changes: 4 additions & 4 deletions libc/utils/MPFRWrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ if(LIBC_TESTS_CAN_USE_MPFR)
target_compile_options(libcMPFRWrapper PRIVATE -O3)
if (LLVM_LIBC_FULL_BUILD)
# It is not easy to make libcMPFRWrapper a standalone library because gmp.h may unconditionally
# pull in some STL headers. As a result, targets using this library will need to link against
# pull in some STL headers. As a result, targets using this library will need to link against
# C++ and unwind libraries. Since we are using MPFR anyway, we directly specifies the GNU toolchain.
target_link_libraries(libcMPFRWrapper PUBLIC -lstdc++ -lgcc_s)
endif()
add_dependencies(
libcMPFRWrapper
libc.src.__support.CPP.string_view
libc.src.__support.CPP.type_traits
libcMPFRWrapper
libc.src.__support.CPP.string_view
libc.src.__support.CPP.type_traits
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.fpbits_str
LibcTest.unit
Expand Down
2 changes: 1 addition & 1 deletion libc/utils/gpu/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target_compile_definitions(llvmlibc_rpc_server PUBLIC

# This utility needs to be compiled for the host system when cross compiling.
if(LLVM_RUNTIMES_TARGET OR LIBC_TARGET_TRIPLE)
target_compile_options(llvmlibc_rpc_server PUBLIC
target_compile_options(llvmlibc_rpc_server PUBLIC
--target=${LLVM_HOST_TRIPLE})
target_link_libraries(llvmlibc_rpc_server PUBLIC
"--target=${LLVM_HOST_TRIPLE}")
Expand Down
24 changes: 12 additions & 12 deletions libc/utils/mathtools/GenerateHPDConstants.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
from math import *

"""
This script is used to generate a table used by
This script is used to generate a table used by
libc/src/__support/high_precision_decimal.h.
For the ith entry in the table there are two values (indexed starting at 0).
The first value is the number of digits longer the second value would be if
multiplied by 2^i.
The second value is the smallest number that would create that number of
additional digits (which in base ten is always 5^i). Anything less creates one
The second value is the smallest number that would create that number of
additional digits (which in base ten is always 5^i). Anything less creates one
fewer digit.
As an example, the 3rd entry in the table is {1, "125"}. This means that if
As an example, the 3rd entry in the table is {1, "125"}. This means that if
125 is multiplied by 2^3 = 8, it will have exactly one more digit.
Multiplying it out we get 125 * 8 = 1000. 125 is the smallest number that gives
that extra digit, for example 124 * 8 = 992, and all larger 3 digit numbers
also give only one extra digit when multiplied by 8, for example 8 * 999 = 7992.
This makes sense because 5^3 * 2^3 = 10^3, the smallest 4 digit number.
For numbers with more digits we can ignore the digits past what's in the second
value, since the most significant digits determine how many extra digits there
will be. Looking at the previous example, if we have 1000, and we look at just
the first 3 digits (since 125 has 3 digits), we see that 100 < 125, so we get
one fewer than 1 extra digits, which is 0.
Multiplying it out we get 1000 * 8 = 8000, which fits the expectation.
Another few quick examples:
value, since the most significant digits determine how many extra digits there
will be. Looking at the previous example, if we have 1000, and we look at just
the first 3 digits (since 125 has 3 digits), we see that 100 < 125, so we get
one fewer than 1 extra digits, which is 0.
Multiplying it out we get 1000 * 8 = 8000, which fits the expectation.
Another few quick examples:
For 1255, 125 !< 125, so 1 digit more: 1255 * 8 = 10040
For 9999, 999 !< 125, so 1 digit more: 9999 * 8 = 79992
Now let's try an example with the 10th entry: {4, "9765625"}. This one means
that 9765625 * 2^10 will have 4 extra digits.
Now let's try an example with the 10th entry: {4, "9765625"}. This one means
that 9765625 * 2^10 will have 4 extra digits.
Let's skip straight to the examples:
For 1, 1 < 9765625, so 4-1=3 extra digits: 1 * 2^10 = 1024, 1 digit to 4 digits is a difference of 3.
For 9765624, 9765624 < 9765625 so 3 extra digits: 9765624 * 1024 = 9999998976, 7 digits to 10 digits is a difference of 3.
Expand Down
2 changes: 1 addition & 1 deletion libc/utils/mathtools/ryu_tablegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
This file is used to generate the tables of values in
This file is used to generate the tables of values in
src/__support/ryu_constants.h and ryu_long_double constants.h. To use it, set
the constants at the top of the file to the values you want to use for the Ryu
algorithm, then run this file. It will output the appropriate tables to stdout,
Expand Down