(root)/
glibc-2.38/
sysdeps/
ieee754/
ldbl-128/
s_totalorderl.c
       1  /* Total order operation.  ldbl-128 version.
       2     Copyright (C) 2016-2023 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 <libm-alias-ldouble.h>
      22  #include <nan-high-order-bit.h>
      23  #include <stdint.h>
      24  #include <shlib-compat.h>
      25  #include <first-versions.h>
      26  
      27  int
      28  __totalorderl (const _Float128 *x, const _Float128 *y)
      29  {
      30    int64_t hx, hy;
      31    uint64_t lx, ly;
      32    GET_LDOUBLE_WORDS64 (hx, lx, *x);
      33    GET_LDOUBLE_WORDS64 (hy, ly, *y);
      34  #if HIGH_ORDER_BIT_IS_SET_FOR_SNAN
      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  }
      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
      69  libm_alias_ldouble (__totalorder, totalorder)
      70  #if SHLIB_COMPAT (libm, GLIBC_2_25, GLIBC_2_31)
      71  int
      72  attribute_compat_text_section
      73  __totalorder_compatl (_Float128 x, _Float128 y)
      74  {
      75    return __totalorderl (&x, &y);
      76  }
      77  /* On platforms that reuse the _Float128 implementation for IEEE long
      78     double (powerpc64le), the libm_alias_float128_other_r_ldbl macro
      79     (which is called by the libm_alias_ldouble macro) is used to create
      80     aliases between *f128 (_Float128 API) and __*ieee128 functions.
      81     However, this compat version of totalorderl is older than the
      82     availability of __ieee*128 symbols, thus, the compat alias is not
      83     required, nor desired.  */
      84  #undef libm_alias_float128_other_r_ldbl
      85  #define libm_alias_float128_other_r_ldbl(from, to, r)
      86  #undef do_symbol
      87  #define do_symbol(orig_name, name, aliasname)			\
      88    strong_alias (orig_name, name)				\
      89    compat_symbol (libm, name, aliasname,				\
      90  		 CONCAT (FIRST_VERSION_libm_, aliasname))
      91  libm_alias_ldouble (__totalorder_compat, totalorder)
      92  #endif