2007-04-16 22:41:42 +02:00
|
|
|
#ifndef _MATH_PRIVATE_H
|
|
|
|
|
|
|
|
#define math_opt_barrier(x) \
|
|
|
|
({ __typeof(x) __x; \
|
|
|
|
if (sizeof (x) <= sizeof (double)) \
|
|
|
|
__asm ("" : "=x" (__x) : "0" (x)); \
|
|
|
|
else \
|
|
|
|
__asm ("" : "=t" (__x) : "0" (x)); \
|
|
|
|
__x; })
|
|
|
|
#define math_force_eval(x) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (sizeof (x) <= sizeof (double)) \
|
|
|
|
__asm __volatile ("" : : "x" (x)); \
|
|
|
|
else \
|
|
|
|
__asm __volatile ("" : : "f" (x)); \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
#include <math/math_private.h>
|
2009-08-24 23:52:49 +02:00
|
|
|
|
|
|
|
/* We can do a few things better on x86-64. */
|
|
|
|
|
2009-08-25 03:05:48 +02:00
|
|
|
/* Direct movement of float into integer register. */
|
|
|
|
#undef EXTRACT_WORDS64
|
|
|
|
#define EXTRACT_WORDS64(i,d) \
|
|
|
|
do { \
|
|
|
|
long int i_; \
|
|
|
|
asm ("movd %1, %0" : "=rm" (i_) : "x" (d)); \
|
|
|
|
(i) = i_; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* And the reverse. */
|
|
|
|
#undef INSERT_WORDS64
|
|
|
|
#define INSERT_WORDS64(d,i) \
|
|
|
|
do { \
|
|
|
|
long int i_ = i; \
|
|
|
|
asm ("movd %1, %0" : "=x" (d) : "rm" (i_)); \
|
|
|
|
} while (0)
|
|
|
|
|
2009-08-24 23:52:49 +02:00
|
|
|
/* Direct movement of float into integer register. */
|
|
|
|
#undef GET_FLOAT_WORD
|
|
|
|
#define GET_FLOAT_WORD(i,d) \
|
|
|
|
do { \
|
|
|
|
int i_; \
|
|
|
|
asm ("movd %1, %0" : "=rm" (i_) : "x" (d)); \
|
|
|
|
(i) = i_; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* And the reverse. */
|
|
|
|
#undef SET_FLOAT_WORD
|
|
|
|
#define SET_FLOAT_WORD(d,i) \
|
|
|
|
do { \
|
|
|
|
int i_ = i; \
|
|
|
|
asm ("movd %1, %0" : "=x" (d) : "rm" (i_)); \
|
|
|
|
} while (0)
|
|
|
|
|
2007-04-16 22:41:42 +02:00
|
|
|
#endif
|
2011-10-08 16:18:26 +02:00
|
|
|
|
|
|
|
#define __isnan(d) \
|
2011-10-17 22:00:39 +02:00
|
|
|
({ long int __di; EXTRACT_WORDS64 (__di, (double) (d)); \
|
2011-10-08 16:18:26 +02:00
|
|
|
(__di & 0x7fffffffffffffffl) > 0x7ff0000000000000l; })
|
|
|
|
#define __isnanf(d) \
|
2011-10-12 17:27:51 +02:00
|
|
|
({ int __di; GET_FLOAT_WORD (__di, (float) d); \
|
2011-10-08 16:18:26 +02:00
|
|
|
(__di & 0x7fffffff) > 0x7f800000; })
|
|
|
|
|
|
|
|
#define __isinf_ns(d) \
|
2011-10-17 22:00:39 +02:00
|
|
|
({ long int __di; EXTRACT_WORDS64 (__di, (double) (d)); \
|
2011-10-08 16:18:26 +02:00
|
|
|
(__di & 0x7fffffffffffffffl) == 0x7ff0000000000000l; })
|
|
|
|
#define __isinf_nsf(d) \
|
2011-10-12 17:27:51 +02:00
|
|
|
({ int __di; GET_FLOAT_WORD (__di, (float) d); \
|
2011-10-08 16:18:26 +02:00
|
|
|
(__di & 0x7fffffff) == 0x7f800000; })
|
|
|
|
|
|
|
|
#define __finite(d) \
|
2011-10-17 22:00:39 +02:00
|
|
|
({ long int __di; EXTRACT_WORDS64 (__di, (double) (d)); \
|
2011-10-08 16:18:26 +02:00
|
|
|
(__di & 0x7fffffffffffffffl) < 0x7ff0000000000000l; })
|
|
|
|
#define __finitef(d) \
|
2011-10-12 17:27:51 +02:00
|
|
|
({ int __di; GET_FLOAT_WORD (__di, (float) d); \
|
2011-10-08 16:18:26 +02:00
|
|
|
(__di & 0x7fffffff) < 0x7f800000; })
|
2011-10-12 17:27:51 +02:00
|
|
|
|
|
|
|
#define __ieee754_sqrt(d) \
|
|
|
|
({ double __res; \
|
2011-10-17 22:00:39 +02:00
|
|
|
asm ("sqrtsd %1, %0" : "=x" (__res) : "xm" ((double) (d))); \
|
2011-10-12 17:27:51 +02:00
|
|
|
__res; })
|
|
|
|
#define __ieee754_sqrtf(d) \
|
|
|
|
({ float __res; \
|
2011-10-17 22:00:39 +02:00
|
|
|
asm ("sqrtss %1, %0" : "=x" (__res) : "xm" ((float) (d))); \
|
2011-10-12 17:27:51 +02:00
|
|
|
__res; })
|
|
|
|
#define __ieee754_sqrtl(d) \
|
|
|
|
({ long double __res; \
|
2011-10-17 22:00:39 +02:00
|
|
|
asm ("fsqrt" : "=t" (__res) : "0" ((long double) (d))); \
|
2011-10-12 17:27:51 +02:00
|
|
|
__res; })
|
2011-10-17 17:23:40 +02:00
|
|
|
|
|
|
|
#ifdef __SSE4_1__
|
|
|
|
# ifndef __rint
|
|
|
|
# define __rint(d) \
|
|
|
|
({ double __res; \
|
2011-10-18 02:30:52 +02:00
|
|
|
asm ("roundsd $4, %1, %0" : "=x" (__res) : "xm" ((double) (d))); \
|
2011-10-17 17:23:40 +02:00
|
|
|
__res; })
|
|
|
|
# endif
|
|
|
|
# ifndef __rintf
|
|
|
|
# define __rintf(d) \
|
|
|
|
({ float __res; \
|
2011-10-18 02:30:52 +02:00
|
|
|
asm ("roundss $4, %1, %0" : "=x" (__res) : "xm" ((float) (d))); \
|
2011-10-17 17:23:40 +02:00
|
|
|
__res; })
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifndef __floor
|
|
|
|
# define __floor(d) \
|
|
|
|
({ double __res; \
|
2011-10-18 02:30:52 +02:00
|
|
|
asm ("roundsd $1, %1, %0" : "=x" (__res) : "xm" ((double) (d))); \
|
2011-10-17 17:23:40 +02:00
|
|
|
__res; })
|
|
|
|
# endif
|
|
|
|
# ifndef __floorf
|
|
|
|
# define __floorf(d) \
|
|
|
|
({ float __res; \
|
2011-10-18 02:30:52 +02:00
|
|
|
asm ("roundss $1, %1, %0" : "=x" (__res) : "xm" ((float) (d))); \
|
2011-10-17 17:23:40 +02:00
|
|
|
__res; })
|
|
|
|
# endif
|
|
|
|
#endif
|
2011-10-18 15:00:46 +02: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; \
|
|
|
|
})
|
|
|
|
// #define libc_fegetroundf() fegetround ()
|
|
|
|
// #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)
|
|
|
|
// #define libc_fesetroundf(r) (void) fesetround (r)
|
|
|
|
// #define libc_fesetroundl(r) (void) fesetround (r)
|
|
|
|
|
|
|
|
#undef libc_feholdexcept
|
|
|
|
#define libc_feholdexcept(e) \
|
2011-10-18 15:59:04 +02:00
|
|
|
do { \
|
2011-10-18 15:00:46 +02:00
|
|
|
unsigned int mxcsr; \
|
|
|
|
asm ("stmxcsr %0" : "=m" (*&mxcsr)); \
|
|
|
|
(e)->__mxcsr = mxcsr; \
|
|
|
|
mxcsr = (mxcsr | 0x1f80) & ~0x3f; \
|
|
|
|
asm volatile ("ldmxcsr %0" : : "m" (*&mxcsr)); \
|
|
|
|
} while (0)
|
|
|
|
// #define libc_feholdexceptf(e) (void) feholdexcept (e)
|
|
|
|
// #define libc_feholdexceptl(e) (void) feholdexcept (e)
|
|
|
|
|
2011-10-18 15:59:04 +02:00
|
|
|
#undef libc_feholdexcept_setround
|
|
|
|
#define libc_feholdexcept_setround(e, r) \
|
|
|
|
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)
|
|
|
|
// #define libc_feholdexcept_setroundf(e, r) ...
|
|
|
|
// #define libc_feholdexcept_setroundl(e, r) ...
|
|
|
|
|
2011-10-18 15:00:46 +02:00
|
|
|
#undef libc_fesetenv
|
|
|
|
#define libc_fesetenv(e) \
|
|
|
|
asm volatile ("ldmxcsr %0" : : "m" ((e)->__mxcsr))
|
|
|
|
// #define libc_fesetenvf(e) (void) fesetenv (e)
|
|
|
|
// #define libc_fesetenvl(e) (void) fesetenv (e)
|