diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt index e24e2b9e2a7bb..683c7464abde9 100644 --- a/libc/config/baremetal/aarch64/entrypoints.txt +++ b/libc/config/baremetal/aarch64/entrypoints.txt @@ -757,7 +757,12 @@ endif() list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) if(LIBC_COMPILER_HAS_FIXED_POINT) diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt index 44e9c3edac353..f8ecc2ea8a3a4 100644 --- a/libc/config/baremetal/arm/entrypoints.txt +++ b/libc/config/baremetal/arm/entrypoints.txt @@ -760,7 +760,12 @@ endif() list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) if(LIBC_COMPILER_HAS_FIXED_POINT) diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt index 29cf322a2e33f..679bfb3803686 100644 --- a/libc/config/baremetal/riscv/entrypoints.txt +++ b/libc/config/baremetal/riscv/entrypoints.txt @@ -760,7 +760,12 @@ endif() list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) if(LIBC_COMPILER_HAS_FIXED_POINT) diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt index 03e00a35a4cbe..72b0265552ab8 100644 --- a/libc/config/darwin/aarch64/entrypoints.txt +++ b/libc/config/darwin/aarch64/entrypoints.txt @@ -590,7 +590,12 @@ endif() list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) if(LIBC_COMPILER_HAS_FIXED_POINT) diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt index 00cedaba810c7..b5ab1ee26a867 100644 --- a/libc/config/darwin/x86_64/entrypoints.txt +++ b/libc/config/darwin/x86_64/entrypoints.txt @@ -233,7 +233,12 @@ set(TARGET_LIBM_ENTRYPOINTS list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) set(TARGET_LLVMLIBC_ENTRYPOINTS diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt index cf2b8c6a55878..77a13a66da545 100644 --- a/libc/config/gpu/amdgpu/entrypoints.txt +++ b/libc/config/gpu/amdgpu/entrypoints.txt @@ -616,7 +616,12 @@ endif() list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) set(TARGET_LLVMLIBC_ENTRYPOINTS diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt index 55b27e69d5571..61c9c717d37ef 100644 --- a/libc/config/gpu/nvptx/entrypoints.txt +++ b/libc/config/gpu/nvptx/entrypoints.txt @@ -617,7 +617,12 @@ endif() list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) set(TARGET_LLVMLIBC_ENTRYPOINTS diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index d76cdc2f2db4b..fbdf8fb621b0f 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -844,7 +844,12 @@ endif() list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) if(LLVM_LIBC_FULL_BUILD) diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt index 813c34d498f46..e3f5feecc896a 100644 --- a/libc/config/linux/arm/entrypoints.txt +++ b/libc/config/linux/arm/entrypoints.txt @@ -460,7 +460,12 @@ set(TARGET_LIBM_ENTRYPOINTS list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) set(TARGET_LLVMLIBC_ENTRYPOINTS diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index 190aef7dd7a37..ba67dddbe8b98 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -863,7 +863,12 @@ endif() list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) if(LIBC_COMPILER_HAS_FIXED_POINT) diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index ec41069e98c91..066dc21497691 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -893,10 +893,14 @@ if(LIBC_TYPES_HAS_FLOAT128) ) endif() - list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) if(LIBC_COMPILER_HAS_FIXED_POINT) diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt index 3160d5790f33b..994078c0ed274 100644 --- a/libc/config/windows/entrypoints.txt +++ b/libc/config/windows/entrypoints.txt @@ -306,7 +306,12 @@ set(TARGET_LIBM_ENTRYPOINTS list(APPEND TARGET_LIBM_ENTRYPOINTS # bfloat16 entrypoints + libc.src.math.ceilbf16 libc.src.math.fabsbf16 + libc.src.math.floorbf16 + libc.src.math.roundbf16 + libc.src.math.roundevenbf16 + libc.src.math.truncbf16 ) set(TARGET_LLVMLIBC_ENTRYPOINTS diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 0522e0e15bad2..c3840d3c4aa89 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -91,6 +91,7 @@ add_math_entrypoint_object(ceilf) add_math_entrypoint_object(ceill) add_math_entrypoint_object(ceilf16) add_math_entrypoint_object(ceilf128) +add_math_entrypoint_object(ceilbf16) add_math_entrypoint_object(copysign) add_math_entrypoint_object(copysignf) @@ -214,6 +215,7 @@ add_math_entrypoint_object(floorf) add_math_entrypoint_object(floorl) add_math_entrypoint_object(floorf16) add_math_entrypoint_object(floorf128) +add_math_entrypoint_object(floorbf16) add_math_entrypoint_object(fma) add_math_entrypoint_object(fmaf) @@ -463,12 +465,14 @@ add_math_entrypoint_object(roundf) add_math_entrypoint_object(roundl) add_math_entrypoint_object(roundf16) add_math_entrypoint_object(roundf128) +add_math_entrypoint_object(roundbf16) 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(roundevenbf16) add_math_entrypoint_object(scalbln) add_math_entrypoint_object(scalblnf) @@ -546,6 +550,7 @@ add_math_entrypoint_object(truncf) add_math_entrypoint_object(truncl) add_math_entrypoint_object(truncf16) add_math_entrypoint_object(truncf128) +add_math_entrypoint_object(truncbf16) add_math_entrypoint_object(ufromfp) add_math_entrypoint_object(ufromfpf) diff --git a/libc/src/math/ceilbf16.h b/libc/src/math/ceilbf16.h new file mode 100644 index 0000000000000..bf70f25ab2b91 --- /dev/null +++ b/libc/src/math/ceilbf16.h @@ -0,0 +1,21 @@ +//===-- Implementation header for ceilbf16 ----------------------*- 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_CEILBF16_H +#define LLVM_LIBC_SRC_MATH_CEILBF16_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 ceilbf16(bfloat16 x); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_CEILBF16_H diff --git a/libc/src/math/floorbf16.h b/libc/src/math/floorbf16.h new file mode 100644 index 0000000000000..9b5a30adadd86 --- /dev/null +++ b/libc/src/math/floorbf16.h @@ -0,0 +1,21 @@ +//===-- Implementation header for floorbf16 ---------------------*- 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_FLOORBF16_H +#define LLVM_LIBC_SRC_MATH_FLOORBF16_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 floorbf16(bfloat16 x); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_FLOORBF16_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index a86619576cfc6..0bec7dda1788a 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -156,6 +156,22 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + ceilbf16 + SRCS + ceilbf16.cpp + HDRS + ../ceilbf16.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.nearest_integer_operations + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + FLAGS + ROUND_OPT +) + add_entrypoint_object( daddl SRCS @@ -801,6 +817,22 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + truncbf16 + SRCS + truncbf16.cpp + HDRS + ../truncbf16.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.nearest_integer_operations + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + FLAGS + ROUND_OPT +) + add_entrypoint_object( floor SRCS @@ -861,6 +893,22 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + floorbf16 + SRCS + floorbf16.cpp + HDRS + ../floorbf16.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.nearest_integer_operations + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + FLAGS + ROUND_OPT +) + add_entrypoint_object( round SRCS @@ -921,6 +969,22 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + roundbf16 + SRCS + roundbf16.cpp + HDRS + ../roundbf16.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.nearest_integer_operations + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + FLAGS + ROUND_OPT +) + add_entrypoint_object( roundeven SRCS @@ -981,6 +1045,22 @@ add_entrypoint_object( libc.src.__support.FPUtil.nearest_integer_operations ) +add_entrypoint_object( + roundevenbf16 + SRCS + roundevenbf16.cpp + HDRS + ../roundevenbf16.h + DEPENDS + libc.src.__support.common + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.nearest_integer_operations + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + FLAGS + ROUND_OPT +) + add_entrypoint_object( lround SRCS diff --git a/libc/src/math/generic/ceilbf16.cpp b/libc/src/math/generic/ceilbf16.cpp new file mode 100644 index 0000000000000..441dcf0e93d6f --- /dev/null +++ b/libc/src/math/generic/ceilbf16.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of ceilbf16 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/ceilbf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, ceilbf16, (bfloat16 x)) { return fputil::ceil(x); } + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/floorbf16.cpp b/libc/src/math/generic/floorbf16.cpp new file mode 100644 index 0000000000000..d157096c3e62f --- /dev/null +++ b/libc/src/math/generic/floorbf16.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of floorbf16 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/floorbf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, floorbf16, (bfloat16 x)) { + return fputil::floor(x); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/roundbf16.cpp b/libc/src/math/generic/roundbf16.cpp new file mode 100644 index 0000000000000..cc7e5e2375d58 --- /dev/null +++ b/libc/src/math/generic/roundbf16.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of roundbf16 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/roundbf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, roundbf16, (bfloat16 x)) { + return fputil::round(x); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/roundevenbf16.cpp b/libc/src/math/generic/roundevenbf16.cpp new file mode 100644 index 0000000000000..39419e483fb9e --- /dev/null +++ b/libc/src/math/generic/roundevenbf16.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of roundevenbf16 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/roundevenbf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, roundevenbf16, (bfloat16 x)) { + return fputil::round_using_specific_rounding_mode(x, FP_INT_TONEAREST); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/truncbf16.cpp b/libc/src/math/generic/truncbf16.cpp new file mode 100644 index 0000000000000..dfbe83d003377 --- /dev/null +++ b/libc/src/math/generic/truncbf16.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of truncbf16 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/truncbf16.h" +#include "src/__support/FPUtil/NearestIntegerOperations.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, truncbf16, (bfloat16 x)) { + return fputil::trunc(x); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/roundbf16.h b/libc/src/math/roundbf16.h new file mode 100644 index 0000000000000..0f74e43ba27be --- /dev/null +++ b/libc/src/math/roundbf16.h @@ -0,0 +1,22 @@ +//===-- Implementation header for roundbf16 ---------------------*- 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_ROUNDBF16_H +#define LLVM_LIBC_SRC_MATH_ROUNDBF16_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 roundbf16(bfloat16 x); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_ROUNDBF16_H diff --git a/libc/src/math/roundevenbf16.h b/libc/src/math/roundevenbf16.h new file mode 100644 index 0000000000000..f4374d2c24e5f --- /dev/null +++ b/libc/src/math/roundevenbf16.h @@ -0,0 +1,21 @@ +//===-- Implementation header for roundevenbf16 -----------------*- 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_ROUNDEVENBF16_H +#define LLVM_LIBC_SRC_MATH_ROUNDEVENBF16_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 roundevenbf16(bfloat16 x); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_ROUNDEVENBF16_H diff --git a/libc/src/math/truncbf16.h b/libc/src/math/truncbf16.h new file mode 100644 index 0000000000000..c87d4cc2b2c4d --- /dev/null +++ b/libc/src/math/truncbf16.h @@ -0,0 +1,21 @@ +//===-- Implementation header for truncbf16 ---------------------*- 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_TRUNCBF16_H +#define LLVM_LIBC_SRC_MATH_TRUNCBF16_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 truncbf16(bfloat16 x); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_TRUNCBF16_H diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index a722f612af817..5f497c63759f4 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -344,6 +344,19 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + truncbf16_test + SUITE + libc-math-smoke-tests + SRCS + truncbf16_test.cpp + HDRS + TruncTest.h + DEPENDS + libc.src.math.truncbf16 + libc.src.__support.FPUtil.bfloat16 +) + add_fp_unittest( canonicalize_test SUITE @@ -543,6 +556,19 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + ceilbf16_test + SUITE + libc-math-smoke-tests + SRCS + ceilbf16_test.cpp + HDRS + CeilTest.h + DEPENDS + libc.src.math.ceilbf16 + libc.src.__support.FPUtil.bfloat16 +) + add_fp_unittest( dfmal_test SUITE @@ -663,6 +689,19 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + floorbf16_test + SUITE + libc-math-smoke-tests + SRCS + floorbf16_test.cpp + HDRS + FloorTest.h + DEPENDS + libc.src.math.floorbf16 + libc.src.__support.FPUtil.bfloat16 +) + add_fp_unittest( round_test SUITE @@ -727,6 +766,19 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + roundbf16_test + SUITE + libc-math-smoke-tests + SRCS + roundbf16_test.cpp + HDRS + RoundTest.h + DEPENDS + libc.src.math.roundbf16 + libc.src.__support.FPUtil.bfloat16 +) + add_fp_unittest( roundeven_test SUITE @@ -791,6 +843,19 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + roundevenbf16_test + SUITE + libc-math-smoke-tests + SRCS + roundevenbf16_test.cpp + HDRS + RoundEvenTest.h + DEPENDS + libc.src.math.roundevenbf16 + libc.src.__support.FPUtil.bfloat16 +) + add_fp_unittest( lround_test SUITE diff --git a/libc/test/src/math/smoke/CeilTest.h b/libc/test/src/math/smoke/CeilTest.h index 7998eab62ec6b..1839db97887c4 100644 --- a/libc/test/src/math/smoke/CeilTest.h +++ b/libc/test/src/math/smoke/CeilTest.h @@ -59,10 +59,12 @@ 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(50.0), func(T(49.62))); + EXPECT_FP_EQ(T(-50.0), func(T(-50.31))); 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))); + EXPECT_FP_EQ(T(-123.0), func(T(-123.5))); } }; diff --git a/libc/test/src/math/smoke/FloorTest.h b/libc/test/src/math/smoke/FloorTest.h index bc19e4f285915..cbcf276cddfff 100644 --- a/libc/test/src/math/smoke/FloorTest.h +++ b/libc/test/src/math/smoke/FloorTest.h @@ -59,10 +59,11 @@ 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(50.0), func(T(50.31))); + EXPECT_FP_EQ(T(-50.0), func(T(-49.63))); 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))); + EXPECT_FP_EQ(T(-124.0), func(T(-123.5))); } }; diff --git a/libc/test/src/math/smoke/RoundTest.h b/libc/test/src/math/smoke/RoundTest.h index beb70008c330b..72889dada1378 100644 --- a/libc/test/src/math/smoke/RoundTest.h +++ b/libc/test/src/math/smoke/RoundTest.h @@ -59,8 +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(123.0), func(T(123.38))); - EXPECT_FP_EQ(T(-123.0), func(T(-123.38))); + EXPECT_FP_EQ(T(50.0), func(T(49.63))); + EXPECT_FP_EQ(T(-50.0), func(T(-50.31))); + EXPECT_FP_EQ(T(124.0), func(T(123.5))); + EXPECT_FP_EQ(T(-124.0), func(T(-123.5))); 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 49688e81707a1..e088f29db2cea 100644 --- a/libc/test/src/math/smoke/TruncTest.h +++ b/libc/test/src/math/smoke/TruncTest.h @@ -61,8 +61,8 @@ class TruncTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { EXPECT_FP_EQ(T(-10.0), func(T(-10.65))); 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))); + EXPECT_FP_EQ(T(123.0), func(T(123.5))); + EXPECT_FP_EQ(T(-123.0), func(T(-123.5))); } }; diff --git a/libc/test/src/math/smoke/ceilbf16_test.cpp b/libc/test/src/math/smoke/ceilbf16_test.cpp new file mode 100644 index 0000000000000..dcaf058344ff0 --- /dev/null +++ b/libc/test/src/math/smoke/ceilbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for ceilbf16 --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/ceilbf16.h" + +LIST_CEIL_TESTS(bfloat16, LIBC_NAMESPACE::ceilbf16) diff --git a/libc/test/src/math/smoke/floorbf16_test.cpp b/libc/test/src/math/smoke/floorbf16_test.cpp new file mode 100644 index 0000000000000..9cc77cd15aa1c --- /dev/null +++ b/libc/test/src/math/smoke/floorbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for floorbf16 -------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/floorbf16.h" + +LIST_FLOOR_TESTS(bfloat16, LIBC_NAMESPACE::floorbf16) diff --git a/libc/test/src/math/smoke/roundbf16_test.cpp b/libc/test/src/math/smoke/roundbf16_test.cpp new file mode 100644 index 0000000000000..51638689e8092 --- /dev/null +++ b/libc/test/src/math/smoke/roundbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for roundbf16 -------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/roundbf16.h" + +LIST_ROUND_TESTS(bfloat16, LIBC_NAMESPACE::roundbf16) diff --git a/libc/test/src/math/smoke/roundevenbf16_test.cpp b/libc/test/src/math/smoke/roundevenbf16_test.cpp new file mode 100644 index 0000000000000..711c37a4e5115 --- /dev/null +++ b/libc/test/src/math/smoke/roundevenbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for roundevenbf16 ---------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/roundevenbf16.h" + +LIST_ROUNDEVEN_TESTS(bfloat16, LIBC_NAMESPACE::roundevenbf16) diff --git a/libc/test/src/math/smoke/truncbf16_test.cpp b/libc/test/src/math/smoke/truncbf16_test.cpp new file mode 100644 index 0000000000000..970fa69b3c7a1 --- /dev/null +++ b/libc/test/src/math/smoke/truncbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for truncbf16 -------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/truncbf16.h" + +LIST_TRUNC_TESTS(bfloat16, LIBC_NAMESPACE::truncbf16)