(root)/
glibc-2.38/
sysdeps/
ieee754/
ldbl-128ibm/
s_totalordermagl.c
       1  /* Total order operation on absolute values.  ldbl-128ibm 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 <nan-high-order-bit.h>
      22  #include <stdint.h>
      23  #include <shlib-compat.h>
      24  
      25  int
      26  __totalordermagl (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 x_sign = hx & 0x8000000000000000ULL;
      39    uint64_t y_sign = hy & 0x8000000000000000ULL;
      40    hx ^= x_sign;
      41    hy ^= y_sign;
      42    if (hx < hy)
      43      return 1;
      44    else if (hx > hy)
      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 >= 0x7ff0000000000000ULL)
      51      return 1;
      52    EXTRACT_WORDS64 (lx, xlo);
      53    EXTRACT_WORDS64 (ly, ylo);
      54    if (((lx | ly) & 0x7fffffffffffffffULL) == 0)
      55      return 1;
      56    lx ^= x_sign;
      57    ly ^= y_sign;
      58  
      59    /* Otherwise compare the low parts.  */
      60    uint64_t lx_sign = lx >> 63;
      61    uint64_t ly_sign = ly >> 63;
      62    lx ^= lx_sign >> 1;
      63    ly ^= ly_sign >> 1;
      64    return lx <= ly;
      65  }
      66  versioned_symbol (libm, __totalordermagl, totalordermagl, GLIBC_2_31);
      67  #if SHLIB_COMPAT (libm, GLIBC_2_25, GLIBC_2_31)
      68  int
      69  attribute_compat_text_section
      70  __totalordermag_compatl (long double x, long double y)
      71  {
      72    return __totalordermagl (&x, &y);
      73  }
      74  compat_symbol (libm, __totalordermag_compatl, totalordermagl, GLIBC_2_25);
      75  #endif