summaryrefslogtreecommitdiff
path: root/sys/arch/hppa/spmath/fcnvfx.c
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2002-05-07 22:19:31 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2002-05-07 22:19:31 +0000
commit7657493d64c6d80359ef3a35f5de5a09b490b1ea (patch)
treee59f824bdf0e43a5fdbc0821e0882cf802ee4283 /sys/arch/hppa/spmath/fcnvfx.c
parentb02e4f767517ffad3d92f4cfb03fd681231fa3e4 (diff)
bring over our mods; the cnv*c have a problem now, described in the osf version of the cnv_float.h, at the end
Diffstat (limited to 'sys/arch/hppa/spmath/fcnvfx.c')
-rw-r--r--sys/arch/hppa/spmath/fcnvfx.c259
1 files changed, 161 insertions, 98 deletions
diff --git a/sys/arch/hppa/spmath/fcnvfx.c b/sys/arch/hppa/spmath/fcnvfx.c
index c646d8dffaa..397596d8a9e 100644
--- a/sys/arch/hppa/spmath/fcnvfx.c
+++ b/sys/arch/hppa/spmath/fcnvfx.c
@@ -1,48 +1,23 @@
-/* $OpenBSD: fcnvfx.c,v 1.5 2001/03/29 03:58:18 mickey Exp $ */
-
-/*
- * Copyright 1996 1995 by Open Software Foundation, Inc.
- * All Rights Reserved
- *
- * Permission to use, copy, modify, and distribute this software and
- * its documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appears in all copies and
- * that both the copyright notice and this permission notice appear in
- * supporting documentation.
- *
- * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE.
- *
- * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
- * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
- * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- */
+/* $OpenBSD: fcnvfx.c,v 1.6 2002/05/07 22:19:30 mickey Exp $ */
/*
- * pmk1.1
- */
-/*
- * (c) Copyright 1986 HEWLETT-PACKARD COMPANY
- *
- * To anyone who acknowledges that this file is provided "AS IS"
- * without any express or implied warranty:
- * permission to use, copy, modify, and distribute this file
- * for any purpose is hereby granted without fee, provided that
- * the above copyright notice and this notice appears in all
- * copies, and that the name of Hewlett-Packard Company not be
- * used in advertising or publicity pertaining to distribution
- * of the software without specific, written prior permission.
- * Hewlett-Packard Company makes no representations about the
- * suitability of this software for any purpose.
- */
+ (c) Copyright 1986 HEWLETT-PACKARD COMPANY
+ To anyone who acknowledges that this file is provided "AS IS"
+ without any express or implied warranty:
+ permission to use, copy, modify, and distribute this file
+ for any purpose is hereby granted without fee, provided that
+ the above copyright notice and this notice appears in all
+ copies, and that the name of Hewlett-Packard Company not be
+ used in advertising or publicity pertaining to distribution
+ of the software without specific, written prior permission.
+ Hewlett-Packard Company makes no representations about the
+ suitability of this software for any purpose.
+*/
+/* @(#)fcnvfx.c: Revision: 2.8.88.2 Date: 93/12/08 13:27:29 */
-#include "../spmath/float.h"
-#include "../spmath/sgl_float.h"
-#include "../spmath/dbl_float.h"
-#include "../spmath/cnv_float.h"
+#include "float.h"
+#include "sgl_float.h"
+#include "dbl_float.h"
+#include "cnv_float.h"
/*
* Single Floating-point to Single Fixed-point
@@ -50,10 +25,9 @@
/*ARGSUSED*/
int
sgl_to_sgl_fcnvfx(srcptr,dstptr,status)
-
-sgl_floating_point *srcptr;
-int *dstptr;
-unsigned int *status;
+ sgl_floating_point *srcptr;
+ int *dstptr;
+ unsigned int *status;
{
register unsigned int src, temp;
register int src_exponent, result;
@@ -69,12 +43,28 @@ 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_isnan(src) )
+ /*
+ * On NaN go unimplemented.
+ */
+ return(UNIMPLEMENTEDEXCEPTION);
+ else {
+ 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);
+ }
}
}
/*
@@ -146,10 +136,9 @@ unsigned int *status;
/*ARGSUSED*/
int
sgl_to_dbl_fcnvfx(srcptr,dstptr,status)
-
-sgl_floating_point *srcptr;
-dbl_integer *dstptr;
-unsigned int *status;
+ sgl_floating_point *srcptr;
+ dbl_integer *dstptr;
+ unsigned int *status;
{
register int src_exponent, resultp1;
register unsigned int src, temp, resultp2;
@@ -165,12 +154,33 @@ 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_isnan(src) )
+ /*
+ * On NaN go unimplemented.
+ */
+ return(UNIMPLEMENTEDEXCEPTION);
+ else {
+ 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);
+ }
}
Dint_set_minint(resultp1,resultp2);
Dint_copytoptr(resultp1,resultp2,dstptr);
@@ -261,10 +271,9 @@ unsigned int *status;
/*ARGSUSED*/
int
dbl_to_sgl_fcnvfx(srcptr,dstptr,status)
-
-dbl_floating_point *srcptr;
-int *dstptr;
-unsigned int *status;
+ dbl_floating_point *srcptr;
+ int *dstptr;
+ unsigned int *status;
{
register unsigned int srcp1,srcp2, tempp1,tempp2;
register int src_exponent, result;
@@ -279,12 +288,28 @@ 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_isnan(srcp1,srcp2) )
+ /*
+ * On NaN go unimplemented.
+ */
+ return(UNIMPLEMENTEDEXCEPTION);
+ else {
+ 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);
+ }
}
}
/*
@@ -305,23 +330,41 @@ unsigned int *status;
/* round result */
switch (Rounding_mode()) {
case ROUNDPLUS:
- if (Dbl_iszero_sign(srcp1)) result++;
- break;
+ if (Dbl_iszero_sign(srcp1))
+ result++;
+ break;
case ROUNDMINUS:
- if (Dbl_isone_sign(srcp1)) result--;
- break;
+ if (Dbl_isone_sign(srcp1)) result--;
+ break;
case ROUNDNEAREST:
- if (Dbl_isone_roundbit(srcp1,srcp2,src_exponent))
+ if (Dbl_isone_roundbit(srcp1,srcp2,src_exponent))
if (Dbl_isone_stickybit(srcp1,srcp2,src_exponent) ||
(Dbl_isone_lowmantissap1(tempp1))) {
- if (Dbl_iszero_sign(srcp1)) result++;
- else result--;
+ if (Dbl_iszero_sign(srcp1)) result++;
+ else result--;
}
}
/* 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);
}
}
}
@@ -334,16 +377,16 @@ unsigned int *status;
/* round result */
switch (Rounding_mode()) {
case ROUNDPLUS:
- if (Dbl_iszero_sign(srcp1)) result++;
- break;
+ if (Dbl_iszero_sign(srcp1)) result++;
+ break;
case ROUNDMINUS:
- if (Dbl_isone_sign(srcp1)) result--;
- break;
+ if (Dbl_isone_sign(srcp1)) result--;
+ break;
case ROUNDNEAREST:
- if (src_exponent == -1)
+ if (src_exponent == -1)
if (Dbl_isnotzero_mantissa(srcp1,srcp2)) {
- if (Dbl_iszero_sign(srcp1)) result++;
- else result--;
+ if (Dbl_iszero_sign(srcp1)) result++;
+ else result--;
}
}
}
@@ -362,10 +405,9 @@ unsigned int *status;
/*ARGSUSED*/
int
dbl_to_dbl_fcnvfx(srcptr,dstptr,status)
-
-dbl_floating_point *srcptr;
-dbl_integer *dstptr;
-unsigned int *status;
+ dbl_floating_point *srcptr;
+ dbl_integer *dstptr;
+ unsigned int *status;
{
register int src_exponent, resultp1;
register unsigned int srcp1, srcp2, tempp1, tempp2, resultp2;
@@ -381,12 +423,33 @@ 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_isnan(srcp1,srcp2) )
+ /*
+ * On NaN go unimplemented.
+ */
+ return(UNIMPLEMENTEDEXCEPTION);
+ 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);
+ }
}
}