Module Name:    src
Committed By:   chs
Date:           Wed Mar 22 23:11:10 UTC 2017

Modified Files:
        src/external/gpl3/gcc/lib/libgcc/libgcc: Makefile
        src/include: fenv.h
        src/lib/libc/arch/m68k/gen: Makefile.inc
        src/lib/libc/arch/sh3: Makefile.inc
        src/lib/libm: Makefile
        src/lib/libm/arch/aarch64: fenv.c
        src/lib/libm/arch/alpha: fenv.c
        src/lib/libm/arch/arm: fenv.c
        src/lib/libm/arch/hppa: fenv.c
        src/lib/libm/arch/i387: fenv.c
        src/lib/libm/arch/ia64: fenv.c
        src/lib/libm/arch/m68k: fenv.c
        src/lib/libm/arch/mips: fenv.c
        src/lib/libm/arch/powerpc: fenv.c
        src/lib/libm/arch/riscv: fenv.c
        src/lib/libm/arch/sh3: fenv.c
        src/lib/libm/arch/sparc: fenv.c
        src/lib/libm/arch/sparc64: fenv.c
        src/lib/libm/arch/x86_64: fenv.c
        src/lib/libm/src: namespace.h
        src/share/mk: bsd.own.mk bsd.sys.mk
        src/sys/arch/arm/include: fenv.h ieeefp.h
        src/sys/arch/m68k/include: fenv.h ieeefp.h
        src/sys/arch/mips/include: fenv.h ieeefp.h
        src/sys/arch/powerpc/include: fenv.h ieeefp.h
        src/sys/arch/riscv/include: fenv.h
        src/sys/arch/sh3/include: fenv.h ieeefp.h
        src/tools/gcc: Makefile
Added Files:
        src/lib/libm/softfloat: feclearexcept.c fedisableexcept.c
            feenableexcept.c fegetenv.c fegetexcept.c fegetexceptflag.c
            fegetround.c feholdexcept.c feraiseexcept.c fesetenv.c
            fesetexceptflag.c fesetround.c fetestexcept.c feupdateenv.c

Log Message:
provide a common softfloat fenv implemenation and use it for softfloat builds.
restore ABI compatibility with previous releases for ieeefp.h on sh3.
add namespace.h protection for all the fenv interfaces.
use MKSOFTFLOAT on sh3 instead of assuming softfloat.
standardize on comparing MKSOFTFLOAT with "no".
remove the arm-specific softfloat fenv code (which also had several bugs).
fix logic errors in the arm hardfloat feraiseexcept() and feupdateenv().


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/external/gpl3/gcc/lib/libgcc/libgcc/Makefile
cvs rdiff -u -r1.24 -r1.25 src/include/fenv.h
cvs rdiff -u -r1.34 -r1.35 src/lib/libc/arch/m68k/gen/Makefile.inc
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/arch/sh3/Makefile.inc
cvs rdiff -u -r1.188 -r1.189 src/lib/libm/Makefile
cvs rdiff -u -r1.2 -r1.3 src/lib/libm/arch/aarch64/fenv.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libm/arch/alpha/fenv.c
cvs rdiff -u -r1.6 -r1.7 src/lib/libm/arch/arm/fenv.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libm/arch/hppa/fenv.c
cvs rdiff -u -r1.7 -r1.8 src/lib/libm/arch/i387/fenv.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libm/arch/ia64/fenv.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libm/arch/m68k/fenv.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libm/arch/mips/fenv.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libm/arch/powerpc/fenv.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libm/arch/riscv/fenv.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libm/arch/sh3/fenv.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libm/arch/sparc/fenv.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libm/arch/sparc64/fenv.c
cvs rdiff -u -r1.6 -r1.7 src/lib/libm/arch/x86_64/fenv.c
cvs rdiff -u -r0 -r1.1 src/lib/libm/softfloat/feclearexcept.c \
    src/lib/libm/softfloat/fedisableexcept.c \
    src/lib/libm/softfloat/feenableexcept.c src/lib/libm/softfloat/fegetenv.c \
    src/lib/libm/softfloat/fegetexcept.c \
    src/lib/libm/softfloat/fegetexceptflag.c \
    src/lib/libm/softfloat/fegetround.c src/lib/libm/softfloat/feholdexcept.c \
    src/lib/libm/softfloat/feraiseexcept.c src/lib/libm/softfloat/fesetenv.c \
    src/lib/libm/softfloat/fesetexceptflag.c \
    src/lib/libm/softfloat/fesetround.c src/lib/libm/softfloat/fetestexcept.c \
    src/lib/libm/softfloat/feupdateenv.c
cvs rdiff -u -r1.13 -r1.14 src/lib/libm/src/namespace.h
cvs rdiff -u -r1.1006 -r1.1007 src/share/mk/bsd.own.mk
cvs rdiff -u -r1.269 -r1.270 src/share/mk/bsd.sys.mk
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/include/fenv.h \
    src/sys/arch/arm/include/ieeefp.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/m68k/include/fenv.h
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/m68k/include/ieeefp.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/mips/include/fenv.h
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/mips/include/ieeefp.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/powerpc/include/fenv.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/powerpc/include/ieeefp.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/riscv/include/fenv.h
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/sh3/include/fenv.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/sh3/include/ieeefp.h
cvs rdiff -u -r1.80 -r1.81 src/tools/gcc/Makefile

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

Modified files:

Index: src/external/gpl3/gcc/lib/libgcc/libgcc/Makefile
diff -u src/external/gpl3/gcc/lib/libgcc/libgcc/Makefile:1.26 src/external/gpl3/gcc/lib/libgcc/libgcc/Makefile:1.27
--- src/external/gpl3/gcc/lib/libgcc/libgcc/Makefile:1.26	Thu Mar 31 06:59:44 2016
+++ src/external/gpl3/gcc/lib/libgcc/libgcc/Makefile	Wed Mar 22 23:11:07 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.26 2016/03/31 06:59:44 martin Exp $
+#	$NetBSD: Makefile,v 1.27 2017/03/22 23:11:07 chs Exp $
 
 REQUIRETOOLS=	yes
 NOLINT=		# defined
@@ -23,7 +23,7 @@ LIB2ADD_HACK+=	${GNUHOSTDIST}/gcc/config
 .endif
 
 # XXXGCC5 GCC 5.3 has all these in libgcc and we have them in libc.
-.if ${MKSOFTFLOAT} == "yes"
+.if ${MKSOFTFLOAT} != "no"
 LIB2ADD_EDITED= ${G_LIB2ADD:T:Nfloatsisf.c:Nfloatunsisf.c:Nfloatsidf.c:Nfloatunsidf.c:Nfixsfsi.c:Nextendsfdf2.c:Naddsf3.c:Nmulsf3.c:Ndivsf3.c:Nadddf3.c:Nsubdf3.c:Nmuldf3.c:Ndivdf3.c:Nfixdfsi.c:S/.asm/.S/}
 .else
 LIB2ADD_EDITED=	${G_LIB2ADD:T:S/.asm/.S/}

Index: src/include/fenv.h
diff -u src/include/fenv.h:1.24 src/include/fenv.h:1.25
--- src/include/fenv.h:1.24	Thu Feb 23 02:06:12 2017
+++ src/include/fenv.h	Wed Mar 22 23:11:07 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.h,v 1.24 2017/02/23 02:06:12 scole Exp $	*/
+/*	$NetBSD: fenv.h,v 1.25 2017/03/22 23:11:07 chs Exp $	*/
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,12 +29,7 @@
 
 #include <sys/featuretest.h>
 
-#if !defined(__aarch64__) && !defined(__arm__) && !defined(__i386__) \
-    && !defined(__ia64__) \
-    && !defined(__hppa__) && !defined(__powerpc__) && !defined(__mips__) \
-    && !defined(__or1k__) && !defined(__riscv__) && !defined(__sparc__) \
-    && !defined(__x86_64__) && !defined(__alpha__) && !defined(__sh__) \
-    && !(defined(__m68k__) && !(defined(__mc68010__) || defined(__mcoldfire__)))
+#if defined(__vax__)
 # ifndef __TEST_FENV
 #  error	"fenv.h is currently not supported for this architecture"
 # endif
@@ -45,6 +40,42 @@ typedef int fenv_t;
 # include <machine/fenv.h>
 #endif
 
+#if \
+	(defined(__arm__) && defined(__SOFTFP__)) || \
+	(defined(__m68k__) && !defined(__HAVE_68881__)) || \
+	defined(__mips_soft_float) || \
+	(defined(__powerpc__) && defined(_SOFT_FLOAT)) || \
+	(defined(__sh__) && !defined(__SH_FPU_ANY__)) || \
+	0
+
+/*
+ * Common definitions for softfloat.
+ */
+
+typedef int fexcept_t;
+
+#ifndef __HAVE_FENV_SOFTFLOAT_DEFS
+
+typedef struct {
+	int	__flags;
+	int	__mask;
+	int	__round;
+} fenv_t;
+
+#define __FENV_GET_FLAGS(__envp)	(__envp)->__flags
+#define __FENV_GET_MASK(__envp)		(__envp)->__mask
+#define __FENV_GET_ROUND(__envp)	(__envp)->__round
+#define __FENV_SET_FLAGS(__envp, __val) \
+	(__envp)->__flags = (__val)
+#define __FENV_SET_MASK(__envp, __val) \
+	(__envp)->__mask = (__val)
+#define __FENV_SET_ROUND(__envp, __val) \
+	(__envp)->__round = (__val)
+
+#endif /* __FENV_GET_FLAGS */
+
+#endif /* softfloat */
+
 __BEGIN_DECLS
 
 /* Function prototypes */

Index: src/lib/libc/arch/m68k/gen/Makefile.inc
diff -u src/lib/libc/arch/m68k/gen/Makefile.inc:1.34 src/lib/libc/arch/m68k/gen/Makefile.inc:1.35
--- src/lib/libc/arch/m68k/gen/Makefile.inc:1.34	Fri Oct  7 11:10:44 2016
+++ src/lib/libc/arch/m68k/gen/Makefile.inc	Wed Mar 22 23:11:07 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.34 2016/10/07 11:10:44 christos Exp $
+#	$NetBSD: Makefile.inc,v 1.35 2017/03/22 23:11:07 chs Exp $
 
 SRCS+=	alloca.S fabs.S
 
@@ -31,10 +31,10 @@ CPPFLAGS._lwp.c	+= -D_LIBC_SOURCE
 # 68000-based machines build with a libgcc that includes
 # much of the (soft)float and integer support that would 
 # otherwise be compiled here.
-.if	(${MACHINE_ARCH} == "m68000" || ${MKSOFTFLOAT} == "yes")
+.if	(${MACHINE_ARCH} == "m68000" || ${MKSOFTFLOAT} != "no")
 SRCS+=	compat_modf_ieee754.c			# generic ieee754 version
 SRCS+=	flt_rounds_softfloat.S
-.if ${MKSOFTFLOAT} != "yes"
+.if ${MKSOFTFLOAT} == "no"
 SRCS+=	fpfake.c
 .endif
 .endif

Index: src/lib/libc/arch/sh3/Makefile.inc
diff -u src/lib/libc/arch/sh3/Makefile.inc:1.6 src/lib/libc/arch/sh3/Makefile.inc:1.7
--- src/lib/libc/arch/sh3/Makefile.inc:1.6	Sat Jun 17 18:04:23 2006
+++ src/lib/libc/arch/sh3/Makefile.inc	Wed Mar 22 23:11:08 2017
@@ -1,6 +1,10 @@
-#	$NetBSD: Makefile.inc,v 1.6 2006/06/17 18:04:23 uwe Exp $
+#	$NetBSD: Makefile.inc,v 1.7 2017/03/22 23:11:08 chs Exp $
 
 SRCS+=	__sigaction14_sigtramp.c __sigtramp2.S
 
+.if ${MKSOFTFLOAT} != "no"
+
 CPPFLAGS+=      -DSOFTFLOAT # -DSOFTFLOAT_NEED_FIXUNS
 .include <softfloat/Makefile.inc>
+
+.endif

Index: src/lib/libm/Makefile
diff -u src/lib/libm/Makefile:1.188 src/lib/libm/Makefile:1.189
--- src/lib/libm/Makefile:1.188	Thu Feb 23 02:05:30 2017
+++ src/lib/libm/Makefile	Wed Mar 22 23:11:08 2017
@@ -1,4 +1,4 @@
-#  $NetBSD: Makefile,v 1.188 2017/02/23 02:05:30 scole Exp $
+#  $NetBSD: Makefile,v 1.189 2017/03/22 23:11:08 chs Exp $
 #
 #  @(#)Makefile 5.1beta 93/09/24
 #
@@ -57,7 +57,9 @@ LINTFLAGS += -g
 .PATH: ${.CURDIR}/arch/aarch64
 ARCH_SRCS = e_sqrt.S e_sqrtf.S s_fabsf.S
 ARCH_SRCS+= s_fma.S s_fmaf.S s_fmax.S s_fmaxf.S s_fmin.S s_fminf.S
+.if ${MKSOFTFLOAT} == "no"
 COMMON_SRCS+= fenv.c
+.endif
 COMMON_SRCS+= e_sqrtl.c
 COMMON_SRCS+= s_fma.c s_fmaf.c s_fmal.c
 .elif (${LIBC_MACHINE_ARCH} == "alpha")
@@ -67,8 +69,10 @@ COMMON_SRCS+= fenv.c
 COPTS+=	-mfloat-ieee -mieee-with-inexact -mfp-trap-mode=sui -mtrap-precision=i
 .elif (${LIBC_MACHINE_CPU} == "arm")
 .PATH.c: ${.CURDIR}/arch/arm
-COMMON_SRCS+= fenv.c s_nexttowardf.c \
-	s_nearbyint.c s_rintl.c
+.if ${MKSOFTFLOAT} == "no"
+COMMON_SRCS+= fenv.c
+.endif
+COMMON_SRCS+= s_nexttowardf.c s_nearbyint.c s_rintl.c
 .for f in fenv.c lrint.S lrintf.S s_fabsf.S s_fma.S s_fmaf.S
 COPTS.$f +=	-mfpu=vfp
 .endfor
@@ -82,16 +86,15 @@ ARCH_SRCS = e_sqrt.S e_sqrtf.S lrint.S l
 COMMON_SRCS += fenv.c
 .elif (${LIBC_MACHINE_ARCH} == "hppa")
 .PATH.c: ${.CURDIR}/arch/hppa
-COMMON_SRCS+= fenv.c s_nexttowardf.c \
-	s_nearbyint.c s_rintl.c
+COMMON_SRCS+= fenv.c s_nexttowardf.c s_nearbyint.c s_rintl.c
 .elif (${LIBC_MACHINE_ARCH} == "sparc")
 .PATH: ${.CURDIR}/arch/sparc
 COMMON_SRCS+= fenv.c
 COMMON_SRCS+= s_fma.c s_fmaf.c s_fmal.c
 .elif (${LIBC_MACHINE_ARCH} == "sparc64")
 .PATH: ${.CURDIR}/arch/sparc64
-COMMON_SRCS+= fenv.c s_nexttowardf.c \
-	s_nearbyint.c s_rintl.c
+COMMON_SRCS+= fenv.c
+COMMON_SRCS+= s_nexttowardf.c s_nearbyint.c s_rintl.c
 .ifndef _COMPAT_M32_MK_
 COMMON_SRCS+= s_nexttoward.c
 .endif
@@ -137,7 +140,7 @@ ARCH_SRCS += s_ceil.S s_copysign.S s_fin
 COPTS+=-m68040
 ARCH_SRCS = s_copysign.S s_finite.S
 .else
-.if (${MKSOFTFLOAT} != "yes")
+.if (${MKSOFTFLOAT} == "no")
 .PATH:	${.CURDIR}/arch/mc68881 ${.CURDIR}/arch/m68k
 ARCH_SRCS = e_acos.S e_asin.S e_atanh.S e_cosh.S e_exp.S e_fmod.S e_log.S \
 	    e_log10.S e_remainder.S e_scalb.S e_sinh.S e_sqrt.S s_atan.S \
@@ -160,9 +163,8 @@ WARNS?=5
 .elif (${LIBC_MACHINE_CPU} == "riscv")
 .PATH:	${.CURDIR}/arch/riscv
 
-COMMON_SRCS += fenv.c
-
 .if ${MKSOFTFLOAT} == "no"
+COMMON_SRCS += fenv.c
 ARCH_SRCS = e_sqrt.S e_sqrtf.S
 ARCH_SRCS += s_copysign.S s_copysignf.S
 ARCH_SRCS += s_fabs.S s_fabsf.S
@@ -172,14 +174,20 @@ ARCH_SRCS += s_fmin.S s_fminf.S
 .endif
 .elif (${LIBC_MACHINE_ARCH} == "powerpc")
 .PATH:	${.CURDIR}/arch/powerpc
+.if ${MKSOFTFLOAT} == "no"
 COMMON_SRCS += fenv.c
+.endif
 .elif (${LIBC_MACHINE_CPU} == "mips")
 .PATH:	${.CURDIR}/arch/mips
+.if ${MKSOFTFLOAT} == "no"
 COMMON_SRCS += fenv.c
+.endif
 .elif (${LIBC_MACHINE_CPU} == "sh3")
 .PATH:	${.CURDIR}/arch/sh3
+.if ${MKSOFTFLOAT} == "no"
 COMMON_SRCS += fenv.c
 .endif
+.endif
 
 WARNS?=5
 
@@ -198,6 +206,27 @@ COPTS+=	-fno-strict-aliasing
 .endif
 CPPFLAGS+=-DLIBM_SCCS
 
+.if ${MKSOFTFLOAT} != "no"
+.PATH:	${.CURDIR}/softfloat
+.include "${.CURDIR}/../libc/libcincludes.mk"
+CPPFLAGS+=	-I${ARCHDIR}/softfloat
+COMMON_SRCS += \
+	feclearexcept.c \
+	fedisableexcept.c \
+	feenableexcept.c \
+	fegetenv.c \
+	fegetexcept.c \
+	fegetexceptflag.c \
+	fegetround.c \
+	feholdexcept.c \
+	feraiseexcept.c \
+	fesetenv.c \
+	fesetexceptflag.c \
+	fesetround.c \
+	fetestexcept.c \
+	feupdateenv.c
+.endif
+
 LIB=	m
 COMMON_SRCS+= b_exp.c b_log.c b_tgamma.c \
 	e_acos.c e_acosf.c e_acosh.c e_acoshf.c e_asin.c e_asinf.c \

Index: src/lib/libm/arch/aarch64/fenv.c
diff -u src/lib/libm/arch/aarch64/fenv.c:1.2 src/lib/libm/arch/aarch64/fenv.c:1.3
--- src/lib/libm/arch/aarch64/fenv.c:1.2	Sat Dec 27 17:52:45 2014
+++ src/lib/libm/arch/aarch64/fenv.c	Wed Mar 22 23:11:08 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fenv.c,v 1.2 2014/12/27 17:52:45 martin Exp $ */
+/* $NetBSD: fenv.c,v 1.3 2017/03/22 23:11:08 chs Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,9 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.2 2014/12/27 17:52:45 martin Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.3 2017/03/22 23:11:08 chs Exp $");
+
+#include "namespace.h"
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -42,6 +44,23 @@ __RCSID("$NetBSD: fenv.c,v 1.2 2014/12/2
 
 #include <aarch64/armreg.h>
 
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
+
 const fenv_t __fe_dfl_env = {
 	.__fpsr = 0,
 	.__fpcr = FPCR_FZ|FPCR_DN|FPCR_RN,
@@ -87,35 +106,12 @@ feraiseexcept(int excepts)
 #ifndef lint
 	_DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0);
 #endif
-#ifdef __SOFTFP__
-	excepts &= fpgetsticky();
-
-	if (excepts) {
-		siginfo_t info;
-		memset(&info, 0, sizeof info);
-		info.si_signo = SIGFPE;
-		info.si_pid = getpid();
-		info.si_uid = geteuid();
-		if (excepts & FE_UNDERFLOW)
-			info.si_code = FPE_FLTUND;
-		else if (excepts & FE_OVERFLOW)
-			info.si_code = FPE_FLTOVF;
-		else if (excepts & FE_DIVBYZERO)
-			info.si_code = FPE_FLTDIV;
-		else if (excepts & FE_INVALID)
-			info.si_code = FPE_FLTINV;
-		else if (excepts & FE_INEXACT)
-			info.si_code = FPE_FLTRES;
-		sigqueueinfo(getpid(), &info);
-	}
-#else
 	unsigned int fpsr = reg_fpsr_read();
 	fpsr = (fpsr & ~FPSR_CSUM) | __SHIFTIN(excepts, FPSR_CSUM);
 	reg_fpsr_write(fpsr);
 	unsigned int fpcr = reg_fpcr_read();
 	fpcr = (fpcr & ~FPCR_ESUM) | __SHIFTIN(excepts, FPCR_ESUM);
 	reg_fpcr_write(fpcr);
-#endif
 	return 0;
 }
 

Index: src/lib/libm/arch/alpha/fenv.c
diff -u src/lib/libm/arch/alpha/fenv.c:1.1 src/lib/libm/arch/alpha/fenv.c:1.2
--- src/lib/libm/arch/alpha/fenv.c:1.1	Tue Aug 23 10:00:15 2016
+++ src/lib/libm/arch/alpha/fenv.c	Wed Mar 22 23:11:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.c,v 1.1 2016/08/23 10:00:15 christos Exp $	*/
+/*	$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:08 chs Exp $	*/
 
 /*-
  * Copyright (c) 2004-2005 David Schultz <d...@freebsd.org>
@@ -28,16 +28,23 @@
  * $FreeBSD: src/lib/msun/alpha/fenv.c,v 1.2 2005/03/16 19:03:44 das Exp $
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.1 2016/08/23 10:00:15 christos Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:08 chs Exp $");
+
+#include "namespace.h"
 
-#ifdef __weak_alias
-#define feenableexcept _feenableexcept
-#define fedisableexcept _fedisableexcept
-#define fegetexcept _fegetexcept
-#endif
 #include <machine/sysarch.h>
 #include <fenv.h>
 
+#ifdef __weak_alias
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(feupdateenv,_feupdateenv)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(fegetexcept,_fegetexcept)
+#endif
+
 const fenv_t __fe_dfl_env = 0x680e000000000000ULL;
 
 /*
@@ -112,12 +119,6 @@ feupdateenv(const fenv_t *envp)
 	return 0; 
 }
 
-#ifdef __weak_alias
-__weak_alias(feenableexcept, _feenableexcept);
-__weak_alias(fedisableexcept, _fedisableexcept);
-__weak_alias(fegetexcept, _fegetexcept);
-#endif
-
 int
 feenableexcept(int mask)
 {

Index: src/lib/libm/arch/arm/fenv.c
diff -u src/lib/libm/arch/arm/fenv.c:1.6 src/lib/libm/arch/arm/fenv.c:1.7
--- src/lib/libm/arch/arm/fenv.c:1.6	Mon Dec 29 19:11:13 2014
+++ src/lib/libm/arch/arm/fenv.c	Wed Mar 22 23:11:08 2017
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.6 2014/12/29 19:11:13 martin Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.7 2017/03/22 23:11:08 chs Exp $");
 
 #include <sys/types.h>
 #include <assert.h>
@@ -38,13 +38,10 @@ __RCSID("$NetBSD: fenv.c,v 1.6 2014/12/2
 #include <inttypes.h>
 
 #ifdef __SOFTFP__
-#include <ieeefp.h>
-#include <sys/signal.h>
-#include <sys/siginfo.h>
-#else
-#include <arm/armreg.h>
+#error This fenv implementation is only for hardfloat.
 #endif
 
+#include <arm/armreg.h>
 #include <arm/vfpreg.h>
 
 const fenv_t __fe_dfl_env = VFP_FPSCR_FZ|VFP_FPSCR_DN|VFP_FPSCR_RN;
@@ -59,14 +56,9 @@ feclearexcept(int excepts)
 #ifndef lint
 	_DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0);
 #endif
-#ifdef __SOFTFP__
-	fpsetsticky(fpgetsticky() & ~excepts);
-	return 0;
-#else
 	int tmp = armreg_fpscr_read() & ~__SHIFTIN(excepts, VFP_FPSCR_CSUM);
 	armreg_fpscr_write(tmp);
 	return 0;
-#endif
 }
 
 /*
@@ -78,12 +70,9 @@ feclearexcept(int excepts)
 int
 fegetexceptflag(fexcept_t *flagp, int excepts)
 {
+
 	_DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0);
-#ifdef __SOFTFP__
-	*flagp = fpgetsticky() & excepts;
-#else
 	*flagp = __SHIFTOUT(armreg_fpscr_read(), VFP_FPSCR_CSUM) & excepts;
-#endif
 	return 0;
 }
 
@@ -98,32 +87,9 @@ feraiseexcept(int excepts)
 #ifndef lint
 	_DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0);
 #endif
-#ifdef __SOFTFP__
-	excepts &= fpgetsticky();
-
-	if (excepts) {
-		siginfo_t info;
-		memset(&info, 0, sizeof info);
-		info.si_signo = SIGFPE;
-		info.si_pid = getpid();
-		info.si_uid = geteuid();
-		if (excepts & FE_UNDERFLOW)
-			info.si_code = FPE_FLTUND;
-		else if (excepts & FE_OVERFLOW)
-			info.si_code = FPE_FLTOVF;
-		else if (excepts & FE_DIVBYZERO)
-			info.si_code = FPE_FLTDIV;
-		else if (excepts & FE_INVALID)
-			info.si_code = FPE_FLTINV;
-		else if (excepts & FE_INEXACT)
-			info.si_code = FPE_FLTRES;
-		sigqueueinfo(getpid(), &info);
-	}
-#else
 	int fpscr = armreg_fpscr_read();
-	fpscr = (fpscr & ~VFP_FPSCR_ESUM) | __SHIFTIN(excepts, VFP_FPSCR_ESUM);
+	fpscr |= __SHIFTIN(excepts, VFP_FPSCR_CSUM);
 	armreg_fpscr_write(fpscr);
-#endif
 	return 0;
 }
 
@@ -142,14 +108,10 @@ fesetexceptflag(const fexcept_t *flagp, 
 #ifndef lint
 	_DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0);
 #endif
-#ifdef __SOFTFP__
-	fpsetsticky((fpgetsticky() & ~excepts) | (excepts & *flagp));
-#else
 	int fpscr = armreg_fpscr_read();
 	fpscr &= ~__SHIFTIN(excepts, VFP_FPSCR_CSUM);
 	fpscr |= __SHIFTIN((*flagp & excepts), VFP_FPSCR_CSUM);
 	armreg_fpscr_write(fpscr);
-#endif
 	return 0;
 }
 
@@ -159,15 +121,9 @@ feenableexcept(int excepts)
 #ifndef lint
 	_DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0);
 #endif
-#ifdef __SOFTFP__
-	int old = fpgetmask();
-	fpsetmask(old | excepts);
-	return old;
-#else
 	int fpscr = armreg_fpscr_read();
 	armreg_fpscr_write(fpscr | __SHIFTIN((excepts), VFP_FPSCR_ESUM));
 	return __SHIFTOUT(fpscr, VFP_FPSCR_ESUM) & FE_ALL_EXCEPT;
-#endif
 }
 
 int
@@ -176,15 +132,9 @@ fedisableexcept(int excepts)
 #ifndef lint
 	_DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0);
 #endif
-#ifdef __SOFTFP__
-	int old = fpgetmask();
-	fpsetmask(old & ~excepts);
-	return old;
-#else
 	int fpscr = armreg_fpscr_read();
 	armreg_fpscr_write(fpscr & ~__SHIFTIN((excepts), VFP_FPSCR_ESUM));
 	return __SHIFTOUT(fpscr, VFP_FPSCR_ESUM) & FE_ALL_EXCEPT;
-#endif
 }
 
 /*
@@ -196,21 +146,13 @@ int
 fetestexcept(int excepts)
 {
 	_DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0);
-#ifdef __SOFTFP__
-	return fpgetsticky() & excepts;
-#else
 	return __SHIFTOUT(armreg_fpscr_read(), VFP_FPSCR_CSUM) & excepts;
-#endif
 }
 
 int     
 fegetexcept(void)
 {
-#ifdef __SOFTFP__
-	return fpgetmask();
-#else
 	return __SHIFTOUT(armreg_fpscr_read(), VFP_FPSCR_ESUM);
-#endif
 }
 
 /*
@@ -219,11 +161,7 @@ fegetexcept(void)
 int
 fegetround(void)
 {
-#ifdef __SOFTFP__
-	return fpgetround();
-#else
 	return __SHIFTOUT(armreg_fpscr_read(), VFP_FPSCR_RMODE);
-#endif
 }
 
 /*
@@ -237,13 +175,9 @@ fesetround(int round)
 #ifndef lint
 	_DIAGASSERT(!(round & ~__SHIFTOUT(VFP_FPSCR_RMODE, VFP_FPSCR_RMODE)));
 #endif
-#ifdef __SOFTFP__
-	(void)fpsetround(round);
-#else
 	int fpscr = armreg_fpscr_read() & ~VFP_FPSCR_RMODE;
 	fpscr |= __SHIFTIN(round, VFP_FPSCR_RMODE);
 	armreg_fpscr_write(fpscr);
-#endif
 	return 0;
 }
 
@@ -254,13 +188,8 @@ fesetround(int round)
 int
 fegetenv(fenv_t *envp)
 {
-#ifdef __SOFTFP__
-	*envp = __SHIFTIN(fpgetround(), VFP_FPSCR_RMODE)
-	    | __SHIFTIN(fpgetmask(), VFP_FPSCR_ESUM)
-	    | __SHIFTIN(fpgetsticky(), VFP_FPSCR_CSUM);
-#else
+
 	*envp = armreg_fpscr_read();
-#endif
 	return 0;
 }
 
@@ -273,16 +202,9 @@ fegetenv(fenv_t *envp)
 int
 feholdexcept(fenv_t *envp)
 {
-#ifdef __SOFTFP__
-	*envp = __SHIFTIN(fpgetround(), VFP_FPSCR_RMODE)
-	    | __SHIFTIN(fpgetmask(), VFP_FPSCR_ESUM)
-	    | __SHIFTIN(fpgetsticky(), VFP_FPSCR_CSUM);
-	fpsetmask(0);
-	fpsetsticky(0);
-#else
+
 	*envp = armreg_fpscr_read();
 	armreg_fpscr_write((*envp) & ~(VFP_FPSCR_ESUM|VFP_FPSCR_CSUM));
-#endif
 	return 0;
 }
 
@@ -295,13 +217,8 @@ feholdexcept(fenv_t *envp)
 int
 fesetenv(const fenv_t *envp)
 {
-#ifdef __SOFTFP__
-	(void)fpsetround(__SHIFTIN(*envp, VFP_FPSCR_RMODE));
-	(void)fpsetmask(__SHIFTOUT(*envp, VFP_FPSCR_ESUM));
-	(void)fpsetsticky(__SHIFTOUT(*envp, VFP_FPSCR_CSUM));
-#else
+
 	armreg_fpscr_write(*envp);
-#endif
 	return 0;
 }
 
@@ -317,15 +234,10 @@ feupdateenv(const fenv_t *envp)
 #ifndef lint
 	_DIAGASSERT(envp != NULL);
 #endif
-#ifdef __SOFTFP__
-	(void)fpsetround(__SHIFTIN(*envp, VFP_FPSCR_RMODE));
-	(void)fpsetmask(fpgetmask() | __SHIFTOUT(*envp, VFP_FPSCR_ESUM));
-	(void)fpsetsticky(fpgetsticky() | __SHIFTOUT(*envp, VFP_FPSCR_CSUM));
-#else
-	int fpscr = armreg_fpscr_read() & ~(VFP_FPSCR_ESUM|VFP_FPSCR_CSUM);
+	int fpscr = armreg_fpscr_read();
+	fpscr &= ~(VFP_FPSCR_ESUM|VFP_FPSCR_RMODE);
 	fpscr |= *envp;
 	armreg_fpscr_write(fpscr);
-#endif
 
 	/* Success */
 	return 0;

Index: src/lib/libm/arch/hppa/fenv.c
diff -u src/lib/libm/arch/hppa/fenv.c:1.3 src/lib/libm/arch/hppa/fenv.c:1.4
--- src/lib/libm/arch/hppa/fenv.c:1.3	Sun Mar 20 14:22:46 2016
+++ src/lib/libm/arch/hppa/fenv.c	Wed Mar 22 23:11:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.c,v 1.3 2016/03/20 14:22:46 skrll Exp $	*/
+/*	$NetBSD: fenv.c,v 1.4 2017/03/22 23:11:08 chs Exp $	*/
 
 /*-
  * Copyright (c) 2004-2005 David Schultz <d...@freebsd.org>
@@ -24,11 +24,30 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.3 2016/03/20 14:22:46 skrll Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.4 2017/03/22 23:11:08 chs Exp $");
+
+#include "namespace.h"
 
 #include <assert.h>
 #include <fenv.h>
 
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
+
 /*
  * Convert from exception flags (__BITS(27,32)) to exception enable bits
  * (__BITS(5,0)) by right-shifting this much:

Index: src/lib/libm/arch/i387/fenv.c
diff -u src/lib/libm/arch/i387/fenv.c:1.7 src/lib/libm/arch/i387/fenv.c:1.8
--- src/lib/libm/arch/i387/fenv.c:1.7	Wed Feb 17 19:54:11 2016
+++ src/lib/libm/arch/i387/fenv.c	Wed Mar 22 23:11:08 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fenv.c,v 1.7 2016/02/17 19:54:11 christos Exp $ */
+/* $NetBSD: fenv.c,v 1.8 2017/03/22 23:11:08 chs Exp $ */
 
 /*-
  * Copyright (c) 2004-2005 David Schultz <d...@freebsd.org>
@@ -27,7 +27,9 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.7 2016/02/17 19:54:11 christos Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.8 2017/03/22 23:11:08 chs Exp $");
+
+#include "namespace.h"
 
 #include <sys/param.h>
 #include <sys/sysctl.h>
@@ -36,6 +38,23 @@ __RCSID("$NetBSD: fenv.c,v 1.7 2016/02/1
 #include <stddef.h>
 #include <string.h>
 
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
+
 /* Load x87 Control Word */
 #define	__fldcw(__cw)		__asm__ __volatile__	\
 	("fldcw %0" : : "m" (__cw))

Index: src/lib/libm/arch/ia64/fenv.c
diff -u src/lib/libm/arch/ia64/fenv.c:1.1 src/lib/libm/arch/ia64/fenv.c:1.2
--- src/lib/libm/arch/ia64/fenv.c:1.1	Thu Feb 23 02:05:30 2017
+++ src/lib/libm/arch/ia64/fenv.c	Wed Mar 22 23:11:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.c,v 1.1 2017/02/23 02:05:30 scole Exp $	*/
+/*	$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:08 chs Exp $	*/
 
 /*-
  * Copyright (c) 2004 David Schultz <d...@freebsd.org>
@@ -29,10 +29,29 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.1 2017/02/23 02:05:30 scole Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:08 chs Exp $");
+
+#include "namespace.h"
 
 #define	__fenv_static
-#include "fenv.h"
+#include <fenv.h>
+
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
 
 #if defined(__GNUC_GNU_INLINE__) && !defined(__lint__)
 #error "This file must be compiled with C99 'inline' semantics"

Index: src/lib/libm/arch/m68k/fenv.c
diff -u src/lib/libm/arch/m68k/fenv.c:1.1 src/lib/libm/arch/m68k/fenv.c:1.2
--- src/lib/libm/arch/m68k/fenv.c:1.1	Thu Dec 24 14:12:12 2015
+++ src/lib/libm/arch/m68k/fenv.c	Wed Mar 22 23:11:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.c,v 1.1 2015/12/24 14:12:12 christos Exp $	*/
+/*	$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:08 chs Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -29,10 +29,29 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.1 2015/12/24 14:12:12 christos Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:08 chs Exp $");
+
+#include "namespace.h"
 
 #define	__fenv_static
-#include "fenv.h"
+#include <fenv.h>
+
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
 
 #if defined(__GNUC_GNU_INLINE__) && !defined(__lint__)
 #error "This file must be compiled with C99 'inline' semantics"
@@ -49,3 +68,6 @@ extern inline int fegetenv(fenv_t *__env
 extern inline int feholdexcept(fenv_t *__envp);
 extern inline int fesetenv(const fenv_t *__envp);
 extern inline int feupdateenv(const fenv_t *__envp);
+extern inline int feenableexcept(int __excepts);
+extern inline int fedisableexcept(int __excepts);
+extern inline int fegetexcept(void);

Index: src/lib/libm/arch/mips/fenv.c
diff -u src/lib/libm/arch/mips/fenv.c:1.2 src/lib/libm/arch/mips/fenv.c:1.3
--- src/lib/libm/arch/mips/fenv.c:1.2	Mon Jan 11 01:34:39 2016
+++ src/lib/libm/arch/mips/fenv.c	Wed Mar 22 23:11:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.c,v 1.2 2016/01/11 01:34:39 christos Exp $	*/
+/*	$NetBSD: fenv.c,v 1.3 2017/03/22 23:11:08 chs Exp $	*/
 
 /*-
  * Copyright (c) 2004 David Schultz <d...@freebsd.org>
@@ -28,10 +28,29 @@
  * $FreeBSD: head/lib/msun/mips/fenv.c 226415 2011-10-16 05:37:56Z das $
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.2 2016/01/11 01:34:39 christos Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.3 2017/03/22 23:11:08 chs Exp $");
+
+#include "namespace.h"
 
 #define	__fenv_static
-#include "fenv.h"
+#include <fenv.h>
+
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
 
 #if defined(__GNUC_GNU_INLINE__) && !defined(__lint__)
 #error "This file must be compiled with C99 'inline' semantics"
@@ -54,3 +73,6 @@ extern inline int fegetenv(fenv_t *__env
 extern inline int feholdexcept(fenv_t *__envp);
 extern inline int fesetenv(const fenv_t *__envp);
 extern inline int feupdateenv(const fenv_t *__envp);
+extern inline int feenableexcept(int __excepts);
+extern inline int fedisableexcept(int __excepts);
+extern inline int fegetexcept(void);

Index: src/lib/libm/arch/powerpc/fenv.c
diff -u src/lib/libm/arch/powerpc/fenv.c:1.1 src/lib/libm/arch/powerpc/fenv.c:1.2
--- src/lib/libm/arch/powerpc/fenv.c:1.1	Sun Dec 20 16:24:25 2015
+++ src/lib/libm/arch/powerpc/fenv.c	Wed Mar 22 23:11:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.c,v 1.1 2015/12/20 16:24:25 christos Exp $	*/
+/*	$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:08 chs Exp $	*/
 
 /*-
  * Copyright (c) 2004 David Schultz <d...@freebsd.org>
@@ -28,10 +28,29 @@
  * $FreeBSD: head/lib/msun/powerpc/fenv.c 226415 2011-10-16 05:37:56Z das $
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.1 2015/12/20 16:24:25 christos Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:08 chs Exp $");
+
+#include "namespace.h"
 
 #define	__fenv_static
-#include "fenv.h"
+#include <fenv.h>
+
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
 
 #if defined(__GNUC_GNU_INLINE__) && !defined(__lint__)
 #error "This file must be compiled with C99 'inline' semantics"
@@ -50,3 +69,6 @@ extern inline int fegetenv(fenv_t *__env
 extern inline int feholdexcept(fenv_t *__envp);
 extern inline int fesetenv(const fenv_t *__envp);
 extern inline int feupdateenv(const fenv_t *__envp);
+extern inline int feenableexcept(int __excepts);
+extern inline int fedisableexcept(int __excepts);
+extern inline int fegetexcept(void);

Index: src/lib/libm/arch/riscv/fenv.c
diff -u src/lib/libm/arch/riscv/fenv.c:1.1 src/lib/libm/arch/riscv/fenv.c:1.2
--- src/lib/libm/arch/riscv/fenv.c:1.1	Fri Sep 19 17:36:25 2014
+++ src/lib/libm/arch/riscv/fenv.c	Wed Mar 22 23:11:08 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fenv.c,v 1.1 2014/09/19 17:36:25 matt Exp $ */
+/* $NetBSD: fenv.c,v 1.2 2017/03/22 23:11:08 chs Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,9 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.1 2014/09/19 17:36:25 matt Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:08 chs Exp $");
+
+#include "namespace.h"
 
 #include <sys/param.h>
 #include <sys/sysctl.h>
@@ -41,6 +43,23 @@ __RCSID("$NetBSD: fenv.c,v 1.1 2014/09/1
 
 #include <riscv/sysreg.h>
 
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
+
 /*
  * The following constant represents the default floating-point environment
  * (that is, the one installed at program startup) and has type pointer to
@@ -50,7 +69,7 @@ __RCSID("$NetBSD: fenv.c,v 1.1 2014/09/1
  * that manage the floating-point environment, namely fesetenv() and
  * feupdateenv().
  */
-fenv_t __fe_dfl_env = __SHIFTIN(FCSR_FRM_RNE, FCSR_FRM);
+const fenv_t __fe_dfl_env = __SHIFTIN(FCSR_FRM_RNE, FCSR_FRM);
 
 /*
  * The feclearexcept() function clears the supported floating-point exceptions

Index: src/lib/libm/arch/sh3/fenv.c
diff -u src/lib/libm/arch/sh3/fenv.c:1.1 src/lib/libm/arch/sh3/fenv.c:1.2
--- src/lib/libm/arch/sh3/fenv.c:1.1	Thu Aug 25 12:15:28 2016
+++ src/lib/libm/arch/sh3/fenv.c	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.c,v 1.1 2016/08/25 12:15:28 christos Exp $	*/
+/*	$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:09 chs Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -29,10 +29,29 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.1 2016/08/25 12:15:28 christos Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
 
 #define	__fenv_static
-#include "fenv.h"
+#include <fenv.h>
+
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
 
 #if defined(__GNUC_GNU_INLINE__) && !defined(__lint__)
 #error "This file must be compiled with C99 'inline' semantics"

Index: src/lib/libm/arch/sparc/fenv.c
diff -u src/lib/libm/arch/sparc/fenv.c:1.1 src/lib/libm/arch/sparc/fenv.c:1.2
--- src/lib/libm/arch/sparc/fenv.c:1.1	Fri May 20 21:42:49 2011
+++ src/lib/libm/arch/sparc/fenv.c	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.c,v 1.1 2011/05/20 21:42:49 nakayama Exp $	*/
+/*	$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:09 chs Exp $	*/
 
 /*-
  * Copyright (c) 2004-2005 David Schultz <d...@freebsd.org>
@@ -24,11 +24,30 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.1 2011/05/20 21:42:49 nakayama Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.2 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
 
 #include <assert.h>
 #include <fenv.h>
 
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
+
 /* Load floating-point state register (32bits) */
 #define	__ldfsr(__r)	__asm__	__volatile__		\
 	("ld %0, %%fsr" : : "m" (__r))

Index: src/lib/libm/arch/sparc64/fenv.c
diff -u src/lib/libm/arch/sparc64/fenv.c:1.2 src/lib/libm/arch/sparc64/fenv.c:1.3
--- src/lib/libm/arch/sparc64/fenv.c:1.2	Fri May 20 21:42:49 2011
+++ src/lib/libm/arch/sparc64/fenv.c	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.c,v 1.2 2011/05/20 21:42:49 nakayama Exp $	*/
+/*	$NetBSD: fenv.c,v 1.3 2017/03/22 23:11:09 chs Exp $	*/
 
 /*-
  * Copyright (c) 2004-2005 David Schultz <d...@freebsd.org>
@@ -24,11 +24,30 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.2 2011/05/20 21:42:49 nakayama Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.3 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
 
 #include <assert.h>
 #include <fenv.h>
 
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
+
 #ifdef __arch64__
 
 /* Load floating-point state register (all 64bits) */

Index: src/lib/libm/arch/x86_64/fenv.c
diff -u src/lib/libm/arch/x86_64/fenv.c:1.6 src/lib/libm/arch/x86_64/fenv.c:1.7
--- src/lib/libm/arch/x86_64/fenv.c:1.6	Mon Nov 11 00:31:51 2013
+++ src/lib/libm/arch/x86_64/fenv.c	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: fenv.c,v 1.6 2013/11/11 00:31:51 joerg Exp $ */
+/* $NetBSD: fenv.c,v 1.7 2017/03/22 23:11:09 chs Exp $ */
 
 /*-
  * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG>
@@ -27,13 +27,32 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: fenv.c,v 1.6 2013/11/11 00:31:51 joerg Exp $");
+__RCSID("$NetBSD: fenv.c,v 1.7 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
 
 #include <assert.h>
 #include <fenv.h>
 #include <stddef.h>
 #include <string.h>
 
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+__weak_alias(fedisableexcept,_fedisableexcept)
+__weak_alias(feenableexcept,_feenableexcept)
+__weak_alias(fegetenv,_fegetenv)
+__weak_alias(fegetexcept,_fegetexcept)
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+__weak_alias(fegetround,_fegetround)
+__weak_alias(feholdexcept,_feholdexcept)
+__weak_alias(feraiseexcept,_feraiseexcept)
+__weak_alias(fesetenv,_fesetenv)
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+__weak_alias(fesetround,_fesetround)
+__weak_alias(fetestexcept,_fetestexcept)
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
+
 /* Load x87 Control Word */
 #define	__fldcw(__cw)		__asm__ __volatile__ \
 	("fldcw %0" : : "m" (__cw))

Index: src/lib/libm/src/namespace.h
diff -u src/lib/libm/src/namespace.h:1.13 src/lib/libm/src/namespace.h:1.14
--- src/lib/libm/src/namespace.h:1.13	Fri Nov 14 14:53:17 2014
+++ src/lib/libm/src/namespace.h	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: namespace.h,v 1.13 2014/11/14 14:53:17 joerg Exp $ */
+/* $NetBSD: namespace.h,v 1.14 2017/03/22 23:11:09 chs Exp $ */
 
 #define atan2 _atan2
 #define atan2f _atan2f
@@ -73,3 +73,18 @@
 
 #define erfl	_erfl
 #define erfcl	_erfcl
+
+#define feclearexcept _feclearexcept
+#define fedisableexcept _fedisableexcept
+#define feenableexcept _feenableexcept
+#define fegetenv _fegetenv
+#define fegetexcept _fegetexcept
+#define fegetexceptflag _fegetexceptflag
+#define fegetround _fegetround
+#define feholdexcept _feholdexcept
+#define feraiseexcept _feraiseexcept
+#define fesetenv _fesetenv
+#define fesetexceptflag _fesetexceptflag
+#define fesetround _fesetround
+#define fetestexcept _fetestexcept
+#define feupdateenv _feupdateenv

Index: src/share/mk/bsd.own.mk
diff -u src/share/mk/bsd.own.mk:1.1006 src/share/mk/bsd.own.mk:1.1007
--- src/share/mk/bsd.own.mk:1.1006	Mon Feb 13 16:33:14 2017
+++ src/share/mk/bsd.own.mk	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.own.mk,v 1.1006 2017/02/13 16:33:14 snj Exp $
+#	$NetBSD: bsd.own.mk,v 1.1007 2017/03/22 23:11:09 chs Exp $
 
 # This needs to be before bsd.init.mk
 .if defined(BSD_MK_COMPAT_FILE)
@@ -967,24 +967,25 @@ MKCOMPATMODULES:=	no
 .endif
 
 #
-# Default mips64 to softfloat now.
-# arm is always softfloat unless it isn't
-# emips is always softfloat.
-# coldfire is always softfloat
-# or1k is always softfloat
+# These platforms use softfloat by default.
 #
-.if ${MACHINE_ARCH} == "mips64eb" || ${MACHINE_ARCH} == "mips64el" || \
-    (${MACHINE_CPU} == "arm" && ${MACHINE_ARCH:M*hf*} == "") || \
-    ${MACHINE_ARCH} == "coldfire" || ${MACHINE_CPU} == "or1k" || \
-    ${MACHINE} == "emips"
+.if ${MACHINE_ARCH} == "mips64eb" || ${MACHINE_ARCH} == "mips64el"
 MKSOFTFLOAT?=	yes
 .endif
 
+#
+# These platforms always use softfloat.
+#
+.if (${MACHINE_CPU} == "arm" && ${MACHINE_ARCH:M*hf*} == "") || \
+    ${MACHINE_ARCH} == "coldfire" || ${MACHINE_CPU} == "or1k" || \
+    ${MACHINE} == "emips" || ${MACHINE_CPU} == "sh3"
+MKSOFTFLOAT=	yes
+.endif
+
 .if ${MACHINE} == "emips"
 SOFTFLOAT_BITS=	32
 .endif
 
-
 #
 # We want to build zfs only for amd64 by default for now.
 #
@@ -995,15 +996,15 @@ MKZFS?=		yes
 #
 # DTrace works on amd64, i386 and earm*
 #
-
 .if ${MACHINE_ARCH} == "i386" || \
     ${MACHINE_ARCH} == "x86_64" || \
     !empty(MACHINE_ARCH:Mearm*)
 MKDTRACE?=	yes
 MKCTF?=		yes
 .endif
+
 #
-# PIE is enabled on amd64 by default
+# PIE is enabled on many platforms by default.
 #
 .if ${MACHINE_ARCH} == "i386" || \
     ${MACHINE_ARCH} == "x86_64" || \

Index: src/share/mk/bsd.sys.mk
diff -u src/share/mk/bsd.sys.mk:1.269 src/share/mk/bsd.sys.mk:1.270
--- src/share/mk/bsd.sys.mk:1.269	Tue Feb  7 21:19:13 2017
+++ src/share/mk/bsd.sys.mk	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: bsd.sys.mk,v 1.269 2017/02/07 21:19:13 christos Exp $
+#	$NetBSD: bsd.sys.mk,v 1.270 2017/03/22 23:11:09 chs Exp $
 #
 # Build definitions used for NetBSD source tree builds.
 
@@ -159,8 +159,11 @@ COPTS+=	${${ACTIVE_CC} == "gcc":? --para
 .endif
 
 .if ${MKSOFTFLOAT:Uno} != "no"
+# sh3 defaults to soft-float and specifies hard-float a different way
+.if ${MACHINE_CPU} != "sh3"
 COPTS+=		${${ACTIVE_CC} == "gcc":? -msoft-float :}
 FOPTS+=		-msoft-float
+.endif
 .elif ${MACHINE_ARCH} == "coldfire"
 COPTS+=		-mhard-float
 FOPTS+=		-mhard-float

Index: src/sys/arch/arm/include/fenv.h
diff -u src/sys/arch/arm/include/fenv.h:1.3 src/sys/arch/arm/include/fenv.h:1.4
--- src/sys/arch/arm/include/fenv.h:1.3	Tue Mar 17 12:20:02 2015
+++ src/sys/arch/arm/include/fenv.h	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.h,v 1.3 2015/03/17 12:20:02 joerg Exp $	*/
+/*	$NetBSD: fenv.h,v 1.4 2017/03/22 23:11:09 chs Exp $	*/
 
 /* 
  * Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995
@@ -34,6 +34,29 @@ typedef int fexcept_t;
 #define	FE_DOWNWARD	2	/* round toward negative infinity */
 #define	FE_TOWARDZERO	3	/* round to zero (truncate) */
 
+#ifdef __SOFTFP__
+
+/*
+ * Provide a platform-specific softfloat ABI.
+ */
+
+#include <arm/vfpreg.h>
+
+typedef int fenv_t;
+#define __FENV_GET_FLAGS(__envp)	__SHIFTOUT(*(__envp), VFP_FPSCR_CSUM)
+#define __FENV_GET_MASK(__envp)		__SHIFTOUT(*(__envp), VFP_FPSCR_ESUM)
+#define __FENV_GET_ROUND(__envp)	__SHIFTOUT(*(__envp), VFP_FPSCR_RMODE)
+#define __FENV_SET_FLAGS(__envp, __val) \
+	*(__envp) = __SHIFTIN((__val), VFP_FPSCR_CSUM)
+#define __FENV_SET_MASK(__envp, __val) \
+	*(__envp) = __SHIFTIN((__val), VFP_FPSCR_ESUM)
+#define __FENV_SET_ROUND(__envp, __val) \
+	*(__envp) = __SHIFTIN((__val), VFP_FPSCR_RMODE)
+
+#define __HAVE_FENV_SOFTFLOAT_DEFS
+
+#endif /* __SOFTFP__ */
+
 __BEGIN_DECLS
 
 /* Default floating-point environment */
Index: src/sys/arch/arm/include/ieeefp.h
diff -u src/sys/arch/arm/include/ieeefp.h:1.3 src/sys/arch/arm/include/ieeefp.h:1.4
--- src/sys/arch/arm/include/ieeefp.h:1.3	Tue Apr 23 05:42:23 2013
+++ src/sys/arch/arm/include/ieeefp.h	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieeefp.h,v 1.3 2013/04/23 05:42:23 matt Exp $	*/
+/*	$NetBSD: ieeefp.h,v 1.4 2017/03/22 23:11:09 chs Exp $	*/
 
 /* 
  * Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995
@@ -20,6 +20,12 @@
 
 typedef int fp_except;
 
+/* adjust for FP_* and FE_* value differences */ 
+#define	__FPE(x) (x)
+#define	__FEE(x) (x)
+#define	__FPR(x) (x)
+#define	__FER(x) (x)
+
 /* Bit defines for fp_except */
 
 #define	FP_X_INV	FE_INVALID	/* invalid operation exception */

Index: src/sys/arch/m68k/include/fenv.h
diff -u src/sys/arch/m68k/include/fenv.h:1.5 src/sys/arch/m68k/include/fenv.h:1.6
--- src/sys/arch/m68k/include/fenv.h:1.5	Mon Feb 27 06:47:30 2017
+++ src/sys/arch/m68k/include/fenv.h	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.h,v 1.5 2017/02/27 06:47:30 chs Exp $	*/
+/*	$NetBSD: fenv.h,v 1.6 2017/03/22 23:11:09 chs Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -36,10 +36,6 @@
 #include <m68k/float.h>
 #include <m68k/fpreg.h>
 
-#ifndef __fenv_static   
-#define __fenv_static   static
-#endif
-
 /* Exception bits, from FPSR */
 #define	FE_INEXACT	FPSR_AINEX
 #define	FE_DIVBYZERO	FPSR_ADZ
@@ -59,7 +55,11 @@
 #define _ROUND_MASK	\
     (FE_TONEAREST | FE_TOWARDZERO | FE_DOWNWARD | FE_UPWARD)
 
-#if !defined(__mc68010__) && !defined(__mcoldfire__)
+#if defined(__HAVE_68881__)
+
+#ifndef __fenv_static
+#define __fenv_static   static
+#endif
 
 typedef uint32_t fexcept_t;
 
@@ -261,9 +261,7 @@ feupdateenv(const fenv_t *__envp)
 
 #if defined(_NETBSD_SOURCE) || defined(_GNU_SOURCE)
 
-/* We currently provide no external definitions of the functions below. */
-
-static inline int
+__fenv_static inline int
 feenableexcept(int __mask)
 {
 	fexcept_t __fpcr, __oldmask;
@@ -276,7 +274,7 @@ feenableexcept(int __mask)
 	return __oldmask;
 }
 
-static inline int
+__fenv_static inline int
 fedisableexcept(int __mask)
 {
 	fexcept_t __fpcr, __oldmask;
@@ -289,7 +287,7 @@ fedisableexcept(int __mask)
 	return __oldmask;
 }
 
-static inline int
+__fenv_static inline int
 fegetexcept(void)
 {
 	fexcept_t __fpcr;
@@ -303,6 +301,6 @@ fegetexcept(void)
 
 __END_DECLS
 
-#endif /* !__m68010__ && !__mcoldfire__ */
+#endif /* __HAVE_68881__ */
 
 #endif /* _M68K_FENV_H_ */

Index: src/sys/arch/m68k/include/ieeefp.h
diff -u src/sys/arch/m68k/include/ieeefp.h:1.9 src/sys/arch/m68k/include/ieeefp.h:1.10
--- src/sys/arch/m68k/include/ieeefp.h:1.9	Mon Feb 27 06:47:58 2017
+++ src/sys/arch/m68k/include/ieeefp.h	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieeefp.h,v 1.9 2017/02/27 06:47:58 chs Exp $	*/
+/*	$NetBSD: ieeefp.h,v 1.10 2017/03/22 23:11:09 chs Exp $	*/
 
 /* 
  * Written by J.T. Conklin, Apr 6, 1995
@@ -21,7 +21,9 @@ typedef int fp_except;
 
 /* adjust for FP_* and FE_* value differences */ 
 #define	__FPE(x) ((x) >> 3)
+#define	__FEE(x) ((x) << 3)
 #define	__FPR(x) ((x) >> 4)
+#define	__FER(x) ((x) << 4)
 
 #define FP_X_IMP	__FPE(FE_INEXACT)	/* imprecise (loss of precision) */
 #define FP_X_DZ		__FPE(FE_DIVBYZERO)	/* divide-by-zero exception */

Index: src/sys/arch/mips/include/fenv.h
diff -u src/sys/arch/mips/include/fenv.h:1.3 src/sys/arch/mips/include/fenv.h:1.4
--- src/sys/arch/mips/include/fenv.h:1.3	Mon Feb 27 06:57:16 2017
+++ src/sys/arch/mips/include/fenv.h	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.h,v 1.3 2017/02/27 06:57:16 chs Exp $	*/
+/*	$NetBSD: fenv.h,v 1.4 2017/03/22 23:11:09 chs Exp $	*/
 
 /*-
  * Copyright (c) 2004-2005 David Schultz <d...@freebsd.org>
@@ -33,14 +33,6 @@
 
 #include <sys/stdint.h>
 
-#ifndef	__fenv_static
-#define	__fenv_static	static
-#endif
-
-typedef	uint32_t 	fpu_control_t __attribute__((__mode__(__SI__)));
-typedef	fpu_control_t	fenv_t;
-typedef	fpu_control_t	fexcept_t;
-
 /* Exception flags */
 #define	FE_INEXACT	0x0004
 #define	FE_UNDERFLOW	0x0008
@@ -57,6 +49,17 @@ typedef	fpu_control_t	fexcept_t;
 #define	FE_DOWNWARD	0x0003
 #define	_ROUND_MASK	(FE_TONEAREST | FE_DOWNWARD | \
 			 FE_UPWARD | FE_TOWARDZERO)
+
+#ifndef __mips_soft_float
+
+#ifndef	__fenv_static
+#define	__fenv_static	static
+#endif
+
+typedef	uint32_t 	fpu_control_t __attribute__((__mode__(__SI__)));
+typedef	fpu_control_t	fenv_t;
+typedef	fpu_control_t	fexcept_t;
+
 __BEGIN_DECLS
 
 /* Default floating-point environment */
@@ -200,9 +203,7 @@ feupdateenv(const fenv_t *__envp)
 
 #if defined(_NETBSD_SOURCE) || defined(_GNU_SOURCE)
 
-/* We currently provide no external definitions of the functions below. */
-
-static inline int
+__fenv_static inline int
 feenableexcept(int __excepts)
 {
 	fenv_t __old_fpsr, __new_fpsr;
@@ -215,7 +216,7 @@ feenableexcept(int __excepts)
 	return __old_fpsr;
 }
 
-static inline int
+__fenv_static inline int
 fedisableexcept(int __excepts)
 {
 	fenv_t __old_fpsr, __new_fpsr;
@@ -228,7 +229,7 @@ fedisableexcept(int __excepts)
 	return __old_fpsr;
 }
 
-static inline int
+__fenv_static inline int
 fegetexcept(void)
 {
 	fenv_t __fpsr;
@@ -241,4 +242,6 @@ fegetexcept(void)
 
 __END_DECLS
 
+#endif /* __mips_soft_float */
+
 #endif	/* !_FENV_H_ */

Index: src/sys/arch/mips/include/ieeefp.h
diff -u src/sys/arch/mips/include/ieeefp.h:1.9 src/sys/arch/mips/include/ieeefp.h:1.10
--- src/sys/arch/mips/include/ieeefp.h:1.9	Mon Feb 27 06:56:03 2017
+++ src/sys/arch/mips/include/ieeefp.h	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieeefp.h,v 1.9 2017/02/27 06:56:03 chs Exp $	*/
+/*	$NetBSD: ieeefp.h,v 1.10 2017/03/22 23:11:09 chs Exp $	*/
 
 /*
  * Written by J.T. Conklin, Apr 11, 1995
@@ -20,6 +20,9 @@ typedef unsigned int fp_except;
 
 /* adjust for FP_* and FE_* value differences */ 
 #define	__FPE(x) ((x) >> 2)
+#define	__FEE(x) ((x) << 2)
+#define	__FPR(x) ((x))
+#define	__FER(x) ((x))
 
 #define FP_X_IMP	__FPE(FE_INEXACT)	/* imprecise (loss of precision) */
 #define FP_X_UFL	__FPE(FE_UNDERFLOW)	/* underflow exception */

Index: src/sys/arch/powerpc/include/fenv.h
diff -u src/sys/arch/powerpc/include/fenv.h:1.2 src/sys/arch/powerpc/include/fenv.h:1.3
--- src/sys/arch/powerpc/include/fenv.h:1.2	Mon Feb 27 06:54:42 2017
+++ src/sys/arch/powerpc/include/fenv.h	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.h,v 1.2 2017/02/27 06:54:42 chs Exp $	*/
+/*	$NetBSD: fenv.h,v 1.3 2017/03/22 23:11:09 chs Exp $	*/
 
 /*-
  * Copyright (c) 2004-2005 David Schultz <d...@freebsd.org>
@@ -33,13 +33,6 @@
 
 #include <sys/stdint.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
@@ -77,6 +70,15 @@ typedef	uint32_t	fexcept_t;
 #define	_ROUND_MASK	(FE_TONEAREST | FE_DOWNWARD | \
 			 FE_UPWARD | FE_TOWARDZERO)
 
+#ifndef _SOFT_FLOAT
+
+#ifndef	__fenv_static
+#define	__fenv_static	static
+#endif
+
+typedef	uint32_t	fenv_t;
+typedef	uint32_t	fexcept_t;
+
 #ifndef _KERNEL
 __BEGIN_DECLS
 
@@ -273,9 +275,7 @@ feupdateenv(const fenv_t *__envp)
 
 #if defined(_NETBSD_SOURCE) || defined(_GNU_SOURCE)
 
-/* We currently provide no external definitions of the functions below. */
-
-static inline int
+__fenv_static inline int
 feenableexcept(int __mask)
 {
 	union __fpscr __r;
@@ -289,7 +289,7 @@ feenableexcept(int __mask)
 	return ((__oldmask & _ENABLE_MASK) << _FPUSW_SHIFT);
 }
 
-static inline int
+__fenv_static inline int
 fedisableexcept(int __mask)
 {
 	union __fpscr __r;
@@ -303,7 +303,7 @@ fedisableexcept(int __mask)
 	return ((__oldmask & _ENABLE_MASK) << _FPUSW_SHIFT);
 }
 
-static inline int
+__fenv_static inline int
 fegetexcept(void)
 {
 	union __fpscr __r;
@@ -315,6 +315,8 @@ fegetexcept(void)
 #endif /* _NETBSD_SOURCE || _GNU_SOURCE */
 
 __END_DECLS
+
 #endif
+#endif	/* _SOFT_FLOAT */
 
 #endif	/* !_POWERPC_FENV_H_ */

Index: src/sys/arch/powerpc/include/ieeefp.h
diff -u src/sys/arch/powerpc/include/ieeefp.h:1.6 src/sys/arch/powerpc/include/ieeefp.h:1.7
--- src/sys/arch/powerpc/include/ieeefp.h:1.6	Mon Feb 27 06:51:46 2017
+++ src/sys/arch/powerpc/include/ieeefp.h	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieeefp.h,v 1.6 2017/02/27 06:51:46 chs Exp $	*/
+/*	$NetBSD: ieeefp.h,v 1.7 2017/03/22 23:11:09 chs Exp $	*/
 
 /* 
  * Written by J.T. Conklin, Apr 6, 1995
@@ -20,6 +20,9 @@ typedef int fp_except;
 
 /* adjust for FP_* and FE_* value differences */ 
 #define	__FPE(x) ((x) >> 25)
+#define	__FEE(x) ((x) << 25)
+#define	__FPR(x) ((x))
+#define	__FER(x) ((x))
 
 #define FP_X_IMP	__FPE(FE_INEXACT)	/* imprecise (loss of precision) */
 #define FP_X_DZ		__FPE(FE_DIVBYZERO)	/* divide-by-zero exception */
@@ -28,10 +31,10 @@ typedef int fp_except;
 #define FP_X_INV	__FPE(FE_INVALID)	/* invalid operation exception */
 
 typedef enum {
-    FP_RN=FE_TONEAREST,		/* round to nearest representable number */
-    FP_RZ=FE_TOWARDZERO,	/* round to zero (truncate) */
-    FP_RP=FE_UPWARD,		/* round toward positive infinity */
-    FP_RM=FE_DOWNWARD		/* round toward negative infinity */
+    FP_RN=__FPR(FE_TONEAREST),	/* round to nearest representable number */
+    FP_RZ=__FPR(FE_TOWARDZERO),	/* round to zero (truncate) */
+    FP_RP=__FPR(FE_UPWARD),	/* round toward positive infinity */
+    FP_RM=__FPR(FE_DOWNWARD)	/* round toward negative infinity */
 } fp_rnd;
 
 #endif /* !_ISOC99_SOURCE */

Index: src/sys/arch/riscv/include/fenv.h
diff -u src/sys/arch/riscv/include/fenv.h:1.1 src/sys/arch/riscv/include/fenv.h:1.2
--- src/sys/arch/riscv/include/fenv.h:1.1	Fri Sep 19 17:36:26 2014
+++ src/sys/arch/riscv/include/fenv.h	Wed Mar 22 23:11:09 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.h,v 1.1 2014/09/19 17:36:26 matt Exp $	*/
+/*	$NetBSD: fenv.h,v 1.2 2017/03/22 23:11:09 chs Exp $	*/
 
 /* 
  * Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995
@@ -27,7 +27,7 @@ typedef int fexcept_t;
 __BEGIN_DECLS
 
 /* Default floating-point environment */
-extern fenv_t	__fe_dfl_env;
+extern const fenv_t	__fe_dfl_env;
 #define FE_DFL_ENV	(&__fe_dfl_env)
 
 __END_DECLS

Index: src/sys/arch/sh3/include/fenv.h
diff -u src/sys/arch/sh3/include/fenv.h:1.2 src/sys/arch/sh3/include/fenv.h:1.3
--- src/sys/arch/sh3/include/fenv.h:1.2	Thu Aug 25 12:29:14 2016
+++ src/sys/arch/sh3/include/fenv.h	Wed Mar 22 23:11:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: fenv.h,v 1.2 2016/08/25 12:29:14 christos Exp $	*/
+/*	$NetBSD: fenv.h,v 1.3 2017/03/22 23:11:10 chs Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -60,6 +60,8 @@
 #define _ROUND_MASK	\
     (FE_TONEAREST | FE_TOWARDZERO)
 
+#ifdef __SH_FPU_ANY__
+
 typedef uint32_t fexcept_t;
 
 typedef struct {
@@ -290,4 +292,6 @@ fegetexcept(void)
 
 __END_DECLS
 
+#endif /* __SH_FPU_ANY__ */
+
 #endif /* _SH3_FENV_H_ */

Index: src/sys/arch/sh3/include/ieeefp.h
diff -u src/sys/arch/sh3/include/ieeefp.h:1.6 src/sys/arch/sh3/include/ieeefp.h:1.7
--- src/sys/arch/sh3/include/ieeefp.h:1.6	Thu Aug 25 12:29:14 2016
+++ src/sys/arch/sh3/include/ieeefp.h	Wed Mar 22 23:11:10 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: ieeefp.h,v 1.6 2016/08/25 12:29:14 christos Exp $ */
+/* $NetBSD: ieeefp.h,v 1.7 2017/03/22 23:11:10 chs Exp $ */
 
 /*
  * Written by J.T. Conklin, Apr 6, 1995
@@ -18,6 +18,10 @@
 
 typedef int fp_except;
 
+#ifdef	__SH_FPU_ANY__
+
+/* hardfloat */
+
 #define	FP_X_INV	FE_INVALID	/* invalid operation exception */
 #define	FP_X_DZ		FE_DIVBYZERO	/* divide-by-zero exception */
 #define	FP_X_OFL	FE_OVERFLOW	/* overflow exception */
@@ -31,6 +35,99 @@ typedef enum {
 	FP_RZ=FE_TOWARDZERO	/* round to zero (truncate) */
 } fp_rnd;
 
+#else /* __SH_FPU_ANY__ */
+
+/* softfloat */
+
+#define	FP_X_INV	0x01	/* invalid operation exception */
+#define	FP_X_DZ		0x04	/* divide-by-zero exception */
+#define	FP_X_OFL	0x08	/* overflow exception */
+#define	FP_X_UFL	0x10	/* underflow exception */
+#define	FP_X_IMP	0x20	/* imprecise (loss of precision) */
+
+typedef enum {
+	FP_RN=0,		/* round to nearest representable number */
+	FP_RM=1,		/* round toward negative infinity */
+	FP_RP=2,        	/* round toward positive infinity */
+	FP_RZ=3			/* round to zero (truncate) */
+} fp_rnd;
+
+/* adjust for FP_* and FE_* value differences */ 
+
+static inline fp_except
+__FPE(int __fe)
+{
+	int __fp = 0;
+
+	if (__fe & FE_DIVBYZERO)
+		__fp |= FP_X_DZ;
+	if (__fe & FE_INEXACT)
+		__fp |= FP_X_IMP;
+	if (__fe & FE_INVALID)
+		__fp |= FP_X_INV;
+	if (__fe & FE_OVERFLOW)
+		__fp |= FP_X_OFL;
+	if (__fe & FE_UNDERFLOW)
+		__fp |= FP_X_UFL;
+	return __fp;
+}
+
+static inline int
+__FEE(fp_except __fp)
+{
+	int __fe = 0;
+
+	if (__fp & FP_X_DZ)
+		__fe |= FE_DIVBYZERO;
+	if (__fp & FP_X_IMP)
+		__fe |= FE_INEXACT;
+	if (__fp & FP_X_INV)
+		__fe |= FE_INVALID;
+	if (__fp & FP_X_OFL)
+		__fe |= FE_OVERFLOW;
+	if (__fp & FP_X_UFL)
+		__fe |= FE_UNDERFLOW;
+	return __fe;
+}
+
+static inline fp_rnd
+__FPR(int __fe)
+{
+
+	switch (__fe) {
+	case FE_TONEAREST:
+		return FP_RN;
+	case FE_DOWNWARD:
+		return FP_RM;
+	case FE_UPWARD:
+		return FP_RP;
+	case FE_TOWARDZERO:
+		return FP_RZ;
+	default:
+		return FP_RN;
+	}
+}
+
+static inline int
+__FER(fp_rnd __fp)
+{
+
+	switch (__fp) {
+	case FP_RN:
+		return FE_TONEAREST;
+	case FP_RM:
+		return FE_DOWNWARD;
+	case FP_RP:
+		return FE_UPWARD;
+	case FP_RZ:
+		return FE_TOWARDZERO;
+	default:
+		return FE_TONEAREST;
+	}
+}
+
+#endif /* __SH_FPU_ANY__ */
+
 #endif /* !_ISOC99_SOURCE */
 
 #endif /* _NETBSD_SOURCE || _ISOC99_SOURCE */

Index: src/tools/gcc/Makefile
diff -u src/tools/gcc/Makefile:1.80 src/tools/gcc/Makefile:1.81
--- src/tools/gcc/Makefile:1.80	Sat Mar 26 09:02:56 2016
+++ src/tools/gcc/Makefile	Wed Mar 22 23:11:10 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.80 2016/03/26 09:02:56 mrg Exp $
+#	$NetBSD: Makefile,v 1.81 2017/03/22 23:11:10 chs Exp $
 
 .include <bsd.own.mk>
 
@@ -23,7 +23,7 @@ MULTILIB_ARGS= --disable-multilib
 .endif
 
 .if ${MKSOFTFLOAT} != "no" && ${MACHINE_CPU} != "m68k" \
-    && ${MACHINE_CPU} != "or1k"
+    && ${MACHINE_CPU} != "or1k" && ${MACHINE_CPU} != "sh3"
 SOFTFLOAT_ARGS=	-with-float=soft
 .endif
 

Added files:

Index: src/lib/libm/softfloat/feclearexcept.c
diff -u /dev/null src/lib/libm/softfloat/feclearexcept.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/feclearexcept.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,51 @@
+/*	$NetBSD: feclearexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: feclearexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(feclearexcept,_feclearexcept)
+#endif
+
+int
+feclearexcept(int excepts)
+{
+    fp_except flags = __FPE(excepts);
+
+    fpsetsticky(fpgetsticky() & ~flags);
+    return 0;
+}
Index: src/lib/libm/softfloat/fedisableexcept.c
diff -u /dev/null src/lib/libm/softfloat/fedisableexcept.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/fedisableexcept.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,52 @@
+/*	$NetBSD: fedisableexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: fedisableexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(fedisableexcept,_fedisableexcept)
+#endif
+
+int
+fedisableexcept(int excepts)
+{
+    fp_except omask;
+
+    omask = fpgetmask();
+    fpsetmask(omask & ~__FPE(excepts));
+    return __FEE(omask);
+}
Index: src/lib/libm/softfloat/feenableexcept.c
diff -u /dev/null src/lib/libm/softfloat/feenableexcept.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/feenableexcept.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,52 @@
+/*	$NetBSD: feenableexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: feenableexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(feenableexcept,_feenableexcept)
+#endif
+
+int
+feenableexcept(int excepts)
+{
+    fp_except omask;
+
+    omask = fpgetmask();
+    fpsetmask(omask | __FPE(excepts));
+    return __FEE(omask);
+}
Index: src/lib/libm/softfloat/fegetenv.c
diff -u /dev/null src/lib/libm/softfloat/fegetenv.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/fegetenv.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,52 @@
+/*	$NetBSD: fegetenv.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: fegetenv.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(fegetenv,_fegetenv)
+#endif
+
+int
+fegetenv(fenv_t *envp)
+{
+
+	__FENV_SET_FLAGS(envp, fpgetsticky());
+	__FENV_SET_MASK(envp, fpgetmask());
+	__FENV_SET_ROUND(envp, fpgetround());
+	return 0;
+}
Index: src/lib/libm/softfloat/fegetexcept.c
diff -u /dev/null src/lib/libm/softfloat/fegetexcept.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/fegetexcept.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,49 @@
+/*	$NetBSD: fegetexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: fegetexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(fegetexcept,_fegetexcept)
+#endif
+
+int
+fegetexcept(void)
+{
+
+	return __FEE(fpgetmask());
+}
Index: src/lib/libm/softfloat/fegetexceptflag.c
diff -u /dev/null src/lib/libm/softfloat/fegetexceptflag.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/fegetexceptflag.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,50 @@
+/*	$NetBSD: fegetexceptflag.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: fegetexceptflag.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(fegetexceptflag,_fegetexceptflag)
+#endif
+
+int
+fegetexceptflag(fexcept_t *flagp, int excepts)
+{
+
+	*flagp = __FEE(fpgetsticky()) & excepts;
+	return 0;
+}
Index: src/lib/libm/softfloat/fegetround.c
diff -u /dev/null src/lib/libm/softfloat/fegetround.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/fegetround.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,49 @@
+/*	$NetBSD: fegetround.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: fegetround.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(fegetround,_fegetround)
+#endif
+
+int
+fegetround(void)
+{
+
+	return __FER(fpgetround());
+}
Index: src/lib/libm/softfloat/feholdexcept.c
diff -u /dev/null src/lib/libm/softfloat/feholdexcept.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/feholdexcept.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,54 @@
+/*	$NetBSD: feholdexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: feholdexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(feholdexcept,_feholdexcept)
+#endif
+
+int
+feholdexcept(fenv_t *envp)
+{
+
+	__FENV_SET_FLAGS(envp, fpgetsticky());
+	__FENV_SET_MASK(envp, fpgetmask());
+	__FENV_SET_ROUND(envp, fpgetround());
+	fpsetsticky(0);
+	fpsetmask(0);
+	return 0;
+}
Index: src/lib/libm/softfloat/feraiseexcept.c
diff -u /dev/null src/lib/libm/softfloat/feraiseexcept.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/feraiseexcept.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,74 @@
+/*	$NetBSD: feraiseexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: feraiseexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifdef __weak_alias
+__weak_alias(feraiseexcept,_feraiseexcept)
+#endif
+
+#include <stdio.h>
+
+int
+feraiseexcept(int excepts)
+{
+
+	fpsetsticky(fpgetsticky() | __FPE(excepts));
+	excepts &= __FEE(fpgetmask());
+	if (excepts) {
+		siginfo_t info;
+		memset(&info, 0, sizeof info);
+		info.si_signo = SIGFPE;
+		info.si_pid = getpid();
+		info.si_uid = geteuid();
+		if (excepts & FE_UNDERFLOW)
+			info.si_code = FPE_FLTUND;
+		else if (excepts & FE_OVERFLOW)
+			info.si_code = FPE_FLTOVF;
+		else if (excepts & FE_DIVBYZERO)
+			info.si_code = FPE_FLTDIV;
+		else if (excepts & FE_INVALID)
+			info.si_code = FPE_FLTINV;
+		else if (excepts & FE_INEXACT)
+			info.si_code = FPE_FLTRES;
+		sigqueueinfo(getpid(), &info);
+	}
+	return 0;
+}
Index: src/lib/libm/softfloat/fesetenv.c
diff -u /dev/null src/lib/libm/softfloat/fesetenv.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/fesetenv.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,52 @@
+/*	$NetBSD: fesetenv.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: fesetenv.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(fesetenv,_fesetenv)
+#endif
+
+int
+fesetenv(const fenv_t *envp)
+{
+
+	fpsetsticky(__FENV_GET_FLAGS(envp));
+	fpsetmask(__FENV_GET_MASK(envp));
+	fpsetround(__FENV_GET_ROUND(envp));
+	return 0;
+}
Index: src/lib/libm/softfloat/fesetexceptflag.c
diff -u /dev/null src/lib/libm/softfloat/fesetexceptflag.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/fesetexceptflag.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,51 @@
+/*	$NetBSD: fesetexceptflag.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: fesetexceptflag.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(fesetexceptflag,_fesetexceptflag)
+#endif
+
+int
+fesetexceptflag(const fexcept_t *flagp, int excepts)
+{
+	int mask = __FPE(excepts);
+
+	fpsetsticky((fpgetsticky() & ~mask) | (__FPE(*flagp) & mask));
+	return 0;
+}
Index: src/lib/libm/softfloat/fesetround.c
diff -u /dev/null src/lib/libm/softfloat/fesetround.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/fesetround.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,50 @@
+/*	$NetBSD: fesetround.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: fesetround.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(fesetround,_fesetround)
+#endif
+
+int
+fesetround(int round)
+{
+
+	fpsetround(__FPR(round));
+	return 0;
+}
Index: src/lib/libm/softfloat/fetestexcept.c
diff -u /dev/null src/lib/libm/softfloat/fetestexcept.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/fetestexcept.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,54 @@
+/*	$NetBSD: fetestexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: fetestexcept.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+#ifdef SOFTFLOAT_FOR_GCC
+#include "softfloat-for-gcc.h"
+#endif
+#include "milieu.h"
+#include "softfloat.h"
+
+#ifdef __weak_alias
+__weak_alias(fetestexcept,_fetestexcept)
+#endif
+
+int
+fetestexcept(int excepts)
+{
+
+	return __FEE(fpgetsticky()) & excepts;
+}
Index: src/lib/libm/softfloat/feupdateenv.c
diff -u /dev/null src/lib/libm/softfloat/feupdateenv.c:1.1
--- /dev/null	Wed Mar 22 23:11:10 2017
+++ src/lib/libm/softfloat/feupdateenv.c	Wed Mar 22 23:11:09 2017
@@ -0,0 +1,57 @@
+/*	$NetBSD: feupdateenv.c,v 1.1 2017/03/22 23:11:09 chs Exp $	*/
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Chuck Silvers.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: feupdateenv.c,v 1.1 2017/03/22 23:11:09 chs Exp $");
+
+#include "namespace.h"
+
+#include <fenv.h>
+#include <ieeefp.h>
+
+#ifdef __weak_alias
+__weak_alias(feupdateenv,_feupdateenv)
+#endif
+
+int
+feupdateenv(const fenv_t *envp)
+{
+	fexcept_t oflag;
+
+	fegetexceptflag(&oflag, FE_ALL_EXCEPT);
+
+	fpsetround(__FENV_GET_ROUND(envp));
+	fpsetmask(__FENV_GET_MASK(envp));
+	fpsetsticky(__FENV_GET_MASK(envp));
+
+	feraiseexcept(oflag);
+	return 0;
+}

Reply via email to