Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/quad Add IEEE 754 versions of



details:   https://anonhg.NetBSD.org/src/rev/7b0feb2cc4b9
branches:  trunk
changeset: 789591:7b0feb2cc4b9
user:      matt <matt%NetBSD.org@localhost>
date:      Sat Aug 24 00:51:48 2013 +0000

description:
Add IEEE 754 versions of
        fixdfdi.c fixsfdi.c fixunsdfdi.c fixunssfdi.c
        floatdidf.c floatdisf.c floatundidf.c floatundisf.c
These don't FP so are well suited to softfloat implementation.

diffstat:

 lib/libc/quad/Makefile.inc          |  12 +++-
 lib/libc/quad/fixdfdi_ieee754.c     |  82 +++++++++++++++++++++++++++++++++++
 lib/libc/quad/fixsfdi_ieee754.c     |  75 ++++++++++++++++++++++++++++++++
 lib/libc/quad/fixunsdfdi_ieee754.c  |  85 +++++++++++++++++++++++++++++++++++++
 lib/libc/quad/fixunssfdi_ieee754.c  |  77 +++++++++++++++++++++++++++++++++
 lib/libc/quad/floatdidf_ieee754.c   |  75 ++++++++++++++++++++++++++++++++
 lib/libc/quad/floatdisf_ieee754.c   |  11 ++--
 lib/libc/quad/floatundidf_ieee754.c |  69 ++++++++++++++++++++++++++++++
 lib/libc/quad/floatundisf_ieee754.c |   9 ++-
 9 files changed, 483 insertions(+), 12 deletions(-)

diffs (truncated from 593 to 300 lines):

diff -r c679b484d8dd -r 7b0feb2cc4b9 lib/libc/quad/Makefile.inc
--- a/lib/libc/quad/Makefile.inc        Fri Aug 23 18:11:47 2013 +0000
+++ b/lib/libc/quad/Makefile.inc        Sat Aug 24 00:51:48 2013 +0000
@@ -1,13 +1,15 @@
-#      $NetBSD: Makefile.inc,v 1.16 2013/04/30 01:43:01 matt Exp $
+#      $NetBSD: Makefile.inc,v 1.17 2013/08/24 00:51:48 matt Exp $
 #      @(#)Makefile.inc        8.1 (Berkeley) 6/4/93
 
 # Quad support
 SRCS.quad=     cmpdi2.c ucmpdi2.c 
 SRCS.quad+=    divdi3.c moddi3.c 
+.if empty(LIBC_MACHINE_ARCH:Mearm*)
 SRCS.quad+=    fixdfdi.c fixsfdi.c
 SRCS.quad+=    fixunsdfdi.c fixunssfdi.c
 SRCS.quad+=    floatdidf.c floatdisf.c
-SRCS.quad+=    floatundisf.c floatundidf.c
+SRCS.quad+=    floatundidf.c floatundisf.c
+.endif
 SRCS.quad+=    muldi3.c
 SRCS.quad+=    negdi2.c
 SRCS.quad+=    qdivrem.c
@@ -17,8 +19,12 @@
 SRCS.quad+=    ashldi3.S ashrdi3.S lshrdi3.S
 .elif (${MACHINE_ARCH} == "m68000")
 SRCS.quad+=    ashldi3.S lshrdi3.S
-.elif (!empty{LIBC_MACHINE_ARCH:Mearm*})
+.elif !empty(LIBC_MACHINE_ARCH:Mearm*)
 SRCS.quad+=    ashldi3.c ashrdi3.c lshrdi3.c lshldi3.c
+SRCS.quad+=    floatdidf_ieee754.c floatdisf_ieee754.c
+SRCS.quad+=    floatundidf_ieee754.c floatundisf_ieee754.c
+SRCS.quad+=    fixdfdi_ieee754.c fixsfdi_ieee754.c
+SRCS.quad+=    fixunsdfdi_ieee754.c fixunssfdi_ieee754.c
 .else
 SRCS.quad+=    ashldi3.c ashrdi3.c lshrdi3.c
 .endif
diff -r c679b484d8dd -r 7b0feb2cc4b9 lib/libc/quad/fixdfdi_ieee754.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/quad/fixdfdi_ieee754.c   Sat Aug 24 00:51:48 2013 +0000
@@ -0,0 +1,82 @@
+/*     $NetBSD: fixdfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 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: fixdfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
+#include "softfloat/softfloat-for-gcc.h"
+#endif
+
+#include "quad.h"
+#include <limits.h>
+#include <stdbool.h>
+#include <machine/ieee.h>
+
+/*
+ * Convert double to signed quad.
+ * Not sure what to do with negative numbers---for now, anything out
+ * of range becomes UQUAD_MAX.
+ */
+quad_t
+__fixdfdi(double x)
+{
+       const union ieee_double_u ux = { .dblu_d = x };
+       signed int exp = ux.dblu_exp - DBL_EXP_BIAS;
+       const bool neg = ux.dblu_sign;
+       quad_t r;
+
+       if (exp >= 62)
+               return neg ? QUAD_MIN : QUAD_MAX;
+
+       r = 1 << DBL_FRACHBITS;         /* implicit bit */
+       r |= ux.dblu_frach;
+       exp -= DBL_FRACHBITS;
+       if (exp < 0) {
+               r >>= -exp;
+       } else if (exp > 0) {
+               r <<= DBL_FRACLBITS;
+               r |= ux.dblu_fracl;
+               exp -= DBL_FRACLBITS;
+               if (exp < 0) {
+                       r >>= -exp;
+               } else if (exp > 0) {
+                       r <<= exp;
+               }
+       }
+       return neg ? -r : r;
+}
diff -r c679b484d8dd -r 7b0feb2cc4b9 lib/libc/quad/fixsfdi_ieee754.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/quad/fixsfdi_ieee754.c   Sat Aug 24 00:51:48 2013 +0000
@@ -0,0 +1,75 @@
+/*     $NetBSD: fixsfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 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: fixsfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
+#include "softfloat/softfloat-for-gcc.h"
+#endif
+
+#include "quad.h"
+#include <limits.h>
+#include <stdbool.h>
+#include <machine/ieee.h>
+
+/*
+ * Convert float to signed quad.
+ */
+quad_t
+__fixsfdi(float x)
+{
+       const union ieee_single_u ux = { .sngu_f = x };
+       signed int exp = ux.sngu_exp - SNG_EXP_BIAS;
+       const bool neg = ux.sngu_sign;
+       quad_t r;
+
+       if (exp < 0)
+               return 0;
+       if (exp > 62)
+               return neg ? QUAD_MIN : QUAD_MAX;
+
+       r = 1 << SNG_FRACBITS;          /* implicit bit */
+       r |= ux.sngu_frac;
+       exp -= SNG_FRACBITS;
+       if (exp < 0) {
+               r >>= -exp;
+       } else if (exp > 0) {
+               r <<= exp;
+       }
+       return neg ? -r : r;
+}
diff -r c679b484d8dd -r 7b0feb2cc4b9 lib/libc/quad/fixunsdfdi_ieee754.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/quad/fixunsdfdi_ieee754.c        Sat Aug 24 00:51:48 2013 +0000
@@ -0,0 +1,85 @@
+/*     $NetBSD: fixunsdfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 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: fixunsdfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 matt Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#if defined(SOFTFLOAT) || defined(__ARM_EABI__)
+#include "softfloat/softfloat-for-gcc.h"
+#endif
+
+#include "quad.h"
+#include <limits.h>
+#include <machine/ieee.h>
+
+/*
+ * Convert double to unsigned quad.
+ * Not sure what to do with negative numbers---for now, anything out
+ * of range becomes UQUAD_MAX.
+ */
+u_quad_t
+__fixunsdfdi(double x)
+{
+       const union ieee_double_u ux = { .dblu_d = x };
+       signed int exp = ux.dblu_exp - DBL_EXP_BIAS;
+       u_quad_t r;
+
+       if (ux.dblu_sign)
+               return UQUAD_MAX;
+       if (exp > 63)
+               return UQUAD_MAX;
+       if (exp < 0)
+               return 0;
+
+       r = 1 << DBL_FRACHBITS;         /* implicit bit */
+       r |= ux.dblu_frach;
+       exp -= DBL_FRACHBITS;
+       if (exp == 0)
+               return r;
+       if (exp < 0)
+               return r >> -exp;
+
+       r <<= DBL_FRACLBITS;
+       r |= ux.dblu_fracl;
+       exp -= DBL_FRACLBITS;
+       if (exp == 0)
+               return r;
+       if (exp < 0)
+               return r >> -exp;
+
+       return r << exp;
+}
diff -r c679b484d8dd -r 7b0feb2cc4b9 lib/libc/quad/fixunssfdi_ieee754.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/quad/fixunssfdi_ieee754.c        Sat Aug 24 00:51:48 2013 +0000
@@ -0,0 +1,77 @@
+/*     $NetBSD: fixunssfdi_ieee754.c,v 1.1 2013/08/24 00:51:48 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



Home | Main Index | Thread Index | Old Index