(root)/
glibc-2.38/
sysdeps/
powerpc/
fpu/
s_logbf.c
       1  /* Get exponent of a floating-point value.  PowerPC version.
       2     Copyright (C) 2012-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  /* ISA 2.07 provides fast GPR to FP instruction (mfvsr{d,wz}) which make
      20     generic implementation faster.  */
      21  #if defined(_ARCH_PWR8) || !defined(_ARCH_PWR7)
      22  # include <sysdeps/ieee754/flt-32/s_logbf.c>
      23  #else
      24  # include <math.h>
      25  # include <libm-alias-float.h>
      26  /* This implementation avoids FP to INT conversions by using VSX
      27     bitwise instructions over FP values.  */
      28  float
      29  __logbf (float x)
      30  {
      31    /* VSX operation are all done internally as double.  */
      32    double ret;
      33  
      34    if (__glibc_unlikely (x == 0.0))
      35      /* Raise FE_DIVBYZERO and return -HUGE_VAL[LF].  */
      36      return -1.0 / fabs (x);
      37  
      38    /* mask to extract the exponent.  */
      39    asm ("xxland %x0,%x1,%x2\n"
      40         "fcfid  %0,%0"
      41         : "=d"(ret)
      42         : "d" (x), "d" (0x7ff0000000000000ULL));
      43    /* ret = (ret >> 52) - 1023.0, since ret is double.  */
      44    ret = (ret * 0x1p-52) - 1023.0;
      45    if (ret > 127.0)
      46      /* Multiplication is used to set logb (+-INF) = INF.  */
      47      return (x * x);
      48    /* Since operations are done with double we don't need
      49       additional tests for subnormal numbers.
      50       The test is to avoid logb_downward (0.0) == -0.0.  */
      51    return ret == -0.0 ? 0.0 : ret;
      52  }
      53  # ifndef __logbf
      54  libm_alias_float (__logb, logb)
      55  # endif
      56  #endif