[compiler-rt] r205312 - Add support for IEEE754 quad precision comparison functions.
Joerg Sonnenberger
joerg at bec.de
Tue Apr 1 06:42:57 PDT 2014
Author: joerg
Date: Tue Apr 1 08:42:56 2014
New Revision: 205312
URL: http://llvm.org/viewvc/llvm-project?rev=205312&view=rev
Log:
Add support for IEEE754 quad precision comparison functions.
>From GuanHong Liu.
Differential Revision: http://llvm-reviews.chandlerc.com/D2797
Added:
compiler-rt/trunk/lib/builtins/comparetf2.c
compiler-rt/trunk/test/builtins/Unit/eqtf2_test.c
compiler-rt/trunk/test/builtins/Unit/fp_test.h
compiler-rt/trunk/test/builtins/Unit/getf2_test.c
compiler-rt/trunk/test/builtins/Unit/gttf2_test.c
compiler-rt/trunk/test/builtins/Unit/letf2_test.c
compiler-rt/trunk/test/builtins/Unit/lttf2_test.c
compiler-rt/trunk/test/builtins/Unit/netf2_test.c
compiler-rt/trunk/test/builtins/Unit/unordtf2_test.c
Added: compiler-rt/trunk/lib/builtins/comparetf2.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/comparetf2.c?rev=205312&view=auto
==============================================================================
--- compiler-rt/trunk/lib/builtins/comparetf2.c (added)
+++ compiler-rt/trunk/lib/builtins/comparetf2.c Tue Apr 1 08:42:56 2014
@@ -0,0 +1,133 @@
+//===-- lib/comparetf2.c - Quad-precision comparisons -------------*- C -*-===//
+//
+// 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 implements the following soft-float comparison routines:
+//
+// __eqtf2 __getf2 __unordtf2
+// __letf2 __gttf2
+// __lttf2
+// __netf2
+//
+// The semantics of the routines grouped in each column are identical, so there
+// is a single implementation for each, and wrappers to provide the other names.
+//
+// The main routines behave as follows:
+//
+// __letf2(a,b) returns -1 if a < b
+// 0 if a == b
+// 1 if a > b
+// 1 if either a or b is NaN
+//
+// __getf2(a,b) returns -1 if a < b
+// 0 if a == b
+// 1 if a > b
+// -1 if either a or b is NaN
+//
+// __unordtf2(a,b) returns 0 if both a and b are numbers
+// 1 if either a or b is NaN
+//
+// Note that __letf2( ) and __getf2( ) are identical except in their handling of
+// NaN values.
+//
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+enum LE_RESULT {
+ LE_LESS = -1,
+ LE_EQUAL = 0,
+ LE_GREATER = 1,
+ LE_UNORDERED = 1
+};
+
+COMPILER_RT_ABI enum LE_RESULT __letf2(fp_t a, fp_t b) {
+
+ const srep_t aInt = toRep(a);
+ const srep_t bInt = toRep(b);
+ const rep_t aAbs = aInt & absMask;
+ const rep_t bAbs = bInt & absMask;
+
+ // If either a or b is NaN, they are unordered.
+ if (aAbs > infRep || bAbs > infRep) return LE_UNORDERED;
+
+ // If a and b are both zeros, they are equal.
+ if ((aAbs | bAbs) == 0) return LE_EQUAL;
+
+ // If at least one of a and b is positive, we get the same result comparing
+ // a and b as signed integers as we would with a floating-point compare.
+ if ((aInt & bInt) >= 0) {
+ if (aInt < bInt) return LE_LESS;
+ else if (aInt == bInt) return LE_EQUAL;
+ else return LE_GREATER;
+ }
+ else {
+ // Otherwise, both are negative, so we need to flip the sense of the
+ // comparison to get the correct result. (This assumes a twos- or ones-
+ // complement integer representation; if integers are represented in a
+ // sign-magnitude representation, then this flip is incorrect).
+ if (aInt > bInt) return LE_LESS;
+ else if (aInt == bInt) return LE_EQUAL;
+ else return LE_GREATER;
+ }
+}
+
+enum GE_RESULT {
+ GE_LESS = -1,
+ GE_EQUAL = 0,
+ GE_GREATER = 1,
+ GE_UNORDERED = -1 // Note: different from LE_UNORDERED
+};
+
+COMPILER_RT_ABI enum GE_RESULT __getf2(fp_t a, fp_t b) {
+
+ const srep_t aInt = toRep(a);
+ const srep_t bInt = toRep(b);
+ const rep_t aAbs = aInt & absMask;
+ const rep_t bAbs = bInt & absMask;
+
+ if (aAbs > infRep || bAbs > infRep) return GE_UNORDERED;
+ if ((aAbs | bAbs) == 0) return GE_EQUAL;
+ if ((aInt & bInt) >= 0) {
+ if (aInt < bInt) return GE_LESS;
+ else if (aInt == bInt) return GE_EQUAL;
+ else return GE_GREATER;
+ } else {
+ if (aInt > bInt) return GE_LESS;
+ else if (aInt == bInt) return GE_EQUAL;
+ else return GE_GREATER;
+ }
+}
+
+COMPILER_RT_ABI int __unordtf2(fp_t a, fp_t b) {
+ const rep_t aAbs = toRep(a) & absMask;
+ const rep_t bAbs = toRep(b) & absMask;
+ return aAbs > infRep || bAbs > infRep;
+}
+
+// The following are alternative names for the preceeding routines.
+
+COMPILER_RT_ABI enum LE_RESULT __eqtf2(fp_t a, fp_t b) {
+ return __letf2(a, b);
+}
+
+COMPILER_RT_ABI enum LE_RESULT __lttf2(fp_t a, fp_t b) {
+ return __letf2(a, b);
+}
+
+COMPILER_RT_ABI enum LE_RESULT __netf2(fp_t a, fp_t b) {
+ return __letf2(a, b);
+}
+
+COMPILER_RT_ABI enum GE_RESULT __gttf2(fp_t a, fp_t b) {
+ return __getf2(a, b);
+}
+
+#endif
Added: compiler-rt/trunk/test/builtins/Unit/eqtf2_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/eqtf2_test.c?rev=205312&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/eqtf2_test.c (added)
+++ compiler-rt/trunk/test/builtins/Unit/eqtf2_test.c Tue Apr 1 08:42:56 2014
@@ -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;
+}
Added: compiler-rt/trunk/test/builtins/Unit/fp_test.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fp_test.h?rev=205312&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fp_test.h (added)
+++ compiler-rt/trunk/test/builtins/Unit/fp_test.h Tue Apr 1 08:42:56 2014
@@ -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);
+}
Added: compiler-rt/trunk/test/builtins/Unit/getf2_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/getf2_test.c?rev=205312&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/getf2_test.c (added)
+++ compiler-rt/trunk/test/builtins/Unit/getf2_test.c Tue Apr 1 08:42:56 2014
@@ -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;
+}
Added: compiler-rt/trunk/test/builtins/Unit/gttf2_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/gttf2_test.c?rev=205312&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/gttf2_test.c (added)
+++ compiler-rt/trunk/test/builtins/Unit/gttf2_test.c Tue Apr 1 08:42:56 2014
@@ -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;
+}
Added: compiler-rt/trunk/test/builtins/Unit/letf2_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/letf2_test.c?rev=205312&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/letf2_test.c (added)
+++ compiler-rt/trunk/test/builtins/Unit/letf2_test.c Tue Apr 1 08:42:56 2014
@@ -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;
+}
Added: compiler-rt/trunk/test/builtins/Unit/lttf2_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/lttf2_test.c?rev=205312&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/lttf2_test.c (added)
+++ compiler-rt/trunk/test/builtins/Unit/lttf2_test.c Tue Apr 1 08:42:56 2014
@@ -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;
+}
Added: compiler-rt/trunk/test/builtins/Unit/netf2_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/netf2_test.c?rev=205312&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/netf2_test.c (added)
+++ compiler-rt/trunk/test/builtins/Unit/netf2_test.c Tue Apr 1 08:42:56 2014
@@ -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;
+}
Added: compiler-rt/trunk/test/builtins/Unit/unordtf2_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/unordtf2_test.c?rev=205312&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/unordtf2_test.c (added)
+++ compiler-rt/trunk/test/builtins/Unit/unordtf2_test.c Tue Apr 1 08:42:56 2014
@@ -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;
+}
More information about the llvm-commits
mailing list