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] c++: mangle decimal float types


The vendor-neutral C++ ABI provides for mangling of decimal floating
point types.  Those types are available in G++ through the use of
__attribute__((mode(DD))) and friends, which I plan to use to support
decimal classes as defined in ISO/IEC TR 24733, "extension for the
programming language C++ to support decimal floating-point arithmetic."

This patch adds support for the decimal float modes for C++ mangling
and adds a test for it.  The new tests required adding support for C++
decimal float tests.

Tested with full bootstrap and regtest with -m32/-m64 on powerpc64-linux
and with simple build of C and C++ and running dfp.exp tests on
i686-linux.

OK for trunk?

2009-09-16  Janis Johnson  <janis187@us.ibm.com>

gcc/cp/
	* mangle.c (write_builtin_type): Support decimal float types.

gcc/testsuite/
	* g++.dg/dfp: New directory.
	* g++.dg/dg.exp: Prune tests in dfp directory.
	* g++.dg/dfp/dfp/exp: New.
	* g++.dg/dfp/mangle-mode.C: New test.

Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 151731)
+++ gcc/cp/mangle.c	(working copy)
@@ -1894,6 +1894,12 @@ write_builtin_type (tree type)
 	write_char ('d');
       else if (type == long_double_type_node)
 	write_char ('e');
+      else if (type == dfloat32_type_node)
+	write_string ("Df");
+      else if (type == dfloat64_type_node)
+	write_string ("Dd");
+      else if (type == dfloat128_type_node)
+	write_string ("De");
       else
 	gcc_unreachable ();
       break;
Index: gcc/testsuite/g++.dg/dg.exp
===================================================================
--- gcc/testsuite/g++.dg/dg.exp	(revision 151731)
+++ gcc/testsuite/g++.dg/dg.exp	(working copy)
@@ -35,6 +35,7 @@ set tests [prune $tests $srcdir/$subdir/
 set tests [prune $tests $srcdir/$subdir/charset/*]
 set tests [prune $tests $srcdir/$subdir/compat/*]
 set tests [prune $tests $srcdir/$subdir/debug/*]
+set tests [prune $tests $srcdir/$subdir/dfp/*]
 set tests [prune $tests $srcdir/$subdir/gcov/*]
 set tests [prune $tests $srcdir/$subdir/pch/*]
 set tests [prune $tests $srcdir/$subdir/plugin/*]
Index: gcc/testsuite/g++.dg/dfp/dfp.exp
===================================================================
--- gcc/testsuite/g++.dg/dfp/dfp.exp	(revision 0)
+++ gcc/testsuite/g++.dg/dfp/dfp.exp	(revision 0)
@@ -0,0 +1,62 @@
+# Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
+
+# This program 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 3 of the License, or
+# (at your option) any later version.
+# 
+# This program 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 COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Load support procs.
+load_lib g++-dg.exp
+
+# Skip these tests for targets that don't support this extension.
+if { ![check_effective_target_dfp] } {
+    return;
+}
+
+# If the decimal float is supported in the compiler but not yet in the
+# runtime, treat all tests as compile-only.
+global dg-do-what-default
+set save-dg-do-what-default ${dg-do-what-default}
+if { ![check_effective_target_dfprt] } {
+    verbose "dfp.exp: runtime support for decimal float does not exist" 2
+    set dg-do-what-default compile
+} else {
+    verbose "dfp.exp: runtime support for decimal float exists, use it" 2
+    set dg-do-what-default run
+}
+verbose "dfp.exp: dg-do-what-default is ${dg-do-what-default}" 2
+
+global DEFAULT_CXXFLAGS
+if [info exists DEFAULT_CXXFLAGS] then {
+  set save_default_cxxflags DEFAULT_CXXFLAGS
+}
+
+# If a testcase doesn't have special options, use these.
+set DEFAULT_CXXFLAGS ""
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[C]] \
+        "" $DEFAULT_CXXFLAGS
+
+# All done.
+dg-finish
+
+set dg-do-what-default ${save-dg-do-what-default}
+verbose "dfp.exp: dg-do-what-default is ${dg-do-what-default}" 2
+if [info exists save_default_cxxflags] {
+  set DEFAULT_CXXFLAGS $save_default_cxxflags
+}
Index: gcc/testsuite/g++.dg/dfp/mangle-mode.C
===================================================================
--- gcc/testsuite/g++.dg/dfp/mangle-mode.C	(revision 0)
+++ gcc/testsuite/g++.dg/dfp/mangle-mode.C	(revision 0)
@@ -0,0 +1,37 @@
+// { dg-do compile }
+
+// Check that the compiler mangles types defined with decimal float
+// modes according to the vendor-neutral C++ ABI.
+
+typedef float _Decimal32 __attribute__((mode(SD)));
+typedef float _Decimal64 __attribute__((mode(DD)));
+typedef float _Decimal128 __attribute__((mode(TD)));
+
+extern void foo32 (_Decimal32 a, _Decimal32 &b, _Decimal32 *c);
+extern void foo64 (_Decimal64 *a, _Decimal64 b, _Decimal64 &c);
+extern void foo128 (_Decimal128 &a, _Decimal128 *b, _Decimal128 c);
+
+void
+bar32 (void)
+{
+  _Decimal32 x, y, z;
+  foo32 (x, y, &z);
+}
+
+void
+bar64 (void)
+{
+  _Decimal64 x, y, z;
+  foo64 (&x, y, z);
+}
+
+void
+bar128 (void)
+{
+  _Decimal128 x, y, z;
+  foo128 (x, &y, z);
+}
+
+// { dg-final { scan-assembler "Z5foo32DfRDfPDf" } }
+// { dg-final { scan-assembler "Z5foo64PDdDdRDd" } }
+// { dg-final { scan-assembler "Z6foo128RDePDeDe" } }



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