[libc-commits] [libc] [libc][math][c23] Implement fmaxf16 and fminf16 function (PR #94131)
Hendrik Hübner via libc-commits
libc-commits at lists.llvm.org
Sun Jun 2 02:10:58 PDT 2024
https://github.com/HendrikHuebner updated https://github.com/llvm/llvm-project/pull/94131
>From 7b89fa06d27537f9f9d73748f3a539df5ce63a44 Mon Sep 17 00:00:00 2001
From: hhuebner <hendrik.huebner18 at gmail.com>
Date: Sun, 2 Jun 2024 02:08:45 +0200
Subject: [PATCH 1/2] [libc][math][c23] Implement fmaxf16 function
---
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/spec/stdc.td | 1 +
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/fmaxf16.h | 21 +++++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 13 +++++++++++++
libc/src/math/generic/fmaxf16.cpp | 19 +++++++++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 13 +++++++++++++
libc/test/src/math/smoke/fmaxf16_test.cpp | 13 +++++++++++++
9 files changed, 83 insertions(+)
create mode 100644 libc/src/math/fmaxf16.h
create mode 100644 libc/src/math/generic/fmaxf16.cpp
create mode 100644 libc/test/src/math/smoke/fmaxf16_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index ca0418c3618ae..dcea9b7705da1 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -500,6 +500,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float16 entrypoints
libc.src.math.fabsf16
+ libc.src.math.fmaxf16
)
endif()
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 367db7d384d23..03478addc2c77 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -533,6 +533,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float16 entrypoints
libc.src.math.fabsf16
+ libc.src.math.fmaxf16
)
endif()
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 109721b8b12a0..58554a4c527a6 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -417,6 +417,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"fmaxf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
FunctionSpec<"fmaxl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"fmaxf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+ GuardedFunctionSpec<"fmaxf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
FunctionSpec<"fmaximum", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fmaximumf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 31df5d0ab8809..174fef8a84710 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -119,6 +119,7 @@ add_math_entrypoint_object(fmax)
add_math_entrypoint_object(fmaxf)
add_math_entrypoint_object(fmaxl)
add_math_entrypoint_object(fmaxf128)
+add_math_entrypoint_object(fmaxf16)
add_math_entrypoint_object(fmin)
add_math_entrypoint_object(fminf)
diff --git a/libc/src/math/fmaxf16.h b/libc/src/math/fmaxf16.h
new file mode 100644
index 0000000000000..f8835abbe6daa
--- /dev/null
+++ b/libc/src/math/fmaxf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for fmaxf16 -------------------------*- 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_MATH_FMAXF_H
+#define LLVM_LIBC_SRC_MATH_FMAXF_H
+
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE {
+
+float16 fmaxf16(float16 x, float16 y);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_FMAXF16_H
+
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 04656e3186181..3681f7161b84e 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1661,6 +1661,19 @@ add_entrypoint_object(
-O3
)
+add_entrypoint_object(
+ fmaxf16
+ SRCS
+ fmaxf16.cpp
+ HDRS
+ ../fmaxf16.h
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.basic_operations
+ COMPILE_OPTIONS
+ -O3
+)
+
add_entrypoint_object(
fmaximum
SRCS
diff --git a/libc/src/math/generic/fmaxf16.cpp b/libc/src/math/generic/fmaxf16.cpp
new file mode 100644
index 0000000000000..022ccb6287eda
--- /dev/null
+++ b/libc/src/math/generic/fmaxf16.cpp
@@ -0,0 +1,19 @@
+//===-- Unittest of fmaxf16 function ----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/fmaxf16.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(float16, fmaxf16, (float16 x, float16 y)) {
+ return fputil::fmax(x, y);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index b46fe5e902c67..c67aaf738567f 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1558,6 +1558,19 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ fmaxf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ fmaxf16_test.cpp
+ HDRS
+ FMaxTest.h
+ DEPENDS
+ libc.src.math.fmaxf16
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
fmaximuml_test
SUITE
diff --git a/libc/test/src/math/smoke/fmaxf16_test.cpp b/libc/test/src/math/smoke/fmaxf16_test.cpp
new file mode 100644
index 0000000000000..1f4a1a5341da6
--- /dev/null
+++ b/libc/test/src/math/smoke/fmaxf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fmaxf128 --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "FMaxTest.h"
+
+#include "src/math/fmaxf16.h"
+
+LIST_FMAX_TESTS(float16, LIBC_NAMESPACE::fmaxf16)
>From 6d5bce044658e549e82300d09befe660be381c27 Mon Sep 17 00:00:00 2001
From: hhuebner <hendrik.huebner18 at gmail.com>
Date: Sun, 2 Jun 2024 02:28:18 +0200
Subject: [PATCH 2/2] [libc][math][c23] Implement fminf16 function
---
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/spec/stdc.td | 1 +
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/fmaxf16.h | 2 +-
libc/src/math/fminf16.h | 20 ++++++++++++++++++++
libc/src/math/generic/CMakeLists.txt | 14 ++++++++++++++
libc/src/math/generic/fmaxf16.cpp | 2 +-
libc/src/math/generic/fminf16.cpp | 19 +++++++++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 13 +++++++++++++
libc/test/src/math/smoke/fminf16_test.cpp | 13 +++++++++++++
11 files changed, 85 insertions(+), 2 deletions(-)
create mode 100644 libc/src/math/fminf16.h
create mode 100644 libc/src/math/generic/fminf16.cpp
create mode 100644 libc/test/src/math/smoke/fminf16_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index dcea9b7705da1..6552d32ef6c87 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -501,6 +501,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
# math.h C23 _Float16 entrypoints
libc.src.math.fabsf16
libc.src.math.fmaxf16
+ libc.src.math.fminf16
)
endif()
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 03478addc2c77..dca2ec6d08e64 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -534,6 +534,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
# math.h C23 _Float16 entrypoints
libc.src.math.fabsf16
libc.src.math.fmaxf16
+ libc.src.math.fminf16
)
endif()
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 58554a4c527a6..e1cc00497761d 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -412,6 +412,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"fminf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
FunctionSpec<"fminl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"fminf128", RetValSpec<Float128Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+ GuardedFunctionSpec<"fminf16", RetValSpec<Float16Type>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
FunctionSpec<"fmax", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fmaxf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 174fef8a84710..ef463565f9146 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -125,6 +125,7 @@ add_math_entrypoint_object(fmin)
add_math_entrypoint_object(fminf)
add_math_entrypoint_object(fminl)
add_math_entrypoint_object(fminf128)
+add_math_entrypoint_object(fminf16)
add_math_entrypoint_object(fmaximum)
add_math_entrypoint_object(fmaximumf)
diff --git a/libc/src/math/fmaxf16.h b/libc/src/math/fmaxf16.h
index f8835abbe6daa..1a7af44c645d7 100644
--- a/libc/src/math/fmaxf16.h
+++ b/libc/src/math/fmaxf16.h
@@ -1,4 +1,4 @@
-//===-- Implementation header for fmaxf16 -------------------------*- C++ -*-===//
+//===-- Implementation header for fmaxf16 -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/math/fminf16.h b/libc/src/math/fminf16.h
new file mode 100644
index 0000000000000..a6c307609c36e
--- /dev/null
+++ b/libc/src/math/fminf16.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for fminf16 ----------------------*- 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_MATH_FMINF16_H
+#define LLVM_LIBC_SRC_MATH_FMINF16_H
+
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE {
+
+float16 fminf16(float16 x, float16 y);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_MATH_FMINF16_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 3681f7161b84e..e37d465260cb4 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1612,6 +1612,20 @@ add_entrypoint_object(
-O3
)
+add_entrypoint_object(
+ fminf16
+ SRCS
+ fminf16.cpp
+ HDRS
+ ../fminf16.h
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.basic_operations
+ COMPILE_OPTIONS
+ -O3
+)
+
+
add_entrypoint_object(
fmax
SRCS
diff --git a/libc/src/math/generic/fmaxf16.cpp b/libc/src/math/generic/fmaxf16.cpp
index 022ccb6287eda..cb7ba0dedef30 100644
--- a/libc/src/math/generic/fmaxf16.cpp
+++ b/libc/src/math/generic/fmaxf16.cpp
@@ -1,4 +1,4 @@
-//===-- Unittest of fmaxf16 function ----------------------------------===//
+//===-- Unittest of fmaxf16 function --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/math/generic/fminf16.cpp b/libc/src/math/generic/fminf16.cpp
new file mode 100644
index 0000000000000..12547c33c6361
--- /dev/null
+++ b/libc/src/math/generic/fminf16.cpp
@@ -0,0 +1,19 @@
+//===-- Implementation of fminf16 function --------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/fminf16.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(float16, fminf16, (float16 x, float16 y)) {
+ return fputil::fmin(x, y);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index c67aaf738567f..b37a32bc3413a 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1506,6 +1506,19 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ fminf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ fminf16_test.cpp
+ HDRS
+ FMaxTest.h
+ DEPENDS
+ libc.src.math.fminf16
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
fmaxf_test
SUITE
diff --git a/libc/test/src/math/smoke/fminf16_test.cpp b/libc/test/src/math/smoke/fminf16_test.cpp
new file mode 100644
index 0000000000000..3d8752657b484
--- /dev/null
+++ b/libc/test/src/math/smoke/fminf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for fminf -----------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "FMinTest.h"
+
+#include "src/math/fminf16.h"
+
+LIST_FMIN_TESTS(float16, LIBC_NAMESPACE::fminf16)
More information about the libc-commits
mailing list