[libc-commits] [libc] [llvm] [libc][math] Refactor rint-nearbyint family to header-only (PR #195577)

via libc-commits libc-commits at lists.llvm.org
Sun May 3 19:28:17 PDT 2026


https://github.com/AnonMiraj created https://github.com/llvm/llvm-project/pull/195577

Refactors the rint-nearbyint math family to be header-only.

part of: #147386

Target Functions:
  - nearbyint
  - nearbyintbf16
  - nearbyintf
  - nearbyintf128
  - nearbyintf16
  - nearbyintl
  - rint
  - rintbf16
  - rintf
  - rintf128
  - rintf16
  - rintl

>From f80a2e163c1030de279b08ffb14de9c52fb3693c Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Mon, 4 May 2026 05:28:02 +0300
Subject: [PATCH] [libc][math] Refactor rint-nearbyint family to header-only

Refactored functions:
  - nearbyint
  - nearbyintbf16
  - nearbyintf
  - nearbyintf128
  - nearbyintf16
  - nearbyintl
  - rint
  - rintbf16
  - rintf
  - rintf128
  - rintf16
  - rintl
---
 libc/shared/math.h                            |  12 ++
 libc/shared/math/nearbyint.h                  |  23 +++
 libc/shared/math/nearbyintbf16.h              |  23 +++
 libc/shared/math/nearbyintf.h                 |  23 +++
 libc/shared/math/nearbyintf128.h              |  29 +++
 libc/shared/math/nearbyintf16.h               |  29 +++
 libc/shared/math/nearbyintl.h                 |  23 +++
 libc/shared/math/rint.h                       |  23 +++
 libc/shared/math/rintbf16.h                   |  23 +++
 libc/shared/math/rintf.h                      |  23 +++
 libc/shared/math/rintf128.h                   |  29 +++
 libc/shared/math/rintf16.h                    |  29 +++
 libc/shared/math/rintl.h                      |  23 +++
 libc/src/__support/math/CMakeLists.txt        | 123 ++++++++++++
 libc/src/__support/math/nearbyint.h           |  25 +++
 libc/src/__support/math/nearbyintbf16.h       |  26 +++
 libc/src/__support/math/nearbyintf.h          |  25 +++
 libc/src/__support/math/nearbyintf128.h       |  31 +++
 libc/src/__support/math/nearbyintf16.h        |  31 +++
 libc/src/__support/math/nearbyintl.h          |  25 +++
 libc/src/__support/math/rint.h                |  29 +++
 libc/src/__support/math/rintbf16.h            |  26 +++
 libc/src/__support/math/rintf.h               |  29 +++
 libc/src/__support/math/rintf128.h            |  31 +++
 libc/src/__support/math/rintf16.h             |  38 ++++
 libc/src/__support/math/rintl.h               |  25 +++
 libc/src/math/generic/CMakeLists.txt          |  44 ++---
 libc/src/math/generic/nearbyint.cpp           |   8 +-
 libc/src/math/generic/nearbyintbf16.cpp       |   7 +-
 libc/src/math/generic/nearbyintf.cpp          |   8 +-
 libc/src/math/generic/nearbyintf128.cpp       |   6 +-
 libc/src/math/generic/nearbyintf16.cpp        |   6 +-
 libc/src/math/generic/nearbyintl.cpp          |   6 +-
 libc/src/math/generic/rint.cpp                |  12 +-
 libc/src/math/generic/rintbf16.cpp            |   7 +-
 libc/src/math/generic/rintf.cpp               |  12 +-
 libc/src/math/generic/rintf128.cpp            |   6 +-
 libc/src/math/generic/rintf16.cpp             |  15 +-
 libc/src/math/generic/rintl.cpp               |   6 +-
 libc/test/shared/CMakeLists.txt               |  24 +++
 .../shared/shared_math_constexpr_test.cpp     |  14 ++
 libc/test/shared/shared_math_test.cpp         |  14 ++
 .../llvm-project-overlay/libc/BUILD.bazel     | 183 +++++++++++++++++-
 43 files changed, 1039 insertions(+), 115 deletions(-)
 create mode 100644 libc/shared/math/nearbyint.h
 create mode 100644 libc/shared/math/nearbyintbf16.h
 create mode 100644 libc/shared/math/nearbyintf.h
 create mode 100644 libc/shared/math/nearbyintf128.h
 create mode 100644 libc/shared/math/nearbyintf16.h
 create mode 100644 libc/shared/math/nearbyintl.h
 create mode 100644 libc/shared/math/rint.h
 create mode 100644 libc/shared/math/rintbf16.h
 create mode 100644 libc/shared/math/rintf.h
 create mode 100644 libc/shared/math/rintf128.h
 create mode 100644 libc/shared/math/rintf16.h
 create mode 100644 libc/shared/math/rintl.h
 create mode 100644 libc/src/__support/math/nearbyint.h
 create mode 100644 libc/src/__support/math/nearbyintbf16.h
 create mode 100644 libc/src/__support/math/nearbyintf.h
 create mode 100644 libc/src/__support/math/nearbyintf128.h
 create mode 100644 libc/src/__support/math/nearbyintf16.h
 create mode 100644 libc/src/__support/math/nearbyintl.h
 create mode 100644 libc/src/__support/math/rint.h
 create mode 100644 libc/src/__support/math/rintbf16.h
 create mode 100644 libc/src/__support/math/rintf.h
 create mode 100644 libc/src/__support/math/rintf128.h
 create mode 100644 libc/src/__support/math/rintf16.h
 create mode 100644 libc/src/__support/math/rintl.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index ec1cfba7c0834..bed4279f621a0 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -343,6 +343,12 @@
 #include "math/modff128.h"
 #include "math/modff16.h"
 #include "math/modfl.h"
+#include "math/nearbyint.h"
+#include "math/nearbyintbf16.h"
+#include "math/nearbyintf.h"
+#include "math/nearbyintf128.h"
+#include "math/nearbyintf16.h"
+#include "math/nearbyintl.h"
 #include "math/nextafter.h"
 #include "math/nextafterbf16.h"
 #include "math/nextafterf.h"
@@ -380,6 +386,12 @@
 #include "math/remquof128.h"
 #include "math/remquof16.h"
 #include "math/remquol.h"
+#include "math/rint.h"
+#include "math/rintbf16.h"
+#include "math/rintf.h"
+#include "math/rintf128.h"
+#include "math/rintf16.h"
+#include "math/rintl.h"
 #include "math/rsqrtf.h"
 #include "math/rsqrtf16.h"
 #include "math/scalbln.h"
diff --git a/libc/shared/math/nearbyint.h b/libc/shared/math/nearbyint.h
new file mode 100644
index 0000000000000..e5439ecf24a79
--- /dev/null
+++ b/libc/shared/math/nearbyint.h
@@ -0,0 +1,23 @@
+//===-- Shared nearbyint function -------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEARBYINT_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINT_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyint.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyint;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINT_H
diff --git a/libc/shared/math/nearbyintbf16.h b/libc/shared/math/nearbyintbf16.h
new file mode 100644
index 0000000000000..f7b5eb47497c3
--- /dev/null
+++ b/libc/shared/math/nearbyintbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared nearbyintbf16 function ---------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEARBYINTBF16_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINTBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyintbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyintbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINTBF16_H
diff --git a/libc/shared/math/nearbyintf.h b/libc/shared/math/nearbyintf.h
new file mode 100644
index 0000000000000..212a0700c56af
--- /dev/null
+++ b/libc/shared/math/nearbyintf.h
@@ -0,0 +1,23 @@
+//===-- Shared nearbyintf function ------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEARBYINTF_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINTF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyintf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyintf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINTF_H
diff --git a/libc/shared/math/nearbyintf128.h b/libc/shared/math/nearbyintf128.h
new file mode 100644
index 0000000000000..824c5c98baf7d
--- /dev/null
+++ b/libc/shared/math/nearbyintf128.h
@@ -0,0 +1,29 @@
+//===-- Shared nearbyintf128 function ---------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEARBYINTF128_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINTF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyintf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyintf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINTF128_H
diff --git a/libc/shared/math/nearbyintf16.h b/libc/shared/math/nearbyintf16.h
new file mode 100644
index 0000000000000..3a9eb50d1f8dd
--- /dev/null
+++ b/libc/shared/math/nearbyintf16.h
@@ -0,0 +1,29 @@
+//===-- Shared nearbyintf16 function ----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEARBYINTF16_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINTF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyintf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyintf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINTF16_H
diff --git a/libc/shared/math/nearbyintl.h b/libc/shared/math/nearbyintl.h
new file mode 100644
index 0000000000000..bcfd937c24f94
--- /dev/null
+++ b/libc/shared/math/nearbyintl.h
@@ -0,0 +1,23 @@
+//===-- Shared nearbyintl function ------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEARBYINTL_H
+#define LLVM_LIBC_SHARED_MATH_NEARBYINTL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nearbyintl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nearbyintl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEARBYINTL_H
diff --git a/libc/shared/math/rint.h b/libc/shared/math/rint.h
new file mode 100644
index 0000000000000..5908a9dbeb9e2
--- /dev/null
+++ b/libc/shared/math/rint.h
@@ -0,0 +1,23 @@
+//===-- Shared rint function ------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_RINT_H
+#define LLVM_LIBC_SHARED_MATH_RINT_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rint.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rint;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_RINT_H
diff --git a/libc/shared/math/rintbf16.h b/libc/shared/math/rintbf16.h
new file mode 100644
index 0000000000000..b22829f227692
--- /dev/null
+++ b/libc/shared/math/rintbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared rintbf16 function --------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_RINTBF16_H
+#define LLVM_LIBC_SHARED_MATH_RINTBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rintbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rintbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_RINTBF16_H
diff --git a/libc/shared/math/rintf.h b/libc/shared/math/rintf.h
new file mode 100644
index 0000000000000..7f829c3d75998
--- /dev/null
+++ b/libc/shared/math/rintf.h
@@ -0,0 +1,23 @@
+//===-- Shared rintf function -----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_RINTF_H
+#define LLVM_LIBC_SHARED_MATH_RINTF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rintf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rintf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_RINTF_H
diff --git a/libc/shared/math/rintf128.h b/libc/shared/math/rintf128.h
new file mode 100644
index 0000000000000..13e2bf502c39e
--- /dev/null
+++ b/libc/shared/math/rintf128.h
@@ -0,0 +1,29 @@
+//===-- Shared rintf128 function --------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_RINTF128_H
+#define LLVM_LIBC_SHARED_MATH_RINTF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rintf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rintf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_RINTF128_H
diff --git a/libc/shared/math/rintf16.h b/libc/shared/math/rintf16.h
new file mode 100644
index 0000000000000..812b826ab746d
--- /dev/null
+++ b/libc/shared/math/rintf16.h
@@ -0,0 +1,29 @@
+//===-- Shared rintf16 function ---------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_RINTF16_H
+#define LLVM_LIBC_SHARED_MATH_RINTF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rintf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rintf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_RINTF16_H
diff --git a/libc/shared/math/rintl.h b/libc/shared/math/rintl.h
new file mode 100644
index 0000000000000..4e6de070b18c8
--- /dev/null
+++ b/libc/shared/math/rintl.h
@@ -0,0 +1,23 @@
+//===-- Shared rintl function -----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_RINTL_H
+#define LLVM_LIBC_SHARED_MATH_RINTL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/rintl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::rintl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_RINTL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 852b0b37cb844..a7d08c2d40cb5 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1954,6 +1954,63 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  nearbyint
+  HDRS
+    nearbyint.h
+  DEPENDS
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nearbyintbf16
+  HDRS
+    nearbyintbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nearbyintf
+  HDRS
+    nearbyintf.h
+  DEPENDS
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nearbyintf128
+  HDRS
+    nearbyintf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nearbyintf16
+  HDRS
+    nearbyintf16.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nearbyintl
+  HDRS
+    nearbyintl.h
+  DEPENDS
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   remainder
   HDRS
@@ -2068,6 +2125,72 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  rint
+  HDRS
+    rint.h
+  DEPENDS
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+  FLAGS
+    ROUND_OPT
+)
+
+add_header_library(
+  rintbf16
+  HDRS
+    rintbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+  FLAGS
+    ROUND_OPT
+)
+
+add_header_library(
+  rintf
+  HDRS
+    rintf.h
+  DEPENDS
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+  FLAGS
+    ROUND_OPT
+)
+
+add_header_library(
+  rintf128
+  HDRS
+    rintf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  rintf16
+  HDRS
+    rintf16.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.cast
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+  FLAGS
+    ROUND_OPT
+)
+
+add_header_library(
+  rintl
+  HDRS
+    rintl.h
+  DEPENDS
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   scalbln
   HDRS
diff --git a/libc/src/__support/math/nearbyint.h b/libc/src/__support/math/nearbyint.h
new file mode 100644
index 0000000000000..762e88667cf59
--- /dev/null
+++ b/libc/src/__support/math/nearbyint.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for nearbyint ---------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINT_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINT_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double nearbyint(double x) {
+  return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINT_H
diff --git a/libc/src/__support/math/nearbyintbf16.h b/libc/src/__support/math/nearbyintbf16.h
new file mode 100644
index 0000000000000..81dd464b77125
--- /dev/null
+++ b/libc/src/__support/math/nearbyintbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nearbyintbf16 -----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTBF16_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 nearbyintbf16(bfloat16 x) {
+  return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTBF16_H
diff --git a/libc/src/__support/math/nearbyintf.h b/libc/src/__support/math/nearbyintf.h
new file mode 100644
index 0000000000000..2a96307aae92e
--- /dev/null
+++ b/libc/src/__support/math/nearbyintf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for nearbyintf --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float nearbyintf(float x) {
+  return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF_H
diff --git a/libc/src/__support/math/nearbyintf128.h b/libc/src/__support/math/nearbyintf128.h
new file mode 100644
index 0000000000000..56d32cd61b5c5
--- /dev/null
+++ b/libc/src/__support/math/nearbyintf128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for nearbyintf128 -----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float128 nearbyintf128(float128 x) {
+  return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF128_H
diff --git a/libc/src/__support/math/nearbyintf16.h b/libc/src/__support/math/nearbyintf16.h
new file mode 100644
index 0000000000000..d7e3fb4c6adef
--- /dev/null
+++ b/libc/src/__support/math/nearbyintf16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for nearbyintf16 ------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float16 nearbyintf16(float16 x) {
+  return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTF16_H
diff --git a/libc/src/__support/math/nearbyintl.h b/libc/src/__support/math/nearbyintl.h
new file mode 100644
index 0000000000000..cbda25fcc382d
--- /dev/null
+++ b/libc/src/__support/math/nearbyintl.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for nearbyintl --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTL_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr long double nearbyintl(long double x) {
+  return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEARBYINTL_H
diff --git a/libc/src/__support/math/rint.h b/libc/src/__support/math/rint.h
new file mode 100644
index 0000000000000..149c75fbd44ce
--- /dev/null
+++ b/libc/src/__support/math/rint.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for rint --------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_RINT_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_RINT_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double rint(double x) {
+#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
+  return __builtin_rint(x);
+#else
+  return fputil::round_using_current_rounding_mode(x);
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_RINT_H
diff --git a/libc/src/__support/math/rintbf16.h b/libc/src/__support/math/rintbf16.h
new file mode 100644
index 0000000000000..a2ddeb1f70bab
--- /dev/null
+++ b/libc/src/__support/math/rintbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for rintbf16 ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_RINTBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_RINTBF16_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 rintbf16(bfloat16 x) {
+  return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_RINTBF16_H
diff --git a/libc/src/__support/math/rintf.h b/libc/src/__support/math/rintf.h
new file mode 100644
index 0000000000000..0ca7cad0f65ed
--- /dev/null
+++ b/libc/src/__support/math/rintf.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for rintf -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_RINTF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_RINTF_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float rintf(float x) {
+#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
+  return __builtin_rintf(x);
+#else
+  return fputil::round_using_current_rounding_mode(x);
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_RINTF_H
diff --git a/libc/src/__support/math/rintf128.h b/libc/src/__support/math/rintf128.h
new file mode 100644
index 0000000000000..2280bd0a6018f
--- /dev/null
+++ b/libc/src/__support/math/rintf128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for rintf128 ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_RINTF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_RINTF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float128 rintf128(float128 x) {
+  return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_RINTF128_H
diff --git a/libc/src/__support/math/rintf16.h b/libc/src/__support/math/rintf16.h
new file mode 100644
index 0000000000000..346cb76d79989
--- /dev/null
+++ b/libc/src/__support/math/rintf16.h
@@ -0,0 +1,38 @@
+//===-- Implementation header for rintf16 -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_RINTF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_RINTF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/cpu_features.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float16 rintf16(float16 x) {
+#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) &&                       \
+    defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
+  return fputil::cast<float16>(__builtin_rintf(x));
+#else
+  return fputil::round_using_current_rounding_mode(x);
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_RINTF16_H
diff --git a/libc/src/__support/math/rintl.h b/libc/src/__support/math/rintl.h
new file mode 100644
index 0000000000000..20f066dc05c12
--- /dev/null
+++ b/libc/src/__support/math/rintl.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for rintl -------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_RINTL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_RINTL_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr long double rintl(long double x) {
+  return fputil::round_using_current_rounding_mode(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_RINTL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index f7444158e05c6..d925a2817c177 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -986,9 +986,7 @@ add_entrypoint_object(
   HDRS
     ../rint.h
   DEPENDS
-    libc.src.__support.FPUtil.nearest_integer_operations
-  FLAGS
-    ROUND_OPT
+    libc.src.__support.math.rint
 )
 
 add_entrypoint_object(
@@ -998,9 +996,7 @@ add_entrypoint_object(
   HDRS
     ../rintf.h
   DEPENDS
-    libc.src.__support.FPUtil.nearest_integer_operations
-  FLAGS
-    ROUND_OPT
+    libc.src.__support.math.rintf
 )
 
 add_entrypoint_object(
@@ -1010,7 +1006,7 @@ add_entrypoint_object(
   HDRS
     ../rintl.h
   DEPENDS
-    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.math.rintl
 )
 
 add_entrypoint_object(
@@ -1020,12 +1016,7 @@ add_entrypoint_object(
   HDRS
     ../rintf16.h
   DEPENDS
-    libc.src.__support.FPUtil.cast
-    libc.src.__support.FPUtil.nearest_integer_operations
-    libc.src.__support.macros.properties.cpu_features
-    libc.src.__support.macros.properties.types
-  FLAGS
-    ROUND_OPT
+    libc.src.__support.math.rintf16
 )
 
 add_entrypoint_object(
@@ -1035,8 +1026,7 @@ add_entrypoint_object(
   HDRS
     ../rintf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.math.rintf128
 )
 
 add_entrypoint_object(
@@ -1046,12 +1036,7 @@ add_entrypoint_object(
   HDRS
     ../rintbf16.h
   DEPENDS
-    libc.src.__support.common
-    libc.src.__support.FPUtil.bfloat16
-    libc.src.__support.FPUtil.nearest_integer_operations
-    libc.src.__support.macros.config
-  FLAGS
-    ROUND_OPT
+    libc.src.__support.math.rintbf16
 )
 
 add_entrypoint_object(
@@ -1181,7 +1166,7 @@ add_entrypoint_object(
   HDRS
     ../nearbyint.h
   DEPENDS
-    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.math.nearbyint
 )
 
 add_entrypoint_object(
@@ -1191,7 +1176,7 @@ add_entrypoint_object(
   HDRS
     ../nearbyintf.h
   DEPENDS
-    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.math.nearbyintf
 )
 
 add_entrypoint_object(
@@ -1201,7 +1186,7 @@ add_entrypoint_object(
   HDRS
     ../nearbyintl.h
   DEPENDS
-    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.math.nearbyintl
 )
 
 add_entrypoint_object(
@@ -1211,8 +1196,7 @@ add_entrypoint_object(
   HDRS
     ../nearbyintf16.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.math.nearbyintf16
 )
 
 add_entrypoint_object(
@@ -1222,8 +1206,7 @@ add_entrypoint_object(
   HDRS
     ../nearbyintf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.math.nearbyintf128
 )
 
 add_entrypoint_object(
@@ -1233,10 +1216,7 @@ add_entrypoint_object(
   HDRS
     ../nearbyintbf16.h
   DEPENDS
-    libc.src.__support.common
-    libc.src.__support.FPUtil.bfloat16
-    libc.src.__support.FPUtil.nearest_integer_operations
-    libc.src.__support.macros.config
+    libc.src.__support.math.nearbyintbf16
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/nearbyint.cpp b/libc/src/math/generic/nearbyint.cpp
index 5662d6698e704..6be29794078fb 100644
--- a/libc/src/math/generic/nearbyint.cpp
+++ b/libc/src/math/generic/nearbyint.cpp
@@ -7,14 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nearbyint.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nearbyint.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(double, nearbyint, (double x)) {
-  return fputil::round_using_current_rounding_mode(x);
-}
+LLVM_LIBC_FUNCTION(double, nearbyint, (double x)) { return math::nearbyint(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nearbyintbf16.cpp b/libc/src/math/generic/nearbyintbf16.cpp
index a6391995963ff..92f097b2ee1d2 100644
--- a/libc/src/math/generic/nearbyintbf16.cpp
+++ b/libc/src/math/generic/nearbyintbf16.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nearbyintbf16.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nearbyintbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(bfloat16, nearbyintbf16, (bfloat16 x)) {
-  return fputil::round_using_current_rounding_mode(x);
+  return math::nearbyintbf16(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nearbyintf.cpp b/libc/src/math/generic/nearbyintf.cpp
index 9b8db08215d88..af6b8fc4cdb36 100644
--- a/libc/src/math/generic/nearbyintf.cpp
+++ b/libc/src/math/generic/nearbyintf.cpp
@@ -7,14 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nearbyintf.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nearbyintf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(float, nearbyintf, (float x)) {
-  return fputil::round_using_current_rounding_mode(x);
-}
+LLVM_LIBC_FUNCTION(float, nearbyintf, (float x)) { return math::nearbyintf(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nearbyintf128.cpp b/libc/src/math/generic/nearbyintf128.cpp
index 95038b8bf1267..9e6ef72a624e7 100644
--- a/libc/src/math/generic/nearbyintf128.cpp
+++ b/libc/src/math/generic/nearbyintf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nearbyintf128.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nearbyintf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, nearbyintf128, (float128 x)) {
-  return fputil::round_using_current_rounding_mode(x);
+  return math::nearbyintf128(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nearbyintf16.cpp b/libc/src/math/generic/nearbyintf16.cpp
index 1e6229b8227b0..93988085e31e5 100644
--- a/libc/src/math/generic/nearbyintf16.cpp
+++ b/libc/src/math/generic/nearbyintf16.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nearbyintf16.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nearbyintf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, nearbyintf16, (float16 x)) {
-  return fputil::round_using_current_rounding_mode(x);
+  return math::nearbyintf16(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nearbyintl.cpp b/libc/src/math/generic/nearbyintl.cpp
index 79ee73c853ab5..56054c9247213 100644
--- a/libc/src/math/generic/nearbyintl.cpp
+++ b/libc/src/math/generic/nearbyintl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nearbyintl.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nearbyintl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(long double, nearbyintl, (long double x)) {
-  return fputil::round_using_current_rounding_mode(x);
+  return math::nearbyintl(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/rint.cpp b/libc/src/math/generic/rint.cpp
index 5defa60ddac1c..cc3ac7d7cf8c4 100644
--- a/libc/src/math/generic/rint.cpp
+++ b/libc/src/math/generic/rint.cpp
@@ -7,18 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/rint.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/rint.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(double, rint, (double x)) {
-#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
-  return __builtin_rint(x);
-#else
-  return fputil::round_using_current_rounding_mode(x);
-#endif
-}
+LLVM_LIBC_FUNCTION(double, rint, (double x)) { return math::rint(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/rintbf16.cpp b/libc/src/math/generic/rintbf16.cpp
index 2ffe16a716205..fdf9040060321 100644
--- a/libc/src/math/generic/rintbf16.cpp
+++ b/libc/src/math/generic/rintbf16.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/rintbf16.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/rintbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(bfloat16, rintbf16, (bfloat16 x)) {
-  return fputil::round_using_current_rounding_mode(x);
+  return math::rintbf16(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/rintf.cpp b/libc/src/math/generic/rintf.cpp
index 2fe7788241168..3af2268d3a772 100644
--- a/libc/src/math/generic/rintf.cpp
+++ b/libc/src/math/generic/rintf.cpp
@@ -7,18 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/rintf.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/rintf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(float, rintf, (float x)) {
-#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
-  return __builtin_rintf(x);
-#else
-  return fputil::round_using_current_rounding_mode(x);
-#endif
-}
+LLVM_LIBC_FUNCTION(float, rintf, (float x)) { return math::rintf(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/rintf128.cpp b/libc/src/math/generic/rintf128.cpp
index f3b8afa1fd08f..297cb493c48e0 100644
--- a/libc/src/math/generic/rintf128.cpp
+++ b/libc/src/math/generic/rintf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/rintf128.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/rintf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, rintf128, (float128 x)) {
-  return fputil::round_using_current_rounding_mode(x);
+  return math::rintf128(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/rintf16.cpp b/libc/src/math/generic/rintf16.cpp
index aefdcbea77064..2ec1eeaa1eefa 100644
--- a/libc/src/math/generic/rintf16.cpp
+++ b/libc/src/math/generic/rintf16.cpp
@@ -7,21 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/rintf16.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/FPUtil/cast.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/properties/cpu_features.h"
+#include "src/__support/math/rintf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(float16, rintf16, (float16 x)) {
-#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) &&                       \
-    defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
-  return fputil::cast<float16>(__builtin_rintf(x));
-#else
-  return fputil::round_using_current_rounding_mode(x);
-#endif
-}
+LLVM_LIBC_FUNCTION(float16, rintf16, (float16 x)) { return math::rintf16(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/rintl.cpp b/libc/src/math/generic/rintl.cpp
index 007d29a144e98..0c116a29110a6 100644
--- a/libc/src/math/generic/rintl.cpp
+++ b/libc/src/math/generic/rintl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/rintl.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/rintl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(long double, rintl, (long double x)) {
-  return fputil::round_using_current_rounding_mode(x);
+  return math::rintl(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index c64dad12391e9..700925aae1f2c 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -341,6 +341,12 @@ add_fp_unittest(
     libc.src.__support.math.modff128
     libc.src.__support.math.modff16
     libc.src.__support.math.modfl
+    libc.src.__support.math.nearbyint
+    libc.src.__support.math.nearbyintbf16
+    libc.src.__support.math.nearbyintf
+    libc.src.__support.math.nearbyintf128
+    libc.src.__support.math.nearbyintf16
+    libc.src.__support.math.nearbyintl
     libc.src.__support.math.nextdown
     libc.src.__support.math.nextdownbf16
     libc.src.__support.math.nextdownf
@@ -378,6 +384,12 @@ add_fp_unittest(
     libc.src.__support.math.remquof128
     libc.src.__support.math.remquof16
     libc.src.__support.math.remquol
+    libc.src.__support.math.rint
+    libc.src.__support.math.rintbf16
+    libc.src.__support.math.rintf
+    libc.src.__support.math.rintf128
+    libc.src.__support.math.rintf16
+    libc.src.__support.math.rintl
     libc.src.__support.math.rsqrtf
     libc.src.__support.math.rsqrtf16
     libc.src.__support.math.scalbln
@@ -624,6 +636,12 @@ add_fp_unittest(
     libc.src.__support.math.modff128
     libc.src.__support.math.modff16
     libc.src.__support.math.modfl
+    libc.src.__support.math.nearbyint
+    libc.src.__support.math.nearbyintbf16
+    libc.src.__support.math.nearbyintf
+    libc.src.__support.math.nearbyintf128
+    libc.src.__support.math.nearbyintf16
+    libc.src.__support.math.nearbyintl
     libc.src.__support.math.remainder
     libc.src.__support.math.remainderbf16
     libc.src.__support.math.remainderf
@@ -636,6 +654,12 @@ add_fp_unittest(
     libc.src.__support.math.remquof128
     libc.src.__support.math.remquof16
     libc.src.__support.math.remquol
+    libc.src.__support.math.rint
+    libc.src.__support.math.rintbf16
+    libc.src.__support.math.rintf
+    libc.src.__support.math.rintf128
+    libc.src.__support.math.rintf16
+    libc.src.__support.math.rintl
     libc.src.__support.math.scalbln
     libc.src.__support.math.scalblnbf16
     libc.src.__support.math.scalblnf
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 9885484e854df..764bce643e187 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -66,6 +66,8 @@ static_assert(0LL == LIBC_NAMESPACE::shared::llrint(0.0));
 static_assert(0LL == LIBC_NAMESPACE::shared::llround(0.0));
 static_assert(0L == LIBC_NAMESPACE::shared::lrint(0.0));
 static_assert(0L == LIBC_NAMESPACE::shared::lround(0.0));
+static_assert(0.0 == LIBC_NAMESPACE::shared::nearbyint(0.0));
+static_assert(0.0 == LIBC_NAMESPACE::shared::rint(0.0));
 
 //===----------------------------------------------------------------------===//
 //                       Float Tests
@@ -118,6 +120,8 @@ static_assert(0LL == LIBC_NAMESPACE::shared::llrintf(0.0f));
 static_assert(0LL == LIBC_NAMESPACE::shared::llroundf(0.0f));
 static_assert(0L == LIBC_NAMESPACE::shared::lrintf(0.0f));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundf(0.0f));
+static_assert(0.0f == LIBC_NAMESPACE::shared::nearbyintf(0.0f));
+static_assert(0.0f == LIBC_NAMESPACE::shared::rintf(0.0f));
 
 //===----------------------------------------------------------------------===//
 //                       Float16 Tests
@@ -188,6 +192,8 @@ static_assert(0LL == LIBC_NAMESPACE::shared::llrintf16(0.0));
 static_assert(0LL == LIBC_NAMESPACE::shared::llroundf16(0.0f16));
 static_assert(0L == LIBC_NAMESPACE::shared::lrintf16(0.0f16));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundf16(0.0f16));
+static_assert(0.0f16 == LIBC_NAMESPACE::shared::nearbyintf16(0.0f16));
+static_assert(0.0f16 == LIBC_NAMESPACE::shared::rintf16(0.0f16));
 #endif // LIBC_TYPES_HAS_FLOAT16
 
 //===----------------------------------------------------------------------===//
@@ -255,6 +261,8 @@ static_assert(0LL == LIBC_NAMESPACE::shared::llrintl(0.0L));
 static_assert(0LL == LIBC_NAMESPACE::shared::llroundl(0.0L));
 static_assert(0L == LIBC_NAMESPACE::shared::lrintl(0.0L));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundl(0.0L));
+static_assert(0.0L == LIBC_NAMESPACE::shared::nearbyintl(0.0L));
+static_assert(0.0L == LIBC_NAMESPACE::shared::rintl(0.0L));
 
 #endif
 
@@ -356,6 +364,9 @@ static_assert(0LL == LIBC_NAMESPACE::shared::llrintf128(float128(0.0)));
 static_assert(0LL == LIBC_NAMESPACE::shared::llroundf128(float128(0.0)));
 static_assert(0L == LIBC_NAMESPACE::shared::lrintf128(float128(0.0)));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundf128(float128(0.0)));
+static_assert(float128(0.0) ==
+              LIBC_NAMESPACE::shared::nearbyintf128(float128(0.0)));
+static_assert(float128(0.0) == LIBC_NAMESPACE::shared::rintf128(float128(0.0)));
 
 #endif // LIBC_TYPES_HAS_FLOAT128
 
@@ -451,5 +462,8 @@ static_assert(0LL == LIBC_NAMESPACE::shared::llroundbf16(bfloat16(0.0)));
 static_assert(0LL == LIBC_NAMESPACE::shared::llrintbf16(bfloat16(0.0)));
 static_assert(0L == LIBC_NAMESPACE::shared::lrintbf16(bfloat16(0.0)));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundbf16(bfloat16(0.0)));
+static_assert(bfloat16(0.0) ==
+              LIBC_NAMESPACE::shared::nearbyintbf16(bfloat16(0.0)));
+static_assert(bfloat16(0.0) == LIBC_NAMESPACE::shared::rintbf16(bfloat16(0.0)));
 
 TEST(LlvmLibcSharedMathTest, ConstantEvaluation) {}
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 4b0229a19b8de..53389b27567be 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -147,6 +147,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llroundf16(0.0f16));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lrintf16(0.0f16));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lroundf16(0.0f16));
+  EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::nearbyintf16(0.0f16));
+  EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::rintf16(0.0f16));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
@@ -297,6 +299,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lroundf(0.0f));
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llrintf(0.0f));
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llroundf(0.0f));
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::nearbyintf(0.0f));
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::rintf(0.0f));
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -423,6 +427,8 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lround(0.0));
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llrint(0.0));
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llround(0.0));
+  EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::nearbyint(0.0));
+  EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::rint(0.0));
 }
 
 // TODO: Enable the tests when double-double type is supported.
@@ -531,6 +537,8 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llroundl(0.0L));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lrintl(0.0L));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lroundl(0.0L));
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::nearbyintl(0.0L));
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::rintl(0.0L));
 }
 
 #endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
@@ -697,6 +705,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   EXPECT_FP_EQ(0.0L, LIBC_NAMESPACE::shared::llroundf128(float128(0.0)));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lrintf128(float128(0.0)));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lroundf128(float128(0.0)));
+  EXPECT_FP_EQ(float128(0.0),
+               LIBC_NAMESPACE::shared::nearbyintf128(float128(0.0)));
+  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::rintf128(float128(0.0)));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
@@ -826,4 +837,7 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lroundbf16(bfloat16(0.0)));
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llrintbf16(bfloat16(0.0)));
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llroundbf16(bfloat16(0.0)));
+  EXPECT_FP_EQ(bfloat16(0.0),
+               LIBC_NAMESPACE::shared::nearbyintbf16(bfloat16(0.0)));
+  EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::rintbf16(bfloat16(0.0)));
 }
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 198614655f7f7..3aba1739b05be 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -5143,6 +5143,63 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_nearbyint",
+    hdrs = ["src/__support/math/nearbyint.h"],
+    deps = [
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nearbyintbf16",
+    hdrs = ["src/__support/math/nearbyintbf16.h"],
+    deps = [
+        ":__support_fputil_bfloat16",
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nearbyintf",
+    hdrs = ["src/__support/math/nearbyintf.h"],
+    deps = [
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nearbyintf128",
+    hdrs = ["src/__support/math/nearbyintf128.h"],
+    deps = [
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nearbyintf16",
+    hdrs = ["src/__support/math/nearbyintf16.h"],
+    deps = [
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nearbyintl",
+    hdrs = ["src/__support/math/nearbyintl.h"],
+    deps = [
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_remainder",
     hdrs = ["src/__support/math/remainder.h"],
@@ -5257,6 +5314,64 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_rint",
+    hdrs = ["src/__support/math/rint.h"],
+    deps = [
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_rintbf16",
+    hdrs = ["src/__support/math/rintbf16.h"],
+    deps = [
+        ":__support_fputil_bfloat16",
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_rintf",
+    hdrs = ["src/__support/math/rintf.h"],
+    deps = [
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_rintf128",
+    hdrs = ["src/__support/math/rintf128.h"],
+    deps = [
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_rintf16",
+    hdrs = ["src/__support/math/rintf16.h"],
+    deps = [
+        ":__support_fputil_cast",
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_rintl",
+    hdrs = ["src/__support/math/rintl.h"],
+    deps = [
+        ":__support_fputil_nearest_integer_operations",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_scalbln",
     hdrs = ["src/__support/math/scalbln.h"],
@@ -10837,18 +10952,46 @@ libc_math_function(
     ],
 )
 
-libc_math_function(name = "nearbyint")
+libc_math_function(
+    name = "nearbyint",
+    additional_deps = [
+        ":__support_math_nearbyint",
+    ],
+)
+
+libc_math_function(
+    name = "nearbyintbf16",
+    additional_deps = [
+        ":__support_math_nearbyintbf16",
+    ],
+)
 
-libc_math_function(name = "nearbyintf")
+libc_math_function(
+    name = "nearbyintf",
+    additional_deps = [
+        ":__support_math_nearbyintf",
+    ],
+)
 
-libc_math_function(name = "nearbyintl")
+libc_math_function(
+    name = "nearbyintl",
+    additional_deps = [
+        ":__support_math_nearbyintl",
+    ],
+)
 
 libc_math_function(
     name = "nearbyintf128",
+    additional_deps = [
+        ":__support_math_nearbyintf128",
+    ],
 )
 
 libc_math_function(
     name = "nearbyintf16",
+    additional_deps = [
+        ":__support_math_nearbyintf16",
+    ],
 )
 
 libc_math_function(
@@ -11112,21 +11255,45 @@ libc_math_function(
     ],
 )
 
-libc_math_function(name = "rint")
+libc_math_function(
+    name = "rint",
+    additional_deps = [
+        ":__support_math_rint",
+    ],
+)
 
-libc_math_function(name = "rintf")
+libc_math_function(
+    name = "rintbf16",
+    additional_deps = [
+        ":__support_math_rintbf16",
+    ],
+)
+
+libc_math_function(
+    name = "rintf",
+    additional_deps = [
+        ":__support_math_rintf",
+    ],
+)
 
-libc_math_function(name = "rintl")
+libc_math_function(
+    name = "rintl",
+    additional_deps = [
+        ":__support_math_rintl",
+    ],
+)
 
 libc_math_function(
     name = "rintf128",
+    additional_deps = [
+        ":__support_math_rintf128",
+    ],
 )
 
 libc_math_function(
     name = "rintf16",
     additional_deps = [
-        ":__support_fputil_cast",
-        ":__support_macros_properties_cpu_features",
+        ":__support_math_rintf16",
     ],
 )
 



More information about the libc-commits mailing list