diff options
Diffstat (limited to 'libc/test/src')
155 files changed, 4417 insertions, 353 deletions
diff --git a/libc/test/src/__support/File/file_test.cpp b/libc/test/src/__support/File/file_test.cpp index b3c9f2b..17dad4d 100644 --- a/libc/test/src/__support/File/file_test.cpp +++ b/libc/test/src/__support/File/file_test.cpp @@ -493,3 +493,22 @@ TEST(LlvmLibcFileTest, WriteNothing) { ASSERT_EQ(f_lbf->close(), 0); ASSERT_EQ(f_nbf->close(), 0); } + +TEST(LlvmLibcFileTest, WriteSplit) { + constexpr size_t FILE_BUFFER_SIZE = 8; + char file_buffer[FILE_BUFFER_SIZE]; + StringFile *f = + new_string_file(file_buffer, FILE_BUFFER_SIZE, _IOFBF, false, "w"); + + static constexpr size_t AVAIL = 12; + f->seek(-AVAIL, SEEK_END); + + const char data[] = "hello"; + ASSERT_EQ(sizeof(data) - 1, f->write(data, sizeof(data) - 1).value); + + const char data2[] = " extra data"; + static constexpr size_t WR_EXPECTED = AVAIL - (sizeof(data) - 1); + ASSERT_EQ(WR_EXPECTED, f->write(data2, sizeof(data2) - 1).value); + EXPECT_TRUE(f->error()); + ASSERT_EQ(f->close(), 0); +} diff --git a/libc/test/src/__support/OSUtil/linux/vdso_test.cpp b/libc/test/src/__support/OSUtil/linux/vdso_test.cpp index 2f68470..71892a0 100644 --- a/libc/test/src/__support/OSUtil/linux/vdso_test.cpp +++ b/libc/test/src/__support/OSUtil/linux/vdso_test.cpp @@ -110,8 +110,8 @@ TEST(LlvmLibcOSUtilVDSOTest, RtSigReturn) { using namespace testing::ErrnoSetterMatcher; // must use struct since there is a function of the same name in the same // scope. - struct sigaction sa {}; - struct sigaction old_sa {}; + struct sigaction sa{}; + struct sigaction old_sa{}; sa.sa_handler = sigprof_handler; sa.sa_flags = SA_RESTORER; vdso::TypedSymbol<vdso::VDSOSym::RTSigReturn> symbol; @@ -158,4 +158,30 @@ TEST(LlvmLibcOSUtilVDSOTest, RiscvHwProbe) { } } +TEST(LlvmLibcOSUtilVDSOTest, GetRandom) { + using namespace testing::ErrnoSetterMatcher; + vdso::TypedSymbol<vdso::VDSOSym::GetRandom> symbol; + if (!symbol) + return; + // This structure exists in kernel UAPI header; but we define it on our own to + // make sure we can test it even on platform without support. + struct VGetrandomOpaqueParams { + uint32_t size_of_opaque_states; + uint32_t mmap_prot; + uint32_t mmap_flags; + uint32_t reserved[13]; + }; + VGetrandomOpaqueParams param{0, 0, 0, {}}; + // When getrandom vDSO symbol is called with special parameters (~0 for state + // size), it populates the desired configuration into VGetrandomOpaqueParams. + int res = symbol( + /*buf=*/nullptr, /*count=*/0, /*flags=*/0, + /*opaque_states=*/¶m, + /*size_of_opaque_states=*/~0); + // Test that the size of the states are correctly populated after a successful + // call. + EXPECT_EQ(res, 0); + EXPECT_GT(param.size_of_opaque_states, 0u); +} + } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/__support/wchar/string_converter_test.cpp b/libc/test/src/__support/wchar/string_converter_test.cpp index d514df9..e45358d 100644 --- a/libc/test/src/__support/wchar/string_converter_test.cpp +++ b/libc/test/src/__support/wchar/string_converter_test.cpp @@ -34,32 +34,32 @@ TEST(LlvmLibcStringConverterTest, UTF8To32) { LIBC_NAMESPACE::internal::StringConverter<char8_t> sc( reinterpret_cast<const char8_t *>(src), &state, SIZE_MAX); - auto res = sc.popUTF32(); + auto res = sc.pop<char32_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x1f921); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 4); - res = sc.popUTF32(); + res = sc.pop<char32_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x2211); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 7); - res = sc.popUTF32(); + res = sc.pop<char32_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xff); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 9); - res = sc.popUTF32(); + res = sc.pop<char32_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x41); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 10); - res = sc.popUTF32(); + res = sc.pop<char32_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 11); - res = sc.popUTF32(); + res = sc.pop<char32_t>(); ASSERT_FALSE(res.has_value()); ASSERT_EQ(res.error(), -1); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 11); @@ -75,66 +75,66 @@ TEST(LlvmLibcStringConverterTest, UTF32To8) { LIBC_NAMESPACE::internal::StringConverter<char32_t> sc( reinterpret_cast<const char32_t *>(src), &state, SIZE_MAX); - auto res = sc.popUTF8(); + auto res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xF0); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x9F); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xA4); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xA1); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); // end of clown emoji, sigma symbol begins - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xE2); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 2); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x88); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 2); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x91); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 2); // end of sigma symbol, y with diaeresis begins - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xC3); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 3); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xBF); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 3); // end of y with diaeresis, letter A begins - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x41); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 4); // null byte - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 5); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_FALSE(res.has_value()); ASSERT_EQ(res.error(), -1); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 5); @@ -148,28 +148,28 @@ TEST(LlvmLibcStringConverterTest, UTF32To8PartialRead) { LIBC_NAMESPACE::internal::StringConverter<char32_t> sc( reinterpret_cast<const char32_t *>(src), &state, SIZE_MAX, 1); - auto res = sc.popUTF8(); + auto res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xF0); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x9F); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xA4); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xA1); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); // can only read 1 character from source string, so error on next pop - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_FALSE(res.has_value()); ASSERT_EQ(res.error(), -1); } @@ -181,12 +181,12 @@ TEST(LlvmLibcStringConverterTest, UTF8To32PartialRead) { LIBC_NAMESPACE::internal::StringConverter<char8_t> sc( reinterpret_cast<const char8_t *>(src), &state, SIZE_MAX, 5); - auto res = sc.popUTF32(); + auto res = sc.pop<char32_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x1f921); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 4); - res = sc.popUTF32(); + res = sc.pop<char32_t>(); ASSERT_FALSE(res.has_value()); ASSERT_EQ(static_cast<int>(res.error()), -1); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 5); @@ -200,27 +200,27 @@ TEST(LlvmLibcStringConverterTest, UTF32To8ErrorHandling) { LIBC_NAMESPACE::internal::StringConverter<char32_t> sc( reinterpret_cast<const char32_t *>(src), &state, SIZE_MAX); - auto res = sc.popUTF8(); + auto res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xF0); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x9F); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xA4); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xA1); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_FALSE(res.has_value()); ASSERT_EQ(static_cast<int>(res.error()), EILSEQ); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); @@ -234,12 +234,12 @@ TEST(LlvmLibcStringConverterTest, UTF8To32ErrorHandling) { LIBC_NAMESPACE::internal::StringConverter<char8_t> sc( reinterpret_cast<const char8_t *>(src), &state, SIZE_MAX); - auto res = sc.popUTF32(); + auto res = sc.pop<char32_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x1f921); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 4); - res = sc.popUTF32(); + res = sc.pop<char32_t>(); ASSERT_FALSE(res.has_value()); ASSERT_EQ(static_cast<int>(res.error()), EILSEQ); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 4); @@ -257,12 +257,12 @@ TEST(LlvmLibcStringConverterTest, InvalidCharacterOutsideBounds) { LIBC_NAMESPACE::internal::StringConverter<char8_t> sc1( reinterpret_cast<const char8_t *>(src1), &ps1, 1); - auto res1 = sc1.popUTF32(); + auto res1 = sc1.pop<char32_t>(); ASSERT_TRUE(res1.has_value()); ASSERT_EQ(static_cast<int>(res1.value()), 0x1f921); ASSERT_EQ(static_cast<int>(sc1.getSourceIndex()), 4); - res1 = sc1.popUTF32(); + res1 = sc1.pop<char32_t>(); ASSERT_FALSE(res1.has_value()); // no space to write error NOT invalid character error (EILSEQ) ASSERT_EQ(static_cast<int>(res1.error()), -1); @@ -275,27 +275,27 @@ TEST(LlvmLibcStringConverterTest, InvalidCharacterOutsideBounds) { LIBC_NAMESPACE::internal::StringConverter<char32_t> sc2( reinterpret_cast<const char32_t *>(src2), &ps2, 4); - auto res2 = sc2.popUTF8(); + auto res2 = sc2.pop<char8_t>(); ASSERT_TRUE(res2.has_value()); ASSERT_EQ(static_cast<int>(res2.value()), 0xF0); ASSERT_EQ(static_cast<int>(sc2.getSourceIndex()), 1); - res2 = sc2.popUTF8(); + res2 = sc2.pop<char8_t>(); ASSERT_TRUE(res2.has_value()); ASSERT_EQ(static_cast<int>(res2.value()), 0x9F); ASSERT_EQ(static_cast<int>(sc2.getSourceIndex()), 1); - res2 = sc2.popUTF8(); + res2 = sc2.pop<char8_t>(); ASSERT_TRUE(res2.has_value()); ASSERT_EQ(static_cast<int>(res2.value()), 0xA4); ASSERT_EQ(static_cast<int>(sc2.getSourceIndex()), 1); - res2 = sc2.popUTF8(); + res2 = sc2.pop<char8_t>(); ASSERT_TRUE(res2.has_value()); ASSERT_EQ(static_cast<int>(res2.value()), 0xA1); ASSERT_EQ(static_cast<int>(sc2.getSourceIndex()), 1); - res2 = sc2.popUTF8(); + res2 = sc2.pop<char8_t>(); ASSERT_FALSE(res2.has_value()); // no space to write error NOT invalid character error (EILSEQ) ASSERT_EQ(static_cast<int>(res2.error()), -1); @@ -315,22 +315,22 @@ TEST(LlvmLibcStringConverterTest, MultipleStringConverters32To8) { LIBC_NAMESPACE::internal::StringConverter<char32_t> sc1( reinterpret_cast<const char32_t *>(src), &state, SIZE_MAX, 1); - auto res = sc1.popUTF8(); + auto res = sc1.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xF0); ASSERT_EQ(static_cast<int>(sc1.getSourceIndex()), 1); - res = sc1.popUTF8(); + res = sc1.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x9F); ASSERT_EQ(static_cast<int>(sc1.getSourceIndex()), 1); - res = sc1.popUTF8(); + res = sc1.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xA4); ASSERT_EQ(static_cast<int>(sc1.getSourceIndex()), 1); - res = sc1.popUTF8(); + res = sc1.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xA1); ASSERT_EQ(static_cast<int>(sc1.getSourceIndex()), 1); @@ -340,12 +340,12 @@ TEST(LlvmLibcStringConverterTest, MultipleStringConverters32To8) { reinterpret_cast<const char32_t *>(src) + sc1.getSourceIndex(), &state, SIZE_MAX, 1); - res = sc2.popUTF8(); + res = sc2.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xC3); ASSERT_EQ(static_cast<int>(sc2.getSourceIndex()), 1); - res = sc2.popUTF8(); + res = sc2.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0xBF); ASSERT_EQ(static_cast<int>(sc2.getSourceIndex()), 1); @@ -357,7 +357,7 @@ TEST(LlvmLibcStringConverterTest, MultipleStringConverters8To32) { LIBC_NAMESPACE::internal::StringConverter<char8_t> sc1( reinterpret_cast<const char8_t *>(src), &state, SIZE_MAX, 2); - auto res = sc1.popUTF32(); + auto res = sc1.pop<char32_t>(); ASSERT_FALSE(res.has_value()); ASSERT_EQ(static_cast<int>(res.error()), -1); ASSERT_EQ(static_cast<int>(sc1.getSourceIndex()), 2); @@ -367,12 +367,12 @@ TEST(LlvmLibcStringConverterTest, MultipleStringConverters8To32) { reinterpret_cast<const char8_t *>(src) + sc1.getSourceIndex(), &state, SIZE_MAX, 3); - res = sc2.popUTF32(); + res = sc2.pop<char32_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0x1f921); ASSERT_EQ(static_cast<int>(sc2.getSourceIndex()), 2); - res = sc2.popUTF32(); + res = sc2.pop<char32_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(res.value()), 0); ASSERT_EQ(static_cast<int>(sc2.getSourceIndex()), 3); @@ -384,11 +384,11 @@ TEST(LlvmLibcStringConverterTest, DestLimitUTF8To32) { LIBC_NAMESPACE::internal::StringConverter<char8_t> sc( reinterpret_cast<const char8_t *>(src), &state, 1); - auto res = sc.popUTF32(); + auto res = sc.pop<char32_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 4); - res = sc.popUTF32(); // no space to pop this into + res = sc.pop<char32_t>(); // no space to pop this into ASSERT_FALSE(res.has_value()); } @@ -399,23 +399,23 @@ TEST(LlvmLibcStringConverterTest, DestLimitUTF32To8) { LIBC_NAMESPACE::internal::StringConverter<char32_t> sc( reinterpret_cast<const char32_t *>(src), &state, 5); - auto res = sc.popUTF8(); + auto res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_TRUE(res.has_value()); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); - res = sc.popUTF8(); + res = sc.pop<char8_t>(); ASSERT_FALSE(res.has_value()); ASSERT_EQ(static_cast<int>(sc.getSourceIndex()), 1); } diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index 43cde0d..4e5563b 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -669,6 +669,25 @@ add_fp_unittest( ) add_fp_unittest( + lroundbf16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + lroundbf16_test.cpp + HDRS + RoundToIntegerTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.errno.errno + libc.src.math.lroundbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( llround_test NEED_MPFR SUITE @@ -741,6 +760,25 @@ add_fp_unittest( ) add_fp_unittest( + llroundbf16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + llroundbf16_test.cpp + HDRS + RoundToIntegerTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.errno.errno + libc.src.math.llroundbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( nearbyint_test NEED_MPFR SUITE @@ -801,6 +839,22 @@ add_fp_unittest( ) add_fp_unittest( + nearbyintbf16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + nearbyintbf16_test.cpp + HDRS + NearbyIntTest.h + DEPENDS + libc.src.math.nearbyintbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.CPP.array + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( rint_test NEED_MPFR SUITE @@ -869,6 +923,24 @@ add_fp_unittest( ) add_fp_unittest( + rintbf16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + rintbf16_test.cpp + HDRS + RIntTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.math.rintbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( lrint_test NEED_MPFR SUITE @@ -933,6 +1005,23 @@ add_fp_unittest( ) add_fp_unittest( + lrintbf16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + lrintbf16_test.cpp + HDRS + RoundToIntegerTest.h + DEPENDS + libc.src.math.lrintbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( llrint_test NEED_MPFR SUITE @@ -997,6 +1086,23 @@ add_fp_unittest( ) add_fp_unittest( + llrintbf16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + llrintbf16_test.cpp + HDRS + RoundToIntegerTest.h + DEPENDS + libc.src.math.llrintbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( exp_test NEED_MPFR SUITE @@ -2170,6 +2276,17 @@ add_fp_unittest( ) add_fp_unittest( + atanpif16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + atanpif16_test.cpp + DEPENDS + libc.src.math.atanpif16 +) + +add_fp_unittest( fmul_test NEED_MPFR SUITE @@ -2283,6 +2400,17 @@ add_fp_unittest( ) add_fp_unittest( + asinpif16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + asinpif16_test.cpp + DEPENDS + libc.src.math.asinpif16 +) + +add_fp_unittest( acosf_test NEED_MPFR SUITE @@ -2972,6 +3100,302 @@ add_fp_unittest( libc.src.__support.macros.properties.types ) +add_fp_unittest( + bf16add_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16add_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.math.bf16add + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16addf_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16addf_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.math.bf16addf + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16addl_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16addl_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.math.bf16addl + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16addf128_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16addf128_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.math.bf16addf128 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16div_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16div_test.cpp + HDRS + DivTest.h + DEPENDS + libc.src.math.bf16div + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16divf_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16divf_test.cpp + HDRS + DivTest.h + DEPENDS + libc.src.math.bf16divf + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16divl_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16divl_test.cpp + HDRS + DivTest.h + DEPENDS + libc.src.math.bf16divl + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16divf128_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16divf128_test.cpp + HDRS + DivTest.h + DEPENDS + libc.src.math.bf16divf128 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16fma_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16fma_test.cpp + HDRS + FmaTest.h + DEPENDS + libc.src.math.bf16fma + libc.src.stdlib.rand + libc.src.stdlib.srand + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16fmaf_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16fmaf_test.cpp + HDRS + FmaTest.h + DEPENDS + libc.src.math.bf16fmaf + libc.src.stdlib.rand + libc.src.stdlib.srand + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16fmal_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16fmal_test.cpp + HDRS + FmaTest.h + DEPENDS + libc.src.math.bf16fmal + libc.src.stdlib.rand + libc.src.stdlib.srand + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16fmaf128_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16fmaf128_test.cpp + HDRS + FmaTest.h + DEPENDS + libc.src.math.bf16fmaf128 + libc.src.stdlib.rand + libc.src.stdlib.srand + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16mul_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16mul_test.cpp + HDRS + MulTest.h + DEPENDS + libc.src.math.bf16mul + libc.src.stdlib.rand + libc.src.stdlib.srand + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16mulf_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16mulf_test.cpp + HDRS + MulTest.h + DEPENDS + libc.src.math.bf16mulf + libc.src.stdlib.rand + libc.src.stdlib.srand + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16mull_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16mull_test.cpp + HDRS + MulTest.h + DEPENDS + libc.src.math.bf16mull + libc.src.stdlib.rand + libc.src.stdlib.srand + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16mulf128_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16mulf128_test.cpp + HDRS + MulTest.h + DEPENDS + libc.src.math.bf16mulf128 + libc.src.stdlib.rand + libc.src.stdlib.srand + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16sub_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16sub_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.math.bf16sub + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16subf_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16subf_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.math.bf16subf + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16subl_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16subl_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.math.bf16subl + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16subf128_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + bf16subf128_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.math.bf16subf128 + libc.src.__support.FPUtil.bfloat16 +) + add_subdirectory(generic) add_subdirectory(smoke) diff --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h index 6af9cfe..e5e9386 100644 --- a/libc/test/src/math/RoundToIntegerTest.h +++ b/libc/test/src/math/RoundToIntegerTest.h @@ -127,8 +127,8 @@ public: test_one_input(func, FloatType(-1.0), IntType(-1), false); test_one_input(func, FloatType(10.0), IntType(10), false); test_one_input(func, FloatType(-10.0), IntType(-10), false); - test_one_input(func, FloatType(1234.0), IntType(1234), false); - test_one_input(func, FloatType(-1234.0), IntType(-1234), false); + test_one_input(func, FloatType(1232.0), IntType(1232), false); + test_one_input(func, FloatType(-1232.0), IntType(-1232), false); // The rest of this function compares with an equivalent MPFR function // which rounds floating point numbers to long values. There is no MPFR diff --git a/libc/test/src/math/asinpif16_test.cpp b/libc/test/src/math/asinpif16_test.cpp new file mode 100644 index 0000000..3718f39 --- /dev/null +++ b/libc/test/src/math/asinpif16_test.cpp @@ -0,0 +1,40 @@ +//===-- Exhaustive test for asinpif16 -------------------------------------===// +// +// 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/asinpif16.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include "utils/MPFRWrapper/MPFRUtils.h" + +using LlvmLibcAsinpif16Test = LIBC_NAMESPACE::testing::FPTest<float16>; + +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; + +// Range: [0, Inf] +static constexpr uint16_t POS_START = 0x0000U; +static constexpr uint16_t POS_STOP = 0x7c00U; + +// Range: [-Inf, 0] +static constexpr uint16_t NEG_START = 0x8000U; +static constexpr uint16_t NEG_STOP = 0xfc00U; + +TEST_F(LlvmLibcAsinpif16Test, PositiveRange) { + for (uint16_t v = POS_START; v <= POS_STOP; ++v) { + float16 x = FPBits(v).get_val(); + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinpi, x, + LIBC_NAMESPACE::asinpif16(x), 0.5); + } +} + +TEST_F(LlvmLibcAsinpif16Test, NegativeRange) { + for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { + float16 x = FPBits(v).get_val(); + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinpi, x, + LIBC_NAMESPACE::asinpif16(x), 0.5); + } +} diff --git a/libc/test/src/math/atanpif16_test.cpp b/libc/test/src/math/atanpif16_test.cpp new file mode 100644 index 0000000..38771f0 --- /dev/null +++ b/libc/test/src/math/atanpif16_test.cpp @@ -0,0 +1,40 @@ +//===-- Exhaustive test for atanpif16 -------------------------------------===// +// +// 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/atanpif16.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include "utils/MPFRWrapper/MPFRUtils.h" + +using LlvmLibcAtanpif16Test = LIBC_NAMESPACE::testing::FPTest<float16>; + +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; + +// Range: [0, Inf] +static constexpr uint16_t POS_START = 0x0000U; +static constexpr uint16_t POS_STOP = 0x7c00U; + +// Range: [-Inf, 0] +static constexpr uint16_t NEG_START = 0x8000U; +static constexpr uint16_t NEG_STOP = 0xfc00U; + +TEST_F(LlvmLibcAtanpif16Test, PositiveRange) { + for (uint16_t v = POS_START; v <= POS_STOP; ++v) { + float16 x = FPBits(v).get_val(); + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atanpi, x, + LIBC_NAMESPACE::atanpif16(x), 0.5); + } +} + +TEST_F(LlvmLibcAtanpif16Test, NegativeRange) { + for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { + float16 x = FPBits(v).get_val(); + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atanpi, x, + LIBC_NAMESPACE::atanpif16(x), 0.5); + } +} diff --git a/libc/test/src/math/bf16add_test.cpp b/libc/test/src/math/bf16add_test.cpp new file mode 100644 index 0000000..9e9c594 --- /dev/null +++ b/libc/test/src/math/bf16add_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16add ---------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16add.h" + +LIST_ADD_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16add) diff --git a/libc/test/src/math/bf16addf128_test.cpp b/libc/test/src/math/bf16addf128_test.cpp new file mode 100644 index 0000000..46f7ad3 --- /dev/null +++ b/libc/test/src/math/bf16addf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addf128 -----------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addf128.h" + +LIST_ADD_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16addf128) diff --git a/libc/test/src/math/bf16addf_test.cpp b/libc/test/src/math/bf16addf_test.cpp new file mode 100644 index 0000000..06d56cf --- /dev/null +++ b/libc/test/src/math/bf16addf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addf --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addf.h" + +LIST_ADD_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16addf) diff --git a/libc/test/src/math/bf16addl_test.cpp b/libc/test/src/math/bf16addl_test.cpp new file mode 100644 index 0000000..bf54827 --- /dev/null +++ b/libc/test/src/math/bf16addl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addl --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addl.h" + +LIST_ADD_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16addl) diff --git a/libc/test/src/math/bf16div_test.cpp b/libc/test/src/math/bf16div_test.cpp new file mode 100644 index 0000000..4516351 --- /dev/null +++ b/libc/test/src/math/bf16div_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16div ---------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16div.h" + +LIST_DIV_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16div) diff --git a/libc/test/src/math/bf16divf128_test.cpp b/libc/test/src/math/bf16divf128_test.cpp new file mode 100644 index 0000000..c42c5bb --- /dev/null +++ b/libc/test/src/math/bf16divf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16divf128 -----------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16divf128.h" + +LIST_DIV_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16divf128) diff --git a/libc/test/src/math/bf16divf_test.cpp b/libc/test/src/math/bf16divf_test.cpp new file mode 100644 index 0000000..873920b --- /dev/null +++ b/libc/test/src/math/bf16divf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16divf --------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16divf.h" + +LIST_DIV_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16divf) diff --git a/libc/test/src/math/bf16divl_test.cpp b/libc/test/src/math/bf16divl_test.cpp new file mode 100644 index 0000000..32ecd62 --- /dev/null +++ b/libc/test/src/math/bf16divl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16divl --------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16divl.h" + +LIST_DIV_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16divl) diff --git a/libc/test/src/math/bf16fma_test.cpp b/libc/test/src/math/bf16fma_test.cpp new file mode 100644 index 0000000..81c73a0c --- /dev/null +++ b/libc/test/src/math/bf16fma_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16fma ---------------------------------------------===// +// +// 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 "FmaTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16fma.h" + +LIST_NARROWING_FMA_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16fma) diff --git a/libc/test/src/math/bf16fmaf128_test.cpp b/libc/test/src/math/bf16fmaf128_test.cpp new file mode 100644 index 0000000..dd8f473 --- /dev/null +++ b/libc/test/src/math/bf16fmaf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16fmaf128 -----------------------------------------===// +// +// 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 "FmaTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16fmaf128.h" + +LIST_NARROWING_FMA_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16fmaf128) diff --git a/libc/test/src/math/bf16fmaf_test.cpp b/libc/test/src/math/bf16fmaf_test.cpp new file mode 100644 index 0000000..04c6748 --- /dev/null +++ b/libc/test/src/math/bf16fmaf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16fmaf --------------------------------------------===// +// +// 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 "FmaTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16fmaf.h" + +LIST_NARROWING_FMA_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16fmaf) diff --git a/libc/test/src/math/bf16fmal_test.cpp b/libc/test/src/math/bf16fmal_test.cpp new file mode 100644 index 0000000..4c45e2c --- /dev/null +++ b/libc/test/src/math/bf16fmal_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16fmal --------------------------------------------===// +// +// 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 "FmaTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16fmal.h" + +LIST_NARROWING_FMA_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16fmal) diff --git a/libc/test/src/math/bf16mul_test.cpp b/libc/test/src/math/bf16mul_test.cpp new file mode 100644 index 0000000..3682705 --- /dev/null +++ b/libc/test/src/math/bf16mul_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for bf16mul ---------------------------------------------===// +// +// 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 "MulTest.h" + +#include "src/math/bf16mul.h" + +#include "src/__support/FPUtil/bfloat16.h" + +LIST_MUL_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16mul) diff --git a/libc/test/src/math/bf16mulf128_test.cpp b/libc/test/src/math/bf16mulf128_test.cpp new file mode 100644 index 0000000..6aee2687 --- /dev/null +++ b/libc/test/src/math/bf16mulf128_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for bf16mulf128 -----------------------------------------===// +// +// 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 "MulTest.h" + +#include "src/math/bf16mulf128.h" + +#include "src/__support/FPUtil/bfloat16.h" + +LIST_MUL_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16mulf128) diff --git a/libc/test/src/math/bf16mulf_test.cpp b/libc/test/src/math/bf16mulf_test.cpp new file mode 100644 index 0000000..048b60f --- /dev/null +++ b/libc/test/src/math/bf16mulf_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for bf16mulf --------------------------------------------===// +// +// 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 "MulTest.h" + +#include "src/math/bf16mulf.h" + +#include "src/__support/FPUtil/bfloat16.h" + +LIST_MUL_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16mulf) diff --git a/libc/test/src/math/bf16mull_test.cpp b/libc/test/src/math/bf16mull_test.cpp new file mode 100644 index 0000000..b8439b2 --- /dev/null +++ b/libc/test/src/math/bf16mull_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for bf16mull --------------------------------------------===// +// +// 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 "MulTest.h" + +#include "src/math/bf16mull.h" + +#include "src/__support/FPUtil/bfloat16.h" + +LIST_MUL_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16mull) diff --git a/libc/test/src/math/bf16sub_test.cpp b/libc/test/src/math/bf16sub_test.cpp new file mode 100644 index 0000000..4a793dc --- /dev/null +++ b/libc/test/src/math/bf16sub_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16sub ---------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16sub.h" + +LIST_SUB_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16sub) diff --git a/libc/test/src/math/bf16subf128_test.cpp b/libc/test/src/math/bf16subf128_test.cpp new file mode 100644 index 0000000..25d6711 --- /dev/null +++ b/libc/test/src/math/bf16subf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subf128 -----------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subf128.h" + +LIST_SUB_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16subf128) diff --git a/libc/test/src/math/bf16subf_test.cpp b/libc/test/src/math/bf16subf_test.cpp new file mode 100644 index 0000000..e8c7440 --- /dev/null +++ b/libc/test/src/math/bf16subf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subf --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subf.h" + +LIST_SUB_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16subf) diff --git a/libc/test/src/math/bf16subl_test.cpp b/libc/test/src/math/bf16subl_test.cpp new file mode 100644 index 0000000..2997369 --- /dev/null +++ b/libc/test/src/math/bf16subl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subl --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subl.h" + +LIST_SUB_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16subl) diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt index 5246337..07c36f424 100644 --- a/libc/test/src/math/exhaustive/CMakeLists.txt +++ b/libc/test/src/math/exhaustive/CMakeLists.txt @@ -378,6 +378,22 @@ add_fp_unittest( ) add_fp_unittest( + fmodbf16_test + NO_RUN_POSTBUILD + NEED_MPFR + SUITE + libc_math_exhaustive_tests + SRCS + fmodbf16_test.cpp + DEPENDS + .exhaustive_test + libc.src.math.fmodbf16 + libc.src.__support.FPUtil.bfloat16 + LINK_LIBRARIES + -lpthread +) + +add_fp_unittest( coshf_test NO_RUN_POSTBUILD NEED_MPFR @@ -567,3 +583,75 @@ add_fp_unittest( LINK_LIBRARIES -lpthread ) + +add_fp_unittest( + bfloat16_add_test + NO_RUN_POSTBUILD + NEED_MPFR + SUITE + libc_math_exhaustive_tests + SRCS + bfloat16_add_test.cpp + COMPILE_OPTIONS + ${libc_opt_high_flag} + DEPENDS + .exhaustive_test + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits + LINK_LIBRARIES + -lpthread +) + +add_fp_unittest( + bfloat16_div_test + NO_RUN_POSTBUILD + NEED_MPFR + SUITE + libc_math_exhaustive_tests + SRCS + bfloat16_div_test.cpp + COMPILE_OPTIONS + ${libc_opt_high_flag} + DEPENDS + .exhaustive_test + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits + LINK_LIBRARIES + -lpthread +) + +add_fp_unittest( + bfloat16_mul_test + NO_RUN_POSTBUILD + NEED_MPFR + SUITE + libc_math_exhaustive_tests + SRCS + bfloat16_mul_test.cpp + COMPILE_OPTIONS + ${libc_opt_high_flag} + DEPENDS + .exhaustive_test + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits + LINK_LIBRARIES + -lpthread +) + +add_fp_unittest( + bfloat16_sub_test + NO_RUN_POSTBUILD + NEED_MPFR + SUITE + libc_math_exhaustive_tests + SRCS + bfloat16_sub_test.cpp + COMPILE_OPTIONS + ${libc_opt_high_flag} + DEPENDS + .exhaustive_test + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits + LINK_LIBRARIES + -lpthread +) diff --git a/libc/test/src/math/exhaustive/bfloat16_add_test.cpp b/libc/test/src/math/exhaustive/bfloat16_add_test.cpp new file mode 100644 index 0000000..3f4c779 --- /dev/null +++ b/libc/test/src/math/exhaustive/bfloat16_add_test.cpp @@ -0,0 +1,65 @@ +//===-- Exhaustive tests for bfloat16 addition ----------------------------===// +// +// 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 "exhaustive_test.h" +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "test/UnitTest/FPMatcher.h" +#include "utils/MPFRWrapper/MPCommon.h" +#include "utils/MPFRWrapper/MPFRUtils.h" + +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; +using LIBC_NAMESPACE::fputil::BFloat16; + +static BFloat16 add_func(BFloat16 x, BFloat16 y) { return x + y; } + +struct Bfloat16AddChecker : public virtual LIBC_NAMESPACE::testing::Test { + using FloatType = BFloat16; + using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>; + using StorageType = typename FPBits::StorageType; + + uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start, + uint16_t y_stop, mpfr::RoundingMode rounding) { + mpfr::ForceRoundingMode r(rounding); + if (!r.success) + return true; + uint16_t xbits = x_start; + uint64_t failed = 0; + do { + BFloat16 x = FPBits(xbits).get_val(); + uint16_t ybits = xbits; + do { + BFloat16 y = FPBits(ybits).get_val(); + mpfr::BinaryInput<BFloat16> input{x, y}; + bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY( + mpfr::Operation::Add, input, add_func(x, y), 0.5, rounding); + failed += (!correct); + } while (ybits++ < y_stop); + } while (xbits++ < x_stop); + return failed; + } +}; + +using LlvmLibcBfloat16ExhaustiveAddTest = + LlvmLibcExhaustiveMathTest<Bfloat16AddChecker, 1 << 2>; + +// range: [0, inf] +static constexpr uint16_t POS_START = 0x0000U; +static constexpr uint16_t POS_STOP = 0x7f80U; + +// range: [-0, -inf] +static constexpr uint16_t NEG_START = 0x8000U; +static constexpr uint16_t NEG_STOP = 0xff80U; + +TEST_F(LlvmLibcBfloat16ExhaustiveAddTest, PositiveRange) { + test_full_range_all_roundings(POS_START, POS_STOP, POS_START, POS_STOP); +} + +TEST_F(LlvmLibcBfloat16ExhaustiveAddTest, NegativeRange) { + test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP); +} diff --git a/libc/test/src/math/exhaustive/bfloat16_div_test.cpp b/libc/test/src/math/exhaustive/bfloat16_div_test.cpp new file mode 100644 index 0000000..2648d5f --- /dev/null +++ b/libc/test/src/math/exhaustive/bfloat16_div_test.cpp @@ -0,0 +1,65 @@ +//===-- Exhaustive tests for bfloat16 division ----------------------------===// +// +// 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 "exhaustive_test.h" +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "test/UnitTest/FPMatcher.h" +#include "utils/MPFRWrapper/MPCommon.h" +#include "utils/MPFRWrapper/MPFRUtils.h" + +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; +using LIBC_NAMESPACE::fputil::BFloat16; + +static BFloat16 div_func(BFloat16 x, BFloat16 y) { return x / y; } + +struct Bfloat16DivChecker : public virtual LIBC_NAMESPACE::testing::Test { + using FloatType = BFloat16; + using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>; + using StorageType = typename FPBits::StorageType; + + uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start, + uint16_t y_stop, mpfr::RoundingMode rounding) { + mpfr::ForceRoundingMode r(rounding); + if (!r.success) + return true; + uint16_t xbits = x_start; + uint64_t failed = 0; + do { + BFloat16 x = FPBits(xbits).get_val(); + uint16_t ybits = xbits; + do { + BFloat16 y = FPBits(ybits).get_val(); + mpfr::BinaryInput<BFloat16> input{x, y}; + bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY( + mpfr::Operation::Div, input, div_func(x, y), 0.5, rounding); + failed += (!correct); + } while (ybits++ < y_stop); + } while (xbits++ < x_stop); + return failed; + } +}; + +using LlvmLibcBfloat16ExhaustiveDivTest = + LlvmLibcExhaustiveMathTest<Bfloat16DivChecker, 1 << 2>; + +// range: [0, inf] +static constexpr uint16_t POS_START = 0x0000U; +static constexpr uint16_t POS_STOP = 0x7f80U; + +// range: [-0, -inf] +static constexpr uint16_t NEG_START = 0x8000U; +static constexpr uint16_t NEG_STOP = 0xff80U; + +TEST_F(LlvmLibcBfloat16ExhaustiveDivTest, PositiveRange) { + test_full_range_all_roundings(POS_START, POS_STOP, POS_START, POS_STOP); +} + +TEST_F(LlvmLibcBfloat16ExhaustiveDivTest, NegativeRange) { + test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP); +} diff --git a/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp b/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp new file mode 100644 index 0000000..3cbbcb5 --- /dev/null +++ b/libc/test/src/math/exhaustive/bfloat16_mul_test.cpp @@ -0,0 +1,65 @@ +//===-- Exhaustive tests for bfloat16 multiplication ----------------------===// +// +// 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 "exhaustive_test.h" +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "test/UnitTest/FPMatcher.h" +#include "utils/MPFRWrapper/MPCommon.h" +#include "utils/MPFRWrapper/MPFRUtils.h" + +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; +using LIBC_NAMESPACE::fputil::BFloat16; + +static BFloat16 mul_func(BFloat16 x, BFloat16 y) { return x * y; } + +struct Bfloat16MulChecker : public virtual LIBC_NAMESPACE::testing::Test { + using FloatType = BFloat16; + using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>; + using StorageType = typename FPBits::StorageType; + + uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start, + uint16_t y_stop, mpfr::RoundingMode rounding) { + mpfr::ForceRoundingMode r(rounding); + if (!r.success) + return true; + uint16_t xbits = x_start; + uint64_t failed = 0; + do { + BFloat16 x = FPBits(xbits).get_val(); + uint16_t ybits = xbits; + do { + BFloat16 y = FPBits(ybits).get_val(); + mpfr::BinaryInput<BFloat16> input{x, y}; + bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY( + mpfr::Operation::Mul, input, mul_func(x, y), 0.5, rounding); + failed += (!correct); + } while (ybits++ < y_stop); + } while (xbits++ < x_stop); + return failed; + } +}; + +using LlvmLibcBfloat16ExhaustiveMulTest = + LlvmLibcExhaustiveMathTest<Bfloat16MulChecker, 1 << 2>; + +// range: [0, inf] +static constexpr uint16_t POS_START = 0x0000U; +static constexpr uint16_t POS_STOP = 0x7f80U; + +// range: [-0, -inf] +static constexpr uint16_t NEG_START = 0x8000U; +static constexpr uint16_t NEG_STOP = 0xff80U; + +TEST_F(LlvmLibcBfloat16ExhaustiveMulTest, PositiveRange) { + test_full_range_all_roundings(POS_START, POS_STOP, POS_START, POS_STOP); +} + +TEST_F(LlvmLibcBfloat16ExhaustiveMulTest, NegativeRange) { + test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP); +} diff --git a/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp b/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp new file mode 100644 index 0000000..11bc6f5 --- /dev/null +++ b/libc/test/src/math/exhaustive/bfloat16_sub_test.cpp @@ -0,0 +1,65 @@ +//===-- Exhaustive tests for bfloat16 subtraction -------------------------===// +// +// 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 "exhaustive_test.h" +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "test/UnitTest/FPMatcher.h" +#include "utils/MPFRWrapper/MPCommon.h" +#include "utils/MPFRWrapper/MPFRUtils.h" + +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; +using LIBC_NAMESPACE::fputil::BFloat16; + +static BFloat16 sub_func(BFloat16 x, BFloat16 y) { return x - y; } + +struct Bfloat16SubChecker : public virtual LIBC_NAMESPACE::testing::Test { + using FloatType = BFloat16; + using FPBits = LIBC_NAMESPACE::fputil::FPBits<bfloat16>; + using StorageType = typename FPBits::StorageType; + + uint64_t check(uint16_t x_start, uint16_t x_stop, uint16_t y_start, + uint16_t y_stop, mpfr::RoundingMode rounding) { + mpfr::ForceRoundingMode r(rounding); + if (!r.success) + return true; + uint16_t xbits = x_start; + uint64_t failed = 0; + do { + BFloat16 x = FPBits(xbits).get_val(); + uint16_t ybits = xbits; + do { + BFloat16 y = FPBits(ybits).get_val(); + mpfr::BinaryInput<BFloat16> input{x, y}; + bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY( + mpfr::Operation::Sub, input, sub_func(x, y), 0.5, rounding); + failed += (!correct); + } while (ybits++ < y_stop); + } while (xbits++ < x_stop); + return failed; + } +}; + +using LlvmLibcBfloat16ExhaustiveSubTest = + LlvmLibcExhaustiveMathTest<Bfloat16SubChecker, 1 << 2>; + +// range: [0, inf] +static constexpr uint16_t POS_START = 0x0000U; +static constexpr uint16_t POS_STOP = 0x7f80U; + +// range: [-0, -inf] +static constexpr uint16_t NEG_START = 0x8000U; +static constexpr uint16_t NEG_STOP = 0xff80U; + +TEST_F(LlvmLibcBfloat16ExhaustiveSubTest, PositiveRange) { + test_full_range_all_roundings(POS_START, POS_STOP, POS_START, POS_STOP); +} + +TEST_F(LlvmLibcBfloat16ExhaustiveSubTest, NegativeRange) { + test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP); +} diff --git a/libc/test/src/math/exhaustive/exhaustive_test.h b/libc/test/src/math/exhaustive/exhaustive_test.h index cdf459c..8be65ba 100644 --- a/libc/test/src/math/exhaustive/exhaustive_test.h +++ b/libc/test/src/math/exhaustive/exhaustive_test.h @@ -164,7 +164,7 @@ struct LlvmLibcExhaustiveMathTest range_begin = current_value; if (stop >= Increment && stop - Increment >= current_value) { - range_end = current_value + Increment; + range_end = static_cast<StorageType>(current_value + Increment); } else { range_end = stop; } diff --git a/libc/test/src/math/exhaustive/fmodbf16_test.cpp b/libc/test/src/math/exhaustive/fmodbf16_test.cpp new file mode 100644 index 0000000..122be7a --- /dev/null +++ b/libc/test/src/math/exhaustive/fmodbf16_test.cpp @@ -0,0 +1,42 @@ +//===-- Exhaustive test for fmodbf16 --------------------------------------===// +// +// 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 "exhaustive_test.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fmodbf16.h" +#include "utils/MPFRWrapper/MPFRUtils.h" + +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; + +using LlvmLibcFmodf16ExhaustiveTest = + LlvmLibcBinaryOpExhaustiveMathTest<bfloat16, mpfr::Operation::Fmod, + LIBC_NAMESPACE::fmodbf16>; + +// range: [0, inf] +static constexpr uint16_t POS_START = 0x0000U; +static constexpr uint16_t POS_STOP = 0x7f80U; + +// range: [-0, -inf] +static constexpr uint16_t NEG_START = 0x8000U; +static constexpr uint16_t NEG_STOP = 0xff80U; + +TEST_F(LlvmLibcFmodf16ExhaustiveTest, PostivePositiveRange) { + test_full_range_all_roundings(POS_START, POS_STOP, POS_START, POS_STOP); +} + +TEST_F(LlvmLibcFmodf16ExhaustiveTest, PostiveNegativeRange) { + test_full_range_all_roundings(POS_START, POS_STOP, NEG_START, NEG_STOP); +} + +TEST_F(LlvmLibcFmodf16ExhaustiveTest, NegativePositiveRange) { + test_full_range_all_roundings(NEG_START, NEG_STOP, POS_START, POS_STOP); +} + +TEST_F(LlvmLibcFmodf16ExhaustiveTest, NegativeNegativeRange) { + test_full_range_all_roundings(NEG_START, NEG_STOP, NEG_START, NEG_STOP); +} diff --git a/libc/test/src/math/explogxf_test.cpp b/libc/test/src/math/explogxf_test.cpp index 49cc962..4d35309 100644 --- a/libc/test/src/math/explogxf_test.cpp +++ b/libc/test/src/math/explogxf_test.cpp @@ -9,11 +9,11 @@ #include "hdr/math_macros.h" #include "in_float_range_test_helper.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/math/acoshf_utils.h" +#include "src/__support/math/exp10f_utils.h" #include "src/math/fabs.h" #include "src/math/fabsf.h" -#include "src/math/generic/explogxf.h" #include "test/UnitTest/FPMatcher.h" -#include "test/UnitTest/Test.h" #include "utils/MPFRWrapper/MPFRUtils.h" using LlvmLibcExplogfTest = LIBC_NAMESPACE::testing::FPTest<float>; diff --git a/libc/test/src/math/llrintbf16_test.cpp b/libc/test/src/math/llrintbf16_test.cpp new file mode 100644 index 0000000..e841e62 --- /dev/null +++ b/libc/test/src/math/llrintbf16_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for llrintbf16 ------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/llrintbf16.h" + +LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long long, + LIBC_NAMESPACE::llrintbf16) diff --git a/libc/test/src/math/llroundbf16_test.cpp b/libc/test/src/math/llroundbf16_test.cpp new file mode 100644 index 0000000..c3b7ea4 --- /dev/null +++ b/libc/test/src/math/llroundbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for llroundbf16 -----------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/llroundbf16.h" + +LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long long, LIBC_NAMESPACE::llroundbf16) diff --git a/libc/test/src/math/lrintbf16_test.cpp b/libc/test/src/math/lrintbf16_test.cpp new file mode 100644 index 0000000..65a5633b8 --- /dev/null +++ b/libc/test/src/math/lrintbf16_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for lrintbf16 -------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/lrintbf16.h" + +LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long, + LIBC_NAMESPACE::lrintbf16) diff --git a/libc/test/src/math/lroundbf16_test.cpp b/libc/test/src/math/lroundbf16_test.cpp new file mode 100644 index 0000000..2f2b7b1 --- /dev/null +++ b/libc/test/src/math/lroundbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for lroundbf16 ------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/lroundbf16.h" + +LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long, LIBC_NAMESPACE::lroundbf16) diff --git a/libc/test/src/math/nearbyintbf16_test.cpp b/libc/test/src/math/nearbyintbf16_test.cpp new file mode 100644 index 0000000..2d64fc5 --- /dev/null +++ b/libc/test/src/math/nearbyintbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for nearbyintbf16 ---------------------------------------===// +// +// 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 "NearbyIntTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/nearbyintbf16.h" + +LIST_NEARBYINT_TESTS(bfloat16, LIBC_NAMESPACE::nearbyintbf16) diff --git a/libc/test/src/math/rintbf16_test.cpp b/libc/test/src/math/rintbf16_test.cpp new file mode 100644 index 0000000..c78dcf6 --- /dev/null +++ b/libc/test/src/math/rintbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for rintbf16 --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/rintbf16.h" + +LIST_RINT_TESTS(bfloat16, LIBC_NAMESPACE::rintbf16) diff --git a/libc/test/src/math/smoke/AddTest.h b/libc/test/src/math/smoke/AddTest.h index 68a4bbe..4bd794c 100644 --- a/libc/test/src/math/smoke/AddTest.h +++ b/libc/test/src/math/smoke/AddTest.h @@ -47,6 +47,10 @@ public: EXPECT_FP_EQ(neg_inf, func(in.neg_inf, in.zero)); EXPECT_FP_EQ(inf, func(in.inf, in.neg_zero)); EXPECT_FP_EQ(neg_inf, func(in.neg_inf, in.neg_zero)); + EXPECT_FP_EQ(inf, func(in.zero, in.inf)); + EXPECT_FP_EQ(inf, func(in.neg_zero, in.inf)); + EXPECT_FP_EQ(neg_inf, func(in.zero, in.neg_inf)); + EXPECT_FP_EQ(neg_inf, func(in.neg_zero, in.neg_inf)); } void test_invalid_operations(AddFunc func) { diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 40b7a342..152f38d 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -345,6 +345,19 @@ add_fp_unittest( ) 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 libc-math-smoke-tests @@ -420,6 +433,22 @@ add_fp_unittest( ) add_fp_unittest( + canonicalizebf16_test + SUITE + libc-math-smoke-tests + SRCS + canonicalizebf16_test.cpp + HDRS + CanonicalizeTest.h + DEPENDS + libc.src.math.canonicalizebf16 + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.integer_literals +) + +add_fp_unittest( iscanonical_test SUITE libc-math-smoke-tests @@ -480,6 +509,19 @@ add_fp_unittest( ) add_fp_unittest( + iscanonicalbf16_test + SUITE + libc-math-smoke-tests + SRCS + iscanonicalbf16_test.cpp + HDRS + IsCanonicalTest.h + DEPENDS + libc.src.math.iscanonicalbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( ceil_test SUITE libc-math-smoke-tests @@ -544,6 +586,19 @@ add_fp_unittest( ) 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 libc-math-smoke-tests @@ -664,6 +719,19 @@ add_fp_unittest( ) 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 libc-math-smoke-tests @@ -728,6 +796,19 @@ add_fp_unittest( ) 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 libc-math-smoke-tests @@ -792,6 +873,19 @@ add_fp_unittest( ) 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 libc-math-smoke-tests @@ -872,6 +966,23 @@ add_fp_unittest( ) add_fp_unittest( + lroundbf16_test + SUITE + libc-math-smoke-tests + SRCS + lroundbf16_test.cpp + HDRS + RoundToIntegerTest.h + DEPENDS + libc.src.errno.errno + libc.src.math.lroundbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( llround_test SUITE libc-math-smoke-tests @@ -952,6 +1063,23 @@ add_fp_unittest( ) add_fp_unittest( + llroundbf16_test + SUITE + libc-math-smoke-tests + SRCS + llroundbf16_test.cpp + HDRS + RoundToIntegerTest.h + DEPENDS + libc.src.errno.errno + libc.src.math.llroundbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( rint_test SUITE libc-math-smoke-tests @@ -1022,6 +1150,21 @@ add_fp_unittest( ) add_fp_unittest( + rintbf16_test + SUITE + libc-math-smoke-tests + SRCS + rintbf16_test.cpp + HDRS + RIntTest.h + DEPENDS + libc.src.math.rintbf16 + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( lrint_test SUITE libc-math-smoke-tests @@ -1102,6 +1245,23 @@ add_fp_unittest( ) add_fp_unittest( + lrintbf16_test + SUITE + libc-math-smoke-tests + SRCS + lrintbf16_test.cpp + HDRS + RoundToIntegerTest.h + DEPENDS + libc.src.errno.errno + libc.src.math.lrintbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( llrint_test SUITE libc-math-smoke-tests @@ -1182,6 +1342,23 @@ add_fp_unittest( ) add_fp_unittest( + llrintbf16_test + SUITE + libc-math-smoke-tests + SRCS + llrintbf16_test.cpp + HDRS + RoundToIntegerTest.h + DEPENDS + libc.src.errno.errno + libc.src.math.llrintbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( exp_test SUITE libc-math-smoke-tests @@ -1412,6 +1589,21 @@ add_fp_unittest( ) add_fp_unittest( + copysignbf16_test + SUITE + libc-math-smoke-tests + SRCS + copysignbf16_test.cpp + HDRS + CopySignTest.h + DEPENDS + libc.src.math.copysignbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( frexp_test SUITE libc-math-smoke-tests @@ -1472,6 +1664,19 @@ add_fp_unittest( ) add_fp_unittest( + frexpbf16_test + SUITE + libc-math-smoke-tests + SRCS + frexpbf16_test.cpp + HDRS + FrexpTest.h + DEPENDS + libc.src.math.frexpbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( fromfp_test SUITE libc-math-smoke-tests @@ -1532,6 +1737,19 @@ add_fp_unittest( ) add_fp_unittest( + fromfpbf16_test + SUITE + libc-math-smoke-tests + SRCS + fromfpbf16_test.cpp + HDRS + FromfpTest.h + DEPENDS + libc.src.math.fromfpbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( fromfpx_test SUITE libc-math-smoke-tests @@ -1592,6 +1810,20 @@ add_fp_unittest( ) add_fp_unittest( + fromfpxbf16_test + SUITE + libc-math-smoke-tests + SRCS + fromfpxbf16_test.cpp + HDRS + FromfpxTest.h + DEPENDS + libc.src.math.fromfpxbf16 + libc.src.__support.FPUtil.bfloat16 +) + + +add_fp_unittest( ufromfp_test SUITE libc-math-smoke-tests @@ -1652,6 +1884,19 @@ add_fp_unittest( ) add_fp_unittest( + ufromfpbf16_test + SUITE + libc-math-smoke-tests + SRCS + ufromfpbf16_test.cpp + HDRS + UfromfpTest.h + DEPENDS + libc.src.math.ufromfpbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( ufromfpx_test SUITE libc-math-smoke-tests @@ -1712,6 +1957,19 @@ add_fp_unittest( ) add_fp_unittest( + ufromfpxbf16_test + SUITE + libc-math-smoke-tests + SRCS + ufromfpxbf16_test.cpp + HDRS + UfromfpxTest.h + DEPENDS + libc.src.math.ufromfpxbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( ilogb_test SUITE libc-math-smoke-tests @@ -1787,6 +2045,22 @@ add_fp_unittest( ) add_fp_unittest( + ilogbbf16_test + SUITE + libc-math-smoke-tests + SRCS + ilogbbf16_test.cpp + HDRS + ILogbTest.h + DEPENDS + libc.src.math.ilogbbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits + libc.src.__support.FPUtil.manipulation_functions +) + +add_fp_unittest( issignaling_test SUITE libc-math-smoke-tests @@ -1847,6 +2121,19 @@ add_fp_unittest( ) add_fp_unittest( + issignalingbf16_test + SUITE + libc-math-smoke-tests + SRCS + issignalingbf16_test.cpp + HDRS + IsSignalingTest.h + DEPENDS + libc.src.math.issignalingbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( llogb_test SUITE libc-math-smoke-tests @@ -1922,6 +2209,22 @@ add_fp_unittest( ) add_fp_unittest( + llogbbf16_test + SUITE + libc-math-smoke-tests + SRCS + llogbbf16_test.cpp + HDRS + ILogbTest.h + DEPENDS + libc.src.math.llogbbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits + libc.src.__support.FPUtil.manipulation_functions +) + +add_fp_unittest( ldexp_test SUITE libc-math-smoke-tests @@ -1931,6 +2234,7 @@ add_fp_unittest( LdExpTest.h DEPENDS libc.src.math.ldexp + libc.src.__support.CPP.algorithm libc.src.__support.CPP.limits libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.normal_float @@ -1946,6 +2250,7 @@ add_fp_unittest( LdExpTest.h DEPENDS libc.src.math.ldexpf + libc.src.__support.CPP.algorithm libc.src.__support.CPP.limits libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.normal_float @@ -1961,6 +2266,7 @@ add_fp_unittest( LdExpTest.h DEPENDS libc.src.math.ldexpl + libc.src.__support.CPP.algorithm libc.src.__support.CPP.limits libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.normal_float @@ -1976,6 +2282,7 @@ add_fp_unittest( LdExpTest.h DEPENDS libc.src.math.ldexpf16 + libc.src.__support.CPP.algorithm libc.src.__support.CPP.limits libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.normal_float @@ -1991,12 +2298,30 @@ add_fp_unittest( LdExpTest.h DEPENDS libc.src.math.ldexpf128 + libc.src.__support.CPP.algorithm libc.src.__support.CPP.limits libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.normal_float ) add_fp_unittest( + ldexpbf16_test + SUITE + libc-math-smoke-tests + SRCS + ldexpbf16_test.cpp + HDRS + LdExpTest.h + DEPENDS + libc.src.math.ldexpbf16 + libc.src.__support.CPP.algorithm + 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( logb_test SUITE libc-math-smoke-tests @@ -2067,6 +2392,21 @@ add_fp_unittest( ) add_fp_unittest( + logbbf16_test + SUITE + libc-math-smoke-tests + SRCS + logbbf16_test.cpp + HDRS + LogbTest.h + DEPENDS + libc.src.math.logbbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.manipulation_functions +) + +add_fp_unittest( modf_test SUITE libc-math-smoke-tests @@ -2142,6 +2482,22 @@ add_fp_unittest( ) add_fp_unittest( + modfbf16_test + SUITE + libc-math-smoke-tests + SRCS + modfbf16_test.cpp + HDRS + ModfTest.h + DEPENDS + libc.src.math.modfbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.basic_operations + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.nearest_integer_operations +) + +add_fp_unittest( fdimf_test SUITE libc-math-smoke-tests @@ -2212,6 +2568,21 @@ add_fp_unittest( ) add_fp_unittest( + fdimbf16_test + SUITE + libc-math-smoke-tests + SRCS + fdimbf16_test.cpp + HDRS + FDimTest.h + DEPENDS + libc.src.math.fdimbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fminf_test SUITE libc-math-smoke-tests @@ -2282,6 +2653,21 @@ add_fp_unittest( ) add_fp_unittest( + fminbf16_test + SUITE + libc-math-smoke-tests + SRCS + fminbf16_test.cpp + HDRS + FMinTest.h + DEPENDS + libc.src.math.fminbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fmaxf_test SUITE libc-math-smoke-tests @@ -2352,6 +2738,21 @@ add_fp_unittest( ) add_fp_unittest( + fmaxbf16_test + SUITE + libc-math-smoke-tests + SRCS + fmaxbf16_test.cpp + HDRS + FMaxTest.h + DEPENDS + libc.src.math.fmaxbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fmaximuml_test SUITE libc-math-smoke-tests @@ -2436,6 +2837,21 @@ add_fp_unittest( ) add_fp_unittest( + fmaximumbf16_test + SUITE + libc-math-smoke-tests + SRCS + fmaximumbf16_test.cpp + HDRS + FMaximumTest.h + DEPENDS + libc.src.math.fmaximumbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fmaximum_num_test SUITE libc-math-smoke-tests @@ -2492,6 +2908,21 @@ add_fp_unittest( ) add_fp_unittest( + fmaximum_numbf16_test + SUITE + libc-math-smoke-tests + SRCS + fmaximum_numbf16_test.cpp + HDRS + FMaximumTest.h + DEPENDS + libc.src.math.fmaximum_numbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fmaximum_magf_test SUITE libc-math-smoke-tests @@ -2567,6 +2998,21 @@ add_fp_unittest( ) add_fp_unittest( + fmaximum_magbf16_test + SUITE + libc-math-smoke-tests + SRCS + fmaximum_magbf16_test.cpp + HDRS + FMaximumTest.h + DEPENDS + libc.src.math.fmaximum_magbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fmaximum_mag_numf_test SUITE libc-math-smoke-tests @@ -2637,6 +3083,21 @@ add_fp_unittest( ) add_fp_unittest( + fmaximum_mag_numbf16_test + SUITE + libc-math-smoke-tests + SRCS + fmaximum_mag_numbf16_test.cpp + HDRS + FMaximumTest.h + DEPENDS + libc.src.math.fmaximum_mag_numbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fminimuml_test SUITE libc-math-smoke-tests @@ -2707,6 +3168,21 @@ add_fp_unittest( ) add_fp_unittest( + fminimumbf16_test + SUITE + libc-math-smoke-tests + SRCS + fminimumbf16_test.cpp + HDRS + FMaximumTest.h + DEPENDS + libc.src.math.fminimumbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fminimum_numf_test SUITE libc-math-smoke-tests @@ -2777,6 +3253,21 @@ add_fp_unittest( ) add_fp_unittest( + fminimum_numbf16_test + SUITE + libc-math-smoke-tests + SRCS + fminimum_numf16_test.cpp + HDRS + FMaximumTest.h + DEPENDS + libc.src.math.fminimum_numf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fminimum_magf_test SUITE libc-math-smoke-tests @@ -2847,6 +3338,21 @@ add_fp_unittest( ) add_fp_unittest( + fminimum_magbf16_test + SUITE + libc-math-smoke-tests + SRCS + fminimum_magbf16_test.cpp + HDRS + FMaximumTest.h + DEPENDS + libc.src.math.fminimum_magbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fminimum_mag_numf_test SUITE libc-math-smoke-tests @@ -2917,6 +3423,21 @@ add_fp_unittest( ) add_fp_unittest( + fminimum_mag_numbf16_test + SUITE + libc-math-smoke-tests + SRCS + fminimum_mag_numbf16_test.cpp + HDRS + FMaximumTest.h + DEPENDS + libc.src.math.fminimum_mag_numbf16 + libc.src.__support.CPP.algorithm + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( fmul_test SUITE libc-math-smoke-tests @@ -3132,6 +3653,20 @@ add_fp_unittest( ) add_fp_unittest( + remquobf16_test + SUITE + libc-math-smoke-tests + SRCS + remquobf16_test.cpp + HDRS + RemQuoTest.h + DEPENDS + libc.src.math.remquobf16 + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( hypotf_test SUITE libc-math-smoke-tests @@ -3248,6 +3783,22 @@ add_fp_unittest( ) add_fp_unittest( + nanbf16_test + SUITE + libc-math-smoke-tests + SRCS + nanbf16_test.cpp + DEPENDS + libc.hdr.signal_macros + libc.src.math.nanbf16 + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fp_bits + # FIXME: The nan tests currently have death tests, which aren't supported for + # hermetic tests. + UNIT_TEST_ONLY +) + +add_fp_unittest( nearbyint_test SUITE libc-math-smoke-tests @@ -3313,6 +3864,20 @@ add_fp_unittest( ) add_fp_unittest( + nearbyintbf16_test + SUITE + libc-math-smoke-tests + SRCS + nearbyintbf16_test.cpp + HDRS + NearbyIntTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.math.nearbyintbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( nextafter_test SUITE libc-math-smoke-tests @@ -3392,6 +3957,23 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + nextafterbf16_test + SUITE + libc-math-smoke-tests + SRCS + nextafterbf16_test.cpp + HDRS + NextAfterTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.math.nextafterbf16 + libc.src.__support.CPP.bit + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + # FIXME: These tests are currently spurious for the GPU. if(NOT LIBC_TARGET_OS_IS_GPU) add_fp_unittest( @@ -3460,6 +4042,23 @@ add_fp_unittest( ) add_fp_unittest( + nexttowardbf16_test + SUITE + libc-math-smoke-tests + SRCS + nexttowardbf16_test.cpp + HDRS + NextTowardTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.math.nexttowardbf16 + libc.src.__support.CPP.bit + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.fp_bits +) + +add_fp_unittest( nextdown_test SUITE libc-math-smoke-tests @@ -3520,6 +4119,19 @@ add_fp_unittest( ) add_fp_unittest( + nextdownbf16_test + SUITE + libc-math-smoke-tests + SRCS + nextdownbf16_test.cpp + HDRS + NextDownTest.h + DEPENDS + libc.src.math.nextdownbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( nextup_test SUITE libc-math-smoke-tests @@ -3579,6 +4191,19 @@ add_fp_unittest( libc.src.math.nextupf128 ) +add_fp_unittest( + nextupbf16_test + SUITE + libc-math-smoke-tests + SRCS + nextupbf16_test.cpp + HDRS + NextUpTest.h + DEPENDS + libc.src.math.nextupbf16 + libc.src.__support.FPUtil.bfloat16 +) + # TODO(lntue): The current implementation of fputil::general::fma<float> is only # correctly rounded for the default rounding mode round-to-nearest tie-to-even. add_fp_unittest( @@ -3879,6 +4504,23 @@ add_fp_unittest( ) add_fp_unittest( + fmodbf16_test + SUITE + libc-math-smoke-tests + SRCS + fmodbf16_test.cpp + HDRS + FModTest.h + DEPENDS + libc.hdr.fenv_macros + libc.src.errno.errno + libc.src.math.fmodbf16 + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.fenv_impl + UNIT_TEST_ONLY +) + +add_fp_unittest( coshf_test SUITE libc-math-smoke-tests @@ -3979,6 +4621,18 @@ add_fp_unittest( ) add_fp_unittest( + atanpif16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + atanpif16_test.cpp + DEPENDS + libc.src.math.atanpif16 + libc.src.errno.errno +) + +add_fp_unittest( asinhf_test SUITE libc-math-smoke-tests @@ -4002,6 +4656,18 @@ add_fp_unittest( ) add_fp_unittest( + asinpif16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + asinpif16_test.cpp + DEPENDS + libc.src.math.asinpif16 + libc.src.errno.errno +) + +add_fp_unittest( acoshf_test SUITE libc-math-smoke-tests @@ -4245,6 +4911,22 @@ add_fp_unittest( ) 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 libc-math-smoke-tests @@ -4320,6 +5002,22 @@ add_fp_unittest( ) 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 libc-math-smoke-tests @@ -4414,6 +5112,19 @@ add_fp_unittest( ) add_fp_unittest( + totalorderbf16_test + SUITE + libc-math-smoke-tests + SRCS + totalorderbf16_test.cpp + HDRS + TotalOrderTest.h + DEPENDS + libc.src.math.totalorderbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( totalordermag_test SUITE libc-math-smoke-tests @@ -4474,6 +5185,19 @@ add_fp_unittest( ) add_fp_unittest( + totalordermagbf16_test + SUITE + libc-math-smoke-tests + SRCS + totalordermagbf16_test.cpp + HDRS + TotalOrderMagTest.h + DEPENDS + libc.src.math.totalordermagbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( getpayload_test SUITE libc-math-smoke-tests @@ -4534,6 +5258,19 @@ add_fp_unittest( ) add_fp_unittest( + getpayloadbf16_test + SUITE + libc-math-smoke-tests + SRCS + getpayloadbf16_test.cpp + HDRS + GetPayloadTest.h + DEPENDS + libc.src.math.getpayloadbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( setpayload_test SUITE libc-math-smoke-tests @@ -4594,6 +5331,19 @@ add_fp_unittest( ) add_fp_unittest( + setpayloadbf16_test + SUITE + libc-math-smoke-tests + SRCS + setpayloadbf16_test.cpp + HDRS + SetPayloadTest.h + DEPENDS + libc.src.math.setpayloadbf16 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( setpayloadsig_test SUITE libc-math-smoke-tests @@ -4653,6 +5403,18 @@ add_fp_unittest( libc.src.math.setpayloadsigf128 ) +add_fp_unittest( + setpayloadsigbf16_test + SUITE + libc-math-smoke-tests + SRCS + setpayloadsigbf16_test.cpp + HDRS + SetPayloadTest.h + DEPENDS + libc.src.math.setpayloadsigbf16 + libc.src.__support.FPUtil.bfloat16 +) add_fp_unittest( f16add_test @@ -5307,6 +6069,69 @@ add_fp_unittest( ) add_fp_unittest( + bfloat16_add_test + SUITE + libc-math-smoke-tests + SRCS + bfloat16_add_test.cpp + HDRS + AddTest.h + DEPENDS + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.properties.os + libc.src.__support.macros.properties.types + libc.hdr.errno_macros + libc.hdr.fenv_macros +) + +add_fp_unittest( + bfloat16_div_test + SUITE + libc-math-smoke-tests + SRCS + bfloat16_div_test.cpp + HDRS + DivTest.h + DEPENDS + libc.src.__support.FPUtil.bfloat16 + libc.hdr.errno_macros + libc.hdr.fenv_macros +) + +add_fp_unittest( + bfloat16_mul_test + SUITE + libc-math-smoke-tests + SRCS + bfloat16_mul_test.cpp + HDRS + MulTest.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + libc.src.__support.FPUtil.bfloat16 + libc.hdr.errno_macros + libc.hdr.fenv_macros +) + +add_fp_unittest( + bfloat16_sub_test + SUITE + libc-math-smoke-tests + SRCS + bfloat16_sub_test.cpp + HDRS + SubTest.h + DEPENDS + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.FPUtil.generic.add_sub + libc.src.__support.macros.properties.os + libc.src.__support.macros.properties.types + libc.hdr.errno_macros + libc.hdr.fenv_macros +) + +add_fp_unittest( add_same_type_test SUITE libc-math-smoke-tests @@ -5337,3 +6162,312 @@ add_fp_unittest( libc.src.__support.macros.properties.os libc.src.__support.macros.properties.types ) + +add_fp_unittest( + bf16add_test + SUITE + libc-math-smoke-tests + SRCS + bf16add_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16add + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16addf_test + SUITE + libc-math-smoke-tests + SRCS + bf16addf_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16addf + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16addl_test + SUITE + libc-math-smoke-tests + SRCS + bf16addl_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16addl + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16addf128_test + SUITE + libc-math-smoke-tests + SRCS + bf16addf128_test.cpp + HDRS + AddTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16addf128 + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16fma_test + SUITE + libc-math-smoke-tests + SRCS + bf16fma_test.cpp + HDRS + FmaTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16fma + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16fmaf_test + SUITE + libc-math-smoke-tests + SRCS + bf16fmaf_test.cpp + HDRS + FmaTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16fmaf + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16fmal_test + SUITE + libc-math-smoke-tests + SRCS + bf16fmal_test.cpp + HDRS + FmaTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16fmal + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16fmaf128_test + SUITE + libc-math-smoke-tests + SRCS + bf16fmaf128_test.cpp + HDRS + FmaTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16fmaf128 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16div_test + SUITE + libc-math-smoke-tests + SRCS + bf16div_test.cpp + HDRS + DivTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16div + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16divf_test + SUITE + libc-math-smoke-tests + SRCS + bf16divf_test.cpp + HDRS + DivTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16divf + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16divl_test + SUITE + libc-math-smoke-tests + SRCS + bf16divl_test.cpp + HDRS + DivTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16divl + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16divf128_test + SUITE + libc-math-smoke-tests + SRCS + bf16divf128_test.cpp + HDRS + DivTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16divf128 + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16mul_test + SUITE + libc-math-smoke-tests + SRCS + bf16mul_test.cpp + HDRS + MulTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16mul + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16mulf_test + SUITE + libc-math-smoke-tests + SRCS + bf16mulf_test.cpp + HDRS + MulTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16mulf + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16mull_test + SUITE + libc-math-smoke-tests + SRCS + bf16mull_test.cpp + HDRS + MulTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16mull + libc.src.__support.FPUtil.bfloat16 +) + +add_fp_unittest( + bf16mulf128_test + SUITE + libc-math-smoke-tests + SRCS + bf16mulf128_test.cpp + HDRS + MulTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16mulf128 + libc.src.__support.FPUtil.bfloat16 +) + + +add_fp_unittest( + bf16sub_test + SUITE + libc-math-smoke-tests + SRCS + bf16sub_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16sub + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16subf_test + SUITE + libc-math-smoke-tests + SRCS + bf16subf_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16subf + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16subl_test + SUITE + libc-math-smoke-tests + SRCS + bf16subl_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16subl + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) + +add_fp_unittest( + bf16subf128_test + SUITE + libc-math-smoke-tests + SRCS + bf16subf128_test.cpp + HDRS + SubTest.h + DEPENDS + libc.hdr.errno_macros + libc.hdr.fenv_macros + libc.src.math.bf16subf128 + libc.src.__support.FPUtil.bfloat16 + libc.src.__support.macros.properties.os +) diff --git a/libc/test/src/math/smoke/CeilTest.h b/libc/test/src/math/smoke/CeilTest.h index 7998eab..1839db9 100644 --- a/libc/test/src/math/smoke/CeilTest.h +++ b/libc/test/src/math/smoke/CeilTest.h @@ -59,10 +59,12 @@ public: 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/DivTest.h b/libc/test/src/math/smoke/DivTest.h index d807479..ff82f68 100644 --- a/libc/test/src/math/smoke/DivTest.h +++ b/libc/test/src/math/smoke/DivTest.h @@ -47,6 +47,11 @@ public: EXPECT_FP_EQ(neg_inf, func(in.neg_inf, in.zero)); EXPECT_FP_EQ(neg_inf, func(in.inf, in.neg_zero)); EXPECT_FP_EQ(inf, func(in.neg_inf, in.neg_zero)); + EXPECT_FP_EQ(zero, func(in.min_normal, in.inf)); + EXPECT_FP_EQ(zero, func(in.zero, in.inf)); + EXPECT_FP_EQ(zero, func(in.neg_zero, in.neg_inf)); + EXPECT_FP_EQ(neg_zero, func(in.min_normal, in.neg_inf)); + EXPECT_FP_EQ(neg_zero, func(in.zero, in.neg_inf)); } void test_division_by_zero(DivFunc func) { diff --git a/libc/test/src/math/smoke/FModTest.h b/libc/test/src/math/smoke/FModTest.h index 04cbc65..e74ee09 100644 --- a/libc/test/src/math/smoke/FModTest.h +++ b/libc/test/src/math/smoke/FModTest.h @@ -31,12 +31,22 @@ class FmodTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { DECLARE_SPECIAL_CONSTANTS(T) + static constexpr T one = T(1.0); + static constexpr T two = T(2.0); + static constexpr T neg_two = T(-2.0); + static constexpr T three = T(3.0); + static constexpr T val_neg_1_1 = T(-1.1); + static constexpr T val_6_5 = T(6.5); + static constexpr T val_neg_6_5 = T(-6.5); + static constexpr T val_2_25 = T(2.25); + static constexpr T val_neg_2_25 = T(-2.25); + public: typedef T (*FModFunc)(T, T); void testSpecialNumbers(FModFunc f) { // fmod (+0, y) == +0 for y != 0. - TEST_SPECIAL(zero, T(3.0), zero, false, 0); + TEST_SPECIAL(zero, three, zero, false, 0); TEST_SPECIAL(zero, min_denormal, zero, false, 0); TEST_SPECIAL(zero, -min_denormal, zero, false, 0); TEST_SPECIAL(zero, min_normal, zero, false, 0); @@ -45,7 +55,7 @@ public: TEST_SPECIAL(zero, -max_normal, zero, false, 0); // fmod (-0, y) == -0 for y != 0. - TEST_SPECIAL(neg_zero, T(3.0), neg_zero, false, 0); + TEST_SPECIAL(neg_zero, three, neg_zero, false, 0); TEST_SPECIAL(neg_zero, min_denormal, neg_zero, false, 0); TEST_SPECIAL(neg_zero, -min_denormal, neg_zero, false, 0); TEST_SPECIAL(neg_zero, min_normal, neg_zero, false, 0); @@ -54,8 +64,8 @@ public: TEST_SPECIAL(neg_zero, -max_normal, neg_zero, false, 0); // fmod (+inf, y) == aNaN plus invalid exception. - TEST_SPECIAL(inf, T(3.0), aNaN, true, FE_INVALID); - TEST_SPECIAL(inf, T(-1.1), aNaN, true, FE_INVALID); + TEST_SPECIAL(inf, three, aNaN, true, FE_INVALID); + TEST_SPECIAL(inf, val_neg_1_1, aNaN, true, FE_INVALID); TEST_SPECIAL(inf, zero, aNaN, true, FE_INVALID); TEST_SPECIAL(inf, neg_zero, aNaN, true, FE_INVALID); TEST_SPECIAL(inf, min_denormal, aNaN, true, FE_INVALID); @@ -65,8 +75,8 @@ public: TEST_SPECIAL(inf, neg_inf, aNaN, true, FE_INVALID); // fmod (-inf, y) == aNaN plus invalid exception. - TEST_SPECIAL(neg_inf, T(3.0), aNaN, true, FE_INVALID); - TEST_SPECIAL(neg_inf, T(-1.1), aNaN, true, FE_INVALID); + TEST_SPECIAL(neg_inf, three, aNaN, true, FE_INVALID); + TEST_SPECIAL(neg_inf, val_neg_1_1, aNaN, true, FE_INVALID); TEST_SPECIAL(neg_inf, zero, aNaN, true, FE_INVALID); TEST_SPECIAL(neg_inf, neg_zero, aNaN, true, FE_INVALID); TEST_SPECIAL(neg_inf, min_denormal, aNaN, true, FE_INVALID); @@ -76,8 +86,8 @@ public: TEST_SPECIAL(neg_inf, neg_inf, aNaN, true, FE_INVALID); // fmod (x, +0) == aNaN plus invalid exception. - TEST_SPECIAL(T(3.0), zero, aNaN, true, FE_INVALID); - TEST_SPECIAL(T(-1.1), zero, aNaN, true, FE_INVALID); + TEST_SPECIAL(three, zero, aNaN, true, FE_INVALID); + TEST_SPECIAL(val_neg_1_1, zero, aNaN, true, FE_INVALID); TEST_SPECIAL(zero, zero, aNaN, true, FE_INVALID); TEST_SPECIAL(neg_zero, zero, aNaN, true, FE_INVALID); TEST_SPECIAL(min_denormal, zero, aNaN, true, FE_INVALID); @@ -85,8 +95,8 @@ public: TEST_SPECIAL(max_normal, zero, aNaN, true, FE_INVALID); // fmod (x, -0) == aNaN plus invalid exception. - TEST_SPECIAL(T(3.0), neg_zero, aNaN, true, FE_INVALID); - TEST_SPECIAL(T(-1.1), neg_zero, aNaN, true, FE_INVALID); + TEST_SPECIAL(three, neg_zero, aNaN, true, FE_INVALID); + TEST_SPECIAL(val_neg_1_1, neg_zero, aNaN, true, FE_INVALID); TEST_SPECIAL(zero, neg_zero, aNaN, true, FE_INVALID); TEST_SPECIAL(neg_zero, neg_zero, aNaN, true, FE_INVALID); TEST_SPECIAL(min_denormal, neg_zero, aNaN, true, FE_INVALID); @@ -99,21 +109,21 @@ public: TEST_SPECIAL(min_denormal, inf, min_denormal, false, 0); TEST_SPECIAL(min_normal, inf, min_normal, false, 0); TEST_SPECIAL(max_normal, inf, max_normal, false, 0); - TEST_SPECIAL(T(3.0), inf, T(3.0), false, 0); + TEST_SPECIAL(three, inf, three, false, 0); // fmod (x, -inf) == x for x not infinite. TEST_SPECIAL(zero, neg_inf, zero, false, 0); TEST_SPECIAL(neg_zero, neg_inf, neg_zero, false, 0); TEST_SPECIAL(min_denormal, neg_inf, min_denormal, false, 0); TEST_SPECIAL(min_normal, neg_inf, min_normal, false, 0); TEST_SPECIAL(max_normal, neg_inf, max_normal, false, 0); - TEST_SPECIAL(T(3.0), neg_inf, T(3.0), false, 0); + TEST_SPECIAL(three, neg_inf, three, false, 0); TEST_SPECIAL(zero, aNaN, aNaN, false, 0); TEST_SPECIAL(zero, neg_aNaN, aNaN, false, 0); TEST_SPECIAL(neg_zero, aNaN, aNaN, false, 0); TEST_SPECIAL(neg_zero, neg_aNaN, aNaN, false, 0); - TEST_SPECIAL(T(1.0), aNaN, aNaN, false, 0); - TEST_SPECIAL(T(1.0), neg_aNaN, aNaN, false, 0); + TEST_SPECIAL(one, aNaN, aNaN, false, 0); + TEST_SPECIAL(one, neg_aNaN, aNaN, false, 0); TEST_SPECIAL(inf, aNaN, aNaN, false, 0); TEST_SPECIAL(inf, neg_aNaN, aNaN, false, 0); TEST_SPECIAL(neg_inf, aNaN, aNaN, false, 0); @@ -122,8 +132,8 @@ public: TEST_SPECIAL(zero, neg_sNaN, aNaN, false, FE_INVALID); TEST_SPECIAL(neg_zero, sNaN, aNaN, false, FE_INVALID); TEST_SPECIAL(neg_zero, neg_sNaN, aNaN, false, FE_INVALID); - TEST_SPECIAL(T(1.0), sNaN, aNaN, false, FE_INVALID); - TEST_SPECIAL(T(1.0), neg_sNaN, aNaN, false, FE_INVALID); + TEST_SPECIAL(one, sNaN, aNaN, false, FE_INVALID); + TEST_SPECIAL(one, neg_sNaN, aNaN, false, FE_INVALID); TEST_SPECIAL(inf, sNaN, aNaN, false, FE_INVALID); TEST_SPECIAL(inf, neg_sNaN, aNaN, false, FE_INVALID); TEST_SPECIAL(neg_inf, sNaN, aNaN, false, FE_INVALID); @@ -132,8 +142,8 @@ public: TEST_SPECIAL(neg_aNaN, zero, aNaN, false, 0); TEST_SPECIAL(aNaN, neg_zero, aNaN, false, 0); TEST_SPECIAL(neg_aNaN, neg_zero, aNaN, false, 0); - TEST_SPECIAL(aNaN, T(1.0), aNaN, false, 0); - TEST_SPECIAL(neg_aNaN, T(1.0), aNaN, false, 0); + TEST_SPECIAL(aNaN, one, aNaN, false, 0); + TEST_SPECIAL(neg_aNaN, one, aNaN, false, 0); TEST_SPECIAL(aNaN, inf, aNaN, false, 0); TEST_SPECIAL(neg_aNaN, inf, aNaN, false, 0); TEST_SPECIAL(aNaN, neg_inf, aNaN, false, 0); @@ -142,8 +152,8 @@ public: TEST_SPECIAL(neg_sNaN, zero, aNaN, false, FE_INVALID); TEST_SPECIAL(sNaN, neg_zero, aNaN, false, FE_INVALID); TEST_SPECIAL(neg_sNaN, neg_zero, aNaN, false, FE_INVALID); - TEST_SPECIAL(sNaN, T(1.0), aNaN, false, FE_INVALID); - TEST_SPECIAL(neg_sNaN, T(1.0), aNaN, false, FE_INVALID); + TEST_SPECIAL(sNaN, one, aNaN, false, FE_INVALID); + TEST_SPECIAL(neg_sNaN, one, aNaN, false, FE_INVALID); TEST_SPECIAL(sNaN, inf, aNaN, false, FE_INVALID); TEST_SPECIAL(neg_sNaN, inf, aNaN, false, FE_INVALID); TEST_SPECIAL(sNaN, neg_inf, aNaN, false, FE_INVALID); @@ -165,10 +175,10 @@ public: TEST_SPECIAL(neg_sNaN, sNaN, aNaN, false, FE_INVALID); TEST_SPECIAL(neg_sNaN, neg_sNaN, aNaN, false, FE_INVALID); - TEST_SPECIAL(T(6.5), T(2.25), T(2.0), false, 0); - TEST_SPECIAL(T(-6.5), T(2.25), T(-2.0), false, 0); - TEST_SPECIAL(T(6.5), T(-2.25), T(2.0), false, 0); - TEST_SPECIAL(T(-6.5), T(-2.25), T(-2.0), false, 0); + TEST_SPECIAL(val_6_5, val_2_25, two, false, 0); + TEST_SPECIAL(val_neg_6_5, val_2_25, neg_two, false, 0); + TEST_SPECIAL(val_6_5, val_neg_2_25, two, false, 0); + TEST_SPECIAL(val_neg_6_5, val_neg_2_25, neg_two, false, 0); TEST_SPECIAL(max_normal, max_normal, zero, false, 0); TEST_SPECIAL(max_normal, -max_normal, zero, false, 0); diff --git a/libc/test/src/math/smoke/FloorTest.h b/libc/test/src/math/smoke/FloorTest.h index bc19e4f..cbcf276 100644 --- a/libc/test/src/math/smoke/FloorTest.h +++ b/libc/test/src/math/smoke/FloorTest.h @@ -59,10 +59,11 @@ public: 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/FromfpTest.h b/libc/test/src/math/smoke/FromfpTest.h index 5620518..708ec25 100644 --- a/libc/test/src/math/smoke/FromfpTest.h +++ b/libc/test/src/math/smoke/FromfpTest.h @@ -85,10 +85,10 @@ public: EXPECT_FP_EQ(T(-10.0), func(T(-10.32), FP_INT_UPWARD, 5U)); EXPECT_FP_EQ(T(11.0), func(T(10.65), FP_INT_UPWARD, 5U)); EXPECT_FP_EQ(T(-10.0), func(T(-10.65), FP_INT_UPWARD, 5U)); - EXPECT_FP_EQ(T(124.0), func(T(123.38), FP_INT_UPWARD, 8U)); - EXPECT_FP_EQ(T(-123.0), func(T(-123.38), FP_INT_UPWARD, 8U)); - EXPECT_FP_EQ(T(124.0), func(T(123.96), FP_INT_UPWARD, 8U)); - EXPECT_FP_EQ(T(-123.0), func(T(-123.96), FP_INT_UPWARD, 8U)); + EXPECT_FP_EQ(T(64.0), func(T(63.25), FP_INT_UPWARD, 8U)); + EXPECT_FP_EQ(T(-63.0), func(T(-63.25), FP_INT_UPWARD, 8U)); + EXPECT_FP_EQ(T(64.0), func(T(63.75), FP_INT_UPWARD, 8U)); + EXPECT_FP_EQ(T(-63.0), func(T(-63.75), FP_INT_UPWARD, 8U)); } void testFractionsUpwardOutsideRange(FromfpFunc func) { @@ -139,10 +139,10 @@ public: EXPECT_FP_EQ(T(-11.0), func(T(-10.32), FP_INT_DOWNWARD, 5U)); EXPECT_FP_EQ(T(10.0), func(T(10.65), FP_INT_DOWNWARD, 5U)); EXPECT_FP_EQ(T(-11.0), func(T(-10.65), FP_INT_DOWNWARD, 5U)); - EXPECT_FP_EQ(T(123.0), func(T(123.38), FP_INT_DOWNWARD, 8U)); - EXPECT_FP_EQ(T(-124.0), func(T(-123.38), FP_INT_DOWNWARD, 8U)); - EXPECT_FP_EQ(T(123.0), func(T(123.96), FP_INT_DOWNWARD, 8U)); - EXPECT_FP_EQ(T(-124.0), func(T(-123.96), FP_INT_DOWNWARD, 8U)); + EXPECT_FP_EQ(T(63.0), func(T(63.25), FP_INT_DOWNWARD, 8U)); + EXPECT_FP_EQ(T(-64.0), func(T(-63.25), FP_INT_DOWNWARD, 8U)); + EXPECT_FP_EQ(T(63.0), func(T(63.75), FP_INT_DOWNWARD, 8U)); + EXPECT_FP_EQ(T(-64.0), func(T(-63.75), FP_INT_DOWNWARD, 8U)); } void testFractionsDownwardOutsideRange(FromfpFunc func) { @@ -193,10 +193,10 @@ public: EXPECT_FP_EQ(T(-10.0), func(T(-10.32), FP_INT_TOWARDZERO, 5U)); EXPECT_FP_EQ(T(10.0), func(T(10.65), FP_INT_TOWARDZERO, 5U)); EXPECT_FP_EQ(T(-10.0), func(T(-10.65), FP_INT_TOWARDZERO, 5U)); - EXPECT_FP_EQ(T(123.0), func(T(123.38), FP_INT_TOWARDZERO, 8U)); - EXPECT_FP_EQ(T(-123.0), func(T(-123.38), FP_INT_TOWARDZERO, 8U)); - EXPECT_FP_EQ(T(123.0), func(T(123.96), FP_INT_TOWARDZERO, 8U)); - EXPECT_FP_EQ(T(-123.0), func(T(-123.96), FP_INT_TOWARDZERO, 8U)); + EXPECT_FP_EQ(T(63.0), func(T(63.25), FP_INT_TOWARDZERO, 8U)); + EXPECT_FP_EQ(T(-63.0), func(T(-63.25), FP_INT_TOWARDZERO, 8U)); + EXPECT_FP_EQ(T(63.0), func(T(63.75), FP_INT_TOWARDZERO, 8U)); + EXPECT_FP_EQ(T(-63.0), func(T(-63.75), FP_INT_TOWARDZERO, 8U)); } void testFractionsTowardZeroOutsideRange(FromfpFunc func) { @@ -241,10 +241,10 @@ public: EXPECT_FP_EQ(T(-10.0), func(T(-10.32), FP_INT_TONEARESTFROMZERO, 5U)); EXPECT_FP_EQ(T(11.0), func(T(10.65), FP_INT_TONEARESTFROMZERO, 5U)); EXPECT_FP_EQ(T(-11.0), func(T(-10.65), FP_INT_TONEARESTFROMZERO, 5U)); - EXPECT_FP_EQ(T(123.0), func(T(123.38), FP_INT_TONEARESTFROMZERO, 8U)); - EXPECT_FP_EQ(T(-123.0), func(T(-123.38), FP_INT_TONEARESTFROMZERO, 8U)); - EXPECT_FP_EQ(T(124.0), func(T(123.96), FP_INT_TONEARESTFROMZERO, 8U)); - EXPECT_FP_EQ(T(-124.0), func(T(-123.96), FP_INT_TONEARESTFROMZERO, 8U)); + EXPECT_FP_EQ(T(63.0), func(T(63.25), FP_INT_TONEARESTFROMZERO, 8U)); + EXPECT_FP_EQ(T(-63.0), func(T(-63.25), FP_INT_TONEARESTFROMZERO, 8U)); + EXPECT_FP_EQ(T(64.0), func(T(63.75), FP_INT_TONEARESTFROMZERO, 8U)); + EXPECT_FP_EQ(T(-64.0), func(T(-63.75), FP_INT_TONEARESTFROMZERO, 8U)); } void testFractionsToNearestFromZeroOutsideRange(FromfpFunc func) { @@ -297,10 +297,10 @@ public: EXPECT_FP_EQ(T(-10.0), func(T(-10.32), FP_INT_TONEAREST, 5U)); EXPECT_FP_EQ(T(11.0), func(T(10.65), FP_INT_TONEAREST, 5U)); EXPECT_FP_EQ(T(-11.0), func(T(-10.65), FP_INT_TONEAREST, 5U)); - EXPECT_FP_EQ(T(123.0), func(T(123.38), FP_INT_TONEAREST, 8U)); - EXPECT_FP_EQ(T(-123.0), func(T(-123.38), FP_INT_TONEAREST, 8U)); - EXPECT_FP_EQ(T(124.0), func(T(123.96), FP_INT_TONEAREST, 8U)); - EXPECT_FP_EQ(T(-124.0), func(T(-123.96), FP_INT_TONEAREST, 8U)); + EXPECT_FP_EQ(T(63.0), func(T(63.25), FP_INT_TONEAREST, 8U)); + EXPECT_FP_EQ(T(-63.0), func(T(-63.25), FP_INT_TONEAREST, 8U)); + EXPECT_FP_EQ(T(64.0), func(T(63.75), FP_INT_TONEAREST, 8U)); + EXPECT_FP_EQ(T(-64.0), func(T(-63.75), FP_INT_TONEAREST, 8U)); EXPECT_FP_EQ(T(2.0), func(T(2.3), FP_INT_TONEAREST, 3U)); EXPECT_FP_EQ(T(-2.0), func(T(-2.3), FP_INT_TONEAREST, 2U)); @@ -391,14 +391,12 @@ public: EXPECT_FP_EQ(T(11.0), func(T(10.65), UNKNOWN_MATH_ROUNDING_DIRECTION, 5U)); EXPECT_FP_EQ(T(-11.0), func(T(-10.65), UNKNOWN_MATH_ROUNDING_DIRECTION, 5U)); - EXPECT_FP_EQ(T(123.0), - func(T(123.38), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U)); - EXPECT_FP_EQ(T(-123.0), - func(T(-123.38), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U)); - EXPECT_FP_EQ(T(124.0), - func(T(123.96), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U)); - EXPECT_FP_EQ(T(-124.0), - func(T(-123.96), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U)); + EXPECT_FP_EQ(T(63.0), func(T(63.25), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U)); + EXPECT_FP_EQ(T(-63.0), + func(T(-63.25), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U)); + EXPECT_FP_EQ(T(64.0), func(T(63.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U)); + EXPECT_FP_EQ(T(-64.0), + func(T(-63.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U)); EXPECT_FP_EQ(T(2.0), func(T(2.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U)); EXPECT_FP_EQ(T(-2.0), func(T(-2.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U)); diff --git a/libc/test/src/math/smoke/FromfpxTest.h b/libc/test/src/math/smoke/FromfpxTest.h index a175a66..1930b22 100644 --- a/libc/test/src/math/smoke/FromfpxTest.h +++ b/libc/test/src/math/smoke/FromfpxTest.h @@ -101,13 +101,13 @@ public: FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION(T(-10.0), func(T(-10.65), FP_INT_UPWARD, 5U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(124.0), func(T(123.38), FP_INT_UPWARD, 8U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(64.0), func(T(63.25), FP_INT_UPWARD, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(-123.0), func(T(-123.38), FP_INT_UPWARD, 8U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(-63.0), func(T(-63.25), FP_INT_UPWARD, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(124.0), func(T(123.96), FP_INT_UPWARD, 8U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(64.0), func(T(63.75), FP_INT_UPWARD, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(-123.0), func(T(-123.96), FP_INT_UPWARD, 8U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(-63.0), func(T(-63.75), FP_INT_UPWARD, 8U), FE_INEXACT); } @@ -175,14 +175,14 @@ public: FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION(T(-11.0), func(T(-10.65), FP_INT_DOWNWARD, 5U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(123.0), func(T(123.38), FP_INT_DOWNWARD, 8U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(63.0), func(T(63.25), FP_INT_DOWNWARD, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION( - T(-124.0), func(T(-123.38), FP_INT_DOWNWARD, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(123.0), func(T(123.96), FP_INT_DOWNWARD, 8U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(-64.0), func(T(-63.25), FP_INT_DOWNWARD, 8U), + FE_INEXACT); + EXPECT_FP_EQ_WITH_EXCEPTION(T(63.0), func(T(63.75), FP_INT_DOWNWARD, 8U), + FE_INEXACT); + EXPECT_FP_EQ_WITH_EXCEPTION(T(-64.0), func(T(-63.75), FP_INT_DOWNWARD, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION( - T(-124.0), func(T(-123.96), FP_INT_DOWNWARD, 8U), FE_INEXACT); } void testFractionsDownwardOutsideRange(FromfpxFunc func) { @@ -249,14 +249,14 @@ public: FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( T(-10.0), func(T(-10.65), FP_INT_TOWARDZERO, 5U), FE_INEXACT); + EXPECT_FP_EQ_WITH_EXCEPTION(T(63.0), func(T(63.25), FP_INT_TOWARDZERO, 8U), + FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(123.0), func(T(123.38), FP_INT_TOWARDZERO, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION( - T(-123.0), func(T(-123.38), FP_INT_TOWARDZERO, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION( - T(123.0), func(T(123.96), FP_INT_TOWARDZERO, 8U), FE_INEXACT); + T(-63.0), func(T(-63.25), FP_INT_TOWARDZERO, 8U), FE_INEXACT); + EXPECT_FP_EQ_WITH_EXCEPTION(T(63.0), func(T(63.75), FP_INT_TOWARDZERO, 8U), + FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(-123.0), func(T(-123.96), FP_INT_TOWARDZERO, 8U), FE_INEXACT); + T(-63.0), func(T(-63.75), FP_INT_TOWARDZERO, 8U), FE_INEXACT); } void testFractionsTowardZeroOutsideRange(FromfpxFunc func) { @@ -318,13 +318,13 @@ public: EXPECT_FP_EQ_WITH_EXCEPTION( T(-11.0), func(T(-10.65), FP_INT_TONEARESTFROMZERO, 5U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(123.0), func(T(123.38), FP_INT_TONEARESTFROMZERO, 8U), FE_INEXACT); + T(63.0), func(T(63.25), FP_INT_TONEARESTFROMZERO, 8U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(-123.0), func(T(-123.38), FP_INT_TONEARESTFROMZERO, 8U), FE_INEXACT); + T(-63.0), func(T(-63.25), FP_INT_TONEARESTFROMZERO, 8U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(124.0), func(T(123.96), FP_INT_TONEARESTFROMZERO, 8U), FE_INEXACT); + T(64.0), func(T(63.75), FP_INT_TONEARESTFROMZERO, 8U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(-124.0), func(T(-123.96), FP_INT_TONEARESTFROMZERO, 8U), FE_INEXACT); + T(-64.0), func(T(-63.75), FP_INT_TONEARESTFROMZERO, 8U), FE_INEXACT); } void testFractionsToNearestFromZeroOutsideRange(FromfpxFunc func) { @@ -393,14 +393,14 @@ public: FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION(T(-11.0), func(T(-10.65), FP_INT_TONEAREST, 5U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(123.0), func(T(123.38), FP_INT_TONEAREST, 8U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(63.0), func(T(63.25), FP_INT_TONEAREST, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION( - T(-123.0), func(T(-123.38), FP_INT_TONEAREST, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(124.0), func(T(123.96), FP_INT_TONEAREST, 8U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(-63.0), func(T(-63.25), FP_INT_TONEAREST, 8U), + FE_INEXACT); + EXPECT_FP_EQ_WITH_EXCEPTION(T(64.0), func(T(63.75), FP_INT_TONEAREST, 8U), + FE_INEXACT); + EXPECT_FP_EQ_WITH_EXCEPTION(T(-64.0), func(T(-63.75), FP_INT_TONEAREST, 8U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION( - T(-124.0), func(T(-123.96), FP_INT_TONEAREST, 8U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION(T(2.0), func(T(2.3), FP_INT_TONEAREST, 3U), FE_INEXACT); @@ -530,16 +530,16 @@ public: T(-11.0), func(T(-10.65), UNKNOWN_MATH_ROUNDING_DIRECTION, 5U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(123.0), func(T(123.38), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U), + T(63.0), func(T(63.25), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(-123.0), func(T(-123.38), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U), + T(-63.0), func(T(-63.25), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(124.0), func(T(123.96), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U), + T(64.0), func(T(63.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(-124.0), func(T(-123.96), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U), + T(-64.0), func(T(-63.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 8U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( diff --git a/libc/test/src/math/smoke/GetPayloadTest.h b/libc/test/src/math/smoke/GetPayloadTest.h index 1b1bf4f..486ea42 100644 --- a/libc/test/src/math/smoke/GetPayloadTest.h +++ b/libc/test/src/math/smoke/GetPayloadTest.h @@ -51,23 +51,50 @@ public: EXPECT_FP_EQ(default_snan_payload, funcWrapper(func, sNaN)); EXPECT_FP_EQ(default_snan_payload, funcWrapper(func, neg_sNaN)); - T qnan_42 = FPBits::quiet_nan(Sign::POS, 0x42).get_val(); - T neg_qnan_42 = FPBits::quiet_nan(Sign::NEG, 0x42).get_val(); - T snan_42 = FPBits::signaling_nan(Sign::POS, 0x42).get_val(); - T neg_snan_42 = FPBits::signaling_nan(Sign::NEG, 0x42).get_val(); - EXPECT_FP_EQ(T(0x42.0p+0), funcWrapper(func, qnan_42)); - EXPECT_FP_EQ(T(0x42.0p+0), funcWrapper(func, neg_qnan_42)); - EXPECT_FP_EQ(T(0x42.0p+0), funcWrapper(func, snan_42)); - EXPECT_FP_EQ(T(0x42.0p+0), funcWrapper(func, neg_snan_42)); - - T qnan_123 = FPBits::quiet_nan(Sign::POS, 0x123).get_val(); - T neg_qnan_123 = FPBits::quiet_nan(Sign::NEG, 0x123).get_val(); - T snan_123 = FPBits::signaling_nan(Sign::POS, 0x123).get_val(); - T neg_snan_123 = FPBits::signaling_nan(Sign::NEG, 0x123).get_val(); - EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, qnan_123)); - EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, neg_qnan_123)); - EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, snan_123)); - EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, neg_snan_123)); + if constexpr (FPBits::FRACTION_LEN - 1 >= 6) { + // [S] [E..E] [QM..M] -> number of M bits should be at least 6 + // 0x31 = 0b110001 = 6 bits + T qnan_31 = FPBits::quiet_nan(Sign::POS, 0x31).get_val(); + T neg_qnan_31 = FPBits::quiet_nan(Sign::NEG, 0x31).get_val(); + T snan_31 = FPBits::signaling_nan(Sign::POS, 0x31).get_val(); + T neg_snan_31 = FPBits::signaling_nan(Sign::NEG, 0x31).get_val(); + EXPECT_FP_EQ(T(0x31.0p+0), funcWrapper(func, qnan_31)); + EXPECT_FP_EQ(T(0x31.0p+0), funcWrapper(func, neg_qnan_31)); + EXPECT_FP_EQ(T(0x31.0p+0), funcWrapper(func, snan_31)); + EXPECT_FP_EQ(T(0x31.0p+0), funcWrapper(func, neg_snan_31)); + + // 0x15 = 0b10101 = 5 bits + T qnan_15 = FPBits::quiet_nan(Sign::POS, 0x15).get_val(); + T neg_qnan_15 = FPBits::quiet_nan(Sign::NEG, 0x15).get_val(); + T snan_15 = FPBits::signaling_nan(Sign::POS, 0x15).get_val(); + T neg_snan_15 = FPBits::signaling_nan(Sign::NEG, 0x15).get_val(); + EXPECT_FP_EQ(T(0x15.0p+0), funcWrapper(func, qnan_15)); + EXPECT_FP_EQ(T(0x15.0p+0), funcWrapper(func, neg_qnan_15)); + EXPECT_FP_EQ(T(0x15.0p+0), funcWrapper(func, snan_15)); + EXPECT_FP_EQ(T(0x15.0p+0), funcWrapper(func, neg_snan_15)); + } + + if constexpr (FPBits::FRACTION_LEN - 1 >= 7) { + T qnan_42 = FPBits::quiet_nan(Sign::POS, 0x42).get_val(); + T neg_qnan_42 = FPBits::quiet_nan(Sign::NEG, 0x42).get_val(); + T snan_42 = FPBits::signaling_nan(Sign::POS, 0x42).get_val(); + T neg_snan_42 = FPBits::signaling_nan(Sign::NEG, 0x42).get_val(); + EXPECT_FP_EQ(T(0x42.0p+0), funcWrapper(func, qnan_42)); + EXPECT_FP_EQ(T(0x42.0p+0), funcWrapper(func, neg_qnan_42)); + EXPECT_FP_EQ(T(0x42.0p+0), funcWrapper(func, snan_42)); + EXPECT_FP_EQ(T(0x42.0p+0), funcWrapper(func, neg_snan_42)); + } + + if constexpr (FPBits::FRACTION_LEN - 1 >= 9) { + T qnan_123 = FPBits::quiet_nan(Sign::POS, 0x123).get_val(); + T neg_qnan_123 = FPBits::quiet_nan(Sign::NEG, 0x123).get_val(); + T snan_123 = FPBits::signaling_nan(Sign::POS, 0x123).get_val(); + T neg_snan_123 = FPBits::signaling_nan(Sign::NEG, 0x123).get_val(); + EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, qnan_123)); + EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, neg_qnan_123)); + EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, snan_123)); + EXPECT_FP_EQ(T(0x123.0p+0), funcWrapper(func, neg_snan_123)); + } } }; diff --git a/libc/test/src/math/smoke/LdExpTest.h b/libc/test/src/math/smoke/LdExpTest.h index 8de70ad..d005f05 100644 --- a/libc/test/src/math/smoke/LdExpTest.h +++ b/libc/test/src/math/smoke/LdExpTest.h @@ -10,7 +10,8 @@ #define LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H #include "hdr/stdint_proxy.h" -#include "src/__support/CPP/limits.h" // INT_MAX +#include "src/__support/CPP/algorithm.h" // cpp::min +#include "src/__support/CPP/limits.h" // INT_MAX #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/NormalFloat.h" #include "test/UnitTest/FEnvSafeTest.h" @@ -135,8 +136,8 @@ public: // Normal which trigger mantissa overflow. T x = NormalFloat(Sign::POS, -FPBits::EXP_BIAS + 1, StorageType(2) * NormalFloat::ONE - StorageType(1)); - ASSERT_FP_EQ(func(x, -1), x / 2); - ASSERT_FP_EQ(func(-x, -1), -x / 2); + ASSERT_FP_EQ(func(x, -1), T(x / 2)); + ASSERT_FP_EQ(func(-x, -1), -T(x / 2)); // Start with a normal number high exponent but pass a very low number for // exp. The result should be a subnormal number. @@ -154,7 +155,9 @@ public: // Start with a subnormal number but pass a very high number for exponent. // The result should not be infinity. - x = NormalFloat(Sign::POS, -FPBits::EXP_BIAS + 1, NormalFloat::ONE >> 10); + x = NormalFloat(Sign::POS, -FPBits::EXP_BIAS + 1, + NormalFloat::ONE >> + LIBC_NAMESPACE::cpp::min(FPBits::FRACTION_LEN, 10)); exp = FPBits::MAX_BIASED_EXPONENT + 5; ASSERT_FALSE(FPBits(func(x, exp)).is_inf()); // But if the exp is large enough to oversome than the normalization shift, diff --git a/libc/test/src/math/smoke/ModfTest.h b/libc/test/src/math/smoke/ModfTest.h index 24cfb115..71f1c6b 100644 --- a/libc/test/src/math/smoke/ModfTest.h +++ b/libc/test/src/math/smoke/ModfTest.h @@ -76,10 +76,16 @@ public: EXPECT_FP_EQ(T(-0.75), func(T(-10.75), &integral)); EXPECT_FP_EQ(integral, T(-10.0)); - EXPECT_FP_EQ(T(0.125), func(T(100.125), &integral)); + EXPECT_FP_EQ(T(0.125), func(T(31.125), &integral)); + EXPECT_FP_EQ(integral, T(31.0)); + + EXPECT_FP_EQ(T(-0.125), func(T(-31.125), &integral)); + EXPECT_FP_EQ(integral, T(-31.0)); + + EXPECT_FP_EQ(T(0.5), func(T(100.5), &integral)); EXPECT_FP_EQ(integral, T(100.0)); - EXPECT_FP_EQ(T(-0.125), func(T(-100.125), &integral)); + EXPECT_FP_EQ(T(-0.5), func(T(-100.5), &integral)); EXPECT_FP_EQ(integral, T(-100.0)); } diff --git a/libc/test/src/math/smoke/MulTest.h b/libc/test/src/math/smoke/MulTest.h index cf7f41a..5020067 100644 --- a/libc/test/src/math/smoke/MulTest.h +++ b/libc/test/src/math/smoke/MulTest.h @@ -53,10 +53,12 @@ public: EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, func(in.zero, in.neg_zero)); EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, func(in.neg_zero, in.zero)); - EXPECT_FP_EQ_ALL_ROUNDING(OutType(1.0), func(1.0, 1.0)); - EXPECT_FP_EQ_ALL_ROUNDING(OutType(15.0), func(3.0, 5.0)); - EXPECT_FP_EQ_ALL_ROUNDING(OutType(0x1.0p-13), func(0x1.0p+1, 0x1.0p-14)); - EXPECT_FP_EQ_ALL_ROUNDING(OutType(0x1.0p-10), func(0x1.0p+2, 0x1.0p-12)); + EXPECT_FP_EQ_ALL_ROUNDING(OutType(1.0), func(InType(1.0), InType(1.0))); + EXPECT_FP_EQ_ALL_ROUNDING(OutType(15.0), func(InType(3.0), InType(5.0))); + EXPECT_FP_EQ_ALL_ROUNDING(OutType(0x1.0p-13), + func(InType(0x1.0p+1), InType(0x1.0p-14))); + EXPECT_FP_EQ_ALL_ROUNDING(OutType(0x1.0p-10), + func(InType(0x1.0p+2), InType(0x1.0p-12))); } void test_invalid_operations(MulFunc func) { diff --git a/libc/test/src/math/smoke/NextAfterTest.h b/libc/test/src/math/smoke/NextAfterTest.h index be27c9f..b7e59f7 100644 --- a/libc/test/src/math/smoke/NextAfterTest.h +++ b/libc/test/src/math/smoke/NextAfterTest.h @@ -12,6 +12,7 @@ #include "src/__support/CPP/bit.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" +#include "src/__support/sign.h" #include "test/UnitTest/FEnvSafeTest.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" @@ -42,6 +43,8 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { const T neg_inf = FPBits::inf(Sign::NEG).get_val(); const T zero = FPBits::zero(Sign::POS).get_val(); const T neg_zero = FPBits::zero(Sign::NEG).get_val(); + const T one = FPBits::one(Sign::POS).get_val(); + const T neg_one = FPBits::one(Sign::NEG).get_val(); const T nan = FPBits::quiet_nan().get_val(); static constexpr StorageType min_subnormal = @@ -55,8 +58,8 @@ public: typedef T (*NextAfterFunc)(T, T); void testNaN(NextAfterFunc func) { - ASSERT_FP_EQ(func(nan, 0), nan); - ASSERT_FP_EQ(func(0, nan), nan); + ASSERT_FP_EQ(func(nan, zero), nan); + ASSERT_FP_EQ(func(zero, nan), nan); } void testBoundaries(NextAfterFunc func) { @@ -65,68 +68,68 @@ public: // 'from' is zero|neg_zero. T x = zero; - T result = func(x, T(1)); + T result = func(x, one); StorageType expected_bits = 1; T expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected); - result = func(x, T(-1)); + result = func(x, neg_one); expected_bits = FPBits::SIGN_MASK + 1; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected); x = neg_zero; - result = func(x, 1); + result = func(x, one); expected_bits = 1; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected); - result = func(x, -1); + result = func(x, neg_one); expected_bits = FPBits::SIGN_MASK + 1; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected); // 'from' is max subnormal value. x = LIBC_NAMESPACE::cpp::bit_cast<T>(max_subnormal); - result = func(x, 1); + result = func(x, one); expected = LIBC_NAMESPACE::cpp::bit_cast<T>(min_normal); ASSERT_FP_EQ(result, expected); - result = func(x, 0); + result = func(x, zero); expected_bits = max_subnormal - 1; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected); x = -x; - result = func(x, -1); + result = func(x, neg_one); expected_bits = FPBits::SIGN_MASK + min_normal; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ(result, expected); - result = func(x, 0); + result = func(x, zero); expected_bits = FPBits::SIGN_MASK + max_subnormal - 1; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected); // 'from' is min subnormal value. x = LIBC_NAMESPACE::cpp::bit_cast<T>(min_subnormal); - result = func(x, 1); + result = func(x, one); expected_bits = min_subnormal + 1; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected); - ASSERT_FP_EQ_WITH_UNDERFLOW(func(x, 0), zero); + ASSERT_FP_EQ_WITH_UNDERFLOW(func(x, zero), zero); x = -x; - result = func(x, -1); + result = func(x, neg_one); expected_bits = FPBits::SIGN_MASK + min_subnormal + 1; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected); - ASSERT_FP_EQ_WITH_UNDERFLOW(func(x, 0), T(-0.0)); + ASSERT_FP_EQ_WITH_UNDERFLOW(func(x, zero), neg_zero); // 'from' is min normal. x = LIBC_NAMESPACE::cpp::bit_cast<T>(min_normal); - result = func(x, 0); + result = func(x, zero); expected_bits = max_subnormal; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected); @@ -137,7 +140,7 @@ public: ASSERT_FP_EQ(result, expected); x = -x; - result = func(x, 0); + result = func(x, zero); expected_bits = FPBits::SIGN_MASK + max_subnormal; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ_WITH_UNDERFLOW(result, expected); @@ -157,14 +160,14 @@ public: // 'from' is infinity. x = inf; - result = func(x, 0); + result = func(x, zero); expected_bits = max_normal; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ(result, expected); ASSERT_FP_EQ(func(x, inf), inf); x = neg_inf; - result = func(x, 0); + result = func(x, zero); expected_bits = FPBits::SIGN_MASK + max_normal; expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits); ASSERT_FP_EQ(result, expected); @@ -172,7 +175,7 @@ public: // 'from' is a power of 2. x = T(32.0); - result = func(x, 0); + result = func(x, zero); FPBits x_bits = FPBits(x); FPBits result_bits = FPBits(result); ASSERT_EQ(result_bits.get_biased_exponent(), @@ -187,7 +190,7 @@ public: x = -x; - result = func(x, 0); + result = func(x, zero); result_bits = FPBits(result); ASSERT_EQ(result_bits.get_biased_exponent(), uint16_t(x_bits.get_biased_exponent() - 1)); diff --git a/libc/test/src/math/smoke/NextTowardTest.h b/libc/test/src/math/smoke/NextTowardTest.h index d2f352c..43e71c6 100644 --- a/libc/test/src/math/smoke/NextTowardTest.h +++ b/libc/test/src/math/smoke/NextTowardTest.h @@ -62,8 +62,8 @@ public: typedef T (*NextTowardFunc)(T, long double); void testNaN(NextTowardFunc func) { - ASSERT_FP_EQ(func(nan, 0), nan); - ASSERT_FP_EQ(func(0, to_nan), nan); + ASSERT_FP_EQ(func(nan, to_zero), nan); + ASSERT_FP_EQ(func(zero, to_nan), nan); } void testBoundaries(NextTowardFunc func) { diff --git a/libc/test/src/math/smoke/RoundTest.h b/libc/test/src/math/smoke/RoundTest.h index beb7000..72889da 100644 --- a/libc/test/src/math/smoke/RoundTest.h +++ b/libc/test/src/math/smoke/RoundTest.h @@ -59,8 +59,10 @@ public: 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/RoundToIntegerTest.h b/libc/test/src/math/smoke/RoundToIntegerTest.h index 2b460ae..6866e91 100644 --- a/libc/test/src/math/smoke/RoundToIntegerTest.h +++ b/libc/test/src/math/smoke/RoundToIntegerTest.h @@ -97,8 +97,8 @@ public: test_one_input(func, F(-1.0), I(-1), false); test_one_input(func, F(10.0), I(10), false); test_one_input(func, F(-10.0), I(-10), false); - test_one_input(func, F(1234.0), I(1234), false); - test_one_input(func, F(-1234.0), I(-1234), false); + test_one_input(func, F(1232.0), I(1232), false); + test_one_input(func, F(-1232.0), I(-1232), false); } void testRoundNumbers(RoundToIntegerFunc func) { @@ -124,7 +124,7 @@ public: continue; // All subnormal numbers should round to zero. if (TestModes) { - if (x > 0) { + if (x > zero) { LIBC_NAMESPACE::fputil::set_round(FE_UPWARD); test_one_input(func, x, I(1), false); LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD); diff --git a/libc/test/src/math/smoke/SetPayloadSigTest.h b/libc/test/src/math/smoke/SetPayloadSigTest.h index f4804796..7b26c98 100644 --- a/libc/test/src/math/smoke/SetPayloadSigTest.h +++ b/libc/test/src/math/smoke/SetPayloadSigTest.h @@ -54,15 +54,31 @@ public: EXPECT_EQ(FPBits::signaling_nan(Sign::POS, 1).uintval(), FPBits(res).uintval()); - EXPECT_EQ(0, func(&res, T(0x42.0p+0))); - EXPECT_TRUE(FPBits(res).is_signaling_nan()); - EXPECT_EQ(FPBits::signaling_nan(Sign::POS, 0x42).uintval(), - FPBits(res).uintval()); - - EXPECT_EQ(0, func(&res, T(0x123.0p+0))); - EXPECT_TRUE(FPBits(res).is_signaling_nan()); - EXPECT_EQ(FPBits::signaling_nan(Sign::POS, 0x123).uintval(), - FPBits(res).uintval()); + if constexpr (FPBits::FRACTION_LEN - 1 >= 6) { + EXPECT_EQ(0, func(&res, T(0x31.0p+0))); + EXPECT_TRUE(FPBits(res).is_signaling_nan()); + EXPECT_EQ(FPBits::signaling_nan(Sign::POS, 0x31).uintval(), + FPBits(res).uintval()); + + EXPECT_EQ(0, func(&res, T(0x15.0p+0))); + EXPECT_TRUE(FPBits(res).is_signaling_nan()); + EXPECT_EQ(FPBits::signaling_nan(Sign::POS, 0x15).uintval(), + FPBits(res).uintval()); + } + + if constexpr (FPBits::FRACTION_LEN - 1 >= 7) { + EXPECT_EQ(0, func(&res, T(0x42.0p+0))); + EXPECT_TRUE(FPBits(res).is_signaling_nan()); + EXPECT_EQ(FPBits::signaling_nan(Sign::POS, 0x42).uintval(), + FPBits(res).uintval()); + } + + if constexpr (FPBits::FRACTION_LEN - 1 >= 9) { + EXPECT_EQ(0, func(&res, T(0x123.0p+0))); + EXPECT_TRUE(FPBits(res).is_signaling_nan()); + EXPECT_EQ(FPBits::signaling_nan(Sign::POS, 0x123).uintval(), + FPBits(res).uintval()); + } FPBits nan_payload_bits = FPBits::one(); nan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 2 + diff --git a/libc/test/src/math/smoke/SetPayloadTest.h b/libc/test/src/math/smoke/SetPayloadTest.h index 9ede567..b86b325 100644 --- a/libc/test/src/math/smoke/SetPayloadTest.h +++ b/libc/test/src/math/smoke/SetPayloadTest.h @@ -54,15 +54,33 @@ public: EXPECT_TRUE(FPBits(res).is_quiet_nan()); EXPECT_EQ(FPBits::quiet_nan(Sign::POS, 1).uintval(), FPBits(res).uintval()); - EXPECT_EQ(0, func(&res, T(0x42.0p+0))); - EXPECT_TRUE(FPBits(res).is_quiet_nan()); - EXPECT_EQ(FPBits::quiet_nan(Sign::POS, 0x42).uintval(), - FPBits(res).uintval()); - - EXPECT_EQ(0, func(&res, T(0x123.0p+0))); - EXPECT_TRUE(FPBits(res).is_quiet_nan()); - EXPECT_EQ(FPBits::quiet_nan(Sign::POS, 0x123).uintval(), - FPBits(res).uintval()); + if constexpr (FPBits::FRACTION_LEN - 1 >= 5) { + EXPECT_EQ(0, func(&res, T(0x15.0p+0))); + EXPECT_TRUE(FPBits(res).is_quiet_nan()); + EXPECT_EQ(FPBits::quiet_nan(Sign::POS, 0x15).uintval(), + FPBits(res).uintval()); + } + + if constexpr (FPBits::FRACTION_LEN - 1 >= 6) { + EXPECT_EQ(0, func(&res, T(0x31.0p+0))); + EXPECT_TRUE(FPBits(res).is_quiet_nan()); + EXPECT_EQ(FPBits::quiet_nan(Sign::POS, 0x31).uintval(), + FPBits(res).uintval()); + } + + if constexpr (FPBits::FRACTION_LEN - 1 >= 7) { + EXPECT_EQ(0, func(&res, T(0x42.0p+0))); + EXPECT_TRUE(FPBits(res).is_quiet_nan()); + EXPECT_EQ(FPBits::quiet_nan(Sign::POS, 0x42).uintval(), + FPBits(res).uintval()); + } + + if constexpr (FPBits::FRACTION_LEN - 1 >= 9) { + EXPECT_EQ(0, func(&res, T(0x123.0p+0))); + EXPECT_TRUE(FPBits(res).is_quiet_nan()); + EXPECT_EQ(FPBits::quiet_nan(Sign::POS, 0x123).uintval(), + FPBits(res).uintval()); + } // The following code is creating a NaN payload manually to prevent a // conversion from BigInt to float128. diff --git a/libc/test/src/math/smoke/SubTest.h b/libc/test/src/math/smoke/SubTest.h index c344db2..4ff4f3d 100644 --- a/libc/test/src/math/smoke/SubTest.h +++ b/libc/test/src/math/smoke/SubTest.h @@ -47,6 +47,10 @@ public: EXPECT_FP_EQ(neg_inf, func(in.neg_inf, in.zero)); EXPECT_FP_EQ(inf, func(in.inf, in.neg_zero)); EXPECT_FP_EQ(neg_inf, func(in.neg_inf, in.neg_zero)); + EXPECT_FP_EQ(neg_inf, func(in.zero, in.inf)); + EXPECT_FP_EQ(neg_inf, func(in.neg_zero, in.inf)); + EXPECT_FP_EQ(inf, func(in.zero, in.neg_inf)); + EXPECT_FP_EQ(inf, func(in.neg_zero, in.neg_inf)); } void test_invalid_operations(SubFunc func) { diff --git a/libc/test/src/math/smoke/TotalOrderMagTest.h b/libc/test/src/math/smoke/TotalOrderMagTest.h index 0a13fd2..8a389df 100644 --- a/libc/test/src/math/smoke/TotalOrderMagTest.h +++ b/libc/test/src/math/smoke/TotalOrderMagTest.h @@ -106,24 +106,45 @@ public: } void testNaNPayloads(TotalOrderMagFunc func) { - T qnan_0x42 = FPBits::quiet_nan(Sign::POS, 0x42).get_val(); - T neg_qnan_0x42 = FPBits::quiet_nan(Sign::NEG, 0x42).get_val(); - T snan_0x42 = FPBits::signaling_nan(Sign::POS, 0x42).get_val(); - T neg_snan_0x42 = FPBits::signaling_nan(Sign::NEG, 0x42).get_val(); - EXPECT_TRUE(funcWrapper(func, aNaN, aNaN)); EXPECT_TRUE(funcWrapper(func, sNaN, sNaN)); - EXPECT_TRUE(funcWrapper(func, aNaN, qnan_0x42)); - EXPECT_FALSE(funcWrapper(func, sNaN, snan_0x42)); - EXPECT_FALSE(funcWrapper(func, qnan_0x42, aNaN)); - EXPECT_TRUE(funcWrapper(func, snan_0x42, sNaN)); EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_aNaN)); EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_sNaN)); - EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_qnan_0x42)); - EXPECT_FALSE(funcWrapper(func, neg_sNaN, neg_snan_0x42)); - EXPECT_FALSE(funcWrapper(func, neg_qnan_0x42, neg_aNaN)); - EXPECT_TRUE(funcWrapper(func, neg_snan_0x42, neg_sNaN)); + + if constexpr (FPBits::FRACTION_LEN - 1 >= 5) { + 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, qnan_0x15)); + EXPECT_FALSE(funcWrapper(func, sNaN, snan_0x15)); + EXPECT_FALSE(funcWrapper(func, qnan_0x15, aNaN)); + EXPECT_TRUE(funcWrapper(func, snan_0x15, sNaN)); + + EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_qnan_0x15)); + EXPECT_FALSE(funcWrapper(func, neg_sNaN, neg_snan_0x15)); + EXPECT_FALSE(funcWrapper(func, neg_qnan_0x15, neg_aNaN)); + EXPECT_TRUE(funcWrapper(func, neg_snan_0x15, neg_sNaN)); + } + + if constexpr (FPBits::FRACTION_LEN - 1 >= 7) { + T qnan_0x42 = FPBits::quiet_nan(Sign::POS, 0x42).get_val(); + T neg_qnan_0x42 = FPBits::quiet_nan(Sign::NEG, 0x42).get_val(); + T snan_0x42 = FPBits::signaling_nan(Sign::POS, 0x42).get_val(); + T neg_snan_0x42 = FPBits::signaling_nan(Sign::NEG, 0x42).get_val(); + + EXPECT_TRUE(funcWrapper(func, aNaN, qnan_0x42)); + EXPECT_FALSE(funcWrapper(func, sNaN, snan_0x42)); + EXPECT_FALSE(funcWrapper(func, qnan_0x42, aNaN)); + EXPECT_TRUE(funcWrapper(func, snan_0x42, sNaN)); + + EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_qnan_0x42)); + EXPECT_FALSE(funcWrapper(func, neg_sNaN, neg_snan_0x42)); + EXPECT_FALSE(funcWrapper(func, neg_qnan_0x42, neg_aNaN)); + EXPECT_TRUE(funcWrapper(func, neg_snan_0x42, neg_sNaN)); + } } }; diff --git a/libc/test/src/math/smoke/TotalOrderTest.h b/libc/test/src/math/smoke/TotalOrderTest.h index e426eb3..50aac20 100644 --- a/libc/test/src/math/smoke/TotalOrderTest.h +++ b/libc/test/src/math/smoke/TotalOrderTest.h @@ -104,24 +104,45 @@ public: } void testNaNPayloads(TotalOrderFunc func) { - T qnan_0x42 = FPBits::quiet_nan(Sign::POS, 0x42).get_val(); - T neg_qnan_0x42 = FPBits::quiet_nan(Sign::NEG, 0x42).get_val(); - T snan_0x42 = FPBits::signaling_nan(Sign::POS, 0x42).get_val(); - T neg_snan_0x42 = FPBits::signaling_nan(Sign::NEG, 0x42).get_val(); - EXPECT_TRUE(funcWrapper(func, aNaN, aNaN)); EXPECT_TRUE(funcWrapper(func, sNaN, sNaN)); - EXPECT_TRUE(funcWrapper(func, aNaN, qnan_0x42)); - EXPECT_FALSE(funcWrapper(func, sNaN, snan_0x42)); - EXPECT_FALSE(funcWrapper(func, qnan_0x42, aNaN)); - EXPECT_TRUE(funcWrapper(func, snan_0x42, sNaN)); EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_aNaN)); EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_sNaN)); - EXPECT_FALSE(funcWrapper(func, neg_aNaN, neg_qnan_0x42)); - EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_snan_0x42)); - EXPECT_TRUE(funcWrapper(func, neg_qnan_0x42, neg_aNaN)); - EXPECT_FALSE(funcWrapper(func, neg_snan_0x42, neg_sNaN)); + + if constexpr (FPBits::FRACTION_LEN - 1 >= 5) { + 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, qnan_0x15)); + EXPECT_FALSE(funcWrapper(func, sNaN, snan_0x15)); + EXPECT_FALSE(funcWrapper(func, qnan_0x15, aNaN)); + EXPECT_TRUE(funcWrapper(func, snan_0x15, sNaN)); + + EXPECT_FALSE(funcWrapper(func, neg_aNaN, neg_qnan_0x15)); + EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_snan_0x15)); + EXPECT_TRUE(funcWrapper(func, neg_qnan_0x15, neg_aNaN)); + EXPECT_FALSE(funcWrapper(func, neg_snan_0x15, neg_sNaN)); + } + + if constexpr (FPBits::FRACTION_LEN - 1 >= 7) { + T qnan_0x42 = FPBits::quiet_nan(Sign::POS, 0x42).get_val(); + T neg_qnan_0x42 = FPBits::quiet_nan(Sign::NEG, 0x42).get_val(); + T snan_0x42 = FPBits::signaling_nan(Sign::POS, 0x42).get_val(); + T neg_snan_0x42 = FPBits::signaling_nan(Sign::NEG, 0x42).get_val(); + + EXPECT_TRUE(funcWrapper(func, aNaN, qnan_0x42)); + EXPECT_FALSE(funcWrapper(func, sNaN, snan_0x42)); + EXPECT_FALSE(funcWrapper(func, qnan_0x42, aNaN)); + EXPECT_TRUE(funcWrapper(func, snan_0x42, sNaN)); + + EXPECT_FALSE(funcWrapper(func, neg_aNaN, neg_qnan_0x42)); + EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_snan_0x42)); + EXPECT_TRUE(funcWrapper(func, neg_qnan_0x42, neg_aNaN)); + EXPECT_FALSE(funcWrapper(func, neg_snan_0x42, neg_sNaN)); + } } }; diff --git a/libc/test/src/math/smoke/TruncTest.h b/libc/test/src/math/smoke/TruncTest.h index 49688e8..e088f29 100644 --- a/libc/test/src/math/smoke/TruncTest.h +++ b/libc/test/src/math/smoke/TruncTest.h @@ -61,8 +61,8 @@ public: 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/UfromfpTest.h b/libc/test/src/math/smoke/UfromfpTest.h index 84c9f80..16785de 100644 --- a/libc/test/src/math/smoke/UfromfpTest.h +++ b/libc/test/src/math/smoke/UfromfpTest.h @@ -76,8 +76,8 @@ public: EXPECT_FP_EQ(T(2.0), func(T(1.75), FP_INT_UPWARD, 2U)); EXPECT_FP_EQ(T(11.0), func(T(10.32), FP_INT_UPWARD, 4U)); EXPECT_FP_EQ(T(11.0), func(T(10.65), FP_INT_UPWARD, 4U)); - EXPECT_FP_EQ(T(124.0), func(T(123.38), FP_INT_UPWARD, 7U)); - EXPECT_FP_EQ(T(124.0), func(T(123.96), FP_INT_UPWARD, 7U)); + EXPECT_FP_EQ(T(64.0), func(T(63.25), FP_INT_UPWARD, 7U)); + EXPECT_FP_EQ(T(64.0), func(T(63.75), FP_INT_UPWARD, 7U)); } void testFractionsUpwardOutsideRange(UfromfpFunc func) { @@ -120,8 +120,8 @@ public: EXPECT_FP_EQ(T(1.0), func(T(1.75), FP_INT_DOWNWARD, 1U)); EXPECT_FP_EQ(T(10.0), func(T(10.32), FP_INT_DOWNWARD, 4U)); EXPECT_FP_EQ(T(10.0), func(T(10.65), FP_INT_DOWNWARD, 4U)); - EXPECT_FP_EQ(T(123.0), func(T(123.38), FP_INT_DOWNWARD, 7U)); - EXPECT_FP_EQ(T(123.0), func(T(123.96), FP_INT_DOWNWARD, 7U)); + EXPECT_FP_EQ(T(63.0), func(T(63.25), FP_INT_DOWNWARD, 7U)); + EXPECT_FP_EQ(T(63.0), func(T(63.75), FP_INT_DOWNWARD, 7U)); } void testFractionsDownwardOutsideRange(UfromfpFunc func) { @@ -167,8 +167,8 @@ public: EXPECT_FP_EQ(T(1.0), func(T(1.75), FP_INT_TOWARDZERO, 1U)); EXPECT_FP_EQ(T(10.0), func(T(10.32), FP_INT_TOWARDZERO, 4U)); EXPECT_FP_EQ(T(10.0), func(T(10.65), FP_INT_TOWARDZERO, 4U)); - EXPECT_FP_EQ(T(123.0), func(T(123.38), FP_INT_TOWARDZERO, 7U)); - EXPECT_FP_EQ(T(123.0), func(T(123.96), FP_INT_TOWARDZERO, 7U)); + EXPECT_FP_EQ(T(63.0), func(T(63.25), FP_INT_TOWARDZERO, 7U)); + EXPECT_FP_EQ(T(63.0), func(T(63.75), FP_INT_TOWARDZERO, 7U)); } void testFractionsTowardZeroOutsideRange(UfromfpFunc func) { @@ -206,8 +206,8 @@ public: EXPECT_FP_EQ(T(2.0), func(T(1.75), FP_INT_TONEARESTFROMZERO, 2U)); EXPECT_FP_EQ(T(10.0), func(T(10.32), FP_INT_TONEARESTFROMZERO, 4U)); EXPECT_FP_EQ(T(11.0), func(T(10.65), FP_INT_TONEARESTFROMZERO, 4U)); - EXPECT_FP_EQ(T(123.0), func(T(123.38), FP_INT_TONEARESTFROMZERO, 7U)); - EXPECT_FP_EQ(T(124.0), func(T(123.96), FP_INT_TONEARESTFROMZERO, 7U)); + EXPECT_FP_EQ(T(63.0), func(T(63.25), FP_INT_TONEARESTFROMZERO, 7U)); + EXPECT_FP_EQ(T(64.0), func(T(63.75), FP_INT_TONEARESTFROMZERO, 7U)); } void testFractionsToNearestFromZeroOutsideRange(UfromfpFunc func) { @@ -254,8 +254,8 @@ public: EXPECT_FP_EQ(T(2.0), func(T(1.75), FP_INT_TONEAREST, 2U)); EXPECT_FP_EQ(T(10.0), func(T(10.32), FP_INT_TONEAREST, 4U)); EXPECT_FP_EQ(T(11.0), func(T(10.65), FP_INT_TONEAREST, 4U)); - EXPECT_FP_EQ(T(123.0), func(T(123.38), FP_INT_TONEAREST, 7U)); - EXPECT_FP_EQ(T(124.0), func(T(123.96), FP_INT_TONEAREST, 7U)); + EXPECT_FP_EQ(T(63.0), func(T(63.25), FP_INT_TONEAREST, 7U)); + EXPECT_FP_EQ(T(64.0), func(T(63.75), FP_INT_TONEAREST, 7U)); EXPECT_FP_EQ(T(2.0), func(T(2.3), FP_INT_TONEAREST, 2U)); EXPECT_FP_EQ(T(2.0), func(T(2.5), FP_INT_TONEAREST, 2U)); @@ -332,10 +332,8 @@ public: EXPECT_FP_EQ(T(2.0), func(T(1.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U)); EXPECT_FP_EQ(T(10.0), func(T(10.32), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U)); EXPECT_FP_EQ(T(11.0), func(T(10.65), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U)); - EXPECT_FP_EQ(T(123.0), - func(T(123.38), UNKNOWN_MATH_ROUNDING_DIRECTION, 7U)); - EXPECT_FP_EQ(T(124.0), - func(T(123.96), UNKNOWN_MATH_ROUNDING_DIRECTION, 7U)); + EXPECT_FP_EQ(T(63.0), func(T(63.25), UNKNOWN_MATH_ROUNDING_DIRECTION, 7U)); + EXPECT_FP_EQ(T(64.0), func(T(63.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 7U)); EXPECT_FP_EQ(T(2.0), func(T(2.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U)); EXPECT_FP_EQ(T(2.0), func(T(2.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U)); diff --git a/libc/test/src/math/smoke/UfromfpxTest.h b/libc/test/src/math/smoke/UfromfpxTest.h index 5916492..1d4d3a3 100644 --- a/libc/test/src/math/smoke/UfromfpxTest.h +++ b/libc/test/src/math/smoke/UfromfpxTest.h @@ -87,9 +87,9 @@ public: FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION(T(11.0), func(T(10.65), FP_INT_UPWARD, 4U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(124.0), func(T(123.38), FP_INT_UPWARD, 7U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(64.0), func(T(63.25), FP_INT_UPWARD, 7U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(124.0), func(T(123.96), FP_INT_UPWARD, 7U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(64.0), func(T(63.75), FP_INT_UPWARD, 7U), FE_INEXACT); } @@ -141,9 +141,9 @@ public: FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION(T(10.0), func(T(10.65), FP_INT_DOWNWARD, 4U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(123.0), func(T(123.38), FP_INT_DOWNWARD, 7U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(63.0), func(T(63.25), FP_INT_DOWNWARD, 7U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(123.0), func(T(123.96), FP_INT_DOWNWARD, 7U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(63.0), func(T(63.75), FP_INT_DOWNWARD, 7U), FE_INEXACT); } @@ -201,10 +201,10 @@ public: FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION(T(10.0), func(T(10.65), FP_INT_TOWARDZERO, 4U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION( - T(123.0), func(T(123.38), FP_INT_TOWARDZERO, 7U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION( - T(123.0), func(T(123.96), FP_INT_TOWARDZERO, 7U), FE_INEXACT); + EXPECT_FP_EQ_WITH_EXCEPTION(T(63.0), func(T(63.25), FP_INT_TOWARDZERO, 7U), + FE_INEXACT); + EXPECT_FP_EQ_WITH_EXCEPTION(T(63.0), func(T(63.75), FP_INT_TOWARDZERO, 7U), + FE_INEXACT); } void testFractionsTowardZeroOutsideRange(UfromfpxFunc func) { @@ -252,9 +252,9 @@ public: EXPECT_FP_EQ_WITH_EXCEPTION( T(11.0), func(T(10.65), FP_INT_TONEARESTFROMZERO, 4U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(123.0), func(T(123.38), FP_INT_TONEARESTFROMZERO, 7U), FE_INEXACT); + T(63.0), func(T(63.25), FP_INT_TONEARESTFROMZERO, 7U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(124.0), func(T(123.96), FP_INT_TONEARESTFROMZERO, 7U), FE_INEXACT); + T(64.0), func(T(63.75), FP_INT_TONEARESTFROMZERO, 7U), FE_INEXACT); } void testFractionsToNearestFromZeroOutsideRange(UfromfpxFunc func) { @@ -311,9 +311,9 @@ public: FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION(T(11.0), func(T(10.65), FP_INT_TONEAREST, 4U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(123.0), func(T(123.38), FP_INT_TONEAREST, 7U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(63.0), func(T(63.25), FP_INT_TONEAREST, 7U), FE_INEXACT); - EXPECT_FP_EQ_WITH_EXCEPTION(T(124.0), func(T(123.96), FP_INT_TONEAREST, 7U), + EXPECT_FP_EQ_WITH_EXCEPTION(T(64.0), func(T(63.75), FP_INT_TONEAREST, 7U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION(T(2.0), func(T(2.3), FP_INT_TONEAREST, 2U), @@ -414,10 +414,10 @@ public: T(11.0), func(T(10.65), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(123.0), func(T(123.38), UNKNOWN_MATH_ROUNDING_DIRECTION, 7U), + T(63.0), func(T(63.25), UNKNOWN_MATH_ROUNDING_DIRECTION, 7U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( - T(124.0), func(T(123.96), UNKNOWN_MATH_ROUNDING_DIRECTION, 7U), + T(64.0), func(T(63.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 7U), FE_INEXACT); EXPECT_FP_EQ_WITH_EXCEPTION( diff --git a/libc/test/src/math/smoke/asinpif16_test.cpp b/libc/test/src/math/smoke/asinpif16_test.cpp new file mode 100644 index 0000000..5303eed --- /dev/null +++ b/libc/test/src/math/smoke/asinpif16_test.cpp @@ -0,0 +1,86 @@ +//===-- Unittests for asinpif16 -------------------------------------------===// +// +// 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/__support/libc_errno.h" +#include "src/math/asinpif16.h" +#include "test/UnitTest/FPMatcher.h" + +using LlvmLibcAsinpif16Test = LIBC_NAMESPACE::testing::FPTest<float16>; + +TEST_F(LlvmLibcAsinpif16Test, SpecialNumbers) { + // zero + EXPECT_FP_EQ(zero, LIBC_NAMESPACE::asinpif16(zero)); + + // +/-1 + EXPECT_FP_EQ(0.5f16, LIBC_NAMESPACE::asinpif16(1.0)); + EXPECT_FP_EQ(-0.5f16, LIBC_NAMESPACE::asinpif16(-1.0)); + + // NaN inputs + EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), + LIBC_NAMESPACE::asinpif16(FPBits::quiet_nan().get_val())); + + EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), + LIBC_NAMESPACE::asinpif16(FPBits::signaling_nan().get_val())); + + // infinity inputs -> should return NaN + libc_errno = 0; + EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), LIBC_NAMESPACE::asinpif16(inf)); + EXPECT_MATH_ERRNO(EDOM); + + libc_errno = 0; + EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), + LIBC_NAMESPACE::asinpif16(neg_inf)); + EXPECT_MATH_ERRNO(EDOM); +} + +TEST_F(LlvmLibcAsinpif16Test, OutOfRange) { + // Test values > 1 + libc_errno = 0; + EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), + LIBC_NAMESPACE::asinpif16(1.5f16)); + EXPECT_MATH_ERRNO(EDOM); + + libc_errno = 0; + EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), + LIBC_NAMESPACE::asinpif16(2.0f16)); + EXPECT_MATH_ERRNO(EDOM); + + // Test values < -1 + libc_errno = 0; + EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), + LIBC_NAMESPACE::asinpif16(-1.5f16)); + EXPECT_MATH_ERRNO(EDOM); + + libc_errno = 0; + EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), + LIBC_NAMESPACE::asinpif16(-2.0f16)); + EXPECT_MATH_ERRNO(EDOM); + + // Test maximum normal value (should be > 1 for float16) + libc_errno = 0; + EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), + LIBC_NAMESPACE::asinpif16(FPBits::max_normal().get_val())); + EXPECT_MATH_ERRNO(EDOM); +} + +TEST_F(LlvmLibcAsinpif16Test, SymmetryProperty) { + // Test that asinpi(-x) = -asinpi(x) + constexpr float16 TEST_VALS[] = {0.1f16, 0.25f16, 0.5f16, 0.75f16, + 0.9f16, 0.99f16, 1.0f16}; + + for (float16 x : TEST_VALS) { + FPBits neg_x_bits(x); + neg_x_bits.set_sign(Sign::NEG); + float16 neg_x = neg_x_bits.get_val(); + + float16 pos_result = LIBC_NAMESPACE::asinpif16(x); + float16 neg_result = LIBC_NAMESPACE::asinpif16(neg_x); + + EXPECT_FP_EQ(pos_result, FPBits(neg_result).abs().get_val()); + } +} diff --git a/libc/test/src/math/smoke/atanpif16_test.cpp b/libc/test/src/math/smoke/atanpif16_test.cpp new file mode 100644 index 0000000..9eb1005a --- /dev/null +++ b/libc/test/src/math/smoke/atanpif16_test.cpp @@ -0,0 +1,64 @@ +//===-- Unittests for atanpif16 -------------------------------------------===// +// +// 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/__support/libc_errno.h" +#include "src/math/atanpif16.h" +#include "test/UnitTest/FPMatcher.h" + +using LIBC_NAMESPACE::cpp::array; +using LlvmLibcAtanpif16Test = LIBC_NAMESPACE::testing::FPTest<float16>; + +TEST_F(LlvmLibcAtanpif16Test, SpecialNumbers) { + // zero + EXPECT_FP_EQ(zero, LIBC_NAMESPACE::atanpif16(zero)); + EXPECT_FP_EQ(neg_zero, LIBC_NAMESPACE::atanpif16(neg_zero)); + + // NaN inputs + EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), + LIBC_NAMESPACE::atanpif16(FPBits::quiet_nan().get_val())); + + EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::atanpif16(aNaN)); + + // infinity inputs -> should return +/-0.5 + EXPECT_FP_EQ(0.5f16, LIBC_NAMESPACE::atanpif16(inf)); + EXPECT_FP_EQ(-0.5f16, LIBC_NAMESPACE::atanpif16(neg_inf)); +} + +TEST_F(LlvmLibcAtanpif16Test, SymmetryProperty) { + // Test that atanpi(-x) = -atanpi(x) + constexpr array<float16, 12> TEST_VALS = { + 0.1f16, 0.25f16, 0.5f16, 0.75f16, 1.0f16, 1.5f16, + 2.0f16, 5.0f16, 10.0f16, 50.0f16, 100.0f16, 1000.0f16}; + + for (float16 x : TEST_VALS) { + FPBits neg_x_bits(x); + neg_x_bits.set_sign(Sign::NEG); + float16 neg_x = neg_x_bits.get_val(); + + float16 pos_result = LIBC_NAMESPACE::atanpif16(x); + float16 neg_result = LIBC_NAMESPACE::atanpif16(neg_x); + + EXPECT_FP_EQ(pos_result, FPBits(neg_result).abs().get_val()); + } +} + +TEST_F(LlvmLibcAtanpif16Test, MonotonicityProperty) { + // Test that atanpi is monotonically increasing + constexpr array<float16, 15> TEST_VALS = { + -1000.0f16, -100.0f16, -10.0f16, -2.0f16, -1.0f16, + -0.5f16, -0.1f16, 0.0f16, 0.1f16, 0.5f16, + 1.0f16, 2.0f16, 10.0f16, 100.0f16, 1000.0f16}; + for (size_t i = 0; i < TEST_VALS.size() - 1; ++i) { + float16 x1 = TEST_VALS[i]; + float16 x2 = TEST_VALS[i + 1]; + float16 result1 = LIBC_NAMESPACE::atanpif16(x1); + float16 result2 = LIBC_NAMESPACE::atanpif16(x2); + + EXPECT_TRUE(result1 < result2); + } +} diff --git a/libc/test/src/math/smoke/bf16add_test.cpp b/libc/test/src/math/smoke/bf16add_test.cpp new file mode 100644 index 0000000..9e9c594 --- /dev/null +++ b/libc/test/src/math/smoke/bf16add_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16add ---------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16add.h" + +LIST_ADD_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16add) diff --git a/libc/test/src/math/smoke/bf16addf128_test.cpp b/libc/test/src/math/smoke/bf16addf128_test.cpp new file mode 100644 index 0000000..46f7ad3 --- /dev/null +++ b/libc/test/src/math/smoke/bf16addf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addf128 -----------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addf128.h" + +LIST_ADD_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16addf128) diff --git a/libc/test/src/math/smoke/bf16addf_test.cpp b/libc/test/src/math/smoke/bf16addf_test.cpp new file mode 100644 index 0000000..06d56cf --- /dev/null +++ b/libc/test/src/math/smoke/bf16addf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addf --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addf.h" + +LIST_ADD_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16addf) diff --git a/libc/test/src/math/smoke/bf16addl_test.cpp b/libc/test/src/math/smoke/bf16addl_test.cpp new file mode 100644 index 0000000..bf54827 --- /dev/null +++ b/libc/test/src/math/smoke/bf16addl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16addl --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16addl.h" + +LIST_ADD_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16addl) diff --git a/libc/test/src/math/smoke/bf16div_test.cpp b/libc/test/src/math/smoke/bf16div_test.cpp new file mode 100644 index 0000000..4516351 --- /dev/null +++ b/libc/test/src/math/smoke/bf16div_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16div ---------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16div.h" + +LIST_DIV_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16div) diff --git a/libc/test/src/math/smoke/bf16divf128_test.cpp b/libc/test/src/math/smoke/bf16divf128_test.cpp new file mode 100644 index 0000000..c42c5bb --- /dev/null +++ b/libc/test/src/math/smoke/bf16divf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16divf128 -----------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16divf128.h" + +LIST_DIV_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16divf128) diff --git a/libc/test/src/math/smoke/bf16divf_test.cpp b/libc/test/src/math/smoke/bf16divf_test.cpp new file mode 100644 index 0000000..873920b --- /dev/null +++ b/libc/test/src/math/smoke/bf16divf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16divf --------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16divf.h" + +LIST_DIV_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16divf) diff --git a/libc/test/src/math/smoke/bf16divl_test.cpp b/libc/test/src/math/smoke/bf16divl_test.cpp new file mode 100644 index 0000000..32ecd62 --- /dev/null +++ b/libc/test/src/math/smoke/bf16divl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16divl --------------------------------------------===// +// +// 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 "DivTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16divl.h" + +LIST_DIV_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16divl) diff --git a/libc/test/src/math/smoke/bf16fma_test.cpp b/libc/test/src/math/smoke/bf16fma_test.cpp new file mode 100644 index 0000000..81c73a0c --- /dev/null +++ b/libc/test/src/math/smoke/bf16fma_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16fma ---------------------------------------------===// +// +// 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 "FmaTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16fma.h" + +LIST_NARROWING_FMA_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16fma) diff --git a/libc/test/src/math/smoke/bf16fmaf128_test.cpp b/libc/test/src/math/smoke/bf16fmaf128_test.cpp new file mode 100644 index 0000000..dd8f473 --- /dev/null +++ b/libc/test/src/math/smoke/bf16fmaf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16fmaf128 -----------------------------------------===// +// +// 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 "FmaTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16fmaf128.h" + +LIST_NARROWING_FMA_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16fmaf128) diff --git a/libc/test/src/math/smoke/bf16fmaf_test.cpp b/libc/test/src/math/smoke/bf16fmaf_test.cpp new file mode 100644 index 0000000..04c6748 --- /dev/null +++ b/libc/test/src/math/smoke/bf16fmaf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16fmaf --------------------------------------------===// +// +// 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 "FmaTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16fmaf.h" + +LIST_NARROWING_FMA_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16fmaf) diff --git a/libc/test/src/math/smoke/bf16fmal_test.cpp b/libc/test/src/math/smoke/bf16fmal_test.cpp new file mode 100644 index 0000000..4c45e2c --- /dev/null +++ b/libc/test/src/math/smoke/bf16fmal_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16fmal --------------------------------------------===// +// +// 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 "FmaTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16fmal.h" + +LIST_NARROWING_FMA_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16fmal) diff --git a/libc/test/src/math/smoke/bf16mul_test.cpp b/libc/test/src/math/smoke/bf16mul_test.cpp new file mode 100644 index 0000000..db6f0cb --- /dev/null +++ b/libc/test/src/math/smoke/bf16mul_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16mul ---------------------------------------------===// +// +// 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 "MulTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16mul.h" + +LIST_MUL_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16mul) diff --git a/libc/test/src/math/smoke/bf16mulf128_test.cpp b/libc/test/src/math/smoke/bf16mulf128_test.cpp new file mode 100644 index 0000000..03cb9f2 --- /dev/null +++ b/libc/test/src/math/smoke/bf16mulf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16mulf128 -----------------------------------------===// +// +// 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 "MulTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16mulf128.h" + +LIST_MUL_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16mulf128) diff --git a/libc/test/src/math/smoke/bf16mulf_test.cpp b/libc/test/src/math/smoke/bf16mulf_test.cpp new file mode 100644 index 0000000..ec40e98 --- /dev/null +++ b/libc/test/src/math/smoke/bf16mulf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16mulf --------------------------------------------===// +// +// 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 "MulTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16mulf.h" + +LIST_MUL_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16mulf) diff --git a/libc/test/src/math/smoke/bf16mull_test.cpp b/libc/test/src/math/smoke/bf16mull_test.cpp new file mode 100644 index 0000000..4cb9c9c --- /dev/null +++ b/libc/test/src/math/smoke/bf16mull_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16mull --------------------------------------------===// +// +// 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 "MulTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/bf16mull.h" + +LIST_MUL_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16mull) diff --git a/libc/test/src/math/smoke/bf16sub_test.cpp b/libc/test/src/math/smoke/bf16sub_test.cpp new file mode 100644 index 0000000..4a793dc --- /dev/null +++ b/libc/test/src/math/smoke/bf16sub_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16sub ---------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16sub.h" + +LIST_SUB_TESTS(bfloat16, double, LIBC_NAMESPACE::bf16sub) diff --git a/libc/test/src/math/smoke/bf16subf128_test.cpp b/libc/test/src/math/smoke/bf16subf128_test.cpp new file mode 100644 index 0000000..25d6711 --- /dev/null +++ b/libc/test/src/math/smoke/bf16subf128_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subf128 -----------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subf128.h" + +LIST_SUB_TESTS(bfloat16, float128, LIBC_NAMESPACE::bf16subf128) diff --git a/libc/test/src/math/smoke/bf16subf_test.cpp b/libc/test/src/math/smoke/bf16subf_test.cpp new file mode 100644 index 0000000..e8c7440 --- /dev/null +++ b/libc/test/src/math/smoke/bf16subf_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subf --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subf.h" + +LIST_SUB_TESTS(bfloat16, float, LIBC_NAMESPACE::bf16subf) diff --git a/libc/test/src/math/smoke/bf16subl_test.cpp b/libc/test/src/math/smoke/bf16subl_test.cpp new file mode 100644 index 0000000..2997369 --- /dev/null +++ b/libc/test/src/math/smoke/bf16subl_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for bf16subl --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/bf16subl.h" + +LIST_SUB_TESTS(bfloat16, long double, LIBC_NAMESPACE::bf16subl) diff --git a/libc/test/src/math/smoke/bfloat16_add_test.cpp b/libc/test/src/math/smoke/bfloat16_add_test.cpp new file mode 100644 index 0000000..1db65a9 --- /dev/null +++ b/libc/test/src/math/smoke/bfloat16_add_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for bfloat16 addition -----------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" + +static bfloat16 add_func(bfloat16 x, bfloat16 y) { return x + y; } + +LIST_ADD_TESTS(bfloat16, bfloat16, add_func) diff --git a/libc/test/src/math/smoke/bfloat16_div_test.cpp b/libc/test/src/math/smoke/bfloat16_div_test.cpp new file mode 100644 index 0000000..c1ab598 --- /dev/null +++ b/libc/test/src/math/smoke/bfloat16_div_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for bfloat16 division -----------------------------------===// +// +// 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 "DivTest.h" + +#include "src/__support/FPUtil/bfloat16.h" + +static bfloat16 div_func(bfloat16 x, bfloat16 y) { return x / y; } + +LIST_DIV_TESTS(bfloat16, bfloat16, div_func) diff --git a/libc/test/src/math/smoke/bfloat16_mul_test.cpp b/libc/test/src/math/smoke/bfloat16_mul_test.cpp new file mode 100644 index 0000000..03e38d8 --- /dev/null +++ b/libc/test/src/math/smoke/bfloat16_mul_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for bfloat16 multiplication -----------------------------===// +// +// 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 "MulTest.h" + +#include "src/__support/FPUtil/bfloat16.h" + +static bfloat16 mul_func(bfloat16 x, bfloat16 y) { return x * y; } + +LIST_MUL_TESTS(bfloat16, bfloat16, mul_func) diff --git a/libc/test/src/math/smoke/bfloat16_sub_test.cpp b/libc/test/src/math/smoke/bfloat16_sub_test.cpp new file mode 100644 index 0000000..5eb4a9b --- /dev/null +++ b/libc/test/src/math/smoke/bfloat16_sub_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for bfloat16 subtraction --------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" + +static bfloat16 sub_func(bfloat16 x, bfloat16 y) { return x - y; } + +LIST_SUB_TESTS(bfloat16, bfloat16, sub_func) diff --git a/libc/test/src/math/smoke/canonicalizebf16_test.cpp b/libc/test/src/math/smoke/canonicalizebf16_test.cpp new file mode 100644 index 0000000..bf955c2 --- /dev/null +++ b/libc/test/src/math/smoke/canonicalizebf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for canonicalizebf16 ------------------------------------===// +// +// 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 "CanonicalizeTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/canonicalizebf16.h" + +LIST_CANONICALIZE_TESTS(bfloat16, LIBC_NAMESPACE::canonicalizebf16) 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 0000000..dcaf058 --- /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/copysignbf16_test.cpp b/libc/test/src/math/smoke/copysignbf16_test.cpp new file mode 100644 index 0000000..71a97e3 --- /dev/null +++ b/libc/test/src/math/smoke/copysignbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for copysignbf16 ----------------------------------------===// +// +// 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 "CopySignTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/copysignbf16.h" + +LIST_COPYSIGN_TESTS(bfloat16, LIBC_NAMESPACE::copysignbf16) diff --git a/libc/test/src/math/smoke/fdimbf16_test.cpp b/libc/test/src/math/smoke/fdimbf16_test.cpp new file mode 100644 index 0000000..43e8039 --- /dev/null +++ b/libc/test/src/math/smoke/fdimbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fdimbf16 --------------------------------------------===// +// +// 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 "FDimTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fdimbf16.h" + +LIST_FDIM_TESTS(bfloat16, LIBC_NAMESPACE::fdimbf16); 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 0000000..9cc77cd --- /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/fmaxbf16_test.cpp b/libc/test/src/math/smoke/fmaxbf16_test.cpp new file mode 100644 index 0000000..8ff9313 --- /dev/null +++ b/libc/test/src/math/smoke/fmaxbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fmaxbf16 --------------------------------------------===// +// +// 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 "FMaxTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fmaxbf16.h" + +LIST_FMAX_TESTS(bfloat16, LIBC_NAMESPACE::fmaxbf16) diff --git a/libc/test/src/math/smoke/fmaximum_mag_numbf16_test.cpp b/libc/test/src/math/smoke/fmaximum_mag_numbf16_test.cpp new file mode 100644 index 0000000..9e435cc --- /dev/null +++ b/libc/test/src/math/smoke/fmaximum_mag_numbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fmaximum_mag_numbf16 --------------------------------===// +// +// 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 "FMaximumMagNumTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fmaximum_mag_numbf16.h" + +LIST_FMAXIMUM_MAG_NUM_TESTS(bfloat16, LIBC_NAMESPACE::fmaximum_mag_numbf16) diff --git a/libc/test/src/math/smoke/fmaximum_magbf16_test.cpp b/libc/test/src/math/smoke/fmaximum_magbf16_test.cpp new file mode 100644 index 0000000..22a0bc3 --- /dev/null +++ b/libc/test/src/math/smoke/fmaximum_magbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fmaximum_magbf16 ------------------------------------===// +// +// 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 "FMaximumMagTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fmaximum_magbf16.h" + +LIST_FMAXIMUM_MAG_TESTS(bfloat16, LIBC_NAMESPACE::fmaximum_magbf16) diff --git a/libc/test/src/math/smoke/fmaximum_numbf16_test.cpp b/libc/test/src/math/smoke/fmaximum_numbf16_test.cpp new file mode 100644 index 0000000..25dbe9f --- /dev/null +++ b/libc/test/src/math/smoke/fmaximum_numbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fmaximum_numbf16 ------------------------------------===// +// +// 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 "FMaximumNumTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fmaximum_numbf16.h" + +LIST_FMAXIMUM_NUM_TESTS(bfloat16, LIBC_NAMESPACE::fmaximum_numbf16) diff --git a/libc/test/src/math/smoke/fmaximumbf16_test.cpp b/libc/test/src/math/smoke/fmaximumbf16_test.cpp new file mode 100644 index 0000000..e2cf56b --- /dev/null +++ b/libc/test/src/math/smoke/fmaximumbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fmaximumbf16 ----------------------------------------===// +// +// 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 "FMaximumTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fmaximumbf16.h" + +LIST_FMAXIMUM_TESTS(bfloat16, LIBC_NAMESPACE::fmaximumbf16) diff --git a/libc/test/src/math/smoke/fminbf16_test.cpp b/libc/test/src/math/smoke/fminbf16_test.cpp new file mode 100644 index 0000000..195a0ac --- /dev/null +++ b/libc/test/src/math/smoke/fminbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fminbf16 --------------------------------------------===// +// +// 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 "FMinTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fminbf16.h" + +LIST_FMIN_TESTS(bfloat16, LIBC_NAMESPACE::fminbf16) diff --git a/libc/test/src/math/smoke/fminimum_mag_numbf16_test.cpp b/libc/test/src/math/smoke/fminimum_mag_numbf16_test.cpp new file mode 100644 index 0000000..ed3d447 --- /dev/null +++ b/libc/test/src/math/smoke/fminimum_mag_numbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fminimum_mag_numbf16 --------------------------------===// +// +// 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 "FMinimumMagNumTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fminimum_mag_numbf16.h" + +LIST_FMINIMUM_MAG_NUM_TESTS(bfloat16, LIBC_NAMESPACE::fminimum_mag_numbf16) diff --git a/libc/test/src/math/smoke/fminimum_magbf16_test.cpp b/libc/test/src/math/smoke/fminimum_magbf16_test.cpp new file mode 100644 index 0000000..94251e0 --- /dev/null +++ b/libc/test/src/math/smoke/fminimum_magbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fminimum_magbf16 ------------------------------------===// +// +// 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 "FMinimumMagTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fminimum_magbf16.h" + +LIST_FMINIMUM_MAG_TESTS(bfloat16, LIBC_NAMESPACE::fminimum_magbf16) diff --git a/libc/test/src/math/smoke/fminimum_numbf16_test.cpp b/libc/test/src/math/smoke/fminimum_numbf16_test.cpp new file mode 100644 index 0000000..fe8bb51 --- /dev/null +++ b/libc/test/src/math/smoke/fminimum_numbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fminimum_numbf16 ------------------------------------===// +// +// 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 "FMinimumNumTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fminimum_numbf16.h" + +LIST_FMINIMUM_NUM_TESTS(bfloat16, LIBC_NAMESPACE::fminimum_numbf16) diff --git a/libc/test/src/math/smoke/fminimumbf16_test.cpp b/libc/test/src/math/smoke/fminimumbf16_test.cpp new file mode 100644 index 0000000..3667e90 --- /dev/null +++ b/libc/test/src/math/smoke/fminimumbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fminimumbf16 ----------------------------------------===// +// +// 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 "FMinimumTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fminimumbf16.h" + +LIST_FMINIMUM_TESTS(bfloat16, LIBC_NAMESPACE::fminimumbf16) diff --git a/libc/test/src/math/smoke/fmodbf16_test.cpp b/libc/test/src/math/smoke/fmodbf16_test.cpp new file mode 100644 index 0000000..8f30941 --- /dev/null +++ b/libc/test/src/math/smoke/fmodbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fmodbf16 --------------------------------------------===// +// +// 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 "FModTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fmodbf16.h" + +LIST_FMOD_TESTS(bfloat16, LIBC_NAMESPACE::fmodbf16) diff --git a/libc/test/src/math/smoke/frexpbf16_test.cpp b/libc/test/src/math/smoke/frexpbf16_test.cpp new file mode 100644 index 0000000..3c80edb --- /dev/null +++ b/libc/test/src/math/smoke/frexpbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- 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 +// +//===----------------------------------------------------------------------===// + +#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/smoke/fromfpbf16_test.cpp b/libc/test/src/math/smoke/fromfpbf16_test.cpp new file mode 100644 index 0000000..45d70b2 --- /dev/null +++ b/libc/test/src/math/smoke/fromfpbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fromfpbf16 ------------------------------------------===// +// +// 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 "FromfpTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fromfpbf16.h" + +LIST_FROMFP_TESTS(bfloat16, LIBC_NAMESPACE::fromfpbf16) diff --git a/libc/test/src/math/smoke/fromfpxbf16_test.cpp b/libc/test/src/math/smoke/fromfpxbf16_test.cpp new file mode 100644 index 0000000..d930ba3 --- /dev/null +++ b/libc/test/src/math/smoke/fromfpxbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for fromfpxbf16 -----------------------------------------===// +// +// 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 "FromfpxTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/fromfpxbf16.h" + +LIST_FROMFPX_TESTS(bfloat16, LIBC_NAMESPACE::fromfpxbf16) diff --git a/libc/test/src/math/smoke/getpayloadbf16_test.cpp b/libc/test/src/math/smoke/getpayloadbf16_test.cpp new file mode 100644 index 0000000..51a5fad --- /dev/null +++ b/libc/test/src/math/smoke/getpayloadbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for getpayloadbf16 --------------------------------------===// +// +// 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 "GetPayloadTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/getpayloadbf16.h" + +LIST_GETPAYLOAD_TESTS(bfloat16, LIBC_NAMESPACE::getpayloadbf16) diff --git a/libc/test/src/math/smoke/ilogbbf16_test.cpp b/libc/test/src/math/smoke/ilogbbf16_test.cpp new file mode 100644 index 0000000..d9fa03a --- /dev/null +++ b/libc/test/src/math/smoke/ilogbbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for ilogbbf16 -------------------------------------------===// +// +// 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 "ILogbTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/ilogbbf16.h" + +LIST_INTLOGB_TESTS(int, bfloat16, LIBC_NAMESPACE::ilogbbf16); diff --git a/libc/test/src/math/smoke/iscanonicalbf16_test.cpp b/libc/test/src/math/smoke/iscanonicalbf16_test.cpp new file mode 100644 index 0000000..3d73588 --- /dev/null +++ b/libc/test/src/math/smoke/iscanonicalbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for iscanonicalbf16 -------------------------------------===// +// +// 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 "IsCanonicalTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/iscanonicalbf16.h" + +LIST_ISCANONICAL_TESTS(bfloat16, LIBC_NAMESPACE::iscanonicalbf16) diff --git a/libc/test/src/math/smoke/issignalingbf16_test.cpp b/libc/test/src/math/smoke/issignalingbf16_test.cpp new file mode 100644 index 0000000..ed7e5af --- /dev/null +++ b/libc/test/src/math/smoke/issignalingbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for issignalingbf16 -------------------------------------===// +// +// 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 "IsSignalingTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/issignalingbf16.h" + +LIST_ISSIGNALING_TESTS(bfloat16, LIBC_NAMESPACE::issignalingbf16) diff --git a/libc/test/src/math/smoke/ldexpbf16_test.cpp b/libc/test/src/math/smoke/ldexpbf16_test.cpp new file mode 100644 index 0000000..2e57eb8 --- /dev/null +++ b/libc/test/src/math/smoke/ldexpbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for ldexpbf16 -------------------------------------------===// +// +// 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 "LdExpTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/ldexpbf16.h" + +LIST_LDEXP_TESTS(bfloat16, LIBC_NAMESPACE::ldexpbf16); diff --git a/libc/test/src/math/smoke/llogbbf16_test.cpp b/libc/test/src/math/smoke/llogbbf16_test.cpp new file mode 100644 index 0000000..4454fbf --- /dev/null +++ b/libc/test/src/math/smoke/llogbbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for llogbbf16 -------------------------------------------===// +// +// 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 "ILogbTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/llogbbf16.h" + +LIST_INTLOGB_TESTS(long, bfloat16, LIBC_NAMESPACE::llogbbf16); diff --git a/libc/test/src/math/smoke/llrintbf16_test.cpp b/libc/test/src/math/smoke/llrintbf16_test.cpp new file mode 100644 index 0000000..e841e62 --- /dev/null +++ b/libc/test/src/math/smoke/llrintbf16_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for llrintbf16 ------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/llrintbf16.h" + +LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long long, + LIBC_NAMESPACE::llrintbf16) diff --git a/libc/test/src/math/smoke/llroundbf16_test.cpp b/libc/test/src/math/smoke/llroundbf16_test.cpp new file mode 100644 index 0000000..c3b7ea4 --- /dev/null +++ b/libc/test/src/math/smoke/llroundbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for llroundbf16 -----------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/llroundbf16.h" + +LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long long, LIBC_NAMESPACE::llroundbf16) diff --git a/libc/test/src/math/smoke/logbbf16_test.cpp b/libc/test/src/math/smoke/logbbf16_test.cpp new file mode 100644 index 0000000..4ceec3d --- /dev/null +++ b/libc/test/src/math/smoke/logbbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for logbbf16 --------------------------------------------===// +// +// 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 "LogbTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/logbbf16.h" + +LIST_LOGB_TESTS(bfloat16, LIBC_NAMESPACE::logbbf16) diff --git a/libc/test/src/math/smoke/lrintbf16_test.cpp b/libc/test/src/math/smoke/lrintbf16_test.cpp new file mode 100644 index 0000000..65a5633b8 --- /dev/null +++ b/libc/test/src/math/smoke/lrintbf16_test.cpp @@ -0,0 +1,15 @@ +//===-- Unittests for lrintbf16 -------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/lrintbf16.h" + +LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(bfloat16, long, + LIBC_NAMESPACE::lrintbf16) diff --git a/libc/test/src/math/smoke/lroundbf16_test.cpp b/libc/test/src/math/smoke/lroundbf16_test.cpp new file mode 100644 index 0000000..2f2b7b1 --- /dev/null +++ b/libc/test/src/math/smoke/lroundbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for lroundbf16 ------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/lroundbf16.h" + +LIST_ROUND_TO_INTEGER_TESTS(bfloat16, long, LIBC_NAMESPACE::lroundbf16) diff --git a/libc/test/src/math/smoke/modfbf16_test.cpp b/libc/test/src/math/smoke/modfbf16_test.cpp new file mode 100644 index 0000000..88ebed5 --- /dev/null +++ b/libc/test/src/math/smoke/modfbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for modfbf16 --------------------------------------------===// +// +// 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 "ModfTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/modfbf16.h" + +LIST_MODF_TESTS(bfloat16, LIBC_NAMESPACE::modfbf16) diff --git a/libc/test/src/math/smoke/nanbf16_test.cpp b/libc/test/src/math/smoke/nanbf16_test.cpp new file mode 100644 index 0000000..4154f6ed --- /dev/null +++ b/libc/test/src/math/smoke/nanbf16_test.cpp @@ -0,0 +1,55 @@ +//===-- Unittests for nanbf16 ---------------------------------------------===// +// +// 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 "hdr/signal_macros.h" +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/nanbf16.h" +#include "test/UnitTest/FEnvSafeTest.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +class LlvmLibcNanf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest { +public: + using StorageType = LIBC_NAMESPACE::fputil::FPBits<bfloat16>::StorageType; + + void run_test(const char *input_str, StorageType bits) { + bfloat16 result = LIBC_NAMESPACE::nanbf16(input_str); + auto actual_fp = LIBC_NAMESPACE::fputil::FPBits<bfloat16>(result); + auto expected_fp = LIBC_NAMESPACE::fputil::FPBits<bfloat16>(bits); + EXPECT_EQ(actual_fp.uintval(), expected_fp.uintval()); + } +}; + +TEST_F(LlvmLibcNanf16Test, NCharSeq) { + run_test("", 0x7fc0); + + // 0x7fc0 + 0x1f (31) = 0x7cdf + run_test("31", 0x7fdf); + + // 0x7fc0 + 0x15 = 0x7fd5 + run_test("0x15", 0x7fd5); + + run_test("1a", 0x7fc0); + run_test("1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_", + 0x7fc0); + run_test("10000000000000000000000000000", 0x7fc0); +} + +TEST_F(LlvmLibcNanf16Test, RandomString) { + run_test(" 1234", 0x7fc0); + run_test("-1234", 0x7fc0); + run_test("asd&f", 0x7fc0); + run_test("123 ", 0x7fc0); +} + +#if defined(LIBC_ADD_NULL_CHECKS) +TEST_F(LlvmLibcNanf16Test, InvalidInput) { + EXPECT_DEATH([] { LIBC_NAMESPACE::nanbf16(nullptr); }, WITH_SIGNAL(-1)); +} +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/math/smoke/nearbyintbf16_test.cpp b/libc/test/src/math/smoke/nearbyintbf16_test.cpp new file mode 100644 index 0000000..2d64fc5 --- /dev/null +++ b/libc/test/src/math/smoke/nearbyintbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for nearbyintbf16 ---------------------------------------===// +// +// 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 "NearbyIntTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/nearbyintbf16.h" + +LIST_NEARBYINT_TESTS(bfloat16, LIBC_NAMESPACE::nearbyintbf16) diff --git a/libc/test/src/math/smoke/nextafterbf16_test.cpp b/libc/test/src/math/smoke/nextafterbf16_test.cpp new file mode 100644 index 0000000..b73a3cb --- /dev/null +++ b/libc/test/src/math/smoke/nextafterbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for nextafterbf16 ---------------------------------------===// +// +// 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 "NextAfterTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/nextafterbf16.h" + +LIST_NEXTAFTER_TESTS(bfloat16, LIBC_NAMESPACE::nextafterbf16) diff --git a/libc/test/src/math/smoke/nextdownbf16_test.cpp b/libc/test/src/math/smoke/nextdownbf16_test.cpp new file mode 100644 index 0000000..3002064 --- /dev/null +++ b/libc/test/src/math/smoke/nextdownbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for nextdownbf16 ----------------------------------------===// +// +// 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 "NextDownTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/nextdownbf16.h" + +LIST_NEXTDOWN_TESTS(bfloat16, LIBC_NAMESPACE::nextdownbf16) diff --git a/libc/test/src/math/smoke/nexttowardbf16_test.cpp b/libc/test/src/math/smoke/nexttowardbf16_test.cpp new file mode 100644 index 0000000..c1f35fc --- /dev/null +++ b/libc/test/src/math/smoke/nexttowardbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for nexttowardbf16 --------------------------------------===// +// +// 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 "NextTowardTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/nexttowardbf16.h" + +LIST_NEXTTOWARD_TESTS(bfloat16, LIBC_NAMESPACE::nexttowardbf16) diff --git a/libc/test/src/math/smoke/nextupbf16_test.cpp b/libc/test/src/math/smoke/nextupbf16_test.cpp new file mode 100644 index 0000000..49ad2f7 --- /dev/null +++ b/libc/test/src/math/smoke/nextupbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for nextupbf16 ------------------------------------------===// +// +// 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 "NextUpTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/nextupbf16.h" + +LIST_NEXTUP_TESTS(bfloat16, LIBC_NAMESPACE::nextupbf16) diff --git a/libc/test/src/math/smoke/remquobf16_test.cpp b/libc/test/src/math/smoke/remquobf16_test.cpp new file mode 100644 index 0000000..3f754bb --- /dev/null +++ b/libc/test/src/math/smoke/remquobf16_test.cpp @@ -0,0 +1,14 @@ +//===-- 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 +// +//===----------------------------------------------------------------------===// + +#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/smoke/rintbf16_test.cpp b/libc/test/src/math/smoke/rintbf16_test.cpp new file mode 100644 index 0000000..c78dcf6 --- /dev/null +++ b/libc/test/src/math/smoke/rintbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for rintbf16 --------------------------------------------===// +// +// 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/__support/FPUtil/bfloat16.h" +#include "src/math/rintbf16.h" + +LIST_RINT_TESTS(bfloat16, LIBC_NAMESPACE::rintbf16) 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 0000000..5163868 --- /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 0000000..711c37a --- /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/scalblnbf16_test.cpp b/libc/test/src/math/smoke/scalblnbf16_test.cpp new file mode 100644 index 0000000..c6fc3aa --- /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 0000000..855fd75 --- /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) diff --git a/libc/test/src/math/smoke/setpayloadbf16_test.cpp b/libc/test/src/math/smoke/setpayloadbf16_test.cpp new file mode 100644 index 0000000..198b454 --- /dev/null +++ b/libc/test/src/math/smoke/setpayloadbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for setpayloadbf16 --------------------------------------===// +// +// 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 "SetPayloadTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/setpayloadbf16.h" + +LIST_SETPAYLOAD_TESTS(bfloat16, LIBC_NAMESPACE::setpayloadbf16) diff --git a/libc/test/src/math/smoke/setpayloadsigbf16_test.cpp b/libc/test/src/math/smoke/setpayloadsigbf16_test.cpp new file mode 100644 index 0000000..aa6a3e9 --- /dev/null +++ b/libc/test/src/math/smoke/setpayloadsigbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for setpayloadsigbf16 -----------------------------------===// +// +// 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 "SetPayloadSigTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/setpayloadsigbf16.h" + +LIST_SETPAYLOADSIG_TESTS(bfloat16, LIBC_NAMESPACE::setpayloadsigbf16) diff --git a/libc/test/src/math/smoke/totalorderbf16_test.cpp b/libc/test/src/math/smoke/totalorderbf16_test.cpp new file mode 100644 index 0000000..11aeeac --- /dev/null +++ b/libc/test/src/math/smoke/totalorderbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for totalorderbf16 --------------------------------------===// +// +// 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 "TotalOrderTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/totalorderbf16.h" + +LIST_TOTALORDER_TESTS(bfloat16, LIBC_NAMESPACE::totalorderbf16) diff --git a/libc/test/src/math/smoke/totalordermagbf16_test.cpp b/libc/test/src/math/smoke/totalordermagbf16_test.cpp new file mode 100644 index 0000000..b5a5a1b --- /dev/null +++ b/libc/test/src/math/smoke/totalordermagbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for totalordermagbf16 -----------------------------------===// +// +// 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 "TotalOrderMagTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/totalordermagbf16.h" + +LIST_TOTALORDERMAG_TESTS(bfloat16, LIBC_NAMESPACE::totalordermagbf16) 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 0000000..970fa69 --- /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) diff --git a/libc/test/src/math/smoke/ufromfpbf16_test.cpp b/libc/test/src/math/smoke/ufromfpbf16_test.cpp new file mode 100644 index 0000000..2c516b0 --- /dev/null +++ b/libc/test/src/math/smoke/ufromfpbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for ufromfpbf16 -----------------------------------------===// +// +// 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 "UfromfpTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/ufromfpbf16.h" + +LIST_UFROMFP_TESTS(bfloat16, LIBC_NAMESPACE::ufromfpbf16) diff --git a/libc/test/src/math/smoke/ufromfpxbf16_test.cpp b/libc/test/src/math/smoke/ufromfpxbf16_test.cpp new file mode 100644 index 0000000..56e2727 --- /dev/null +++ b/libc/test/src/math/smoke/ufromfpxbf16_test.cpp @@ -0,0 +1,14 @@ +//===-- Unittests for ufromfpxbf16 ----------------------------------------===// +// +// 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 "UfromfpxTest.h" + +#include "src/__support/FPUtil/bfloat16.h" +#include "src/math/ufromfpxbf16.h" + +LIST_UFROMFPX_TESTS(bfloat16, LIBC_NAMESPACE::ufromfpxbf16) diff --git a/libc/test/src/stdfix/BitsFxTest.h b/libc/test/src/stdfix/BitsFxTest.h index eca6ab1..cdb363f 100644 --- a/libc/test/src/stdfix/BitsFxTest.h +++ b/libc/test/src/stdfix/BitsFxTest.h @@ -54,7 +54,7 @@ public: if (max >= 11 && FXRep::FRACTION_LEN >= kMinFbits) { // (10.71875)_10 = (1010.1011100)_2 - constexpr long long kExpected = 1372; + constexpr int64_t kExpected = 1372; EXPECT_EQ( static_cast<XType>(kExpected << (FXRep::FRACTION_LEN - kMinFbits)), func(special_num_t)); @@ -63,9 +63,11 @@ public: if constexpr (FXRep::SIGN_LEN > 0) { if (min <= -11 && FXRep::FRACTION_LEN >= kMinFbits) { // (-10.71875)_10 = (-1010.1011100)_2 - constexpr long long kExpected = -1372; - EXPECT_EQ(static_cast<XType>(kExpected - << (FXRep::FRACTION_LEN - kMinFbits)), + constexpr int64_t kExpected = + static_cast<int64_t>(static_cast<uint64_t>(-1372) + << (FXRep::FRACTION_LEN - kMinFbits)); + + EXPECT_EQ(static_cast<XType>(kExpected), func(negative_special_num_t)); } } diff --git a/libc/test/src/string/strcspn_test.cpp b/libc/test/src/string/strcspn_test.cpp index d83b3cf..ec98f72 100644 --- a/libc/test/src/string/strcspn_test.cpp +++ b/libc/test/src/string/strcspn_test.cpp @@ -48,3 +48,7 @@ TEST(LlvmLibcStrCSpnTest, DuplicatedCharactersNotPartOfComplementarySpan) { EXPECT_EQ(LIBC_NAMESPACE::strcspn("aaaa", "aa"), size_t{0}); EXPECT_EQ(LIBC_NAMESPACE::strcspn("aaaa", "baa"), size_t{0}); } + +TEST(LlvmLibcStrCSpnTest, TopBitSet) { + EXPECT_EQ(LIBC_NAMESPACE::strcspn("hello\x80world", "\x80"), size_t{5}); +} diff --git a/libc/test/src/string/strpbrk_test.cpp b/libc/test/src/string/strpbrk_test.cpp index fbe14da..cc80246 100644 --- a/libc/test/src/string/strpbrk_test.cpp +++ b/libc/test/src/string/strpbrk_test.cpp @@ -60,3 +60,7 @@ TEST(LlvmLibcStrPBrkTest, FindsFirstOfRepeated) { TEST(LlvmLibcStrPBrkTest, FindsFirstInBreakset) { EXPECT_STREQ(LIBC_NAMESPACE::strpbrk("12345", "34"), "345"); } + +TEST(LlvmLibcStrPBrkTest, TopBitSet) { + EXPECT_STREQ(LIBC_NAMESPACE::strpbrk("hello\x80world", "\x80 "), "\x80world"); +} diff --git a/libc/test/src/string/strsep_test.cpp b/libc/test/src/string/strsep_test.cpp index 06318de..553edd9 100644 --- a/libc/test/src/string/strsep_test.cpp +++ b/libc/test/src/string/strsep_test.cpp @@ -18,21 +18,21 @@ TEST(LlvmLibcStrsepTest, NullSrc) { TEST(LlvmLibcStrsepTest, NoTokenFound) { { char s[] = ""; - char *string = s, *orig = s; + char *string = s; EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string, ""), nullptr); - EXPECT_EQ(orig, string); + EXPECT_TRUE(string == nullptr); } { char s[] = "abcde"; char *string = s, *orig = s; EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string, ""), orig); - EXPECT_EQ(string, orig + 5); + EXPECT_TRUE(string == nullptr); } { char s[] = "abcde"; char *string = s, *orig = s; EXPECT_STREQ(LIBC_NAMESPACE::strsep(&string, "fghijk"), orig); - EXPECT_EQ(string, orig + 5); + EXPECT_TRUE(string == nullptr); } } @@ -53,6 +53,22 @@ TEST(LlvmLibcStrsepTest, DelimitersShouldNotBeIncludedInToken) { } } +TEST(LlvmLibcStrsepTest, SubsequentSearchesReturnNull) { + char s[] = "a"; + char *string = s; + ASSERT_STREQ(LIBC_NAMESPACE::strsep(&string, ":"), "a"); + ASSERT_EQ(LIBC_NAMESPACE::strsep(&string, ":"), nullptr); + ASSERT_EQ(LIBC_NAMESPACE::strsep(&string, ":"), nullptr); +} + +TEST(LlvmLibcStrsepTest, TopBitSet) { + char top_bit_set_str[] = "hello\x80world"; + char *p = top_bit_set_str; + ASSERT_STREQ(LIBC_NAMESPACE::strsep(&p, "\x80"), "hello"); + ASSERT_STREQ(LIBC_NAMESPACE::strsep(&p, "\x80"), "world"); + ASSERT_EQ(LIBC_NAMESPACE::strsep(&p, "\x80"), nullptr); +} + #if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcStrsepTest, CrashOnNullPtr) { diff --git a/libc/test/src/string/strspn_test.cpp b/libc/test/src/string/strspn_test.cpp index 82f9b2a..813612f 100644 --- a/libc/test/src/string/strspn_test.cpp +++ b/libc/test/src/string/strspn_test.cpp @@ -85,6 +85,10 @@ TEST(LlvmLibcStrSpnTest, DuplicatedCharactersToBeSearchedForShouldStillMatch) { EXPECT_EQ(LIBC_NAMESPACE::strspn("aaaa", "aa"), size_t{4}); } +TEST(LlvmLibcStrSpnTest, TopBitSet) { + EXPECT_EQ(LIBC_NAMESPACE::strspn("hello\x80world", "helo\x80rld"), size_t{6}); +} + #if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcStrSpnTest, CrashOnNullPtr) { diff --git a/libc/test/src/string/strtok_r_test.cpp b/libc/test/src/string/strtok_r_test.cpp index fdc27ba..8c4d3c36 100644 --- a/libc/test/src/string/strtok_r_test.cpp +++ b/libc/test/src/string/strtok_r_test.cpp @@ -122,3 +122,20 @@ TEST(LlvmLibcStrTokReentrantTest, DelimitersShouldNotBeIncludedInToken) { token = LIBC_NAMESPACE::strtok_r(nullptr, "_:,_", &reserve); ASSERT_STREQ(token, nullptr); } + +TEST(LlvmLibcStrTokReentrantTest, SubsequentSearchesReturnNull) { + char src[] = "a"; + char *reserve = nullptr; + char *token = LIBC_NAMESPACE::strtok_r(src, ":", &reserve); + ASSERT_STREQ(token, "a"); + ASSERT_EQ(LIBC_NAMESPACE::strtok_r(nullptr, ":", &reserve), nullptr); + ASSERT_EQ(LIBC_NAMESPACE::strtok_r(nullptr, ":", &reserve), nullptr); +} + +TEST(LlvmLibcStrTokReentrantTest, TopBitSet) { + char top_bit_set_str[] = "hello\x80world"; + char *p; + ASSERT_STREQ(LIBC_NAMESPACE::strtok_r(top_bit_set_str, "\x80", &p), "hello"); + ASSERT_STREQ(LIBC_NAMESPACE::strtok_r(nullptr, "\x80", &p), "world"); + ASSERT_EQ(LIBC_NAMESPACE::strtok_r(nullptr, "\x80", &p), nullptr); +} diff --git a/libc/test/src/string/strtok_test.cpp b/libc/test/src/string/strtok_test.cpp index b820653..3c097fde 100644 --- a/libc/test/src/string/strtok_test.cpp +++ b/libc/test/src/string/strtok_test.cpp @@ -76,3 +76,17 @@ TEST(LlvmLibcStrTokTest, DelimitersShouldNotBeIncludedInToken) { token = LIBC_NAMESPACE::strtok(nullptr, "_:,_"); ASSERT_STREQ(token, nullptr); } + +TEST(LlvmLibcStrTokTest, SubsequentSearchesReturnNull) { + char src[] = "a"; + ASSERT_STREQ("a", LIBC_NAMESPACE::strtok(src, ":")); + ASSERT_EQ(LIBC_NAMESPACE::strtok(nullptr, ":"), nullptr); + ASSERT_EQ(LIBC_NAMESPACE::strtok(nullptr, ":"), nullptr); +} + +TEST(LlvmLibcStrTokTest, TopBitSet) { + char top_bit_set_str[] = "hello\x80world"; + ASSERT_STREQ(LIBC_NAMESPACE::strtok(top_bit_set_str, "\x80"), "hello"); + ASSERT_STREQ(LIBC_NAMESPACE::strtok(nullptr, "\x80"), "world"); + ASSERT_EQ(LIBC_NAMESPACE::strtok(nullptr, "\x80"), nullptr); +} diff --git a/libc/test/src/sys/random/linux/getrandom_test.cpp b/libc/test/src/sys/random/linux/getrandom_test.cpp index 70ecfbf..249942d 100644 --- a/libc/test/src/sys/random/linux/getrandom_test.cpp +++ b/libc/test/src/sys/random/linux/getrandom_test.cpp @@ -19,11 +19,12 @@ using LlvmLibcGetRandomTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; TEST_F(LlvmLibcGetRandomTest, InvalidFlag) { LIBC_NAMESPACE::cpp::array<char, 10> buffer; ASSERT_THAT(LIBC_NAMESPACE::getrandom(buffer.data(), buffer.size(), -1), - Fails(EINVAL)); + Fails<ssize_t>(EINVAL)); } TEST_F(LlvmLibcGetRandomTest, InvalidBuffer) { - ASSERT_THAT(LIBC_NAMESPACE::getrandom(nullptr, 65536, 0), Fails(EFAULT)); + ASSERT_THAT(LIBC_NAMESPACE::getrandom(nullptr, 65536, 0), + Fails<ssize_t>(EFAULT)); } TEST_F(LlvmLibcGetRandomTest, ReturnsSize) { diff --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt index be7aa6f..66753b8 100644 --- a/libc/test/src/time/CMakeLists.txt +++ b/libc/test/src/time/CMakeLists.txt @@ -72,6 +72,29 @@ add_libc_unittest( libc.hdr.types.struct_tm ) +add_libc_unittest( + localtime_test + SUITE + libc_time_unittests + SRCS + localtime_test.cpp + DEPENDS + libc.hdr.types.time_t + libc.src.time.localtime +) + +add_libc_unittest( + localtime_r_test + SUITE + libc_time_unittests + SRCS + localtime_r_test.cpp + DEPENDS + libc.hdr.types.struct_tm + libc.hdr.types.time_t + libc.src.time.localtime_r +) + add_libc_test( clock_gettime_test SUITE diff --git a/libc/test/src/time/localtime_r_test.cpp b/libc/test/src/time/localtime_r_test.cpp new file mode 100644 index 0000000..8f7a79e --- /dev/null +++ b/libc/test/src/time/localtime_r_test.cpp @@ -0,0 +1,93 @@ +//===-- Unittests for localtime_r -----------------------------------------===// +// +// 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/time/localtime_r.h" +#include "test/UnitTest/Test.h" + +TEST(LlvmLibcLocaltimeR, ValidUnixTimestamp0) { + struct tm input = {.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 0, + .tm_mon = 0, + .tm_year = 0, + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + const time_t timer = 0; + + struct tm *result = LIBC_NAMESPACE::localtime_r(&timer, &input); + + ASSERT_EQ(70, result->tm_year); + ASSERT_EQ(0, result->tm_mon); + ASSERT_EQ(1, result->tm_mday); + ASSERT_EQ(0, result->tm_hour); + ASSERT_EQ(0, result->tm_min); + ASSERT_EQ(0, result->tm_sec); + ASSERT_EQ(4, result->tm_wday); + ASSERT_EQ(0, result->tm_yday); + ASSERT_EQ(0, result->tm_isdst); +} + +TEST(LlvmLibcLocaltime, NullPtr) { + EXPECT_DEATH([] { LIBC_NAMESPACE::localtime_r(nullptr, nullptr); }, + WITH_SIGNAL(4)); +} + +// TODO(zimirza): These tests does not expect the correct output of localtime as +// per specification. This is due to timezone functions removed from +// https://github.com/llvm/llvm-project/pull/110363. +// This will be resolved a new pull request. + +TEST(LlvmLibcLocaltimeR, ValidUnixTimestamp) { + struct tm input = {.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 0, + .tm_mon = 0, + .tm_year = 0, + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + const time_t timer = 1756595338; + struct tm *result = LIBC_NAMESPACE::localtime_r(&timer, &input); + + ASSERT_EQ(125, result->tm_year); + ASSERT_EQ(7, result->tm_mon); + ASSERT_EQ(30, result->tm_mday); + ASSERT_EQ(23, result->tm_hour); + ASSERT_EQ(8, result->tm_min); + ASSERT_EQ(58, result->tm_sec); + ASSERT_EQ(6, result->tm_wday); + ASSERT_EQ(241, result->tm_yday); + ASSERT_EQ(0, result->tm_isdst); +} + +TEST(LlvmLibcLocaltimeR, ValidUnixTimestampNegative) { + struct tm input = {.tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 0, + .tm_mon = 0, + .tm_year = 0, + .tm_wday = 0, + .tm_yday = 0, + .tm_isdst = 0}; + const time_t timer = -1756595338; + struct tm *result = LIBC_NAMESPACE::localtime_r(&timer, &input); + + ASSERT_EQ(14, result->tm_year); + ASSERT_EQ(4, result->tm_mon); + ASSERT_EQ(4, result->tm_mday); + ASSERT_EQ(0, result->tm_hour); + ASSERT_EQ(51, result->tm_min); + ASSERT_EQ(2, result->tm_sec); + ASSERT_EQ(1, result->tm_wday); + ASSERT_EQ(123, result->tm_yday); + ASSERT_EQ(0, result->tm_isdst); +} diff --git a/libc/test/src/time/localtime_test.cpp b/libc/test/src/time/localtime_test.cpp new file mode 100644 index 0000000..144060c --- /dev/null +++ b/libc/test/src/time/localtime_test.cpp @@ -0,0 +1,64 @@ +//===-- Unittests for localtime -------------------------------------------===// +// +// 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/time/localtime.h" +#include "test/UnitTest/Test.h" + +TEST(LlvmLibcLocaltime, ValidUnixTimestamp0) { + const time_t timer = 0; + struct tm *result = LIBC_NAMESPACE::localtime(&timer); + + ASSERT_EQ(70, result->tm_year); + ASSERT_EQ(0, result->tm_mon); + ASSERT_EQ(1, result->tm_mday); + ASSERT_EQ(0, result->tm_hour); + ASSERT_EQ(0, result->tm_min); + ASSERT_EQ(0, result->tm_sec); + ASSERT_EQ(4, result->tm_wday); + ASSERT_EQ(0, result->tm_yday); + ASSERT_EQ(0, result->tm_isdst); +} + +TEST(LlvmLibcLocaltime, NullPtr) { + EXPECT_DEATH([] { LIBC_NAMESPACE::localtime(nullptr); }, WITH_SIGNAL(4)); +} + +// TODO(zimirza): These tests does not expect the correct output of localtime as +// per specification. This is due to timezone functions removed from +// https://github.com/llvm/llvm-project/pull/110363. +// This will be resolved a new pull request. + +TEST(LlvmLibcLocaltime, ValidUnixTimestamp) { + const time_t timer = 1756595338; + struct tm *result = LIBC_NAMESPACE::localtime(&timer); + + ASSERT_EQ(125, result->tm_year); + ASSERT_EQ(7, result->tm_mon); + ASSERT_EQ(30, result->tm_mday); + ASSERT_EQ(23, result->tm_hour); + ASSERT_EQ(8, result->tm_min); + ASSERT_EQ(58, result->tm_sec); + ASSERT_EQ(6, result->tm_wday); + ASSERT_EQ(241, result->tm_yday); + ASSERT_EQ(0, result->tm_isdst); +} + +TEST(LlvmLibcLocaltime, ValidUnixTimestampNegative) { + const time_t timer = -1756595338; + struct tm *result = LIBC_NAMESPACE::localtime(&timer); + + ASSERT_EQ(14, result->tm_year); + ASSERT_EQ(4, result->tm_mon); + ASSERT_EQ(4, result->tm_mday); + ASSERT_EQ(0, result->tm_hour); + ASSERT_EQ(51, result->tm_min); + ASSERT_EQ(2, result->tm_sec); + ASSERT_EQ(1, result->tm_wday); + ASSERT_EQ(123, result->tm_yday); + ASSERT_EQ(0, result->tm_isdst); +} diff --git a/libc/test/src/time/timespec_get_test.cpp b/libc/test/src/time/timespec_get_test.cpp index 327bfef..9758501 100644 --- a/libc/test/src/time/timespec_get_test.cpp +++ b/libc/test/src/time/timespec_get_test.cpp @@ -24,6 +24,8 @@ TEST(LlvmLibcTimespecGet, Utc) { #endif } +// Baremetal implementation currently only supports TIME_UTC +#ifndef LIBC_TARGET_OS_IS_BAREMETAL TEST(LlvmLibcTimespecGet, Monotonic) { timespec ts1, ts2; int result; @@ -37,6 +39,7 @@ TEST(LlvmLibcTimespecGet, Monotonic) { ASSERT_GE(ts2.tv_nsec, ts1.tv_nsec); } } +#endif TEST(LlvmLibcTimespecGet, Unknown) { timespec ts; diff --git a/libc/test/src/wchar/mbrtowc_test.cpp b/libc/test/src/wchar/mbrtowc_test.cpp index c406300..ddf8fc7 100644 --- a/libc/test/src/wchar/mbrtowc_test.cpp +++ b/libc/test/src/wchar/mbrtowc_test.cpp @@ -37,18 +37,18 @@ TEST_F(LlvmLibcMBRToWCTest, TwoByte) { const char ch[2] = {static_cast<char>(0xC2), static_cast<char>(0x8E)}; // car symbol wchar_t dest[2]; - mbstate_t *mb; + mbstate_t mb; LIBC_NAMESPACE::memset(&mb, 0, sizeof(mbstate_t)); - size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 2, mb); + size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 2, &mb); ASSERT_EQ(static_cast<int>(*dest), 142); ASSERT_EQ(static_cast<int>(n), 2); ASSERT_ERRNO_SUCCESS(); // Should fail since we have not read enough - n = LIBC_NAMESPACE::mbrtowc(dest, ch, 1, mb); + n = LIBC_NAMESPACE::mbrtowc(dest, ch, 1, &mb); ASSERT_EQ(static_cast<int>(n), -2); // Should pass after reading one more byte - n = LIBC_NAMESPACE::mbrtowc(dest, ch + 1, 1, mb); + n = LIBC_NAMESPACE::mbrtowc(dest, ch + 1, 1, &mb); ASSERT_EQ(static_cast<int>(n), 1); ASSERT_EQ(static_cast<int>(*dest), 142); ASSERT_ERRNO_SUCCESS(); @@ -58,19 +58,19 @@ TEST_F(LlvmLibcMBRToWCTest, ThreeByte) { const char ch[3] = {static_cast<char>(0xE2), static_cast<char>(0x88), static_cast<char>(0x91)}; // ∑ sigma symbol wchar_t dest[2]; - mbstate_t *mb; + mbstate_t mb; LIBC_NAMESPACE::memset(&mb, 0, sizeof(mbstate_t)); - size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 3, mb); + size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 3, &mb); ASSERT_EQ(static_cast<int>(*dest), 8721); ASSERT_EQ(static_cast<int>(n), 3); ASSERT_ERRNO_SUCCESS(); // Should fail since we have not read enough - n = LIBC_NAMESPACE::mbrtowc(dest, ch, 1, mb); + n = LIBC_NAMESPACE::mbrtowc(dest, ch, 1, &mb); ASSERT_EQ(static_cast<int>(n), -2); ASSERT_ERRNO_SUCCESS(); // Should pass after reading two more bytes - n = LIBC_NAMESPACE::mbrtowc(dest, ch + 1, 2, mb); + n = LIBC_NAMESPACE::mbrtowc(dest, ch + 1, 2, &mb); ASSERT_EQ(static_cast<int>(n), 2); ASSERT_EQ(static_cast<int>(*dest), 8721); ASSERT_ERRNO_SUCCESS(); @@ -81,18 +81,18 @@ TEST_F(LlvmLibcMBRToWCTest, FourByte) { static_cast<char>(0xA4), static_cast<char>(0xA1)}; // 🤡 clown emoji wchar_t dest[2]; - mbstate_t *mb; + mbstate_t mb; LIBC_NAMESPACE::memset(&mb, 0, sizeof(mbstate_t)); - size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 4, mb); + size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 4, &mb); ASSERT_EQ(static_cast<int>(*dest), 129313); ASSERT_EQ(static_cast<int>(n), 4); ASSERT_ERRNO_SUCCESS(); // Should fail since we have not read enough - n = LIBC_NAMESPACE::mbrtowc(dest, ch, 2, mb); + n = LIBC_NAMESPACE::mbrtowc(dest, ch, 2, &mb); ASSERT_EQ(static_cast<int>(n), -2); ASSERT_ERRNO_SUCCESS(); // Should pass after reading two more bytes - n = LIBC_NAMESPACE::mbrtowc(dest, ch + 2, 2, mb); + n = LIBC_NAMESPACE::mbrtowc(dest, ch + 2, 2, &mb); ASSERT_EQ(static_cast<int>(n), 2); ASSERT_EQ(static_cast<int>(*dest), 129313); ASSERT_ERRNO_SUCCESS(); @@ -101,9 +101,9 @@ TEST_F(LlvmLibcMBRToWCTest, FourByte) { TEST_F(LlvmLibcMBRToWCTest, InvalidByte) { const char ch[1] = {static_cast<char>(0x80)}; wchar_t dest[2]; - mbstate_t *mb; + mbstate_t mb; LIBC_NAMESPACE::memset(&mb, 0, sizeof(mbstate_t)); - size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 1, mb); + size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 1, &mb); ASSERT_EQ(static_cast<int>(n), -1); ASSERT_ERRNO_EQ(EILSEQ); } @@ -113,18 +113,18 @@ TEST_F(LlvmLibcMBRToWCTest, InvalidMultiByte) { static_cast<char>(0x80), static_cast<char>(0x00)}; // invalid sequence of bytes wchar_t dest[2]; - mbstate_t *mb; + mbstate_t mb; LIBC_NAMESPACE::memset(&mb, 0, sizeof(mbstate_t)); // Trying to push all 4 should error - size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 4, mb); + size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 4, &mb); ASSERT_EQ(static_cast<int>(n), -1); ASSERT_ERRNO_EQ(EILSEQ); // Trying to push just the first one should error - n = LIBC_NAMESPACE::mbrtowc(dest, ch, 1, mb); + n = LIBC_NAMESPACE::mbrtowc(dest, ch, 1, &mb); ASSERT_EQ(static_cast<int>(n), -1); ASSERT_ERRNO_EQ(EILSEQ); // Trying to push the second and third should correspond to null wc - n = LIBC_NAMESPACE::mbrtowc(dest, ch + 1, 2, mb); + n = LIBC_NAMESPACE::mbrtowc(dest, ch + 1, 2, &mb); ASSERT_EQ(static_cast<int>(n), 0); ASSERT_TRUE(*dest == L'\0'); ASSERT_ERRNO_SUCCESS(); @@ -136,10 +136,10 @@ TEST_F(LlvmLibcMBRToWCTest, InvalidLastByte) { const char ch[4] = {static_cast<char>(0xF1), static_cast<char>(0x80), static_cast<char>(0x80), static_cast<char>(0xC0)}; wchar_t dest[2]; - mbstate_t *mb; + mbstate_t mb; LIBC_NAMESPACE::memset(&mb, 0, sizeof(mbstate_t)); // Trying to push all 4 should error - size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 4, mb); + size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 4, &mb); ASSERT_EQ(static_cast<int>(n), -1); ASSERT_ERRNO_EQ(EILSEQ); } @@ -148,10 +148,10 @@ TEST_F(LlvmLibcMBRToWCTest, ValidTwoByteWithExtraRead) { const char ch[3] = {static_cast<char>(0xC2), static_cast<char>(0x8E), static_cast<char>(0x80)}; wchar_t dest[2]; - mbstate_t *mb; + mbstate_t mb; LIBC_NAMESPACE::memset(&mb, 0, sizeof(mbstate_t)); // Trying to push all 3 should return valid 2 byte - size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 3, mb); + size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 3, &mb); ASSERT_EQ(static_cast<int>(n), 2); ASSERT_EQ(static_cast<int>(*dest), 142); ASSERT_ERRNO_SUCCESS(); @@ -161,14 +161,14 @@ TEST_F(LlvmLibcMBRToWCTest, TwoValidTwoBytes) { const char ch[4] = {static_cast<char>(0xC2), static_cast<char>(0x8E), static_cast<char>(0xC7), static_cast<char>(0x8C)}; wchar_t dest[2]; - mbstate_t *mb; + mbstate_t mb; LIBC_NAMESPACE::memset(&mb, 0, sizeof(mbstate_t)); // mbstate should reset after reading first one - size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 2, mb); + size_t n = LIBC_NAMESPACE::mbrtowc(dest, ch, 2, &mb); ASSERT_EQ(static_cast<int>(n), 2); ASSERT_EQ(static_cast<int>(*dest), 142); ASSERT_ERRNO_SUCCESS(); - n = LIBC_NAMESPACE::mbrtowc(dest + 1, ch + 2, 2, mb); + n = LIBC_NAMESPACE::mbrtowc(dest + 1, ch + 2, 2, &mb); ASSERT_EQ(static_cast<int>(n), 2); ASSERT_EQ(static_cast<int>(*(dest + 1)), 460); ASSERT_ERRNO_SUCCESS(); @@ -176,16 +176,16 @@ TEST_F(LlvmLibcMBRToWCTest, TwoValidTwoBytes) { TEST_F(LlvmLibcMBRToWCTest, NullString) { wchar_t dest[2] = {L'O', L'K'}; - mbstate_t *mb; + mbstate_t mb; LIBC_NAMESPACE::memset(&mb, 0, sizeof(mbstate_t)); // reading on nullptr should return 0 - size_t n = LIBC_NAMESPACE::mbrtowc(dest, nullptr, 2, mb); + size_t n = LIBC_NAMESPACE::mbrtowc(dest, nullptr, 2, &mb); ASSERT_EQ(static_cast<int>(n), 0); ASSERT_TRUE(dest[0] == L'O'); ASSERT_ERRNO_SUCCESS(); // reading a null terminator should return 0 const char *ch = "\0"; - n = LIBC_NAMESPACE::mbrtowc(dest, ch, 1, mb); + n = LIBC_NAMESPACE::mbrtowc(dest, ch, 1, &mb); ASSERT_EQ(static_cast<int>(n), 0); ASSERT_ERRNO_SUCCESS(); } @@ -194,10 +194,10 @@ TEST_F(LlvmLibcMBRToWCTest, NullDest) { const char ch[4] = {static_cast<char>(0xF0), static_cast<char>(0x9F), static_cast<char>(0xA4), static_cast<char>(0xA1)}; // 🤡 clown emoji - mbstate_t *mb; + mbstate_t mb; LIBC_NAMESPACE::memset(&mb, 0, sizeof(mbstate_t)); // reading nullptr should return correct size - size_t n = LIBC_NAMESPACE::mbrtowc(nullptr, ch, 10, mb); + size_t n = LIBC_NAMESPACE::mbrtowc(nullptr, ch, 10, &mb); ASSERT_EQ(static_cast<int>(n), 4); ASSERT_ERRNO_SUCCESS(); } diff --git a/libc/test/src/wctype/iswalpha_test.cpp b/libc/test/src/wctype/iswalpha_test.cpp index f3f75f4..a82c005 100644 --- a/libc/test/src/wctype/iswalpha_test.cpp +++ b/libc/test/src/wctype/iswalpha_test.cpp @@ -9,46 +9,48 @@ #include "src/__support/CPP/span.h" #include "src/wctype/iswalpha.h" -#include "test/UnitTest/LibcTest.h" #include "test/UnitTest/Test.h" -namespace { - -// TODO: Merge the wctype tests using this framework. -constexpr char WALPHA_ARRAY[] = { - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', -}; - -bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { - for (size_t i = 0; i < arr.size(); ++i) - if (static_cast<int>(arr[i]) == ch) - return true; - return false; -} - -} // namespace - TEST(LlvmLibciswalpha, SimpleTest) { - EXPECT_TRUE(LIBC_NAMESPACE::iswalpha('a')); - EXPECT_TRUE(LIBC_NAMESPACE::iswalpha('B')); - - EXPECT_FALSE(LIBC_NAMESPACE::iswalpha('3')); - EXPECT_FALSE(LIBC_NAMESPACE::iswalpha(' ')); - EXPECT_FALSE(LIBC_NAMESPACE::iswalpha('?')); - EXPECT_FALSE(LIBC_NAMESPACE::iswalpha('\0')); - EXPECT_FALSE(LIBC_NAMESPACE::iswalpha(-1)); + EXPECT_NE(LIBC_NAMESPACE::iswalpha('a'), 0); + EXPECT_NE(LIBC_NAMESPACE::iswalpha('B'), 0); + + EXPECT_EQ(LIBC_NAMESPACE::iswalpha('3'), 0); + EXPECT_EQ(LIBC_NAMESPACE::iswalpha(' '), 0); + EXPECT_EQ(LIBC_NAMESPACE::iswalpha('?'), 0); + EXPECT_EQ(LIBC_NAMESPACE::iswalpha('\0'), 0); + EXPECT_EQ(LIBC_NAMESPACE::iswalpha(-1), 0); } -TEST(LlvmLibciswalpha, DefaultLocale) { - // Loops through all characters, verifying that letters return - // true and everything else returns false. - for (int ch = -255; ch < 255; ++ch) { - if (in_span(ch, WALPHA_ARRAY)) - EXPECT_TRUE(LIBC_NAMESPACE::iswalpha(ch)); - else - EXPECT_FALSE(LIBC_NAMESPACE::iswalpha(ch)); - } -} +// TODO: once iswalpha supports more than just ascii-range characters add a +// proper test. + +// namespace { + +// // TODO: Merge the wctype tests using this framework. +// constexpr char WALPHA_ARRAY[] = { +// 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', +// 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', +// 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', +// 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', +// }; + +// bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { +// for (size_t i = 0; i < arr.size(); ++i) +// if (static_cast<int>(arr[i]) == ch) +// return true; +// return false; +// } + +// } // namespace + +// TEST(LlvmLibciswalpha, DefaultLocale) { +// // Loops through all characters, verifying that letters return +// // true and everything else returns false. +// for (int ch = -255; ch < 255; ++ch) { +// if (in_span(ch, WALPHA_ARRAY)) +// EXPECT_TRUE(LIBC_NAMESPACE::iswalpha(ch)); +// else +// EXPECT_FALSE(LIBC_NAMESPACE::iswalpha(ch)); +// } +// } |