Index: head/lib/msun/Symbol.map =================================================================== --- head/lib/msun/Symbol.map (revision 226217) +++ head/lib/msun/Symbol.map (revision 226218) @@ -1,230 +1,240 @@ /* * $FreeBSD$ */ /* 7.0-CURRENT */ FBSD_1.0 { __fe_dfl_env; tgamma; acos; acosf; acosh; acoshf; asin; asinf; atan2; atan2f; atanh; atanhf; cosh; coshf; exp; expf; fmod; fmodf; gamma; gamma_r; gammaf; gammaf_r; hypot; hypotf; j0; y0; j0f; y0f; j1; y1; j1f; y1f; jn; yn; jnf; ynf; lgamma; lgamma_r; lgammaf; lgammaf_r; log; log10; log10f; logf; pow; powf; remainder; remainderf; scalb; scalbf; sinh; sinhf; sqrt; sqrtf; asinh; asinhf; atan; atanf; cbrt; cbrtf; ceil; ceilf; ceill; cimag; cimagf; cimagl; conj; conjf; conjl; copysign; copysignf; copysignl; cos; cosf; creal; crealf; creall; erf; erfc; erff; erfcf; exp2; exp2f; expm1; expm1f; fabs; fabsf; fabsl; fdim; fdimf; fdiml; finite; finitef; floor; floorf; floorl; fma; fmaf; fmal; fmax; fmaxf; fmaxl; fmin; fminf; fminl; frexp; frexpf; frexpl; ilogb; ilogbf; ilogbl; __isfinite; __isfinitef; __isfinitel; isnanf; __isnanl; __isnormal; __isnormalf; __isnormall; llrint; llrintf; llround; llroundf; llroundl; log1p; log1pf; logb; logbf; lrint; lrintf; lround; lroundf; lroundl; modff; modfl; nearbyint; nearbyintf; nextafter; nexttoward; nexttowardl; nextafterl; nextafterf; nexttowardf; remquo; remquof; rint; rintf; round; roundf; roundl; scalbln; scalblnf; scalblnl; scalbn; scalbnl; scalbnf; ldexpf; ldexpl; __signbit; __signbitf; __signbitl; signgam; significand; significandf; sin; sinf; tan; tanf; tanh; tanhf; trunc; truncf; truncl; cabs; cabsf; drem; dremf; }; /* First added in 8.0-CURRENT */ FBSD_1.1 { carg; cargf; csqrt; csqrtf; logbl; nan; nanf; nanl; llrintl; lrintl; nearbyintl; rintl; exp2l; sinl; cosl; tanl; tgammaf; sqrtl; hypotl; cabsl; csqrtl; remquol; remainderl; fmodl; acosl; asinl; atan2l; atanl; cargl; cproj; cprojf; cprojl; }; /* First added in 9.0-CURRENT */ FBSD_1.2 { __isnanf; cbrtl; cexp; cexpf; log2; log2f; }; + +/* First added in 10.0-CURRENT */ +FBSD_1.3 { + feclearexcept; + fegetexceptflag; + fetestexcept; + fegetround; + fesetround; + fesetenv; +}; Index: head/lib/msun/amd64/Symbol.map =================================================================== --- head/lib/msun/amd64/Symbol.map (revision 226217) +++ head/lib/msun/amd64/Symbol.map (revision 226218) @@ -1,14 +1,12 @@ /* * $FreeBSD$ */ FBSD_1.0 { fesetexceptflag; feraiseexcept; fegetenv; feholdexcept; feupdateenv; - __feenableexcept; - __fedisableexcept; feenableexcept; fedisableexcept; }; Index: head/lib/msun/amd64/fenv.c =================================================================== --- head/lib/msun/amd64/fenv.c (revision 226217) +++ head/lib/msun/amd64/fenv.c (revision 226218) @@ -1,149 +1,164 @@ /*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include + +#define __fenv_static #include +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + const fenv_t __fe_dfl_env = { { 0xffff0000 | __INITIAL_FPUCW__, 0xffff0000, 0xffffffff, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff } }, __INITIAL_MXCSR__ }; +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); + int fesetexceptflag(const fexcept_t *flagp, int excepts) { fenv_t env; __fnstenv(&env.__x87); env.__x87.__status &= ~excepts; env.__x87.__status |= *flagp & excepts; __fldenv(env.__x87); __stmxcsr(&env.__mxcsr); env.__mxcsr &= ~excepts; env.__mxcsr |= *flagp & excepts; __ldmxcsr(env.__mxcsr); return (0); } int feraiseexcept(int excepts) { fexcept_t ex = excepts; fesetexceptflag(&ex, excepts); __fwait(); return (0); } +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); + int fegetenv(fenv_t *envp) { __fnstenv(&envp->__x87); __stmxcsr(&envp->__mxcsr); /* * fnstenv masks all exceptions, so we need to restore the * control word to avoid this side effect. */ __fldcw(envp->__x87.__control); return (0); } int feholdexcept(fenv_t *envp) { __uint32_t mxcsr; __stmxcsr(&mxcsr); __fnstenv(&envp->__x87); __fnclex(); envp->__mxcsr = mxcsr; mxcsr &= ~FE_ALL_EXCEPT; mxcsr |= FE_ALL_EXCEPT << _SSE_EMASK_SHIFT; __ldmxcsr(mxcsr); return (0); } + +extern inline int fesetenv(const fenv_t *__envp); int feupdateenv(const fenv_t *envp) { __uint32_t mxcsr; __uint16_t status; __fnstsw(&status); __stmxcsr(&mxcsr); fesetenv(envp); feraiseexcept((mxcsr | status) & FE_ALL_EXCEPT); return (0); } int __feenableexcept(int mask) { __uint32_t mxcsr, omask; __uint16_t control; mask &= FE_ALL_EXCEPT; __fnstcw(&control); __stmxcsr(&mxcsr); omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control &= ~mask; __fldcw(control); mxcsr &= ~(mask << _SSE_EMASK_SHIFT); __ldmxcsr(mxcsr); return (~omask); } int __fedisableexcept(int mask) { __uint32_t mxcsr, omask; __uint16_t control; mask &= FE_ALL_EXCEPT; __fnstcw(&control); __stmxcsr(&mxcsr); omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control |= mask; __fldcw(control); mxcsr |= mask << _SSE_EMASK_SHIFT; __ldmxcsr(mxcsr); return (~omask); } __weak_reference(__feenableexcept, feenableexcept); __weak_reference(__fedisableexcept, fedisableexcept); Index: head/lib/msun/amd64/fenv.h =================================================================== --- head/lib/msun/amd64/fenv.h (revision 226217) +++ head/lib/msun/amd64/fenv.h (revision 226218) @@ -1,217 +1,222 @@ /*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _FENV_H_ #define _FENV_H_ #include #include +#ifndef __fenv_static +#define __fenv_static static +#endif + typedef struct { struct { __uint32_t __control; __uint32_t __status; __uint32_t __tag; char __other[16]; } __x87; __uint32_t __mxcsr; } fenv_t; typedef __uint16_t fexcept_t; /* Exception flags */ #define FE_INVALID 0x01 #define FE_DENORMAL 0x02 #define FE_DIVBYZERO 0x04 #define FE_OVERFLOW 0x08 #define FE_UNDERFLOW 0x10 #define FE_INEXACT 0x20 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \ FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* Rounding modes */ #define FE_TONEAREST 0x0000 #define FE_DOWNWARD 0x0400 #define FE_UPWARD 0x0800 #define FE_TOWARDZERO 0x0c00 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ FE_UPWARD | FE_TOWARDZERO) /* * As compared to the x87 control word, the SSE unit's control word * has the rounding control bits offset by 3 and the exception mask * bits offset by 7. */ #define _SSE_ROUND_SHIFT 3 #define _SSE_EMASK_SHIFT 7 __BEGIN_DECLS /* Default floating-point environment */ extern const fenv_t __fe_dfl_env; #define FE_DFL_ENV (&__fe_dfl_env) #define __fldcw(__cw) __asm __volatile("fldcw %0" : : "m" (__cw)) #define __fldenv(__env) __asm __volatile("fldenv %0" : : "m" (__env)) #define __fldenvx(__env) __asm __volatile("fldenv %0" : : "m" (__env) \ : "st", "st(1)", "st(2)", "st(3)", "st(4)", \ "st(5)", "st(6)", "st(7)") #define __fnclex() __asm __volatile("fnclex") #define __fnstenv(__env) __asm __volatile("fnstenv %0" : "=m" (*(__env))) #define __fnstcw(__cw) __asm __volatile("fnstcw %0" : "=m" (*(__cw))) #define __fnstsw(__sw) __asm __volatile("fnstsw %0" : "=am" (*(__sw))) #define __fwait() __asm __volatile("fwait") #define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr)) #define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr))) -static __inline int +__fenv_static inline int feclearexcept(int __excepts) { fenv_t __env; if (__excepts == FE_ALL_EXCEPT) { __fnclex(); } else { __fnstenv(&__env.__x87); __env.__x87.__status &= ~__excepts; __fldenv(__env.__x87); } __stmxcsr(&__env.__mxcsr); __env.__mxcsr &= ~__excepts; __ldmxcsr(__env.__mxcsr); return (0); } -static __inline int +__fenv_static inline int fegetexceptflag(fexcept_t *__flagp, int __excepts) { __uint32_t __mxcsr; __uint16_t __status; __stmxcsr(&__mxcsr); __fnstsw(&__status); *__flagp = (__mxcsr | __status) & __excepts; return (0); } int fesetexceptflag(const fexcept_t *__flagp, int __excepts); int feraiseexcept(int __excepts); -static __inline int +__fenv_static inline int fetestexcept(int __excepts) { __uint32_t __mxcsr; __uint16_t __status; __stmxcsr(&__mxcsr); __fnstsw(&__status); return ((__status | __mxcsr) & __excepts); } -static __inline int +__fenv_static inline int fegetround(void) { __uint16_t __control; /* * We assume that the x87 and the SSE unit agree on the * rounding mode. Reading the control word on the x87 turns * out to be about 5 times faster than reading it on the SSE * unit on an Opteron 244. */ __fnstcw(&__control); return (__control & _ROUND_MASK); } -static __inline int +__fenv_static inline int fesetround(int __round) { __uint32_t __mxcsr; __uint16_t __control; if (__round & ~_ROUND_MASK) return (-1); __fnstcw(&__control); __control &= ~_ROUND_MASK; __control |= __round; __fldcw(__control); __stmxcsr(&__mxcsr); __mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT); __mxcsr |= __round << _SSE_ROUND_SHIFT; __ldmxcsr(__mxcsr); return (0); } int fegetenv(fenv_t *__envp); int feholdexcept(fenv_t *__envp); -static __inline int +__fenv_static inline int fesetenv(const fenv_t *__envp) { /* * XXX Using fldenvx() instead of fldenv() tells the compiler that this * instruction clobbers the i387 register stack. This happens because * we restore the tag word from the saved environment. Normally, this * would happen anyway and we wouldn't care, because the ABI allows * function calls to clobber the i387 regs. However, fesetenv() is * inlined, so we need to be more careful. */ __fldenvx(__envp->__x87); __ldmxcsr(__envp->__mxcsr); return (0); } int feupdateenv(const fenv_t *__envp); #if __BSD_VISIBLE int feenableexcept(int __mask); int fedisableexcept(int __mask); -static __inline int +/* We currently provide no external definition of fegetexcept(). */ +static inline int fegetexcept(void) { __uint16_t __control; /* * We assume that the masks for the x87 and the SSE unit are * the same. */ __fnstcw(&__control); return (~__control & FE_ALL_EXCEPT); } #endif /* __BSD_VISIBLE */ __END_DECLS #endif /* !_FENV_H_ */ Index: head/lib/msun/arm/Symbol.map =================================================================== --- head/lib/msun/arm/Symbol.map (revision 226217) +++ head/lib/msun/arm/Symbol.map (revision 226218) @@ -1,5 +1,13 @@ /* * $FreeBSD$ */ FBSD_1.0 { }; + +FBSD_1.3 { + fesetexceptflag; + feraiseexcept; + fegetenv; + feholdexcept; + feupdateenv; +}; Index: head/lib/msun/arm/fenv.c =================================================================== --- head/lib/msun/arm/fenv.c (revision 226217) +++ head/lib/msun/arm/fenv.c (revision 226218) @@ -1,35 +1,52 @@ /*- * Copyright (c) 2004 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ +#define __fenv_static #include +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + /* * Hopefully the system ID byte is immutable, so it's valid to use * this as a default environment. */ const fenv_t __fe_dfl_env = 0; + +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); +extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +extern inline int feraiseexcept(int __excepts); +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); +extern inline int fegetenv(fenv_t *__envp); +extern inline int feholdexcept(fenv_t *__envp); +extern inline int fesetenv(const fenv_t *__envp); +extern inline int feupdateenv(const fenv_t *__envp); Index: head/lib/msun/arm/fenv.h =================================================================== --- head/lib/msun/arm/fenv.h (revision 226217) +++ head/lib/msun/arm/fenv.h (revision 226218) @@ -1,217 +1,223 @@ /*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _FENV_H_ #define _FENV_H_ #include +#ifndef __fenv_static +#define __fenv_static static +#endif + typedef __uint32_t fenv_t; typedef __uint32_t fexcept_t; /* Exception flags */ #define FE_INVALID 0x0001 #define FE_DIVBYZERO 0x0002 #define FE_OVERFLOW 0x0004 #define FE_UNDERFLOW 0x0008 #define FE_INEXACT 0x0010 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* Rounding modes */ #define FE_TONEAREST 0x0000 #define FE_TOWARDZERO 0x0001 #define FE_UPWARD 0x0002 #define FE_DOWNWARD 0x0003 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ FE_UPWARD | FE_TOWARDZERO) __BEGIN_DECLS /* Default floating-point environment */ extern const fenv_t __fe_dfl_env; #define FE_DFL_ENV (&__fe_dfl_env) /* We need to be able to map status flag positions to mask flag positions */ #define _FPUSW_SHIFT 16 #define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT) #ifdef ARM_HARD_FLOAT #define __rfs(__fpsr) __asm __volatile("rfs %0" : "=r" (*(__fpsr))) #define __wfs(__fpsr) __asm __volatile("wfs %0" : : "r" (__fpsr)) #else #define __rfs(__fpsr) #define __wfs(__fpsr) #endif -static __inline int +__fenv_static inline int feclearexcept(int __excepts) { fexcept_t __fpsr; __rfs(&__fpsr); __fpsr &= ~__excepts; __wfs(__fpsr); return (0); } -static __inline int +__fenv_static inline int fegetexceptflag(fexcept_t *__flagp, int __excepts) { fexcept_t __fpsr; __rfs(&__fpsr); *__flagp = __fpsr & __excepts; return (0); } -static __inline int +__fenv_static inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts) { fexcept_t __fpsr; __rfs(&__fpsr); __fpsr &= ~__excepts; __fpsr |= *__flagp & __excepts; __wfs(__fpsr); return (0); } -static __inline int +__fenv_static inline int feraiseexcept(int __excepts) { fexcept_t __ex = __excepts; fesetexceptflag(&__ex, __excepts); /* XXX */ return (0); } -static __inline int +__fenv_static inline int fetestexcept(int __excepts) { fexcept_t __fpsr; __rfs(&__fpsr); return (__fpsr & __excepts); } -static __inline int +__fenv_static inline int fegetround(void) { /* * Apparently, the rounding mode is specified as part of the * instruction format on ARM, so the dynamic rounding mode is * indeterminate. Some FPUs may differ. */ return (-1); } -static __inline int +__fenv_static inline int fesetround(int __round) { return (-1); } -static __inline int +__fenv_static inline int fegetenv(fenv_t *__envp) { __rfs(__envp); return (0); } -static __inline int +__fenv_static inline int feholdexcept(fenv_t *__envp) { fenv_t __env; __rfs(&__env); *__envp = __env; __env &= ~(FE_ALL_EXCEPT | _ENABLE_MASK); __wfs(__env); return (0); } -static __inline int +__fenv_static inline int fesetenv(const fenv_t *__envp) { __wfs(*__envp); return (0); } -static __inline int +__fenv_static inline int feupdateenv(const fenv_t *__envp) { fexcept_t __fpsr; __rfs(&__fpsr); __wfs(*__envp); feraiseexcept(__fpsr & FE_ALL_EXCEPT); return (0); } #if __BSD_VISIBLE -static __inline int +/* We currently provide no external definitions of the functions below. */ + +static inline int feenableexcept(int __mask) { fenv_t __old_fpsr, __new_fpsr; __rfs(&__old_fpsr); __new_fpsr = __old_fpsr | (__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT; __wfs(__new_fpsr); return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); } -static __inline int +static inline int fedisableexcept(int __mask) { fenv_t __old_fpsr, __new_fpsr; __rfs(&__old_fpsr); __new_fpsr = __old_fpsr & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); __wfs(__new_fpsr); return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); } -static __inline int +static inline int fegetexcept(void) { fenv_t __fpsr; __rfs(&__fpsr); return ((__fpsr & _ENABLE_MASK) >> _FPUSW_SHIFT); } #endif /* __BSD_VISIBLE */ __END_DECLS #endif /* !_FENV_H_ */ Index: head/lib/msun/i387/Symbol.map =================================================================== --- head/lib/msun/i387/Symbol.map (revision 226217) +++ head/lib/msun/i387/Symbol.map (revision 226218) @@ -1,16 +1,14 @@ /* * $FreeBSD$ */ FBSD_1.0 { __has_sse; __test_sse; fesetexceptflag; feraiseexcept; fegetenv; feholdexcept; feupdateenv; - __feenableexcept; - __fedisableexcept; feenableexcept; fedisableexcept; }; Index: head/lib/msun/i387/fenv.c =================================================================== --- head/lib/msun/i387/fenv.c (revision 226217) +++ head/lib/msun/i387/fenv.c (revision 226218) @@ -1,213 +1,225 @@ /*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include -#include "fenv.h" +#define __fenv_static +#include + +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + const fenv_t __fe_dfl_env = { __INITIAL_NPXCW__, 0x0000, 0x0000, 0x1f80, 0xffffffff, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff } }; enum __sse_support __has_sse = #ifdef __SSE__ __SSE_YES; #else __SSE_UNK; #endif #define getfl(x) __asm __volatile("pushfl\n\tpopl %0" : "=mr" (*(x))) #define setfl(x) __asm __volatile("pushl %0\n\tpopfl" : : "g" (x)) #define cpuid_dx(x) __asm __volatile("pushl %%ebx\n\tmovl $1, %%eax\n\t" \ "cpuid\n\tpopl %%ebx" \ : "=d" (*(x)) : : "eax", "ecx") /* * Test for SSE support on this processor. We need to do this because * we need to use ldmxcsr/stmxcsr to get correct results if any part * of the program was compiled to use SSE floating-point, but we can't * use SSE on older processors. */ int __test_sse(void) { int flag, nflag; int dx_features; /* Am I a 486? */ getfl(&flag); nflag = flag ^ 0x200000; setfl(nflag); getfl(&nflag); if (flag != nflag) { /* Not a 486, so CPUID should work. */ cpuid_dx(&dx_features); if (dx_features & 0x2000000) { __has_sse = __SSE_YES; return (1); } } __has_sse = __SSE_NO; return (0); } +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); + int fesetexceptflag(const fexcept_t *flagp, int excepts) { fenv_t env; __uint32_t mxcsr; __fnstenv(&env); env.__status &= ~excepts; env.__status |= *flagp & excepts; __fldenv(env); if (__HAS_SSE()) { __stmxcsr(&mxcsr); mxcsr &= ~excepts; mxcsr |= *flagp & excepts; __ldmxcsr(mxcsr); } return (0); } int feraiseexcept(int excepts) { fexcept_t ex = excepts; fesetexceptflag(&ex, excepts); __fwait(); return (0); } +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); + int fegetenv(fenv_t *envp) { __uint32_t mxcsr; __fnstenv(envp); /* * fnstenv masks all exceptions, so we need to restore * the old control word to avoid this side effect. */ __fldcw(envp->__control); if (__HAS_SSE()) { __stmxcsr(&mxcsr); __set_mxcsr(*envp, mxcsr); } return (0); } int feholdexcept(fenv_t *envp) { __uint32_t mxcsr; __fnstenv(envp); __fnclex(); if (__HAS_SSE()) { __stmxcsr(&mxcsr); __set_mxcsr(*envp, mxcsr); mxcsr &= ~FE_ALL_EXCEPT; mxcsr |= FE_ALL_EXCEPT << _SSE_EMASK_SHIFT; __ldmxcsr(mxcsr); } return (0); } +extern inline int fesetenv(const fenv_t *__envp); + int feupdateenv(const fenv_t *envp) { __uint32_t mxcsr; __uint16_t status; __fnstsw(&status); if (__HAS_SSE()) __stmxcsr(&mxcsr); else mxcsr = 0; fesetenv(envp); feraiseexcept((mxcsr | status) & FE_ALL_EXCEPT); return (0); } int __feenableexcept(int mask) { __uint32_t mxcsr, omask; __uint16_t control; mask &= FE_ALL_EXCEPT; __fnstcw(&control); if (__HAS_SSE()) __stmxcsr(&mxcsr); else mxcsr = 0; omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control &= ~mask; __fldcw(control); if (__HAS_SSE()) { mxcsr &= ~(mask << _SSE_EMASK_SHIFT); __ldmxcsr(mxcsr); } return (~omask); } int __fedisableexcept(int mask) { __uint32_t mxcsr, omask; __uint16_t control; mask &= FE_ALL_EXCEPT; __fnstcw(&control); if (__HAS_SSE()) __stmxcsr(&mxcsr); else mxcsr = 0; omask = (control | mxcsr >> _SSE_EMASK_SHIFT) & FE_ALL_EXCEPT; control |= mask; __fldcw(control); if (__HAS_SSE()) { mxcsr |= mask << _SSE_EMASK_SHIFT; __ldmxcsr(mxcsr); } return (~omask); } - -__weak_reference(__feenableexcept, feenableexcept); -__weak_reference(__fedisableexcept, fedisableexcept); Index: head/lib/msun/i387/fenv.h =================================================================== --- head/lib/msun/i387/fenv.h (revision 226217) +++ head/lib/msun/i387/fenv.h (revision 226218) @@ -1,254 +1,259 @@ /*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _FENV_H_ #define _FENV_H_ #include #include +#ifndef __fenv_static +#define __fenv_static static +#endif + /* * To preserve binary compatibility with FreeBSD 5.3, we pack the * mxcsr into some reserved fields, rather than changing sizeof(fenv_t). */ typedef struct { __uint16_t __control; __uint16_t __mxcsr_hi; __uint16_t __status; __uint16_t __mxcsr_lo; __uint32_t __tag; char __other[16]; } fenv_t; #define __get_mxcsr(env) (((env).__mxcsr_hi << 16) | \ ((env).__mxcsr_lo)) #define __set_mxcsr(env, x) do { \ (env).__mxcsr_hi = (__uint32_t)(x) >> 16; \ (env).__mxcsr_lo = (__uint16_t)(x); \ } while (0) typedef __uint16_t fexcept_t; /* Exception flags */ #define FE_INVALID 0x01 #define FE_DENORMAL 0x02 #define FE_DIVBYZERO 0x04 #define FE_OVERFLOW 0x08 #define FE_UNDERFLOW 0x10 #define FE_INEXACT 0x20 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \ FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* Rounding modes */ #define FE_TONEAREST 0x0000 #define FE_DOWNWARD 0x0400 #define FE_UPWARD 0x0800 #define FE_TOWARDZERO 0x0c00 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ FE_UPWARD | FE_TOWARDZERO) /* * As compared to the x87 control word, the SSE unit's control word * has the rounding control bits offset by 3 and the exception mask * bits offset by 7. */ #define _SSE_ROUND_SHIFT 3 #define _SSE_EMASK_SHIFT 7 __BEGIN_DECLS /* After testing for SSE support once, we cache the result in __has_sse. */ enum __sse_support { __SSE_YES, __SSE_NO, __SSE_UNK }; extern enum __sse_support __has_sse; int __test_sse(void); #ifdef __SSE__ #define __HAS_SSE() 1 #else #define __HAS_SSE() (__has_sse == __SSE_YES || \ (__has_sse == __SSE_UNK && __test_sse())) #endif /* Default floating-point environment */ extern const fenv_t __fe_dfl_env; #define FE_DFL_ENV (&__fe_dfl_env) #define __fldcw(__cw) __asm __volatile("fldcw %0" : : "m" (__cw)) #define __fldenv(__env) __asm __volatile("fldenv %0" : : "m" (__env)) #define __fldenvx(__env) __asm __volatile("fldenv %0" : : "m" (__env) \ : "st", "st(1)", "st(2)", "st(3)", "st(4)", \ "st(5)", "st(6)", "st(7)") #define __fnclex() __asm __volatile("fnclex") #define __fnstenv(__env) __asm __volatile("fnstenv %0" : "=m" (*(__env))) #define __fnstcw(__cw) __asm __volatile("fnstcw %0" : "=m" (*(__cw))) #define __fnstsw(__sw) __asm __volatile("fnstsw %0" : "=am" (*(__sw))) #define __fwait() __asm __volatile("fwait") #define __ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr)) #define __stmxcsr(__csr) __asm __volatile("stmxcsr %0" : "=m" (*(__csr))) -static __inline int +__fenv_static inline int feclearexcept(int __excepts) { fenv_t __env; __uint32_t __mxcsr; if (__excepts == FE_ALL_EXCEPT) { __fnclex(); } else { __fnstenv(&__env); __env.__status &= ~__excepts; __fldenv(__env); } if (__HAS_SSE()) { __stmxcsr(&__mxcsr); __mxcsr &= ~__excepts; __ldmxcsr(__mxcsr); } return (0); } -static __inline int +__fenv_static inline int fegetexceptflag(fexcept_t *__flagp, int __excepts) { __uint32_t __mxcsr; __uint16_t __status; __fnstsw(&__status); if (__HAS_SSE()) __stmxcsr(&__mxcsr); else __mxcsr = 0; *__flagp = (__mxcsr | __status) & __excepts; return (0); } int fesetexceptflag(const fexcept_t *__flagp, int __excepts); int feraiseexcept(int __excepts); -static __inline int +__fenv_static inline int fetestexcept(int __excepts) { __uint32_t __mxcsr; __uint16_t __status; __fnstsw(&__status); if (__HAS_SSE()) __stmxcsr(&__mxcsr); else __mxcsr = 0; return ((__status | __mxcsr) & __excepts); } -static __inline int +__fenv_static inline int fegetround(void) { __uint16_t __control; /* * We assume that the x87 and the SSE unit agree on the * rounding mode. Reading the control word on the x87 turns * out to be about 5 times faster than reading it on the SSE * unit on an Opteron 244. */ __fnstcw(&__control); return (__control & _ROUND_MASK); } -static __inline int +__fenv_static inline int fesetround(int __round) { __uint32_t __mxcsr; __uint16_t __control; if (__round & ~_ROUND_MASK) return (-1); __fnstcw(&__control); __control &= ~_ROUND_MASK; __control |= __round; __fldcw(__control); if (__HAS_SSE()) { __stmxcsr(&__mxcsr); __mxcsr &= ~(_ROUND_MASK << _SSE_ROUND_SHIFT); __mxcsr |= __round << _SSE_ROUND_SHIFT; __ldmxcsr(__mxcsr); } return (0); } int fegetenv(fenv_t *__envp); int feholdexcept(fenv_t *__envp); -static __inline int +__fenv_static inline int fesetenv(const fenv_t *__envp) { fenv_t __env = *__envp; __uint32_t __mxcsr; __mxcsr = __get_mxcsr(__env); __set_mxcsr(__env, 0xffffffff); /* * XXX Using fldenvx() instead of fldenv() tells the compiler that this * instruction clobbers the i387 register stack. This happens because * we restore the tag word from the saved environment. Normally, this * would happen anyway and we wouldn't care, because the ABI allows * function calls to clobber the i387 regs. However, fesetenv() is * inlined, so we need to be more careful. */ __fldenvx(__env); if (__HAS_SSE()) __ldmxcsr(__mxcsr); return (0); } int feupdateenv(const fenv_t *__envp); #if __BSD_VISIBLE int feenableexcept(int __mask); int fedisableexcept(int __mask); -static __inline int +/* We currently provide no external definition of fegetexcept(). */ +static inline int fegetexcept(void) { __uint16_t __control; /* * We assume that the masks for the x87 and the SSE unit are * the same. */ __fnstcw(&__control); return (~__control & FE_ALL_EXCEPT); } #endif /* __BSD_VISIBLE */ __END_DECLS #endif /* !_FENV_H_ */ Index: head/lib/msun/ia64/Symbol.map =================================================================== --- head/lib/msun/ia64/Symbol.map (revision 226217) +++ head/lib/msun/ia64/Symbol.map (revision 226218) @@ -1,6 +1,13 @@ /* * $FreeBSD$ */ FBSD_1.0 { feupdateenv; }; + +FBSD_1.3 { + fesetexceptflag; + feraiseexcept; + fegetenv; + feholdexcept; +}; Index: head/lib/msun/ia64/fenv.c =================================================================== --- head/lib/msun/ia64/fenv.c (revision 226217) +++ head/lib/msun/ia64/fenv.c (revision 226218) @@ -1,49 +1,66 @@ /*- * Copyright (c) 2004 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include + +#define __fenv_static #include +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + const fenv_t __fe_dfl_env = 0x0009804c8a70033fULL; + +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); +extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +extern inline int feraiseexcept(int __excepts); +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); +extern inline int fegetenv(fenv_t *__envp); +extern inline int feholdexcept(fenv_t *__envp); +extern inline int fesetenv(const fenv_t *__envp); /* * It doesn't pay to inline feupdateenv() because it includes one of * the rare uses of feraiseexcept() where the argument is not a * constant. Thus, no dead code elimination can occur, resulting in * significant bloat. */ int feupdateenv(const fenv_t *envp) { fenv_t fpsr; __stfpsr(&fpsr); __ldfpsr(*envp); feraiseexcept((fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); return (0); } Index: head/lib/msun/ia64/fenv.h =================================================================== --- head/lib/msun/ia64/fenv.h (revision 226217) +++ head/lib/msun/ia64/fenv.h (revision 226218) @@ -1,242 +1,248 @@ /*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _FENV_H_ #define _FENV_H_ #include +#ifndef __fenv_static +#define __fenv_static static +#endif + typedef __uint64_t fenv_t; typedef __uint16_t fexcept_t; /* Exception flags */ #define FE_INVALID 0x01 #define FE_DENORMAL 0x02 #define FE_DIVBYZERO 0x04 #define FE_OVERFLOW 0x08 #define FE_UNDERFLOW 0x10 #define FE_INEXACT 0x20 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \ FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* Rounding modes */ #define FE_TONEAREST 0x0000 #define FE_DOWNWARD 0x0400 #define FE_UPWARD 0x0800 #define FE_TOWARDZERO 0x0c00 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ FE_UPWARD | FE_TOWARDZERO) __BEGIN_DECLS /* Default floating-point environment */ extern const fenv_t __fe_dfl_env; #define FE_DFL_ENV (&__fe_dfl_env) #define _FPUSW_SHIFT 13 #define __stfpsr(__r) __asm __volatile("mov %0=ar.fpsr" : "=r" (*(__r))) #define __ldfpsr(__r) __asm __volatile("mov ar.fpsr=%0;;" : : "r" (__r)) -static __inline int +__fenv_static inline int feclearexcept(int __excepts) { fenv_t __fpsr; __stfpsr(&__fpsr); __fpsr &= ~((fenv_t)__excepts << _FPUSW_SHIFT); __ldfpsr(__fpsr); return (0); } -static __inline int +__fenv_static inline int fegetexceptflag(fexcept_t *__flagp, int __excepts) { fenv_t __fpsr; __stfpsr(&__fpsr); *__flagp = (fexcept_t)(__fpsr >> _FPUSW_SHIFT) & __excepts; return (0); } -static __inline int +__fenv_static inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts) { fenv_t __fpsr; __stfpsr(&__fpsr); __fpsr &= ~((fenv_t)__excepts << _FPUSW_SHIFT); __fpsr |= (fenv_t)(__excepts & *__flagp) << _FPUSW_SHIFT; __ldfpsr(__fpsr); return (0); } /* * It is worthwhile to use the inline version of this function iff it * is called with arguments that are compile-time constants (due to * dead code elimination). Unfortunately, gcc isn't smart enough to * figure this out automatically, and there's no way to tell it. * We assume that constant arguments will be the common case. */ -static __inline int +__fenv_static inline int feraiseexcept(int __excepts) { volatile double d; /* * With a compiler that supports the FENV_ACCESS pragma * properly, simple expressions like '0.0 / 0.0' should * be sufficient to generate traps. Unfortunately, we * need to bring a volatile variable into the equation * to prevent incorrect optimizations. */ if (__excepts & FE_INVALID) { d = 0.0; d = 0.0 / d; } if (__excepts & FE_DIVBYZERO) { d = 0.0; d = 1.0 / d; } if (__excepts & FE_OVERFLOW) { d = 0x1.ffp1023; d *= 2.0; } if (__excepts & FE_UNDERFLOW) { d = 0x1p-1022; d /= 0x1p1023; } if (__excepts & FE_INEXACT) { d = 0x1p-1022; d += 1.0; } return (0); } -static __inline int +__fenv_static inline int fetestexcept(int __excepts) { fenv_t __fpsr; __stfpsr(&__fpsr); return ((__fpsr >> _FPUSW_SHIFT) & __excepts); } -static __inline int +__fenv_static inline int fegetround(void) { fenv_t __fpsr; __stfpsr(&__fpsr); return (__fpsr & _ROUND_MASK); } -static __inline int +__fenv_static inline int fesetround(int __round) { fenv_t __fpsr; if (__round & ~_ROUND_MASK) return (-1); __stfpsr(&__fpsr); __fpsr &= ~_ROUND_MASK; __fpsr |= __round; __ldfpsr(__fpsr); return (0); } -static __inline int +__fenv_static inline int fegetenv(fenv_t *__envp) { __stfpsr(__envp); return (0); } -static __inline int +__fenv_static inline int feholdexcept(fenv_t *__envp) { fenv_t __fpsr; __stfpsr(&__fpsr); *__envp = __fpsr; __fpsr &= ~((fenv_t)FE_ALL_EXCEPT << _FPUSW_SHIFT); __fpsr |= FE_ALL_EXCEPT; __ldfpsr(__fpsr); return (0); } -static __inline int +__fenv_static inline int fesetenv(const fenv_t *__envp) { __ldfpsr(*__envp); return (0); } int feupdateenv(const fenv_t *__envp); #if __BSD_VISIBLE -static __inline int +/* We currently provide no external definitions of the functions below. */ + +static inline int feenableexcept(int __mask) { fenv_t __newfpsr, __oldfpsr; __stfpsr(&__oldfpsr); __newfpsr = __oldfpsr & ~(__mask & FE_ALL_EXCEPT); __ldfpsr(__newfpsr); return (~__oldfpsr & FE_ALL_EXCEPT); } -static __inline int +static inline int fedisableexcept(int __mask) { fenv_t __newfpsr, __oldfpsr; __stfpsr(&__oldfpsr); __newfpsr = __oldfpsr | (__mask & FE_ALL_EXCEPT); __ldfpsr(__newfpsr); return (~__oldfpsr & FE_ALL_EXCEPT); } -static __inline int +static inline int fegetexcept(void) { fenv_t __fpsr; __stfpsr(&__fpsr); return (~__fpsr & FE_ALL_EXCEPT); } #endif /* __BSD_VISIBLE */ __END_DECLS #endif /* !_FENV_H_ */ Index: head/lib/msun/mips/Symbol.map =================================================================== --- head/lib/msun/mips/Symbol.map (revision 226217) +++ head/lib/msun/mips/Symbol.map (revision 226218) @@ -1,5 +1,13 @@ /* * $FreeBSD$ */ FBSD_1.0 { }; + +FBSD_1.3 { + fesetexceptflag; + feraiseexcept; + fegetenv; + feholdexcept; + feupdateenv; +}; Index: head/lib/msun/mips/fenv.c =================================================================== --- head/lib/msun/mips/fenv.c (revision 226217) +++ head/lib/msun/mips/fenv.c (revision 226218) @@ -1,35 +1,52 @@ /*- * Copyright (c) 2004 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ +#define __fenv_static #include +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + /* * Hopefully the system ID byte is immutable, so it's valid to use * this as a default environment. */ const fenv_t __fe_dfl_env = 0; + +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); +extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +extern inline int feraiseexcept(int __excepts); +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); +extern inline int fegetenv(fenv_t *__envp); +extern inline int feholdexcept(fenv_t *__envp); +extern inline int fesetenv(const fenv_t *__envp); +extern inline int feupdateenv(const fenv_t *__envp); Index: head/lib/msun/mips/fenv.h =================================================================== --- head/lib/msun/mips/fenv.h (revision 226217) +++ head/lib/msun/mips/fenv.h (revision 226218) @@ -1,217 +1,223 @@ /*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _FENV_H_ #define _FENV_H_ #include +#ifndef __fenv_static +#define __fenv_static static +#endif + typedef __uint32_t fenv_t; typedef __uint32_t fexcept_t; /* Exception flags */ #define FE_INVALID 0x0001 #define FE_DIVBYZERO 0x0002 #define FE_OVERFLOW 0x0004 #define FE_UNDERFLOW 0x0008 #define FE_INEXACT 0x0010 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* Rounding modes */ #define FE_TONEAREST 0x0000 #define FE_TOWARDZERO 0x0001 #define FE_UPWARD 0x0002 #define FE_DOWNWARD 0x0003 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ FE_UPWARD | FE_TOWARDZERO) __BEGIN_DECLS /* Default floating-point environment */ extern const fenv_t __fe_dfl_env; #define FE_DFL_ENV (&__fe_dfl_env) /* We need to be able to map status flag positions to mask flag positions */ #define _FPUSW_SHIFT 16 #define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT) #ifdef ARM_HARD_FLOAT #define __rfs(__fpsr) __asm __volatile("rfs %0" : "=r" (*(__fpsr))) #define __wfs(__fpsr) __asm __volatile("wfs %0" : : "r" (__fpsr)) #else #define __rfs(__fpsr) #define __wfs(__fpsr) #endif -static __inline int +__fenv_static inline int feclearexcept(int __excepts) { fexcept_t __fpsr; __rfs(&__fpsr); __fpsr &= ~__excepts; __wfs(__fpsr); return (0); } -static __inline int +__fenv_static inline int fegetexceptflag(fexcept_t *__flagp, int __excepts) { fexcept_t __fpsr; __rfs(&__fpsr); *__flagp = __fpsr & __excepts; return (0); } -static __inline int +__fenv_static inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts) { fexcept_t __fpsr; __rfs(&__fpsr); __fpsr &= ~__excepts; __fpsr |= *__flagp & __excepts; __wfs(__fpsr); return (0); } -static __inline int +__fenv_static inline int feraiseexcept(int __excepts) { fexcept_t __ex = __excepts; fesetexceptflag(&__ex, __excepts); /* XXX */ return (0); } -static __inline int +__fenv_static inline int fetestexcept(int __excepts) { fexcept_t __fpsr; __rfs(&__fpsr); return (__fpsr & __excepts); } -static __inline int +__fenv_static inline int fegetround(void) { /* * Apparently, the rounding mode is specified as part of the * instruction format on ARM, so the dynamic rounding mode is * indeterminate. Some FPUs may differ. */ return (-1); } -static __inline int +__fenv_static inline int fesetround(int __round) { return (-1); } -static __inline int +__fenv_static inline int fegetenv(fenv_t *__envp) { __rfs(__envp); return (0); } -static __inline int +__fenv_static inline int feholdexcept(fenv_t *__envp) { fenv_t __env; __rfs(&__env); *__envp = __env; __env &= ~(FE_ALL_EXCEPT | _ENABLE_MASK); __wfs(__env); return (0); } -static __inline int +__fenv_static inline int fesetenv(const fenv_t *__envp) { __wfs(*__envp); return (0); } -static __inline int +__fenv_static inline int feupdateenv(const fenv_t *__envp) { fexcept_t __fpsr; __rfs(&__fpsr); __wfs(*__envp); feraiseexcept(__fpsr & FE_ALL_EXCEPT); return (0); } #if __BSD_VISIBLE -static __inline int +/* We currently provide no external definitions of the functions below. */ + +static inline int feenableexcept(int __mask) { fenv_t __old_fpsr, __new_fpsr; __rfs(&__old_fpsr); __new_fpsr = __old_fpsr | (__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT; __wfs(__new_fpsr); return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); } -static __inline int +static inline int fedisableexcept(int __mask) { fenv_t __old_fpsr, __new_fpsr; __rfs(&__old_fpsr); __new_fpsr = __old_fpsr & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); __wfs(__new_fpsr); return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); } -static __inline int +static inline int fegetexcept(void) { fenv_t __fpsr; __rfs(&__fpsr); return ((__fpsr & _ENABLE_MASK) >> _FPUSW_SHIFT); } #endif /* __BSD_VISIBLE */ __END_DECLS #endif /* !_FENV_H_ */ Index: head/lib/msun/powerpc/Symbol.map =================================================================== --- head/lib/msun/powerpc/Symbol.map (revision 226217) +++ head/lib/msun/powerpc/Symbol.map (revision 226218) @@ -1,5 +1,13 @@ /* * $FreeBSD$ */ FBSD_1.0 { }; + +FBSD_1.3 { + fesetexceptflag; + feraiseexcept; + fegetenv; + feholdexcept; + feupdateenv; +}; Index: head/lib/msun/powerpc/fenv.c =================================================================== --- head/lib/msun/powerpc/fenv.c (revision 226217) +++ head/lib/msun/powerpc/fenv.c (revision 226218) @@ -1,31 +1,48 @@ /*- * Copyright (c) 2004 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ +#define __fenv_static #include +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + const fenv_t __fe_dfl_env = 0x00000000; + +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); +extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +extern inline int feraiseexcept(int __excepts); +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); +extern inline int fegetenv(fenv_t *__envp); +extern inline int feholdexcept(fenv_t *__envp); +extern inline int fesetenv(const fenv_t *__envp); +extern inline int feupdateenv(const fenv_t *__envp); Index: head/lib/msun/powerpc/fenv.h =================================================================== --- head/lib/msun/powerpc/fenv.h (revision 226217) +++ head/lib/msun/powerpc/fenv.h (revision 226218) @@ -1,268 +1,274 @@ /*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _FENV_H_ #define _FENV_H_ #include +#ifndef __fenv_static +#define __fenv_static static +#endif + typedef __uint32_t fenv_t; typedef __uint32_t fexcept_t; /* Exception flags */ #define FE_INEXACT 0x02000000 #define FE_DIVBYZERO 0x04000000 #define FE_UNDERFLOW 0x08000000 #define FE_OVERFLOW 0x10000000 #define FE_INVALID 0x20000000 /* all types of invalid FP ops */ /* * The PowerPC architecture has extra invalid flags that indicate the * specific type of invalid operation occurred. These flags may be * tested, set, and cleared---but not masked---separately. All of * these bits are cleared when FE_INVALID is cleared, but only * FE_VXSOFT is set when FE_INVALID is explicitly set in software. */ #define FE_VXCVI 0x00000100 /* invalid integer convert */ #define FE_VXSQRT 0x00000200 /* square root of a negative */ #define FE_VXSOFT 0x00000400 /* software-requested exception */ #define FE_VXVC 0x00080000 /* ordered comparison involving NaN */ #define FE_VXIMZ 0x00100000 /* inf * 0 */ #define FE_VXZDZ 0x00200000 /* 0 / 0 */ #define FE_VXIDI 0x00400000 /* inf / inf */ #define FE_VXISI 0x00800000 /* inf - inf */ #define FE_VXSNAN 0x01000000 /* operation on a signalling NaN */ #define FE_ALL_INVALID (FE_VXCVI | FE_VXSQRT | FE_VXSOFT | FE_VXVC | \ FE_VXIMZ | FE_VXZDZ | FE_VXIDI | FE_VXISI | \ FE_VXSNAN | FE_INVALID) #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ FE_ALL_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* Rounding modes */ #define FE_TONEAREST 0x0000 #define FE_TOWARDZERO 0x0001 #define FE_UPWARD 0x0002 #define FE_DOWNWARD 0x0003 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ FE_UPWARD | FE_TOWARDZERO) __BEGIN_DECLS /* Default floating-point environment */ extern const fenv_t __fe_dfl_env; #define FE_DFL_ENV (&__fe_dfl_env) /* We need to be able to map status flag positions to mask flag positions */ #define _FPUSW_SHIFT 22 #define _ENABLE_MASK ((FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \ FE_OVERFLOW | FE_UNDERFLOW) >> _FPUSW_SHIFT) #ifndef _SOFT_FLOAT #define __mffs(__env) __asm __volatile("mffs %0" : "=f" (*(__env))) #define __mtfsf(__env) __asm __volatile("mtfsf 255,%0" : : "f" (__env)) #else #define __mffs(__env) #define __mtfsf(__env) #endif union __fpscr { double __d; struct { __uint32_t __junk; fenv_t __reg; } __bits; }; -static __inline int +__fenv_static inline int feclearexcept(int __excepts) { union __fpscr __r; if (__excepts & FE_INVALID) __excepts |= FE_ALL_INVALID; __mffs(&__r.__d); __r.__bits.__reg &= ~__excepts; __mtfsf(__r.__d); return (0); } -static __inline int +__fenv_static inline int fegetexceptflag(fexcept_t *__flagp, int __excepts) { union __fpscr __r; __mffs(&__r.__d); *__flagp = __r.__bits.__reg & __excepts; return (0); } -static __inline int +__fenv_static inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts) { union __fpscr __r; if (__excepts & FE_INVALID) __excepts |= FE_ALL_EXCEPT; __mffs(&__r.__d); __r.__bits.__reg &= ~__excepts; __r.__bits.__reg |= *__flagp & __excepts; __mtfsf(__r.__d); return (0); } -static __inline int +__fenv_static inline int feraiseexcept(int __excepts) { union __fpscr __r; if (__excepts & FE_INVALID) __excepts |= FE_VXSOFT; __mffs(&__r.__d); __r.__bits.__reg |= __excepts; __mtfsf(__r.__d); return (0); } -static __inline int +__fenv_static inline int fetestexcept(int __excepts) { union __fpscr __r; __mffs(&__r.__d); return (__r.__bits.__reg & __excepts); } -static __inline int +__fenv_static inline int fegetround(void) { union __fpscr __r; __mffs(&__r.__d); return (__r.__bits.__reg & _ROUND_MASK); } -static __inline int +__fenv_static inline int fesetround(int __round) { union __fpscr __r; if (__round & ~_ROUND_MASK) return (-1); __mffs(&__r.__d); __r.__bits.__reg &= ~_ROUND_MASK; __r.__bits.__reg |= __round; __mtfsf(__r.__d); return (0); } -static __inline int +__fenv_static inline int fegetenv(fenv_t *__envp) { union __fpscr __r; __mffs(&__r.__d); *__envp = __r.__bits.__reg; return (0); } -static __inline int +__fenv_static inline int feholdexcept(fenv_t *__envp) { union __fpscr __r; __mffs(&__r.__d); *__envp = __r.__d; __r.__bits.__reg &= ~(FE_ALL_EXCEPT | _ENABLE_MASK); __mtfsf(__r.__d); return (0); } -static __inline int +__fenv_static inline int fesetenv(const fenv_t *__envp) { union __fpscr __r; __r.__bits.__reg = *__envp; __mtfsf(__r.__d); return (0); } -static __inline int +__fenv_static inline int feupdateenv(const fenv_t *__envp) { union __fpscr __r; __mffs(&__r.__d); __r.__bits.__reg &= FE_ALL_EXCEPT; __r.__bits.__reg |= *__envp; __mtfsf(__r.__d); return (0); } #if __BSD_VISIBLE -static __inline int +/* We currently provide no external definitions of the functions below. */ + +static inline int feenableexcept(int __mask) { union __fpscr __r; fenv_t __oldmask; __mffs(&__r.__d); __oldmask = __r.__bits.__reg; __r.__bits.__reg |= (__mask & FE_ALL_EXCEPT) >> _FPUSW_SHIFT; __mtfsf(__r.__d); return ((__oldmask & _ENABLE_MASK) << _FPUSW_SHIFT); } -static __inline int +static inline int fedisableexcept(int __mask) { union __fpscr __r; fenv_t __oldmask; __mffs(&__r.__d); __oldmask = __r.__bits.__reg; __r.__bits.__reg &= ~((__mask & FE_ALL_EXCEPT) >> _FPUSW_SHIFT); __mtfsf(__r.__d); return ((__oldmask & _ENABLE_MASK) << _FPUSW_SHIFT); } -static __inline int +static inline int fegetexcept(void) { union __fpscr __r; __mffs(&__r.__d); return ((__r.__bits.__reg & _ENABLE_MASK) << _FPUSW_SHIFT); } #endif /* __BSD_VISIBLE */ __END_DECLS #endif /* !_FENV_H_ */ Index: head/lib/msun/sparc64/Symbol.map =================================================================== --- head/lib/msun/sparc64/Symbol.map (revision 226217) +++ head/lib/msun/sparc64/Symbol.map (revision 226218) @@ -1,5 +1,13 @@ /* * $FreeBSD$ */ FBSD_1.0 { }; + +FBSD_1.3 { + fesetexceptflag; + feraiseexcept; + fegetenv; + feholdexcept; + feupdateenv; +}; Index: head/lib/msun/sparc64/fenv.c =================================================================== --- head/lib/msun/sparc64/fenv.c (revision 226217) +++ head/lib/msun/sparc64/fenv.c (revision 226218) @@ -1,36 +1,53 @@ /*- * Copyright (c) 2004 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ +#define __fenv_static #include +#ifdef __GNUC_GNU_INLINE__ +#error "This file must be compiled with C99 'inline' semantics" +#endif + /* * The FSR_version field may be different on different * implementations, but it is immutable and opaque to the * application. Thus, 0 is valid as the default environment. */ const fenv_t __fe_dfl_env = 0; + +extern inline int feclearexcept(int __excepts); +extern inline int fegetexceptflag(fexcept_t *__flagp, int __excepts); +extern inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts); +extern inline int feraiseexcept(int __excepts); +extern inline int fetestexcept(int __excepts); +extern inline int fegetround(void); +extern inline int fesetround(int __round); +extern inline int fegetenv(fenv_t *__envp); +extern inline int feholdexcept(fenv_t *__envp); +extern inline int fesetenv(const fenv_t *__envp); +extern inline int feupdateenv(const fenv_t *__envp); Index: head/lib/msun/sparc64/fenv.h =================================================================== --- head/lib/msun/sparc64/fenv.h (revision 226217) +++ head/lib/msun/sparc64/fenv.h (revision 226218) @@ -1,254 +1,260 @@ /*- * Copyright (c) 2004-2005 David Schultz * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _FENV_H_ #define _FENV_H_ #include +#ifndef __fenv_static +#define __fenv_static static +#endif + typedef __uint64_t fenv_t; typedef __uint64_t fexcept_t; /* Exception flags */ #define FE_INVALID 0x00000200 #define FE_DIVBYZERO 0x00000040 #define FE_OVERFLOW 0x00000100 #define FE_UNDERFLOW 0x00000080 #define FE_INEXACT 0x00000020 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) /* * Rounding modes * * We can't just use the hardware bit values here, because that would * make FE_UPWARD and FE_DOWNWARD negative, which is not allowed. */ #define FE_TONEAREST 0x0 #define FE_TOWARDZERO 0x1 #define FE_UPWARD 0x2 #define FE_DOWNWARD 0x3 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ FE_UPWARD | FE_TOWARDZERO) #define _ROUND_SHIFT 30 __BEGIN_DECLS /* Default floating-point environment */ extern const fenv_t __fe_dfl_env; #define FE_DFL_ENV (&__fe_dfl_env) /* We need to be able to map status flag positions to mask flag positions */ #define _FPUSW_SHIFT 18 #define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT) #define __ldxfsr(__r) __asm __volatile("ldx %0, %%fsr" : : "m" (__r)) #define __stxfsr(__r) __asm __volatile("stx %%fsr, %0" : "=m" (*(__r))) -static __inline int +__fenv_static __inline int feclearexcept(int __excepts) { fexcept_t __r; __stxfsr(&__r); __r &= ~__excepts; __ldxfsr(__r); return (0); } -static __inline int +__fenv_static inline int fegetexceptflag(fexcept_t *__flagp, int __excepts) { fexcept_t __r; __stxfsr(&__r); *__flagp = __r & __excepts; return (0); } -static __inline int +__fenv_static inline int fesetexceptflag(const fexcept_t *__flagp, int __excepts) { fexcept_t __r; __stxfsr(&__r); __r &= ~__excepts; __r |= *__flagp & __excepts; __ldxfsr(__r); return (0); } /* * In contrast with the ia64 platform, it seems to be worthwhile to * inline this function on sparc64 even when the arguments are not * compile-time constants. Perhaps this depends on the register window. */ -static __inline int +__fenv_static inline int feraiseexcept(int __excepts) { volatile double d; /* * With a compiler that supports the FENV_ACCESS pragma * properly, simple expressions like '0.0 / 0.0' should * be sufficient to generate traps. Unfortunately, we * need to bring a volatile variable into the equation * to prevent incorrect optimizations. */ if (__excepts & FE_INVALID) { d = 0.0; d = 0.0 / d; } if (__excepts & FE_DIVBYZERO) { d = 0.0; d = 1.0 / d; } if (__excepts & FE_OVERFLOW) { d = 0x1.ffp1023; d *= 2.0; } if (__excepts & FE_UNDERFLOW) { d = 0x1p-1022; d /= 0x1p1023; } if (__excepts & FE_INEXACT) { d = 0x1p-1022; d += 1.0; } return (0); } -static __inline int +__fenv_static inline int fetestexcept(int __excepts) { fexcept_t __r; __stxfsr(&__r); return (__r & __excepts); } -static __inline int +__fenv_static inline int fegetround(void) { fenv_t __r; __stxfsr(&__r); return ((__r >> _ROUND_SHIFT) & _ROUND_MASK); } -static __inline int +__fenv_static inline int fesetround(int __round) { fenv_t __r; if (__round & ~_ROUND_MASK) return (-1); __stxfsr(&__r); __r &= ~(_ROUND_MASK << _ROUND_SHIFT); __r |= __round << _ROUND_SHIFT; __ldxfsr(__r); return (0); } -static __inline int +__fenv_static inline int fegetenv(fenv_t *__envp) { __stxfsr(__envp); return (0); } -static __inline int +__fenv_static inline int feholdexcept(fenv_t *__envp) { fenv_t __r; __stxfsr(&__r); *__envp = __r; __r &= ~(FE_ALL_EXCEPT | _ENABLE_MASK); __ldxfsr(__r); return (0); } -static __inline int +__fenv_static inline int fesetenv(const fenv_t *__envp) { __ldxfsr(*__envp); return (0); } -static __inline int +__fenv_static inline int feupdateenv(const fenv_t *__envp) { fexcept_t __r; __stxfsr(&__r); __ldxfsr(*__envp); feraiseexcept(__r & FE_ALL_EXCEPT); return (0); } #if __BSD_VISIBLE -static __inline int +/* We currently provide no external definitions of the functions below. */ + +static inline int feenableexcept(int __mask) { fenv_t __old_r, __new_r; __stxfsr(&__old_r); __new_r = __old_r | ((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); __ldxfsr(__new_r); return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); } -static __inline int +static inline int fedisableexcept(int __mask) { fenv_t __old_r, __new_r; __stxfsr(&__old_r); __new_r = __old_r & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT); __ldxfsr(__new_r); return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT); } -static __inline int +static inline int fegetexcept(void) { fenv_t __r; __stxfsr(&__r); return ((__r & _ENABLE_MASK) >> _FPUSW_SHIFT); } #endif /* __BSD_VISIBLE */ __END_DECLS #endif /* !_FENV_H_ */