Blame sysdeps/powerpc/power7/fpu/s_logbf.c

Packit 6c4009
/* logbf(). PowerPC/POWER7 version.
Packit 6c4009
   Copyright (C) 2012-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include "math_private.h"
Packit 6c4009
#include <libm-alias-float.h>
Packit 6c4009
Packit 6c4009
/* This implementation avoids FP to INT conversions by using VSX
Packit 6c4009
   bitwise instructions over FP values.  */
Packit 6c4009
Packit 6c4009
static const double two1div52 = 2.220446049250313e-16;	/* 1/2**52  */
Packit 6c4009
static const double two10m1   = -1023.0;		/* -2**10 + 1  */
Packit 6c4009
static const double two7m1    = -127.0;			/* -2**7 + 1  */
Packit 6c4009
Packit 6c4009
/* FP mask to extract the exponent.  */
Packit 6c4009
static const union {
Packit 6c4009
  unsigned long long mask;
Packit 6c4009
  double d;
Packit 6c4009
} mask = { 0x7ff0000000000000ULL };
Packit 6c4009
Packit 6c4009
float
Packit 6c4009
__logbf (float x)
Packit 6c4009
{
Packit 6c4009
  /* VSX operation are all done internally as double.  */
Packit 6c4009
  double ret;
Packit 6c4009
Packit 6c4009
  if (__builtin_expect (x == 0.0, 0))
Packit 6c4009
    /* Raise FE_DIVBYZERO and return -HUGE_VAL[LF].  */
Packit 6c4009
    return -1.0 / __builtin_fabsf (x);
Packit 6c4009
Packit 6c4009
  /* ret = x & 0x7f800000;  */
Packit 6c4009
  asm (
Packit 6c4009
    "xxland %x0,%x1,%x2\n"
Packit 6c4009
    "fcfid  %0,%0"
Packit 6c4009
    : "=f"(ret)
Packit 6c4009
    : "f" (x), "f" (mask.d));
Packit 6c4009
  /* ret = (ret >> 52) - 1023.0, since ret is double.  */
Packit 6c4009
  ret = (ret * two1div52) + two10m1;
Packit 6c4009
  if (__builtin_expect (ret > -two7m1, 0))
Packit 6c4009
    /* Multiplication is used to set logb (+-INF) = INF.  */
Packit 6c4009
    return (x * x);
Packit 6c4009
  /* Since operations are done with double we don't need
Packit 6c4009
     additional tests for subnormal numbers.
Packit 6c4009
     The test is to avoid logb_downward (0.0) == -0.0.  */
Packit 6c4009
  return ret == -0.0 ? 0.0 : ret;
Packit 6c4009
}
Packit 6c4009
libm_alias_float (__logb, logb)