Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/arch/ns32k/gen Use the C version of ldexp(). The a...



details:   https://anonhg.NetBSD.org/src/rev/c6b80348a2c8
branches:  trunk
changeset: 475914:c6b80348a2c8
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Sun Aug 29 19:08:44 1999 +0000

description:
Use the C version of ldexp().  The assembler version was broken in several
ways (ldexp(0.0, 5000) returned +Inf, didn't do normalization/denormalization,
etc.).

diffstat:

 lib/libc/arch/ns32k/gen/Makefile.inc |   7 +-
 lib/libc/arch/ns32k/gen/ldexp.S      |  85 ------------------------------------
 lib/libc/arch/ns32k/gen/ldexp.c      |  68 ++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 88 deletions(-)

diffs (181 lines):

diff -r 7efc379f216f -r c6b80348a2c8 lib/libc/arch/ns32k/gen/Makefile.inc
--- a/lib/libc/arch/ns32k/gen/Makefile.inc      Sun Aug 29 19:04:02 1999 +0000
+++ b/lib/libc/arch/ns32k/gen/Makefile.inc      Sun Aug 29 19:08:44 1999 +0000
@@ -1,7 +1,7 @@
-#      $NetBSD: Makefile.inc,v 1.11 1999/08/29 18:32:36 mycroft Exp $
+#      $NetBSD: Makefile.inc,v 1.12 1999/08/29 19:08:44 mycroft Exp $
 
 # objects built from assembler sources (need lint stubs)
-ASSRCS+=alloca.S fabs.S ldexp.S modf.S
+ASSRCS+=alloca.S fabs.S modf.S
 
 ASSRCS+=__setjmp14.S
 ASSRCS+=_setjmp.S
@@ -12,4 +12,5 @@
 
 # objects built from C sources
 SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
-       fpsetround.c fpsetsticky.c infinity.c frexp.c isinf.c isnan.c bswap64.c
+       fpsetround.c fpsetsticky.c infinity.c frexp.c isinf.c isnan.c ldexp.c \
+       bswap64.c
diff -r 7efc379f216f -r c6b80348a2c8 lib/libc/arch/ns32k/gen/ldexp.S
--- a/lib/libc/arch/ns32k/gen/ldexp.S   Sun Aug 29 19:04:02 1999 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/*     $NetBSD: ldexp.S,v 1.4 1997/05/08 13:38:40 matthias Exp $       */
-
-/* 
- * Copyright (c) 1992 Helsinki University of Technology
- * All Rights Reserved.
- * 
- * 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.
- * 
- * HELSINKI UNIVERSITY OF TECHNOLOGY ALLOWS FREE USE OF THIS SOFTWARE IN
- * ITS "AS IS" CONDITION. HELSINKI UNIVERSITY OF TECHNOLOGY DISCLAIMS ANY
- * LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE
- * USE OF THIS SOFTWARE.
- */
-/*
- * HISTORY
- * 29-Apr-92  Tero Kivinen (kivinen) at Helsinki University of Technology
- *     Created.
- */
-
-/*
- * double ldexp (value, exp)
- * double value;
- * int exp;
- *
- * Ldexp returns value*2**exp, if that result is in range.
- * If underflow occurs, it returns zero.  If overflow occurs,
- * it returns a value of appropriate sign and largest
- * possible magnitude.  In case of either overflow or underflow,
- * errno is set to ERANGE.  Note that errno is not modified if
- * no error occurs.
- */
-
-#include <machine/asm.h>
-
-#if defined(LIBC_SCCS)
-       RCSID("$NetBSD: ldexp.S,v 1.4 1997/05/08 13:38:40 matthias Exp $")
-#endif
-
-#define ERANGE 34
-
-ENTRY(ldexp)
-       enter   [],8
-       movd    12(fp),r1       /* get value, high 32 bit */
-       lshd    -20,r1          /* extract exponent */
-       andd    0x7ff,r1        /* 11 lower bits */
-       subd    1023,r1         /* unbias exponent */
-       movd    16(fp),r0       /* get exp */
-       addd    r1,r0           /* add exponents */
-       cmpd    r0,1023         /* most positive exponent */
-       bgt     1f              /* too large */
-       cmpd    r0,-1022        /* most negative exponent */
-       blt     0f              /* too small */
-       addd    1023,r0         /* bias exponent */
-       lshd    20,r0           /* convert exponent back to its place */
-       movd    12(fp),r1       /* get value high 32 bit */
-       bicd    0x7ff00000,r1   /* clear exponent */
-       ord     r0,r1           /* insert exponent */
-       movd    r1,-4(fp)       /* put high 32 bit to local variable */
-       movd    8(fp),-8(fp)    /* value low 32 bit to local variable */
-       movl    -8(fp),f0       /* return value * 2**exp */
-       exit    []
-       ret     0               /* neither */
-
-0:     movdl   0d0e0,f0        /* if underflow return 0, set errno */
-       movd    ERANGE,r0
-       exit    []
-       br      cerror
-
-1:     movl    3f(pc),f0       /* if overflow return HUGE */
-       movdl   0d0e0,f2
-       cmpl    f2,8(fp)        /* check original sign */
-       bgt     2f
-       negl    f0,f0           /* if negative, return -HUGE */
-2:     movd    ERANGE,r0
-       exit    []
-       br      cerror
-       
-3:     .long   0xffffffff      /* the largest number that can */
-       .long   0x7fefffff      /* be represented in a long floating */
-                               /* number.  This is given in hex in order */
-                               /* to avoid floating conversions */
diff -r 7efc379f216f -r c6b80348a2c8 lib/libc/arch/ns32k/gen/ldexp.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/arch/ns32k/gen/ldexp.c   Sun Aug 29 19:08:44 1999 +0000
@@ -0,0 +1,68 @@
+/*     $NetBSD: ldexp.c,v 1.1 1999/08/29 19:08:44 mycroft Exp $        */
+
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum.
+ *
+ * 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 NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 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: ldexp.c,v 1.1 1999/08/29 19:08:44 mycroft Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <machine/ieee.h>
+#include <math.h>
+
+/*
+ * ldexp(value, exp): return value * (2 ** exp).
+ */
+double
+ldexp(value, exp)
+       double value;
+       int exp;
+{
+       double temp;
+
+#if __GNUC__ >= 2
+       __asm ("fscale"
+               : "=t" (temp)
+               : "0" (value), "u" ((double)exp));
+#else
+       __asm ("fscale; fstp %%st(1)"
+               : "=f" (temp)
+               : "f" (value), "0" ((double)exp));
+#endif
+       return (temp);
+}



Home | Main Index | Thread Index | Old Index