Skip to content

[libc][math] Refactor floor family to header-only#182194

Merged
hulxv merged 9 commits intollvm:mainfrom
hulxv:libc/math/refactor/header-only/floor
Feb 28, 2026
Merged

[libc][math] Refactor floor family to header-only#182194
hulxv merged 9 commits intollvm:mainfrom
hulxv:libc/math/refactor/header-only/floor

Conversation

@hulxv
Copy link
Copy Markdown
Member

@hulxv hulxv commented Feb 19, 2026

Refactors the floor math family to be header-only.

Closes #182193

Target Functions:

  • floor
  • floorbf16
  • floorf
  • floorf128
  • floorf16
  • floorl

@hulxv hulxv requested a review from bassiounix February 19, 2026 00:15
@llvmbot llvmbot added libc bazel "Peripheral" support tier build system: utils/bazel labels Feb 19, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Feb 19, 2026

@llvm/pr-subscribers-libc

Author: Mohamed Emad (hulxv)

Changes

Refactors the floor math family to be header-only.

Closes #182193

Target Functions:

  • floor
  • floorbf16
  • floorf
  • floorf128
  • floorf16
  • floorl

Patch is 26.73 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/182194.diff

24 Files Affected:

  • (modified) libc/shared/math.h (+6)
  • (added) libc/shared/math/floor.h (+22)
  • (added) libc/shared/math/floorbf16.h (+22)
  • (added) libc/shared/math/floorf.h (+22)
  • (added) libc/shared/math/floorf128.h (+28)
  • (added) libc/shared/math/floorf16.h (+28)
  • (added) libc/shared/math/floorl.h (+22)
  • (modified) libc/src/__support/math/CMakeLists.txt (+52)
  • (added) libc/src/__support/math/floor.h (+30)
  • (added) libc/src/__support/math/floorbf16.h (+25)
  • (added) libc/src/__support/math/floorf.h (+30)
  • (added) libc/src/__support/math/floorf128.h (+30)
  • (added) libc/src/__support/math/floorf16.h (+39)
  • (added) libc/src/__support/math/floorl.h (+24)
  • (modified) libc/src/math/generic/CMakeLists.txt (+6-22)
  • (modified) libc/src/math/generic/floor.cpp (+2-10)
  • (modified) libc/src/math/generic/floorbf16.cpp (+2-5)
  • (modified) libc/src/math/generic/floorf.cpp (+2-10)
  • (modified) libc/src/math/generic/floorf128.cpp (+2-4)
  • (modified) libc/src/math/generic/floorf16.cpp (+2-13)
  • (modified) libc/src/math/generic/floorl.cpp (+2-4)
  • (modified) libc/test/shared/CMakeLists.txt (+6)
  • (modified) libc/test/shared/shared_math_test.cpp (+12)
  • (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+95-5)
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 8a5aca82c6ec3..07b3b169812df 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -85,6 +85,12 @@
 #include "math/f16sqrtl.h"
 #include "math/ffma.h"
 #include "math/ffmal.h"
+#include "math/floor.h"
+#include "math/floorbf16.h"
+#include "math/floorf.h"
+#include "math/floorf128.h"
+#include "math/floorf16.h"
+#include "math/floorl.h"
 #include "math/frexpf.h"
 #include "math/frexpf128.h"
 #include "math/frexpf16.h"
diff --git a/libc/shared/math/floor.h b/libc/shared/math/floor.h
new file mode 100644
index 0000000000000..feacbf2a7a038
--- /dev/null
+++ b/libc/shared/math/floor.h
@@ -0,0 +1,22 @@
+//===-- Shared floor 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_FLOOR_H
+#define LLVM_LIBC_SHARED_MATH_FLOOR_H
+
+#include "src/__support/math/floor.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::floor;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FLOOR_H
diff --git a/libc/shared/math/floorbf16.h b/libc/shared/math/floorbf16.h
new file mode 100644
index 0000000000000..6153a9fa3d57f
--- /dev/null
+++ b/libc/shared/math/floorbf16.h
@@ -0,0 +1,22 @@
+//===-- Shared floorbf16 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_FLOORBF16_H
+#define LLVM_LIBC_SHARED_MATH_FLOORBF16_H
+
+#include "src/__support/math/floorbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::floorbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FLOORBF16_H
diff --git a/libc/shared/math/floorf.h b/libc/shared/math/floorf.h
new file mode 100644
index 0000000000000..b6b9f8b21a1ea
--- /dev/null
+++ b/libc/shared/math/floorf.h
@@ -0,0 +1,22 @@
+//===-- Shared floorf 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_FLOORF_H
+#define LLVM_LIBC_SHARED_MATH_FLOORF_H
+
+#include "src/__support/math/floorf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::floorf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FLOORF_H
diff --git a/libc/shared/math/floorf128.h b/libc/shared/math/floorf128.h
new file mode 100644
index 0000000000000..bdf6bf6749f72
--- /dev/null
+++ b/libc/shared/math/floorf128.h
@@ -0,0 +1,28 @@
+//===-- Shared floorf128 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_FLOORF128_H
+#define LLVM_LIBC_SHARED_MATH_FLOORF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/floorf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::floorf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FLOORF128_H
diff --git a/libc/shared/math/floorf16.h b/libc/shared/math/floorf16.h
new file mode 100644
index 0000000000000..fbb4650798a42
--- /dev/null
+++ b/libc/shared/math/floorf16.h
@@ -0,0 +1,28 @@
+//===-- Shared floorf16 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_FLOORF16_H
+#define LLVM_LIBC_SHARED_MATH_FLOORF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/floorf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::floorf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_FLOORF16_H
diff --git a/libc/shared/math/floorl.h b/libc/shared/math/floorl.h
new file mode 100644
index 0000000000000..f071031a9e22c
--- /dev/null
+++ b/libc/shared/math/floorl.h
@@ -0,0 +1,22 @@
+//===-- Shared floorl 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_FLOORL_H
+#define LLVM_LIBC_SHARED_MATH_FLOORL_H
+
+#include "src/__support/math/floorl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::floorl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FLOORL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e21fe8ef0ab93..aaa99a34ab2dc 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -800,6 +800,58 @@ add_header_library(
     libc.src.__support.FPUtil.fma
     libc.src.__support.macros.config
 )
+add_header_library(
+  floor
+  HDRS
+    floor.h
+  DEPENDS
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+add_header_library(
+  floorbf16
+  HDRS
+    floorbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+add_header_library(
+  floorf
+  HDRS
+    floorf.h
+  DEPENDS
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+add_header_library(
+  floorf128
+  HDRS
+    floorf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
+add_header_library(
+  floorf16
+  HDRS
+    floorf16.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
+)
+add_header_library(
+  floorl
+  HDRS
+    floorl.h
+  DEPENDS
+    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.macros.config
+)
 
 add_header_library(
   frexpf128
diff --git a/libc/src/__support/math/floor.h b/libc/src/__support/math/floor.h
new file mode 100644
index 0000000000000..ec58531cff40e
--- /dev/null
+++ b/libc/src/__support/math/floor.h
@@ -0,0 +1,30 @@
+//===-- Implementation header for floor -------------------------*- 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_FLOOR_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOOR_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE double floor(double x) {
+#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
+  return __builtin_floor(x);
+#else
+  return fputil::floor(x);
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOOR_H
diff --git a/libc/src/__support/math/floorbf16.h b/libc/src/__support/math/floorbf16.h
new file mode 100644
index 0000000000000..41e1cc4830f92
--- /dev/null
+++ b/libc/src/__support/math/floorbf16.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for floorbf16 ---------------------*- 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_FLOORBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOORBF16_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 bfloat16 floorbf16(bfloat16 x) { return fputil::floor(x); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOORBF16_H
diff --git a/libc/src/__support/math/floorf.h b/libc/src/__support/math/floorf.h
new file mode 100644
index 0000000000000..000825a8dfdbd
--- /dev/null
+++ b/libc/src/__support/math/floorf.h
@@ -0,0 +1,30 @@
+//===-- Implementation header for floorf ------------------------*- 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_FLOORF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float floorf(float x) {
+#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
+  return __builtin_floorf(x);
+#else
+  return fputil::floor(x);
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF_H
diff --git a/libc/src/__support/math/floorf128.h b/libc/src/__support/math/floorf128.h
new file mode 100644
index 0000000000000..951970ba6ae75
--- /dev/null
+++ b/libc/src/__support/math/floorf128.h
@@ -0,0 +1,30 @@
+//===-- Implementation header for floorf128 ---------------------*- 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_FLOORF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF128_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 float128 floorf128(float128 x) { return fputil::floor(x); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF128_H
diff --git a/libc/src/__support/math/floorf16.h b/libc/src/__support/math/floorf16.h
new file mode 100644
index 0000000000000..5ceebb63d2718
--- /dev/null
+++ b/libc/src/__support/math/floorf16.h
@@ -0,0 +1,39 @@
+//===-- Implementation header for floorf16 ----------------------*- 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_FLOORF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF16_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 float16 floorf16(float16 x) {
+#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) &&                       \
+    defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
+  return fputil::cast<float16>(__builtin_floorf(x));
+#else
+  return fputil::floor(x);
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOORF16_H
diff --git a/libc/src/__support/math/floorl.h b/libc/src/__support/math/floorl.h
new file mode 100644
index 0000000000000..6c6cdf3ed3dfc
--- /dev/null
+++ b/libc/src/__support/math/floorl.h
@@ -0,0 +1,24 @@
+//===-- Implementation header for floorl ------------------------*- 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_FLOORL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FLOORL_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE long double floorl(long double x) { return fputil::floor(x); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FLOORL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 57a29665318a3..25a1768494b7c 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -671,9 +671,7 @@ add_entrypoint_object(
   HDRS
     ../floor.h
   DEPENDS
-    libc.src.__support.FPUtil.nearest_integer_operations
-  FLAGS
-    ROUND_OPT
+    libc.src.__support.math.floor
 )
 
 add_entrypoint_object(
@@ -683,9 +681,7 @@ add_entrypoint_object(
   HDRS
     ../floorf.h
   DEPENDS
-    libc.src.__support.FPUtil.nearest_integer_operations
-  FLAGS
-    ROUND_OPT
+    libc.src.__support.math.floorf
 )
 
 add_entrypoint_object(
@@ -695,7 +691,7 @@ add_entrypoint_object(
   HDRS
     ../floorl.h
   DEPENDS
-    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.math.floorl
 )
 
 add_entrypoint_object(
@@ -705,12 +701,7 @@ add_entrypoint_object(
   HDRS
     ../floorf16.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.floorf16
 )
 
 add_entrypoint_object(
@@ -720,8 +711,7 @@ add_entrypoint_object(
   HDRS
     ../floorf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.nearest_integer_operations
+    libc.src.__support.math.floorf128
 )
 
 add_entrypoint_object(
@@ -731,13 +721,7 @@ add_entrypoint_object(
   HDRS
     ../floorbf16.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.macros.properties.types
-  FLAGS
-    ROUND_OPT
+    libc.src.__support.math.floorbf16
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/floor.cpp b/libc/src/math/generic/floor.cpp
index 86aed6c61a7cc..525e0f2a6ae88 100644
--- a/libc/src/math/generic/floor.cpp
+++ b/libc/src/math/generic/floor.cpp
@@ -7,18 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/floor.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/floor.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(double, floor, (double x)) {
-#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
-  return __builtin_floor(x);
-#else
-  return fputil::floor(x);
-#endif
-}
+LLVM_LIBC_FUNCTION(double, floor, (double x)) { return math::floor(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/floorbf16.cpp b/libc/src/math/generic/floorbf16.cpp
index d157096c3e62f..88fb89d193432 100644
--- a/libc/src/math/generic/floorbf16.cpp
+++ b/libc/src/math/generic/floorbf16.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/floorbf16.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/floorbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(bfloat16, floorbf16, (bfloat16 x)) {
-  return fputil::floor(x);
+  return math::floorbf16(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/floorf.cpp b/libc/src/math/generic/floorf.cpp
index 22739eff68ec2..c9f7e780b5eb1 100644
--- a/libc/src/math/generic/floorf.cpp
+++ b/libc/src/math/generic/floorf.cpp
@@ -7,18 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/floorf.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/floorf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(float, floorf, (float x)) {
-#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
-  return __builtin_floorf(x);
-#else
-  return fputil::floor(x);
-#endif
-}
+LLVM_LIBC_FUNCTION(float, floorf, (float x)) { return math::floorf(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/floorf128.cpp b/libc/src/math/generic/floorf128.cpp
index f3ad20a1dcba0..4740ec569611c 100644
--- a/libc/src/math/generic/floorf128.cpp
+++ b/libc/src/math/generic/floorf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/floorf128.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/floorf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, floorf128, (float128 x)) {
-  return fputil::floor(x);
+  return math::floorf128(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/floorf16.cpp b/libc/src/math/generic/floorf16.cpp
index 361b22729f642..f79e61278cfca 100644
--- a/libc/src/math/generic/floorf16.cpp
+++ b/libc/src/math/generic/floorf16.cpp
@@ -7,21 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/floorf16.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/floorf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(float16, floorf16, (float16 x)) {
-#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) &&                       \
-    defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
-  return fputil::cast<float16>(__builtin_floorf(x));
-#else
-  return fputil::floor(x);
-#endif
-}
+LLVM_LIB...
[truncated]

@hulxv hulxv force-pushed the libc/math/refactor/header-only/floor branch from 058e0d8 to be87db6 Compare February 19, 2026 00:25
Copy link
Copy Markdown
Member

@bassiounix bassiounix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous PRs

Refactored functions:
  - floor
  - floorbf16
  - floorf
  - floorf128
  - floorf16
  - floorl
@hulxv hulxv force-pushed the libc/math/refactor/header-only/floor branch from be87db6 to e9bb55f Compare February 19, 2026 23:37
Refactored functions:
  - floor
  - floorbf16
  - floorf
  - floorf128
  - floorf16
  - floorl
@hulxv hulxv force-pushed the libc/math/refactor/header-only/floor branch from 5042395 to 8fe259b Compare February 24, 2026 00:35
@hulxv hulxv requested a review from bassiounix February 24, 2026 00:36
@hulxv hulxv requested a review from bassiounix February 24, 2026 20:01
@hulxv hulxv requested a review from bassiounix February 25, 2026 20:48
@hulxv hulxv force-pushed the libc/math/refactor/header-only/floor branch from 3773c00 to e9d26a1 Compare February 27, 2026 19:43
@hulxv hulxv requested a review from bassiounix February 27, 2026 19:51
@hulxv hulxv merged commit fb6b470 into llvm:main Feb 28, 2026
28 checks passed
sahas3 pushed a commit to sahas3/llvm-project that referenced this pull request Mar 4, 2026
Refactors the floor math family to be header-only.

Closes llvm#182193

Target Functions:
  - floor
  - floorbf16
  - floorf
  - floorf128
  - floorf16
  - floorl
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
Refactors the floor math family to be header-only.

Closes llvm#182193

Target Functions:
  - floor
  - floorbf16
  - floorf
  - floorf128
  - floorf16
  - floorl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bazel "Peripheral" support tier build system: utils/bazel libc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[libc][math] Refactor floor Math Functions to Header Only

3 participants