From 7d3e587d7dd17beaf84c16c1f3495e675678093e Mon Sep 17 00:00:00 2001 From: hhuebner Date: Sun, 2 Jun 2024 02:08:45 +0200 Subject: [PATCH 1/6] [libc][math][c23] Implement fmaxf16 function --- libc/config/linux/aarch64/entrypoints.txt | 2 ++ libc/config/linux/x86_64/entrypoints.txt | 2 ++ 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, 85 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 c990a5ba9e669..2a4f789925e89 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -505,6 +505,8 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.fabsf16 libc.src.math.fdimf16 libc.src.math.floorf16 + libc.src.math.fmaxf16 + libc.src.math.fminf16 libc.src.math.fromfpf16 libc.src.math.fromfpxf16 libc.src.math.llrintf16 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 780ffb6d972cd..fe121820d6b6c 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -538,6 +538,8 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.fabsf16 libc.src.math.fdimf16 libc.src.math.floorf16 + libc.src.math.fmaxf16 + libc.src.math.fminf16 libc.src.math.fromfpf16 libc.src.math.fromfpxf16 libc.src.math.llrintf16 diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 0aadeb1a43a00..eb24e86f3c51b 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -421,6 +421,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"fmaxf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fmaxl", RetValSpec, [ArgSpec, ArgSpec]>, GuardedFunctionSpec<"fmaxf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, + GuardedFunctionSpec<"fmaxf16", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, FunctionSpec<"fmaximum", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fmaximumf", RetValSpec, [ArgSpec, ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 5ae03b1f46c32..06067a803d3ad 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -124,6 +124,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 95904bef93d24..358abf2ea0a64 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1831,6 +1831,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 09e54349501ca..3ff8ebe18d34e 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -1799,6 +1799,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 3e1db1c1e3292c9e481be3f033f3973c349a64b9 Mon Sep 17 00:00:00 2001 From: hhuebner Date: Sun, 2 Jun 2024 02:28:18 +0200 Subject: [PATCH 2/6] [libc][math][c23] Implement fminf16 function --- 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 +++++++++++++ 9 files changed, 83 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/spec/stdc.td b/libc/spec/stdc.td index eb24e86f3c51b..3098736963d35 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -416,6 +416,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"fminf", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fminl", RetValSpec, [ArgSpec, ArgSpec]>, GuardedFunctionSpec<"fminf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, + GuardedFunctionSpec<"fminf16", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, FunctionSpec<"fmax", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"fmaxf", RetValSpec, [ArgSpec, ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 06067a803d3ad..83ce322e82730 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -130,6 +130,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 358abf2ea0a64..00e2f0abc9521 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1782,6 +1782,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 3ff8ebe18d34e..a331c02a12ea3 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -1747,6 +1747,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 + FMinTest.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) From 6b7e1afc490f94fd13245e1d9f05751cd5ab8ceb Mon Sep 17 00:00:00 2001 From: hhuebner Date: Sun, 2 Jun 2024 11:20:16 +0200 Subject: [PATCH 3/6] Remove redundant newline at end of file --- libc/src/math/fmaxf16.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libc/src/math/fmaxf16.h b/libc/src/math/fmaxf16.h index 1a7af44c645d7..3b6b177a111f3 100644 --- a/libc/src/math/fmaxf16.h +++ b/libc/src/math/fmaxf16.h @@ -18,4 +18,3 @@ float16 fmaxf16(float16 x, float16 y); } // namespace LIBC_NAMESPACE #endif // LLVM_LIBC_SRC_MATH_FMAXF16_H - From 8ca8255f58fae358afe693b0fa01bc17cf5b547a Mon Sep 17 00:00:00 2001 From: hhuebner Date: Wed, 5 Jun 2024 01:06:37 +0200 Subject: [PATCH 4/6] Update index and comments --- libc/docs/math/index.rst | 4 ++-- libc/src/math/fmaxf16.h | 4 ++-- libc/src/math/fminf16.h | 2 +- libc/src/math/generic/fmaxf16.cpp | 2 +- libc/test/src/math/smoke/fmaxf16_test.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index fd753742b522d..afadf71245656 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -136,7 +136,7 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | floor | |check| | |check| | |check| | |check| | |check| | 7.12.9.2 | F.10.6.2 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| fmax | |check| | |check| | |check| | | |check| | 7.12.12.2 | F.10.9.2 | +| fmax | |check| | |check| | |check| | |check| | |check| | 7.12.12.2 | F.10.9.2 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | fmaximum | |check| | |check| | |check| | | |check| | 7.12.12.4 | F.10.9.4 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ @@ -146,7 +146,7 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | fmaximum_num | |check| | |check| | |check| | | |check| | 7.12.12.8 | F.10.9.5 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| fmin | |check| | |check| | |check| | | |check| | 7.12.12.3 | F.10.9.3 | +| fmin | |check| | |check| | |check| | |check| | |check| | 7.12.12.3 | F.10.9.3 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | fminimum | |check| | |check| | |check| | | |check| | 7.12.12.5 | F.10.9.4 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ diff --git a/libc/src/math/fmaxf16.h b/libc/src/math/fmaxf16.h index 3b6b177a111f3..bf608f82c420a 100644 --- a/libc/src/math/fmaxf16.h +++ b/libc/src/math/fmaxf16.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_MATH_FMAXF_H -#define LLVM_LIBC_SRC_MATH_FMAXF_H +#ifndef LLVM_LIBC_SRC_MATH_FMAXF16_H +#define LLVM_LIBC_SRC_MATH_FMAXF16_H #include "src/__support/macros/properties/types.h" diff --git a/libc/src/math/fminf16.h b/libc/src/math/fminf16.h index a6c307609c36e..22d4e6c803948 100644 --- a/libc/src/math/fminf16.h +++ b/libc/src/math/fminf16.h @@ -1,4 +1,4 @@ -//===-- Implementation header for fminf16 ----------------------*- C++ -*-===// +//===-- 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. diff --git a/libc/src/math/generic/fmaxf16.cpp b/libc/src/math/generic/fmaxf16.cpp index cb7ba0dedef30..465257d38cae9 100644 --- a/libc/src/math/generic/fmaxf16.cpp +++ b/libc/src/math/generic/fmaxf16.cpp @@ -1,4 +1,4 @@ -//===-- Unittest of fmaxf16 function --------------------------------------===// +//===-- Implementation 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/test/src/math/smoke/fmaxf16_test.cpp b/libc/test/src/math/smoke/fmaxf16_test.cpp index 1f4a1a5341da6..79c03b7685b06 100644 --- a/libc/test/src/math/smoke/fmaxf16_test.cpp +++ b/libc/test/src/math/smoke/fmaxf16_test.cpp @@ -1,4 +1,4 @@ -//===-- Unittests for fmaxf128 --------------------------------------------===// +//===-- Unittests for fmaxf16 --------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. From ab57eacee639958e15c2882d6b763a3a07c18d9b Mon Sep 17 00:00:00 2001 From: hhuebner Date: Wed, 5 Jun 2024 01:16:52 +0200 Subject: [PATCH 5/6] Fix fminf16_test comment --- libc/test/src/math/smoke/fminf16_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/test/src/math/smoke/fminf16_test.cpp b/libc/test/src/math/smoke/fminf16_test.cpp index 3d8752657b484..4379a6e750653 100644 --- a/libc/test/src/math/smoke/fminf16_test.cpp +++ b/libc/test/src/math/smoke/fminf16_test.cpp @@ -1,4 +1,4 @@ -//===-- Unittests for fminf -----------------------------------------------===// +//===-- Unittests for fminf16 ---------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. From 9799eb6a71450c7fd3a19413d45ad2dffa6245c5 Mon Sep 17 00:00:00 2001 From: hhuebner Date: Thu, 6 Jun 2024 00:44:14 +0200 Subject: [PATCH 6/6] Fix fmaxf16_test comment --- libc/src/math/generic/fmaxf16.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/src/math/generic/fmaxf16.cpp b/libc/src/math/generic/fmaxf16.cpp index 465257d38cae9..c317aef3cb3b8 100644 --- a/libc/src/math/generic/fmaxf16.cpp +++ b/libc/src/math/generic/fmaxf16.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of fmaxf16 function --------------------------------------===// +//===-- Implementation 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.