riscv64: Add missing (slightly modified) fenv.h from FreeBSD
* A few tips for future folks follows. * fenv.h gets wrapped in our buildtools * If anything in the arch fenv.h "doesn't work" buildtools will silently fail early on (autotools HAVE_FENV_H) Change-Id: Icae064fde42af3bbed5ea2eadfaa8c18c677e6a6 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2164 Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com> Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
parent
2d697067b2
commit
15fb7d88e9
262
headers/posix/arch/riscv64/fenv.h
Normal file
262
headers/posix/arch/riscv64/fenv.h
Normal file
@ -0,0 +1,262 @@
|
||||
/*-
|
||||
* 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$
|
||||
*/
|
||||
|
||||
#ifndef _FENV_H_
|
||||
#define _FENV_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.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_ */
|
@ -11,6 +11,8 @@
|
||||
# include <arch/arm64/fenv.h>
|
||||
#elif defined(__POWERPC__)
|
||||
# include <arch/ppc/fenv.h>
|
||||
#elif defined(__riscv64__)
|
||||
# include <arch/riscv64/fenv.h>
|
||||
#elif defined(__sparc__)
|
||||
# include <arch/sparc64/fenv.h>
|
||||
#else
|
||||
|
100
src/system/libroot/posix/musl/math/riscv64/Jamfile
Normal file
100
src/system/libroot/posix/musl/math/riscv64/Jamfile
Normal file
@ -0,0 +1,100 @@
|
||||
SubDir HAIKU_TOP src system libroot posix musl math riscv64 ;
|
||||
|
||||
SubDirCcFlags -Wno-unused-but-set-variable ;
|
||||
|
||||
SubDirSysHdrs [ FDirName $(SUBDIR) .. .. include ] ;
|
||||
UseHeaders [ FDirName $(SUBDIR) .. .. internal ] ;
|
||||
|
||||
local arch ;
|
||||
for arch in $(TARGET_ARCHS) {
|
||||
UseHeaders [ FDirName $(SUBDIR) .. .. arch $(arch) ] ;
|
||||
}
|
||||
UseHeaders [ FDirName $(SUBDIR) .. .. arch generic ] ;
|
||||
|
||||
local generics =
|
||||
acos.c acosf.c acosl.c
|
||||
acosh.c acoshf.c acoshl.c
|
||||
asin.c asinf.c asinl.c
|
||||
asinh.c asinhf.c asinhl.c
|
||||
atan2.c atan2f.c atan2l.c
|
||||
atan.c atanf.c atanl.c
|
||||
atanh.c atanhf.c atanhl.c
|
||||
cbrt.c cbrtf.c cbrtl.c
|
||||
ceil.c ceilf.c ceill.c
|
||||
copysign.c copysignf.c copysignl.c
|
||||
cos.c cosf.c cosl.c __cosl.c __cos.c __cosdf.c
|
||||
cosh.c coshf.c coshl.c
|
||||
erf.c erff.c erfl.c
|
||||
exp10.c exp10f.c exp10l.c
|
||||
exp2.c exp2f.c exp2f_data.c exp2l.c
|
||||
exp.c exp_data.c expf.c expl.c
|
||||
expm1.c expm1f.c expm1l.c
|
||||
__expo2.c __expo2f.c
|
||||
fabsl.c
|
||||
fdim.c fdimf.c fdiml.c
|
||||
finite.c finitef.c
|
||||
floor.c floorf.c floorl.c
|
||||
fmal.c
|
||||
fmax.c fmaxf.c fmaxl.c
|
||||
fmin.c fminf.c fminl.c
|
||||
fmod.c fmodf.c fmodl.c
|
||||
frexp.c frexpf.c frexpl.c
|
||||
hypot.c hypotf.c hypotl.c
|
||||
ilogb.c ilogbf.c ilogbl.c
|
||||
__invtrigl.c
|
||||
j0.c j0f.c j1.c j1f.c jn.c jnf.c
|
||||
ldexp.c ldexpf.c ldexpl.c
|
||||
lgamma.c lgammaf.c lgammaf_r.c lgammal.c lgamma_r.c
|
||||
llrint.c llrintf.c llrintl.c
|
||||
llround.c llroundf.c llroundl.c
|
||||
log10.c log10f.c log10l.c
|
||||
log1p.c log1pf.c log1pl.c
|
||||
log2.c log2_data.c log2f.c log2f_data.c log2l.c
|
||||
logb.c logbf.c logbl.c
|
||||
log.c log_data.c logf.c logf_data.c logl.c
|
||||
lrint.c lrintf.c lrintl.c
|
||||
lround.c lroundf.c lroundl.c
|
||||
__math_divzero.c __math_divzerof.c __math_invalid.c __math_invalidf.c
|
||||
__math_oflow.c __math_oflowf.c __math_uflow.c __math_uflowf.c
|
||||
__math_xflow.c __math_xflowf.c
|
||||
modf.c modff.c modfl.c
|
||||
nan.c nanf.c nanl.c
|
||||
nearbyint.c nearbyintf.c nearbyintl.c
|
||||
nextafter.c nextafterf.c nextafterl.c
|
||||
nexttoward.c nexttowardf.c nexttowardl.c
|
||||
__polevll.c pow.c pow_data.c powf.c powf_data.c powl.c
|
||||
remainder.c remainderf.c remainderl.c
|
||||
__rem_pio2.c __rem_pio2f.c __rem_pio2_large.c __rem_pio2l.c
|
||||
remquo.c remquof.c remquol.c
|
||||
rint.c rintf.c rintl.c
|
||||
round.c roundf.c roundl.c
|
||||
scalb.c scalbf.c scalbln.c scalblnf.c scalblnl.c scalbn.c scalbnf.c scalbnl.c
|
||||
signgam.c
|
||||
significand.c significandf.c
|
||||
__sin.c sin.c __sinl.c sinl.c
|
||||
sincos.c sincosf.c sincosl.c
|
||||
__sindf.c sinf.c
|
||||
sinh.c sinhf.c sinhl.c
|
||||
sqrtl.c
|
||||
__tan.c tan.c __tandf.c tanf.c __tanl.c tanl.c
|
||||
tanh.c tanhf.c tanhl.c
|
||||
tgamma.c tgammaf.c tgammal.c
|
||||
trunc.c truncf.c truncl.c
|
||||
;
|
||||
|
||||
local architectureObject ;
|
||||
for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
on $(architectureObject) {
|
||||
local architecture = $(TARGET_PACKAGING_ARCH) ;
|
||||
|
||||
MergeObject <$(architecture)>posix_musl_math.o :
|
||||
fabs.c fabsf.c
|
||||
fma.c fmaf.c
|
||||
sqrt.c sqrtf.c
|
||||
|
||||
$(generics)
|
||||
;
|
||||
|
||||
SEARCH on [ FGristFiles $(generics) ] = [ FDirName $(SUBDIR) .. ] ;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user