ff6b24501f
On some architectures, the parts of math_private.h relating to the floating-point environment are in a separate file fenv_private.h included from math_private.h. As this is purely an architecture-specific convention used by several architectures, however, all such architectures still need their own math_private.h, even if it has nothing to do beyond #include <fenv_private.h> and peculiarity of including the i386 file directly instead of having a shared file in sysdeps/x86. This patch makes the fenv_private.h name an architecture-independent convention in glibc. The include of fenv_private.h from math_private.h becomes architecture-independent (until callers are updated to include fenv_private.h directly so the include from math_private.h is no longer needed). Some architecture math_private.h headers are removed if no longer needed, or renamed to fenv_private.h if all they define belongs in that header; architecture fenv_private.h headers now do require #include_next <fenv_private.h>. The i386 fenv_private.h file moves to sysdeps/x86/fpu/ to reflect how it is actually shared with x86_64. The generic math_private.h gets a new include of <stdbool.h>, as needed for bool in some prototypes in that header (previously that was indirectly included via include/fenv.h, which now only gets included too late in math_private.h, after those prototypes). Tested for x86_64 and x86, and tested with build-many-glibcs.py that installed stripped shared libraries are unchanged by the patch. * sysdeps/aarch64/fpu/fenv_private.h: New file. Based on .... * sysdeps/aarch64/fpu/math_private.h: ... this file. All contents moved to fenv_private.h except for ... (TOINT_INTRINSICS): Kept in math_private.h. (roundtoint): Likewise. (converttoint): Likewise. * sysdeps/arm/fenv_private.h: Change multiple-include guard to [ARM_FENV_PRIVATE_H]. Include next <fenv_private.h>. * sysdeps/arm/math_private.h: Remove. * sysdeps/generic/fenv_private.h: New file. Contents moved from .... * sysdeps/generic/math_private.h: ... this file. Include <stdbool.h>. Do not include <fenv.h> or <get-rounding-mode.h>. Include <fenv_private.h>. Remove functions and macros moved to fenv_private.h. * sysdeps/i386/fpu/math_private.h: Remove. * sysdeps/mips/math_private.h: Move to .... * sysdeps/mips/fpu/fenv_private.h: ... here. Change multiple-include guard to [MIPS_FENV_PRIVATE_H]. Remove [__mips_hard_float] conditional. Include next <fenv_private.h>. * sysdeps/powerpc/fpu/fenv_private.h: Change multiple-include guard to [POWERPC_FENV_PRIVATE_H]. Include next <fenv_private.h>. * sysdeps/powerpc/fpu/math_private.h: Do not include <fenv_private.h>. * sysdeps/riscv/rvf/math_private.h: Move to .... * sysdeps/riscv/rvf/fenv_private.h: ... here. Change multiple-include guard to [RISCV_FENV_PRIVATE_H]. Include next <fenv_private.h>. * sysdeps/sparc/fpu/fenv_private.h: Change multiple-include guard to [SPARC_FENV_PRIVATE_H]. Include next <fenv_private.h>. * sysdeps/sparc/fpu/math_private.h: Remove. * sysdeps/i386/fpu/fenv_private.h: Move to .... * sysdeps/x86/fpu/fenv_private.h: ... here. Change multiple-include guard to [X86_FENV_PRIVATE_H]. Include next <fenv_private.h>. * sysdeps/x86_64/fpu/math_private.h: Do not include <sysdeps/i386/fpu/fenv_private.h>.
267 lines
6.4 KiB
C
267 lines
6.4 KiB
C
/*
|
|
* ====================================================
|
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
*
|
|
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
* Permission to use, copy, modify, and distribute this
|
|
* software is freely granted, provided that this notice
|
|
* is preserved.
|
|
* ====================================================
|
|
*/
|
|
|
|
/*
|
|
* from: @(#)fdlibm.h 5.1 93/09/24
|
|
*/
|
|
|
|
#ifndef _MATH_PRIVATE_H_
|
|
#define _MATH_PRIVATE_H_
|
|
|
|
#include <endian.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <sys/types.h>
|
|
|
|
/* Gather machine dependent _Floatn support. */
|
|
#include <bits/floatn.h>
|
|
|
|
/* The original fdlibm code used statements like:
|
|
n0 = ((*(int*)&one)>>29)^1; * index of high word *
|
|
ix0 = *(n0+(int*)&x); * high word of x *
|
|
ix1 = *((1-n0)+(int*)&x); * low word of x *
|
|
to dig two 32 bit words out of the 64 bit IEEE floating point
|
|
value. That is non-ANSI, and, moreover, the gcc instruction
|
|
scheduler gets it wrong. We instead use the following macros.
|
|
Unlike the original code, we determine the endianness at compile
|
|
time, not at run time; I don't see much benefit to selecting
|
|
endianness at run time. */
|
|
|
|
/* A union which permits us to convert between a double and two 32 bit
|
|
ints. */
|
|
|
|
#if __FLOAT_WORD_ORDER == __BIG_ENDIAN
|
|
|
|
typedef union
|
|
{
|
|
double value;
|
|
struct
|
|
{
|
|
uint32_t msw;
|
|
uint32_t lsw;
|
|
} parts;
|
|
uint64_t word;
|
|
} ieee_double_shape_type;
|
|
|
|
#endif
|
|
|
|
#if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
|
|
|
|
typedef union
|
|
{
|
|
double value;
|
|
struct
|
|
{
|
|
uint32_t lsw;
|
|
uint32_t msw;
|
|
} parts;
|
|
uint64_t word;
|
|
} ieee_double_shape_type;
|
|
|
|
#endif
|
|
|
|
/* Get two 32 bit ints from a double. */
|
|
|
|
#define EXTRACT_WORDS(ix0,ix1,d) \
|
|
do { \
|
|
ieee_double_shape_type ew_u; \
|
|
ew_u.value = (d); \
|
|
(ix0) = ew_u.parts.msw; \
|
|
(ix1) = ew_u.parts.lsw; \
|
|
} while (0)
|
|
|
|
/* Get the more significant 32 bit int from a double. */
|
|
|
|
#ifndef GET_HIGH_WORD
|
|
# define GET_HIGH_WORD(i,d) \
|
|
do { \
|
|
ieee_double_shape_type gh_u; \
|
|
gh_u.value = (d); \
|
|
(i) = gh_u.parts.msw; \
|
|
} while (0)
|
|
#endif
|
|
|
|
/* Get the less significant 32 bit int from a double. */
|
|
|
|
#ifndef GET_LOW_WORD
|
|
# define GET_LOW_WORD(i,d) \
|
|
do { \
|
|
ieee_double_shape_type gl_u; \
|
|
gl_u.value = (d); \
|
|
(i) = gl_u.parts.lsw; \
|
|
} while (0)
|
|
#endif
|
|
|
|
/* Get all in one, efficient on 64-bit machines. */
|
|
#ifndef EXTRACT_WORDS64
|
|
# define EXTRACT_WORDS64(i,d) \
|
|
do { \
|
|
ieee_double_shape_type gh_u; \
|
|
gh_u.value = (d); \
|
|
(i) = gh_u.word; \
|
|
} while (0)
|
|
#endif
|
|
|
|
/* Set a double from two 32 bit ints. */
|
|
#ifndef INSERT_WORDS
|
|
# define INSERT_WORDS(d,ix0,ix1) \
|
|
do { \
|
|
ieee_double_shape_type iw_u; \
|
|
iw_u.parts.msw = (ix0); \
|
|
iw_u.parts.lsw = (ix1); \
|
|
(d) = iw_u.value; \
|
|
} while (0)
|
|
#endif
|
|
|
|
/* Get all in one, efficient on 64-bit machines. */
|
|
#ifndef INSERT_WORDS64
|
|
# define INSERT_WORDS64(d,i) \
|
|
do { \
|
|
ieee_double_shape_type iw_u; \
|
|
iw_u.word = (i); \
|
|
(d) = iw_u.value; \
|
|
} while (0)
|
|
#endif
|
|
|
|
/* Set the more significant 32 bits of a double from an int. */
|
|
#ifndef SET_HIGH_WORD
|
|
#define SET_HIGH_WORD(d,v) \
|
|
do { \
|
|
ieee_double_shape_type sh_u; \
|
|
sh_u.value = (d); \
|
|
sh_u.parts.msw = (v); \
|
|
(d) = sh_u.value; \
|
|
} while (0)
|
|
#endif
|
|
|
|
/* Set the less significant 32 bits of a double from an int. */
|
|
#ifndef SET_LOW_WORD
|
|
# define SET_LOW_WORD(d,v) \
|
|
do { \
|
|
ieee_double_shape_type sl_u; \
|
|
sl_u.value = (d); \
|
|
sl_u.parts.lsw = (v); \
|
|
(d) = sl_u.value; \
|
|
} while (0)
|
|
#endif
|
|
|
|
/* A union which permits us to convert between a float and a 32 bit
|
|
int. */
|
|
|
|
typedef union
|
|
{
|
|
float value;
|
|
uint32_t word;
|
|
} ieee_float_shape_type;
|
|
|
|
/* Get a 32 bit int from a float. */
|
|
#ifndef GET_FLOAT_WORD
|
|
# define GET_FLOAT_WORD(i,d) \
|
|
do { \
|
|
ieee_float_shape_type gf_u; \
|
|
gf_u.value = (d); \
|
|
(i) = gf_u.word; \
|
|
} while (0)
|
|
#endif
|
|
|
|
/* Set a float from a 32 bit int. */
|
|
#ifndef SET_FLOAT_WORD
|
|
# define SET_FLOAT_WORD(d,i) \
|
|
do { \
|
|
ieee_float_shape_type sf_u; \
|
|
sf_u.word = (i); \
|
|
(d) = sf_u.value; \
|
|
} while (0)
|
|
#endif
|
|
|
|
/* We need to guarantee an expansion of name when building
|
|
ldbl-128 files as another type (e.g _Float128). */
|
|
#define mathx_hidden_def(name) hidden_def(name)
|
|
|
|
/* Get long double macros from a separate header. */
|
|
#include <math_ldbl.h>
|
|
|
|
/* Include function declarations for each floating-point. */
|
|
#define _Mdouble_ double
|
|
#define _MSUF_
|
|
#include <math_private_calls.h>
|
|
#undef _MSUF_
|
|
#undef _Mdouble_
|
|
|
|
#define _Mdouble_ float
|
|
#define _MSUF_ f
|
|
#define __MATH_DECLARING_FLOAT
|
|
#include <math_private_calls.h>
|
|
#undef __MATH_DECLARING_FLOAT
|
|
#undef _MSUF_
|
|
#undef _Mdouble_
|
|
|
|
#define _Mdouble_ long double
|
|
#define _MSUF_ l
|
|
#define __MATH_DECLARING_LONG_DOUBLE
|
|
#include <math_private_calls.h>
|
|
#undef __MATH_DECLARING_LONG_DOUBLE
|
|
#undef _MSUF_
|
|
#undef _Mdouble_
|
|
|
|
#if __HAVE_DISTINCT_FLOAT128
|
|
# define _Mdouble_ _Float128
|
|
# define _MSUF_ f128
|
|
# define __MATH_DECLARING_FLOATN
|
|
# include <math_private_calls.h>
|
|
# undef __MATH_DECLARING_FLOATN
|
|
# undef _MSUF_
|
|
# undef _Mdouble_
|
|
#endif
|
|
|
|
#if __HAVE_DISTINCT_FLOAT128
|
|
|
|
/* __builtin_isinf_sign is broken in GCC < 7 for float128. */
|
|
# if ! __GNUC_PREREQ (7, 0)
|
|
# include <ieee754_float128.h>
|
|
extern inline int
|
|
__isinff128 (_Float128 x)
|
|
{
|
|
int64_t hx, lx;
|
|
GET_FLOAT128_WORDS64 (hx, lx, x);
|
|
lx |= (hx & 0x7fffffffffffffffLL) ^ 0x7fff000000000000LL;
|
|
lx |= -lx;
|
|
return ~(lx >> 63) & (hx >> 62);
|
|
}
|
|
# endif
|
|
|
|
extern inline _Float128
|
|
fabsf128 (_Float128 x)
|
|
{
|
|
return __builtin_fabsf128 (x);
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
/* Prototypes for functions of the IBM Accurate Mathematical Library. */
|
|
extern double __exp1 (double __x, double __xx);
|
|
extern double __sin (double __x);
|
|
extern double __cos (double __x);
|
|
extern int __branred (double __x, double *__a, double *__aa);
|
|
extern void __doasin (double __x, double __dx, double __v[]);
|
|
extern void __dubsin (double __x, double __dx, double __v[]);
|
|
extern void __dubcos (double __x, double __dx, double __v[]);
|
|
extern double __sin32 (double __x, double __res, double __res1);
|
|
extern double __cos32 (double __x, double __res, double __res1);
|
|
extern double __mpsin (double __x, double __dx, bool __range_reduce);
|
|
extern double __mpcos (double __x, double __dx, bool __range_reduce);
|
|
extern void __docos (double __x, double __dx, double __v[]);
|
|
|
|
#include <fenv_private.h>
|
|
|
|
#endif /* _MATH_PRIVATE_H_ */
|