From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10001 invoked by alias); 27 Mar 2007 16:30:17 -0000 Received: (qmail 9928 invoked by uid 22791); 27 Mar 2007 16:30:12 -0000 X-Spam-Check-By: sourceware.org Received: from igw3.br.ibm.com (HELO igw3.br.ibm.com) (32.104.18.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 27 Mar 2007 17:30:01 +0100 Received: from mailhub3.br.ibm.com (unknown [9.18.232.110]) by igw3.br.ibm.com (Postfix) with ESMTP id 291AE3902C4 for ; Tue, 27 Mar 2007 13:23:56 -0300 (BRT) Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.18.232.46]) by mailhub3.br.ibm.com (8.13.8/8.13.8/NCO v8.3) with ESMTP id l2RGTdqt1155194 for ; Tue, 27 Mar 2007 13:29:39 -0300 Received: from d24av01.br.ibm.com (loopback [127.0.0.1]) by d24av01.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id l2RGReoL018719 for ; Tue, 27 Mar 2007 13:27:40 -0300 Received: from dyn532128.br.ibm.com ([9.18.238.251]) by d24av01.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id l2RGReNw018715 for ; Tue, 27 Mar 2007 13:27:40 -0300 Subject: [patch 1/4] libdecnumber support From: Thiago Jung Bauermann To: gdb-patches@sourceware.org References: <20070323030737.475073862@br.ibm.com> Content-Type: text/plain Date: Tue, 27 Mar 2007 16:30:00 -0000 Message-Id: <1175012969.21904.9.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.3 Content-Transfer-Encoding: 7bit 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-03/txt/msg00251.txt.bz2 plain text document attachment (libdecnumber-support.diff) This patch provides functions to interact with libdecnumber and changes the Makefile to compile it. 2007-03-23 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. (valprint.o): Add dfp_h as a new dependence. * 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-03-13 14:56:28.000000000 -0300 +++ gdb/Makefile.in 2007-03-13 14:56:33.000000000 -0300 @@ -122,6 +122,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 = $(READLINE_DIR)/libreadline.a @@ -354,7 +360,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) @@ -377,10 +383,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) @@ -620,6 +626,10 @@ safe_ctype_h = $(INCLUDE_DIR)/safe-ctyp hashtab_h = $(INCLUDE_DIR)/hashtab.h filenames_h = $(INCLUDE_DIR)/filenames.h +decimal128_h = $(LIBDECNUMBER_DIR)/decimal128.h +decimal64_h = $(LIBDECNUMBER_DIR)/decimal64.h +decimal32_h = $(LIBDECNUMBER_DIR)/decimal32.h + # # $BUILD/ headers # @@ -687,6 +697,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 @@ -937,7 +948,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 \ @@ -1966,6 +1977,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) \ @@ -2867,7 +2879,7 @@ 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) $(scm_lang_h) $(demangle_h) $(doublest_h) \ Index: gdb/dfp.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gdb/dfp.c 2007-03-13 15:19:43.000000000 -0300 @@ -0,0 +1,122 @@ +/* Decimal floating point support for GDB. + + Copyright 2006 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 "defs.h" +#include "dfp.h" +#include + +/* The order of the following headers is important for making sure + decNumber structure is large enough to hold decimal128 digits. */ + +#include "decimal128.h" +#include "decimal64.h" +#include "decimal32.h" +#include "decNumber.h" + +/* In gdb, we are using an array of gdb_byte to represent decimal values. The + byte order of our representation might be different than that of underlying + architecture. This routine does the conversion if it is necessary. */ +static void +exchange_dfp (const gdb_byte *valaddr, int len, gdb_byte *dec_val) +{ + int index; + + if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_LITTLE) + for (index = 0; index < len; index++) + dec_val[index] = valaddr[len - index - 1]; + else + for (index = 0; index < len; index++) + dec_val[index] = valaddr[index]; + + 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); + + exchange_dfp (decbytes, len, dec); + switch (len) + { + case 4: + decimal32ToString ((decimal32 *) dec, s); + return; + case 8: + decimal64ToString ((decimal64 *) dec, s); + return; + case 16: + decimal128ToString ((decimal128 *) dec, s); + return; + default: + return; + } + + 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, char *string) +{ + decNumber dn; + decContext set; + int index; + uint8_t *dec = (uint8_t *)malloc (len); + + switch (len) + { + case 4: + decContextDefault (&set, DEC_INIT_DECIMAL32); + break; + case 8: + decContextDefault (&set, DEC_INIT_DECIMAL64); + break; + case 16: + decContextDefault (&set, DEC_INIT_DECIMAL128); + break; + } + + set.traps = 0; + + decNumberFromString (&dn, string, &set); + switch (len) + { + case 4: + decimal32FromNumber ((decimal32 *) dec, &dn, &set); + break; + case 8: + decimal64FromNumber ((decimal64 *) dec, &dn, &set); + break; + case 16: + decimal128FromNumber ((decimal128 *) dec, &dn, &set); + break; + } + + exchange_dfp (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-03-13 14:56:33.000000000 -0300 @@ -0,0 +1,40 @@ +/* Decimal floating point support for GDB. + + Copyright 2006 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 +#include +#include + +extern void decimal_to_string (const uint8_t *, int, char *); +extern int decimal_from_string (uint8_t *, int, char *); + +#endif --