tech-userlevel archive

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

fenv fixes for softfloat



hi folks,

the attached patch fixes the libm fenv.h interfaces on softfloat platforms.
currently on sh3, mips, and powerpc the fenv implementation is hardfloat
even though it's supposed to be softfloat.

here's what I have for a commit 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().
----------

does anyone see any problem with this patch?
if not I'll commit in a few days.


I have tested this patch on quite a few combinations of platforms,
though I skipped some where we don't have a softfloat build:



fenv softfloat
arm		good
arm libc_vfp	bad - lib doesn't use hardware round/except state
m68k		? - libgcc_s.so is linked before libc.so
mips		good
powerpc		good
sh3		good



fenv softfloat - old test binary, new libs

arm		good
arm libc_vfp	bad - lib doesn't use hardware round/except state
m68k		? - libgcc_s.so is linked before libc.so
mips		? - no old bins
powerpc		? - no old bins
sh3		good



fenv hardfloat
alpha		
amd64		good
arm		good
hppa		
i386		good
ia64		
m68k		good
mips		good
powerpc		good
sparc		
sparc64		
vax		



fenv hardfloat - old test binary, new libs

arm		good
m68k		good
mips		good
powerpc		? - t_fpsetmask failures, same with old libs






finally, here are some more FP problems that this patch does not fix:

 - m68k softfloat doesn't build because of the dueling softfloat
   implementations in libgcc vs. libc.

 - the arm libc_vfp.so (which provides hardfloat implementations of functions
   using the softfloat ABI) needs to replace the functions which access
   the rounding and exception state with ones that access the hardware version
   of those.  it looks like the mips libc_fp.so has the same issue.

 - the softfloat rounding and exception state is global to the process
   rather than being per-thread as it should be.


I plan to get back to these eventually, but I wanted to be sure to get
my existing changes in for netbsd-8.

-Chuck
Index: src/include/fenv.h
===================================================================
RCS file: /home/chs/netbsd/cvs/src/include/fenv.h,v
retrieving revision 1.24
diff -u -p -r1.24 fenv.h
--- src/include/fenv.h	23 Feb 2017 02:06:12 -0000	1.24
+++ src/include/fenv.h	18 Mar 2017 18:33:56 -0000
@@ -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/flt_rounds_softfloat.S
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libc/arch/m68k/gen/flt_rounds_softfloat.S,v
retrieving revision 1.6
diff -u -p -r1.6 flt_rounds_softfloat.S
--- src/lib/libc/arch/m68k/gen/flt_rounds_softfloat.S	18 Mar 2014 18:20:37 -0000	1.6
+++ src/lib/libc/arch/m68k/gen/flt_rounds_softfloat.S	16 Mar 2017 11:19:33 -0000
@@ -12,19 +12,22 @@
 #include <machine/asm.h>
 
 	.text
-#if 0
-	/* NB: this is tied to the gcc-2.95 lb1sf68.asm: */
-_map:
+	/* NB: this is tied to libc's softfloat: */
+1:
 	.byte 1		/* round to nearest */
 	.byte 0		/* round to zero */
-	.byte 2		/* round to positive infinity */
 	.byte 3		/* round to negative infinity */
-#endif
+	.byte 2		/* round to positive infinity */
 
 ENTRY(__flt_rounds)
-	/* lea	_C_LABEL(_fpCCR),%a0	| check the rounding mode */
-	/* movew	6(%a0),%d0	| rounding mode in d0 */
-	/* lea	_map,%a0 */
-	moveb	#0,%d0
+#ifdef __PIC__
+	GOT_SETUP(%a0)
+	movel	_C_LABEL(_softfloat_float_rounding_mode)@GOT(%a0),%a0
+#else
+	lea	_C_LABEL(_softfloat_float_rounding_mode),%a0
+#endif
+	movel	(%a0),%d0
+	LEA_LCL(1b,%a0)
+	moveb	(%a0,%d0),%d0
 	rts
 END(__flt_rounds)
Index: src/lib/libc/arch/sh3/Makefile.inc
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libc/arch/sh3/Makefile.inc,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile.inc
--- src/lib/libc/arch/sh3/Makefile.inc	17 Jun 2006 18:04:23 -0000	1.6
+++ src/lib/libc/arch/sh3/Makefile.inc	16 Mar 2017 11:19:33 -0000
@@ -2,5 +2,9 @@
 
 SRCS+=	__sigaction14_sigtramp.c __sigtramp2.S
 
+.if ${MKSOFTFLOAT} != "no"
+
 CPPFLAGS+=      -DSOFTFLOAT # -DSOFTFLOAT_NEED_FIXUNS
 .include <softfloat/Makefile.inc>
+
+.endif
Index: src/lib/libm/Makefile
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/Makefile,v
retrieving revision 1.188
diff -u -p -r1.188 Makefile
--- src/lib/libm/Makefile	23 Feb 2017 02:05:30 -0000	1.188
+++ src/lib/libm/Makefile	17 Mar 2017 16:09:52 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/aarch64/fenv.c,v
retrieving revision 1.2
diff -u -p -r1.2 fenv.c
--- src/lib/libm/arch/aarch64/fenv.c	27 Dec 2014 17:52:45 -0000	1.2
+++ src/lib/libm/arch/aarch64/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -32,6 +32,8 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.2 2014/12/27 17:52:45 martin Exp $");
 
+#include "namespace.h"
+
 #include <sys/param.h>
 #include <sys/types.h>
 #include <assert.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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/alpha/fenv.c,v
retrieving revision 1.1
diff -u -p -r1.1 fenv.c
--- src/lib/libm/arch/alpha/fenv.c	23 Aug 2016 10:00:15 -0000	1.1
+++ src/lib/libm/arch/alpha/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -30,14 +30,21 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.1 2016/08/23 10:00:15 christos Exp $");
 
-#ifdef __weak_alias
-#define feenableexcept _feenableexcept
-#define fedisableexcept _fedisableexcept
-#define fegetexcept _fegetexcept
-#endif
+#include "namespace.h"
+
 #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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/arm/fenv.c,v
retrieving revision 1.6
diff -u -p -r1.6 fenv.c
--- src/lib/libm/arch/arm/fenv.c	29 Dec 2014 19:11:13 -0000	1.6
+++ src/lib/libm/arch/arm/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/hppa/fenv.c,v
retrieving revision 1.3
diff -u -p -r1.3 fenv.c
--- src/lib/libm/arch/hppa/fenv.c	20 Mar 2016 14:22:46 -0000	1.3
+++ src/lib/libm/arch/hppa/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -26,9 +26,28 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.3 2016/03/20 14:22:46 skrll 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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/i387/fenv.c,v
retrieving revision 1.7
diff -u -p -r1.7 fenv.c
--- src/lib/libm/arch/i387/fenv.c	17 Feb 2016 19:54:11 -0000	1.7
+++ src/lib/libm/arch/i387/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -29,6 +29,8 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.7 2016/02/17 19:54:11 christos Exp $");
 
+#include "namespace.h"
+
 #include <sys/param.h>
 #include <sys/sysctl.h>
 #include <assert.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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/ia64/fenv.c,v
retrieving revision 1.1
diff -u -p -r1.1 fenv.c
--- src/lib/libm/arch/ia64/fenv.c	23 Feb 2017 02:05:30 -0000	1.1
+++ src/lib/libm/arch/ia64/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -31,8 +31,27 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.1 2017/02/23 02:05:30 scole 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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/m68k/fenv.c,v
retrieving revision 1.1
diff -u -p -r1.1 fenv.c
--- src/lib/libm/arch/m68k/fenv.c	24 Dec 2015 14:12:12 -0000	1.1
+++ src/lib/libm/arch/m68k/fenv.c	17 Mar 2017 19:58:00 -0000
@@ -31,8 +31,27 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.1 2015/12/24 14:12:12 christos 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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/mips/fenv.c,v
retrieving revision 1.2
diff -u -p -r1.2 fenv.c
--- src/lib/libm/arch/mips/fenv.c	11 Jan 2016 01:34:39 -0000	1.2
+++ src/lib/libm/arch/mips/fenv.c	17 Mar 2017 18:06:18 -0000
@@ -30,8 +30,27 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.2 2016/01/11 01:34:39 christos 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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/powerpc/fenv.c,v
retrieving revision 1.1
diff -u -p -r1.1 fenv.c
--- src/lib/libm/arch/powerpc/fenv.c	20 Dec 2015 16:24:25 -0000	1.1
+++ src/lib/libm/arch/powerpc/fenv.c	17 Mar 2017 19:57:33 -0000
@@ -30,8 +30,27 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.1 2015/12/20 16:24:25 christos 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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/riscv/fenv.c,v
retrieving revision 1.1
diff -u -p -r1.1 fenv.c
--- src/lib/libm/arch/riscv/fenv.c	19 Sep 2014 17:36:25 -0000	1.1
+++ src/lib/libm/arch/riscv/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -32,6 +32,8 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.1 2014/09/19 17:36:25 matt Exp $");
 
+#include "namespace.h"
+
 #include <sys/param.h>
 #include <sys/sysctl.h>
 #include <assert.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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/sh3/fenv.c,v
retrieving revision 1.1
diff -u -p -r1.1 fenv.c
--- src/lib/libm/arch/sh3/fenv.c	25 Aug 2016 12:15:28 -0000	1.1
+++ src/lib/libm/arch/sh3/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -31,8 +31,27 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.1 2016/08/25 12:15:28 christos 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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/sparc/fenv.c,v
retrieving revision 1.1
diff -u -p -r1.1 fenv.c
--- src/lib/libm/arch/sparc/fenv.c	20 May 2011 21:42:49 -0000	1.1
+++ src/lib/libm/arch/sparc/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -26,9 +26,28 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.1 2011/05/20 21:42:49 nakayama 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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/sparc64/fenv.c,v
retrieving revision 1.2
diff -u -p -r1.2 fenv.c
--- src/lib/libm/arch/sparc64/fenv.c	20 May 2011 21:42:49 -0000	1.2
+++ src/lib/libm/arch/sparc64/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -26,9 +26,28 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.2 2011/05/20 21:42:49 nakayama 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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/arch/x86_64/fenv.c,v
retrieving revision 1.6
diff -u -p -r1.6 fenv.c
--- src/lib/libm/arch/x86_64/fenv.c	11 Nov 2013 00:31:51 -0000	1.6
+++ src/lib/libm/arch/x86_64/fenv.c	16 Mar 2017 11:19:33 -0000
@@ -29,11 +29,30 @@
 #include <sys/cdefs.h>
 __RCSID("$NetBSD: fenv.c,v 1.6 2013/11/11 00:31:51 joerg 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/softfloat/feclearexcept.c
===================================================================
RCS file: src/lib/libm/softfloat/feclearexcept.c
diff -N src/lib/libm/softfloat/feclearexcept.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/feclearexcept.c	17 Mar 2017 15:51:15 -0000
@@ -0,0 +1,51 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/fedisableexcept.c
diff -N src/lib/libm/softfloat/fedisableexcept.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/fedisableexcept.c	11 Mar 2017 14:50:37 -0000
@@ -0,0 +1,52 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/feenableexcept.c
diff -N src/lib/libm/softfloat/feenableexcept.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/feenableexcept.c	11 Mar 2017 14:50:18 -0000
@@ -0,0 +1,52 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/fegetenv.c
diff -N src/lib/libm/softfloat/fegetenv.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/fegetenv.c	11 Mar 2017 14:41:18 -0000
@@ -0,0 +1,52 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/fegetexcept.c
diff -N src/lib/libm/softfloat/fegetexcept.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/fegetexcept.c	11 Mar 2017 14:57:32 -0000
@@ -0,0 +1,49 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/fegetexceptflag.c
diff -N src/lib/libm/softfloat/fegetexceptflag.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/fegetexceptflag.c	11 Mar 2017 14:52:18 -0000
@@ -0,0 +1,50 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/fegetround.c
diff -N src/lib/libm/softfloat/fegetround.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/fegetround.c	11 Mar 2017 14:41:53 -0000
@@ -0,0 +1,49 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/feholdexcept.c
diff -N src/lib/libm/softfloat/feholdexcept.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/feholdexcept.c	11 Mar 2017 14:43:23 -0000
@@ -0,0 +1,54 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/feraiseexcept.c
diff -N src/lib/libm/softfloat/feraiseexcept.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/feraiseexcept.c	12 Mar 2017 19:05:08 -0000
@@ -0,0 +1,74 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/fesetenv.c
diff -N src/lib/libm/softfloat/fesetenv.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/fesetenv.c	11 Mar 2017 14:44:36 -0000
@@ -0,0 +1,52 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/fesetexceptflag.c
diff -N src/lib/libm/softfloat/fesetexceptflag.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/fesetexceptflag.c	17 Mar 2017 15:58:05 -0000
@@ -0,0 +1,51 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/fesetround.c
diff -N src/lib/libm/softfloat/fesetround.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/fesetround.c	11 Mar 2017 14:54:40 -0000
@@ -0,0 +1,50 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/fetestexcept.c
diff -N src/lib/libm/softfloat/fetestexcept.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/fetestexcept.c	11 Mar 2017 14:55:05 -0000
@@ -0,0 +1,54 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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
===================================================================
RCS file: src/lib/libm/softfloat/feupdateenv.c
diff -N src/lib/libm/softfloat/feupdateenv.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/lib/libm/softfloat/feupdateenv.c	11 Mar 2017 14:41:27 -0000
@@ -0,0 +1,57 @@
+/*	$NetBSD$	*/
+
+/*-
+ * 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$");
+
+#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;
+}
Index: src/lib/libm/src/namespace.h
===================================================================
RCS file: /home/chs/netbsd/cvs/src/lib/libm/src/namespace.h,v
retrieving revision 1.13
diff -u -p -r1.13 namespace.h
--- src/lib/libm/src/namespace.h	14 Nov 2014 14:53:17 -0000	1.13
+++ src/lib/libm/src/namespace.h	16 Mar 2017 11:19:33 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/share/mk/bsd.own.mk,v
retrieving revision 1.1006
diff -u -p -r1.1006 bsd.own.mk
--- src/share/mk/bsd.own.mk	13 Feb 2017 16:33:14 -0000	1.1006
+++ src/share/mk/bsd.own.mk	16 Mar 2017 11:32:29 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/share/mk/bsd.sys.mk,v
retrieving revision 1.269
diff -u -p -r1.269 bsd.sys.mk
--- src/share/mk/bsd.sys.mk	7 Feb 2017 21:19:13 -0000	1.269
+++ src/share/mk/bsd.sys.mk	16 Mar 2017 11:28:45 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/arm/include/fenv.h,v
retrieving revision 1.3
diff -u -p -r1.3 fenv.h
--- src/sys/arch/arm/include/fenv.h	17 Mar 2015 12:20:02 -0000	1.3
+++ src/sys/arch/arm/include/fenv.h	18 Mar 2017 18:35:58 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/arm/include/ieeefp.h,v
retrieving revision 1.3
diff -u -p -r1.3 ieeefp.h
--- src/sys/arch/arm/include/ieeefp.h	23 Apr 2013 05:42:23 -0000	1.3
+++ src/sys/arch/arm/include/ieeefp.h	16 Mar 2017 11:19:33 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/m68k/include/fenv.h,v
retrieving revision 1.5
diff -u -p -r1.5 fenv.h
--- src/sys/arch/m68k/include/fenv.h	27 Feb 2017 06:47:30 -0000	1.5
+++ src/sys/arch/m68k/include/fenv.h	17 Mar 2017 20:48:26 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/m68k/include/ieeefp.h,v
retrieving revision 1.9
diff -u -p -r1.9 ieeefp.h
--- src/sys/arch/m68k/include/ieeefp.h	27 Feb 2017 06:47:58 -0000	1.9
+++ src/sys/arch/m68k/include/ieeefp.h	16 Mar 2017 11:19:33 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/mips/include/fenv.h,v
retrieving revision 1.3
diff -u -p -r1.3 fenv.h
--- src/sys/arch/mips/include/fenv.h	27 Feb 2017 06:57:16 -0000	1.3
+++ src/sys/arch/mips/include/fenv.h	17 Mar 2017 17:59:03 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/mips/include/ieeefp.h,v
retrieving revision 1.9
diff -u -p -r1.9 ieeefp.h
--- src/sys/arch/mips/include/ieeefp.h	27 Feb 2017 06:56:03 -0000	1.9
+++ src/sys/arch/mips/include/ieeefp.h	16 Mar 2017 11:19:33 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/powerpc/include/fenv.h,v
retrieving revision 1.2
diff -u -p -r1.2 fenv.h
--- src/sys/arch/powerpc/include/fenv.h	27 Feb 2017 06:54:42 -0000	1.2
+++ src/sys/arch/powerpc/include/fenv.h	17 Mar 2017 20:48:56 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/powerpc/include/ieeefp.h,v
retrieving revision 1.6
diff -u -p -r1.6 ieeefp.h
--- src/sys/arch/powerpc/include/ieeefp.h	27 Feb 2017 06:51:46 -0000	1.6
+++ src/sys/arch/powerpc/include/ieeefp.h	16 Mar 2017 11:19:33 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/riscv/include/fenv.h,v
retrieving revision 1.1
diff -u -p -r1.1 fenv.h
--- src/sys/arch/riscv/include/fenv.h	19 Sep 2014 17:36:26 -0000	1.1
+++ src/sys/arch/riscv/include/fenv.h	16 Mar 2017 11:19:33 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/sh3/include/fenv.h,v
retrieving revision 1.2
diff -u -p -r1.2 fenv.h
--- src/sys/arch/sh3/include/fenv.h	25 Aug 2016 12:29:14 -0000	1.2
+++ src/sys/arch/sh3/include/fenv.h	16 Mar 2017 11:19:33 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/sys/arch/sh3/include/ieeefp.h,v
retrieving revision 1.6
diff -u -p -r1.6 ieeefp.h
--- src/sys/arch/sh3/include/ieeefp.h	25 Aug 2016 12:29:14 -0000	1.6
+++ src/sys/arch/sh3/include/ieeefp.h	16 Mar 2017 11:19:33 -0000
@@ -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
===================================================================
RCS file: /home/chs/netbsd/cvs/src/tools/gcc/Makefile,v
retrieving revision 1.80
diff -u -p -r1.80 Makefile
--- src/tools/gcc/Makefile	26 Mar 2016 09:02:56 -0000	1.80
+++ src/tools/gcc/Makefile	16 Mar 2017 11:19:33 -0000
@@ -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
 


Home | Main Index | Thread Index | Old Index