]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/ieee754/ldbl-128/s_totalorderl.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / ieee754 / ldbl-128 / s_totalorderl.c
CommitLineData
5e9d98a3 1/* Total order operation. ldbl-128 version.
04277e02 2 Copyright (C) 2016-2019 Free Software Foundation, Inc.
5e9d98a3
JM
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
5a82c748 17 <https://www.gnu.org/licenses/>. */
5e9d98a3
JM
18
19#include <math.h>
20#include <math_private.h>
fd3b4e7c 21#include <libm-alias-ldouble.h>
6f322a89 22#include <nan-high-order-bit.h>
5e9d98a3 23#include <stdint.h>
42760d76
JM
24#include <shlib-compat.h>
25#include <first-versions.h>
5e9d98a3
JM
26
27int
42760d76 28__totalorderl (const _Float128 *x, const _Float128 *y)
5e9d98a3
JM
29{
30 int64_t hx, hy;
31 uint64_t lx, ly;
42760d76
JM
32 GET_LDOUBLE_WORDS64 (hx, lx, *x);
33 GET_LDOUBLE_WORDS64 (hy, ly, *y);
6f322a89 34#if HIGH_ORDER_BIT_IS_SET_FOR_SNAN
5e9d98a3
JM
35 uint64_t uhx = hx & 0x7fffffffffffffffULL;
36 uint64_t uhy = hy & 0x7fffffffffffffffULL;
37 /* For the preferred quiet NaN convention, this operation is a
38 comparison of the representations of the arguments interpreted as
39 sign-magnitude integers. If both arguments are NaNs, invert the
40 quiet/signaling bit so comparing that way works. */
41 if ((uhx > 0x7fff000000000000ULL || (uhx == 0x7fff000000000000ULL
42 && lx != 0))
43 && (uhy > 0x7fff000000000000ULL || (uhy == 0x7fff000000000000ULL
44 && ly != 0)))
45 {
46 hx ^= 0x0000800000000000ULL;
47 hy ^= 0x0000800000000000ULL;
48 }
49#endif
50 uint64_t hx_sign = hx >> 63;
51 uint64_t hy_sign = hy >> 63;
52 hx ^= hx_sign >> 1;
53 lx ^= hx_sign;
54 hy ^= hy_sign >> 1;
55 ly ^= hy_sign;
56 return hx < hy || (hx == hy && lx <= ly);
57}
42760d76
JM
58#ifdef SHARED
59# define CONCATX(x, y) x ## y
60# define CONCAT(x, y) CONCATX (x, y)
61# define UNIQUE_ALIAS(name) CONCAT (name, __COUNTER__)
62# define do_symbol(orig_name, name, aliasname) \
63 strong_alias (orig_name, name) \
64 versioned_symbol (libm, name, aliasname, GLIBC_2_31)
65# undef weak_alias
66# define weak_alias(name, aliasname) \
67 do_symbol (name, UNIQUE_ALIAS (name), aliasname);
68#endif
fd3b4e7c 69libm_alias_ldouble (__totalorder, totalorder)
42760d76
JM
70#if SHLIB_COMPAT (libm, GLIBC_2_25, GLIBC_2_31)
71int
72attribute_compat_text_section
73__totalorder_compatl (_Float128 x, _Float128 y)
74{
75 return __totalorderl (&x, &y);
76}
77#undef do_symbol
78#define do_symbol(orig_name, name, aliasname) \
79 strong_alias (orig_name, name) \
80 compat_symbol (libm, name, aliasname, \
81 CONCAT (FIRST_VERSION_libm_, aliasname))
82libm_alias_ldouble (__totalorder_compat, totalorder)
83#endif