2007-04-16 20:41:42 +00:00
|
|
|
#ifndef _MATH_PRIVATE_H
|
|
|
|
|
|
|
|
#define math_opt_barrier(x) \
|
2011-10-25 12:17:57 +00:00
|
|
|
({ __typeof(x) __x; \
|
|
|
|
if (sizeof (x) <= sizeof (double)) \
|
|
|
|
__asm ("" : "=x" (__x) : "0" (x)); \
|
|
|
|
else \
|
|
|
|
__asm ("" : "=t" (__x) : "0" (x)); \
|
|
|
|
__x; })
|
2007-04-16 20:41:42 +00:00
|
|
|
#define math_force_eval(x) \
|
2011-10-25 12:17:57 +00:00
|
|
|
do { \
|
|
|
|
if (sizeof (x) <= sizeof (double)) \
|
|
|
|
__asm __volatile ("" : : "x" (x)); \
|
|
|
|
else \
|
|
|
|
__asm __volatile ("" : : "f" (x)); \
|
|
|
|
} while (0)
|
2007-04-16 20:41:42 +00:00
|
|
|
|
|
|
|
#include <math/math_private.h>
|
2009-08-24 21:52:49 +00:00
|
|
|
|
|
|
|
/* We can do a few things better on x86-64. */
|
|
|
|
|
2011-10-25 12:17:57 +00:00
|
|
|
#ifdef __AVX__
|
|
|
|
# define MOVD "vmovd"
|
|
|
|
#else
|
|
|
|
# define MOVD "movd"
|
|
|
|
#endif
|
|
|
|
|
2009-08-25 01:05:48 +00:00
|
|
|
/* Direct movement of float into integer register. */
|
|
|
|
#undef EXTRACT_WORDS64
|
2011-10-25 12:17:57 +00:00
|
|
|
#define EXTRACT_WORDS64(i, d) \
|
|
|
|
do { \
|
|
|
|
long int i_; \
|
|
|
|
asm (MOVD " %1, %0" : "=rm" (i_) : "x" ((double) (d))); \
|
|
|
|
(i) = i_; \
|
|
|
|
} while (0)
|
2009-08-25 01:05:48 +00:00
|
|
|
|
|
|
|
/* And the reverse. */
|
|
|
|
#undef INSERT_WORDS64
|
2011-10-25 12:17:57 +00:00
|
|
|
#define INSERT_WORDS64(d, i) \
|
|
|
|
do { \
|
|
|
|
long int i_ = i; \
|
|
|
|
double d__; \
|
|
|
|
asm (MOVD " %1, %0" : "=x" (d__) : "rm" (i_)); \
|
|
|
|
d = d__; \
|
|
|
|
} while (0)
|
2009-08-25 01:05:48 +00:00
|
|
|
|
2009-08-24 21:52:49 +00:00
|
|
|
/* Direct movement of float into integer register. */
|
|
|
|
#undef GET_FLOAT_WORD
|
2011-10-25 12:17:57 +00:00
|
|
|
#define GET_FLOAT_WORD(i, d) \
|
|
|
|
do { \
|
|
|
|
int i_; \
|
|
|
|
asm (MOVD " %1, %0" : "=rm" (i_) : "x" ((float) (d))); \
|
|
|
|
(i) = i_; \
|
|
|
|
} while (0)
|
2009-08-24 21:52:49 +00:00
|
|
|
|
|
|
|
/* And the reverse. */
|
|
|
|
#undef SET_FLOAT_WORD
|
2011-10-25 12:17:57 +00:00
|
|
|
#define SET_FLOAT_WORD(f, i) \
|
|
|
|
do { \
|
|
|
|
int i_ = i; \
|
|
|
|
float f__; \
|
|
|
|
asm (MOVD " %1, %0" : "=x" (f__) : "rm" (i_)); \
|
|
|
|
f = f__; \
|
|
|
|
} while (0)
|
2009-08-24 21:52:49 +00:00
|
|
|
|
2007-04-16 20:41:42 +00:00
|
|
|
#endif
|
2011-10-08 14:18:26 +00:00
|
|
|
|
|
|
|
#define __isnan(d) \
|
2011-10-17 20:00:39 +00:00
|
|
|
({ long int __di; EXTRACT_WORDS64 (__di, (double) (d)); \
|
2011-10-08 14:18:26 +00:00
|
|
|
(__di & 0x7fffffffffffffffl) > 0x7ff0000000000000l; })
|
|
|
|
#define __isnanf(d) \
|
2011-10-12 15:27:51 +00:00
|
|
|
({ int __di; GET_FLOAT_WORD (__di, (float) d); \
|
2011-10-08 14:18:26 +00:00
|
|
|
(__di & 0x7fffffff) > 0x7f800000; })
|
|
|
|
|
|
|
|
#define __isinf_ns(d) \
|
2011-10-17 20:00:39 +00:00
|
|
|
({ long int __di; EXTRACT_WORDS64 (__di, (double) (d)); \
|
2011-10-08 14:18:26 +00:00
|
|
|
(__di & 0x7fffffffffffffffl) == 0x7ff0000000000000l; })
|
|
|
|
#define __isinf_nsf(d) \
|
2011-10-12 15:27:51 +00:00
|
|
|
({ int __di; GET_FLOAT_WORD (__di, (float) d); \
|
2011-10-08 14:18:26 +00:00
|
|
|
(__di & 0x7fffffff) == 0x7f800000; })
|
|
|
|
|
|
|
|
#define __finite(d) \
|
2011-10-17 20:00:39 +00:00
|
|
|
({ long int __di; EXTRACT_WORDS64 (__di, (double) (d)); \
|
2011-10-08 14:18:26 +00:00
|
|
|
(__di & 0x7fffffffffffffffl) < 0x7ff0000000000000l; })
|
|
|
|
#define __finitef(d) \
|
2011-10-12 15:27:51 +00:00
|
|
|
({ int __di; GET_FLOAT_WORD (__di, (float) d); \
|
2011-10-08 14:18:26 +00:00
|
|
|
(__di & 0x7fffffff) < 0x7f800000; })
|
2011-10-12 15:27:51 +00:00
|
|
|
|
2011-10-25 12:17:57 +00:00
|
|
|
#ifdef __AVX__
|
|
|
|
# define __ieee754_sqrt(d) \
|
|
|
|
({ double __res; \
|
|
|
|
asm ("vsqrtsd %1, %0, %0" : "=x" (__res) : "xm" ((double) (d))); \
|
|
|
|
__res; })
|
|
|
|
# define __ieee754_sqrtf(d) \
|
|
|
|
({ float __res; \
|
|
|
|
asm ("vsqrtss %1, %0, %0" : "=x" (__res) : "xm" ((float) (d))); \
|
|
|
|
__res; })
|
|
|
|
#else
|
|
|
|
# define __ieee754_sqrt(d) \
|
2011-10-12 15:27:51 +00:00
|
|
|
({ double __res; \
|
2011-10-17 20:00:39 +00:00
|
|
|
asm ("sqrtsd %1, %0" : "=x" (__res) : "xm" ((double) (d))); \
|
2011-10-12 15:27:51 +00:00
|
|
|
__res; })
|
2011-10-25 12:17:57 +00:00
|
|
|
# define __ieee754_sqrtf(d) \
|
2011-10-12 15:27:51 +00:00
|
|
|
({ float __res; \
|
2011-10-17 20:00:39 +00:00
|
|
|
asm ("sqrtss %1, %0" : "=x" (__res) : "xm" ((float) (d))); \
|
2011-10-12 15:27:51 +00:00
|
|
|
__res; })
|
2011-10-25 12:17:57 +00:00
|
|
|
#endif
|
2011-10-12 15:27:51 +00:00
|
|
|
#define __ieee754_sqrtl(d) \
|
|
|
|
({ long double __res; \
|
2011-10-17 20:00:39 +00:00
|
|
|
asm ("fsqrt" : "=t" (__res) : "0" ((long double) (d))); \
|
2011-10-12 15:27:51 +00:00
|
|
|
__res; })
|
2011-10-17 15:23:40 +00:00
|
|
|
|
|
|
|
#ifdef __SSE4_1__
|
|
|
|
# ifndef __rint
|
2011-10-25 12:17:57 +00:00
|
|
|
# ifdef __AVX__
|
|
|
|
# define __rint(d) \
|
|
|
|
({ double __res; \
|
|
|
|
asm ("vroundsd $4, %1, %0, %0" : "=x" (__res) : "xm" ((double) (d))); \
|
|
|
|
__res; })
|
|
|
|
# else
|
|
|
|
# define __rint(d) \
|
2011-10-17 15:23:40 +00:00
|
|
|
({ double __res; \
|
2011-10-18 00:30:52 +00:00
|
|
|
asm ("roundsd $4, %1, %0" : "=x" (__res) : "xm" ((double) (d))); \
|
2011-10-17 15:23:40 +00:00
|
|
|
__res; })
|
2011-10-25 12:17:57 +00:00
|
|
|
# endif
|
2011-10-17 15:23:40 +00:00
|
|
|
# endif
|
|
|
|
# ifndef __rintf
|
2011-10-25 12:17:57 +00:00
|
|
|
# ifdef __AVX__
|
|
|
|
# define __rintf(d) \
|
|
|
|
({ float __res; \
|
|
|
|
asm ("vroundss $4, %1, %0, %0" : "=x" (__res) : "xm" ((float) (d))); \
|
|
|
|
__res; })
|
|
|
|
# else
|
|
|
|
# define __rintf(d) \
|
2011-10-17 15:23:40 +00:00
|
|
|
({ float __res; \
|
2011-10-18 00:30:52 +00:00
|
|
|
asm ("roundss $4, %1, %0" : "=x" (__res) : "xm" ((float) (d))); \
|
2011-10-17 15:23:40 +00:00
|
|
|
__res; })
|
2011-10-25 12:17:57 +00:00
|
|
|
# endif
|
2011-10-17 15:23:40 +00:00
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifndef __floor
|
2011-10-25 12:17:57 +00:00
|
|
|
# ifdef __AVX__
|
|
|
|
# define __floor(d) \
|
|
|
|
({ double __res; \
|
|
|
|
asm ("vroundsd $1, %1, %0, %0" : "=x" (__res) : "xm" ((double) (d))); \
|
|
|
|
__res; })
|
|
|
|
# else
|
|
|
|
# define __floor(d) \
|
2011-10-17 15:23:40 +00:00
|
|
|
({ double __res; \
|
2011-10-18 00:30:52 +00:00
|
|
|
asm ("roundsd $1, %1, %0" : "=x" (__res) : "xm" ((double) (d))); \
|
2011-10-17 15:23:40 +00:00
|
|
|
__res; })
|
2011-10-25 12:17:57 +00:00
|
|
|
# endif
|
2011-10-17 15:23:40 +00:00
|
|
|
# endif
|
|
|
|
# ifndef __floorf
|
2011-10-25 12:17:57 +00:00
|
|
|
# ifdef __AVX__
|
|
|
|
# define __floorf(d) \
|
|
|
|
({ float __res; \
|
|
|
|
asm ("vroundss $1, %1, %0, %0" : "=x" (__res) : "xm" ((float) (d))); \
|
|
|
|
__res; })
|
|
|
|
# else
|
|
|
|
# define __floorf(d) \
|
2011-10-17 15:23:40 +00:00
|
|
|
({ float __res; \
|
2011-10-18 00:30:52 +00:00
|
|
|
asm ("roundss $1, %1, %0" : "=x" (__res) : "xm" ((float) (d))); \
|
2011-10-17 15:23:40 +00:00
|
|
|
__res; })
|
2011-10-25 12:17:57 +00:00
|
|
|
# endif
|
2011-10-17 15:23:40 +00:00
|
|
|
# endif
|
|
|
|
#endif
|
2011-10-18 13:00:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Specialized variants of the <fenv.h> interfaces which only handle
|
|
|
|
either the FPU or the SSE unit. */
|
|
|
|
#undef libc_fegetround
|
|
|
|
#define libc_fegetround() \
|
|
|
|
({ \
|
|
|
|
unsigned int mxcsr; \
|
|
|
|
asm volatile ("stmxcsr %0" : "=m" (*&mxcsr)); \
|
|
|
|
(mxcsr & 0x6000) >> 3; \
|
|
|
|
})
|
2011-10-18 19:11:31 +00:00
|
|
|
#undef libc_fegetroundf
|
|
|
|
#define libc_fegetroundf() libc_fegetround ()
|
2011-10-18 13:00:46 +00:00
|
|
|
// #define libc_fegetroundl() fegetround ()
|
|
|
|
|
|
|
|
#undef libc_fesetround
|
|
|
|
#define libc_fesetround(r) \
|
|
|
|
do { \
|
|
|
|
unsigned int mxcsr; \
|
|
|
|
asm ("stmxcsr %0" : "=m" (*&mxcsr)); \
|
|
|
|
mxcsr = (mxcsr & ~0x6000) | ((r) << 3); \
|
|
|
|
asm volatile ("ldmxcsr %0" : : "m" (*&mxcsr)); \
|
|
|
|
} while (0)
|
2011-10-18 19:11:31 +00:00
|
|
|
#undef libc_fesetroundf
|
|
|
|
#define libc_fesetroundf(r) libc_fesetround (r)
|
2011-10-18 13:00:46 +00:00
|
|
|
// #define libc_fesetroundl(r) (void) fesetround (r)
|
|
|
|
|
|
|
|
#undef libc_feholdexcept
|
2011-10-25 12:17:57 +00:00
|
|
|
#ifdef __AVX__
|
|
|
|
# define libc_feholdexcept(e) \
|
|
|
|
do { \
|
|
|
|
unsigned int mxcsr; \
|
|
|
|
asm ("vstmxcsr %0" : "=m" (*&mxcsr)); \
|
|
|
|
(e)->__mxcsr = mxcsr; \
|
|
|
|
mxcsr = (mxcsr | 0x1f80) & ~0x3f; \
|
|
|
|
asm volatile ("vldmxcsr %0" : : "m" (*&mxcsr)); \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
# define libc_feholdexcept(e) \
|
2011-10-18 13:59:04 +00:00
|
|
|
do { \
|
2011-10-18 13:00:46 +00:00
|
|
|
unsigned int mxcsr; \
|
|
|
|
asm ("stmxcsr %0" : "=m" (*&mxcsr)); \
|
|
|
|
(e)->__mxcsr = mxcsr; \
|
|
|
|
mxcsr = (mxcsr | 0x1f80) & ~0x3f; \
|
|
|
|
asm volatile ("ldmxcsr %0" : : "m" (*&mxcsr)); \
|
|
|
|
} while (0)
|
2011-10-25 12:17:57 +00:00
|
|
|
#endif
|
2011-10-18 19:11:31 +00:00
|
|
|
#undef libc_feholdexceptf
|
|
|
|
#define libc_feholdexceptf(e) libc_feholdexcept (e)
|
2011-10-18 13:00:46 +00:00
|
|
|
// #define libc_feholdexceptl(e) (void) feholdexcept (e)
|
|
|
|
|
2011-10-18 13:59:04 +00:00
|
|
|
#undef libc_feholdexcept_setround
|
2011-10-25 12:17:57 +00:00
|
|
|
#ifdef __AVX__
|
|
|
|
# define libc_feholdexcept_setround(e, r) \
|
|
|
|
do { \
|
|
|
|
unsigned int mxcsr; \
|
|
|
|
asm ("vstmxcsr %0" : "=m" (*&mxcsr)); \
|
|
|
|
(e)->__mxcsr = mxcsr; \
|
|
|
|
mxcsr = ((mxcsr | 0x1f80) & ~0x603f) | ((r) << 3); \
|
|
|
|
asm volatile ("vldmxcsr %0" : : "m" (*&mxcsr)); \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
# define libc_feholdexcept_setround(e, r) \
|
2011-10-18 13:59:04 +00:00
|
|
|
do { \
|
|
|
|
unsigned int mxcsr; \
|
|
|
|
asm ("stmxcsr %0" : "=m" (*&mxcsr)); \
|
|
|
|
(e)->__mxcsr = mxcsr; \
|
|
|
|
mxcsr = ((mxcsr | 0x1f80) & ~0x603f) | ((r) << 3); \
|
|
|
|
asm volatile ("ldmxcsr %0" : : "m" (*&mxcsr)); \
|
|
|
|
} while (0)
|
2011-10-25 12:17:57 +00:00
|
|
|
#endif
|
2011-10-18 19:11:31 +00:00
|
|
|
#undef libc_feholdexcept_setroundf
|
|
|
|
#define libc_feholdexcept_setroundf(e, r) libc_feholdexcept_setround (e, r)
|
2011-10-18 13:59:04 +00:00
|
|
|
// #define libc_feholdexcept_setroundl(e, r) ...
|
|
|
|
|
2011-10-18 19:11:31 +00:00
|
|
|
#undef libc_fetestexcept
|
2011-10-25 12:17:57 +00:00
|
|
|
#ifdef __AVX__
|
|
|
|
# define libc_fetestexcept(e) \
|
|
|
|
({ unsigned int mxcsr; asm volatile ("vstmxcsr %0" : "=m" (*&mxcsr)); \
|
2011-10-18 19:11:31 +00:00
|
|
|
mxcsr & (e) & FE_ALL_EXCEPT; })
|
2011-10-25 12:17:57 +00:00
|
|
|
#else
|
|
|
|
# define libc_fetestexcept(e) \
|
|
|
|
({ unsigned int mxcsr; asm volatile ("stmxcsr %0" : "=m" (*&mxcsr)); \
|
|
|
|
mxcsr & (e) & FE_ALL_EXCEPT; })
|
|
|
|
#endif
|
2011-10-18 19:11:31 +00:00
|
|
|
#undef libc_fetestexceptf
|
|
|
|
#define libc_fetestexceptf(e) libc_fetestexcept (e)
|
|
|
|
// #define libc_fetestexceptl(e) fetestexcept (e)
|
|
|
|
|
2011-10-18 13:00:46 +00:00
|
|
|
#undef libc_fesetenv
|
2011-10-25 12:17:57 +00:00
|
|
|
#ifdef __AVX__
|
|
|
|
# define libc_fesetenv(e) \
|
|
|
|
asm volatile ("vldmxcsr %0" : : "m" ((e)->__mxcsr))
|
|
|
|
#else
|
|
|
|
# define libc_fesetenv(e) \
|
2011-10-18 13:00:46 +00:00
|
|
|
asm volatile ("ldmxcsr %0" : : "m" ((e)->__mxcsr))
|
2011-10-25 12:17:57 +00:00
|
|
|
#endif
|
2011-10-18 19:11:31 +00:00
|
|
|
#undef libc_fesetenvf
|
|
|
|
#define libc_fesetenvf(e) libc_fesetenv (e)
|
2011-10-18 13:00:46 +00:00
|
|
|
// #define libc_fesetenvl(e) (void) fesetenv (e)
|
2011-10-18 19:11:31 +00:00
|
|
|
|
|
|
|
#undef libc_feupdateenv
|
2011-10-25 12:17:57 +00:00
|
|
|
#ifdef __AVX__
|
|
|
|
# define libc_feupdateenv(e) \
|
|
|
|
do { \
|
|
|
|
unsigned int mxcsr; \
|
|
|
|
asm volatile ("vstmxcsr %0" : "=m" (*&mxcsr)); \
|
|
|
|
asm volatile ("vldmxcsr %0" : : "m" ((e)->__mxcsr)); \
|
|
|
|
__feraiseexcept (mxcsr & FE_ALL_EXCEPT); \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
# define libc_feupdateenv(e) \
|
2011-10-18 19:11:31 +00:00
|
|
|
do { \
|
|
|
|
unsigned int mxcsr; \
|
|
|
|
asm volatile ("stmxcsr %0" : "=m" (*&mxcsr)); \
|
|
|
|
asm volatile ("ldmxcsr %0" : : "m" ((e)->__mxcsr)); \
|
2011-10-19 09:16:57 +00:00
|
|
|
__feraiseexcept (mxcsr & FE_ALL_EXCEPT); \
|
2011-10-18 19:11:31 +00:00
|
|
|
} while (0)
|
2011-10-25 12:17:57 +00:00
|
|
|
#endif
|
2011-10-18 19:11:31 +00:00
|
|
|
#undef libc_feupdateenvf
|
|
|
|
#define libc_feupdateenvf(e) libc_feupdateenv (e)
|
|
|
|
// #define libc_feupdateenvl(e) (void) feupdateenv (e)
|