2004-06-06 12:03:59 +02:00
|
|
|
/*-
|
2005-03-16 20:03:46 +01:00
|
|
|
* Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
|
2004-06-06 12:03:59 +02:00
|
|
|
* 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 <sys/_types.h>
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
#ifndef __fenv_static
|
|
|
|
#define __fenv_static static
|
|
|
|
#endif
|
|
|
|
|
2004-06-06 12:03:59 +02:00
|
|
|
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
|
2013-10-27 11:44:22 +01:00
|
|
|
#ifdef __ARM_PCS_VFP
|
|
|
|
#define FE_DENORMAL 0x0080
|
|
|
|
#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
|
|
|
|
FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW | FE_DENORMAL)
|
|
|
|
#else
|
2004-06-06 12:03:59 +02:00
|
|
|
#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
|
|
|
|
FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
|
2013-10-27 11:44:22 +01:00
|
|
|
#endif
|
2004-06-06 12:03:59 +02:00
|
|
|
|
2005-01-24 01:35:02 +01:00
|
|
|
/* Rounding modes */
|
2014-03-15 22:58:07 +01:00
|
|
|
#define VFP_FE_TONEAREST 0x00000000
|
|
|
|
#define VFP_FE_UPWARD 0x00400000
|
|
|
|
#define VFP_FE_DOWNWARD 0x00800000
|
|
|
|
#define VFP_FE_TOWARDZERO 0x00c00000
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
#ifdef __ARM_PCS_VFP
|
2014-03-15 22:58:07 +01:00
|
|
|
#define FE_TONEAREST VFP_FE_TONEAREST
|
|
|
|
#define FE_UPWARD VFP_FE_UPWARD
|
|
|
|
#define FE_DOWNWARD VFP_FE_DOWNWARD
|
|
|
|
#define FE_TOWARDZERO VFP_FE_TOWARDZERO
|
2013-10-27 11:44:22 +01:00
|
|
|
#else
|
2005-01-24 01:35:02 +01:00
|
|
|
#define FE_TONEAREST 0x0000
|
|
|
|
#define FE_TOWARDZERO 0x0001
|
|
|
|
#define FE_UPWARD 0x0002
|
|
|
|
#define FE_DOWNWARD 0x0003
|
2013-10-27 11:44:22 +01:00
|
|
|
#endif
|
2005-01-24 01:35:02 +01:00
|
|
|
#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
|
|
|
|
FE_UPWARD | FE_TOWARDZERO)
|
2004-06-06 12:03:59 +02:00
|
|
|
__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 */
|
2013-10-27 11:44:22 +01:00
|
|
|
#ifndef __ARM_PCS_VFP
|
|
|
|
#define _FPUSW_SHIFT 16
|
2004-06-06 12:03:59 +02:00
|
|
|
#define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT)
|
2013-10-27 11:44:22 +01:00
|
|
|
#endif
|
2004-06-06 12:03:59 +02:00
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
#ifndef __ARM_PCS_VFP
|
2012-01-20 07:54:30 +01:00
|
|
|
|
|
|
|
int feclearexcept(int __excepts);
|
|
|
|
int fegetexceptflag(fexcept_t *__flagp, int __excepts);
|
|
|
|
int fesetexceptflag(const fexcept_t *__flagp, int __excepts);
|
|
|
|
int feraiseexcept(int __excepts);
|
|
|
|
int fetestexcept(int __excepts);
|
|
|
|
int fegetround(void);
|
|
|
|
int fesetround(int __round);
|
|
|
|
int fegetenv(fenv_t *__envp);
|
|
|
|
int feholdexcept(fenv_t *__envp);
|
|
|
|
int fesetenv(const fenv_t *__envp);
|
|
|
|
int feupdateenv(const fenv_t *__envp);
|
2014-03-15 22:58:07 +01:00
|
|
|
#if __BSD_VISIBLE
|
|
|
|
int feenableexcept(int __mask);
|
|
|
|
int fedisableexcept(int __mask);
|
|
|
|
int fegetexcept(void);
|
|
|
|
#endif
|
2012-01-16 05:09:17 +01:00
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
#else /* __ARM_PCS_VFP */
|
2012-01-16 05:09:17 +01:00
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
#define vmrs_fpscr(__r) __asm __volatile("vmrs %0, fpscr" : "=&r"(__r))
|
|
|
|
#define vmsr_fpscr(__r) __asm __volatile("vmsr fpscr, %0" : : "r"(__r))
|
2004-06-06 12:03:59 +02:00
|
|
|
|
2014-01-25 19:13:43 +01:00
|
|
|
#define _FPU_MASK_SHIFT 8
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
feclearexcept(int __excepts)
|
|
|
|
{
|
|
|
|
fexcept_t __fpsr;
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__fpsr);
|
2004-06-06 12:03:59 +02:00
|
|
|
__fpsr &= ~__excepts;
|
2013-10-27 11:44:22 +01:00
|
|
|
vmsr_fpscr(__fpsr);
|
2004-06-06 12:03:59 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
fegetexceptflag(fexcept_t *__flagp, int __excepts)
|
|
|
|
{
|
|
|
|
fexcept_t __fpsr;
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__fpsr);
|
2004-06-06 12:03:59 +02:00
|
|
|
*__flagp = __fpsr & __excepts;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
fesetexceptflag(const fexcept_t *__flagp, int __excepts)
|
|
|
|
{
|
|
|
|
fexcept_t __fpsr;
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__fpsr);
|
2004-06-06 12:03:59 +02:00
|
|
|
__fpsr &= ~__excepts;
|
|
|
|
__fpsr |= *__flagp & __excepts;
|
2013-10-27 11:44:22 +01:00
|
|
|
vmsr_fpscr(__fpsr);
|
2004-06-06 12:03:59 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
feraiseexcept(int __excepts)
|
|
|
|
{
|
|
|
|
fexcept_t __ex = __excepts;
|
|
|
|
|
|
|
|
fesetexceptflag(&__ex, __excepts); /* XXX */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
fetestexcept(int __excepts)
|
|
|
|
{
|
|
|
|
fexcept_t __fpsr;
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__fpsr);
|
2004-06-06 12:03:59 +02:00
|
|
|
return (__fpsr & __excepts);
|
|
|
|
}
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
fegetround(void)
|
|
|
|
{
|
2013-10-27 11:44:22 +01:00
|
|
|
fenv_t __fpsr;
|
2004-06-06 12:03:59 +02:00
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__fpsr);
|
|
|
|
return (__fpsr & _ROUND_MASK);
|
2004-06-06 12:03:59 +02:00
|
|
|
}
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
fesetround(int __round)
|
|
|
|
{
|
2013-10-27 11:44:22 +01:00
|
|
|
fenv_t __fpsr;
|
2004-06-06 12:03:59 +02:00
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__fpsr);
|
|
|
|
__fpsr &= ~(_ROUND_MASK);
|
|
|
|
__fpsr |= __round;
|
|
|
|
vmsr_fpscr(__fpsr);
|
|
|
|
return (0);
|
2004-06-06 12:03:59 +02:00
|
|
|
}
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
fegetenv(fenv_t *__envp)
|
|
|
|
{
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(*__envp);
|
2004-06-06 12:03:59 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
feholdexcept(fenv_t *__envp)
|
|
|
|
{
|
|
|
|
fenv_t __env;
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__env);
|
2004-06-06 12:03:59 +02:00
|
|
|
*__envp = __env;
|
2013-10-27 11:44:22 +01:00
|
|
|
__env &= ~(FE_ALL_EXCEPT);
|
|
|
|
vmsr_fpscr(__env);
|
2004-06-06 12:03:59 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
fesetenv(const fenv_t *__envp)
|
|
|
|
{
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmsr_fpscr(*__envp);
|
2004-06-06 12:03:59 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
__fenv_static inline int
|
2004-06-06 12:03:59 +02:00
|
|
|
feupdateenv(const fenv_t *__envp)
|
|
|
|
{
|
|
|
|
fexcept_t __fpsr;
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__fpsr);
|
|
|
|
vmsr_fpscr(*__envp);
|
2004-06-06 12:03:59 +02:00
|
|
|
feraiseexcept(__fpsr & FE_ALL_EXCEPT);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if __BSD_VISIBLE
|
|
|
|
|
2011-10-10 17:43:09 +02:00
|
|
|
/* We currently provide no external definitions of the functions below. */
|
|
|
|
|
2014-01-25 19:13:43 +01:00
|
|
|
__fenv_static inline int
|
2005-03-16 20:03:46 +01:00
|
|
|
feenableexcept(int __mask)
|
2004-06-06 12:03:59 +02:00
|
|
|
{
|
2005-03-16 20:03:46 +01:00
|
|
|
fenv_t __old_fpsr, __new_fpsr;
|
2004-06-06 12:03:59 +02:00
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__old_fpsr);
|
2014-01-25 19:13:43 +01:00
|
|
|
__new_fpsr = __old_fpsr |
|
|
|
|
((__mask & FE_ALL_EXCEPT) << _FPU_MASK_SHIFT);
|
2013-10-27 11:44:22 +01:00
|
|
|
vmsr_fpscr(__new_fpsr);
|
2014-01-25 19:13:43 +01:00
|
|
|
return ((__old_fpsr >> _FPU_MASK_SHIFT) & FE_ALL_EXCEPT);
|
2005-03-16 20:03:46 +01:00
|
|
|
}
|
|
|
|
|
2014-01-25 19:13:43 +01:00
|
|
|
__fenv_static inline int
|
2005-03-16 20:03:46 +01:00
|
|
|
fedisableexcept(int __mask)
|
|
|
|
{
|
|
|
|
fenv_t __old_fpsr, __new_fpsr;
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__old_fpsr);
|
2014-01-25 19:13:43 +01:00
|
|
|
__new_fpsr = __old_fpsr &
|
|
|
|
~((__mask & FE_ALL_EXCEPT) << _FPU_MASK_SHIFT);
|
2013-10-27 11:44:22 +01:00
|
|
|
vmsr_fpscr(__new_fpsr);
|
2014-01-25 19:13:43 +01:00
|
|
|
return ((__old_fpsr >> _FPU_MASK_SHIFT) & FE_ALL_EXCEPT);
|
2004-06-06 12:03:59 +02:00
|
|
|
}
|
|
|
|
|
2014-01-25 19:13:43 +01:00
|
|
|
__fenv_static inline int
|
2005-03-16 20:03:46 +01:00
|
|
|
fegetexcept(void)
|
2004-06-06 12:03:59 +02:00
|
|
|
{
|
|
|
|
fenv_t __fpsr;
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
vmrs_fpscr(__fpsr);
|
|
|
|
return (__fpsr & FE_ALL_EXCEPT);
|
2004-06-06 12:03:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __BSD_VISIBLE */
|
|
|
|
|
2013-10-27 11:44:22 +01:00
|
|
|
#endif /* __ARM_PCS_VFP */
|
2012-01-16 05:09:17 +01:00
|
|
|
|
2004-06-06 12:03:59 +02:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif /* !_FENV_H_ */
|