Module Name:    src
Committed By:   skrll
Date:           Sun Jan  1 20:04:36 UTC 2012

Modified Files:
        src/sys/arch/hppa/spmath: fcnvfx.c fcnvfxt.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/hppa/spmath/fcnvfx.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/hppa/spmath/fcnvfxt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/hppa/spmath/fcnvfx.c
diff -u src/sys/arch/hppa/spmath/fcnvfx.c:1.4 src/sys/arch/hppa/spmath/fcnvfx.c:1.5
--- src/sys/arch/hppa/spmath/fcnvfx.c:1.4	Thu Feb 22 05:46:30 2007
+++ src/sys/arch/hppa/spmath/fcnvfx.c	Sun Jan  1 20:04:36 2012
@@ -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 @@ unsigned int *status;
 		/* 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 @@ unsigned int *status;
 		/* 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 @@ unsigned int *status;
 	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 @@ unsigned int *status;
 			/*  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 @@ unsigned int *status;
 			/* 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 @@ unsigned int *status;
 		/* 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);
 		}
 	}
 

Index: src/sys/arch/hppa/spmath/fcnvfxt.c
diff -u src/sys/arch/hppa/spmath/fcnvfxt.c:1.3 src/sys/arch/hppa/spmath/fcnvfxt.c:1.4
--- src/sys/arch/hppa/spmath/fcnvfxt.c:1.3	Sun Dec 11 12:17:40 2005
+++ src/sys/arch/hppa/spmath/fcnvfxt.c	Sun Jan  1 20:04:36 2012
@@ -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 @@ unsigned int *status;
 		/* 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 @@ unsigned int *status;
 		/* 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 @@ unsigned int *status;
 	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 @@ unsigned int *status;
 		/* 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);
 		}
 	}
 	/*

Reply via email to