Source-Changes-HG archive

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

[src/trunk]: src/lib/libm/src the MI lrint() code assumes that rounding is do...



details:   https://anonhg.NetBSD.org/src/rev/9491cd7a0f74
branches:  trunk
changeset: 351786:9491cd7a0f74
user:      chs <chs%NetBSD.org@localhost>
date:      Mon Feb 27 06:49:02 2017 +0000

description:
the MI lrint() code assumes that rounding is done in at most double precision
but m68k (68881) uses extended precision by default, so put the FPU in
double-precision mode temporarily here.

diffstat:

 lib/libm/src/lrint.c |  23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diffs (46 lines):

diff -r 016fc163d898 -r 9491cd7a0f74 lib/libm/src/lrint.c
--- a/lib/libm/src/lrint.c      Mon Feb 27 06:47:58 2017 +0000
+++ b/lib/libm/src/lrint.c      Mon Feb 27 06:49:02 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lrint.c,v 1.5 2015/07/09 06:17:13 nat Exp $ */
+/* $NetBSD: lrint.c,v 1.6 2017/02/27 06:49:02 chs Exp $ */
 
 /*-
  * Copyright (c) 2004
@@ -46,6 +46,15 @@
  -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)
 {
@@ -68,8 +77,20 @@
        /* >= 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;
 



Home | Main Index | Thread Index | Old Index