Beispiel #1
0
long double
__truncl (long double x)
{
  double xh, xl, hi, lo;

  ldbl_unpack (x, &xh, &xl);

  /* Return Inf, Nan, +/-0 unchanged.  */
  if (__builtin_expect (xh != 0.0
			&& __builtin_isless (__builtin_fabs (xh),
					     __builtin_inf ()), 1))
    {
      double orig_xh;

      /* Long double arithmetic, including the canonicalisation below,
	 only works in round-to-nearest mode.  */

      /* Convert the high double to integer.  */
      orig_xh = xh;
      hi = ldbl_nearbyint (xh);

      /* Subtract integral high part from the value.  */
      xh -= hi;
      ldbl_canonicalize (&xh, &xl);

      /* Now convert the low double, adjusted for any remainder from the
         high double.  */
      lo = ldbl_nearbyint (xh);

      /* Adjust the result when the remainder is non-zero.  nearbyint
         rounds values to the nearest integer, and values halfway
         between integers to the nearest even integer.  floorl must
         round towards -Inf.  */
      xh -= lo;
      ldbl_canonicalize (&xh, &xl);

      if (orig_xh < 0.0)
	{
	  if (xh > 0.0 || (xh == 0.0 && xl > 0.0))
	    lo += 1.0;
	}
      else
	{
	  if (xh < 0.0 || (xh == 0.0 && xl < 0.0))
	    lo -= 1.0;
	}

      /* Ensure the final value is canonical.  In certain cases,
         rounding causes hi,lo calculated so far to be non-canonical.  */
      xh = hi;
      xl = lo;
      ldbl_canonicalize (&xh, &xl);

      /* Ensure we return -0 rather than +0 when appropriate.  */
      if (orig_xh < 0.0)
	xh = -__builtin_fabs (xh);
    }

  return ldbl_pack (xh, xl);
}
Beispiel #2
0
/* Tanh(x)
 * Return the Hyperbolic Tangent of x
 *
 * Method :
 *				       x    -x
 *				      e  - e
 *	0. tanh(x) is defined to be -----------
 *				       x    -x
 *				      e  + e
 *	1. reduce x to non-negative by tanh(-x) = -tanh(x).
 *	2.  0      <= x <= 2**-55 : tanh(x) := x*(one+x)
 *					        -t
 *	    2**-55 <  x <=  1     : tanh(x) := -----; t = expm1(-2x)
 *					       t + 2
 *						     2
 *	    1      <= x <=  22.0  : tanh(x) := 1-  ----- ; t=expm1(2x)
 *						   t + 2
 *	    22.0   <  x <= INF    : tanh(x) := 1.
 *
 * Special cases:
 *	tanh(NaN) is NaN;
 *	only tanh(0)=0 is exact for finite argument.
 */
double __builtin_tanh(double x)
{
	double t,z;
	int jx,ix;

    /* High word of |x|. */
	jx = GET_HI(x);
	ix = jx&0x7fffffff;

    /* x is INF or NaN */
	if(ix>=0x7ff00000) { 
	    if (jx>=0) return one/x+one;    /* tanh(+-inf)=+-1 */
	    else       return __builtin_nan("");    /* tanh(NaN) = NaN */
	}

    /* |x| < 22 */
	if (ix < 0x40360000) {		/* |x|<22 */
	    if (ix<0x3c800000) 		/* |x|<2**-55 */
		return x*(one+x);    	/* tanh(small) = small */
	    if (ix>=0x3ff00000) {	/* |x|>=1  */
		t = __builtin_expm1(two*__builtin_fabs(x));
		z = one - two/(t+two);
	    } else {
	        t = __builtin_expm1(-two*__builtin_fabs(x));
	        z= -t/(t+two);
	    }
    /* |x| > 22, return +-1 */
	} else {
	    z = one - tiny;		/* raised inexact flag */
	}
	return (jx>=0)? z: -z;
}
int main()
{
    printf("%f\n", __builtin_fabsf(negative10()));
    printf("%f\n", __builtin_fabsf(positive42()));
    printf("%f\n", __builtin_fabsf(negative_dbl_max()));

    printf("%f\n", __builtin_fabs(negative10()));
    printf("%f\n", __builtin_fabs(positive42()));
    printf("%f\n", __builtin_fabs(negative_dbl_max()));
}
Beispiel #4
0
int main(int argc, char ** argv)
{
  unsigned int x = 0x12345678;
  unsigned int y = 0xDEADBEEF;
  unsigned long long xx = 0x1234567812345678ULL;
  unsigned z;
  double a = 3.14159;
  double b = 2.718;
  double c = 1.414;
  unsigned short s = 0x1234;

  printf("mulhw(%x, %x) = %x\n", x, y, __builtin_mulhw(x, y));
  printf("mulhwu(%x, %x) = %x\n", x, y, __builtin_mulhwu(x, y));
  printf("clz(%x) = %d\n", x, __builtin_clz(x));
  printf("clzll(%llx) = %d\n", (unsigned long long) x, __builtin_clzll(x));
  printf("clzll(%llx) = %d\n", xx, __builtin_clzll(xx));
  z = __builtin_bswap(x);
  printf("clzll(%lx) = %d\n", z, __builtin_clzll(z));
  printf("bswap(%x) = %x\n", x, __builtin_bswap(x));
  printf("bswap16(%x) = %x\n", s, __builtin_bswap16(s));

  printf("fmadd(%f, %f, %f) = %f\n", a, b, c, __builtin_fmadd(a, b, c));
  printf("fmsub(%f, %f, %f) = %f\n", a, b, c, __builtin_fmsub(a, b, c));
  printf("fabs(%f) = %f\n", a, __builtin_fabs(a));
  printf("fabs(%f) = %f\n", -a, __builtin_fabs(-a));
  printf("fsqrt(%f) = %f\n", a, __builtin_fsqrt(a));
  printf("frsqrte(%f) = %s\n",
         a, check_relative_error(1.0 / sqrt(a), __builtin_frsqrte(a), 1./32.));
  printf("fres(%f) = %s\n",
         a, check_relative_error(1.0 / a, __builtin_fres(a), 1./256.));
  printf("fsel(%f, %f, %f) = %f\n", a, b, c, __builtin_fsel(a, b, c));
  printf("fsel(%f, %f, %f) = %f\n", -a, b, c, __builtin_fsel(-a, b, c));
  printf("fcti(%f) = %d\n", a, __builtin_fcti(a));
  printf("fcti(%f) = %d\n", b, __builtin_fcti(b));
  printf("fcti(%f) = %d\n", c, __builtin_fcti(c));
  __builtin_eieio();
  __builtin_sync();
  __builtin_isync();
  printf("isel(%d, %d, %d) = %d\n", 0, x, y, __builtin_isel(0, x, y));
  printf("isel(%d, %d, %d) = %d\n", 42, x, y, __builtin_isel(42, x, y));
  printf ("read_16_rev = %x\n", __builtin_read16_reversed(&s));
  printf ("read_32_rev = %x\n", __builtin_read32_reversed(&y));
  __builtin_write16_reversed(&s, 0x789A);
  printf ("after write_16_rev: %x\n", s);
  __builtin_write32_reversed(&y, 0x12345678);
  printf ("after write_32_rev: %x\n", y);
  y = 0;
  __builtin_write32_reversed(&y, 0x12345678);
  printf ("CSE write_32_rev: %s\n", y == 0x78563412 ? "ok" : "ERROR");
  /* Make sure that ignoring the result of a builtin
     doesn't cause an internal error */
  (void) __builtin_bswap(x);
  (void) __builtin_fsqrt(a);
  return 0;
}
Beispiel #5
0
double __builtin_logb(double x)
{
	int lx,ix;
	ix = (GET_HI(x))&0x7fffffff;	/* high |x| */
	lx = GET_LO(x);			/* low x */
	if((ix|lx)==0) return -1.0/__builtin_fabs(x);
	if(ix>=0x7ff00000) return __builtin_fabs(x);
	if((ix>>=20)==0) 			/* IEEE 754 logb */
		return -1022.0; 
	else
		return (double) (ix-1023); 
Beispiel #6
0
int
main ()
{
  unsigned x[3] = { 0, 128, 0 };
  double y[3];

  bar (x, y);
  if (__builtin_fabs (y[0] - 0.33333) > 0.001
      || __builtin_fabs (y[1] - 1) > 0.001
      || __builtin_fabs (y[2] - 0.25098) > 0.001)
    __builtin_abort ();

  return 0;
}
Beispiel #7
0
void test32(void)
{
  volatile float val[8];
  int i, j;

  printf("--- Single precision\n");
  val[0] = 0.0f;
  val[1] = - val[0];
  val[2] = single_of_bits(0x7F800000);
  val[3] = - val[2];

  val[4] = single_of_bits(0x7F800005);
  val[5] = single_of_bits(0x7FC00006);
  val[6] = single_of_bits(0xFF800009);
  val[7] = single_of_bits(0xFFC00001);

  for (i = 0; i < 8; i++) {
    printf("opp(%s) = 0x%08x\n", valname[i], bits_of_single(- val[i]));
    printf("double(%s) = 0x%016llx\n", valname[i], bits_of_double((double)(val[i])));
    printf("abs(%s) = 0x%08x\n", valname[i], bits_of_single(__builtin_fabs(val[i])));
    for (j = 0; j < 8; j++) {
      printf("%s + %s = 0x%08x\n",
             valname[i], valname[j], bits_of_single(val[i] + val[j]));
      printf("%s - %s = 0x%08x\n",
             valname[i], valname[j], bits_of_single(val[i] - val[j]));
      printf("%s * %s = 0x%08x\n",
             valname[i], valname[j], bits_of_single(val[i] * val[j]));
      printf("%s / %s = 0x%08x\n",
             valname[i], valname[j], bits_of_single(val[i] / val[j]));
    }
  }
}
Beispiel #8
0
int
main (int argc, char **argv)
{
  float f1 = 3.14159f;
  float f2 = 2.718f;
  /* This 'assembler' statement should be portable between ARM and AArch64.  */
  asm volatile ("" : : : "memory");
  __fp16 in1 = f1;
  __fp16 in2 = f2;

  /* Do the addition on __fp16's (implicitly converts both operands to
     float32, adds, converts back to f16, then we convert back to f32).  */
  __fp16 res1 = in1 + in2;
  asm volatile ("" : : : "memory");
  float f_res_1 = res1;

  /* Do the addition on float32's (we convert both operands to f32, and add,
     as above, but skip the final conversion f32 -> f16 -> f32).  */
  float f1a = in1;
  float f2a = in2;
  float f_res_2 = f1a + f2a;

  if (__builtin_fabs (f_res_2 - f_res_1) > EPSILON)
    abort ();
  return 0;
}
Beispiel #9
0
long double
__truncl (long double x)
{
  double xh, xl, hi, lo;

  ldbl_unpack (x, &xh, &xl);

  /* Return Inf, Nan, +/-0 unchanged.  */
  if (__builtin_expect (xh != 0.0
			&& __builtin_isless (__builtin_fabs (xh),
					     __builtin_inf ()), 1))
    {
      hi = __trunc (xh);
      if (hi != xh)
	{
	  /* The high part is not an integer; the low part does not
	     affect the result.  */
	  xh = hi;
	  xl = 0;
	}
      else
	{
	  /* The high part is a nonzero integer.  */
	  lo = xh > 0 ? __floor (xl) : __ceil (xl);
	  xh = hi;
	  xl = lo;
	  ldbl_canonicalize_int (&xh, &xl);
	}
    }

  return ldbl_pack (xh, xl);
}
Beispiel #10
0
int
main (void)
{
  float64x1_t arg1;
  float64x1_t arg2;
  float64x1_t arg3;

  float64_t expected;
  float64_t actual;

  arg1 = vcreate_f64 (0x3fe730af8db9e6f7ULL);
  arg2 = vcreate_f64 (0x3fe6b78680fa29ceULL);
  arg3 = vcreate_f64 (0x3feea3cbf921fbe0ULL);

  INHIB_OPT (arg1);
  INHIB_OPT (arg2);
  INHIB_OPT (arg3);

  expected = 4.4964705746355915e-2;
  actual = vget_lane_f64 (vfms_f64 (arg1, arg2, arg3), 0);

  if (__builtin_fabs (expected - actual) > EPS)
    abort ();

  return 0;
}
Beispiel #11
0
static inline Math::Vector3<double> Vector3Orthonormalize(const double &eps,
														  const Math::Vector3<double> &u,
														  const Math::Vector3<double> &v)
{
    Math::Vector3<double> p;
    
    double D = __builtin_sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
    
	if( __builtin_fabs( D - 1.0 ) > eps )
	{
        double N = u.x * v.x + u.y * v.y + u.z * v.z;
        double Q = N / D;
        
        p.x = u.x - Q * v.x;
        p.y = u.y - Q * v.y;
        p.z = u.z - Q * v.z;
        
        double L = 1.0 / __builtin_sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
        
        p.x *= L;
        p.y *= L;
        p.z *= L;
    } // if
	
	return p;
} // Vector3Orthonormalize
Beispiel #12
0
// CHECK-LABEL: define void @test_float_builtin_ops
void test_float_builtin_ops(float F, double D, long double LD) {
  volatile float resf;
  volatile double resd;
  volatile long double resld;

  resf = __builtin_fmodf(F,F);
  // CHECK: frem float

  resd = __builtin_fmod(D,D);
  // CHECK: frem double

  resld = __builtin_fmodl(LD,LD);
  // CHECK: frem x86_fp80

  resf = __builtin_fabsf(F);
  resd = __builtin_fabs(D);
  resld = __builtin_fabsl(LD);
  // CHECK: call float @llvm.fabs.f32(float
  // CHECK: call double @llvm.fabs.f64(double
  // CHECK: call x86_fp80 @llvm.fabs.f80(x86_fp80

  resf = __builtin_canonicalizef(F);
  resd = __builtin_canonicalize(D);
  resld = __builtin_canonicalizel(LD);
  // CHECK: call float @llvm.canonicalize.f32(float
  // CHECK: call double @llvm.canonicalize.f64(double
  // CHECK: call x86_fp80 @llvm.canonicalize.f80(x86_fp80
}
Beispiel #13
0
int foo (struct reflection_type *r, int n, unsigned s)
{
  int i;
  y = 0;
  w = 0;
  for (i = 1; i < n; ++i)
    {
      struct reflection_type *x = &r[i*s];
      double fpred = x->f_pred;
      double fexp = x->f_exp;
      double tem = (fpred - fexp);
      y += __builtin_fabs (tem / x->f_sigma);
      w += __builtin_fabs (tem / fexp);
    }
  return i;
}
Beispiel #14
0
double atanh( double x )
{
	if( x != x )	return x + x;
	
	double fabsx = __builtin_fabs( x );

	if( fabsx > 1.0)
		return sqrt( -fabsx );
	
	if( fabsx >= 0x1.0p-27 )		//sqrt( negative epsilon )
	{
		fabsx = 0.5 * log1p( (fabsx + fabsx) / (1.0 - fabsx) );
		
	}
	else
	{
		if( x == 0.0 )
			return x;
	
		fabsx *= 0x1.0p55;
		fabsx += 0x1.0p-1022;
		fabsx *= 0x1.0p-55;
	}

	if( x < 0 )
		fabsx = -fabsx;

	return fabsx;
}
Beispiel #15
0
long double
__roundl (long double x)
{
  double xh, xl, hi, lo;

  ldbl_unpack (x, &xh, &xl);

  /* Return Inf, Nan, +/-0 unchanged.  */
  if (__builtin_expect (xh != 0.0
			&& __builtin_isless (__builtin_fabs (xh),
					     __builtin_inf ()), 1))
    {
      hi = __round (xh);
      if (hi != xh)
	{
	  /* The high part is not an integer; the low part only
	     affects the result if the high part is exactly half way
	     between two integers and the low part is nonzero with the
	     opposite sign.  */
	  if (fabs (hi - xh) == 0.5)
	    {
	      if (xh > 0 && xl < 0)
		xh = hi - 1;
	      else if (xh < 0 && xl > 0)
		xh = hi + 1;
	      else
		xh = hi;
	    }
	  else
	    xh = hi;
	  xl = 0;
	}
      else
	{
	  /* The high part is a nonzero integer.  */
	  lo = __round (xl);
	  if (fabs (lo - xl) == 0.5)
	    {
	      if (xh > 0 && xl < 0)
		xl = lo + 1;
	      else if (xh < 0 && lo > 0)
		xl = lo - 1;
	      else
		xl = lo;
	    }
	  else
	    xl = lo;
	  xh = hi;
	  ldbl_canonicalize_int (&xh, &xl);
	}
    }
  else
    /* Quiet signaling NaN arguments.  */
    xh += xh;

  return ldbl_pack (xh, xl);
}
Beispiel #16
0
long double
__roundl (long double x)
{
  double xh, xl, hi, lo;

  ldbl_unpack (x, &xh, &xl);

  /* Return Inf, Nan, +/-0 unchanged.  */
  if (__builtin_expect (xh != 0.0
			&& __builtin_isless (__builtin_fabs (xh),
					     __builtin_inf ()), 1))
    {
      double orig_xh;

      /* Long double arithmetic, including the canonicalisation below,
	 only works in round-to-nearest mode.  */

      /* Convert the high double to integer.  */
      orig_xh = xh;
      hi = ldbl_nearbyint (xh);

      /* Subtract integral high part from the value.  */
      xh -= hi;
      ldbl_canonicalize (&xh, &xl);

      /* Now convert the low double, adjusted for any remainder from the
	 high double.  */
      lo = ldbl_nearbyint (xh);

      /* Adjust the result when the remainder is exactly 0.5.  nearbyint
	 rounds values halfway between integers to the nearest even
	 integer.  roundl must round away from zero.
	 Also correct cases where nearbyint returns an incorrect value
	 for LO.  */
      xh -= lo;
      ldbl_canonicalize (&xh, &xl);
      if (xh == 0.5)
	{
	  if (xl > 0.0 || (xl == 0.0 && orig_xh > 0.0))
	    lo += 1.0;
	}
      else if (-xh == 0.5)
	{
	  if (xl < 0.0 || (xl == 0.0 && orig_xh < 0.0))
	    lo -= 1.0;
	}

      /* Ensure the final value is canonical.  In certain cases,
	 rounding causes hi,lo calculated so far to be non-canonical.  */
      xh = hi;
      xl = lo;
      ldbl_canonicalize (&xh, &xl);
    }

  return ldbl_pack (xh, xl);
}
Beispiel #17
0
/*
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates.
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 * conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
 * conditions and the following disclaimer in the documentation and/or other materials provided
 * with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used to
 * endorse or promote products derived from this software without specific prior written
 * permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
int main() {
  volatile float a = 0.125f;
  if (__builtin_fabs(a) != 0.125f) {
    return 1;
  }
  volatile float b = -0.125f;
  if (__builtin_fabs(b) != 0.125f) {
    return 1;
  }
  volatile float c = 0.f;
  if (__builtin_fabs(c) != 0.f) {
    return 1;
  }
  volatile float d = -0.f;
  if (__builtin_fabs(d) != 0.f) {
    return 1;
  }
  return 0;
}
Beispiel #18
0
int main(int argc, char ** argv)
{
  unsigned int x = 0x12345678;
  unsigned int y = 0xDEADBEEF;
  double a = 3.14159;
  double b = 2.718;
  double c = 1.414;
  unsigned short s = 0x1234;

  printf("mulhw(%x, %x) = %x\n", x, y, __builtin_mulhw(x, y));
  printf("mulhwu(%x, %x) = %x\n", x, y, __builtin_mulhwu(x, y));
  printf("cntlz(%x) = %d\n", x, __builtin_clz(x));
  printf("bswap(%x) = %x\n", x, __builtin_bswap(x));
  printf("bswap16(%x) = %x\n", s, __builtin_bswap16(s));

  printf("fmadd(%f, %f, %f) = %f\n", a, b, c, __builtin_fmadd(a, b, c));
  printf("fmsub(%f, %f, %f) = %f\n", a, b, c, __builtin_fmsub(a, b, c));
  printf("fabs(%f) = %f\n", a, __builtin_fabs(a));
  printf("fabs(%f) = %f\n", -a, __builtin_fabs(-a));
  printf("fsqrt(%f) = %f\n", a, __builtin_fsqrt(a));
  printf("frsqrte(%f) = %f\n", a, __builtin_frsqrte(a));
  printf("fres(%f) = %f\n", a, __builtin_fres(a));
  printf("fsel(%f, %f, %f) = %f\n", a, b, c, __builtin_fsel(a, b, c));
  printf("fsel(%f, %f, %f) = %f\n", -a, b, c, __builtin_fsel(-a, b, c));
  printf("fcti(%f) = %d\n", a, __builtin_fcti(a));
  printf("fcti(%f) = %d\n", b, __builtin_fcti(b));
  printf("fcti(%f) = %d\n", c, __builtin_fcti(c));
  __builtin_eieio();
  __builtin_sync();
  __builtin_isync();
  printf ("read_16_rev = %x\n", __builtin_read16_reversed(&s));
  printf ("read_32_rev = %x\n", __builtin_read32_reversed(&y));
  __builtin_write16_reversed(&s, 0x789A);
  printf ("after write_16_rev: %x\n", s);
  __builtin_write32_reversed(&y, 0x12345678);
  printf ("after write_32_rev: %x\n", y);
  y = 0;
  __builtin_write32_reversed(&y, 0x12345678);
  printf ("CSE write_32_rev: %s\n", y == 0x78563412 ? "ok" : "ERROR");

  return 0;
}
Beispiel #19
0
int
main (void)
{
  volatile uint64_t expected;
  uint64_t actual;

  int i, j;

  for (i = 0; i < SIZE; ++i)
   for (j = 0; j < SIZE; ++j)
     {
        expected = __builtin_fabs (in[i]) < __builtin_fabs (in[j]) ? -1 : 0;
        actual = vcaltd_f64 (in[i], in[j]);

        if (actual != expected)
          abort ();
     }

  return 0;
}
Beispiel #20
0
int
main (void)
{
  uint64_t expected;
  uint64_t actual;
  float64x1_t arg1, arg2;
  int i, j;

  for (i = 0; i < SIZE; ++i)
   for (j = 0; j < SIZE; ++j)
     {
        expected = __builtin_fabs (in[i]) >= __builtin_fabs (in[j]) ? -1 : 0;
        arg1 = (float64x1_t) { in[i] };
        arg2 = (float64x1_t) { in[j] };
        actual = vget_lane_u64 (vcage_f64 (arg1, arg2), 0);

        if (actual != expected)
          abort ();
     }

  return 0;
}
Beispiel #21
0
__attribute__((noinline, noclone)) void
bar (double p[][4])
{
  int i;
  double d = 172.0;
  for (i = 0; i < 4096; i++)
    {
      if (p[i][0] != 6.0 || p[i][1] != 6.0 || p[i][2] != 10.0)
	__builtin_abort ();
      if (__builtin_fabs (p[i][3] - d) > 0.25)
	__builtin_abort ();
    }
}
Beispiel #22
0
/* 
 * wrapper asin(x)
 */
double __builtin_asin(double x)		/* wrapper asin */
{
#ifdef _IEEE_LIBM
	return __hide_ieee754_asin(x);
#else
	double z;
	z = __hide_ieee754_asin(x);
	if(_LIB_VERSION == _IEEE_ || __builtin_isnan(x)) return z;
	if(__builtin_fabs(x)>1.0) {
	        return __hide_kernel_standard(x,x,2); /* asin(|x|>1) */
	} else
	    return z;
#endif
}
Beispiel #23
0
int __fpclassifyd( double x )
{
    x = __builtin_fabs(x);
    if( EXPECT_FALSE( x == 0.0 ) )
        return FP_ZERO;
        
    if( EXPECT_FALSE( x < 0x1.0p-1022 ) )
        return FP_SUBNORMAL;
    
    if( EXPECT_TRUE( x < __builtin_inf() ) )
        return FP_NORMAL;
        
    if( EXPECT_TRUE( x == __builtin_inf() ) )
        return FP_INFINITE;

    return FP_NAN;
}
Beispiel #24
0
static inline Math::Vector2<double> Vector2Normalize(const double eps,
													 const Math::Vector2<double> &v)
{
    Math::Vector2<double> p(v);
    
	double L = __builtin_sqrt(v.x * v.x + v.y * v.y);
    
	if( __builtin_fabs( L - 1.0 ) > eps )
	{
		L = 1.0/L;
		
		p.x *= L;
		p.y *= L;
	} // if
	
	return p;
} // Vector2Normalize
static float rintf (float x)
{
	volatile float TWO23 = 8388608.0;

	if (__builtin_fabs (x) < TWO23)
	{
		if (x > 0.0)
		{
			x += TWO23;
			x -= TWO23;
		}
		else if (x < 0.0)
		{
			x = TWO23 - x;
			x = -(x - TWO23);
		}
	}

	return x;
}
Beispiel #26
0
double __hide_ieee754_asin(double x)
{
	double t=0.0,w,p,q,c,r,s;
	int hx,ix;
	hx = GET_HI(x);
	ix = hx&0x7fffffff;
	if(ix>= 0x3ff00000) {		/* |x|>= 1 */
	    if(((ix-0x3ff00000)|GET_LO(x))==0)
		    /* asin(1)=+-pi/2 with inexact */
		return x*pio2_hi+x*pio2_lo;	
	    return __builtin_nan("");		/* asin(|x|>1) is NaN */   
	} else if (ix<0x3fe00000) {	/* |x|<0.5 */
	    if(ix<0x3e400000) {		/* if |x| < 2**-27 */
		if(huge+x>one) return x;/* return x with inexact if x!=0*/
	    } else 
		t = x*x;
		p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
		q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
		w = p/q;
		return x+x*w;
	}
	/* 1> |x|>= 0.5 */
	w = one-__builtin_fabs(x);
	t = w*0.5;
	p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
	q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
	s = __builtin_sqrt(t);
	if(ix>=0x3FEF3333) { 	/* if |x| > 0.975 */
	    w = p/q;
	    t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
	} else {
	    w  = s;
	    SET_LOW_WORD(w, 0);
	    c  = (t-w*w)/(s+w);
	    r  = p/q;
	    p  = 2.0*s*r-(pio2_lo-2.0*c);
	    q  = pio4_hi-2.0*w;
	    t  = pio4_hi-(p-q);
	}    
	if(hx>0) return t; else return -t;    
}
Beispiel #27
0
GNU_FPOST_ATTR

#if CONFIG_POST & CONFIG_SYS_POST_FPU

static float rintf (float x)
{
    volatile float TWO23 = 8388608.0;

    if (__builtin_fabs (x) < TWO23)
    {
        if (x > 0.0)
        {
            x += TWO23;
            x -= TWO23;
        }
        else if (x < 0.0)
        {
            x = TWO23 - x;
            x = -(x - TWO23);
        }
    }

    return x;
}
Beispiel #28
0
float        g7  = __builtin_nanf("");
long double  g8  = __builtin_nanl("");

// GCC constant folds these too (via native strtol):
//double       g6_1  = __builtin_nan("1");
//float        g7_1  = __builtin_nanf("1");
//long double  g8_1  = __builtin_nanl("1");

// APFloat doesn't have signalling NaN functions.
//double       g9  = __builtin_nans("");
//float        g10 = __builtin_nansf("");
//long double  g11 = __builtin_nansl("");

//int          g12 = __builtin_abs(-12);

double       g13 = __builtin_fabs(-12.);
double       g13_0 = __builtin_fabs(-0.);
double       g13_1 = __builtin_fabs(-__builtin_inf());
float        g14 = __builtin_fabsf(-12.f);
// GCC doesn't eat this one.
//long double  g15 = __builtin_fabsfl(-12.0L);

float        g16 = __builtin_copysign(1.0, -1.0);
double       g17 = __builtin_copysignf(1.0f, -1.0f);
long double  g18 = __builtin_copysignl(1.0L, -1.0L);

char classify_nan     [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nan(""))];
char classify_snan    [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nans(""))];
char classify_inf     [__builtin_fpclassify(-1, +1, -1, -1, -1, __builtin_inf())];
char classify_neg_inf [__builtin_fpclassify(-1, +1, -1, -1, -1, -__builtin_inf())];
char classify_normal  [__builtin_fpclassify(-1, -1, +1, -1, -1, 1.539)];
Beispiel #29
0
void test_long(long x) {
  (void)abs(x);  // no warning - int and long are same length for this target
  (void)labs(x);
  (void)llabs(x);

  (void)fabsf(x);
  // expected-warning@-1 {{using floating point absolute value function 'fabsf' when argument is of integer type}}
  // expected-note@-2 {{use function 'labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"labs"
  (void)fabs(x);
  // expected-warning@-1 {{using floating point absolute value function 'fabs' when argument is of integer type}}
  // expected-note@-2 {{use function 'labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"labs"
  (void)fabsl(x);
  // expected-warning@-1 {{using floating point absolute value function 'fabsl' when argument is of integer type}}
  // expected-note@-2 {{use function 'labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"labs"

  (void)cabsf(x);
  // expected-warning@-1 {{using complex absolute value function 'cabsf' when argument is of integer type}}
  // expected-note@-2 {{use function 'labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"labs"
  (void)cabs(x);
  // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of integer type}}
  // expected-note@-2 {{use function 'labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"labs"
  (void)cabsl(x);
  // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of integer type}}
  // expected-note@-2 {{use function 'labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"labs"

  (void)__builtin_abs(x);  // no warning - int and long are same length for
                           // this target
  (void)__builtin_labs(x);
  (void)__builtin_llabs(x);

  (void)__builtin_fabsf(x);
  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsf' when argument is of integer type}}
  // expected-note@-2 {{use function '__builtin_labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_labs"
  (void)__builtin_fabs(x);
  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabs' when argument is of integer type}}
  // expected-note@-2 {{use function '__builtin_labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_labs"
  (void)__builtin_fabsl(x);
  // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsl' when argument is of integer type}}
  // expected-note@-2 {{use function '__builtin_labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_labs"

  (void)__builtin_cabsf(x);
  // expected-warning@-1 {{using complex absolute value function '__builtin_cabsf' when argument is of integer type}}
  // expected-note@-2 {{use function '__builtin_labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_labs"
  (void)__builtin_cabs(x);
  // expected-warning@-1 {{using complex absolute value function '__builtin_cabs' when argument is of integer type}}
  // expected-note@-2 {{use function '__builtin_labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_labs"
  (void)__builtin_cabsl(x);
  // expected-warning@-1 {{using complex absolute value function '__builtin_cabsl' when argument is of integer type}}
  // expected-note@-2 {{use function '__builtin_labs' instead}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_labs"
}
Beispiel #30
0
void test_unsigned_long(unsigned long x) {
  (void)abs(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to 'abs' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:""
  (void)labs(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to 'labs' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:""
  (void)llabs(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to 'llabs' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:""

  (void)fabsf(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to 'fabsf' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:""
  (void)fabs(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to 'fabs' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:""
  (void)fabsl(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to 'fabsl' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:""

  (void)cabsf(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to 'cabsf' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:""
  (void)cabs(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to 'cabs' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:""
  (void)cabsl(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to 'cabsl' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:""

  (void)__builtin_abs(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to '__builtin_abs' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:""
  (void)__builtin_labs(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to '__builtin_labs' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:""
  (void)__builtin_llabs(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to '__builtin_llabs' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:""

  (void)__builtin_fabsf(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to '__builtin_fabsf' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:""
  (void)__builtin_fabs(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to '__builtin_fabs' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:""
  (void)__builtin_fabsl(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to '__builtin_fabsl' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:""

  (void)__builtin_cabsf(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to '__builtin_cabsf' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:""
  (void)__builtin_cabs(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to '__builtin_cabs' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:""
  (void)__builtin_cabsl(x);
  // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}}
  // expected-note@-2 {{remove the call to '__builtin_cabsl' since unsigned values cannot be negative}}
  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:""
}