hrev53784 adds 2 changesets to branch 'master'
old head: 2d697067b2021ca5369f875289415dae30340af2
new head: 3a85d802ee63cce871963b28de50fd9ffd8900ac
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=3a85d802ee63+%5E2d697067b202
----------------------------------------------------------------------------
15fb7d88e971: 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@xxxxxxxxxxx>
Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
3a85d802ee63: libroot/riscv64: Fix build. Add MIT optimized bswap from rv8
Change-Id: I4d0e1ec34d1568594cac0f7378f87852c997ab81
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2166
Reviewed-by: Alex von Gluck IV <kallisti5@xxxxxxxxxxx>
Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
[ Alexander von Gluck IV <kallisti5@xxxxxxxxxxx> ]
----------------------------------------------------------------------------
5 files changed, 417 insertions(+), 17 deletions(-)
headers/posix/arch/riscv64/fenv.h | 262 +++++++++++++++++++
headers/posix/fenv.h | 2 +
src/system/libroot/os/arch/riscv64/Jamfile | 2 +
src/system/libroot/os/arch/riscv64/byteorder.S | 68 +++--
.../libroot/posix/musl/math/riscv64/Jamfile | 100 +++++++
############################################################################
Commit: 15fb7d88e971c4d6c787c6a3a5c159afb1ebf77b
URL: https://git.haiku-os.org/haiku/commit/?id=15fb7d88e971
Author: Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date: Tue Jan 28 01:59:50 2020 UTC
Committer: Adrien Destugues <pulkomandy@xxxxxxxxx>
Commit-Date: Tue Jan 28 11:48:42 2020 UTC
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@xxxxxxxxxxx>
Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
----------------------------------------------------------------------------
diff --git a/headers/posix/arch/riscv64/fenv.h
b/headers/posix/arch/riscv64/fenv.h
new file mode 100644
index 0000000000..5d2776c2b9
--- /dev/null
+++ b/headers/posix/arch/riscv64/fenv.h
@@ -0,0 +1,262 @@
+/*-
+ * Copyright (c) 2004-2005 David Schultz <das@xxxxxxxxxxx>
+ * Copyright (c) 2015-2016 Ruslan Bukin <br@xxxxxxxxxx>
+ * 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_ */
diff --git a/headers/posix/fenv.h b/headers/posix/fenv.h
index 02a48a2c90..6c8c37a61c 100644
--- a/headers/posix/fenv.h
+++ b/headers/posix/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
diff --git a/src/system/libroot/posix/musl/math/riscv64/Jamfile
b/src/system/libroot/posix/musl/math/riscv64/Jamfile
new file mode 100644
index 0000000000..b24a209c64
--- /dev/null
+++ b/src/system/libroot/posix/musl/math/riscv64/Jamfile
@@ -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) ..
] ;
+ }
+}
############################################################################
Revision: hrev53784
Commit: 3a85d802ee63cce871963b28de50fd9ffd8900ac
URL: https://git.haiku-os.org/haiku/commit/?id=3a85d802ee63
Author: Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date: Tue Jan 28 04:23:13 2020 UTC
Committer: Adrien Destugues <pulkomandy@xxxxxxxxx>
Commit-Date: Tue Jan 28 11:48:42 2020 UTC
libroot/riscv64: Fix build. Add MIT optimized bswap from rv8
Change-Id: I4d0e1ec34d1568594cac0f7378f87852c997ab81
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2166
Reviewed-by: Alex von Gluck IV <kallisti5@xxxxxxxxxxx>
Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
----------------------------------------------------------------------------
diff --git a/src/system/libroot/os/arch/riscv64/Jamfile
b/src/system/libroot/os/arch/riscv64/Jamfile
index 64aa1a8422..e16a245868 100644
--- a/src/system/libroot/os/arch/riscv64/Jamfile
+++ b/src/system/libroot/os/arch/riscv64/Jamfile
@@ -13,6 +13,8 @@ for architectureObject in [ MultiArchSubDirSetup riscv64 ] {
SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;
MergeObject <$(architecture)>os_arch_$(TARGET_ARCH).o :
+ byteorder.S
+
stack_frame.c
system_time.c
diff --git a/src/system/libroot/os/arch/riscv64/byteorder.S
b/src/system/libroot/os/arch/riscv64/byteorder.S
index 9bded18ee4..06fa75ed35 100644
--- a/src/system/libroot/os/arch/riscv64/byteorder.S
+++ b/src/system/libroot/os/arch/riscv64/byteorder.S
@@ -1,30 +1,41 @@
/*
- * Copyright 2009, Johannes Wischert. All rights reserved.
+ * Copyright 2018-2020, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
+ *
+ * Optimized byteswap functions from the rv8 test
+ * suite licensed under the MIT License
+ * https://github.com/rv8-io/rv8/tree/master/src/test
+ *
*/
#include <asm_defs.h>
.text
-/*
- * These aren't needed on gcc4+
- * uint16 __swap_int16(uint16 value)
- * uint32 __swap_int32(uint32 value)
- * uint64 __swap_int64(uint64 value)
- */
-
-/* TODO: The following functions can surely be optimized. A simple optimization
- * would be to define macros with the contents of the __swap_int{32,64}
- * functions and use those instead of calling the functions.
- */
-
/* float __swap_float(float value)
*/
FUNCTION(__swap_float):
// Assumes single precision
- b __swap_int32
- //rts
+ 1: auipc a4, %pcrel_hi(__bswap64_c1)
+ ld a4, %pcrel_lo(1b)(a4)
+ slli a5, a0, 8
+ and a5, a5, a4
+ srli a0, a0, 8
+ srli a4, a4, 8
+ and a0, a0, a4
+ or a5, a5, a0
+ 1: auipc a4, %pcrel_hi(__bswap64_c2)
+ ld a4, %pcrel_lo(1b)(a4)
+ slli a0, a5, 16
+ and a0, a0, a4
+ srli a5, a5, 16
+ srli a4, a4, 16
+ and a5, a5, a4
+ or a5, a5, a0
+ slli a0, a5, 32
+ srli a5, a5, 32
+ or a0, a0, a5
+ ret
FUNCTION_END(__swap_float)
@@ -32,7 +43,30 @@ FUNCTION_END(__swap_float)
*/
FUNCTION(__swap_double):
// Assumes double is int64 on RV64
- b __swap_int64
- //rts
+ 1: auipc a4, %pcrel_hi(__bswap64_c1)
+ ld a4, %pcrel_lo(1b)(a4)
+ slli a5, a0, 8
+ and a5, a5, a4
+ srli a0, a0, 8
+ srli a4, a4, 8
+ and a0, a0, a4
+ or a5, a5, a0
+ 1: auipc a4, %pcrel_hi(__bswap64_c2)
+ ld a4, %pcrel_lo(1b)(a4)
+ slli a0, a5, 16
+ and a0, a0, a4
+ srli a5, a5, 16
+ srli a4, a4, 16
+ and a5, a5, a4
+ or a5, a5, a0
+ slli a0, a5, 32
+ srli a5, a5, 32
+ or a0, a0, a5
+ ret
FUNCTION_END(__swap_double)
+
+.section .rodata
+__bswap32_c1: .4byte 0xFF00FF00ULL
+__bswap64_c1: .8byte 0xFF00FF00FF00FF00ULL
+__bswap64_c2: .8byte 0xFFFF0000FFFF0000ULL