Meta: Add OpenLibm

This commit is contained in:
Alec Murphy
2025-04-04 18:16:29 -04:00
parent 4a72f35e9b
commit 172b4ce7a3
724 changed files with 51312 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
#ifndef OPENLIBM_H
#define OPENLIBM_H
#include <openlibm_complex.h>
#include <openlibm_fenv.h>
#include <openlibm_math.h>
#endif /* !OPENLIBM_H */

View File

@@ -0,0 +1,179 @@
/* $OpenBSD: complex.h,v 1.5 2014/03/16 18:38:30 guenther Exp $ */
/*
* Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef OPENLIBM_USE_HOST_COMPLEX_H
#include <complex.h>
#else /* !OPENLIBM_USE_HOST_COMPLEX_H */
#ifndef OPENLIBM_COMPLEX_H
#define OPENLIBM_COMPLEX_H
#define complex _Complex
#define _Complex_I 1.0fi
#define I _Complex_I
/*
* Macros that can be used to construct complex values.
*
* The C99 standard intends x+I*y to be used for this, but x+I*y is
* currently unusable in general since gcc introduces many overflow,
* underflow, sign and efficiency bugs by rewriting I*y as
* (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
* In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
* to -0.0+I*0.0.
*
* In C11, a CMPLX(x,y) macro was added to circumvent this limitation,
* and gcc 4.7 added a __builtin_complex feature to simplify implementation
* of CMPLX in libc, so we can take advantage of these features if they
* are available. Clang simply allows complex values to be constructed
* using a compound literal.
*
* If __builtin_complex is not available, resort to using inline
* functions instead. These can unfortunately not be used to construct
* compile-time constants.
*
* C99 specifies that complex numbers have the same representation as
* an array of two elements, where the first element is the real part
* and the second element is the imaginary part.
*/
#ifdef __clang__
# define CMPLXF(x, y) ((float complex){x, y})
# define CMPLX(x, y) ((double complex){x, y})
# define CMPLXL(x, y) ((long double complex){x, y})
#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__INTEL_COMPILER)
# define CMPLXF(x,y) __builtin_complex ((float) (x), (float) (y))
# define CMPLX(x,y) __builtin_complex ((double) (x), (double) (y))
# define CMPLXL(x,y) __builtin_complex ((long double) (x), (long double) (y))
#else
static inline float complex
CMPLXF(float x, float y)
{
union {
float a[2];
float complex f;
} z = {{ x, y }};
return (z.f);
}
static inline double complex
CMPLX(double x, double y)
{
union {
double a[2];
double complex f;
} z = {{ x, y }};
return (z.f);
}
static inline long double complex
CMPLXL(long double x, long double y)
{
union {
long double a[2];
long double complex f;
} z = {{ x, y }};
return (z.f);
}
#endif
/*
* Double versions of C99 functions
*/
double complex cacos(double complex);
double complex casin(double complex);
double complex catan(double complex);
double complex ccos(double complex);
double complex csin(double complex);
double complex ctan(double complex);
double complex cacosh(double complex);
double complex casinh(double complex);
double complex catanh(double complex);
double complex ccosh(double complex);
double complex csinh(double complex);
double complex ctanh(double complex);
double complex cexp(double complex);
double complex clog(double complex);
double cabs(double complex);
double complex cpow(double complex, double complex);
double complex csqrt(double complex);
double carg(double complex);
double cimag(double complex);
double complex conj(double complex);
double complex cproj(double complex);
double creal(double complex);
/*
* Float versions of C99 functions
*/
float complex cacosf(float complex);
float complex casinf(float complex);
float complex catanf(float complex);
float complex ccosf(float complex);
float complex csinf(float complex);
float complex ctanf(float complex);
float complex cacoshf(float complex);
float complex casinhf(float complex);
float complex catanhf(float complex);
float complex ccoshf(float complex);
float complex csinhf(float complex);
float complex ctanhf(float complex);
float complex cexpf(float complex);
float complex clogf(float complex);
float cabsf(float complex);
float complex cpowf(float complex, float complex);
float complex csqrtf(float complex);
float cargf(float complex);
float cimagf(float complex);
float complex conjf(float complex);
float complex cprojf(float complex);
float crealf(float complex);
/*
* Long double versions of C99 functions
*/
long double complex cacosl(long double complex);
long double complex casinl(long double complex);
long double complex catanl(long double complex);
long double complex ccosl(long double complex);
long double complex csinl(long double complex);
long double complex ctanl(long double complex);
long double complex cacoshl(long double complex);
long double complex casinhl(long double complex);
long double complex catanhl(long double complex);
long double complex ccoshl(long double complex);
long double complex csinhl(long double complex);
long double complex ctanhl(long double complex);
long double complex cexpl(long double complex);
long double complex clogl(long double complex);
long double cabsl(long double complex);
long double complex cpowl(long double complex,
long double complex);
long double complex csqrtl(long double complex);
long double cargl(long double complex);
long double cimagl(long double complex);
long double complex conjl(long double complex);
long double complex cprojl(long double complex);
long double creall(long double complex);
#endif /* !OPENLIBM_COMPLEX_H */
#endif /* OPENLIBM_USE_HOST_COMPLEX_H */

View File

@@ -0,0 +1,14 @@
#ifndef OPENLIBM_DEFS_H_
#define OPENLIBM_DEFS_H_
#ifdef _WIN32
# ifdef IMPORT_EXPORTS
# define OLM_DLLEXPORT __declspec(dllimport)
# else
# define OLM_DLLEXPORT __declspec(dllexport)
# endif
#else
#define OLM_DLLEXPORT __attribute__ ((visibility("default")))
#endif
#endif // OPENLIBM_DEFS_H_

View File

@@ -0,0 +1,27 @@
#ifdef OPENLIBM_USE_HOST_FENV_H
#include <fenv.h>
#else /* !OPENLIBM_USE_HOST_FENV_H */
#if defined(__aarch64__)
#include <openlibm_fenv_aarch64.h>
#elif defined(__arm__)
#include <openlibm_fenv_arm.h>
#elif defined(__x86_64__)
#include <openlibm_fenv_amd64.h>
#elif defined(__i386__)
#include <openlibm_fenv_i387.h>
#elif defined(__powerpc__) || defined(__POWERPC__)
#include <openlibm_fenv_powerpc.h>
#elif defined(__mips__)
#include <openlibm_fenv_mips.h>
#elif defined(__s390__)
#include <openlibm_fenv_s390.h>
#elif defined(__riscv)
#include <openlibm_fenv_riscv.h>
#elif defined(__loongarch64)
#include <openlibm_fenv_loongarch64.h>
#else
#error "Unsupported platform"
#endif
#endif /* OPENLIBM_USE_HOST_FENV_H */

View File

@@ -0,0 +1,247 @@
/*-
* Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
* 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.
*/
#ifndef _FENV_H_
#define _FENV_H_
#include <stdint.h>
#include "cdefs-compat.h"
#ifndef __fenv_static
#define __fenv_static static
#endif
/* The high 32 bits contain fpcr, low 32 contain fpsr. */
typedef __uint64_t fenv_t;
typedef __uint64_t fexcept_t;
/* Exception flags */
#define FE_INVALID 0x00000001
#define FE_DIVBYZERO 0x00000002
#define FE_OVERFLOW 0x00000004
#define FE_UNDERFLOW 0x00000008
#define FE_INEXACT 0x00000010
#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_UPWARD 0x1
#define FE_DOWNWARD 0x2
#define FE_TOWARDZERO 0x3
#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
FE_UPWARD | FE_TOWARDZERO)
#define _ROUND_SHIFT 22
__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 8
#define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT)
#define __mrs_fpcr(__r) __asm __volatile("mrs %0, fpcr" : "=r" (__r))
#define __msr_fpcr(__r) __asm __volatile("msr fpcr, %0" : : "r" (__r))
#define __mrs_fpsr(__r) __asm __volatile("mrs %0, fpsr" : "=r" (__r))
#define __msr_fpsr(__r) __asm __volatile("msr fpsr, %0" : : "r" (__r))
__fenv_static inline int
feclearexcept(int __excepts)
{
fexcept_t __r;
__mrs_fpsr(__r);
__r &= ~__excepts;
__msr_fpsr(__r);
return (0);
}
__fenv_static inline int
fegetexceptflag(fexcept_t *__flagp, int __excepts)
{
fexcept_t __r;
__mrs_fpsr(__r);
*__flagp = __r & __excepts;
return (0);
}
__fenv_static inline int
fesetexceptflag(const fexcept_t *__flagp, int __excepts)
{
fexcept_t __r;
__mrs_fpsr(__r);
__r &= ~__excepts;
__r |= *__flagp & __excepts;
__msr_fpsr(__r);
return (0);
}
__fenv_static inline int
feraiseexcept(int __excepts)
{
fexcept_t __r;
__mrs_fpsr(__r);
__r |= __excepts;
__msr_fpsr(__r);
return (0);
}
__fenv_static inline int
fetestexcept(int __excepts)
{
fexcept_t __r;
__mrs_fpsr(__r);
return (__r & __excepts);
}
__fenv_static inline int
fegetround(void)
{
fenv_t __r;
__mrs_fpcr(__r);
return ((__r >> _ROUND_SHIFT) & _ROUND_MASK);
}
__fenv_static inline int
fesetround(int __round)
{
fenv_t __r;
if (__round & ~_ROUND_MASK)
return (-1);
__mrs_fpcr(__r);
__r &= ~(_ROUND_MASK << _ROUND_SHIFT);
__r |= __round << _ROUND_SHIFT;
__msr_fpcr(__r);
return (0);
}
__fenv_static inline int
fegetenv(fenv_t *__envp)
{
__uint64_t fpcr;
__uint64_t fpsr;
__mrs_fpcr(fpcr);
__mrs_fpsr(fpsr);
*__envp = fpsr | (fpcr << 32);
return (0);
}
__fenv_static inline int
feholdexcept(fenv_t *__envp)
{
fenv_t __r;
__mrs_fpcr(__r);
*__envp = __r << 32;
__r &= ~(_ENABLE_MASK);
__msr_fpcr(__r);
__mrs_fpsr(__r);
*__envp |= (__uint32_t)__r;
__r &= ~(_ENABLE_MASK);
__msr_fpsr(__r);
return (0);
}
__fenv_static inline int
fesetenv(const fenv_t *__envp)
{
__msr_fpcr((*__envp) >> 32);
__msr_fpsr((fenv_t)(__uint32_t)*__envp);
return (0);
}
__fenv_static inline int
feupdateenv(const fenv_t *__envp)
{
fexcept_t __r;
__mrs_fpsr(__r);
fesetenv(__envp);
feraiseexcept(__r & FE_ALL_EXCEPT);
return (0);
}
#if __BSD_VISIBLE
/* We currently provide no external definitions of the functions below. */
static inline int
feenableexcept(int __mask)
{
fenv_t __old_r, __new_r;
__mrs_fpcr(__old_r);
__new_r = __old_r | ((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT);
__msr_fpcr(__new_r);
return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
}
static inline int
fedisableexcept(int __mask)
{
fenv_t __old_r, __new_r;
__mrs_fpcr(__old_r);
__new_r = __old_r & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT);
__msr_fpcr(__new_r);
return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
}
static inline int
fegetexcept(void)
{
fenv_t __r;
__mrs_fpcr(__r);
return ((__r & _ENABLE_MASK) >> _FPUSW_SHIFT);
}
#endif /* __BSD_VISIBLE */
__END_DECLS
#endif /* !_FENV_H_ */

View File

@@ -0,0 +1,223 @@
/*-
* Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
* 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: src/lib/msun/amd64/fenv.h,v 1.8 2011/10/10 15:43:09 das Exp $
*/
#ifndef _FENV_H_
#define _FENV_H_
#include <openlibm_defs.h>
#include "cdefs-compat.h"
#include "types-compat.h"
#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)))
__fenv_static __attribute__((always_inline)) 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);
}
__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);
}
OLM_DLLEXPORT int fesetexceptflag(const fexcept_t *__flagp, int __excepts);
OLM_DLLEXPORT int feraiseexcept(int __excepts);
__fenv_static __attribute__((always_inline)) inline int
fetestexcept(int __excepts)
{
uint32_t __mxcsr;
uint16_t __status;
__stmxcsr(&__mxcsr);
__fnstsw(&__status);
return ((__status | __mxcsr) & __excepts);
}
__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);
}
__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);
}
OLM_DLLEXPORT int fegetenv(fenv_t *__envp);
OLM_DLLEXPORT int feholdexcept(fenv_t *__envp);
__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);
}
OLM_DLLEXPORT int feupdateenv(const fenv_t *__envp);
#if __BSD_VISIBLE
OLM_DLLEXPORT int feenableexcept(int __mask);
OLM_DLLEXPORT int fedisableexcept(int __mask);
/* 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_ */

View File

@@ -0,0 +1,227 @@
/*-
* Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
* 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: src/lib/msun/arm/fenv.h,v 1.6 2011/10/10 15:43:09 das Exp $
*/
#ifndef _FENV_H_
#define _FENV_H_
#include <stdint.h>
#include "cdefs-compat.h"
#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)
/* Test for hardware support for ARM floating point operations, explicitly
checking for float and double support, see "ARM C Language Extensions", 6.5.1 */
#if defined(__ARM_FP) && (__ARM_FP & 0x0C) != 0
#define __rfs(__fpsr) __asm __volatile("vmrs %0,fpscr" : "=&r" (*(__fpsr)))
#define __wfs(__fpsr) __asm __volatile("vmsr fpscr,%0" : : "r" (__fpsr))
#else
#define __rfs(__fpsr) (*(__fpsr) = 0)
#define __wfs(__fpsr)
#endif
__fenv_static inline int
feclearexcept(int __excepts)
{
fexcept_t __fpsr;
__rfs(&__fpsr);
__fpsr &= ~__excepts;
__wfs(__fpsr);
return (0);
}
__fenv_static inline int
fegetexceptflag(fexcept_t *__flagp, int __excepts)
{
fexcept_t __fpsr;
__rfs(&__fpsr);
*__flagp = __fpsr & __excepts;
return (0);
}
__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);
}
__fenv_static inline int
feraiseexcept(int __excepts)
{
fexcept_t __ex = __excepts;
fesetexceptflag(&__ex, __excepts); /* XXX */
return (0);
}
__fenv_static inline int
fetestexcept(int __excepts)
{
fexcept_t __fpsr;
__rfs(&__fpsr);
return (__fpsr & __excepts);
}
__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);
}
__fenv_static inline int
fesetround(int __round)
{
return (-1);
}
__fenv_static inline int
fegetenv(fenv_t *__envp)
{
__rfs(__envp);
return (0);
}
__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);
}
__fenv_static inline int
fesetenv(const fenv_t *__envp)
{
__wfs(*__envp);
return (0);
}
__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
/* 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
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
fegetexcept(void)
{
fenv_t __fpsr;
__rfs(&__fpsr);
return ((__fpsr & _ENABLE_MASK) >> _FPUSW_SHIFT);
}
#endif /* __BSD_VISIBLE */
__END_DECLS
#endif /* !_FENV_H_ */

View File

@@ -0,0 +1,260 @@
/*-
* Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
* 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: src/lib/msun/i387/fenv.h,v 1.8 2011/10/10 15:43:09 das Exp $
*/
#ifndef _FENV_H_
#define _FENV_H_
#include "openlibm_defs.h"
#include "cdefs-compat.h"
#include "types-compat.h"
#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 };
OLM_DLLEXPORT extern enum __sse_support __has_sse;
OLM_DLLEXPORT 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 */
OLM_DLLEXPORT 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)))
__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);
}
__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);
}
OLM_DLLEXPORT int fesetexceptflag(const fexcept_t *__flagp, int __excepts);
OLM_DLLEXPORT int feraiseexcept(int __excepts);
__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);
}
__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);
}
__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);
}
OLM_DLLEXPORT int fegetenv(fenv_t *__envp);
OLM_DLLEXPORT int feholdexcept(fenv_t *__envp);
__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);
}
OLM_DLLEXPORT int feupdateenv(const fenv_t *__envp);
#if __BSD_VISIBLE
OLM_DLLEXPORT int feenableexcept(int __mask);
OLM_DLLEXPORT int fedisableexcept(int __mask);
/* 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_ */

View File

@@ -0,0 +1,226 @@
/*-
* Copyright (c) 2023 Yifan An <me@anyi.fan>
* 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.
*/
#ifndef _FENV_H_
#define _FENV_H_
#include <stdint.h>
#include "cdefs-compat.h"
#ifndef __fenv_static
#define __fenv_static static
#endif
typedef uint32_t fenv_t;
typedef uint32_t fexcept_t;
/* Exception flags */
#define FE_INVALID 0x100000
#define FE_DIVBYZERO 0x080000
#define FE_OVERFLOW 0x040000
#define FE_UNDERFLOW 0x020000
#define FE_INEXACT 0x010000
#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
/* Rounding modes */
#define FE_TONEAREST 0x0000
#define FE_TOWARDZERO 0x0100
#define FE_DOWNWARD 0x0200
#define FE_UPWARD 0x0300
#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 _FPU_MASK_V 0x10
#define _FPU_MASK_Z 0x08
#define _FPU_MASK_O 0x04
#define _FPU_MASK_U 0x02
#define _FPU_MASK_I 0x01
#define _FPUSW_SHIFT 16
#define _ENABLE_MASK (_FPU_MASK_V | _FPU_MASK_Z | _FPU_MASK_O | _FPU_MASK_U | _FPU_MASK_I)
#define __rfs(__fpsr) __asm __volatile("movfcsr2gr %0,$r0" : "=r"(__fpsr))
#define __wfs(__fpsr) __asm __volatile("movgr2fcsr $r0,%0" : : "r"(__fpsr))
__fenv_static inline int
feclearexcept(int __excepts)
{
fexcept_t __fpsr;
__rfs(__fpsr);
__fpsr &= ~__excepts;
__wfs(__fpsr);
return (0);
}
__fenv_static inline int
fegetexceptflag(fexcept_t *__flagp, int __excepts)
{
fexcept_t __fpsr;
__rfs(__fpsr);
*__flagp = __fpsr & __excepts;
return (0);
}
__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);
}
__fenv_static inline int
feraiseexcept(int __excepts)
{
fexcept_t __ex = __excepts;
fesetexceptflag(&__ex, __excepts); /* XXX */
return (0);
}
__fenv_static inline int
fetestexcept(int __excepts)
{
fexcept_t __fpsr;
__rfs(__fpsr);
return (__fpsr & __excepts);
}
__fenv_static inline int
fegetround(void)
{
fexcept_t __fpsr;
__rfs(__fpsr);
return __fpsr & _ROUND_MASK;
}
__fenv_static inline int
fesetround(int __round)
{
fexcept_t __fpsr;
if ((__round & ~_ROUND_MASK) != 0)
return 1;
__rfs(__fpsr);
__fpsr &= ~_ROUND_MASK;
__fpsr |= __round;
__wfs(__fpsr);
return (0);
}
__fenv_static inline int
fegetenv(fenv_t *__envp)
{
__rfs(*__envp);
return (0);
}
__fenv_static inline int
feholdexcept(fenv_t *__envp)
{
fenv_t __env;
__rfs(__env);
*__envp = __env;
__env &= ~(FE_ALL_EXCEPT | _FPU_MASK_V | _FPU_MASK_Z | _FPU_MASK_O | _FPU_MASK_U | _FPU_MASK_I);
__wfs(__env);
return (0);
}
__fenv_static inline int
fesetenv(const fenv_t *__envp)
{
__wfs(*__envp);
return (0);
}
__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
feenableexcept(int __mask)
{
fenv_t __old_fpsr, __new_fpsr;
__rfs(__new_fpsr);
__old_fpsr = (__new_fpsr & _ENABLE_MASK) << _FPUSW_SHIFT;
__new_fpsr |= (__mask & FE_ALL_EXCEPT) >> _FPUSW_SHIFT;
__wfs(__new_fpsr);
return __old_fpsr;
}
static inline int
fedisableexcept(int __mask)
{
fenv_t __old_fpsr, __new_fpsr;
__rfs(__new_fpsr);
__old_fpsr = (__new_fpsr & _ENABLE_MASK) << _FPUSW_SHIFT;
__new_fpsr &= ~((__mask & FE_ALL_EXCEPT) >> _FPUSW_SHIFT);
__wfs(__new_fpsr);
return __old_fpsr;
}
static inline int
fegetexcept(void)
{
fenv_t __fpsr;
__rfs(__fpsr);
return ((__fpsr & _ENABLE_MASK) << _FPUSW_SHIFT);
}
#endif /* __BSD_VISIBLE */
__END_DECLS
#endif /* !_FENV_H_ */

View File

@@ -0,0 +1,278 @@
/*-
* Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
* 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 <stdint.h>
#include "cdefs-compat.h"
#ifndef __fenv_static
#define __fenv_static static
#endif
typedef uint32_t fenv_t;
typedef uint32_t fexcept_t;
/* Exception flags */
#ifdef __mips_soft_float
#define _FPUSW_SHIFT 16
#define FE_INVALID 0x0001
#define FE_DIVBYZERO 0x0002
#define FE_OVERFLOW 0x0004
#define FE_UNDERFLOW 0x0008
#define FE_INEXACT 0x0010
#else
#define _FCSR_CAUSE_SHIFT 10
#define FE_INVALID 0x0040
#define FE_DIVBYZERO 0x0020
#define FE_OVERFLOW 0x0010
#define FE_UNDERFLOW 0x0008
#define FE_INEXACT 0x0004
#endif
#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 _ENABLE_SHIFT 5
#define _ENABLE_MASK (FE_ALL_EXCEPT << _ENABLE_SHIFT)
#ifndef __mips_soft_float
#define __cfc1(__fcsr) __asm __volatile("cfc1 %0, $31" : "=r" (__fcsr))
#define __ctc1(__fcsr) __asm __volatile("ctc1 %0, $31" :: "r" (__fcsr))
#endif
#ifdef __mips_soft_float
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);
#else
__fenv_static inline int
feclearexcept(int __excepts)
{
fexcept_t fcsr;
__excepts &= FE_ALL_EXCEPT;
__cfc1(fcsr);
fcsr &= ~(__excepts | (__excepts << _FCSR_CAUSE_SHIFT));
__ctc1(fcsr);
return (0);
}
__fenv_static inline int
fegetexceptflag(fexcept_t *__flagp, int __excepts)
{
fexcept_t fcsr;
__excepts &= FE_ALL_EXCEPT;
__cfc1(fcsr);
*__flagp = fcsr & __excepts;
return (0);
}
__fenv_static inline int
fesetexceptflag(const fexcept_t *__flagp, int __excepts)
{
fexcept_t fcsr;
__excepts &= FE_ALL_EXCEPT;
__cfc1(fcsr);
fcsr &= ~__excepts;
fcsr |= *__flagp & __excepts;
__ctc1(fcsr);
return (0);
}
__fenv_static inline int
feraiseexcept(int __excepts)
{
fexcept_t fcsr;
__excepts &= FE_ALL_EXCEPT;
__cfc1(fcsr);
fcsr |= __excepts | (__excepts << _FCSR_CAUSE_SHIFT);
__ctc1(fcsr);
return (0);
}
__fenv_static inline int
fetestexcept(int __excepts)
{
fexcept_t fcsr;
__excepts &= FE_ALL_EXCEPT;
__cfc1(fcsr);
return (fcsr & __excepts);
}
__fenv_static inline int
fegetround(void)
{
fexcept_t fcsr;
__cfc1(fcsr);
return (fcsr & _ROUND_MASK);
}
__fenv_static inline int
fesetround(int __round)
{
fexcept_t fcsr;
if (__round & ~_ROUND_MASK)
return (-1);
__cfc1(fcsr);
fcsr &= ~_ROUND_MASK;
fcsr |= __round;
__ctc1(fcsr);
return (0);
}
__fenv_static inline int
fegetenv(fenv_t *__envp)
{
__cfc1(*__envp);
return (0);
}
__fenv_static inline int
feholdexcept(fenv_t *__envp)
{
fexcept_t fcsr;
__cfc1(fcsr);
*__envp = fcsr;
fcsr &= ~(FE_ALL_EXCEPT | _ENABLE_MASK);
__ctc1(fcsr);
return (0);
}
__fenv_static inline int
fesetenv(const fenv_t *__envp)
{
__ctc1(*__envp);
return (0);
}
__fenv_static inline int
feupdateenv(const fenv_t *__envp)
{
fexcept_t fcsr;
__cfc1(fcsr);
fesetenv(__envp);
feraiseexcept(fcsr);
return (0);
}
#endif /* !__mips_soft_float */
#if __BSD_VISIBLE
/* We currently provide no external definitions of the functions below. */
#ifdef __mips_soft_float
int feenableexcept(int __mask);
int fedisableexcept(int __mask);
int fegetexcept(void);
#else
static inline int
feenableexcept(int __mask)
{
fenv_t __old_fcsr, __new_fcsr;
__cfc1(__old_fcsr);
__new_fcsr = __old_fcsr | (__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT;
__ctc1(__new_fcsr);
return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT);
}
static inline int
fedisableexcept(int __mask)
{
fenv_t __old_fcsr, __new_fcsr;
__cfc1(__old_fcsr);
__new_fcsr = __old_fcsr & ~((__mask & FE_ALL_EXCEPT) << _ENABLE_SHIFT);
__ctc1(__new_fcsr);
return ((__old_fcsr >> _ENABLE_SHIFT) & FE_ALL_EXCEPT);
}
static inline int
fegetexcept(void)
{
fexcept_t fcsr;
__cfc1(fcsr);
return ((fcsr & _ENABLE_MASK) >> _ENABLE_SHIFT);
}
#endif /* !__mips_soft_float */
#endif /* __BSD_VISIBLE */
__END_DECLS
#endif /* !_FENV_H_ */

View File

@@ -0,0 +1,279 @@
/*-
* Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
* 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>
#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 {
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
fenv_t __reg;
__uint32_t __junk;
#else
__uint32_t __junk;
fenv_t __reg;
#endif
} __bits;
};
__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);
}
__fenv_static inline int
fegetexceptflag(fexcept_t *__flagp, int __excepts)
{
union __fpscr __r;
__mffs(&__r.__d);
*__flagp = __r.__bits.__reg & __excepts;
return (0);
}
__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);
}
__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);
}
__fenv_static inline int
fetestexcept(int __excepts)
{
union __fpscr __r;
__mffs(&__r.__d);
return (__r.__bits.__reg & __excepts);
}
__fenv_static inline int
fegetround(void)
{
union __fpscr __r;
__mffs(&__r.__d);
return (__r.__bits.__reg & _ROUND_MASK);
}
__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);
}
__fenv_static inline int
fegetenv(fenv_t *__envp)
{
union __fpscr __r;
__mffs(&__r.__d);
*__envp = __r.__bits.__reg;
return (0);
}
__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);
}
__fenv_static inline int
fesetenv(const fenv_t *__envp)
{
union __fpscr __r;
__r.__bits.__reg = *__envp;
__mtfsf(__r.__d);
return (0);
}
__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
/* 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
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
fegetexcept(void)
{
union __fpscr __r;
__mffs(&__r.__d);
return ((__r.__bits.__reg & _ENABLE_MASK) << _FPUSW_SHIFT);
}
#endif /* __BSD_VISIBLE */
__END_DECLS
#endif /* !_FENV_H_ */

View File

@@ -0,0 +1,261 @@
/*-
* Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
* Copyright (c) 2015-2016 Ruslan Bukin <br@bsdpad.com>
* All rights reserved.
*
* Portions of this software were developed by SRI International and the
* University of Cambridge Computer Laboratory under DARPA/AFRL contract
* FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
*
* Portions of this software were developed by the University of Cambridge
* Computer Laboratory as part of the CTSRD Project, with support from the
* UK Higher Education Innovation Fund (HEIF).
*
* 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: head/lib/msun/riscv/fenv.h 332792 2018-04-19 20:36:15Z brooks $
*/
#ifndef _FENV_H_
#define _FENV_H_
#include <stdint.h>
#include "cdefs-compat.h"
#ifndef __fenv_static
#define __fenv_static static
#endif
typedef uint64_t fenv_t;
typedef uint64_t fexcept_t;
/* Exception flags */
#define FE_INVALID 0x0010
#define FE_DIVBYZERO 0x0008
#define FE_OVERFLOW 0x0004
#define FE_UNDERFLOW 0x0002
#define FE_INEXACT 0x0001
#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
/*
* RISC-V Rounding modes
*/
#define _ROUND_SHIFT 5
#define FE_TONEAREST (0x00 << _ROUND_SHIFT)
#define FE_TOWARDZERO (0x01 << _ROUND_SHIFT)
#define FE_DOWNWARD (0x02 << _ROUND_SHIFT)
#define FE_UPWARD (0x03 << _ROUND_SHIFT)
#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)
#if !defined(__riscv_float_abi_soft) && !defined(__riscv_float_abi_double)
#if defined(__riscv_float_abi_single)
#error single precision floating point ABI not supported
#else
#error compiler did not set soft/hard float macros
#endif
#endif
#ifndef __riscv_float_abi_soft
#define __rfs(__fcsr) __asm __volatile("csrr %0, fcsr" : "=r" (__fcsr))
#define __wfs(__fcsr) __asm __volatile("csrw fcsr, %0" :: "r" (__fcsr))
#endif
#ifdef __riscv_float_abi_soft
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);
#else
__fenv_static inline int
feclearexcept(int __excepts)
{
__asm __volatile("csrc fflags, %0" :: "r"(__excepts));
return (0);
}
__fenv_static inline int
fegetexceptflag(fexcept_t *__flagp, int __excepts)
{
fexcept_t __fcsr;
__rfs(__fcsr);
*__flagp = __fcsr & __excepts;
return (0);
}
__fenv_static inline int
fesetexceptflag(const fexcept_t *__flagp, int __excepts)
{
fexcept_t __fcsr;
__fcsr = *__flagp;
__asm __volatile("csrc fflags, %0" :: "r"(__excepts));
__asm __volatile("csrs fflags, %0" :: "r"(__fcsr & __excepts));
return (0);
}
__fenv_static inline int
feraiseexcept(int __excepts)
{
__asm __volatile("csrs fflags, %0" :: "r"(__excepts));
return (0);
}
__fenv_static inline int
fetestexcept(int __excepts)
{
fexcept_t __fcsr;
__rfs(__fcsr);
return (__fcsr & __excepts);
}
__fenv_static inline int
fegetround(void)
{
fexcept_t __fcsr;
__rfs(__fcsr);
return (__fcsr & _ROUND_MASK);
}
__fenv_static inline int
fesetround(int __round)
{
fexcept_t __fcsr;
if (__round & ~_ROUND_MASK)
return (-1);
__rfs(__fcsr);
__fcsr &= ~_ROUND_MASK;
__fcsr |= __round;
__wfs(__fcsr);
return (0);
}
__fenv_static inline int
fegetenv(fenv_t *__envp)
{
__rfs(*__envp);
return (0);
}
__fenv_static inline int
feholdexcept(fenv_t *__envp)
{
/* No exception traps. */
return (-1);
}
__fenv_static inline int
fesetenv(const fenv_t *__envp)
{
__wfs(*__envp);
return (0);
}
__fenv_static inline int
feupdateenv(const fenv_t *__envp)
{
fexcept_t __fcsr;
__rfs(__fcsr);
__wfs(*__envp);
feraiseexcept(__fcsr & FE_ALL_EXCEPT);
return (0);
}
#endif /* !__riscv_float_abi_soft */
#if __BSD_VISIBLE
/* We currently provide no external definitions of the functions below. */
#ifdef __riscv_float_abi_soft
int feenableexcept(int __mask);
int fedisableexcept(int __mask);
int fegetexcept(void);
#else
static inline int
feenableexcept(int __mask)
{
/* No exception traps. */
return (-1);
}
static inline int
fedisableexcept(int __mask)
{
/* No exception traps. */
return (0);
}
static inline int
fegetexcept(void)
{
/* No exception traps. */
return (0);
}
#endif /* !__riscv_float_abi_soft */
#endif /* __BSD_VISIBLE */
__END_DECLS
#endif /* !_FENV_H_ */

View File

@@ -0,0 +1,235 @@
/*-
* Copyright (c) 2016 Dan Horák <dan[at]danny.cz>
* 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>
#ifndef __fenv_static
#define __fenv_static static
#endif
typedef __uint32_t fenv_t;
typedef __uint32_t fexcept_t;
/* Exception flags */
#define FE_INEXACT 0x080000
#define FE_UNDERFLOW 0x100000
#define FE_OVERFLOW 0x200000
#define FE_DIVBYZERO 0x400000
#define FE_INVALID 0x800000 /* all types of invalid FP ops */
#define FE_ALL_EXCEPT (FE_INVALID | FE_DIVBYZERO | FE_INEXACT | 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 _FPC_EXC_MASK_SHIFT 8
#define _ENABLE_MASK ((FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
FE_OVERFLOW | FE_UNDERFLOW) << _FPC_EXC_MASK_SHIFT)
/* Macros for accessing the hardware control word. */
#define _FPU_GETCW(cw) __asm__ __volatile__ ("efpc %0,0" : "=d" (cw))
#define _FPU_SETCW(cw) __asm__ __volatile__ ("sfpc %0,0" : : "d" (cw))
__fenv_static inline int
feclearexcept(int __excepts)
{
fexcept_t __r;
if (__excepts & FE_INVALID)
__excepts |= FE_ALL_EXCEPT;
_FPU_GETCW(__r);
__r &= ~__excepts;
_FPU_SETCW(__r);
return (0);
}
__fenv_static inline int
fegetexceptflag(fexcept_t *__flagp, int __excepts)
{
fexcept_t __r;
_FPU_GETCW(__r);
*__flagp = __r & __excepts;
return (0);
}
__fenv_static inline int
fesetexceptflag(const fexcept_t *__flagp, int __excepts)
{
fexcept_t __r;
if (__excepts & FE_INVALID)
__excepts |= FE_ALL_EXCEPT;
_FPU_GETCW(__r);
__r &= ~__excepts;
__r |= *__flagp & __excepts;
_FPU_SETCW(__r);
return (0);
}
__fenv_static inline int
feraiseexcept(int __excepts)
{
fexcept_t __r;
_FPU_GETCW(__r);
__r |= __excepts;
_FPU_SETCW(__r);
return (0);
}
__fenv_static inline int
fetestexcept(int __excepts)
{
fexcept_t __r;
_FPU_GETCW(__r);
return (__r & __excepts);
}
__fenv_static inline int
fegetround(void)
{
fexcept_t __r;
_FPU_GETCW(__r);
return (__r & _ROUND_MASK);
}
__fenv_static inline int
fesetround(int __round)
{
fexcept_t __r;
if (__round & ~_ROUND_MASK)
return (-1);
_FPU_GETCW(__r);
__r &= ~_ROUND_MASK;
__r |= __round;
_FPU_SETCW(__r);
return (0);
}
__fenv_static inline int
fegetenv(fenv_t *__envp)
{
_FPU_GETCW(*__envp);
return (0);
}
__fenv_static inline int
feholdexcept(fenv_t *__envp)
{
fexcept_t __r;
_FPU_GETCW(__r);
*__envp = __r;
__r &= ~(FE_ALL_EXCEPT | _ENABLE_MASK);
_FPU_SETCW(__r);
return (0);
}
__fenv_static inline int
fesetenv(const fenv_t *__envp)
{
_FPU_SETCW(*__envp);
return (0);
}
__fenv_static inline int
feupdateenv(const fenv_t *__envp)
{
fexcept_t __r;
_FPU_GETCW(__r);
__r &= FE_ALL_EXCEPT;
__r |= *__envp;
_FPU_SETCW(__r);
return (0);
}
#if __BSD_VISIBLE
/* We currently provide no external definitions of the functions below. */
static inline int
feenableexcept(int __mask)
{
fenv_t __r;
fenv_t __oldmask;
_FPU_GETCW(__r);
__oldmask = __r;
__r |= (__mask & FE_ALL_EXCEPT) << _FPC_EXC_MASK_SHIFT;
_FPU_SETCW(__r);
return ((__oldmask & _ENABLE_MASK) >> _FPC_EXC_MASK_SHIFT);
}
static inline int
fedisableexcept(int __mask)
{
fenv_t __r;
fenv_t __oldmask;
_FPU_GETCW(__r);
__oldmask = __r;
__r &= ~((__mask & FE_ALL_EXCEPT) << _FPC_EXC_MASK_SHIFT);
_FPU_SETCW(__r);
return ((__oldmask & _ENABLE_MASK) >> _FPC_EXC_MASK_SHIFT);
}
static inline int
fegetexcept(void)
{
fexcept_t __r;
_FPU_GETCW(__r);
return (__r & (_ENABLE_MASK >> _FPC_EXC_MASK_SHIFT));
}
#endif /* __BSD_VISIBLE */
__END_DECLS
#endif /* !_FENV_H_ */

View File

@@ -0,0 +1,493 @@
/*
* ====================================================
* 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
* $FreeBSD: src/lib/msun/src/openlibm.h,v 1.82 2011/11/12 19:55:48 theraven Exp $
*/
#ifdef OPENLIBM_USE_HOST_MATH_H
#include <math.h>
#else /* !OPENLIBM_USE_HOST_MATH_H */
#include <openlibm_defs.h>
#ifndef OPENLIBM_MATH_H
#define OPENLIBM_MATH_H
#if (defined(_WIN32) || defined (_MSC_VER)) && !defined(__WIN32__)
#define __WIN32__
#endif
#if !defined(__arm__) && !defined(__wasm__)
#define OLM_LONG_DOUBLE
#endif
#ifndef __pure2
#define __pure2
#endif
/*
* ANSI/POSIX
*/
extern const union __infinity_un {
unsigned char __uc[8];
double __ud;
} __infinity;
extern const union __nan_un {
unsigned char __uc[sizeof(float)];
float __uf;
} __nan;
/* VBS
#if __GNUC_PREREQ__(3, 3) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
#define __MATH_BUILTIN_CONSTANTS
#endif
#if __GNUC_PREREQ__(3, 0) && !defined(__INTEL_COMPILER)
#define __MATH_BUILTIN_RELOPS
#endif
*/
//VBS begin
#define __MATH_BUILTIN_CONSTANTS
#define __MATH_BUILTIN_RELOPS
#ifndef __ISO_C_VISIBLE
#define __ISO_C_VISIBLE 1999
#endif
//VBS end
#ifdef __MATH_BUILTIN_CONSTANTS
#define HUGE_VAL __builtin_huge_val()
#else
#define HUGE_VAL (__infinity.__ud)
#endif
#if __ISO_C_VISIBLE >= 1999
#define FP_ILOGB0 (-INT_MAX)
#define FP_ILOGBNAN INT_MAX
#ifdef __MATH_BUILTIN_CONSTANTS
#define HUGE_VALF __builtin_huge_valf()
#define HUGE_VALL __builtin_huge_vall()
#define INFINITY __builtin_inff()
#define NAN __builtin_nanf("")
#else
#define HUGE_VALF (float)HUGE_VAL
#define HUGE_VALL (long double)HUGE_VAL
#define INFINITY HUGE_VALF
#define NAN (__nan.__uf)
#endif /* __MATH_BUILTIN_CONSTANTS */
#define MATH_ERRNO 1
#define MATH_ERREXCEPT 2
#define math_errhandling MATH_ERREXCEPT
#define FP_FAST_FMAF 1
#ifdef __ia64__
#define FP_FAST_FMA 1
#define FP_FAST_FMAL 1
#endif
/* Symbolic constants to classify floating point numbers. */
#define FP_INFINITE 0x01
#define FP_NAN 0x02
#define FP_NORMAL 0x04
#define FP_SUBNORMAL 0x08
#define FP_ZERO 0x10
#define fpclassify(x) \
((sizeof (x) == sizeof (float)) ? __fpclassifyf(x) \
: (sizeof (x) == sizeof (double)) ? __fpclassifyd(x) \
: __fpclassifyl(x))
#define isfinite(x) \
((sizeof (x) == sizeof (float)) ? __isfinitef(x) \
: (sizeof (x) == sizeof (double)) ? __isfinite(x) \
: __isfinitel(x))
#define isinf(x) \
((sizeof (x) == sizeof (float)) ? __isinff(x) \
: (sizeof (x) == sizeof (double)) ? isinf(x) \
: __isinfl(x))
#define isnan(x) \
((sizeof (x) == sizeof (float)) ? __isnanf(x) \
: (sizeof (x) == sizeof (double)) ? isnan(x) \
: __isnanl(x))
#define isnormal(x) \
((sizeof (x) == sizeof (float)) ? __isnormalf(x) \
: (sizeof (x) == sizeof (double)) ? __isnormal(x) \
: __isnormall(x))
#ifdef __MATH_BUILTIN_RELOPS
#define isgreater(x, y) __builtin_isgreater((x), (y))
#define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
#define isless(x, y) __builtin_isless((x), (y))
#define islessequal(x, y) __builtin_islessequal((x), (y))
#define islessgreater(x, y) __builtin_islessgreater((x), (y))
#define isunordered(x, y) __builtin_isunordered((x), (y))
#else
#define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
#define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
#define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
#define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
#define islessgreater(x, y) (!isunordered((x), (y)) && \
((x) > (y) || (y) > (x)))
#define isunordered(x, y) (isnan(x) || isnan(y))
#endif /* __MATH_BUILTIN_RELOPS */
#define signbit(x) \
((sizeof (x) == sizeof (float)) ? __signbitf(x) \
: (sizeof (x) == sizeof (double)) ? __signbit(x) \
: __signbitl(x))
//VBS
//typedef __double_t double_t;
//typedef __float_t float_t;
#endif /* __ISO_C_VISIBLE >= 1999 */
/*
* XOPEN/SVID
*/
#if __BSD_VISIBLE || __XSI_VISIBLE
#define M_E 2.7182818284590452354 /* e */
#define M_LOG2E 1.4426950408889634074 /* log 2e */
#define M_LOG10E 0.43429448190325182765 /* log 10e */
#define M_LN2 0.69314718055994530942 /* log e2 */
#define M_LN10 2.30258509299404568402 /* log e10 */
#define M_PI 3.14159265358979323846 /* pi */
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#define M_PI_4 0.78539816339744830962 /* pi/4 */
#define M_1_PI 0.31830988618379067154 /* 1/pi */
#define M_2_PI 0.63661977236758134308 /* 2/pi */
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
#define MAXFLOAT ((float)3.40282346638528860e+38)
#ifndef OPENLIBM_ONLY_THREAD_SAFE
OLM_DLLEXPORT extern int signgam;
#endif
#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
#if __BSD_VISIBLE
#if 0
/* Old value from 4.4BSD-Lite openlibm.h; this is probably better. */
#define HUGE HUGE_VAL
#else
#define HUGE MAXFLOAT
#endif
#endif /* __BSD_VISIBLE */
/*
* Most of these functions depend on the rounding mode and have the side
* effect of raising floating-point exceptions, so they are not declared
* as __pure2. In C99, FENV_ACCESS affects the purity of these functions.
*/
#if defined(__cplusplus)
extern "C" {
#endif
/* Symbol present when OpenLibm is used. */
int isopenlibm(void);
/*
* ANSI/POSIX
*/
OLM_DLLEXPORT int __fpclassifyd(double) __pure2;
OLM_DLLEXPORT int __fpclassifyf(float) __pure2;
OLM_DLLEXPORT int __fpclassifyl(long double) __pure2;
OLM_DLLEXPORT int __isfinitef(float) __pure2;
OLM_DLLEXPORT int __isfinite(double) __pure2;
OLM_DLLEXPORT int __isfinitel(long double) __pure2;
OLM_DLLEXPORT int __isinff(float) __pure2;
OLM_DLLEXPORT int __isinfl(long double) __pure2;
OLM_DLLEXPORT int __isnanf(float) __pure2;
OLM_DLLEXPORT int __isnanl(long double) __pure2;
OLM_DLLEXPORT int __isnormalf(float) __pure2;
OLM_DLLEXPORT int __isnormal(double) __pure2;
OLM_DLLEXPORT int __isnormall(long double) __pure2;
OLM_DLLEXPORT int __signbit(double) __pure2;
OLM_DLLEXPORT int __signbitf(float) __pure2;
OLM_DLLEXPORT int __signbitl(long double) __pure2;
OLM_DLLEXPORT double acos(double);
OLM_DLLEXPORT double asin(double);
OLM_DLLEXPORT double atan(double);
OLM_DLLEXPORT double atan2(double, double);
OLM_DLLEXPORT double cos(double);
OLM_DLLEXPORT double sin(double);
OLM_DLLEXPORT double tan(double);
OLM_DLLEXPORT double cosh(double);
OLM_DLLEXPORT double sinh(double);
OLM_DLLEXPORT double tanh(double);
OLM_DLLEXPORT double exp(double);
OLM_DLLEXPORT double frexp(double, int *); /* fundamentally !__pure2 */
OLM_DLLEXPORT double ldexp(double, int);
OLM_DLLEXPORT double log(double);
OLM_DLLEXPORT double log10(double);
OLM_DLLEXPORT double modf(double, double *); /* fundamentally !__pure2 */
OLM_DLLEXPORT double pow(double, double);
OLM_DLLEXPORT double sqrt(double);
OLM_DLLEXPORT double ceil(double);
OLM_DLLEXPORT double fabs(double) __pure2;
OLM_DLLEXPORT double floor(double);
OLM_DLLEXPORT double fmod(double, double);
/*
* These functions are not in C90.
*/
#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE
OLM_DLLEXPORT double acosh(double);
OLM_DLLEXPORT double asinh(double);
OLM_DLLEXPORT double atanh(double);
OLM_DLLEXPORT double cbrt(double);
OLM_DLLEXPORT double erf(double);
OLM_DLLEXPORT double erfc(double);
OLM_DLLEXPORT double exp2(double);
OLM_DLLEXPORT double expm1(double);
OLM_DLLEXPORT double fma(double, double, double);
OLM_DLLEXPORT double hypot(double, double);
OLM_DLLEXPORT int ilogb(double) __pure2;
OLM_DLLEXPORT int (isinf)(double) __pure2;
OLM_DLLEXPORT int (isnan)(double) __pure2;
OLM_DLLEXPORT double lgamma(double);
OLM_DLLEXPORT long long llrint(double);
OLM_DLLEXPORT long long llround(double);
OLM_DLLEXPORT double log1p(double);
OLM_DLLEXPORT double log2(double);
OLM_DLLEXPORT double logb(double);
OLM_DLLEXPORT long lrint(double);
OLM_DLLEXPORT long lround(double);
OLM_DLLEXPORT double nan(const char *) __pure2;
OLM_DLLEXPORT double nextafter(double, double);
OLM_DLLEXPORT double remainder(double, double);
OLM_DLLEXPORT double remquo(double, double, int *);
OLM_DLLEXPORT double rint(double);
#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XSI_VISIBLE */
#if __BSD_VISIBLE || __XSI_VISIBLE
OLM_DLLEXPORT double j0(double);
OLM_DLLEXPORT double j1(double);
OLM_DLLEXPORT double jn(int, double);
OLM_DLLEXPORT double y0(double);
OLM_DLLEXPORT double y1(double);
OLM_DLLEXPORT double yn(int, double);
#endif /* __BSD_VISIBLE || __XSI_VISIBLE */
#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
OLM_DLLEXPORT double copysign(double, double) __pure2;
OLM_DLLEXPORT double fdim(double, double);
OLM_DLLEXPORT double fmax(double, double) __pure2;
OLM_DLLEXPORT double fmin(double, double) __pure2;
OLM_DLLEXPORT double nearbyint(double);
OLM_DLLEXPORT double round(double);
OLM_DLLEXPORT double scalbln(double, long);
OLM_DLLEXPORT double scalbn(double, int);
OLM_DLLEXPORT double tgamma(double);
OLM_DLLEXPORT double trunc(double);
#endif
/*
* BSD math library entry points
*/
#if __BSD_VISIBLE
OLM_DLLEXPORT int isinff(float) __pure2;
OLM_DLLEXPORT int isnanf(float) __pure2;
/*
* Reentrant version of lgamma; passes signgam back by reference as the
* second argument; user must allocate space for signgam.
*/
OLM_DLLEXPORT double lgamma_r(double, int *);
/*
* Single sine/cosine function.
*/
OLM_DLLEXPORT void sincos(double, double *, double *);
#endif /* __BSD_VISIBLE */
/* float versions of ANSI/POSIX functions */
#if __ISO_C_VISIBLE >= 1999
OLM_DLLEXPORT float acosf(float);
OLM_DLLEXPORT float asinf(float);
OLM_DLLEXPORT float atanf(float);
OLM_DLLEXPORT float atan2f(float, float);
OLM_DLLEXPORT float cosf(float);
OLM_DLLEXPORT float sinf(float);
OLM_DLLEXPORT float tanf(float);
OLM_DLLEXPORT float coshf(float);
OLM_DLLEXPORT float sinhf(float);
OLM_DLLEXPORT float tanhf(float);
OLM_DLLEXPORT float exp2f(float);
OLM_DLLEXPORT float expf(float);
OLM_DLLEXPORT float expm1f(float);
OLM_DLLEXPORT float frexpf(float, int *); /* fundamentally !__pure2 */
OLM_DLLEXPORT int ilogbf(float) __pure2;
OLM_DLLEXPORT float ldexpf(float, int);
OLM_DLLEXPORT float log10f(float);
OLM_DLLEXPORT float log1pf(float);
OLM_DLLEXPORT float log2f(float);
OLM_DLLEXPORT float logf(float);
OLM_DLLEXPORT float modff(float, float *); /* fundamentally !__pure2 */
OLM_DLLEXPORT float powf(float, float);
OLM_DLLEXPORT float sqrtf(float);
OLM_DLLEXPORT float ceilf(float);
OLM_DLLEXPORT float fabsf(float) __pure2;
OLM_DLLEXPORT float floorf(float);
OLM_DLLEXPORT float fmodf(float, float);
OLM_DLLEXPORT float roundf(float);
OLM_DLLEXPORT float erff(float);
OLM_DLLEXPORT float erfcf(float);
OLM_DLLEXPORT float hypotf(float, float);
OLM_DLLEXPORT float lgammaf(float);
OLM_DLLEXPORT float tgammaf(float);
OLM_DLLEXPORT float acoshf(float);
OLM_DLLEXPORT float asinhf(float);
OLM_DLLEXPORT float atanhf(float);
OLM_DLLEXPORT float cbrtf(float);
OLM_DLLEXPORT float logbf(float);
OLM_DLLEXPORT float copysignf(float, float) __pure2;
OLM_DLLEXPORT long long llrintf(float);
OLM_DLLEXPORT long long llroundf(float);
OLM_DLLEXPORT long lrintf(float);
OLM_DLLEXPORT long lroundf(float);
OLM_DLLEXPORT float nanf(const char *) __pure2;
OLM_DLLEXPORT float nearbyintf(float);
OLM_DLLEXPORT float nextafterf(float, float);
OLM_DLLEXPORT float remainderf(float, float);
OLM_DLLEXPORT float remquof(float, float, int *);
OLM_DLLEXPORT float rintf(float);
OLM_DLLEXPORT float scalblnf(float, long);
OLM_DLLEXPORT float scalbnf(float, int);
OLM_DLLEXPORT float truncf(float);
OLM_DLLEXPORT float fdimf(float, float);
OLM_DLLEXPORT float fmaf(float, float, float);
OLM_DLLEXPORT float fmaxf(float, float) __pure2;
OLM_DLLEXPORT float fminf(float, float) __pure2;
#endif
/*
* float versions of BSD math library entry points
*/
#if __BSD_VISIBLE
OLM_DLLEXPORT float dremf(float, float);
OLM_DLLEXPORT float j0f(float);
OLM_DLLEXPORT float j1f(float);
OLM_DLLEXPORT float jnf(int, float);
OLM_DLLEXPORT float y0f(float);
OLM_DLLEXPORT float y1f(float);
OLM_DLLEXPORT float ynf(int, float);
/*
* Float versions of reentrant version of lgamma; passes signgam back by
* reference as the second argument; user must allocate space for signgam.
*/
OLM_DLLEXPORT float lgammaf_r(float, int *);
/*
* Single sine/cosine function.
*/
OLM_DLLEXPORT void sincosf(float, float *, float *);
#endif /* __BSD_VISIBLE */
/*
* long double versions of ISO/POSIX math functions
*/
#if __ISO_C_VISIBLE >= 1999
OLM_DLLEXPORT long double acoshl(long double);
OLM_DLLEXPORT long double acosl(long double);
OLM_DLLEXPORT long double asinhl(long double);
OLM_DLLEXPORT long double asinl(long double);
OLM_DLLEXPORT long double atan2l(long double, long double);
OLM_DLLEXPORT long double atanhl(long double);
OLM_DLLEXPORT long double atanl(long double);
OLM_DLLEXPORT long double cbrtl(long double);
OLM_DLLEXPORT long double ceill(long double);
OLM_DLLEXPORT long double copysignl(long double, long double) __pure2;
OLM_DLLEXPORT long double coshl(long double);
OLM_DLLEXPORT long double cosl(long double);
OLM_DLLEXPORT long double erfcl(long double);
OLM_DLLEXPORT long double erfl(long double);
OLM_DLLEXPORT long double exp2l(long double);
OLM_DLLEXPORT long double expl(long double);
OLM_DLLEXPORT long double expm1l(long double);
OLM_DLLEXPORT long double fabsl(long double) __pure2;
OLM_DLLEXPORT long double fdiml(long double, long double);
OLM_DLLEXPORT long double floorl(long double);
OLM_DLLEXPORT long double fmal(long double, long double, long double);
OLM_DLLEXPORT long double fmaxl(long double, long double) __pure2;
OLM_DLLEXPORT long double fminl(long double, long double) __pure2;
OLM_DLLEXPORT long double fmodl(long double, long double);
OLM_DLLEXPORT long double frexpl(long double value, int *); /* fundamentally !__pure2 */
OLM_DLLEXPORT long double hypotl(long double, long double);
OLM_DLLEXPORT int ilogbl(long double) __pure2;
OLM_DLLEXPORT long double ldexpl(long double, int);
OLM_DLLEXPORT long double lgammal(long double);
OLM_DLLEXPORT long long llrintl(long double);
OLM_DLLEXPORT long long llroundl(long double);
OLM_DLLEXPORT long double log10l(long double);
OLM_DLLEXPORT long double log1pl(long double);
OLM_DLLEXPORT long double log2l(long double);
OLM_DLLEXPORT long double logbl(long double);
OLM_DLLEXPORT long double logl(long double);
OLM_DLLEXPORT long lrintl(long double);
OLM_DLLEXPORT long lroundl(long double);
OLM_DLLEXPORT long double modfl(long double, long double *); /* fundamentally !__pure2 */
OLM_DLLEXPORT long double nanl(const char *) __pure2;
OLM_DLLEXPORT long double nearbyintl(long double);
OLM_DLLEXPORT long double nextafterl(long double, long double);
OLM_DLLEXPORT double nexttoward(double, long double);
OLM_DLLEXPORT float nexttowardf(float, long double);
OLM_DLLEXPORT long double nexttowardl(long double, long double);
OLM_DLLEXPORT long double powl(long double, long double);
OLM_DLLEXPORT long double remainderl(long double, long double);
OLM_DLLEXPORT long double remquol(long double, long double, int *);
OLM_DLLEXPORT long double rintl(long double);
OLM_DLLEXPORT long double roundl(long double);
OLM_DLLEXPORT long double scalblnl(long double, long);
OLM_DLLEXPORT long double scalbnl(long double, int);
OLM_DLLEXPORT long double sinhl(long double);
OLM_DLLEXPORT long double sinl(long double);
OLM_DLLEXPORT long double sqrtl(long double);
OLM_DLLEXPORT long double tanhl(long double);
OLM_DLLEXPORT long double tanl(long double);
OLM_DLLEXPORT long double tgammal(long double);
OLM_DLLEXPORT long double truncl(long double);
#endif /* __ISO_C_VISIBLE >= 1999 */
/* Reentrant version of lgammal. */
#if __BSD_VISIBLE
OLM_DLLEXPORT long double lgammal_r(long double, int *);
/*
* Single sine/cosine function.
*/
OLM_DLLEXPORT void sincosl(long double, long double *, long double *);
#endif /* __BSD_VISIBLE */
#if defined(__cplusplus)
}
#endif
#endif /* !OPENLIBM_MATH_H */
#endif /* OPENLIBM_USE_HOST_MATH_H */