diff options
author | David Schultz <das@FreeBSD.org> | 2011-10-21 06:40:36 +0000 |
---|---|---|
committer | David Schultz <das@FreeBSD.org> | 2011-10-21 06:40:36 +0000 |
commit | 6232589aeb9b7c1c1e731d9ec324cfdb57202a48 (patch) | |
tree | c48465604c7967f5162a2c5f32ab24721a37e96c /lib/libc/mips/gen | |
parent | 417c551014c2c138b57a2ea5133162a2b194fb3e (diff) | |
download | src-6232589aeb9b7c1c1e731d9ec324cfdb57202a48.tar.gz src-6232589aeb9b7c1c1e731d9ec324cfdb57202a48.zip |
Replace a proliferation of buggy MD implementations of modf() with a
working MI one. The MI one only needs to be overridden on machines
with non-IEEE754 arithmetic. (The last supported one was the VAX.)
It can also be overridden if someone comes up with a faster one that
actually passes the regression tests -- but this is harder than it sounds.
Notes
Notes:
svn path=/head/; revision=226606
Diffstat (limited to 'lib/libc/mips/gen')
-rw-r--r-- | lib/libc/mips/gen/Makefile.inc | 2 | ||||
-rw-r--r-- | lib/libc/mips/gen/modf.S | 82 | ||||
-rw-r--r-- | lib/libc/mips/gen/modf.c | 107 |
3 files changed, 1 insertions, 190 deletions
diff --git a/lib/libc/mips/gen/Makefile.inc b/lib/libc/mips/gen/Makefile.inc index 1fafb012bdc3..8ee69d051ddb 100644 --- a/lib/libc/mips/gen/Makefile.inc +++ b/lib/libc/mips/gen/Makefile.inc @@ -1,7 +1,7 @@ # $NetBSD: Makefile.inc,v 1.27 2005/10/07 17:16:40 tsutsui Exp $ # $FreeBSD$ -SRCS+= infinity.c fabs.c ldexp.c modf.c +SRCS+= infinity.c fabs.c ldexp.c # SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \ # fpsetround.c fpsetsticky.c diff --git a/lib/libc/mips/gen/modf.S b/lib/libc/mips/gen/modf.S deleted file mode 100644 index 5eee3f1fb576..000000000000 --- a/lib/libc/mips/gen/modf.S +++ /dev/null @@ -1,82 +0,0 @@ -/* $NetBSD: modf.S,v 1.10 2003/08/07 16:42:15 agc 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> -__FBSDID("$FreeBSD$"); - -#if defined(LIBC_SCCS) && !defined(lint) - ASMSTR("from: @(#)modf.s 8.1 (Berkeley) 6/4/93") - ASMSTR("$NetBSD: modf.S,v 1.10 2003/08/07 16:42:15 agc Exp $") -#endif /* LIBC_SCCS and not lint */ - -#ifdef __ABICALLS__ - .abicalls -#endif - -/* - * double modf(val, iptr) - * double val, *iptr; - * returns: xxx and n (in *iptr) where val == n.xxx - */ -LEAF(modf) -#ifdef __ABICALLS__ - .set noreorder - .cpload t9 - .set reorder -#endif - 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 - s.d $f0, 0(a2) # save the integer part - sub.d $f0, $f12, $f0 # subtract val - integer part - j ra -END(modf) diff --git a/lib/libc/mips/gen/modf.c b/lib/libc/mips/gen/modf.c deleted file mode 100644 index cb5aeac2ea46..000000000000 --- a/lib/libc/mips/gen/modf.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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. - * - * $NetBSD: modf.c,v 1.1 1995/02/10 17:50:25 cgd Exp $ - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/types.h> -#include <errno.h> -#include <math.h> -#include <machine/ieee.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(val, iptr) - double val, *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); -} |