Source-Changes-HG archive

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

[src/trunk]: src/lib/libc Add ieee754 versions of the compiler runtime functions



details:   https://anonhg.NetBSD.org/src/rev/924701da7da5
branches:  trunk
changeset: 767095:924701da7da5
user:      matt <matt%NetBSD.org@localhost>
date:      Sat Jul 09 02:30:27 2011 +0000

description:
Add ieee754 versions of the compiler runtime functions
        __fixuns{sf,df,tf}{si,di}.
Add an ieee754 version of the compiler runtime function __floatuntfdi

diffstat:

 lib/libc/arch/mips/Makefile.inc     |   13 +++-
 lib/libc/gen/fixunsdfsi_ieee754.c   |   65 +++++++++++++++++++++
 lib/libc/gen/fixunsgen64_ieee754.c  |   45 ++++++++++++++
 lib/libc/gen/fixunsgen_ieee754.c    |  110 ++++++++++++++++++++++++++++++++++++
 lib/libc/gen/fixunssfsi_ieee754.c   |   64 ++++++++++++++++++++
 lib/libc/gen/fixunstfdi_ieee754.c   |   72 +++++++++++++++++++++++
 lib/libc/gen/fixunstfsi_ieee754.c   |   71 +++++++++++++++++++++++
 lib/libc/quad/floatunditf_ieee754.c |  104 ++++++++++++++++++++++++++++++++++
 8 files changed, 542 insertions(+), 2 deletions(-)

diffs (truncated from 585 to 300 lines):

diff -r d3e613604fbb -r 924701da7da5 lib/libc/arch/mips/Makefile.inc
--- a/lib/libc/arch/mips/Makefile.inc   Sat Jul 09 02:28:31 2011 +0000
+++ b/lib/libc/arch/mips/Makefile.inc   Sat Jul 09 02:30:27 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.10 2011/01/26 01:18:48 pooka Exp $
+#      $NetBSD: Makefile.inc,v 1.11 2011/07/09 02:30:27 matt Exp $
 
 .include <bsd.own.mk>
 
@@ -9,6 +9,15 @@
 
 .if ${MKSOFTFLOAT} != "no"
 .include <softfloat/Makefile.inc>
-CPPFLAGS+= -DSOFTFLOAT_NEED_FIXUNS
 CPPFLAGS+= -DSOFTFLOAT
+
+SRCS+= fixunsgen_ieee754.c fixunssfsi_ieee754.c fixunsdfsi_ieee754.c
+SRCS+= fixunsgen64_ieee754.c #fixunssfdi.c fixunsdfdi.c
+.if ${MACHINE_ARCH} == "mips64eb" || ${MACHINE_ARCH} == "mips64el"
+SRCS+= fixunstfsi_ieee754.c fixunstfdi_ieee754.c
 .endif
+.endif
+
+.if ${MACHINE_ARCH} == "mips64eb" || ${MACHINE_ARCH} == "mips64el"
+SRCS+= floatunditf_ieee754.c
+.endif
diff -r d3e613604fbb -r 924701da7da5 lib/libc/gen/fixunsdfsi_ieee754.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gen/fixunsdfsi_ieee754.c Sat Jul 09 02:30:27 2011 +0000
@@ -0,0 +1,65 @@
+/*     $NetBSD: fixunsdfsi_ieee754.c,v 1.1 2011/07/09 02:30:27 matt Exp $      */
+/*-
+ * Copyright (c) 2011 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>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: fixunsdfsi_ieee754.c,v 1.1 2011/07/09 02:30:27 matt Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <float.h>
+#include <machine/ieee.h>
+
+uint32_t __fixunsgen32(int, bool, size_t, size_t, const uint32_t *);
+
+uint32_t __fixunsdfsi(double);
+
+/*
+ * Convert double to (unsigned) int.  All operations are done module 2^32.
+ */
+uint32_t
+__fixunsdfsi(double x)
+{
+       const union ieee_double_u dblu = { .dblu_d = x };
+       const uint32_t frac[(DBL_FRACBITS + 31)/32 + 1] = {
+               [0] = 0,
+               [1] = dblu.dblu_dbl.dbl_fracl,
+               [2] = dblu.dblu_dbl.dbl_frach,
+       };
+
+       return __fixunsgen32(
+               dblu.dblu_dbl.dbl_exp - DBL_EXP_BIAS,
+               dblu.dblu_dbl.dbl_sign != 0,
+               DBL_MANT_DIG,
+               DBL_FRACHBITS,
+               &frac[__arraycount(frac)-1]);
+}
diff -r d3e613604fbb -r 924701da7da5 lib/libc/gen/fixunsgen64_ieee754.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gen/fixunsgen64_ieee754.c        Sat Jul 09 02:30:27 2011 +0000
@@ -0,0 +1,45 @@
+/*     $NetBSD: fixunsgen64_ieee754.c,v 1.1 2011/07/09 02:30:27 matt 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 <sys/cdefs.h>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: fixunsgen64_ieee754.c,v 1.1 2011/07/09 02:30:27 matt Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#define        FIXUNSNAME(n)   n##64
+#define        UINTXX_T        uint64_t
+
+#include "fixunsgen_ieee754.c"
diff -r d3e613604fbb -r 924701da7da5 lib/libc/gen/fixunsgen_ieee754.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gen/fixunsgen_ieee754.c  Sat Jul 09 02:30:27 2011 +0000
@@ -0,0 +1,110 @@
+/*     $NetBSD: fixunsgen_ieee754.c,v 1.1 2011/07/09 02:30:27 matt 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 <sys/cdefs.h>
+
+#if !defined(FIXUNSNAME) && defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: fixunsgen_ieee754.c,v 1.1 2011/07/09 02:30:27 matt Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <float.h>
+
+#ifndef FIXUNSNAME
+#define        FIXUNSNAME(n)   n##32
+#define        UINTXX_T        uint32_t
+#endif
+
+__dso_hidden UINTXX_T
+       FIXUNSNAME(__fixunsgen)(int, bool, size_t, size_t, const uint32_t *);
+
+/*
+ * Convert double to (unsigned) int.  All operations are done module 2^32.
+ */
+UINTXX_T
+FIXUNSNAME(__fixunsgen)(int exp, bool sign, size_t mant_dig, size_t fracbits,
+       const uint32_t *frac)
+{
+       UINTXX_T tmp;
+
+       /*
+        * If it's less than 1 (negative exponent), it's going to round
+        * to zero.  If the exponent is so large that it is a multiple of
+        * 2^N, then x module 2^N will be 0.
+        */
+       if (__predict_false(exp < 0 || exp - mant_dig > sizeof(UINTXX_T)*8-1))
+               return 0;
+
+       /*
+        * This is simplier than it seems.  Basically we are constructing
+        * fixed binary representation of the floating point number tossing
+        * away bits that wont be in the modulis we return.
+        */
+       tmp = 1;
+       for (size_t ebits = exp;;) {
+               if (ebits <= fracbits) {
+                       /*
+                        * The current fraction has more bits than we need.
+                        * Shift the current value over and insert the bits
+                        * we want.  We're done.
+                        */
+                       tmp <<= ebits;
+                       tmp |= *frac >> (fracbits - ebits);
+                       break;
+               }
+               if (fracbits == sizeof(tmp)*4) {
+                       /*
+                        * Shifts must be < sizeof(type).  If it's going to be
+                        * sizeof(type), just replace the value.
+                        */
+                       tmp = *frac--;
+               } else {
+                       tmp <<= fracbits;
+                       tmp |= *frac--;
+               }
+               ebits -= fracbits;
+               fracbits = sizeof(frac[0]) * 4;
+       }
+
+       /*
+        * If the input was negative, make tmp negative module 2^32.
+        */
+       if (sign)
+               tmp = -tmp;
+
+       return tmp;
+}
diff -r d3e613604fbb -r 924701da7da5 lib/libc/gen/fixunssfsi_ieee754.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gen/fixunssfsi_ieee754.c Sat Jul 09 02:30:27 2011 +0000
@@ -0,0 +1,64 @@
+/*     $NetBSD: fixunssfsi_ieee754.c,v 1.1 2011/07/09 02:30:27 matt Exp $      */
+/*-
+ * Copyright (c) 2011 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>
+
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: fixunssfsi_ieee754.c,v 1.1 2011/07/09 02:30:27 matt Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdbool.h>
+#include <stdint.h>



Home | Main Index | Thread Index | Old Index