From 4e567242133678c88a6cb5aeb979c6148f6a7035 Mon Sep 17 00:00:00 2001 From: OverMighty Date: Wed, 3 Jul 2024 01:27:09 +0200 Subject: [PATCH] [libc][math][c23] Add f16{add,sub}{,l,f128} C23 math functions (#97072) Part of #93566. --- libc/config/linux/aarch64/entrypoints.txt | 2 + libc/config/linux/x86_64/entrypoints.txt | 6 ++ libc/docs/math/index.rst | 4 +- libc/spec/llvm_libc_ext.td | 4 + libc/spec/stdc.td | 4 + libc/src/math/CMakeLists.txt | 6 ++ libc/src/math/f16add.h | 20 +++++ libc/src/math/f16addf128.h | 20 +++++ libc/src/math/f16addl.h | 20 +++++ libc/src/math/f16sub.h | 20 +++++ libc/src/math/f16subf128.h | 20 +++++ libc/src/math/f16subl.h | 20 +++++ libc/src/math/generic/CMakeLists.txt | 78 ++++++++++++++++++ libc/src/math/generic/f16add.cpp | 19 +++++ libc/src/math/generic/f16addf128.cpp | 19 +++++ libc/src/math/generic/f16addl.cpp | 19 +++++ libc/src/math/generic/f16sub.cpp | 19 +++++ libc/src/math/generic/f16subf128.cpp | 19 +++++ libc/src/math/generic/f16subl.cpp | 19 +++++ libc/test/src/math/CMakeLists.txt | 52 ++++++++++++ libc/test/src/math/f16add_test.cpp | 13 +++ libc/test/src/math/f16addl_test.cpp | 13 +++ libc/test/src/math/f16sub_test.cpp | 13 +++ libc/test/src/math/f16subl_test.cpp | 13 +++ libc/test/src/math/smoke/CMakeLists.txt | 87 ++++++++++++++++++++ libc/test/src/math/smoke/f16add_test.cpp | 13 +++ libc/test/src/math/smoke/f16addf128_test.cpp | 13 +++ libc/test/src/math/smoke/f16addl_test.cpp | 13 +++ libc/test/src/math/smoke/f16sub_test.cpp | 13 +++ libc/test/src/math/smoke/f16subf128_test.cpp | 13 +++ libc/test/src/math/smoke/f16subl_test.cpp | 13 +++ 31 files changed, 605 insertions(+), 2 deletions(-) create mode 100644 libc/src/math/f16add.h create mode 100644 libc/src/math/f16addf128.h create mode 100644 libc/src/math/f16addl.h create mode 100644 libc/src/math/f16sub.h create mode 100644 libc/src/math/f16subf128.h create mode 100644 libc/src/math/f16subl.h create mode 100644 libc/src/math/generic/f16add.cpp create mode 100644 libc/src/math/generic/f16addf128.cpp create mode 100644 libc/src/math/generic/f16addl.cpp create mode 100644 libc/src/math/generic/f16sub.cpp create mode 100644 libc/src/math/generic/f16subf128.cpp create mode 100644 libc/src/math/generic/f16subl.cpp create mode 100644 libc/test/src/math/f16add_test.cpp create mode 100644 libc/test/src/math/f16addl_test.cpp create mode 100644 libc/test/src/math/f16sub_test.cpp create mode 100644 libc/test/src/math/f16subl_test.cpp create mode 100644 libc/test/src/math/smoke/f16add_test.cpp create mode 100644 libc/test/src/math/smoke/f16addf128_test.cpp create mode 100644 libc/test/src/math/smoke/f16addl_test.cpp create mode 100644 libc/test/src/math/smoke/f16sub_test.cpp create mode 100644 libc/test/src/math/smoke/f16subf128_test.cpp create mode 100644 libc/test/src/math/smoke/f16subl_test.cpp diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index ff35e8fffec197..940df63e3912b7 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -508,12 +508,14 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.canonicalizef16 libc.src.math.ceilf16 libc.src.math.copysignf16 + libc.src.math.f16add libc.src.math.f16addf libc.src.math.f16div libc.src.math.f16divf libc.src.math.f16fmaf libc.src.math.f16sqrt libc.src.math.f16sqrtf + libc.src.math.f16sub libc.src.math.f16subf libc.src.math.fabsf16 libc.src.math.fdimf16 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 3eefa129c97585..09f04fb31dfd82 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -538,7 +538,9 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.canonicalizef16 libc.src.math.ceilf16 libc.src.math.copysignf16 + libc.src.math.f16add libc.src.math.f16addf + libc.src.math.f16addl libc.src.math.f16div libc.src.math.f16divf libc.src.math.f16divl @@ -548,7 +550,9 @@ if(LIBC_TYPES_HAS_FLOAT16) libc.src.math.f16sqrt libc.src.math.f16sqrtf libc.src.math.f16sqrtl + libc.src.math.f16sub libc.src.math.f16subf + libc.src.math.f16subl libc.src.math.fabsf16 libc.src.math.fdimf16 libc.src.math.floorf16 @@ -601,9 +605,11 @@ if(LIBC_TYPES_HAS_FLOAT16) if(LIBC_TYPES_HAS_FLOAT128) list(APPEND TARGET_LIBM_ENTRYPOINTS # math.h C23 mixed _Float16 and _Float128 entrypoints + libc.src.math.f16addf128 libc.src.math.f16divf128 libc.src.math.f16fmaf128 libc.src.math.f16sqrtf128 + libc.src.math.f16subf128 ) endif() endif() diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index e4da3d42baf7ac..04f63d03778a80 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -124,13 +124,13 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | dsub | N/A | N/A | | N/A | | 7.12.14.2 | F.10.11 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| f16add | |check|\* | | | N/A | | 7.12.14.1 | F.10.11 | +| f16add | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.1 | F.10.11 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | f16div | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.4 | F.10.11 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | f16fma | |check| | |check| | |check| | N/A | |check| | 7.12.14.5 | F.10.11 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| f16sub | |check|\* | | | N/A | | 7.12.14.2 | F.10.11 | +| f16sub | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.2 | F.10.11 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | fabs | |check| | |check| | |check| | |check| | |check| | 7.12.7.3 | F.10.4.3 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td index ff7831f8bce16b..b994e7ca56a933 100644 --- a/libc/spec/llvm_libc_ext.td +++ b/libc/spec/llvm_libc_ext.td @@ -57,9 +57,13 @@ def LLVMLibcExt : StandardSpec<"llvm_libc_ext"> { [], // Types [], // Enumerations [ + GuardedFunctionSpec<"f16add", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"f16addf", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"f16addl", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"f16sub", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"f16subf", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"f16subl", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"f16div", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"f16divf", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 6e59062dde7273..9ff40bf76700c8 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -729,6 +729,10 @@ def StdC : StandardSpec<"stdc"> { GuardedFunctionSpec<"setpayloadsigf16", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"f16addf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">, + + GuardedFunctionSpec<"f16subf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">, + GuardedFunctionSpec<"f16divf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">, GuardedFunctionSpec<"f16sqrtf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 5b20913134fdf5..0983d268bd4b8c 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -99,7 +99,10 @@ add_math_entrypoint_object(exp10f) add_math_entrypoint_object(expm1) add_math_entrypoint_object(expm1f) +add_math_entrypoint_object(f16add) add_math_entrypoint_object(f16addf) +add_math_entrypoint_object(f16addl) +add_math_entrypoint_object(f16addf128) add_math_entrypoint_object(f16div) add_math_entrypoint_object(f16divf) @@ -116,7 +119,10 @@ add_math_entrypoint_object(f16sqrtf) add_math_entrypoint_object(f16sqrtl) add_math_entrypoint_object(f16sqrtf128) +add_math_entrypoint_object(f16sub) add_math_entrypoint_object(f16subf) +add_math_entrypoint_object(f16subl) +add_math_entrypoint_object(f16subf128) add_math_entrypoint_object(fabs) add_math_entrypoint_object(fabsf) diff --git a/libc/src/math/f16add.h b/libc/src/math/f16add.h new file mode 100644 index 00000000000000..763a0787d860de --- /dev/null +++ b/libc/src/math/f16add.h @@ -0,0 +1,20 @@ +//===-- Implementation header for f16add ------------------------*- 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_F16ADD_H +#define LLVM_LIBC_SRC_MATH_F16ADD_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 f16add(double x, double y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_F16ADD_H diff --git a/libc/src/math/f16addf128.h b/libc/src/math/f16addf128.h new file mode 100644 index 00000000000000..284ce1d3037755 --- /dev/null +++ b/libc/src/math/f16addf128.h @@ -0,0 +1,20 @@ +//===-- Implementation header for f16addf128 --------------------*- 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_F16ADDF128_H +#define LLVM_LIBC_SRC_MATH_F16ADDF128_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 f16addf128(float128 x, float128 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_F16ADDF128_H diff --git a/libc/src/math/f16addl.h b/libc/src/math/f16addl.h new file mode 100644 index 00000000000000..6a7267a10d0c6a --- /dev/null +++ b/libc/src/math/f16addl.h @@ -0,0 +1,20 @@ +//===-- Implementation header for f16addl -----------------------*- 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_F16ADDL_H +#define LLVM_LIBC_SRC_MATH_F16ADDL_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 f16addl(long double x, long double y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_F16ADDL_H diff --git a/libc/src/math/f16sub.h b/libc/src/math/f16sub.h new file mode 100644 index 00000000000000..66f82daada0196 --- /dev/null +++ b/libc/src/math/f16sub.h @@ -0,0 +1,20 @@ +//===-- Implementation header for f16sub ------------------------*- 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_F16SUB_H +#define LLVM_LIBC_SRC_MATH_F16SUB_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 f16sub(double x, double y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_F16SUB_H diff --git a/libc/src/math/f16subf128.h b/libc/src/math/f16subf128.h new file mode 100644 index 00000000000000..eb674297ba2667 --- /dev/null +++ b/libc/src/math/f16subf128.h @@ -0,0 +1,20 @@ +//===-- Implementation header for f16subf128 --------------------*- 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_F16SUBF128_H +#define LLVM_LIBC_SRC_MATH_F16SUBF128_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 f16subf128(float128 x, float128 y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_F16SUBF128_H diff --git a/libc/src/math/f16subl.h b/libc/src/math/f16subl.h new file mode 100644 index 00000000000000..43b44a57a604ef --- /dev/null +++ b/libc/src/math/f16subl.h @@ -0,0 +1,20 @@ +//===-- Implementation header for f16subl -----------------------*- 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_F16SUBL_H +#define LLVM_LIBC_SRC_MATH_F16SUBL_H + +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE { + +float16 f16subl(long double x, long double y); + +} // namespace LIBC_NAMESPACE + +#endif // LLVM_LIBC_SRC_MATH_F16SUBL_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index d6ea8c54174b69..2e4ed8f2961da5 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -3795,6 +3795,19 @@ add_entrypoint_object( -O3 ) +add_entrypoint_object( + f16add + SRCS + f16add.cpp + HDRS + ../f16add.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.generic.add_sub + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( f16addf SRCS @@ -3808,6 +3821,45 @@ add_entrypoint_object( -O3 ) +add_entrypoint_object( + f16addl + SRCS + f16addl.cpp + HDRS + ../f16addl.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.generic.add_sub + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( + f16addf128 + SRCS + f16addf128.cpp + HDRS + ../f16addf128.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.generic.add_sub + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( + f16sub + SRCS + f16sub.cpp + HDRS + ../f16sub.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.generic.add_sub + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( f16subf SRCS @@ -3821,6 +3873,32 @@ add_entrypoint_object( -O3 ) +add_entrypoint_object( + f16subl + SRCS + f16subl.cpp + HDRS + ../f16subl.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.generic.add_sub + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( + f16subf128 + SRCS + f16subf128.cpp + HDRS + ../f16subf128.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.generic.add_sub + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( f16div SRCS diff --git a/libc/src/math/generic/f16add.cpp b/libc/src/math/generic/f16add.cpp new file mode 100644 index 00000000000000..ef9b43e9f46aa3 --- /dev/null +++ b/libc/src/math/generic/f16add.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of f16add 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/f16add.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, f16add, (double x, double y)) { + return fputil::generic::add(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/f16addf128.cpp b/libc/src/math/generic/f16addf128.cpp new file mode 100644 index 00000000000000..61c458f7d5de1f --- /dev/null +++ b/libc/src/math/generic/f16addf128.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of f16addf128 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/f16addf128.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, f16addf128, (float128 x, float128 y)) { + return fputil::generic::add(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/f16addl.cpp b/libc/src/math/generic/f16addl.cpp new file mode 100644 index 00000000000000..d32d09d0dbb836 --- /dev/null +++ b/libc/src/math/generic/f16addl.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of f16addl 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/f16addl.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, f16addl, (long double x, long double y)) { + return fputil::generic::add(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/f16sub.cpp b/libc/src/math/generic/f16sub.cpp new file mode 100644 index 00000000000000..114c8ad3155e1b --- /dev/null +++ b/libc/src/math/generic/f16sub.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of f16sub 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/f16sub.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, f16sub, (double x, double y)) { + return fputil::generic::sub(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/f16subf128.cpp b/libc/src/math/generic/f16subf128.cpp new file mode 100644 index 00000000000000..1f9ff28abdf298 --- /dev/null +++ b/libc/src/math/generic/f16subf128.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of f16subf128 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/f16subf128.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, f16subf128, (float128 x, float128 y)) { + return fputil::generic::sub(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/src/math/generic/f16subl.cpp b/libc/src/math/generic/f16subl.cpp new file mode 100644 index 00000000000000..31970af9a23668 --- /dev/null +++ b/libc/src/math/generic/f16subl.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of f16subl 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/f16subl.h" +#include "src/__support/FPUtil/generic/add_sub.h" +#include "src/__support/common.h" + +namespace LIBC_NAMESPACE { + +LLVM_LIBC_FUNCTION(float16, f16subl, (long double x, long double y)) { + return fputil::generic::sub(x, y); +} + +} // namespace LIBC_NAMESPACE diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index 637e6720400ffb..f919634ae108c5 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -1996,6 +1996,19 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + f16add_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + f16add_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.math.f16add +) + add_fp_unittest( f16addf_test NEED_MPFR @@ -2009,6 +2022,32 @@ add_fp_unittest( libc.src.math.f16addf ) +add_fp_unittest( + f16addl_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + f16addl_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.math.f16addl +) + +add_fp_unittest( + f16sub_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + f16sub_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.math.f16sub +) + add_fp_unittest( f16subf_test NEED_MPFR @@ -2022,6 +2061,19 @@ add_fp_unittest( libc.src.math.f16subf ) +add_fp_unittest( + f16subl_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + f16subl_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.math.f16subl +) + add_fp_unittest( f16div_test NEED_MPFR diff --git a/libc/test/src/math/f16add_test.cpp b/libc/test/src/math/f16add_test.cpp new file mode 100644 index 00000000000000..c47ece2a925551 --- /dev/null +++ b/libc/test/src/math/f16add_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16add ----------------------------------------------===// +// +// 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 "AddTest.h" + +#include "src/math/f16add.h" + +LIST_ADD_TESTS(float16, double, LIBC_NAMESPACE::f16add) diff --git a/libc/test/src/math/f16addl_test.cpp b/libc/test/src/math/f16addl_test.cpp new file mode 100644 index 00000000000000..f8e0d9ba6b4dec --- /dev/null +++ b/libc/test/src/math/f16addl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16addl ---------------------------------------------===// +// +// 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 "AddTest.h" + +#include "src/math/f16addl.h" + +LIST_ADD_TESTS(float16, long double, LIBC_NAMESPACE::f16addl) diff --git a/libc/test/src/math/f16sub_test.cpp b/libc/test/src/math/f16sub_test.cpp new file mode 100644 index 00000000000000..37b970952fe5e3 --- /dev/null +++ b/libc/test/src/math/f16sub_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16sub ----------------------------------------------===/ +// +// 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 "SubTest.h" + +#include "src/math/f16sub.h" + +LIST_SUB_TESTS(float16, double, LIBC_NAMESPACE::f16sub) diff --git a/libc/test/src/math/f16subl_test.cpp b/libc/test/src/math/f16subl_test.cpp new file mode 100644 index 00000000000000..c41e6e97bab09f --- /dev/null +++ b/libc/test/src/math/f16subl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16subl ---------------------------------------------===// +// +// 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 "SubTest.h" + +#include "src/math/f16subl.h" + +LIST_SUB_TESTS(float16, long double, LIBC_NAMESPACE::f16subl) diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 1b269edaa24778..f244e7addc1516 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -3643,6 +3643,21 @@ add_fp_unittest( libc.src.math.setpayloadsigf16 ) +add_fp_unittest( + f16add_test + SUITE + libc-math-smoke-tests + SRCS + f16add_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.__support.FPUtil.basic_operations + libc.src.math.f16add +) + add_fp_unittest( f16addf_test SUITE @@ -3658,6 +3673,50 @@ add_fp_unittest( libc.src.math.f16addf ) +add_fp_unittest( + f16addl_test + SUITE + libc-math-smoke-tests + SRCS + f16addl_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.__support.FPUtil.basic_operations + libc.src.math.f16addl +) + +add_fp_unittest( + f16addf128_test + SUITE + libc-math-smoke-tests + SRCS + f16addf128_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.__support.FPUtil.basic_operations + libc.src.math.f16addf128 +) + +add_fp_unittest( + f16sub_test + SUITE + libc-math-smoke-tests + SRCS + f16sub_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.__support.FPUtil.basic_operations + libc.src.math.f16sub +) + add_fp_unittest( f16subf_test SUITE @@ -3672,6 +3731,34 @@ add_fp_unittest( libc.src.math.f16subf ) +add_fp_unittest( + f16subl_test + SUITE + libc-math-smoke-tests + SRCS + f16subl_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.__support.FPUtil.basic_operations + libc.src.math.f16subl +) + +add_fp_unittest( + f16subf128_test + SUITE + libc-math-smoke-tests + SRCS + f16subf128_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.__support.FPUtil.basic_operations + libc.src.math.f16subf128 +) + add_fp_unittest( f16div_test SUITE diff --git a/libc/test/src/math/smoke/f16add_test.cpp b/libc/test/src/math/smoke/f16add_test.cpp new file mode 100644 index 00000000000000..c47ece2a925551 --- /dev/null +++ b/libc/test/src/math/smoke/f16add_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16add ----------------------------------------------===// +// +// 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 "AddTest.h" + +#include "src/math/f16add.h" + +LIST_ADD_TESTS(float16, double, LIBC_NAMESPACE::f16add) diff --git a/libc/test/src/math/smoke/f16addf128_test.cpp b/libc/test/src/math/smoke/f16addf128_test.cpp new file mode 100644 index 00000000000000..8ed123b4ff1e85 --- /dev/null +++ b/libc/test/src/math/smoke/f16addf128_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16addf128 ------------------------------------------===// +// +// 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 "AddTest.h" + +#include "src/math/f16addf128.h" + +LIST_ADD_TESTS(float16, float128, LIBC_NAMESPACE::f16addf128) diff --git a/libc/test/src/math/smoke/f16addl_test.cpp b/libc/test/src/math/smoke/f16addl_test.cpp new file mode 100644 index 00000000000000..f8e0d9ba6b4dec --- /dev/null +++ b/libc/test/src/math/smoke/f16addl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16addl ---------------------------------------------===// +// +// 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 "AddTest.h" + +#include "src/math/f16addl.h" + +LIST_ADD_TESTS(float16, long double, LIBC_NAMESPACE::f16addl) diff --git a/libc/test/src/math/smoke/f16sub_test.cpp b/libc/test/src/math/smoke/f16sub_test.cpp new file mode 100644 index 00000000000000..4ab347ba614fbd --- /dev/null +++ b/libc/test/src/math/smoke/f16sub_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16sub ----------------------------------------------===// +// +// 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 "SubTest.h" + +#include "src/math/f16sub.h" + +LIST_SUB_TESTS(float16, double, LIBC_NAMESPACE::f16sub) diff --git a/libc/test/src/math/smoke/f16subf128_test.cpp b/libc/test/src/math/smoke/f16subf128_test.cpp new file mode 100644 index 00000000000000..4936d89c1f9045 --- /dev/null +++ b/libc/test/src/math/smoke/f16subf128_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16subf128 ------------------------------------------===// +// +// 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 "SubTest.h" + +#include "src/math/f16subf128.h" + +LIST_SUB_TESTS(float16, float128, LIBC_NAMESPACE::f16subf128) diff --git a/libc/test/src/math/smoke/f16subl_test.cpp b/libc/test/src/math/smoke/f16subl_test.cpp new file mode 100644 index 00000000000000..c41e6e97bab09f --- /dev/null +++ b/libc/test/src/math/smoke/f16subl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for f16subl ---------------------------------------------===// +// +// 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 "SubTest.h" + +#include "src/math/f16subl.h" + +LIST_SUB_TESTS(float16, long double, LIBC_NAMESPACE::f16subl)