diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index ca0418c3618ae0..3bbd1629e3d8d1 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -499,7 +499,12 @@ set(TARGET_LIBM_ENTRYPOINTS if(LIBC_TYPES_HAS_FLOAT16) list(APPEND TARGET_LIBM_ENTRYPOINTS # math.h C23 _Float16 entrypoints + libc.src.math.ceilf16 libc.src.math.fabsf16 + libc.src.math.floorf16 + libc.src.math.roundf16 + libc.src.math.roundevenf16 + libc.src.math.truncf16 ) endif() diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 367db7d384d23d..62434298890f06 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -532,7 +532,12 @@ set(TARGET_LIBM_ENTRYPOINTS if(LIBC_TYPES_HAS_FLOAT16) list(APPEND TARGET_LIBM_ENTRYPOINTS # math.h C23 _Float16 entrypoints + libc.src.math.ceilf16 libc.src.math.fabsf16 + libc.src.math.floorf16 + libc.src.math.roundf16 + libc.src.math.roundevenf16 + libc.src.math.truncf16 ) endif() diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index cd90b6ae85769b..9df7dcfc256db0 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -108,7 +108,7 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | | (float) | (double) | (long double) | (float16) | (float128) | C23 Definition Section | C23 Error Handling Section | +==================+==================+=================+========================+======================+========================+========================+============================+ -| ceil | |check| | |check| | |check| | | |check| | 7.12.9.1 | F.10.6.1 | +| ceil | |check| | |check| | |check| | |check| | |check| | 7.12.9.1 | F.10.6.1 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | canonicalize | |check| | |check| | |check| | | |check| | 7.12.11.7 | F.10.8.7 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ @@ -134,7 +134,7 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | ffma | N/A | | | N/A | | 7.12.14.5 | F.10.11 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| floor | |check| | |check| | |check| | | |check| | 7.12.9.2 | F.10.6.2 | +| 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 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ @@ -204,13 +204,13 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | rint | |check| | |check| | |check| | | |check| | 7.12.9.4 | F.10.6.4 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| round | |check| | |check| | |check| | | |check| | 7.12.9.6 | F.10.6.6 | +| round | |check| | |check| | |check| | |check| | |check| | 7.12.9.6 | F.10.6.6 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| roundeven | |check| | |check| | |check| | | |check| | 7.12.9.8 | F.10.6.8 | +| roundeven | |check| | |check| | |check| | |check| | |check| | 7.12.9.8 | F.10.6.8 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | scalbn | |check| | |check| | |check| | | |check| | 7.12.6.19 | F.10.3.19 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| trunc | |check| | |check| | |check| | | |check| | 7.12.9.9 | F.10.6.9 | +| trunc | |check| | |check| | |check| | |check| | |check| | 7.12.9.9 | F.10.6.9 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | ufromfp | |check| | |check| | |check| | | |check| | 7.12.9.10 | F.10.6.10 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 109721b8b12a02..cacc91ce8789a6 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -390,6 +390,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"ceil", RetValSpec, [ArgSpec]>, FunctionSpec<"ceilf", RetValSpec, [ArgSpec]>, FunctionSpec<"ceill", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"ceilf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"ceilf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, FunctionSpec<"fabs", RetValSpec, [ArgSpec], [ConstAttr]>, @@ -406,6 +407,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"floor", RetValSpec, [ArgSpec]>, FunctionSpec<"floorf", RetValSpec, [ArgSpec]>, FunctionSpec<"floorl", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"floorf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"floorf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, FunctionSpec<"fmin", RetValSpec, [ArgSpec, ArgSpec]>, @@ -565,8 +567,15 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"round", RetValSpec, [ArgSpec]>, FunctionSpec<"roundf", RetValSpec, [ArgSpec]>, FunctionSpec<"roundl", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"roundf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"roundf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, + FunctionSpec<"roundeven", RetValSpec, [ArgSpec]>, + FunctionSpec<"roundevenf", RetValSpec, [ArgSpec]>, + FunctionSpec<"roundevenl", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"roundevenf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"roundevenf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, + FunctionSpec<"lround", RetValSpec, [ArgSpec]>, FunctionSpec<"lroundf", RetValSpec, [ArgSpec]>, FunctionSpec<"lroundl", RetValSpec, [ArgSpec]>, @@ -600,6 +609,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"trunc", RetValSpec, [ArgSpec]>, FunctionSpec<"truncf", RetValSpec, [ArgSpec]>, FunctionSpec<"truncl", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"truncf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"truncf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, FunctionSpec<"nearbyint", RetValSpec, [ArgSpec]>, diff --git a/libc/src/__support/FPUtil/NearestIntegerOperations.h b/libc/src/__support/FPUtil/NearestIntegerOperations.h index 4645ab0b5350be..65fd9794dd66e7 100644 --- a/libc/src/__support/FPUtil/NearestIntegerOperations.h +++ b/libc/src/__support/FPUtil/NearestIntegerOperations.h @@ -22,6 +22,7 @@ namespace fputil { template , int> = 0> LIBC_INLINE T trunc(T x) { + using StorageType = typename FPBits::StorageType; FPBits bits(x); // If x is infinity or NaN, return it. @@ -43,12 +44,15 @@ LIBC_INLINE T trunc(T x) { return FPBits::zero(bits.sign()).get_val(); int trim_size = FPBits::FRACTION_LEN - exponent; - bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size); + StorageType trunc_mantissa = + static_cast((bits.get_mantissa() >> trim_size) << trim_size); + bits.set_mantissa(trunc_mantissa); return bits.get_val(); } template , int> = 0> LIBC_INLINE T ceil(T x) { + using StorageType = typename FPBits::StorageType; FPBits bits(x); // If x is infinity NaN or zero, return it. @@ -71,7 +75,9 @@ LIBC_INLINE T ceil(T x) { } uint32_t trim_size = FPBits::FRACTION_LEN - exponent; - bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size); + StorageType trunc_mantissa = + static_cast((bits.get_mantissa() >> trim_size) << trim_size); + bits.set_mantissa(trunc_mantissa); T trunc_value = bits.get_val(); // If x is already an integer, return it. @@ -124,7 +130,9 @@ LIBC_INLINE T round(T x) { uint32_t trim_size = FPBits::FRACTION_LEN - exponent; bool half_bit_set = bool(bits.get_mantissa() & (StorageType(1) << (trim_size - 1))); - bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size); + StorageType trunc_mantissa = + static_cast((bits.get_mantissa() >> trim_size) << trim_size); + bits.set_mantissa(trunc_mantissa); T trunc_value = bits.get_val(); // If x is already an integer, return it. @@ -181,7 +189,9 @@ round_using_specific_rounding_mode(T x, int rnd) { uint32_t trim_size = FPBits::FRACTION_LEN - exponent; FPBits new_bits = bits; - new_bits.set_mantissa((bits.get_mantissa() >> trim_size) << trim_size); + StorageType trunc_mantissa = + static_cast((bits.get_mantissa() >> trim_size) << trim_size); + new_bits.set_mantissa(trunc_mantissa); T trunc_value = new_bits.get_val(); // If x is already an integer, return it. @@ -190,7 +200,8 @@ round_using_specific_rounding_mode(T x, int rnd) { StorageType trim_value = bits.get_mantissa() & ((StorageType(1) << trim_size) - 1); - StorageType half_value = (StorageType(1) << (trim_size - 1)); + StorageType half_value = + static_cast((StorageType(1) << (trim_size - 1))); // If exponent is 0, trimSize will be equal to the mantissa width, and // truncIsOdd` will not be correct. So, we handle it as a special case // below. diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 31df5d0ab88098..3b07b0b8679c46 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -67,6 +67,7 @@ add_math_entrypoint_object(canonicalizel) add_math_entrypoint_object(ceil) add_math_entrypoint_object(ceilf) add_math_entrypoint_object(ceill) +add_math_entrypoint_object(ceilf16) add_math_entrypoint_object(ceilf128) add_math_entrypoint_object(copysign) @@ -110,6 +111,7 @@ add_math_entrypoint_object(fdimf128) add_math_entrypoint_object(floor) add_math_entrypoint_object(floorf) add_math_entrypoint_object(floorl) +add_math_entrypoint_object(floorf16) add_math_entrypoint_object(floorf128) add_math_entrypoint_object(fma) @@ -293,11 +295,13 @@ add_math_entrypoint_object(rintf128) add_math_entrypoint_object(round) add_math_entrypoint_object(roundf) add_math_entrypoint_object(roundl) +add_math_entrypoint_object(roundf16) add_math_entrypoint_object(roundf128) add_math_entrypoint_object(roundeven) add_math_entrypoint_object(roundevenf) add_math_entrypoint_object(roundevenl) +add_math_entrypoint_object(roundevenf16) add_math_entrypoint_object(roundevenf128) add_math_entrypoint_object(scalbn) @@ -331,6 +335,7 @@ add_math_entrypoint_object(tgammaf) add_math_entrypoint_object(trunc) add_math_entrypoint_object(truncf) add_math_entrypoint_object(truncl) +add_math_entrypoint_object(truncf16) add_math_entrypoint_object(truncf128) add_math_entrypoint_object(ufromfp) diff --git a/libc/src/math/ceilf16.h b/libc/src/math/ceilf16.h new file mode 100644 index 00000000000000..36a6bd219d5b56 --- /dev/null +++ b/libc/src/math/ceilf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for ceilf16 -----------------------*- 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_CEILF16_H +#define LLVM_LIBC_SRC_MATH_CEILF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 ceilf16(float16 x); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_CEILF16_H diff --git a/libc/src/math/floorf16.h b/libc/src/math/floorf16.h new file mode 100644 index 00000000000000..4e5e196105cf6d --- /dev/null +++ b/libc/src/math/floorf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for floorf16 ----------------------*- 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_FLOORF16_H +#define LLVM_LIBC_SRC_MATH_FLOORF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 floorf16(float16 x); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_FLOORF16_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 04656e3186181d..369616caa2565b 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -82,6 +82,19 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + ceilf16 + SRCS + ceilf16.cpp + HDRS + ../ceilf16.h + COMPILE_OPTIONS + -O3 + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.nearest_integer_operations +) + add_entrypoint_object( ceilf128 SRCS @@ -303,6 +316,19 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + truncf16 + SRCS + truncf16.cpp + HDRS + ../truncf16.h + COMPILE_OPTIONS + -O3 + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.nearest_integer_operations +) + add_entrypoint_object( truncf128 SRCS @@ -352,6 +378,19 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + floorf16 + SRCS + floorf16.cpp + HDRS + ../floorf16.h + COMPILE_OPTIONS + -O3 + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.nearest_integer_operations +) + add_entrypoint_object( floorf128 SRCS @@ -401,6 +440,19 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + roundf16 + SRCS + roundf16.cpp + HDRS + ../roundf16.h + COMPILE_OPTIONS + -O3 + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.nearest_integer_operations +) + add_entrypoint_object( roundf128 SRCS @@ -450,6 +502,19 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + roundevenf16 + SRCS + roundevenf16.cpp + HDRS + ../roundevenf16.h + COMPILE_OPTIONS + -O3 + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.nearest_integer_operations +) + add_entrypoint_object( roundevenf128 SRCS diff --git a/libc/src/math/generic/ceilf16.cpp b/libc/src/math/generic/ceilf16.cpp new file mode 100644 index 00000000000000..205d7428f66e67 --- /dev/null +++ b/libc/src/math/generic/ceilf16.cpp @@ -0,0 +1,17 @@ +//===-- Implementation of ceilf16 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/ceilf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, ceilf16, (float16 x)) { return fputil::ceil(x); } + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/floorf16.cpp b/libc/src/math/generic/floorf16.cpp new file mode 100644 index 00000000000000..db0b326c0e5f66 --- /dev/null +++ b/libc/src/math/generic/floorf16.cpp @@ -0,0 +1,17 @@ +//===-- Implementation of floorf16 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/floorf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, floorf16, (float16 x)) { return fputil::floor(x); } + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/roundevenf16.cpp b/libc/src/math/generic/roundevenf16.cpp new file mode 100644 index 00000000000000..9ecf79ce6f6c24 --- /dev/null +++ b/libc/src/math/generic/roundevenf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of roundevenf16 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/roundevenf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, roundevenf16, (float16 x)) { + return fputil::round_using_specific_rounding_mode(x, FP_INT_TONEAREST); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/roundf16.cpp b/libc/src/math/generic/roundf16.cpp new file mode 100644 index 00000000000000..75a255d7798d5b --- /dev/null +++ b/libc/src/math/generic/roundf16.cpp @@ -0,0 +1,17 @@ +//===-- Implementation of roundf16 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/roundf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, roundf16, (float16 x)) { return fputil::round(x); } + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/truncf16.cpp b/libc/src/math/generic/truncf16.cpp new file mode 100644 index 00000000000000..65bd57d8103230 --- /dev/null +++ b/libc/src/math/generic/truncf16.cpp @@ -0,0 +1,17 @@ +//===-- Implementation of truncf16 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/truncf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, truncf16, (float16 x)) { return fputil::trunc(x); } + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/roundevenf16.h b/libc/src/math/roundevenf16.h new file mode 100644 index 00000000000000..382e2e39cff3fa --- /dev/null +++ b/libc/src/math/roundevenf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for roundevenf16 ------------------*- 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_ROUNDEVENF16_H +#define LLVM_LIBC_SRC_MATH_ROUNDEVENF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 roundevenf16(float16 x); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_ROUNDEVENF16_H diff --git a/libc/src/math/roundf16.h b/libc/src/math/roundf16.h new file mode 100644 index 00000000000000..e52f2aeb87e6d6 --- /dev/null +++ b/libc/src/math/roundf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for roundf16 ----------------------*- 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_ROUNDF16_H +#define LLVM_LIBC_SRC_MATH_ROUNDF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 roundf16(float16 x); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_ROUNDF16_H diff --git a/libc/src/math/truncf16.h b/libc/src/math/truncf16.h new file mode 100644 index 00000000000000..6d65980461c497 --- /dev/null +++ b/libc/src/math/truncf16.h @@ -0,0 +1,20 @@ +//===-- Implementation header for truncf16 ----------------------*- 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_TRUNCF16_H +#define LLVM_LIBC_SRC_MATH_TRUNCF16_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 truncf16(float16 x); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_TRUNCF16_H diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index b46fe5e902c67f..685a53d8e7c6a4 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -156,6 +156,18 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + truncf16_test + SUITE + libc-math-smoke-tests + SRCS + truncf16_test.cpp + HDRS + TruncTest.h + DEPENDS + libc.src.math.truncf16 +) + add_fp_unittest( truncf128_test SUITE @@ -268,6 +280,18 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + ceilf16_test + SUITE + libc-math-smoke-tests + SRCS + ceilf16_test.cpp + HDRS + CeilTest.h + DEPENDS + libc.src.math.ceilf16 +) + add_fp_unittest( ceilf128_test SUITE @@ -320,6 +344,18 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + floorf16_test + SUITE + libc-math-smoke-tests + SRCS + floorf16_test.cpp + HDRS + FloorTest.h + DEPENDS + libc.src.math.floorf16 +) + add_fp_unittest( floorf128_test SUITE @@ -372,6 +408,18 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + roundf16_test + SUITE + libc-math-smoke-tests + SRCS + roundf16_test.cpp + HDRS + RoundTest.h + DEPENDS + libc.src.math.roundf16 +) + add_fp_unittest( roundf128_test SUITE @@ -424,6 +472,18 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + roundevenf16_test + SUITE + libc-math-smoke-tests + SRCS + roundevenf16_test.cpp + HDRS + RoundEvenTest.h + DEPENDS + libc.src.math.roundevenf16 +) + add_fp_unittest( roundevenf128_test SUITE diff --git a/libc/test/src/math/smoke/CeilTest.h b/libc/test/src/math/smoke/CeilTest.h index 5e108c0e0feea1..7998eab62ec6b2 100644 --- a/libc/test/src/math/smoke/CeilTest.h +++ b/libc/test/src/math/smoke/CeilTest.h @@ -59,10 +59,10 @@ class CeilTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { EXPECT_FP_EQ(T(-10.0), func(T(-10.32))); EXPECT_FP_EQ(T(11.0), func(T(10.65))); EXPECT_FP_EQ(T(-10.0), func(T(-10.65))); - EXPECT_FP_EQ(T(1235.0), func(T(1234.38))); - EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38))); - EXPECT_FP_EQ(T(1235.0), func(T(1234.96))); - EXPECT_FP_EQ(T(-1234.0), func(T(-1234.96))); + EXPECT_FP_EQ(T(124.0), func(T(123.38))); + EXPECT_FP_EQ(T(-123.0), func(T(-123.38))); + EXPECT_FP_EQ(T(124.0), func(T(123.96))); + EXPECT_FP_EQ(T(-123.0), func(T(-123.96))); } }; diff --git a/libc/test/src/math/smoke/FloorTest.h b/libc/test/src/math/smoke/FloorTest.h index b2102459bc3de6..bc19e4f2859158 100644 --- a/libc/test/src/math/smoke/FloorTest.h +++ b/libc/test/src/math/smoke/FloorTest.h @@ -59,10 +59,10 @@ class FloorTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { EXPECT_FP_EQ(T(-11.0), func(T(-10.32))); EXPECT_FP_EQ(T(10.0), func(T(10.65))); EXPECT_FP_EQ(T(-11.0), func(T(-10.65))); - EXPECT_FP_EQ(T(1234.0), func(T(1234.38))); - EXPECT_FP_EQ(T(-1235.0), func(T(-1234.38))); - EXPECT_FP_EQ(T(1234.0), func(T(1234.96))); - EXPECT_FP_EQ(T(-1235.0), func(T(-1234.96))); + EXPECT_FP_EQ(T(123.0), func(T(123.38))); + EXPECT_FP_EQ(T(-124.0), func(T(-123.38))); + EXPECT_FP_EQ(T(123.0), func(T(123.96))); + EXPECT_FP_EQ(T(-124.0), func(T(-123.96))); } }; diff --git a/libc/test/src/math/smoke/RoundEvenTest.h b/libc/test/src/math/smoke/RoundEvenTest.h index 479b70912fedc9..3477315e683a45 100644 --- a/libc/test/src/math/smoke/RoundEvenTest.h +++ b/libc/test/src/math/smoke/RoundEvenTest.h @@ -57,10 +57,10 @@ class RoundEvenTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { EXPECT_FP_EQ(T(-10.0), func(T(-10.50))); EXPECT_FP_EQ(T(11.0), func(T(10.65))); EXPECT_FP_EQ(T(-11.0), func(T(-10.65))); - EXPECT_FP_EQ(T(1234.0), func(T(1234.50))); - EXPECT_FP_EQ(T(-1234.0), func(T(-1234.50))); - EXPECT_FP_EQ(T(1236.0), func(T(1235.50))); - EXPECT_FP_EQ(T(-1236.0), func(T(-1235.50))); + EXPECT_FP_EQ(T(124.0), func(T(124.50))); + EXPECT_FP_EQ(T(-124.0), func(T(-124.50))); + EXPECT_FP_EQ(T(126.0), func(T(125.50))); + EXPECT_FP_EQ(T(-126.0), func(T(-125.50))); } }; diff --git a/libc/test/src/math/smoke/RoundTest.h b/libc/test/src/math/smoke/RoundTest.h index 36994f27eb4c05..beb70008c330bd 100644 --- a/libc/test/src/math/smoke/RoundTest.h +++ b/libc/test/src/math/smoke/RoundTest.h @@ -59,10 +59,10 @@ class RoundTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { EXPECT_FP_EQ(T(-10.0), func(T(-10.32))); EXPECT_FP_EQ(T(11.0), func(T(10.65))); EXPECT_FP_EQ(T(-11.0), func(T(-10.65))); - EXPECT_FP_EQ(T(1234.0), func(T(1234.38))); - EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38))); - EXPECT_FP_EQ(T(1235.0), func(T(1234.96))); - EXPECT_FP_EQ(T(-1235.0), func(T(-1234.96))); + EXPECT_FP_EQ(T(123.0), func(T(123.38))); + EXPECT_FP_EQ(T(-123.0), func(T(-123.38))); + EXPECT_FP_EQ(T(124.0), func(T(123.96))); + EXPECT_FP_EQ(T(-124.0), func(T(-123.96))); } }; diff --git a/libc/test/src/math/smoke/TruncTest.h b/libc/test/src/math/smoke/TruncTest.h index 1d9c44dfb37488..49688e81707a1e 100644 --- a/libc/test/src/math/smoke/TruncTest.h +++ b/libc/test/src/math/smoke/TruncTest.h @@ -59,10 +59,10 @@ class TruncTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { EXPECT_FP_EQ(T(-10.0), func(T(-10.32))); EXPECT_FP_EQ(T(10.0), func(T(10.65))); EXPECT_FP_EQ(T(-10.0), func(T(-10.65))); - EXPECT_FP_EQ(T(1234.0), func(T(1234.38))); - EXPECT_FP_EQ(T(-1234.0), func(T(-1234.38))); - EXPECT_FP_EQ(T(1234.0), func(T(1234.96))); - EXPECT_FP_EQ(T(-1234.0), func(T(-1234.96))); + EXPECT_FP_EQ(T(123.0), func(T(123.38))); + EXPECT_FP_EQ(T(-123.0), func(T(-123.38))); + EXPECT_FP_EQ(T(123.0), func(T(123.96))); + EXPECT_FP_EQ(T(-123.0), func(T(-123.96))); } }; diff --git a/libc/test/src/math/smoke/ceilf16_test.cpp b/libc/test/src/math/smoke/ceilf16_test.cpp new file mode 100644 index 00000000000000..a6ec922836a759 --- /dev/null +++ b/libc/test/src/math/smoke/ceilf16_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for ceilf16 ---------------------------------------------===// +// +// 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 "CeilTest.h" + +#include "src/math/ceilf16.h" + +LIST_CEIL_TESTS(float16, LIBC_NAMESPACE::ceilf16) diff --git a/libc/test/src/math/smoke/floorf16_test.cpp b/libc/test/src/math/smoke/floorf16_test.cpp new file mode 100644 index 00000000000000..ca5160e927035e --- /dev/null +++ b/libc/test/src/math/smoke/floorf16_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for floorf16 --------------------------------------------===// +// +// 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 "FloorTest.h" + +#include "src/math/floorf16.h" + +LIST_FLOOR_TESTS(float16, LIBC_NAMESPACE::floorf16) diff --git a/libc/test/src/math/smoke/roundevenf16_test.cpp b/libc/test/src/math/smoke/roundevenf16_test.cpp new file mode 100644 index 00000000000000..911a32c9f73f46 --- /dev/null +++ b/libc/test/src/math/smoke/roundevenf16_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for roundevenf16 ----------------------------------------===// +// +// 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 "RoundEvenTest.h" + +#include "src/math/roundevenf16.h" + +LIST_ROUNDEVEN_TESTS(float16, LIBC_NAMESPACE::roundevenf16) diff --git a/libc/test/src/math/smoke/roundf16_test.cpp b/libc/test/src/math/smoke/roundf16_test.cpp new file mode 100644 index 00000000000000..54ead855934db4 --- /dev/null +++ b/libc/test/src/math/smoke/roundf16_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for roundf16 --------------------------------------------===// +// +// 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 "RoundTest.h" + +#include "src/math/roundf16.h" + +LIST_ROUND_TESTS(float16, LIBC_NAMESPACE::roundf16) diff --git a/libc/test/src/math/smoke/truncf16_test.cpp b/libc/test/src/math/smoke/truncf16_test.cpp new file mode 100644 index 00000000000000..832d88ec84f8ed --- /dev/null +++ b/libc/test/src/math/smoke/truncf16_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for truncf16 --------------------------------------------===// +// +// 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 "TruncTest.h" + +#include "src/math/truncf16.h" + +LIST_TRUNC_TESTS(float16, LIBC_NAMESPACE::truncf16)