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

[commits] r11106 - in /libdfp/trunk: ChangeLog Makefile.in sysdeps/powerpc/dfpu/fe_decround.c tests/test-round.c



Author: ryanarn
Date: Fri Jul 30 07:28:05 2010
New Revision: 11106

Log:
2010-07-30  Ryan S. Arnold  <rsa@xxxxxxxxxx>

	* sysdeps/powerpc/dfpu/fe_decround.c (__fe_dec_getround): The
	structure which defined the DRN was to small and the compiler started
	generating code that wasn't properly extracting the DRN field from the
	structure holding the FPSCR value.  This is fixed.
	* tests/test-round.c: Testcase to prove fe_dec_getround() and
	fe_dec_setround().
	* Makefile.in (libdfp_tests): Added test-round.


Added:
    libdfp/trunk/tests/test-round.c
Modified:
    libdfp/trunk/ChangeLog
    libdfp/trunk/Makefile.in
    libdfp/trunk/sysdeps/powerpc/dfpu/fe_decround.c

Modified: libdfp/trunk/ChangeLog
==============================================================================
--- libdfp/trunk/ChangeLog (original)
+++ libdfp/trunk/ChangeLog Fri Jul 30 07:28:05 2010
@@ -1,3 +1,13 @@
+2010-07-30  Ryan S. Arnold  <rsa@xxxxxxxxxx>
+
+	* sysdeps/powerpc/dfpu/fe_decround.c (__fe_dec_getround): The
+	structure which defined the DRN was to small and the compiler started
+	generating code that wasn't properly extracting the DRN field from the
+	structure holding the FPSCR value.  This is fixed.
+	* tests/test-round.c: Testcase to prove fe_dec_getround() and
+	fe_dec_setround().
+	* Makefile.in (libdfp_tests): Added test-round.
+
 2010-07-28  Ryan S. Arnold  <rsa@xxxxxxxxxx>
 
 	* configure: Regenerated.

Modified: libdfp/trunk/Makefile.in
==============================================================================
--- libdfp/trunk/Makefile.in (original)
+++ libdfp/trunk/Makefile.in Fri Jul 30 07:28:05 2010
@@ -293,7 +293,7 @@
 GLIBC_LIBS := $(glibc_builddir)/libc.so $(glibc_builddir)/math/libm.so $(glibc_builddir)/nptl/libpthread.so
 endif
 
-libdfp_tests = test-printf test-param test-amort test-decode test-quantize test-isnan test-isinf test-isfinite test-fpclassify test-logd test-strtod test-numdigits test-left_justify test-get_digits
+libdfp_tests = test-printf test-param test-amort test-decode test-quantize test-isnan test-isinf test-isfinite test-fpclassify test-logd test-strtod test-numdigits test-left_justify test-get_digits test-round
 
 # Explicitly link against the uninstalled GLIBC and the Libdfp.so.1 we just
 # built.

Modified: libdfp/trunk/sysdeps/powerpc/dfpu/fe_decround.c
==============================================================================
--- libdfp/trunk/sysdeps/powerpc/dfpu/fe_decround.c (original)
+++ libdfp/trunk/sysdeps/powerpc/dfpu/fe_decround.c Fri Jul 30 07:28:05 2010
@@ -74,28 +74,28 @@
   switch(rounding_direction)
     {
       case FE_DEC_TONEAREST:
-	asm ("mtfsfi 7, 0\n");
+	asm ("mtfsfi 7, 0, 1\n");
 	break;
       case FE_DEC_TOWARDZERO:
-	asm ("mtfsfi 7, 1\n");
+	asm ("mtfsfi 7, 1, 1\n");
 	break;
       case FE_DEC_UPWARD:
-	asm ("mtfsfi 7, 2\n");
+	asm ("mtfsfi 7, 2, 1\n");
 	break;
       case FE_DEC_DOWNWARD:
-	asm ("mtfsfi 7, 3\n");
+	asm ("mtfsfi 7, 3, 1\n");
 	break;
       case FE_DEC_TONEARESTFROMZERO:
-	asm ("mtfsfi 7, 4\n");
+	asm ("mtfsfi 7, 4, 1\n");
 	break;
       case 5: /* Allow covert setting of this rounding mode.  */
-	asm ("mtfsfi 7, 5\n");
+	asm ("mtfsfi 7, 5, 1\n");
 	break;
       case 6: /* Allow covert setting of this rounding mode.  */
-	asm ("mtfsfi 7, 6\n");
+	asm ("mtfsfi 7, 6, 1\n");
 	break;
       case 7: /* Allow covert setting of this rounding mode.  */
-	asm ("mtfsfi 7, 7\n");
+	asm ("mtfsfi 7, 7, 1\n");
 	break;
       default:
 	return 1;
@@ -109,7 +109,10 @@
 {
   union {
     double as_double;
-    struct { unsigned int dummy, dummy2: 28, drn:3; };
+    /* Per ISA 2.05 bit 28 of the FPSCR is reserved for future extension of the
+     * FPSCR (DRN) and is therefore ok to read bits 28-31 of the high word with
+     * the mffs.  */
+    struct { unsigned int dummy: 28, drn:4, dummy2; };
   } fpscr;
 
   /* On Power6, read the fpscr into a double union using mffs

Added: libdfp/trunk/tests/test-round.c
==============================================================================
--- libdfp/trunk/tests/test-round.c (added)
+++ libdfp/trunk/tests/test-round.c Fri Jul 30 07:28:05 2010
@@ -1,0 +1,76 @@
+/* Test fe_dec_getround() and fe_dec_setround()
+
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This file is part of the Decimal Floating Point C Library.
+
+   Author(s): Ryan S. Arnold <rsa@xxxxxxxxxx>
+
+   The Decimal Floating Point C Library is free software; you can
+   redistribute it and/or modify it under the terms of the GNU Lesser
+   General Public License version 2.1.
+
+   The Decimal Floating Point C Library is distributed in the hope that
+   it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+   the GNU Lesser General Public License version 2.1 for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License version 2.1 along with the Decimal Floating Point C Library;
+   if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+   Suite 330, Boston, MA 02111-1307 USA.
+
+   Please see libdfp/COPYING.txt for more information.  */
+
+#ifndef __STDC_WANT_DEC_FP__
+#define __STDC_WANT_DEC_FP__
+#endif
+
+#include <float.h> /* DEC_NAN definition.  */
+#include <stdio.h>
+#include <math.h>
+#include <fenv.h>
+
+#define _WANT_VC 1 /* Pick up the _VC_P(x,y,fmt) macro.  */
+#include "scaffold.c" /* Pick up the _VC_P(x,y,fmt) macro.  */
+
+/* Inspired by GLIBC stdio-common/tfformat.c  */
+typedef struct{
+  int line;
+  int set;     /* Set it to this.  */
+  int expect;  /* Result should be this.  */
+  const char *format; /* printf %d */
+} d_type;
+
+d_type printf_rms[] =
+{
+  {__LINE__, FE_DEC_TONEAREST, FE_DEC_TONEAREST,  "%d"},
+  {__LINE__, FE_DEC_TOWARDZERO, FE_DEC_TOWARDZERO,  "%d"},
+  {__LINE__, FE_DEC_UPWARD, FE_DEC_UPWARD,  "%d"},
+  {__LINE__, FE_DEC_DOWNWARD, FE_DEC_DOWNWARD,  "%d"},
+  {__LINE__, FE_DEC_TONEARESTFROMZERO, FE_DEC_TONEARESTFROMZERO,  "%d"},
+  {__LINE__, 5, 5, "%d"}, /* Non-spec hardware rounding mode.  */
+  {__LINE__, 6, 6, "%d"}, /* Non-spec hardware rounding mode.  */
+  {__LINE__, 7, 7, "%d"}, /* Non-spec hardware rounding mode.  */
+  {0,0,0,0 }
+};
+
+int main (void)
+{
+  d_type *dptr;
+
+  for (dptr = printf_rms; dptr->line; dptr++)
+    {
+      int retval;
+      fe_dec_setround(dptr->set);
+      retval = fe_dec_getround();
+      _VC_P(__FILE__,dptr->line, dptr->expect,retval,dptr->format);
+    }
+
+  _REPORT();
+
+  /* fail comes from scaffold.c  */
+  return fail;
+}
+
+