Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <bauerman@br.ibm.com>
To: Daniel Jacobowitz <drow@false.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch 3/4] decimal floating point support for expressions
Date: Mon, 15 Oct 2007 18:12:00 -0000	[thread overview]
Message-ID: <1192471932.5787.46.camel@localhost.localdomain> (raw)
In-Reply-To: <20071011161645.GD22982@caradoc.them.org>

[-- 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);

  reply	other threads:[~2007-10-15 18:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-20 21:57 [patch 0/4] decimal floating point support 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
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 [this message]
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
     [not found] <20070323030737.475073862@br.ibm.com>
2007-03-27 16:30 ` [patch 3/4] decimal floating point support for expressions Thiago Jung Bauermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1192471932.5787.46.camel@localhost.localdomain \
    --to=bauerman@br.ibm.com \
    --cc=drow@false.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox