[PATCH] decimal float change for mixed-mode operations

Janis Johnson janis187@us.ibm.com
Thu Dec 22 21:05:00 GMT 2005


Initially the DFP support followed the specs in N1137, which specified
usual arithmetic conversions for operations between decimal float and
other types.  The latest draft, N1150, disallows operations in which one
operand is a decimal float type and another is a generic float or complex
type.  This patch implements the rule in N1150.

Bootstrapped and regtested on powerpc64-linux for trunk, where it has no
effect, and on the dfp-branch, where it behaves as expected.  OK for
trunk?  If so, I'll also check it in on the dfp-branch.

2005-12-22  Janis Johnson  <janis187@us.ibm.com>

	* c-typeck.c (c_common_type): Disallow operations between decimal
	float and various other types.
	* convert.c (convert_to_real): Don't short-circuit conversion for
	decimal float.

Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c	(revision 108920)
+++ gcc/c-typeck.c	(working copy)
@@ -583,6 +583,31 @@
   gcc_assert (code2 == VECTOR_TYPE || code2 == COMPLEX_TYPE
 	      || code2 == REAL_TYPE || code2 == INTEGER_TYPE);
 
+  /* When one operand is a decimal float type, the other operand cannot be
+     a generic float type or a complex type.  We also disallow vector types
+     here.  */
+  if ((DECIMAL_FLOAT_MODE_P (TYPE_MODE (TYPE_MAIN_VARIANT (t1)))
+       || DECIMAL_FLOAT_MODE_P (TYPE_MODE (TYPE_MAIN_VARIANT (t2))))
+      && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TYPE_MAIN_VARIANT (t1)))
+           && DECIMAL_FLOAT_MODE_P (TYPE_MODE (TYPE_MAIN_VARIANT (t2)))))
+    {
+      if (code1 == VECTOR_TYPE || code2 == VECTOR_TYPE)
+	{
+	  error ("can't mix operands of decimal float and vector types");
+	  return error_mark_node;
+	}
+      if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
+	{
+	  error ("can't mix operands of decimal float and complex types");
+	  return error_mark_node;
+	}
+      if (code1 == REAL_TYPE && code2 == REAL_TYPE)
+	{
+	  error ("can't mix operands of decimal float and other float types");
+          return error_mark_node;
+	}
+    }
+
   /* If one type is a vector type, return that type.  (How the usual
      arithmetic conversions apply to the vector types extension is not
      precisely specified.)  */
Index: gcc/convert.c
===================================================================
--- gcc/convert.c	(revision 108920)
+++ gcc/convert.c	(working copy)
@@ -307,8 +307,12 @@
   switch (TREE_CODE (TREE_TYPE (expr)))
     {
     case REAL_TYPE:
-      return build1 (flag_float_store ? CONVERT_EXPR : NOP_EXPR,
-		     type, expr);
+      /* Ignore the conversion if we don't need to store intermediate
+        results and if neither type is decimal float.  */
+      return build1 ((flag_float_store
+		      || DECIMAL_FLOAT_MODE_P (TYPE_MODE (type))
+		      || DECIMAL_FLOAT_MODE_P (TYPE_MODE (itype)))
+		     ? CONVERT_EXPR : NOP_EXPR, type, expr);
 
     case INTEGER_TYPE:
     case ENUMERAL_TYPE:



More information about the Gcc-patches mailing list