Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch 3/4] decimal floating point support for expressions
  2007-09-20 21:57 [patch 0/4] decimal floating point support Thiago Jung Bauermann
@ 2007-09-20 21:57 ` Thiago Jung Bauermann
  2007-10-11 16:18   ` Daniel Jacobowitz
  2007-09-20 21:57 ` [patch 4/4] decimal floating point testcases Thiago Jung Bauermann
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-09-20 21:57 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: expressions.diff --]
[-- Type: text/plain, Size: 9275 bytes --]

2007-09-20  Wu Zhou  <woodzltc@cn.ibm.com> 
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* c-exp.y (YYSTYPE): Add typed_val_decfloat for decimal
	floating point in YYSTYPE union.
	(DECFLOAT) Add token and expression element handling code.
	(parse_number): Parse DFP constants, which end with suffix 'df',
	'dd' or 'dl'.  Return DECFLOAT.
	* eval.c (evaluate_subexp_standard): Call value_from_decfloat to
	handle OP_DECFLOAT.
	* expression.h (enum exp_opcode): Add an opcode (OP_DECFLOAT)
	for DFP constants.
	(union exp_element): Add decfloatconst to represent DFP
	elements, which is 16 bytes by default.
	* parse.c (write_exp_elt_decfloatcst): New function to write a
	decimal float const into the expression.
	(operator_length_standard): Set operator length for OP_DECFLOAT
	to 4.
	* parser-defs.h (write_exp_elt_decfloatcst): Prototype.
	* valarith.c (value_neg): Add code to handle the negation
	operation of DFP values.
	* value.c (value_from_decfloat): New function to get the value
	from a decimal floating point.
	* value.h (value_from_decfloat): Prototype.

Index: gdb/c-exp.y
===================================================================
--- gdb/c-exp.y.orig	2007-09-18 02:41:10.000000000 -0300
+++ gdb/c-exp.y	2007-09-18 02:50:11.000000000 -0300
@@ -52,6 +52,7 @@ Boston, MA 02110-1301, USA.  */
 #include "charset.h"
 #include "block.h"
 #include "cp-support.h"
+#include "dfp.h"
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
@@ -130,6 +131,10 @@ void yyerror (char *);
       DOUBLEST dval;
       struct type *type;
     } typed_val_float;
+    struct {
+      gdb_byte val[16];
+      struct type *type;
+    } typed_val_decfloat;
     struct symbol *sym;
     struct type *tval;
     struct stoken sval;
@@ -162,6 +167,7 @@ static int parse_number (char *, int, in
 
 %token <typed_val_int> INT
 %token <typed_val_float> FLOAT
+%token <typed_val_decfloat> DECFLOAT
 
 /* Both NAME and TYPENAME tokens represent symbols in the input,
    and both convey their data as strings.
@@ -496,6 +502,13 @@ exp	:	FLOAT
 			  write_exp_elt_opcode (OP_DOUBLE); }
 	;
 
+exp	:	DECFLOAT
+			{ write_exp_elt_opcode (OP_DECFLOAT);
+			  write_exp_elt_type ($1.type);
+			  write_exp_elt_decfloatcst ($1.val);
+			  write_exp_elt_opcode (OP_DECFLOAT); }
+	;
+
 exp	:	variable
 	;
 
@@ -1077,6 +1090,40 @@ parse_number (p, len, parsed_float, puti
       char saved_char = p[len];
 
       p[len] = 0;	/* null-terminate the token */
+
+      /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
+         point.  Return DECFLOAT.  */
+
+      if (p[len - 2] == 'd' && p[len - 1] == 'f')
+	{
+	  p[len - 2] = '\0';
+	  putithere->typed_val_decfloat.type =
+	    builtin_type (current_gdbarch)->builtin_decfloat;
+	  decimal_from_string (putithere->typed_val_decfloat.val, 4, p);
+	  p[len] = saved_char;
+	  return (DECFLOAT);
+	}
+
+      if (p[len - 2] == 'd' && p[len - 1] == 'd')
+	{
+	  p[len - 2] = '\0';
+	  putithere->typed_val_decfloat.type =
+	    builtin_type (current_gdbarch)->builtin_decdouble;
+	  decimal_from_string (putithere->typed_val_decfloat.val, 8, p);
+	  p[len] = saved_char;
+	  return (DECFLOAT);
+	}
+
+      if (p[len - 2] == 'd' && p[len - 1] == 'l')
+	{
+	  p[len - 2] = '\0';
+	  putithere->typed_val_decfloat.type =
+	    builtin_type (current_gdbarch)->builtin_declong;
+	  decimal_from_string (putithere->typed_val_decfloat.val, 16, p);
+	  p[len] = saved_char;
+	  return (DECFLOAT);
+	}
+
       num = sscanf (p, DOUBLEST_SCAN_FORMAT "%s",
 		    &putithere->typed_val_float.dval, s);
       p[len] = saved_char;	/* restore the input stream */
Index: gdb/eval.c
===================================================================
--- gdb/eval.c.orig	2007-09-18 02:41:11.000000000 -0300
+++ gdb/eval.c	2007-09-18 02:50:11.000000000 -0300
@@ -456,6 +456,11 @@ evaluate_subexp_standard (struct type *e
       return value_from_double (exp->elts[pc + 1].type,
 				exp->elts[pc + 2].doubleconst);
 
+    case OP_DECFLOAT:
+      (*pos) += 3;
+      return value_from_decfloat (expect_type, exp->elts[pc + 1].type,
+				exp->elts[pc + 2].decfloatconst);
+
     case OP_VAR_VALUE:
       (*pos) += 3;
       if (noside == EVAL_SKIP)
Index: gdb/expression.h
===================================================================
--- gdb/expression.h.orig	2007-09-18 02:41:11.000000000 -0300
+++ gdb/expression.h	2007-09-18 02:50:11.000000000 -0300
@@ -328,6 +328,11 @@ enum exp_opcode
     /* A F90 array range operator (for "exp:exp", "exp:", ":exp" and ":").  */
     OP_F90_RANGE,
 
+    /* OP_DECFLOAT is followed by a type pointer in the next exp_element
+       and a dec long constant value in the following exp_element.
+       Then comes another OP_DECFLOAT.  */
+    OP_DECFLOAT,
+
      /* First extension operator.  Individual language modules define
         extra operators they need as constants with values 
         OP_LANGUAGE_SPECIFIC0 + k, for k >= 0, using a separate 
@@ -355,6 +360,7 @@ union exp_element
     struct symbol *symbol;
     LONGEST longconst;
     DOUBLEST doubleconst;
+    gdb_byte decfloatconst[16];
     /* Really sizeof (union exp_element) characters (or less for the last
        element of a string).  */
     char string;
Index: gdb/parse.c
===================================================================
--- gdb/parse.c.orig	2007-09-18 02:41:11.000000000 -0300
+++ gdb/parse.c	2007-09-18 02:50:11.000000000 -0300
@@ -248,6 +248,18 @@ write_exp_elt_dblcst (DOUBLEST expelt)
 }
 
 void
+write_exp_elt_decfloatcst (gdb_byte expelt[16])
+{
+  union exp_element tmp;
+  int index;
+
+  for (index = 0; index < 16; index++)
+    tmp.decfloatconst[index] = expelt[index];
+
+  write_exp_elt (tmp);
+}
+
+void
 write_exp_elt_type (struct type *expelt)
 {
   union exp_element tmp;
@@ -706,6 +718,7 @@ operator_length_standard (struct express
 
     case OP_LONG:
     case OP_DOUBLE:
+    case OP_DECFLOAT:
     case OP_VAR_VALUE:
       oplen = 4;
       break;
Index: gdb/parser-defs.h
===================================================================
--- gdb/parser-defs.h.orig	2007-09-18 02:41:11.000000000 -0300
+++ gdb/parser-defs.h	2007-09-18 02:50:11.000000000 -0300
@@ -119,6 +119,8 @@ extern void write_exp_elt_longcst (LONGE
 
 extern void write_exp_elt_dblcst (DOUBLEST);
 
+extern void write_exp_elt_decfloatcst (gdb_byte *);
+
 extern void write_exp_elt_type (struct type *);
 
 extern void write_exp_elt_intern (struct internalvar *);
Index: gdb/valarith.c
===================================================================
--- gdb/valarith.c.orig	2007-09-18 02:41:16.000000000 -0300
+++ gdb/valarith.c	2007-09-18 02:50:11.000000000 -0300
@@ -1376,6 +1376,20 @@ value_neg (struct value *arg1)
 
   type = check_typedef (value_type (arg1));
 
+  if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
+    {
+      struct value *val = allocate_value (result_type);
+      int len = TYPE_LENGTH (type);
+      gdb_byte *decbytes = (gdb_byte *) value_contents (arg1);
+
+      if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_LITTLE)
+	decbytes[len-1] = decbytes[len - 1] | 0x80;
+      else
+	decbytes[0] = decbytes[0] | 0x80;
+      memcpy (value_contents_raw (val), decbytes, 16);
+      return val;
+    }
+
   if (TYPE_CODE (type) == TYPE_CODE_FLT)
     return value_from_double (result_type, -value_as_double (arg1));
   else if (is_integral_type (type))
Index: gdb/value.c
===================================================================
--- gdb/value.c.orig	2007-09-18 02:41:16.000000000 -0300
+++ gdb/value.c	2007-09-18 02:50:11.000000000 -0300
@@ -34,6 +34,7 @@
 #include "gdb_assert.h"
 #include "regcache.h"
 #include "block.h"
+#include "dfp.h"
 
 /* Prototypes for exported functions. */
 
@@ -1612,6 +1613,27 @@ value_from_double (struct type *type, DO
 }
 
 struct value *
+value_from_decfloat (struct type *expect_type, struct type *type,
+		      gdb_byte decbytes[16])
+{
+  struct value *val = allocate_value (type);
+  int len = TYPE_LENGTH (type);
+
+  if (expect_type)
+    {
+      int expect_len = TYPE_LENGTH (expect_type);
+      char decstr[128];
+      int real_len;
+
+      decimal_to_string (decbytes, len, decstr);
+      decimal_from_string (decbytes, expect_len, decstr);
+    }
+
+  memcpy (value_contents_raw (val), decbytes, len);
+  return val;
+}
+
+struct value *
 coerce_ref (struct value *arg)
 {
   struct type *value_type_arg_tmp = check_typedef (value_type (arg));
Index: gdb/value.h
===================================================================
--- gdb/value.h.orig	2007-09-18 02:44:26.000000000 -0300
+++ gdb/value.h	2007-09-18 02:50:11.000000000 -0300
@@ -280,6 +280,9 @@ extern void pack_long (gdb_byte *buf, st
 extern struct value *value_from_longest (struct type *type, LONGEST num);
 extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
 extern struct value *value_from_double (struct type *type, DOUBLEST num);
+extern struct value *value_from_decfloat (struct type *expect_type,
+					  struct type *type,
+					  gdb_byte decbytes[16]);
 extern struct value *value_from_string (char *string);
 
 extern struct value *value_at (struct type *type, CORE_ADDR addr);

-- 


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [patch 0/4] decimal floating point support
@ 2007-09-20 21:57 Thiago Jung Bauermann
  2007-09-20 21:57 ` [patch 3/4] decimal floating point support for expressions Thiago Jung Bauermann
                   ` (3 more replies)
  0 siblings, 4 replies; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-09-20 21:57 UTC (permalink / raw)
  To: gdb-patches

:ADDPATCH language-feature:

Hi folks,

This is a continuation of the Decimal Floating Point support saga. :-)

It works with binaries generated by GCC 4.2.0 (which has software DFP
support) and also binaries using hardware DFP as found in POWER6
processors.

I refreshed for today's CVS HEAD the DFP patches I submitted previously
here:

http://sourceware.org/ml/gdb-patches/2007-03/msg00247.html

Please see the link above for more detailed discussion and references. 

The main change from the previous patch series is in the dfp.c file,
which interfaces with libdecnumber. The reason is that libdecnumber in
gcc's svn trunk was updated to version 3.53, bringing some changes with
it. 

Some .h files changed location, but more importantly the library now
stores decimal floats in host byte order. In previous versions,
libdecnumber always stored them in big endian, regardless of the host
byte order. The function match_endianness in dfp.c takes care of fixing
byte order before/after calling libdecnumber functions (decimal floats
are stored in target byte order in GDB data structures).

I also tidied up some minor things like fixing one or two ChangeLog
entries and updating copyright year in testcase files. When refreshing,
there were two rejects in gdbtypes because of the Great Builtin-Types
Reorganization that took place, but they were trivial to fix.

These patches have been tested on ppc32-linux, ppc64-linux and with
remote debugging using i386 host and ppc32 target (to test endianness
handling). I also checked that there are no regressions both in ppc32
and ppc64.

Is this ok for CVS HEAD?
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [patch 4/4] decimal floating point testcases
  2007-09-20 21:57 [patch 0/4] decimal floating point support Thiago Jung Bauermann
  2007-09-20 21:57 ` [patch 3/4] decimal floating point support for expressions Thiago Jung Bauermann
@ 2007-09-20 21:57 ` Thiago Jung Bauermann
  2007-10-11 16:19   ` Daniel Jacobowitz
  2007-09-20 21:57 ` [patch 1/4] libdecnumber support Thiago Jung Bauermann
  2007-09-20 21:57 ` [patch 2/4] decimal floating point types Thiago Jung Bauermann
  3 siblings, 1 reply; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-09-20 21:57 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: testcases.diff --]
[-- Type: text/plain, Size: 18451 bytes --]

The dfp-test.exp testcase needs a gcc with DPF support installed.
For instance, gcc >= 4.2.0.

-- 

2007-09-20  Wu Zhou  <woodzltc@cn.ibm.com> 
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* gdb.base/dfp-exprs.exp: new file adding tests for Decimal
	Floating Point expressions.
	* gdb.base/dfp-test.exp: new file adding tests for Decimal
	Floating Point variables.
	* gdb.base/dfp-test.c: new file containing program with Decimal
	Floating variables, used by gdb.base/dfp-test.exp.

Index: gdb/testsuite/gdb.base/dfp-exprs.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb/testsuite/gdb.base/dfp-exprs.exp	2007-09-20 16:13:53.000000000 -0300
@@ -0,0 +1,95 @@
+# Copyright (C) 2007 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 2 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# This file was written by Wu Zhou. (woodzltc@cn.ibm.com)
+
+# This file is part of the gdb testsuite.  It contains test for evaluating
+# simple decimal floating point (DFP) expression.
+
+if $tracelevel then {
+	strace $tracelevel
+}
+
+proc test_dfp_literals_accepted {} {
+
+    # Test various dfp values, covering 32-bit, 64-bit and 128-bit ones
+
+    # _Decimal32 constants, which can support up to 7 digits
+    gdb_test "p 1.2df" " = 1.2"
+    gdb_test "p -1.2df" " = -1.2"
+    gdb_test "p 1.234567df" " = 1.234567"
+    gdb_test "p -1.234567df" " = -1.234567"
+    gdb_test "p 1234567.df" " = 1234567"
+    gdb_test "p -1234567.df" " = -1234567"
+
+    gdb_test "p 1.2E1df" " = 12"
+    gdb_test "p 1.2E10df" " = 1.2E\\+10"
+    gdb_test "p 1.2E-10df" " = 1.2E-10"
+
+    # The largest exponent for 32-bit dfp value is 96.
+    gdb_test "p 1.2E96df" " = 1.200000E\\+96"
+
+    # _Decimal64 constants, which can support up to 16 digits
+    gdb_test "p 1.2dd" " = 1.2"
+    gdb_test "p -1.2dd" " = -1.2"
+    gdb_test "p 1.234567890123456dd" " = 1.234567890123456"
+    gdb_test "p -1.234567890123456dd" " = -1.234567890123456"
+    gdb_test "p 1234567890123456.dd" " = 1234567890123456"
+    gdb_test "p -1234567890123456.dd" " = -1234567890123456"
+
+    gdb_test "p 1.2E1dd" " = 12"
+    gdb_test "p 1.2E10dd" " = 1.2E\\+10"
+    gdb_test "p 1.2E-10dd" " = 1.2E-10"
+
+    # The largest exponent for 64-bit dfp value is 384.
+    gdb_test "p 1.2E384dd" " = 1.200000000000000E\\+384"
+
+    # _Decimal128 constants, which can support up to 34 digits
+    gdb_test "p 1.2dl" " = 1.2"
+    gdb_test "p -1.2dl" " = -1.2"
+    gdb_test "p 1.234567890123456789012345678901234dl" " = 1.234567890123456789012345678901234"
+    gdb_test "p -1.234567890123456789012345678901234dl" " = -1.234567890123456789012345678901234"
+    gdb_test "p 1234567890123456789012345678901234.dl" " = 1234567890123456789012345678901234"
+    gdb_test "p -1234567890123456789012345678901234.dl" " = -1234567890123456789012345678901234"
+
+    gdb_test "p 1.2E1dl" " = 12"
+    gdb_test "p 1.2E10dl" " = 1.2E\\+10"
+    gdb_test "p 1.2E-10dl" " = 1.2E-10"
+
+    # The largest exponent for 128-bit dfp value is 6144.
+    gdb_test "p 1.2E6144dl" " = 1.200000000000000000000000000000000E\\+6144"
+}
+
+proc test_dfp_arithmetic_expressions {} {
+
+# Arithmetic operations for DFP types are not yet implemented in GDB.
+# These tests are to verify that they will generate expected error messages.
+
+   gdb_test "p 1.4df + 1.2df" "Argument to arithmetic operation not a number or boolean.*"
+   gdb_test "p 1.4df - 1.2df" ".*Argument to arithmetic operation not a number or boolean.*"
+   gdb_test "p 1.4df * 1.2df" "Argument to arithmetic operation not a number or boolean.*"
+   gdb_test "p 1.4df / 1.2df" "Argument to arithmetic operation not a number or boolean.*"
+
+}
+
+# Start with a fresh gdb.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+test_dfp_literals_accepted
+test_dfp_arithmetic_expressions
Index: gdb/testsuite/gdb.base/dfp-test.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb/testsuite/gdb.base/dfp-test.c	2007-09-20 14:40:05.000000000 -0300
@@ -0,0 +1,95 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2006 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 2 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 this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+volatile _Decimal32 d32;
+volatile _Decimal64 d64;
+volatile _Decimal128 d128;
+
+struct decstruct
+{
+  int int4;
+  long long8;
+  _Decimal32 dec32;
+  _Decimal64 dec64;
+  _Decimal128 dec128;
+} ds;
+
+static _Decimal32
+arg0_32 (_Decimal32 arg0, _Decimal32 arg1, _Decimal32 arg2,
+         _Decimal32 arg3, _Decimal32 arg4, _Decimal32 arg5)
+{
+  return arg0;
+}
+
+static _Decimal64
+arg0_64 (_Decimal64 arg0, _Decimal64 arg1, _Decimal64 arg2,
+         _Decimal64 arg3, _Decimal64 arg4, _Decimal64 arg5)
+{
+  return arg0;
+}
+
+static _Decimal128
+arg0_128 (_Decimal128 arg0, _Decimal128 arg1, _Decimal128 arg2,
+         _Decimal128 arg3, _Decimal128 arg4, _Decimal128 arg5)
+{
+  return arg0;
+}
+
+int main()
+{
+  /* An finite 32-bits decimal floating point.  */
+  d32 = 1.2345df;		/* Initialize d32.  */
+
+  /* Non-finite 32-bits decimal floating point: infinity and NaN.  */
+  d32 = __builtin_infd32();	/* Positive infd32.  */
+  d32 = -__builtin_infd32();	/* Negative infd32.  */
+  d32 = __builtin_nand32("");
+
+  /* An finite 64-bits decimal floating point.  */
+  d64 = 1.2345dd;		/* Initialize d64.  */
+
+  /* Non-finite 64-bits decimal floating point: infinity and NaN.  */
+  d64 = __builtin_infd64();	/* Positive infd64.  */
+  d64 = -__builtin_infd64();	/* Negative infd64.  */
+  d64 = __builtin_nand64("");
+
+  /* An finite 128-bits decimal floating point.  */
+  d128 = 1.2345dl;		/* Initialize d128.  */
+
+  /* Non-finite 128-bits decimal floating point: infinity and NaN.  */
+  d128 = __builtin_infd128();	/* Positive infd128.  */
+  d128 = -__builtin_infd128();	/* Negative infd128.  */
+  d128 = __builtin_nand128("");
+
+  /* Functions with decimal floating point as parameter and return value. */
+  d32 = arg0_32 (0.1df, 1.0df, 2.0df, 3.0df, 4.0df, 5.0df);
+  d64 = arg0_64 (0.1dd, 1.0dd, 2.0dd, 3.0dd, 4.0dd, 5.0dd);
+  d128 = arg0_128 (0.1dl, 1.0dl, 2.0dl, 3.0dl, 4.0dl, 5.0dl);
+
+  ds.int4 = 1;
+  ds.long8 = 2;
+  ds.dec32 = 1.2345df;
+  ds.dec64 = 1.2345dd;
+  ds.dec128 = 1.2345dl;
+
+  return 0;	/* Exit point.  */
+}
Index: gdb/testsuite/gdb.base/dfp-test.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb/testsuite/gdb.base/dfp-test.exp	2007-09-20 16:14:01.000000000 -0300
@@ -0,0 +1,247 @@
+# Copyright 2007 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 2 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#  This file was written by Wu Zhou. (woodzltc@cn.ibm.com)
+
+# This file is part of the gdb testsuite.  It is intended to test that
+# gdb could correctly hane decimal floating point introduced in IEEE 754R.
+
+proc d32_set_tests {} {
+
+    gdb_test "p d32=123.45df" " = 123.45"
+    gdb_test "p d32=12345.df" " = 12345"
+    gdb_test "p d32=12345.67df" " = 12345.67"
+    gdb_test "p d32=1234567.df" " = 1234567"
+
+    gdb_test "p d32=1.234567E0df" " = 1.234567"
+    gdb_test "p d32=1.234567E10df" " = 1.234567E\\+10"
+    gdb_test "p d32=1.234567E+96df" " = 1.234567E\\+96"
+
+    # Test that gdb could handle the max, normalized min and subnormalized min.
+    gdb_test "p d32=9.999999E96df" " = 9.999999E\\+96"
+    gdb_test "p d32=1.0E-95df" " = 1.0E\\-95"
+    gdb_test "p d32=1.E-101df" " = 1E\\-101"
+    gdb_test "p d32=0.000001E-95df" " = 1E\\-101"
+
+    # Test that gdb could detect coefficient/exponent out of range.
+    # The coefficient out of range will be rounded to its nearest value.
+    # And the exponent out of range will be handled as infinity.
+    gdb_test "p d32=1.2345678df" " = 1.234568" "1.2345678 is rounded to 1.234568"
+    gdb_test "p d32=1.0E-101df" " = 1E-101" "1.0E-101 is rounded to 1E-101"
+    gdb_test "p d32=1.234567E+97df" " = Infinity" "1.234567E+97 is Infinity"
+
+    # Test that gdb could detect the errors in the string representation of _Decimal32
+    gdb_test "p d32=12345.df" " = 12345" "12345. is an valid number"
+    gdb_test "p d32=12345df" ".*Invalid number.*" "12345 is an invalid number"
+    gdb_test "p d32=1.23Edf" " = NaN" "1.23E is NaN (not a number)"
+    gdb_test "p d32=1.23E45Adf" " = NaN" "1.23E45A is NaN (not a number)"
+}
+
+proc d64_set_tests {} {
+
+    gdb_test "p d64=123.45dd" " = 123.45"
+    gdb_test "p d64=12345.dd" " = 12345"
+    gdb_test "p d64=12345.67dd" " = 12345.67"
+    gdb_test "p d64=1.234567890123456dd" " = 1.234567890123456"
+
+    gdb_test "p d64=1.234567890123456E10dd" " = 12345678901.23456"
+    gdb_test "p d64=1.234567890123456E100dd" " = 1.234567890123456E\\+100"
+    gdb_test "p d64=1.234567890123456E384dd" " = 1.234567890123456E\\+384"
+
+    # Test that gdb could handle the max, normalized min and subnormalized min.
+    gdb_test "p d64=9.999999999999999E384dd" " = 9.999999999999999E\\+384"
+    gdb_test "p d64=1.E-383dd" " = 1E\\-383"
+    gdb_test "p d64=1.E-398dd" " = 1E\\-398"
+    gdb_test "p d64=0.000000000000001E-383dd" " = 1E\\-398"
+
+    # Test that gdb could detect coefficient/exponent out of range.
+    # The coefficient out of range will be rounded to its nearest value.
+    # And the exponent out of range will be handled as infinity.
+    gdb_test "p d64=1.2345678901234567dd" " = 1.234567890123457" "1.2345678901234567 is rounded to 1.234567890123457"
+    gdb_test "p d64=9.9999999999999999E384dd" " = Infinity" "d64=9.9999999999999999E384 is Infinity"
+    gdb_test "p d64=1.234567890123456E385dd" " = Infinity" "d64=1.234567890123456E385 is Infinity"
+
+    # Test that gdb could detect the errors in the string representation of _Decimal64
+    gdb_test "p d64=12345dd" ".*Invalid number.*" "12345dd is an invalid number"
+    gdb_test "p d64=1.23Edd" " = NaN" "1.23E is NaN (not a number)"
+    gdb_test "p d64=1.23E45Add" "= NaN" "1.23E45A is NaN (not a number)"
+}
+
+proc d128_set_tests {} {
+
+    gdb_test "p d128=123.45dl" " = 123.45"
+    gdb_test "p d128=12345.dl" " = 12345"
+    gdb_test "p d128=12345.67dl" " = 12345.67"
+    gdb_test "p d128=1.234567890123456789012345678901234dl" " = 1.234567890123456789012345678901234"
+
+    gdb_test "p d128=1.234567890123456E10dl" " = 12345678901.23456"
+    gdb_test "p d128=1.234567890123456E100dl" " = 1.234567890123456E\\+100"
+    gdb_test "p d128=1.234567890123456E1000dl" " = 1.234567890123456E\\+1000"
+
+    # Test that gdb could handle the max, normalized min and subnormalized min.
+    gdb_test "p d128=9.999999999999999999999999999999999E6144dl" " = 9.999999999999999999999999999999999E\\+6144"
+    gdb_test "p d128=1.E-6143dl" " = 1E\\-6143"
+    gdb_test "p d128=1.E-6176dl" " = 1E\\-6176"
+    gdb_test "p d128=0.000000000000000000000000000000001E-6143dl" " = 1E\\-6176"
+
+    # Test that gdb could detect coefficient/exponent out of range.
+    # The coefficient out of range will be rounded to its nearest value.
+    # And the exponent out of range will be handled as infinity.
+    gdb_test "p d128=1.2345678901234567890123456789012345dl" "1.234567890123456789012345678901234" "1.2345678901234567890123456789012345 is rounded to 1.234567890123456789012345678901234"
+    gdb_test "p d128=1.234567890123456E6145dl" "Infinity" "d128=1.234567890123456E6145 is Infinity"
+
+    # Test that gdb could detect the errors in the string representation of _Decimal128
+    gdb_test "p d128=12345dl" ".*Invalid number.*" "12345dl is an invalid number"
+    gdb_test "p d128=1.23Edl" " = NaN" "1.23E is NaN (not a number)"
+    gdb_test "p d128=1.23E45Adl" "= NaN" "1.23E45A is NaN (not a number)"
+}
+
+
+if $tracelevel {
+    strace $tracelevel
+}
+
+set testfile "dfp-test"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug"] != "" } {
+    untested "Couldn't compile ${srcfile}"
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+if ![runto_main] then {
+    perror "couldn't run to breakpoint"
+    continue
+}
+
+# Different tests on 32-bits decimal floating point, including the printing
+# of finite numbers, infinite and NaN, and also the setting of different
+# decimal value.
+
+if [gdb_test "next" \
+    ".*Positive infd32.*" \
+    "next after initializing d32"] then { gdb_suppress_tests }
+gdb_test "print d32" "1.2345" "d32 is initialized to 1.2345"
+
+if [gdb_test "next" \
+    ".*Negative infd32.*" \
+    "next after assigning builtin infinity to d32"] then { gdb_suppress_tests }
+gdb_test "print d32" "Infinity" "d32 is positive Infinity"
+
+if [gdb_test "next" \
+    ".*__builtin_nand32.*" \
+    "next after assigning negative builtin infinity to d32"] then { gdb_suppress_tests }
+gdb_test "print d32" "-Infinity" "d32 is negative Infinity"
+
+if [gdb_test "next" \
+    ".*d64 = 1.2345.*" \
+    "next after assigning builtin NaN to d32"] then { gdb_suppress_tests }
+gdb_test "print d32" "NaN" "d32 is NaN"
+
+d32_set_tests
+
+
+# Different tests on 64-bits decimal floating point, including the display
+# of finite number, infinite and NaN, and also the setting of different
+# decimal value.
+
+if [gdb_test "next" \
+    ".*Positive infd64.*" \
+    "next after initializing d64"] then { gdb_suppress_tests }
+gdb_test "print d64" "1.2345" "d64 is initialized to 1.2345"
+
+if [gdb_test "next" \
+    ".*Negative infd64.*" \
+    "next after assigning builtin infinity to d64"] then { gdb_suppress_tests }
+gdb_test "print d64" "Infinity" "d64 is positive Infinity"
+
+if [gdb_test "next" \
+    ".*__builtin_nand64.*" \
+    "next after assigning negative builtin infinity to d64"] then { gdb_suppress_tests }
+gdb_test "print d64" "-Infinity" "d64 is negative Infinity"
+
+if [gdb_test "next" \
+    ".*d128 = 1.2345.*" \
+    "next after assigning builtin NaN to d64"] then { gdb_suppress_tests }
+gdb_test "print d64" "NaN" "d64 is NaN"
+
+d64_set_tests
+
+
+# Different tests on 128-bits decimal floating point, including the display
+# of finite number, infinite and NaN, and also the setting of different
+# decimal value.
+
+if [gdb_test "next" \
+    ".*Positive infd128.*" \
+    "next after initializing d128"] then { gdb_suppress_tests }
+gdb_test "print d128" "1.2345" "d128 is initialized to 1.2345"
+
+d128_set_tests
+
+if [gdb_test "next" \
+    ".*Negative infd128.*" \
+    "next after assigning builtin infinity to d128"] then { gdb_suppress_tests }
+gdb_test "print d128" "Infinity" "d128 is positive Infinity"
+
+if [gdb_test "next" \
+    ".*__builtin_nand128.*" \
+    "next after assigning negative builtin infinity to d128"] then { gdb_suppress_tests }
+gdb_test "print d128" "-Infinity" "d128 is negative Infinity"
+
+if [gdb_test "next" \
+    ".*arg0_32.*" \
+    "next after assigning builtin NaN to d128"] then { gdb_suppress_tests }
+gdb_test "print d128" "NaN" "d128 is NaN"
+
+# The following tests are intended to verify that gdb can correctly handle
+# DFP types in function arguments.
+
+gdb_breakpoint arg0_32
+gdb_continue_to_breakpoint "entry to arg0_32"
+gdb_test "backtrace" ".*arg0_32 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_32"
+
+gdb_breakpoint arg0_64
+gdb_continue_to_breakpoint "entry to arg0_64"
+gdb_test "backtrace" ".*arg0_64 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_64"
+
+gdb_breakpoint arg0_128
+gdb_continue_to_breakpoint "entry to arg0_128"
+gdb_test "backtrace" ".*arg0_128 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_128"
+
+# The following tests are intended to verify that gdb can handle DFP types
+# correctly in struct.
+
+gdb_breakpoint [gdb_get_line_number "Exit point"]
+gdb_continue_to_breakpoint "Setting a decimal struct"
+gdb_test "print ds.dec32" " = 1.2345"
+gdb_test "print ds.dec64" " = 1.2345"
+gdb_test "print ds.dec128" " = 1.2345"
+
+# The following tests are intended to verify that gdb can handle "d1=d2"
+# and "d1=-d2" correctly.
+
+gdb_test "print ds.dec32=d32" " = 0.1"
+gdb_test "print ds.dec64=d64" " = 0.1"
+gdb_test "print ds.dec128=d128" " = 0.1"
+gdb_test "print ds.dec32 = -d32" " = -0.1"
+gdb_test "print ds.dec64 = -d64" " = -0.1"
+gdb_test "print ds.dec128 = -d128" " = -0.1"

-- 


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [patch 1/4] libdecnumber support
  2007-09-20 21:57 [patch 0/4] decimal floating point support Thiago Jung Bauermann
  2007-09-20 21:57 ` [patch 3/4] decimal floating point support for expressions Thiago Jung Bauermann
  2007-09-20 21:57 ` [patch 4/4] decimal floating point testcases Thiago Jung Bauermann
@ 2007-09-20 21:57 ` Thiago Jung Bauermann
  2007-10-11 15:57   ` Daniel Jacobowitz
  2007-09-20 21:57 ` [patch 2/4] decimal floating point types Thiago Jung Bauermann
  3 siblings, 1 reply; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-09-20 21:57 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: libdecnumber-support.diff --]
[-- Type: text/plain, Size: 10523 bytes --]

This patch provides functions to interact with libdecnumber and changes
the Makefile to compile it.

2007-09-20  Wu Zhou  <woodzltc@cn.ibm.com> 
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* Makefile.in (LIBDECNUMBER_DIR, LIBDECNUMBER, LIBDECNUMBER_SRC
	LIBDECNUMBER_CFLAGS): New macros for libdecnumber.
	(INTERNAL_CFLAGS_BASE): Add LIBDECNUMBER_CFLAGS in.
	(INSTALLED_LIBS): Add -ldecnumber in.
	(CLIBS): Add LIBDECNUMBER in.
	(decimal128_h, decimal64_h, decimal32_h): New macros for decimal
	headers.
	(dfp_h): New macros for decimal floating point.
	(dfp.o): New target.
	(COMMON_OBS): Add dfp.o in.
	(valprint.o): Add dfp_h as dependency.
	(value.o): Add dfp_h as dependency.
	* dfp.h: New header file for decimal floating point support in
	GDB.
	* dfp.c: New source file for decimal floating point support in
	GDB.  Implement decimal_from_string and decimal_to_string based
	on libdecnumber API.
 
Index: gdb/Makefile.in
===================================================================
--- gdb/Makefile.in.orig	2007-09-20 14:21:39.000000000 -0300
+++ gdb/Makefile.in	2007-09-20 14:37:29.000000000 -0300
@@ -125,6 +125,12 @@ BFD = $(BFD_DIR)/libbfd.a
 BFD_SRC = $(srcdir)/$(BFD_DIR)
 BFD_CFLAGS = -I$(BFD_DIR) -I$(BFD_SRC)
 
+# Where is the decnumber library?  Typically in ../libdecnumber.
+LIBDECNUMBER_DIR = ../libdecnumber
+LIBDECNUMBER = $(LIBDECNUMBER_DIR)/libdecnumber.a
+LIBDECNUMBER_SRC = $(srcdir)/$(LIBDECNUMBER_DIR)
+LIBDECNUMBER_CFLAGS = -I$(LIBDECNUMBER_DIR) -I$(LIBDECNUMBER_SRC)
+
 # Where is the READLINE library?  Typically in ../readline.
 READLINE_DIR = ../readline
 READLINE_SRC = $(srcdir)/$(READLINE_DIR)
@@ -358,7 +364,7 @@ CXXFLAGS = -g -O
 INTERNAL_CFLAGS_BASE = \
 	$(CFLAGS) $(GLOBAL_CFLAGS) $(PROFILE_CFLAGS) \
 	$(GDB_CFLAGS) $(OPCODES_CFLAGS) $(READLINE_CFLAGS) \
-	$(BFD_CFLAGS) $(INCLUDE_CFLAGS) \
+	$(BFD_CFLAGS) $(INCLUDE_CFLAGS) $(LIBDECNUMBER_CFLAGS) \
 	$(INTL_CFLAGS) $(ENABLE_CFLAGS) $(INTERNAL_CPPFLAGS)
 INTERNAL_WARN_CFLAGS = $(INTERNAL_CFLAGS_BASE) $(GDB_WARN_CFLAGS)
 INTERNAL_CFLAGS = $(INTERNAL_WARN_CFLAGS) $(GDB_WERROR_CFLAGS)
@@ -381,10 +387,10 @@ INTERNAL_LDFLAGS = $(CFLAGS) $(GLOBAL_CF
 # LIBIBERTY appears twice on purpose.
 # If you have the Cygnus libraries installed,
 # you can use 'CLIBS=$(INSTALLED_LIBS)' 'CDEPS='
-INSTALLED_LIBS=-lbfd -lreadline -lopcodes -liberty \
+INSTALLED_LIBS=-lbfd -lreadline -lopcodes -liberty -ldecnumber \
 	$(XM_CLIBS) $(TM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ \
 	-lintl -liberty
-CLIBS = $(SIM) $(READLINE) $(OPCODES) $(BFD) $(INTL) $(LIBIBERTY) \
+CLIBS = $(SIM) $(READLINE) $(OPCODES) $(BFD) $(INTL) $(LIBIBERTY) $(LIBDECNUMBER) \
 	$(XM_CLIBS) $(TM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ \
 	$(LIBICONV) $(LIBEXPAT) \
 	$(LIBIBERTY) $(WIN32LIBS)
@@ -624,6 +630,10 @@ safe_ctype_h =  $(INCLUDE_DIR)/safe-ctyp
 hashtab_h =	$(INCLUDE_DIR)/hashtab.h
 filenames_h =	$(INCLUDE_DIR)/filenames.h
 
+decimal128_h = $(LIBDECNUMBER_DIR)/dpd/decimal128.h
+decimal64_h = $(LIBDECNUMBER_DIR)/dpd/decimal64.h
+decimal32_h = $(LIBDECNUMBER_DIR)/dpd/decimal32.h
+
 #
 # $BUILD/ headers
 #
@@ -690,6 +700,7 @@ dictionary_h = dictionary.h
 disasm_h = disasm.h
 doublest_h = doublest.h $(floatformat_h)
 dummy_frame_h = dummy-frame.h
+dfp_h = dfp.h
 dwarf2expr_h = dwarf2expr.h
 dwarf2_frame_h = dwarf2-frame.h
 dwarf2loc_h = dwarf2loc.h
@@ -938,7 +949,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $
 	auxv.o \
 	bfd-target.o \
 	blockframe.o breakpoint.o findvar.o regcache.o \
-	charset.o disasm.o dummy-frame.o \
+	charset.o disasm.o dummy-frame.o dfp.o \
 	source.o value.o eval.o valops.o valarith.o valprint.o printcmd.o \
 	block.o symtab.o symfile.o symmisc.o linespec.o dictionary.o \
 	infcall.o \
@@ -1953,6 +1964,7 @@ dsrec.o: dsrec.c $(defs_h) $(serial_h) $
 dummy-frame.o: dummy-frame.c $(defs_h) $(dummy_frame_h) $(regcache_h) \
 	$(frame_h) $(inferior_h) $(gdb_assert_h) $(frame_unwind_h) \
 	$(command_h) $(gdbcmd_h) $(gdb_string_h)
+dfp.o: dfp.c $(defs_h) $(dfp_h) $(decimal128_h) $(decimal64_h) $(decimal32_h)
 dwarf2expr.o: dwarf2expr.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(value_h) \
 	$(gdbcore_h) $(elf_dwarf2_h) $(dwarf2expr_h)
 dwarf2-frame.o: dwarf2-frame.c $(defs_h) $(dwarf2expr_h) $(elf_dwarf2_h) \
@@ -2814,11 +2826,11 @@ valops.o: valops.c $(defs_h) $(symtab_h)
 valprint.o: valprint.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
 	$(value_h) $(gdbcore_h) $(gdbcmd_h) $(target_h) $(language_h) \
 	$(annotate_h) $(valprint_h) $(floatformat_h) $(doublest_h) \
-	$(exceptions_h)
+	$(exceptions_h) $(dfp_h)
 value.o: value.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
 	$(value_h) $(gdbcore_h) $(command_h) $(gdbcmd_h) $(target_h) \
 	$(language_h) $(demangle_h) $(doublest_h) \
-	$(gdb_assert_h) $(regcache_h) $(block_h)
+	$(gdb_assert_h) $(regcache_h) $(block_h) $(dfp_h)
 varobj.o: varobj.c $(defs_h) $(exceptions_h) $(value_h) $(expression_h) \
 	$(frame_h) $(language_h) $(wrapper_h) $(gdbcmd_h) $(block_h) \
 	$(gdb_assert_h) $(gdb_string_h) $(varobj_h) $(vec_h)
Index: gdb/dfp.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb/dfp.c	2007-09-20 14:21:45.000000000 -0300
@@ -0,0 +1,123 @@
+/* Decimal floating point support for GDB.
+
+   Copyright 2007 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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 2 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 this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <ctype.h>
+#include <endian.h>
+#include "defs.h"
+#include "dfp.h"
+
+/* The order of the following headers is important for making sure
+   decNumber structure is large enough to hold decimal128 digits.  */
+
+#include "dpd/decimal128.h"
+#include "dpd/decimal64.h"
+#include "dpd/decimal32.h"
+
+/* In GDB, we are using an array of gdb_byte to represent decimal values.
+   They are stored in host byte order.  This routine does the conversion if
+   the target byte order is different.  */
+static void
+match_endianness (const gdb_byte *from, int len, gdb_byte *to)
+{
+  int i;
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define OPPOSITE_BYTE_ORDER BFD_ENDIAN_BIG
+#else
+#define OPPOSITE_BYTE_ORDER BFD_ENDIAN_LITTLE
+#endif
+
+  if (gdbarch_byte_order (current_gdbarch) == OPPOSITE_BYTE_ORDER)
+    for (i = 0; i < len; i++)
+      to[i] = from[len - i - 1];
+  else
+    for (i = 0; i < len; i++)
+      to[i] = from[i];
+
+  return;
+}
+
+/* Convert decimal type to its string representation.  LEN is the length
+   of the decimal type, 4 bytes for decimal32, 8 bytes for decimal64 and
+   16 bytes for decimal128.  */
+void
+decimal_to_string (const uint8_t *decbytes, int len, char *s)
+{
+  uint8_t *dec = (uint8_t *)malloc (len);
+
+  match_endianness (decbytes, len, dec);
+  switch (len)
+    {
+      case 4:
+        decimal32ToString ((decimal32 *) dec, s);
+        break;
+      case 8:
+        decimal64ToString ((decimal64 *) dec, s);
+        break;
+      case 16:
+        decimal128ToString ((decimal128 *) dec, s);
+        break;
+      default:
+	free (dec);
+	error(_("Unknown decimal floating point type.\n"));
+	break;
+    }
+
+  free (dec);
+}
+
+/* Convert the string form of a decimal value to its decimal representation.
+   LEN is the length of the decimal type, 4 bytes for decimal32, 8 bytes for
+   decimal64 and 16 bytes for decimal128.  */
+int
+decimal_from_string (uint8_t *decbytes, int len, const char *string)
+{
+  decContext set;
+  uint8_t *dec = (uint8_t *)malloc (len);
+
+  switch (len)
+    {
+      case 4:
+	decContextDefault (&set, DEC_INIT_DECIMAL32);
+	set.traps = 0;
+	decimal32FromString ((decimal32 *) dec, string, &set);
+	break;
+      case 8:
+	decContextDefault (&set, DEC_INIT_DECIMAL64);
+	set.traps = 0;
+	decimal64FromString ((decimal64 *) dec, string, &set);
+	break;
+      case 16:
+	decContextDefault (&set, DEC_INIT_DECIMAL128);
+	set.traps = 0;
+	decimal128FromString ((decimal128 *) dec, string, &set);
+	break;
+      default:
+	free (dec);
+	error(_("Unknown decimal floating point type.\n"));
+	break;
+    }
+
+  match_endianness (dec, len, decbytes);
+  free (dec);
+
+  return 1;
+}
Index: gdb/dfp.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb/dfp.h	2007-09-20 14:21:45.000000000 -0300
@@ -0,0 +1,40 @@
+/* Decimal floating point support for GDB.
+
+   Copyright 2007 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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 2 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 this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+/* Decimal floating point is one of the extension to IEEE 754, which is
+   described in http://grouper.ieee.org/groups/754/revision.html and
+   http://www2.hursley.ibm.com/decimal/.  It completes binary floating
+   point by representing floating point more exactly.  */
+
+/* There is a project intended to add DFP support into GCC, described in
+   http://gcc.gnu.org/wiki/Decimal%20Floating-Point.  This file is intended
+   to add DFP support into GDB.  */
+
+#ifndef DFP_H
+#define DFP_H
+#include <string.h>
+#include <stdio.h>
+#include <stdint.h>
+
+extern void decimal_to_string (const uint8_t *, int, char *);
+extern int decimal_from_string (uint8_t *, int, const char *);
+
+#endif

-- 


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [patch 2/4] decimal floating point types
  2007-09-20 21:57 [patch 0/4] decimal floating point support Thiago Jung Bauermann
                   ` (2 preceding siblings ...)
  2007-09-20 21:57 ` [patch 1/4] libdecnumber support Thiago Jung Bauermann
@ 2007-09-20 21:57 ` Thiago Jung Bauermann
  2007-10-11 16:00   ` Daniel Jacobowitz
  3 siblings, 1 reply; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-09-20 21:57 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: decfloat-types.diff --]
[-- Type: text/plain, Size: 8206 bytes --]

2007-09-20  Wu Zhou  <woodzltc@cn.ibm.com> 
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* c-lang.c (c_create_fundamental_type): Create fundamental
	types for DFP.
	* c-typeprint.c (c_type_print_varspec_prefix): Add
	TYPE_CODE_DECFLOAT to no prefix needed case.
	(c_type_print_varspec_suffix): Add TYPE_CODE_DECFLOAT to no
	suffix needed case.
	* c-valprint.c (c_val_print): Call print_decimal_floating to
	print DFP values.
	* dwarf2read.c (read_base_type): Read DW_ATE_decimal_float
	attribute code and return TYPE_CODE_DECFLOAT.
	(dwarf_base_type): Set dwarf2_fundamental_type for DFP values.
	* gdbtypes.c (gdbtypes_post_init): Initialize builtin_decfloat,
	builtin_decdouble and builtin_declong. 
	* gdbtypes.h (enum type_code): Add TYPE_CODE_DECFLOAT as a
	type code for DFP.
	(FT_DECFLOAT, FT_DBL_PREC_DECFLOAT, FT_EXT_PREC_DECFLOAT): New
	types, for decimal floating point.
	(FT_NUM_MEMBERS):  Increment, new types added.
	(struct builtin_type): Add builtin_decfloat, builtin_decdouble
	and builtin_declong.
	* valprint.c (print_decimal_floating): New function to print DFP
	values.
	* value.h (print_decimal_floating): Prototype.

Index: gdb/c-lang.c
===================================================================
--- gdb/c-lang.c.orig	2007-09-18 02:41:10.000000000 -0300
+++ gdb/c-lang.c	2007-09-18 02:44:26.000000000 -0300
@@ -325,6 +325,21 @@ c_create_fundamental_type (struct objfil
 			  / TARGET_CHAR_BIT,
 			0, "long double", objfile);
       break;
+    case FT_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			32 / 8,
+			0, "decimal float", objfile);
+      break;
+    case FT_DBL_PREC_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			64 / 8,
+			0, "decimal double", objfile);
+      break;
+    case FT_EXT_PREC_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			128 / 8,
+			0, "decimal long double", objfile);
+      break;
     case FT_COMPLEX:
       type = init_type (TYPE_CODE_FLT,
 			2 * gdbarch_float_bit (current_gdbarch)
Index: gdb/c-valprint.c
===================================================================
--- gdb/c-valprint.c.orig	2007-09-18 02:41:10.000000000 -0300
+++ gdb/c-valprint.c	2007-09-18 02:44:26.000000000 -0300
@@ -474,6 +474,13 @@ c_val_print (struct type *type, const gd
 	}
       break;
 
+    case TYPE_CODE_DECFLOAT:
+      if (format)
+	print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
+      else
+	print_decimal_floating (valaddr + embedded_offset, type, stream);
+      break;
+
     case TYPE_CODE_VOID:
       fprintf_filtered (stream, "void");
       break;
Index: gdb/dwarf2read.c
===================================================================
--- gdb/dwarf2read.c.orig	2007-09-18 02:41:10.000000000 -0300
+++ gdb/dwarf2read.c	2007-09-18 02:44:26.000000000 -0300
@@ -4868,6 +4868,9 @@ read_base_type (struct die_info *die, st
 	case DW_ATE_complex_float:
 	  code = TYPE_CODE_COMPLEX;
 	  break;
+	case DW_ATE_decimal_float:
+	  code = TYPE_CODE_DECFLOAT;
+	  break;
 	case DW_ATE_float:
 	  code = TYPE_CODE_FLT;
 	  break;
@@ -7755,6 +7758,18 @@ dwarf_base_type (int encoding, int size,
 	  type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
 	}
       return type;
+    case DW_ATE_decimal_float:
+      if (size == 16)
+	{
+	  type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_DECFLOAT, cu);
+	}
+      else if (size == 8)
+	{
+	  type = dwarf2_fundamental_type (objfile, FT_EXT_PREC_DECFLOAT, cu);
+	}
+      else
+	type = dwarf2_fundamental_type (objfile, FT_DECFLOAT, cu);
+      return type;
     case DW_ATE_signed:
       switch (size)
 	{
Index: gdb/gdbtypes.c
===================================================================
--- gdb/gdbtypes.c.orig	2007-09-18 02:41:11.000000000 -0300
+++ gdb/gdbtypes.c	2007-09-18 02:50:06.000000000 -0300
@@ -3508,6 +3508,21 @@ gdbtypes_post_init (struct gdbarch *gdba
 	       0,
 	       "bool", (struct objfile *) NULL);
 
+  /* The following three are about decimal floating point types, which
+     are 32-bits, 64-bits and 128-bits respectively.  */
+  builtin_type->builtin_decfloat =
+    init_type (TYPE_CODE_DECFLOAT, 32 / 8,
+	        0,
+	       "decimal float", (struct objfile *) NULL);
+  builtin_type->builtin_decdouble =
+    init_type (TYPE_CODE_DECFLOAT, 64 / 8,
+	       0,
+	       "decimal double", (struct objfile *) NULL);
+  builtin_type->builtin_declong =
+    init_type (TYPE_CODE_DECFLOAT, 128 / 8,
+	       0,
+	       "decimal long double", (struct objfile *) NULL);
+
   /* Pointer/Address types.  */
 
   /* NOTE: on some targets, addresses and pointers are not necessarily
Index: gdb/gdbtypes.h
===================================================================
--- gdb/gdbtypes.h.orig	2007-09-18 02:41:11.000000000 -0300
+++ gdb/gdbtypes.h	2007-09-18 02:44:26.000000000 -0300
@@ -65,7 +65,12 @@ struct block;
 #define FT_UNSIGNED_BYTE	27
 #define FT_TEMPLATE_ARG		28
 
-#define FT_NUM_MEMBERS		29	/* Highest FT_* above, plus one. */
+/* The following three fundamental types are for decimal floating point.  */
+#define FT_DECFLOAT		29
+#define FT_DBL_PREC_DECFLOAT	30
+#define FT_EXT_PREC_DECFLOAT	31
+
+#define FT_NUM_MEMBERS		32	/* Highest FT_* above, plus one. */
 
 /* Some macros for char-based bitfields.  */
 
@@ -169,7 +174,9 @@ enum type_code
     TYPE_CODE_TEMPLATE,		/* C++ template */
     TYPE_CODE_TEMPLATE_ARG,	/* C++ template arg */
 
-    TYPE_CODE_NAMESPACE		/* C++ namespace.  */
+    TYPE_CODE_NAMESPACE,	/* C++ namespace.  */
+
+    TYPE_CODE_DECFLOAT		/* Decimal floating point.  */
   };
 
 /* For now allow source to use TYPE_CODE_CLASS for C++ classes, as an
@@ -1041,6 +1048,9 @@ struct builtin_type
   struct type *builtin_bool;
   struct type *builtin_long_long;
   struct type *builtin_unsigned_long_long;
+  struct type *builtin_decfloat;
+  struct type *builtin_decdouble;
+  struct type *builtin_declong;
 };
 
 /* Return the type table for the specified architecture.  */
Index: gdb/valprint.c
===================================================================
--- gdb/valprint.c.orig	2007-09-18 02:41:16.000000000 -0300
+++ gdb/valprint.c	2007-09-18 02:44:26.000000000 -0300
@@ -33,6 +33,7 @@
 #include "floatformat.h"
 #include "doublest.h"
 #include "exceptions.h"
+#include "dfp.h"
 
 #include <errno.h>
 
@@ -506,6 +507,18 @@ print_floating (const gdb_byte *valaddr,
 }
 
 void
+print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+			struct ui_file *stream)
+{
+  char decstr[128];
+  unsigned len = TYPE_LENGTH (type);
+
+  decimal_to_string (valaddr, len, decstr);
+  fputs_filtered (decstr, stream);
+  return;
+}
+
+void
 print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
 		    unsigned len)
 {
Index: gdb/value.h
===================================================================
--- gdb/value.h.orig	2007-09-18 02:41:16.000000000 -0300
+++ gdb/value.h	2007-09-18 02:44:26.000000000 -0300
@@ -488,6 +488,9 @@ extern void print_longest (struct ui_fil
 extern void print_floating (const gdb_byte *valaddr, struct type *type,
 			    struct ui_file *stream);
 
+extern void print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+				    struct ui_file *stream);
+
 extern int value_print (struct value *val, struct ui_file *stream, int format,
 			enum val_prettyprint pretty);
 
Index: gdb/c-typeprint.c
===================================================================
--- gdb/c-typeprint.c.orig	2007-09-18 02:41:10.000000000 -0300
+++ gdb/c-typeprint.c	2007-09-18 02:44:26.000000000 -0300
@@ -277,6 +277,7 @@ c_type_print_varspec_prefix (struct type
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_TEMPLATE:
     case TYPE_CODE_NAMESPACE:
+    case TYPE_CODE_DECFLOAT:
       /* These types need no prefix.  They are listed here so that
          gcc -Wall will reveal any types that haven't been handled.  */
       break;
@@ -599,6 +600,7 @@ c_type_print_varspec_suffix (struct type
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_TEMPLATE:
     case TYPE_CODE_NAMESPACE:
+    case TYPE_CODE_DECFLOAT:
       /* These types do not need a suffix.  They are listed so that
          gcc -Wall will report types that may not have been considered.  */
       break;

-- 


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 1/4] libdecnumber support
  2007-09-20 21:57 ` [patch 1/4] libdecnumber support Thiago Jung Bauermann
@ 2007-10-11 15:57   ` Daniel Jacobowitz
  2007-10-11 16:07     ` Daniel Jacobowitz
  2007-10-15 18:11     ` Thiago Jung Bauermann
  0 siblings, 2 replies; 23+ messages in thread
From: Daniel Jacobowitz @ 2007-10-11 15:57 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches

I'll review all these now.  Before you check them in, though, give
me a chance to get libdecnumber merged into the src repository.  It
shouldn't take long.

On Thu, Sep 20, 2007 at 06:54:11PM -0300, Thiago Jung Bauermann wrote:
> +#include <ctype.h>
> +#include <endian.h>
> +#include "defs.h"
> +#include "dfp.h"

What do you need ctype.h for?  That will tell me whether you really
want ctype.h or libiberty's locale-independent safe-ctype.h.

defs.h should always be first.

endian.h is not portable.  You should probably use the autoconf macro
AC_C_BIGENDIAN.

> +/* Convert decimal type to its string representation.  LEN is the length
> +   of the decimal type, 4 bytes for decimal32, 8 bytes for decimal64 and
> +   16 bytes for decimal128.  */
> +void
> +decimal_to_string (const uint8_t *decbytes, int len, char *s)
> +{
> +  uint8_t *dec = (uint8_t *)malloc (len);

You didn't include anything that would give you uint8_t; use
gdb_byte.  Also we never use malloc, only xmalloc.  Or you could avoid
the allocation by using gdb_byte dec[16].

> +        break;
> +      default:
> +	free (dec);

Spaces and tabs mixed up?  xfree, like xmalloc.

> +	error(_("Unknown decimal floating point type.\n"));

Space before parentheses please.

> +/* There is a project intended to add DFP support into GCC, described in
> +   http://gcc.gnu.org/wiki/Decimal%20Floating-Point.  This file is intended
> +   to add DFP support into GDB.  */

This comment doesn't belong here.  The file is part of GDB once the
patch is applied.

> +#ifndef DFP_H
> +#define DFP_H
> +#include <string.h>
> +#include <stdio.h>
> +#include <stdint.h>

Don't include standard headers here; stick to what defs.h provides.
Just as well, since neither string.h nor stdint.h is portable.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 2/4] decimal floating point types
  2007-09-20 21:57 ` [patch 2/4] decimal floating point types Thiago Jung Bauermann
@ 2007-10-11 16:00   ` Daniel Jacobowitz
  2007-10-15 18:12     ` Thiago Jung Bauermann
  0 siblings, 1 reply; 23+ messages in thread
From: Daniel Jacobowitz @ 2007-10-11 16:00 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches

On Thu, Sep 20, 2007 at 06:54:12PM -0300, Thiago Jung Bauermann wrote:
> +    case DW_ATE_decimal_float:
> +      if (size == 16)
> +	{
> +	  type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_DECFLOAT, cu);
> +	}
> +      else if (size == 8)
> +	{
> +	  type = dwarf2_fundamental_type (objfile, FT_EXT_PREC_DECFLOAT, cu);
> +	}
> +      else
> +	type = dwarf2_fundamental_type (objfile, FT_DECFLOAT, cu);
> +      return type;

You don't need a bunch of those extra braces.

> +  /* The following three are about decimal floating point types, which
> +     are 32-bits, 64-bits and 128-bits respectively.  */
> +  builtin_type->builtin_decfloat =
> +    init_type (TYPE_CODE_DECFLOAT, 32 / 8,
> +	        0,
> +	       "decimal float", (struct objfile *) NULL);

I think our convention is to put the equals sign after the line break.

>  void
> +print_decimal_floating (const gdb_byte *valaddr, struct type *type,
> +			struct ui_file *stream)
> +{
> +  char decstr[128];
> +  unsigned len = TYPE_LENGTH (type);
> +
> +  decimal_to_string (valaddr, len, decstr);
> +  fputs_filtered (decstr, stream);
> +  return;
> +}

Does the libdecnumber API specify that 128 bytes is enough?  If so
this should be a constant in dfp.h.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 1/4] libdecnumber support
  2007-10-11 15:57   ` Daniel Jacobowitz
@ 2007-10-11 16:07     ` Daniel Jacobowitz
  2007-10-15 18:32       ` Thiago Jung Bauermann
  2007-10-15 18:11     ` Thiago Jung Bauermann
  1 sibling, 1 reply; 23+ messages in thread
From: Daniel Jacobowitz @ 2007-10-11 16:07 UTC (permalink / raw)
  To: Thiago Jung Bauermann, gdb-patches

Oh, I also noticed some GPLv2 copyright headers; please update to
GPLv3.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 3/4] decimal floating point support for expressions
  2007-09-20 21:57 ` [patch 3/4] decimal floating point support for expressions Thiago Jung Bauermann
@ 2007-10-11 16:18   ` Daniel Jacobowitz
  2007-10-15 18:12     ` Thiago Jung Bauermann
  0 siblings, 1 reply; 23+ messages in thread
From: Daniel Jacobowitz @ 2007-10-11 16:18 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches

On Thu, Sep 20, 2007 at 06:54:13PM -0300, Thiago Jung Bauermann wrote:
> +	  putithere->typed_val_decfloat.type =
> +	    builtin_type (current_gdbarch)->builtin_decfloat;

Equals sign on next line please.

> @@ -1376,6 +1376,20 @@ value_neg (struct value *arg1)
>  
>    type = check_typedef (value_type (arg1));
>  
> +  if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
> +    {
> +      struct value *val = allocate_value (result_type);
> +      int len = TYPE_LENGTH (type);
> +      gdb_byte *decbytes = (gdb_byte *) value_contents (arg1);
> +
> +      if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_LITTLE)
> +	decbytes[len-1] = decbytes[len - 1] | 0x80;
> +      else
> +	decbytes[0] = decbytes[0] | 0x80;
> +      memcpy (value_contents_raw (val), decbytes, 16);
> +      return val;
> +    }
> +

The reason we allocate a new value is to leave the existing value
unchanged, so you shouldn't modify the contents of arg1.  The casts
are probably there because otherwise GCC complained you were removing
a const.  Don't do that :-)

> +#include "dfp.h"

If you add an #include, update Makefile.in.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 4/4] decimal floating point testcases
  2007-09-20 21:57 ` [patch 4/4] decimal floating point testcases Thiago Jung Bauermann
@ 2007-10-11 16:19   ` Daniel Jacobowitz
  2007-10-15 18:12     ` Thiago Jung Bauermann
  0 siblings, 1 reply; 23+ messages in thread
From: Daniel Jacobowitz @ 2007-10-11 16:19 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches

On Thu, Sep 20, 2007 at 06:54:14PM -0300, Thiago Jung Bauermann wrote:
> +# This file is part of the gdb testsuite.  It is intended to test that
> +# gdb could correctly hane decimal floating point introduced in IEEE 754R.

"handle".  Otherwise looks fine (except for GPLv3 copyright updates).

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 1/4] libdecnumber support
  2007-10-11 15:57   ` Daniel Jacobowitz
  2007-10-11 16:07     ` Daniel Jacobowitz
@ 2007-10-15 18:11     ` Thiago Jung Bauermann
  2007-10-15 18:38       ` Daniel Jacobowitz
  1 sibling, 1 reply; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-15 18:11 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 2968 bytes --]

On Thu, 2007-10-11 at 11:54 -0400, Daniel Jacobowitz wrote: 
> I'll review all these now.

Thank you very much.

> Before you check them in, though, give
> me a chance to get libdecnumber merged into the src repository.  It
> shouldn't take long.

Thanks for taking care of this.

> On Thu, Sep 20, 2007 at 06:54:11PM -0300, Thiago Jung Bauermann wrote:
> > +#include <ctype.h>
> > +#include <endian.h>
> > +#include "defs.h"
> > +#include "dfp.h"
> 
> What do you need ctype.h for?  That will tell me whether you really
> want ctype.h or libiberty's locale-independent safe-ctype.h.
> 
> defs.h should always be first.

It turned out that ctype.h was not needed at all. I just removed it and
it made no difference. Probably a left-over from an older version of the
code.

> endian.h is not portable.  You should probably use the autoconf macro
> AC_C_BIGENDIAN.

Ok, I'm using it now. When I run autoreconf inside the src/gdb
directory, I get the following:

$ autoreconf
autoreconf: cannot create `cd $srcdir;pwd`/../../../..: No such file or
directory
autoreconf: cannot create `cd $srcdir;pwd`/../../..: No such file or
directory
autoreconf: cannot create `cd $srcdir;pwd`/..: No such file or directory
$ echo $?
0

Is this a problem? Things still seem to work fine. I used autoconf
version 2.61.

> > +/* Convert decimal type to its string representation.  LEN is the length
> > +   of the decimal type, 4 bytes for decimal32, 8 bytes for decimal64 and
> > +   16 bytes for decimal128.  */
> > +void
> > +decimal_to_string (const uint8_t *decbytes, int len, char *s)
> > +{
> > +  uint8_t *dec = (uint8_t *)malloc (len);
> 
> You didn't include anything that would give you uint8_t; use
> gdb_byte.

I included dfp.h, which included stdint.h. I see now that GDB doesn't
use C99 yet, so I changed to gdb_byte.

> Also we never use malloc, only xmalloc.  Or you could avoid
> the allocation by using gdb_byte dec[16].

Good idea. Just changed to use temporary array as suggested.

> > +        break;
> > +      default:
> > +	free (dec);
> 
> Spaces and tabs mixed up?  xfree, like xmalloc.

Fixed. No '\t' in the file now. By the way, what's the policy in GDB
w.r.t. tabs and spaces? Never use tabs?

> > +	error(_("Unknown decimal floating point type.\n"));
> 
> Space before parentheses please.

Fixed.

> > +/* There is a project intended to add DFP support into GCC, described in
> > +   http://gcc.gnu.org/wiki/Decimal%20Floating-Point.  This file is intended
> > +   to add DFP support into GDB.  */
> 
> This comment doesn't belong here.  The file is part of GDB once the
> patch is applied.

Ok, removed comment.

> > +#ifndef DFP_H
> > +#define DFP_H
> > +#include <string.h>
> > +#include <stdio.h>
> > +#include <stdint.h>
> 
> Don't include standard headers here; stick to what defs.h provides.
> Just as well, since neither string.h nor stdint.h is portable.

Ok, removed.
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center

[-- Attachment #2: libdecnumber-support.diff --]
[-- Type: text/x-patch, Size: 11282 bytes --]

Subject: libdecnumber support

This patch provides functions to interact with libdecnumber and changes
the Makefile to compile it.

2007-10-15  Wu Zhou  <woodzltc@cn.ibm.com> 
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* Makefile.in (LIBDECNUMBER_DIR, LIBDECNUMBER, LIBDECNUMBER_SRC
	LIBDECNUMBER_CFLAGS): New macros for libdecnumber.
	(INTERNAL_CFLAGS_BASE): Add LIBDECNUMBER_CFLAGS in.
	(INSTALLED_LIBS): Add -ldecnumber in.
	(CLIBS): Add LIBDECNUMBER in.
	(decimal128_h, decimal64_h, decimal32_h): New macros for decimal
	headers.
	(dfp_h): New macros for decimal floating point.
	(dfp.o): New target.
	(COMMON_OBS): Add dfp.o in.
	(c-exp.o): Add dfp_h as dependency.
	(valprint.o): Add dfp_h as dependency.
	(value.o): Add dfp_h as dependency.
	* dfp.h: New header file for decimal floating point support in
	GDB.
	* dfp.c: New source file for decimal floating point support in
	GDB.  Implement decimal_from_string and decimal_to_string based
	on libdecnumber API.
	* configure.ac: Add AC_C_BIGENDIAN test.
 
Index: gdb/Makefile.in
===================================================================
--- gdb/Makefile.in.orig	2007-10-15 14:25:14.000000000 -0200
+++ gdb/Makefile.in	2007-10-15 14:35:06.000000000 -0200
@@ -125,6 +125,12 @@ BFD = $(BFD_DIR)/libbfd.a
 BFD_SRC = $(srcdir)/$(BFD_DIR)
 BFD_CFLAGS = -I$(BFD_DIR) -I$(BFD_SRC)
 
+# Where is the decnumber library?  Typically in ../libdecnumber.
+LIBDECNUMBER_DIR = ../libdecnumber
+LIBDECNUMBER = $(LIBDECNUMBER_DIR)/libdecnumber.a
+LIBDECNUMBER_SRC = $(srcdir)/$(LIBDECNUMBER_DIR)
+LIBDECNUMBER_CFLAGS = -I$(LIBDECNUMBER_DIR) -I$(LIBDECNUMBER_SRC)
+
 # Where is the READLINE library?  Typically in ../readline.
 READLINE_DIR = ../readline
 READLINE_SRC = $(srcdir)/$(READLINE_DIR)
@@ -358,7 +364,7 @@ CXXFLAGS = -g -O
 INTERNAL_CFLAGS_BASE = \
 	$(CFLAGS) $(GLOBAL_CFLAGS) $(PROFILE_CFLAGS) \
 	$(GDB_CFLAGS) $(OPCODES_CFLAGS) $(READLINE_CFLAGS) \
-	$(BFD_CFLAGS) $(INCLUDE_CFLAGS) \
+	$(BFD_CFLAGS) $(INCLUDE_CFLAGS) $(LIBDECNUMBER_CFLAGS) \
 	$(INTL_CFLAGS) $(ENABLE_CFLAGS) $(INTERNAL_CPPFLAGS)
 INTERNAL_WARN_CFLAGS = $(INTERNAL_CFLAGS_BASE) $(GDB_WARN_CFLAGS)
 INTERNAL_CFLAGS = $(INTERNAL_WARN_CFLAGS) $(GDB_WERROR_CFLAGS)
@@ -381,10 +387,10 @@ INTERNAL_LDFLAGS = $(CFLAGS) $(GLOBAL_CF
 # LIBIBERTY appears twice on purpose.
 # If you have the Cygnus libraries installed,
 # you can use 'CLIBS=$(INSTALLED_LIBS)' 'CDEPS='
-INSTALLED_LIBS=-lbfd -lreadline -lopcodes -liberty \
+INSTALLED_LIBS=-lbfd -lreadline -lopcodes -liberty -ldecnumber \
 	$(XM_CLIBS) $(TM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ \
 	-lintl -liberty
-CLIBS = $(SIM) $(READLINE) $(OPCODES) $(BFD) $(INTL) $(LIBIBERTY) \
+CLIBS = $(SIM) $(READLINE) $(OPCODES) $(BFD) $(INTL) $(LIBIBERTY) $(LIBDECNUMBER) \
 	$(XM_CLIBS) $(TM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ \
 	$(LIBICONV) $(LIBEXPAT) \
 	$(LIBIBERTY) $(WIN32LIBS)
@@ -624,6 +630,10 @@ safe_ctype_h =  $(INCLUDE_DIR)/safe-ctyp
 hashtab_h =	$(INCLUDE_DIR)/hashtab.h
 filenames_h =	$(INCLUDE_DIR)/filenames.h
 
+decimal128_h = $(LIBDECNUMBER_DIR)/dpd/decimal128.h
+decimal64_h = $(LIBDECNUMBER_DIR)/dpd/decimal64.h
+decimal32_h = $(LIBDECNUMBER_DIR)/dpd/decimal32.h
+
 #
 # $BUILD/ headers
 #
@@ -690,6 +700,7 @@ dictionary_h = dictionary.h
 disasm_h = disasm.h
 doublest_h = doublest.h $(floatformat_h)
 dummy_frame_h = dummy-frame.h
+dfp_h = dfp.h
 dwarf2expr_h = dwarf2expr.h
 dwarf2_frame_h = dwarf2-frame.h
 dwarf2loc_h = dwarf2loc.h
@@ -938,7 +949,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $
 	auxv.o \
 	bfd-target.o \
 	blockframe.o breakpoint.o findvar.o regcache.o \
-	charset.o disasm.o dummy-frame.o \
+	charset.o disasm.o dummy-frame.o dfp.o \
 	source.o value.o eval.o valops.o valarith.o valprint.o printcmd.o \
 	block.o symtab.o symfile.o symmisc.o linespec.o dictionary.o \
 	infcall.o \
@@ -1871,7 +1882,7 @@ buildsym.o: buildsym.c $(defs_h) $(bfd_h
 	$(cp_support_h) $(dictionary_h) $(buildsym_h) $(stabsread_h)
 c-exp.o: c-exp.c $(defs_h) $(gdb_string_h) $(expression_h) $(value_h) \
 	$(parser_defs_h) $(language_h) $(c_lang_h) $(bfd_h) $(symfile_h) \
-	$(objfiles_h) $(charset_h) $(block_h) $(cp_support_h)
+	$(objfiles_h) $(charset_h) $(block_h) $(cp_support_h) $(dfp_h)
 charset.o: charset.c $(defs_h) $(charset_h) $(gdbcmd_h) $(gdb_assert_h) \
 	$(gdb_string_h)
 c-lang.o: c-lang.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \
@@ -1954,6 +1965,7 @@ dsrec.o: dsrec.c $(defs_h) $(serial_h) $
 dummy-frame.o: dummy-frame.c $(defs_h) $(dummy_frame_h) $(regcache_h) \
 	$(frame_h) $(inferior_h) $(gdb_assert_h) $(frame_unwind_h) \
 	$(command_h) $(gdbcmd_h) $(gdb_string_h)
+dfp.o: dfp.c $(defs_h) $(dfp_h) $(decimal128_h) $(decimal64_h) $(decimal32_h)
 dwarf2expr.o: dwarf2expr.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(value_h) \
 	$(gdbcore_h) $(elf_dwarf2_h) $(dwarf2expr_h)
 dwarf2-frame.o: dwarf2-frame.c $(defs_h) $(dwarf2expr_h) $(elf_dwarf2_h) \
@@ -2815,11 +2827,11 @@ valops.o: valops.c $(defs_h) $(symtab_h)
 valprint.o: valprint.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
 	$(value_h) $(gdbcore_h) $(gdbcmd_h) $(target_h) $(language_h) \
 	$(annotate_h) $(valprint_h) $(floatformat_h) $(doublest_h) \
-	$(exceptions_h)
+	$(exceptions_h) $(dfp_h)
 value.o: value.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
 	$(value_h) $(gdbcore_h) $(command_h) $(gdbcmd_h) $(target_h) \
 	$(language_h) $(demangle_h) $(doublest_h) \
-	$(gdb_assert_h) $(regcache_h) $(block_h)
+	$(gdb_assert_h) $(regcache_h) $(block_h) $(dfp_h)
 varobj.o: varobj.c $(defs_h) $(exceptions_h) $(value_h) $(expression_h) \
 	$(frame_h) $(language_h) $(wrapper_h) $(gdbcmd_h) $(block_h) \
 	$(gdb_assert_h) $(gdb_string_h) $(varobj_h) $(vec_h)
Index: gdb/dfp.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb/dfp.c	2007-10-15 14:35:06.000000000 -0200
@@ -0,0 +1,113 @@
+/* Decimal floating point support for GDB.
+
+   Copyright 2007 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+
+/* The order of the following headers is important for making sure
+   decNumber structure is large enough to hold decimal128 digits.  */
+
+#include "dpd/decimal128.h"
+#include "dpd/decimal64.h"
+#include "dpd/decimal32.h"
+
+/* In GDB, we are using an array of gdb_byte to represent decimal values.
+   They are stored in host byte order.  This routine does the conversion if
+   the target byte order is different.  */
+static void
+match_endianness (const gdb_byte *from, int len, gdb_byte *to)
+{
+  int i;
+
+#if WORDS_BIGENDIAN
+#define OPPOSITE_BYTE_ORDER BFD_ENDIAN_LITTLE
+#else
+#define OPPOSITE_BYTE_ORDER BFD_ENDIAN_BIG
+#endif
+
+  if (gdbarch_byte_order (current_gdbarch) == OPPOSITE_BYTE_ORDER)
+    for (i = 0; i < len; i++)
+      to[i] = from[len - i - 1];
+  else
+    for (i = 0; i < len; i++)
+      to[i] = from[i];
+
+  return;
+}
+
+/* Convert decimal type to its string representation.  LEN is the length
+   of the decimal type, 4 bytes for decimal32, 8 bytes for decimal64 and
+   16 bytes for decimal128.  */
+void
+decimal_to_string (const gdb_byte *decbytes, int len, char *s)
+{
+  gdb_byte dec[16];
+
+  match_endianness (decbytes, len, dec);
+  switch (len)
+    {
+      case 4:
+        decimal32ToString ((decimal32 *) dec, s);
+        break;
+      case 8:
+        decimal64ToString ((decimal64 *) dec, s);
+        break;
+      case 16:
+        decimal128ToString ((decimal128 *) dec, s);
+        break;
+      default:
+        error (_("Unknown decimal floating point type.\n"));
+        break;
+    }
+}
+
+/* Convert the string form of a decimal value to its decimal representation.
+   LEN is the length of the decimal type, 4 bytes for decimal32, 8 bytes for
+   decimal64 and 16 bytes for decimal128.  */
+int
+decimal_from_string (gdb_byte *decbytes, int len, const char *string)
+{
+  decContext set;
+  gdb_byte dec[16];
+
+  switch (len)
+    {
+      case 4:
+        decContextDefault (&set, DEC_INIT_DECIMAL32);
+        set.traps = 0;
+        decimal32FromString ((decimal32 *) dec, string, &set);
+        break;
+      case 8:
+        decContextDefault (&set, DEC_INIT_DECIMAL64);
+        set.traps = 0;
+        decimal64FromString ((decimal64 *) dec, string, &set);
+        break;
+      case 16:
+        decContextDefault (&set, DEC_INIT_DECIMAL128);
+        set.traps = 0;
+        decimal128FromString ((decimal128 *) dec, string, &set);
+        break;
+      default:
+        error (_("Unknown decimal floating point type.\n"));
+        break;
+    }
+
+  match_endianness (dec, len, decbytes);
+
+  return 1;
+}
Index: gdb/dfp.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb/dfp.h	2007-10-15 14:35:06.000000000 -0200
@@ -0,0 +1,35 @@
+/* Decimal floating point support for GDB.
+
+   Copyright 2007 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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 this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Decimal floating point is one of the extension to IEEE 754, which is
+   described in http://grouper.ieee.org/groups/754/revision.html and
+   http://www2.hursley.ibm.com/decimal/.  It completes binary floating
+   point by representing floating point more exactly.  */
+
+#ifndef DFP_H
+#define DFP_H
+
+/* When using decimal128, this is the maximum string length + 1
+ * (value comes from libdecnumber's DECIMAL128_String constant).  */
+#define MAX_DECIMAL_STRING  43
+
+extern void decimal_to_string (const gdb_byte *, int, char *);
+extern int decimal_from_string (gdb_byte *, int, const char *);
+
+#endif
Index: gdb/configure.ac
===================================================================
--- gdb/configure.ac.orig	2007-10-01 14:20:02.000000000 -0300
+++ gdb/configure.ac	2007-10-15 14:35:06.000000000 -0200
@@ -496,6 +496,7 @@ AC_CHECK_TYPES(uintptr_t, [], [], [#incl
 
 AC_C_CONST
 AC_C_INLINE
+AC_C_BIGENDIAN
 
 # ------------------------------ #
 # Checks for library functions.  #

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 2/4] decimal floating point types
  2007-10-11 16:00   ` Daniel Jacobowitz
@ 2007-10-15 18:12     ` Thiago Jung Bauermann
  2007-10-24 20:11       ` Daniel Jacobowitz
  0 siblings, 1 reply; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-15 18:12 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1888 bytes --]

On Thu, 2007-10-11 at 11:57 -0400, Daniel Jacobowitz wrote: 
> On Thu, Sep 20, 2007 at 06:54:12PM -0300, Thiago Jung Bauermann wrote:
> > +    case DW_ATE_decimal_float:
> > +      if (size == 16)
> > +	{
> > +	  type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_DECFLOAT, cu);
> > +	}
> > +      else if (size == 8)
> > +	{
> > +	  type = dwarf2_fundamental_type (objfile, FT_EXT_PREC_DECFLOAT, cu);
> > +	}
> > + else 
> > +	type = dwarf2_fundamental_type (objfile, FT_DECFLOAT, cu);
> > +      return type;
> 
> You don't need a bunch of those extra braces.

Right. Removed.

> > +  /* The following three are about decimal floating point types, which
> > +     are 32-bits, 64-bits and 128-bits respectively.  */
> > +  builtin_type->builtin_decfloat =
> > +    init_type (TYPE_CODE_DECFLOAT, 32 / 8,
> > +	        0,
> > +	       "decimal float", (struct objfile *) NULL);
> 
> I think our convention is to put the equals sign after the line break.

Most of the types in gdbtypes_post_init have the equals sign at the end
of the line, so this code was being consistent with them. But you're
right, the GNU Coding Standards say to break a line before an operator.
Changed.

> >  void
> > +print_decimal_floating (const gdb_byte *valaddr, struct type *type,
> > +			struct ui_file *stream)
> > +{
> > +  char decstr[128];
> > +  unsigned len = TYPE_LENGTH (type);
> > +
> > +  decimal_to_string (valaddr, len, decstr);
> > +  fputs_filtered (decstr, stream);
> > +  return;
> > +}
> 
> Does the libdecnumber API specify that 128 bytes is enough?  If so
> this should be a constant in dfp.h.

Actually, I just found out that libdecnumber specifies a lower limit: 43
(including the '\0' at the end), so I created a MAX_DECIMAL_STRING
constant in dfp.h and use that here.

What do you think of this version?
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center

[-- Attachment #2: decfloat-types.diff --]
[-- Type: text/x-patch, Size: 8234 bytes --]

Subject: decimal floating point types

2007-10-15  Wu Zhou  <woodzltc@cn.ibm.com> 
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* c-lang.c (c_create_fundamental_type): Create fundamental
	types for DFP.
	* c-typeprint.c (c_type_print_varspec_prefix): Add
	TYPE_CODE_DECFLOAT to no prefix needed case.
	(c_type_print_varspec_suffix): Add TYPE_CODE_DECFLOAT to no
	suffix needed case.
	* c-valprint.c (c_val_print): Call print_decimal_floating to
	print DFP values.
	* dwarf2read.c (read_base_type): Read DW_ATE_decimal_float
	attribute code and return TYPE_CODE_DECFLOAT.
	(dwarf_base_type): Set dwarf2_fundamental_type for DFP values.
	* gdbtypes.c (gdbtypes_post_init): Initialize builtin_decfloat,
	builtin_decdouble and builtin_declong. 
	* gdbtypes.h (enum type_code): Add TYPE_CODE_DECFLOAT as a
	type code for DFP.
	(FT_DECFLOAT, FT_DBL_PREC_DECFLOAT, FT_EXT_PREC_DECFLOAT): New
	types, for decimal floating point.
	(FT_NUM_MEMBERS):  Increment, new types added.
	(struct builtin_type): Add builtin_decfloat, builtin_decdouble
	and builtin_declong.
	* valprint.c (print_decimal_floating): New function to print DFP
	values.
	* value.h (print_decimal_floating): Prototype.

Index: gdb/c-lang.c
===================================================================
--- gdb/c-lang.c.orig	2007-09-25 23:45:17.000000000 -0300
+++ gdb/c-lang.c	2007-10-15 14:35:18.000000000 -0200
@@ -325,6 +325,21 @@ c_create_fundamental_type (struct objfil
 			  / TARGET_CHAR_BIT,
 			0, "long double", objfile);
       break;
+    case FT_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			32 / 8,
+			0, "decimal float", objfile);
+      break;
+    case FT_DBL_PREC_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			64 / 8,
+			0, "decimal double", objfile);
+      break;
+    case FT_EXT_PREC_DECFLOAT:
+      type = init_type (TYPE_CODE_DECFLOAT,
+			128 / 8,
+			0, "decimal long double", objfile);
+      break;
     case FT_COMPLEX:
       type = init_type (TYPE_CODE_FLT,
 			2 * gdbarch_float_bit (current_gdbarch)
Index: gdb/c-valprint.c
===================================================================
--- gdb/c-valprint.c.orig	2007-09-25 23:45:18.000000000 -0300
+++ gdb/c-valprint.c	2007-10-15 14:35:18.000000000 -0200
@@ -474,6 +474,13 @@ c_val_print (struct type *type, const gd
 	}
       break;
 
+    case TYPE_CODE_DECFLOAT:
+      if (format)
+	print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
+      else
+	print_decimal_floating (valaddr + embedded_offset, type, stream);
+      break;
+
     case TYPE_CODE_VOID:
       fprintf_filtered (stream, "void");
       break;
Index: gdb/dwarf2read.c
===================================================================
--- gdb/dwarf2read.c.orig	2007-09-27 20:26:54.000000000 -0300
+++ gdb/dwarf2read.c	2007-10-15 14:35:18.000000000 -0200
@@ -4869,6 +4869,9 @@ read_base_type (struct die_info *die, st
 	case DW_ATE_complex_float:
 	  code = TYPE_CODE_COMPLEX;
 	  break;
+	case DW_ATE_decimal_float:
+	  code = TYPE_CODE_DECFLOAT;
+	  break;
 	case DW_ATE_float:
 	  code = TYPE_CODE_FLT;
 	  break;
@@ -7756,6 +7759,14 @@ dwarf_base_type (int encoding, int size,
 	  type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu);
 	}
       return type;
+    case DW_ATE_decimal_float:
+      if (size == 16)
+	type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_DECFLOAT, cu);
+      else if (size == 8)
+	type = dwarf2_fundamental_type (objfile, FT_EXT_PREC_DECFLOAT, cu);
+      else
+	type = dwarf2_fundamental_type (objfile, FT_DECFLOAT, cu);
+      return type;
     case DW_ATE_signed:
       switch (size)
 	{
Index: gdb/gdbtypes.c
===================================================================
--- gdb/gdbtypes.c.orig	2007-10-09 11:22:47.000000000 -0300
+++ gdb/gdbtypes.c	2007-10-15 14:35:18.000000000 -0200
@@ -3506,6 +3506,21 @@ gdbtypes_post_init (struct gdbarch *gdba
 	       0,
 	       "bool", (struct objfile *) NULL);
 
+  /* The following three are about decimal floating point types, which
+     are 32-bits, 64-bits and 128-bits respectively.  */
+  builtin_type->builtin_decfloat
+    = init_type (TYPE_CODE_DECFLOAT, 32 / 8,
+	        0,
+	       "decimal float", (struct objfile *) NULL);
+  builtin_type->builtin_decdouble
+    = init_type (TYPE_CODE_DECFLOAT, 64 / 8,
+	       0,
+	       "decimal double", (struct objfile *) NULL);
+  builtin_type->builtin_declong
+    = init_type (TYPE_CODE_DECFLOAT, 128 / 8,
+	       0,
+	       "decimal long double", (struct objfile *) NULL);
+
   /* Pointer/Address types.  */
 
   /* NOTE: on some targets, addresses and pointers are not necessarily
Index: gdb/gdbtypes.h
===================================================================
--- gdb/gdbtypes.h.orig	2007-09-25 23:45:18.000000000 -0300
+++ gdb/gdbtypes.h	2007-10-15 14:35:18.000000000 -0200
@@ -65,7 +65,12 @@ struct block;
 #define FT_UNSIGNED_BYTE	27
 #define FT_TEMPLATE_ARG		28
 
-#define FT_NUM_MEMBERS		29	/* Highest FT_* above, plus one. */
+/* The following three fundamental types are for decimal floating point.  */
+#define FT_DECFLOAT		29
+#define FT_DBL_PREC_DECFLOAT	30
+#define FT_EXT_PREC_DECFLOAT	31
+
+#define FT_NUM_MEMBERS		32	/* Highest FT_* above, plus one. */
 
 /* Some macros for char-based bitfields.  */
 
@@ -169,7 +174,9 @@ enum type_code
     TYPE_CODE_TEMPLATE,		/* C++ template */
     TYPE_CODE_TEMPLATE_ARG,	/* C++ template arg */
 
-    TYPE_CODE_NAMESPACE		/* C++ namespace.  */
+    TYPE_CODE_NAMESPACE,	/* C++ namespace.  */
+
+    TYPE_CODE_DECFLOAT		/* Decimal floating point.  */
   };
 
 /* For now allow source to use TYPE_CODE_CLASS for C++ classes, as an
@@ -1041,6 +1048,9 @@ struct builtin_type
   struct type *builtin_bool;
   struct type *builtin_long_long;
   struct type *builtin_unsigned_long_long;
+  struct type *builtin_decfloat;
+  struct type *builtin_decdouble;
+  struct type *builtin_declong;
 };
 
 /* Return the type table for the specified architecture.  */
Index: gdb/valprint.c
===================================================================
--- gdb/valprint.c.orig	2007-09-25 23:45:23.000000000 -0300
+++ gdb/valprint.c	2007-10-15 14:35:18.000000000 -0200
@@ -33,6 +33,7 @@
 #include "floatformat.h"
 #include "doublest.h"
 #include "exceptions.h"
+#include "dfp.h"
 
 #include <errno.h>
 
@@ -506,6 +507,18 @@ print_floating (const gdb_byte *valaddr,
 }
 
 void
+print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+			struct ui_file *stream)
+{
+  char decstr[MAX_DECIMAL_STRING];
+  unsigned len = TYPE_LENGTH (type);
+
+  decimal_to_string (valaddr, len, decstr);
+  fputs_filtered (decstr, stream);
+  return;
+}
+
+void
 print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
 		    unsigned len)
 {
Index: gdb/value.h
===================================================================
--- gdb/value.h.orig	2007-10-15 14:25:14.000000000 -0200
+++ gdb/value.h	2007-10-15 14:35:46.000000000 -0200
@@ -492,6 +492,9 @@ extern void print_longest (struct ui_fil
 extern void print_floating (const gdb_byte *valaddr, struct type *type,
 			    struct ui_file *stream);
 
+extern void print_decimal_floating (const gdb_byte *valaddr, struct type *type,
+				    struct ui_file *stream);
+
 extern int value_print (struct value *val, struct ui_file *stream, int format,
 			enum val_prettyprint pretty);
 
Index: gdb/c-typeprint.c
===================================================================
--- gdb/c-typeprint.c.orig	2007-09-25 23:45:18.000000000 -0300
+++ gdb/c-typeprint.c	2007-10-15 14:35:18.000000000 -0200
@@ -277,6 +277,7 @@ c_type_print_varspec_prefix (struct type
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_TEMPLATE:
     case TYPE_CODE_NAMESPACE:
+    case TYPE_CODE_DECFLOAT:
       /* These types need no prefix.  They are listed here so that
          gcc -Wall will reveal any types that haven't been handled.  */
       break;
@@ -599,6 +600,7 @@ c_type_print_varspec_suffix (struct type
     case TYPE_CODE_COMPLEX:
     case TYPE_CODE_TEMPLATE:
     case TYPE_CODE_NAMESPACE:
+    case TYPE_CODE_DECFLOAT:
       /* These types do not need a suffix.  They are listed so that
          gcc -Wall will report types that may not have been considered.  */
       break;

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 3/4] decimal floating point support for expressions
  2007-10-11 16:18   ` Daniel Jacobowitz
@ 2007-10-15 18:12     ` Thiago Jung Bauermann
  2007-10-24 20:12       ` Daniel Jacobowitz
  0 siblings, 1 reply; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-15 18:12 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1498 bytes --]

On Thu, 2007-10-11 at 12:16 -0400, Daniel Jacobowitz wrote: 
> On Thu, Sep 20, 2007 at 06:54:13PM -0300, Thiago Jung Bauermann wrote:
> > +	  putithere->typed_val_decfloat.type =
> > +	    builtin_type (current_gdbarch)->builtin_decfloat;
> 
> Equals sign on next line please.

Done.

> > @@ -1376,6 +1376,20 @@ value_neg (struct value *arg1)
> >  
> >    type = check_typedef (value_type (arg1));
> >  
> > +  if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
> > +    {
> > +      struct value *val = allocate_value (result_type);
> > +      int len = TYPE_LENGTH (type);
> > +      gdb_byte *decbytes = (gdb_byte *) value_contents (arg1);
> > +
> > +      if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_LITTLE)
> > +	decbytes[len-1] = decbytes[len - 1] | 0x80;
> > +      else
> > +	decbytes[0] = decbytes[0] | 0x80;
> > +      memcpy (value_contents_raw (val), decbytes, 16);
> > +      return val;
> > +    }
> > +
> 
> The reason we allocate a new value is to leave the existing value
> unchanged, so you shouldn't modify the contents of arg1.  The casts
> are probably there because otherwise GCC complained you were removing
> a const.  Don't do that :-)

Oops, that was indeed naughty. What about the version in this patch? 

> > +#include "dfp.h"
> 
> If you add an #include, update Makefile.in.

Oops, forgot about this dependency. Updated first patch in series to add
$(dfp_h) dependency to c-exp.o target.
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center

[-- Attachment #2: expressions.diff --]
[-- Type: text/x-patch, Size: 9392 bytes --]

Subject: decimal floating point support for expressions

2007-10-15  Wu Zhou  <woodzltc@cn.ibm.com> 
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* c-exp.y (YYSTYPE): Add typed_val_decfloat for decimal
	floating point in YYSTYPE union.
	(DECFLOAT) Add token and expression element handling code.
	(parse_number): Parse DFP constants, which end with suffix 'df',
	'dd' or 'dl'.  Return DECFLOAT.
	* eval.c (evaluate_subexp_standard): Call value_from_decfloat to
	handle OP_DECFLOAT.
	* expression.h (enum exp_opcode): Add an opcode (OP_DECFLOAT)
	for DFP constants.
	(union exp_element): Add decfloatconst to represent DFP
	elements, which is 16 bytes by default.
	* parse.c (write_exp_elt_decfloatcst): New function to write a
	decimal float const into the expression.
	(operator_length_standard): Set operator length for OP_DECFLOAT
	to 4.
	* parser-defs.h (write_exp_elt_decfloatcst): Prototype.
	* valarith.c (value_neg): Add code to handle the negation
	operation of DFP values.
	* value.c (value_from_decfloat): New function to get the value
	from a decimal floating point.
	* value.h (value_from_decfloat): Prototype.

Index: gdb/c-exp.y
===================================================================
--- gdb/c-exp.y.orig	2007-09-25 23:45:17.000000000 -0300
+++ gdb/c-exp.y	2007-10-15 14:35:22.000000000 -0200
@@ -52,6 +52,7 @@ Boston, MA 02110-1301, USA.  */
 #include "charset.h"
 #include "block.h"
 #include "cp-support.h"
+#include "dfp.h"
 
 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
    as well as gratuitiously global symbol names, so we can have multiple
@@ -130,6 +131,10 @@ void yyerror (char *);
       DOUBLEST dval;
       struct type *type;
     } typed_val_float;
+    struct {
+      gdb_byte val[16];
+      struct type *type;
+    } typed_val_decfloat;
     struct symbol *sym;
     struct type *tval;
     struct stoken sval;
@@ -162,6 +167,7 @@ static int parse_number (char *, int, in
 
 %token <typed_val_int> INT
 %token <typed_val_float> FLOAT
+%token <typed_val_decfloat> DECFLOAT
 
 /* Both NAME and TYPENAME tokens represent symbols in the input,
    and both convey their data as strings.
@@ -496,6 +502,13 @@ exp	:	FLOAT
 			  write_exp_elt_opcode (OP_DOUBLE); }
 	;
 
+exp	:	DECFLOAT
+			{ write_exp_elt_opcode (OP_DECFLOAT);
+			  write_exp_elt_type ($1.type);
+			  write_exp_elt_decfloatcst ($1.val);
+			  write_exp_elt_opcode (OP_DECFLOAT); }
+	;
+
 exp	:	variable
 	;
 
@@ -1077,6 +1090,40 @@ parse_number (p, len, parsed_float, puti
       char saved_char = p[len];
 
       p[len] = 0;	/* null-terminate the token */
+
+      /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
+         point.  Return DECFLOAT.  */
+
+      if (p[len - 2] == 'd' && p[len - 1] == 'f')
+	{
+	  p[len - 2] = '\0';
+	  putithere->typed_val_decfloat.type
+	    = builtin_type (current_gdbarch)->builtin_decfloat;
+	  decimal_from_string (putithere->typed_val_decfloat.val, 4, p);
+	  p[len] = saved_char;
+	  return (DECFLOAT);
+	}
+
+      if (p[len - 2] == 'd' && p[len - 1] == 'd')
+	{
+	  p[len - 2] = '\0';
+	  putithere->typed_val_decfloat.type
+	    = builtin_type (current_gdbarch)->builtin_decdouble;
+	  decimal_from_string (putithere->typed_val_decfloat.val, 8, p);
+	  p[len] = saved_char;
+	  return (DECFLOAT);
+	}
+
+      if (p[len - 2] == 'd' && p[len - 1] == 'l')
+	{
+	  p[len - 2] = '\0';
+	  putithere->typed_val_decfloat.type
+	    = builtin_type (current_gdbarch)->builtin_declong;
+	  decimal_from_string (putithere->typed_val_decfloat.val, 16, p);
+	  p[len] = saved_char;
+	  return (DECFLOAT);
+	}
+
       num = sscanf (p, DOUBLEST_SCAN_FORMAT "%s",
 		    &putithere->typed_val_float.dval, s);
       p[len] = saved_char;	/* restore the input stream */
Index: gdb/eval.c
===================================================================
--- gdb/eval.c.orig	2007-10-15 14:25:14.000000000 -0200
+++ gdb/eval.c	2007-10-15 14:35:22.000000000 -0200
@@ -456,6 +456,11 @@ evaluate_subexp_standard (struct type *e
       return value_from_double (exp->elts[pc + 1].type,
 				exp->elts[pc + 2].doubleconst);
 
+    case OP_DECFLOAT:
+      (*pos) += 3;
+      return value_from_decfloat (expect_type, exp->elts[pc + 1].type,
+				exp->elts[pc + 2].decfloatconst);
+
     case OP_VAR_VALUE:
       (*pos) += 3;
       if (noside == EVAL_SKIP)
Index: gdb/expression.h
===================================================================
--- gdb/expression.h.orig	2007-09-25 23:45:18.000000000 -0300
+++ gdb/expression.h	2007-10-15 14:35:22.000000000 -0200
@@ -328,6 +328,11 @@ enum exp_opcode
     /* A F90 array range operator (for "exp:exp", "exp:", ":exp" and ":").  */
     OP_F90_RANGE,
 
+    /* OP_DECFLOAT is followed by a type pointer in the next exp_element
+       and a dec long constant value in the following exp_element.
+       Then comes another OP_DECFLOAT.  */
+    OP_DECFLOAT,
+
      /* First extension operator.  Individual language modules define
         extra operators they need as constants with values 
         OP_LANGUAGE_SPECIFIC0 + k, for k >= 0, using a separate 
@@ -355,6 +360,7 @@ union exp_element
     struct symbol *symbol;
     LONGEST longconst;
     DOUBLEST doubleconst;
+    gdb_byte decfloatconst[16];
     /* Really sizeof (union exp_element) characters (or less for the last
        element of a string).  */
     char string;
Index: gdb/parse.c
===================================================================
--- gdb/parse.c.orig	2007-10-01 14:20:02.000000000 -0300
+++ gdb/parse.c	2007-10-15 14:35:22.000000000 -0200
@@ -248,6 +248,18 @@ write_exp_elt_dblcst (DOUBLEST expelt)
 }
 
 void
+write_exp_elt_decfloatcst (gdb_byte expelt[16])
+{
+  union exp_element tmp;
+  int index;
+
+  for (index = 0; index < 16; index++)
+    tmp.decfloatconst[index] = expelt[index];
+
+  write_exp_elt (tmp);
+}
+
+void
 write_exp_elt_type (struct type *expelt)
 {
   union exp_element tmp;
@@ -718,6 +730,7 @@ operator_length_standard (struct express
 
     case OP_LONG:
     case OP_DOUBLE:
+    case OP_DECFLOAT:
     case OP_VAR_VALUE:
       oplen = 4;
       break;
Index: gdb/parser-defs.h
===================================================================
--- gdb/parser-defs.h.orig	2007-09-25 23:45:19.000000000 -0300
+++ gdb/parser-defs.h	2007-10-15 14:35:22.000000000 -0200
@@ -119,6 +119,8 @@ extern void write_exp_elt_longcst (LONGE
 
 extern void write_exp_elt_dblcst (DOUBLEST);
 
+extern void write_exp_elt_decfloatcst (gdb_byte *);
+
 extern void write_exp_elt_type (struct type *);
 
 extern void write_exp_elt_intern (struct internalvar *);
Index: gdb/valarith.c
===================================================================
--- gdb/valarith.c.orig	2007-09-25 23:45:23.000000000 -0300
+++ gdb/valarith.c	2007-10-15 14:35:22.000000000 -0200
@@ -1376,6 +1376,23 @@ value_neg (struct value *arg1)
 
   type = check_typedef (value_type (arg1));
 
+  if (TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
+    {
+      struct value *val = allocate_value (result_type);
+      int len = TYPE_LENGTH (type);
+      gdb_byte decbytes[16];  /* a decfloat is at most 128 bits long */
+
+      memcpy(decbytes, value_contents(arg1), len);
+
+      if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_LITTLE)
+	decbytes[len-1] = decbytes[len - 1] | 0x80;
+      else
+	decbytes[0] = decbytes[0] | 0x80;
+
+      memcpy (value_contents_raw (val), decbytes, len);
+      return val;
+    }
+
   if (TYPE_CODE (type) == TYPE_CODE_FLT)
     return value_from_double (result_type, -value_as_double (arg1));
   else if (is_integral_type (type))
Index: gdb/value.c
===================================================================
--- gdb/value.c.orig	2007-10-15 14:25:14.000000000 -0200
+++ gdb/value.c	2007-10-15 14:35:22.000000000 -0200
@@ -34,6 +34,7 @@
 #include "gdb_assert.h"
 #include "regcache.h"
 #include "block.h"
+#include "dfp.h"
 
 /* Prototypes for exported functions. */
 
@@ -1642,6 +1643,27 @@ value_from_double (struct type *type, DO
 }
 
 struct value *
+value_from_decfloat (struct type *expect_type, struct type *type,
+		      gdb_byte decbytes[16])
+{
+  struct value *val = allocate_value (type);
+  int len = TYPE_LENGTH (type);
+
+  if (expect_type)
+    {
+      int expect_len = TYPE_LENGTH (expect_type);
+      char decstr[128];
+      int real_len;
+
+      decimal_to_string (decbytes, len, decstr);
+      decimal_from_string (decbytes, expect_len, decstr);
+    }
+
+  memcpy (value_contents_raw (val), decbytes, len);
+  return val;
+}
+
+struct value *
 coerce_ref (struct value *arg)
 {
   struct type *value_type_arg_tmp = check_typedef (value_type (arg));
Index: gdb/value.h
===================================================================
--- gdb/value.h.orig	2007-10-15 14:35:18.000000000 -0200
+++ gdb/value.h	2007-10-15 14:35:22.000000000 -0200
@@ -280,6 +280,9 @@ extern void pack_long (gdb_byte *buf, st
 extern struct value *value_from_longest (struct type *type, LONGEST num);
 extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr);
 extern struct value *value_from_double (struct type *type, DOUBLEST num);
+extern struct value *value_from_decfloat (struct type *expect_type,
+					  struct type *type,
+					  gdb_byte decbytes[16]);
 extern struct value *value_from_string (char *string);
 
 extern struct value *value_at (struct type *type, CORE_ADDR addr);

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 4/4] decimal floating point testcases
  2007-10-11 16:19   ` Daniel Jacobowitz
@ 2007-10-15 18:12     ` Thiago Jung Bauermann
  2007-10-25 18:22       ` Thiago Jung Bauermann
  0 siblings, 1 reply; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-15 18:12 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches


On Thu, 2007-10-11 at 12:17 -0400, Daniel Jacobowitz wrote: 
> On Thu, Sep 20, 2007 at 06:54:14PM -0300, Thiago Jung Bauermann wrote:
> > +# This file is part of the gdb testsuite.  It is intended to test that
> > +# gdb could correctly hane decimal floating point introduced in IEEE 754R.
> 
> "handle".  Otherwise looks fine (except for GPLv3 copyright updates).

Done, thanks! Will commit with other patches.
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 1/4] libdecnumber support
  2007-10-11 16:07     ` Daniel Jacobowitz
@ 2007-10-15 18:32       ` Thiago Jung Bauermann
  0 siblings, 0 replies; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-15 18:32 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

On Thu, 2007-10-11 at 12:00 -0400, Daniel Jacobowitz wrote: 
> Oh, I also noticed some GPLv2 copyright headers; please update to
> GPLv3.

Yeah, forgot to update headers. This is done in the new patches I'm
posting now, for the new files created by this patch series.
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 1/4] libdecnumber support
  2007-10-15 18:11     ` Thiago Jung Bauermann
@ 2007-10-15 18:38       ` Daniel Jacobowitz
  2007-10-25 18:23         ` Thiago Jung Bauermann
  0 siblings, 1 reply; 23+ messages in thread
From: Daniel Jacobowitz @ 2007-10-15 18:38 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches

On Mon, Oct 15, 2007 at 04:10:57PM -0200, Thiago Jung Bauermann wrote:
> Ok, I'm using it now. When I run autoreconf inside the src/gdb
> directory, I get the following:
> 
> $ autoreconf
> autoreconf: cannot create `cd $srcdir;pwd`/../../../..: No such file or
> directory
> autoreconf: cannot create `cd $srcdir;pwd`/../../..: No such file or
> directory
> autoreconf: cannot create `cd $srcdir;pwd`/..: No such file or directory
> $ echo $?
> 0
> 
> Is this a problem? Things still seem to work fine. I used autoconf
> version 2.61.

I have not tried autoreconf.  It's helpful to use the same version
that was used last time, when not deliberately upgrading autoconf;
in this case that's 2.59.  I keep a separate installation of it around
for this purpose, and run autoconf + autoheader by hand.

> > > +        break;
> > > +      default:
> > > +	free (dec);
> > 
> > Spaces and tabs mixed up?  xfree, like xmalloc.
> 
> Fixed. No '\t' in the file now. By the way, what's the policy in GDB
> w.r.t. tabs and spaces? Never use tabs?

Our policy is to always use leading tabs; so whenever you have eight
spaces at the line it becomes a tab.  This comes, of course, from
emacs :-)

Aside from leading spaces, and using autoconf 2.59, this version is
OK.  I added libdecnumber last week, so all should be ready now.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 2/4] decimal floating point types
  2007-10-15 18:12     ` Thiago Jung Bauermann
@ 2007-10-24 20:11       ` Daniel Jacobowitz
  2007-10-25 18:24         ` Thiago Jung Bauermann
  0 siblings, 1 reply; 23+ messages in thread
From: Daniel Jacobowitz @ 2007-10-24 20:11 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches

On Mon, Oct 15, 2007 at 04:11:49PM -0200, Thiago Jung Bauermann wrote:
> 2007-10-15  Wu Zhou  <woodzltc@cn.ibm.com> 
> 	    Thiago Jung Bauermann  <bauerman@br.ibm.com>
> 
> 	* c-lang.c (c_create_fundamental_type): Create fundamental
> 	types for DFP.
> 	* c-typeprint.c (c_type_print_varspec_prefix): Add
> 	TYPE_CODE_DECFLOAT to no prefix needed case.
> 	(c_type_print_varspec_suffix): Add TYPE_CODE_DECFLOAT to no
> 	suffix needed case.
> 	* c-valprint.c (c_val_print): Call print_decimal_floating to
> 	print DFP values.
> 	* dwarf2read.c (read_base_type): Read DW_ATE_decimal_float
> 	attribute code and return TYPE_CODE_DECFLOAT.
> 	(dwarf_base_type): Set dwarf2_fundamental_type for DFP values.
> 	* gdbtypes.c (gdbtypes_post_init): Initialize builtin_decfloat,
> 	builtin_decdouble and builtin_declong. 
> 	* gdbtypes.h (enum type_code): Add TYPE_CODE_DECFLOAT as a
> 	type code for DFP.
> 	(FT_DECFLOAT, FT_DBL_PREC_DECFLOAT, FT_EXT_PREC_DECFLOAT): New
> 	types, for decimal floating point.
> 	(FT_NUM_MEMBERS):  Increment, new types added.
> 	(struct builtin_type): Add builtin_decfloat, builtin_decdouble
> 	and builtin_declong.
> 	* valprint.c (print_decimal_floating): New function to print DFP
> 	values.
> 	* value.h (print_decimal_floating): Prototype.

This version looks good to me.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 3/4] decimal floating point support for expressions
  2007-10-15 18:12     ` Thiago Jung Bauermann
@ 2007-10-24 20:12       ` Daniel Jacobowitz
  2007-10-25 18:40         ` Thiago Jung Bauermann
  0 siblings, 1 reply; 23+ messages in thread
From: Daniel Jacobowitz @ 2007-10-24 20:12 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches

On Mon, Oct 15, 2007 at 04:12:12PM -0200, Thiago Jung Bauermann wrote:
> Subject: decimal floating point support for expressions
> 
> 2007-10-15  Wu Zhou  <woodzltc@cn.ibm.com> 
> 	    Thiago Jung Bauermann  <bauerman@br.ibm.com>
> 
> 	* c-exp.y (YYSTYPE): Add typed_val_decfloat for decimal
> 	floating point in YYSTYPE union.
> 	(DECFLOAT) Add token and expression element handling code.
> 	(parse_number): Parse DFP constants, which end with suffix 'df',
> 	'dd' or 'dl'.  Return DECFLOAT.
> 	* eval.c (evaluate_subexp_standard): Call value_from_decfloat to
> 	handle OP_DECFLOAT.
> 	* expression.h (enum exp_opcode): Add an opcode (OP_DECFLOAT)
> 	for DFP constants.
> 	(union exp_element): Add decfloatconst to represent DFP
> 	elements, which is 16 bytes by default.
> 	* parse.c (write_exp_elt_decfloatcst): New function to write a
> 	decimal float const into the expression.
> 	(operator_length_standard): Set operator length for OP_DECFLOAT
> 	to 4.
> 	* parser-defs.h (write_exp_elt_decfloatcst): Prototype.
> 	* valarith.c (value_neg): Add code to handle the negation
> 	operation of DFP values.
> 	* value.c (value_from_decfloat): New function to get the value
> 	from a decimal floating point.
> 	* value.h (value_from_decfloat): Prototype.

This one looks OK.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 4/4] decimal floating point testcases
  2007-10-15 18:12     ` Thiago Jung Bauermann
@ 2007-10-25 18:22       ` Thiago Jung Bauermann
  0 siblings, 0 replies; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-25 18:22 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches


On Mon, 2007-10-15 at 16:12 -0200, Thiago Jung Bauermann wrote:
> On Thu, 2007-10-11 at 12:17 -0400, Daniel Jacobowitz wrote: 
> > On Thu, Sep 20, 2007 at 06:54:14PM -0300, Thiago Jung Bauermann wrote:
> > > +# This file is part of the gdb testsuite.  It is intended to test that
> > > +# gdb could correctly hane decimal floating point introduced in IEEE 754R.
> > 
> > "handle".  Otherwise looks fine (except for GPLv3 copyright updates).
> 
> Done, thanks! Will commit with other patches.

Commited.
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 1/4] libdecnumber support
  2007-10-15 18:38       ` Daniel Jacobowitz
@ 2007-10-25 18:23         ` Thiago Jung Bauermann
  0 siblings, 0 replies; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-25 18:23 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

On Mon, 2007-10-15 at 14:31 -0400, Daniel Jacobowitz wrote:
> Our policy is to always use leading tabs; so whenever you have eight
> spaces at the line it becomes a tab.  This comes, of course, from
> emacs :-)
> 
> Aside from leading spaces, and using autoconf 2.59, this version is
> OK.  I added libdecnumber last week, so all should be ready now.

Converted to leading tabs, used autoconf 2.59 and commited. Thanks!
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 2/4] decimal floating point types
  2007-10-24 20:11       ` Daniel Jacobowitz
@ 2007-10-25 18:24         ` Thiago Jung Bauermann
  0 siblings, 0 replies; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-25 18:24 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

On Wed, 2007-10-24 at 16:09 -0400, Daniel Jacobowitz wrote:
> This version looks good to me.

Commited. Thanks!
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [patch 3/4] decimal floating point support for expressions
  2007-10-24 20:12       ` Daniel Jacobowitz
@ 2007-10-25 18:40         ` Thiago Jung Bauermann
  0 siblings, 0 replies; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-10-25 18:40 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

On Wed, 2007-10-24 at 16:12 -0400, Daniel Jacobowitz wrote:
> This one looks OK.

Commited. Thanks!
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [patch 4/4] decimal floating point testcases
       [not found] <20070323030737.475073862@br.ibm.com>
@ 2007-03-27 16:30 ` Thiago Jung Bauermann
  0 siblings, 0 replies; 23+ messages in thread
From: Thiago Jung Bauermann @ 2007-03-27 16:30 UTC (permalink / raw)
  To: gdb-patches

plain text document attachment (testcases.diff)
2007-03-23  Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* gdb.base/dfp-exprs.exp: new file adding tests for Decimal
	Floating Point expressions.
	* gdb.base/dfp-test.exp: new file adding tests for Decimal
	Floating Point variables.
	* gdb.base/dfp-test.c: new file containing program with Decimal
	Floating variables, used by gdb.base/dfp-test.exp.

Index: gdb/testsuite/gdb.base/dfp-exprs.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb/testsuite/gdb.base/dfp-exprs.exp	2007-03-13 14:47:56.000000000 -0300
@@ -0,0 +1,95 @@
+# Copyright (C) 2006 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 2 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# This file was written by Wu Zhou. (woodzltc@cn.ibm.com)
+
+# This file is part of the gdb testsuite.  It contains test for evaluating
+# simple decimal floating point (DFP) expression.
+
+if $tracelevel then {
+	strace $tracelevel
+}
+
+proc test_dfp_literals_accepted {} {
+
+    # Test various dfp values, covering 32-bit, 64-bit and 128-bit ones
+
+    # _Decimal32 constants, which can support up to 7 digits
+    gdb_test "p 1.2df" " = 1.2"
+    gdb_test "p -1.2df" " = -1.2"
+    gdb_test "p 1.234567df" " = 1.234567"
+    gdb_test "p -1.234567df" " = -1.234567"
+    gdb_test "p 1234567.df" " = 1234567"
+    gdb_test "p -1234567.df" " = -1234567"
+
+    gdb_test "p 1.2E1df" " = 12"
+    gdb_test "p 1.2E10df" " = 1.2E\\+10"
+    gdb_test "p 1.2E-10df" " = 1.2E-10"
+
+    # The largest exponent for 32-bit dfp value is 96.
+    gdb_test "p 1.2E96df" " = 1.200000E\\+96"
+
+    # _Decimal64 constants, which can support up to 16 digits
+    gdb_test "p 1.2dd" " = 1.2"
+    gdb_test "p -1.2dd" " = -1.2"
+    gdb_test "p 1.234567890123456dd" " = 1.234567890123456"
+    gdb_test "p -1.234567890123456dd" " = -1.234567890123456"
+    gdb_test "p 1234567890123456.dd" " = 1234567890123456"
+    gdb_test "p -1234567890123456.dd" " = -1234567890123456"
+
+    gdb_test "p 1.2E1dd" " = 12"
+    gdb_test "p 1.2E10dd" " = 1.2E\\+10"
+    gdb_test "p 1.2E-10dd" " = 1.2E-10"
+
+    # The largest exponent for 64-bit dfp value is 384.
+    gdb_test "p 1.2E384dd" " = 1.200000000000000E\\+384"
+
+    # _Decimal128 constants, which can support up to 34 digits
+    gdb_test "p 1.2dl" " = 1.2"
+    gdb_test "p -1.2dl" " = -1.2"
+    gdb_test "p 1.234567890123456789012345678901234dl" " = 1.234567890123456789012345678901234"
+    gdb_test "p -1.234567890123456789012345678901234dl" " = -1.234567890123456789012345678901234"
+    gdb_test "p 1234567890123456789012345678901234.dl" " = 1234567890123456789012345678901234"
+    gdb_test "p -1234567890123456789012345678901234.dl" " = -1234567890123456789012345678901234"
+
+    gdb_test "p 1.2E1dl" " = 12"
+    gdb_test "p 1.2E10dl" " = 1.2E\\+10"
+    gdb_test "p 1.2E-10dl" " = 1.2E-10"
+
+    # The largest exponent for 128-bit dfp value is 6144.
+    gdb_test "p 1.2E6144dl" " = 1.200000000000000000000000000000000E\\+6144"
+}
+
+proc test_dfp_arithmetic_expressions {} {
+
+# Arithmetic operations for DFP types are not yet implemented in GDB.
+# These tests are to verify that they will generate expected error messages.
+
+   gdb_test "p 1.4df + 1.2df" "Argument to arithmetic operation not a number or boolean.*"
+   gdb_test "p 1.4df - 1.2df" ".*Argument to arithmetic operation not a number or boolean.*"
+   gdb_test "p 1.4df * 1.2df" "Argument to arithmetic operation not a number or boolean.*"
+   gdb_test "p 1.4df / 1.2df" "Argument to arithmetic operation not a number or boolean.*"
+
+}
+
+# Start with a fresh gdb.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+test_dfp_literals_accepted
+test_dfp_arithmetic_expressions
Index: gdb/testsuite/gdb.base/dfp-test.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb/testsuite/gdb.base/dfp-test.c	2007-03-13 14:47:56.000000000 -0300
@@ -0,0 +1,95 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2006 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 2 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 this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+volatile _Decimal32 d32;
+volatile _Decimal64 d64;
+volatile _Decimal128 d128;
+
+struct decstruct
+{
+  int int4;
+  long long8;
+  _Decimal32 dec32;
+  _Decimal64 dec64;
+  _Decimal128 dec128;
+} ds;
+
+static _Decimal32
+arg0_32 (_Decimal32 arg0, _Decimal32 arg1, _Decimal32 arg2,
+         _Decimal32 arg3, _Decimal32 arg4, _Decimal32 arg5)
+{
+  return arg0;
+}
+
+static _Decimal64
+arg0_64 (_Decimal64 arg0, _Decimal64 arg1, _Decimal64 arg2,
+         _Decimal64 arg3, _Decimal64 arg4, _Decimal64 arg5)
+{
+  return arg0;
+}
+
+static _Decimal128
+arg0_128 (_Decimal128 arg0, _Decimal128 arg1, _Decimal128 arg2,
+         _Decimal128 arg3, _Decimal128 arg4, _Decimal128 arg5)
+{
+  return arg0;
+}
+
+int main()
+{
+  /* An finite 32-bits decimal floating point.  */
+  d32 = 1.2345df;		/* Initialize d32.  */
+
+  /* Non-finite 32-bits decimal floating point: infinity and NaN.  */
+  d32 = __builtin_infd32();	/* Positive infd32.  */
+  d32 = -__builtin_infd32();	/* Negative infd32.  */
+  d32 = __builtin_nand32("");
+
+  /* An finite 64-bits decimal floating point.  */
+  d64 = 1.2345dd;		/* Initialize d64.  */
+
+  /* Non-finite 64-bits decimal floating point: infinity and NaN.  */
+  d64 = __builtin_infd64();	/* Positive infd64.  */
+  d64 = -__builtin_infd64();	/* Negative infd64.  */
+  d64 = __builtin_nand64("");
+
+  /* An finite 128-bits decimal floating point.  */
+  d128 = 1.2345dl;		/* Initialize d128.  */
+
+  /* Non-finite 128-bits decimal floating point: infinity and NaN.  */
+  d128 = __builtin_infd128();	/* Positive infd128.  */
+  d128 = -__builtin_infd128();	/* Negative infd128.  */
+  d128 = __builtin_nand128("");
+
+  /* Functions with decimal floating point as parameter and return value. */
+  d32 = arg0_32 (0.1df, 1.0df, 2.0df, 3.0df, 4.0df, 5.0df);
+  d64 = arg0_64 (0.1dd, 1.0dd, 2.0dd, 3.0dd, 4.0dd, 5.0dd);
+  d128 = arg0_128 (0.1dl, 1.0dl, 2.0dl, 3.0dl, 4.0dl, 5.0dl);
+
+  ds.int4 = 1;
+  ds.long8 = 2;
+  ds.dec32 = 1.2345df;
+  ds.dec64 = 1.2345dd;
+  ds.dec128 = 1.2345dl;
+
+  return 0;	/* Exit point.  */
+}
Index: gdb/testsuite/gdb.base/dfp-test.exp
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gdb/testsuite/gdb.base/dfp-test.exp	2007-03-13 14:47:56.000000000 -0300
@@ -0,0 +1,247 @@
+# Copyright 2006 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 2 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#  This file was written by Wu Zhou. (woodzltc@cn.ibm.com)
+
+# This file is part of the gdb testsuite.  It is intended to test that
+# gdb could correctly hane decimal floating point introduced in IEEE 754R.
+
+proc d32_set_tests {} {
+
+    gdb_test "p d32=123.45df" " = 123.45"
+    gdb_test "p d32=12345.df" " = 12345"
+    gdb_test "p d32=12345.67df" " = 12345.67"
+    gdb_test "p d32=1234567.df" " = 1234567"
+
+    gdb_test "p d32=1.234567E0df" " = 1.234567"
+    gdb_test "p d32=1.234567E10df" " = 1.234567E\\+10"
+    gdb_test "p d32=1.234567E+96df" " = 1.234567E\\+96"
+
+    # Test that gdb could handle the max, normalized min and subnormalized min.
+    gdb_test "p d32=9.999999E96df" " = 9.999999E\\+96"
+    gdb_test "p d32=1.0E-95df" " = 1.0E\\-95"
+    gdb_test "p d32=1.E-101df" " = 1E\\-101"
+    gdb_test "p d32=0.000001E-95df" " = 1E\\-101"
+
+    # Test that gdb could detect coefficient/exponent out of range.
+    # The coefficient out of range will be rounded to its nearest value.
+    # And the exponent out of range will be handled as infinity.
+    gdb_test "p d32=1.2345678df" " = 1.234568" "1.2345678 is rounded to 1.234568"
+    gdb_test "p d32=1.0E-101df" " = 1E-101" "1.0E-101 is rounded to 1E-101"
+    gdb_test "p d32=1.234567E+97df" " = Infinity" "1.234567E+97 is Infinity"
+
+    # Test that gdb could detect the errors in the string representation of _Decimal32
+    gdb_test "p d32=12345.df" " = 12345" "12345. is an valid number"
+    gdb_test "p d32=12345df" ".*Invalid number.*" "12345 is an invalid number"
+    gdb_test "p d32=1.23Edf" " = NaN" "1.23E is NaN (not a number)"
+    gdb_test "p d32=1.23E45Adf" " = NaN" "1.23E45A is NaN (not a number)"
+}
+
+proc d64_set_tests {} {
+
+    gdb_test "p d64=123.45dd" " = 123.45"
+    gdb_test "p d64=12345.dd" " = 12345"
+    gdb_test "p d64=12345.67dd" " = 12345.67"
+    gdb_test "p d64=1.234567890123456dd" " = 1.234567890123456"
+
+    gdb_test "p d64=1.234567890123456E10dd" " = 12345678901.23456"
+    gdb_test "p d64=1.234567890123456E100dd" " = 1.234567890123456E\\+100"
+    gdb_test "p d64=1.234567890123456E384dd" " = 1.234567890123456E\\+384"
+
+    # Test that gdb could handle the max, normalized min and subnormalized min.
+    gdb_test "p d64=9.999999999999999E384dd" " = 9.999999999999999E\\+384"
+    gdb_test "p d64=1.E-383dd" " = 1E\\-383"
+    gdb_test "p d64=1.E-398dd" " = 1E\\-398"
+    gdb_test "p d64=0.000000000000001E-383dd" " = 1E\\-398"
+
+    # Test that gdb could detect coefficient/exponent out of range.
+    # The coefficient out of range will be rounded to its nearest value.
+    # And the exponent out of range will be handled as infinity.
+    gdb_test "p d64=1.2345678901234567dd" " = 1.234567890123457" "1.2345678901234567 is rounded to 1.234567890123457"
+    gdb_test "p d64=9.9999999999999999E384dd" " = Infinity" "d64=9.9999999999999999E384 is Infinity"
+    gdb_test "p d64=1.234567890123456E385dd" " = Infinity" "d64=1.234567890123456E385 is Infinity"
+
+    # Test that gdb could detect the errors in the string representation of _Decimal64
+    gdb_test "p d64=12345dd" ".*Invalid number.*" "12345dd is an invalid number"
+    gdb_test "p d64=1.23Edd" " = NaN" "1.23E is NaN (not a number)"
+    gdb_test "p d64=1.23E45Add" "= NaN" "1.23E45A is NaN (not a number)"
+}
+
+proc d128_set_tests {} {
+
+    gdb_test "p d128=123.45dl" " = 123.45"
+    gdb_test "p d128=12345.dl" " = 12345"
+    gdb_test "p d128=12345.67dl" " = 12345.67"
+    gdb_test "p d128=1.234567890123456789012345678901234dl" " = 1.234567890123456789012345678901234"
+
+    gdb_test "p d128=1.234567890123456E10dl" " = 12345678901.23456"
+    gdb_test "p d128=1.234567890123456E100dl" " = 1.234567890123456E\\+100"
+    gdb_test "p d128=1.234567890123456E1000dl" " = 1.234567890123456E\\+1000"
+
+    # Test that gdb could handle the max, normalized min and subnormalized min.
+    gdb_test "p d128=9.999999999999999999999999999999999E6144dl" " = 9.999999999999999999999999999999999E\\+6144"
+    gdb_test "p d128=1.E-6143dl" " = 1E\\-6143"
+    gdb_test "p d128=1.E-6176dl" " = 1E\\-6176"
+    gdb_test "p d128=0.000000000000000000000000000000001E-6143dl" " = 1E\\-6176"
+
+    # Test that gdb could detect coefficient/exponent out of range.
+    # The coefficient out of range will be rounded to its nearest value.
+    # And the exponent out of range will be handled as infinity.
+    gdb_test "p d128=1.2345678901234567890123456789012345dl" "1.234567890123456789012345678901234" "1.2345678901234567890123456789012345 is rounded to 1.234567890123456789012345678901234"
+    gdb_test "p d128=1.234567890123456E6145dl" "Infinity" "d128=1.234567890123456E6145 is Infinity"
+
+    # Test that gdb could detect the errors in the string representation of _Decimal128
+    gdb_test "p d128=12345dl" ".*Invalid number.*" "12345dl is an invalid number"
+    gdb_test "p d128=1.23Edl" " = NaN" "1.23E is NaN (not a number)"
+    gdb_test "p d128=1.23E45Adl" "= NaN" "1.23E45A is NaN (not a number)"
+}
+
+
+if $tracelevel {
+    strace $tracelevel
+}
+
+set testfile "dfp-test"
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "compiler=/opt/biarch/gcc411-P6DFP4/bin/gcc debug"] != "" } {
+    untested "Couldn't compile ${srcfile}"
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+if ![runto_main] then {
+    perror "couldn't run to breakpoint"
+    continue
+}
+
+# Different tests on 32-bits decimal floating point, including the printing
+# of finite numbers, infinite and NaN, and also the setting of different
+# decimal value.
+
+if [gdb_test "next" \
+    ".*Positive infd32.*" \
+    "next after initializing d32"] then { gdb_suppress_tests }
+gdb_test "print d32" "1.2345" "d32 is initialized to 1.2345"
+
+if [gdb_test "next" \
+    ".*Negative infd32.*" \
+    "next after assigning builtin infinity to d32"] then { gdb_suppress_tests }
+gdb_test "print d32" "Infinity" "d32 is positive Infinity"
+
+if [gdb_test "next" \
+    ".*__builtin_nand32.*" \
+    "next after assigning negative builtin infinity to d32"] then { gdb_suppress_tests }
+gdb_test "print d32" "-Infinity" "d32 is negative Infinity"
+
+if [gdb_test "next" \
+    ".*d64 = 1.2345.*" \
+    "next after assigning builtin NaN to d32"] then { gdb_suppress_tests }
+gdb_test "print d32" "NaN" "d32 is NaN"
+
+d32_set_tests
+
+
+# Different tests on 64-bits decimal floating point, including the display
+# of finite number, infinite and NaN, and also the setting of different
+# decimal value.
+
+if [gdb_test "next" \
+    ".*Positive infd64.*" \
+    "next after initializing d64"] then { gdb_suppress_tests }
+gdb_test "print d64" "1.2345" "d64 is initialized to 1.2345"
+
+if [gdb_test "next" \
+    ".*Negative infd64.*" \
+    "next after assigning builtin infinity to d64"] then { gdb_suppress_tests }
+gdb_test "print d64" "Infinity" "d64 is positive Infinity"
+
+if [gdb_test "next" \
+    ".*__builtin_nand64.*" \
+    "next after assigning negative builtin infinity to d64"] then { gdb_suppress_tests }
+gdb_test "print d64" "-Infinity" "d64 is negative Infinity"
+
+if [gdb_test "next" \
+    ".*d128 = 1.2345.*" \
+    "next after assigning builtin NaN to d64"] then { gdb_suppress_tests }
+gdb_test "print d64" "NaN" "d64 is NaN"
+
+d64_set_tests
+
+
+# Different tests on 128-bits decimal floating point, including the display
+# of finite number, infinite and NaN, and also the setting of different
+# decimal value.
+
+if [gdb_test "next" \
+    ".*Positive infd128.*" \
+    "next after initializing d128"] then { gdb_suppress_tests }
+gdb_test "print d128" "1.2345" "d128 is initialized to 1.2345"
+
+d128_set_tests
+
+if [gdb_test "next" \
+    ".*Negative infd128.*" \
+    "next after assigning builtin infinity to d128"] then { gdb_suppress_tests }
+gdb_test "print d128" "Infinity" "d128 is positive Infinity"
+
+if [gdb_test "next" \
+    ".*__builtin_nand128.*" \
+    "next after assigning negative builtin infinity to d128"] then { gdb_suppress_tests }
+gdb_test "print d128" "-Infinity" "d128 is negative Infinity"
+
+if [gdb_test "next" \
+    ".*arg0_32.*" \
+    "next after assigning builtin NaN to d128"] then { gdb_suppress_tests }
+gdb_test "print d128" "NaN" "d128 is NaN"
+
+# The following tests are intended to verify that gdb can correctly handle
+# DFP types in function arguments.
+
+gdb_breakpoint arg0_32
+gdb_continue_to_breakpoint "entry to arg0_32"
+gdb_test "backtrace" ".*arg0_32 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_32"
+
+gdb_breakpoint arg0_64
+gdb_continue_to_breakpoint "entry to arg0_64"
+gdb_test "backtrace" ".*arg0_64 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_64"
+
+gdb_breakpoint arg0_128
+gdb_continue_to_breakpoint "entry to arg0_128"
+gdb_test "backtrace" ".*arg0_128 \\(arg0=0.1, arg1=1.0, arg2=2.0, arg3=3.0, arg4=4.0, arg5=5.0\\).*" "backtrace at arg0_128"
+
+# The following tests are intended to verify that gdb can handle DFP types
+# correctly in struct.
+
+gdb_breakpoint [gdb_get_line_number "Exit point"]
+gdb_continue_to_breakpoint "Setting a decimal struct"
+gdb_test "print ds.dec32" " = 1.2345"
+gdb_test "print ds.dec64" " = 1.2345"
+gdb_test "print ds.dec128" " = 1.2345"
+
+# The following tests are intended to verify that gdb can handle "d1=d2"
+# and "d1=-d2" correctly.
+
+gdb_test "print ds.dec32=d32" " = 0.1"
+gdb_test "print ds.dec64=d64" " = 0.1"
+gdb_test "print ds.dec128=d128" " = 0.1"
+gdb_test "print ds.dec32 = -d32" " = -0.1"
+gdb_test "print ds.dec64 = -d64" " = -0.1"
+gdb_test "print ds.dec128 = -d128" " = -0.1"

--


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2007-10-25 18:24 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-20 21:57 [patch 0/4] decimal floating point support Thiago Jung Bauermann
2007-09-20 21:57 ` [patch 3/4] decimal floating point support for expressions Thiago Jung Bauermann
2007-10-11 16:18   ` Daniel Jacobowitz
2007-10-15 18:12     ` Thiago Jung Bauermann
2007-10-24 20:12       ` Daniel Jacobowitz
2007-10-25 18:40         ` Thiago Jung Bauermann
2007-09-20 21:57 ` [patch 4/4] decimal floating point testcases Thiago Jung Bauermann
2007-10-11 16:19   ` Daniel Jacobowitz
2007-10-15 18:12     ` Thiago Jung Bauermann
2007-10-25 18:22       ` Thiago Jung Bauermann
2007-09-20 21:57 ` [patch 1/4] libdecnumber support Thiago Jung Bauermann
2007-10-11 15:57   ` Daniel Jacobowitz
2007-10-11 16:07     ` Daniel Jacobowitz
2007-10-15 18:32       ` Thiago Jung Bauermann
2007-10-15 18:11     ` Thiago Jung Bauermann
2007-10-15 18:38       ` Daniel Jacobowitz
2007-10-25 18:23         ` Thiago Jung Bauermann
2007-09-20 21:57 ` [patch 2/4] decimal floating point types Thiago Jung Bauermann
2007-10-11 16:00   ` Daniel Jacobowitz
2007-10-15 18:12     ` Thiago Jung Bauermann
2007-10-24 20:11       ` Daniel Jacobowitz
2007-10-25 18:24         ` Thiago Jung Bauermann
     [not found] <20070323030737.475073862@br.ibm.com>
2007-03-27 16:30 ` [patch 4/4] decimal floating point testcases Thiago Jung Bauermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox