summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authormartynas <martynas@openbsd.org>2011-07-08 22:28:32 +0000
committermartynas <martynas@openbsd.org>2011-07-08 22:28:32 +0000
commitaeb694e3afa554db8dd44ee8140d036724efada5 (patch)
tree27134d6d85c1d25448c6bbdb4cc7222c925034fe /lib/libc
parentDon't accidentally mask off the T_USER bit before calling trap(). (diff)
downloadwireguard-openbsd-aeb694e3afa554db8dd44ee8140d036724efada5.tar.xz
wireguard-openbsd-aeb694e3afa554db8dd44ee8140d036724efada5.zip
Revert (leaving the complex math part alone). Some stuff is depending
on this historical behavior; so we're stuck in this stupid situation. No cookie for me.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/arch/alpha/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/alpha/gen/fabs.S37
-rw-r--r--lib/libc/arch/amd64/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/amd64/gen/fabs.S17
-rw-r--r--lib/libc/arch/amd64/gen/modf.S91
-rw-r--r--lib/libc/arch/arm/gen/Makefile.inc6
-rw-r--r--lib/libc/arch/arm/gen/fabs.c35
-rw-r--r--lib/libc/arch/hppa/gen/Makefile.inc5
-rw-r--r--lib/libc/arch/hppa/gen/fabs.c17
-rw-r--r--lib/libc/arch/hppa64/gen/Makefile.inc5
-rw-r--r--lib/libc/arch/hppa64/gen/fabs.c13
-rw-r--r--lib/libc/arch/i386/gen/Makefile.inc6
-rw-r--r--lib/libc/arch/i386/gen/fabs.S39
-rw-r--r--lib/libc/arch/i386/gen/modf.S68
-rw-r--r--lib/libc/arch/m68k/gen/Makefile.inc6
-rw-r--r--lib/libc/arch/m68k/gen/fabs.S47
-rw-r--r--lib/libc/arch/m68k/gen/modf.S50
-rw-r--r--lib/libc/arch/m88k/gen/Makefile.inc6
-rw-r--r--lib/libc/arch/m88k/gen/fabs.S46
-rw-r--r--lib/libc/arch/mips64/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/mips64/gen/fabs.S46
-rw-r--r--lib/libc/arch/mips64/gen/modf.S71
-rw-r--r--lib/libc/arch/powerpc/gen/Makefile.inc3
-rw-r--r--lib/libc/arch/powerpc/gen/fabs.c38
-rw-r--r--lib/libc/arch/sh/gen/Makefile.inc6
-rw-r--r--lib/libc/arch/sh/gen/fabs.c40
-rw-r--r--lib/libc/arch/sparc/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/sparc/gen/fabs.S44
-rw-r--r--lib/libc/arch/sparc/gen/modf.S186
-rw-r--r--lib/libc/arch/sparc64/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/sparc64/gen/fabs.S42
-rw-r--r--lib/libc/arch/sparc64/gen/modf.S181
-rw-r--r--lib/libc/arch/vax/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/vax/gen/fabs.S41
-rw-r--r--lib/libc/arch/vax/gen/frexp.c69
-rw-r--r--lib/libc/arch/vax/gen/modf.S54
-rw-r--r--lib/libc/gen/Makefile.inc13
-rw-r--r--lib/libc/gen/frexp.395
-rw-r--r--lib/libc/gen/frexp.c79
-rw-r--r--lib/libc/gen/modf.376
-rw-r--r--lib/libc/gen/modf.c104
-rw-r--r--lib/libc/shlib_version2
42 files changed, 1670 insertions, 38 deletions
diff --git a/lib/libc/arch/alpha/gen/Makefile.inc b/lib/libc/arch/alpha/gen/Makefile.inc
index 0ea3b2aca9a..9f4eeaabd0b 100644
--- a/lib/libc/arch/alpha/gen/Makefile.inc
+++ b/lib/libc/arch/alpha/gen/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.11 2011/07/08 19:21:41 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.12 2011/07/08 22:28:32 martynas Exp $
# $NetBSD: Makefile.inc,v 1.3 1995/04/29 05:09:14 cgd Exp $
-SRCS+= _setjmp.S infinity.c ldexp.c nan.c setjmp.S
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.c modf.c nan.c setjmp.S
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
SRCS+= sigsetjmp.S
diff --git a/lib/libc/arch/alpha/gen/fabs.S b/lib/libc/arch/alpha/gen/fabs.S
new file mode 100644
index 00000000000..3976b758fb6
--- /dev/null
+++ b/lib/libc/arch/alpha/gen/fabs.S
@@ -0,0 +1,37 @@
+/* $OpenBSD: fabs.S,v 1.7 2011/07/08 22:28:32 martynas Exp $ */
+/* $NetBSD: fabs.S,v 1.2 1996/10/17 03:08:05 cgd Exp $ */
+
+/*
+ * Copyright (c) 1994, 1995 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#include <machine/asm.h>
+
+WEAK_ALIAS(fabsl, fabs)
+LEAF(fabs, 1)
+ cpys fzero, fa0, fv0
+ RET
+END(fabs)
diff --git a/lib/libc/arch/amd64/gen/Makefile.inc b/lib/libc/arch/amd64/gen/Makefile.inc
index eae9b4a4649..ad1d79d82a9 100644
--- a/lib/libc/arch/amd64/gen/Makefile.inc
+++ b/lib/libc/arch/amd64/gen/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.9 2011/07/08 19:21:41 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.10 2011/07/08 22:28:32 martynas Exp $
-SRCS+= _setjmp.S infinity.c ldexp.c nan.c setjmp.S \
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.c modf.S nan.c setjmp.S \
sigsetjmp.S
SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c
SRCS+= flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S fpsetmask.S \
diff --git a/lib/libc/arch/amd64/gen/fabs.S b/lib/libc/arch/amd64/gen/fabs.S
new file mode 100644
index 00000000000..c91edc528ac
--- /dev/null
+++ b/lib/libc/arch/amd64/gen/fabs.S
@@ -0,0 +1,17 @@
+/* $OpenBSD: fabs.S,v 1.6 2011/07/08 22:28:32 martynas Exp $ */
+/* $NetBSD: fabs.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */
+
+#include <machine/asm.h>
+
+/*
+ * Ok, this sucks. Is there really no way to push an xmm register onto
+ * the FP stack directly?
+ */
+
+ENTRY(fabs)
+ movsd %xmm0, -8(%rsp)
+ fldl -8(%rsp)
+ fabs
+ fstpl -8(%rsp)
+ movsd -8(%rsp),%xmm0
+ ret
diff --git a/lib/libc/arch/amd64/gen/modf.S b/lib/libc/arch/amd64/gen/modf.S
new file mode 100644
index 00000000000..38eaade93fc
--- /dev/null
+++ b/lib/libc/arch/amd64/gen/modf.S
@@ -0,0 +1,91 @@
+/* $OpenBSD: modf.S,v 1.4 2011/07/08 22:28:32 martynas Exp $ */
+/* $NetBSD: modf.S,v 1.1 2001/06/19 00:25:03 fvdl Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Sean Eric Fagan.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ * from: @(#)modf.s 5.5 (Berkeley) 3/18/91
+ */
+
+#include <machine/asm.h>
+
+/*
+ * modf(value, iptr): return fractional part of value, and stores the
+ * integral part into iptr (a pointer to double).
+ *
+ * Written by Sean Eric Fagan (sef@kithrup.COM)
+ * Sun Mar 11 20:27:30 PST 1990
+ */
+
+/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */
+ENTRY(modf)
+
+ /*
+ * Set chop mode.
+ */
+ fnstcw -12(%rsp)
+ movw -12(%rsp),%dx
+ orw $3072,%dx
+ movw %dx,-16(%rsp)
+ fldcw -16(%rsp)
+
+ /*
+ * Get integral part.
+ */
+ movsd %xmm0,-24(%rsp)
+ fldl -24(%rsp)
+ frndint
+ fstpl -8(%rsp)
+
+ /*
+ * Restore control word.
+ */
+ fldcw -12(%rsp)
+
+ /*
+ * Store integral part.
+ */
+ movsd -8(%rsp),%xmm0
+ movsd %xmm0,(%rdi)
+
+ /*
+ * Get fractional part and return it.
+ */
+ fldl -24(%rsp)
+ fsubl -8(%rsp)
+ fstpl -8(%rsp)
+ movsd -8(%rsp),%xmm0
+
+ ret
diff --git a/lib/libc/arch/arm/gen/Makefile.inc b/lib/libc/arch/arm/gen/Makefile.inc
index e60db0bb264..7a67e856223 100644
--- a/lib/libc/arch/arm/gen/Makefile.inc
+++ b/lib/libc/arch/arm/gen/Makefile.inc
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile.inc,v 1.12 2011/07/08 19:21:41 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.13 2011/07/08 22:28:33 martynas Exp $
# $NetBSD: Makefile.inc,v 1.6 2003/08/01 17:03:47 lukem Exp $
-SRCS+= byte_swap_2.S byte_swap_4.S divsi3.S flt_rounds.c infinity.c
-SRCS+= ldexp.c nan.c
+SRCS+= byte_swap_2.S byte_swap_4.S divsi3.S fabs.c flt_rounds.c infinity.c
+SRCS+= ldexp.c modf.c nan.c
SRCS+= setjmp.S _setjmp.S sigsetjmp.S
SRCS+= alloca.S
diff --git a/lib/libc/arch/arm/gen/fabs.c b/lib/libc/arch/arm/gen/fabs.c
new file mode 100644
index 00000000000..18c7b45b4c2
--- /dev/null
+++ b/lib/libc/arch/arm/gen/fabs.c
@@ -0,0 +1,35 @@
+/* $OpenBSD: fabs.c,v 1.7 2011/07/08 22:28:33 martynas Exp $ */
+/*
+ * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <machine/ieee.h>
+
+/*
+ * fabs(d) returns the absolute value of d.
+ */
+double
+fabs(double d)
+{
+ struct ieee_double *p = (struct ieee_double *)&d;
+
+ p->dbl_sign = 0;
+
+ return(d);
+}
+
+__weak_alias(fabsl, fabs);
diff --git a/lib/libc/arch/hppa/gen/Makefile.inc b/lib/libc/arch/hppa/gen/Makefile.inc
index 99588741c72..318a2eb976b 100644
--- a/lib/libc/arch/hppa/gen/Makefile.inc
+++ b/lib/libc/arch/hppa/gen/Makefile.inc
@@ -1,7 +1,8 @@
-# $OpenBSD: Makefile.inc,v 1.12 2011/07/08 19:21:41 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.13 2011/07/08 22:28:33 martynas Exp $
SRCS+= setjmp.S
-SRCS+= infinity.c ldexp.c nan.c setjmp.S
+SRCS+= fabs.c
+SRCS+= infinity.c ldexp.c modf.c nan.c setjmp.S
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
diff --git a/lib/libc/arch/hppa/gen/fabs.c b/lib/libc/arch/hppa/gen/fabs.c
new file mode 100644
index 00000000000..d234fb01850
--- /dev/null
+++ b/lib/libc/arch/hppa/gen/fabs.c
@@ -0,0 +1,17 @@
+/* $OpenBSD: fabs.c,v 1.7 2011/07/08 22:28:33 martynas Exp $ */
+
+/*
+ * Written by Miodrag Vallat. Public domain
+ */
+
+#include <sys/cdefs.h>
+
+double
+fabs(double val)
+{
+
+ __asm__ __volatile__("fabs,dbl %0,%0" : "+f" (val));
+ return (val);
+}
+
+__weak_alias(fabsl, fabs);
diff --git a/lib/libc/arch/hppa64/gen/Makefile.inc b/lib/libc/arch/hppa64/gen/Makefile.inc
index 66add238ee0..5fc7f14de70 100644
--- a/lib/libc/arch/hppa64/gen/Makefile.inc
+++ b/lib/libc/arch/hppa64/gen/Makefile.inc
@@ -1,7 +1,8 @@
-# $OpenBSD: Makefile.inc,v 1.8 2011/07/08 19:21:41 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.9 2011/07/08 22:28:33 martynas Exp $
SRCS+= setjmp.S
-SRCS+= infinity.c ldexp.c nan.c setjmp.S
+SRCS+= fabs.c
+SRCS+= infinity.c ldexp.c modf.c nan.c setjmp.S
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c
diff --git a/lib/libc/arch/hppa64/gen/fabs.c b/lib/libc/arch/hppa64/gen/fabs.c
new file mode 100644
index 00000000000..2a31ff0b12c
--- /dev/null
+++ b/lib/libc/arch/hppa64/gen/fabs.c
@@ -0,0 +1,13 @@
+/* $OpenBSD: fabs.c,v 1.3 2011/07/08 22:28:33 martynas Exp $ */
+
+/*
+ * Written by Miodrag Vallat. Public domain
+ */
+
+double
+fabs(double val)
+{
+
+ __asm__ __volatile__("fabs,dbl %0,%0" : "+f" (val));
+ return (val);
+}
diff --git a/lib/libc/arch/i386/gen/Makefile.inc b/lib/libc/arch/i386/gen/Makefile.inc
index 2afe10d6644..6e623b1e252 100644
--- a/lib/libc/arch/i386/gen/Makefile.inc
+++ b/lib/libc/arch/i386/gen/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.11 2011/07/08 19:21:41 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.12 2011/07/08 22:28:33 martynas Exp $
-SRCS+= _setjmp.S alloca.S infinity.c ldexp.c \
- nan.c setjmp.S sigsetjmp.S
+SRCS+= _setjmp.S alloca.S fabs.S infinity.c ldexp.c \
+ modf.S nan.c setjmp.S sigsetjmp.S
SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c
SRCS+= flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S fpsetmask.S \
fpsetround.S fpsetsticky.S
diff --git a/lib/libc/arch/i386/gen/fabs.S b/lib/libc/arch/i386/gen/fabs.S
new file mode 100644
index 00000000000..7041a729a16
--- /dev/null
+++ b/lib/libc/arch/i386/gen/fabs.S
@@ -0,0 +1,39 @@
+/* $OpenBSD: fabs.S,v 1.9 2011/07/08 22:28:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <machine/asm.h>
+
+ENTRY(fabs)
+ fldl 4(%esp)
+ fabs
+ ret
diff --git a/lib/libc/arch/i386/gen/modf.S b/lib/libc/arch/i386/gen/modf.S
new file mode 100644
index 00000000000..4b623611a60
--- /dev/null
+++ b/lib/libc/arch/i386/gen/modf.S
@@ -0,0 +1,68 @@
+/* $OpenBSD: modf.S,v 1.7 2011/07/08 22:28:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Sean Eric Fagan.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <machine/asm.h>
+
+/*
+ * modf(value, iptr): return fractional part of value, and stores the
+ * integral part into iptr (a pointer to double).
+ *
+ * Written by Sean Eric Fagan (sef@kithrup.COM)
+ * Sun Mar 11 20:27:30 PST 1990
+ */
+
+/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */
+ENTRY(modf)
+ pushl %ebp
+ movl %esp,%ebp
+ subl $16,%esp
+ fnstcw -12(%ebp)
+ movw -12(%ebp),%dx
+ orw $3072,%dx
+ movw %dx,-16(%ebp)
+ fldcw -16(%ebp)
+ fldl 8(%ebp)
+ frndint
+ fstpl -8(%ebp)
+ fldcw -12(%ebp)
+ movl 16(%ebp),%eax
+ movl -8(%ebp),%edx
+ movl -4(%ebp),%ecx
+ movl %edx,(%eax)
+ movl %ecx,4(%eax)
+ fldl 8(%ebp)
+ fsubl -8(%ebp)
+ jmp L1
+L1:
+ leave
+ ret
diff --git a/lib/libc/arch/m68k/gen/Makefile.inc b/lib/libc/arch/m68k/gen/Makefile.inc
index 18e477d7fb6..9f7c9c544ad 100644
--- a/lib/libc/arch/m68k/gen/Makefile.inc
+++ b/lib/libc/arch/m68k/gen/Makefile.inc
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.9 2011/07/08 19:21:41 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.10 2011/07/08 22:28:33 martynas Exp $
-SRCS+= _setjmp.S infinity.c ldexp.S \
- nan.c setjmp.S sigsetjmp.S
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.S \
+ modf.S nan.c setjmp.S sigsetjmp.S
SRCS+= flt_rounds.S fpgetmask.S fpgetround.S fpgetsticky.S fpsetmask.S \
fpsetround.S fpsetsticky.S
SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c
diff --git a/lib/libc/arch/m68k/gen/fabs.S b/lib/libc/arch/m68k/gen/fabs.S
new file mode 100644
index 00000000000..d12fd7dd7bb
--- /dev/null
+++ b/lib/libc/arch/m68k/gen/fabs.S
@@ -0,0 +1,47 @@
+/* $OpenBSD: fabs.S,v 1.8 2011/07/08 22:28:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+/* fabs - floating absolute value */
+
+#include "DEFS.h"
+
+ENTRY(fabs)
+ fmoved sp@(4),fp0
+ fjnlt L1
+ fnegx fp0
+L1:
+ fmoved fp0,sp@-
+ movel sp@+,d0
+ movel sp@+,d1
+ rts
diff --git a/lib/libc/arch/m68k/gen/modf.S b/lib/libc/arch/m68k/gen/modf.S
new file mode 100644
index 00000000000..aa32d6815b4
--- /dev/null
+++ b/lib/libc/arch/m68k/gen/modf.S
@@ -0,0 +1,50 @@
+/* $OpenBSD: modf.S,v 1.6 2011/07/08 22:28:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 "DEFS.h"
+
+/*
+ * double modf(val, iptr)
+ * returns: xxx and n (in *iptr) where val == n.xxx
+ */
+ENTRY(modf)
+ fmoved sp@(4),fp0
+ movel sp@(12),a0
+ fintrzx fp0,fp1
+ fmoved fp1,a0@
+ fsubx fp1,fp0
+ fmoved fp0,sp@-
+ movel sp@+,d0
+ movel sp@+,d1
+ rts
diff --git a/lib/libc/arch/m88k/gen/Makefile.inc b/lib/libc/arch/m88k/gen/Makefile.inc
index 0c830c1f82c..ca09446840e 100644
--- a/lib/libc/arch/m88k/gen/Makefile.inc
+++ b/lib/libc/arch/m88k/gen/Makefile.inc
@@ -1,12 +1,12 @@
-# $OpenBSD: Makefile.inc,v 1.11 2011/07/08 19:21:41 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.12 2011/07/08 22:28:33 martynas Exp $
# $NetBSD: Makefile.inc,v 1.3 1995/04/10 21:09:06 jtc Exp $
-#SRCS+= _setjmp.S infinity.c ldexp.c nan.c
+#SRCS+= _setjmp.S fabs.S infinity.c ldexp.c modf.c nan.c
#SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
# fpsetround.c fpsetsticky.c
#SRCS+= fixunsdfsi.S mul.S umul.S saveregs.S setjmp.S sigsetjmp.S
-SRCS+= _setjmp.S infinity.c ldexp.c nan.c
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.c modf.c nan.c
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c
diff --git a/lib/libc/arch/m88k/gen/fabs.S b/lib/libc/arch/m88k/gen/fabs.S
new file mode 100644
index 00000000000..68fe00a9392
--- /dev/null
+++ b/lib/libc/arch/m88k/gen/fabs.S
@@ -0,0 +1,46 @@
+/* $OpenBSD: fabs.S,v 1.9 2011/07/08 22:28:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1996 Nivas Madhur
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Nivas Madhur.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 "DEFS.h"
+
+/*
+ * Will work only if the argument passed is in IEEE format!
+ */
+
+ENTRY(fabs)
+ subu r31,r31,16
+ st.d r2,r31,0
+ ld.bu r4,r31,0
+ mask r4,r4,0x7f /* set sign bit to 0 */
+ st.b r4,r31,0
+ ld.d r2,r31,0
+ jmp.n r1
+ addu r31,r31,16
diff --git a/lib/libc/arch/mips64/gen/Makefile.inc b/lib/libc/arch/mips64/gen/Makefile.inc
index bc18a54e966..0fca3d4c355 100644
--- a/lib/libc/arch/mips64/gen/Makefile.inc
+++ b/lib/libc/arch/mips64/gen/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.10 2011/07/08 19:21:41 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.11 2011/07/08 22:28:33 martynas Exp $
-SRCS+= _setjmp.S infinity.c ldexp.S nan.c
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.S modf.S nan.c
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c
diff --git a/lib/libc/arch/mips64/gen/fabs.S b/lib/libc/arch/mips64/gen/fabs.S
new file mode 100644
index 00000000000..a21bc42dc60
--- /dev/null
+++ b/lib/libc/arch/mips64/gen/fabs.S
@@ -0,0 +1,46 @@
+/* $OpenBSD: fabs.S,v 1.7 2011/07/08 22:28:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <machine/asm.h>
+
+/*
+ * fabs(x)
+ * double x;
+ *
+ * Return absolute value of x.
+ */
+LEAF(fabs, 0)
+ .set noreorder
+ j ra
+ abs.d $f0, $f12 # compute absolute value of x
+END(fabs)
diff --git a/lib/libc/arch/mips64/gen/modf.S b/lib/libc/arch/mips64/gen/modf.S
new file mode 100644
index 00000000000..029e7044191
--- /dev/null
+++ b/lib/libc/arch/mips64/gen/modf.S
@@ -0,0 +1,71 @@
+/* $OpenBSD: modf.S,v 1.5 2011/07/08 22:28:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1991, 1993, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <machine/asm.h>
+
+/*
+ * double modf(val, iptr)
+ * double val, *iptr;
+ * returns: xxx and n (in *iptr) where val == n.xxx
+ */
+LEAF(modf, 0)
+ .set reorder
+ cfc1 t0, $31 # get the control register
+ li.d $f2, 4503599627370496e0 # f2 <- 2^52
+
+ or t1, t0, 0x3 # set rounding mode to round to zero
+ xor t1, t1, 0x2 # (i.e., 01)
+ ctc1 t1, $31
+
+ mov.d $f0, $f12 # f0 <- f12
+ abs.d $f4, $f12 # f4 <- |f12|
+ c.olt.d $f4, $f2 # f4 ? < f2
+ bc1f 1f # leave f0 alone if Nan, infinity
+ # or >=2^52
+ c.eq.d $f12,$f4 # was f12 positive ?
+ add.d $f4,$f2,$f4 # round off to integer
+ bc1f 2f # No -> will have to negate result
+ sub.d $f0,$f4,$f2 # Remove fudge factor
+ j 1f # integer fraction got
+2:
+ sub.d $f0,$f2,$f4 # Remove fudge factor and negate
+1:
+ ctc1 t0, $31 # restore old rounding mode
+#ifdef __mips64
+ s.d $f0, 0(a1) # save the integer part
+#else
+ s.d $f0, 0(a2) # save the integer part
+#endif
+ sub.d $f0, $f12, $f0 # subtract val - integer part
+ j ra
+END(modf)
diff --git a/lib/libc/arch/powerpc/gen/Makefile.inc b/lib/libc/arch/powerpc/gen/Makefile.inc
index a34902b061f..80766c400a2 100644
--- a/lib/libc/arch/powerpc/gen/Makefile.inc
+++ b/lib/libc/arch/powerpc/gen/Makefile.inc
@@ -1,4 +1,5 @@
-SRCS+= infinity.c setjmp.S sigsetjmp.S flt_rounds.c ldexp.c nan.c
+SRCS+= infinity.c setjmp.S sigsetjmp.S flt_rounds.c ldexp.c modf.c nan.c
+SRCS+= fabs.c
SRCS+= fpgetmask.c fpsetmask.c
SRCS+= fpgetround.c fpsetround.c
SRCS+= fpgetsticky.c fpsetsticky.c
diff --git a/lib/libc/arch/powerpc/gen/fabs.c b/lib/libc/arch/powerpc/gen/fabs.c
new file mode 100644
index 00000000000..fcd6f671e80
--- /dev/null
+++ b/lib/libc/arch/powerpc/gen/fabs.c
@@ -0,0 +1,38 @@
+/* $OpenBSD: fabs.c,v 1.6 2011/07/08 22:28:33 martynas Exp $ */
+
+/*
+ * Copyright (c) 2002 Theo de Raadt
+ * All rights reserved.
+ *
+ * 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 AUTHOR ``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 AUTHOR 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>
+#include <math.h>
+
+double
+fabs(double x)
+{
+ __asm__ __volatile("fabs %0,%1" : "=f"(x) : "f"(x));
+ return (x);
+}
+
+__weak_alias(fabsl, fabs);
diff --git a/lib/libc/arch/sh/gen/Makefile.inc b/lib/libc/arch/sh/gen/Makefile.inc
index 5566687b208..55de1973b30 100644
--- a/lib/libc/arch/sh/gen/Makefile.inc
+++ b/lib/libc/arch/sh/gen/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.9 2011/07/08 19:21:42 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.10 2011/07/08 22:28:33 martynas Exp $
-SRCS+= flt_rounds.c infinity.c ldexp.c nan.c setjmp.S _setjmp.S
+SRCS+= flt_rounds.c infinity.c ldexp.c modf.c nan.c setjmp.S _setjmp.S
SRCS+= sigsetjmp.S
-SRCS+= fpgetmask.c fpgetround.c fpgetsticky.c \
+SRCS+= fabs.c fpgetmask.c fpgetround.c fpgetsticky.c \
fpsetmask.c fpsetround.c fpsetsticky.c
diff --git a/lib/libc/arch/sh/gen/fabs.c b/lib/libc/arch/sh/gen/fabs.c
new file mode 100644
index 00000000000..b7396043b43
--- /dev/null
+++ b/lib/libc/arch/sh/gen/fabs.c
@@ -0,0 +1,40 @@
+/* $OpenBSD: fabs.c,v 1.9 2011/07/08 22:28:33 martynas Exp $ */
+/*
+ * Copyright (c) 2006 Miodrag Vallat.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice, this permission notice, and the disclaimer below
+ * appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/cdefs.h>
+#if !defined(__SH4__) || defined(__SH4_NOFPU__)
+#include <sys/types.h>
+#include <machine/ieee.h>
+#endif /* !defined(__SH4__) || defined(__SH4_NOFPU__) */
+
+#include <math.h>
+
+double
+fabs(double d)
+{
+#if defined(__SH4__) && !defined(__SH4_NOFPU__)
+ __asm__ __volatile__("fabs %0" : "+f" (d));
+#else
+ struct ieee_double *p = (struct ieee_double *)&d;
+
+ p->dbl_sign = 0;
+#endif
+ return (d);
+}
+
+__weak_alias(fabsl, fabs);
diff --git a/lib/libc/arch/sparc/gen/Makefile.inc b/lib/libc/arch/sparc/gen/Makefile.inc
index f47b5e53980..61aedf50cce 100644
--- a/lib/libc/arch/sparc/gen/Makefile.inc
+++ b/lib/libc/arch/sparc/gen/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.11 2011/07/08 19:21:42 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.12 2011/07/08 22:28:33 martynas Exp $
-SRCS+= _setjmp.S infinity.c ldexp.c nan.c
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.c modf.S nan.c
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
SRCS+= fixunsdfsi.S mul.S umul.S saveregs.S setjmp.S sigsetjmp.S
diff --git a/lib/libc/arch/sparc/gen/fabs.S b/lib/libc/arch/sparc/gen/fabs.S
new file mode 100644
index 00000000000..f69a03884df
--- /dev/null
+++ b/lib/libc/arch/sparc/gen/fabs.S
@@ -0,0 +1,44 @@
+/* $OpenBSD: fabs.S,v 1.8 2011/07/08 22:28:33 martynas Exp $ */
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+/* fabs - floating absolute value */
+
+#include "DEFS.h"
+
+WEAK_ALIAS(fabsl, fabs)
+ENTRY(fabs)
+ std %o0, [%sp + 32] ! return value => %f0:f1
+ ldd [%sp + 32], %f0 ! (via kernel %o0/%o1 slot)
+ retl
+ fabss %f0, %f0 ! return absolute value
diff --git a/lib/libc/arch/sparc/gen/modf.S b/lib/libc/arch/sparc/gen/modf.S
new file mode 100644
index 00000000000..8bdedf8641b
--- /dev/null
+++ b/lib/libc/arch/sparc/gen/modf.S
@@ -0,0 +1,186 @@
+/* $OpenBSD: modf.S,v 1.7 2011/07/08 22:28:33 martynas Exp $ */
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 "DEFS.h"
+#include <machine/fsr.h>
+
+/*
+ * double modf(double val, double *iptr)
+ *
+ * Returns the fractional part of `val', storing the integer part of
+ * `val' in *iptr. Both *iptr and the return value have the same sign
+ * as `val'.
+ *
+ * Method:
+ *
+ * We use the fpu's normalization hardware to compute the integer portion
+ * of the double precision argument. Sun IEEE double precision numbers
+ * have 52 bits of mantissa, 11 bits of exponent, and one bit of sign,
+ * with the sign occupying bit 31 of word 0, and the exponent bits 30:20
+ * of word 0. Thus, values >= 2^52 are by definition integers.
+ *
+ * If we take a value that is in the range [+0..2^52) and add 2^52, all
+ * of the fractional bits fall out and all of the integer bits are summed
+ * with 2^52. If we then subtract 2^52, we get those integer bits back.
+ * This must be done with rounding set to `towards 0' or `towards -inf'.
+ * `Toward -inf' fails when the value is 0 (we get -0 back)....
+ *
+ * Note that this method will work anywhere, but is machine dependent in
+ * various aspects.
+ *
+ * Stack usage:
+ * 4@[%fp - 4] saved %fsr
+ * 4@[%fp - 8] new %fsr with rounding set to `towards 0'
+ * 8@[%fp - 16] space for moving between %i and %f registers
+ * Register usage:
+ * %i0%i1 double val;
+ * %l0 scratch
+ * %l1 sign bit (0x80000000)
+ * %i2 double *iptr;
+ * %f2:f3 `magic number' 2^52, in fpu registers
+ * %f4:f5 double v, in fpu registers
+ */
+
+ .align 8
+Lmagic:
+ .word 0x43300000 ! sign = 0, exponent = 52 + 1023, mantissa = 0
+ .word 0 ! (i.e., .double 0r4503599627370496e+00)
+
+L0:
+ .word 0 ! 0.0
+ .word 0
+
+ENTRY(modf)
+ save %sp, -64-16, %sp
+
+ /*
+ * First, compute v = abs(val) by clearing sign bit,
+ * and then set up the fpu registers. This would be
+ * much easier if we could do alu operations on fpu registers!
+ */
+ sethi %hi(0x80000000), %l1 ! sign bit
+ andn %i0, %l1, %l0
+ st %l0, [%fp - 16]
+#ifdef PIC
+ PICCY_SET(Lmagic, %l0, %o7)
+ ldd [%l0], %f2
+#else
+ sethi %hi(Lmagic), %l0
+ ldd [%l0 + %lo(Lmagic)], %f2
+#endif
+ st %i1, [%fp - 12]
+ ldd [%fp - 16], %f4 ! %f4:f5 = v
+
+ /*
+ * Is %f4:f5 >= %f2:f3 ? If so, it is all integer bits.
+ * It is probably less, though.
+ */
+ fcmped %f4, %f2
+ nop ! fpop2 delay
+ fbuge Lbig ! if >= (or unordered), go out
+ nop
+
+ /*
+ * v < 2^52, so add 2^52, then subtract 2^52, but do it all
+ * with rounding set towards zero. We leave any enabled
+ * traps enabled, but change the rounding mode. This might
+ * not be so good. Oh well....
+ */
+ st %fsr, [%fp - 4] ! %l5 = current FSR mode
+ set FSR_RD, %l3 ! %l3 = rounding direction mask
+ ld [%fp - 4], %l5
+ set FSR_RD_RZ << FSR_RD_SHIFT, %l4
+ andn %l5, %l3, %l6
+ or %l6, %l4, %l6 ! round towards zero, please
+ and %l5, %l3, %l5 ! save original rounding mode
+ st %l6, [%fp - 8]
+ ld [%fp - 8], %fsr
+
+ faddd %f4, %f2, %f4 ! %f4:f5 += 2^52
+ fsubd %f4, %f2, %f4 ! %f4:f5 -= 2^52
+
+ /*
+ * Restore %fsr, but leave exceptions accrued.
+ */
+ st %fsr, [%fp - 4]
+ ld [%fp - 4], %l6
+ andn %l6, %l3, %l6 ! %l6 = %fsr & ~FSR_RD;
+ or %l5, %l6, %l5 ! %l5 |= %l6;
+ st %l5, [%fp - 4]
+ ld [%fp - 4], %fsr ! restore %fsr, leaving accrued stuff
+
+ /*
+ * Now insert the original sign in %f4:f5.
+ * This is a lot of work, so it is conditional here.
+ */
+ btst %l1, %i0
+ be 1f
+ nop
+ st %f4, [%fp - 16]
+ ld [%fp - 16], %g1
+ or %l1, %g1, %g1
+ st %g1, [%fp - 16]
+ ld [%fp - 16], %f4
+1:
+
+ /*
+ * The value in %f4:f5 is now the integer portion of the original
+ * argument. We need to store this in *ival (%i2), subtract it
+ * from the original value argument (%i0:i1), and return the result.
+ */
+ std %f4, [%i2] ! *ival = %f4:f5;
+ std %i0, [%fp - 16]
+ ldd [%fp - 16], %f0 ! %f0:f1 = val;
+ fsubd %f0, %f4, %f0 ! %f0:f1 -= %f4:f5;
+ ret
+ restore
+
+Lbig:
+ /*
+ * We get here if the original comparison of %f4:f5 (v) to
+ * %f2:f3 (2^52) came out `greater or unordered'. In this
+ * case the integer part is the original value, and the
+ * fractional part is 0.
+ */
+#ifdef PIC
+ PICCY_SET(L0, %l0, %o7)
+ std %f0, [%i2] ! *ival = val;
+ ldd [%l0], %f0 ! return 0.0;
+#else
+ sethi %hi(L0), %l0
+ std %f0, [%i2] ! *ival = val;
+ ldd [%l0 + %lo(L0)], %f0 ! return 0.0;
+#endif
+ ret
+ restore
diff --git a/lib/libc/arch/sparc64/gen/Makefile.inc b/lib/libc/arch/sparc64/gen/Makefile.inc
index 4a38fffef49..d4b42cf70f0 100644
--- a/lib/libc/arch/sparc64/gen/Makefile.inc
+++ b/lib/libc/arch/sparc64/gen/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.10 2011/07/08 19:21:42 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.11 2011/07/08 22:28:33 martynas Exp $
-SRCS+= _setjmp.S infinity.c ldexp.c nan.c
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.c modf.S nan.c
SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
fpsetround.c fpsetsticky.c
SRCS+= fpclassifyl.c isfinitel.c isinfl.c isnanl.c isnormall.c signbitl.c
diff --git a/lib/libc/arch/sparc64/gen/fabs.S b/lib/libc/arch/sparc64/gen/fabs.S
new file mode 100644
index 00000000000..492250c3f41
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/fabs.S
@@ -0,0 +1,42 @@
+/* $OpenBSD: fabs.S,v 1.7 2011/07/08 22:28:33 martynas Exp $ */
+/* $NetBSD: fabs.S,v 1.2 2000/07/23 07:12:22 eeh Exp $ */
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <machine/asm.h>
+
+/* fabs - floating absolute value */
+
+ENTRY(fabs)
+ retl
+ fabsd %f0, %f0 ! return absolute value
diff --git a/lib/libc/arch/sparc64/gen/modf.S b/lib/libc/arch/sparc64/gen/modf.S
new file mode 100644
index 00000000000..48023098a37
--- /dev/null
+++ b/lib/libc/arch/sparc64/gen/modf.S
@@ -0,0 +1,181 @@
+/* $OpenBSD: modf.S,v 1.5 2011/07/08 22:28:33 martynas Exp $ */
+/* $NetBSD: modf.S,v 1.3 2000/11/01 23:32:41 eeh Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <machine/asm.h>
+
+#include <machine/fsr.h>
+
+/*
+ * double modf(double val, double *iptr)
+ *
+ * Returns the fractional part of `val', storing the integer part of
+ * `val' in *iptr. Both *iptr and the return value have the same sign
+ * as `val'.
+ *
+ * Method:
+ *
+ * We use the fpu's normalization hardware to compute the integer portion
+ * of the double precision argument. Sun IEEE double precision numbers
+ * have 52 bits of mantissa, 11 bits of exponent, and one bit of sign,
+ * with the sign occupying bit 31 of word 0, and the exponent bits 30:20
+ * of word 0. Thus, values >= 2^52 are by definition integers.
+ *
+ * If we take a value that is in the range [+0..2^52) and add 2^52, all
+ * of the fractional bits fall out and all of the integer bits are summed
+ * with 2^52. If we then subtract 2^52, we get those integer bits back.
+ * This must be done with rounding set to `towards 0' or `towards -inf'.
+ * `Toward -inf' fails when the value is 0 (we get -0 back)....
+ *
+ * Note that this method will work anywhere, but is machine dependent in
+ * various aspects.
+ *
+ * Stack usage:
+ * 4@[%fp + BIAS - 4] saved %fsr
+ * 4@[%fp + BIAS - 8] new %fsr with rounding set to `towards 0'
+ * 8@[%fp + BIAS - 16] space for moving between %i and %f registers
+ * Register usage:
+ * %f0:f1 double val;
+ * %l0 scratch
+ * %l1 sign bit (0x80000000)
+ * %i1 double *iptr;
+ * %f2:f3 `magic number' 2^52, in fpu registers
+ * %f4:f5 double v, in fpu registers
+ * %f6:f7 double temp.
+ */
+
+ .align 8
+Lmagic:
+ .word 0x43300000 ! sign = 0, exponent = 52 + 1023, mantissa = 0
+ .word 0 ! (i.e., .double 0r4503599627370496e+00)
+
+L0:
+ .word 0 ! 0.0
+ .word 0
+
+ENTRY(modf)
+ save %sp, -CC64FSZ-16, %sp
+
+ /*
+ * First, compute v = abs(val)
+ */
+ fabsd %f0, %f4 ! %f4:f5 = v
+ fcmped %fcc1, %f0, %f4 ! %fcc1 = (val == abs(val))
+#ifdef PIC
+ PICCY_SET(Lmagic, %l0, %o7)
+ ldd [%l0], %f2
+#else
+ sethi %hi(Lmagic), %l0
+ ldd [%l0 + %lo(Lmagic)], %f2
+#endif
+
+ /*
+ * Is %f4:f5 >= %f2:f3 ? If so, it is all integer bits.
+ * It is probably less, though.
+ */
+ fcmped %f4, %f2
+ fbuge Lbig ! if >= (or unordered), go out
+ nop
+
+ /*
+ * v < 2^52, so add 2^52, then subtract 2^52, but do it all
+ * with rounding set towards zero. We leave any enabled
+ * traps enabled, but change the rounding mode. This might
+ * not be so good. Oh well....
+ */
+ st %fsr, [%fp + BIAS - 4] ! %l5 = current FSR mode
+ set FSR_RD, %l3 ! %l3 = rounding direction mask
+ ld [%fp + BIAS - 4], %l5
+ set FSR_RD_RZ << FSR_RD_SHIFT, %l4
+ andn %l5, %l3, %l6
+ or %l6, %l4, %l6 ! round towards zero, please
+ and %l5, %l3, %l5 ! save original rounding mode
+ st %l6, [%fp + BIAS - 8]
+ ld [%fp + BIAS - 8], %fsr
+
+ faddd %f4, %f2, %f4 ! %f4:f5 += 2^52
+ fsubd %f4, %f2, %f4 ! %f4:f5 -= 2^52
+
+ /*
+ * Restore %fsr, but leave exceptions accrued.
+ */
+ st %fsr, [%fp + BIAS - 4]
+ ld [%fp + BIAS - 4], %l6
+ andn %l6, %l3, %l6 ! %l6 = %fsr & ~FSR_RD;
+ or %l5, %l6, %l5 ! %l5 |= %l6;
+ st %l5, [%fp + BIAS - 4]
+ ld [%fp + BIAS - 4], %fsr ! restore %fsr, leaving accrued stuff
+
+ /*
+ * Now insert the original sign in %f4:f5.
+ * %fcc1 should still have the reults of (val == abs(val))
+ * from above, so we use a conditional move on %fcc1 to:
+ *
+ * %f4 = (val == abs(val)) ? %f4 : -%f4
+ *
+ */
+ fnegd %f4, %f6
+ fmovdnz %fcc1, %f6, %f4
+1:
+
+ /*
+ * The value in %f4:f5 is now the integer portion of the original
+ * argument. We need to store this in *ival (%i1), subtract it
+ * from the original value argument (%d0), and return the result.
+ */
+ std %f4, [%i1] ! *ival = %f4:f5;
+ fsubd %f0, %f4, %f0 ! %f0:f1 -= %f4:f5;
+ ret
+ restore
+
+Lbig:
+ /*
+ * We get here if the original comparison of %f4:f5 (v) to
+ * %f2:f3 (2^52) came out `greater or unordered'. In this
+ * case the integer part is the original value, and the
+ * fractional part is 0.
+ */
+#ifdef PIC
+ PICCY_SET(L0, %l0, %o7)
+ std %f0, [%i1] ! *ival = val;
+ ldd [%l0], %f0 ! return 0.0;
+#else
+ sethi %hi(L0), %l0
+ std %f0, [%i1] ! *ival = val;
+ ldd [%l0 + %lo(L0)], %f0 ! return 0.0;
+#endif
+ ret
+ restore
+
diff --git a/lib/libc/arch/vax/gen/Makefile.inc b/lib/libc/arch/vax/gen/Makefile.inc
index 7741bc2d65f..c7a7fa9b942 100644
--- a/lib/libc/arch/vax/gen/Makefile.inc
+++ b/lib/libc/arch/vax/gen/Makefile.inc
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile.inc,v 1.8 2011/07/08 19:21:42 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.9 2011/07/08 22:28:33 martynas Exp $
-SRCS+= _setjmp.S infinity.c ldexp.S \
+SRCS+= _setjmp.S fabs.S infinity.c ldexp.S modf.S \
setjmp.S udiv.S urem.S sigsetjmp.S
SRCS+= alloca.S
diff --git a/lib/libc/arch/vax/gen/fabs.S b/lib/libc/arch/vax/gen/fabs.S
new file mode 100644
index 00000000000..d50520eebf3
--- /dev/null
+++ b/lib/libc/arch/vax/gen/fabs.S
@@ -0,0 +1,41 @@
+/* $OpenBSD: fabs.S,v 1.8 2011/07/08 22:28:33 martynas Exp $ */
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+/* fabs - floating absolute value */
+
+#include "DEFS.h"
+
+WEAK_ALIAS(fabsl,fabs)
+ENTRY(fabs, 0)
+ movd 4(ap),r0
+ bgeq 1f
+ mnegd r0,r0
+1:
+ ret
diff --git a/lib/libc/arch/vax/gen/frexp.c b/lib/libc/arch/vax/gen/frexp.c
new file mode 100644
index 00000000000..d146e9b294d
--- /dev/null
+++ b/lib/libc/arch/vax/gen/frexp.c
@@ -0,0 +1,69 @@
+/* $OpenBSD: frexp.c,v 1.10 2011/07/08 22:28:33 martynas Exp $ */
+/*-
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+/* LINTLIBRARY */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <math.h>
+
+double
+frexp(value, eptr)
+ double value;
+ int *eptr;
+{
+ union {
+ double v;
+ struct {
+ u_int u_mant1 : 7;
+ u_int u_exp : 8;
+ u_int u_sign : 1;
+ u_int u_mant2 : 16;
+ u_int u_mant3 : 32;
+ } s;
+ } u;
+
+ if (value) {
+ u.v = value;
+ *eptr = u.s.u_exp - 128;
+ u.s.u_exp = 128;
+ return(u.v);
+ } else {
+ *eptr = 0;
+ return((double)0);
+ }
+}
+
+#ifdef lint
+/* PROTOLIB1 */
+long double frexpl(long double, int *);
+#else /* lint */
+__weak_alias(frexpl, frexp);
+#endif /* lint */
diff --git a/lib/libc/arch/vax/gen/modf.S b/lib/libc/arch/vax/gen/modf.S
new file mode 100644
index 00000000000..1659059831f
--- /dev/null
+++ b/lib/libc/arch/vax/gen/modf.S
@@ -0,0 +1,54 @@
+/* $OpenBSD: modf.S,v 1.8 2011/07/08 22:28:33 martynas Exp $ */
+/*
+ * Copyright (c) 1983, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+/*
+ * double modf (value, iptr)
+ * double value, *iptr;
+ *
+ * Modf returns the fractional part of "value",
+ * and stores the integer part indirectly through "iptr".
+ */
+
+#include "DEFS.h"
+
+ENTRY(modf, R2)
+ cvtdl 4(ap),r2
+ bvs 0f
+ cvtld r2,*12(ap)
+ subd3 *12(ap),4(ap),r0
+ ret
+0:
+ emodd 4(ap),$0,$0f1.0,r2,r0
+ bvs 1f # integer overflow
+ cvtld r2,*12(ap)
+ ret
+1:
+ subd3 r0,4(ap),*12(ap)
+ ret
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 03165e1a5b6..28dc6e4dce0 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.51 2011/07/08 19:21:42 martynas Exp $
+# $OpenBSD: Makefile.inc,v 1.52 2011/07/08 22:28:33 martynas Exp $
# gen sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen ${LIBCSRCDIR}/gen
@@ -6,7 +6,7 @@
SRCS+= alarm.c assert.c auth_subr.c authenticate.c \
basename.c clock.c closedir.c confstr.c ctermid.c ctype_.c \
daemon.c devname.c dirname.c disklabel.c elf_hash.c err.c \
- errx.c errlist.c errno.c exec.c fnmatch.c fpclassify.c \
+ errx.c errlist.c errno.c exec.c fnmatch.c fpclassify.c frexp.c \
fstab.c ftok.c fts.c ftw.c getbsize.c getcap.c getcwd.c \
getdomainname.c getgrent.c getgrouplist.c gethostname.c \
getloadavg.c getlogin.c getmntinfo.c getnetgrent.c getpagesize.c \
@@ -30,7 +30,8 @@ SRCS+= _sys_errlist.c _sys_nerr.c _sys_siglist.c
# machine-dependent gen sources
# m-d Makefile.inc must include sources for:
-# _setjmp() infinity ldexp() nan setjmp() sigsetjmp()
+# _setjmp() fabs() frexp() infinity ldexp() modf() nan
+# setjmp() sigsetjmp()
.include "${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen/Makefile.inc"
@@ -48,7 +49,7 @@ errlst.o errlst.po:
MAN+= alarm.3 auth_subr.3 authenticate.3 basename.3 clock.3 confstr.3 \
ctermid.3 ctype.3 daemon.3 devname.3 directory.3 dirname.3 err.3 \
- exec.3 fnmatch.3 fpclassify.3 fpgetmask.3 ftok.3 fts.3 ftw.3 \
+ exec.3 fnmatch.3 fpclassify.3 fpgetmask.3 frexp.3 ftok.3 fts.3 ftw.3 \
getbsize.3 getcap.3 getcwd.3 getdomainname.3 getdiskbyname.3 \
getfsent.3 getgrent.3 getgrouplist.3 gethostname.3 getloadavg.3 \
getmntinfo.3 getnetgrent.3 getpagesize.3 getpass.3 getpwent.3 \
@@ -56,7 +57,7 @@ MAN+= alarm.3 auth_subr.3 authenticate.3 basename.3 clock.3 confstr.3 \
getttyent.3 getusershell.3 glob.3 initgroups.3 isalnum.3 isalpha.3 \
isascii.3 isblank.3 iscntrl.3 isdigit.3 isfdtype.3 isgraph.3 \
isgreater.3 islower.3 isprint.3 ispunct.3 isspace.3 isupper.3 \
- isxdigit.3 ldexp.3 lockf.3 login_cap.3 nice.3 nlist.3 pause.3 \
+ isxdigit.3 ldexp.3 lockf.3 login_cap.3 modf.3 nice.3 nlist.3 pause.3 \
popen.3 psignal.3 pw_dup.3 pwcache.3 raise.3 readpassphrase.3 \
scandir.3 setjmp.3 setmode.3 setproctitle.3 siginterrupt.3 signal.3 \
sigsetops.3 sleep.3 statvfs.3 sysconf.3 sysctl.3 strtofflags.3 \
@@ -91,6 +92,7 @@ MLINKS+=fpclassify.3 finite.3 fpclassify.3 finitef.3 fpclassify.3 isfinite.3 \
MLINKS+=fpgetmask.3 fpgetround.3 fpgetmask.3 fpgetsticky.3 \
fpgetmask.3 fpsetmask.3 fpgetmask.3 fpsetround.3 \
fpgetmask.3 fpsetsticky.3
+MLINKS+=frexp.3 frexpf.3 frexp.3 frexpl.3
MLINKS+=fts.3 fts_open.3 fts.3 fts_read.3 fts.3 fts_children.3 \
fts.3 fts_set.3 fts.3 fts_close.3
MLINKS+=ftw.3 nftw.3
@@ -122,6 +124,7 @@ MLINKS+=login_cap.3 login_getclass.3 login_cap.3 login_getstyle.3 login_cap.3 \
login_getcapsize.3 login_cap.3 login_getcapstr.3 login_cap.3 \
login_getcaptime.3 login_cap.3 login_close.3 login_cap.3 \
secure_path.3 login_cap.3 setclasscontext.3 login_cap.3 setusercontext.3
+MLINKS+=modf.3 modff.3
MLINKS+=popen.3 pclose.3
MLINKS+=psignal.3 sys_siglist.3 psignal.3 sys_signame.3
MLINKS+=pwcache.3 user_from_uid.3 pwcache.3 group_from_gid.3
diff --git a/lib/libc/gen/frexp.3 b/lib/libc/gen/frexp.3
new file mode 100644
index 00000000000..2ba0daa8ce2
--- /dev/null
+++ b/lib/libc/gen/frexp.3
@@ -0,0 +1,95 @@
+.\" $OpenBSD: frexp.3,v 1.12 2011/07/08 22:28:33 martynas Exp $
+.\"
+.\" Copyright (c) 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" 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.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.Dd $Mdocdate: July 8 2011 $
+.Dt FREXP 3
+.Os
+.Sh NAME
+.Nm frexp ,
+.Nm frexpf ,
+.Nm frexpl
+.Nd convert floating-point number to fractional and integral components
+.Sh SYNOPSIS
+.Fd #include <math.h>
+.Ft double
+.Fn frexp "double value" "int *exp"
+.Ft float
+.Fn frexpf "float value" "int *exp"
+.Ft long double
+.Fn frexpl "long double value" "int *exp"
+.Sh DESCRIPTION
+The
+.Fn frexp
+function breaks a floating-point number into a normalized
+fraction and an integral power of 2.
+It stores the integer in the
+.Li int
+object pointed to by
+.Fa exp .
+The
+.Fn frexpf
+function is a single precision version of
+.Fn frexp .
+The
+.Fn frexpl
+function is an extended precision version of
+.Fn frexp .
+.Sh RETURN VALUES
+The
+.Fn frexp ,
+.Fn frexpf
+and
+.Fn frexpl
+functions return the value
+.Li x ,
+such that
+.Li x
+is a
+.Li double
+with magnitude in the interval [1/2,\ 1) or zero, and
+.Fa value
+equals
+.Li x
+times 2 raised to the power
+.Fa *exp .
+If
+.Fa value
+is zero, both parts of the result are zero.
+.Sh SEE ALSO
+.Xr ldexp 3 ,
+.Xr modf 3
+.Sh STANDARDS
+The
+.Fn frexp
+function conforms to
+.St -ansiC .
diff --git a/lib/libc/gen/frexp.c b/lib/libc/gen/frexp.c
new file mode 100644
index 00000000000..97cc624035a
--- /dev/null
+++ b/lib/libc/gen/frexp.c
@@ -0,0 +1,79 @@
+/* $OpenBSD: frexp.c,v 1.7 2011/07/08 22:28:33 martynas Exp $ */
+
+/*-
+ * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
+ * All rights reserved.
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $FreeBSD: frexp.c,v 1.1 2004/07/18 21:23:39 das Exp $
+ */
+
+/* LINTLIBRARY */
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <machine/ieee.h>
+#include <float.h>
+#include <math.h>
+
+double
+frexp(double v, int *ex)
+{
+ union {
+ double v;
+ struct ieee_double s;
+ } u;
+
+ u.v = v;
+ switch (u.s.dbl_exp) {
+ case 0: /* 0 or subnormal */
+ if ((u.s.dbl_fracl | u.s.dbl_frach) == 0) {
+ *ex = 0;
+ } else {
+ /*
+ * The power of 2 is arbitrary, any value from 54 to
+ * 1024 will do.
+ */
+ u.v *= 0x1.0p514;
+ *ex = u.s.dbl_exp - (DBL_EXP_BIAS - 1 + 514);
+ u.s.dbl_exp = DBL_EXP_BIAS - 1;
+ }
+ break;
+ case DBL_EXP_INFNAN: /* Inf or NaN; value of *ex is unspecified */
+ break;
+ default: /* normal */
+ *ex = u.s.dbl_exp - (DBL_EXP_BIAS - 1);
+ u.s.dbl_exp = DBL_EXP_BIAS - 1;
+ break;
+ }
+ return (u.v);
+}
+
+#if LDBL_MANT_DIG == 53
+#ifdef lint
+/* PROTOLIB1 */
+long double frexpl(long double, int *);
+#else /* lint */
+__weak_alias(frexpl, frexp);
+#endif /* lint */
+#endif /* LDBL_MANT_DIG == 53 */
diff --git a/lib/libc/gen/modf.3 b/lib/libc/gen/modf.3
new file mode 100644
index 00000000000..aa5434b5d17
--- /dev/null
+++ b/lib/libc/gen/modf.3
@@ -0,0 +1,76 @@
+.\" $OpenBSD: modf.3,v 1.10 2011/07/08 22:28:33 martynas Exp $
+.\"
+.\" Copyright (c) 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" 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.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+.\"
+.Dd $Mdocdate: July 8 2011 $
+.Dt MODF 3
+.Os
+.Sh NAME
+.Nm modf ,
+.Nm modff
+.Nd extract signed integral and fractional values from floating-point number
+.Sh SYNOPSIS
+.Fd #include <math.h>
+.Ft double
+.Fn modf "double value" "double *iptr"
+.Ft float
+.Fn modff "float value" "float *iptr"
+.Sh DESCRIPTION
+The
+.Fn modf
+function breaks the argument
+.Fa value
+into integral and fractional parts, each of which has the
+same sign as the argument.
+It stores the integral part as a
+.Li double
+in the object pointed to by
+.Fa iptr .
+The
+.Fn modff
+function is a single precision version of
+.Fn modf .
+.Sh RETURN VALUES
+The
+.Fn modf
+and
+.Fn modff
+functions return the signed fractional part of
+.Fa value .
+.Sh SEE ALSO
+.Xr frexp 3 ,
+.Xr ldexp 3
+.Sh STANDARDS
+The
+.Fn modf
+function conforms to
+.St -ansiC .
diff --git a/lib/libc/gen/modf.c b/lib/libc/gen/modf.c
new file mode 100644
index 00000000000..24effd38045
--- /dev/null
+++ b/lib/libc/gen/modf.c
@@ -0,0 +1,104 @@
+/* $OpenBSD: modf.c,v 1.3 2011/07/08 22:28:33 martynas Exp $ */
+/* $NetBSD: modf.c,v 1.1 1995/02/10 17:50:25 cgd Exp $ */
+
+/*
+ * Copyright (c) 1994, 1995 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ *
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ *
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
+ * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ *
+ * Carnegie Mellon requests users of this software to return to
+ *
+ * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
+ * School of Computer Science
+ * Carnegie Mellon University
+ * Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+#include <sys/types.h>
+#include <machine/ieee.h>
+#include <errno.h>
+#include <math.h>
+
+/*
+ * double modf(double val, double *iptr)
+ * returns: f and i such that |f| < 1.0, (f + i) = val, and
+ * sign(f) == sign(i) == sign(val).
+ *
+ * Beware signedness when doing subtraction, and also operand size!
+ */
+double
+modf(double val, double *iptr)
+{
+ union doub {
+ double v;
+ struct ieee_double s;
+ } u, v;
+ u_int64_t frac;
+
+ /*
+ * If input is Inf or NaN, return it and leave i alone.
+ */
+ u.v = val;
+ if (u.s.dbl_exp == DBL_EXP_INFNAN)
+ return (u.v);
+
+ /*
+ * If input can't have a fractional part, return
+ * (appropriately signed) zero, and make i be the input.
+ */
+ if ((int)u.s.dbl_exp - DBL_EXP_BIAS > DBL_FRACBITS - 1) {
+ *iptr = u.v;
+ v.v = 0.0;
+ v.s.dbl_sign = u.s.dbl_sign;
+ return (v.v);
+ }
+
+ /*
+ * If |input| < 1.0, return it, and set i to the appropriately
+ * signed zero.
+ */
+ if (u.s.dbl_exp < DBL_EXP_BIAS) {
+ v.v = 0.0;
+ v.s.dbl_sign = u.s.dbl_sign;
+ *iptr = v.v;
+ return (u.v);
+ }
+
+ /*
+ * There can be a fractional part of the input.
+ * If you look at the math involved for a few seconds, it's
+ * plain to see that the integral part is the input, with the
+ * low (DBL_FRACBITS - (exponent - DBL_EXP_BIAS)) bits zeroed,
+ * the fractional part is the part with the rest of the
+ * bits zeroed. Just zeroing the high bits to get the
+ * fractional part would yield a fraction in need of
+ * normalization. Therefore, we take the easy way out, and
+ * just use subtraction to get the fractional part.
+ */
+ v.v = u.v;
+ /* Zero the low bits of the fraction, the sleazy way. */
+ frac = ((u_int64_t)v.s.dbl_frach << 32) + v.s.dbl_fracl;
+ frac >>= DBL_FRACBITS - (u.s.dbl_exp - DBL_EXP_BIAS);
+ frac <<= DBL_FRACBITS - (u.s.dbl_exp - DBL_EXP_BIAS);
+ v.s.dbl_fracl = frac & 0xffffffff;
+ v.s.dbl_frach = frac >> 32;
+ *iptr = v.v;
+
+ u.v -= v.v;
+ u.s.dbl_sign = v.s.dbl_sign;
+ return (u.v);
+}
diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version
index 98a31a2a31f..d7c8404b7c2 100644
--- a/lib/libc/shlib_version
+++ b/lib/libc/shlib_version
@@ -1,4 +1,4 @@
-major=59
+major=60
minor=0
# note: If changes were made to include/thread_private.h or if system
# calls were added/changed then libpthread must also be updated.