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/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/spec/stdc.td b/libc/spec/stdc.td index 0aadeb1a43a00..3098736963d35 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -416,11 +416,13 @@ 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]>, 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..83ce322e82730 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -124,11 +124,13 @@ 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) 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 new file mode 100644 index 0000000000000..bf608f82c420a --- /dev/null +++ b/libc/src/math/fmaxf16.h @@ -0,0 +1,20 @@ +//===-- 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_FMAXF16_H +#define LLVM_LIBC_SRC_MATH_FMAXF16_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/fminf16.h b/libc/src/math/fminf16.h new file mode 100644 index 0000000000000..22d4e6c803948 --- /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 95904bef93d24..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 @@ -1831,6 +1845,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..c317aef3cb3b8 --- /dev/null +++ b/libc/src/math/generic/fmaxf16.cpp @@ -0,0 +1,19 @@ +//===-- 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. +// 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/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 09e54349501ca..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 @@ -1799,6 +1812,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..79c03b7685b06 --- /dev/null +++ b/libc/test/src/math/smoke/fmaxf16_test.cpp @@ -0,0 +1,13 @@ +//===-- 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. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FMaxTest.h" + +#include "src/math/fmaxf16.h" + +LIST_FMAX_TESTS(float16, LIBC_NAMESPACE::fmaxf16) 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..4379a6e750653 --- /dev/null +++ b/libc/test/src/math/smoke/fminf16_test.cpp @@ -0,0 +1,13 @@ +//===-- 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. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "FMinTest.h" + +#include "src/math/fminf16.h" + +LIST_FMIN_TESTS(float16, LIBC_NAMESPACE::fminf16)