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

[Commits] r19855 - in /libdfp/trunk: ./ sysdeps/powerpc/dfpu/ sysdeps/soft-dfp/dpd/ tests/



Author: ryanarn
Date: Fri Jul 27 19:49:50 2012
New Revision: 19855

Log:
2012-07-27  Ryan S. Arnold  <rsa@xxxxxxxxxxxxxxxxxx>
	* Makefile.in (test-printf.os, test-strtod.os): New rules to depend on
	printf_dfp.os and strtod[32|64|128].os respectively.
	* strtod128.c (__DEC_MANT_DIG__, __DEC_MAX_EXP__, __DEC_MIN_EXP__):
	Define to _Decimal128 values.
	* tests/test-strtod.c: Added tests near __DEC*_MAX_EXP__ and
	__DEC*_MIN_EXP__.
	* strtod64.c (__DEC_MANT_DIG__, __DEC_MAX_EXP__, __DEC_MIN_EXP__):
	Define to _Decimal64 values.
	* sysdeps/powerpc/dfpu/numdigits.h (left_justify): Fix VSX case by
	replacing xxlxor with xxlor insn.
	(getexp): Replace stfwix with stfd to prevent erroneous sign extend.
	* sysdeps/soft-dfp/dpd/numdigits.h (getexp): Make return value
	congruent with hardware-dfp for NaN.
	* strtod32.c (__DEC_MANT_DIG__, __DEC_MAX_EXP__, __DEC_MIN_EXP__):
	Define to _Decimal32 values.
	(FUNCTION_L_INTERNAL): Add left_justify call if proposed exponent is
	sufficiently close to __DEC*_MAX_EXP__.  Add zero return if proposed
	exponent is smaller than __DEC*_MIN_EXP__.



Modified:
    libdfp/trunk/ChangeLog
    libdfp/trunk/Makefile.in
    libdfp/trunk/strtod128.c
    libdfp/trunk/strtod32.c
    libdfp/trunk/strtod64.c
    libdfp/trunk/sysdeps/powerpc/dfpu/numdigits.h
    libdfp/trunk/sysdeps/soft-dfp/dpd/numdigits.h
    libdfp/trunk/tests/test-strtod.c

Modified: libdfp/trunk/ChangeLog
==============================================================================
--- libdfp/trunk/ChangeLog (original)
+++ libdfp/trunk/ChangeLog Fri Jul 27 19:49:50 2012
@@ -1,3 +1,23 @@
+2012-07-27  Ryan S. Arnold  <rsa@xxxxxxxxxxxxxxxxxx>
+	* Makefile.in (test-printf.os, test-strtod.os): New rules to depend on
+	printf_dfp.os and strtod[32|64|128].os respectively.
+	* strtod128.c (__DEC_MANT_DIG__, __DEC_MAX_EXP__, __DEC_MIN_EXP__):
+	Define to _Decimal128 values.
+	* tests/test-strtod.c: Added tests near __DEC*_MAX_EXP__ and
+	__DEC*_MIN_EXP__.
+	* strtod64.c (__DEC_MANT_DIG__, __DEC_MAX_EXP__, __DEC_MIN_EXP__):
+	Define to _Decimal64 values.
+	* sysdeps/powerpc/dfpu/numdigits.h (left_justify): Fix VSX case by
+	replacing xxlxor with xxlor insn.
+	(getexp): Replace stfwix with stfd to prevent erroneous sign extend.
+	* sysdeps/soft-dfp/dpd/numdigits.h (getexp): Make return value
+	congruent with hardware-dfp for NaN.
+	* strtod32.c (__DEC_MANT_DIG__, __DEC_MAX_EXP__, __DEC_MIN_EXP__):
+	Define to _Decimal32 values.
+	(FUNCTION_L_INTERNAL): Add left_justify call if proposed exponent is
+	sufficiently close to __DEC*_MAX_EXP__.  Add zero return if proposed
+	exponent is smaller than __DEC*_MIN_EXP__.
+
 2012-07-25  Ryan S. Arnold  <rsa@xxxxxxxxxxxxxxxxxx>
 
 	* Makefile.in (libdfp_c_tests): Added test-getexp.

Modified: libdfp/trunk/Makefile.in
==============================================================================
--- libdfp/trunk/Makefile.in (original)
+++ libdfp/trunk/Makefile.in Fri Jul 27 19:49:50 2012
@@ -335,13 +335,14 @@
 		 test-isnan test-isinf test-isfinite test-fpclassify test-logd \
 		 test-log10d test-strtod test-numdigits test-get_digits \
 		 test-round test-bfp-conversions test-stdlib test-wchar \
-		 test-expd test-GCC-PR52140 test-getexp
+		 test-expd test-GCC-PR52140 test-getexp test-left_justify
 
 libdfp_cxx_tests = test-ostream test-ostream-g-spec test-istream
 
 libdfp_tests = $(libdfp_c_tests) $(libdfp_cxx_tests)
 
 test-printf.os: $(top_builddir)/printf_dfp.os
+test-strtod.os: $(top_builddir)/strtod32.os $(top_builddir)/strtod64.os $(top_builddir)/strtod128.os
 
 # Empty rule which simply makes the libdfp_tests .so's dependent on
 # tests/scaffold.c so that when the scaffold file changes all of the test .so

Modified: libdfp/trunk/strtod128.c
==============================================================================
--- libdfp/trunk/strtod128.c (original)
+++ libdfp/trunk/strtod128.c Fri Jul 27 19:49:50 2012
@@ -1,7 +1,7 @@
 /* Convert string representing a number to Decimal Float value, using given locale.
 
    Copyright (C) 2006 IBM Corporation.
-   Copyright (C) 2007, 2009 Free Software Foundation.
+   Copyright (C) 2007-2012 Free Software Foundation.
 
    This file is part of the Decimal Floating Point C Library.
 
@@ -30,6 +30,10 @@
 #define FLOAT_SIZE	128
 #define FLOAT_ZERO	0.DL
 #define SET_MANTISSA(x,y)
+#define PRINTF_SPEC "%DDf"
+#define __DEC_MANT_DIG__ __DEC128_MANT_DIG__
+#define __DEC_MAX_EXP__ __DEC128_MAX_EXP__
+#define __DEC_MIN_EXP__ __DEC128_MIN_EXP__
 #endif
 
 #include "strtod32.c"

Modified: libdfp/trunk/strtod32.c
==============================================================================
--- libdfp/trunk/strtod32.c (original)
+++ libdfp/trunk/strtod32.c Fri Jul 27 19:49:50 2012
@@ -1,7 +1,6 @@
 /* Convert string representing a number to Decimal Float value, using given locale.
 
-   Copyright (C) 1997, 1998, 2002, 2004, 2005, 2006, 2009
-   Free Software Foundation, Inc.
+   Copyright (C) 1997-2012, Free Software Foundation, Inc.
 
    This file is part of the Decimal Floating Point C Library.
 
@@ -71,12 +70,15 @@
 # define FLT		DEC32
 # define FLOAT_ZERO	0.DF
 # define SET_MANTISSA(x,y)
+# define PRINTF_SPEC "%Hf"
+# define __DEC_MANT_DIG__ __DEC32_MANT_DIG__
+# define __DEC_MAX_EXP__ __DEC32_MAX_EXP__
+# define __DEC_MIN_EXP__ __DEC32_MIN_EXP__
 #endif
 
 #define DEC_TYPE	FLOAT
 #define _DECIMAL_SIZE	FLOAT_SIZE
 #include <numdigits.h>
-
 
 #ifdef USE_WIDE_CHAR
 extern unsigned long long int ____wcstoull_l_internal (const wchar_t *, wchar_t **,
@@ -869,7 +871,8 @@
       return negative ? -FLOAT_HUGE_VAL : FLOAT_HUGE_VAL;
     }
 
-  if (exponent < MIN_10_EXP - (MANT_DIG + 1))
+  /* Obvious underflow before normalization.  */
+  if (exponent < MIN_10_EXP - MANT_DIG + 1 )
     {
       __set_errno (ERANGE);
       freelocale(C_locale);
@@ -979,7 +982,23 @@
   while(++exponent < 0)
     d32 /= 10;
 #else
+  /* Computed underflow after normalization.  */
+  if ( exponent <  (__DEC_MIN_EXP__ - __DEC_MANT_DIG__))
+    {
+      __set_errno (ERANGE);
+      freelocale(C_locale);
+      return FLOAT_ZERO;
+    }
+
+  /* Left justification allows us to set a positive exponent that's near
+   * __DEC*_MAX_EXP__, i.e. _almost_ overflowing.  Complete left justification
+   * may be overkill for most numbers in this situation, so perhaps a specific
+   * digit shift will be a better solution in the future.  */
+  if (exponent > (__DEC_MAX_EXP__ - __DEC_MANT_DIG__))
+      d32 = FUNC_D(left_justify) (d32);
+
   d32 = FUNC_D(setexp) (d32, FUNC_D (getexp) (d32) + exponent);
+
 #endif
 
   return negative? -d32:d32;

Modified: libdfp/trunk/strtod64.c
==============================================================================
--- libdfp/trunk/strtod64.c (original)
+++ libdfp/trunk/strtod64.c Fri Jul 27 19:49:50 2012
@@ -1,7 +1,7 @@
 /* Convert string representing a number to Decimal Float value, using given locale.
 
    Copyright (C) 2006 IBM Corporation.
-   Copyright (C) 2007, 2009 Free Software Foundation.
+   Copyright (C) 2007-2012 Free Software Foundation.
 
    This file is part of the Decimal Floating Point C Library.
 
@@ -30,6 +30,10 @@
 #define FLOAT_SIZE	64
 #define FLOAT_ZERO	0.DD
 #define SET_MANTISSA(x,y)
+#define PRINTF_SPEC "%Df"
+#define __DEC_MANT_DIG__ __DEC64_MANT_DIG__
+#define __DEC_MAX_EXP__ __DEC64_MAX_EXP__
+#define __DEC_MIN_EXP__ __DEC64_MIN_EXP__
 #endif
 
 #include "strtod32.c"

Modified: libdfp/trunk/sysdeps/powerpc/dfpu/numdigits.h
==============================================================================
--- libdfp/trunk/sysdeps/powerpc/dfpu/numdigits.h (original)
+++ libdfp/trunk/sysdeps/powerpc/dfpu/numdigits.h Fri Jul 27 19:49:50 2012
@@ -86,7 +86,7 @@
 {
   DEC_TYPE tmp = x;
   union {
-    int i[2];
+    unsigned int i[2];
     double f;
   } e;
 
@@ -179,7 +179,7 @@
 # error "Unknown decimal size"
 #endif
 
-#ifdef __VSX__
+ #ifdef __VSX__
   static vector int vsx_adjust = { 0, ADJUST, 0, 0 };
   register vector int tmp3;
 #else
@@ -190,9 +190,9 @@
   asm ("dxex" Q " %0,%1\n\t" : "=d"(tmp2) : "d"(rnd));
 
 #ifdef __VSX__
-  asm ("xxlxor %x0,%x1,%x1" : "=v"(tmp3) : "d"(tmp2));
+  asm ("xxlor %x0,%x1,%x1" : "=v"(tmp3) : "d"(tmp2));
   asm ("vsubuwm %0,%1,%2" : "=v"(tmp3) : "v"(tmp3), "v"(vsx_adjust));
-  asm ("xxlxor %x0,%x1,%x1" : "=d"(tmp2) : "v"(tmp3));
+  asm ("xxlor %x0,%x1,%x1" : "=d"(tmp2) : "v"(tmp3));
 #else
   d2.f = tmp2;
   d2.i[1] -= ADJUST;

Modified: libdfp/trunk/sysdeps/soft-dfp/dpd/numdigits.h
==============================================================================
--- libdfp/trunk/sysdeps/soft-dfp/dpd/numdigits.h (original)
+++ libdfp/trunk/sysdeps/soft-dfp/dpd/numdigits.h Fri Jul 27 19:49:50 2012
@@ -1,7 +1,7 @@
 /* Number of digits functions.
 
    Copyright (C) 2006, 2007, 2008 IBM Corporation.
-   Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2007-2012, Free Software Foundation, Inc.
 
    This file is part of the Decimal Floating Point C Library.
 
@@ -23,7 +23,7 @@
 
    Please see dfp/COPYING.txt for more information.  */
 
-/* Alow this file to be included more than once, so don't use the usual
+/* Allow this file to be included more than once, so don't use the usual
    include guards.  */
 
 #define NUMDIGITS_SUPPORT 1
@@ -80,6 +80,10 @@
   exp -= DECIMAL128_Bias;
 
 #endif
+
+  /* Hardware DFP returns -2 = DECIMAL*_BIAS for a NaN. Be congruent with that.  */
+  if (exp < 0)
+    return --exp;
 
   return exp;
 }

Modified: libdfp/trunk/tests/test-strtod.c
==============================================================================
--- libdfp/trunk/tests/test-strtod.c (original)
+++ libdfp/trunk/tests/test-strtod.c Fri Jul 27 19:49:50 2012
@@ -70,13 +70,20 @@
   {__LINE__, "3.14", 3.140000DF, 3.140000DD, 3.140000DL },
   {__LINE__, "3.14e-2", 0.031400DF, 0.031400DD, 0.031400DL },
   {__LINE__, "1234.5678910111213e-5", 0.01234568DF ,0.01234567891011121DD ,0.012345678910111213DL },
-  {__LINE__, "-1234.57", -1234.57F, -1234.57DD, -1234.57DL},
+  {__LINE__, "-1234.57", -1234.57DF, -1234.57DD, -1234.57DL},
   {0,0,0,0,0 }
 };
 
 const char DECLET32_NAN[] = "+0,000,000E-101";
 const char DECLET64_NAN[] = "+0,000,000,000,000,000E-398";
 const char DECLET128_NAN[] = "+0,000,000,000,000,000,000,000,000,000,000,000E-6176";
+
+const char DECLET_ZERO_D32[] = "+0,000,000E+0";
+const char DECLET_ZERO_D64[] = "+0,000,000,000,000,000E+0";
+
+const char DECLET_HUGE_VAL_D32[] = "+0,000,000E-101";
+const char DECLET_HUGE_VAL_D64[] = "+0,000,000,000,000,000E-398";
+const char DECLET_HUGE_VAL_D128[] = "+0,000,000,000,000,000,000,000,000,000,000,000E-6176";
 
 /* Inspired by GLIBC stdio-common/tfformat.c  */
 typedef struct{
@@ -92,6 +99,25 @@
   /* Compare against the decoded declet for each representation of DEC_NAN
    * since you can't compare DEC_NAN to DEC_NAN.  */
   {__LINE__, "NaN", DECLET32_NAN, DECLET64_NAN, DECLET128_NAN},
+  {__LINE__, "4E-382", "+0,000,000E+0", "+0,000,000,000,000,004E-382", "+0,000,000,000,000,000,000,000,000,000,000,004E-382"},
+
+  /* __DEC64_SUBNORMAL_MIN__ */
+  {__LINE__, "0.000000000000001E-383",  DECLET_ZERO_D32, "+0,000,000,000,000,001E-398", "+0,000,000,000,000,000,000,000,000,000,000,001E-398"},
+  /* This exceeds __DEC64_MIN_EXP__ so it can't be encoded in _Decimal64 and will underflow.  */
+  {__LINE__, "4E-399", DECLET_ZERO_D32, "+0,000,000,000,000,000E+0", "+0,000,000,000,000,000,000,000,000,000,000,004E-399"},
+  {__LINE__, "4000000000000000E-383", DECLET_ZERO_D32, "+4,000,000,000,000,000E-383", "+0,000,000,000,000,000,004,000,000,000,000,000E-383"},
+  {__LINE__, "4000000000000000E-384", DECLET_ZERO_D32, "+4,000,000,000,000,000E-384", "+0,000,000,000,000,000,004,000,000,000,000,000E-384"},
+  {__LINE__, "4000000000000000E-398", DECLET_ZERO_D32, "+4,000,000,000,000,000E-398", "+0,000,000,000,000,000,004,000,000,000,000,000E-398"},
+  /* This exceeds __DEC64_MIN_EXP__ so it can't be encoded in _Decimal64 and will underflow.  */
+  {__LINE__, "4000000000000000E-399", DECLET_ZERO_D32, DECLET_ZERO_D64, "+0,000,000,000,000,000,004,000,000,000,000,000E-399"},
+  /* This exceeds __DEC64_SUBNORMAL_MIN__ so it can't be encoded in _Decimal64 and will underflow.  */
+  {__LINE__, "4E-400", DECLET_ZERO_D32, DECLET_ZERO_D64, "+0,000,000,000,000,000,000,000,000,000,000,004E-400"},
+
+  {__LINE__, "4E369", DECLET_HUGE_VAL_D32, "+0,000,000,000,000,004E+369", "+0,000,000,000,000,000,000,000,000,000,000,004E+369"},
+  {__LINE__, "4E383", DECLET_HUGE_VAL_D32, "+4,000,000,000,000,000E+368", "+0,000,000,000,000,000,000,000,000,000,000,004E+383"},
+  {__LINE__, "4E384", DECLET_HUGE_VAL_D32, "+4,000,000,000,000,000E+369", "+0,000,000,000,000,000,000,000,000,000,000,004E+384"},
+  {__LINE__, "4E385", DECLET_HUGE_VAL_D32, DECLET_HUGE_VAL_D64, "+0,000,000,000,000,000,000,000,000,000,000,004E+385"},
+
   {__LINE__, "1.23456789E-7", "+1,234,568E-13", "+0,000,000,123,456,789E-15", "+0,000,000,000,000,000,000,000,000,123,456,789E-15" },
   {__LINE__, "1234.5678910111213e-5", "+1,234,568E-8", "+1,234,567,891,011,121E-17", "+0,000,000,000,000,000,012,345,678,910,111,213E-18" },
   {0,0,0,0,0 }
@@ -122,14 +148,6 @@
       _DC_P(__FILE__,dnanptr->line,dnanptr->d128, strtod128(dnanptr->input,NULL));
     }
 
-  {
-   #include "decode.h"
-    _Decimal64 d64 = strtod64("4e384",NULL);
-    printf("4e384DD: %.16Da\n", d64);
-   char dbuf[256];
-   printf("%s\n", decoded64(d64,dbuf));
-  }
-
   _REPORT();
 
   /* fail comes from scaffold.c  */

_______________________________________________
Commits mailing list
Commits@xxxxxxxxxx
http://eglibc.org/cgi-bin/mailman/listinfo/commits