aboutsummaryrefslogtreecommitdiff
path: root/compiler-rt/lib/builtins/comparetf2.c
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/lib/builtins/comparetf2.c')
-rw-r--r--compiler-rt/lib/builtins/comparetf2.c81
1 files changed, 5 insertions, 76 deletions
diff --git a/compiler-rt/lib/builtins/comparetf2.c b/compiler-rt/lib/builtins/comparetf2.c
index 2eb34cf37fbc..f1592454138c 100644
--- a/compiler-rt/lib/builtins/comparetf2.c
+++ b/compiler-rt/lib/builtins/comparetf2.c
@@ -40,45 +40,9 @@
#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 };
+#include "fp_compare_impl.inc"
-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;
- }
-}
+COMPILER_RT_ABI CMP_RESULT __letf2(fp_t a, fp_t b) { return __leXf2__(a, b); }
#if defined(__ELF__)
// Alias for libgcc compatibility
@@ -88,47 +52,12 @@ COMPILER_RT_ALIAS(__letf2, __eqtf2)
COMPILER_RT_ALIAS(__letf2, __lttf2)
COMPILER_RT_ALIAS(__letf2, __netf2)
-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 CMP_RESULT __getf2(fp_t a, fp_t b) { return __geXf2__(a, b); }
COMPILER_RT_ALIAS(__getf2, __gttf2)
-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;
+COMPILER_RT_ABI CMP_RESULT __unordtf2(fp_t a, fp_t b) {
+ return __unordXf2__(a, b);
}
#endif