Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libm Replace our rounding functions with the ones from F...
details: https://anonhg.NetBSD.org/src/rev/4caf2d28f1f9
branches: trunk
changeset: 353428:4caf2d28f1f9
user: christos <christos%NetBSD.org@localhost>
date: Sat May 06 18:03:24 2017 +0000
description:
Replace our rounding functions with the ones from FreeBSD
diffstat:
lib/libm/Makefile | 9 ++-
lib/libm/src/llrint.c | 13 -----
lib/libm/src/llrintf.c | 13 -----
lib/libm/src/llround.c | 13 -----
lib/libm/src/llroundf.c | 13 -----
lib/libm/src/lrint.c | 114 ----------------------------------------------
lib/libm/src/lrintf.c | 92 -------------------------------------
lib/libm/src/lround.c | 85 ----------------------------------
lib/libm/src/lroundf.c | 80 --------------------------------
lib/libm/src/s_llrint.c | 13 +++++
lib/libm/src/s_llrintf.c | 13 +++++
lib/libm/src/s_llrintl.c | 13 +++++
lib/libm/src/s_llround.c | 15 ++++++
lib/libm/src/s_llroundf.c | 15 ++++++
lib/libm/src/s_llroundl.c | 15 ++++++
lib/libm/src/s_lrint.c | 64 +++++++++++++++++++++++++
lib/libm/src/s_lrintf.c | 13 +++++
lib/libm/src/s_lrintl.c | 13 +++++
lib/libm/src/s_lround.c | 72 +++++++++++++++++++++++++++++
lib/libm/src/s_lroundf.c | 15 ++++++
lib/libm/src/s_lroundl.c | 15 ++++++
21 files changed, 282 insertions(+), 426 deletions(-)
diffs (truncated from 809 to 300 lines):
diff -r 77cd65874b1c -r 4caf2d28f1f9 lib/libm/Makefile
--- a/lib/libm/Makefile Sat May 06 18:02:52 2017 +0000
+++ b/lib/libm/Makefile Sat May 06 18:03:24 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.190 2017/03/23 18:26:03 chs Exp $
+# $NetBSD: Makefile,v 1.191 2017/05/06 18:03:24 christos Exp $
#
# @(#)Makefile 5.1beta 93/09/24
#
@@ -248,6 +248,10 @@
s_floor.c s_floorf.c s_floorl.c s_frexpf.c \
s_ilogb.c s_ilogbf.c s_ilogbl.c \
s_isinff.c s_isnanf.c s_lib_version.c s_log1p.c \
+ s_llrint.c s_llrintf.c s_llrintl.c \
+ s_llround.c s_llroundf.c s_llroundl.c \
+ s_lrint.c s_lrintf.c s_lrintl.c \
+ s_lround.c s_lroundf.c s_lroundl.c \
s_log1pf.c s_logb.c s_logbf.c s_logbl.c \
s_matherr.c s_modff.c s_modfl.c s_nextafter.c s_nextafterl.c \
s_nextafterf.c s_remquo.c s_remquof.c s_rint.c s_rintf.c \
@@ -265,8 +269,7 @@
w_log2f.c w_logf.c \
w_pow.c w_powf.c w_remainder.c w_remainderf.c w_scalb.c w_scalbf.c \
w_sinh.c w_sinhf.c w_sqrt.c w_sqrtf.c w_sqrtl.c \
- lrint.c lrintf.c llrint.c llrintf.c lround.c lroundf.c llround.c \
- llroundf.c s_frexp.c s_frexpl.c s_modf.c \
+ s_frexp.c s_frexpl.c s_modf.c \
s_fmax.c s_fmaxf.c s_fmaxl.c \
s_fmin.c s_fminf.c s_fminl.c s_fdim.c
diff -r 77cd65874b1c -r 4caf2d28f1f9 lib/libm/src/llrint.c
--- a/lib/libm/src/llrint.c Sat May 06 18:02:52 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-/* $NetBSD: llrint.c,v 1.2 2004/10/13 15:18:32 drochner Exp $ */
-
-/*
- * Written by Matthias Drochner <drochner%NetBSD.org@localhost>.
- * Public domain.
- */
-
-#define LRINTNAME llrint
-#define RESTYPE long long int
-#define RESTYPE_MIN LLONG_MIN
-#define RESTYPE_MAX LLONG_MAX
-
-#include "lrint.c"
diff -r 77cd65874b1c -r 4caf2d28f1f9 lib/libm/src/llrintf.c
--- a/lib/libm/src/llrintf.c Sat May 06 18:02:52 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-/* $NetBSD: llrintf.c,v 1.2 2004/10/13 15:18:32 drochner Exp $ */
-
-/*
- * Written by Matthias Drochner <drochner%NetBSD.org@localhost>.
- * Public domain.
- */
-
-#define LRINTNAME llrintf
-#define RESTYPE long long int
-#define RESTYPE_MIN LLONG_MIN
-#define RESTYPE_MAX LLONG_MAX
-
-#include "lrintf.c"
diff -r 77cd65874b1c -r 4caf2d28f1f9 lib/libm/src/llround.c
--- a/lib/libm/src/llround.c Sat May 06 18:02:52 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-/* $NetBSD: llround.c,v 1.2 2004/10/13 15:18:32 drochner Exp $ */
-
-/*
- * Written by Matthias Drochner <drochner%NetBSD.org@localhost>.
- * Public domain.
- */
-
-#define LROUNDNAME llround
-#define RESTYPE long long int
-#define RESTYPE_MIN LLONG_MIN
-#define RESTYPE_MAX LLONG_MAX
-
-#include "lround.c"
diff -r 77cd65874b1c -r 4caf2d28f1f9 lib/libm/src/llroundf.c
--- a/lib/libm/src/llroundf.c Sat May 06 18:02:52 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-/* $NetBSD: llroundf.c,v 1.2 2004/10/13 15:18:32 drochner Exp $ */
-
-/*
- * Written by Matthias Drochner <drochner%NetBSD.org@localhost>.
- * Public domain.
- */
-
-#define LROUNDNAME llroundf
-#define RESTYPE long long int
-#define RESTYPE_MIN LLONG_MIN
-#define RESTYPE_MAX LLONG_MAX
-
-#include "lroundf.c"
diff -r 77cd65874b1c -r 4caf2d28f1f9 lib/libm/src/lrint.c
--- a/lib/libm/src/lrint.c Sat May 06 18:02:52 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-/* $NetBSD: lrint.c,v 1.6 2017/02/27 06:49:02 chs Exp $ */
-
-/*-
- * Copyright (c) 2004
- * Matthias Drochner. All rights reserved.
- *
- * 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 AUTHOR 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 AUTHOR 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 <math.h>
-#include <sys/ieee754.h>
-#include <machine/limits.h>
-#include "math_private.h"
-
-#ifndef LRINTNAME
-#define LRINTNAME lrint
-#define RESTYPE long int
-#define RESTYPE_MIN LONG_MIN
-#define RESTYPE_MAX LONG_MAX
-#endif
-
-#define RESTYPE_BITS (sizeof(RESTYPE) * 8)
-
-static const double
-TWO52[2]={
- 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
- -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
-};
-
-#ifdef __HAVE_68881__
-#include <m68k/fpreg.h>
-
-#define get_fpcr(__fpcr) \
- __asm__ __volatile__ ("fmove%.l %!,%0" : "=dm" (__fpcr))
-#define set_fpcr(__fpcr) \
- __asm__ __volatile__ ("fmove%.l %0,%!" : : "dm" (__fpcr))
-#endif
-
-RESTYPE
-LRINTNAME(double x)
-{
- u_int32_t i0, i1;
- int e, s, shift;
- RESTYPE res;
-
- GET_HIGH_WORD(i0, x);
- e = i0 >> 20;
- s = (uint32_t)e >> DBL_EXPBITS;
- e = (e & 0x7ff) - DBL_EXP_BIAS;
-
- /* 1.0 x 2^-1 is the smallest number which can be rounded to 1 */
- if (e < -1)
- return (0);
- /* 1.0 x 2^31 (or 2^63) is already too large */
- if (e >= (int)RESTYPE_BITS - 1)
- return (s ? RESTYPE_MIN : RESTYPE_MAX); /* ??? unspecified */
-
- /* >= 2^52 is already an exact integer */
- if (e < DBL_FRACBITS) {
- /* round, using current direction */
-#ifdef __HAVE_68881__
- int ofpcr, nfpcr;
-
- /* For m68k hardfloat, use double-precision */
- get_fpcr(ofpcr);
- nfpcr = (ofpcr & ~FPCR_PREC) | FPCR_DBL;
- set_fpcr(nfpcr);
-#endif
- x += TWO52[s];
- x -= TWO52[s];
-#ifdef __HAVE_68881__
- __asm__ __volatile__ ("/* dummy %0 */" : : "f" (x));
- set_fpcr(ofpcr);
-#endif
- } else
- return x;
-
- EXTRACT_WORDS(i0, i1, x);
- e = ((i0 >> 20) & 0x7ff) - DBL_EXP_BIAS;
- i0 &= 0xfffff;
- i0 |= (1 << 20);
-
- shift = e - DBL_FRACBITS;
- if (shift >=0)
- res = (shift < 32 ? (RESTYPE)i1 << shift : 0);
- else
- res = (shift > -32 ? i1 >> -shift : 0);
- shift += 32;
- if (shift >=0)
- res |= (shift < 32 ? (RESTYPE)i0 << shift : 0);
- else
- res |= (shift > -32 ? i0 >> -shift : 0);
-
- return (s ? -res : res);
-}
diff -r 77cd65874b1c -r 4caf2d28f1f9 lib/libm/src/lrintf.c
--- a/lib/libm/src/lrintf.c Sat May 06 18:02:52 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-/* $NetBSD: lrintf.c,v 1.6 2015/07/09 06:17:13 nat Exp $ */
-
-/*-
- * Copyright (c) 2004
- * Matthias Drochner. All rights reserved.
- *
- * 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 AUTHOR 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 AUTHOR 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 <math.h>
-#include <sys/ieee754.h>
-#include <machine/limits.h>
-#include "math_private.h"
-
-#ifndef LRINTNAME
-#define LRINTNAME lrintf
-#define RESTYPE long int
-#define RESTYPE_MIN LONG_MIN
-#define RESTYPE_MAX LONG_MAX
-#endif
-
-#define RESTYPE_BITS (sizeof(RESTYPE) * 8)
-
-static const float
-TWO23[2]={
- 8.3886080000e+06, /* 0x4b000000 */
- -8.3886080000e+06, /* 0xcb000000 */
-};
-
-RESTYPE
-LRINTNAME(float x)
-{
- u_int32_t i0;
- int e, s, shift;
- RESTYPE res;
-#ifdef __i386__ /* XXX gcc4 will omit the rounding otherwise */
- volatile
-#endif
- float w;
-
- GET_FLOAT_WORD(i0, x);
- e = i0 >> SNG_FRACBITS;
- s = (uint32_t)e >> SNG_EXPBITS;
- e = (e & 0xff) - SNG_EXP_BIAS;
-
- /* 1.0 x 2^-1 is the smallest number which can be rounded to 1 */
- if (e < -1)
- return (0);
- /* 1.0 x 2^31 (or 2^63) is already too large */
- if (e >= (int)RESTYPE_BITS - 1)
- return (s ? RESTYPE_MIN : RESTYPE_MAX); /* ??? unspecified */
-
- /* >= 2^23 is already an exact integer */
- if (e < SNG_FRACBITS) {
- /* round, using current direction */
- w = TWO23[s] + x;
- x = w - TWO23[s];
- } else
- return x;
-
- GET_FLOAT_WORD(i0, x);
Home |
Main Index |
Thread Index |
Old Index