diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt index ff3a6bfa8a2fc..637be4f19d5b7 100644 --- a/libc/config/baremetal/aarch64/entrypoints.txt +++ b/libc/config/baremetal/aarch64/entrypoints.txt @@ -814,6 +814,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt index f8916d71f86aa..19aedb0a8677d 100644 --- a/libc/config/baremetal/arm/entrypoints.txt +++ b/libc/config/baremetal/arm/entrypoints.txt @@ -817,6 +817,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt index 8a72fa6692869..cfbb598cbe4bf 100644 --- a/libc/config/baremetal/riscv/entrypoints.txt +++ b/libc/config/baremetal/riscv/entrypoints.txt @@ -817,6 +817,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt index 796c0d3c8a4ff..26e97d8993039 100644 --- a/libc/config/darwin/aarch64/entrypoints.txt +++ b/libc/config/darwin/aarch64/entrypoints.txt @@ -647,6 +647,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt index fa1d8def8936c..0556a6f7a4715 100644 --- a/libc/config/darwin/x86_64/entrypoints.txt +++ b/libc/config/darwin/x86_64/entrypoints.txt @@ -290,6 +290,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt index 49c41411cb5d2..8817972480aac 100644 --- a/libc/config/gpu/amdgpu/entrypoints.txt +++ b/libc/config/gpu/amdgpu/entrypoints.txt @@ -673,6 +673,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt index 06a2c9addb7fb..db762ed5c74d6 100644 --- a/libc/config/gpu/nvptx/entrypoints.txt +++ b/libc/config/gpu/nvptx/entrypoints.txt @@ -675,6 +675,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index feea7ff69c166..0a2ebfa3f8720 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -902,6 +902,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt index 8e92fac863c6b..ea1c5c0558272 100644 --- a/libc/config/linux/arm/entrypoints.txt +++ b/libc/config/linux/arm/entrypoints.txt @@ -517,6 +517,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index fb08cfe7bd3f8..d5180b77c3af0 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -920,6 +920,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 37af75454daa3..c64db2cc3548f 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -953,6 +953,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt index c09e6b259fa42..9f825bdf657e9 100644 --- a/libc/config/windows/entrypoints.txt +++ b/libc/config/windows/entrypoints.txt @@ -363,6 +363,8 @@ list(APPEND TARGET_LIBM_ENTRYPOINTS libc.src.math.rintbf16 libc.src.math.roundbf16 libc.src.math.roundevenbf16 + libc.src.math.scalblnbf16 + libc.src.math.scalbnbf16 libc.src.math.setpayloadbf16 libc.src.math.setpayloadsigbf16 libc.src.math.truncbf16 diff --git a/libc/docs/headers/math/index.rst b/libc/docs/headers/math/index.rst index 89624460c3af5..a707b37894afc 100644 --- a/libc/docs/headers/math/index.rst +++ b/libc/docs/headers/math/index.rst @@ -233,9 +233,9 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+ | roundeven | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.9.8 | F.10.6.8 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+ -| scalbln | |check| | |check| | |check| | |check| | |check| | | 7.12.6.19 | F.10.3.19 | +| scalbln | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+ -| scalbn | |check| | |check| | |check| | |check| | |check| | | 7.12.6.19 | F.10.3.19 | +| scalbn | |check| | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+ | setpayload | |check| | |check| | |check| | |check| | |check| | |check| | F.10.13.2 | N/A | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+------------------------+----------------------------+ diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 1edb517421e28..4b325f773b35f 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -518,12 +518,14 @@ add_math_entrypoint_object(scalblnf) add_math_entrypoint_object(scalblnl) add_math_entrypoint_object(scalblnf16) add_math_entrypoint_object(scalblnf128) +add_math_entrypoint_object(scalblnbf16) add_math_entrypoint_object(scalbn) add_math_entrypoint_object(scalbnf) add_math_entrypoint_object(scalbnl) add_math_entrypoint_object(scalbnf16) add_math_entrypoint_object(scalbnf128) +add_math_entrypoint_object(scalbnbf16) add_math_entrypoint_object(setpayload) add_math_entrypoint_object(setpayloadf) diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 904f8d2eb4704..5e252c1cc2f26 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -4646,6 +4646,21 @@ add_entrypoint_object( libc.src.__support.FPUtil.manipulation_functions ) +add_entrypoint_object( + scalblnbf16 + SRCS + scalblnbf16.cpp + HDRS + ../scalblnbf16.h + DEPENDS + libc.hdr.float_macros + libc.src.__support.common + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.manipulation_functions +) + add_entrypoint_object( scalbn SRCS @@ -4703,6 +4718,21 @@ add_entrypoint_object( libc.src.__support.FPUtil.manipulation_functions ) +add_entrypoint_object( + scalbnbf16 + SRCS + scalbnbf16.cpp + HDRS + ../scalblnbf16.h + DEPENDS + libc.hdr.float_macros + libc.src.__support.common + libc.src.__support.macros.config + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.manipulation_functions +) + add_entrypoint_object( fmaf SRCS diff --git a/libc/src/math/generic/scalblnbf16.cpp b/libc/src/math/generic/scalblnbf16.cpp new file mode 100644 index 0000000000000..f85f702660ed2 --- /dev/null +++ b/libc/src/math/generic/scalblnbf16.cpp @@ -0,0 +1,26 @@ +//===-- Implementation of scalblnbf16 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/scalblnbf16.h" +#include "hdr/float_macros.h" +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +#if FLT_RADIX != 2 +#error "FLT_RADIX != 2 is not supported." +#endif + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, scalblnbf16, (bfloat16 x, long n)) { + return fputil::ldexp(x, n); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/scalbnbf16.cpp b/libc/src/math/generic/scalbnbf16.cpp new file mode 100644 index 0000000000000..108f9e7d4d057 --- /dev/null +++ b/libc/src/math/generic/scalbnbf16.cpp @@ -0,0 +1,26 @@ +//===-- Implementation of scalbnbf16 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/scalbnbf16.h" +#include "hdr/float_macros.h" +#include "src/__support/FPUtil/ManipulationFunctions.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +#if FLT_RADIX != 2 +#error "FLT_RADIX != 2 is not supported." +#endif + +namespace LIBC_NAMESPACE_DECL { + +LLVM_LIBC_FUNCTION(bfloat16, scalbnbf16, (bfloat16 x, int n)) { + return fputil::ldexp(x, n); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/scalblnbf16.h b/libc/src/math/scalblnbf16.h new file mode 100644 index 0000000000000..10aad05fc6b1f --- /dev/null +++ b/libc/src/math/scalblnbf16.h @@ -0,0 +1,21 @@ +//===-- Implementation header for scalblnbf16 -------------------*- 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_SCALBLNBF16_H +#define LLVM_LIBC_SRC_MATH_SCALBLNBF16_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 scalblnbf16(bfloat16 x, long n); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_SCALBLNBF16_H diff --git a/libc/src/math/scalbnbf16.h b/libc/src/math/scalbnbf16.h new file mode 100644 index 0000000000000..67efa338fe630 --- /dev/null +++ b/libc/src/math/scalbnbf16.h @@ -0,0 +1,21 @@ +//===-- Implementation header for scalbnbf16 --------------------*- 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_SCALBNBF16_H +#define LLVM_LIBC_SRC_MATH_SCALBNBF16_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +bfloat16 scalbnbf16(bfloat16 x, int n); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_SCALBNBF16_H diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 166802fd9f9cc..226ef2ee71866 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -4881,6 +4881,22 @@ add_fp_unittest( libc.src.__support.FPUtil.normal_float ) +add_fp_unittest( + scalblnbf16_test + SUITE + libc-math-smoke-tests + SRCS + scalblnbf16_test.cpp + HDRS + ScalbnTest.h + DEPENDS + libc.src.math.scalblnbf16 + libc.src.__support.CPP.limits + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits + libc.src.__support.FPUtil.normal_float +) + add_fp_unittest( scalbn_test SUITE @@ -4956,6 +4972,22 @@ add_fp_unittest( libc.src.__support.FPUtil.normal_float ) +add_fp_unittest( + scalbnbf16_test + SUITE + libc-math-smoke-tests + SRCS + scalbnbf16_test.cpp + HDRS + ScalbnTest.h + DEPENDS + libc.src.math.scalbnbf16 + libc.src.__support.CPP.limits + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits + libc.src.__support.FPUtil.normal_float +) + add_fp_unittest( erff_test SUITE diff --git a/libc/test/src/math/smoke/TotalOrderMagTest.h b/libc/test/src/math/smoke/TotalOrderMagTest.h index b5c26bb4bcd37..32f3932cb3f6d 100644 --- a/libc/test/src/math/smoke/TotalOrderMagTest.h +++ b/libc/test/src/math/smoke/TotalOrderMagTest.h @@ -107,6 +107,11 @@ class TotalOrderMagTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { void testNaNPayloads(TotalOrderMagFunc func) { + T qnan_0x15 = FPBits::quiet_nan(Sign::POS, 0x15).get_val(); + T neg_qnan_0x15 = FPBits::quiet_nan(Sign::NEG, 0x15).get_val(); + T snan_0x15 = FPBits::signaling_nan(Sign::POS, 0x15).get_val(); + T neg_snan_0x15 = FPBits::signaling_nan(Sign::NEG, 0x15).get_val(); + EXPECT_TRUE(funcWrapper(func, aNaN, aNaN)); EXPECT_TRUE(funcWrapper(func, sNaN, sNaN)); diff --git a/libc/test/src/math/smoke/TotalOrderTest.h b/libc/test/src/math/smoke/TotalOrderTest.h index 4281a9a0b987d..febed0157a6b2 100644 --- a/libc/test/src/math/smoke/TotalOrderTest.h +++ b/libc/test/src/math/smoke/TotalOrderTest.h @@ -105,6 +105,11 @@ class TotalOrderTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { void testNaNPayloads(TotalOrderFunc func) { + T qnan_0x15 = FPBits::quiet_nan(Sign::POS, 0x15).get_val(); + T neg_qnan_0x15 = FPBits::quiet_nan(Sign::NEG, 0x15).get_val(); + T snan_0x15 = FPBits::signaling_nan(Sign::POS, 0x15).get_val(); + T neg_snan_0x15 = FPBits::signaling_nan(Sign::NEG, 0x15).get_val(); + EXPECT_TRUE(funcWrapper(func, aNaN, aNaN)); EXPECT_TRUE(funcWrapper(func, sNaN, sNaN)); diff --git a/libc/test/src/math/smoke/scalblnbf16_test.cpp b/libc/test/src/math/smoke/scalblnbf16_test.cpp new file mode 100644 index 0000000000000..c6fc3aac5e744 --- /dev/null +++ b/libc/test/src/math/smoke/scalblnbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for scalblnbf16 -----------------------------------------===// +// +// 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 "ScalbnTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/scalblnbf16.h" + +LIST_SCALBN_TESTS(bfloat16, long, LIBC_NAMESPACE::scalblnbf16) diff --git a/libc/test/src/math/smoke/scalbnbf16_test.cpp b/libc/test/src/math/smoke/scalbnbf16_test.cpp new file mode 100644 index 0000000000000..855fd75e6e8f9 --- /dev/null +++ b/libc/test/src/math/smoke/scalbnbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for scalbnbf16 ------------------------------------------===// +// +// 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 "ScalbnTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/scalbnbf16.h" + +LIST_SCALBN_TESTS(bfloat16, int, LIBC_NAMESPACE::scalbnbf16)