[libc-commits] [libc] [libc] Add missing shared_math docs in `add_math_function.md` (PR #188026)
via libc-commits
libc-commits at lists.llvm.org
Mon Mar 23 05:36:09 PDT 2026
https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/188026
>From 0b1c54f3daf537f1b3acafa4ed57c180fcde516c Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 23 Mar 2026 17:16:07 +0530
Subject: [PATCH 1/6] feat: added missing doc for shared math test
---
libc/src/math/docs/add_math_function.md | 480 ++++++++++++------------
1 file changed, 245 insertions(+), 235 deletions(-)
diff --git a/libc/src/math/docs/add_math_function.md b/libc/src/math/docs/add_math_function.md
index ae45d595bbdd6..0b1403d1b0c0c 100644
--- a/libc/src/math/docs/add_math_function.md
+++ b/libc/src/math/docs/add_math_function.md
@@ -1,235 +1,245 @@
-# How to add a new math function to LLVM-libc
-
-This document is to serve as a cookbook for adding a new math function
-implementation to LLVM libc. To add a new function, apart from the actual
-implementation, one has to follow a few other steps to setup proper registration
-and shipping of the new function. Each of these steps will be described in
-detail below.
-
-## Registration
-
-To register the function's entry points for supported OSes and architectures,
-together with its specifications:
-
-- Add entry points `libc.src.math.func` to the following files:
-```
- libc/config/linux/<arch>/entrypoints.txt
- libc/config/windows/entrypoints.txt
-```
-- Add function specs to the file:
-```
- libc/include/math.yaml
-```
-
-## Implementation
-
-The function's actual implementation is defined in an internal header, while the public entry point is a thin wrapper
-added to the following locations:
-
-- Add the core math logic (under `LIBC_NAMESPACE::math` namespace) to:
-```
- libc/src/__support/math/<func>.h
-```
-- Add the corresponding `add_header_library` to:
-```
- libc/src/__support/math/CMakeLists.txt
-```
-- Add `add_math_entrypoint_object(<func>)` to:
-```
- libc/src/math/CMakeLists.txt
-```
-- Add function declaration (under `LIBC_NAMESPACE` namespace) to:
-```
- libc/src/math/<func>.h
-```
-- Add function definition (calling the __support implementation) to:
-```
- libc/src/math/generic/<func>.cpp
-```
-- Add the corresponding `add_entrypoint_object` to:
-```
- libc/src/math/generic/CMakeLists.txt
-```
-- Add architectural specific implementations to:
-```
- libc/src/math/<arch>/<func>.cpp
-```
-
-### Shared Math Library
-
-If the function should be available to internal LLVM projects:
-
-- Include the support header in:
-```
- libc/shared/math.h
-```
-- Add a header that exports the function via using in:
-```
- libc/shared/math/<func>.h
-```
-- add a simple test case to
-```
- libc/test/shared/shared_math_test.cpp
-```
-- add the corresponding `libc_support_library` and `libc_math_function` to:
-```
-utils/bazel/llvm-project-overlay/libc/BUILD.bazel
-```
-
-### Floating point utility
-
-- Floating point utilities and math functions that are also used internally are
-located at:
-```
- libc/src/__support/FPUtils
-```
-- These are preferred to be included as header-only.
-- To manipulate bits of floating point numbers, use the template class
-`LIBC_NAMESPACE::fputil::FPBits<>` in the header file:
-```
- libc/src/__support/FPUtils/FPBits.h
-```
-
-## Testing
-
-### MPFR utility
-
-In addition to the normal testing macros such as `EXPECT_EQ, ASSERT_THAT, ...`
-there are two special macros `ASSERT_MPFR_MATCH` and `EXPECT_MPFR_MATCH` to
-compare your outputs with the corresponding MPFR function. In
-order for your new function to be supported by these two macros,
-the following files will need to be updated:
-
-- Add the function enum to `LIBC_NAMESPACE::testing::mpfr::Operation` in the
-header file:
-```
- libc/utils/MPFRWrapper/MPFRUtils.h
-```
-- Add support for `func` in the `MPFRNumber` class and the corresponding link
-between the enum and its call to the file:
-```
- libc/utils/MPFRWrapper/MPFRUtils.cpp
-```
-
-### Unit tests
-
-Besides the usual testing macros like `EXPECT_EQ, ASSERT_TRUE, ...` there are
-testing macros specifically used for floating point values, such as
-`EXPECT_FP_EQ, ASSERT_FP_LE, ...`
-
-- Add smoke tests (simple cases and zeros / inf / nan inputs or outputs) to:
-```
- libc/test/src/math/smoke/<func>_test.cpp
-```
-- Add unit test that might require MPFR to:
-```
- libc/test/src/math/<func>_test.cpp
-```
-- Add the corresponding entry points to:
-```
- libc/test/src/math/smoke/CMakeLists.txt
- libc/test/src/math/CMakeLists.txt
-```
-
-### Exhaustive tests
-
-Exhaustive tests are long-running tests that are not included when you run
-`ninja check-libc`. These exhaustive tests are added and manually run in
-order to find exceptional cases for your function's implementation.
-
-- Add an exhaustive test to:
-```
- libc/test/src/math/exhaustive/<func>_test.cpp
-```
-- Add the corresponding entry point to:
-```
- libc/test/src/math/exhaustive/CMakeLists.txt
-```
-- The template class `LlvmLibcExhaustiveMathTest` located at:
-```
- libc/test/src/math/exhaustive/exhaustive_test.h
-```
-can be used for conveniently parallelizing the exhaustive tests.
-
-### Performance tests
-
-Performance tests compare your function's implementation with the system libc
-implementation (which is very often glibc).
-
-- Add a performance test to:
-```
- libc/test/src/math/performance_testing/<func>_perf.cpp
-```
-- Add the corresponding entry point to:
-```
- libc/test/src/math/performance_testing/CMakeLists.txt
-```
-
-## Build and Run
-
-- Check out the LLVM source tree:
-```
- $ git clone https://github.com/llvm/llvm-project.git
-```
-
-- Compiler Requirements: The libc implementation should support compiling with both Clang and GCC (12.2).
-
-- Setup projects with CMake:
-```
- $ cd llvm-project
- $ mkdir build
- $ cd build
- $ cmake ../llvm -G Ninja \
- -DLLVM_ENABLE_RUNTIMES="libc" \
- -DCMAKE_BUILD_TYPE=Debug \
- -DCMAKE_C_COMPILER=clang \
- -DCMAKE_CXX_COMPILER=clang++
- $ cd runtimes/runtimes-bins/
-```
-
-- Build the whole `libc`:
-```
- $ ninja libc
-```
-
-- Run all unit tests:
-```
- $ ninja check-libc
-```
-
-- Run math smoke tests only:
-```
- $ ninja libc-math-smoke-tests
-```
-
-- Run math smoke and unit tests:
-```
- $ ninja libc-math-unittests
-```
-
-- Build and Run a specific unit test:
-```
- $ ninja libc.test.src.math.<func>_test.__unit__
- $ projects/libc/test/src/math/libc.test.src.math.<func>_test
-```
-
-- Build and Run exhaustive test (might take hours to run):
-```
- $ ninja libc.test.src.math.exhaustive.<func>_test.__unit__
- $ projects/libc/test/src/math/exhaustive/libc.test.src.math.exhaustive.<func>_test.__unit__
-```
-
-- Build and Run performance test:
-```
- $ ninja libc.test.src.math.performance_testing.<func>_perf
- $ projects/libc/test/src/math/performance_testing/libc.test.src.math.performance_testing.<func>_perf
- $ cat <func>_perf.log
-```
-
-## Code reviews
-
-We use GitHub's inbuilt pull request system for code review:
-```
- https://docs.github.com/articles/about-collaborative-development-models
- https://docs.github.com/articles/about-pull-requests
-```
+# How to add a new math function to LLVM-libc
+
+This document is to serve as a cookbook for adding a new math function
+implementation to LLVM libc. To add a new function, apart from the actual
+implementation, one has to follow a few other steps to setup proper registration
+and shipping of the new function. Each of these steps will be described in
+detail below.
+
+## Registration
+
+To register the function's entry points for supported OSes and architectures,
+together with its specifications:
+
+- Add entry points `libc.src.math.<func>` to the following files:
+```
+ libc/config/linux/<arch>/entrypoints.txt
+ libc/config/windows/entrypoints.txt
+```
+- Add function specs to the file:
+```
+ libc/include/math.yaml
+```
+
+## Implementation
+
+The function's actual implementation is defined in an internal header, while the public entry point is a thin wrapper
+added to the following locations:
+
+- Add the core math logic (under `LIBC_NAMESPACE::math` namespace) to:
+```
+ libc/src/__support/math/<func>.h
+```
+- Add the corresponding `add_header_library` to:
+```
+ libc/src/__support/math/CMakeLists.txt
+```
+- Add `add_math_entrypoint_object(<func>)` to:
+```
+ libc/src/math/CMakeLists.txt
+```
+- Add function declaration (under `LIBC_NAMESPACE` namespace) to:
+```
+ libc/src/math/<func>.h
+```
+- Add function definition (calling the __support implementation) to:
+```
+ libc/src/math/generic/<func>.cpp
+```
+- Add the corresponding `add_entrypoint_object` to:
+```
+ libc/src/math/generic/CMakeLists.txt
+```
+- Add architectural specific implementations to:
+```
+ libc/src/math/<arch>/<func>.cpp
+```
+
+### Shared Math Library
+
+If the function should be available to internal LLVM projects:
+
+- Include the support header in:
+```
+ libc/shared/math.h
+```
+- Add a header that exports the function via using in:
+```
+ libc/shared/math/<func>.h
+```
+- Add a header that exports the function via using in:
+```
+ libc/shared/math/<func>.h
+```
+- Add the corresponding entry `libc.src.__support.math.<func>` to:
+```
+ libc/test/shared/CMakeLists.txt
+```
+- Add the corresponding `libc_support_library` and `libc_math_function` to:
+```
+utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+```s
+
+### Floating point utility
+
+- Floating point utilities and math functions that are also used internally are
+located at:
+```
+ libc/src/__support/FPUtils
+```
+- These are preferred to be included as header-only.
+- To manipulate bits of floating point numbers, use the template class
+`LIBC_NAMESPACE::fputil::FPBits<>` in the header file:
+```
+ libc/src/__support/FPUtils/FPBits.h
+```
+
+## Testing
+
+### MPFR utility
+
+In addition to the normal testing macros such as `EXPECT_EQ, ASSERT_THAT, ...`
+there are two special macros `ASSERT_MPFR_MATCH` and `EXPECT_MPFR_MATCH` to
+compare your outputs with the corresponding MPFR function. In
+order for your new function to be supported by these two macros,
+the following files will need to be updated:
+
+- Add the function enum to `LIBC_NAMESPACE::testing::mpfr::Operation` in the
+header file:
+```
+ libc/utils/MPFRWrapper/MPFRUtils.h
+```
+- Add support for `func` in the `MPFRNumber` class and the corresponding link
+between the enum and its call to the file:
+```
+ libc/utils/MPFRWrapper/MPFRUtils.cpp
+```
+
+### Unit tests
+
+Besides the usual testing macros like `EXPECT_EQ, ASSERT_TRUE, ...` there are
+testing macros specifically used for floating point values, such as
+`EXPECT_FP_EQ, ASSERT_FP_LE, ...`
+
+- Add smoke tests (simple cases and zeros / inf / nan inputs or outputs) to:
+```
+ libc/test/src/math/smoke/<func>_test.cpp
+```
+- Add unit test that might require MPFR to:
+```
+ libc/test/src/math/<func>_test.cpp
+```
+- Add the corresponding entry points to:
+```
+ libc/test/src/math/smoke/CMakeLists.txt
+ libc/test/src/math/CMakeLists.txt
+```
+
+### Exhaustive tests
+
+Exhaustive tests are long-running tests that are not included when you run
+`ninja check-libc`. These exhaustive tests are added and manually run in
+order to find exceptional cases for your function's implementation.
+
+- Add an exhaustive test to:
+```
+ libc/test/src/math/exhaustive/<func>_test.cpp
+```
+- Add the corresponding entry point to:
+```
+ libc/test/src/math/exhaustive/CMakeLists.txt
+```
+- The template class `LlvmLibcExhaustiveMathTest` located at:
+```
+ libc/test/src/math/exhaustive/exhaustive_test.h
+```
+can be used for conveniently parallelizing the exhaustive tests.
+
+### Performance tests
+
+Performance tests compare your function's implementation with the system libc
+implementation (which is very often glibc).
+
+- Add a performance test to:
+```
+ libc/test/src/math/performance_testing/<func>_perf.cpp
+```
+- Add the corresponding entry point to:
+```
+ libc/test/src/math/performance_testing/CMakeLists.txt
+```
+
+## Build and Run
+
+- Check out the LLVM source tree:
+```
+ $ git clone https://github.com/llvm/llvm-project.git
+```
+
+- Compiler Requirements: The libc implementation should support compiling with both Clang and GCC (12.2).
+
+- Setup projects with CMake:
+```
+ $ cd llvm-project
+ $ mkdir build
+ $ cd build
+ $ cmake ../llvm -G Ninja \
+ -DLLVM_ENABLE_RUNTIMES="libc" \
+ -DCMAKE_BUILD_TYPE=Debug \
+ -DCMAKE_C_COMPILER=clang \
+ -DCMAKE_CXX_COMPILER=clang++
+ $ cd runtimes/runtimes-bins/
+```
+
+- Build the whole `libc`:
+```
+ $ ninja libc
+```
+
+- Run all unit tests:
+```
+ $ ninja check-libc
+```
+
+- Run math smoke tests only:
+```
+ $ ninja libc-math-smoke-tests
+```
+
+- Run math smoke and unit tests:
+```
+ $ ninja libc-math-unittests
+```
+
+- Build and Run a specific unit test:
+```
+ $ ninja libc.test.src.math.<func>_test.__unit__
+ $ projects/libc/test/src/math/libc.test.src.math.<func>_test.__unit__
+```
+
+- Build and Run shared math test:
+```
+ $ ninja libc.test.shared.shared_math_test.__unit__
+ $ projects/libc/test/shared/libc.test.shared.shared_math_test.__unit__
+```
+
+- Build and Run exhaustive test (might take hours to run):
+```
+ $ ninja libc.test.src.math.exhaustive.<func>_test.__unit__
+ $ projects/libc/test/src/math/exhaustive/libc.test.src.math.exhaustive.<func>_test.__unit__
+```
+
+- Build and Run performance test:
+```
+ $ ninja libc.test.src.math.performance_testing.<func>_perf
+ $ projects/libc/test/src/math/performance_testing/libc.test.src.math.performance_testing.<func>_perf
+ $ cat <func>_perf.log
+```
+
+## Code reviews
+
+We use GitHub's inbuilt pull request system for code review:
+```
+ https://docs.github.com/articles/about-collaborative-development-models
+ https://docs.github.com/articles/about-pull-requests
+```
>From 60a3f778f58e4583349fe03b3c2df0b152e8b599 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 23 Mar 2026 17:17:39 +0530
Subject: [PATCH 2/6] chore: lf
---
libc/src/math/docs/add_math_function.md | 490 ++++++++++++------------
1 file changed, 245 insertions(+), 245 deletions(-)
diff --git a/libc/src/math/docs/add_math_function.md b/libc/src/math/docs/add_math_function.md
index 0b1403d1b0c0c..0406f71036d41 100644
--- a/libc/src/math/docs/add_math_function.md
+++ b/libc/src/math/docs/add_math_function.md
@@ -1,245 +1,245 @@
-# How to add a new math function to LLVM-libc
-
-This document is to serve as a cookbook for adding a new math function
-implementation to LLVM libc. To add a new function, apart from the actual
-implementation, one has to follow a few other steps to setup proper registration
-and shipping of the new function. Each of these steps will be described in
-detail below.
-
-## Registration
-
-To register the function's entry points for supported OSes and architectures,
-together with its specifications:
-
-- Add entry points `libc.src.math.<func>` to the following files:
-```
- libc/config/linux/<arch>/entrypoints.txt
- libc/config/windows/entrypoints.txt
-```
-- Add function specs to the file:
-```
- libc/include/math.yaml
-```
-
-## Implementation
-
-The function's actual implementation is defined in an internal header, while the public entry point is a thin wrapper
-added to the following locations:
-
-- Add the core math logic (under `LIBC_NAMESPACE::math` namespace) to:
-```
- libc/src/__support/math/<func>.h
-```
-- Add the corresponding `add_header_library` to:
-```
- libc/src/__support/math/CMakeLists.txt
-```
-- Add `add_math_entrypoint_object(<func>)` to:
-```
- libc/src/math/CMakeLists.txt
-```
-- Add function declaration (under `LIBC_NAMESPACE` namespace) to:
-```
- libc/src/math/<func>.h
-```
-- Add function definition (calling the __support implementation) to:
-```
- libc/src/math/generic/<func>.cpp
-```
-- Add the corresponding `add_entrypoint_object` to:
-```
- libc/src/math/generic/CMakeLists.txt
-```
-- Add architectural specific implementations to:
-```
- libc/src/math/<arch>/<func>.cpp
-```
-
-### Shared Math Library
-
-If the function should be available to internal LLVM projects:
-
-- Include the support header in:
-```
- libc/shared/math.h
-```
-- Add a header that exports the function via using in:
-```
- libc/shared/math/<func>.h
-```
-- Add a header that exports the function via using in:
-```
- libc/shared/math/<func>.h
-```
-- Add the corresponding entry `libc.src.__support.math.<func>` to:
-```
- libc/test/shared/CMakeLists.txt
-```
-- Add the corresponding `libc_support_library` and `libc_math_function` to:
-```
-utils/bazel/llvm-project-overlay/libc/BUILD.bazel
-```s
-
-### Floating point utility
-
-- Floating point utilities and math functions that are also used internally are
-located at:
-```
- libc/src/__support/FPUtils
-```
-- These are preferred to be included as header-only.
-- To manipulate bits of floating point numbers, use the template class
-`LIBC_NAMESPACE::fputil::FPBits<>` in the header file:
-```
- libc/src/__support/FPUtils/FPBits.h
-```
-
-## Testing
-
-### MPFR utility
-
-In addition to the normal testing macros such as `EXPECT_EQ, ASSERT_THAT, ...`
-there are two special macros `ASSERT_MPFR_MATCH` and `EXPECT_MPFR_MATCH` to
-compare your outputs with the corresponding MPFR function. In
-order for your new function to be supported by these two macros,
-the following files will need to be updated:
-
-- Add the function enum to `LIBC_NAMESPACE::testing::mpfr::Operation` in the
-header file:
-```
- libc/utils/MPFRWrapper/MPFRUtils.h
-```
-- Add support for `func` in the `MPFRNumber` class and the corresponding link
-between the enum and its call to the file:
-```
- libc/utils/MPFRWrapper/MPFRUtils.cpp
-```
-
-### Unit tests
-
-Besides the usual testing macros like `EXPECT_EQ, ASSERT_TRUE, ...` there are
-testing macros specifically used for floating point values, such as
-`EXPECT_FP_EQ, ASSERT_FP_LE, ...`
-
-- Add smoke tests (simple cases and zeros / inf / nan inputs or outputs) to:
-```
- libc/test/src/math/smoke/<func>_test.cpp
-```
-- Add unit test that might require MPFR to:
-```
- libc/test/src/math/<func>_test.cpp
-```
-- Add the corresponding entry points to:
-```
- libc/test/src/math/smoke/CMakeLists.txt
- libc/test/src/math/CMakeLists.txt
-```
-
-### Exhaustive tests
-
-Exhaustive tests are long-running tests that are not included when you run
-`ninja check-libc`. These exhaustive tests are added and manually run in
-order to find exceptional cases for your function's implementation.
-
-- Add an exhaustive test to:
-```
- libc/test/src/math/exhaustive/<func>_test.cpp
-```
-- Add the corresponding entry point to:
-```
- libc/test/src/math/exhaustive/CMakeLists.txt
-```
-- The template class `LlvmLibcExhaustiveMathTest` located at:
-```
- libc/test/src/math/exhaustive/exhaustive_test.h
-```
-can be used for conveniently parallelizing the exhaustive tests.
-
-### Performance tests
-
-Performance tests compare your function's implementation with the system libc
-implementation (which is very often glibc).
-
-- Add a performance test to:
-```
- libc/test/src/math/performance_testing/<func>_perf.cpp
-```
-- Add the corresponding entry point to:
-```
- libc/test/src/math/performance_testing/CMakeLists.txt
-```
-
-## Build and Run
-
-- Check out the LLVM source tree:
-```
- $ git clone https://github.com/llvm/llvm-project.git
-```
-
-- Compiler Requirements: The libc implementation should support compiling with both Clang and GCC (12.2).
-
-- Setup projects with CMake:
-```
- $ cd llvm-project
- $ mkdir build
- $ cd build
- $ cmake ../llvm -G Ninja \
- -DLLVM_ENABLE_RUNTIMES="libc" \
- -DCMAKE_BUILD_TYPE=Debug \
- -DCMAKE_C_COMPILER=clang \
- -DCMAKE_CXX_COMPILER=clang++
- $ cd runtimes/runtimes-bins/
-```
-
-- Build the whole `libc`:
-```
- $ ninja libc
-```
-
-- Run all unit tests:
-```
- $ ninja check-libc
-```
-
-- Run math smoke tests only:
-```
- $ ninja libc-math-smoke-tests
-```
-
-- Run math smoke and unit tests:
-```
- $ ninja libc-math-unittests
-```
-
-- Build and Run a specific unit test:
-```
- $ ninja libc.test.src.math.<func>_test.__unit__
- $ projects/libc/test/src/math/libc.test.src.math.<func>_test.__unit__
-```
-
-- Build and Run shared math test:
-```
- $ ninja libc.test.shared.shared_math_test.__unit__
- $ projects/libc/test/shared/libc.test.shared.shared_math_test.__unit__
-```
-
-- Build and Run exhaustive test (might take hours to run):
-```
- $ ninja libc.test.src.math.exhaustive.<func>_test.__unit__
- $ projects/libc/test/src/math/exhaustive/libc.test.src.math.exhaustive.<func>_test.__unit__
-```
-
-- Build and Run performance test:
-```
- $ ninja libc.test.src.math.performance_testing.<func>_perf
- $ projects/libc/test/src/math/performance_testing/libc.test.src.math.performance_testing.<func>_perf
- $ cat <func>_perf.log
-```
-
-## Code reviews
-
-We use GitHub's inbuilt pull request system for code review:
-```
- https://docs.github.com/articles/about-collaborative-development-models
- https://docs.github.com/articles/about-pull-requests
-```
+# How to add a new math function to LLVM-libc
+
+This document is to serve as a cookbook for adding a new math function
+implementation to LLVM libc. To add a new function, apart from the actual
+implementation, one has to follow a few other steps to setup proper registration
+and shipping of the new function. Each of these steps will be described in
+detail below.
+
+## Registration
+
+To register the function's entry points for supported OSes and architectures,
+together with its specifications:
+
+- Add entry points `libc.src.math.<func>` to the following files:
+```
+ libc/config/linux/<arch>/entrypoints.txt
+ libc/config/windows/entrypoints.txt
+```
+- Add function specs to the file:
+```
+ libc/include/math.yaml
+```
+
+## Implementation
+
+The function's actual implementation is defined in an internal header, while the public entry point is a thin wrapper
+added to the following locations:
+
+- Add the core math logic (under `LIBC_NAMESPACE::math` namespace) to:
+```
+ libc/src/__support/math/<func>.h
+```
+- Add the corresponding `add_header_library` to:
+```
+ libc/src/__support/math/CMakeLists.txt
+```
+- Add `add_math_entrypoint_object(<func>)` to:
+```
+ libc/src/math/CMakeLists.txt
+```
+- Add function declaration (under `LIBC_NAMESPACE` namespace) to:
+```
+ libc/src/math/<func>.h
+```
+- Add function definition (calling the __support implementation) to:
+```
+ libc/src/math/generic/<func>.cpp
+```
+- Add the corresponding `add_entrypoint_object` to:
+```
+ libc/src/math/generic/CMakeLists.txt
+```
+- Add architectural specific implementations to:
+```
+ libc/src/math/<arch>/<func>.cpp
+```
+
+### Shared Math Library
+
+If the function should be available to internal LLVM projects:
+
+- Include the support header in:
+```
+ libc/shared/math.h
+```
+- Add a header that exports the function via using in:
+```
+ libc/shared/math/<func>.h
+```
+- Add a header that exports the function via using in:
+```
+ libc/shared/math/<func>.h
+```
+- Add the corresponding entry `libc.src.__support.math.<func>` to:
+```
+ libc/test/shared/CMakeLists.txt
+```
+- Add the corresponding `libc_support_library` and `libc_math_function` to:
+```
+utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+```s
+
+### Floating point utility
+
+- Floating point utilities and math functions that are also used internally are
+located at:
+```
+ libc/src/__support/FPUtils
+```
+- These are preferred to be included as header-only.
+- To manipulate bits of floating point numbers, use the template class
+`LIBC_NAMESPACE::fputil::FPBits<>` in the header file:
+```
+ libc/src/__support/FPUtils/FPBits.h
+```
+
+## Testing
+
+### MPFR utility
+
+In addition to the normal testing macros such as `EXPECT_EQ, ASSERT_THAT, ...`
+there are two special macros `ASSERT_MPFR_MATCH` and `EXPECT_MPFR_MATCH` to
+compare your outputs with the corresponding MPFR function. In
+order for your new function to be supported by these two macros,
+the following files will need to be updated:
+
+- Add the function enum to `LIBC_NAMESPACE::testing::mpfr::Operation` in the
+header file:
+```
+ libc/utils/MPFRWrapper/MPFRUtils.h
+```
+- Add support for `func` in the `MPFRNumber` class and the corresponding link
+between the enum and its call to the file:
+```
+ libc/utils/MPFRWrapper/MPFRUtils.cpp
+```
+
+### Unit tests
+
+Besides the usual testing macros like `EXPECT_EQ, ASSERT_TRUE, ...` there are
+testing macros specifically used for floating point values, such as
+`EXPECT_FP_EQ, ASSERT_FP_LE, ...`
+
+- Add smoke tests (simple cases and zeros / inf / nan inputs or outputs) to:
+```
+ libc/test/src/math/smoke/<func>_test.cpp
+```
+- Add unit test that might require MPFR to:
+```
+ libc/test/src/math/<func>_test.cpp
+```
+- Add the corresponding entry points to:
+```
+ libc/test/src/math/smoke/CMakeLists.txt
+ libc/test/src/math/CMakeLists.txt
+```
+
+### Exhaustive tests
+
+Exhaustive tests are long-running tests that are not included when you run
+`ninja check-libc`. These exhaustive tests are added and manually run in
+order to find exceptional cases for your function's implementation.
+
+- Add an exhaustive test to:
+```
+ libc/test/src/math/exhaustive/<func>_test.cpp
+```
+- Add the corresponding entry point to:
+```
+ libc/test/src/math/exhaustive/CMakeLists.txt
+```
+- The template class `LlvmLibcExhaustiveMathTest` located at:
+```
+ libc/test/src/math/exhaustive/exhaustive_test.h
+```
+can be used for conveniently parallelizing the exhaustive tests.
+
+### Performance tests
+
+Performance tests compare your function's implementation with the system libc
+implementation (which is very often glibc).
+
+- Add a performance test to:
+```
+ libc/test/src/math/performance_testing/<func>_perf.cpp
+```
+- Add the corresponding entry point to:
+```
+ libc/test/src/math/performance_testing/CMakeLists.txt
+```
+
+## Build and Run
+
+- Check out the LLVM source tree:
+```
+ $ git clone https://github.com/llvm/llvm-project.git
+```
+
+- Compiler Requirements: The libc implementation should support compiling with both Clang and GCC (12.2).
+
+- Setup projects with CMake:
+```
+ $ cd llvm-project
+ $ mkdir build
+ $ cd build
+ $ cmake ../llvm -G Ninja \
+ -DLLVM_ENABLE_RUNTIMES="libc" \
+ -DCMAKE_BUILD_TYPE=Debug \
+ -DCMAKE_C_COMPILER=clang \
+ -DCMAKE_CXX_COMPILER=clang++
+ $ cd runtimes/runtimes-bins/
+```
+
+- Build the whole `libc`:
+```
+ $ ninja libc
+```
+
+- Run all unit tests:
+```
+ $ ninja check-libc
+```
+
+- Run math smoke tests only:
+```
+ $ ninja libc-math-smoke-tests
+```
+
+- Run math smoke and unit tests:
+```
+ $ ninja libc-math-unittests
+```
+
+- Build and Run a specific unit test:
+```
+ $ ninja libc.test.src.math.<func>_test.__unit__
+ $ projects/libc/test/src/math/libc.test.src.math.<func>_test.__unit__
+```
+
+- Build and Run shared math test:
+```
+ $ ninja libc.test.shared.shared_math_test.__unit__
+ $ projects/libc/test/shared/libc.test.shared.shared_math_test.__unit__
+```
+
+- Build and Run exhaustive test (might take hours to run):
+```
+ $ ninja libc.test.src.math.exhaustive.<func>_test.__unit__
+ $ projects/libc/test/src/math/exhaustive/libc.test.src.math.exhaustive.<func>_test.__unit__
+```
+
+- Build and Run performance test:
+```
+ $ ninja libc.test.src.math.performance_testing.<func>_perf
+ $ projects/libc/test/src/math/performance_testing/libc.test.src.math.performance_testing.<func>_perf
+ $ cat <func>_perf.log
+```
+
+## Code reviews
+
+We use GitHub's inbuilt pull request system for code review:
+```
+ https://docs.github.com/articles/about-collaborative-development-models
+ https://docs.github.com/articles/about-pull-requests
+```
>From d466d7b10745f2e2dbeb6dd83b5606560c4b725e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 23 Mar 2026 17:25:30 +0530
Subject: [PATCH 3/6] nits
---
libc/src/math/docs/add_math_function.md | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libc/src/math/docs/add_math_function.md b/libc/src/math/docs/add_math_function.md
index 0406f71036d41..a0a434ae1d301 100644
--- a/libc/src/math/docs/add_math_function.md
+++ b/libc/src/math/docs/add_math_function.md
@@ -67,18 +67,18 @@ If the function should be available to internal LLVM projects:
```
libc/shared/math/<func>.h
```
-- Add a header that exports the function via using in:
+- Add a simple test case to
```
- libc/shared/math/<func>.h
+ libc/test/shared/shared_math_test.cpp
```
- Add the corresponding entry `libc.src.__support.math.<func>` to:
```
- libc/test/shared/CMakeLists.txt
+ libc/test/shared/CMakeLists.txt
```
- Add the corresponding `libc_support_library` and `libc_math_function` to:
```
-utils/bazel/llvm-project-overlay/libc/BUILD.bazel
-```s
+ utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+```
### Floating point utility
@@ -240,6 +240,6 @@ implementation (which is very often glibc).
We use GitHub's inbuilt pull request system for code review:
```
- https://docs.github.com/articles/about-collaborative-development-models
- https://docs.github.com/articles/about-pull-requests
+ https://docs.github.com/articles/about-collaborative-development-models
+ https://docs.github.com/articles/about-pull-requests
```
>From 95457921fc21317b79c6d1614c88e57666b7378b Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 23 Mar 2026 17:37:22 +0530
Subject: [PATCH 4/6] nits
---
libc/src/math/docs/add_math_function.md | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libc/src/math/docs/add_math_function.md b/libc/src/math/docs/add_math_function.md
index a0a434ae1d301..08a2a424b321a 100644
--- a/libc/src/math/docs/add_math_function.md
+++ b/libc/src/math/docs/add_math_function.md
@@ -13,8 +13,8 @@ together with its specifications:
- Add entry points `libc.src.math.<func>` to the following files:
```
- libc/config/linux/<arch>/entrypoints.txt
- libc/config/windows/entrypoints.txt
+ libc/config/linux/<arch>/entrypoints.txt
+ libc/config/windows/entrypoints.txt
```
- Add function specs to the file:
```
@@ -69,15 +69,15 @@ If the function should be available to internal LLVM projects:
```
- Add a simple test case to
```
- libc/test/shared/shared_math_test.cpp
+ libc/test/shared/shared_math_test.cpp
```
- Add the corresponding entry `libc.src.__support.math.<func>` to:
```
- libc/test/shared/CMakeLists.txt
+ libc/test/shared/CMakeLists.txt
```
- Add the corresponding `libc_support_library` and `libc_math_function` to:
```
- utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+ utils/bazel/llvm-project-overlay/libc/BUILD.bazel
```
### Floating point utility
@@ -240,6 +240,6 @@ implementation (which is very often glibc).
We use GitHub's inbuilt pull request system for code review:
```
- https://docs.github.com/articles/about-collaborative-development-models
- https://docs.github.com/articles/about-pull-requests
+ https://docs.github.com/articles/about-collaborative-development-models
+ https://docs.github.com/articles/about-pull-requests
```
>From bf83960f4e143f54950884acd7bccd90ef4b1e01 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 23 Mar 2026 18:04:30 +0530
Subject: [PATCH 5/6] nit (:)
---
libc/src/math/docs/add_math_function.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/libc/src/math/docs/add_math_function.md b/libc/src/math/docs/add_math_function.md
index 08a2a424b321a..ec909b368af01 100644
--- a/libc/src/math/docs/add_math_function.md
+++ b/libc/src/math/docs/add_math_function.md
@@ -13,8 +13,8 @@ together with its specifications:
- Add entry points `libc.src.math.<func>` to the following files:
```
- libc/config/linux/<arch>/entrypoints.txt
- libc/config/windows/entrypoints.txt
+ libc/config/linux/<arch>/entrypoints.txt
+ libc/config/windows/entrypoints.txt
```
- Add function specs to the file:
```
@@ -67,7 +67,7 @@ If the function should be available to internal LLVM projects:
```
libc/shared/math/<func>.h
```
-- Add a simple test case to
+- Add a simple test case to:
```
libc/test/shared/shared_math_test.cpp
```
>From 054527f9528250bd5edc38057f57eadb9b7c4027 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 23 Mar 2026 18:05:27 +0530
Subject: [PATCH 6/6] nit
---
libc/src/math/docs/add_math_function.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/math/docs/add_math_function.md b/libc/src/math/docs/add_math_function.md
index ec909b368af01..df02d44c04028 100644
--- a/libc/src/math/docs/add_math_function.md
+++ b/libc/src/math/docs/add_math_function.md
@@ -104,7 +104,7 @@ compare your outputs with the corresponding MPFR function. In
order for your new function to be supported by these two macros,
the following files will need to be updated:
-- Add the function enum to `LIBC_NAMESPACE::testing::mpfr::Operation` in the
+- Add the function enum to: `LIBC_NAMESPACE::testing::mpfr::Operation` in the
header file:
```
libc/utils/MPFRWrapper/MPFRUtils.h
More information about the libc-commits
mailing list