Source-Changes-HG archive

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

[src/trunk]: src Clean up some rampant code duplication wrt ieee number handl...



details:   https://anonhg.NetBSD.org/src/rev/ed4c39614018
branches:  trunk
changeset: 522446:ed4c39614018
user:      simonb <simonb%NetBSD.org@localhost>
date:      Tue Feb 19 13:08:12 2002 +0000

description:
Clean up some rampant code duplication wrt ieee number handling:
 - Add alignment-safe double and float unions.
 - Use the above for the __infinity and __nan constants on all
   architectures that use the standard ieee754 representation of
   those constants.
 - Add a single copy of various ieee754 math functions (frexp, isinf,
   isnan, ldexp and modf) that had numerous duplicates among the
   arch-specific directories.
 - Use the above functions on all architectures where the generic C
   versions where used.  Architectures that had local assembly
   routines are untouched (for those functions only).

diffstat:

 include/math.h                           |   30 +++++-
 lib/libc/arch/alpha/gen/Makefile.inc     |   10 +-
 lib/libc/arch/alpha/gen/frexp.c          |   86 -----------------
 lib/libc/arch/alpha/gen/infinity.c       |   34 ------
 lib/libc/arch/alpha/gen/isinf.c          |   68 -------------
 lib/libc/arch/alpha/gen/isnan.c          |   68 -------------
 lib/libc/arch/alpha/gen/ldexp.c          |  154 -------------------------------
 lib/libc/arch/alpha/gen/modf.c           |  104 --------------------
 lib/libc/arch/alpha/gen/nanf.c           |   15 ---
 lib/libc/arch/arm/gen/Makefile.inc       |    9 +-
 lib/libc/arch/arm/gen/frexp.c            |   86 -----------------
 lib/libc/arch/arm/gen/isinf.c            |   72 --------------
 lib/libc/arch/arm/gen/isnan.c            |   72 --------------
 lib/libc/arch/arm/gen/ldexp.c            |  154 -------------------------------
 lib/libc/arch/arm/gen/modf.c             |  104 --------------------
 lib/libc/arch/arm/gen/nanf.c             |   13 --
 lib/libc/arch/i386/gen/Makefile.inc      |    9 +-
 lib/libc/arch/i386/gen/frexp.c           |   86 -----------------
 lib/libc/arch/i386/gen/infinity.c        |   13 --
 lib/libc/arch/i386/gen/isinf.c           |   68 -------------
 lib/libc/arch/i386/gen/isnan.c           |   68 -------------
 lib/libc/arch/i386/gen/nanf.c            |   13 --
 lib/libc/arch/m68k/gen/Makefile.inc      |   17 ++-
 lib/libc/arch/m68k/gen/frexp.c           |   86 -----------------
 lib/libc/arch/m68k/gen/infinity.c        |   13 --
 lib/libc/arch/m68k/gen/isinf.c           |   68 -------------
 lib/libc/arch/m68k/gen/isnan.c           |   68 -------------
 lib/libc/arch/m68k/gen/ldexp_040.c       |  154 -------------------------------
 lib/libc/arch/m68k/gen/ldexp_softfloat.c |  154 -------------------------------
 lib/libc/arch/m68k/gen/modf_softfloat.c  |  104 --------------------
 lib/libc/arch/m68k/gen/nanf.c            |   13 --
 lib/libc/arch/mips/gen/Makefile.inc      |    9 +-
 lib/libc/arch/mips/gen/frexp.c           |   86 -----------------
 lib/libc/arch/mips/gen/infinity.c        |   15 ---
 lib/libc/arch/mips/gen/isinf.c           |   68 -------------
 lib/libc/arch/mips/gen/isnan.c           |   68 -------------
 lib/libc/arch/mips/gen/nanf.c            |   18 ---
 lib/libc/arch/ns32k/gen/Makefile.inc     |    9 +-
 lib/libc/arch/ns32k/gen/frexp.c          |   86 -----------------
 lib/libc/arch/ns32k/gen/infinity.c       |   11 --
 lib/libc/arch/ns32k/gen/isinf.c          |   68 -------------
 lib/libc/arch/ns32k/gen/isnan.c          |   68 -------------
 lib/libc/arch/ns32k/gen/ldexp.c          |  154 -------------------------------
 lib/libc/arch/ns32k/gen/nanf.c           |   13 --
 lib/libc/arch/powerpc/gen/Makefile.inc   |   12 +-
 lib/libc/arch/powerpc/gen/frexp.c        |   86 -----------------
 lib/libc/arch/powerpc/gen/infinity.c     |   13 --
 lib/libc/arch/powerpc/gen/isinf.c        |   68 -------------
 lib/libc/arch/powerpc/gen/isnan.c        |   68 -------------
 lib/libc/arch/powerpc/gen/ldexp.c        |  154 -------------------------------
 lib/libc/arch/powerpc/gen/modf.c         |  104 --------------------
 lib/libc/arch/powerpc/gen/nanf.c         |   13 --
 lib/libc/arch/sh3/gen/Makefile.inc       |   11 +-
 lib/libc/arch/sh3/gen/frexp.c            |   68 -------------
 lib/libc/arch/sh3/gen/infinity.c         |   18 ---
 lib/libc/arch/sh3/gen/isinf.c            |   68 -------------
 lib/libc/arch/sh3/gen/isnan.c            |   68 -------------
 lib/libc/arch/sh3/gen/ldexp.c            |  154 -------------------------------
 lib/libc/arch/sh3/gen/modf.c             |  104 --------------------
 lib/libc/arch/sh3/gen/nanf.c             |   18 ---
 lib/libc/arch/sparc/gen/Makefile.inc     |    8 +-
 lib/libc/arch/sparc/gen/frexp.c          |   86 -----------------
 lib/libc/arch/sparc/gen/infinity.c       |   13 --
 lib/libc/arch/sparc/gen/isinf.c          |   68 -------------
 lib/libc/arch/sparc/gen/isnan.c          |   68 -------------
 lib/libc/arch/sparc/gen/ldexp.c          |  154 -------------------------------
 lib/libc/arch/sparc/gen/nanf.c           |   13 --
 lib/libc/arch/sparc64/gen/Makefile.inc   |    8 +-
 lib/libc/arch/sparc64/gen/frexp.c        |   86 -----------------
 lib/libc/arch/sparc64/gen/infinity.c     |   13 --
 lib/libc/arch/sparc64/gen/isinf.c        |   68 -------------
 lib/libc/arch/sparc64/gen/isnan.c        |   68 -------------
 lib/libc/arch/sparc64/gen/ldexp.c        |  154 -------------------------------
 lib/libc/arch/sparc64/gen/nanf.c         |   13 --
 lib/libc/arch/x86_64/gen/Makefile.inc    |    8 +-
 lib/libc/arch/x86_64/gen/frexp.c         |   86 -----------------
 lib/libc/arch/x86_64/gen/infinity.c      |   13 --
 lib/libc/arch/x86_64/gen/isinf.c         |   68 -------------
 lib/libc/arch/x86_64/gen/isnan.c         |   68 -------------
 lib/libc/arch/x86_64/gen/nanf.c          |   13 --
 lib/libc/gen/ieee754_frexp.c             |   84 ++++++++++++++++
 lib/libc/gen/ieee754_infinity.c          |   15 +++
 lib/libc/gen/ieee754_isinf.c             |   71 ++++++++++++++
 lib/libc/gen/ieee754_isnan.c             |   71 ++++++++++++++
 lib/libc/gen/ieee754_ldexp.c             |  152 ++++++++++++++++++++++++++++++
 lib/libc/gen/ieee754_modf.c              |  103 ++++++++++++++++++++
 lib/libc/gen/ieee754_nanf.c              |   18 +++
 sys/arch/alpha/include/math.h            |   12 +--
 sys/arch/arm/include/math.h              |   12 +--
 sys/arch/i386/include/math.h             |   12 +--
 sys/arch/m68k/include/math.h             |   12 +--
 sys/arch/mips/include/math.h             |   12 +--
 sys/arch/pc532/include/math.h            |   11 +-
 sys/arch/powerpc/include/math.h          |   12 +--
 sys/arch/sh3/include/math.h              |   12 +--
 sys/arch/sparc/include/math.h            |   12 +--
 sys/arch/sparc64/include/math.h          |   12 +--
 sys/arch/x86_64/include/math.h           |   12 +--
 98 files changed, 641 insertions(+), 4793 deletions(-)

diffs (truncated from 5940 to 300 lines):

diff -r 6a1411e17d6d -r ed4c39614018 include/math.h
--- a/include/math.h    Tue Feb 19 12:13:10 2002 +0000
+++ b/include/math.h    Tue Feb 19 13:08:12 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: math.h,v 1.23 2001/01/05 23:36:38 christos Exp $       */
+/*     $NetBSD: math.h,v 1.24 2002/02/19 13:08:12 simonb Exp $ */
 
 /*
  * ====================================================
@@ -20,13 +20,35 @@
 
 #include <sys/cdefs.h>
 #include <sys/featuretest.h>
-#include <machine/math.h>
+
+union __float_u {
+       unsigned char __dummy[sizeof(float)];
+       float __val;
+};
+
+union __double_u {
+       unsigned char __dummy[sizeof(double)];
+       double __val;
+};
+
+#include <machine/math.h>              /* may use __float_u or __double_u */
 
 /*
  * ANSI/POSIX
  */
-extern __const char __infinity[];
-#define HUGE_VAL       (*(__const double *)(__const void *)__infinity)
+extern __const union __double_u __infinity;
+#define HUGE_VAL       __infinity.__val
+
+/*
+ * ISO C99
+ */
+#if defined(__HAVE_NANF) && \
+    (!defined(_ANSI_SOURCE) && \
+    (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) || \
+     defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L))
+extern __const union __float_u __nanf;
+#define        NAN             __nanf.__val
+#endif /* __HAVE_NANF && (!_ANSI_SOURCE && ....) */
 
 /*
  * XOPEN/SVID
diff -r 6a1411e17d6d -r ed4c39614018 lib/libc/arch/alpha/gen/Makefile.inc
--- a/lib/libc/arch/alpha/gen/Makefile.inc      Tue Feb 19 12:13:10 2002 +0000
+++ b/lib/libc/arch/alpha/gen/Makefile.inc      Tue Feb 19 13:08:12 2002 +0000
@@ -1,6 +1,12 @@
-#      $NetBSD: Makefile.inc,v 1.7 1999/12/23 10:15:06 kleink Exp $
+#      $NetBSD: Makefile.inc,v 1.8 2002/02/19 13:08:16 simonb Exp $
+
+SRCS+= fabs.S 
 
-SRCS+= fabs.S frexp.c infinity.c isinf.c isnan.c ldexp.c modf.c nanf.c
+# Common ieee754 constants and functions
+SRCS+= ieee754_infinity.c ieee754_nanf.c
+SRCS+= ieee754_frexp.c ieee754_isinf.c ieee754_isnan.c ieee754_ldexp.c
+SRCS+= ieee754_modf.c
+
 SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
        fpsetround.c fpsetsticky.c
 SRCS+= _setjmp.S
diff -r 6a1411e17d6d -r ed4c39614018 lib/libc/arch/alpha/gen/frexp.c
--- a/lib/libc/arch/alpha/gen/frexp.c   Tue Feb 19 12:13:10 2002 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-/*     $NetBSD: frexp.c,v 1.4 1999/08/29 18:39:35 mycroft 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. 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: Header: frexp.c,v 1.1 91/07/07 04:45:01 torek Exp
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)frexp.c    8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: frexp.c,v 1.4 1999/08/29 18:39:35 mycroft Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <machine/ieee.h>
-#include <math.h>
-
-/*
- * Split the given value into a fraction in the range [0.5, 1.0) and
- * an exponent, such that frac * (2^exp) == value.  If value is 0,
- * return 0.
- */
-double
-frexp(value, eptr)
-       double value;
-       int *eptr;
-{
-       union {
-                double v;
-               struct ieee_double s;
-       } u;
-
-       if (value) {
-               /*
-                * Fractions in [0.5..1.0) have an exponent of 2^-1.
-                * Leave Inf and NaN alone, however.
-                * WHAT ABOUT DENORMS?
-                */
-               u.v = value;
-               if (u.s.dbl_exp != DBL_EXP_INFNAN) {
-                       *eptr = u.s.dbl_exp - (DBL_EXP_BIAS - 1);
-                       u.s.dbl_exp = DBL_EXP_BIAS - 1;
-               }
-               return (u.v);
-       } else {
-               *eptr = 0;
-               return (0.0);
-       }
-}
diff -r 6a1411e17d6d -r ed4c39614018 lib/libc/arch/alpha/gen/infinity.c
--- a/lib/libc/arch/alpha/gen/infinity.c        Tue Feb 19 12:13:10 2002 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/* $NetBSD: infinity.c,v 1.6 2000/06/14 06:49:02 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@localhost
- *  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 <math.h>
-
-/* bytes for +Infinity on an Alpha (IEEE double format) */
-const char __infinity[] __attribute__((__aligned__(__alignof__(double)))) = 
-                                       { 0, 0, 0, 0, 0, 0, (char)0xf0, 0x7f };
diff -r 6a1411e17d6d -r ed4c39614018 lib/libc/arch/alpha/gen/isinf.c
--- a/lib/libc/arch/alpha/gen/isinf.c   Tue Feb 19 12:13:10 2002 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*     $NetBSD: isinf.c,v 1.5 2000/01/22 22:44:59 mycroft 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. 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: Header: isinf.c,v 1.1 91/07/08 19:03:34 torek Exp
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)isinf.c    8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: isinf.c,v 1.5 2000/01/22 22:44:59 mycroft Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
-
-#include "namespace.h"
-#include <sys/types.h>
-#include <machine/ieee.h>
-#include <math.h>
-
-#ifdef __weak_alias
-__weak_alias(isinf,_isinf)
-#endif
-
-int
-isinf(d)
-       double d;
-{
-       register struct ieee_double *p = (struct ieee_double *)(void *)&d;
-
-       return (p->dbl_exp == DBL_EXP_INFNAN &&
-           (p->dbl_frach == 0 && p->dbl_fracl == 0));
-}
diff -r 6a1411e17d6d -r ed4c39614018 lib/libc/arch/alpha/gen/isnan.c
--- a/lib/libc/arch/alpha/gen/isnan.c   Tue Feb 19 12:13:10 2002 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*     $NetBSD: isnan.c,v 1.2 2000/01/22 22:44:59 mycroft 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. 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



Home | Main Index | Thread Index | Old Index