diff options
author | Joerg Sonnenberger <joerg@bec.de> | 2014-04-01 13:42:56 +0000 |
---|---|---|
committer | Joerg Sonnenberger <joerg@bec.de> | 2014-04-01 13:42:56 +0000 |
commit | 6530149704e794c781feedd03dff2c74a400c42d (patch) | |
tree | 2d8f0a275b6c667f36936ff7042876f59c038f60 /compiler-rt/test/builtins | |
parent | 107e4abfd0040c719462708446b6fe9cf5de060a (diff) | |
download | bcm5719-llvm-6530149704e794c781feedd03dff2c74a400c42d.tar.gz bcm5719-llvm-6530149704e794c781feedd03dff2c74a400c42d.zip |
Add support for IEEE754 quad precision comparison functions.
From GuanHong Liu.
Differential Revision: http://llvm-reviews.chandlerc.com/D2797
llvm-svn: 205312
Diffstat (limited to 'compiler-rt/test/builtins')
-rw-r--r-- | compiler-rt/test/builtins/Unit/eqtf2_test.c | 89 | ||||
-rw-r--r-- | compiler-rt/test/builtins/Unit/fp_test.h | 223 | ||||
-rw-r--r-- | compiler-rt/test/builtins/Unit/getf2_test.c | 89 | ||||
-rw-r--r-- | compiler-rt/test/builtins/Unit/gttf2_test.c | 89 | ||||
-rw-r--r-- | compiler-rt/test/builtins/Unit/letf2_test.c | 89 | ||||
-rw-r--r-- | compiler-rt/test/builtins/Unit/lttf2_test.c | 89 | ||||
-rw-r--r-- | compiler-rt/test/builtins/Unit/netf2_test.c | 89 | ||||
-rw-r--r-- | compiler-rt/test/builtins/Unit/unordtf2_test.c | 65 |
8 files changed, 822 insertions, 0 deletions
diff --git a/compiler-rt/test/builtins/Unit/eqtf2_test.c b/compiler-rt/test/builtins/Unit/eqtf2_test.c new file mode 100644 index 00000000000..038583503ab --- /dev/null +++ b/compiler-rt/test/builtins/Unit/eqtf2_test.c @@ -0,0 +1,89 @@ +//===------------ eqtf2_test.c - Test __eqtf2------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file tests __eqtf2 for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +int __eqtf2(long double a, long double b); + +int test__eqtf2(long double a, long double b, enum EXPECTED_RESULT expected) +{ + int x = __eqtf2(a, b); + int ret = compareResultCMP(x, expected); + + if (ret){ + printf("error in test__eqtf2(%.20Lf, %.20Lf) = %d, " + "expected %s\n", a, b, x, expectedStr(expected)); + } + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + // NaN + if (test__eqtf2(makeQNaN128(), + 0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // < + // exp + if (test__eqtf2(0x1.234567890abcdef1234567890abcp-3L, + 0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // mantissa + if (test__eqtf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.334567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // sign + if (test__eqtf2(-0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // == + if (test__eqtf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + EQUAL_0)) + return 1; + // > + // exp + if (test__eqtf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp-3L, + NEQUAL_0)) + return 1; + // mantissa + if (test__eqtf2(0x1.334567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // sign + if (test__eqtf2(0x1.234567890abcdef1234567890abcp+3L, + -0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} diff --git a/compiler-rt/test/builtins/Unit/fp_test.h b/compiler-rt/test/builtins/Unit/fp_test.h new file mode 100644 index 00000000000..da58ca989cd --- /dev/null +++ b/compiler-rt/test/builtins/Unit/fp_test.h @@ -0,0 +1,223 @@ +//===--------------------------- fp_test.h - ------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines shared functions for the test. +// +//===----------------------------------------------------------------------===// + +#include <stdlib.h> +#include <limits.h> +#include <string.h> + +enum EXPECTED_RESULT { + LESS_0, LESS_EQUAL_0, EQUAL_0, GREATER_0, GREATER_EQUAL_0, NEQUAL_0 +}; + +static inline float fromRep32(uint32_t x) +{ + float ret; + memcpy(&ret, &x, 4); + return ret; +} + +static inline double fromRep64(uint64_t x) +{ + double ret; + memcpy(&ret, &x, 8); + return ret; +} + +static inline long double fromRep128(uint64_t hi, uint64_t lo) +{ + __uint128_t x = ((__uint128_t)hi << 64) + lo; + long double ret; + memcpy(&ret, &x, 16); + return ret; +} + +static inline uint32_t toRep32(float x) +{ + uint32_t ret; + memcpy(&ret, &x, 4); + return ret; +} + +static inline uint64_t toRep64(double x) +{ + uint64_t ret; + memcpy(&ret, &x, 8); + return ret; +} + +static inline __uint128_t toRep128(long double x) +{ + __uint128_t ret; + memcpy(&ret, &x, 16); + return ret; +} + +static inline int compareResultF(float result, + uint32_t expected) +{ + uint32_t rep = toRep32(result); + + if (rep == expected){ + return 0; + } + // test other posible NaN representation(signal NaN) + else if (expected == 0x7fc00000U){ + if ((rep & 0x7f800000U) == 0x7f800000U && + (rep & 0x7fffffU) > 0){ + return 0; + } + } + return 1; +} + +static inline int compareResultD(double result, + uint64_t expected) +{ + uint64_t rep = toRep64(result); + + if (rep == expected){ + return 0; + } + // test other posible NaN representation(signal NaN) + else if (expected == 0x7ff8000000000000UL){ + if ((rep & 0x7ff0000000000000UL) == 0x7ff0000000000000UL && + (rep & 0xfffffffffffffUL) > 0){ + return 0; + } + } + return 1; +} + +// return 0 if equal +// use two 64-bit integers intead of one 128-bit integer +// because 128-bit integer constant can't be assigned directly +static inline int compareResultLD(long double result, + uint64_t expectedHi, + uint64_t expectedLo) +{ + __uint128_t rep = toRep128(result); + uint64_t hi = rep >> 64; + uint64_t lo = rep; + + if (hi == expectedHi && lo == expectedLo){ + return 0; + } + // test other posible NaN representation(signal NaN) + else if (expectedHi == 0x7fff800000000000UL && expectedLo == 0x0UL){ + if ((hi & 0x7fff000000000000UL) == 0x7fff000000000000UL && + ((hi & 0xffffffffffffUL) > 0 || lo > 0)){ + return 0; + } + } + return 1; +} + +static inline int compareResultCMP(int result, + enum EXPECTED_RESULT expected) +{ + switch(expected){ + case LESS_0: + if (result < 0) + return 0; + break; + case LESS_EQUAL_0: + if (result <= 0) + return 0; + break; + case EQUAL_0: + if (result == 0) + return 0; + break; + case NEQUAL_0: + if (result != 0) + return 0; + break; + case GREATER_EQUAL_0: + if (result >= 0) + return 0; + break; + case GREATER_0: + if (result > 0) + return 0; + break; + default: + return 1; + } + return 1; +} + +static inline char *expectedStr(enum EXPECTED_RESULT expected) +{ + switch(expected){ + case LESS_0: + return "<0"; + case LESS_EQUAL_0: + return "<=0"; + case EQUAL_0: + return "=0"; + case NEQUAL_0: + return "!=0"; + case GREATER_EQUAL_0: + return ">=0"; + case GREATER_0: + return ">0"; + default: + return ""; + } + return ""; +} + +static inline float makeQNaN32() +{ + return fromRep32(0x7fc00000U); +} + +static inline double makeQNaN64() +{ + return fromRep64(0x7ff8000000000000UL); +} + +static inline long double makeQNaN128() +{ + return fromRep128(0x7fff800000000000UL, 0x0UL); +} + +static inline float makeNaN32(uint32_t rand) +{ + return fromRep32(0x7f800000U | (rand & 0x7fffffU)); +} + +static inline double makeNaN64(uint64_t rand) +{ + return fromRep64(0x7ff0000000000000UL | (rand & 0xfffffffffffffUL)); +} + +static inline long double makeNaN128(uint64_t rand) +{ + return fromRep128(0x7fff000000000000UL | (rand & 0xffffffffffffUL), 0x0UL); +} + +static inline float makeInf32() +{ + return fromRep32(0x7f800000U); +} + +static inline double makeInf64() +{ + return fromRep64(0x7ff0000000000000UL); +} + +static inline long double makeInf128() +{ + return fromRep128(0x7fff000000000000UL, 0x0UL); +} diff --git a/compiler-rt/test/builtins/Unit/getf2_test.c b/compiler-rt/test/builtins/Unit/getf2_test.c new file mode 100644 index 00000000000..9796b8ab845 --- /dev/null +++ b/compiler-rt/test/builtins/Unit/getf2_test.c @@ -0,0 +1,89 @@ +//===------------ getf2_test.c - Test __getf2------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file tests __getf2 for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +int __getf2(long double a, long double b); + +int test__getf2(long double a, long double b, enum EXPECTED_RESULT expected) +{ + int x = __getf2(a, b); + int ret = compareResultCMP(x, expected); + + if (ret){ + printf("error in test__getf2(%.20Lf, %.20Lf) = %d, " + "expected %s\n", a, b, x, expectedStr(expected)); + } + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + // NaN + if (test__getf2(makeQNaN128(), + 0x1.234567890abcdef1234567890abcp+3L, + LESS_0)) + return 1; + // < + // exp + if (test__getf2(0x1.234567890abcdef1234567890abcp-3L, + 0x1.234567890abcdef1234567890abcp+3L, + LESS_0)) + return 1; + // mantissa + if (test__getf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.334567890abcdef1234567890abcp+3L, + LESS_0)) + return 1; + // sign + if (test__getf2(-0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + LESS_0)) + return 1; + // == + if (test__getf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + GREATER_EQUAL_0)) + return 1; + // > + // exp + if (test__getf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp-3L, + GREATER_EQUAL_0)) + return 1; + // mantissa + if (test__getf2(0x1.334567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + GREATER_EQUAL_0)) + return 1; + // sign + if (test__getf2(0x1.234567890abcdef1234567890abcp+3L, + -0x1.234567890abcdef1234567890abcp+3L, + GREATER_EQUAL_0)) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} diff --git a/compiler-rt/test/builtins/Unit/gttf2_test.c b/compiler-rt/test/builtins/Unit/gttf2_test.c new file mode 100644 index 00000000000..6508d4b978c --- /dev/null +++ b/compiler-rt/test/builtins/Unit/gttf2_test.c @@ -0,0 +1,89 @@ +//===------------ gttf2_test.c - Test __gttf2------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file tests __gttf2 for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +int __gttf2(long double a, long double b); + +int test__gttf2(long double a, long double b, enum EXPECTED_RESULT expected) +{ + int x = __gttf2(a, b); + int ret = compareResultCMP(x, expected); + + if (ret){ + printf("error in test__gttf2(%.20Lf, %.20Lf) = %d, " + "expected %s\n", a, b, x, expectedStr(expected)); + } + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + // NaN + if (test__gttf2(makeQNaN128(), + 0x1.234567890abcdef1234567890abcp+3L, + LESS_EQUAL_0)) + return 1; + // < + // exp + if (test__gttf2(0x1.234567890abcdef1234567890abcp-3L, + 0x1.234567890abcdef1234567890abcp+3L, + LESS_EQUAL_0)) + return 1; + // mantissa + if (test__gttf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.334567890abcdef1234567890abcp+3L, + LESS_EQUAL_0)) + return 1; + // sign + if (test__gttf2(-0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + LESS_EQUAL_0)) + return 1; + // == + if (test__gttf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + LESS_EQUAL_0)) + return 1; + // > + // exp + if (test__gttf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp-3L, + GREATER_0)) + return 1; + // mantissa + if (test__gttf2(0x1.334567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + GREATER_0)) + return 1; + // sign + if (test__gttf2(0x1.234567890abcdef1234567890abcp+3L, + -0x1.234567890abcdef1234567890abcp+3L, + GREATER_0)) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} diff --git a/compiler-rt/test/builtins/Unit/letf2_test.c b/compiler-rt/test/builtins/Unit/letf2_test.c new file mode 100644 index 00000000000..1842e3c5562 --- /dev/null +++ b/compiler-rt/test/builtins/Unit/letf2_test.c @@ -0,0 +1,89 @@ +//===------------ letf2_test.c - Test __letf2------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file tests __letf2 for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +int __letf2(long double a, long double b); + +int test__letf2(long double a, long double b, enum EXPECTED_RESULT expected) +{ + int x = __letf2(a, b); + int ret = compareResultCMP(x, expected); + + if (ret){ + printf("error in test__letf2(%.20Lf, %.20Lf) = %d, " + "expected %s\n", a, b, x, expectedStr(expected)); + } + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + // NaN + if (test__letf2(makeQNaN128(), + 0x1.234567890abcdef1234567890abcp+3L, + GREATER_0)) + return 1; + // < + // exp + if (test__letf2(0x1.234567890abcdef1234567890abcp-3L, + 0x1.234567890abcdef1234567890abcp+3L, + LESS_EQUAL_0)) + return 1; + // mantissa + if (test__letf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.334567890abcdef1234567890abcp+3L, + LESS_EQUAL_0)) + return 1; + // sign + if (test__letf2(-0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + LESS_EQUAL_0)) + return 1; + // == + if (test__letf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + LESS_EQUAL_0)) + return 1; + // > + // exp + if (test__letf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp-3L, + GREATER_0)) + return 1; + // mantissa + if (test__letf2(0x1.334567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + GREATER_0)) + return 1; + // sign + if (test__letf2(0x1.234567890abcdef1234567890abcp+3L, + -0x1.234567890abcdef1234567890abcp+3L, + GREATER_0)) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} diff --git a/compiler-rt/test/builtins/Unit/lttf2_test.c b/compiler-rt/test/builtins/Unit/lttf2_test.c new file mode 100644 index 00000000000..e8f9dc17c6f --- /dev/null +++ b/compiler-rt/test/builtins/Unit/lttf2_test.c @@ -0,0 +1,89 @@ +//===------------ lttf2_test.c - Test __lttf2------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file tests __lttf2 for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +int __lttf2(long double a, long double b); + +int test__lttf2(long double a, long double b, enum EXPECTED_RESULT expected) +{ + int x = __lttf2(a, b); + int ret = compareResultCMP(x, expected); + + if (ret){ + printf("error in test__lttf2(%.20Lf, %.20Lf) = %d, " + "expected %s\n", a, b, x, expectedStr(expected)); + } + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + // NaN + if (test__lttf2(makeQNaN128(), + 0x1.234567890abcdef1234567890abcp+3L, + GREATER_EQUAL_0)) + return 1; + // < + // exp + if (test__lttf2(0x1.234567890abcdef1234567890abcp-3L, + 0x1.234567890abcdef1234567890abcp+3L, + LESS_0)) + return 1; + // mantissa + if (test__lttf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.334567890abcdef1234567890abcp+3L, + LESS_0)) + return 1; + // sign + if (test__lttf2(-0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + LESS_0)) + return 1; + // == + if (test__lttf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + GREATER_EQUAL_0)) + return 1; + // > + // exp + if (test__lttf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp-3L, + GREATER_EQUAL_0)) + return 1; + // mantissa + if (test__lttf2(0x1.334567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + GREATER_EQUAL_0)) + return 1; + // sign + if (test__lttf2(0x1.234567890abcdef1234567890abcp+3L, + -0x1.234567890abcdef1234567890abcp+3L, + GREATER_EQUAL_0)) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} diff --git a/compiler-rt/test/builtins/Unit/netf2_test.c b/compiler-rt/test/builtins/Unit/netf2_test.c new file mode 100644 index 00000000000..bbd953ab59e --- /dev/null +++ b/compiler-rt/test/builtins/Unit/netf2_test.c @@ -0,0 +1,89 @@ +//===------------ netf2_test.c - Test __netf2------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file tests __netf2 for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +int __netf2(long double a, long double b); + +int test__netf2(long double a, long double b, enum EXPECTED_RESULT expected) +{ + int x = __netf2(a, b); + int ret = compareResultCMP(x, expected); + + if (ret){ + printf("error in test__netf2(%.20Lf, %.20Lf) = %d, " + "expected %s\n", a, b, x, expectedStr(expected)); + } + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + // NaN + if (test__netf2(makeQNaN128(), + 0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // < + // exp + if (test__netf2(0x1.234567890abcdef1234567890abcp-3L, + 0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // mantissa + if (test__netf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.334567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // sign + if (test__netf2(-0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // == + if (test__netf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + EQUAL_0)) + return 1; + // > + // exp + if (test__netf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp-3L, + NEQUAL_0)) + return 1; + // mantissa + if (test__netf2(0x1.334567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // sign + if (test__netf2(0x1.234567890abcdef1234567890abcp+3L, + -0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} diff --git a/compiler-rt/test/builtins/Unit/unordtf2_test.c b/compiler-rt/test/builtins/Unit/unordtf2_test.c new file mode 100644 index 00000000000..114cd8cb38a --- /dev/null +++ b/compiler-rt/test/builtins/Unit/unordtf2_test.c @@ -0,0 +1,65 @@ +//===------------ unordtf2_test.c - Test __unordtf2------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file tests __unordtf2 for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +int __unordtf2(long double a, long double b); + +int test__unordtf2(long double a, long double b, enum EXPECTED_RESULT expected) +{ + int x = __unordtf2(a, b); + int ret = compareResultCMP(x, expected); + + if (ret){ + printf("error in test__unordtf2(%.20Lf, %.20Lf) = %d, " + "expected %s\n", a, b, x, expectedStr(expected)); + } + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LP64__ && __LDBL_MANT_DIG__ == 113 + // NaN + if (test__unordtf2(makeQNaN128(), + 0x1.234567890abcdef1234567890abcp+3L, + NEQUAL_0)) + return 1; + // other + if (test__unordtf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.334567890abcdef1234567890abcp+3L, + EQUAL_0)) + return 1; + if (test__unordtf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp+3L, + EQUAL_0)) + return 1; + if (test__unordtf2(0x1.234567890abcdef1234567890abcp+3L, + 0x1.234567890abcdef1234567890abcp-3L, + EQUAL_0)) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} |