This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] clean up support for testing DFP rounding


Runtime support for decimal floating point includes undocumented support
for testing that software emulation of DFP can handle rounding modes
correctly.  This support is not intended to be used in applications,
which might use a different version of these functions compiled to use
rounding support from C library functions that support decimal float.

This patch cleans up the current testing support for DFP rounding, and
uses a new macro that's similar to the one used in soft-fp support.

Tested on powerpc64-linux with --enable-decimal-float.  OK for mainline?

2006-11-15  Janis Johnson  <janis187@us.ibm.com>

libdecnumber/
	* decRound.c: Move declarations to header file.
	* decRound.h: New.

gcc/
	* config/dfp-bit.h: Include decRound.h.
	(CONTEXT_ROUND): Delete.
	(DFP_INIT_ROUNDMODE): Define if not already defined.
	* config/dfp-bit.c (dfp_unary_op, dfp_binary_op, dfp_compare_op,
	DFP_TO_DFP, INT_TO_DFP, BFP_TO_DFP): Use DFP_INIT_ROUNDMODE.

Index: libdecnumber/decRound.c
===================================================================
--- libdecnumber/decRound.c	(revision 118865)
+++ libdecnumber/decRound.c	(working copy)
@@ -1,6 +1,7 @@
-/* Temporary support for a libc-like fp environment for decimal float.
-   Copyright (C) 2005 Free Software Foundation, Inc.
+/* Internal testing support for rounding for decimal float.
 
+   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+
    This file is part of GCC.
 
    GCC is free software; you can redistribute it and/or modify it
@@ -20,7 +21,11 @@
 
 #include "config.h"
 #include "decContext.h"
+#include "decRound.h"
 
+/* Internal, non-documented functions for testing libgcc functions.
+   This support is not sufficient for application use.  */
+
 #define FE_DEC_DOWNWARD 0
 #define FE_DEC_TONEAREST 1
 #define FE_DEC_TONEARESTFROMZERO 2
@@ -28,11 +33,6 @@
 #define FE_DEC_UPWARD 4
 #define FE_DEC_MAX 5
 
-extern void __dfp_set_round (int);
-extern int __dfp_get_round (void);
-extern enum rounding __decGetRound (void);
-
-/* FIXME: these should be in thread-local storage for runtime support.  */
 static enum rounding __dfp_rounding_mode = DEC_ROUND_HALF_EVEN;
 
 /* Set the decNumber rounding mode from the FE_DEC_* value in MODE.  */ 
Index: libdecnumber/decRound.h
===================================================================
--- libdecnumber/decRound.h	(revision 0)
+++ libdecnumber/decRound.h	(revision 0)
@@ -0,0 +1,26 @@
+/* Internal testing support for rounding for decimal float.
+
+   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   GCC 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 General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING.  If not, write to the Free
+   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.  */
+
+#define DFP_INIT_ROUNDMODE(A)  A = __decGetRound()
+
+extern void __dfp_set_round (int);
+extern int __dfp_get_round (void);
+extern enum rounding __decGetRound (void);
Index: gcc/config/dfp-bit.h
===================================================================
--- gcc/config/dfp-bit.h	(revision 118865)
+++ gcc/config/dfp-bit.h	(working copy)
@@ -30,6 +30,7 @@
 #ifndef _DFPBIT_H
 #define _DFPBIT_H
 
+#include "decRound.h"
 #include "tconfig.h"
 #include "coretypes.h"
 #include "tm.h"
@@ -114,9 +115,9 @@
 #define CONTEXT_INIT DEC_INIT_DECIMAL128
 #endif
 
-/* Define CONTEXT_ROUND to obtain the current decNumber rounding mode.  */
-extern enum rounding	__decGetRound (void);
-#define CONTEXT_ROUND	__decGetRound ()
+#ifndef DFP_INIT_ROUNDMODE
+#define DFP_INIT_ROUNDMODE(A) A = DEC_ROUND_HALF_EVEN
+#endif
 
 extern int __dfp_traps;
 #define CONTEXT_TRAPS	__dfp_traps
Index: gcc/config/dfp-bit.c
===================================================================
--- gcc/config/dfp-bit.c	(revision 118865)
+++ gcc/config/dfp-bit.c	(working copy)
@@ -81,7 +81,7 @@
   HOST_TO_IEEE (arg, &a);
 
   decContextDefault (&context, CONTEXT_INIT);
-  context.round = CONTEXT_ROUND;
+  DFP_INIT_ROUNDMODE (context.round);
 
   TO_INTERNAL (&a, &arg1);
 
@@ -110,7 +110,7 @@
   HOST_TO_IEEE (arg_b, &b);
 
   decContextDefault (&context, CONTEXT_INIT);
-  context.round = CONTEXT_ROUND;
+  DFP_INIT_ROUNDMODE (context.round);
 
   TO_INTERNAL (&a, &arg1);
   TO_INTERNAL (&b, &arg2);
@@ -140,7 +140,7 @@
   HOST_TO_IEEE (arg_b, &b);
 
   decContextDefault (&context, CONTEXT_INIT);
-  context.round = CONTEXT_ROUND;
+  DFP_INIT_ROUNDMODE (context.round);
 
   TO_INTERNAL (&a, &arg1);
   TO_INTERNAL (&b, &arg2);
@@ -374,7 +374,7 @@
   decContext context;
 
   decContextDefault (&context, CONTEXT_INIT);
-  context.round = CONTEXT_ROUND;
+  DFP_INIT_ROUNDMODE (context.round);
 
   HOST_TO_IEEE (f_from, &s_from);
   TO_INTERNAL (&s_from, &d);
@@ -462,7 +462,7 @@
   decContext context;
 
   decContextDefault (&context, CONTEXT_INIT);
-  context.round = CONTEXT_ROUND;
+  DFP_INIT_ROUNDMODE (context.round);
 
   /* Use a C library function to get a floating point string.  */
   sprintf (buf, INT_FMT ".0", CAST_FOR_FMT(i));
@@ -506,7 +506,7 @@
   decContext context;
 
   decContextDefault (&context, CONTEXT_INIT);
-  context.round = CONTEXT_ROUND;
+  DFP_INIT_ROUNDMODE (context.round);
 
   /* Use a C library function to write the floating point value to a string.  */
 #ifdef BFP_VIA_TYPE


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]