[libc-commits] [libc] 055a77b - [libc] Add missing MPFR-based tests for f16 and bf16 math functions (#218281)
via libc-commits
libc-commits at lists.llvm.org
Sun Aug 30 02:36:55 PDT 2026
Author: tht2005
Date: 2026-08-30T15:06:50+05:30
New Revision: 055a77bb291a8df8a8be1084472984e80cf203b5
URL: https://github.com/llvm/llvm-project/commit/055a77bb291a8df8a8be1084472984e80cf203b5
DIFF: https://github.com/llvm/llvm-project/commit/055a77bb291a8df8a8be1084472984e80cf203b5.diff
LOG: [libc] Add missing MPFR-based tests for f16 and bf16 math functions (#218281)
Fixes #218219
Added:
libc/test/src/math/ceilbf16_test.cpp
libc/test/src/math/fabsbf16_test.cpp
libc/test/src/math/fabsf16_test.cpp
libc/test/src/math/floorbf16_test.cpp
libc/test/src/math/frexpbf16_test.cpp
libc/test/src/math/frexpf16_test.cpp
libc/test/src/math/remquobf16_test.cpp
libc/test/src/math/remquof16_test.cpp
libc/test/src/math/roundbf16_test.cpp
libc/test/src/math/roundevenbf16_test.cpp
libc/test/src/math/truncbf16_test.cpp
Modified:
libc/test/src/math/CMakeLists.txt
libc/test/src/math/CeilTest.h
libc/test/src/math/FloorTest.h
libc/test/src/math/RemQuoTest.h
libc/test/src/math/TruncTest.h
libc/utils/MPFRWrapper/MPFRUtils.cpp
utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
Removed:
libc/test/src/math/generic/CMakeLists.txt
################################################################################
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 0b31146d2b821..8f1a543de0a5e 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -318,6 +318,35 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ fabsf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ fabsf16_test.cpp
+ HDRS
+ FAbsTest.h
+ DEPENDS
+ libc.src.math.fabsf16
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ fabsbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ fabsbf16_test.cpp
+ HDRS
+ FAbsTest.h
+ DEPENDS
+ libc.src.math.fabsbf16
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
fabsl_test
NEED_MPFR
@@ -435,6 +464,22 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ truncbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ truncbf16_test.cpp
+ HDRS
+ TruncTest.h
+ DEPENDS
+ libc.src.math.truncbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
ceil_test
NEED_MPFR
@@ -511,6 +556,22 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ ceilbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ ceilbf16_test.cpp
+ HDRS
+ CeilTest.h
+ DEPENDS
+ libc.src.math.ceilbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
floor_test
NEED_MPFR
@@ -587,6 +648,22 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ floorbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ floorbf16_test.cpp
+ HDRS
+ FloorTest.h
+ DEPENDS
+ libc.src.math.floorbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
round_test
NEED_MPFR
@@ -647,6 +724,22 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ roundbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ roundbf16_test.cpp
+ HDRS
+ RoundTest.h
+ DEPENDS
+ libc.src.math.roundbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
roundf128_test
NEED_MPFR_F128
@@ -722,6 +815,22 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ roundevenbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ roundevenbf16_test.cpp
+ HDRS
+ RoundEvenTest.h
+ DEPENDS
+ libc.src.math.roundevenbf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
lround_test
NEED_MPFR
@@ -1478,6 +1587,35 @@ add_fp_unittest(
libc.src.__support.FPUtil.basic_operations
)
+add_fp_unittest(
+ frexpf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ frexpf16_test.cpp
+ HDRS
+ FrexpTest.h
+ DEPENDS
+ libc.src.math.frexpf16
+ libc.src.__support.FPUtil.basic_operations
+)
+
+add_fp_unittest(
+ frexpbf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ frexpbf16_test.cpp
+ HDRS
+ FrexpTest.h
+ DEPENDS
+ libc.src.math.frexpbf16
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.FPUtil.bfloat16
+)
+
add_fp_unittest(
frexpl_test
NEED_MPFR
@@ -1937,10 +2075,44 @@ add_fp_unittest(
RemQuoTest.h
DEPENDS
libc.src.math.remquof
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ remquof16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ remquof16_test.cpp
+ HDRS
+ RemQuoTest.h
+ DEPENDS
+ libc.src.math.remquof16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ remquobf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ remquobf16_test.cpp
+ HDRS
+ RemQuoTest.h
+ DEPENDS
+ libc.src.math.remquobf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
remquo_test
NEED_MPFR
@@ -1952,6 +2124,7 @@ add_fp_unittest(
RemQuoTest.h
DEPENDS
libc.src.math.remquo
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.fp_bits
)
@@ -1967,6 +2140,7 @@ add_fp_unittest(
RemQuoTest.h
DEPENDS
libc.src.math.remquol
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.basic_operations
libc.src.__support.FPUtil.fp_bits
)
@@ -3748,7 +3922,6 @@ add_fp_unittest(
libc.src.__support.FPUtil.bfloat16
)
-add_subdirectory(generic)
add_subdirectory(smoke)
if(NOT LLVM_LIBC_FULL_BUILD)
diff --git a/libc/test/src/math/CeilTest.h b/libc/test/src/math/CeilTest.h
index d30bd200b02ba..3856695d9f732 100644
--- a/libc/test/src/math/CeilTest.h
+++ b/libc/test/src/math/CeilTest.h
@@ -27,48 +27,6 @@ class CeilTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
public:
typedef T (*CeilFunc)(T);
- void testSpecialNumbers(CeilFunc func) {
- EXPECT_FP_EQ(zero, func(zero));
- EXPECT_FP_EQ(neg_zero, func(neg_zero));
-
- EXPECT_FP_EQ(inf, func(inf));
- EXPECT_FP_EQ(neg_inf, func(neg_inf));
-
- EXPECT_FP_EQ(aNaN, func(aNaN));
- }
-
- void testRoundedNumbers(CeilFunc func) {
- EXPECT_FP_EQ(T(1.0), func(T(1.0)));
- EXPECT_FP_EQ(T(-1.0), func(T(-1.0)));
- EXPECT_FP_EQ(T(10.0), func(T(10.0)));
- EXPECT_FP_EQ(T(-10.0), func(T(-10.0)));
- EXPECT_FP_EQ(T(1234.0), func(T(1234.0)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0)));
- }
-
- void testFractions(CeilFunc func) {
- EXPECT_FP_EQ(T(1.0), func(T(0.5)));
- EXPECT_FP_EQ(T(-0.0), func(T(-0.5)));
- EXPECT_FP_EQ(T(1.0), func(T(0.115)));
- EXPECT_FP_EQ(T(-0.0), func(T(-0.115)));
- EXPECT_FP_EQ(T(1.0), func(T(0.715)));
- EXPECT_FP_EQ(T(-0.0), func(T(-0.715)));
- EXPECT_FP_EQ(T(2.0), func(T(1.3)));
- EXPECT_FP_EQ(T(-1.0), func(T(-1.3)));
- EXPECT_FP_EQ(T(2.0), func(T(1.5)));
- EXPECT_FP_EQ(T(-1.0), func(T(-1.5)));
- EXPECT_FP_EQ(T(2.0), func(T(1.75)));
- EXPECT_FP_EQ(T(-1.0), func(T(-1.75)));
- EXPECT_FP_EQ(T(11.0), func(T(10.32)));
- 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(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)));
- }
-
void testRange(CeilFunc func) {
constexpr int COUNT = 1'231;
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
@@ -87,9 +45,6 @@ class CeilTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
#define LIST_CEIL_TESTS(T, func) \
using LlvmLibcCeilTest = CeilTest<T>; \
- TEST_F(LlvmLibcCeilTest, SpecialNumbers) { testSpecialNumbers(&func); } \
- TEST_F(LlvmLibcCeilTest, RoundedNubmers) { testRoundedNumbers(&func); } \
- TEST_F(LlvmLibcCeilTest, Fractions) { testFractions(&func); } \
TEST_F(LlvmLibcCeilTest, Range) { testRange(&func); }
#endif // LLVM_LIBC_TEST_SRC_MATH_CEILTEST_H
diff --git a/libc/test/src/math/FloorTest.h b/libc/test/src/math/FloorTest.h
index 0ac31c0306cfa..28c16f4421fa6 100644
--- a/libc/test/src/math/FloorTest.h
+++ b/libc/test/src/math/FloorTest.h
@@ -27,48 +27,6 @@ class FloorTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
public:
typedef T (*FloorFunc)(T);
- void testSpecialNumbers(FloorFunc func) {
- EXPECT_FP_EQ(zero, func(zero));
- EXPECT_FP_EQ(neg_zero, func(neg_zero));
-
- EXPECT_FP_EQ(inf, func(inf));
- EXPECT_FP_EQ(neg_inf, func(neg_inf));
-
- EXPECT_FP_EQ(aNaN, func(aNaN));
- }
-
- void testRoundedNumbers(FloorFunc func) {
- EXPECT_FP_EQ(T(1.0), func(T(1.0)));
- EXPECT_FP_EQ(T(-1.0), func(T(-1.0)));
- EXPECT_FP_EQ(T(10.0), func(T(10.0)));
- EXPECT_FP_EQ(T(-10.0), func(T(-10.0)));
- EXPECT_FP_EQ(T(1234.0), func(T(1234.0)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0)));
- }
-
- void testFractions(FloorFunc func) {
- EXPECT_FP_EQ(T(0.0), func(T(0.5)));
- EXPECT_FP_EQ(T(-1.0), func(T(-0.5)));
- EXPECT_FP_EQ(T(0.0), func(T(0.115)));
- EXPECT_FP_EQ(T(-1.0), func(T(-0.115)));
- EXPECT_FP_EQ(T(0.0), func(T(0.715)));
- EXPECT_FP_EQ(T(-1.0), func(T(-0.715)));
- EXPECT_FP_EQ(T(1.0), func(T(1.3)));
- EXPECT_FP_EQ(T(-2.0), func(T(-1.3)));
- EXPECT_FP_EQ(T(1.0), func(T(1.5)));
- EXPECT_FP_EQ(T(-2.0), func(T(-1.5)));
- EXPECT_FP_EQ(T(1.0), func(T(1.75)));
- EXPECT_FP_EQ(T(-2.0), func(T(-1.75)));
- EXPECT_FP_EQ(T(10.0), func(T(10.32)));
- 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(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)));
- }
-
void testRange(FloorFunc func) {
constexpr int COUNT = 1'231;
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
@@ -87,9 +45,6 @@ class FloorTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
#define LIST_FLOOR_TESTS(T, func) \
using LlvmLibcFloorTest = FloorTest<T>; \
- TEST_F(LlvmLibcFloorTest, SpecialNumbers) { testSpecialNumbers(&func); } \
- TEST_F(LlvmLibcFloorTest, RoundedNubmers) { testRoundedNumbers(&func); } \
- TEST_F(LlvmLibcFloorTest, Fractions) { testFractions(&func); } \
TEST_F(LlvmLibcFloorTest, Range) { testRange(&func); }
#endif // LLVM_LIBC_TEST_SRC_MATH_FLOORTEST_H
diff --git a/libc/test/src/math/RemQuoTest.h b/libc/test/src/math/RemQuoTest.h
index 40b4ce748fa6b..4e135ce7cc4f6 100644
--- a/libc/test/src/math/RemQuoTest.h
+++ b/libc/test/src/math/RemQuoTest.h
@@ -10,6 +10,7 @@
#define LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H
#include "hdr/math_macros.h"
+#include "src/__support/CPP/algorithm.h"
#include "src/__support/FPUtil/BasicOperations.h"
#include "src/__support/FPUtil/FPBits.h"
#include "test/UnitTest/FEnvSafeTest.h"
@@ -105,7 +106,9 @@ class RemQuoTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
void testSubnormalRange(RemQuoFunc func) {
constexpr StorageType COUNT = 1'231;
- constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
+ StorageType(1));
for (StorageType v = MIN_SUBNORMAL, w = MAX_SUBNORMAL;
v <= MAX_SUBNORMAL && w >= MIN_SUBNORMAL; v += STEP, w -= STEP) {
T x = FPBits(v).get_val(), y = FPBits(w).get_val();
diff --git a/libc/test/src/math/TruncTest.h b/libc/test/src/math/TruncTest.h
index db0f19c83265f..2e1c2f64c07db 100644
--- a/libc/test/src/math/TruncTest.h
+++ b/libc/test/src/math/TruncTest.h
@@ -27,48 +27,6 @@ class TruncTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
public:
typedef T (*TruncFunc)(T);
- void testSpecialNumbers(TruncFunc func) {
- EXPECT_FP_EQ(zero, func(zero));
- EXPECT_FP_EQ(neg_zero, func(neg_zero));
-
- EXPECT_FP_EQ(inf, func(inf));
- EXPECT_FP_EQ(neg_inf, func(neg_inf));
-
- EXPECT_FP_EQ(aNaN, func(aNaN));
- }
-
- void testRoundedNumbers(TruncFunc func) {
- EXPECT_FP_EQ(T(1.0), func(T(1.0)));
- EXPECT_FP_EQ(T(-1.0), func(T(-1.0)));
- EXPECT_FP_EQ(T(10.0), func(T(10.0)));
- EXPECT_FP_EQ(T(-10.0), func(T(-10.0)));
- EXPECT_FP_EQ(T(1234.0), func(T(1234.0)));
- EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0)));
- }
-
- void testFractions(TruncFunc func) {
- EXPECT_FP_EQ(T(0.0), func(T(0.5)));
- EXPECT_FP_EQ(T(-0.0), func(T(-0.5)));
- EXPECT_FP_EQ(T(0.0), func(T(0.115)));
- EXPECT_FP_EQ(T(-0.0), func(T(-0.115)));
- EXPECT_FP_EQ(T(0.0), func(T(0.715)));
- EXPECT_FP_EQ(T(-0.0), func(T(-0.715)));
- EXPECT_FP_EQ(T(1.0), func(T(1.3)));
- EXPECT_FP_EQ(T(-1.0), func(T(-1.3)));
- EXPECT_FP_EQ(T(1.0), func(T(1.5)));
- EXPECT_FP_EQ(T(-1.0), func(T(-1.5)));
- EXPECT_FP_EQ(T(1.0), func(T(1.75)));
- EXPECT_FP_EQ(T(-1.0), func(T(-1.75)));
- EXPECT_FP_EQ(T(10.0), func(T(10.32)));
- 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(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)));
- }
-
void testRange(TruncFunc func) {
constexpr int COUNT = 1'231;
constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
@@ -87,9 +45,6 @@ class TruncTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
#define LIST_TRUNC_TESTS(T, func) \
using LlvmLibcTruncTest = TruncTest<T>; \
- TEST_F(LlvmLibcTruncTest, SpecialNumbers) { testSpecialNumbers(&func); } \
- TEST_F(LlvmLibcTruncTest, RoundedNubmers) { testRoundedNumbers(&func); } \
- TEST_F(LlvmLibcTruncTest, Fractions) { testFractions(&func); } \
TEST_F(LlvmLibcTruncTest, Range) { testRange(&func); }
#endif // LLVM_LIBC_TEST_SRC_MATH_TRUNCTEST_H
diff --git a/libc/test/src/math/ceilbf16_test.cpp b/libc/test/src/math/ceilbf16_test.cpp
new file mode 100644
index 0000000000000..3cbd9de0a611e
--- /dev/null
+++ b/libc/test/src/math/ceilbf16_test.cpp
@@ -0,0 +1,19 @@
+//===-- 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for ceilbf16
+///
+//===----------------------------------------------------------------------===//
+
+#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/fabsbf16_test.cpp b/libc/test/src/math/fabsbf16_test.cpp
new file mode 100644
index 0000000000000..2ac14763b7c41
--- /dev/null
+++ b/libc/test/src/math/fabsbf16_test.cpp
@@ -0,0 +1,19 @@
+//===-- Unittests for fabsbf16 --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for fabsbf16
+///
+//===----------------------------------------------------------------------===//
+
+#include "FAbsTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/fabsbf16.h"
+
+LIST_FABS_TESTS(bfloat16, LIBC_NAMESPACE::fabsbf16)
diff --git a/libc/test/src/math/fabsf16_test.cpp b/libc/test/src/math/fabsf16_test.cpp
new file mode 100644
index 0000000000000..cf6b8f5e7a3cd
--- /dev/null
+++ b/libc/test/src/math/fabsf16_test.cpp
@@ -0,0 +1,18 @@
+//===-- Unittests for fabsf16 ---------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for fabsf16
+///
+//===----------------------------------------------------------------------===//
+
+#include "FAbsTest.h"
+
+#include "src/math/fabsf16.h"
+
+LIST_FABS_TESTS(float16, LIBC_NAMESPACE::fabsf16)
diff --git a/libc/test/src/math/floorbf16_test.cpp b/libc/test/src/math/floorbf16_test.cpp
new file mode 100644
index 0000000000000..d11ca17dad74c
--- /dev/null
+++ b/libc/test/src/math/floorbf16_test.cpp
@@ -0,0 +1,19 @@
+//===-- 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for floorbf16
+///
+//===----------------------------------------------------------------------===//
+
+#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/frexpbf16_test.cpp b/libc/test/src/math/frexpbf16_test.cpp
new file mode 100644
index 0000000000000..913e3ac097c4d
--- /dev/null
+++ b/libc/test/src/math/frexpbf16_test.cpp
@@ -0,0 +1,19 @@
+//===-- Unittests for frexpbf16 -------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for frexpbf16
+///
+//===----------------------------------------------------------------------===//
+
+#include "FrexpTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/frexpbf16.h"
+
+LIST_FREXP_TESTS(bfloat16, LIBC_NAMESPACE::frexpbf16)
diff --git a/libc/test/src/math/frexpf16_test.cpp b/libc/test/src/math/frexpf16_test.cpp
new file mode 100644
index 0000000000000..6a31033949910
--- /dev/null
+++ b/libc/test/src/math/frexpf16_test.cpp
@@ -0,0 +1,18 @@
+//===-- Unittests for frexpf16 --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for frexpf16
+///
+//===----------------------------------------------------------------------===//
+
+#include "FrexpTest.h"
+
+#include "src/math/frexpf16.h"
+
+LIST_FREXP_TESTS(float16, LIBC_NAMESPACE::frexpf16)
diff --git a/libc/test/src/math/generic/CMakeLists.txt b/libc/test/src/math/generic/CMakeLists.txt
deleted file mode 100644
index a9d54d6424294..0000000000000
--- a/libc/test/src/math/generic/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-add_fp_unittest(
- ceil_test
- NEED_MPFR
- SUITE
- libc-math-unittests
- SRCS
- ../ceil_test.cpp
- DEPENDS
- libc.src.math.generic.ceil
-)
-
-add_fp_unittest(
- ceilf_test
- NEED_MPFR
- SUITE
- libc-math-unittests
- SRCS
- ../ceilf_test.cpp
- DEPENDS
- libc.src.math.generic.ceilf
-)
-
-add_fp_unittest(
- ceill_test
- NEED_MPFR
- SUITE
- libc-math-unittests
- SRCS
- ../ceill_test.cpp
- DEPENDS
- libc.src.math.generic.ceill
-)
diff --git a/libc/test/src/math/remquobf16_test.cpp b/libc/test/src/math/remquobf16_test.cpp
new file mode 100644
index 0000000000000..2c5ad5a7e2770
--- /dev/null
+++ b/libc/test/src/math/remquobf16_test.cpp
@@ -0,0 +1,19 @@
+//===-- Unittests for remquobf16 ------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for remquobf16
+///
+//===----------------------------------------------------------------------===//
+
+#include "RemQuoTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/remquobf16.h"
+
+LIST_REMQUO_TESTS(bfloat16, LIBC_NAMESPACE::remquobf16)
diff --git a/libc/test/src/math/remquof16_test.cpp b/libc/test/src/math/remquof16_test.cpp
new file mode 100644
index 0000000000000..33b98fa3d38e1
--- /dev/null
+++ b/libc/test/src/math/remquof16_test.cpp
@@ -0,0 +1,18 @@
+//===-- Unittests for remquof16 -------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for remquof16
+///
+//===----------------------------------------------------------------------===//
+
+#include "RemQuoTest.h"
+
+#include "src/math/remquof16.h"
+
+LIST_REMQUO_TESTS(float16, LIBC_NAMESPACE::remquof16)
diff --git a/libc/test/src/math/roundbf16_test.cpp b/libc/test/src/math/roundbf16_test.cpp
new file mode 100644
index 0000000000000..2ee44fdbcc505
--- /dev/null
+++ b/libc/test/src/math/roundbf16_test.cpp
@@ -0,0 +1,19 @@
+//===-- 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for roundbf16
+///
+//===----------------------------------------------------------------------===//
+
+#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/roundevenbf16_test.cpp b/libc/test/src/math/roundevenbf16_test.cpp
new file mode 100644
index 0000000000000..ad73ee518fead
--- /dev/null
+++ b/libc/test/src/math/roundevenbf16_test.cpp
@@ -0,0 +1,19 @@
+//===-- 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for roundevenbf16
+///
+//===----------------------------------------------------------------------===//
+
+#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/truncbf16_test.cpp b/libc/test/src/math/truncbf16_test.cpp
new file mode 100644
index 0000000000000..398185208947b
--- /dev/null
+++ b/libc/test/src/math/truncbf16_test.cpp
@@ -0,0 +1,19 @@
+//===-- 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains tests for truncbf16
+///
+//===----------------------------------------------------------------------===//
+
+#include "TruncTest.h"
+
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/truncbf16.h"
+
+LIST_TRUNC_TESTS(bfloat16, LIBC_NAMESPACE::truncbf16)
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index bc32b11466e5a..83500cb59de9d 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -332,6 +332,12 @@ template void explain_unary_operation_two_outputs_error<double>(
template void explain_unary_operation_two_outputs_error<long double>(
Operation, long double, const BinaryOutput<long double> &, double,
RoundingMode);
+#ifdef LIBC_TYPES_HAS_FLOAT16
+template void explain_unary_operation_two_outputs_error<float16>(
+ Operation, float16, const BinaryOutput<float16> &, double, RoundingMode);
+#endif
+template void explain_unary_operation_two_outputs_error<bfloat16>(
+ Operation, bfloat16, const BinaryOutput<bfloat16> &, double, RoundingMode);
template <typename T>
void explain_binary_operation_two_outputs_error(
@@ -368,6 +374,14 @@ template void explain_binary_operation_two_outputs_error<double>(
template void explain_binary_operation_two_outputs_error<long double>(
Operation, const BinaryInput<long double> &,
const BinaryOutput<long double> &, double, RoundingMode);
+#ifdef LIBC_TYPES_HAS_FLOAT16
+template void explain_binary_operation_two_outputs_error<float16>(
+ Operation, const BinaryInput<float16> &, const BinaryOutput<float16> &,
+ double, RoundingMode);
+#endif
+template void explain_binary_operation_two_outputs_error<bfloat16>(
+ Operation, const BinaryInput<bfloat16> &, const BinaryOutput<bfloat16> &,
+ double, RoundingMode);
template <typename InputType, typename OutputType>
void explain_binary_operation_one_output_error(
@@ -605,6 +619,12 @@ template bool compare_unary_operation_two_outputs<double>(
template bool compare_unary_operation_two_outputs<long double>(
Operation, long double, const BinaryOutput<long double> &, double,
RoundingMode);
+#ifdef LIBC_TYPES_HAS_FLOAT16
+template bool compare_unary_operation_two_outputs<float16>(
+ Operation, float16, const BinaryOutput<float16> &, double, RoundingMode);
+#endif
+template bool compare_unary_operation_two_outputs<bfloat16>(
+ Operation, bfloat16, const BinaryOutput<bfloat16> &, double, RoundingMode);
template <typename T>
bool compare_binary_operation_two_outputs(Operation op,
@@ -639,6 +659,14 @@ template bool compare_binary_operation_two_outputs<double>(
template bool compare_binary_operation_two_outputs<long double>(
Operation, const BinaryInput<long double> &,
const BinaryOutput<long double> &, double, RoundingMode);
+#ifdef LIBC_TYPES_HAS_FLOAT16
+template bool compare_binary_operation_two_outputs<float16>(
+ Operation, const BinaryInput<float16> &, const BinaryOutput<float16> &,
+ double, RoundingMode);
+#endif
+template bool compare_binary_operation_two_outputs<bfloat16>(
+ Operation, const BinaryInput<bfloat16> &, const BinaryOutput<bfloat16> &,
+ double, RoundingMode);
template <typename InputType, typename OutputType>
bool compare_binary_operation_one_output(Operation op,
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
index 601db61b6a6fc..d8914aa3b8ec7 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel
@@ -59,6 +59,12 @@ math_mpfr_test(
hdrs = ["CeilTest.h"],
)
+math_mpfr_test(
+ name = "ceilbf16",
+ hdrs = ["CeilTest.h"],
+ deps = ["//libc:__support_fputil_bfloat16"],
+)
+
math_mpfr_test(
name = "ceilf128",
hdrs = ["CeilTest.h"],
@@ -149,6 +155,17 @@ math_mpfr_test(
hdrs = ["FAbsTest.h"],
)
+math_mpfr_test(
+ name = "fabsf16",
+ hdrs = ["FAbsTest.h"],
+)
+
+math_mpfr_test(
+ name = "fabsbf16",
+ hdrs = ["FAbsTest.h"],
+ deps = ["//libc:__support_fputil_bfloat16"],
+)
+
math_mpfr_test(
name = "fabsl",
hdrs = ["FAbsTest.h"],
@@ -226,6 +243,12 @@ math_mpfr_test(
hdrs = ["FloorTest.h"],
)
+math_mpfr_test(
+ name = "floorbf16",
+ hdrs = ["FloorTest.h"],
+ deps = ["//libc:__support_fputil_bfloat16"],
+)
+
# TODO: Add fma, fmaf, fmal, fmul, fmull tests. Missing stdlib/rand dependency.
# math_mpfr_test(name = "f16mul")
@@ -246,6 +269,17 @@ math_mpfr_test(
hdrs = ["FrexpTest.h"],
)
+math_mpfr_test(
+ name = "frexpf16",
+ hdrs = ["FrexpTest.h"],
+)
+
+math_mpfr_test(
+ name = "frexpbf16",
+ hdrs = ["FrexpTest.h"],
+ deps = ["//libc:__support_fputil_bfloat16"],
+)
+
math_mpfr_test(
name = "frexpl",
hdrs = ["FrexpTest.h"],
@@ -450,6 +484,17 @@ math_mpfr_test(
hdrs = ["RemQuoTest.h"],
)
+math_mpfr_test(
+ name = "remquof16",
+ hdrs = ["RemQuoTest.h"],
+)
+
+math_mpfr_test(
+ name = "remquobf16",
+ hdrs = ["RemQuoTest.h"],
+ deps = ["//libc:__support_fputil_bfloat16"],
+)
+
math_mpfr_test(
name = "remquol",
hdrs = ["RemQuoTest.h"],
@@ -495,6 +540,12 @@ math_mpfr_test(
hdrs = ["RoundEvenTest.h"],
)
+math_mpfr_test(
+ name = "roundevenbf16",
+ hdrs = ["RoundEvenTest.h"],
+ deps = ["//libc:__support_fputil_bfloat16"],
+)
+
math_mpfr_test(
name = "round",
hdrs = ["RoundTest.h"],
@@ -505,6 +556,12 @@ math_mpfr_test(
hdrs = ["RoundTest.h"],
)
+math_mpfr_test(
+ name = "roundbf16",
+ hdrs = ["RoundTest.h"],
+ deps = ["//libc:__support_fputil_bfloat16"],
+)
+
math_mpfr_test(
name = "roundl",
hdrs = ["RoundTest.h"],
@@ -635,6 +692,12 @@ math_mpfr_test(
hdrs = ["TruncTest.h"],
)
+math_mpfr_test(
+ name = "truncbf16",
+ hdrs = ["TruncTest.h"],
+ deps = ["//libc:__support_fputil_bfloat16"],
+)
+
math_mpfr_test(name = "cbrtf16")
math_mpfr_test(name = "cosf16")
More information about the libc-commits
mailing list