xref: /freebsd/contrib/llvm-project/compiler-rt/lib/builtins/comparedf2.c (revision fe6060f10f634930ff71b7c50291ddc610da2475)
10b57cec5SDimitry Andric //===-- lib/comparedf2.c - Double-precision comparisons -----------*- C -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // // This file implements the following soft-float comparison routines:
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //   __eqdf2   __gedf2   __unorddf2
120b57cec5SDimitry Andric //   __ledf2   __gtdf2
130b57cec5SDimitry Andric //   __ltdf2
140b57cec5SDimitry Andric //   __nedf2
150b57cec5SDimitry Andric //
160b57cec5SDimitry Andric // The semantics of the routines grouped in each column are identical, so there
170b57cec5SDimitry Andric // is a single implementation for each, and wrappers to provide the other names.
180b57cec5SDimitry Andric //
190b57cec5SDimitry Andric // The main routines behave as follows:
200b57cec5SDimitry Andric //
210b57cec5SDimitry Andric //   __ledf2(a,b) returns -1 if a < b
220b57cec5SDimitry Andric //                         0 if a == b
230b57cec5SDimitry Andric //                         1 if a > b
240b57cec5SDimitry Andric //                         1 if either a or b is NaN
250b57cec5SDimitry Andric //
260b57cec5SDimitry Andric //   __gedf2(a,b) returns -1 if a < b
270b57cec5SDimitry Andric //                         0 if a == b
280b57cec5SDimitry Andric //                         1 if a > b
290b57cec5SDimitry Andric //                        -1 if either a or b is NaN
300b57cec5SDimitry Andric //
310b57cec5SDimitry Andric //   __unorddf2(a,b) returns 0 if both a and b are numbers
320b57cec5SDimitry Andric //                           1 if either a or b is NaN
330b57cec5SDimitry Andric //
340b57cec5SDimitry Andric // Note that __ledf2( ) and __gedf2( ) are identical except in their handling of
350b57cec5SDimitry Andric // NaN values.
360b57cec5SDimitry Andric //
370b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric #define DOUBLE_PRECISION
400b57cec5SDimitry Andric #include "fp_lib.h"
410b57cec5SDimitry Andric 
42*fe6060f1SDimitry Andric #include "fp_compare_impl.inc"
430b57cec5SDimitry Andric 
__ledf2(fp_t a,fp_t b)44*fe6060f1SDimitry Andric COMPILER_RT_ABI CMP_RESULT __ledf2(fp_t a, fp_t b) { return __leXf2__(a, b); }
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric #if defined(__ELF__)
470b57cec5SDimitry Andric // Alias for libgcc compatibility
COMPILER_RT_ALIAS(__ledf2,__cmpdf2)480b57cec5SDimitry Andric COMPILER_RT_ALIAS(__ledf2, __cmpdf2)
490b57cec5SDimitry Andric #endif
500b57cec5SDimitry Andric COMPILER_RT_ALIAS(__ledf2, __eqdf2)
510b57cec5SDimitry Andric COMPILER_RT_ALIAS(__ledf2, __ltdf2)
520b57cec5SDimitry Andric COMPILER_RT_ALIAS(__ledf2, __nedf2)
530b57cec5SDimitry Andric 
54*fe6060f1SDimitry Andric COMPILER_RT_ABI CMP_RESULT __gedf2(fp_t a, fp_t b) { return __geXf2__(a, b); }
550b57cec5SDimitry Andric 
COMPILER_RT_ALIAS(__gedf2,__gtdf2)560b57cec5SDimitry Andric COMPILER_RT_ALIAS(__gedf2, __gtdf2)
570b57cec5SDimitry Andric 
58*fe6060f1SDimitry Andric COMPILER_RT_ABI CMP_RESULT __unorddf2(fp_t a, fp_t b) {
59*fe6060f1SDimitry Andric   return __unordXf2__(a, b);
600b57cec5SDimitry Andric }
610b57cec5SDimitry Andric 
620b57cec5SDimitry Andric #if defined(__ARM_EABI__)
630b57cec5SDimitry Andric #if defined(COMPILER_RT_ARMHF_TARGET)
__aeabi_dcmpun(fp_t a,fp_t b)640b57cec5SDimitry Andric AEABI_RTABI int __aeabi_dcmpun(fp_t a, fp_t b) { return __unorddf2(a, b); }
650b57cec5SDimitry Andric #else
COMPILER_RT_ALIAS(__unorddf2,__aeabi_dcmpun)660b57cec5SDimitry Andric COMPILER_RT_ALIAS(__unorddf2, __aeabi_dcmpun)
670b57cec5SDimitry Andric #endif
680b57cec5SDimitry Andric #endif
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric #if defined(_WIN32) && !defined(__MINGW32__)
710b57cec5SDimitry Andric // The alias mechanism doesn't work on Windows except for MinGW, so emit
720b57cec5SDimitry Andric // wrapper functions.
730b57cec5SDimitry Andric int __eqdf2(fp_t a, fp_t b) { return __ledf2(a, b); }
__ltdf2(fp_t a,fp_t b)740b57cec5SDimitry Andric int __ltdf2(fp_t a, fp_t b) { return __ledf2(a, b); }
__nedf2(fp_t a,fp_t b)750b57cec5SDimitry Andric int __nedf2(fp_t a, fp_t b) { return __ledf2(a, b); }
__gtdf2(fp_t a,fp_t b)760b57cec5SDimitry Andric int __gtdf2(fp_t a, fp_t b) { return __gedf2(a, b); }
770b57cec5SDimitry Andric #endif
78