Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch fenv.h for sh



details:   https://anonhg.NetBSD.org/src/rev/c8d985b6a96e
branches:  trunk
changeset: 817555:c8d985b6a96e
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Aug 25 12:14:10 2016 +0000

description:
fenv.h for sh

diffstat:

 sys/arch/dreamcast/include/Makefile |    4 +-
 sys/arch/dreamcast/include/fenv.h   |    3 +
 sys/arch/hpcsh/include/Makefile     |    4 +-
 sys/arch/hpcsh/include/fenv.h       |    3 +
 sys/arch/mmeye/include/Makefile     |    4 +-
 sys/arch/mmeye/include/fenv.h       |    3 +
 sys/arch/sh3/include/Makefile       |    4 +-
 sys/arch/sh3/include/fenv.h         |  292 ++++++++++++++++++++++++++++++++++++
 sys/arch/sh3/include/fpreg.h        |   48 +++++
 9 files changed, 357 insertions(+), 8 deletions(-)

diffs (truncated from 441 to 300 lines):

diff -r 79f2f68d92e7 -r c8d985b6a96e sys/arch/dreamcast/include/Makefile
--- a/sys/arch/dreamcast/include/Makefile       Thu Aug 25 12:12:59 2016 +0000
+++ b/sys/arch/dreamcast/include/Makefile       Thu Aug 25 12:14:10 2016 +0000
@@ -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 @@
        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 \
diff -r 79f2f68d92e7 -r c8d985b6a96e sys/arch/dreamcast/include/fenv.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/dreamcast/include/fenv.h Thu Aug 25 12:14:10 2016 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: fenv.h,v 1.1 2016/08/25 12:14:10 christos Exp $        */
+
+#include <sh3/fenv.h>
diff -r 79f2f68d92e7 -r c8d985b6a96e sys/arch/hpcsh/include/Makefile
--- a/sys/arch/hpcsh/include/Makefile   Thu Aug 25 12:12:59 2016 +0000
+++ b/sys/arch/hpcsh/include/Makefile   Thu Aug 25 12:14:10 2016 +0000
@@ -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 @@
        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 \
diff -r 79f2f68d92e7 -r c8d985b6a96e sys/arch/hpcsh/include/fenv.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcsh/include/fenv.h     Thu Aug 25 12:14:10 2016 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: fenv.h,v 1.1 2016/08/25 12:14:10 christos Exp $        */
+
+#include <sh3/fenv.h>
diff -r 79f2f68d92e7 -r c8d985b6a96e sys/arch/mmeye/include/Makefile
--- a/sys/arch/mmeye/include/Makefile   Thu Aug 25 12:12:59 2016 +0000
+++ b/sys/arch/mmeye/include/Makefile   Thu Aug 25 12:14:10 2016 +0000
@@ -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 @@
        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 \
diff -r 79f2f68d92e7 -r c8d985b6a96e sys/arch/mmeye/include/fenv.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/mmeye/include/fenv.h     Thu Aug 25 12:14:10 2016 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: fenv.h,v 1.1 2016/08/25 12:14:10 christos Exp $        */
+
+#include <sh3/fenv.h>
diff -r 79f2f68d92e7 -r c8d985b6a96e sys/arch/sh3/include/Makefile
--- a/sys/arch/sh3/include/Makefile     Thu Aug 25 12:12:59 2016 +0000
+++ b/sys/arch/sh3/include/Makefile     Thu Aug 25 12:14:10 2016 +0000
@@ -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 @@
        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 \
diff -r 79f2f68d92e7 -r c8d985b6a96e sys/arch/sh3/include/fenv.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sh3/include/fenv.h       Thu Aug 25 12:14:10 2016 +0000
@@ -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;
+



Home | Main Index | Thread Index | Old Index