aboutsummaryrefslogtreecommitdiff
path: root/libc/test
diff options
context:
space:
mode:
authorOverMighty <its.overmighty@gmail.com>2024-06-10 23:30:18 +0200
committerGitHub <noreply@github.com>2024-06-10 17:30:18 -0400
commitf50656c50938781fdfdabe05c9225783ce7e409d (patch)
treec69656577ecea2903d7da64130451f50fef47b3c /libc/test
parent0babff96759d2fa91af2dcab7564b6f08954e8fa (diff)
downloadllvm-f50656c50938781fdfdabe05c9225783ce7e409d.zip
llvm-f50656c50938781fdfdabe05c9225783ce7e409d.tar.gz
llvm-f50656c50938781fdfdabe05c9225783ce7e409d.tar.bz2
[libc][math][c23] Add MPFR unit tests for {rint,lrint,llrint,lround,llround}f16 (#94473)
Diffstat (limited to 'libc/test')
-rw-r--r--libc/test/src/math/CMakeLists.txt133
-rw-r--r--libc/test/src/math/RIntTest.h20
-rw-r--r--libc/test/src/math/RoundToIntegerTest.h29
-rw-r--r--libc/test/src/math/llrintf16_test.cpp14
-rw-r--r--libc/test/src/math/llroundf16_test.cpp13
-rw-r--r--libc/test/src/math/lrintf16_test.cpp13
-rw-r--r--libc/test/src/math/lroundf16_test.cpp13
-rw-r--r--libc/test/src/math/rintf16_test.cpp13
8 files changed, 213 insertions, 35 deletions
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index e4a3087..79e6e89 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -440,11 +440,11 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.hdr.fenv_macros
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.lround
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -458,11 +458,11 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.hdr.fenv_macros
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.lroundf
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -476,11 +476,29 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.hdr.fenv_macros
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.lroundl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ lroundf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ lroundf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.errno.errno
+ libc.src.math.lroundf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -494,11 +512,11 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.hdr.fenv_macros
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.llround
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -512,11 +530,11 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.hdr.fenv_macros
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.llroundf
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -530,11 +548,29 @@ add_fp_unittest(
HDRS
RoundToIntegerTest.h
DEPENDS
+ libc.hdr.fenv_macros
libc.src.errno.errno
- libc.src.fenv.feclearexcept
- libc.src.fenv.feraiseexcept
- libc.src.fenv.fetestexcept
libc.src.math.llroundl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ llroundf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ llroundf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.errno.errno
+ libc.src.math.llroundf16
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -548,7 +584,9 @@ add_fp_unittest(
HDRS
RIntTest.h
DEPENDS
+ libc.hdr.fenv_macros
libc.src.math.rint
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -563,7 +601,9 @@ add_fp_unittest(
HDRS
RIntTest.h
DEPENDS
+ libc.hdr.fenv_macros
libc.src.math.rintf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -578,7 +618,26 @@ add_fp_unittest(
HDRS
RIntTest.h
DEPENDS
+ libc.hdr.fenv_macros
libc.src.math.rintl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ rintf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ rintf16_test.cpp
+ HDRS
+ RIntTest.h
+ DEPENDS
+ libc.hdr.fenv_macros
+ libc.src.math.rintf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -594,6 +653,7 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.math.lrint
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -609,6 +669,7 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.math.lrintf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -624,6 +685,23 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.math.lrintl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ lrintf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ lrintf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.math.lrintf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -639,6 +717,7 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.math.llrint
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -654,6 +733,7 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.math.llrintf
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
@@ -669,6 +749,23 @@ add_fp_unittest(
RoundToIntegerTest.h
DEPENDS
libc.src.math.llrintl
+ libc.src.__support.CPP.algorithm
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ llrintf16_test
+ NEED_MPFR
+ SUITE
+ libc-math-unittests
+ SRCS
+ llrintf16_test.cpp
+ HDRS
+ RoundToIntegerTest.h
+ DEPENDS
+ libc.src.math.llrintf16
+ libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
)
diff --git a/libc/test/src/math/RIntTest.h b/libc/test/src/math/RIntTest.h
index 007b504..d31bf74 100644
--- a/libc/test/src/math/RIntTest.h
+++ b/libc/test/src/math/RIntTest.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_RINTTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_RINTTEST_H
+#include "src/__support/CPP/algorithm.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "test/UnitTest/FEnvSafeTest.h"
@@ -18,7 +19,6 @@
#include "hdr/fenv_macros.h"
#include "hdr/math_macros.h"
-#include <stdio.h>
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
@@ -101,8 +101,10 @@ public:
}
void testSubnormalRange(RIntFunc func) {
- constexpr StorageType COUNT = 100'001;
- constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
+ constexpr int COUNT = 100'001;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
+ StorageType(1));
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
T x = FPBits(i).get_val();
for (int mode : ROUNDING_MODES) {
@@ -114,15 +116,17 @@ public:
}
void testNormalRange(RIntFunc func) {
- constexpr StorageType COUNT = 100'001;
- constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
+ constexpr int COUNT = 100'001;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>((MAX_NORMAL - MIN_NORMAL) / COUNT),
+ StorageType(1));
for (StorageType i = MIN_NORMAL; i <= MAX_NORMAL; i += STEP) {
- T x = FPBits(i).get_val();
+ FPBits xbits(i);
+ T x = xbits.get_val();
// In normal range on x86 platforms, the long double implicit 1 bit can be
// zero making the numbers NaN. We will skip them.
- if (isnan(x)) {
+ if (xbits.is_nan())
continue;
- }
for (int mode : ROUNDING_MODES) {
LIBC_NAMESPACE::fputil::set_round(mode);
diff --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h
index d40e150..bb7e8643 100644
--- a/libc/test/src/math/RoundToIntegerTest.h
+++ b/libc/test/src/math/RoundToIntegerTest.h
@@ -9,6 +9,7 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
+#include "src/__support/CPP/algorithm.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "test/UnitTest/FEnvSafeTest.h"
@@ -136,10 +137,13 @@ public:
return;
constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
+ constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
+ if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
+ return;
// We start with 1.0 so that the implicit bit for x86 long doubles
// is set.
FPBits bits(F(1.0));
- bits.set_biased_exponent(EXPONENT_LIMIT + FPBits::EXP_BIAS);
+ bits.set_biased_exponent(BIASED_EXPONENT_LIMIT);
bits.set_sign(Sign::NEG);
bits.set_mantissa(0);
@@ -200,10 +204,13 @@ public:
return;
constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
+ constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
+ if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
+ return;
// We start with 1.0 so that the implicit bit for x86 long doubles
// is set.
FPBits bits(F(1.0));
- bits.set_biased_exponent(EXPONENT_LIMIT + FPBits::EXP_BIAS);
+ bits.set_biased_exponent(BIASED_EXPONENT_LIMIT);
bits.set_sign(Sign::NEG);
bits.set_mantissa(FPBits::FRACTION_MASK);
@@ -226,8 +233,10 @@ public:
}
void testSubnormalRange(RoundToIntegerFunc func) {
- constexpr StorageType COUNT = 1'000'001;
- constexpr StorageType STEP = (MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT;
+ constexpr int COUNT = 1'000'001;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
+ StorageType(1));
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
F x = FPBits(i).get_val();
if (x == F(0.0))
@@ -268,15 +277,17 @@ public:
if (sizeof(I) > sizeof(long))
return;
- constexpr StorageType COUNT = 1'000'001;
- constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT;
+ constexpr int COUNT = 1'000'001;
+ constexpr StorageType STEP = LIBC_NAMESPACE::cpp::max(
+ static_cast<StorageType>((MAX_NORMAL - MIN_NORMAL) / COUNT),
+ StorageType(1));
for (StorageType i = MIN_NORMAL; i <= MAX_NORMAL; i += STEP) {
- F x = FPBits(i).get_val();
+ FPBits xbits(i);
+ F x = xbits.get_val();
// In normal range on x86 platforms, the long double implicit 1 bit can be
// zero making the numbers NaN. We will skip them.
- if (isnan(x)) {
+ if (xbits.is_nan())
continue;
- }
if (TestModes) {
for (int m : ROUNDING_MODES) {
diff --git a/libc/test/src/math/llrintf16_test.cpp b/libc/test/src/math/llrintf16_test.cpp
new file mode 100644
index 0000000..d16bd8f
--- /dev/null
+++ b/libc/test/src/math/llrintf16_test.cpp
@@ -0,0 +1,14 @@
+//===-- Unittests for llrintf16 -------------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/math/llrintf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float16, long long,
+ LIBC_NAMESPACE::llrintf16)
diff --git a/libc/test/src/math/llroundf16_test.cpp b/libc/test/src/math/llroundf16_test.cpp
new file mode 100644
index 0000000..9342b24
--- /dev/null
+++ b/libc/test/src/math/llroundf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for llroundf16 ------------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/math/llroundf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(float16, long long, LIBC_NAMESPACE::llroundf16)
diff --git a/libc/test/src/math/lrintf16_test.cpp b/libc/test/src/math/lrintf16_test.cpp
new file mode 100644
index 0000000..28b1a1c
--- /dev/null
+++ b/libc/test/src/math/lrintf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for lrintf16 --------------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/math/lrintf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(float16, long, LIBC_NAMESPACE::lrintf16)
diff --git a/libc/test/src/math/lroundf16_test.cpp b/libc/test/src/math/lroundf16_test.cpp
new file mode 100644
index 0000000..3077134
--- /dev/null
+++ b/libc/test/src/math/lroundf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for lroundf16 -------------------------------------------===//
+//
+// 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 "RoundToIntegerTest.h"
+
+#include "src/math/lroundf16.h"
+
+LIST_ROUND_TO_INTEGER_TESTS(float16, long, LIBC_NAMESPACE::lroundf16)
diff --git a/libc/test/src/math/rintf16_test.cpp b/libc/test/src/math/rintf16_test.cpp
new file mode 100644
index 0000000..2adf256
--- /dev/null
+++ b/libc/test/src/math/rintf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for rintf16 ---------------------------------------------===//
+//
+// 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 "RIntTest.h"
+
+#include "src/math/rintf16.h"
+
+LIST_RINT_TESTS(float16, LIBC_NAMESPACE::rintf16)