summaryrefslogtreecommitdiff
path: root/lib/libm/softfloat
diff options
context:
space:
mode:
authorchs <chs@NetBSD.org>2017-03-22 23:11:07 +0000
committerchs <chs@NetBSD.org>2017-03-22 23:11:07 +0000
commitce8aa0c8f9ea692b5cbb15ad34ce933d78b98317 (patch)
tree80cf830060875b1d40c78e33afa240c058b1d81f /lib/libm/softfloat
parentb13c9c92f5f3fb3b6e010d31acd1b2a6bd1b1c22 (diff)
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().
Diffstat (limited to 'lib/libm/softfloat')
-rw-r--r--lib/libm/softfloat/feclearexcept.c51
-rw-r--r--lib/libm/softfloat/fedisableexcept.c52
-rw-r--r--lib/libm/softfloat/feenableexcept.c52
-rw-r--r--lib/libm/softfloat/fegetenv.c52
-rw-r--r--lib/libm/softfloat/fegetexcept.c49
-rw-r--r--lib/libm/softfloat/fegetexceptflag.c50
-rw-r--r--lib/libm/softfloat/fegetround.c49
-rw-r--r--lib/libm/softfloat/feholdexcept.c54
-rw-r--r--lib/libm/softfloat/feraiseexcept.c74
-rw-r--r--lib/libm/softfloat/fesetenv.c52
-rw-r--r--lib/libm/softfloat/fesetexceptflag.c51
-rw-r--r--lib/libm/softfloat/fesetround.c50
-rw-r--r--lib/libm/softfloat/fetestexcept.c54
-rw-r--r--lib/libm/softfloat/feupdateenv.c57
14 files changed, 747 insertions, 0 deletions
diff --git a/lib/libm/softfloat/feclearexcept.c b/lib/libm/softfloat/feclearexcept.c
new file mode 100644
index 00000000000..c95ca9ed7c7
--- /dev/null
+++ b/lib/libm/softfloat/feclearexcept.c
@@ -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;
+}
diff --git a/lib/libm/softfloat/fedisableexcept.c b/lib/libm/softfloat/fedisableexcept.c
new file mode 100644
index 00000000000..2b3edc87737
--- /dev/null
+++ b/lib/libm/softfloat/fedisableexcept.c
@@ -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);
+}
diff --git a/lib/libm/softfloat/feenableexcept.c b/lib/libm/softfloat/feenableexcept.c
new file mode 100644
index 00000000000..67766c5d360
--- /dev/null
+++ b/lib/libm/softfloat/feenableexcept.c
@@ -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);
+}
diff --git a/lib/libm/softfloat/fegetenv.c b/lib/libm/softfloat/fegetenv.c
new file mode 100644
index 00000000000..851f51054c6
--- /dev/null
+++ b/lib/libm/softfloat/fegetenv.c
@@ -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;
+}
diff --git a/lib/libm/softfloat/fegetexcept.c b/lib/libm/softfloat/fegetexcept.c
new file mode 100644
index 00000000000..5d700cbee0c
--- /dev/null
+++ b/lib/libm/softfloat/fegetexcept.c
@@ -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());
+}
diff --git a/lib/libm/softfloat/fegetexceptflag.c b/lib/libm/softfloat/fegetexceptflag.c
new file mode 100644
index 00000000000..59e4b70703a
--- /dev/null
+++ b/lib/libm/softfloat/fegetexceptflag.c
@@ -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;
+}
diff --git a/lib/libm/softfloat/fegetround.c b/lib/libm/softfloat/fegetround.c
new file mode 100644
index 00000000000..5d26553b172
--- /dev/null
+++ b/lib/libm/softfloat/fegetround.c
@@ -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());
+}
diff --git a/lib/libm/softfloat/feholdexcept.c b/lib/libm/softfloat/feholdexcept.c
new file mode 100644
index 00000000000..15de4c01499
--- /dev/null
+++ b/lib/libm/softfloat/feholdexcept.c
@@ -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;
+}
diff --git a/lib/libm/softfloat/feraiseexcept.c b/lib/libm/softfloat/feraiseexcept.c
new file mode 100644
index 00000000000..2280adb7fc0
--- /dev/null
+++ b/lib/libm/softfloat/feraiseexcept.c
@@ -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;
+}
diff --git a/lib/libm/softfloat/fesetenv.c b/lib/libm/softfloat/fesetenv.c
new file mode 100644
index 00000000000..a72430ee4b4
--- /dev/null
+++ b/lib/libm/softfloat/fesetenv.c
@@ -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;
+}
diff --git a/lib/libm/softfloat/fesetexceptflag.c b/lib/libm/softfloat/fesetexceptflag.c
new file mode 100644
index 00000000000..ca8e04a277d
--- /dev/null
+++ b/lib/libm/softfloat/fesetexceptflag.c
@@ -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;
+}
diff --git a/lib/libm/softfloat/fesetround.c b/lib/libm/softfloat/fesetround.c
new file mode 100644
index 00000000000..0a9c093c039
--- /dev/null
+++ b/lib/libm/softfloat/fesetround.c
@@ -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;
+}
diff --git a/lib/libm/softfloat/fetestexcept.c b/lib/libm/softfloat/fetestexcept.c
new file mode 100644
index 00000000000..caef269589c
--- /dev/null
+++ b/lib/libm/softfloat/fetestexcept.c
@@ -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;
+}
diff --git a/lib/libm/softfloat/feupdateenv.c b/lib/libm/softfloat/feupdateenv.c
new file mode 100644
index 00000000000..bdb9f3e7493
--- /dev/null
+++ b/lib/libm/softfloat/feupdateenv.c
@@ -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;
+}