1 /* Total order operation. ldbl-128ibm version.
2 Copyright (C) 2016-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <math.h>
20 #include <math_private.h>
21 #include <nan-high-order-bit.h>
22 #include <stdint.h>
23 #include <shlib-compat.h>
24
25 int
__totalorderl(const long double * x,const long double * y)26 __totalorderl (const long double *x, const long double *y)
27 {
28 double xhi, xlo, yhi, ylo;
29 int64_t hx, hy, lx, ly;
30
31 ldbl_unpack (*x, &xhi, &xlo);
32 EXTRACT_WORDS64 (hx, xhi);
33 ldbl_unpack (*y, &yhi, &ylo);
34 EXTRACT_WORDS64 (hy, yhi);
35 #if HIGH_ORDER_BIT_IS_SET_FOR_SNAN
36 # error not implemented
37 #endif
38 uint64_t hx_sign = hx >> 63;
39 uint64_t hy_sign = hy >> 63;
40 int64_t hx_adj = hx ^ (hx_sign >> 1);
41 int64_t hy_adj = hy ^ (hy_sign >> 1);
42 if (hx_adj < hy_adj)
43 return 1;
44 else if (hx_adj > hy_adj)
45 return 0;
46
47 /* The high doubles are identical. If they are NaNs or both the low
48 parts are zero, the low parts are not significant (and if they
49 are infinities, both the low parts must be zero). */
50 if ((hx & 0x7fffffffffffffffULL) >= 0x7ff0000000000000ULL)
51 return 1;
52 EXTRACT_WORDS64 (lx, xlo);
53 EXTRACT_WORDS64 (ly, ylo);
54 if (((lx | ly) & 0x7fffffffffffffffULL) == 0)
55 return 1;
56
57 /* Otherwise compare the low parts. */
58 uint64_t lx_sign = lx >> 63;
59 uint64_t ly_sign = ly >> 63;
60 lx ^= lx_sign >> 1;
61 ly ^= ly_sign >> 1;
62 return lx <= ly;
63 }
64 versioned_symbol (libm, __totalorderl, totalorderl, GLIBC_2_31);
65 #if SHLIB_COMPAT (libm, GLIBC_2_25, GLIBC_2_31)
66 int
67 attribute_compat_text_section
__totalorder_compatl(long double x,long double y)68 __totalorder_compatl (long double x, long double y)
69 {
70 return __totalorderl (&x, &y);
71 }
72 compat_symbol (libm, __totalorder_compatl, totalorderl, GLIBC_2_25);
73 #endif
74