[libc-commits] [libc] [llvm] [libc][math] Refactor float16 operations to header-only (PR #181745)

via libc-commits libc-commits at lists.llvm.org
Tue Feb 17 11:28:44 PST 2026


https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/181745

>From 945cd8faaa4a02d680b0753d970d1d9be6007713 Mon Sep 17 00:00:00 2001
From: Ezzeldin Ibrahim <ezzibrahimx at gmail.com>
Date: Tue, 17 Feb 2026 09:30:16 +0200
Subject: [PATCH] [libc][math] Refactor float16 operations to header-only

---
 libc/shared/math.h                            |  12 +
 libc/shared/math/f16div.h                     |  28 +++
 libc/shared/math/f16divf.h                    |  28 +++
 libc/shared/math/f16divf128.h                 |  31 +++
 libc/shared/math/f16divl.h                    |  28 +++
 libc/shared/math/f16mul.h                     |  28 +++
 libc/shared/math/f16mulf.h                    |  28 +++
 libc/shared/math/f16mulf128.h                 |  31 +++
 libc/shared/math/f16mull.h                    |  28 +++
 libc/shared/math/f16sub.h                     |  28 +++
 libc/shared/math/f16subf.h                    |  28 +++
 libc/shared/math/f16subf128.h                 |  31 +++
 libc/shared/math/f16subl.h                    |  28 +++
 libc/src/__support/math/CMakeLists.txt        | 124 +++++++++++
 libc/src/__support/math/f16div.h              |  32 +++
 libc/src/__support/math/f16divf.h             |  32 +++
 libc/src/__support/math/f16divf128.h          |  35 +++
 libc/src/__support/math/f16divl.h             |  32 +++
 libc/src/__support/math/f16mul.h              |  32 +++
 libc/src/__support/math/f16mulf.h             |  32 +++
 libc/src/__support/math/f16mulf128.h          |  35 +++
 libc/src/__support/math/f16mull.h             |  32 +++
 libc/src/__support/math/f16sub.h              |  32 +++
 libc/src/__support/math/f16subf.h             |  32 +++
 libc/src/__support/math/f16subf128.h          |  35 +++
 libc/src/__support/math/f16subl.h             |  32 +++
 libc/src/math/generic/CMakeLists.txt          |  36 +--
 libc/src/math/generic/f16div.cpp              |   6 +-
 libc/src/math/generic/f16divf.cpp             |   6 +-
 libc/src/math/generic/f16divf128.cpp          |   6 +-
 libc/src/math/generic/f16divl.cpp             |   6 +-
 libc/src/math/generic/f16mul.cpp              |   6 +-
 libc/src/math/generic/f16mulf.cpp             |   6 +-
 libc/src/math/generic/f16mulf128.cpp          |   6 +-
 libc/src/math/generic/f16mull.cpp             |   6 +-
 libc/src/math/generic/f16sub.cpp              |   6 +-
 libc/src/math/generic/f16subf.cpp             |   6 +-
 libc/src/math/generic/f16subf128.cpp          |   6 +-
 libc/src/math/generic/f16subl.cpp             |   6 +-
 libc/test/shared/CMakeLists.txt               |  12 +
 libc/test/shared/shared_math_test.cpp         |  21 +-
 .../llvm-project-overlay/libc/BUILD.bazel     | 207 +++++++++++++++++-
 42 files changed, 1136 insertions(+), 86 deletions(-)
 create mode 100644 libc/shared/math/f16div.h
 create mode 100644 libc/shared/math/f16divf.h
 create mode 100644 libc/shared/math/f16divf128.h
 create mode 100644 libc/shared/math/f16divl.h
 create mode 100644 libc/shared/math/f16mul.h
 create mode 100644 libc/shared/math/f16mulf.h
 create mode 100644 libc/shared/math/f16mulf128.h
 create mode 100644 libc/shared/math/f16mull.h
 create mode 100644 libc/shared/math/f16sub.h
 create mode 100644 libc/shared/math/f16subf.h
 create mode 100644 libc/shared/math/f16subf128.h
 create mode 100644 libc/shared/math/f16subl.h
 create mode 100644 libc/src/__support/math/f16div.h
 create mode 100644 libc/src/__support/math/f16divf.h
 create mode 100644 libc/src/__support/math/f16divf128.h
 create mode 100644 libc/src/__support/math/f16divl.h
 create mode 100644 libc/src/__support/math/f16mul.h
 create mode 100644 libc/src/__support/math/f16mulf.h
 create mode 100644 libc/src/__support/math/f16mulf128.h
 create mode 100644 libc/src/__support/math/f16mull.h
 create mode 100644 libc/src/__support/math/f16sub.h
 create mode 100644 libc/src/__support/math/f16subf.h
 create mode 100644 libc/src/__support/math/f16subf128.h
 create mode 100644 libc/src/__support/math/f16subl.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 93f7d6a8156cf..12e4fc20eb99b 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -67,13 +67,25 @@
 #include "math/expm1.h"
 #include "math/expm1f.h"
 #include "math/expm1f16.h"
+#include "math/f16div.h"
+#include "math/f16divf.h"
+#include "math/f16divf128.h"
+#include "math/f16divl.h"
 #include "math/f16fma.h"
 #include "math/f16fmaf.h"
 #include "math/f16fmaf128.h"
 #include "math/f16fmal.h"
+#include "math/f16mul.h"
+#include "math/f16mulf.h"
+#include "math/f16mulf128.h"
+#include "math/f16mull.h"
 #include "math/f16sqrt.h"
 #include "math/f16sqrtf.h"
 #include "math/f16sqrtl.h"
+#include "math/f16sub.h"
+#include "math/f16subf.h"
+#include "math/f16subf128.h"
+#include "math/f16subl.h"
 #include "math/ffma.h"
 #include "math/ffmal.h"
 #include "math/frexpf.h"
diff --git a/libc/shared/math/f16div.h b/libc/shared/math/f16div.h
new file mode 100644
index 0000000000000..cf889e050116b
--- /dev/null
+++ b/libc/shared/math/f16div.h
@@ -0,0 +1,28 @@
+//===-- Shared f16div 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_F16DIV_H
+#define LLVM_LIBC_SHARED_MATH_F16DIV_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16div.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16div;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16DIV_H
diff --git a/libc/shared/math/f16divf.h b/libc/shared/math/f16divf.h
new file mode 100644
index 0000000000000..d021f25aa2b6f
--- /dev/null
+++ b/libc/shared/math/f16divf.h
@@ -0,0 +1,28 @@
+//===-- Shared f16divf 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_F16DIVF_H
+#define LLVM_LIBC_SHARED_MATH_F16DIVF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16divf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16divf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16DIVF_H
diff --git a/libc/shared/math/f16divf128.h b/libc/shared/math/f16divf128.h
new file mode 100644
index 0000000000000..2b00589c7a0e0
--- /dev/null
+++ b/libc/shared/math/f16divf128.h
@@ -0,0 +1,31 @@
+//===-- Shared f16divf128 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_F16DIVF128_H
+#define LLVM_LIBC_SHARED_MATH_F16DIVF128_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/f16divf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16divf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16DIVF128_H
diff --git a/libc/shared/math/f16divl.h b/libc/shared/math/f16divl.h
new file mode 100644
index 0000000000000..be3e377231849
--- /dev/null
+++ b/libc/shared/math/f16divl.h
@@ -0,0 +1,28 @@
+//===-- Shared f16divl 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_F16DIVL_H
+#define LLVM_LIBC_SHARED_MATH_F16DIVL_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16divl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16divl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16DIVL_H
diff --git a/libc/shared/math/f16mul.h b/libc/shared/math/f16mul.h
new file mode 100644
index 0000000000000..9cd6afee68307
--- /dev/null
+++ b/libc/shared/math/f16mul.h
@@ -0,0 +1,28 @@
+//===-- Shared f16mul 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_F16MUL_H
+#define LLVM_LIBC_SHARED_MATH_F16MUL_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16mul.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16mul;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16MUL_H
diff --git a/libc/shared/math/f16mulf.h b/libc/shared/math/f16mulf.h
new file mode 100644
index 0000000000000..629e23ea76777
--- /dev/null
+++ b/libc/shared/math/f16mulf.h
@@ -0,0 +1,28 @@
+//===-- Shared f16mulf 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_F16MULF_H
+#define LLVM_LIBC_SHARED_MATH_F16MULF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16mulf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16mulf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16MULF_H
diff --git a/libc/shared/math/f16mulf128.h b/libc/shared/math/f16mulf128.h
new file mode 100644
index 0000000000000..6052e0421692a
--- /dev/null
+++ b/libc/shared/math/f16mulf128.h
@@ -0,0 +1,31 @@
+//===-- Shared f16mulf128 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_F16MULF128_H
+#define LLVM_LIBC_SHARED_MATH_F16MULF128_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/f16mulf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16mulf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16MULF128_H
diff --git a/libc/shared/math/f16mull.h b/libc/shared/math/f16mull.h
new file mode 100644
index 0000000000000..58237afd62ea4
--- /dev/null
+++ b/libc/shared/math/f16mull.h
@@ -0,0 +1,28 @@
+//===-- Shared f16mull 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_F16MULL_H
+#define LLVM_LIBC_SHARED_MATH_F16MULL_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16mull.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16mull;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16MULL_H
diff --git a/libc/shared/math/f16sub.h b/libc/shared/math/f16sub.h
new file mode 100644
index 0000000000000..3481ee121d0f7
--- /dev/null
+++ b/libc/shared/math/f16sub.h
@@ -0,0 +1,28 @@
+//===-- Shared f16sub 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_F16SUB_H
+#define LLVM_LIBC_SHARED_MATH_F16SUB_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16sub.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16sub;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16SUB_H
diff --git a/libc/shared/math/f16subf.h b/libc/shared/math/f16subf.h
new file mode 100644
index 0000000000000..14015df03cc0c
--- /dev/null
+++ b/libc/shared/math/f16subf.h
@@ -0,0 +1,28 @@
+//===-- Shared f16subf 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_F16SUBF_H
+#define LLVM_LIBC_SHARED_MATH_F16SUBF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16subf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16subf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16SUBF_H
diff --git a/libc/shared/math/f16subf128.h b/libc/shared/math/f16subf128.h
new file mode 100644
index 0000000000000..f9a6426bfa1e2
--- /dev/null
+++ b/libc/shared/math/f16subf128.h
@@ -0,0 +1,31 @@
+//===-- Shared f16subf128 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_F16SUBF128_H
+#define LLVM_LIBC_SHARED_MATH_F16SUBF128_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/f16subf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16subf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16SUBF128_H
diff --git a/libc/shared/math/f16subl.h b/libc/shared/math/f16subl.h
new file mode 100644
index 0000000000000..f4918af8705f4
--- /dev/null
+++ b/libc/shared/math/f16subl.h
@@ -0,0 +1,28 @@
+//===-- Shared f16subl 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_F16SUBL_H
+#define LLVM_LIBC_SHARED_MATH_F16SUBL_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16subl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16subl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16SUBL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index aaab78c01a891..48666e2bb9dfe 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -670,6 +670,130 @@ add_header_library(
     libc.src.__support.math.exp10_float16_constants
 )
 
+add_header_library(
+  f16div
+  HDRS
+    f16div.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16divf
+  HDRS
+    f16divf.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16divf128
+  HDRS
+    f16divf128.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16divl
+  HDRS
+    f16divl.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16mul
+  HDRS
+    f16mul.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16mulf
+  HDRS
+    f16mulf.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16mulf128
+  HDRS
+    f16mulf128.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16mull
+  HDRS
+    f16mull.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16sub
+  HDRS
+    f16sub.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16subf
+  HDRS
+    f16subf.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16subf128
+  HDRS
+    f16subf128.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  f16subl
+  HDRS
+    f16subl.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
+
+
 add_header_library(
   ffmal
   HDRS
diff --git a/libc/src/__support/math/f16div.h b/libc/src/__support/math/f16div.h
new file mode 100644
index 0000000000000..f53759330b867
--- /dev/null
+++ b/libc/src/__support/math/f16div.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16div ------------------------*- 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_F16DIV_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16DIV_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16div(double x, double y) {
+  return fputil::generic::div<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16DIV_H
diff --git a/libc/src/__support/math/f16divf.h b/libc/src/__support/math/f16divf.h
new file mode 100644
index 0000000000000..488a3fb191b87
--- /dev/null
+++ b/libc/src/__support/math/f16divf.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16divf -----------------------*- 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_F16DIVF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16DIVF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16divf(float x, float y) {
+  return fputil::generic::div<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16DIVF_H
diff --git a/libc/src/__support/math/f16divf128.h b/libc/src/__support/math/f16divf128.h
new file mode 100644
index 0000000000000..e0a93f60bfece
--- /dev/null
+++ b/libc/src/__support/math/f16divf128.h
@@ -0,0 +1,35 @@
+//===-- Implementation header for f16divf128 --------------------*- 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_F16DIVF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16DIVF128_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16divf128(float128 x, float128 y) {
+  return fputil::generic::div<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16DIVF128_H
diff --git a/libc/src/__support/math/f16divl.h b/libc/src/__support/math/f16divl.h
new file mode 100644
index 0000000000000..6d8f63605824b
--- /dev/null
+++ b/libc/src/__support/math/f16divl.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16divl -----------------------*- 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_F16DIVL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16DIVL_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16divl(long double x, long double y) {
+  return fputil::generic::div<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16DIVL_H
diff --git a/libc/src/__support/math/f16mul.h b/libc/src/__support/math/f16mul.h
new file mode 100644
index 0000000000000..7ae906b8af279
--- /dev/null
+++ b/libc/src/__support/math/f16mul.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16mul ------------------------*- 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_F16MUL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16MUL_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16mul(double x, double y) {
+  return fputil::generic::mul<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16MUL_H
diff --git a/libc/src/__support/math/f16mulf.h b/libc/src/__support/math/f16mulf.h
new file mode 100644
index 0000000000000..9a432d3fae4f2
--- /dev/null
+++ b/libc/src/__support/math/f16mulf.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16mulf -----------------------*- 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_F16MULF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16MULF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16mulf(float x, float y) {
+  return fputil::generic::mul<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16MULF_H
diff --git a/libc/src/__support/math/f16mulf128.h b/libc/src/__support/math/f16mulf128.h
new file mode 100644
index 0000000000000..54a90957269a7
--- /dev/null
+++ b/libc/src/__support/math/f16mulf128.h
@@ -0,0 +1,35 @@
+//===-- Implementation header for f16mulf128 --------------------*- 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_F16MULF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16MULF128_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16mulf128(float128 x, float128 y) {
+  return fputil::generic::mul<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16MULF128_H
diff --git a/libc/src/__support/math/f16mull.h b/libc/src/__support/math/f16mull.h
new file mode 100644
index 0000000000000..5fee45ad01124
--- /dev/null
+++ b/libc/src/__support/math/f16mull.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16mull -----------------------*- 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_F16MULL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16MULL_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16mull(long double x, long double y) {
+  return fputil::generic::mul<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16MULL_H
diff --git a/libc/src/__support/math/f16sub.h b/libc/src/__support/math/f16sub.h
new file mode 100644
index 0000000000000..3280fb08e3103
--- /dev/null
+++ b/libc/src/__support/math/f16sub.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16sub ------------------------*- 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_F16SUB_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16SUB_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16sub(double x, double y) {
+  return fputil::generic::sub<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16SUB_H
diff --git a/libc/src/__support/math/f16subf.h b/libc/src/__support/math/f16subf.h
new file mode 100644
index 0000000000000..1e19e90d18a6b
--- /dev/null
+++ b/libc/src/__support/math/f16subf.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16subf -----------------------*- 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_F16SUBF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16SUBF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16subf(float x, float y) {
+  return fputil::generic::sub<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16SUBF_H
diff --git a/libc/src/__support/math/f16subf128.h b/libc/src/__support/math/f16subf128.h
new file mode 100644
index 0000000000000..a85b30fba53fa
--- /dev/null
+++ b/libc/src/__support/math/f16subf128.h
@@ -0,0 +1,35 @@
+//===-- Implementation header for f16subf128 --------------------*- 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_F16SUBF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16SUBF128_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16subf128(float128 x, float128 y) {
+  return fputil::generic::sub<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16SUBF128_H
diff --git a/libc/src/__support/math/f16subl.h b/libc/src/__support/math/f16subl.h
new file mode 100644
index 0000000000000..4515517f60ca2
--- /dev/null
+++ b/libc/src/__support/math/f16subl.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16subl -----------------------*- 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_F16SUBL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16SUBL_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float16 f16subl(long double x, long double y) {
+  return fputil::generic::sub<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16SUBL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 75b51b4587bea..09c642f5ffa62 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4844,8 +4844,7 @@ add_entrypoint_object(
   HDRS
     ../f16sub.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.math.f16sub
 )
 
 add_entrypoint_object(
@@ -4855,8 +4854,7 @@ add_entrypoint_object(
   HDRS
     ../f16subf.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.math.f16subf
 )
 
 add_entrypoint_object(
@@ -4866,8 +4864,7 @@ add_entrypoint_object(
   HDRS
     ../f16subl.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.math.f16subl
 )
 
 add_entrypoint_object(
@@ -4877,8 +4874,7 @@ add_entrypoint_object(
   HDRS
     ../f16subf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.math.f16subf128
 )
 
 add_entrypoint_object(
@@ -4888,8 +4884,7 @@ add_entrypoint_object(
   HDRS
     ../f16div.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.math.f16div
 )
 
 add_entrypoint_object(
@@ -4899,8 +4894,7 @@ add_entrypoint_object(
   HDRS
     ../f16divf.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.math.f16divf
 )
 
 add_entrypoint_object(
@@ -4910,8 +4904,7 @@ add_entrypoint_object(
   HDRS
     ../f16divl.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.math.f16divl
 )
 
 add_entrypoint_object(
@@ -4921,8 +4914,7 @@ add_entrypoint_object(
   HDRS
     ../f16divf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.math.f16divf128
 )
 
 add_entrypoint_object(
@@ -5086,8 +5078,7 @@ add_entrypoint_object(
   HDRS
     ../f16mul.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.math.f16mul
 )
 
 add_entrypoint_object(
@@ -5097,8 +5088,7 @@ add_entrypoint_object(
   HDRS
     ../f16mulf.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.math.f16mulf
 )
 
 add_entrypoint_object(
@@ -5108,8 +5098,7 @@ add_entrypoint_object(
   HDRS
     ../f16mull.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.math.f16mull
 )
 
 add_entrypoint_object(
@@ -5119,8 +5108,7 @@ add_entrypoint_object(
   HDRS
     ../f16mulf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.math.f16mulf128
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/f16div.cpp b/libc/src/math/generic/f16div.cpp
index 7df94a8ef508f..8ca1bf35f5e77 100644
--- a/libc/src/math/generic/f16div.cpp
+++ b/libc/src/math/generic/f16div.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16div.h"
-#include "src/__support/FPUtil/generic/div.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16div.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16div, (double x, double y)) {
-  return fputil::generic::div<float16>(x, y);
+  return math::f16div(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16divf.cpp b/libc/src/math/generic/f16divf.cpp
index 3e6289eee4017..b9d9b7994212b 100644
--- a/libc/src/math/generic/f16divf.cpp
+++ b/libc/src/math/generic/f16divf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16divf.h"
-#include "src/__support/FPUtil/generic/div.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16divf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16divf, (float x, float y)) {
-  return fputil::generic::div<float16>(x, y);
+  return math::f16divf(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16divf128.cpp b/libc/src/math/generic/f16divf128.cpp
index 8980ebe9640bd..8a0b1b367c5b3 100644
--- a/libc/src/math/generic/f16divf128.cpp
+++ b/libc/src/math/generic/f16divf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16divf128.h"
-#include "src/__support/FPUtil/generic/div.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16divf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16divf128, (float128 x, float128 y)) {
-  return fputil::generic::div<float16>(x, y);
+  return math::f16divf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16divl.cpp b/libc/src/math/generic/f16divl.cpp
index 2a0b20041e0d3..5ed8fd5112123 100644
--- a/libc/src/math/generic/f16divl.cpp
+++ b/libc/src/math/generic/f16divl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16divl.h"
-#include "src/__support/FPUtil/generic/div.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16divl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16divl, (long double x, long double y)) {
-  return fputil::generic::div<float16>(x, y);
+  return math::f16divl(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16mul.cpp b/libc/src/math/generic/f16mul.cpp
index f7a5225b60f11..1f958085ff3ef 100644
--- a/libc/src/math/generic/f16mul.cpp
+++ b/libc/src/math/generic/f16mul.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16mul.h"
-#include "src/__support/FPUtil/generic/mul.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16mul.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16mul, (double x, double y)) {
-  return fputil::generic::mul<float16>(x, y);
+  return math::f16mul(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16mulf.cpp b/libc/src/math/generic/f16mulf.cpp
index 2c04664f804ea..af906ac3d1d0e 100644
--- a/libc/src/math/generic/f16mulf.cpp
+++ b/libc/src/math/generic/f16mulf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16mulf.h"
-#include "src/__support/FPUtil/generic/mul.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16mulf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16mulf, (float x, float y)) {
-  return fputil::generic::mul<float16>(x, y);
+  return math::f16mulf(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16mulf128.cpp b/libc/src/math/generic/f16mulf128.cpp
index 7e2d6a0d194ae..885409e8ba314 100644
--- a/libc/src/math/generic/f16mulf128.cpp
+++ b/libc/src/math/generic/f16mulf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16mulf128.h"
-#include "src/__support/FPUtil/generic/mul.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16mulf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16mulf128, (float128 x, float128 y)) {
-  return fputil::generic::mul<float16>(x, y);
+  return math::f16mulf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16mull.cpp b/libc/src/math/generic/f16mull.cpp
index fc66fba4d9f23..e8bb878c6e00e 100644
--- a/libc/src/math/generic/f16mull.cpp
+++ b/libc/src/math/generic/f16mull.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16mull.h"
-#include "src/__support/FPUtil/generic/mul.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16mull.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16mull, (long double x, long double y)) {
-  return fputil::generic::mul<float16>(x, y);
+  return math::f16mull(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16sub.cpp b/libc/src/math/generic/f16sub.cpp
index 88962b880491d..3f177d6f68aa5 100644
--- a/libc/src/math/generic/f16sub.cpp
+++ b/libc/src/math/generic/f16sub.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16sub.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16sub.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16sub, (double x, double y)) {
-  return fputil::generic::sub<float16>(x, y);
+  return math::f16sub(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16subf.cpp b/libc/src/math/generic/f16subf.cpp
index adc0ca4375aaf..cf3b9a1b4ed08 100644
--- a/libc/src/math/generic/f16subf.cpp
+++ b/libc/src/math/generic/f16subf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16subf.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16subf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16subf, (float x, float y)) {
-  return fputil::generic::sub<float16>(x, y);
+  return math::f16subf(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16subf128.cpp b/libc/src/math/generic/f16subf128.cpp
index c3e0ba559f663..6bcf226dcb4b9 100644
--- a/libc/src/math/generic/f16subf128.cpp
+++ b/libc/src/math/generic/f16subf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16subf128.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16subf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16subf128, (float128 x, float128 y)) {
-  return fputil::generic::sub<float16>(x, y);
+  return math::f16subf128(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16subl.cpp b/libc/src/math/generic/f16subl.cpp
index 0ade79064773d..62887123c005f 100644
--- a/libc/src/math/generic/f16subl.cpp
+++ b/libc/src/math/generic/f16subl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/f16subl.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16subl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, f16subl, (long double x, long double y)) {
-  return fputil::generic::sub<float16>(x, y);
+  return math::f16subl(x, y);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 9dfbedee66a33..11bbf869ac45a 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -63,13 +63,25 @@ add_fp_unittest(
     libc.src.__support.math.exp10f16
     libc.src.__support.math.expf
     libc.src.__support.math.expf16
+    libc.src.__support.math.f16div
+    libc.src.__support.math.f16divf
+    libc.src.__support.math.f16divf128
+    libc.src.__support.math.f16divl
     libc.src.__support.math.f16fma
     libc.src.__support.math.f16fmaf
     libc.src.__support.math.f16fmaf128
     libc.src.__support.math.f16fmal
+    libc.src.__support.math.f16mul
+    libc.src.__support.math.f16mulf
+    libc.src.__support.math.f16mulf128
+    libc.src.__support.math.f16mull
     libc.src.__support.math.f16sqrt
     libc.src.__support.math.f16sqrtf
     libc.src.__support.math.f16sqrtl
+    libc.src.__support.math.f16sub
+    libc.src.__support.math.f16subf
+    libc.src.__support.math.f16subf128
+    libc.src.__support.math.f16subl
     libc.src.__support.math.ffma
     libc.src.__support.math.ffmal
     libc.src.__support.math.frexpf
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 2d7ee388f754d..0acd8cca10b69 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -47,12 +47,29 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   EXPECT_FP_EQ(10.0f16, LIBC_NAMESPACE::shared::f16fmaf128(
                             float128(2.0), float128(3.0), float128(4.0)));
 
-#endif
+  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::f16divf128(
+                                  float128(0.0), float128(1.0)));
+
+  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::f16mulf128(
+                                  float128(0.0), float128(0.0)));
+
+  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::f16subf128(
+                                  float128(0.0), float128(0.0)));
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+  EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::f16div(0.0, 1.0));
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::f16divl(0.0L, 1.0L));
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::f16divf(0.0f, 1.0f));
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::f16mul(0.0L, 0.0L));
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::f16mull(0.0L, 0.0L));
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::f16mulf(0.0f, 0.0f));
+  EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::f16sub(0.0, 0.0));
+  EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::f16subl(0.0L, 0.0L));
+  EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::f16subf(0.0f, 0.0f));
 
   EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::f16sqrt(0.0));
 
   EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::f16sqrtf(0.0f));
-
   EXPECT_FP_EQ(float16(10.0),
                LIBC_NAMESPACE::shared::f16fmal(2.0L, 3.0L, 4.0L));
 
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 608180b90e87b..1f6291440b96d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2962,6 +2962,129 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_f16div",
+    hdrs = ["src/__support/math/f16div.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16divf",
+    hdrs = ["src/__support/math/f16divf.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16divf128",
+    hdrs = ["src/__support/math/f16divf128.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16divl",
+    hdrs = ["src/__support/math/f16divl.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16mul",
+    hdrs = ["src/__support/math/f16mul.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16mulf",
+    hdrs = ["src/__support/math/f16mulf.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16mulf128",
+    hdrs = ["src/__support/math/f16mulf128.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16mull",
+    hdrs = ["src/__support/math/f16mull.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16sub",
+    hdrs = ["src/__support/math/f16sub.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16subf",
+    hdrs = ["src/__support/math/f16subf.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16subf128",
+    hdrs = ["src/__support/math/f16subf128.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_f16subl",
+    hdrs = ["src/__support/math/f16subl.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_f16fma",
     hdrs = ["src/__support/math/f16fma.h"],
@@ -4688,13 +4811,33 @@ libc_math_function(name = "f16addf128")
 
 libc_math_function(name = "f16addl")
 
-libc_math_function(name = "f16div")
+libc_math_function(
+    name = "f16div",
+    additional_deps = [
+        ":__support_math_f16div",
+    ],
+)
 
-libc_math_function(name = "f16divf")
+libc_math_function(
+    name = "f16divf",
+    additional_deps = [
+        ":__support_math_f16divf",
+    ],
+)
 
-libc_math_function(name = "f16divf128")
+libc_math_function(
+    name = "f16divf128",
+    additional_deps = [
+        ":__support_math_f16divf128",
+    ],
+)
 
-libc_math_function(name = "f16divl")
+libc_math_function(
+    name = "f16divl",
+    additional_deps = [
+        ":__support_math_f16divl",
+    ],
+)
 
 libc_math_function(
     name = "f16fma",
@@ -4716,13 +4859,33 @@ libc_math_function(
     additional_deps = [":__support_math_f16fmal"],
 )
 
-libc_math_function(name = "f16mul")
+libc_math_function(
+    name = "f16mul",
+    additional_deps = [
+        ":__support_math_f16mul",
+    ],
+)
 
-libc_math_function(name = "f16mulf")
+libc_math_function(
+    name = "f16mulf",
+    additional_deps = [
+        ":__support_math_f16mulf",
+    ],
+)
 
-libc_math_function(name = "f16mulf128")
+libc_math_function(
+    name = "f16mulf128",
+    additional_deps = [
+        ":__support_math_f16mulf128",
+    ],
+)
 
-libc_math_function(name = "f16mull")
+libc_math_function(
+    name = "f16mull",
+    additional_deps = [
+        ":__support_math_f16mull",
+    ],
+)
 
 libc_math_function(
     name = "f16sqrt",
@@ -4747,13 +4910,33 @@ libc_math_function(
     ],
 )
 
-libc_math_function(name = "f16sub")
+libc_math_function(
+    name = "f16sub",
+    additional_deps = [
+        ":__support_math_f16sub",
+    ],
+)
 
-libc_math_function(name = "f16subf")
+libc_math_function(
+    name = "f16subf",
+    additional_deps = [
+        ":__support_math_f16subf",
+    ],
+)
 
-libc_math_function(name = "f16subf128")
+libc_math_function(
+    name = "f16subf128",
+    additional_deps = [
+        ":__support_math_f16subf128",
+    ],
+)
 
-libc_math_function(name = "f16subl")
+libc_math_function(
+    name = "f16subl",
+    additional_deps = [
+        ":__support_math_f16subl",
+    ],
+)
 
 libc_math_function(name = "fabs")
 



More information about the libc-commits mailing list