[libc-commits] [libc] [llvm] [libc][math] Refactor ceil family to header-only (PR #182121)
Mohamed Emad via libc-commits
libc-commits at lists.llvm.org
Thu Feb 19 13:54:58 PST 2026
https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/182121
>From c7ec815aa0056f3d2a5f844bd3d80bbff400d732 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 18 Feb 2026 22:45:18 +0200
Subject: [PATCH] [libc][math] Refactor ceil family to header-only
Refactored functions:
- ceil
- ceilbf16
- ceilf
- ceilf128
- ceilf16
- ceill
---
libc/shared/math.h | 6 ++
libc/shared/math/ceil.h | 22 ++++
libc/shared/math/ceilbf16.h | 22 ++++
libc/shared/math/ceilf.h | 22 ++++
libc/shared/math/ceilf128.h | 28 +++++
libc/shared/math/ceilf16.h | 28 +++++
libc/shared/math/ceill.h | 22 ++++
libc/src/__support/math/CMakeLists.txt | 66 ++++++++++++
libc/src/__support/math/ceil.h | 29 +++++
libc/src/__support/math/ceilbf16.h | 24 +++++
libc/src/__support/math/ceilf.h | 29 +++++
libc/src/__support/math/ceilf128.h | 29 +++++
libc/src/__support/math/ceilf16.h | 38 +++++++
libc/src/__support/math/ceill.h | 25 +++++
libc/src/math/generic/CMakeLists.txt | 28 ++---
libc/src/math/generic/ceil.cpp | 12 +--
libc/src/math/generic/ceilbf16.cpp | 9 +-
libc/src/math/generic/ceilf.cpp | 12 +--
libc/src/math/generic/ceilf128.cpp | 8 +-
libc/src/math/generic/ceilf16.cpp | 15 +--
libc/src/math/generic/ceill.cpp | 6 +-
libc/test/shared/CMakeLists.txt | 6 ++
libc/test/shared/shared_math_test.cpp | 11 ++
.../llvm-project-overlay/libc/BUILD.bazel | 100 +++++++++++++++++-
24 files changed, 524 insertions(+), 73 deletions(-)
create mode 100644 libc/shared/math/ceil.h
create mode 100644 libc/shared/math/ceilbf16.h
create mode 100644 libc/shared/math/ceilf.h
create mode 100644 libc/shared/math/ceilf128.h
create mode 100644 libc/shared/math/ceilf16.h
create mode 100644 libc/shared/math/ceill.h
create mode 100644 libc/src/__support/math/ceil.h
create mode 100644 libc/src/__support/math/ceilbf16.h
create mode 100644 libc/src/__support/math/ceilf.h
create mode 100644 libc/src/__support/math/ceilf128.h
create mode 100644 libc/src/__support/math/ceilf16.h
create mode 100644 libc/src/__support/math/ceill.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 8a5aca82c6ec3..ca187b9c3a7df 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -45,6 +45,12 @@
#include "math/canonicalizel.h"
#include "math/cbrt.h"
#include "math/cbrtf.h"
+#include "math/ceil.h"
+#include "math/ceilbf16.h"
+#include "math/ceilf.h"
+#include "math/ceilf128.h"
+#include "math/ceilf16.h"
+#include "math/ceill.h"
#include "math/cos.h"
#include "math/cosf.h"
#include "math/cosf16.h"
diff --git a/libc/shared/math/ceil.h b/libc/shared/math/ceil.h
new file mode 100644
index 0000000000000..ecbe5699cbc61
--- /dev/null
+++ b/libc/shared/math/ceil.h
@@ -0,0 +1,22 @@
+//===-- Shared ceil 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_CEIL_H
+#define LLVM_LIBC_SHARED_MATH_CEIL_H
+
+#include "src/__support/math/ceil.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ceil;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_CEIL_H
diff --git a/libc/shared/math/ceilbf16.h b/libc/shared/math/ceilbf16.h
new file mode 100644
index 0000000000000..a72a77c237324
--- /dev/null
+++ b/libc/shared/math/ceilbf16.h
@@ -0,0 +1,22 @@
+//===-- Shared ceilbf16 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_CEILBF16_H
+#define LLVM_LIBC_SHARED_MATH_CEILBF16_H
+
+#include "src/__support/math/ceilbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ceilbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_CEILBF16_H
diff --git a/libc/shared/math/ceilf.h b/libc/shared/math/ceilf.h
new file mode 100644
index 0000000000000..9cae81ee98e1e
--- /dev/null
+++ b/libc/shared/math/ceilf.h
@@ -0,0 +1,22 @@
+//===-- Shared ceilf 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_CEILF_H
+#define LLVM_LIBC_SHARED_MATH_CEILF_H
+
+#include "src/__support/math/ceilf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ceilf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_CEILF_H
diff --git a/libc/shared/math/ceilf128.h b/libc/shared/math/ceilf128.h
new file mode 100644
index 0000000000000..08500bb46a022
--- /dev/null
+++ b/libc/shared/math/ceilf128.h
@@ -0,0 +1,28 @@
+//===-- Shared ceilf128 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_CEILF128_H
+#define LLVM_LIBC_SHARED_MATH_CEILF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/ceilf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ceilf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_CEILF128_H
diff --git a/libc/shared/math/ceilf16.h b/libc/shared/math/ceilf16.h
new file mode 100644
index 0000000000000..0758fd3d79158
--- /dev/null
+++ b/libc/shared/math/ceilf16.h
@@ -0,0 +1,28 @@
+//===-- Shared ceilf16 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_CEILF16_H
+#define LLVM_LIBC_SHARED_MATH_CEILF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/ceilf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ceilf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_CEILF16_H
diff --git a/libc/shared/math/ceill.h b/libc/shared/math/ceill.h
new file mode 100644
index 0000000000000..d3bc61d150c4d
--- /dev/null
+++ b/libc/shared/math/ceill.h
@@ -0,0 +1,22 @@
+//===-- Shared ceill 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_CEILL_H
+#define LLVM_LIBC_SHARED_MATH_CEILL_H
+
+#include "src/__support/math/ceill.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::ceill;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_CEILL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e21fe8ef0ab93..6c75292186ac9 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -476,6 +476,72 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ ceil
+ HDRS
+ ceil.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ ceilbf16
+ HDRS
+ ceilbf16.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(
+ ceilf
+ HDRS
+ ceilf.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+ FLAGS
+ ROUND_OPT
+)
+
+add_header_library(
+ ceilf128
+ HDRS
+ ceilf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ ceilf16
+ HDRS
+ ceilf16.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(
+ ceill
+ HDRS
+ ceill.h
+ DEPENDS
+ libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.macros.config
+)
+
add_header_library(
common_constants
HDRS
diff --git a/libc/src/__support/math/ceil.h b/libc/src/__support/math/ceil.h
new file mode 100644
index 0000000000000..71b89a76c1d25
--- /dev/null
+++ b/libc/src/__support/math/ceil.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for ceil --------------------------*- 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_CEIL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CEIL_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE double ceil(double x) {
+#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
+ return __builtin_ceil(x);
+#else
+ return fputil::ceil(x);
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CEIL_H
diff --git a/libc/src/__support/math/ceilbf16.h b/libc/src/__support/math/ceilbf16.h
new file mode 100644
index 0000000000000..bdb7dfee6a325
--- /dev/null
+++ b/libc/src/__support/math/ceilbf16.h
@@ -0,0 +1,24 @@
+//===-- Implementation header for ceilbf16 ----------------------*- 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_CEILBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CEILBF16_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 ceilbf16(bfloat16 x) { return fputil::ceil(x); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CEILBF16_H
diff --git a/libc/src/__support/math/ceilf.h b/libc/src/__support/math/ceilf.h
new file mode 100644
index 0000000000000..58710b9bfc126
--- /dev/null
+++ b/libc/src/__support/math/ceilf.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for ceilf -------------------------*- 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_CEILF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CEILF_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE float ceilf(float x) {
+#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
+ return __builtin_ceilf(x);
+#else
+ return fputil::ceil(x);
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CEILF_H
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
new file mode 100644
index 0000000000000..8877594d58d68
--- /dev/null
+++ b/libc/src/__support/math/ceilf128.h
@@ -0,0 +1,29 @@
+//===-- Implementation header for ceilf128 ----------------------*- 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_CEILF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CEILF128_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 ceilf128(float128 x) { return fputil::ceil(x); }
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CEILF128_H
diff --git a/libc/src/__support/math/ceilf16.h b/libc/src/__support/math/ceilf16.h
new file mode 100644
index 0000000000000..c5a8e432b1fe6
--- /dev/null
+++ b/libc/src/__support/math/ceilf16.h
@@ -0,0 +1,38 @@
+//===-- Implementation header for ceilf16 -----------------------*- 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_CEILF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CEILF16_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 ceilf16(float16 x) {
+#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
+ defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
+ return fputil::cast<float16>(__builtin_ceilf(x));
+#else
+ return fputil::ceil(x);
+#endif
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CEILF16_H
diff --git a/libc/src/__support/math/ceill.h b/libc/src/__support/math/ceill.h
new file mode 100644
index 0000000000000..54aa86796933a
--- /dev/null
+++ b/libc/src/__support/math/ceill.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for ceill -------------------------*- 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_CEILL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_CEILL_H
+
+#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE long double ceill(long double x) {
+ return fputil::ceil(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CEILL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 57a29665318a3..32329680dc58b 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -125,9 +125,7 @@ add_entrypoint_object(
HDRS
../ceil.h
DEPENDS
- libc.src.__support.FPUtil.nearest_integer_operations
- FLAGS
- ROUND_OPT
+ libc.src.__support.math.ceil
)
add_entrypoint_object(
@@ -137,9 +135,7 @@ add_entrypoint_object(
HDRS
../ceilf.h
DEPENDS
- libc.src.__support.FPUtil.nearest_integer_operations
- FLAGS
- ROUND_OPT
+ libc.src.__support.math.ceilf
)
add_entrypoint_object(
@@ -149,7 +145,7 @@ add_entrypoint_object(
HDRS
../ceill.h
DEPENDS
- libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.math.ceill
)
add_entrypoint_object(
@@ -159,12 +155,7 @@ add_entrypoint_object(
HDRS
../ceilf16.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.ceilf16
)
add_entrypoint_object(
@@ -174,8 +165,7 @@ add_entrypoint_object(
HDRS
../ceilf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.nearest_integer_operations
+ libc.src.__support.math.ceilf128
)
add_entrypoint_object(
@@ -185,13 +175,7 @@ add_entrypoint_object(
HDRS
../ceilbf16.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.ceilbf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/ceil.cpp b/libc/src/math/generic/ceil.cpp
index 72c6e990fcc71..bb0cd7b869566 100644
--- a/libc/src/math/generic/ceil.cpp
+++ b/libc/src/math/generic/ceil.cpp
@@ -7,18 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/ceil.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ceil.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(double, ceil, (double x)) {
-#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
- return __builtin_ceil(x);
-#else
- return fputil::ceil(x);
-#endif
-}
+LLVM_LIBC_FUNCTION(double, ceil, (double x)) { return math::ceil(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ceilbf16.cpp b/libc/src/math/generic/ceilbf16.cpp
index 441dcf0e93d6f..0abb7b22cbc6b 100644
--- a/libc/src/math/generic/ceilbf16.cpp
+++ b/libc/src/math/generic/ceilbf16.cpp
@@ -7,13 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/ceilbf16.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/ceilbf16.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(bfloat16, ceilbf16, (bfloat16 x)) { return fputil::ceil(x); }
+LLVM_LIBC_FUNCTION(bfloat16, ceilbf16, (bfloat16 x)) {
+ return math::ceilbf16(x);
+}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ceilf.cpp b/libc/src/math/generic/ceilf.cpp
index dfd0dc62bc51b..f13371354d273 100644
--- a/libc/src/math/generic/ceilf.cpp
+++ b/libc/src/math/generic/ceilf.cpp
@@ -7,18 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/ceilf.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ceilf.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float, ceilf, (float x)) {
-#ifdef __LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC
- return __builtin_ceilf(x);
-#else
- return fputil::ceil(x);
-#endif
-}
+LLVM_LIBC_FUNCTION(float, ceilf, (float x)) { return math::ceilf(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ceilf128.cpp b/libc/src/math/generic/ceilf128.cpp
index 5d0cf46933cdf..fd9c206612207 100644
--- a/libc/src/math/generic/ceilf128.cpp
+++ b/libc/src/math/generic/ceilf128.cpp
@@ -7,12 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/ceilf128.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ceilf128.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float128, ceilf128, (float128 x)) { return fputil::ceil(x); }
+LLVM_LIBC_FUNCTION(float128, ceilf128, (float128 x)) {
+ return math::ceilf128(x);
+}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ceilf16.cpp b/libc/src/math/generic/ceilf16.cpp
index 9d89efc5311d1..74fe2e5e0ad52 100644
--- a/libc/src/math/generic/ceilf16.cpp
+++ b/libc/src/math/generic/ceilf16.cpp
@@ -7,21 +7,10 @@
//===----------------------------------------------------------------------===//
#include "src/math/ceilf16.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/ceilf16.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float16, ceilf16, (float16 x)) {
-#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
- defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
- return fputil::cast<float16>(__builtin_ceilf(x));
-#else
- return fputil::ceil(x);
-#endif
-}
+LLVM_LIBC_FUNCTION(float16, ceilf16, (float16 x)) { return math::ceilf16(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ceill.cpp b/libc/src/math/generic/ceill.cpp
index bce9d557be78a..42cae448bc989 100644
--- a/libc/src/math/generic/ceill.cpp
+++ b/libc/src/math/generic/ceill.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/ceill.h"
-#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/ceill.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(long double, ceill, (long double x)) {
- return fputil::ceil(x);
+ return math::ceill(x);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 53ad309af4f30..6ed83372d7b62 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -41,6 +41,12 @@ add_fp_unittest(
libc.src.__support.math.canonicalizel
libc.src.__support.math.cbrt
libc.src.__support.math.cbrtf
+ libc.src.__support.math.ceil
+ libc.src.__support.math.ceilbf16
+ libc.src.__support.math.ceilf
+ libc.src.__support.math.ceilf128
+ libc.src.__support.math.ceilf16
+ libc.src.__support.math.ceill
libc.src.__support.math.cos
libc.src.__support.math.cosf
libc.src.__support.math.cosf16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 7f2f39ac7a285..92cd48712b615 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -88,6 +88,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef16(&canonicalizef16_cx,
&canonicalizef16_x));
EXPECT_FP_EQ(0x0p+0f16, canonicalizef16_cx);
+
+ EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::ceilf16(0.0f16));
}
#endif // LIBC_TYPES_HAS_FLOAT16
@@ -150,6 +152,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef(&canonicalizef_cx,
&canonicalizef_x));
EXPECT_FP_EQ(0x0p+0f, canonicalizef_cx);
+
+ EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::ceilf(0.0f));
}
TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -187,6 +191,8 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalize(&canonicalize_cx,
&canonicalize_x));
EXPECT_FP_EQ(0.0, canonicalize_cx);
+
+ EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::ceil(0.0));
}
TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -203,6 +209,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizel(&canonicalizel_cx,
&canonicalizel_x));
EXPECT_FP_EQ(0x0p+0L, canonicalizel_cx);
+ EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::ceill(0.0L));
}
#ifdef LIBC_TYPES_HAS_FLOAT128
@@ -238,6 +245,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef128(&canonicalizef128_cx,
&canonicalizef128_x));
EXPECT_FP_EQ(float128(0.0), canonicalizef128_cx);
+
+ EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::ceilf128(float128(0.0)));
}
#endif // LIBC_TYPES_HAS_FLOAT128
@@ -257,4 +266,6 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
EXPECT_FP_EQ(bfloat16(5.0), LIBC_NAMESPACE::shared::bf16addf(2.0f, 3.0f));
EXPECT_FP_EQ(bfloat16(10.0),
LIBC_NAMESPACE::shared::bf16fmaf(2.0f, 3.0f, 4.0f));
+
+ EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::ceilbf16(bfloat16(0.0)));
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index b90688af7a1d2..9b32a92082816 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2786,6 +2786,64 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_ceil",
+ hdrs = ["src/__support/math/ceil.h"],
+ deps = [
+ ":__support_fputil_nearest_integer_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_ceilbf16",
+ hdrs = ["src/__support/math/ceilbf16.h"],
+ deps = [
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_nearest_integer_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_ceilf",
+ hdrs = ["src/__support/math/ceilf.h"],
+ deps = [
+ ":__support_fputil_nearest_integer_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_ceilf128",
+ hdrs = ["src/__support/math/ceilf128.h"],
+ deps = [
+ ":__support_fputil_nearest_integer_operations",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_ceilf16",
+ hdrs = ["src/__support/math/ceilf16.h"],
+ deps = [
+ ":__support_fputil_cast",
+ ":__support_fputil_nearest_integer_operations",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_ceill",
+ hdrs = ["src/__support/math/ceill.h"],
+ deps = [
+ ":__support_fputil_nearest_integer_operations",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_common_constants",
hdrs = ["src/__support/math/common_constants.h"],
@@ -4675,15 +4733,47 @@ libc_math_function(
additional_deps = [":__support_math_cbrtf"],
)
-libc_math_function(name = "ceil")
+libc_math_function(
+ name = "ceil",
+ additional_deps = [
+ ":__support_math_ceil",
+ ],
+)
-libc_math_function(name = "ceilf")
+libc_math_function(
+ name = "ceilbf16",
+ additional_deps = [
+ ":__support_math_ceilbf16",
+ ],
+)
-libc_math_function(name = "ceill")
+libc_math_function(
+ name = "ceilf",
+ additional_deps = [
+ ":__support_math_ceilf",
+ ],
+)
-libc_math_function(name = "ceilf128")
+libc_math_function(
+ name = "ceill",
+ additional_deps = [
+ ":__support_math_ceill",
+ ],
+)
-libc_math_function(name = "ceilf16")
+libc_math_function(
+ name = "ceilf128",
+ additional_deps = [
+ ":__support_math_ceilf128",
+ ],
+)
+
+libc_math_function(
+ name = "ceilf16",
+ additional_deps = [
+ ":__support_math_ceilf16",
+ ],
+)
libc_math_function(name = "copysign")
More information about the libc-commits
mailing list