[compiler-rt][builtins] Add more test cases for __div[sdt]f3 LibCalls

* Make the three tests look more uniformly
* Explicitly specify types of integer and floating point literals
* Add more test cases (mostly inspired by divtf3_test.c)
  - tests are added for obviously special cases such as +/-Inf, +/-0.0 and some
    more implementation-specific cases such as divisor being almost 1.0
* Make NaN in the second test case of `divtf3` to be `sNaN` instead of
  testing for `qNaN` again

Reviewed By: sepavloff

Differential Revision: https://reviews.llvm.org/D84932
This commit is contained in:
Anatoly Trosinenko 2020-08-25 14:01:19 +03:00
parent 151f603199
commit b9f49d13fd
4 changed files with 241 additions and 8 deletions

View File

@ -24,11 +24,72 @@ int test__divdf3(double a, double b, uint64_t expected)
int main()
{
// Returned NaNs are assumed to be qNaN by default
// qNaN / any = qNaN
if (test__divdf3(makeQNaN64(), 3., UINT64_C(0x7ff8000000000000)))
return 1;
// NaN / any = NaN
if (test__divdf3(makeNaN64(UINT64_C(0x123)), 3., UINT64_C(0x7ff8000000000000)))
return 1;
// any / qNaN = qNaN
if (test__divdf3(3., makeQNaN64(), UINT64_C(0x7ff8000000000000)))
return 1;
// any / NaN = NaN
if (test__divdf3(3., makeNaN64(UINT64_C(0x123)), UINT64_C(0x7ff8000000000000)))
return 1;
// +Inf / positive = +Inf
if (test__divdf3(makeInf64(), 3., UINT64_C(0x7ff0000000000000)))
return 1;
// +Inf / negative = -Inf
if (test__divdf3(makeInf64(), -3., UINT64_C(0xfff0000000000000)))
return 1;
// -Inf / positive = -Inf
if (test__divdf3(makeNegativeInf64(), 3., UINT64_C(0xfff0000000000000)))
return 1;
// -Inf / negative = +Inf
if (test__divdf3(makeNegativeInf64(), -3., UINT64_C(0x7ff0000000000000)))
return 1;
// Inf / Inf = NaN
if (test__divdf3(makeInf64(), makeInf64(), UINT64_C(0x7ff8000000000000)))
return 1;
// 0.0 / 0.0 = NaN
if (test__divdf3(+0x0.0p+0, +0x0.0p+0, UINT64_C(0x7ff8000000000000)))
return 1;
// +0.0 / +Inf = +0.0
if (test__divdf3(+0x0.0p+0, makeInf64(), UINT64_C(0x0)))
return 1;
// +Inf / +0.0 = +Inf
if (test__divdf3(makeInf64(), +0x0.0p+0, UINT64_C(0x7ff0000000000000)))
return 1;
// positive / +0.0 = +Inf
if (test__divdf3(+1.0, +0x0.0p+0, UINT64_C(0x7ff0000000000000)))
return 1;
// positive / -0.0 = -Inf
if (test__divdf3(+1.0, -0x0.0p+0, UINT64_C(0xfff0000000000000)))
return 1;
// negative / +0.0 = -Inf
if (test__divdf3(-1.0, +0x0.0p+0, UINT64_C(0xfff0000000000000)))
return 1;
// negative / -0.0 = +Inf
if (test__divdf3(-1.0, -0x0.0p+0, UINT64_C(0x7ff0000000000000)))
return 1;
// 1/3
if (test__divdf3(1., 3., 0x3fd5555555555555ULL))
if (test__divdf3(1., 3., UINT64_C(0x3fd5555555555555)))
return 1;
// smallest normal result
if (test__divdf3(4.450147717014403e-308, 2., 0x10000000000000ULL))
if (test__divdf3(0x1.0p-1021, 2., UINT64_C(0x10000000000000)))
return 1;
// divisor is exactly 1.0
if (test__divdf3(0x1.0p+0, 0x1.0p+0, UINT64_C(0x3ff0000000000000)))
return 1;
// divisor is truncated to exactly 1.0 in UQ1.31
if (test__divdf3(0x1.0p+0, 0x1.00000001p+0, UINT64_C(0x3fefffffffe00000)))
return 1;
return 0;

View File

@ -24,11 +24,72 @@ int test__divsf3(float a, float b, uint32_t expected)
int main()
{
// Returned NaNs are assumed to be qNaN by default
// qNaN / any = qNaN
if (test__divsf3(makeQNaN32(), 3.F, UINT32_C(0x7fc00000)))
return 1;
// NaN / any = NaN
if (test__divsf3(makeNaN32(UINT32_C(0x123)), 3.F, UINT32_C(0x7fc00000)))
return 1;
// any / qNaN = qNaN
if (test__divsf3(3.F, makeQNaN32(), UINT32_C(0x7fc00000)))
return 1;
// any / NaN = NaN
if (test__divsf3(3.F, makeNaN32(UINT32_C(0x123)), UINT32_C(0x7fc00000)))
return 1;
// +Inf / positive = +Inf
if (test__divsf3(makeInf32(), 3.F, UINT32_C(0x7f800000)))
return 1;
// +Inf / negative = -Inf
if (test__divsf3(makeInf32(), -3.F, UINT32_C(0xff800000)))
return 1;
// -Inf / positive = -Inf
if (test__divsf3(makeNegativeInf32(), 3.F, UINT32_C(0xff800000)))
return 1;
// -Inf / negative = +Inf
if (test__divsf3(makeNegativeInf32(), -3.F, UINT32_C(0x7f800000)))
return 1;
// Inf / Inf = NaN
if (test__divsf3(makeInf32(), makeInf32(), UINT32_C(0x7fc00000)))
return 1;
// 0.0 / 0.0 = NaN
if (test__divsf3(+0x0.0p+0F, +0x0.0p+0F, UINT32_C(0x7fc00000)))
return 1;
// +0.0 / +Inf = +0.0
if (test__divsf3(+0x0.0p+0F, makeInf32(), UINT32_C(0x0)))
return 1;
// +Inf / +0.0 = +Inf
if (test__divsf3(makeInf32(), +0x0.0p+0F, UINT32_C(0x7f800000)))
return 1;
// positive / +0.0 = +Inf
if (test__divsf3(+1.F, +0x0.0p+0F, UINT32_C(0x7f800000)))
return 1;
// positive / -0.0 = -Inf
if (test__divsf3(+1.F, -0x0.0p+0F, UINT32_C(0xff800000)))
return 1;
// negative / +0.0 = -Inf
if (test__divsf3(-1.F, +0x0.0p+0F, UINT32_C(0xff800000)))
return 1;
// negative / -0.0 = +Inf
if (test__divsf3(-1.F, -0x0.0p+0F, UINT32_C(0x7f800000)))
return 1;
// 1/3
if (test__divsf3(1.f, 3.f, 0x3EAAAAABU))
if (test__divsf3(1.F, 3.F, UINT32_C(0x3eaaaaab)))
return 1;
// smallest normal result
if (test__divsf3(2.3509887e-38, 2., 0x00800000U))
if (test__divsf3(0x1.0p-125F, 2.F, UINT32_C(0x00800000)))
return 1;
// divisor is exactly 1.0
if (test__divsf3(0x1.0p+0F, 0x1.0p+0F, UINT32_C(0x3f800000)))
return 1;
// divisor is truncated to exactly 1.0 in UQ1.15
if (test__divsf3(0x1.0p+0F, 0x1.0001p+0F, UINT32_C(0x3f7fff00)))
return 1;
return 0;

View File

@ -32,6 +32,8 @@ char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
int main()
{
#if __LDBL_MANT_DIG__ == 113
// Returned NaNs are assumed to be qNaN by default
// qNaN / any = qNaN
if (test__divtf3(makeQNaN128(),
0x1.23456789abcdefp+5L,
@ -39,17 +41,111 @@ int main()
UINT64_C(0x0)))
return 1;
// NaN / any = NaN
if (test__divtf3(makeNaN128(UINT64_C(0x800030000000)),
if (test__divtf3(makeNaN128(UINT64_C(0x30000000)),
0x1.23456789abcdefp+5L,
UINT64_C(0x7fff800000000000),
UINT64_C(0x0)))
return 1;
// inf / any = inf
if (test__divtf3(makeInf128(),
0x1.23456789abcdefp+5L,
// any / qNaN = qNaN
if (test__divtf3(0x1.23456789abcdefp+5L,
makeQNaN128(),
UINT64_C(0x7fff800000000000),
UINT64_C(0x0)))
return 1;
// any / NaN = NaN
if (test__divtf3(0x1.23456789abcdefp+5L,
makeNaN128(UINT64_C(0x30000000)),
UINT64_C(0x7fff800000000000),
UINT64_C(0x0)))
return 1;
// +Inf / positive = +Inf
if (test__divtf3(makeInf128(), 3.L,
UINT64_C(0x7fff000000000000),
UINT64_C(0x0)))
return 1;
// +Inf / negative = -Inf
if (test__divtf3(makeInf128(), -3.L,
UINT64_C(0xffff000000000000),
UINT64_C(0x0)))
return 1;
// -Inf / positive = -Inf
if (test__divtf3(makeNegativeInf128(), 3.L,
UINT64_C(0xffff000000000000),
UINT64_C(0x0)))
return 1;
// -Inf / negative = +Inf
if (test__divtf3(makeNegativeInf128(), -3.L,
UINT64_C(0x7fff000000000000),
UINT64_C(0x0)))
return 1;
// Inf / Inf = NaN
if (test__divtf3(makeInf128(), makeInf128(),
UINT64_C(0x7fff800000000000),
UINT64_C(0x0)))
return 1;
// 0.0 / 0.0 = NaN
if (test__divtf3(+0x0.0p+0L, +0x0.0p+0L,
UINT64_C(0x7fff800000000000),
UINT64_C(0x0)))
return 1;
// +0.0 / +Inf = +0.0
if (test__divtf3(+0x0.0p+0L, makeInf128(),
UINT64_C(0x0),
UINT64_C(0x0)))
return 1;
// +Inf / +0.0 = +Inf
if (test__divtf3(makeInf128(), +0x0.0p+0L,
UINT64_C(0x7fff000000000000),
UINT64_C(0x0)))
return 1;
// positive / +0.0 = +Inf
if (test__divtf3(+1.0L, +0x0.0p+0L,
UINT64_C(0x7fff000000000000),
UINT64_C(0x0)))
return 1;
// positive / -0.0 = -Inf
if (test__divtf3(+1.0L, -0x0.0p+0L,
UINT64_C(0xffff000000000000),
UINT64_C(0x0)))
return 1;
// negative / +0.0 = -Inf
if (test__divtf3(-1.0L, +0x0.0p+0L,
UINT64_C(0xffff000000000000),
UINT64_C(0x0)))
return 1;
// negative / -0.0 = +Inf
if (test__divtf3(-1.0L, -0x0.0p+0L,
UINT64_C(0x7fff000000000000),
UINT64_C(0x0)))
return 1;
// 1/3
if (test__divtf3(1.L, 3.L,
UINT64_C(0x3ffd555555555555),
UINT64_C(0x5555555555555555)))
return 1;
// smallest normal result
if (test__divtf3(0x1.0p-16381L, 2.L,
UINT64_C(0x0001000000000000),
UINT64_C(0x0)))
return 1;
// divisor is exactly 1.0
if (test__divtf3(0x1.0p+0L,
0x1.0p+0L,
UINT64_C(0x3fff000000000000),
UINT64_C(0x0)))
return 1;
// divisor is truncated to exactly 1.0 in UQ1.63
if (test__divtf3(0x1.0p+0L,
0x1.0000000000000001p+0L,
UINT64_C(0x3ffeffffffffffff),
UINT64_C(0xfffe000000000000)))
return 1;
// any / any
if (test__divtf3(0x1.a23b45362464523375893ab4cdefp+5L,
0x1.eedcbaba3a94546558237654321fp-1L,

View File

@ -253,14 +253,29 @@ static inline float makeInf32(void)
return fromRep32(0x7f800000U);
}
static inline float makeNegativeInf32(void)
{
return fromRep32(0xff800000U);
}
static inline double makeInf64(void)
{
return fromRep64(0x7ff0000000000000UL);
}
static inline double makeNegativeInf64(void)
{
return fromRep64(0xfff0000000000000UL);
}
#if __LDBL_MANT_DIG__ == 113
static inline long double makeInf128(void)
{
return fromRep128(0x7fff000000000000UL, 0x0UL);
}
static inline long double makeNegativeInf128(void)
{
return fromRep128(0xffff000000000000UL, 0x0UL);
}
#endif