diff --git a/compiler-rt/test/builtins/Unit/divdf3_test.c b/compiler-rt/test/builtins/Unit/divdf3_test.c --- a/compiler-rt/test/builtins/Unit/divdf3_test.c +++ b/compiler-rt/test/builtins/Unit/divdf3_test.c @@ -24,11 +24,72 @@ 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; diff --git a/compiler-rt/test/builtins/Unit/divsf3_test.c b/compiler-rt/test/builtins/Unit/divsf3_test.c --- a/compiler-rt/test/builtins/Unit/divsf3_test.c +++ b/compiler-rt/test/builtins/Unit/divsf3_test.c @@ -24,11 +24,72 @@ 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; diff --git a/compiler-rt/test/builtins/Unit/divtf3_test.c b/compiler-rt/test/builtins/Unit/divtf3_test.c --- a/compiler-rt/test/builtins/Unit/divtf3_test.c +++ b/compiler-rt/test/builtins/Unit/divtf3_test.c @@ -32,6 +32,8 @@ 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 @@ 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, diff --git a/compiler-rt/test/builtins/Unit/fp_test.h b/compiler-rt/test/builtins/Unit/fp_test.h --- a/compiler-rt/test/builtins/Unit/fp_test.h +++ b/compiler-rt/test/builtins/Unit/fp_test.h @@ -253,14 +253,29 @@ 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