Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/hppa/spmath When converting a floating value to an ...



details:   https://anonhg.NetBSD.org/src/rev/b20984028245
branches:  trunk
changeset: 772393:b20984028245
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sun Jan 01 20:04:36 2012 +0000

description:
When converting a floating value to an integer, properly raise the "invalid"
exception when the floating value is infinite or NaN or if the integral part
of the floating value exceeds the range of the integer type, as required by
the C99/IEEE754 standard.

Fixes Python 2.6 build on hppa.

>From OpenBSD.

diffstat:

 sys/arch/hppa/spmath/fcnvfx.c  |  99 +++++++++++++++++++++++++++++------------
 sys/arch/hppa/spmath/fcnvfxt.c |  73 +++++++++++++++++++++---------
 2 files changed, 121 insertions(+), 51 deletions(-)

diffs (272 lines):

diff -r 7e3e77cdd9e0 -r b20984028245 sys/arch/hppa/spmath/fcnvfx.c
--- a/sys/arch/hppa/spmath/fcnvfx.c     Sun Jan 01 19:12:17 2012 +0000
+++ b/sys/arch/hppa/spmath/fcnvfx.c     Sun Jan 01 20:04:36 2012 +0000
@@ -1,6 +1,5 @@
-/*     $NetBSD: fcnvfx.c,v 1.4 2007/02/22 05:46:30 thorpej Exp $       */
 
-/*     $OpenBSD: fcnvfx.c,v 1.5 2001/03/29 03:58:18 mickey Exp $       */
+/*     $OpenBSD: fcnvfx.c,v 1.8 2010/07/30 18:05:23 kettenis Exp $     */
 
 /*
  * Copyright 1996 1995 by Open Software Foundation, Inc.
@@ -42,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fcnvfx.c,v 1.4 2007/02/22 05:46:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fcnvfx.c,v 1.5 2012/01/01 20:04:36 skrll Exp $");
 
 #include "../spmath/float.h"
 #include "../spmath/sgl_float.h"
@@ -74,12 +73,15 @@
                /* check for MININT */
                if ((src_exponent > SGL_FX_MAX_EXP + 1) ||
                Sgl_isnotzero_mantissa(src) || Sgl_iszero_sign(src)) {
-                       /*
-                        * Since source is a number which cannot be
-                        * represented in fixed-point format, return
-                        * largest (or smallest) fixed-point number.
-                        */
-                       Sgl_return_overflow(src,dstptr);
+                       if (Sgl_iszero_sign(src)) result = 0x7fffffff;
+                       else result = 0x80000000;
+
+                       if (Is_invalidtrap_enabled()) {
+                               return(INVALIDEXCEPTION);
+                       }
+                       Set_invalidflag();
+                       *dstptr = result;
+                       return(NOEXCEPTION);
                }
        }
        /*
@@ -170,12 +172,21 @@
                /* check for MININT */
                if ((src_exponent > DBL_FX_MAX_EXP + 1) ||
                Sgl_isnotzero_mantissa(src) || Sgl_iszero_sign(src)) {
-                       /*
-                        * Since source is a number which cannot be
-                        * represented in fixed-point format, return
-                        * largest (or smallest) fixed-point number.
-                        */
-                       Sgl_return_overflow_dbl(src,dstptr);
+                       if (Sgl_iszero_sign(src)) {
+                               resultp1 = 0x7fffffff;
+                               resultp2 = 0xffffffff;
+                       }
+                       else {
+                               resultp1 = 0x80000000;
+                               resultp2 = 0;
+                       }
+
+                       if (Is_invalidtrap_enabled()) {
+                               return(INVALIDEXCEPTION);
+                       }
+                       Set_invalidflag();
+                       Dint_copytoptr(resultp1,resultp2,dstptr);
+                       return(NOEXCEPTION);
                }
                Dint_set_minint(resultp1,resultp2);
                Dint_copytoptr(resultp1,resultp2,dstptr);
@@ -284,12 +295,15 @@
        if (src_exponent > SGL_FX_MAX_EXP) {
                /* check for MININT */
                if (Dbl_isoverflow_to_int(src_exponent,srcp1,srcp2)) {
-                       /*
-                        * Since source is a number which cannot be
-                        * represented in fixed-point format, return
-                        * largest (or smallest) fixed-point number.
-                        */
-                       Dbl_return_overflow(srcp1,srcp2,dstptr);
+                       if (Dbl_iszero_sign(srcp1)) result = 0x7fffffff;
+                       else result = 0x80000000;
+
+                       if (Is_invalidtrap_enabled()) {
+                               return(INVALIDEXCEPTION);
+                       }
+                       Set_invalidflag();
+                       *dstptr = result;
+                       return(NOEXCEPTION);
                }
        }
        /*
@@ -310,7 +324,8 @@
                        /*  round result  */
                        switch (Rounding_mode()) {
                        case ROUNDPLUS:
-                            if (Dbl_iszero_sign(srcp1)) result++;
+                               if (Dbl_iszero_sign(srcp1))
+                                       result++;
                             break;
                        case ROUNDMINUS:
                             if (Dbl_isone_sign(srcp1)) result--;
@@ -326,7 +341,24 @@
                        /* check for overflow */
                        if ((Dbl_iszero_sign(srcp1) && result < 0) ||
                            (Dbl_isone_sign(srcp1) && result > 0)) {
-                               Dbl_return_overflow(srcp1,srcp2,dstptr);
+
+                               if (Dbl_iszero_sign(srcp1))
+                                       result = 0x7fffffff;
+                               else
+                                       result = 0x80000000;
+
+                           if (Is_overflowtrap_enabled()) {
+                           if (Is_inexacttrap_enabled())
+                             return(OVERFLOWEXCEPTION|INEXACTEXCEPTION);
+                           else Set_inexactflag();
+                           return(OVERFLOWEXCEPTION);
+                           }
+                         Set_overflowflag();
+                         *dstptr = result;
+                         if (Is_inexacttrap_enabled() )
+                               return(INEXACTEXCEPTION);
+                         else Set_inexactflag();
+                         return(NOEXCEPTION);
                        }
                }
        }
@@ -386,12 +418,21 @@
                /* check for MININT */
                if ((src_exponent > DBL_FX_MAX_EXP + 1) ||
                Dbl_isnotzero_mantissa(srcp1,srcp2) || Dbl_iszero_sign(srcp1)) {
-                       /*
-                        * Since source is a number which cannot be
-                        * represented in fixed-point format, return
-                        * largest (or smallest) fixed-point number.
-                        */
-                       Dbl_return_overflow_dbl(srcp1,srcp2,dstptr);
+                       if (Dbl_iszero_sign(srcp1)) {
+                               resultp1 = 0x7fffffff;
+                               resultp2 = 0xffffffff;
+                       }
+                       else {
+                               resultp1 = 0x80000000;
+                               resultp2 = 0;
+                       }
+
+                       if (Is_invalidtrap_enabled()) {
+                               return(INVALIDEXCEPTION);
+                       }
+                       Set_invalidflag();
+                       Dint_copytoptr(resultp1,resultp2,dstptr);
+                       return(NOEXCEPTION);
                }
        }
 
diff -r 7e3e77cdd9e0 -r b20984028245 sys/arch/hppa/spmath/fcnvfxt.c
--- a/sys/arch/hppa/spmath/fcnvfxt.c    Sun Jan 01 19:12:17 2012 +0000
+++ b/sys/arch/hppa/spmath/fcnvfxt.c    Sun Jan 01 20:04:36 2012 +0000
@@ -1,6 +1,6 @@
-/*     $NetBSD: fcnvfxt.c,v 1.3 2005/12/11 12:17:40 christos Exp $     */
+/*     $NetBSD: fcnvfxt.c,v 1.4 2012/01/01 20:04:36 skrll Exp $        */
 
-/*     $OpenBSD: fcnvfxt.c,v 1.5 2001/03/29 03:58:18 mickey Exp $      */
+/*     $OpenBSD: fcnvfxt.c,v 1.8 2010/07/30 18:05:23 kettenis Exp $    */
 
 /*
  * Copyright 1996 1995 by Open Software Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fcnvfxt.c,v 1.3 2005/12/11 12:17:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fcnvfxt.c,v 1.4 2012/01/01 20:04:36 skrll Exp $");
 
 #include "../spmath/float.h"
 #include "../spmath/sgl_float.h"
@@ -74,12 +74,15 @@
                /* check for MININT */
                if ((src_exponent > SGL_FX_MAX_EXP + 1) ||
                Sgl_isnotzero_mantissa(src) || Sgl_iszero_sign(src)) {
-                       /*
-                        * Since source is a number which cannot be
-                        * represented in fixed-point format, return
-                        * largest (or smallest) fixed-point number.
-                        */
-                       Sgl_return_overflow(src,dstptr);
+                       if (Sgl_iszero_sign(src)) result = 0x7fffffff;
+                       else result = 0x80000000;
+
+                       if (Is_invalidtrap_enabled()) {
+                               return(INVALIDEXCEPTION);
+                       }
+                       Set_invalidflag();
+                       *dstptr = result;
+                       return(NOEXCEPTION);
                }
        }
        /*
@@ -135,12 +138,21 @@
                /* check for MININT */
                if ((src_exponent > DBL_FX_MAX_EXP + 1) ||
                Sgl_isnotzero_mantissa(src) || Sgl_iszero_sign(src)) {
-                       /*
-                        * Since source is a number which cannot be
-                        * represented in fixed-point format, return
-                        * largest (or smallest) fixed-point number.
-                        */
-                       Sgl_return_overflow_dbl(src,dstptr);
+                       if (Sgl_iszero_sign(src)) {
+                               resultp1 = 0x7fffffff;
+                               resultp2 = 0xffffffff;
+                       }
+                       else {
+                               resultp1 = 0x80000000;
+                               resultp2 = 0;
+                       }
+
+                       if (Is_invalidtrap_enabled()) {
+                               return(INVALIDEXCEPTION);
+                       }
+                       Set_invalidflag();
+                       Dint_copytoptr(resultp1,resultp2,dstptr);
+                       return(NOEXCEPTION);
                }
                Dint_set_minint(resultp1,resultp2);
                Dint_copytoptr(resultp1,resultp2,dstptr);
@@ -200,7 +212,15 @@
        if (src_exponent > SGL_FX_MAX_EXP) {
                /* check for MININT */
                if (Dbl_isoverflow_to_int(src_exponent,srcp1,srcp2)) {
-                       Dbl_return_overflow(srcp1,srcp2,dstptr);
+                       if (Dbl_iszero_sign(srcp1)) result = 0x7fffffff;
+                       else result = 0x80000000;
+
+                       if (Is_invalidtrap_enabled()) {
+                               return(INVALIDEXCEPTION);
+                       }
+                       Set_invalidflag();
+                       *dstptr = result;
+                       return(NOEXCEPTION);
                }
        }
        /*
@@ -258,12 +278,21 @@
                /* check for MININT */
                if ((src_exponent > DBL_FX_MAX_EXP + 1) ||
                Dbl_isnotzero_mantissa(srcp1,srcp2) || Dbl_iszero_sign(srcp1)) {
-                       /*
-                        * Since source is a number which cannot be
-                        * represented in fixed-point format, return
-                        * largest (or smallest) fixed-point number.
-                        */
-                       Dbl_return_overflow_dbl(srcp1,srcp2,dstptr);
+                       if (Dbl_iszero_sign(srcp1)) {
+                               resultp1 = 0x7fffffff;
+                               resultp2 = 0xffffffff;
+                       }
+                       else {
+                               resultp1 = 0x80000000;
+                               resultp2 = 0;
+                       }
+
+                       if (Is_invalidtrap_enabled()) {
+                               return(INVALIDEXCEPTION);
+                       }
+                       Set_invalidflag();
+                       Dint_copytoptr(resultp1,resultp2,dstptr);
+                       return(NOEXCEPTION);
                }
        }
        /*



Home | Main Index | Thread Index | Old Index