Skip to content

Commit edb359d

Browse files
committed
chore: add smoke and general tests for sqrtbf16 higher math function
Signed-off-by: Krishna Pandey <[email protected]>
1 parent a3a5d6b commit edb359d

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

libc/test/src/math/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,18 @@ add_fp_unittest(
17051705
libc.src.math.sqrtf128
17061706
)
17071707

1708+
add_fp_unittest(
1709+
sqrtbf16_test
1710+
NEED_MPFR
1711+
SUITE
1712+
libc-math-unittests
1713+
SRCS
1714+
sqrtbf16_test.cpp
1715+
DEPENDS
1716+
libc.src.math.sqrtbf16
1717+
libc.src.__support.FPUtil.bfloat16
1718+
)
1719+
17081720
add_fp_unittest(
17091721
generic_sqrtf_test
17101722
NEED_MPFR

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,6 +3455,19 @@ add_fp_unittest(
34553455
libc.src.math.sqrtf128
34563456
)
34573457

3458+
add_fp_unittest(
3459+
sqrtbf16_test
3460+
SUITE
3461+
libc-math-smoke-tests
3462+
SRCS
3463+
sqrtbf16_test.cpp
3464+
HDRS
3465+
SqrtTest.h
3466+
DEPENDS
3467+
libc.src.math.sqrtbf16
3468+
libc.src.__support.FPUtil.bfloat16
3469+
)
3470+
34583471
add_fp_unittest(
34593472
generic_sqrtf_test
34603473
SUITE
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===-- Unittests for sqrtbf16 --------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "SqrtTest.h"
10+
11+
#include "src/__support/FPUtil/bfloat16.h"
12+
#include "src/math/sqrtbf16.h"
13+
14+
LIST_SQRT_TESTS(bfloat16, LIBC_NAMESPACE::sqrtbf16);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===-- Exhaustive test for sqrtbf16 --------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/__support/FPUtil/bfloat16.h"
10+
#include "src/math/sqrtbf16.h"
11+
#include "test/UnitTest/FPMatcher.h"
12+
#include "test/UnitTest/Test.h"
13+
#include "utils/MPFRWrapper/MPFRUtils.h"
14+
15+
using LlvmLibcSqrtf16Test = LIBC_NAMESPACE::testing::FPTest<bfloat16>;
16+
17+
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
18+
19+
// range: [0, inf]
20+
static constexpr uint16_t POS_START = 0x0000U;
21+
static constexpr uint16_t POS_STOP = 0x7f80U;
22+
23+
TEST_F(LlvmLibcSqrtf16Test, PositiveRange) {
24+
for (uint16_t v = POS_START; v <= POS_STOP; ++v) {
25+
bfloat16 x = FPBits(v).get_val();
26+
EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sqrt, x,
27+
LIBC_NAMESPACE::sqrtbf16(x), 0.5);
28+
}
29+
}

libc/utils/MPFRWrapper/MPFRUtils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ template void explain_unary_operation_single_output_error(Operation op,
272272
double, RoundingMode);
273273
#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
274274

275+
template void explain_unary_operation_single_output_error(Operation op,
276+
bfloat16, bfloat16,
277+
double, RoundingMode);
278+
275279
template <typename T>
276280
void explain_unary_operation_two_outputs_error(
277281
Operation op, T input, const BinaryOutput<T> &libc_result,
@@ -559,6 +563,9 @@ template bool compare_unary_operation_single_output(Operation, float128,
559563
long double, double,
560564
RoundingMode);
561565
#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
566+
template bool compare_unary_operation_single_output(Operation, bfloat16,
567+
bfloat16, double,
568+
RoundingMode);
562569

563570
template <typename T>
564571
bool compare_unary_operation_two_outputs(Operation op, T input,

0 commit comments

Comments
 (0)