[PATCH] D85352: [CUDA, test-suite] More test cases for rint() and nearint()
Artem Belevich via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 5 12:47:48 PDT 2020
tra created this revision.
tra added a reviewer: jlebar.
Herald added subscribers: sanjoy.google, bixia, yaxunl.
tra requested review of this revision.
Provides coverage for the bug fixed in D85236 <https://reviews.llvm.org/D85236>
Repository:
rT test-suite
https://reviews.llvm.org/D85352
Files:
External/CUDA/math_h.cu
Index: External/CUDA/math_h.cu
===================================================================
--- External/CUDA/math_h.cu
+++ External/CUDA/math_h.cu
@@ -1352,6 +1352,8 @@
assert(nearbyint(V(1)) == 1);
assert(nearbyint(V(1.)) == 1);
assert(nearbyint(V(1.f)) == 1);
+ // There are more checks in test_rint(). rint and nearbyint behave the same
+ // way on the GPU, so we only test them in one place.
}
__device__ void test_nextafter()
@@ -1443,7 +1445,7 @@
assert(std::remquo(V(0.5f), 1.f, &ip) == 0.5);
}
-__device__ void test_rint()
+__device__ void test_rint_nearbyint()
{
static_assert((std::is_same<decltype(rint((float)0)), float>::value), "");
static_assert((std::is_same<decltype(rint((bool)0)), double>::value), "");
@@ -1457,9 +1459,35 @@
static_assert((std::is_same<decltype(rint((double)0)), double>::value), "");
static_assert((std::is_same<decltype(rintf(0)), float>::value), "");
static_assert((std::is_same<decltype(rint(Ambiguous())), Ambiguous>::value), "");
- assert(rint(V(1)) == 1);
- assert(rint(V(1.)) == 1);
- assert(rint(V(1.f)) == 1);
+ // Verify that rint/nearbyint produce identical correct results
+ auto check = [](double input, double fpresult) {
+ // FP rint()/nearbyint must match the expected result.
+ assert(rint(V(float(input))) == float(fpresult));
+ assert(nearbyint(V(float(input))) == float(fpresult));
+ assert(rint(V(input)) == fpresult);
+ assert(nearbyint(V(input)) == fpresult);
+ // for integral types, std::rint(input) == std::rint(double(input))
+ int iinput = input;
+ assert(std::rint(V(iinput)) == std::rint(double(V(iinput))));
+ assert(std::nearbyint(V(iinput)) == std::nearbyint(double(V(iinput))));
+ };
+ // Whole values round to themselves and do not change sign.
+ check(0.0, 0.0);
+ check(-0.0, -0.0);
+ check(1.0, 1.0);
+ check(-1.0, -1.0);
+ // Half-way values round towards nearest even number.
+ check(2.5, 2.0);
+ check(-2.5, -2.0);
+ check(3.5, 4.0);
+ check(-3.5, -4.0);
+ // Everything else is rounded towards nearest integer.
+ check(2.1, 2.0);
+ check(-2.1, -2.0);
+ check(2.7, 3.0);
+ check(-2.7, -3.0);
+ check(3.9, 4.0);
+ check(-3.9, -4.0);
}
__device__ void test_round()
@@ -1638,7 +1666,7 @@
test_nextafter();
test_remainder();
test_remquo();
- test_rint();
+ test_rint_nearbyint();
test_round();
test_scalbln();
test_scalbn();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85352.283357.patch
Type: text/x-patch
Size: 2521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200805/338ad426/attachment.bin>
More information about the llvm-commits
mailing list