Пример #1
0
// CHECK-LABEL: define void @bar(
void bar() {
  float f;
  double d;
  long double ld;

  // LLVM's hex representation of float constants is really unfortunate;
  // basically it does a float-to-double "conversion" and then prints the
  // hex form of that.  That gives us weird artifacts like exponents
  // that aren't numerically similar to the original exponent and
  // significand bit-patterns that are offset by three bits (because
  // the exponent was expanded from 8 bits to 11).
  //
  // 0xAE98 == 1010111010011000
  // 0x15D3 == 1010111010011

  f = __builtin_huge_valf();     // CHECK: float    0x7FF0000000000000
  d = __builtin_huge_val();      // CHECK: double   0x7FF0000000000000
  ld = __builtin_huge_vall();    // CHECK: x86_fp80 0xK7FFF8000000000000000
  f = __builtin_nanf("");        // CHECK: float    0x7FF8000000000000
  d = __builtin_nan("");         // CHECK: double   0x7FF8000000000000
  ld = __builtin_nanl("");       // CHECK: x86_fp80 0xK7FFFC000000000000000
  f = __builtin_nanf("0xAE98");  // CHECK: float    0x7FF815D300000000
  d = __builtin_nan("0xAE98");   // CHECK: double   0x7FF800000000AE98
  ld = __builtin_nanl("0xAE98"); // CHECK: x86_fp80 0xK7FFFC00000000000AE98
  f = __builtin_nansf("");       // CHECK: float    0x7FF4000000000000
  d = __builtin_nans("");        // CHECK: double   0x7FF4000000000000
  ld = __builtin_nansl("");      // CHECK: x86_fp80 0xK7FFFA000000000000000
  f = __builtin_nansf("0xAE98"); // CHECK: float    0x7FF015D300000000
  d = __builtin_nans("0xAE98");  // CHECK: double   0x7FF000000000AE98
  ld = __builtin_nansl("0xAE98");// CHECK: x86_fp80 0xK7FFF800000000000AE98

}
Пример #2
0
int
matherr (struct exception* e)
{
  const char *n;

  if (e->type != DOMAIN)
    return 0;

  n = e->name;
  if (__builtin_strcmp (n, "acos") == 0
      || __builtin_strcmp (n, "asin") == 0)
    e->retval = __builtin_nan ("");
  else if (__builtin_strcmp (n, "atan2") == 0)
    {
      if (e->arg1 == 0 && e->arg2 == 0)
	{
	  double nz;

	  nz = -0.0;
	  if (__builtin_memcmp (&e->arg2, &nz, sizeof (double)) != 0)
	    e->retval = e->arg1;
	  else
	    e->retval = copysign (PI, e->arg1);
	}
      else
	return 0;
    }
  else if (__builtin_strcmp (n, "log") == 0
	   || __builtin_strcmp (n, "log10") == 0)
    e->retval = __builtin_nan ("");
  else if (__builtin_strcmp (n, "pow") == 0)
    {
      if (e->arg1 < 0)
	e->retval = __builtin_nan ("");
      else if (e->arg1 == 0 && e->arg2 == 0)
	e->retval = 1.0;
      else if (e->arg1 == 0 && e->arg2 < 0)
	{
	  double i;

	  if (modf (e->arg2, &i) == 0 && ((int64_t) i & 1) == 1)
	    e->retval = copysign (__builtin_inf (), e->arg1);
	  else
	    e->retval = __builtin_inf ();
	}
      else
	return 0;
    }
  else if (__builtin_strcmp (n, "sqrt") == 0)
    {
      if (e->arg1 < 0)
	e->retval = __builtin_nan ("");
      else
	return 0;
    }
  else
    return 0;

  return 1;
}
Пример #3
0
namespace float_limits
{
  // Use some GCC internal stuff here.
  constexpr float       rl78_nan_flt  = static_cast<float>(__builtin_nan(""));
  constexpr float       rl78_inf_flt  = static_cast<float>(__builtin_inf());
  constexpr double      rl78_nan_dbl  = __builtin_nan("");
  constexpr double      rl78_inf_dbl  = __builtin_inf();
  constexpr long double rl78_nan_ldbl = static_cast<long double>(__builtin_nan(""));
  constexpr long double rl78_inf_ldbl = static_cast<long double>(__builtin_inf());
}
Пример #4
0
__complex double
__go_complex128_div (__complex double a, __complex double b)
{
  if (__builtin_expect (b == 0+0i, 0))
    {
      if (!__builtin_isinf (__real__ a)
	  && !__builtin_isinf (__imag__ a)
	  && (__builtin_isnan (__real__ a) || __builtin_isnan (__imag__ a)))
	{
	  /* Pass "1" to nan to match math/bits.go.  */
	  return __builtin_nan("1") + __builtin_nan("1")*1i;
	}
    }
  return a / b;
}
Пример #5
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;
}
Пример #6
0
int
main ()
{
  int i;
  s1[0] = 5.0;
  s1[1] = 6.0;
  s1[2] = 5.0;
  s1[3] = __builtin_nan ("");
  s2[0] = 6.0;
  s2[1] = 5.0;
  s2[2] = 5.0;
  s2[3] = 5.0;
  asm volatile ("" : : : "memory");
  foo ();
  asm volatile ("" : : : "memory");
  for (i = 0; i < 16 * 4; i++)
    if (i >= 12 * 4 && (i & 3) == 3)
      {
	if (s3[i] != 0.0) abort ();
      }
    else
      {
        static int masks[] = { 2, 2|4, 1, 1|4, 1|2, 8, 2, 1 };
        if (s3[i]
	    != (((1 << (i & 3)) & ((i & 4) ? ~masks[i / 8] : masks[i / 8]))
		? -1.0 : 0.0))
	  abort ();
      }
  return 0;
}
Пример #7
0
int
main (void)
{
  const double inf = __builtin_inf ();
  const double nan = __builtin_nan ("");
  volatile double d;

  __int128 i;
  d = INT128_MIN;
  CHECK_BOUNDARY (i, d);
  d = 0.0;
  CHECK_BOUNDARY (i, d);
  d = INT128_MAX;
  CHECK_BOUNDARY (i, d);
  CHECK_NONNUMBERS (i);

  unsigned __int128 u;
  d = UINT128_MAX;
  CHECK_BOUNDARY (u, d);
  d = 0.0;
  CHECK_BOUNDARY (u, d);
  CHECK_NONNUMBERS (u);

  return 0;
}
int
main ()
{
  double nan = __builtin_nan ("");
  float nanf = __builtin_nanf ("");
  long double nanl = __builtin_nanl ("");

  double pinf = __builtin_inf ();
  float pinff = __builtin_inff ();
  long double pinfl = __builtin_infl ();

  if (__builtin_finite (pinf))
    link_error ();
  if (__builtin_finitef (pinff))
    link_error ();
  if (__builtin_finitel (pinfl))
    link_error ();

  if (__builtin_finite (nan))
    link_error ();
  if (__builtin_finitef (nanf))
    link_error ();
  if (__builtin_finitel (nanl))
    link_error ();

  if (!__builtin_finite (4.0))
    link_error ();
  if (!__builtin_finitef (4.0))
    link_error ();
  if (!__builtin_finitel (4.0))
    link_error ();
}
Пример #9
0
/* __ieee754_pow(x,y) return x**y
 *
 *		      n
 * Method:  Let x =  2   * (1+f)
 *	1. Compute and return log2(x) in two pieces:
 *		log2(x) = w1 + w2,
 *	   where w1 has 53-24 = 29 bit trailing zeros.
 *	2. Perform y*log2(x) = n+y' by simulating muti-precision 
 *	   arithmetic, where |y'|<=0.5.
 *	3. Return x**y = 2**n*exp(y'*log2)
 *
 * Special cases:
 *	1.  (anything) ** 0  is 1
 *	2.  (anything) ** 1  is itself
 *	3.  (anything) ** NAN is NAN
 *	4.  NAN ** (anything except 0) is NAN
 *	5.  +-(|x| > 1) **  +INF is +INF
 *	6.  +-(|x| > 1) **  -INF is +0
 *	7.  +-(|x| < 1) **  +INF is +0
 *	8.  +-(|x| < 1) **  -INF is +INF
 *	9.  +-1         ** +-INF is NAN
 *	10. +0 ** (+anything except 0, NAN)               is +0
 *	11. -0 ** (+anything except 0, NAN, odd integer)  is +0
 *	12. +0 ** (-anything except 0, NAN)               is +INF
 *	13. -0 ** (-anything except 0, NAN, odd integer)  is +INF
 *	14. -0 ** (odd integer) = -( +0 ** (odd integer) )
 *	15. +INF ** (+anything except 0,NAN) is +INF
 *	16. +INF ** (-anything except 0,NAN) is +0
 *	17. -INF ** (anything)  = -0 ** (-anything)
 *	18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
 *	19. (-anything except 0 and inf) ** (non-integer) is NAN
 *
 * Accuracy:
 *	pow(x,y) returns x**y nearly rounded. In particular
 *			pow(integer,integer)
 *	always returns the correct integer provided it is 
 *	representable.
 *
 * Constants :
 * The hexadecimal values are the intended ones for the following 
 * constants. The decimal values may be used, provided that the 
 * compiler will convert from decimal to binary accurately enough 
 * to produce the hexadecimal values shown.
 */
double __attribute__((optimize("-fno-unsafe-math-optimizations"))) __hide_ieee754_pow(double x, double y)
{
	double z,ax,z_h,z_l,p_h,p_l;
	double y1,t1,t2,r,s,t,u,v,w;
	int i,j,k,yisint,n;
	int hx,hy,ix,iy;
	unsigned lx,ly;

	hx = GET_HI(x); lx = GET_LO(x);
	hy = GET_HI(y); ly = GET_LO(y);
	ix = hx&0x7fffffff;  iy = hy&0x7fffffff;

    /* y==zero: x**0 = 1 */
	if((iy|ly)==0) return one; 	
	if(x == 1.0) return one;

    /* +-NaN return x+y */
	if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
	   iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) 
		return __builtin_nan("");	

    /* determine if y is an odd int when x < 0
     * yisint = 0	... y is not an integer
     * yisint = 1	... y is an odd int
     * yisint = 2	... y is an even int
     */
	yisint  = 0;
	if(hx<0) {	
	    if(iy>=0x43400000) yisint = 2; /* even integer y */
	    else if(iy>=0x3ff00000) {
		k = (iy>>20)-0x3ff;	   /* exponent */
		if(k>20) {
		    j = ly>>(52-k);
		    if((j<<(52-k))==ly) yisint = 2-(j&1);
		} else if(ly==0) {
Пример #10
0
double __builtin_sin(double x)
{
	double y[2],z=0.0;
	int n, ix;

    /* High word of x. */
	ix = GET_HI(x);

    /* |x| ~< pi/4 */
	ix &= 0x7fffffff;
	if(ix <= 0x3fe921fb) return __hide_kernel_sin(x,z,0);

    /* sin(Inf or NaN) is NaN */
	else if (ix>=0x7ff00000) return __builtin_nan("");

    /* argument reduction needed */
	else {
	    n = __hide_ieee754_rem_pio2(x,y);
	    switch(n&3) {
		case 0: return  __hide_kernel_sin(y[0],y[1],1);
		case 1: return  __hide_kernel_cos(y[0],y[1]);
		case 2: return -__hide_kernel_sin(y[0],y[1],1);
		default:
			return -__hide_kernel_cos(y[0],y[1]);
	    }
	}
}
Пример #11
0
int main(void)
{
  double x = __builtin_nan ("");
  long double y = 1.1L;

  feenableexcept (FE_INEXACT);
  feclearexcept (FE_ALL_EXCEPT);
  x = x + y;
  return fetestexcept(FE_INEXACT);
}
Пример #12
0
	double nan(const char *unused)
{
	double x;

#if __GNUC_PREREQ (3, 3)
	x = __builtin_nan("");
#else
	INSERT_WORDS(x,0x7ff80000,0);
#endif
	return x;
}
Пример #13
0
int
test_main (void)
{
  json_ctx_t json_ctx;
  size_t i;

  bench_start ();

  json_init (&json_ctx, 2, stdout);
  json_attr_object_begin (&json_ctx, TEST_NAME);

  /* Create 2 test arrays, one with 10% zeroes, 10% negative values,
     79% positive values and 1% infinity/NaN.  The other contains
     50% inf, 50% NaN.  This relies on rand behaving correctly.  */

  for (i = 0; i < SIZE; i++)
    {
      int x = rand () & 255;
      arr1[i] = (x < 25) ? 0.0 : ((x < 50) ? -1 : 100);
      if (x == 255) arr1[i] = __builtin_inf ();
      if (x == 254) arr1[i] = __builtin_nan ("0");
      arr2[i] = (x < 128) ? __builtin_inf () : __builtin_nan ("0");
    }

  for (i = 0; i < sizeof (test_list) / sizeof (test_list[0]); i++)
    {
      json_attr_object_begin (&json_ctx, test_list[i].name);
      do_one_test (&json_ctx, test_list[i].fn, arr2, SIZE, "inf/nan");
      json_attr_object_end (&json_ctx);
    }

  for (i = 0; i < sizeof (test_list) / sizeof (test_list[0]); i++)
    {
      json_attr_object_begin (&json_ctx, test_list[i].name);
      do_one_test (&json_ctx, test_list[i].fn, arr1, SIZE, "normal");
      json_attr_object_end (&json_ctx);
    }

  json_attr_object_end (&json_ctx);
  return 0;
}
Пример #14
0
float __builtin_log10f(float x)		/* wrapper log10f */
{
#ifdef _IEEE_LIBM
	return __hide_ieee754_log10f(x);
#else
	float z;
	struct exception exc;
	z = __hide_ieee754_log10f(x);
	if(_LIB_VERSION == _IEEE_ || __builtin_isnan(x)) return z;
	if(x<=(float)0.0) {
#ifndef HUGE_VAL 
#define HUGE_VAL inf
	    double inf = 0.0;

	    SET_HIGH_WORD(inf,0x7ff00000);	/* set inf to infinite */
#endif
	    exc.name = "log10f";
	    exc.err = 0;
	    exc.arg1 = exc.arg2 = (double)x;
	    if (_LIB_VERSION == _SVID_)
               exc.retval = -HUGE;
	    else
	       exc.retval = -HUGE_VAL;
	    if(x==(float)0.0) {
	        /* log10f(0) */
	        exc.type = SING;
	        if (_LIB_VERSION == _POSIX_)
	           errno = ERANGE;
	        else if (!matherr(&exc)) {
	           errno = ERANGE;
	        }
	    } else { 
	        /* log10f(x<0) */
	        exc.type = DOMAIN;
	        if (_LIB_VERSION == _POSIX_)
	           errno = EDOM;
	        else if (!__builtin_matherr(&exc)) {
	           errno = EDOM;
	        }
                exc.retval = __builtin_nan("");
            }
	    if (exc.err != 0)
               errno = exc.err;
            return (float)exc.retval; 
	} else
	    return z;
#endif
}
Пример #15
0
int main() {
  volatile float a = __builtin_nanf("");
  if (__builtin_isfinite(a)) {
    return 1;
  }
  volatile float b = __builtin_inff();
  if (__builtin_isfinite(b)) {
    return 1;
  }
  volatile double c = __builtin_nan("");
  if (__builtin_isfinite(c)) {
    return 1;
  }
  volatile double d = __builtin_inf();
  if (__builtin_isfinite(d)) {
    return 1;
  }
#ifdef __clang__ // TODO: dragonegg uses native calls which do not work with X86_FP80
  volatile long double e = __builtin_nanl("");
  if (__builtin_isfinite(e)) {
    return 1;
  }
  volatile long double f = __builtin_infl();
  if (__builtin_isfinite(f)) {
    return 1;
  }
#endif
  volatile float g = 0;
  if (!__builtin_isfinite(g)) {
    return 1;
  }
  volatile double h = 0;
  if (!__builtin_isfinite(h)) {
    return 1;
  }
#ifdef __clang__ // TODO: dragonegg uses native calls which do not work with X86_FP80
  volatile long double i = 0;
  if (!__builtin_isfinite(i)) {
    return 1;
  }
#endif
  return 0;
}
Пример #16
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;    
}
Пример #17
0
int main() {
  volatile float a = __builtin_nanf("");
  if (!__builtin_isnan(a)) {
    return 1;
  }
  volatile float b = __builtin_nansf("");
  if (!__builtin_isnan(b)) {
    return 1;
  }
  volatile double c = __builtin_nan("");
  if (!__builtin_isnan(c)) {
    return 1;
  }
  volatile double d = __builtin_nans("");
  if (!__builtin_isnan(d)) {
    return 1;
  }
  volatile long double e = __builtin_nanl("");
  if (!__builtin_isnan(e)) {
    return 1;
  }
  volatile long double f = __builtin_nansl("");
  if (!__builtin_isnan(f)) {
    return 1;
  }
  volatile float g = 0;
  if (__builtin_isnan(g)) {
    return 1;
  }
  volatile double h = 0;
  if (__builtin_isnan(h)) {
    return 1;
  }
  volatile long double i = 0;
  if (__builtin_isnan(i)) {
    return 1;
  }
  return 0;
}
Пример #18
0
int
main (void)
{
  errno = 0;
  i = 100;
  d = __builtin_nan ("");
  tester = check_quiet_nan;
  feclearexcept (FE_ALL_EXCEPT);
  test ();

  d = -1.0e80;
  tester = check_large_neg;
  errno = 0;
  test ();

  d = 1.0e80;
  tester = check_large_pos;
  errno = 0;
  test ();

  return 0;
}
Пример #19
0
/* PR c/19984 */
/* { dg-do compile } */
/* { dg-options "-O2 -std=c99 -Wpedantic" } */


double nan (const char *);

const double nok = nan ("");	/* { dg-warning "(not a constant)|(near initialization)" } */

const double ok = __builtin_nan ("");

double
foo ()
{
  double ok2 = nan ("");
  return ok2;
}
Пример #20
0
int
main ()
{
  pinf = __builtin_inf ();
  ninf = -__builtin_inf ();
  NaN = __builtin_nan ("");

  iuneq (ninf, pinf, 0);
  iuneq (NaN, NaN, 1);
  iuneq (pinf, ninf, 0);
  iuneq (1, 4, 0);
  iuneq (3, 3, 1);
  iuneq (5, 2, 0);

  ieq (1, 4, 0);
  ieq (3, 3, 1);
  ieq (5, 2, 0);

  iltgt (ninf, pinf, 1);
  iltgt (NaN, NaN, 0);
  iltgt (pinf, ninf, 1);
  iltgt (1, 4, 1);
  iltgt (3, 3, 0);
  iltgt (5, 2, 1);

  ine (1, 4, 1);
  ine (3, 3, 0);
  ine (5, 2, 1);

  iunlt (NaN, ninf, 1);
  iunlt (pinf, NaN, 1);
  iunlt (pinf, ninf, 0);
  iunlt (pinf, pinf, 0);
  iunlt (ninf, ninf, 0);
  iunlt (1, 4, 1);
  iunlt (3, 3, 0);
  iunlt (5, 2, 0);

  ilt (1, 4, 1);
  ilt (3, 3, 0);
  ilt (5, 2, 0);

  iunle (NaN, ninf, 1);
  iunle (pinf, NaN, 1);
  iunle (pinf, ninf, 0);
  iunle (pinf, pinf, 1);
  iunle (ninf, ninf, 1);
  iunle (1, 4, 1);
  iunle (3, 3, 1);
  iunle (5, 2, 0);

  ile (1, 4, 1);
  ile (3, 3, 1);
  ile (5, 2, 0);

  iungt (NaN, ninf, 1);
  iungt (pinf, NaN, 1);
  iungt (pinf, ninf, 1);
  iungt (pinf, pinf, 0);
  iungt (ninf, ninf, 0);
  iungt (1, 4, 0);
  iungt (3, 3, 0);
  iungt (5, 2, 1);

  igt (1, 4, 0);
  igt (3, 3, 0);
  igt (5, 2, 1);

  iunge (NaN, ninf, 1);
  iunge (pinf, NaN, 1);
  iunge (ninf, pinf, 0);
  iunge (pinf, pinf, 1);
  iunge (ninf, ninf, 1);
  iunge (1, 4, 0);
  iunge (3, 3, 1);
  iunge (5, 2, 1);

  ige (1, 4, 0);
  ige (3, 3, 1);
  ige (5, 2, 1);

  return 0;
}
Пример #21
0
int
main (void)
{
  const double inf = __builtin_inf ();
  const double nan = __builtin_nan ("");
  volatile double d;

  volatile signed char sc;
  d = SCHAR_MIN;
  CHECK_BOUNDARY (sc, d);
  d = 0.0;
  CHECK_BOUNDARY (sc, d);
  d = SCHAR_MAX;
  CHECK_BOUNDARY (sc, d);
  CHECK_NONNUMBERS (sc);

  volatile unsigned char uc;
  d = UCHAR_MAX;
  CHECK_BOUNDARY (uc, d);
  d = 0.0;
  CHECK_BOUNDARY (uc, d);
  CHECK_NONNUMBERS (uc);

  volatile short int s;
  d = SHRT_MIN;
  CHECK_BOUNDARY (s, d);
  d = 0.0;
  CHECK_BOUNDARY (s, d);
  d = SHRT_MAX;
  CHECK_BOUNDARY (s, d);
  CHECK_NONNUMBERS (s);

  volatile unsigned short int us;
  d = USHRT_MAX;
  CHECK_BOUNDARY (us, d);
  d = 0.0;
  CHECK_BOUNDARY (us, d);
  CHECK_NONNUMBERS (us);

  volatile int i;
  d = INT_MIN;
  CHECK_BOUNDARY (i, d);
  d = 0.0;
  CHECK_BOUNDARY (i, d);
  d = INT_MAX;
  CHECK_BOUNDARY (i, d);
  CHECK_NONNUMBERS (i);

  volatile unsigned int u;
  d = UINT_MAX;
  CHECK_BOUNDARY (u, d);
  d = 0.0;
  CHECK_BOUNDARY (u, d);
  CHECK_NONNUMBERS (u);

  volatile long l;
  /* 64-bit vs 32-bit longs matter causes too much of a headache.  */
  d = 0.0;
  CHECK_BOUNDARY (l, d);
  CHECK_NONNUMBERS (l);

  volatile unsigned long ul;
  d = 0.0;
  CHECK_BOUNDARY (ul, d);
  CHECK_NONNUMBERS (ul);

  volatile long long ll;
  d = LLONG_MIN;
  CHECK_BOUNDARY (ll, d);
  d = 0.0;
  CHECK_BOUNDARY (ll, d);
  d = LLONG_MAX;
  CHECK_BOUNDARY (ll, d);
  CHECK_NONNUMBERS (ll);

  volatile unsigned long long ull;
  d = ULLONG_MAX;
  CHECK_BOUNDARY (ull, d);
  d = 0.0;
  CHECK_BOUNDARY (ull, d);
  CHECK_NONNUMBERS (ull);

  return 0;
}
Пример #22
0
// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r3 -emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NAN2008 %s
// RUN: FileCheck -allow-empty -check-prefix=NO-WARNINGS %s < %t
//
// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -march=mips32r6 -emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NAN2008 %s
// RUN: FileCheck -check-prefix=CHECK-MIPS32R6 %s < %t
//
// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64 -emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NANLEGACY %s
// RUN: FileCheck -check-prefix=CHECK-MIPS64 %s < %t
//
// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64r2 -emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NAN2008 %s
// RUN: FileCheck -allow-empty -check-prefix=NO-WARNINGS %s < %t
//
// RUN: %clang -target mips64el-unknown-linux -mnan=legacy -march=mips64r6 -emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NAN2008 %s
// RUN: FileCheck -check-prefix=CHECK-MIPS64R6 %s < %t

// NO-WARNINGS-NOT: warning: ignoring '-mnan=legacy' option
// NO-WARNINGS-NOT: warning: ignoring '-mnan=2008' option

// CHECK-MIPS2: warning: ignoring '-mnan=2008' option because the 'mips2' architecture does not support it
// CHECK-MIPS3: warning: ignoring '-mnan=2008' option because the 'mips3' architecture does not support it
// CHECK-MIPS4: warning: ignoring '-mnan=2008' option because the 'mips4' architecture does not support it
// CHECK-MIPS32: warning: ignoring '-mnan=2008' option because the 'mips32' architecture does not support it
// CHECK-MIPS32R6: warning: ignoring '-mnan=legacy' option because the 'mips32r6' architecture does not support it
// CHECK-MIPS64: warning: ignoring '-mnan=2008' option because the 'mips64' architecture does not support it
// CHECK-MIPS64R6: warning: ignoring '-mnan=legacy' option because the 'mips64r6' architecture does not support it

// CHECK-NANLEGACY: float 0x7FF4000000000000
// CHECK-NAN2008: float 0x7FF8000000000000

float f =  __builtin_nan("");
void bar()
{
  /* An argument of NaN is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_csqrtf (__builtin_nanf("")));
#endif
  foo (__builtin_csqrt (__builtin_nan("")));
  fool (__builtin_csqrtl (__builtin_nanl("")));

  /* An argument of Inf/-Inf is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_csqrtf (__builtin_inff()));
#endif
  foo (__builtin_csqrt (__builtin_inf()));
  fool (__builtin_csqrtl (__builtin_infl()));
#ifndef __SPU__
  foof (__builtin_csqrtf (-__builtin_inff()));
#endif
  foo (__builtin_csqrt (-__builtin_inf()));
  fool (__builtin_csqrtl (-__builtin_infl()));

  /* Check for overflow/underflow.  */
  TESTIT (cexp, 1e20);
  TESTIT (cexp, -1e20);
  
  /* An argument of NaN is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_cpowf (__builtin_nanf(""), 2.5F));
#endif
  foo (__builtin_cpow (__builtin_nan(""), 2.5));
  fool (__builtin_cpowl (__builtin_nanl(""), 2.5L));
#ifndef __SPU__
  foof (__builtin_cpowf (2.5F, __builtin_nanf("")));
#endif
  foo (__builtin_cpow (2.5, __builtin_nan("")));
  fool (__builtin_cpowl (2.5L, __builtin_nanl("")));

  /* An argument of Inf/-Inf is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_cpowf (__builtin_inff(), 2.5F));
#endif
  foo (__builtin_cpow (__builtin_inf(), 2.5));
  fool (__builtin_cpowl (__builtin_infl(), 2.5L));
#ifndef __SPU__
  foof (__builtin_cpowf (-__builtin_inff(), 2.5F));
#endif
  foo (__builtin_cpow (-__builtin_inf(), 2.5));
  fool (__builtin_cpowl (-__builtin_infl(), 2.5L));
#ifndef __SPU__
  foof (__builtin_cpowf (2.5F, __builtin_inff()));
#endif
  foo (__builtin_cpow (2.5, __builtin_inf()));
  fool (__builtin_cpowl (2.5L, __builtin_infl()));
#ifndef __SPU__
  foof (__builtin_cpowf (2.5F, -__builtin_inff()));
#endif
  foo (__builtin_cpow (2.5, -__builtin_inf()));
  fool (__builtin_cpowl (2.5L, -__builtin_infl()));

  /* Check for Inv/NaN return values.  */
  TESTIT2 (cpow, -0.0, -4.5); /* Returns Inf */
  TESTIT2 (cpow, 0.0, -4.5); /* Returns Inf */

  /* Check for overflow/underflow.  */
  foof (__builtin_cpowf (__FLT_MAX__, 3.5F));
  foof (__builtin_cpowf (__FLT_MAX__ * 1.FI, 3.5F));
  foo (__builtin_cpow (__DBL_MAX__, 3.5));
  foo (__builtin_cpow (__DBL_MAX__ * 1.I, 3.5));
  fool (__builtin_cpowl (__LDBL_MAX__, 3.5L));
  fool (__builtin_cpowl (__LDBL_MAX__ * 1.LI, 3.5L));
  TESTIT2 (cpow, 2.0, 0x1p50);
  TESTIT2 (cpow, 2.0, 0x1p28);
  TESTIT2 (cpow, 2.0, 0x1p24);
  foof (__builtin_cpowf (__FLT_MAX__, -3.5F));
  foof (__builtin_cpowf (__FLT_MAX__ * 1.FI, -3.5F));
  foo (__builtin_cpow (__DBL_MAX__, -3.5));
  foo (__builtin_cpow (__DBL_MAX__ * 1.I, -3.5));
  fool (__builtin_cpowl (__LDBL_MAX__, -3.5L));
  fool (__builtin_cpowl (__LDBL_MAX__ * 1.LI, -3.5L));
  TESTIT2 (cpow, 2.0, -0x1p50);
  TESTIT2 (cpow, 2.0, -0x1p28);
  TESTIT2 (cpow, 2.0, -0x1p24);

}
Пример #24
0
// RUN: %clang_cc1 -fsyntax-only -verify %s

// Math stuff

double       g0  = __builtin_huge_val();
float        g1  = __builtin_huge_valf();
long double  g2  = __builtin_huge_vall();

double       g3  = __builtin_inf();
float        g4  = __builtin_inff();
long double  g5  = __builtin_infl();

double       g6  = __builtin_nan("");
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());
int fpu_post_test_math6 (void)
{
	pinf = __builtin_inf ();
	ninf = -__builtin_inf ();
	NaN = __builtin_nan ("");

	iuneq (ninf, pinf, 0);
	iuneq (NaN, NaN, 1);
	iuneq (pinf, ninf, 0);
	iuneq (1, 4, 0);
	iuneq (3, 3, 1);
	iuneq (5, 2, 0);

	ieq (1, 4, 0);
	ieq (3, 3, 1);
	ieq (5, 2, 0);

	iltgt (ninf, pinf, 1);
	iltgt (NaN, NaN, 0);
	iltgt (pinf, ninf, 1);
	iltgt (1, 4, 1);
	iltgt (3, 3, 0);
	iltgt (5, 2, 1);

	ine (1, 4, 1);
	ine (3, 3, 0);
	ine (5, 2, 1);

	iunlt (NaN, ninf, 1);
	iunlt (pinf, NaN, 1);
	iunlt (pinf, ninf, 0);
	iunlt (pinf, pinf, 0);
	iunlt (ninf, ninf, 0);
	iunlt (1, 4, 1);
	iunlt (3, 3, 0);
	iunlt (5, 2, 0);

	ilt (1, 4, 1);
	ilt (3, 3, 0);
	ilt (5, 2, 0);

	iunle (NaN, ninf, 1);
	iunle (pinf, NaN, 1);
	iunle (pinf, ninf, 0);
	iunle (pinf, pinf, 1);
	iunle (ninf, ninf, 1);
	iunle (1, 4, 1);
	iunle (3, 3, 1);
	iunle (5, 2, 0);

	ile (1, 4, 1);
	ile (3, 3, 1);
	ile (5, 2, 0);

	iungt (NaN, ninf, 1);
	iungt (pinf, NaN, 1);
	iungt (pinf, ninf, 1);
	iungt (pinf, pinf, 0);
	iungt (ninf, ninf, 0);
	iungt (1, 4, 0);
	iungt (3, 3, 0);
	iungt (5, 2, 1);

	igt (1, 4, 0);
	igt (3, 3, 0);
	igt (5, 2, 1);

	iunge (NaN, ninf, 1);
	iunge (pinf, NaN, 1);
	iunge (ninf, pinf, 0);
	iunge (pinf, pinf, 1);
	iunge (ninf, ninf, 1);
	iunge (1, 4, 0);
	iunge (3, 3, 1);
	iunge (5, 2, 1);

	ige (1, 4, 0);
	ige (3, 3, 1);
	ige (5, 2, 1);

	if (failed) {
		post_log ("Error in FPU math6 test\n");
		return -1;
	}
	return 0;
}
Пример #26
0
void bar()
{
  /* An argument of NaN is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_exp2f (__builtin_nanf("")));
#endif
  foo (__builtin_exp2 (__builtin_nan("")));
  fool (__builtin_exp2l (__builtin_nanl("")));

  /* An argument of Inf/-Inf is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_exp2f (__builtin_inff()));
#endif
  foo (__builtin_exp2 (__builtin_inf()));
  fool (__builtin_exp2l (__builtin_infl()));
#ifndef __SPU__
  foof (__builtin_exp2f (-__builtin_inff()));
#endif
  foo (__builtin_exp2 (-__builtin_inf()));
  fool (__builtin_exp2l (-__builtin_infl()));

  /* Result overflows MPFR, which in version 2.2.x has 30 exponent bits.  */
  TESTIT (exp2, 0x1p50);
  /* Result underflows MPFR, which in version 2.2.x has 30 exponent bits.  */
  TESTIT (exp2, -0x1p50);

  /* Result overflows GCC's REAL_VALUE_TYPE, which has 26 exponent bits.  */
  TESTIT (exp2, 0x1p28);
  /* Result underflows GCC's REAL_VALUE_TYPE, which has 26 exponent bits.  */
  TESTIT (exp2, -0x1p28);
  
  /* Result overflows (even an extended) C double's mode.  */
  TESTIT (exp2, 0x1p24);
  /* Result underflows (even an extended) C double's mode.  */
  TESTIT (exp2, -0x1p24);

  /* Ensure that normal arguments/results are folded.  */
  TESTIT (exp2, 1.5);
  TESTIT (exp2, -1.5);
  
  /* The asin arg must be [-1 ... 1] inclusive.  */
  TESTIT (asin, -1.5);
  TESTIT (asin, 1.5);

  /* The acos arg must be [-1 ... 1] inclusive.  */
  TESTIT (acos, -1.5);
  TESTIT (acos, 1.5);
  
  /* The acosh arg must be [1 ... Inf] inclusive.  */
  TESTIT (acosh, 0.5);

  /* The atanh arg must be [-1 ... 1] EXclusive.  */
  TESTIT (atanh, -1.0);
  TESTIT (atanh, 1.0);

  /* The log* arg must be [0 ... Inf] EXclusive.  */
  TESTIT (log, -1.0);
  TESTIT (log, 0.0);
  TESTIT (log, -0.0);
  
  TESTIT (log2, -1.0);
  TESTIT (log2, 0.0);
  TESTIT (log2, -0.0);
  
  TESTIT (log10, -1.0);
  TESTIT (log10, 0.0);
  TESTIT (log10, -0.0);
  
  /* The log1p arg must be [-1 ... Inf] EXclusive.  */
  TESTIT (log1p, -2.0);
  TESTIT (log1p, -1.0);

  /* The tgamma arg errors with zero or negative integers.  */
  TESTIT (tgamma, 0.0);
  TESTIT (tgamma, -0.0);
  TESTIT (tgamma, -1.0);
  TESTIT (tgamma, -2.0);
  TESTIT (tgamma, -3.0);

  /* An argument of NaN is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_powf (__builtin_nanf(""), 2.5F));
#endif
  foo (__builtin_pow (__builtin_nan(""), 2.5));
  fool (__builtin_powl (__builtin_nanl(""), 2.5L));
#ifndef __SPU__
  foof (__builtin_powf (2.5F, __builtin_nanf("")));
#endif
  foo (__builtin_pow (2.5, __builtin_nan("")));
  fool (__builtin_powl (2.5L, __builtin_nanl("")));

  /* An argument of Inf/-Inf is not evaluated at compile-time.  */
#ifndef __SPU__
  foof (__builtin_powf (__builtin_inff(), 2.5F));
#endif
  foo (__builtin_pow (__builtin_inf(), 2.5));
  fool (__builtin_powl (__builtin_infl(), 2.5L));
#ifndef __SPU__
  foof (__builtin_powf (-__builtin_inff(), 2.5F));
#endif
  foo (__builtin_pow (-__builtin_inf(), 2.5));
  fool (__builtin_powl (-__builtin_infl(), 2.5L));
#ifndef __SPU__
  foof (__builtin_powf (2.5F, __builtin_inff()));
#endif
  foo (__builtin_pow (2.5, __builtin_inf()));
  fool (__builtin_powl (2.5L, __builtin_infl()));
#ifndef __SPU__
  foof (__builtin_powf (2.5F, -__builtin_inff()));
#endif
  foo (__builtin_pow (2.5, -__builtin_inf()));
  fool (__builtin_powl (2.5L, -__builtin_infl()));

  /* Check for Inv/NaN return values.  */
  TESTIT2 (pow, -0.0, -4.5); /* Returns Inf */
  TESTIT2 (pow, 0.0, -4.5); /* Returns Inf */
  TESTIT2 (pow, -3.0, -4.5); /* Returns NaN */

  /* Check for overflow/underflow.  */
  foof (__builtin_powf (__FLT_MAX__, 3.5F));
  foo (__builtin_pow (__DBL_MAX__, 3.5));
  fool (__builtin_powl (__LDBL_MAX__, 3.5L));
  TESTIT2 (pow, 2.0, 0x1p50);
  foof (__builtin_powf (__FLT_MAX__, -3.5F));
  foo (__builtin_pow (__DBL_MAX__, -3.5));
  fool (__builtin_powl (__LDBL_MAX__, -3.5L));
  TESTIT2 (pow, 2.0, -0x1p50);
  
  /* The sqrt arg must be [0 ... Inf] inclusive.  */
  TESTIT (sqrt, -0.5);
  TESTIT (sqrt, -0.0);
  TESTIT (sqrt, 0.0);

  /* Check for overflow/underflow.  */

  /* These adjustments are too big.  */
#define FLT_EXP_ADJ (2*(__FLT_MAX_EXP__-__FLT_MIN_EXP__)+1)
#define DBL_EXP_ADJ (2*(__DBL_MAX_EXP__-__DBL_MIN_EXP__)+1)
#define LDBL_EXP_ADJ (2*(__LDBL_MAX_EXP__-__LDBL_MIN_EXP__)+1)

  TESTIT2_I2 (ldexp, 1.0, __INT_MAX__);
  TESTIT2_I2 (ldexp, 1.0, -__INT_MAX__-1);
  TESTIT2_I2 (ldexp, -1.0, __INT_MAX__);
  TESTIT2_I2 (ldexp, -1.0, -__INT_MAX__-1);
  TESTIT2_I2ALL (ldexp, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__,
		 DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ);
  TESTIT2_I2ALL (ldexp, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__,
		 -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ);
  TESTIT2_I2ALL (ldexp, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__,
		 __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__);
  TESTIT2_I2ALL (ldexp, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__,
		 __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__);

  TESTIT2_I2 (scalbn, 1.0, __INT_MAX__);
  TESTIT2_I2 (scalbn, 1.0, -__INT_MAX__-1);
  TESTIT2_I2 (scalbn, -1.0, __INT_MAX__);
  TESTIT2_I2 (scalbn, -1.0, -__INT_MAX__-1);
  TESTIT2_I2ALL (scalbn, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__,
		 DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ);
  TESTIT2_I2ALL (scalbn, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__,
		 -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ);
  TESTIT2_I2ALL (scalbn, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__,
		 __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__);
  TESTIT2_I2ALL (scalbn, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__,
		 __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__);

  TESTIT2_I2 (scalbln, 1.0, __LONG_MAX__);
  TESTIT2_I2 (scalbln, 1.0, -__LONG_MAX__-1);
  TESTIT2_I2 (scalbln, -1.0, __LONG_MAX__);
  TESTIT2_I2 (scalbln, -1.0, -__LONG_MAX__-1);
  TESTIT2_I2ALL (scalbln, __FLT_MIN__, FLT_EXP_ADJ, __DBL_MIN__,
		 DBL_EXP_ADJ, __LDBL_MIN__, LDBL_EXP_ADJ);
  TESTIT2_I2ALL (scalbln, __FLT_MAX__, -FLT_EXP_ADJ, __DBL_MAX__,
		 -DBL_EXP_ADJ, __LDBL_MAX__, -LDBL_EXP_ADJ);
  TESTIT2_I2ALL (scalbln, __FLT_MIN__, __FLT_MIN_EXP__, __DBL_MIN__,
		 __DBL_MIN_EXP__, __LDBL_MIN__, __LDBL_MIN_EXP__);
  TESTIT2_I2ALL (scalbln, __FLT_MAX__, __FLT_MAX_EXP__, __DBL_MAX__,
		 __DBL_MAX_EXP__, __LDBL_MAX__, __LDBL_MAX_EXP__);

  TESTIT (logb, 0.0);
  TESTIT (logb, -0.0);

  TESTIT (ilogb, 0.0);
  TESTIT (ilogb, -0.0);

#ifndef __SPU__
  foof (__builtin_ilogbf (__builtin_inff()));
#endif
  foo (__builtin_ilogb (__builtin_inf()));
  fool (__builtin_ilogbl (__builtin_infl()));
#ifndef __SPU__
  foof (__builtin_ilogbf (-__builtin_inff()));
#endif
  foo (__builtin_ilogb (-__builtin_inf()));
  fool (__builtin_ilogbl (-__builtin_infl()));

#ifndef __SPU__
  foof (__builtin_ilogbf (__builtin_nanf("")));
#endif
  foo (__builtin_ilogb (__builtin_nan("")));
  fool (__builtin_ilogbl (__builtin_nanl("")));
#ifndef __SPU__
  foof (__builtin_ilogbf (-__builtin_nanf("")));
#endif
  foo (__builtin_ilogb (-__builtin_nan("")));
  fool (__builtin_ilogbl (-__builtin_nanl("")));

  /* The y* arg must be [0 ... Inf] EXclusive.  */
  TESTIT (y0, -1.0);
  TESTIT (y0, 0.0);
  TESTIT (y0, -0.0);

  TESTIT (y1, -1.0);
  TESTIT (y1, 0.0);
  TESTIT (y1, -0.0);

  TESTIT2_I1 (yn, 2, -1.0);
  TESTIT2_I1 (yn, 2, 0.0);
  TESTIT2_I1 (yn, 2, -0.0);

  TESTIT2_I1 (yn, -3, -1.0);
  TESTIT2_I1 (yn, -3, 0.0);
  TESTIT2_I1 (yn, -3, -0.0);

  /* The second argument of remquo/remainder/drem must not be 0.  */
  TESTIT_REMQUO (1.0, 0.0);
  TESTIT_REMQUO (1.0, -0.0);
  TESTIT2 (remainder, 1.0, 0.0);
  TESTIT2 (remainder, 1.0, -0.0);
  TESTIT2 (drem, 1.0, 0.0);
  TESTIT2 (drem, 1.0, -0.0);

  /* The argument to lgamma* cannot be zero or a negative integer.  */
  TESTIT_REENT (lgamma, -4.0); /* lgamma_r */
  TESTIT_REENT (lgamma, -3.0); /* lgamma_r */
  TESTIT_REENT (lgamma, -2.0); /* lgamma_r */
  TESTIT_REENT (lgamma, -1.0); /* lgamma_r */
  TESTIT_REENT (lgamma, -0.0); /* lgamma_r */
  TESTIT_REENT (lgamma, 0.0); /* lgamma_r */
  
  TESTIT_REENT (gamma, -4.0); /* gamma_r */
  TESTIT_REENT (gamma, -3.0); /* gamma_r */
  TESTIT_REENT (gamma, -2.0); /* gamma_r */
  TESTIT_REENT (gamma, -1.0); /* gamma_r */
  TESTIT_REENT (gamma, -0.0); /* gamma_r */
  TESTIT_REENT (gamma, 0.0); /* gamma_r */
}
Пример #27
0
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include <math.h>
#include <math_private.h>
#include <stdbool.h>
#include <stdio.h>

struct test
{
  double hi, lo1, lo2;
};

static const struct test tests[] =
  {
    { __builtin_nan (""), 1, __builtin_nans ("") },
    { -__builtin_nan (""), 1, __builtin_nans ("") },
    { __builtin_nans (""), 1, __builtin_nan ("") },
    { -__builtin_nans (""), 1, __builtin_nan ("") },
    { __builtin_inf (), 0.0, -0.0 },
    { -__builtin_inf (), 0.0, -0.0 },
    { 1.5, 0.0, -0.0 },
  };

static int
do_test (void)
{
  int result = 0;

  for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); i++)
    {
Пример #28
0
/* { dg-do run } */
/* { dg-options "-O2 -fno-math-errno -fno-trapping-math -msse2 -mfpmath=sse" } */
/* { dg-require-effective-target sse2 } */

#include "sse2-check.h"

double x[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
	-0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,  /* +-DBL_MAX */
	-0x1p-52, 0x1p-52,				    /* +-DBL_EPSILON */
	/* nextafter/before 0.5, 1.0 and 1.5 */
	0x1.0000000000001p-1, 0x1.fffffffffffffp-2,
	0x1.0000000000001p+0, 0x1.fffffffffffffp-1,
	0x1.8000000000001p+0, 0x1.7ffffffffffffp+0,
	-0.0, 0.0, -0.5, 0.5, -1.0, 1.0, -1.5, 1.5, -2.0, 2.0,
	-2.5, 2.5 };
#define NUM (sizeof(x)/sizeof(double))

double expect_round[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
	-0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
	-0.0, 0.0,
	1.0, 0.0, 1.0, 1.0, 2.0, 1.0,
	-0.0, 0.0, -1.0, 1.0, -1.0, 1.0, -2.0, 2.0, -2.0, 2.0,
	-3.0, 3.0 };

double expect_rint[] = { __builtin_nan(""), __builtin_inf(), -__builtin_inf(),
        -0x1.fffffffffffffp+1023, 0x1.fffffffffffffp+1023,
        -0.0, 0.0,
        1.0, 0.0, 1.0, 1.0, 2.0, 1.0,
        -0.0, 0.0, -0.0, 0.0, -1.0, 1.0, -2.0, 2.0, -2.0, 2.0,
        -2.0, 2.0 };
Пример #29
0
void runBenchmark(enum BenchmarkType benchmarkType, int32_t size, struct BenchmarkResult* out) {
	const int32_t experiments = 10;
	struct BenchmarkResult result = {
		.time = __builtin_nan(""),
		.flops = __builtin_nan(""),
		.throughput = __builtin_nan("")
	};

	switch (benchmarkType) {
		case BenchmarkTypeNaiveDGEMM:
		{
			double* a = malloc(size * size * sizeof(double));
			double* b = malloc(size * size * sizeof(double));
			double* c = malloc(size * size * sizeof(double));

			for (int32_t i = 0; i < size * size; i++) {
				a[i] = ((double) rand()) / ((double) RAND_MAX);
				b[i] = ((double) rand()) / ((double) RAND_MAX);
			}
			memset(c, 0, size * size * sizeof(double));

			for (int32_t experiment = 0; experiment < experiments; ++experiment) {
				const double timeStart = time_sec();
				dgemm_naive(size, a, b, c);
				result.time = fmin(result.time, time_sec() - timeStart);
			}
			result.flops = 2.0 * size * size * size / result.time;

			free(a);
			free(b);
			free(c);
			break;
		}
		case BenchmarkTypeBlockedDGEMM:
		{
			double* a = malloc(size * size * sizeof(double));
			double* b = malloc(size * size * sizeof(double));
			double* c = malloc(size * size * sizeof(double));

			for (int32_t i = 0; i < size * size; i++) {
				a[i] = ((double) rand()) / ((double) RAND_MAX);
				b[i] = ((double) rand()) / ((double) RAND_MAX);
			}
			memset(c, 0, size * size * sizeof(double));

			for (int32_t experiment = 0; experiment < experiments; ++experiment) {
				const double timeStart = time_sec();
				dgemm_blocked(size, a, b, c);
				result.time = fmin(result.time, time_sec() - timeStart);
			}
			result.flops = 2.0 * size * size * size / result.time;

			free(a);
			free(b);
			free(c);
			break;
		}
		case BenchmarkTypeBlisDGEMM:
		{
			obj_t alpha, beta;
			bli_obj_scalar_init_detached(BLIS_DOUBLE, &alpha);
			bli_obj_scalar_init_detached(BLIS_DOUBLE, &beta);
			bli_setsc( 1.0, 0.0, &alpha);
			bli_setsc( 0.0, 0.0, &beta);

			obj_t a, b, c;
			bli_obj_create(BLIS_DOUBLE, size, size, 0, 0, &a);
			bli_obj_create(BLIS_DOUBLE, size, size, 0, 0, &b);
			bli_obj_create(BLIS_DOUBLE, size, size, 0, 0, &c);
			bli_randm(&a);
			bli_randm(&b);
			bli_randm(&c);

			for (int32_t i = 0; i < experiments; ++i) {
				const double timeStart = time_sec();
				bli_gemm(&alpha, &a, &b, &beta, &c);
				result.time = fmin(result.time, time_sec() - timeStart);
			}
			result.flops = 2.0 * size * size * size / result.time;

			bli_obj_free(&a);
			bli_obj_free(&b);
			bli_obj_free(&c);
			break;
		}
		case BenchmarkTypePointerChasing:
		{
			struct xor_shift xor_shift = xor_shift_init(UINT32_C(1), __builtin_ctz(size));
			uint32_t last_index = 1;
			void** data = (void**) malloc(size * sizeof(void*));
			data[0] = &data[1];
			for (size_t i = 0; i < size; i++) {
				const uint32_t index = xor_shift_next(&xor_shift);
				data[last_index] = &data[index];
				last_index = index;
			}
			const int32_t iterations = 16777216 / size;
			for (int32_t experiment = 0; experiment < experiments; ++experiment) {
				const double timeStart = time_sec();
				for (int32_t iteration = 0; iteration < iterations; iteration++) {
					chase_pointers(data);
				}
				result.time = fmin(result.time, (time_sec() - timeStart) / ((double) iterations) / ((double) size));
			}
			free((void*) data);
			break;
		}
		default:
			__builtin_unreachable();
	}
	*out = result;
}
Пример #30
0
int
convert_infnan (st_parameter_dt *dtp, void *dest, const char *buffer,
	        int length)
{
  const char *s = buffer;
  int is_inf, plus = 1;

  if (*s == '+')
    s++;
  else if (*s == '-')
    {
      s++;
      plus = 0;
    }

  is_inf = *s == 'i';

  switch (length)
    {
    case 4:
      if (is_inf)
	*((GFC_REAL_4*) dest) = plus ? __builtin_inff () : -__builtin_inff ();
      else
	*((GFC_REAL_4*) dest) = plus ? __builtin_nanf ("") : -__builtin_nanf ("");
      break;

    case 8:
      if (is_inf)
	*((GFC_REAL_8*) dest) = plus ? __builtin_inf () : -__builtin_inf ();
      else
	*((GFC_REAL_8*) dest) = plus ? __builtin_nan ("") : -__builtin_nan ("");
      break;

#if defined(HAVE_GFC_REAL_10)
    case 10:
      if (is_inf)
	*((GFC_REAL_10*) dest) = plus ? __builtin_infl () : -__builtin_infl ();
      else
	*((GFC_REAL_10*) dest) = plus ? __builtin_nanl ("") : -__builtin_nanl ("");
      break;
#endif

#if defined(HAVE_GFC_REAL_16)
# if defined(GFC_REAL_16_IS_FLOAT128)
    case 16:
      *((GFC_REAL_16*) dest) = __qmath_(strtoflt128) (buffer, NULL);
      break;
# else
    case 16:
      if (is_inf)
	*((GFC_REAL_16*) dest) = plus ? __builtin_infl () : -__builtin_infl ();
      else
	*((GFC_REAL_16*) dest) = plus ? __builtin_nanl ("") : -__builtin_nanl ("");
      break;
# endif
#endif

    default:
      internal_error (&dtp->common, "Unsupported real kind during IO");
    }

  return 0;
}