From 59323cef79402b492891650f4b185e375fd35c5a Mon Sep 17 00:00:00 2001 From: kettenis Date: Fri, 30 Jul 2010 18:05:23 +0000 Subject: [PATCH] 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. ok miod@ --- sys/arch/hppa/spmath/fcnvfx.c | 132 ++++++++++----------------------- sys/arch/hppa/spmath/fcnvfxt.c | 128 ++++++++++---------------------- 2 files changed, 80 insertions(+), 180 deletions(-) diff --git a/sys/arch/hppa/spmath/fcnvfx.c b/sys/arch/hppa/spmath/fcnvfx.c index 4b846f68d53..d29f4419e50 100644 --- a/sys/arch/hppa/spmath/fcnvfx.c +++ b/sys/arch/hppa/spmath/fcnvfx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fcnvfx.c,v 1.7 2003/04/10 17:27:58 mickey Exp $ */ +/* $OpenBSD: fcnvfx.c,v 1.8 2010/07/30 18:05:23 kettenis Exp $ */ /* (c) Copyright 1986 HEWLETT-PACKARD COMPANY To anyone who acknowledges that this file is provided "AS IS" @@ -43,28 +43,15 @@ sgl_to_sgl_fcnvfx(srcptr, null, dstptr, status) /* check for MININT */ if ((src_exponent > SGL_FX_MAX_EXP + 1) || Sgl_isnotzero_mantissa(src) || Sgl_iszero_sign(src)) { - if( Sgl_isnan(src) ) - /* - * On NaN go unimplemented. - */ - return(UNIMPLEMENTEDEXCEPTION); - else { - if (Sgl_iszero_sign(src)) result = 0x7fffffff; - else result = 0x80000000; + if (Sgl_iszero_sign(src)) 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); + if (Is_invalidtrap_enabled()) { + return(INVALIDEXCEPTION); } + Set_invalidflag(); + *dstptr = result; + return(NOEXCEPTION); } } /* @@ -154,33 +141,21 @@ sgl_to_dbl_fcnvfx(srcptr, null, dstptr, status) /* check for MININT */ if ((src_exponent > DBL_FX_MAX_EXP + 1) || Sgl_isnotzero_mantissa(src) || Sgl_iszero_sign(src)) { - if( Sgl_isnan(src) ) - /* - * On NaN go unimplemented. - */ - return(UNIMPLEMENTEDEXCEPTION); - else { - if (Sgl_iszero_sign(src)) { + if (Sgl_iszero_sign(src)) { resultp1 = 0x7fffffff; - resultp2 = 0xffffffff; - } - else { - resultp1 = 0x80000000; - resultp2 = 0; - } - if (Is_overflowtrap_enabled()) { - if (Is_inexacttrap_enabled()) - return(OVERFLOWEXCEPTION|INEXACTEXCEPTION); - else Set_inexactflag(); - return(OVERFLOWEXCEPTION); - } - Set_overflowflag(); - Dint_copytoptr(resultp1,resultp2,dstptr); - if (Is_inexacttrap_enabled() ) - return(INEXACTEXCEPTION); - else Set_inexactflag(); - return(NOEXCEPTION); + 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); @@ -288,28 +263,15 @@ dbl_to_sgl_fcnvfx(srcptr, null, dstptr, status) if (src_exponent > SGL_FX_MAX_EXP) { /* check for MININT */ if (Dbl_isoverflow_to_int(src_exponent,srcp1,srcp2)) { - if( Dbl_isnan(srcp1,srcp2) ) - /* - * On NaN go unimplemented. - */ - return(UNIMPLEMENTEDEXCEPTION); - else { - if (Dbl_iszero_sign(srcp1)) result = 0x7fffffff; - else result = 0x80000000; + 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); + if (Is_invalidtrap_enabled()) { + return(INVALIDEXCEPTION); } + Set_invalidflag(); + *dstptr = result; + return(NOEXCEPTION); } } /* @@ -423,33 +385,21 @@ dbl_to_dbl_fcnvfx(srcptr, null, dstptr, status) /* check for MININT */ if ((src_exponent > DBL_FX_MAX_EXP + 1) || Dbl_isnotzero_mantissa(srcp1,srcp2) || Dbl_iszero_sign(srcp1)) { - if( Dbl_isnan(srcp1,srcp2) ) - /* - * On NaN go unimplemented. - */ - return(UNIMPLEMENTEDEXCEPTION); + if (Dbl_iszero_sign(srcp1)) { + resultp1 = 0x7fffffff; + resultp2 = 0xffffffff; + } else { - if (Dbl_iszero_sign(srcp1)) { - resultp1 = 0x7fffffff; - resultp2 = 0xffffffff; - } - else { - resultp1 = 0x80000000; - resultp2 = 0; - } - if (Is_overflowtrap_enabled()) { - if (Is_inexacttrap_enabled()) - return(OVERFLOWEXCEPTION|INEXACTEXCEPTION); - else Set_inexactflag(); - return(OVERFLOWEXCEPTION); - } - Set_overflowflag(); - Dint_copytoptr(resultp1,resultp2,dstptr); - if (Is_inexacttrap_enabled() ) - return(INEXACTEXCEPTION); - else Set_inexactflag(); - return(NOEXCEPTION); + resultp1 = 0x80000000; + resultp2 = 0; + } + + if (Is_invalidtrap_enabled()) { + return(INVALIDEXCEPTION); } + Set_invalidflag(); + Dint_copytoptr(resultp1,resultp2,dstptr); + return(NOEXCEPTION); } } diff --git a/sys/arch/hppa/spmath/fcnvfxt.c b/sys/arch/hppa/spmath/fcnvfxt.c index 96e17dc09d9..a29d15e5f9a 100644 --- a/sys/arch/hppa/spmath/fcnvfxt.c +++ b/sys/arch/hppa/spmath/fcnvfxt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fcnvfxt.c,v 1.7 2003/04/10 17:27:58 mickey Exp $ */ +/* $OpenBSD: fcnvfxt.c,v 1.8 2010/07/30 18:05:23 kettenis Exp $ */ /* (c) Copyright 1986 HEWLETT-PACKARD COMPANY To anyone who acknowledges that this file is provided "AS IS" @@ -43,28 +43,15 @@ sgl_to_sgl_fcnvfxt(srcptr, null, dstptr, status) /* check for MININT */ if ((src_exponent > SGL_FX_MAX_EXP + 1) || Sgl_isnotzero_mantissa(src) || Sgl_iszero_sign(src)) { - if( Sgl_isnan(src) ) - /* - * On NaN go unimplemented. - */ - return(UNIMPLEMENTEDEXCEPTION); - else { - if (Sgl_iszero_sign(src)) result = 0x7fffffff; - else result = 0x80000000; + if (Sgl_iszero_sign(src)) 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); + if (Is_invalidtrap_enabled()) { + return(INVALIDEXCEPTION); } + Set_invalidflag(); + *dstptr = result; + return(NOEXCEPTION); } } /* @@ -119,33 +106,21 @@ sgl_to_dbl_fcnvfxt(srcptr, null, dstptr, status) /* check for MININT */ if ((src_exponent > DBL_FX_MAX_EXP + 1) || Sgl_isnotzero_mantissa(src) || Sgl_iszero_sign(src)) { - if( Sgl_isnan(src) ) - /* - * On NaN go unimplemented. - */ - return(UNIMPLEMENTEDEXCEPTION); - else { - if (Sgl_iszero_sign(src)) { + if (Sgl_iszero_sign(src)) { resultp1 = 0x7fffffff; resultp2 = 0xffffffff; - } - else { - resultp1 = 0x80000000; - resultp2 = 0; - } - if (Is_overflowtrap_enabled()) { - if (Is_inexacttrap_enabled()) - return(OVERFLOWEXCEPTION|INEXACTEXCEPTION); - else Set_inexactflag(); - return(OVERFLOWEXCEPTION); - } - Set_overflowflag(); - Dint_copytoptr(resultp1,resultp2,dstptr); - if (Is_inexacttrap_enabled() ) - return(INEXACTEXCEPTION); - else Set_inexactflag(); - return(NOEXCEPTION); } + 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); @@ -204,28 +179,15 @@ dbl_to_sgl_fcnvfxt(srcptr, null, dstptr, status) if (src_exponent > SGL_FX_MAX_EXP) { /* check for MININT */ if (Dbl_isoverflow_to_int(src_exponent,srcp1,srcp2)) { - if( Dbl_isnan(srcp1,srcp2) ) - /* - * On NaN go unimplemented. - */ - return(UNIMPLEMENTEDEXCEPTION); - else { - if (Dbl_iszero_sign(srcp1)) result = 0x7fffffff; - else result = 0x80000000; + 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); + if (Is_invalidtrap_enabled()) { + return(INVALIDEXCEPTION); } + Set_invalidflag(); + *dstptr = result; + return(NOEXCEPTION); } } /* @@ -282,33 +244,21 @@ dbl_to_dbl_fcnvfxt(srcptr, null, dstptr, status) /* check for MININT */ if ((src_exponent > DBL_FX_MAX_EXP + 1) || Dbl_isnotzero_mantissa(srcp1,srcp2) || Dbl_iszero_sign(srcp1)) { - if( Dbl_isnan(srcp1,srcp2) ) - /* - * On NaN go unimplemented. - */ - return(UNIMPLEMENTEDEXCEPTION); - else { - if (Dbl_iszero_sign(srcp1)) { + if (Dbl_iszero_sign(srcp1)) { resultp1 = 0x7fffffff; resultp2 = 0xffffffff; - } - else { - resultp1 = 0x80000000; - resultp2 = 0; - } - if (Is_overflowtrap_enabled()) { - if (Is_inexacttrap_enabled()) - return(OVERFLOWEXCEPTION|INEXACTEXCEPTION); - else Set_inexactflag(); - return(OVERFLOWEXCEPTION); - } - Set_overflowflag(); - Dint_copytoptr(resultp1,resultp2,dstptr); - if (Is_inexacttrap_enabled() ) - return(INEXACTEXCEPTION); - else Set_inexactflag(); - return(NOEXCEPTION); } + else { + resultp1 = 0x80000000; + resultp2 = 0; + } + + if (Is_invalidtrap_enabled()) { + return(INVALIDEXCEPTION); + } + Set_invalidflag(); + Dint_copytoptr(resultp1,resultp2,dstptr); + return(NOEXCEPTION); } } /* -- 2.20.1