Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/m68k/fpe Rewrite fpu_int().



details:   https://anonhg.NetBSD.org/src/rev/536fb363df69
branches:  trunk
changeset: 779883:536fb363df69
user:      isaki <isaki%NetBSD.org@localhost>
date:      Mon Jun 25 04:52:23 2012 +0000

description:
Rewrite fpu_int().
Especially, remove the special treatment when |x| < 1
because it forgets to consider FPCR round mode.
See PR/46627 for the detail.  Thanks Y.Sugahara for advice.

diffstat:

 sys/arch/m68k/fpe/fpu_int.c |  44 +++++++++++---------------------------------
 1 files changed, 11 insertions(+), 33 deletions(-)

diffs (78 lines):

diff -r 6ea2ba42e069 -r 536fb363df69 sys/arch/m68k/fpe/fpu_int.c
--- a/sys/arch/m68k/fpe/fpu_int.c       Mon Jun 25 02:32:12 2012 +0000
+++ b/sys/arch/m68k/fpe/fpu_int.c       Mon Jun 25 04:52:23 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fpu_int.c,v 1.10 2011/07/18 14:11:27 isaki Exp $       */
+/*     $NetBSD: fpu_int.c,v 1.11 2012/06/25 04:52:23 isaki Exp $       */
 
 /*
  * Copyright (c) 1995 Ken Nakata
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fpu_int.c,v 1.10 2011/07/18 14:11:27 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_int.c,v 1.11 2012/06/25 04:52:23 isaki Exp $");
 
 #include <sys/types.h>
 
@@ -78,50 +78,28 @@
 fpu_int(struct fpemu *fe)
 {
        register struct fpn *x = &fe->fe_f2;
-       register int rsh, lsh, wsh, i;
+       register int rsh;
 
        /* special cases first */
        if (x->fp_class != FPC_NUM) {
                return x;
        }
-       /*
-        * even if we have exponent == -1, we still have possiblity
-        * that the result >= 1.0 when mantissa ~= 1.0 and rounded up
-        */
-       if (x->fp_exp < -1) {
-               x->fp_class = FPC_ZERO;
-               x->fp_mant[0] = x->fp_mant[1] = x->fp_mant[2] = 0;
-               return x;
-       }
 
-       /* real work */
        rsh = FP_NMANT - 1 - x->fp_exp;
-       if (rsh - FP_NG <= 0) {
+       if (rsh <= FP_NG) {
                return x;
        }
 
-       fpu_shr(x, rsh - FP_NG);        /* shift to the right */
+       /* shift to the right */
+       x->fp_exp = 0;
+       fpu_shr(x, rsh - FP_NG);
 
-       if (fpu_round(fe, x) == 1 /* rounded up */ &&
-           x->fp_mant[2 - (FP_NMANT-rsh)/32] & (1 << ((FP_NMANT-rsh)%32))
-           /* x >= 2.0 */) {
-               rsh--;                  /* reduce shift count by 1 */
-               x->fp_exp++;            /* adjust exponent */
-       }
+       /* round according to FPCR round mode */
+       fpu_round(fe, x);
 
        /* shift it back to the left */
-       wsh = rsh / 32;
-       lsh = rsh % 32;
-       rsh = 32 - lsh;
-       for (i = 0; i + wsh < 2; i++) {
-               x->fp_mant[i] = (x->fp_mant[i+wsh] << lsh) |
-                   (x->fp_mant[i+wsh+1] >> rsh);
-       }
-       x->fp_mant[i] = (x->fp_mant[i+wsh] << lsh);
-       i++;
-       for (; i < 3; i++) {
-               x->fp_mant[i] = 0;
-       }
+       x->fp_exp = FP_NMANT - 1;
+       fpu_norm(x);
 
        return x;
 }



Home | Main Index | Thread Index | Old Index