[libc-commits] [libc] [llvm] [libc][math] Refactor float16 operations to header-only (PR #181745)
via libc-commits
libc-commits at lists.llvm.org
Mon Feb 16 13:27:26 PST 2026
https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/181745
>From 5ca8a00d3a9858e3a5c564e17e3694666e756f0e Mon Sep 17 00:00:00 2001
From: Ezzeldin Ibrahim <ezzibrahimx at gmail.com>
Date: Mon, 16 Feb 2026 23:02:46 +0200
Subject: [PATCH] [libc][math] Refactor float16 operations to header-only
---
libc/shared/math.h | 17 +
libc/shared/math/f16add.h | 28 ++
libc/shared/math/f16addf.h | 28 ++
libc/shared/math/f16addf128.h | 31 ++
libc/shared/math/f16addl.h | 28 ++
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/f16sqrtf128.h | 31 ++
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 | 175 +++++++++++
libc/src/__support/math/f16add.h | 32 ++
libc/src/__support/math/f16addf.h | 32 ++
libc/src/__support/math/f16addf128.h | 35 +++
libc/src/__support/math/f16addl.h | 32 ++
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/f16sqrtf128.h | 35 +++
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 | 51 +--
libc/src/math/generic/f16add.cpp | 6 +-
libc/src/math/generic/f16addf.cpp | 6 +-
libc/src/math/generic/f16addf128.cpp | 6 +-
libc/src/math/generic/f16addl.cpp | 6 +-
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/f16sqrtf128.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 | 17 +
libc/test/shared/shared_math_test.cpp | 30 +-
.../llvm-project-overlay/libc/BUILD.bazel | 291 +++++++++++++++++-
57 files changed, 1612 insertions(+), 121 deletions(-)
create mode 100644 libc/shared/math/f16add.h
create mode 100644 libc/shared/math/f16addf.h
create mode 100644 libc/shared/math/f16addf128.h
create mode 100644 libc/shared/math/f16addl.h
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/f16sqrtf128.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/f16add.h
create mode 100644 libc/src/__support/math/f16addf.h
create mode 100644 libc/src/__support/math/f16addf128.h
create mode 100644 libc/src/__support/math/f16addl.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/f16sqrtf128.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..f11e28b6d3133 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -67,13 +67,30 @@
#include "math/expm1.h"
#include "math/expm1f.h"
#include "math/expm1f16.h"
+#include "math/f16add.h"
+#include "math/f16addf.h"
+#include "math/f16addf128.h"
+#include "math/f16addl.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/f16sqrtf128.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/f16add.h b/libc/shared/math/f16add.h
new file mode 100644
index 0000000000000..f83d685086716
--- /dev/null
+++ b/libc/shared/math/f16add.h
@@ -0,0 +1,28 @@
+//===-- Shared f16add 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_F16ADD_H
+#define LLVM_LIBC_SHARED_MATH_F16ADD_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16add.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16add;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16ADD_H
diff --git a/libc/shared/math/f16addf.h b/libc/shared/math/f16addf.h
new file mode 100644
index 0000000000000..b75b0755c464a
--- /dev/null
+++ b/libc/shared/math/f16addf.h
@@ -0,0 +1,28 @@
+//===-- Shared f16addf 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_F16ADDF_H
+#define LLVM_LIBC_SHARED_MATH_F16ADDF_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16addf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16addf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16ADDF_H
diff --git a/libc/shared/math/f16addf128.h b/libc/shared/math/f16addf128.h
new file mode 100644
index 0000000000000..353686a9529f4
--- /dev/null
+++ b/libc/shared/math/f16addf128.h
@@ -0,0 +1,31 @@
+//===-- Shared f16addf128 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_F16ADDF128_H
+#define LLVM_LIBC_SHARED_MATH_F16ADDF128_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/f16addf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16addf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16ADDF128_H
diff --git a/libc/shared/math/f16addl.h b/libc/shared/math/f16addl.h
new file mode 100644
index 0000000000000..817380d81bfae
--- /dev/null
+++ b/libc/shared/math/f16addl.h
@@ -0,0 +1,28 @@
+//===-- Shared f16addl 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_F16ADDL_H
+#define LLVM_LIBC_SHARED_MATH_F16ADDL_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/f16addl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16addl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16ADDL_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/f16sqrtf128.h b/libc/shared/math/f16sqrtf128.h
new file mode 100644
index 0000000000000..fba8f202f89a2
--- /dev/null
+++ b/libc/shared/math/f16sqrtf128.h
@@ -0,0 +1,31 @@
+//===-- Shared f16sqrtf128 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_F16SQRTF128_H
+#define LLVM_LIBC_SHARED_MATH_F16SQRTF128_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/f16sqrtf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::f16sqrtf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_F16SQRTF128_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..df1bbc5d7b706 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -669,6 +669,181 @@ add_header_library(
libc.src.__support.math.expf16_utils
libc.src.__support.math.exp10_float16_constants
)
+add_header_library(
+ f16add
+ HDRS
+ f16add.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ f16addf
+ HDRS
+ f16addf.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ f16addf128
+ HDRS
+ f16addf128.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(
+ f16addl
+ HDRS
+ f16addl.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.macros.config
+)
+
+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(
+ f16sqrtf128
+ HDRS
+ f16sqrtf128.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.sqrt
+ 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
diff --git a/libc/src/__support/math/f16add.h b/libc/src/__support/math/f16add.h
new file mode 100644
index 0000000000000..1ac9dfa82df61
--- /dev/null
+++ b/libc/src/__support/math/f16add.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16add ------------------------*- 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_F16ADD_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16ADD_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 f16add(double x, double y) {
+ return fputil::generic::add<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16ADD_H
diff --git a/libc/src/__support/math/f16addf.h b/libc/src/__support/math/f16addf.h
new file mode 100644
index 0000000000000..790266629a9e7
--- /dev/null
+++ b/libc/src/__support/math/f16addf.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16addf -----------------------*- 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_F16ADDF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16ADDF_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 f16addf(float x, float y) {
+ return fputil::generic::add<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16ADDF_H
diff --git a/libc/src/__support/math/f16addf128.h b/libc/src/__support/math/f16addf128.h
new file mode 100644
index 0000000000000..9b3532c67727c
--- /dev/null
+++ b/libc/src/__support/math/f16addf128.h
@@ -0,0 +1,35 @@
+//===-- Implementation header for f16addf128 --------------------*- 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_F16ADDF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16ADDF128_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 f16addf128(float128 x, float128 y) {
+ return fputil::generic::add<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_F16ADDF128_H
diff --git a/libc/src/__support/math/f16addl.h b/libc/src/__support/math/f16addl.h
new file mode 100644
index 0000000000000..eb9a5dae8be2a
--- /dev/null
+++ b/libc/src/__support/math/f16addl.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for f16addl -----------------------*- 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_F16ADDL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16ADDL_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 f16addl(long double x, long double y) {
+ return fputil::generic::add<float16>(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16ADDL_H
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/f16sqrtf128.h b/libc/src/__support/math/f16sqrtf128.h
new file mode 100644
index 0000000000000..46cbca7093c0a
--- /dev/null
+++ b/libc/src/__support/math/f16sqrtf128.h
@@ -0,0 +1,35 @@
+//===-- Implementation header for f16sqrtf128 -------------------*- 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_F16SQRTF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_F16SQRTF128_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/sqrt.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr float16 f16sqrtf128(float128 x) {
+ return fputil::sqrt<float16>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_F16SQRTF128_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..5e087ec86141a 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4800,8 +4800,7 @@ add_entrypoint_object(
HDRS
../f16add.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.math.f16add
)
add_entrypoint_object(
@@ -4811,8 +4810,7 @@ add_entrypoint_object(
HDRS
../f16addf.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.math.f16addf
)
add_entrypoint_object(
@@ -4822,8 +4820,7 @@ add_entrypoint_object(
HDRS
../f16addl.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.math.f16addl
)
add_entrypoint_object(
@@ -4833,8 +4830,7 @@ add_entrypoint_object(
HDRS
../f16addf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.generic.add_sub
+ libc.src.__support.math.f16addf128
)
add_entrypoint_object(
@@ -4844,8 +4840,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 +4850,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 +4860,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 +4870,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 +4880,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 +4890,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 +4900,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 +4910,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(
@@ -5003,8 +4991,7 @@ add_entrypoint_object(
HDRS
../f16sqrtf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.sqrt
+ libc.src.__support.math.f16sqrtf128
)
add_entrypoint_object(
@@ -5086,8 +5073,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 +5083,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 +5093,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 +5103,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/f16add.cpp b/libc/src/math/generic/f16add.cpp
index e9be8a743721e..fcd31e73183a1 100644
--- a/libc/src/math/generic/f16add.cpp
+++ b/libc/src/math/generic/f16add.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/f16add.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16add.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, f16add, (double x, double y)) {
- return fputil::generic::add<float16>(x, y);
+ return math::f16add(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16addf.cpp b/libc/src/math/generic/f16addf.cpp
index ee05ff7f00531..63fe8c5f044bd 100644
--- a/libc/src/math/generic/f16addf.cpp
+++ b/libc/src/math/generic/f16addf.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/f16addf.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16addf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, f16addf, (float x, float y)) {
- return fputil::generic::add<float16>(x, y);
+ return math::f16addf(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16addf128.cpp b/libc/src/math/generic/f16addf128.cpp
index 4e9038e23125a..87e327e0c20d4 100644
--- a/libc/src/math/generic/f16addf128.cpp
+++ b/libc/src/math/generic/f16addf128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/f16addf128.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16addf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, f16addf128, (float128 x, float128 y)) {
- return fputil::generic::add<float16>(x, y);
+ return math::f16addf128(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/f16addl.cpp b/libc/src/math/generic/f16addl.cpp
index 925f08418b99d..4d93b7105aa79 100644
--- a/libc/src/math/generic/f16addl.cpp
+++ b/libc/src/math/generic/f16addl.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/f16addl.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16addl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, f16addl, (long double x, long double y)) {
- return fputil::generic::add<float16>(x, y);
+ return math::f16addl(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
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/f16sqrtf128.cpp b/libc/src/math/generic/f16sqrtf128.cpp
index d33d6d2963fea..eca577091e0e9 100644
--- a/libc/src/math/generic/f16sqrtf128.cpp
+++ b/libc/src/math/generic/f16sqrtf128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/f16sqrtf128.h"
-#include "src/__support/FPUtil/sqrt.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/f16sqrtf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, f16sqrtf128, (float128 x)) {
- return fputil::sqrt<float16>(x);
+ return math::f16sqrtf128(x);
}
} // 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..eb32d47bd1af5 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -63,13 +63,30 @@ add_fp_unittest(
libc.src.__support.math.exp10f16
libc.src.__support.math.expf
libc.src.__support.math.expf16
+ libc.src.__support.math.f16add
+ libc.src.__support.math.f16addf
+ libc.src.__support.math.f16addf128
+ libc.src.__support.math.f16addl
+ 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.f16sqrtf128
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..682f1de63954b 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -47,12 +47,38 @@ 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::f16addf128(
+ float128(0.0), float128(0.0)));
+
+ 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::f16sqrtf128(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::f16add(0.0, 0.0));
+ EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::f16addl(0.0L, 0.0L));
+ EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::f16addf(0.0f, 0.0f));
+ 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..9131bc0f0e1ca 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2962,6 +2962,181 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_f16add",
+ hdrs = ["src/__support/math/f16add.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_f16addf",
+ hdrs = ["src/__support/math/f16addf.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_f16addf128",
+ hdrs = ["src/__support/math/f16addf128.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_f16addl",
+ hdrs = ["src/__support/math/f16addl.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+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_f16sqrtf128",
+ hdrs = ["src/__support/math/f16sqrtf128.h"],
+ deps = [
+ ":__support_fputil_sqrt",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+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"],
@@ -4680,21 +4855,61 @@ libc_math_function(
additional_deps = [":__support_math_expm1f16"],
)
-libc_math_function(name = "f16add")
+libc_math_function(
+ name = "f16add",
+ additional_deps = [
+ ":__support_math_f16add",
+ ],
+)
-libc_math_function(name = "f16addf")
+libc_math_function(
+ name = "f16addf",
+ additional_deps = [
+ ":__support_math_f16addf",
+ ],
+)
-libc_math_function(name = "f16addf128")
+libc_math_function(
+ name = "f16addf128",
+ additional_deps = [
+ ":__support_math_f16addf128",
+ ],
+)
-libc_math_function(name = "f16addl")
+libc_math_function(
+ name = "f16addl",
+ additional_deps = [
+ ":__support_math_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 +4931,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",
@@ -4736,7 +4971,9 @@ libc_math_function(
libc_math_function(
name = "f16sqrtf128",
- additional_deps = [":__support_fputil_sqrt"],
+ additional_deps = [
+ ":__support_math_f16sqrtf128",
+ ],
)
libc_math_function(
@@ -4747,13 +4984,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