|
|
|
@ -21,16 +21,6 @@ |
|
|
|
|
|
|
|
#include "libc.h" |
|
|
|
|
|
|
|
union fshape { |
|
|
|
float value; |
|
|
|
uint32_t bits; |
|
|
|
}; |
|
|
|
|
|
|
|
union dshape { |
|
|
|
double value; |
|
|
|
uint64_t bits; |
|
|
|
}; |
|
|
|
|
|
|
|
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 |
|
|
|
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN |
|
|
|
union ldshape { |
|
|
|
@ -58,86 +48,86 @@ union ldshape { |
|
|
|
#error Unsupported long double representation |
|
|
|
#endif |
|
|
|
|
|
|
|
#define FORCE_EVAL(x) do { \ |
|
|
|
if (sizeof(x) == sizeof(float)) { \ |
|
|
|
volatile float __x; \ |
|
|
|
__x = (x); \ |
|
|
|
} else if (sizeof(x) == sizeof(double)) { \ |
|
|
|
volatile double __x; \ |
|
|
|
__x = (x); \ |
|
|
|
} else { \ |
|
|
|
volatile long double __x; \ |
|
|
|
__x = (x); \ |
|
|
|
} \ |
|
|
|
#define FORCE_EVAL(x) do { \ |
|
|
|
if (sizeof(x) == sizeof(float)) { \ |
|
|
|
volatile float __x; \ |
|
|
|
__x = (x); \ |
|
|
|
} else if (sizeof(x) == sizeof(double)) { \ |
|
|
|
volatile double __x; \ |
|
|
|
__x = (x); \ |
|
|
|
} else { \ |
|
|
|
volatile long double __x; \ |
|
|
|
__x = (x); \ |
|
|
|
} \ |
|
|
|
} while(0) |
|
|
|
|
|
|
|
/* Get two 32 bit ints from a double. */ |
|
|
|
#define EXTRACT_WORDS(hi,lo,d) \ |
|
|
|
do { \ |
|
|
|
union dshape __u; \ |
|
|
|
__u.value = (d); \ |
|
|
|
(hi) = __u.bits >> 32; \ |
|
|
|
(lo) = (uint32_t)__u.bits; \ |
|
|
|
#define EXTRACT_WORDS(hi,lo,d) \ |
|
|
|
do { \ |
|
|
|
union {double f; uint64_t i;} __u; \ |
|
|
|
__u.f = (d); \ |
|
|
|
(hi) = __u.i >> 32; \ |
|
|
|
(lo) = (uint32_t)__u.i; \ |
|
|
|
} while (0) |
|
|
|
|
|
|
|
/* Get the more significant 32 bit int from a double. */ |
|
|
|
#define GET_HIGH_WORD(i,d) \ |
|
|
|
do { \ |
|
|
|
union dshape __u; \ |
|
|
|
__u.value = (d); \ |
|
|
|
(i) = __u.bits >> 32; \ |
|
|
|
#define GET_HIGH_WORD(hi,d) \ |
|
|
|
do { \ |
|
|
|
union {double f; uint64_t i;} __u; \ |
|
|
|
__u.f = (d); \ |
|
|
|
(hi) = __u.i >> 32; \ |
|
|
|
} while (0) |
|
|
|
|
|
|
|
/* Get the less significant 32 bit int from a double. */ |
|
|
|
#define GET_LOW_WORD(i,d) \ |
|
|
|
do { \ |
|
|
|
union dshape __u; \ |
|
|
|
__u.value = (d); \ |
|
|
|
(i) = (uint32_t)__u.bits; \ |
|
|
|
#define GET_LOW_WORD(lo,d) \ |
|
|
|
do { \ |
|
|
|
union {double f; uint64_t i;} __u; \ |
|
|
|
__u.f = (d); \ |
|
|
|
(lo) = (uint32_t)__u.i; \ |
|
|
|
} while (0) |
|
|
|
|
|
|
|
/* Set a double from two 32 bit ints. */ |
|
|
|
#define INSERT_WORDS(d,hi,lo) \ |
|
|
|
do { \ |
|
|
|
union dshape __u; \ |
|
|
|
__u.bits = ((uint64_t)(hi) << 32) | (uint32_t)(lo); \ |
|
|
|
(d) = __u.value; \ |
|
|
|
#define INSERT_WORDS(d,hi,lo) \ |
|
|
|
do { \ |
|
|
|
union {double f; uint64_t i;} __u; \ |
|
|
|
__u.i = ((uint64_t)(hi)<<32) | (uint32_t)(lo); \ |
|
|
|
(d) = __u.f; \ |
|
|
|
} while (0) |
|
|
|
|
|
|
|
/* Set the more significant 32 bits of a double from an int. */ |
|
|
|
#define SET_HIGH_WORD(d,hi) \ |
|
|
|
do { \ |
|
|
|
union dshape __u; \ |
|
|
|
__u.value = (d); \ |
|
|
|
__u.bits &= 0xffffffff; \ |
|
|
|
__u.bits |= (uint64_t)(hi) << 32; \ |
|
|
|
(d) = __u.value; \ |
|
|
|
#define SET_HIGH_WORD(d,hi) \ |
|
|
|
do { \ |
|
|
|
union {double f; uint64_t i;} __u; \ |
|
|
|
__u.f = (d); \ |
|
|
|
__u.i &= 0xffffffff; \ |
|
|
|
__u.i |= (uint64_t)(hi) << 32; \ |
|
|
|
(d) = __u.f; \ |
|
|
|
} while (0) |
|
|
|
|
|
|
|
/* Set the less significant 32 bits of a double from an int. */ |
|
|
|
#define SET_LOW_WORD(d,lo) \ |
|
|
|
do { \ |
|
|
|
union dshape __u; \ |
|
|
|
__u.value = (d); \ |
|
|
|
__u.bits &= 0xffffffff00000000ull; \ |
|
|
|
__u.bits |= (uint32_t)(lo); \ |
|
|
|
(d) = __u.value; \ |
|
|
|
#define SET_LOW_WORD(d,lo) \ |
|
|
|
do { \ |
|
|
|
union {double f; uint64_t i;} __u; \ |
|
|
|
__u.f = (d); \ |
|
|
|
__u.i &= 0xffffffff00000000ull; \ |
|
|
|
__u.i |= (uint32_t)(lo); \ |
|
|
|
(d) = __u.f; \ |
|
|
|
} while (0) |
|
|
|
|
|
|
|
/* Get a 32 bit int from a float. */ |
|
|
|
#define GET_FLOAT_WORD(i,d) \ |
|
|
|
do { \ |
|
|
|
union fshape __u; \ |
|
|
|
__u.value = (d); \ |
|
|
|
(i) = __u.bits; \ |
|
|
|
#define GET_FLOAT_WORD(w,d) \ |
|
|
|
do { \ |
|
|
|
union {float f; uint32_t i;} __u; \ |
|
|
|
__u.f = (d); \ |
|
|
|
(w) = __u.i; \ |
|
|
|
} while (0) |
|
|
|
|
|
|
|
/* Set a float from a 32 bit int. */ |
|
|
|
#define SET_FLOAT_WORD(d,i) \ |
|
|
|
do { \ |
|
|
|
union fshape __u; \ |
|
|
|
__u.bits = (i); \ |
|
|
|
(d) = __u.value; \ |
|
|
|
#define SET_FLOAT_WORD(d,w) \ |
|
|
|
do { \ |
|
|
|
union {float f; uint32_t i;} __u; \ |
|
|
|
__u.i = (w); \ |
|
|
|
(d) = __u.f; \ |
|
|
|
} while (0) |
|
|
|
|
|
|
|
/* fdlibm kernel functions */ |
|
|
|
|