[libc-commits] [libc] [llvm] [libc][math] Refactor fmod-modf family to header-only (PR #195406)
via libc-commits
libc-commits at lists.llvm.org
Fri May 1 20:21:38 PDT 2026
https://github.com/AnonMiraj created https://github.com/llvm/llvm-project/pull/195406
Refactors the fmod-modf math family to be header-only.
part of: #147386
Target Functions:
- fmod
- fmodbf16
- fmodf
- fmodf128
- fmodf16
- fmodl
- modf
- modfbf16
- modff
- modff128
- modff16
- modfl
>From a9128de9acc4d2523aae8edd8ad110d33f50feda Mon Sep 17 00:00:00 2001
From: Anonmiraj <ezzibrahimx at gmail.com>
Date: Sat, 2 May 2026 06:21:23 +0300
Subject: [PATCH] [libc][math] Refactor fmod-modf family to header-only
Refactored functions:
- fmod
- fmodbf16
- fmodf
- fmodf128
- fmodf16
- fmodl
- modf
- modfbf16
- modff
- modff128
- modff16
- modfl
---
libc/shared/math.h | 12 ++
libc/shared/math/fmod.h | 23 +++
libc/shared/math/fmodbf16.h | 23 +++
libc/shared/math/fmodf.h | 23 +++
libc/shared/math/fmodf128.h | 29 +++
libc/shared/math/fmodf16.h | 29 +++
libc/shared/math/fmodl.h | 23 +++
libc/shared/math/modf.h | 23 +++
libc/shared/math/modfbf16.h | 23 +++
libc/shared/math/modff.h | 23 +++
libc/shared/math/modff128.h | 29 +++
libc/shared/math/modff16.h | 29 +++
libc/shared/math/modfl.h | 23 +++
libc/src/__support/FPUtil/generic/FMod.h | 10 +-
libc/src/__support/math/CMakeLists.txt | 113 ++++++++++++
libc/src/__support/math/fmod.h | 25 +++
libc/src/__support/math/fmodbf16.h | 26 +++
libc/src/__support/math/fmodf.h | 25 +++
libc/src/__support/math/fmodf128.h | 31 ++++
libc/src/__support/math/fmodf16.h | 31 ++++
libc/src/__support/math/fmodl.h | 25 +++
libc/src/__support/math/modf.h | 25 +++
libc/src/__support/math/modfbf16.h | 26 +++
libc/src/__support/math/modff.h | 25 +++
libc/src/__support/math/modff128.h | 31 ++++
libc/src/__support/math/modff16.h | 31 ++++
libc/src/__support/math/modfl.h | 25 +++
libc/src/math/generic/CMakeLists.txt | 36 ++--
libc/src/math/generic/fmod.cpp | 6 +-
libc/src/math/generic/fmodbf16.cpp | 7 +-
libc/src/math/generic/fmodf.cpp | 6 +-
libc/src/math/generic/fmodf128.cpp | 6 +-
libc/src/math/generic/fmodf16.cpp | 6 +-
libc/src/math/generic/fmodl.cpp | 6 +-
libc/src/math/generic/modf.cpp | 6 +-
libc/src/math/generic/modfbf16.cpp | 7 +-
libc/src/math/generic/modff.cpp | 6 +-
libc/src/math/generic/modff128.cpp | 6 +-
libc/src/math/generic/modff16.cpp | 6 +-
libc/src/math/generic/modfl.cpp | 6 +-
libc/test/shared/CMakeLists.txt | 24 +++
.../shared/shared_math_constexpr_test.cpp | 8 +
libc/test/shared/shared_math_test.cpp | 29 +++
.../llvm-project-overlay/libc/BUILD.bazel | 167 ++++++++++++++++--
44 files changed, 1010 insertions(+), 89 deletions(-)
create mode 100644 libc/shared/math/fmod.h
create mode 100644 libc/shared/math/fmodbf16.h
create mode 100644 libc/shared/math/fmodf.h
create mode 100644 libc/shared/math/fmodf128.h
create mode 100644 libc/shared/math/fmodf16.h
create mode 100644 libc/shared/math/fmodl.h
create mode 100644 libc/shared/math/modf.h
create mode 100644 libc/shared/math/modfbf16.h
create mode 100644 libc/shared/math/modff.h
create mode 100644 libc/shared/math/modff128.h
create mode 100644 libc/shared/math/modff16.h
create mode 100644 libc/shared/math/modfl.h
create mode 100644 libc/src/__support/math/fmod.h
create mode 100644 libc/src/__support/math/fmodbf16.h
create mode 100644 libc/src/__support/math/fmodf.h
create mode 100644 libc/src/__support/math/fmodf128.h
create mode 100644 libc/src/__support/math/fmodf16.h
create mode 100644 libc/src/__support/math/fmodl.h
create mode 100644 libc/src/__support/math/modf.h
create mode 100644 libc/src/__support/math/modfbf16.h
create mode 100644 libc/src/__support/math/modff.h
create mode 100644 libc/src/__support/math/modff128.h
create mode 100644 libc/src/__support/math/modff16.h
create mode 100644 libc/src/__support/math/modfl.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 6d2b573244c0c..7b34492586467 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -211,6 +211,12 @@
#include "math/fminimumf16.h"
#include "math/fminimuml.h"
#include "math/fminl.h"
+#include "math/fmod.h"
+#include "math/fmodbf16.h"
+#include "math/fmodf.h"
+#include "math/fmodf128.h"
+#include "math/fmodf16.h"
+#include "math/fmodl.h"
#include "math/frexpf.h"
#include "math/frexpf128.h"
#include "math/frexpf16.h"
@@ -262,6 +268,12 @@
#include "math/logbl.h"
#include "math/logf.h"
#include "math/logf16.h"
+#include "math/modf.h"
+#include "math/modfbf16.h"
+#include "math/modff.h"
+#include "math/modff128.h"
+#include "math/modff16.h"
+#include "math/modfl.h"
#include "math/nextafter.h"
#include "math/nextafterbf16.h"
#include "math/nextafterf.h"
diff --git a/libc/shared/math/fmod.h b/libc/shared/math/fmod.h
new file mode 100644
index 0000000000000..7c90e2392fe49
--- /dev/null
+++ b/libc/shared/math/fmod.h
@@ -0,0 +1,23 @@
+//===-- Shared fmod 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_FMOD_H
+#define LLVM_LIBC_SHARED_MATH_FMOD_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmod.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmod;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMOD_H
diff --git a/libc/shared/math/fmodbf16.h b/libc/shared/math/fmodbf16.h
new file mode 100644
index 0000000000000..71f1f2f7f4c19
--- /dev/null
+++ b/libc/shared/math/fmodbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared fmodbf16 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_FMODBF16_H
+#define LLVM_LIBC_SHARED_MATH_FMODBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmodbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmodbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMODBF16_H
diff --git a/libc/shared/math/fmodf.h b/libc/shared/math/fmodf.h
new file mode 100644
index 0000000000000..bec012c77a9a3
--- /dev/null
+++ b/libc/shared/math/fmodf.h
@@ -0,0 +1,23 @@
+//===-- Shared fmodf 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_FMODF_H
+#define LLVM_LIBC_SHARED_MATH_FMODF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmodf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmodf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMODF_H
diff --git a/libc/shared/math/fmodf128.h b/libc/shared/math/fmodf128.h
new file mode 100644
index 0000000000000..9d1c48477d79e
--- /dev/null
+++ b/libc/shared/math/fmodf128.h
@@ -0,0 +1,29 @@
+//===-- Shared fmodf128 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_FMODF128_H
+#define LLVM_LIBC_SHARED_MATH_FMODF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmodf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmodf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_FMODF128_H
diff --git a/libc/shared/math/fmodf16.h b/libc/shared/math/fmodf16.h
new file mode 100644
index 0000000000000..e2944fddb5a3d
--- /dev/null
+++ b/libc/shared/math/fmodf16.h
@@ -0,0 +1,29 @@
+//===-- Shared fmodf16 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_FMODF16_H
+#define LLVM_LIBC_SHARED_MATH_FMODF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmodf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmodf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_FMODF16_H
diff --git a/libc/shared/math/fmodl.h b/libc/shared/math/fmodl.h
new file mode 100644
index 0000000000000..6b61bbf57a175
--- /dev/null
+++ b/libc/shared/math/fmodl.h
@@ -0,0 +1,23 @@
+//===-- Shared fmodl 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_FMODL_H
+#define LLVM_LIBC_SHARED_MATH_FMODL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/fmodl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::fmodl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_FMODL_H
diff --git a/libc/shared/math/modf.h b/libc/shared/math/modf.h
new file mode 100644
index 0000000000000..3b16dac78ea3b
--- /dev/null
+++ b/libc/shared/math/modf.h
@@ -0,0 +1,23 @@
+//===-- Shared modf 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_MODF_H
+#define LLVM_LIBC_SHARED_MATH_MODF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_MODF_H
diff --git a/libc/shared/math/modfbf16.h b/libc/shared/math/modfbf16.h
new file mode 100644
index 0000000000000..3cecf890bb588
--- /dev/null
+++ b/libc/shared/math/modfbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared modfbf16 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_MODFBF16_H
+#define LLVM_LIBC_SHARED_MATH_MODFBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modfbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modfbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_MODFBF16_H
diff --git a/libc/shared/math/modff.h b/libc/shared/math/modff.h
new file mode 100644
index 0000000000000..23752ba41daf6
--- /dev/null
+++ b/libc/shared/math/modff.h
@@ -0,0 +1,23 @@
+//===-- Shared modff 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_MODFF_H
+#define LLVM_LIBC_SHARED_MATH_MODFF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modff.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modff;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_MODFF_H
diff --git a/libc/shared/math/modff128.h b/libc/shared/math/modff128.h
new file mode 100644
index 0000000000000..bbc6b8e4d09c0
--- /dev/null
+++ b/libc/shared/math/modff128.h
@@ -0,0 +1,29 @@
+//===-- Shared modff128 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_MODFF128_H
+#define LLVM_LIBC_SHARED_MATH_MODFF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modff128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modff128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_MODFF128_H
diff --git a/libc/shared/math/modff16.h b/libc/shared/math/modff16.h
new file mode 100644
index 0000000000000..6cefd1dc99ae1
--- /dev/null
+++ b/libc/shared/math/modff16.h
@@ -0,0 +1,29 @@
+//===-- Shared modff16 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_MODFF16_H
+#define LLVM_LIBC_SHARED_MATH_MODFF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modff16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modff16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_MODFF16_H
diff --git a/libc/shared/math/modfl.h b/libc/shared/math/modfl.h
new file mode 100644
index 0000000000000..9b900797d114f
--- /dev/null
+++ b/libc/shared/math/modfl.h
@@ -0,0 +1,23 @@
+//===-- Shared modfl 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_MODFL_H
+#define LLVM_LIBC_SHARED_MATH_MODFL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/modfl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::modfl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_MODFL_H
diff --git a/libc/src/__support/FPUtil/generic/FMod.h b/libc/src/__support/FPUtil/generic/FMod.h
index 30d6472085f6f..b74b8b7d1b18d 100644
--- a/libc/src/__support/FPUtil/generic/FMod.h
+++ b/libc/src/__support/FPUtil/generic/FMod.h
@@ -170,7 +170,7 @@ class FMod {
using FPB = FPBits<T>;
using StorageType = typename FPB::StorageType;
- LIBC_INLINE static bool pre_check(T x, T y, T &out) {
+ LIBC_INLINE static constexpr bool pre_check(T x, T y, T &out) {
using FPB = fputil::FPBits<T>;
const T quiet_nan = FPB::quiet_nan().get_val();
FPB sx(x), sy(y);
@@ -200,8 +200,8 @@ class FMod {
if (LIBC_LIKELY(sx.uintval() <= sy.uintval())) {
if (sx.uintval() < sy.uintval())
- return sx; // |x|<|y| return x
- return FPB::zero(); // |x|=|y| return 0.0
+ return sx; // |x|<|y| return x
+ return FPB::zero(); // |x|=|y| return 0.0
}
int e_x = sx.get_biased_exponent();
@@ -276,8 +276,8 @@ class FMod {
}
public:
- LIBC_INLINE static T eval(T x, T y) {
- if (T out; LIBC_UNLIKELY(pre_check(x, y, out)))
+ LIBC_INLINE static constexpr T eval(T x, T y) {
+ if (T out{}; LIBC_UNLIKELY(pre_check(x, y, out)))
return out;
FPB sx(x), sy(y);
Sign sign = sx.sign();
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index dad34b0023154..d36b6d9196e75 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1157,6 +1157,62 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ fmod
+ HDRS
+ fmod.h
+ DEPENDS
+ libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fmodbf16
+ HDRS
+ fmodbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fmodf
+ HDRS
+ fmodf.h
+ DEPENDS
+ libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fmodf128
+ HDRS
+ fmodf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fmodf16
+ HDRS
+ fmodf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ fmodl
+ HDRS
+ fmodl.h
+ DEPENDS
+ libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.macros.config
+)
add_header_library(
llogbbf16
@@ -1178,6 +1234,63 @@ add_header_library(
libc.src.__support.macros.config
)
+add_header_library(
+ modf
+ HDRS
+ modf.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ modfbf16
+ HDRS
+ modfbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ modff
+ HDRS
+ modff.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ modff128
+ HDRS
+ modff128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ modff16
+ HDRS
+ modff16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ modfl
+ HDRS
+ modfl.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
add_header_library(
sincos_integer_utils
HDRS
diff --git a/libc/src/__support/math/fmod.h b/libc/src/__support/math/fmod.h
new file mode 100644
index 0000000000000..79c48708d8aec
--- /dev/null
+++ b/libc/src/__support/math/fmod.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmod --------------------------*- 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_FMOD_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMOD_H
+
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double fmod(double x, double y) {
+ return fputil::generic::FMod<double>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMOD_H
diff --git a/libc/src/__support/math/fmodbf16.h b/libc/src/__support/math/fmodbf16.h
new file mode 100644
index 0000000000000..8f0bfbce4d16d
--- /dev/null
+++ b/libc/src/__support/math/fmodbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for fmodbf16 ----------------------*- 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_FMODBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMODBF16_H
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 fmodbf16(bfloat16 x, bfloat16 y) {
+ return fputil::generic::FMod<bfloat16>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODBF16_H
diff --git a/libc/src/__support/math/fmodf.h b/libc/src/__support/math/fmodf.h
new file mode 100644
index 0000000000000..0209da81539d5
--- /dev/null
+++ b/libc/src/__support/math/fmodf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmodf -------------------------*- 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_FMODF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMODF_H
+
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float fmodf(float x, float y) {
+ return fputil::generic::FMod<float, uint64_t>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODF_H
diff --git a/libc/src/__support/math/fmodf128.h b/libc/src/__support/math/fmodf128.h
new file mode 100644
index 0000000000000..b15c1e17caab8
--- /dev/null
+++ b/libc/src/__support/math/fmodf128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for fmodf128 ----------------------*- 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_FMODF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMODF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float128 fmodf128(float128 x, float128 y) {
+ return fputil::generic::FMod<float128>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODF128_H
diff --git a/libc/src/__support/math/fmodf16.h b/libc/src/__support/math/fmodf16.h
new file mode 100644
index 0000000000000..d69dfbb03d331
--- /dev/null
+++ b/libc/src/__support/math/fmodf16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for fmodf16 -----------------------*- 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_FMODF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMODF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float16 fmodf16(float16 x, float16 y) {
+ return fputil::generic::FMod<float16, uint32_t>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODF16_H
diff --git a/libc/src/__support/math/fmodl.h b/libc/src/__support/math/fmodl.h
new file mode 100644
index 0000000000000..5625fb875dbaf
--- /dev/null
+++ b/libc/src/__support/math/fmodl.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for fmodl -------------------------*- 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_FMODL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_FMODL_H
+
+#include "src/__support/FPUtil/generic/FMod.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr long double fmodl(long double x, long double y) {
+ return fputil::generic::FMod<long double>::eval(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMODL_H
diff --git a/libc/src/__support/math/modf.h b/libc/src/__support/math/modf.h
new file mode 100644
index 0000000000000..6625cd4c22ddc
--- /dev/null
+++ b/libc/src/__support/math/modf.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for modf --------------------------*- 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_MODF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODF_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr double modf(double x, double *iptr) {
+ return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODF_H
diff --git a/libc/src/__support/math/modfbf16.h b/libc/src/__support/math/modfbf16.h
new file mode 100644
index 0000000000000..ef8085204d1af
--- /dev/null
+++ b/libc/src/__support/math/modfbf16.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for modfbf16 ----------------------*- 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_MODFBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODFBF16_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 modfbf16(bfloat16 x, bfloat16 *iptr) {
+ return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODFBF16_H
diff --git a/libc/src/__support/math/modff.h b/libc/src/__support/math/modff.h
new file mode 100644
index 0000000000000..6ddb5b539a178
--- /dev/null
+++ b/libc/src/__support/math/modff.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for modff -------------------------*- 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_MODFF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODFF_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float modff(float x, float *iptr) {
+ return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODFF_H
diff --git a/libc/src/__support/math/modff128.h b/libc/src/__support/math/modff128.h
new file mode 100644
index 0000000000000..69688dd255151
--- /dev/null
+++ b/libc/src/__support/math/modff128.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for modff128 ----------------------*- 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_MODFF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODFF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float128 modff128(float128 x, float128 *iptr) {
+ return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODFF128_H
diff --git a/libc/src/__support/math/modff16.h b/libc/src/__support/math/modff16.h
new file mode 100644
index 0000000000000..46fb98caee16b
--- /dev/null
+++ b/libc/src/__support/math/modff16.h
@@ -0,0 +1,31 @@
+//===-- Implementation header for modff16 -----------------------*- 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_MODFF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODFF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr float16 modff16(float16 x, float16 *iptr) {
+ return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODFF16_H
diff --git a/libc/src/__support/math/modfl.h b/libc/src/__support/math/modfl.h
new file mode 100644
index 0000000000000..d016a4c45237b
--- /dev/null
+++ b/libc/src/__support/math/modfl.h
@@ -0,0 +1,25 @@
+//===-- Implementation header for modfl -------------------------*- 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_MODFL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_MODFL_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace math {
+
+LIBC_INLINE constexpr long double modfl(long double x, long double *iptr) {
+ return fputil::modf(x, *iptr);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_MODFL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index df6e2dd9dbfc0..f78fd112e6603 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -2001,7 +2001,7 @@ add_entrypoint_object(
HDRS
../modf.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.modf
)
add_entrypoint_object(
@@ -2011,7 +2011,7 @@ add_entrypoint_object(
HDRS
../modff.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.modff
)
add_entrypoint_object(
@@ -2021,7 +2021,7 @@ add_entrypoint_object(
HDRS
../modfl.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.modfl
)
add_entrypoint_object(
@@ -2031,8 +2031,7 @@ add_entrypoint_object(
HDRS
../modff16.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.modff16
)
add_entrypoint_object(
@@ -2042,8 +2041,7 @@ add_entrypoint_object(
HDRS
../modff128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.modff128
)
add_entrypoint_object(
@@ -2053,11 +2051,7 @@ add_entrypoint_object(
HDRS
../modfbf16.h
DEPENDS
- libc.src.__support.common
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.manipulation_functions
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.modfbf16
)
add_entrypoint_object(
@@ -3489,7 +3483,7 @@ add_entrypoint_object(
HDRS
../fmod.h
DEPENDS
- libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.math.fmod
)
add_entrypoint_object(
@@ -3499,7 +3493,7 @@ add_entrypoint_object(
HDRS
../fmodf.h
DEPENDS
- libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.math.fmodf
)
add_entrypoint_object(
@@ -3509,7 +3503,7 @@ add_entrypoint_object(
HDRS
../fmodl.h
DEPENDS
- libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.math.fmodl
)
add_entrypoint_object(
@@ -3519,8 +3513,7 @@ add_entrypoint_object(
HDRS
../fmodf16.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.math.fmodf16
)
add_entrypoint_object(
@@ -3530,8 +3523,7 @@ add_entrypoint_object(
HDRS
../fmodf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.math.fmodf128
)
add_entrypoint_object(
@@ -3541,11 +3533,7 @@ add_entrypoint_object(
HDRS
../fmodbf16.h
DEPENDS
- libc.src.__support.common
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.generic.fmod
+ libc.src.__support.math.fmodbf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/fmod.cpp b/libc/src/math/generic/fmod.cpp
index 010e66aa745ca..88b4676aeff36 100644
--- a/libc/src/math/generic/fmod.cpp
+++ b/libc/src/math/generic/fmod.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fmod.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmod.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(double, fmod, (double x, double y)) {
- return fputil::generic::FMod<double>::eval(x, y);
+ return math::fmod(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmodbf16.cpp b/libc/src/math/generic/fmodbf16.cpp
index 902a680fe860c..4cd3d4df360e7 100644
--- a/libc/src/math/generic/fmodbf16.cpp
+++ b/libc/src/math/generic/fmodbf16.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fmodbf16.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmodbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, fmodbf16, (bfloat16 x, bfloat16 y)) {
- return fputil::generic::FMod<bfloat16>::eval(x, y);
+ return math::fmodbf16(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmodf.cpp b/libc/src/math/generic/fmodf.cpp
index 1e1ef48895cc7..563d799d90081 100644
--- a/libc/src/math/generic/fmodf.cpp
+++ b/libc/src/math/generic/fmodf.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fmodf.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmodf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, fmodf, (float x, float y)) {
- return fputil::generic::FMod<float, uint64_t>::eval(x, y);
+ return math::fmodf(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmodf128.cpp b/libc/src/math/generic/fmodf128.cpp
index a7633bf9c2fff..c72ec7ec1cdf5 100644
--- a/libc/src/math/generic/fmodf128.cpp
+++ b/libc/src/math/generic/fmodf128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fmodf128.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmodf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float128, fmodf128, (float128 x, float128 y)) {
- return fputil::generic::FMod<float128>::eval(x, y);
+ return math::fmodf128(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmodf16.cpp b/libc/src/math/generic/fmodf16.cpp
index 2585639559496..121153a23a4b3 100644
--- a/libc/src/math/generic/fmodf16.cpp
+++ b/libc/src/math/generic/fmodf16.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fmodf16.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmodf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, fmodf16, (float16 x, float16 y)) {
- return fputil::generic::FMod<float16, uint32_t>::eval(x, y);
+ return math::fmodf16(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/fmodl.cpp b/libc/src/math/generic/fmodl.cpp
index 1af8ffc976ddd..dbf87288c6d88 100644
--- a/libc/src/math/generic/fmodl.cpp
+++ b/libc/src/math/generic/fmodl.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/fmodl.h"
-#include "src/__support/FPUtil/generic/FMod.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/fmodl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(long double, fmodl, (long double x, long double y)) {
- return fputil::generic::FMod<long double>::eval(x, y);
+ return math::fmodl(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modf.cpp b/libc/src/math/generic/modf.cpp
index ce56aa0bcf544..24a9d1c6a2364 100644
--- a/libc/src/math/generic/modf.cpp
+++ b/libc/src/math/generic/modf.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/modf.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(double, modf, (double x, double *iptr)) {
- return fputil::modf(x, *iptr);
+ return math::modf(x, iptr);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modfbf16.cpp b/libc/src/math/generic/modfbf16.cpp
index 09458f6a2db40..8f5932220264a 100644
--- a/libc/src/math/generic/modfbf16.cpp
+++ b/libc/src/math/generic/modfbf16.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/modfbf16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modfbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, modfbf16, (bfloat16 x, bfloat16 *iptr)) {
- return fputil::modf(x, *iptr);
+ return math::modfbf16(x, iptr);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modff.cpp b/libc/src/math/generic/modff.cpp
index c86a4fb279c7f..2576b0d294b57 100644
--- a/libc/src/math/generic/modff.cpp
+++ b/libc/src/math/generic/modff.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/modff.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modff.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, modff, (float x, float *iptr)) {
- return fputil::modf(x, *iptr);
+ return math::modff(x, iptr);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modff128.cpp b/libc/src/math/generic/modff128.cpp
index 6f519a6901105..099bb2e907fb8 100644
--- a/libc/src/math/generic/modff128.cpp
+++ b/libc/src/math/generic/modff128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/modff128.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modff128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float128, modff128, (float128 x, float128 *iptr)) {
- return fputil::modf(x, *iptr);
+ return math::modff128(x, iptr);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modff16.cpp b/libc/src/math/generic/modff16.cpp
index 853fc55e26bab..c474672b90a70 100644
--- a/libc/src/math/generic/modff16.cpp
+++ b/libc/src/math/generic/modff16.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/modff16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modff16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, modff16, (float16 x, float16 *iptr)) {
- return fputil::modf(x, *iptr);
+ return math::modff16(x, iptr);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/modfl.cpp b/libc/src/math/generic/modfl.cpp
index 8c9ab486b5aa3..320dff32a091d 100644
--- a/libc/src/math/generic/modfl.cpp
+++ b/libc/src/math/generic/modfl.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/modfl.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/modfl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(long double, modfl, (long double x, long double *iptr)) {
- return fputil::modf(x, *iptr);
+ return math::modfl(x, iptr);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index b716d246d3f7b..5dc546b88677d 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -208,6 +208,12 @@ add_fp_unittest(
libc.src.__support.math.fminimumf16
libc.src.__support.math.fminimuml
libc.src.__support.math.fminl
+ libc.src.__support.math.fmod
+ libc.src.__support.math.fmodbf16
+ libc.src.__support.math.fmodf
+ libc.src.__support.math.fmodf128
+ libc.src.__support.math.fmodf16
+ libc.src.__support.math.fmodl
libc.src.__support.math.frexpf
libc.src.__support.math.frexpf128
libc.src.__support.math.frexpf16
@@ -260,6 +266,12 @@ add_fp_unittest(
libc.src.__support.math.logbl
libc.src.__support.math.logf16
libc.src.__support.math.llogbl
+ libc.src.__support.math.modf
+ libc.src.__support.math.modfbf16
+ libc.src.__support.math.modff
+ libc.src.__support.math.modff128
+ libc.src.__support.math.modff16
+ libc.src.__support.math.modfl
libc.src.__support.math.nextdown
libc.src.__support.math.nextdownbf16
libc.src.__support.math.nextdownf
@@ -403,10 +415,22 @@ add_fp_unittest(
libc.src.__support.math.fminimumf16
libc.src.__support.math.fminimuml
libc.src.__support.math.fminl
+ libc.src.__support.math.fmod
+ libc.src.__support.math.fmodbf16
+ libc.src.__support.math.fmodf
+ libc.src.__support.math.fmodf128
+ libc.src.__support.math.fmodf16
+ libc.src.__support.math.fmodl
libc.src.__support.math.llogbbf16
libc.src.__support.math.log
libc.src.__support.math.logbbf16
libc.src.__support.math.ilogbbf16
+ libc.src.__support.math.modf
+ libc.src.__support.math.modfbf16
+ libc.src.__support.math.modff
+ libc.src.__support.math.modff128
+ libc.src.__support.math.modff16
+ libc.src.__support.math.modfl
libc.src.__support.math.sqrtl
)
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 403a010c3c59d..cadcf1f908d42 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -29,6 +29,7 @@ static_assert(0.0 == LIBC_NAMESPACE::shared::fmin(0.0, 0.0));
static_assert(0.0 == LIBC_NAMESPACE::shared::fmax(0.0, 0.0));
static_assert(0.0 == LIBC_NAMESPACE::shared::fmaximum_num(0.0, 0.0));
static_assert(0.0 == LIBC_NAMESPACE::shared::fminimum_num(0.0, 0.0));
+static_assert(0.0 == LIBC_NAMESPACE::shared::fmod(4.0, 2.0));
//===----------------------------------------------------------------------===//
// Float Tests
@@ -46,6 +47,7 @@ static_assert(0.0f == LIBC_NAMESPACE::shared::fminf(0.0f, 0.0f));
static_assert(0.0f == LIBC_NAMESPACE::shared::fmaxf(0.0f, 0.0f));
static_assert(0.0f == LIBC_NAMESPACE::shared::fmaximum_numf(0.0f, 0.0f));
static_assert(0.0f == LIBC_NAMESPACE::shared::fminimum_numf(0.0f, 0.0f));
+static_assert(0.0f == LIBC_NAMESPACE::shared::fmodf(4.0f, 2.0f));
//===----------------------------------------------------------------------===//
// Float16 Tests
@@ -66,6 +68,7 @@ static_assert(0.0f16 ==
LIBC_NAMESPACE::shared::fmaximum_numf16(0.0f16, 0.0f16));
static_assert(0.0f16 ==
LIBC_NAMESPACE::shared::fminimum_numf16(0.0f16, 0.0f16));
+static_assert(0.0f16 == LIBC_NAMESPACE::shared::fmodf16(4.0f16, 2.0f16));
#endif // LIBC_TYPES_HAS_FLOAT16
@@ -92,6 +95,7 @@ static_assert(0.0L == LIBC_NAMESPACE::shared::fminl(0.0L, 0.0L));
static_assert(0.0L == LIBC_NAMESPACE::shared::fmaxl(0.0L, 0.0L));
static_assert(0.0L == LIBC_NAMESPACE::shared::fmaximum_numl(0.0L, 0.0L));
static_assert(0.0L == LIBC_NAMESPACE::shared::fminimum_numl(0.0L, 0.0L));
+static_assert(0.0L == LIBC_NAMESPACE::shared::fmodl(4.0L, 2.0L));
#endif
@@ -135,6 +139,8 @@ static_assert(float128(0.0) ==
static_assert(float128(0.0) ==
LIBC_NAMESPACE::shared::fminimum_numf128(float128(0.0),
float128(0.0)));
+static_assert(float128(0.0) ==
+ LIBC_NAMESPACE::shared::fmodf128(float128(4.0), float128(2.0)));
#endif // LIBC_TYPES_HAS_FLOAT128
@@ -176,5 +182,7 @@ static_assert(bfloat16(0.0) ==
static_assert(bfloat16(0.0) ==
LIBC_NAMESPACE::shared::fminimum_numbf16(bfloat16(0.0),
bfloat16(0.0)));
+static_assert(bfloat16(0.0) ==
+ LIBC_NAMESPACE::shared::fmodbf16(bfloat16(4.0), bfloat16(2.0)));
TEST(LlvmLibcSharedMathTest, ConstantEvaluation) {}
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index a71cc858d8b21..78cc2283ff6c3 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -110,6 +110,11 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
LIBC_NAMESPACE::shared::fmaximum_numf16(0.0f16, 0.0f16));
EXPECT_FP_EQ(0x0p+0f16,
LIBC_NAMESPACE::shared::fminimum_numf16(0.0f16, 0.0f16));
+ EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::fmodf16(1.0f16, 1.0f16));
+ float16 modff16_iptr = 0.0f16;
+ EXPECT_FP_EQ(0x0p+0f16,
+ LIBC_NAMESPACE::shared::modff16(0.0f16, &modff16_iptr));
+ EXPECT_FP_EQ(0.0f16, modff16_iptr);
}
#endif // LIBC_TYPES_HAS_FLOAT16
@@ -226,6 +231,10 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fminf(0.0f, 0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fmaximum_numf(0.0f, 0.0f));
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fminimum_numf(0.0f, 0.0f));
+ EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fmodf(1.0f, 1.0f));
+ float modff_iptr = 0.0f;
+ EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::modff(0.0f, &modff_iptr));
+ EXPECT_FP_EQ(0.0f, modff_iptr);
}
TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -318,6 +327,10 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmin(0.0, 0.0));
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmaximum_num(0.0, 0.0));
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fminimum_num(0.0, 0.0));
+ EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmod(1.0, 1.0));
+ double modf_iptr = 0.0;
+ EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::modf(0.0, &modf_iptr));
+ EXPECT_FP_EQ(0.0, modf_iptr);
}
// TODO: Enable the tests when double-double type is supported.
@@ -391,6 +404,10 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fminl(0.0L, 0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fmaximum_numl(0.0L, 0.0L));
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fminimum_numl(0.0L, 0.0L));
+ EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fmodl(1.0L, 1.0L));
+ long double modfl_iptr = 0.0L;
+ EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::modfl(0.0L, &modfl_iptr));
+ EXPECT_FP_EQ(0.0L, modfl_iptr);
}
#endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
@@ -509,6 +526,12 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
float128(0.0), float128(0.0)));
EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::fminimum_numf128(
float128(0.0), float128(0.0)));
+ EXPECT_FP_EQ(float128(0.0),
+ LIBC_NAMESPACE::shared::fmodf128(float128(1.0), float128(1.0)));
+ float128 modff128_iptr = float128(0.0);
+ EXPECT_FP_EQ(float128(0.0),
+ LIBC_NAMESPACE::shared::modff128(float128(0.0), &modff128_iptr));
+ EXPECT_FP_EQ(float128(0.0), modff128_iptr);
}
#endif // LIBC_TYPES_HAS_FLOAT128
@@ -590,4 +613,10 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
bfloat16(0.0), bfloat16(0.0)));
EXPECT_FP_EQ(bfloat16(0.0), LIBC_NAMESPACE::shared::fminimum_numbf16(
bfloat16(0.0), bfloat16(0.0)));
+ EXPECT_FP_EQ(bfloat16(0.0),
+ LIBC_NAMESPACE::shared::fmodbf16(bfloat16(1.0), bfloat16(1.0)));
+ bfloat16 modfbf16_iptr = bfloat16(0.0);
+ EXPECT_FP_EQ(bfloat16(0.0),
+ LIBC_NAMESPACE::shared::modfbf16(bfloat16(0.0), &modfbf16_iptr));
+ EXPECT_FP_EQ(bfloat16(0.0), modfbf16_iptr);
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 652b0819fa31e..026423f7b4671 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -4362,6 +4362,63 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_fmod",
+ hdrs = ["src/__support/math/fmod.h"],
+ deps = [
+ ":__support_fputil_generic_fmod",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_fmodbf16",
+ hdrs = ["src/__support/math/fmodbf16.h"],
+ deps = [
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_generic_fmod",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_fmodf",
+ hdrs = ["src/__support/math/fmodf.h"],
+ deps = [
+ ":__support_fputil_generic_fmod",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_fmodf128",
+ hdrs = ["src/__support/math/fmodf128.h"],
+ deps = [
+ ":__support_fputil_generic_fmod",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_fmodf16",
+ hdrs = ["src/__support/math/fmodf16.h"],
+ deps = [
+ ":__support_fputil_generic_fmod",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_fmodl",
+ hdrs = ["src/__support/math/fmodl.h"],
+ deps = [
+ ":__support_fputil_generic_fmod",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_ilogbbf16",
hdrs = ["src/__support/math/ilogbbf16.h"],
@@ -4372,6 +4429,63 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_modf",
+ hdrs = ["src/__support/math/modf.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_modfbf16",
+ hdrs = ["src/__support/math/modfbf16.h"],
+ deps = [
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_modff",
+ hdrs = ["src/__support/math/modff.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_modff128",
+ hdrs = ["src/__support/math/modff128.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_modff16",
+ hdrs = ["src/__support/math/modff16.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_modfl",
+ hdrs = ["src/__support/math/modfl.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_llogbbf16",
hdrs = ["src/__support/math/llogbbf16.h"],
@@ -8723,38 +8837,43 @@ libc_math_function(
libc_math_function(
name = "fmod",
- additional_deps = [":__support_fputil_generic_fmod"],
+ additional_deps = [
+ ":__support_math_fmod",
+ ],
)
libc_math_function(
name = "fmodbf16",
additional_deps = [
- ":__support_fputil_bfloat16",
- ":__support_fputil_generic_fmod",
+ ":__support_math_fmodbf16",
],
)
libc_math_function(
name = "fmodf",
- additional_deps = [":__support_fputil_generic_fmod"],
+ additional_deps = [
+ ":__support_math_fmodf",
+ ],
)
libc_math_function(
name = "fmodl",
- additional_deps = [":__support_fputil_generic_fmod"],
+ additional_deps = [
+ ":__support_math_fmodl",
+ ],
)
libc_math_function(
name = "fmodf128",
additional_deps = [
- ":__support_fputil_generic_fmod",
+ ":__support_math_fmodf128",
],
)
libc_math_function(
name = "fmodf16",
additional_deps = [
- ":__support_fputil_generic_fmod",
+ ":__support_math_fmodf16",
],
)
@@ -9190,18 +9309,46 @@ libc_math_function(
name = "lroundf16",
)
-libc_math_function(name = "modf")
+libc_math_function(
+ name = "modf",
+ additional_deps = [
+ ":__support_math_modf",
+ ],
+)
+
+libc_math_function(
+ name = "modfbf16",
+ additional_deps = [
+ ":__support_math_modfbf16",
+ ],
+)
-libc_math_function(name = "modff")
+libc_math_function(
+ name = "modff",
+ additional_deps = [
+ ":__support_math_modff",
+ ],
+)
-libc_math_function(name = "modfl")
+libc_math_function(
+ name = "modfl",
+ additional_deps = [
+ ":__support_math_modfl",
+ ],
+)
libc_math_function(
name = "modff128",
+ additional_deps = [
+ ":__support_math_modff128",
+ ],
)
libc_math_function(
name = "modff16",
+ additional_deps = [
+ ":__support_math_modff16",
+ ],
)
libc_math_function(
More information about the libc-commits
mailing list