diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index dfdebf7c277be6..23842c951c8cc4 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -503,6 +503,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.fabsf16 libc.src.math.floorf16 libc.src.math.llrintf16 + libc.src.math.llroundf16 libc.src.math.lrintf16 libc.src.math.lroundf16 libc.src.math.nearbyintf16 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 8558fd847ab7bd..6506ea3108169d 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -536,6 +536,7 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.fabsf16 libc.src.math.floorf16 libc.src.math.llrintf16 + libc.src.math.llroundf16 libc.src.math.lrintf16 libc.src.math.lroundf16 libc.src.math.nearbyintf16 diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index abd96dc124d54c..b1a8aa2dd94704 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -176,7 +176,7 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | llrint | |check| | |check| | |check| | |check| | |check| | 7.12.9.5 | F.10.6.5 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| llround | |check| | |check| | |check| | | |check| | 7.12.9.7 | F.10.6.7 | +| llround | |check| | |check| | |check| | |check| | |check| | 7.12.9.7 | F.10.6.7 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | logb | |check| | |check| | |check| | | |check| | 7.12.6.17 | F.10.3.17 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 8e0a4b21540786..2e64336ed48356 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -585,6 +585,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"llround", RetValSpec, [ArgSpec]>, FunctionSpec<"llroundf", RetValSpec, [ArgSpec]>, FunctionSpec<"llroundl", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"llroundf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"llroundf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, FunctionSpec<"rint", RetValSpec, [ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 99cb3982b58c47..84c9beebfbea26 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -231,6 +231,7 @@ add_math_entrypoint_object(llrintf128) add_math_entrypoint_object(llround) add_math_entrypoint_object(llroundf) add_math_entrypoint_object(llroundl) +add_math_entrypoint_object(llroundf16) add_math_entrypoint_object(llroundf128) add_math_entrypoint_object(lrint) diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index ddbf594144c2d5..4fb744254cfdcf 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -626,6 +626,19 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + llroundf16 + SRCS + llroundf16.cpp + HDRS + ../llroundf16.h + COMPILE_OPTIONS + -O3 + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.nearest_integer_operations +) + add_entrypoint_object( llroundf128 SRCS diff --git a/libc/src/math/generic/llroundf16.cpp b/libc/src/math/generic/llroundf16.cpp new file mode 100644 index 00000000000000..e12421aa1f6fae --- /dev/null +++ b/libc/src/math/generic/llroundf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of llroundf16 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/llroundf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(long long, llroundf16, (float16 x)) { + return fputil::round_to_signed_integer(x); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/llroundf16.h b/libc/src/math/llroundf16.h new file mode 100644 index 00000000000000..379c45446ab278 --- /dev/null +++ b/libc/src/math/llroundf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for llroundf16 --------------------*- 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_LLROUNDF16_H +#define LLVM_LIBC_SRC_MATH_LLROUNDF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +long long llroundf16(float16 x); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_LLROUNDF16_H diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 48bc2e545a4c3a..8f4eb37e665cbf 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -625,6 +625,22 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + llroundf16_test + SUITE + libc-math-smoke-tests + SRCS + llroundf16_test.cpp + HDRS + RoundToIntegerTest.h + DEPENDS + libc.src.errno.errno + libc.src.math.llroundf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + add_fp_unittest( llroundf128_test SUITE diff --git a/libc/test/src/math/smoke/llroundf16_test.cpp b/libc/test/src/math/smoke/llroundf16_test.cpp new file mode 100644 index 00000000000000..9342b24fd5d041 --- /dev/null +++ b/libc/test/src/math/smoke/llroundf16_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for llroundf16 ------------------------------------------===// +// +// 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 "RoundToIntegerTest.h" + +#include "src/math/llroundf16.h" + +LIST_ROUND_TO_INTEGER_TESTS(float16, long long, LIBC_NAMESPACE::llroundf16)