From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4481 invoked by alias); 15 Oct 2007 18:11:11 -0000 Received: (qmail 4469 invoked by uid 22791); 15 Oct 2007 18:11:10 -0000 X-Spam-Check-By: sourceware.org Received: from igw1.br.ibm.com (HELO igw1.br.ibm.com) (32.104.18.24) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 15 Oct 2007 18:11:01 +0000 Received: from mailhub1.br.ibm.com (mailhub1 [9.18.232.109]) by igw1.br.ibm.com (Postfix) with ESMTP id 76D0832C1BA for ; Mon, 15 Oct 2007 16:09:03 -0200 (BRDT) Received: from d24av02.br.ibm.com (d24av02.br.ibm.com [9.18.232.47]) by mailhub1.br.ibm.com (8.13.8/8.13.8/NCO v8.5) with ESMTP id l9FIAwSQ2937024 for ; Mon, 15 Oct 2007 16:10:58 -0200 Received: from d24av02.br.ibm.com (loopback [127.0.0.1]) by d24av02.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id l9FIAwHU014833 for ; Mon, 15 Oct 2007 15:10:58 -0300 Received: from [9.18.238.251] (dyn532128.br.ibm.com [9.18.238.251]) by d24av02.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id l9FIAwHF014826; Mon, 15 Oct 2007 15:10:58 -0300 Subject: Re: [patch 1/4] libdecnumber support From: Thiago Jung Bauermann To: Daniel Jacobowitz Cc: gdb-patches@sourceware.org In-Reply-To: <20071011155418.GA22982@caradoc.them.org> References: <20070920215410.062714003@br.ibm.com> <20070920215539.570827491@br.ibm.com> <20071011155418.GA22982@caradoc.them.org> Content-Type: multipart/mixed; boundary="=-Zq7aKfel9o04J36SiKkk" Date: Mon, 15 Oct 2007 18:11:00 -0000 Message-Id: <1192471857.5787.44.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.12.0 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-10/txt/msg00394.txt.bz2 --=-Zq7aKfel9o04J36SiKkk Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 2968 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 > > +#include > > +#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 > > +#include > > +#include > > 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 --=-Zq7aKfel9o04J36SiKkk Content-Disposition: attachment; filename=libdecnumber-support.diff Content-Type: text/x-patch; name=libdecnumber-support.diff; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 11282 Subject: libdecnumber support This patch provides functions to interact with libdecnumber and changes the Makefile to compile it. 2007-10-15 Wu Zhou Thiago Jung Bauermann * 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 . */ + +#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 . */ + +/* 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. # --=-Zq7aKfel9o04J36SiKkk--