Module Name:    src
Committed By:   christos
Date:           Thu Aug 25 12:14:10 UTC 2016

Modified Files:
        src/sys/arch/dreamcast/include: Makefile
        src/sys/arch/hpcsh/include: Makefile
        src/sys/arch/mmeye/include: Makefile
        src/sys/arch/sh3/include: Makefile
Added Files:
        src/sys/arch/dreamcast/include: fenv.h
        src/sys/arch/hpcsh/include: fenv.h
        src/sys/arch/mmeye/include: fenv.h
        src/sys/arch/sh3/include: fenv.h fpreg.h

Log Message:
fenv.h for sh


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/dreamcast/include/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/arch/dreamcast/include/fenv.h
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/hpcsh/include/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/arch/hpcsh/include/fenv.h
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/mmeye/include/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/arch/mmeye/include/fenv.h
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/sh3/include/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/arch/sh3/include/fenv.h \
    src/sys/arch/sh3/include/fpreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/dreamcast/include/Makefile
diff -u src/sys/arch/dreamcast/include/Makefile:1.18 src/sys/arch/dreamcast/include/Makefile:1.19
--- src/sys/arch/dreamcast/include/Makefile:1.18	Tue Jul 19 11:52:30 2011
+++ src/sys/arch/dreamcast/include/Makefile	Thu Aug 25 08:14:10 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.18 2011/07/19 15:52:30 dyoung Exp $
+#	$NetBSD: Makefile,v 1.19 2016/08/25 12:14:10 christos Exp $
 
 INCSDIR= /usr/include/dreamcast
 
@@ -7,7 +7,7 @@ INCS=	ansi.h aout_machdep.h asm.h \
 	cdefs.h coff_machdep.h cpu.h cputypes.h \
 	disklabel.h \
 	elf_machdep.h endian.h endian_machdep.h \
-	float.h frame.h \
+	fenv.h float.h frame.h \
 	ieee.h ieeefp.h \
 	int_const.h int_fmtio.h int_limits.h int_mwgwtypes.h int_types.h \
 	intr.h \

Index: src/sys/arch/hpcsh/include/Makefile
diff -u src/sys/arch/hpcsh/include/Makefile:1.19 src/sys/arch/hpcsh/include/Makefile:1.20
--- src/sys/arch/hpcsh/include/Makefile:1.19	Tue Jul 19 11:30:53 2011
+++ src/sys/arch/hpcsh/include/Makefile	Thu Aug 25 08:14:10 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.19 2011/07/19 15:30:53 dyoung Exp $
+#	$NetBSD: Makefile,v 1.20 2016/08/25 12:14:10 christos Exp $
 
 INCSDIR= /usr/include/hpcsh
 
@@ -7,7 +7,7 @@ INCS=	ansi.h aout_machdep.h apmvar.h asm
 	cdefs.h coff_machdep.h cpu.h cputypes.h \
 	disklabel.h \
 	elf_machdep.h endian.h endian_machdep.h \
-	float.h frame.h \
+	fenv.h float.h frame.h \
 	ieee.h ieeefp.h \
 	int_const.h int_fmtio.h int_limits.h int_mwgwtypes.h int_types.h \
 	intr.h \

Index: src/sys/arch/mmeye/include/Makefile
diff -u src/sys/arch/mmeye/include/Makefile:1.25 src/sys/arch/mmeye/include/Makefile:1.26
--- src/sys/arch/mmeye/include/Makefile:1.25	Tue Jul 19 11:17:20 2011
+++ src/sys/arch/mmeye/include/Makefile	Thu Aug 25 08:14:10 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.25 2011/07/19 15:17:20 dyoung Exp $
+#	$NetBSD: Makefile,v 1.26 2016/08/25 12:14:10 christos Exp $
 
 INCSDIR= /usr/include/mmeye
 
@@ -7,7 +7,7 @@ INCS=	ansi.h aout_machdep.h asm.h \
 	cdefs.h coff_machdep.h cpu.h cputypes.h \
 	disklabel.h \
 	elf_machdep.h endian.h endian_machdep.h \
-	float.h frame.h \
+	fenv.h float.h frame.h \
 	ieee.h ieeefp.h \
 	int_const.h int_fmtio.h int_limits.h int_mwgwtypes.h int_types.h \
 	intr.h \

Index: src/sys/arch/sh3/include/Makefile
diff -u src/sys/arch/sh3/include/Makefile:1.26 src/sys/arch/sh3/include/Makefile:1.27
--- src/sys/arch/sh3/include/Makefile:1.26	Sun Jul 17 19:52:12 2011
+++ src/sys/arch/sh3/include/Makefile	Thu Aug 25 08:14:10 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.26 2011/07/17 23:52:12 dyoung Exp $
+#	$NetBSD: Makefile,v 1.27 2016/08/25 12:14:10 christos Exp $
 
 INCSDIR= /usr/include/sh3
 
@@ -7,7 +7,7 @@ INCS=	ansi.h aout_machdep.h asm.h \
 	cdefs.h coff_machdep.h cpu.h cputypes.h \
 	disklabel.h \
 	elf_machdep.h endian.h endian_machdep.h \
-	float.h frame.h \
+	float.h fenv.h fpreg.h frame.h \
 	ieee.h ieeefp.h \
 	int_const.h int_fmtio.h int_limits.h int_mwgwtypes.h int_types.h \
 	intr.h \

Added files:

Index: src/sys/arch/dreamcast/include/fenv.h
diff -u /dev/null src/sys/arch/dreamcast/include/fenv.h:1.1
--- /dev/null	Thu Aug 25 08:14:10 2016
+++ src/sys/arch/dreamcast/include/fenv.h	Thu Aug 25 08:14:10 2016
@@ -0,0 +1,3 @@
+/*	$NetBSD: fenv.h,v 1.1 2016/08/25 12:14:10 christos Exp $	*/
+
+#include <sh3/fenv.h>

Index: src/sys/arch/hpcsh/include/fenv.h
diff -u /dev/null src/sys/arch/hpcsh/include/fenv.h:1.1
--- /dev/null	Thu Aug 25 08:14:10 2016
+++ src/sys/arch/hpcsh/include/fenv.h	Thu Aug 25 08:14:10 2016
@@ -0,0 +1,3 @@
+/*	$NetBSD: fenv.h,v 1.1 2016/08/25 12:14:10 christos Exp $	*/
+
+#include <sh3/fenv.h>

Index: src/sys/arch/mmeye/include/fenv.h
diff -u /dev/null src/sys/arch/mmeye/include/fenv.h:1.1
--- /dev/null	Thu Aug 25 08:14:10 2016
+++ src/sys/arch/mmeye/include/fenv.h	Thu Aug 25 08:14:10 2016
@@ -0,0 +1,3 @@
+/*	$NetBSD: fenv.h,v 1.1 2016/08/25 12:14:10 christos Exp $	*/
+
+#include <sh3/fenv.h>

Index: src/sys/arch/sh3/include/fenv.h
diff -u /dev/null src/sys/arch/sh3/include/fenv.h:1.1
--- /dev/null	Thu Aug 25 08:14:10 2016
+++ src/sys/arch/sh3/include/fenv.h	Thu Aug 25 08:14:10 2016
@@ -0,0 +1,292 @@
+/*	$NetBSD: fenv.h,v 1.1 2016/08/25 12:14:10 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 _SH3_FENV_H_
+#define _SH3_FENV_H_
+
+#include <sys/stdint.h>
+#include <sh3/float.h>
+#include <sh3/fpreg.h>
+
+#ifndef __fenv_static   
+#define __fenv_static   static
+#endif
+
+/* Exception bits, from FPSCR */
+#define	FE_INEXACT	((uint32_t)FPSCR_EXCEPTION_INEXACT >> 5)
+#define	FE_DIVBYZERO	((uint32_t)FPSCR_EXCEPTION_ZERODIV >> 5)
+#define	FE_UNDERFLOW	((uint32_t)FPSCR_EXCEPTION_UNDERFLOW >> 5)
+#define	FE_OVERFLOW	((uint32_t)FPSCR_EXCEPTION_OVERFLOW >> 5)
+#define	FE_INVALID	((uint32_t)FPSCR_EXCEPTION_INVALID >> 5)
+
+#define FE_ALL_EXCEPT \
+    (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
+
+/* Rounding modes, from FPSCR */
+#define FE_TONEAREST	FPSCR_ROUND_NEAREST
+#define	FE_TOWARDZERO	FPSCR_ROUND_ZERO
+/* 	FE_DOWNWARD	*/
+/*	FE_UPWARD	*/
+
+#define _ROUND_MASK	\
+    (FE_TONEAREST | FE_TOWARDZERO)
+
+typedef uint32_t fexcept_t;
+
+typedef struct {
+	uint32_t __fpscr;
+} fenv_t;
+			 
+#define FE_DFL_ENV      ((fenv_t *) -1) 
+
+#define __get_fpscr(__fpscr) \
+    __asm__ __volatile__ ("sts fpscr,%0" : "=r" (__fpscr))
+#define __set_fpscr(__fpscr) \
+    __asm__ __volatile__ ("lds %0,fpscr" : : "r" (__fpscr))
+
+__BEGIN_DECLS
+
+__fenv_static inline int
+feclearexcept(int __excepts)
+{
+	fexcept_t __fpscr;
+
+	__excepts &= FE_ALL_EXCEPT;
+
+	__get_fpscr(__fpscr);
+	__fpscr &= ~__excepts;
+	__set_fpscr(__fpscr);
+
+	return 0;
+}
+
+__fenv_static inline int
+fegetexceptflag(fexcept_t *__flagp, int __excepts)
+{
+	fexcept_t __fpscr;
+
+	__get_fpscr(__fpscr);
+
+	*__flagp = __fpscr & __excepts & FE_ALL_EXCEPT;
+
+	return 0;
+}
+
+__fenv_static inline int
+fesetexceptflag(const fexcept_t *__flagp, int __excepts)
+{
+	fexcept_t __fpscr;
+
+	__get_fpscr(__fpscr);
+
+	__fpscr &= ~(__excepts & FE_ALL_EXCEPT);
+	__fpscr |= *__flagp & __excepts & FE_ALL_EXCEPT;
+
+	__set_fpscr(__fpscr);
+
+	return 0;
+}
+
+static inline void
+__fmul(double a, double b)
+{
+#ifdef __sh4__
+	__asm__ __volatile__ ("fmul %1, %0" : "+d" (a) : "d" (b));
+#endif
+}
+
+static inline void
+__fdiv(double a, double b) {
+#ifdef __sh4__
+	__asm__ __volatile__ ("fdiv %1, %0" : "+d" (a) : "d" (b));
+#endif
+}
+
+__fenv_static inline int
+feraiseexcept(int __excepts)
+{
+	fexcept_t __fpscr;
+
+	if (__excepts & FE_INVALID)	/* Inf * 0 */
+		__fmul(__builtin_huge_val(), 0.0);
+
+	if (__excepts & FE_DIVBYZERO)	/* 1.0 / 0 */
+		__fdiv(1.0, 0.0);
+
+	if (__excepts & FE_OVERFLOW)	/* MAX * MAX */
+		__fmul(LDBL_MAX, LDBL_MAX);
+
+	if (__excepts & FE_UNDERFLOW)	/* MIN / 10.0 */
+		__fdiv(LDBL_MIN, 10.0);
+
+	if (__excepts & FE_INEXACT)	/* 1 / 3 */
+		__fdiv(1.0, 3.0);
+
+	__get_fpscr(__fpscr);
+
+	__fpscr |= __excepts & FE_ALL_EXCEPT;
+
+	__set_fpscr(__fpscr);
+
+	return 0;
+}
+
+__fenv_static inline int
+fetestexcept(int __excepts)
+{
+	fexcept_t __fpscr;
+
+	__get_fpscr(__fpscr);
+
+	return __fpscr & __excepts & FE_ALL_EXCEPT;
+}
+
+__fenv_static inline int
+fegetround(void)
+{
+	fexcept_t __fpscr;
+
+	__get_fpscr(__fpscr);
+	return __fpscr & _ROUND_MASK;
+}
+
+__fenv_static inline int
+fesetround(int __round)
+{
+	fexcept_t __fpscr;
+
+	if (__round & ~_ROUND_MASK)
+		return -1;
+
+	__get_fpscr(__fpscr);
+
+	__fpscr &= ~_ROUND_MASK;
+	__fpscr |= __round;
+
+	__set_fpscr(__fpscr);
+
+	return 0;
+}
+
+__fenv_static inline int
+fegetenv(fenv_t *__envp)
+{
+	fexcept_t __fpscr;
+
+	__get_fpscr(__fpscr);
+	__envp->__fpscr = __fpscr;
+
+	return 0;
+}
+
+__fenv_static inline int
+feholdexcept(fenv_t *__envp)
+{
+	fexcept_t __fpscr;
+
+	__get_fpscr(__fpscr);
+	__envp->__fpscr = __fpscr;
+
+	__fpscr &= ~FE_ALL_EXCEPT;
+	__fpscr &= ~(FE_ALL_EXCEPT << 5);
+	__set_fpscr(__fpscr);	/* clear all */
+
+	return 0;
+}
+
+__fenv_static inline int
+fesetenv(const fenv_t *__envp)
+{
+	if (__envp == FE_DFL_ENV)
+		__set_fpscr(FPSCR_DEFAULT);
+	else
+		__set_fpscr(__envp->__fpscr);
+
+	return 0;
+}
+
+__fenv_static inline int
+feupdateenv(const fenv_t *__envp)
+{
+	fexcept_t __fpscr;
+
+	__get_fpscr(__fpscr);
+	__fpscr &= FE_ALL_EXCEPT;
+	fesetenv(__envp);
+	feraiseexcept((int)__fpscr);
+	return 0;
+}
+
+#if defined(_NETBSD_SOURCE) || defined(_GNU_SOURCE)
+
+/* We currently provide no external definitions of the functions below. */
+
+static inline int
+feenableexcept(int __mask)
+{
+	fexcept_t __fpscr, __oldmask;
+
+	__get_fpscr(__fpscr);
+	__oldmask = (__fpscr >> 5) & FE_ALL_EXCEPT;
+	__fpscr |= (__mask & FE_ALL_EXCEPT) << 5;
+	__set_fpscr(__fpscr);
+
+	return __oldmask;
+}
+
+static inline int
+fedisableexcept(int __mask)
+{
+	fexcept_t __fpscr, __oldmask;
+
+	__get_fpscr(__fpscr);
+	__oldmask = (__fpscr >> 5) & FE_ALL_EXCEPT;
+	__fpscr &= ~(__mask & FE_ALL_EXCEPT) << 5;
+	__set_fpscr(__fpscr);
+
+	return __oldmask;
+}
+
+static inline int
+fegetexcept(void)
+{
+	fexcept_t __fpscr;
+
+	__get_fpscr(__fpscr);
+
+	return (__fpscr >> 5) & FE_ALL_EXCEPT;
+}
+
+#endif /* _NETBSD_SOURCE || _GNU_SOURCE */
+
+__END_DECLS
+
+#endif /* _SH3_FENV_H_ */
Index: src/sys/arch/sh3/include/fpreg.h
diff -u /dev/null src/sys/arch/sh3/include/fpreg.h:1.1
--- /dev/null	Thu Aug 25 08:14:10 2016
+++ src/sys/arch/sh3/include/fpreg.h	Thu Aug 25 08:14:10 2016
@@ -0,0 +1,48 @@
+/*	$NetBSD: fpreg.h,v 1.1 2016/08/25 12:14:10 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 _SH3_FPREG_H_
+#define _SH3_FPREG_H_
+
+/* Rounding */
+#define	FPSCR_ROUND_NEAREST	0x0
+#define FPSCR_ROUND_ZERO	0x1
+
+/* Exceptions */
+#define	FPSCR_EXCEPTION_INEXACT		0x080	/* Inexact operatiomn  */
+#define	FPSCR_EXCEPTION_UNDERFLOW	0x100	/* Underflow */
+#define	FPSCR_EXCEPTION_OVERFLOW	0x200	/* Overflow */
+#define	FPSCR_EXCEPTION_ZERODIV		0x400	/* Divide by zero */
+#define	FPSCR_EXCEPTION_INVALID		0x800	/* Invalid operation */
+
+#define FPSCR_DEFAULT	0x00080000	/* no interrupts, round to nearest */
+
+#endif /* _SH3_FPREG_H_ */

Reply via email to